Skip to content

Commit

Permalink
improve enable/disable of swapitemdelay
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 1, 2025
1 parent 22ad86b commit f738988
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,34 @@

public class SilentSwapDelay extends AEFModule implements Listener {

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

private Map<UUID, Long> swapItemCooldowns;

public SilentSwapDelay() {
super("combat.silent-swap-delay", false);
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
a block, clicking a block (for example to place a crystal) or
damaging an entity. (50 ms = 1 tick)"""));
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
a block, clicking a block (for example to place a crystal) or
damaging an entity. (50 ms = 1 tick)"""));
}

@Override
public void enable() {
swapItemCooldowns = new ConcurrentHashMap<>();
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

@Override
public boolean shouldEnable() {
return config.getBoolean(configPath + ".enable", false);
}

@Override
public void disable() {
HandlerList.unregisterAll(this);
if (swapItemCooldowns != null) {
swapItemCooldowns.clear();
swapItemCooldowns = null;
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,34 @@

public class SilentSwapDelay extends AEFModule implements Listener {

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

private Map<UUID, Long> swapItemCooldowns;

public SilentSwapDelay() {
super("combat.silent-swap-delay", false);
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" +
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" +
"a block, clicking a block (for example to place a crystal) or\n" +
"damaging an entity. (50 ms = 1 tick)"));
}

@Override
public void enable() {
swapItemCooldowns = new ConcurrentHashMap<>();
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

@Override
public void disable() {
HandlerList.unregisterAll(this);
if (swapItemCooldowns != null) {
swapItemCooldowns.clear();
swapItemCooldowns = null;
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
Expand Down

0 comments on commit f738988

Please sign in to comment.