enchanted apple cooldown
This commit is contained in:
@@ -2,22 +2,49 @@ package fun.ogre.ogredupealias.events;
|
|||||||
|
|
||||||
import fun.ogre.ogredupealias.data.PlacedStructures;
|
import fun.ogre.ogredupealias.data.PlacedStructures;
|
||||||
import fun.ogre.ogredupealias.plugin.InventoryPresets;
|
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.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class InteractionListener implements Listener {
|
public class InteractionListener implements Listener {
|
||||||
|
|
||||||
|
private static final Cooldown<UUID> aAppleCooldown = new Cooldown<>();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onClick(PlayerInteractEvent e) {
|
public void onClick(PlayerInteractEvent e) {
|
||||||
try {
|
try {
|
||||||
this.processTable(e);
|
this.processTable(e);
|
||||||
|
this.handleEApples(e);
|
||||||
}
|
}
|
||||||
catch (Exception ignore) {}
|
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) {
|
private void processTable(PlayerInteractEvent e) {
|
||||||
final Player p = e.getPlayer();
|
final Player p = e.getPlayer();
|
||||||
final Block b = e.getClickedBlock();
|
final Block b = e.getClickedBlock();
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public abstract class ArrayUtils {
|
public final class ArrayUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms an array to another one
|
* Transforms an array to another one
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import org.bukkit.inventory.meta.SkullMeta;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public abstract class ItemUtils {
|
public final class ItemUtils {
|
||||||
|
|
||||||
public static String nbtOf(ItemStack item) {
|
public static String nbtOf(ItemStack item) {
|
||||||
if (item == null || item.getType().isAir()) return "air{}";
|
if (item == null || item.getType().isAir()) return "air{}";
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import org.bukkit.entity.Player;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class SoundUtils {
|
public final class SoundUtils {
|
||||||
|
|
||||||
private static final Map<String,Long> cooldown = new HashMap<>();
|
private static final Map<String,Long> cooldown = new HashMap<>();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package fun.ogre.ogredupealias.utils;
|
package fun.ogre.ogredupealias.utils;
|
||||||
|
|
||||||
public abstract class StringUtils {
|
public final class StringUtils {
|
||||||
|
|
||||||
public static String capitalize(String s) {
|
public static String capitalize(String s) {
|
||||||
if (s.length() == 1) return s.toUpperCase();
|
if (s.length() == 1) return s.toUpperCase();
|
||||||
|
|||||||
Reference in New Issue
Block a user