-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
228 additions
and
197 deletions.
There are no files selected for viewing
94 changes: 0 additions & 94 deletions
94
...itFixesFolia/src/main/java/me/xginko/aef/modules/combat/CrystalAuraHotbarSwitchDelay.java
This file was deleted.
Oops, something went wrong.
114 changes: 114 additions & 0 deletions
114
AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/SilentSwapDelay.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,114 @@ | ||
package me.xginko.aef.modules.combat; | ||
|
||
import com.cryptomorin.xseries.XEntityType; | ||
import me.xginko.aef.modules.AEFModule; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.HandlerList; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.block.Action; | ||
import org.bukkit.event.block.BlockPlaceEvent; | ||
import org.bukkit.event.entity.EntityDamageByEntityEvent; | ||
import org.bukkit.event.player.PlayerInteractEvent; | ||
import org.bukkit.event.player.PlayerItemHeldEvent; | ||
import org.bukkit.event.player.PlayerKickEvent; | ||
import org.bukkit.event.player.PlayerQuitEvent; | ||
|
||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
public class SilentSwapDelay extends AEFModule implements Listener { | ||
|
||
private final Map<UUID, PlayerData> playerDataMap; | ||
private final long swapDelayMillis; | ||
|
||
public SilentSwapDelay() { | ||
super("combat.crystal-aura.silent-swap-delay"); | ||
this.playerDataMap = new ConcurrentHashMap<>(); | ||
this.swapDelayMillis = config.getLong(configPath + ".min-swap-delay-millis", 50L, | ||
"The delay in millis a player cant swap hotbar items after placing\n" + | ||
"a block, clicking a block (for example to place a crystal) or\n" + | ||
"damaging an entity. (50 ms = 1 tick)"); | ||
} | ||
|
||
@Override | ||
public void enable() { | ||
plugin.getServer().getPluginManager().registerEvents(this, plugin); | ||
} | ||
|
||
@Override | ||
public boolean shouldEnable() { | ||
return config.getBoolean(configPath + ".enable", false); | ||
} | ||
|
||
@Override | ||
public void disable() { | ||
HandlerList.unregisterAll(this); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
private void onPlayerItemHeld(PlayerItemHeldEvent event) { // Fired when a hot bar item selection changes | ||
PlayerData playerData = playerDataMap.computeIfAbsent(event.getPlayer().getUniqueId(), PlayerData::new); | ||
|
||
if (playerData.lastAttackEntityTimeMillis.get() + swapDelayMillis > System.currentTimeMillis()) { | ||
event.setCancelled(true); | ||
return; | ||
} | ||
|
||
if (playerData.lastInteractBlockTimeMillis.get() + swapDelayMillis > System.currentTimeMillis()) { | ||
event.setCancelled(true); | ||
return; | ||
} | ||
|
||
if (playerData.lastPlaceBlockTimeMillis.get() + swapDelayMillis > System.currentTimeMillis()) { | ||
event.setCancelled(true); | ||
} | ||
} | ||
|
||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
private void onEntityDamageByEntity(EntityDamageByEntityEvent event) { | ||
if (event.getDamager().getType() != XEntityType.PLAYER.get()) return; | ||
|
||
playerDataMap.computeIfAbsent(event.getDamager().getUniqueId(), PlayerData::new) | ||
.lastAttackEntityTimeMillis.set(System.currentTimeMillis()); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
private void onPlayerInteract(PlayerInteractEvent event) { | ||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; | ||
|
||
playerDataMap.computeIfAbsent(event.getPlayer().getUniqueId(), PlayerData::new) | ||
.lastInteractBlockTimeMillis.set(System.currentTimeMillis()); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
private void onBlockPlace(BlockPlaceEvent event) { | ||
playerDataMap.computeIfAbsent(event.getPlayer().getUniqueId(), PlayerData::new) | ||
.lastPlaceBlockTimeMillis.set(System.currentTimeMillis()); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
private void onPlayerQuit(PlayerQuitEvent event) { | ||
playerDataMap.remove(event.getPlayer().getUniqueId()); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
private void onPlayerKicked(PlayerKickEvent event) { | ||
playerDataMap.remove(event.getPlayer().getUniqueId()); | ||
} | ||
|
||
private static class PlayerData { | ||
|
||
public final UUID uuid; | ||
public final AtomicLong lastInteractBlockTimeMillis, lastAttackEntityTimeMillis, lastPlaceBlockTimeMillis; | ||
|
||
public PlayerData(UUID uuid) { | ||
this.uuid = uuid; | ||
this.lastInteractBlockTimeMillis = new AtomicLong(); | ||
this.lastAttackEntityTimeMillis = new AtomicLong(); | ||
this.lastPlaceBlockTimeMillis = new AtomicLong(); | ||
} | ||
} | ||
} |
103 changes: 0 additions & 103 deletions
103
...tFixesLegacy/src/main/java/me/xginko/aef/modules/combat/CrystalAuraHotbarSwitchDelay.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.