From eba90276776adf9f9de5ca44dec7d666e9c5dced Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Mon, 8 Mar 2021 16:57:09 +0100 Subject: [PATCH 1/5] Use java 15 to build on travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 815850c..d3a0ff2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ language: java jdk: - openjdk8 - openjdk11 - - openjdk14 + - openjdk15 cache: directories: From c1cf6e6316715b5e0b72db2d13f38cf828a90188 Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Wed, 10 Mar 2021 19:02:38 +0100 Subject: [PATCH 2/5] Move ItemFilter logic into PCGF_PluginLib --- .../Minepacks/Bukkit/Listener/ItemFilter.java | 39 ++++--------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemFilter.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemFilter.java index 5effefd..c74163d 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemFilter.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemFilter.java @@ -32,27 +32,24 @@ import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection; -import java.util.HashSet; -import java.util.Set; public class ItemFilter extends MinepacksListener implements at.pcgamingfreaks.Minepacks.Bukkit.API.ItemFilter { public final Message messageNotAllowedInBackpack; public final ItemNameResolver itemNameResolver; - private final boolean whitelistMode; - private final Collection filteredMaterials = new HashSet<>(); - private final Set filteredNames, filteredLore; + private final at.pcgamingfreaks.Bukkit.ItemFilter filter; public ItemFilter(final Minepacks plugin) { super(plugin); - whitelistMode = plugin.getConfiguration().isItemFilterModeWhitelist(); + boolean whitelistMode = plugin.getConfiguration().isItemFilterModeWhitelist(); + filter = new at.pcgamingfreaks.Bukkit.ItemFilter(whitelistMode); + Collection filteredMaterials = plugin.getConfiguration().getItemFilterMaterials(); if(plugin.getConfiguration().isShulkerboxesPreventInBackpackEnabled() && !whitelistMode) { for(Material mat : DisableShulkerboxes.SHULKER_BOX_MATERIALS) @@ -60,9 +57,9 @@ public ItemFilter(final Minepacks plugin) filteredMaterials.add(new MinecraftMaterial(mat, (short) -1)); } } - filteredMaterials.addAll(plugin.getConfiguration().getItemFilterMaterials()); - filteredNames = plugin.getConfiguration().getItemFilterNames(); - filteredLore = plugin.getConfiguration().getItemFilterLore(); + filter.addFilteredMaterials(filteredMaterials); + filter.addFilteredNames(plugin.getConfiguration().getItemFilterNames()); + filter.addFilteredLore(plugin.getConfiguration().getItemFilterLore()); messageNotAllowedInBackpack = plugin.getLanguage().getMessage("Ingame.NotAllowedInBackpack").replaceAll("\\{ItemName}", "%s"); @@ -90,27 +87,7 @@ public ItemFilter(final Minepacks plugin) @Override public boolean isItemBlocked(final @Nullable ItemStack item) { - if(item == null) return false; - if(filteredMaterials.contains(new MinecraftMaterial(item))) return !whitelistMode; - if(item.hasItemMeta()) - { - ItemMeta meta = item.getItemMeta(); - assert meta != null; //TODO remove after testing - if(meta.hasDisplayName() && filteredNames.contains(meta.getDisplayName())) return !whitelistMode; - if(meta.hasLore() && !filteredLore.isEmpty()) - { - StringBuilder loreBuilder = new StringBuilder(); - //noinspection ConstantConditions - for(String loreLine : meta.getLore()) - { - if(filteredLore.contains(loreLine)) return !whitelistMode; - if(loreBuilder.length() > 0) loreBuilder.append("\n"); - loreBuilder.append(loreLine); - } - if(filteredLore.contains(loreBuilder.toString())) return !whitelistMode; - } - } - return whitelistMode; + return filter.isItemBlocked(item); } @Override From 0aee9bf3028d7b9d8b2449bbff1cd6a29761883c Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Thu, 11 Mar 2021 16:49:33 +0100 Subject: [PATCH 3/5] Ignore backpack requests for NPCs (#156) --- .../at/pcgamingfreaks/Minepacks/Bukkit/Database/Database.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Database.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Database.java index 1f02af6..5550d1f 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Database.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Database.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 GeorgH93 + * Copyright (C) 2021 GeorgH93 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -195,7 +195,7 @@ protected String getPlayerFormattedUUID(OfflinePlayer player) public void getBackpack(final OfflinePlayer player, final Callback callback, final boolean createNewOnFail) { - if(player == null) + if(player == null || player.getClass().getName().contains("NPC")) { return; } From 0cee4ba06681819d2eb19183e5ab6746cd5e1d50 Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Thu, 11 Mar 2021 23:18:54 +0100 Subject: [PATCH 4/5] Fix bug with the backpack item detection on Paper --- .../Minepacks/Bukkit/Listener/ItemShortcut.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java index 9752a1d..f50bcb2 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/ItemShortcut.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 GeorgH93 + * Copyright (C) 2021 GeorgH93 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -50,7 +50,7 @@ public class ItemShortcut extends MinepacksListener { private static final UUID MINEPACKS_UUID = UUID.nameUUIDFromBytes("Minepacks".getBytes()); - private final String itemName, value, openCommand; + private final String itemName, itemNameNoReset, value, openCommand; private final Message messageDoNotRemoveItem; private final boolean improveDeathChestCompatibility, blockAsHat, allowRightClickOnContainers, blockItemFromMoving; private final int preferredSlotId; @@ -60,6 +60,7 @@ public ItemShortcut(final @NotNull Minepacks plugin) { super(plugin); itemName = ChatColor.translateAlternateColorCodes('&', plugin.getConfiguration().getItemShortcutItemName()); + itemNameNoReset = itemName.replace(ChatColor.RESET.toString(), ""); value = plugin.getConfiguration().getItemShortcutHeadValue(); improveDeathChestCompatibility = plugin.getConfiguration().isItemShortcutImproveDeathChestCompatibilityEnabled(); blockAsHat = plugin.getConfiguration().isItemShortcutBlockAsHatEnabled(); @@ -86,8 +87,9 @@ public ItemShortcut(final @NotNull Minepacks plugin) public boolean isItemShortcut(final @Nullable ItemStack stack) { - //noinspection ConstantConditions - return stack != null && stack.getType() == HeadUtils.HEAD_MATERIAL && stack.hasItemMeta() && itemName.equals(stack.getItemMeta().getDisplayName()); + if(stack == null || stack.getType() != HeadUtils.HEAD_MATERIAL || !stack.hasItemMeta()) return false; + String itemDisplayName = stack.getItemMeta().getDisplayName(); + return itemDisplayName != null && itemNameNoReset.equals(itemDisplayName.replace(ChatColor.RESET.toString(), "")); } private void addItem(Player player) From eee8817dc1f213e6dc4366f67521151d47fb56ca Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Fri, 12 Mar 2021 16:54:58 +0100 Subject: [PATCH 5/5] Update to v2.3.22 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 80fe7bd..b50949b 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ pom - 2.3.21.3 + 2.3.22 UTF-8 UTF-8