GodMode 1.0.2

This was created as a part of 50 line challenge to implement GodMode.

  1. vk2gpz
    This plugin was create as a part of 50 lines challenge. It simply implements GodMode (/god).

    Code (Text):

    package com.vk2gpz.godmode;

    import org.bukkit.command.*;
    import org.bukkit.entity.Player;
    import org.bukkit.event.*;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.player.*;
    import org.bukkit.plugin.java.JavaPlugin;
    import java.util.*;

    public class GodMode extends JavaPlugin implements CommandExecutor, Listener {
      private static List<Player> GODS = new ArrayList<>();
      @Override
      public void onEnable() {
        getCommand("god").setExecutor(this);
        getServer().getPluginManager().registerEvents(this, this);
      }
      @Override
      public boolean onCommand(CommandSender s, Command c, String l, String[] a) {
        if (s instanceof Player && s.hasPermission("godmode.use")) {
          boolean b = (GODS.contains(((Player)s))) ? GODS.remove((Player)s) : GODS.add((Player)s);
          s.sendMessage("§6God mode §c" + (GODS.contains((Player)s) ? "enabled" : "disabled") + "§6.");
        }
        return true;
      }
      @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled=false)
      public void onDamage(EntityDamageEvent e) {
        if (e.getEntity() instanceof Player && GODS.contains(e.getEntity())) {
          e.setCancelled(true);
          ((Player) e.getEntity()).setHealth(((Player) e.getEntity()).getMaxHealth());
        }
      }
      @EventHandler
      public void onJoin(PlayerJoinEvent e) {
        GODS.remove(e.getPlayer());
      }
      @EventHandler
      public void onLeave(PlayerQuitEvent e) {
        GODS.remove(e.getPlayer());
      }
    }
     
    Ducki0210, iErqnYT, Chalwk and 4 others like this.

Recent Updates

  1. made it shorter.
  2. refactored.

Recent Reviews

  1. SincerelyFaust
    SincerelyFaust
    4/5,
    Version: 1.0.2
    Works for 1.13.1, I would only suggest adding /godall for enabling godmode for everyone in server, also /god <name> so we can turn on god for someone else that doesn't have permission and disabling hunger while in godmode.
  2. NamerPRO
    NamerPRO
    5/5,
    Version: 1.0.2
    If I were you, I'd remove this:

    @EventHandler
    public void onJoin(PlayerJoinEvent e) {
    GODS.remove(e.getPlayer());
    }
    @EventHandler
    public void onLeave(PlayerQuitEvent e) {
    GODS.remove(e.getPlayer());
    }
  3. Djmadzik
    Djmadzik
    5/5,
    Version: 1.0.2
    work perfect, plz if you can add mc.worldofpixium.com like server use your plugin it will be really appreciate, thx ^^