Skip to content

Commit

Permalink
* Introduced locally copied NamespacedKey since versions prior to 1.1…
Browse files Browse the repository at this point in the history
…2 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
  • Loading branch information
Hempfest committed Jun 24, 2021
1 parent 0bb6c71 commit ff7bc4f
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,11 @@ private ClickListener() {
@EventHandler
public void onMenuClick(InventoryClickEvent e) {
// If the top inventory isn't ours, ignore it
if (e.getInventory() != inventory) {
if (!e.getInventory().equals(inventory)) {
return;
}
// If the bottom inventory was clicked...
if (e.getClickedInventory() == e.getView().getBottomInventory()) {
if (e.getView().getBottomInventory().equals(e.getClickedInventory())) {
// and we want to cancel clicks for the bottom, cancel the event
if (cancelClickLower) e.setCancelled(true);
// if we are not allowing shift clicks
Expand All @@ -399,7 +399,7 @@ public void onMenuClick(InventoryClickEvent e) {
final Player player = (Player) whoClicked;
final int slot = e.getSlot();
// if this is a menu click (top inventory)
if (e.getClickedInventory() == e.getInventory()) {
if (e.getInventory().equals(e.getClickedInventory())) {
// search the menu elements map for the slot
if (contents.keySet().parallelStream().anyMatch(key -> key == slot)) {
// cancel the click
Expand Down Expand Up @@ -427,7 +427,7 @@ public void onMenuClick(InventoryClickEvent e) {
@EventHandler
public void onMenuDrag(InventoryDragEvent e) {
// If the top inventory isn't ours, ignore it
if (e.getInventory() != inventory) {
if (!e.getInventory().equals(inventory)) {
return;
}
// If the slots include the top inventory, cancel the event
Expand All @@ -447,7 +447,7 @@ public void onMenuDrag(InventoryDragEvent e) {
*/
@EventHandler
public void onMenuOpen(InventoryOpenEvent e) {
if (e.getInventory() != inventory) {
if (!e.getInventory().equals(inventory)) {
return;
}
if (pendingDelete != null) {
Expand All @@ -470,7 +470,7 @@ public void onMenuOpen(InventoryOpenEvent e) {
*/
@EventHandler
public void onMenuClose(InventoryCloseEvent e) {
if (e.getInventory() != inventory) {
if (!e.getInventory().equals(inventory)) {
return;
}
final HumanEntity closer = e.getPlayer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.github.sanctum.labyrinth.formatting.PaginatedList;
import com.github.sanctum.labyrinth.gui.InventoryRows;
import com.github.sanctum.labyrinth.library.NamespacedKey;
import com.github.sanctum.labyrinth.task.Asynchronous;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
Expand All @@ -12,10 +12,7 @@
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
Expand All @@ -28,7 +25,6 @@
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.Plugin;

/**
Expand Down Expand Up @@ -126,6 +122,7 @@ public PaginatedBuilder(Plugin plugin, String title) {
*/
public PaginatedBuilder<T> forPlugin(Plugin plugin) {
NAMESPACE = new NamespacedKey(plugin, "paginated_utility_manager");
PLUGIN = plugin;
CONTROLLER = new PaginatedListener();
Bukkit.getPluginManager().registerEvents(CONTROLLER, plugin);
return this;
Expand Down Expand Up @@ -695,37 +692,13 @@ public Plugin getPlugin() {
*/
public class PaginatedListener implements Listener {

private boolean metaMatches(ItemStack one, ItemStack two) {
boolean isNew = Arrays.stream(Material.values()).map(Material::name).collect(Collectors.toList()).contains("PLAYER_HEAD");
Material type;
if (isNew) {
type = Material.valueOf("PLAYER_HEAD");
} else {
type = Material.valueOf("SKULL_ITEM");
}
if (one.getType() == type && two.getType() == type) {
if (one.hasItemMeta() && two.hasItemMeta()) {
if (one.getItemMeta() instanceof SkullMeta && two.getItemMeta() instanceof SkullMeta) {
SkullMeta Meta1 = (SkullMeta) one.getItemMeta();
SkullMeta Meta2 = (SkullMeta) one.getItemMeta();
if (Meta1.hasOwner() && Meta2.hasOwner()) {
return Meta1.getOwningPlayer().getUniqueId().equals(Meta2.getOwningPlayer().getUniqueId());
}
}
return false;
}
return false;
}
return false;
}

@EventHandler(priority = EventPriority.NORMAL)
public void onClose(InventoryCloseEvent e) {
if (!(e.getPlayer() instanceof Player))
return;
if (e.getView().getTopInventory().getSize() < SIZE)
return;
if (getInventory() == e.getInventory()) {
if (e.getInventory().equals(getInventory())) {

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

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

@EventHandler(priority = EventPriority.NORMAL)
public void onMove(InventoryMoveItemEvent e) {
if (e.getSource() == getInventory()) {
if (e.getSource().equals(getInventory())) {
e.setCancelled(true);
}
}
Expand All @@ -755,9 +728,9 @@ public void onDrag(InventoryDragEvent e) {
return;
if (e.getView().getTopInventory().getSize() < SIZE)
return;
if (getInventory() != e.getInventory())
return;
if (e.getInventory() == getInventory()) {
if (!e.getInventory().equals(getInventory())) return;

if (e.getInventory().equals(getInventory())) {
e.setResult(Event.Result.DENY);
}
}
Expand All @@ -766,16 +739,14 @@ public void onDrag(InventoryDragEvent e) {
public void onClick(InventoryClickEvent e) {
if (!(e.getWhoClicked() instanceof Player))
return;
if (e.getView().getTopInventory().getSize() < SIZE)
return;
if (e.getView().getTopInventory().getSize() < SIZE) return;

if (e.getHotbarButton() != -1) {
e.setCancelled(true);
return;
}

if (getInventory() != e.getInventory())
return;
if (!e.getInventory().equals(getInventory())) return;

if (e.getClickedInventory() == e.getInventory()) {
Player p = (Player) e.getWhoClicked();
Expand All @@ -798,8 +769,8 @@ public void onClick(InventoryClickEvent e) {
e.setCancelled(false);
return;
}
if (PROCESS_LIST.stream().anyMatch(i -> i.isSimilar(item) || metaMatches(i, item))) {
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));
if (PROCESS_LIST.stream().anyMatch(i -> i.isSimilar(item))) {
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));
}
if (NAVIGATION_BACK.keySet().stream().anyMatch(i -> i.isSimilar(item))) {
ITEM_ACTIONS.get(item).clickEvent(new PaginatedClickAction<>(PaginatedBuilder.this, p, e.getView(), item, e.isLeftClick(), e.isRightClick(), e.isShiftClick(), e.getClick() == ClickType.MIDDLE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@
*/
public final class Labyrinth extends JavaPlugin implements Listener {

public static final LinkedList<Cooldown> COOLDOWNS = new LinkedList<>();
public static final LinkedList<WrappedComponent> COMPONENTS = new LinkedList<>();
public static final ConcurrentLinkedQueue<Integer> TASKS = new ConcurrentLinkedQueue<>();
private static final LinkedList<Cooldown> COOLDOWNS = new LinkedList<>();
private static final LinkedList<WrappedComponent> COMPONENTS = new LinkedList<>();
private static final ConcurrentLinkedQueue<Integer> TASKS = new ConcurrentLinkedQueue<>();
private static final List<PersistentContainer> CONTAINERS = new LinkedList<>();
private static Labyrinth INSTANCE;
private VentMap eventMap;
Expand Down Expand Up @@ -118,10 +118,14 @@ public void onDisable() {
Thread.sleep(1);
} catch (InterruptedException ignored) {
}

SkullItem.getLog().clear();
if (Item.getCache().size() > 0) {
for (Item i : Item.getCache()) {
Item.removeEntry(i);

if (Bukkit.getVersion().contains("1.14") || Bukkit.getVersion().contains("1.15") || Bukkit.getVersion().contains("1.16") || Bukkit.getVersion().contains("1.17")) {
if (Item.getCache().size() > 0) {
for (Item i : Item.getCache()) {
Item.removeEntry(i);
}
}
}

Expand All @@ -131,6 +135,18 @@ public VentMap getEventMap() {
return eventMap;
}

public static ConcurrentLinkedQueue<Integer> getTasks() {
return TASKS;
}

public static LinkedList<Cooldown> getCooldowns() {
return COOLDOWNS;
}

public static LinkedList<WrappedComponent> getComponents() {
return COMPONENTS;
}

/**
* @return All data containers linked to the specified plugin.
* <p>
Expand Down Expand Up @@ -166,7 +182,7 @@ public static Plugin getInstance() {
}


public static class ComponentListener implements Listener {
static class ComponentListener implements Listener {
@EventHandler
public void onCommandNote(PlayerCommandPreprocessEvent e) {
for (WrappedComponent component : COMPONENTS) {
Expand Down

0 comments on commit ff7bc4f

Please sign in to comment.