-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use packetlistener for illegal checks
- Loading branch information
Showing
4 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...acy/src/main/java/me/moomoo/anarchyexploitfixes/events/PacketPlayerAttackEntityEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package me.moomoo.anarchyexploitfixes.events; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Cancellable; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.HandlerList; | ||
import org.bukkit.inventory.EquipmentSlot; | ||
|
||
public class PacketPlayerAttackEntityEvent extends Event implements Cancellable { | ||
|
||
private static final HandlerList handlers = new HandlerList(); | ||
private boolean isCancelled = false; | ||
|
||
private final Player player; | ||
private final EquipmentSlot hand; | ||
|
||
public PacketPlayerAttackEntityEvent(Player player, EquipmentSlot hand) { | ||
this.player = player; | ||
this.hand = hand; | ||
} | ||
|
||
public PacketPlayerAttackEntityEvent(boolean isAsync, Player player, EquipmentSlot hand) { | ||
super(isAsync); | ||
this.player = player; | ||
this.hand = hand; | ||
} | ||
|
||
public Player getPlayer() { | ||
return player; | ||
} | ||
|
||
public EquipmentSlot getHand() { | ||
return hand; | ||
} | ||
|
||
@Override | ||
public void setCancelled(boolean cancel) { | ||
isCancelled = cancel; | ||
} | ||
|
||
@Override | ||
public boolean isCancelled() { | ||
return isCancelled; | ||
} | ||
|
||
@Override | ||
public HandlerList getHandlers() { | ||
return handlers; | ||
} | ||
|
||
public static HandlerList getHandlerList() { | ||
return handlers; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...yExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/listener/AEFListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package me.moomoo.anarchyexploitfixes.listener; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public interface AEFListener { | ||
|
||
boolean shouldEnable(); | ||
void enable(); | ||
void disable(); | ||
|
||
Set<AEFListener> LISTENERS = new HashSet<>(); | ||
|
||
static void reloadListeners() { | ||
LISTENERS.forEach(AEFListener::disable); | ||
LISTENERS.clear(); | ||
|
||
LISTENERS.add(new InteractEntityPacketListener()); | ||
|
||
for (AEFListener listener : LISTENERS) { | ||
if (listener.shouldEnable()) { | ||
listener.enable(); | ||
} | ||
} | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
...cy/src/main/java/me/moomoo/anarchyexploitfixes/listener/InteractEntityPacketListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package me.moomoo.anarchyexploitfixes.listener; | ||
|
||
import com.github.retrooper.packetevents.PacketEvents; | ||
import com.github.retrooper.packetevents.event.PacketListenerAbstract; | ||
import com.github.retrooper.packetevents.event.PacketListenerPriority; | ||
import com.github.retrooper.packetevents.event.PacketReceiveEvent; | ||
import com.github.retrooper.packetevents.protocol.packettype.PacketType; | ||
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity; | ||
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; | ||
import me.moomoo.anarchyexploitfixes.events.PacketPlayerAttackEntityEvent; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.EquipmentSlot; | ||
|
||
public final class InteractEntityPacketListener extends PacketListenerAbstract implements AEFListener { | ||
|
||
public InteractEntityPacketListener() { | ||
super(PacketListenerPriority.HIGHEST); | ||
} | ||
|
||
@Override | ||
public boolean shouldEnable() { | ||
return !AnarchyExploitFixes.getConfiguration().packet_events_disabled; | ||
} | ||
|
||
@Override | ||
public void enable() { | ||
PacketEvents.getAPI().getEventManager().registerListener(this); | ||
} | ||
|
||
@Override | ||
public void disable() { | ||
PacketEvents.getAPI().getEventManager().unregisterListener(this); | ||
} | ||
|
||
@Override | ||
public void onPacketReceive(PacketReceiveEvent event) { | ||
if (event.getPacketType() != PacketType.Play.Client.INTERACT_ENTITY) return; | ||
if (event.isCancelled()) return; | ||
|
||
WrapperPlayClientInteractEntity packet = new WrapperPlayClientInteractEntity(event); | ||
if (packet.getAction() != WrapperPlayClientInteractEntity.InteractAction.ATTACK) return; | ||
|
||
final PacketPlayerAttackEntityEvent attackEvent = new PacketPlayerAttackEntityEvent( | ||
true, | ||
(Player) event.getPlayer(), | ||
EquipmentSlot.valueOf(packet.getHand().name()) | ||
); | ||
|
||
if (!attackEvent.callEvent()) { | ||
event.setCancelled(true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters