Skip to content

Commit 47b7ab1

Browse files
committed
Fix max cost unsetting on modern versions
Presumably this is due to a bug in the AnvilView impl, but unsure.
1 parent 15060ec commit 47b7ab1

File tree

2 files changed

+7
-25
lines changed

2 files changed

+7
-25
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>com.github.jikoo</groupId>
88
<artifactId>anvilunlocker</artifactId>
99
<name>AnvilUnlocker</name>
10-
<version>1.1.0</version>
10+
<version>1.1.1-SNAPSHOT</version>
1111

1212
<properties>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -36,13 +36,13 @@
3636
<dependency>
3737
<groupId>com.comphenix.protocol</groupId>
3838
<artifactId>ProtocolLib</artifactId>
39-
<version>4.8.0</version>
39+
<version>5.3.0</version>
4040
<scope>provided</scope>
4141
</dependency>
4242
<dependency>
4343
<groupId>org.jetbrains</groupId>
4444
<artifactId>annotations</artifactId>
45-
<version>23.0.0</version>
45+
<version>26.0.1</version>
4646
<!-- Annotations is only used during compilation. -->
4747
<scope>provided</scope>
4848
</dependency>

src/main/java/com/github/jikoo/anvilunlocker/AnvilUnlocker.java

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
import com.comphenix.protocol.PacketType;
44
import com.comphenix.protocol.ProtocolLibrary;
55
import com.comphenix.protocol.events.PacketContainer;
6-
import java.lang.reflect.InvocationTargetException;
76
import org.bukkit.GameMode;
87
import org.bukkit.Material;
98
import org.bukkit.entity.Player;
109
import org.bukkit.event.EventHandler;
1110
import org.bukkit.event.EventPriority;
1211
import org.bukkit.event.Listener;
1312
import org.bukkit.event.inventory.InventoryCloseEvent;
14-
import org.bukkit.event.inventory.InventoryOpenEvent;
1513
import org.bukkit.event.inventory.PrepareAnvilEvent;
1614
import org.bukkit.inventory.AnvilInventory;
1715
import org.bukkit.inventory.ItemStack;
@@ -37,20 +35,6 @@ public void reloadConfig() {
3735
maximumCost = constrainAnvilMax(getConfig().getInt("maximumCost"));
3836
}
3937

40-
@EventHandler(priority = EventPriority.MONITOR)
41-
private void onInventoryOpen(@NotNull InventoryOpenEvent event) {
42-
if (!(event.getInventory() instanceof AnvilInventory)) {
43-
return;
44-
}
45-
46-
((AnvilInventory) event.getInventory()).setMaximumRepairCost(maximumCost);
47-
48-
if (event.getPlayer() instanceof Player
49-
&& event.getPlayer().getGameMode() != GameMode.CREATIVE) {
50-
setInstantBuild((Player) event.getPlayer(), true);
51-
}
52-
}
53-
5438
@EventHandler(priority = EventPriority.MONITOR)
5539
private void onInventoryClose(@NotNull InventoryCloseEvent event) {
5640
if (event.getInventory() instanceof AnvilInventory
@@ -67,8 +51,10 @@ private void onPrepareAnvil(@NotNull PrepareAnvilEvent event) {
6751
return;
6852
}
6953

54+
AnvilInventory anvil = event.getInventory();
55+
anvil.setMaximumRepairCost(maximumCost);
56+
7057
getServer().getScheduler().runTask(this, () -> {
71-
AnvilInventory anvil = event.getInventory();
7258
ItemStack input2 = anvil.getItem(1);
7359
setInstantBuild(
7460
(Player) event.getView().getPlayer(),
@@ -88,11 +74,7 @@ public void setInstantBuild(@NotNull Player player, boolean instantBuild) {
8874
packet.getFloat().write(0, player.getFlySpeed() / 2);
8975
packet.getFloat().write(1, player.getWalkSpeed() / 2);
9076

91-
try {
92-
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
93-
} catch (InvocationTargetException e) {
94-
e.printStackTrace();
95-
}
77+
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
9678
}
9779

9880
private static int constrainAnvilMax(int actual) {

0 commit comments

Comments
 (0)