Solved Any one can Help me my GodMode not Work...

Discussion in 'Spigot Plugin Development' started by Keybax, Jan 7, 2019.

  1. i need help ... i dont find my fail...my GodMod dosent work


    Code (Java):
    package de.SoproII.LamaCraftCBSystem.Addon.CB.Befehle;



    import org.bukkit.entity.Player;

    import de.SoproII.LamaCraftCBSystem.Addon.CB.main.Main;

    import java.util.ArrayList;

    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;

    public class SoproII_GodMod implements CommandExecutor
    {
        public static ArrayList<String> god;
       
        static {
            SoproII_GodMod.god = new ArrayList<String>();
        }
       
        public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
            if (sender instanceof Player) {
                final Player p = (Player)sender;
                if (p.hasPermission("lama.god")) {
                    if (args.length == 0) {
                        if (SoproII_GodMod.god.contains(p.getName())) {
                            SoproII_GodMod.god.remove(p.getName());
                            p.sendMessage(String.valueOf(Main.prefix) + "Du bist §cnicht §7mehr im §bGod §7Modus");
                        }
                        else {
                            SoproII_GodMod.god.add(p.getName());
                            p.sendMessage(String.valueOf(Main.prefix) + "Du bist §anun §7im §bGod §7Modus");
                        }
                    }
                    else if (args.length == 1) {
                        final Player target = Bukkit.getPlayer(args[0]);
                        if (p.hasPermission("lama.god.others")) {
                            if (target != null) {
                                if (target != p) {
                                    if (SoproII_GodMod.god.contains(target.getName())) {
                                        SoproII_GodMod.god.remove(target.getName());
                                        p.sendMessage(String.valueOf(Main.prefix) + "Du hast §b" + target.getName() + " §7den God Modus §causgeschaltet");
                                        target.sendMessage(String.valueOf(Main.prefix) + "Du bist §cnicht §7mehr im §bGod §7Modus");
                                    }
                                    else {
                                        SoproII_GodMod.god.add(target.getName());
                                        p.sendMessage(String.valueOf(Main.prefix) + "Du hast §b" + target.getName() + " §7den God Modus §aangeschaltet");
                                        target.sendMessage(String.valueOf(Main.prefix) + "Du bist §anun §7im §bGod §7Modus");
                                    }
                                }
                                else {
                                    p.sendMessage(String.valueOf(Main.prefix) + "§cDu kannst nicht mit dir selbst interagieren");
                                }
                            }
                            else {
                                p.sendMessage("§c§lDer Spieler ist nicht Online");
                            }
                        }
                        else {
                            p.sendMessage(Main.NoPerm);
                        }
                    }
                    else {
                        p.sendMessage(String.valueOf(Main.prefix) + "Bitte benutze §e/God §b[Spieler]");
                    }
                }
                else {
                    p.sendMessage(Main.NoPerm);
                }
            }
            else {
                sender.sendMessage("§c§lDu bist kein Spieler");
            }
            return false;
        }
    }
     
     
  2. no command label...?
     
  3. No need to check for what command it is if the class is responsible for only one command.
    Would you mind actually explaining what's wrong? Doesn't work isn't enough...
     
  4. Wasn't saying that it's the source, i was just confused, nvm lmao
     
  5. [QUOTE = "PsionicPvP, Beitrag: 3276185, Mitglied: 325146"] Keine Befehlsbezeichnung ...? [/ QUOTE]
    istin the Main Class
     
  6. [QUOTE = "Shin1gamiX, Beitrag: 3276189, member: 603967"] Sie müssen nicht prüfen, um welchen Befehl es sich handelt, wenn die Klasse nur für einen Befehl verantwortlich ist.

    Würde es Ihnen etwas ausmachen zu erklären, was falsch ist? Funktioniert nicht genug ... [/ QUOTE]


    ich idk.. i use the command /god name the Message is korrekt and i am no in god mode.. monster, player, fall dmg all can kill me ..
     
  7. here is the text in english so you can see the text on off and more



    Code (Java):
    package de.SoproII.LamaCraftCBSystem.Addon.CB.Befehle;



    import org.bukkit.entity.Player;

    import de.SoproII.LamaCraftCBSystem.Addon.CB.main.Main;

    import java.util.ArrayList;

    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;

    public class SoproII_GodMod implements CommandExecutor
    {
        public static ArrayList<String> god;
       
        static {
            SoproII_GodMod.god = new ArrayList<String>();
        }
       
        public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
            if (sender instanceof Player) {
                final Player p = (Player)sender;
                if (p.hasPermission("lama.god")) {
                    if (args.length == 0) {
                        if (SoproII_GodMod.god.contains(p.getName())) {
                            SoproII_GodMod.god.remove(p.getName());
                            p.sendMessage(String.valueOf(Main.prefix) + "you are not more in GodMode");
                        }
                        else {
                            SoproII_GodMod.god.add(p.getName());
                            p.sendMessage(String.valueOf(Main.prefix) + "You are now in GodMode");
                        }
                    }
                    else if (args.length == 1) {
                        final Player target = Bukkit.getPlayer(args[0]);
                        if (p.hasPermission("lama.god.others")) {
                            if (target != null) {
                                if (target != p) {
                                    if (SoproII_GodMod.god.contains(target.getName())) {
                                        SoproII_GodMod.god.remove(target.getName());
                                        p.sendMessage(String.valueOf(Main.prefix) + "you have for §b" + target.getName() + " §7Make god mode OFF");
                                        target.sendMessage(String.valueOf(Main.prefix) + "God Mod OFF");
                                    }
                                    else {
                                        SoproII_GodMod.god.add(target.getName());
                                        p.sendMessage(String.valueOf(Main.prefix) + "you have for§b" + target.getName() + " §7Make god mode ON");
                                        target.sendMessage(String.valueOf(Main.prefix) + "God Mode ON");
                                    }
                                }
                                else {
                                    p.sendMessage(String.valueOf(Main.prefix) + "§cwhy you use your name for your self ?");
                                }
                            }
                            else {
                                p.sendMessage("§c§lDPlayer is not Online");
                            }
                        }
                        else {
                            p.sendMessage(Main.NoPerm);
                        }
                    }
                    else {
                        p.sendMessage(String.valueOf(Main.prefix) + "fail command use §e/God §b[Spieler]");
                    }
                }
                else {
                    p.sendMessage(Main.NoPerm);
                }
            }
            else {
                sender.sendMessage("§c§lyou are not a player");
            }
            return false;
        }
    }
     
     
  8. What doesn't work?
     
  9. Well, simply being in a collection doesn't make you invulnerable. You'll have to listen to EntityDamagEvent, check if the entity is a player and if they are inside the collection. If true, prevent them from taking damage.

    Here's a link on a resource that has it's code shared. The author was doing a challenge of 50 lines.

    Code (Java):
    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.*;

    /*
    For anyone reading this, implementing CommandExecutor on a class
    that extends JavaPlugin is unnecessary as JavaPlugin makes up for that.
    */

    public class GodMode extends JavaPlugin implements CommandExecutor, Listener {
      private static List<Player> GODS = new ArrayList<>();
      @Override
      public void onEnable() {
        getCommand("god").setExecutor(this); // This is Shin1gamiX, this one is unnecessary, for anyone reading 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());
      }
    }
    Perhaps it may help. Resource found here.
     
    • Like Like x 1


  10. AHHH Thanks ! :D