Skip to content

Commit

Permalink
Optimize AlwaysSword feature
Browse files Browse the repository at this point in the history
  • Loading branch information
MetallicGoat committed May 23, 2024
1 parent 0dab7a2 commit 3b5fde4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.3</version>
<version>2.11.6</version>
<scope>provided</scope>
</dependency>
<!-- <dependency>-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.scheduler.BukkitTask;

import java.util.HashMap;
import java.util.Map;

public class AlwaysSword implements Listener {

// TODO keep track of running instances
final Map<Player, BukkitTask> runningTasks = new HashMap<>();

@EventHandler
public void onClick(InventoryClickEvent e) {
if (!SwordsToolsConfig.always_sword_drop_enabled)
Expand All @@ -32,7 +37,10 @@ public void onClick(InventoryClickEvent e) {
&& arena.getStatus() == ArenaStatus.RUNNING
&& player.getGameMode() != GameMode.SPECTATOR) {

Bukkit.getServer().getScheduler().runTaskLater((MBedwarsTweaksPlugin.getInstance()), () -> {
if (runningTasks.containsKey(player))
runningTasks.get(player).cancel();

runningTasks.put(player, Bukkit.getServer().getScheduler().runTaskLater((MBedwarsTweaksPlugin.getInstance()), () -> {
final Inventory pi = player.getInventory();
final int i = ToolSwordHelper.getSwordsAmount(player);

Expand All @@ -54,9 +62,10 @@ public void onClick(InventoryClickEvent e) {
(e.getCursor() == null || e.getCursor() != null && !e.getCursor().getType().name().endsWith("SWORD") && ToolSwordHelper.isNotToIgnore(e.getCursor()))) {

pi.addItem(ToolSwordHelper.getDefaultWoodSword(player, arena));

}
}, 25L);

runningTasks.remove(player);
}, 25L));
}
}

Expand Down

0 comments on commit 3b5fde4

Please sign in to comment.