Minecraft[1.7] Spawner Modifications

Discussion in 'Spigot Plugin Development' started by AMinecraftDev, Jun 15, 2016.

  1. Hi, So I am currently working on a plugin which modifies exactly how often a spawner spawns, and how many mobs it spawns, so I was wondering, what is the best way to do this? I've tried via. NBT tags but they return null, not sure if it's because of 1.7 or what, but they don't work. Here is the code I'm currently trying to use to modify it:
    Code (Text):
        public void onSpawnerSpawn(SpawnerSpawnEvent e) {
            CreatureSpawner cs = e.getSpawner();
            Location l = cs.getLocation();
            String loc = locationString(l);
            if(!locListDelay.contains(loc)) {
                System.out.println("EVENT CALLED");
                int tier = 0;
                if(plugin.getSpawners().contains("Spawners."+loc)) {
                    tier = plugin.getSpawners().getInt("Spawners."+loc);
                int delay = plugin.getConfig().getInt("Settings.Time.Tier"+tier) * 20;
                System.out.println("DELAY: " + delay);
                new BukkitRunnable() {
                    public void run() {
                }.runTaskTimer(plugin, (long)delay, 0L);
            } else {
    However it doesn't actually set the delay to what I want it to be set to, it just gets reset to a random time. Is there a way I can change this? Also add a modifier to set how many mobs it will spawn.

  2. Bump, please reply i really need to fix this asap!
  3. Only bump every 24 hours. Your question is just as important as everyone else's.

    Your delay int is probably null. Are you sure that the tier delays are stored like this in your config?
    Code (Text):
        Tier1: 5
        Tier2: 20
        Tier3: 45
  4. Ye i have
    Code (Text):
        Tier1: 5
        Tier2: 7
        Tier3: 10
        Tier1: 1
        Tier2: 2
        Tier3: 3

    I want it to spawn that amount of mobs every that often :p
  5. Also the delay isn't null because i print it out and it says the correct time, it just doesn't actually modify the spawner delay
  6. @HazePvPHD their NBT Tag isn't null. What were you using?
  7. What do you mean what was I using? I was trying to edit the CreatureSpawner. Do I have to edit the NBT tag?
  8. @HazePvPHD you said you were getting it's NBT tag, but it returned null. Could you show the code you were trying to use?
  9. Ahh, yes.

    Code (Text):
    import java.util.HashMap;
    import java.util.List;

    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
    import org.bukkit.inventory.meta.ItemMeta;

    import com.aliumcraft.bottlexp.utils.NMS;

    import net.minecraft.server.v1_7_R4.*;

    public class v1_7_R4 implements NMS {

        public org.bukkit.inventory.ItemStack addItems(String type, String displayName, List<String> lore, HashMap<String, String> nbtTag) {
            org.bukkit.inventory.ItemStack is = new org.bukkit.inventory.ItemStack(Material.getMaterial(type), 1);
            CraftItemStack cis = CraftItemStack.asCraftCopy(is);
            ItemStack nmsis = CraftItemStack.asNMSCopy(cis);
            NBTTagCompound com = new NBTTagCompound();
            for(String var : nbtTag.keySet()) {
                com.setString(var, nbtTag.get(var));
            org.bukkit.inventory.ItemStack bis = CraftItemStack.asBukkitCopy(nmsis);
            ItemMeta bisMeta = bis.getItemMeta();
            bisMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', displayName));
            return bis;

        public String getTag(org.bukkit.inventory.ItemStack is, String key) {
            ItemStack s = CraftItemStack.asNMSCopy(is);
            NBTTagCompound com = s.getTag();
            if (com!=null && com.hasKey(key)) {
                return com.getString(key);
            } else {
                return null;
    ^^ Is what I use to get/set the tag, and here is the actual code I tried:

    Code (Text):
    Map<String,String> hash = new HashMap<String,String>();

    hash.put("SPAWN-RATE", tier);
    hash.put("SPAWN-AMOUNT", amount);

    ItemStack is = addItems("MOB_SPAWNER", "&eSpawner", lore, hash);

    String s = getTag(is, "SPAWN-RATE");
    And the string s will equal to null..