Godmode bug ( My fault )

Discussion in 'Plugin Development' started by kreashenz, Mar 30, 2013.

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

    kreashenz

    I may have posted a couple things about god mode, but I still CAN'T GET IT!!!! I've tried 4 different events, cancelled them all, done this and that, and yet only one of them works, but not even completely.. What this one does, is cancels the event ONE time.. I am godmode for 1 hit, and then it removes.. I got no idea what the hell this is, or how it was caused.. Please help me.. Thanks :)
    Code:
    package me.kreashenz.minecraftrp.Commands;
     
    import java.util.ArrayList;
     
    import me.kreashenz.minecraftrp.MCRP;
    import me.kreashenz.minecraftrp.Utilities.Functions;
     
    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.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent;
     
    public class God implements CommandExecutor, Listener {
     
        ArrayList<String> godmode = new ArrayList<String>();
     
        public MCRP plugin;
        public God(MCRP plugin){this.plugin=plugin;}
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(cmd.getName().equalsIgnoreCase("god")){
                if(sender instanceof Player){
                    if(sender.hasPermission("mcrp.god")){
                        if (godmode.contains(sender.getName()))
                        {
                            sender.sendMessage("§cGod mode §6disabled§c.");
                            godmode.remove(sender.getName());
                        } else {
                            sender.sendMessage("§cGod mode §6enabled§c.");
                            godmode.add(sender.getName());
                        }
                    } else sender.sendMessage(Functions.noPerm());
                } else sender.sendMessage("§cYou must be a player to use this command.");
            }
            return true;
        }
     
        @EventHandler(priority = EventPriority.MONITOR)
        public void onGodMode(EntityDamageEvent e){
            if (e.getEntity() instanceof Player){
                Player p = (Player) e.getEntity();            
                if (!godmode.contains(p.getName())){
                    godmode.add(p.getName());
                    e.setCancelled(true);
                } else godmode.remove(p.getName());
            }
        }
        // This part is blocked off, because I was testing.
        /*       
        @EventHandler(priority = EventPriority.MONITOR)
        public void onGodModeCheck(EntityDamageByEntityEvent e){
            if (e.getEntity() instanceof Player){
                Player p = (Player) e.getEntity();            
                if (!godmode.contains(p.getName())){
                    e.setCancelled(true);
                    godmode.add(p.getName());
                } else godmode.remove(p.getName());
            }
        }
         */
    }
     
  2. Offline

    jorisk322

    You're checking if the player is not in the list. If he's not in the list, you add him to the list, and cancel the damage. When the player IS in the list, you remove him from it. Why?
     
  3. Offline

    hockeygoalie5

    Use highest priority, not monitor. Monitor should not change the event. Also, it looks like your listener just gives someone god mode if they don't have it, and removes it if they do. Try this in your listener:
    Code:
    if(godmode.contains(p.getName())) {
        e.setCancelled(true);
    }
    
     
  4. Offline

    kreashenz

    jorisk322 hockeygoalie5 I added that part if hes on the list, then remove, because I'm stupid, and I thought that if they typed it again, it would remove them.
    [EDIT] And now its COMPLETELY stopped working. This is what I mean, you do one thing, and it stops it, you do another thing, it works, but 1 time.. Confusing as hell.

    Also, were you talking about the command, or the event, because I just realized.. Haha

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  5. Offline

    jorisk322

    The event
     
  6. Offline

    ConflictRealms

    Code:
     
      @EventHandler(priority = EventPriority.HIGHEST)
        public void onGodMode(EntityDamageEvent e){
            if (e.getEntity() instanceof Player){
                Player p = (Player) e.getEntity();           
                if (godmode.contains(p.getName())){
                    e.setCancelled(true);
                } 
            }
        }
    I would check more then 1 event. Theirs a couple you will needa cancell
     
  7. Offline

    kreashenz

  8. Offline

    ZeusAllMighty11

    When I give a user godmode, I use 1 line of code
    Code:
    player.setNoDamageTicks(9999999999);
    
     
  9. Offline

    kreashenz

    ZeusAllMighty11 AHAHA! Fair enough, I guess I could use that for a while.. What if the time runs out, the player will be removed from god mode, how do I keep them permanently in godmode.. Should I use </> for it?
     
  10. Offline

    SugarCraft

    What about looping it every 9999999999 seconds
     
  11. Offline

    kreashenz

    Yeah, I don't know how to loop seconds.. Lol! I know some of the hard stuff, but none of the easy stuff.. Pretty stupid. I learnt Arrays before I learnt HashMaps :)
     
  12. Offline

    ZeusAllMighty11

    Just everytime they log in or out, set it again... :p ?
     
  13. Offline

    kreashenz

    ZeusAllMighty11 Could I use an if statement, so if the timer goes under (say) 20, it just sets back to 20?

    ZeusAllMighty11 New code :
    Code:java
    1. package me.kreashenz.minecraftrp.Commands;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import me.kreashenz.minecraftrp.MCRP;
    6. import me.kreashenz.minecraftrp.Utilities.Functions;
    7.  
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandExecutor;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.Listener;
    13.  
    14. public class God implements CommandExecutor, Listener {
    15.  
    16. ArrayList<String> godmode = new ArrayList<String>();
    17.  
    18. public MCRP plugin;
    19. public God(MCRP plugin){this.plugin=plugin;}
    20. @Override
    21. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    22. Player player = (Player)sender;
    23. if(cmd.getName().equalsIgnoreCase("god")){
    24. if(sender instanceof Player){
    25. if(sender.hasPermission("mcrp.god")){
    26. if (godmode.contains(sender.getName())){
    27. if(player.getNoDamageTicks() < 20){
    28. player.setNoDamageTicks(999999999);
    29. }
    30. sender.sendMessage(Functions.getPrefix() + "§cGod mode §6disabled§c.");
    31. godmode.remove(sender.getName());
    32. } else {
    33. if(player.getNoDamageTicks() > 1){
    34. player.setNoDamageTicks(0);
    35. }
    36. sender.sendMessage(Functions.getPrefix() + "§cGod mode §6enabled§c.");
    37. godmode.add(sender.getName());
    38. }
    39. } else sender.sendMessage(Functions.noPerm());
    40. } else sender.sendMessage("§cYou must be a player to use this command.");
    41. }
    42. return true;
    43. }
    44. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  14. Offline

    ZeusAllMighty11

    You mixed up enabled and disabled but sure
     
Thread Status:
Not open for further replies.

Share This Page