Hello I am just testing a few things with a plugin that can grow trees at random when you shift next to saplings, my code works, but it is always growing the tree, I think it is just running it multiple times, and not just once per toggle sneak. Does anyone know how to fix this? Code: package me.flash110; import java.util.ArrayList; import java.util.List; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.TreeType; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.plugin.java.JavaPlugin; import net.minecraft.server.v1_8_R3.EnumParticle; public class Trees extends JavaPlugin implements Listener { static int max = 4; static int min = 1; public static ArrayList<String> cooldown = new ArrayList<>(); public void onEnable() { Bukkit.getPluginManager().registerEvents(this, this); } @EventHandler public void shift(PlayerToggleSneakEvent e) { Player p = e.getPlayer(); Location l = p.getLocation(); cool(p , l); } private static List<Location> getArenaBlocks(Location l, int radius) { World w = l.getWorld(); int xCoord = (int) l.getX(); int zCoord = (int) l.getZ(); int YCoord = (int) l.getY(); List<Location> tempList = new ArrayList<Location>(); for (int x = -radius; x <= radius; x++) { for (int z = -radius; z <= radius; z++) { for (int y = -radius; y <= radius; y++) { tempList.add(new Location(w, xCoord + x, YCoord + y, zCoord + z)); for(Location loc : tempList) { if (loc.getBlock().getType() == Material.SAPLING) { int rand = (int) (Math.random() * ((max - min) + 1) + min); if (rand == 3) { loc.getBlock().setType(Material.AIR); loc.getWorld().generateTree(loc, TreeType.TREE); } else { ParticleCat.sendParticle(EnumParticle.VILLAGER_HAPPY, loc, 1, 1, 1, 1, 15); } } } } } } return tempList; } public void cool(Player p, Location l) { cooldown.add(p.getName()); Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){ @Override public void run() { cooldown.remove(p.getName()); getArenaBlocks(l, 3); } },10); } }
Did you try to debug it yet? just put a sysout or smth in the event-method and you will see on the console if its only called once if you press shift or if its called multiple times and btw. your "profile message" is a little weird. Code: public static ArrayList<String> friends = new ArrayList<>(); friends.add(Bukkit.getForums().getOnline); if the object returned by getForums() doesn't have a accessable field called "getOnline" this code won't work. I think you are missing brackets, aren't you?