Help With God Mode

Discussion in 'Plugin Development' started by IcyRelic, Mar 18, 2012.

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

    IcyRelic

    how would i create a god mode

    here is what i have so far
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player player = (Player) sender;
            String title = ("[" + ChatColor.GOLD + "Legendary Essentials" + ChatColor.WHITE +  "] ");
           
            if (cmd.getName().equalsIgnoreCase("god") && sender.isOp()) {
               
            }
    }
     
  2. Offline

    Usche

    jeeez... normally a programmer uses his own brain, instead of others...

    get the Player and save him to a HashMap or Smth. Create Listener for the getDamageEvent - look if the Player is in Godmode and than cancel the event....
     
    dillyg10 likes this.
  3. Offline

    Iron_Crystal

    If you don't know the syntax of that, it would probably something like this:

    Code:Java
    1. public class GodMode implements Listener
    2. {
    3. public static NameOfMainPlugin plugin;
    4. public GodMode(NameOfMainPlugin instance)
    5. {
    6. plugin = instance;
    7. }
    8.  
    9. @EventHandler
    10. public void onPlayerDamageEvent (EntityDamageEvent event)
    11. {
    12. Entity entity = event.getEntity();
    13. if (entity instanceof Player)
    14. {
    15. if statement //check if player is in god mode
    16. {
    17. event.isCancelled(true);
    18. }
    19. }
    20. }
    21. }
     
  4. Offline

    IcyRelic

    here is what i have now

    Code:
    package me.icyrelic.com;
     
     
     
     
    import java.util.HashSet;
    import java.util.Set;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class LegendaryEssentials extends JavaPlugin{
        private final Set<String> hasGodMode = new HashSet<String>();
     
     
        @Override
        public void onDisable() {
           
        }
     
        @Override
        public void onEnable() {
        }
       
        @EventHandler
     
        public void onPlayerDamageEvent (EntityDamageEvent event)
     
        {
     
            Entity entity = event.getEntity();
     
            if (entity instanceof Player)
     
            {
                Player player = (Player) event.getEntity();
     
                if(hasGodMode.contains(player.getName()) == true)
     
                {
     
                    event.setCancelled(true);
     
                }
     
            }
     
        }
     
     
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player player = (Player) sender;
            String title = ("[" + ChatColor.GOLD + "Legendary Essentials" + ChatColor.WHITE +  "] ");
           
            if (cmd.getName().equalsIgnoreCase("god") && sender.isOp()) {
                if(hasGodMode.contains(player.getName()) == true){
                    hasGodMode.remove(player.getName());
                    player.sendMessage(title + "Godmode Disabled!");
                }else{
                    hasGodMode.add(player.getName());
                    player.sendMessage(title + "Godmode Enabled!");
                }
            }
     
    }
    }
    and it doesnt work
     
  5. Offline

    Iron_Crystal

    can you show the error?

    Edit: You have your listener in the same class.
     
  6. Offline

    Usche

  7. Offline

    Taco

    Check the source for GodPowers in my signature. You'll need to dig around to figure it out, but I'm not going to write the code for you, so base yours off what you can find.
     
Thread Status:
Not open for further replies.

Share This Page