Skip to content

Commit

Permalink
Added area of effect command, help page and fixed tab completion
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDutchMC committed Oct 6, 2020
1 parent 49dac1a commit 72f5039
Show file tree
Hide file tree
Showing 12 changed files with 250 additions and 4 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public static List<Integer> spawnHighlight(Player p, List<Location> 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);
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pluginVersion = 1.0
pluginVersion = 2.0
pluginGroup = nl.thedutchmc.harotorch
pluginName = HaroTorch
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> recipeShape;
public HashMap<Character, Material> recipeKeys = new HashMap<>();
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/nl/thedutchmc/harotorch/HaroTorch.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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")) {
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {

if(args.length == 1) {
List<String> 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<String> result = new ArrayList<>();
return result;
}

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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<Location> nearbyTorches = TorchHandler.getTorchLocationsNearPlayer((Player) sender, HaroTorch.getConfigHandler().torchHighlightRange);
final List<TorchParticleObject> torchParticles = new ArrayList<>();

for(Location l : nearbyTorches) {

final List<Location> 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<Location> circleLocations;
private Location torch;

public TorchParticleObject(int r, int g, int b, List<Location> circleLocations, Location torch) {
this.particleColor = Color.fromRGB(r, g, b);
this.circleLocations = circleLocations;
this.torch = torch;
}

public Color getTorchParticleColor() {
return this.particleColor;
}

public List<Location> getCircleLocations() {
return this.circleLocations;
}

public Location getTorch() {
return this.torch;
}
}

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
3 changes: 3 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 72f5039

Please sign in to comment.