enchanted apple cooldown

This commit is contained in:
ImproperIssues
2023-05-06 16:33:30 -07:00
parent ab3f1dc4e2
commit ace526af6a
5 changed files with 31 additions and 4 deletions

View File

@@ -2,22 +2,49 @@ package fun.ogre.ogredupealias.events;
import fun.ogre.ogredupealias.data.PlacedStructures;
import fun.ogre.ogredupealias.plugin.InventoryPresets;
import fun.ogre.ogredupealias.utils.Cooldown;
import fun.ogre.ogredupealias.utils.Text;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import java.util.UUID;
public class InteractionListener implements Listener {
private static final Cooldown<UUID> aAppleCooldown = new Cooldown<>();
@EventHandler
public void onClick(PlayerInteractEvent e) {
try {
this.processTable(e);
this.handleEApples(e);
}
catch (Exception ignore) {}
}
private void handleEApples(PlayerInteractEvent e) {
final Player p = e.getPlayer();
final ItemStack item = e.getItem();
final Action a = e.getAction();
if (!a.name().contains("RIGHT_CLICK")) return;
if (item == null) return;
if (item.getType() != Material.ENCHANTED_GOLDEN_APPLE) return;
if (aAppleCooldown.isOnCooldown(p.getUniqueId())) {
e.setCancelled(true);
p.sendMessage(Text.ofAll("&cEnchanted Golden Apples are on cooldown!"));
return;
}
aAppleCooldown.setCooldown(p.getUniqueId(), 30 * 1000);
}
private void processTable(PlayerInteractEvent e) {
final Player p = e.getPlayer();
final Block b = e.getClickedBlock();

View File

@@ -8,7 +8,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
public abstract class ArrayUtils {
public final class ArrayUtils {
/**
* Transforms an array to another one

View File

@@ -9,7 +9,7 @@ import org.bukkit.inventory.meta.SkullMeta;
import java.util.UUID;
public abstract class ItemUtils {
public final class ItemUtils {
public static String nbtOf(ItemStack item) {
if (item == null || item.getType().isAir()) return "air{}";

View File

@@ -6,7 +6,7 @@ import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
public abstract class SoundUtils {
public final class SoundUtils {
private static final Map<String,Long> cooldown = new HashMap<>();

View File

@@ -1,6 +1,6 @@
package fun.ogre.ogredupealias.utils;
public abstract class StringUtils {
public final class StringUtils {
public static String capitalize(String s) {
if (s.length() == 1) return s.toUpperCase();