Skip to content

Commit

Permalink
Fix part 1/2 of Github #10
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasDeBruijn committed May 26, 2021
1 parent adeb0c4 commit b631c11
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pluginVersion = 2.2.3
pluginVersion = 2.2.4
pluginGroup = nl.thedutchmc.harotorch
pluginName = HaroTorch
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<String> mobExclusionList = this.getConfig().getStringList("mobsExcludeFromBlockList");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,8 +22,23 @@

public class HighlightAreaOfEffectExecutor {

private static HashMap<UUID, Long> 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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,6 +18,8 @@

public class HighlightExecutor {

private static HashMap<UUID, Long> lastCommandTimestamps = new HashMap<>();

private static Class<?> craftPlayerClass;
private static Class<?> craftWorldClass;
private static Class<?> worldClass;
Expand Down Expand Up @@ -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<Location> nearbyTorches = TorchHandler.getTorchLocationsNearPlayer((Player) sender, HaroTorch.getConfigHandler().torchHighlightRange);
Player p = (Player) sender;

Expand Down
11 changes: 10 additions & 1 deletion src/main/java/nl/thedutchmc/harotorch/torch/TorchHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -123,7 +124,15 @@ public static List<Location> getTorchLocationsNearPlayer(Player player, int radi
for(Map.Entry<Location, Torch> 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);
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@ mobsExcludeFromBlockList:

# How many torches are players allowed to place down
# Set to -1 to disable
torchPlaceLimit: -1
torchPlaceLimit: -1


# Command cooldown in seconds. Default: 30. -1 to disable.
commandCooldown: 30
1 change: 1 addition & 0 deletions src/main/resources/en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b631c11

Please sign in to comment.