Skip to content

Commit

Permalink
correct values (oops)
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 22, 2024
1 parent 154f1fd commit f418111
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,17 @@

public class InventoryActionLag implements AnarchyExploitFixesModule, Listener {

private final Map<InventoryAction, Integer> clickActionLimits;
private final Map<InventoryAction, Integer> clickActionLimits = new HashMap<>();
private final Cache<UUID, Map<InventoryAction, Integer>> entityInventoryClicks;
private final Cache<Location, Map<InventoryAction, Integer>> blockInventoryClicks;
private final boolean logIsEnabled;

public InventoryActionLag() {
shouldEnable();
this.clickActionLimits = new HashMap<>();
Config config = AnarchyExploitFixes.getConfiguration();
config.addComment("lag-preventions.prevent-inventory-action-lag.enable", """
Prevent lag generated by players quickly moving big items back and forth between inventories.\s
Uses cached counters that auto-reset after the configurable time in milliseconds.\s
Format is: InventoryClickAction: AllowedClicksPerTime""");
Uses cached counters that auto-reset after the configurable time in milliseconds.""");
this.logIsEnabled = config.getBoolean("lag-preventions.prevent-inventory-action-lag.log", true);
Duration cacheTime = Duration.ofMillis(FastMath.max(config.getInt("lag-preventions.prevent-inventory-action-lag.cache-time-millis", 2000,
"The amount of time in milliseconds an entry is kept after writing."), 1));
Expand All @@ -48,9 +46,10 @@ public InventoryActionLag() {
Map<String, Object> defaults = new HashMap<>();
defaults.put("COLLECT_TO_CURSOR", 5);
defaults.put("MOVE_TO_OTHER_INVENTORY", 5);
defaults.put("HOTBAR_SWAP", 5);
ConfigSection section = config.getConfigSection("lag-preventions.prevent-inventory-action-lag.click-action-limits", defaults,
"Use correct enums from: https://jd.papermc.io/paper/1.20/org/bukkit/event/inventory/InventoryAction.html.");
defaults.put("HOTBAR_SWAP", 10);
ConfigSection section = config.getConfigSection("lag-preventions.prevent-inventory-action-lag.click-action-limits", defaults, """
Use correct enums from: https://jd.papermc.io/paper/1.20/org/bukkit/event/inventory/InventoryAction.html.\s
Format is: InventoryClickAction: AllowedClicksPerTime""");
for (String configuredAction : section.getKeys(false)) {
try {
InventoryAction action = InventoryAction.valueOf(configuredAction);
Expand Down Expand Up @@ -83,8 +82,7 @@ public void enable() {

@Override
public boolean shouldEnable() {
return AnarchyExploitFixes.getConfiguration().getBoolean("lag-preventions.prevent-inventory-action-lag.enable", false)
&& !clickActionLimits.isEmpty();
return AnarchyExploitFixes.getConfiguration().getBoolean("lag-preventions.prevent-inventory-action-lag.enable", false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public void onPacketReceiving(PacketEvent event) {
}

switch (this.getClickType(packet)) {
case SWAP, PICKUP, PICKUP_ALL, CLONE -> {
case SWAP, PICKUP_ALL -> {
event.setCancelled(true);
}
case QUICK_MOVE -> {
case THROW -> {
event.setCancelled(slot == -1);
}
case QUICK_CRAFT, THROW -> {
case QUICK_MOVE -> {
event.setCancelled(slot == -999);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@

public class InventoryActionLag implements AnarchyExploitFixesModule, Listener {

private final Map<InventoryAction, Integer> clickActionLimits;
private final Map<InventoryAction, Integer> clickActionLimits = new HashMap<>();
private final Cache<UUID, Map<InventoryAction, Integer>> entityInventoryClicks;
private final Cache<Location, Map<InventoryAction, Integer>> blockInventoryClicks;
private final boolean logIsEnabled;

public InventoryActionLag() {
shouldEnable();
this.clickActionLimits = new HashMap<>();
Config config = AnarchyExploitFixes.getConfiguration();
config.addComment("lag-preventions.prevent-inventory-action-lag.enable",
"Prevent lag generated by players quickly moving big items back and forth between inventories.\n" +
"Uses cached counters that auto-reset after the configurable time in milliseconds.\n" +
"Format is: InventoryClickAction: AllowedClicksPerTime");
"Uses cached counters that auto-reset after the configurable time in milliseconds.");
this.logIsEnabled = config.getBoolean("lag-preventions.prevent-inventory-action-lag.log", true);
Duration cacheTime = Duration.ofMillis(FastMath.max(config.getInt("lag-preventions.prevent-inventory-action-lag.cache-time-millis", 2000,
"The amount of time in milliseconds an entry is kept after writing."), 1));
Expand All @@ -47,9 +45,10 @@ public InventoryActionLag() {
Map<String, Object> defaults = new HashMap<>();
defaults.put("COLLECT_TO_CURSOR", 5);
defaults.put("MOVE_TO_OTHER_INVENTORY", 5);
defaults.put("HOTBAR_SWAP", 5);
defaults.put("HOTBAR_SWAP", 10);
ConfigSection section = config.getConfigSection("lag-preventions.prevent-inventory-action-lag.click-action-limits", defaults,
"Use correct enums from: https://jd.papermc.io/paper/1.12/org/bukkit/event/inventory/InventoryAction.html.");
"Use correct enums from: https://jd.papermc.io/paper/1.12/org/bukkit/event/inventory/InventoryAction.html.\n" +
"Format is: InventoryClickAction: AllowedClicksPerTime");
for (String configuredAction : section.getKeys(false)) {
try {
InventoryAction action = InventoryAction.valueOf(configuredAction);
Expand Down Expand Up @@ -82,8 +81,7 @@ public void enable() {

@Override
public boolean shouldEnable() {
return AnarchyExploitFixes.getConfiguration().getBoolean("lag-preventions.prevent-inventory-action-lag.enable", false)
&& !clickActionLimits.isEmpty();
return AnarchyExploitFixes.getConfiguration().getBoolean("lag-preventions.prevent-inventory-action-lag.enable", false);
}

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,11 @@ public void onPacketReceiving(PacketEvent event) {

switch (this.getClickType(packet)) {
case SWAP:
case PICKUP:
case PICKUP_ALL:
case CLONE:
event.setCancelled(true);
case QUICK_MOVE:
event.setCancelled(slot == -1);
case QUICK_CRAFT:
case THROW:
event.setCancelled(slot == -1);
case QUICK_MOVE:
event.setCancelled(slot == -999);
}
} catch (Exception e) {
Expand Down

0 comments on commit f418111

Please sign in to comment.