Plugin broken

Discussion in 'Plugin Development' started by JavaNoob, Sep 1, 2020.

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

    JavaNoob

    I have been experimenting a lot, because I think the best way to learn is to just try things. But I also don't want to give up on it.
    I have been trying to make a plugin that gives zombies different potion effects, and makes creepers powered and drop a lot of xp. The creeper part worked at first, dropping a ton of xp. But after I bumped the numbers up and I also added all the zombie potion effects, nothing worked. No creepers, no commands, no super-powered zombies. What am I doing wrong?
    Code:
    package me.nay.block;
    
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Creeper;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Zombie;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDeathEvent;
    import org.bukkit.event.entity.EntitySpawnEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    
    import io.netty.util.internal.ThreadLocalRandom;
    
    
    
    public class Main extends JavaPlugin implements Listener {
    
        @Override
        public void onEnable() {
            System.out.println("PLUGIN ENABLED");
            Bukkit.getPluginManager().registerEvents(this, this);
        }
        @Override
        public void onDisable() {
            System.out.println("PLUGIN DISABLED");
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equals("speed1")) {
                if (sender instanceof Player) {
                   
               
                    Player player = (Player) sender;
                    player.setFlySpeed((float) .20);
                }
               
            } else if (cmd.getName().equals("speed2")) {
                if (sender instanceof Player) {
                   
               
                    Player player = (Player) sender;
                    player.setFlySpeed((float) .50);
                }
            } else if (cmd.getName().equals("speed3")) {
                if (sender instanceof Player) {
                    Player player = (Player) sender;
                    player.setFlySpeed((float) 1.0);
                }
            } else {
                System.out.println("Not a valid command!");
                Player player = (Player) sender;
                player.sendMessage("Not a valid command!");
            }
           
            return false;
        }
       
    
        @EventHandler
        public void onDeath(EntityDeathEvent event) {
            if (event.getEntityType() == EntityType.CREEPER) {
                event.setDroppedExp(4000000);
               
            }
               
        }
    
        @EventHandler
        public void onSpawn(EntitySpawnEvent event) {
            if (event.getEntityType() == EntityType.CREEPER) {
               
                Creeper creeper = (Creeper) event.getEntity();
                creeper.setCanPickupItems(true);
                creeper.setPowered(true);
           
            } else if (event.getEntityType() == EntityType.ZOMBIE) {
                int x = ThreadLocalRandom.current().nextInt(1, 7);
               
                switch(x) {
                case 1:
                    Zombie zombie = (Zombie) event.getEntity();
                    zombie.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 10000, 1));
                    break;
                case 2:
                    Zombie zombie2 = (Zombie) event.getEntity();
                    zombie2.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 10000, 1000));
                    break;
                case 3:
                    Zombie zombie3 = (Zombie) event.getEntity();
                    zombie3.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 10000, 1000));
                    break;
                case 4:
                    Zombie zombie4 = (Zombie) event.getEntity();
                    zombie4.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 10000, 1000));
                    break;
                case 5:
                    Zombie zombie5 = (Zombie) event.getEntity();
                    zombie5.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 10000, 10));
                    break;
                case 6:
                    Zombie zombie6 = (Zombie) event.getEntity();
                    zombie6.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10000, 100000000));
                    break;
                case 7:
                    Zombie zombie7 = (Zombie) event.getEntity();
                    zombie7.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 10000, 10000));
                    break;
                }
               
            }
           
        }
    
    }
     
    Last edited: Sep 2, 2020
  2. Offline

    Kars

    1. You need to set the executor for that command, otherwise it will not work.
    2. I'm guessing here but dropped exp might be a short int with a max value of 32k; 4 million exceeds that.
    3. Debug your zombie event. Remove the if statements and the switch case, only add the potion effect and see if it works.
    4. Read console errors
     
  3. Offline

    timtower Administrator Administrator Moderator

    Defaults to main class, so as long as it is the main class then you don't need to set the executor.
     
  4. Offline

    JavaNoob

    Okay, I will try that, thank you. And I believe as timtower said, as long as the commands are in the same class, you do not have to set an executor.

    Edit: I have tried it with only one confirmed potion effect, and it worked. I lowered down the xp level for the creepers, and that also worked. So was my switch code messed up, or was the creeper xp exceeding the limit screwing it up?
     
    Last edited: Sep 2, 2020
Thread Status:
Not open for further replies.

Share This Page