Please Help me with an EggThrowEvent CMD | Command

Discussion in 'Plugin Development' started by Asaster, Oct 16, 2020.

  1. Offline

    Asaster

    Hello!
    I wanna write a funny CMD for my Server but it does not work out ;(
    It is supposed to enable / disable an EggThrowEvent with which you can spawn many entities with.
    I appreciate the help!

    The code:
    Code:
    package de.asaster.system.commands;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.*;
    import org.bukkit.event.player.PlayerEggThrowEvent;
    
    public class egg_cmd implements CommandExecutor {
    
        public boolean eventOn;
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    
            Player p = (Player) sender;
    
            if (sender instanceof Player) {
                if (p.hasPermission("perm.chicken")) {
    
                    if (args.length == 1) {
    
                        if (args[0].equalsIgnoreCase("on")) {
                            eventOn = true;
    
                        } else if (args[0].equalsIgnoreCase("off")) {
                            eventOn = false;
    
                        }
                    } else if (args.length < 1) {
                        p.sendMessage("use /egg <on> <off>");
    
                    } else if (args.length > 1) {
                        p.sendMessage("use /egg <on> <off>");
    
                    }
                }
    
            } else {
    
                sender.sendMessage("this is an in-game CMD");
    
            }
    
            return false;
    
        }
    
        @EventHandler
        public boolean onEvent(PlayerEggThrowEvent e) {
            Player p = e.getPlayer();
            if (p.hasPermission("server.vollidiot")) {
                e.setHatching(true);
                e.setNumHatches((byte) 20);
                e.setHatchingType(EntityType.CHICKEN);
    
            }
            if (eventOn == true) {
    
                return true;
            } else if (eventOn == false) {
    
                return false;
            }
            return eventOn;
    
        }
    
    }
     
    Last edited by a moderator: Oct 17, 2020
  2. Online

    timtower Moderator Moderator

    @Asaster You did not register the listener.
    Nor do eventlisteners return something.
     

Share This Page