1.15.2 Selceted Players can´t be banned

Discussion in 'Spigot Plugin Development' started by SchnellfeuerXD, May 19, 2020.

  1. Hello, Im working on a Ban Plguin and I want that the Admins cant be banned. But if I use the if statement but its not working. I wrote the names of the admins in the if statement, I want that if one of the names ist selcted that its not working. Heres my Code:

    Code (Text):

    package de.grafplaiz.bangui.events;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.ConsoleCommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.inventory.meta.ItemMeta;


    import de.grafplaiz.bangui.inventorys.BanGründe;


    public class AuswahlClickEvent implements Listener{
       
        BanGründe plugin;
        public AuswahlClickEvent(BanGründe plugin) {
            this.plugin = plugin;
        }
       

        @EventHandler
       
        public void onMenuClick(InventoryClickEvent e) {
            Player player = (Player) e.getWhoClicked();
           
            if(e.getView().getTitle().equalsIgnoreCase(ChatColor.BLUE + "Spieler Liste")) {
                e.setCancelled(true);
                if(e.getCurrentItem().getType().equals(Material.PLAYER_HEAD)) {
                    Player whoToBan = player.getServer().getPlayer(e.getCurrentItem().getItemMeta().getDisplayName());
                    plugin.openBanGründe(player, whoToBan);
                }else if (e.getCurrentItem().getType().equals(Material.BARRIER)) {
                    player.closeInventory();
                }
               
            }else if(e.getView().getTitle().equalsIgnoreCase(ChatColor.RED + "Grund: ")) {
                ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
                e.setCancelled(true);
                ItemMeta name = e.getClickedInventory().getItem(13).getItemMeta();
                switch(e.getCurrentItem().getType()) {
                case GREEN_WOOL:
                    if(name.getDisplayName() == "SchnellfeuerXD" + "Spawnnrw" + "Chris938_YT" + "GrafBastisch" + "GrafPlaiz")  {
                        player.sendMessage("§8[§4GrafBan§8] §7Du kannst keinen Admin Bannen!");
                    } else {
                        player.sendMessage("§8[§4GrafBan§8] §7Du hast " + "§c§n" + name.getDisplayName() + "§r §7einen Tag gemuted!");
                    }
                    break;
                   
                case GREEN_TERRACOTTA:
                    if(name.getDisplayName() == "SchnellfeuerXD" + "Spawnnrw" + "Chris938_YT" + "GrafBastisch" + "GrafPlaiz")  {
                        player.sendMessage("§8[§4GrafBan§8] §7Du kannst keinen Admin Bannen!");
                    } else {
                        player.sendMessage("§8[§4GrafBan§8] §7Du hast " + "§c§n" + name.getDisplayName() + "§r §7fünf Tage gemuted!");
                    }
                    break;
                   
                   
                case GREEN_CONCRETE:
                    if(name.getDisplayName() == "SchnellfeuerXD" + "Spawnnrw" + "Chris938_YT" + "GrafBastisch" + "GrafPlaiz")  {
                        player.sendMessage("§8[§4GrafBan§8] §7Du kannst keinen Admin Bannen!");
                    } else {
                        player.sendMessage("§8[§4GrafBan§8] §7Du hast " + "§c§n" + name.getDisplayName() + "§r §7sieben Tage gemuted!");
                    }
                    break;
                   
                   
                case YELLOW_WOOL:
                    if(name.getDisplayName() == "SchnellfeuerXD" + "Spawnnrw" + "Chris938_YT" + "GrafBastisch" + "GrafPlaiz")  {
                        player.sendMessage("§8[§4GrafBan§8] §7Du kannst keinen Admin Bannen!");
                    } else {
                        player.sendMessage("§8[§4GrafBan§8] §7Du hast " + "§c§n" + name.getDisplayName() + "§r §7einen Tag gebannt!");
                    }              
                    break;
                   
                   
                case YELLOW_TERRACOTTA:
                    if(name.getDisplayName() == "SchnellfeuerXD" + "Spawnnrw" + "Chris938_YT" + "GrafBastisch" + "GrafPlaiz")  {
                        player.sendMessage("§8[§4GrafBan§8] §7Du kannst keinen Admin Bannen!");
                    } else {
                        player.sendMessage("§8[§4GrafBan§8] §7Du hast " + "§c§n" + name.getDisplayName() + "§r §7fünf Tage gebannt!");
                    }              
                    break;
                   
                   
                case YELLOW_CONCRETE:
                    if(name.getDisplayName() == "SchnellfeuerXD" + "Spawnnrw" + "Chris938_YT" + "GrafBastisch" + "GrafPlaiz")  {
                        player.sendMessage("§8[§4GrafBan§8] §7Du kannst keinen Admin Bannen!");
                    } else {
                        player.sendMessage("§8[§4GrafBan§8] §7Du hast " + "§c§n" + name.getDisplayName() + "§r §7sieben Tage gebannt!");
                    }              
                    break;
                   
                   
                case RED_WOOL:
                    if(name.getDisplayName() == "SchnellfeuerXD" + "Spawnnrw" + "Chris938_YT" + "GrafBastisch" + "GrafPlaiz")  {
                        player.sendMessage("§8[§4GrafBan§8] §7Du kannst keinen Admin Bannen!");
                    } else {
                        player.sendMessage("§8[§4GrafBan§8] §7Du hast " + "§c§n" + name.getDisplayName() + "§r §7182 Tage gebannt!");
                    }              
                    break;
                   
                   
                case RED_TERRACOTTA:
                    if(name.getDisplayName() == "SchnellfeuerXD" + "Spawnnrw" + "Chris938_YT" + "GrafBastisch" + "GrafPlaiz")  {
                        player.sendMessage("§8[§4GrafBan§8] §7Du kannst keinen Admin Bannen!");
                    } else {
                        player.sendMessage("§8[§4GrafBan§8] §7Du hast " + "§c§n" + name.getDisplayName() + "§r §7365 Tage gebannt!");
                    }      
                    break;
                   
                   
                case RED_CONCRETE:
                    if(name.getDisplayName() == "SchnellfeuerXD" + "Spawnnrw" + "Chris938_YT" + "GrafBastisch" + "GrafPlaiz")  {
                        player.sendMessage("§8[§4GrafBan§8] §7Du kannst keinen Admin Bannen!");
                    } else {
                        player.sendMessage("§8[§4GrafBan§8] §7Du hast " + "§c§n" + name.getDisplayName() + "§r§7 " + "§c§n§lPERMANET" + "§r§7 "+ "§r§7gebannt!");
                    }
                    break;
                   
                   
                case STRUCTURE_VOID:
                    player.sendMessage("§8[§4GrafBan§8] §7Du hast " + "§c§n" + name.getDisplayName() + "§r §7Sicherheits gebannt, bitte informiere " + "§c§nSOFORT" + "§r §7einen Admin!");
                    break;
                   
                   
                case BARRIER:
                    player.closeInventory();
                    break;
                   
                   
                default:
                    break;
                }
            }
           
        }

    }

     
    Maybe you can help me!
     
  2. Using the + operator like that means that you are checking if the name of the item is all of their names together, you need to do separate checks for each string

    atm you are checking if the items name is SchnellfeuerXDSpawnnrwChris938_YTGrafBastischGrafPlaiz
     
  3. Thank you I`ll trie that
     
  4. Its still not working mybe bebause name is an Item meta?
     
  5. Try using equals() instead of ==
     
  6. You MUST always use String.equals() when you want to compare strings