Skip to content

Commit f3f77ba

Browse files
committed
revamp MultiPageGui, fix KitItemListener & BountyHuntersHook
1 parent 4fe19ed commit f3f77ba

File tree

13 files changed

+231
-60
lines changed

13 files changed

+231
-60
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ buildscript {
1010

1111
allprojects {
1212
group 'me.realized'
13-
version '3.2.0'
13+
version '3.2.1-SNAPSHOT'
1414
}
1515

1616
subprojects {

duels-api/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dependencies {
22
compile 'com.google.code.findbugs:jsr305:3.0.2'
3-
compile 'org.spigotmc:spigot-api:1.13-R0.1-SNAPSHOT'
3+
compile 'org.spigotmc:spigot-api:1.13.1-R0.1-SNAPSHOT'
44
}
55

66
shadowJar {

duels-plugin/src/main/java/me/realized/duels/extra/KitItemListener.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.bukkit.entity.Item;
1010
import org.bukkit.entity.Player;
1111
import org.bukkit.event.EventHandler;
12+
import org.bukkit.event.EventPriority;
1213
import org.bukkit.event.Listener;
1314
import org.bukkit.event.inventory.InventoryClickEvent;
1415
import org.bukkit.event.player.PlayerInteractEvent;
@@ -29,7 +30,7 @@ public KitItemListener(final DuelsPlugin plugin) {
2930
plugin.getServer().getPluginManager().registerEvents(this, plugin);
3031
}
3132

32-
@EventHandler
33+
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
3334
public void on(final InventoryClickEvent event) {
3435
final Player player = (Player) event.getWhoClicked();
3536

@@ -39,7 +40,7 @@ public void on(final InventoryClickEvent event) {
3940

4041
final Inventory clicked = event.getClickedInventory();
4142

42-
if (clicked == null || !(clicked instanceof PlayerInventory)) {
43+
if (!(clicked instanceof PlayerInventory)) {
4344
return;
4445
}
4546

duels-plugin/src/main/java/me/realized/duels/hook/hooks/BountyHuntersHook.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,38 @@
22

33
import me.realized.duels.DuelsPlugin;
44
import me.realized.duels.arena.ArenaManager;
5+
import me.realized.duels.config.Config;
56
import me.realized.duels.util.hook.PluginHook;
6-
import net.Indyuce.bh.api.BountyClaimEvent;
7-
import net.Indyuce.bh.api.BountyCreateEvent;
8-
import net.Indyuce.bh.resource.BountyCause;
7+
import net.Indyuce.bountyhunters.api.BountyCause;
8+
import net.Indyuce.bountyhunters.api.event.BountyClaimEvent;
9+
import net.Indyuce.bountyhunters.api.event.BountyCreateEvent;
910
import org.bukkit.event.EventHandler;
1011
import org.bukkit.event.Listener;
1112

1213
public class BountyHuntersHook extends PluginHook<DuelsPlugin> implements Listener {
1314

15+
private final Config config;
1416
private final ArenaManager arenaManager;
1517

1618
public BountyHuntersHook(final DuelsPlugin plugin) {
1719
super(plugin, "BountyHunters");
20+
this.config = plugin.getConfiguration();
1821
this.arenaManager = plugin.getArenaManager();
1922

20-
if (plugin.getConfiguration().isPreventBountyLoss()) {
21-
plugin.getServer().getPluginManager().registerEvents(this, plugin);
23+
try {
24+
Class.forName("net.Indyuce.bountyhunters.api.event.BountyClaimEvent");
25+
Class.forName("net.Indyuce.bountyhunters.api.event.BountyCreateEvent");
26+
Class.forName("net.Indyuce.bountyhunters.api.BountyCause");
27+
} catch (ClassNotFoundException ex) {
28+
throw new RuntimeException("This version of " + getName() + " is not supported. Please try upgrading to the latest version.");
2229
}
30+
31+
plugin.getServer().getPluginManager().registerEvents(this, plugin);
2332
}
2433

2534
@EventHandler(ignoreCancelled = true)
2635
public void on(final BountyClaimEvent event) {
27-
if (!arenaManager.isInMatch(event.getClaimer())) {
36+
if (!config.isPreventBountyLoss() || !arenaManager.isInMatch(event.getClaimer())) {
2837
return;
2938
}
3039

@@ -33,7 +42,7 @@ public void on(final BountyClaimEvent event) {
3342

3443
@EventHandler(ignoreCancelled = true)
3544
public void on(final BountyCreateEvent event) {
36-
if (event.getCause() != BountyCause.AUTO_BOUNTY || !arenaManager.isInMatch(event.getBounty().getTarget().getPlayer())) {
45+
if (!config.isPreventBountyLoss() || event.getCause() != BountyCause.AUTO_BOUNTY || !arenaManager.isInMatch(event.getBounty().getTarget().getPlayer())) {
3746
return;
3847
}
3948

duels-plugin/src/main/java/me/realized/duels/queue/Queue.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ boolean removePlayer(final Player player) {
6767
return false;
6868
}
6969

70-
void removeAll(final Set<QueueEntry> players) {
71-
this.players.removeAll(players);
72-
update();
70+
boolean removeAll(final Set<QueueEntry> players) {
71+
return this.players.removeAll(players);
7372
}
7473

7574
private void update() {

duels-plugin/src/main/java/me/realized/duels/queue/QueueManager.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,13 @@ public void handleLoad() throws Exception {
155155
}
156156
}
157157

158-
queue.removeAll(remove);
158+
if (queue.removeAll(remove) && !update) {
159+
update = true;
160+
}
161+
}
162+
163+
if (update) {
164+
gui.calculatePages();
159165
}
160166
}, 20L, 40L).getTaskId();
161167
}

duels-plugin/src/main/java/me/realized/duels/util/compat/CompatBase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class CompatBase {
3939
static Class<?> TITLE_ACTIONS;
4040
static final Class<?> CHAT_SERIALIZER;
4141

42+
static final Field CB_INVENTORY;
43+
static final Field CB_INVENTORY_TITLE;
44+
4245
static {
4346
final Class<?> CB_ITEMSTACK = ReflectionUtil.getCBClass("inventory.CraftItemStack");
4447
final Class<?> NMS_ITEMSTACK = ReflectionUtil.getNMSClass("ItemStack");
@@ -85,5 +88,8 @@ class CompatBase {
8588
}
8689

8790
CHAT_SERIALIZER = !pre1_8 ? ReflectionUtil.getNMSClass("ChatComponentText") : null;
91+
92+
CB_INVENTORY = ReflectionUtil.getDeclaredField(ReflectionUtil.getCBClass("inventory.CraftInventory"), "inventory");
93+
CB_INVENTORY_TITLE = ReflectionUtil.getDeclaredField(ReflectionUtil.getCBClass("inventory.CraftInventoryCustom$MinecraftInventory"), "title");
8894
}
8995
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package me.realized.duels.util.compat;
2+
3+
import org.bukkit.inventory.Inventory;
4+
5+
public final class Inventories extends CompatBase {
6+
7+
public static void setTitle(final Inventory inventory, final String title) {
8+
try {
9+
CB_INVENTORY_TITLE.set(CB_INVENTORY.get(inventory), title);
10+
} catch (IllegalAccessException ex) {
11+
ex.printStackTrace();
12+
}
13+
}
14+
15+
private Inventories() {}
16+
}

duels-plugin/src/main/java/me/realized/duels/util/compat/ReflectionUtil.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,15 @@ public static Field getField(final Class<?> clazz, final String name) {
6565
return null;
6666
}
6767
}
68+
69+
public static Field getDeclaredField(final Class<?> clazz, final String name) {
70+
try {
71+
final Field field = clazz.getDeclaredField(name);
72+
field.setAccessible(true);
73+
return field;
74+
} catch (NoSuchFieldException ex) {
75+
Log.error(ex.getMessage(), ex);
76+
return null;
77+
}
78+
}
6879
}

duels-plugin/src/main/java/me/realized/duels/util/gui/AbstractGui.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ public void set(final Inventory inventory, final int from, final int to, final B
5656
Slots.run(from, to, slot -> set(inventory, slot, button));
5757
}
5858

59+
public void remove(final Inventory inventory) {
60+
buttons.remove(inventory);
61+
}
62+
63+
public Button<P> remove(final Inventory inventory, final int slot) {
64+
final Map<Integer, Button<P>> buttons;
65+
return (buttons = this.buttons.get(inventory)) != null ? buttons.remove(slot) : null;
66+
}
67+
5968
public void update(final Player player, final Inventory inventory, final Button<P> button) {
6069
final Map<Integer, Button<P>> cached = buttons.get(inventory);
6170

0 commit comments

Comments
 (0)