2
2
3
3
import com .github .sanctum .labyrinth .formatting .PaginatedList ;
4
4
import com .github .sanctum .labyrinth .gui .InventoryRows ;
5
+ import com .github .sanctum .labyrinth .library .NamespacedKey ;
5
6
import com .github .sanctum .labyrinth .task .Asynchronous ;
6
- import java .util .Arrays ;
7
7
import java .util .Comparator ;
8
8
import java .util .HashMap ;
9
9
import java .util .LinkedList ;
12
12
import java .util .UUID ;
13
13
import java .util .concurrent .CompletableFuture ;
14
14
import java .util .function .Supplier ;
15
- import java .util .stream .Collectors ;
16
15
import org .bukkit .Bukkit ;
17
- import org .bukkit .Material ;
18
- import org .bukkit .NamespacedKey ;
19
16
import org .bukkit .entity .Player ;
20
17
import org .bukkit .event .Event ;
21
18
import org .bukkit .event .EventHandler ;
28
25
import org .bukkit .event .inventory .InventoryMoveItemEvent ;
29
26
import org .bukkit .inventory .Inventory ;
30
27
import org .bukkit .inventory .ItemStack ;
31
- import org .bukkit .inventory .meta .SkullMeta ;
32
28
import org .bukkit .plugin .Plugin ;
33
29
34
30
/**
@@ -126,6 +122,7 @@ public PaginatedBuilder(Plugin plugin, String title) {
126
122
*/
127
123
public PaginatedBuilder <T > forPlugin (Plugin plugin ) {
128
124
NAMESPACE = new NamespacedKey (plugin , "paginated_utility_manager" );
125
+ PLUGIN = plugin ;
129
126
CONTROLLER = new PaginatedListener ();
130
127
Bukkit .getPluginManager ().registerEvents (CONTROLLER , plugin );
131
128
return this ;
@@ -695,37 +692,13 @@ public Plugin getPlugin() {
695
692
*/
696
693
public class PaginatedListener implements Listener {
697
694
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
-
722
695
@ EventHandler (priority = EventPriority .NORMAL )
723
696
public void onClose (InventoryCloseEvent e ) {
724
697
if (!(e .getPlayer () instanceof Player ))
725
698
return ;
726
699
if (e .getView ().getTopInventory ().getSize () < SIZE )
727
700
return ;
728
- if (getInventory () == e . getInventory ()) {
701
+ if (e . getInventory (). equals ( getInventory () )) {
729
702
730
703
Player p = (Player ) e .getPlayer ();
731
704
@@ -744,7 +717,7 @@ public void onClose(InventoryCloseEvent e) {
744
717
745
718
@ EventHandler (priority = EventPriority .NORMAL )
746
719
public void onMove (InventoryMoveItemEvent e ) {
747
- if (e .getSource () == getInventory ()) {
720
+ if (e .getSource (). equals ( getInventory () )) {
748
721
e .setCancelled (true );
749
722
}
750
723
}
@@ -755,9 +728,9 @@ public void onDrag(InventoryDragEvent e) {
755
728
return ;
756
729
if (e .getView ().getTopInventory ().getSize () < SIZE )
757
730
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 () )) {
761
734
e .setResult (Event .Result .DENY );
762
735
}
763
736
}
@@ -766,16 +739,14 @@ public void onDrag(InventoryDragEvent e) {
766
739
public void onClick (InventoryClickEvent e ) {
767
740
if (!(e .getWhoClicked () instanceof Player ))
768
741
return ;
769
- if (e .getView ().getTopInventory ().getSize () < SIZE )
770
- return ;
742
+ if (e .getView ().getTopInventory ().getSize () < SIZE ) return ;
771
743
772
744
if (e .getHotbarButton () != -1 ) {
773
745
e .setCancelled (true );
774
746
return ;
775
747
}
776
748
777
- if (getInventory () != e .getInventory ())
778
- return ;
749
+ if (!e .getInventory ().equals (getInventory ())) return ;
779
750
780
751
if (e .getClickedInventory () == e .getInventory ()) {
781
752
Player p = (Player ) e .getWhoClicked ();
@@ -798,8 +769,8 @@ public void onClick(InventoryClickEvent e) {
798
769
e .setCancelled (false );
799
770
return ;
800
771
}
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 ));
803
774
}
804
775
if (NAVIGATION_BACK .keySet ().stream ().anyMatch (i -> i .isSimilar (item ))) {
805
776
ITEM_ACTIONS .get (item ).clickEvent (new PaginatedClickAction <>(PaginatedBuilder .this , p , e .getView (), item , e .isLeftClick (), e .isRightClick (), e .isShiftClick (), e .getClick () == ClickType .MIDDLE ));
0 commit comments