Skip to content

Commit

Permalink
fix issues with crafting
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Nov 8, 2023
1 parent a311721 commit 94c1f5a
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion AnarchyExploitFixesFolia/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>me.moomoo.anarchyexploitfixes</groupId>
<artifactId>AnarchyExploitFixes</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>

<artifactId>Folia</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@

public class AntiWindowClickCrash implements AnarchyExploitFixesModule {


public AntiWindowClickCrash() {
Config config = AnarchyExploitFixes.getConfiguration();
config.addComment("patches.window-click-crash-patch.enable", "Patches Container click / Window click crash exploit.");
AnarchyExploitFixes.getConfiguration().addComment("patches.window-click-crash-patch.enable", "Patches Container click / Window click crash exploit.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;

public class WindowClickListener extends PacketAdapter {
Expand All @@ -20,25 +20,27 @@ protected void register() {

@Override
public void onPacketReceiving(PacketEvent event) {
final StructureModifier<Integer> integers = event.getPacket().getIntegers();
if (getButton(integers) < 0 || getSlot(integers) < 0) {
final PacketContainer packet = event.getPacket();
if (!getClickType(packet).equals(InventoryClickType.SWAP)) return;

if (getButton(packet) < 0 || getSlot(packet) < 0) {
event.setCancelled(true);
}
}

private int getSyncId(StructureModifier<Integer> packet) {
return packet.read(0);
private int getSlot(PacketContainer packet) {
return packet.getIntegers().read(2);
}

private int getRevision(StructureModifier<Integer> packet) {
return packet.read(1);
private int getButton(PacketContainer packet) {
return packet.getIntegers().read(3);
}

private int getSlot(StructureModifier<Integer> packet) {
return packet.read(2);
private enum InventoryClickType {
PICKUP, QUICK_MOVE, SWAP, CLONE, THROW, QUICK_CRAFT, PICKUP_ALL;
}

private int getButton(StructureModifier<Integer> packet) {
return packet.read(3);
private InventoryClickType getClickType(PacketContainer packet) {
return packet.getEnumModifier(InventoryClickType.class, 4).read(0);
}
}
2 changes: 1 addition & 1 deletion AnarchyExploitFixesLegacy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>me.moomoo.anarchyexploitfixes</groupId>
<artifactId>AnarchyExploitFixes</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</parent>

<artifactId>Legacy</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public class AntiWindowClickCrash implements AnarchyExploitFixesModule {


public AntiWindowClickCrash() {
Config config = AnarchyExploitFixes.getConfiguration();
config.addComment("patches.window-click-crash-patch.enable", "Patches Container click / Window click crash exploit.");
AnarchyExploitFixes.getConfiguration().addComment("patches.window-click-crash-patch.enable", "Patches Container click / Window click crash exploit.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;

public class WindowClickListener extends PacketAdapter {
Expand All @@ -20,25 +20,27 @@ protected void register() {

@Override
public void onPacketReceiving(PacketEvent event) {
final StructureModifier<Integer> integers = event.getPacket().getIntegers();
if (getButton(integers) < 0 || getSlot(integers) < 0) {
final PacketContainer packet = event.getPacket();
if (!getClickType(packet).equals(InventoryClickType.SWAP)) return;

if (getButton(packet) < 0 || getSlot(packet) < 0) {
event.setCancelled(true);
}
}

private int getSyncId(StructureModifier<Integer> packet) {
return packet.read(0);
private int getSlot(PacketContainer packet) {
return packet.getIntegers().read(2);
}

private int getRevision(StructureModifier<Integer> packet) {
return packet.read(1);
private int getButton(PacketContainer packet) {
return packet.getIntegers().read(3);
}

private int getSlot(StructureModifier<Integer> packet) {
return packet.read(2);
private enum InventoryClickType {
PICKUP, QUICK_MOVE, SWAP, CLONE, THROW, QUICK_CRAFT, PICKUP_ALL;
}

private int getButton(StructureModifier<Integer> packet) {
return packet.read(3);
private InventoryClickType getClickType(PacketContainer packet) {
return packet.getEnumModifier(InventoryClickType.class, 4).read(0);
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.moomoo.anarchyexploitfixes</groupId>
<artifactId>AnarchyExploitFixes</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
<modules>
<module>AnarchyExploitFixesFolia</module>
<module>AnarchyExploitFixesLegacy</module>
Expand Down

0 comments on commit 94c1f5a

Please sign in to comment.