Skip to content

Commit ff7bc4f

Browse files
committed
* Introduced locally copied NamespacedKey since versions prior to 1.12 don't have it.
* Fixed some listener information regarding legacy builds * Labyrinth now supports versions 1.8 through 1.17 B) * New head database use CustomHead.java SkullItem is marked for removal next patch. * Added isValid boolean to EconomyProvision
1 parent 0bb6c71 commit ff7bc4f

File tree

13 files changed

+169
-125
lines changed

13 files changed

+169
-125
lines changed

labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/menuman/Menu.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,11 @@ private ClickListener() {
374374
@EventHandler
375375
public void onMenuClick(InventoryClickEvent e) {
376376
// If the top inventory isn't ours, ignore it
377-
if (e.getInventory() != inventory) {
377+
if (!e.getInventory().equals(inventory)) {
378378
return;
379379
}
380380
// If the bottom inventory was clicked...
381-
if (e.getClickedInventory() == e.getView().getBottomInventory()) {
381+
if (e.getView().getBottomInventory().equals(e.getClickedInventory())) {
382382
// and we want to cancel clicks for the bottom, cancel the event
383383
if (cancelClickLower) e.setCancelled(true);
384384
// if we are not allowing shift clicks
@@ -399,7 +399,7 @@ public void onMenuClick(InventoryClickEvent e) {
399399
final Player player = (Player) whoClicked;
400400
final int slot = e.getSlot();
401401
// if this is a menu click (top inventory)
402-
if (e.getClickedInventory() == e.getInventory()) {
402+
if (e.getInventory().equals(e.getClickedInventory())) {
403403
// search the menu elements map for the slot
404404
if (contents.keySet().parallelStream().anyMatch(key -> key == slot)) {
405405
// cancel the click
@@ -427,7 +427,7 @@ public void onMenuClick(InventoryClickEvent e) {
427427
@EventHandler
428428
public void onMenuDrag(InventoryDragEvent e) {
429429
// If the top inventory isn't ours, ignore it
430-
if (e.getInventory() != inventory) {
430+
if (!e.getInventory().equals(inventory)) {
431431
return;
432432
}
433433
// If the slots include the top inventory, cancel the event
@@ -447,7 +447,7 @@ public void onMenuDrag(InventoryDragEvent e) {
447447
*/
448448
@EventHandler
449449
public void onMenuOpen(InventoryOpenEvent e) {
450-
if (e.getInventory() != inventory) {
450+
if (!e.getInventory().equals(inventory)) {
451451
return;
452452
}
453453
if (pendingDelete != null) {
@@ -470,7 +470,7 @@ public void onMenuOpen(InventoryOpenEvent e) {
470470
*/
471471
@EventHandler
472472
public void onMenuClose(InventoryCloseEvent e) {
473-
if (e.getInventory() != inventory) {
473+
if (!e.getInventory().equals(inventory)) {
474474
return;
475475
}
476476
final HumanEntity closer = e.getPlayer();

labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/menuman/PaginatedBuilder.java

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import com.github.sanctum.labyrinth.formatting.PaginatedList;
44
import com.github.sanctum.labyrinth.gui.InventoryRows;
5+
import com.github.sanctum.labyrinth.library.NamespacedKey;
56
import com.github.sanctum.labyrinth.task.Asynchronous;
6-
import java.util.Arrays;
77
import java.util.Comparator;
88
import java.util.HashMap;
99
import java.util.LinkedList;
@@ -12,10 +12,7 @@
1212
import java.util.UUID;
1313
import java.util.concurrent.CompletableFuture;
1414
import java.util.function.Supplier;
15-
import java.util.stream.Collectors;
1615
import org.bukkit.Bukkit;
17-
import org.bukkit.Material;
18-
import org.bukkit.NamespacedKey;
1916
import org.bukkit.entity.Player;
2017
import org.bukkit.event.Event;
2118
import org.bukkit.event.EventHandler;
@@ -28,7 +25,6 @@
2825
import org.bukkit.event.inventory.InventoryMoveItemEvent;
2926
import org.bukkit.inventory.Inventory;
3027
import org.bukkit.inventory.ItemStack;
31-
import org.bukkit.inventory.meta.SkullMeta;
3228
import org.bukkit.plugin.Plugin;
3329

3430
/**
@@ -126,6 +122,7 @@ public PaginatedBuilder(Plugin plugin, String title) {
126122
*/
127123
public PaginatedBuilder<T> forPlugin(Plugin plugin) {
128124
NAMESPACE = new NamespacedKey(plugin, "paginated_utility_manager");
125+
PLUGIN = plugin;
129126
CONTROLLER = new PaginatedListener();
130127
Bukkit.getPluginManager().registerEvents(CONTROLLER, plugin);
131128
return this;
@@ -695,37 +692,13 @@ public Plugin getPlugin() {
695692
*/
696693
public class PaginatedListener implements Listener {
697694

698-
private boolean metaMatches(ItemStack one, ItemStack two) {
699-
boolean isNew = Arrays.stream(Material.values()).map(Material::name).collect(Collectors.toList()).contains("PLAYER_HEAD");
700-
Material type;
701-
if (isNew) {
702-
type = Material.valueOf("PLAYER_HEAD");
703-
} else {
704-
type = Material.valueOf("SKULL_ITEM");
705-
}
706-
if (one.getType() == type && two.getType() == type) {
707-
if (one.hasItemMeta() && two.hasItemMeta()) {
708-
if (one.getItemMeta() instanceof SkullMeta && two.getItemMeta() instanceof SkullMeta) {
709-
SkullMeta Meta1 = (SkullMeta) one.getItemMeta();
710-
SkullMeta Meta2 = (SkullMeta) one.getItemMeta();
711-
if (Meta1.hasOwner() && Meta2.hasOwner()) {
712-
return Meta1.getOwningPlayer().getUniqueId().equals(Meta2.getOwningPlayer().getUniqueId());
713-
}
714-
}
715-
return false;
716-
}
717-
return false;
718-
}
719-
return false;
720-
}
721-
722695
@EventHandler(priority = EventPriority.NORMAL)
723696
public void onClose(InventoryCloseEvent e) {
724697
if (!(e.getPlayer() instanceof Player))
725698
return;
726699
if (e.getView().getTopInventory().getSize() < SIZE)
727700
return;
728-
if (getInventory() == e.getInventory()) {
701+
if (e.getInventory().equals(getInventory())) {
729702

730703
Player p = (Player) e.getPlayer();
731704

@@ -744,7 +717,7 @@ public void onClose(InventoryCloseEvent e) {
744717

745718
@EventHandler(priority = EventPriority.NORMAL)
746719
public void onMove(InventoryMoveItemEvent e) {
747-
if (e.getSource() == getInventory()) {
720+
if (e.getSource().equals(getInventory())) {
748721
e.setCancelled(true);
749722
}
750723
}
@@ -755,9 +728,9 @@ public void onDrag(InventoryDragEvent e) {
755728
return;
756729
if (e.getView().getTopInventory().getSize() < SIZE)
757730
return;
758-
if (getInventory() != e.getInventory())
759-
return;
760-
if (e.getInventory() == getInventory()) {
731+
if (!e.getInventory().equals(getInventory())) return;
732+
733+
if (e.getInventory().equals(getInventory())) {
761734
e.setResult(Event.Result.DENY);
762735
}
763736
}
@@ -766,16 +739,14 @@ public void onDrag(InventoryDragEvent e) {
766739
public void onClick(InventoryClickEvent e) {
767740
if (!(e.getWhoClicked() instanceof Player))
768741
return;
769-
if (e.getView().getTopInventory().getSize() < SIZE)
770-
return;
742+
if (e.getView().getTopInventory().getSize() < SIZE) return;
771743

772744
if (e.getHotbarButton() != -1) {
773745
e.setCancelled(true);
774746
return;
775747
}
776748

777-
if (getInventory() != e.getInventory())
778-
return;
749+
if (!e.getInventory().equals(getInventory())) return;
779750

780751
if (e.getClickedInventory() == e.getInventory()) {
781752
Player p = (Player) e.getWhoClicked();
@@ -798,8 +769,8 @@ public void onClick(InventoryClickEvent e) {
798769
e.setCancelled(false);
799770
return;
800771
}
801-
if (PROCESS_LIST.stream().anyMatch(i -> i.isSimilar(item) || metaMatches(i, item))) {
802-
ITEM_ACTIONS.entrySet().stream().filter(en -> en.getKey().isSimilar(item) || metaMatches(en.getKey(), item)).map(Map.Entry::getValue).findFirst().get().clickEvent(new PaginatedClickAction<>(PaginatedBuilder.this, p, e.getView(), item, e.isLeftClick(), e.isRightClick(), e.isShiftClick(), e.getClick() == ClickType.MIDDLE));
772+
if (PROCESS_LIST.stream().anyMatch(i -> i.isSimilar(item))) {
773+
ITEM_ACTIONS.entrySet().stream().filter(en -> en.getKey().isSimilar(item)).map(Map.Entry::getValue).findFirst().get().clickEvent(new PaginatedClickAction<>(PaginatedBuilder.this, p, e.getView(), item, e.isLeftClick(), e.isRightClick(), e.isShiftClick(), e.getClick() == ClickType.MIDDLE));
803774
}
804775
if (NAVIGATION_BACK.keySet().stream().anyMatch(i -> i.isSimilar(item))) {
805776
ITEM_ACTIONS.get(item).clickEvent(new PaginatedClickAction<>(PaginatedBuilder.this, p, e.getView(), item, e.isLeftClick(), e.isRightClick(), e.isShiftClick(), e.getClick() == ClickType.MIDDLE));

labyrinth-plugin/src/main/java/com/github/sanctum/labyrinth/Labyrinth.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@
6363
*/
6464
public final class Labyrinth extends JavaPlugin implements Listener {
6565

66-
public static final LinkedList<Cooldown> COOLDOWNS = new LinkedList<>();
67-
public static final LinkedList<WrappedComponent> COMPONENTS = new LinkedList<>();
68-
public static final ConcurrentLinkedQueue<Integer> TASKS = new ConcurrentLinkedQueue<>();
66+
private static final LinkedList<Cooldown> COOLDOWNS = new LinkedList<>();
67+
private static final LinkedList<WrappedComponent> COMPONENTS = new LinkedList<>();
68+
private static final ConcurrentLinkedQueue<Integer> TASKS = new ConcurrentLinkedQueue<>();
6969
private static final List<PersistentContainer> CONTAINERS = new LinkedList<>();
7070
private static Labyrinth INSTANCE;
7171
private VentMap eventMap;
@@ -118,10 +118,14 @@ public void onDisable() {
118118
Thread.sleep(1);
119119
} catch (InterruptedException ignored) {
120120
}
121+
121122
SkullItem.getLog().clear();
122-
if (Item.getCache().size() > 0) {
123-
for (Item i : Item.getCache()) {
124-
Item.removeEntry(i);
123+
124+
if (Bukkit.getVersion().contains("1.14") || Bukkit.getVersion().contains("1.15") || Bukkit.getVersion().contains("1.16") || Bukkit.getVersion().contains("1.17")) {
125+
if (Item.getCache().size() > 0) {
126+
for (Item i : Item.getCache()) {
127+
Item.removeEntry(i);
128+
}
125129
}
126130
}
127131

@@ -131,6 +135,18 @@ public VentMap getEventMap() {
131135
return eventMap;
132136
}
133137

138+
public static ConcurrentLinkedQueue<Integer> getTasks() {
139+
return TASKS;
140+
}
141+
142+
public static LinkedList<Cooldown> getCooldowns() {
143+
return COOLDOWNS;
144+
}
145+
146+
public static LinkedList<WrappedComponent> getComponents() {
147+
return COMPONENTS;
148+
}
149+
134150
/**
135151
* @return All data containers linked to the specified plugin.
136152
* <p>
@@ -166,7 +182,7 @@ public static Plugin getInstance() {
166182
}
167183

168184

169-
public static class ComponentListener implements Listener {
185+
static class ComponentListener implements Listener {
170186
@EventHandler
171187
public void onCommandNote(PlayerCommandPreprocessEvent e) {
172188
for (WrappedComponent component : COMPONENTS) {

0 commit comments

Comments
 (0)