TntSpawners plugin not dropping all the spawners

Discussion in 'Plugin Development' started by immensebuttpain, Jan 5, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    immensebuttpain

    Code:
    package me.ImmenseButtPain;
    
    import java.util.Iterator;
    import java.util.List;
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockState;
    import org.bukkit.block.CreatureSpawner;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityExplodeEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import de.dustplanet.util.SilkUtil;
    
    public class Main extends JavaPlugin{
    
        Logger log;
        SilkUtil su;
        int distance;
       
        public void onEnable(){
            su = SilkUtil.hookIntoSilkSpanwers();
            log = Bukkit.getLogger();
            getServer().getPluginManager().registerEvents(new TntSpawners(), this);
            saveDefaultConfig();
            distance = getConfig().getInt("distance");
        }
       
        public class TntSpawners implements Listener{
           
            @EventHandler
            public void onEntityExplode(EntityExplodeEvent event) {
                List<Block> destroyed = event.blockList();
                Iterator<Block> it = destroyed.iterator();
                BlockState bs = null;
                while(it.hasNext()) {
                    Block block = it.next();
                    if(saveBlock(block.getType())){
                        getLogger().info("save it!");
                        for(Player p : Bukkit.getOnlinePlayers()){
                            if(p.hasPermission("TntSpawners.savespawner")){
                                if(block.getWorld() == p.getWorld()){
                                    if(block.getLocation().distance(p.getLocation()) < distance){
                                        bs = block.getState();
                                        Location loc = block.getLocation();
                                        it.remove();
                                        if(bs instanceof CreatureSpawner){CreatureSpawner cs = (CreatureSpawner) bs;
                                            String name = cs.getCreatureTypeName();
                                            ItemStack is = su.newSpawnerItem(su.getSpawnerEntityID(block), name);
                                            ItemMeta m = is.getItemMeta();
                                            m.setDisplayName(ChatColor.YELLOW + name + ChatColor.WHITE + " Spawner");
                                            is.setItemMeta(m);
                                            block.setType(Material.AIR);
                                            Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin(getName()), new DropBlock(loc, is), 5);
                                            break;
                                        }                                      
                                        ItemStack is = new ItemStack(block.getType());
                                        block.setType(Material.AIR);
                                        Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin(getName()), new DropBlock(loc, is), 5);
                                        break;
                                    }
                                }
                            }        
                        }
                    }               
                }
            }
        }
       
        public class DropBlock implements Runnable  {
    
            Location loc;
            ItemStack is;
           
            DropBlock(Location l, ItemStack i) {
                loc = l;
                is = i;
            }
           
            @Override
            public void run() {
                loc.getWorld().dropItem(loc, is);
            }
           
        }
       
        public boolean saveBlock(Material mat){
            List<String> save = getConfig().getStringList("BlockstoDrop");
            for(String name : save){
                Material test = Material.matchMaterial(name);
                if(test == mat){
                    return true;
                }
            }
            return false;
        }
    }
    
    The plugin works halfway, it says the save it in the console like it's suppose too, but it will not drop the spawner, here's a video showing it in action:


    Code:
    version: 1.1
    distance: 20
    BlockstoDrop:
      - Mob_Spawner
      - 52
      - MONSTER_SPAWNER
    this is inside the config, i added all the things i could think that would work for monsterspawner, i've tested it with glass, and other items but it won't make those items drop by explosions. idk what the problem is and i would love some help

    It also only says save it in the console if it blows up something in the config. so it knows that's the item that it's suppose to drop, but that doesn't work.

    EDIT by Timtower: merged posts, please use the edit button instead
     
    Last edited by a moderator: Jan 6, 2015
  2. Offline

    nj2miami

    Why don't you add some output code to see if it is reaching certain levels of your conditionals? This will help narrow down what is not firing. It is nested 7 levels deep so it is hard to troubleshoot from the outside.
     
Thread Status:
Not open for further replies.

Share This Page