Skip to content

Commit

Permalink
add option to update inv on cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Aug 21, 2024
1 parent fd20a39 commit c4d5e3c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.cryptomorin.xseries.XEntityType;
import me.xginko.aef.modules.AEFModule;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
Expand All @@ -23,10 +24,13 @@ public class SilentSwapDelay extends AEFModule implements Listener {

private final Map<UUID, Long> swapItemCooldowns;
private final long cooldownNanos;
private final boolean updateInventory;

public SilentSwapDelay() {
super("combat.silent-swap-delay");
this.swapItemCooldowns = new ConcurrentHashMap<>();
this.updateInventory = config.getBoolean(configPath + ".update-inventory-on-cancel", false,
"Can help with desync but recommended to leave off unless you have issues.");
this.cooldownNanos = TimeUnit.MILLISECONDS.toNanos(
config.getLong(configPath + ".min-swap-delay-millis", 40L,"""
The delay in millis a player cant swap hotbar items after placing
Expand Down Expand Up @@ -55,6 +59,7 @@ private void onPlayerItemHeld(PlayerItemHeldEvent event) { // Fired when a hot b

if (swapItemCooldowns.get(event.getPlayer().getUniqueId()) > System.nanoTime()) {
event.setCancelled(true);
if (updateInventory) event.getPlayer().updateInventory();
}
}

Expand All @@ -64,6 +69,7 @@ private void onInventoryInteract(InventoryInteractEvent event) {

if (swapItemCooldowns.get(event.getWhoClicked().getUniqueId()) > System.nanoTime()) {
event.setCancelled(true);
if (updateInventory) ((Player) event.getWhoClicked()).updateInventory();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.cryptomorin.xseries.XEntityType;
import me.xginko.aef.modules.AEFModule;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
Expand All @@ -23,10 +24,13 @@ public class SilentSwapDelay extends AEFModule implements Listener {

private final Map<UUID, Long> swapItemCooldowns;
private final long cooldownNanos;
private final boolean updateInventory;

public SilentSwapDelay() {
super("combat.silent-swap-delay");
this.swapItemCooldowns = new ConcurrentHashMap<>();
this.updateInventory = config.getBoolean(configPath + ".update-inventory-on-cancel", false,
"Can help with desync but recommended to leave off unless you have issues.");
this.cooldownNanos = TimeUnit.MILLISECONDS.toNanos(
config.getLong(configPath + ".min-swap-delay-millis", 40L,
"The delay in millis a player cant swap hotbar items after placing\n" +
Expand Down Expand Up @@ -55,6 +59,7 @@ private void onPlayerItemHeld(PlayerItemHeldEvent event) { // Fired when a hot b

if (swapItemCooldowns.get(event.getPlayer().getUniqueId()) > System.nanoTime()) {
event.setCancelled(true);
if (updateInventory) event.getPlayer().updateInventory();
}
}

Expand All @@ -64,6 +69,7 @@ private void onInventoryInteract(InventoryInteractEvent event) {

if (swapItemCooldowns.get(event.getWhoClicked().getUniqueId()) > System.nanoTime()) {
event.setCancelled(true);
if (updateInventory) ((Player) event.getWhoClicked()).updateInventory();
}
}

Expand Down

0 comments on commit c4d5e3c

Please sign in to comment.