1.16.5 Opening Inventory causes PvP to disable

Discussion in 'Spigot Plugin Development' started by MrMel, Jun 30, 2021.

  1. So I'm trying to create a voting thing for my event plugin, and whenever I open the voting GUI to all the players,
    the GUI opens and works as expected. The problem is that after the GUI is closed, doesn't matter if the plugin or player closes it. Players can no longer pvp.

    No errors in config, tried using multiple ways for my GUI code.
    This is my current code:

    Code (Text):
    private final AgoniaEvents plugin = AgoniaEvents.getInstance();

        private Inventory inventory;
        private VoteGUI voteGUI;

        public MainVoteGUI() {
            this.inventory = Bukkit.createInventory(null, 9 * 5, StringUtils.colour("&8Rösta på Event"));
        }

        private void setItem(ItemStack itemStack, int pos) {
            inventory.setItem(pos, itemStack);
        }

        public void resetPoll() {
            List<AgoniaEvent> eventsTotal = new ArrayList<>(plugin.getEventManager().getEvents());
            // blanda ordningen av events
            Collections.shuffle(eventsTotal);
            List<AgoniaEvent> randomEvents = new ArrayList<>();
            if (eventsTotal.size() <= 5) {
                randomEvents.addAll(eventsTotal);
            } else {
                Iterator<AgoniaEvent> itr = eventsTotal.iterator();
                int i = 0;
                while (itr.hasNext()) {
                    if (i == 3) {
                        break;
                    }
                    randomEvents.add(itr.next());
                    itr.remove();
                    i++;
                }
            }
            this.inventory = Bukkit.createInventory(null, 9 * (randomEvents.size() > 5 ? 5 : randomEvents.size()), StringUtils.colour("Rösta på Event"));
            for (int i = 0; i < randomEvents.size(); i++) {
                setItem(new ItemBuilder(Material.OAK_SIGN)
                        .setName(randomEvents.get(i).getEventName())
                        .setLore(randomEvents.get(i).getDescriptionMessage())
                        .build(), i * 9);
                setItem(new ItemStack(Material.IRON_BARS), (i * 9) + 1);

                for(int j = 0; j < 6; j++) {
                    setItem(new ItemBuilder(Material.RED_STAINED_GLASS).build(), (i * 9) + 1 + j + 1);
                }
            }
            voteGUI = new VoteGUI(randomEvents);
        }

        public Inventory getInventory() {
            return inventory;
        }


        public VoteGUI getVoteGUI() {
            return voteGUI;
        }

        public void update(Player player) {
            int totalVotes = plugin.getEventManager().getPlayerVote().size();
            int i = 0;
            for (Map.Entry<AgoniaEvent, Integer> map : plugin.getEventManager().getVotedEvents().entrySet()) {
                int voted = map.getValue();
                AgoniaEvent event = map.getKey();
                double percent;
                if (Double.isNaN(voted) || voted == 0) {
                    percent = 0.0;
                } else {
                    percent = ((double) voted / (double) totalVotes) * 100;
                }
                ItemStack stack = new ItemBuilder(Material.OAK_SIGN)
                        .setName(event.getEventName())
                        .setLore(event.getDescriptionMessage())
                        .build();
                if (voteGUI.getPlayerVote().containsKey(player) && voteGUI.getPlayerVote().get(player).equals(event)) {
                    ItemMeta meta = stack.getItemMeta();
                    meta.addEnchant(Enchantment.DAMAGE_ALL, 1, true);
                    meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
                    stack.setItemMeta(meta);
                }
                setItem(stack, (i * 9));

                for (int j = 0; j < 6; j++) {
                    setItem(new ItemStack(Material.RED_STAINED_GLASS_PANE), (i * 9) + 1 + j + 1);
                }

                if (voted > 0) {
                    double vote = 0;
                    for (int j = 0; i < 6; j++) {
                        if (vote > percent) {
                            break;
                        }
                        setItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), (i * 9) + 1 + j + 1);
                        vote += 16.7;
                    }
                }
                i++;
            }
            player.updateInventory();
        }
    Never seen this issue before, it's really weird.
     
  2. I highly doubt it's your plugin that's causing the issue since it changes nothing that has to do with pvp or damage - I think it's a different plugin that's causing that (for some reason). Try running a server with only that plugin and check if it still does that.
     
  3. I tried removing everything except: [ my plugin, fawe, worldguard, multiverse core ]
    Still doesn't work, seems really off that it works when removing the vote thing, but when adding it back it doesn't work.
     
  4. What do you mean by "can no longer pvp"? They can't take damage from other players, can't take damage at all, a message shows up saying "PVP isn't allowed here"?
     
  5. They can't take any damage at all, no fall damage, no damage from players. No message shows up and doesn't matter where we are in the world. No errors in the console either.
     
  6. Is this all the code in the plugin? Because it makes no sense that this code does that - it only works with items and menus.
    I suggest you look at any other code present in the plugin.
     
    • Agree Agree x 1