From 72f5039b08506f30b4711df7155790b2863a514b Mon Sep 17 00:00:00 2001 From: TheDutchMC Date: Tue, 6 Oct 2020 22:31:38 +0200 Subject: [PATCH] Added area of effect command, help page and fixed tab completion --- .gitignore | 18 +++ .../torchSubCmds/Highlight_1_16_r2.java | 1 - gradle.properties | 2 +- .../harotorch/ConfigurationHandler.java | 3 +- .../nl/thedutchmc/harotorch/HaroTorch.java | 2 + .../commands/TorchCommandExecutor.java | 28 ++++- .../commands/TorchCommandTabCompleter.java | 31 +++++ .../commands/torchSubCmds/HelpExecutor.java | 22 ++++ .../HighlightAreaOfEffectExecutor.java | 115 ++++++++++++++++++ .../torchSubCmds/VersionExecutor.java | 17 +++ src/main/resources/config.yml | 3 + src/main/resources/plugin.yml | 12 ++ 12 files changed, 250 insertions(+), 4 deletions(-) create mode 100644 .gitignore create mode 100644 src/main/java/nl/thedutchmc/harotorch/commands/TorchCommandTabCompleter.java create mode 100644 src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HelpExecutor.java create mode 100644 src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HighlightAreaOfEffectExecutor.java create mode 100644 src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/VersionExecutor.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e47906c --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +# Ignore Gradle project-specific cache directory +.gradle/ + +# Ignore Gradle build output directory +build/ +releases/ + +# Minecraft +server/ + +# Eclipse +.project +.settings/ +.classpath +bin/ + +#NMS Version directory excludes +Spigot_1_16_R2/bin/ diff --git a/Spigot_1_16_R2/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/Highlight_1_16_r2.java b/Spigot_1_16_R2/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/Highlight_1_16_r2.java index 374a29b..2d8c5f4 100644 --- a/Spigot_1_16_R2/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/Highlight_1_16_r2.java +++ b/Spigot_1_16_R2/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/Highlight_1_16_r2.java @@ -37,7 +37,6 @@ public static List spawnHighlight(Player p, List locations) { nmsEntity.setFlag(6, true); //Glowing nmsEntity.setFlag(5, true); //Invisibility nmsEntity.setSize(2, true); //Set the size of the magma cube to be a full block - nmsEntity.setLocation(loc.getBlockX() + 0.5D, loc.getBlockY(), loc.getBlockZ() + 0.5D, 0f, 0f); PacketPlayOutSpawnEntityLiving spawnPacket = new PacketPlayOutSpawnEntityLiving(nmsEntity); diff --git a/gradle.properties b/gradle.properties index 622a0c3..9157651 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ -pluginVersion = 1.0 +pluginVersion = 2.0 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 49f8ad1..85fb25d 100644 --- a/src/main/java/nl/thedutchmc/harotorch/ConfigurationHandler.java +++ b/src/main/java/nl/thedutchmc/harotorch/ConfigurationHandler.java @@ -16,7 +16,7 @@ public class ConfigurationHandler { public String torchBlock, messageTorchBrokenOwnerMismatch, messageTorchBrokenSuccess, messageTorchPlacedSucccess; public boolean enableTorchParticles; - public int torchRange, torchHighlightRange, torchHighlightTime; + public int torchRange, torchHighlightRange, torchHighlightTime, torchAoeParticleHeight; public List recipeShape; public HashMap recipeKeys = new HashMap<>(); @@ -63,6 +63,7 @@ public void readConfig() { torchRange = this.getConfig().getInt("torchRange"); torchHighlightRange = this.getConfig().getInt("torchHighlightRange"); torchHighlightTime = this.getConfig().getInt("torchHighlightTime"); + torchAoeParticleHeight = this.getConfig().getInt("torchAoeParticleHeight"); //Recipe parsing recipeShape = this.getConfig().getStringList("recipeShape"); diff --git a/src/main/java/nl/thedutchmc/harotorch/HaroTorch.java b/src/main/java/nl/thedutchmc/harotorch/HaroTorch.java index c925e8f..4265909 100644 --- a/src/main/java/nl/thedutchmc/harotorch/HaroTorch.java +++ b/src/main/java/nl/thedutchmc/harotorch/HaroTorch.java @@ -10,6 +10,7 @@ import net.md_5.bungee.api.ChatColor; import nl.thedutchmc.harotorch.commands.TorchCommandExecutor; +import nl.thedutchmc.harotorch.commands.TorchCommandTabCompleter; import nl.thedutchmc.harotorch.events.BlockBreakEventListener; import nl.thedutchmc.harotorch.events.BlockExplodeEventListener; import nl.thedutchmc.harotorch.events.BlockFromToEventListener; @@ -55,6 +56,7 @@ public void onEnable() { //Commands this.getCommand("torch").setExecutor(new TorchCommandExecutor(this)); + this.getCommand("torch").setTabCompleter(new TorchCommandTabCompleter()); //Scheduler for particles if(CONFIG.enableTorchParticles) { diff --git a/src/main/java/nl/thedutchmc/harotorch/commands/TorchCommandExecutor.java b/src/main/java/nl/thedutchmc/harotorch/commands/TorchCommandExecutor.java index b38cc80..6e23dc3 100644 --- a/src/main/java/nl/thedutchmc/harotorch/commands/TorchCommandExecutor.java +++ b/src/main/java/nl/thedutchmc/harotorch/commands/TorchCommandExecutor.java @@ -7,7 +7,10 @@ import nl.thedutchmc.harotorch.HaroTorch; import nl.thedutchmc.harotorch.commands.torchSubCmds.ConvertExecutor; import nl.thedutchmc.harotorch.commands.torchSubCmds.GiveExecutor; +import nl.thedutchmc.harotorch.commands.torchSubCmds.HelpExecutor; +import nl.thedutchmc.harotorch.commands.torchSubCmds.HighlightAreaOfEffectExecutor; import nl.thedutchmc.harotorch.commands.torchSubCmds.HighlightExecutor; +import nl.thedutchmc.harotorch.commands.torchSubCmds.VersionExecutor; public class TorchCommandExecutor implements CommandExecutor { @@ -26,8 +29,21 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } if(args[0].equalsIgnoreCase("help")) { + if(!sender.hasPermission("harotorch.help")) { + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + "You do not have permission to use this command!"); + return true; + } - return true; + return HelpExecutor.help(sender); + } + + else if(args[0].equalsIgnoreCase("version")) { + if(!sender.hasPermission("harotorch.version")) { + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + "You do not have permission to use this command!"); + return true; + } + + return VersionExecutor.version(sender, plugin); } else if(args[0].equalsIgnoreCase("convert")) { @@ -57,6 +73,16 @@ else if(args[0].equalsIgnoreCase("highlight")) { return HighlightExecutor.highlight(sender, args, plugin); } + else if(args[0].equalsIgnoreCase("aoe")) { + if(!sender.hasPermission("harotorch.aoe")) { + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.RED + "You do not have permission to use this command!"); + return true; + } + + HighlightAreaOfEffectExecutor.aoe(sender, plugin); + + return true; + } return false; } diff --git a/src/main/java/nl/thedutchmc/harotorch/commands/TorchCommandTabCompleter.java b/src/main/java/nl/thedutchmc/harotorch/commands/TorchCommandTabCompleter.java new file mode 100644 index 0000000..2dbb2d2 --- /dev/null +++ b/src/main/java/nl/thedutchmc/harotorch/commands/TorchCommandTabCompleter.java @@ -0,0 +1,31 @@ +package nl.thedutchmc.harotorch.commands; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; + +public class TorchCommandTabCompleter implements TabCompleter { + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + + if(args.length == 1) { + List result = new ArrayList<>(); + if(sender.hasPermission("harotorch.highlight")) result.add("highlight"); + if(sender.hasPermission("harotorch.help")) result.add("help"); + if(sender.hasPermission("harotorch.give")) result.add("give"); + if(sender.hasPermission("harotorch.convert")) result.add("convert"); + if(sender.hasPermission("harotorch.version")) result.add("version"); + if(sender.hasPermission("harotorch.aoe")) result.add("aoe"); + + return result; + } + + List result = new ArrayList<>(); + return result; + } + +} diff --git a/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HelpExecutor.java b/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HelpExecutor.java new file mode 100644 index 0000000..ee8fd35 --- /dev/null +++ b/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HelpExecutor.java @@ -0,0 +1,22 @@ +package nl.thedutchmc.harotorch.commands.torchSubCmds; + +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; + +import nl.thedutchmc.harotorch.HaroTorch; + +public class HelpExecutor { + + public static boolean help(CommandSender sender) { + + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + "HaroTorch help menu"); + sender.sendMessage("- " + ChatColor.GOLD + "/torch help " + ChatColor.WHITE + "Shows you this page."); + sender.sendMessage("- " + ChatColor.GOLD + "/torch highlight " + ChatColor.WHITE + "Highlight all nearby torches."); + sender.sendMessage("- " + ChatColor.GOLD + "/torch give " + ChatColor.WHITE + "Give yourself a HaroTorch."); + sender.sendMessage("- " + ChatColor.GOLD + "/torch convert " + ChatColor.WHITE + "Convert v1 torches to v2 torches."); + sender.sendMessage("- " + ChatColor.GOLD + "/torch version " + ChatColor.WHITE + "Get the HaroTorch and NMS version number."); + + return true; + } + +} diff --git a/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HighlightAreaOfEffectExecutor.java b/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HighlightAreaOfEffectExecutor.java new file mode 100644 index 0000000..0e9f206 --- /dev/null +++ b/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/HighlightAreaOfEffectExecutor.java @@ -0,0 +1,115 @@ +package nl.thedutchmc.harotorch.commands.torchSubCmds; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; + +import net.md_5.bungee.api.ChatColor; +import nl.thedutchmc.harotorch.HaroTorch; +import nl.thedutchmc.harotorch.torch.TorchHandler; + +public class HighlightAreaOfEffectExecutor { + + public static boolean aoe(CommandSender sender, HaroTorch plugin) { + + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + "Showing the area of effect for " + ChatColor.RED + HaroTorch.getConfigHandler().torchHighlightTime + ChatColor.GOLD + " seconds!"); + + List nearbyTorches = TorchHandler.getTorchLocationsNearPlayer((Player) sender, HaroTorch.getConfigHandler().torchHighlightRange); + final List torchParticles = new ArrayList<>(); + + for(Location l : nearbyTorches) { + + final List blocksOnTorchRadius = new ArrayList<>(); + + final int radius = HaroTorch.getConfigHandler().torchRange; + final int cx = l.getBlockX(); + final int cz = l.getBlockZ(); + final World w = l.getWorld(); + + for(int i = 0; i < 360; i++) { + + final double rad = i * ((2 * Math.PI)/360); + + final int x = (int) (cx + (radius * Math.cos(rad))); + final int z = (int) (cz + (radius * Math.sin(rad))); + + final int y = w.getHighestBlockAt(x, z).getY() + 1; + + blocksOnTorchRadius.add(new Location(w, x, y, z)); + } + + final int r = (int) (Math.random() * 256D); + final int g = (int) (Math.random() * 256D); + final int b = (int) (Math.random() * 256D); + + torchParticles.add(new TorchParticleObject(r, g, b, blocksOnTorchRadius, l)); + } + + final BukkitTask particle = new BukkitRunnable() { + + @Override + public void run() { + + for(TorchParticleObject torchParticle : torchParticles) { + + final Location torchLoc = torchParticle.getTorch(); + + torchLoc.getWorld().spawnParticle(Particle.REDSTONE, torchLoc.getX() + 0.5D, torchLoc.getY() + 1.5D, torchLoc.getZ() + 0.5D, 25, 0D, 0D, 0D, 0.005, new Particle.DustOptions(torchParticle.getTorchParticleColor(), 1)); + + for(Location l : torchParticle.getCircleLocations()) { + + for(int i = 0; i < HaroTorch.getConfigHandler().torchAoeParticleHeight; i++) { + torchLoc.getWorld().spawnParticle(Particle.REDSTONE, l.getX() + 0.5D, l.getY() + 0.5D + i, l.getZ() + 0.5D, 5, 0D, 0D, 0D, 0.005, new Particle.DustOptions(torchParticle.getTorchParticleColor(), 1)); + } + } + } + } + + }.runTaskTimer(plugin, 60L, 10L); + + new BukkitRunnable() { + + @Override + public void run() { + particle.cancel(); + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + "Highlighting has ended!"); + } + }.runTaskLater(plugin, 30L * 20L); + + return true; + } + + private static class TorchParticleObject { + + private Color particleColor; + private List circleLocations; + private Location torch; + + public TorchParticleObject(int r, int g, int b, List circleLocations, Location torch) { + this.particleColor = Color.fromRGB(r, g, b); + this.circleLocations = circleLocations; + this.torch = torch; + } + + public Color getTorchParticleColor() { + return this.particleColor; + } + + public List getCircleLocations() { + return this.circleLocations; + } + + public Location getTorch() { + return this.torch; + } + } + +} diff --git a/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/VersionExecutor.java b/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/VersionExecutor.java new file mode 100644 index 0000000..b31502f --- /dev/null +++ b/src/main/java/nl/thedutchmc/harotorch/commands/torchSubCmds/VersionExecutor.java @@ -0,0 +1,17 @@ +package nl.thedutchmc.harotorch.commands.torchSubCmds; + +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; + +import nl.thedutchmc.harotorch.HaroTorch; + +public class VersionExecutor { + + public static boolean version(CommandSender sender, HaroTorch plugin) { + + sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + "You are running HaroTorch version " + ChatColor.RED + plugin.getDescription().getVersion() + ChatColor.GOLD + " and NMS version " + ChatColor.RED + HaroTorch.NMS_VERSION); + + return true; + } + +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 4f386cf..c00025b 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -23,6 +23,9 @@ torchHighlightRange: 64 #For how long should the Torches be higlighted. In seconds. Default: 30 torchHighlightTime: 30 +#How many 'rows' of particles should be spawned when a user uses /torch aoe. Default: 10 +torchAoeParticleHeight: 10 + # Recipe for the Torch # # Example: diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 38ac740..03aa6a1 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -17,6 +17,9 @@ permissions: harotorch.give: true harotorch.convert: true harotorch.highlight: true + harotorch.help: true + harotorch.version: true + harotorch.aoe: true harotorch.give: description: /torch give default: op @@ -25,4 +28,13 @@ permissions: default: op harotorch.highlight: description: /torch highlight + default: true + harotorch.help: + description: /torch help + default: true + harotorch.version: + description: /torch version + default: true + harotorch.aoe: + description: /torch aoe default: true \ No newline at end of file