Solved God-Command

Discussion in 'Plugin Development' started by EnveRuleZZ, Jan 30, 2015.

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

    EnveRuleZZ

    Hey guys, unfortunately I'm back here again haha...So basically I want to make a God-Command. I tried everything but it just won't work. If god mode is enabled, the player still loses health...Yes, I registered my events :D My code:

    Code:
    private Main plugin;
       
        public GodClass(Main plugin) {
            this.plugin = plugin;
          }
       
        String noPerm = "§4You don't have permission to do that";
        public static ArrayList<String> god = new ArrayList<String>();
    
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            if(cmd.getName().equalsIgnoreCase("god")) {
                Player p = (Player) sender;
                String usage = "§8Usage:§6 /god (<Player>)";
                if(args.length == 0) {
                    if(p.hasPermission("freebuild.god")) {
                        if(!(god.contains(p.getName()))) {
                            god.add(p.getName());
                            p.sendMessage("§8You are now in God Mode");
                        }else{
                            god.remove(p.getName());
                            p.sendMessage("§8You are no longer in God Mode");
                        }
                    }else{
                        p.sendMessage(noPerm);
                    }
                }else if(args.length == 1) {
                   
                }else{
                    p.sendMessage(usage);
                }
            }
           
           
           
           
            return false;
        }
       
        @EventHandler
        public void onDamage(EntityDamageEvent e) {
        Entity ent = e.getEntity();
        if(e instanceof Player) {
            Player p = (Player) ent;
            if(god.contains(p.getName())) {
                e.setCancelled(true);
            }
        }
        }
     
  2. @EnveRuleZZ
    • Does your command class implement CommandExecutor/Listener?
    • Does the command work in the first place?
    • Have you tried using debugging messages (sending messages to console/player)
    • Are you sure the player is in the list (print the list to see if they're there)
    These are just a bunch of basic checks that I would run if I found something not working right.
     
  3. Offline

    SuperOriginal

    Look closely
     
  4. Offline

    EnveRuleZZ

    Oooh, oops sorry I didn't see that, thank you haha my bad :D @SuperOriginal
     
    SuperOriginal likes this.
Thread Status:
Not open for further replies.

Share This Page