-
Notifications
You must be signed in to change notification settings - Fork 9
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
1 parent
6fa8526
commit f272f64
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
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
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
38 changes: 38 additions & 0 deletions
38
src/main/java/me/metallicgoat/tweaksaddon/tweaks/misc/SpecialItemCooldown.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,38 @@ | ||
package me.metallicgoat.tweaksaddon.tweaks.misc; | ||
|
||
import de.marcely.bedwars.api.event.player.PlayerUseSpecialItemEvent; | ||
import me.metallicgoat.tweaksaddon.MBedwarsTweaksPlugin; | ||
import me.metallicgoat.tweaksaddon.config.MainConfig; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
|
||
import java.util.IdentityHashMap; | ||
import java.util.Map; | ||
|
||
public class SpecialItemCooldown implements Listener { | ||
|
||
private final Map<Player, String> cooldownPlayers = new IdentityHashMap<>(); | ||
|
||
@EventHandler (priority = EventPriority.LOW) | ||
public void onSpecialItemUse(PlayerUseSpecialItemEvent event) { | ||
if (MainConfig.special_items_cooldown == 0) | ||
return; | ||
|
||
final String cooldownItemId = cooldownPlayers.get(event.getPlayer()); | ||
final String itemId = event.getSpecialItem().getId(); | ||
|
||
if (cooldownItemId != null && event.getSpecialItem().getId().equals(cooldownItemId)) { | ||
event.setCancelled(true); | ||
return; | ||
} | ||
|
||
cooldownPlayers.put(event.getPlayer(), itemId); | ||
|
||
Bukkit.getScheduler().runTaskLater(MBedwarsTweaksPlugin.getInstance(), () -> { | ||
cooldownPlayers.remove(event.getPlayer()); | ||
}, (long) (20D * MainConfig.special_items_cooldown)); | ||
} | ||
} |