From 949f3968c62a3c62764cfc7f0da2a8d9f9dd7db6 Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 16 Apr 2015 20:52:58 -0700 Subject: [PATCH] Initial implementation of /particle command using Spigot API https://github.com/deathcap/GlowstonePlusPlus/issues/13 --- .../org/bukkit/command/SimpleCommandMap.java | 1 + .../command/defaults/ParticleCommand.java | 64 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 src/main/java/org/bukkit/command/defaults/ParticleCommand.java diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java index d75380c8bd..445b94d8fc 100644 --- a/src/main/java/org/bukkit/command/SimpleCommandMap.java +++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java @@ -76,6 +76,7 @@ public void setFallbackCommands() { register("bukkit", new SetWorldSpawnCommand()); register("bukkit", new SetIdleTimeoutCommand()); register("bukkit", new AchievementCommand()); + register("bukkit", new ParticleCommand()); } /** diff --git a/src/main/java/org/bukkit/command/defaults/ParticleCommand.java b/src/main/java/org/bukkit/command/defaults/ParticleCommand.java new file mode 100644 index 0000000000..e518a718aa --- /dev/null +++ b/src/main/java/org/bukkit/command/defaults/ParticleCommand.java @@ -0,0 +1,64 @@ +package org.bukkit.command.defaults; + +import org.bukkit.ChatColor; +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class ParticleCommand extends VanillaCommand { + public ParticleCommand() { + super("particle"); + this.description = "Creates particle effects."; + this.usageMessage = "/particle [count] [mode]"; + this.setPermission("bukkit.command.particle"); + } + + @Override + public boolean execute(CommandSender sender, String currentAlias, String[] args) { + if (!testPermission(sender)) { + return true; + } + + if (args.length < 8) { + sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); + return false; + } + + if (!(sender instanceof Player)) { + sender.sendMessage("You can only perform this command as a player"); + return true; + } + + final Player player = (Player) sender; + + final Location location = player.getLocation(); + final World world = location.getWorld(); + + final String name = args[0]; + final float x = (float) getRelativeDouble(location.getX(), sender, args[1]); + final float y = (float) getRelativeDouble(location.getY(), sender, args[2]); + final float z = (float) getRelativeDouble(location.getZ(), sender, args[3]); + final float xd = (float) getDouble(sender, args[4]); + final float yd = (float) getDouble(sender, args[5]); + final float zd = (float) getDouble(sender, args[6]); + final float speed = (float) getDouble(sender, args[7]); + final int count = args.length > 8 ? getInteger(sender, args[8], 1) : 1; + final boolean force = args.length > 9 ? args[9].equals("force") : false; + + Effect effect = Effect.getByName(name); + if (effect == null || effect.getType() != Effect.Type.PARTICLE) { + sender.sendMessage("Unknown particle effect: " + name); + return true; + } + + int id = effect.getId(); + int data = 0; // TODO + int radius = force ? 48 : 16; + + world.spigot().playEffect(new Location(world, x, y, z), effect, id, data, xd, yd, zd, speed, count, radius); + + return true; + } +}