Solved Plugin works in 1.8.0 does not work in 1.8.3

Discussion in 'Spigot Plugin Development' started by MaximePremont, Feb 5, 2020.

Thread Status:
Not open for further replies.
  1. Hello, I am currently in the process of creating a plugin that should work with all versions of minecraft from 1.8.0 to 1.15.X, my plugin works perfectly in 1.8.0 but when I did the test on a 1.8.3 server, it no longer works despite no error in the console and I do not understand why. Please note that my plugin does not use NMS.

    Here is the git repository : https://github.com/MaximePremont/ConfirmMenu

    The part that does not work is the fact that my function ConfirmMenuAPI.isConfirming (player) in the MenuEvents class (line 25) returns False in 1.8.3 while it returns True in 1.8.0.

    Code (Text):
    package fr.mpremont.confirmmenu;

    import java.util.HashMap;

    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;

    import fr.mpremont.confirmmenu.events.custom.CancelEvent;
    import fr.mpremont.confirmmenu.menus.ConfirmMenu;

    public class ConfirmMenuAPI {
       
        private static HashMap<Player, String> list = new HashMap<Player, String>();
       
        public static void confirm(Player player, String action) {
           
            Bukkit.broadcastMessage("§e>> "+player.getName()+" :: "+action);
           
            if(!isConfirming(player)) {
               
                Bukkit.broadcastMessage("§5Added");
                list.put(player, action);
                ConfirmMenu.openMenu(player);
               
            }
           
        }
       
        public static void cancel(Player player) {
           
            if(isConfirming(player)) {
               
                CancelEvent event = new CancelEvent(player, getConfirmAction(player));
                list.remove(player);
                Bukkit.getPluginManager().callEvent(event);
                if(player.getOpenInventory() != null) {
                    player.closeInventory();
                }
               
            }
           
        }
       
        public static boolean isConfirming(Player player) {
           
            boolean result = false;
            if(list.containsKey(player)) {
               
                result = true;
                Bukkit.broadcastMessage("§dContains "+player.getName());
               
            }
           
            return result;
           
        }
       
        public static String getConfirmAction(Player player) {
           
            String result = null;
           
            if(isConfirming(player) == true) {
               
                result = list.get(player);
               
            }
           
            return result;
           
        }
       
        public static void w(Player p) {
           
            if(isConfirming(p)) {
               
                list.remove(p);
               
            }
           
        }

    }
     

    Code (Text):
    package fr.mpremont.confirmmenu.events;

    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;

    import fr.mpremont.confirmmenu.ConfirmMenuAPI;
    import fr.mpremont.confirmmenu.events.custom.ConfirmEvent;

    public class MenuEvents implements Listener {

        @EventHandler
        public void onClick(InventoryClickEvent e) {
           
            if(e.getInventory() == null) {
               
                return;
               
            }else {
               
                Player p = (Player) e.getWhoClicked();
                if(ConfirmMenuAPI.isConfirming(p)) {
                   
                    e.setCancelled(true);
                   
                    if(e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR) {
                       
                        return;
                       
                    }else if(e.getCurrentItem().getType() == Material.SLIME_BLOCK) {
                       
                        ConfirmEvent event = new ConfirmEvent(p, ConfirmMenuAPI.getConfirmAction(p));
                        Bukkit.getPluginManager().callEvent(event);
                        ConfirmMenuAPI.w(p);
                        p.closeInventory();
                       
                    }else {
                       
                        ConfirmMenuAPI.cancel(p);
                       
                    }
                   
                }else {
                   
                    Bukkit.broadcastMessage("§cMenuEvents :: Isn't confirming");
                   
                }
               
            }
           
        }
       
    }
     

    Do not hesitate if you need other information or specific pieces of my code to help me solve the problem. Thank you !
     
  2. First of all, you should not use the actual player object reference as a map key, have you tried using UUIDs?
     
  3. I haven't tried it yet, I'm doing it right now and I'm giving my results.
     
  4. Btw, you should write isConfirming like this:
    Code (Text):

    public static boolean isConfirming(Player player) {
            return list.containsKey(player);
        }
     
    as containsKey already returns the value you need, no need to create one more boolean
     
  5. I did this and no changes (I added brodcasts in my ConfirmMenuAPI and MenuEvents classes for testing). Here is the code of my modified ConfirmMenuAPI class and the result obtained.

    Code (Text):
    package fr.mpremont.confirmmenu;

    import java.util.HashMap;
    import java.util.UUID;

    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;

    import fr.mpremont.confirmmenu.events.custom.CancelEvent;
    import fr.mpremont.confirmmenu.menus.ConfirmMenu;

    public class ConfirmMenuAPI {
       
        private static HashMap<UUID, String> list = new HashMap<UUID, String>();
       
        public static void confirm(Player player, String action) {
           
            Bukkit.broadcastMessage("§e>> "+player.getName()+" :: "+action);
           
            if(!isConfirming(player)) {
               
                Bukkit.broadcastMessage("§5Added");
                list.put(player.getUniqueId(), action);
                ConfirmMenu.openMenu(player);
               
            }
           
        }
       
        public static void cancel(Player player) {
           
            if(isConfirming(player)) {
               
                CancelEvent event = new CancelEvent(player, getConfirmAction(player));
                list.remove(player.getUniqueId());
                Bukkit.getPluginManager().callEvent(event);
                if(player.getOpenInventory() != null) {
                    player.closeInventory();
                }
               
            }
           
        }
       
        public static boolean isConfirming(Player player) {
           
            if(list.containsKey(player.getUniqueId())) {
                Bukkit.broadcastMessage("§dContains "+player.getName());
            }
            return list.containsKey(player.getUniqueId());
           
        }
       
        public static String getConfirmAction(Player player) {
           
            String result = null;
           
            if(isConfirming(player)) {
               
                result = list.get(player.getUniqueId());
               
            }
           
            return result;
           
        }
       
        public static void w(Player p) {
           
            if(isConfirming(p)) {
               
                list.remove(p.getUniqueId());
               
            }
           
        }

    }
     
    [​IMG]
     
  6. I solved my problem. That was other thing.
    Thanks !
     
Thread Status:
Not open for further replies.