[SPIGOT-7286] Asynchronous entity add! Created: 05/Mar/23 Updated: 25/Dec/24 Resolved: 05/Mar/23 |
|
Status: | Closed |
Project: | Spigot |
Component/s: | None |
Affects Version/s: | None |
Fix Version/s: | None |
Type: | Bug | Priority: | Major |
Reporter: | Developer Team | Assignee: | Unassigned |
Resolution: | Invalid | Votes: | 0 |
Labels: | Drop, Items |
Attachments: |
![]() |
Version: | 1.19.2 |
Guidelines Read: | Yes |
Description |
My code: package net.malejmarabu.gs.games.function; import net.malejmarabu.gs.addtional.Yamls; import java.util.*; public class ItemDroper { private Yamls yml; public HashMap<Location, Integer> levels = new HashMap<>(); public HashMap<String, ArrayList<Location>> maps = new HashMap<>(); private HashMap<Location, Long> lastgen = new HashMap<>(); Timer timer = new Timer(); double[] brint = \{1,0.75,0.5,0.25,0.125};
public void ItemGenerator(Location loc, Material material, int level) { if (material.equals(Material.IRON_BLOCK)) { interval = irint[level]; }if (material.equals(Material.GOLD_BLOCK)) { interval = glint[level]; }if (material.equals(Material.DIAMOND_BLOCK)) { interval = diint[level]; }if (material.equals(Material.EMERALD_BLOCK)) { interval = emint[level]; }if(!lastgen.containsKey(loc)) { lastgen.put(loc, cur); }last = lastgen.get(loc); //if (last - cur >= interval * 1000) { if (material.equals(Material.GOLD_BLOCK)) { ItemStack items = new ItemStack(Material.GOLD_INGOT, 1); Item item = world.dropItem(block.getLocation(), items); }if (material.equals(Material.IRON_BLOCK)) { ItemStack items = new ItemStack(Material.IRON_INGOT, 1); Item item = world.dropItem(block.getLocation(), items); }if (material.equals(Material.BROWN_CONCRETE)) { ItemStack items = new ItemStack(Material.BRICK, 1); Item item = world.dropItem(block.getLocation(), items); item.setCustomName("Bronze"); }if (material.equals(Material.EMERALD_BLOCK)) { ItemStack items = new ItemStack(Material.EMERALD, 1); Item item = world.dropItem(block.getLocation(), items); } //Bukkit.getLogger().info("At position: " + loc.getBlockX() + " " + loc.getBlockY() + " " + loc.getBlockZ() + " from material: " + material + " here drop item"); public void setup() { this.yml = new Yamls(); //Location loc = new Location(Bukkit.getWorld(yml.getGens().getString("Generators." + i + ".loc.world")), yml.getGens().getDouble("Generators." + i + ".loc.x"), yml.getGens().getDouble("Generators." + i + ".loc.y"), yml.getGens().getDouble("Generators." + i + ".loc .of")); else { maps.get(map).add(loc); } Timer timer = new Timer(); else { else { level = levels.get(loc); } ItemGenerator(loc, material, level); public void stop() { timer.cancel(); }}
The error is that the timer stops and suddenly it prints this error: I don't know how to fix it. |
Comments |
Comment by Developer Team [ 05/Mar/23 ] |
Thanks |
Comment by Black Hole [ 05/Mar/23 ] |
For help using the Bukkit scheduler, please ask on the Spigot forums. |
Comment by FreeSoccerHDX [ 05/Mar/23 ] |
Like the exception says you cant add entities to the world from another thread then the main-thread. The following Call is the Problem: Item item = world.dropItem(block.getLocation(), items); Option 1 is to use the Bukkit-Scheduler for all |