COMMANDS NOT WORKING

Discussion in 'Spigot Plugin Development' started by UnlimitedNinjas, Jun 24, 2018.

  1. recently command without args wouldnt work, but now even this doesnt heres code:

    plugin.yml:
    Code (Text):
    name: SuperBlocks
    main: me.thesilentpro.net.Main
    version: 5.0
    commands:
      wakeup:
        usage: /<wakeup> <player>
        description: Wake someone up...
      uuid:
        usage: /<command> <player>
        description: Get the uuid of a player.
        aliases: [finduuid, uuidfind]
      ip:
        usage: /<command> <player>
        description: Get the ip of a player.
        aliases: [address, ipaddress]
      find:
        usage: /<command> <player>
        description: Find in what player someone is.
        aliases: [whereis, findplayer]
      doom:
        usage: /<command> <player>
        description: Used to ban admins.
      smite:
        usage: /<command> <player> <reason>
        description: Smite a player.
        aliases: [s]
      entitywipe:
        usage: /<command>
        description: Wipe entities in the world you are in.
        aliases: [ew]
      overlord:
        usage: /<command>
        description: Enable/Disable overlord mode.
        aliases: [ovmode, ov]
      emoji:
        usage: /<command>
        description: List of emojis
        aliases: [emojilist]
      launch:
        usage: /<command> <player>
        description: Launch a player.
        aliases: [l]
      drop:
        usage: /<command> <player>
        description: Drop a player from a high place.
        aliases: [d]
      spreload:
        usage: /<command>
        description: Reload the config
        aliases: [sprl]
      gcast:
        usage: /<command> <message>
        description: Gcast a message
        aliases: [gc]
      schat:
        usage: /<command> <message>
        description: Send a message to the staffchat
        aliases: [spchat, sc]
      freeze:
        usage: /<command> <player> <reason>
        description: Freeze a player.
        aliases: [f]
      expel:
        usage: /<command>
        description: Push nearby players away.
        aliases: [e]
    permissions:
      sp.notify:
        default: op
      sp.f:
        default: op
      sp.wakeup:
        default: op
      sp.uuid:
        default: op
      sp.address:
        default: op
      sp.find:
        default: op
      sp.wcast:
        default: op
      sp.scast:
        default: op
      sp.drop:
        default: op
      sp.launch:
        default: op
      sp.reload:
        default: op
      sp.gcast:
        default: op
      sp.staffchat:
        default: op
    freeze class:
    Code (Text):
    package me.thesilentpro.net.commands;

    import java.util.ArrayList;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerMoveEvent;

    public class Freeze implements CommandExecutor {
       
       
        ArrayList<String> frozen = new ArrayList<String>();
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String lable, String args[]) {
            if (sender instanceof Player) {
                Player p = (Player) sender;
                if (p.hasPermission("sp.freeze")) {
                    if (args.length == 1) {
                        Player target = Bukkit.getServer().getPlayer(args[0]);
                        if (frozen.contains(target.getName())) {
                            frozen.remove(target.getName());
                            p.sendMessage(ChatColor.GREEN + target.getName() + " has been unfrozen!");
                            for (Player admin : Bukkit.getServer().getOnlinePlayers()) {
                                if (admin.hasPermission("sp.notify")) {
                                    admin.sendMessage(ChatColor.GREEN + target.getName() + " has been unfrozen by " + p.getName());
                                }
                            }
                        }else {
                            frozen.add(target.getName());
                            p.sendMessage(ChatColor.RED + target.getName() + " is now frozen!");
                            for (Player admin : Bukkit.getServer().getOnlinePlayers()) {
                                if (admin.hasPermission("sp.notify")) {
                                    admin.sendMessage(ChatColor.RED + target.getName() + " has been frozen by " + p.getName());
                                }
                            }
                        }
                    }
                    if (args.length >= 2) {
                        String reason = "";
                        int x = 0;
                        for (String a : args) {
                            if (x == 0) {
                                x++;
                                continue;
                            }
                            reason = reason + " " + a;
                        }
                        reason = reason.trim();
                        Player target = Bukkit.getServer().getPlayer(args[0]);
                        if (frozen.contains(target.getName())) {
                            frozen.remove(target.getName());
                            p.sendMessage(ChatColor.GREEN + target.getName() + " has been unfrozen!");
                            for (Player admin : Bukkit.getServer().getOnlinePlayers()) {
                                if (admin.hasPermission("sp.notify")) {
                                    admin.sendMessage(ChatColor.GREEN + target.getName() + " has been unfrozen by " + p.getName());
                                }
                            }
                        }else {
                            frozen.add(target.getName());
                            p.sendMessage(ChatColor.RED + target.getName() + " has been frozen for " + ChatColor.DARK_RED + reason);
                            for (Player admin : Bukkit.getServer().getOnlinePlayers()) {
                                if (admin.hasPermission("sp.notify")) {
                                    admin.sendMessage(ChatColor.RED + target.getName() + " has been frozen by " + p.getName());
                                    admin.sendMessage(ChatColor.RED + "Reason: " + ChatColor.YELLOW + reason);
                                }
                            }
                        }
                    }else {
                        p.sendMessage(ChatColor.RED + "Usage: /freeze <player> {reason}");
                    }
                }else {
                    p.sendMessage(ChatColor.RED + "No permission!");
                }
            }
            return true;
        }
       
        @EventHandler
        public void onMove(PlayerMoveEvent e) {
            if (frozen.contains(e.getPlayer().getName())) {
                e.setCancelled(true);
                e.getPlayer().sendMessage(ChatColor.RED + "You are frozen!");
            }
        }
       
        @EventHandler
        public void onInteract(PlayerInteractEvent e) {
            if (frozen.contains(e.getPlayer().getName())) {
                e.setCancelled(true);
                e.getPlayer().sendMessage(ChatColor.RED + "You are frozen!");
            }
        }
       
        @EventHandler
        public void onBreak(BlockBreakEvent e) {
            if (frozen.contains(e.getPlayer().getName())) {
                e.setCancelled(true);
                e.getPlayer().sendMessage(ChatColor.RED + "You are frozen!");
            }
        }
       
        @EventHandler
        public void onPlace(BlockPlaceEvent e) {
            if (frozen.contains(e.getPlayer().getName())) {
                e.setCancelled(true);
                e.getPlayer().sendMessage(ChatColor.RED + "You are frozen!");
            }
        }

    }
    main
    Code (Text):
    public class Main extends JavaPlugin implements Listener, CommandExecutor {
       
        private final static Pattern ipPattern = Pattern.compile("([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])");
       
        public String cc(String msg) {
            return ChatColor.translateAlternateColorCodes('&', msg);
        }
       
        public static Main plugin;
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            sender.sendMessage("Unregistered, please contact an admin!");
            return true;
        }
       
        public void onEnable(){

              getConfig().options().copyDefaults(true);
                saveDefaultConfig();
                Bukkit.getServer().getPluginManager().registerEvents(this, this);
                plugin = this;
                getCommand("wakeup").setExecutor(new Wakeup());
                getCommand("uuid").setExecutor(new UUID());
                getCommand("ip").setExecutor(new Address());
                getCommand("find").setExecutor(new Find());
                getCommand("doom").setExecutor(new Doom());
                getCommand("schat").setExecutor(new Staffchat());
                getCommand("smite").setExecutor(new Smite());
                getCommand("drop").setExecutor(new Drop());
                getCommand("gcast").setExecutor(new Gcast());
                getCommand("launch").setExecutor(new Launch());
                getCommand("spreload").setExecutor(new Reload());
                getCommand("alert").setExecutor(new Alert());
                getCommand("entitywipe").setExecutor(new Entitywipe());
                getCommand("overlord").setExecutor(new Overlord());
                getCommand("emojis").setExecutor(new Emoji());
                getCommand("freeze").setExecutor(new Freeze());;
                getCommand("expel").setExecutor(new Expel());

            }
         
            public void onDisable() {
                saveDefaultConfig();
            }
    they dont return any errors just the unregister command from main class
     
  2. (offtopic) use if (not) statements instead (if (!p.hasPermission){return;}
    Code (Text):
    if (!(sender instanceof Player)) {
    return;
    }
     
  3. Someone is gonna get mad, but I'm gonna tell you: Learn Java. All the resources you published are just a result of the code that lots of us sent you when you posted your questions(literally you posted 5 times a thread called commands not working). In this way you don't learn anything and you start to depend on us. What's the point?
     
    • Agree Agree x 2
    • Winner Winner x 2
  4. Hoping to see an answer from him
    Ya, I'm too optimistic
     
  5. Anyways, you forgot author: in the plugin.yml
    Code (Text):
    main: yourmainclasshere
    version: 1.2
    author: Falcon_Seeker
    name: CoolPlugin
     
  6. He's not really the author so...
     
    • Funny Funny x 2
  7. So you saying that i steal the code?
    well help me then, in those "5 posts" you didnt help me, at least try
     
  8. First of all I'm not saying you steal code as in the moment someone gives it to you in this forums everyone can use it. Also I helped tons of people (600 messages and 100 ratings), but I'm not gonna help someone who has never learnt Java and posts resources literally copying the code that someone gave him. There isn't a line in your plug-ins that was made by you
     
    • Like Like x 1
  9. I am TheSilentPro!!!!!!
     
  10. Can you please read what I wrote thx
     
  11. Yes, as people have said above, learning Java is mandatory for using Spigot. If you don't understand Java, you won't understand a thing you are doing. I've noticed lots of mistakes in the code you have that could call NullPointerExceptions and many beginner mistakes.
     
  12. Point them out pls?
     
  13. you didn't register your class Freeze for the event handler, so your methods like:

    @EventHandler
    public void onInteract(PlayerInteractEvent e) {

    etc.. won't work

    Freeze class has to implements Listener interface also you should register Freeze on the enable method, something like: Bukkit.getServer().getPluginManager().registerEvents(this, new Freeze() );

    Remember: each class that has an @EventHandler should be registered as Listener on onEnable method of the main class

    i haven't looked all the code so there may be other errors, goodluck
     
  14. Take a few minutes and read your code, where do you think a NullPointerException would be thrown. Also take a look at your package name, then look at the Java Naming Conventions.