Lobbyswitchertool problems with settings up Inventory

Discussion in 'Spigot Plugin Development' started by dmmk218, Mar 17, 2019.

  1. Hey everybody,

    so I'm actually fronting a problem with my Inventory setting up.

    I've setup an PluginMessagingChannel to communicate with BungeeCord works pretty fine and it was easy to understand for me. But now I'm fronting a problem what nearly drives me crazy. I've double checked all these statements. So here is my code I've got so far:

    Code (Java):
    @EventHandler
        public static void onAsyncChatEvent(AsyncPlayerChatEvent e) {
            if (e.getMessage().toLowerCase().equals("#showserver")) {
                CalculateLobbyServer.getServer(e.getPlayer());
                Bukkit.getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() {
                   
                    @Override
                    public void run() {
                        e.getPlayer().sendMessage(Main.serverName);
                    }
                }, 40L);
            }
            if (e.getMessage().toLowerCase().equals("#conserver")) {
                e.getPlayer().sendMessage(yswitch.getString("L5.Server"));
            }
        }
       
        @EventHandler
        public static void onPlayerJoin(PlayerJoinEvent e) {
           
            CalculateLobbyServer.getServer(e.getPlayer());
           
            String serverName = Main.serverName;
           
            String configServer1 = yswitch.getString("L1.Server");
            String configServer2 = yswitch.getString("L2.Server");
            String configServer3 = yswitch.getString("L3.Server");
            String configServer4 = yswitch.getString("L4.Server");
            String configServer5 = yswitch.getString("L5.Server");
           
            if (serverName.equals(configServer5)) {
                System.out.println("EventFired Match");
            }
           
            Bukkit.getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() {
               
                @Override
                public void run() {
                   
                    if (yswitch.getBoolean("L1.hide") == false) {
                        if (configServer1.equalsIgnoreCase(serverName)) {
                            String nameToTranslate1 = yswitch.getString("L1.Name");
                            String nameColored1 = ChatColor.translateAlternateColorCodes('&', nameToTranslate1);
                            switcherInv.setItem(yswitch.getInt("L1.Slot"), createIs(nameColored1, Material.INK_SACK, yswitch.getString("L1.LoreC"), yswitch.getInt("L1.Stacksize"), (short) 1));
                            System.out.println("EventFired L1");
                            return;
                        }
                        if (!(configServer1.equalsIgnoreCase(serverName))) {
                            String nameToTranslate1 = yswitch.getString("L1.Name");
                            String nameColored1 = ChatColor.translateAlternateColorCodes('&', nameToTranslate1);
                            switcherInv.setItem(yswitch.getInt("L1.Slot"), createIs(nameColored1, Material.INK_SACK, yswitch.getString("L1.Lore"), yswitch.getInt("L1.Stacksize"), (short) 10));
                            System.out.println("EventFired L1 - 2");
                        }
                    }
                    if (yswitch.getBoolean("L2.hide") == false) {
                        if (configServer2.equalsIgnoreCase(serverName)) {
                            String nameToTranslate2 = yswitch.getString("L2.Name");
                            String nameColored2 = ChatColor.translateAlternateColorCodes('&', nameToTranslate2);
                            switcherInv.setItem(yswitch.getInt("L2.Slot"), createIs(nameColored2, Material.INK_SACK, yswitch.getString("L2.LoreC"), yswitch.getInt("L2.Stacksize"), (short) 1));
                            System.out.println("EventFired L2");
                            return;
                        }
                        if (!(configServer2.equalsIgnoreCase(serverName))) {
                            String nameToTranslate2 = yswitch.getString("L2.Name");
                            String nameColored2 = ChatColor.translateAlternateColorCodes('&', nameToTranslate2);
                            switcherInv.setItem(yswitch.getInt("L2.Slot"), createIs(nameColored2, Material.INK_SACK, yswitch.getString("L2.Lore"), yswitch.getInt("L2.Stacksize"), (short) 10));
                            System.out.println("EventFired L2 - 2");
                        }
                    }
                    if (yswitch.getBoolean("L3.hide") == false) {
                        if (configServer3.equalsIgnoreCase(serverName)) {
                            String nameToTranslate3 = yswitch.getString("L3.Name");
                            String nameColored3 = ChatColor.translateAlternateColorCodes('&', nameToTranslate3);
                            switcherInv.setItem(yswitch.getInt("L3.Slot"), createIs(nameColored3, Material.INK_SACK, yswitch.getString("L3.LoreC"), yswitch.getInt("L3.Stacksize"), (short) 1));
                            System.out.println("EventFired L3");
                            return;
                        }
                        if (!(configServer3.equalsIgnoreCase(serverName))) {
                            String nameToTranslate3 = yswitch.getString("L3.Name");
                            String nameColored3 = ChatColor.translateAlternateColorCodes('&', nameToTranslate3);
                            switcherInv.setItem(yswitch.getInt("L3.Slot"), createIs(nameColored3, Material.INK_SACK, yswitch.getString("L3.Lore"), yswitch.getInt("L3.Stacksize"), (short) 10));
                            System.out.println("EventFired L3 - 2");
                        }
                    }
                    if (yswitch.getBoolean("L4.hide") == false) {
                        if (configServer4.equalsIgnoreCase(serverName)) {
                            String nameToTranslate4 = yswitch.getString("L4.Name");
                            String nameColored4 = ChatColor.translateAlternateColorCodes('&', nameToTranslate4);
                            switcherInv.setItem(yswitch.getInt("L4.Slot"), createIs(nameColored4, Material.INK_SACK, yswitch.getString("L4.LoreC"), yswitch.getInt("L4.Stacksize"), (short) 1));
                            System.out.println("EventFired L4");
                            return;
                        }
                        if (!(configServer4.equalsIgnoreCase(serverName))) {
                            String nameToTranslate4 = yswitch.getString("L4.Name");
                            String nameColored4 = ChatColor.translateAlternateColorCodes('&', nameToTranslate4);
                            switcherInv.setItem(yswitch.getInt("L4.Slot"), createIs(nameColored4, Material.INK_SACK, yswitch.getString("L4.Lore"), yswitch.getInt("L4.Stacksize"), (short) 10));
                            System.out.println("EventFired L4 - 2");
                        }
                    }
                    if (yswitch.getBoolean("L5.hide") == false) {
                        if (configServer5.equalsIgnoreCase(serverName)) {
                            String nameToTranslate5 = yswitch.getString("L5.Name");
                            String nameColored5 = ChatColor.translateAlternateColorCodes('&', nameToTranslate5);
                            switcherInv.setItem(yswitch.getInt("L5.Slot"), createIs(nameColored5, Material.INK_SACK, yswitch.getString("L5.LoreC"), yswitch.getInt("L5.Stacksize"), (short) 1));
                            System.out.println("EventFired L5");
                            return;
                        }
                        if (!(configServer5.equalsIgnoreCase(serverName))) {
                            String nameToTranslate5 = yswitch.getString("L5.Name");
                            String nameColored5 = ChatColor.translateAlternateColorCodes('&', nameToTranslate5);
                            switcherInv.setItem(yswitch.getInt("L5.Slot"), createIs(nameColored5, Material.INK_SACK, yswitch.getString("L5.Lore"), yswitch.getInt("L5.Stacksize"), (short) 10));
                            System.out.println("EventFired L5 - 2");
                        }
                    }
                   
                }
            }, 40L);
        }
    I've put some DebugLines and that AsyncChatEvent to verify it give the correct values back and to see wich events are fired. configServer5 value is set to the BungeeCord config name of my Testserver.
    I've verified with AsyncChatEvent that the values I get back are the same. But the first if clause in my PlayerJoinEvent isn't triggered. The other if statement where another item should be set, also won't be triggered. Got anyone an idea what I am doing wrong?


    Thanks in advance
    dmmk218
     
  2. First off let's cover some Java Basics:
    1. Don't make a simple variable like servername static. The object containing that value should be passed on via the constructor.
    2. Why are those methods static. Only use static if there is no plain OOP workaround or if it is a utility method.
    3. This: yswitch.getBoolean("L5.hide") == false should be replaced by: !yswitch.getBoolean("L5.hide")
    I can't directly fix your problem as I do not know enough.
    BUT I would recommend debugging as follows: add a System.out.println confront of each not working if clause. Than you see if they do not match. Than if one is wrong go backwards through the process where the value is being updated. Sout a message after every line of code and print out all variables.
     
  3. Why aren't you verifying the values in the PlayerJoinEvent handler? The logic you are implementing in the posted snippet is not exactly clear, and there are many ways that it could possibly be incorrect
     
  4. @Gerolmed
    So well the server name is actually static it doesn't change in the BungeeCord config the only reason why I set it every time is because you need a Player for your "GetServer" BungeeCordChannel. I don't see any problem with this.

    And to your point 3 whats wrong with that it works it passes by there that isn't the problem and I've added System.outs at the necessary places btw.


    @xTrollxDudex

    I do? Read the event or you mean something completely different.
     
  5. I don’t understand. You said you verified the values with the chat event, but now you’re saying you’re verifying the value with the join event? Just print out the values to console or something and see if they match.
     
  6. Ah I see we miss understood each other xD

    I verified with that AsycChatEvent the the value from the config is the same as the value the MessagingChannel gives me back by printing out the values ingame. The join event only has some System.out.println(""); phrases to see wich of the if clauses are triggered and the if clauses are based on the server whats defined in the config and just checks back if this server from the config equals the result from the MessagingChannel. I've delayed the if clauses to give the variables a bit of time to initialize.