Solved How to set a spawner type to 'none'

Discussion in 'Plugin Development' started by fireboyev, Jun 13, 2016.

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

    fireboyev

    Hello! I would like to know how I could possibly set a spawner mob type to spawn nothing. If possible please give me an idea that does not include changing the spawning delay, thanks.
     
  2. Offline

    Zombie_Striker

    @fireboyev
    You can try setting the mobType to a mob that cannot be spawned (I.e a leashknot).
     
  3. Offline

    fireboyev

    Doesn't work. still spawns leads.

    would it be possible to spawn air? like as an item.
     
  4. Offline

    Zombie_Striker

  5. Offline

    fireboyev

    Okay so items work but now ill tell you what i want it to do.
    My plugin is a plugin that lets you get the mob eggs from spawners and changes the spawner to an empty spawner (something doesn't spawn like the air item) but now when i click on the spawner when it is set to item it gives me the egg called spawn item, how can i make it not give me that mob type or how can i test if the mobtype of a spawner is a certain entity like dropped item
     
  6. Offline

    Zombie_Striker

  7. Offline

    fireboyev

    Still doesn't work and still gives me the item spawn egg. Here is my Code:
    Code:
    package com.fireboyev.soulspawners.event;
    
    
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.block.CreatureSpawner;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    
    import com.fireboyev.soulspawners.SpawnEggs;
    
    public class SoulTake implements Listener {
        @EventHandler
        public void OnPlayerInteract(PlayerInteractEvent event) {
    
            Player player = event.getPlayer();
            Block block = event.getClickedBlock();
    
            Material material = block.getType();
            CreatureSpawner type = (CreatureSpawner) block.getState();
            EntityType mobtype = type.getSpawnedType();
           
           
            if (material == Material.MOB_SPAWNER && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                player.sendMessage("This is a Mob Spawner");
                ItemStack item = new ItemStack(Material.MONSTER_EGG);
                item = new SpawnEggs(mobtype).toItemStack(1);
                PlayerInventory inv = player.getInventory();
               
                if (!(mobtype.equals(EntityType.DROPPED_ITEM))) {
                    inv.addItem(item);
                    type.setSpawnedType(EntityType.DROPPED_ITEM);
                }
            }
        }
    }
    
     
  8. Offline

    Zombie_Striker

    Use '==' for comparing enums.

    Try debugging. Test what mobtype is equal to. Although it should be dropped item, it might not.
     
  9. Offline

    fireboyev

    I have yet another problem. When I add

    Code:
    } else {
                    player.sendMessage(Prefix + "Spawner Type Is already set to " + Default + "!");
    
    it doesnt work here is my code:
    Code:
    package com.fireboyev.soulspawners.event;
    
    import java.util.List;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.block.CreatureSpawner;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    
    import com.fireboyev.soulspawners.SoulSpawners;
    import com.fireboyev.soulspawners.SpawnEggs;
    
    public class SoulTake implements Listener {
        private SoulSpawners plugin;
    
        @EventHandler
        public void OnPlayerInteract(PlayerInteractEvent event) {
    
            String Prefix = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Prefix"));
             String Default = plugin.getConfig().getString("Default Mobtype").toUpperCase();
             @SuppressWarnings("unchecked")
             List<String> Worlds = (List<String>)
             plugin.getConfig().getList("Worlds");
            Player player = event.getPlayer();
            Block block = event.getClickedBlock();
    
            Material material = block.getType();
            CreatureSpawner type = (CreatureSpawner) block.getState();
            EntityType mobtype = type.getSpawnedType();
    
             if (player.getWorld().getName().equals(Worlds)) {
            if (material == Material.MOB_SPAWNER && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                player.sendMessage("This is a Mob Spawner");
                ItemStack item = new ItemStack(Material.MONSTER_EGG);
                item = new SpawnEggs(mobtype).toItemStack(1);
                PlayerInventory inv = player.getInventory();
    
                if (!(mobtype == EntityType.PIG)) {
                    inv.addItem(item);
                    type.setSpawnedType(EntityType.PIG);
                } else {
                    player.sendMessage(Prefix + "Spawner Type Is already set to " + Default + "!");
                }
                }
            }
        }
    }
    
     
    Last edited: Jun 15, 2016
  10. Offline

    Zombie_Striker

    First, this is too close to "default" (the equivalent to an "else" statement, but for switch statements), and does not follow JavaNamingConventions. Choose another variable name that starts with a lowercase letter.

    Second, a lot of your variables are not need. You only need to create a variable if the sequence to get them are far too long (i.e you have to go through 7+ objects to get it) or if you use it a lot. You only use variables like material and inv once or twice. Only keep variables you use a lot or are hard to get.

    Finally, what do you mean "doesn't work". Does it run? Does it not do the thing you want to happen? If so, what is the thing you want to happen?
     
  11. Offline

    fireboyev

    Without the else statement it worked just how i wanted it but as soon as i added it, it stopped working. when i removed it, it worked again.
    also each time i right click it spits out errors in the console:
    Code:
    [19:52:22 ERROR]: Could not pass event PlayerInteractEvent to SoulSpawners v0.1
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[Spigot.jar:git-Spigot-798f32d-0cd0397]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[Spigot.jar:git-Spigot-798f32d-0cd0397]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [Spigot.jar:git-Spigot-798f32d-0cd0397]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [Spigot.jar:git-Spigot-798f32d-0cd0397]
            at org.bukkit.craftbukkit.v1_9_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:231) [Spigot.jar:git-Spigot-798f32d-0cd0397]
            at net.minecraft.server.v1_9_R2.PlayerInteractManager.a(PlayerInteractManager.java:483) [Spigot.jar:git-Spigot-798f32d-0cd0397]
            at net.minecraft.server.v1_9_R2.PlayerConnection.a(PlayerConnection.java:887) [Spigot.jar:git-Spigot-798f32d-0cd0397]
            at net.minecraft.server.v1_9_R2.PacketPlayInUseItem.a(SourceFile:55) [Spigot.jar:git-Spigot-798f32d-0cd0397]
            at net.minecraft.server.v1_9_R2.PacketPlayInUseItem.a(SourceFile:11) [Spigot.jar:git-Spigot-798f32d-0cd0397]
            at net.minecraft.server.v1_9_R2.PlayerConnectionUtils$1.run(SourceFile:13) [Spigot.jar:git-Spigot-798f32d-0cd0397]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_92]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_92]
            at net.minecraft.server.v1_9_R2.SystemUtils.a(SourceFile:45) [Spigot.jar:git-Spigot-798f32d-0cd0397]
            at net.minecraft.server.v1_9_R2.MinecraftServer.D(MinecraftServer.java:726) [Spigot.jar:git-Spigot-798f32d-0cd0397]
            at net.minecraft.server.v1_9_R2.DedicatedServer.D(DedicatedServer.java:399) [Spigot.jar:git-Spigot-798f32d-0cd0397]
            at net.minecraft.server.v1_9_R2.MinecraftServer.C(MinecraftServer.java:665) [Spigot.jar:git-Spigot-798f32d-0cd0397]
            at net.minecraft.server.v1_9_R2.MinecraftServer.run(MinecraftServer.java:564) [Spigot.jar:git-Spigot-798f32d-0cd0397]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_92]
    Caused by: java.lang.NullPointerException
            at com.fireboyev.soulspawners.event.SoulTake.OnPlayerInteract(SoulTake.java:27) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_92]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[Spigot.jar:git-Spigot-798f32d-0cd0397]
            ... 17 more
    >
    it did this before even when it was working
     
  12. Offline

    Zombie_Striker

    The issue is something on this line is null. Let's go through each of the variables and say whether a variable can be null.:
    1. ChatColor cannot be null
    2. translateAlt cannot be null.
    3. The '&' cannot be null.
    4. Plugin can be null.
    5. the comfig cannot be null.
    6. the string at "prefix" can be null.
    Go through everything that can be null, and null check. If it is null, set it equal to something.
     
  13. Offline

    fireboyev

    After a little testing, I found out what the null is. The problem is in getting the config
    Code:
    String pluginprefix = plugin.getConfig().getString("prefix");
    sooo, how to I fix it?

    -EDIT-

    Fixed it myself, Thanks for all your help ZombieStriker! :)
     
    Last edited: Jun 22, 2016
Thread Status:
Not open for further replies.

Share This Page