From b631c1135b2b4a53528864ac244f76c49ec7e4ae Mon Sep 17 00:00:00 2001 From: Tobias de Bruijn Date: Wed, 26 May 2021 14:11:26 +0200 Subject: [PATCH] Fix part 1/2 of Github #10 --- gradle.properties | 2 +- .../harotorch/ConfigurationHandler.java | 3 ++- .../HighlightAreaOfEffectExecutor.java | 17 +++++++++++++++++ .../torchSubCmds/HighlightExecutor.java | 17 +++++++++++++++++ .../harotorch/torch/TorchHandler.java | 11 ++++++++++- src/main/resources/config.yml | 6 +++++- src/main/resources/en.properties | 1 + src/main/resources/plugin.yml | 1 + 8 files changed, 54 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index dfc8d14..632da7b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ -pluginVersion = 2.2.3 +pluginVersion = 2.2.4 pluginGroup = nl.thedutchmc.harotorch pluginName = HaroTorch \ No newline at end of file diff --git a/src/main/java/nl/thedutchmc/harotorch/ConfigurationHandler.java b/src/main/java/nl/thedutchmc/harotorch/ConfigurationHandler.java index f3c5441..af34801 100644 --- a/src/main/java/nl/thedutchmc/harotorch/ConfigurationHandler.java +++ b/src/main/java/nl/thedutchmc/harotorch/ConfigurationHandler.java @@ -20,7 +20,7 @@ public class ConfigurationHandler { public String torchBlock, activeLang; public Boolean enableTorchParticles, allowRemoveNotOwnedTorch, onlyBlockHostileMobs; - public Integer torchRange, torchHighlightRange, torchHighlightTime, torchAoeParticleHeight; + public Integer torchRange, torchHighlightRange, torchHighlightTime, torchAoeParticleHeight, commandCooldown; /** * Indicates how many torches a player may place. If null or -1, it should be disabled. @@ -77,6 +77,7 @@ public void readConfig() { torchHighlightTime = this.getConfig().getInt("torchHighlightTime"); torchAoeParticleHeight = this.getConfig().getInt("torchAoeParticleHeight"); torchPlaceLimit = this.getConfig().getInt("torchPlaceLimit"); + commandCooldown = this.getConfig().getInt("commandCooldown"); //Mob exclusion list parsing List mobExclusionList = this.getConfig().getStringList("mobsExcludeFromBlockList"); diff --git a/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HighlightAreaOfEffectExecutor.java b/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HighlightAreaOfEffectExecutor.java index ac2635c..74c533e 100644 --- a/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HighlightAreaOfEffectExecutor.java +++ b/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HighlightAreaOfEffectExecutor.java @@ -1,7 +1,9 @@ package nl.thedutchmc.harotorch.commands.torchSubCmds; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.UUID; import org.bukkit.Color; import org.bukkit.Location; @@ -20,8 +22,23 @@ public class HighlightAreaOfEffectExecutor { + private static HashMap lastCommandTimestamps = new HashMap<>(); + public static boolean aoe(CommandSender sender, HaroTorch plugin) { + Integer commandCooldown = HaroTorch.getConfigHandler().commandCooldown; + if(commandCooldown != null && commandCooldown > 0) { + Long lastCommandUseTimestamp = lastCommandTimestamps.get(((Player) sender).getUniqueId()); + if(lastCommandUseTimestamp != null) { + if(lastCommandUseTimestamp >= System.currentTimeMillis()) { + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + LangHandler.activeLang.getLangMessages().get("commandCooldown")); + return true; + } + } + + lastCommandTimestamps.put(((Player) sender).getUniqueId(), System.currentTimeMillis() + (commandCooldown * 1000)); + } + String msg = LangHandler.activeLang.getLangMessages().get("startingAoe").replaceAll("%SECONDS%", ChatColor.RED + String.valueOf(HaroTorch.getConfigHandler().torchHighlightTime) + ChatColor.GOLD); sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + msg); diff --git a/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HighlightExecutor.java b/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HighlightExecutor.java index 4bff73f..a9c5aaf 100644 --- a/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HighlightExecutor.java +++ b/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HighlightExecutor.java @@ -1,7 +1,9 @@ package nl.thedutchmc.harotorch.commands.torchSubCmds; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.UUID; import org.bukkit.Location; import org.bukkit.command.CommandSender; @@ -16,6 +18,8 @@ public class HighlightExecutor { + private static HashMap lastCommandTimestamps = new HashMap<>(); + private static Class craftPlayerClass; private static Class craftWorldClass; private static Class worldClass; @@ -65,6 +69,19 @@ public class HighlightExecutor { public static boolean highlight(CommandSender sender, String[] args, HaroTorch plugin) { + Integer commandCooldown = HaroTorch.getConfigHandler().commandCooldown; + if(commandCooldown != null && commandCooldown > 0) { + Long lastCommandUseTimestamp = lastCommandTimestamps.get(((Player) sender).getUniqueId()); + if(lastCommandUseTimestamp != null) { + if(lastCommandUseTimestamp >= System.currentTimeMillis()) { + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + LangHandler.activeLang.getLangMessages().get("commandCooldown")); + return true; + } + } + + lastCommandTimestamps.put(((Player) sender).getUniqueId(), System.currentTimeMillis() + (commandCooldown * 1000)); + } + List nearbyTorches = TorchHandler.getTorchLocationsNearPlayer((Player) sender, HaroTorch.getConfigHandler().torchHighlightRange); Player p = (Player) sender; diff --git a/src/main/java/nl/thedutchmc/harotorch/torch/TorchHandler.java b/src/main/java/nl/thedutchmc/harotorch/torch/TorchHandler.java index 93abd39..200f273 100644 --- a/src/main/java/nl/thedutchmc/harotorch/torch/TorchHandler.java +++ b/src/main/java/nl/thedutchmc/harotorch/torch/TorchHandler.java @@ -9,6 +9,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.NamespacedKey; +import org.bukkit.World; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -123,7 +124,15 @@ public static List getTorchLocationsNearPlayer(Player player, int radi for(Map.Entry entry : torches.entrySet()) { Location l = entry.getKey(); - if(!l.getWorld().getName().equals(player.getLocation().getWorld().getName())) continue; + World playerWorld = player.getLocation().getWorld(); + //Issue #9 + if(playerWorld == null || l.getWorld() == null) { + continue; + } + + if(!l.getWorld().getName().equals(playerWorld.getName())) { + continue; + } if(l.distanceSquared(player.getLocation()) < Math.pow(radius, 2)) { result.add(l); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e2d8bb4..f7e9dc5 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -67,4 +67,8 @@ mobsExcludeFromBlockList: # How many torches are players allowed to place down # Set to -1 to disable -torchPlaceLimit: -1 \ No newline at end of file +torchPlaceLimit: -1 + + +# Command cooldown in seconds. Default: 30. -1 to disable. +commandCooldown: 30 \ No newline at end of file diff --git a/src/main/resources/en.properties b/src/main/resources/en.properties index aa20e05..2eff678 100644 --- a/src/main/resources/en.properties +++ b/src/main/resources/en.properties @@ -5,6 +5,7 @@ goodbye=Thank you for using HaroTorch! commandOnlyForPlayers=This command can only be used by Players! noPermission=You do not have permission to use this command! missingArguments=Missing arguments! Use %HELP_COMMAND% for help! +commandCooldown=Slow down. You're running commands too quickly! #GiveExecutor quantityNaN=The given quantity is not a number! diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 03aa6a1..5ac4b11 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,6 +3,7 @@ name: HaroTorch-V2 author: TheDutchMC76 api-version: 1.16 description: HaroTorch is a plugin which adds the HaroTorch, a block which blocks mob spawns in a configurable radius. +softdepend: [Multiverse-Core] version: @version@ commands: torch: