2019-10-17 16:04:43 -06:00
|
|
|
package dev.esophose.playerparticles.command;
|
2018-09-26 02:07:46 -06:00
|
|
|
|
2019-12-09 12:04:06 -07:00
|
|
|
import dev.esophose.playerparticles.PlayerParticles;
|
2019-10-17 16:04:43 -06:00
|
|
|
import dev.esophose.playerparticles.manager.DataManager;
|
2019-12-12 19:32:53 -07:00
|
|
|
import dev.esophose.playerparticles.manager.LocaleManager;
|
2019-10-17 16:04:43 -06:00
|
|
|
import dev.esophose.playerparticles.manager.ParticleManager;
|
|
|
|
import dev.esophose.playerparticles.manager.PermissionManager;
|
|
|
|
import dev.esophose.playerparticles.particles.FixedParticleEffect;
|
|
|
|
import dev.esophose.playerparticles.particles.PPlayer;
|
|
|
|
import dev.esophose.playerparticles.particles.ParticleEffect;
|
|
|
|
import dev.esophose.playerparticles.particles.ParticleEffect.NoteColor;
|
|
|
|
import dev.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor;
|
|
|
|
import dev.esophose.playerparticles.particles.ParticleEffect.ParticleProperty;
|
|
|
|
import dev.esophose.playerparticles.particles.ParticlePair;
|
2019-12-12 19:32:53 -07:00
|
|
|
import dev.esophose.playerparticles.styles.ParticleStyle;
|
2019-12-09 12:04:06 -07:00
|
|
|
import dev.esophose.playerparticles.util.ParticleUtils;
|
2019-12-12 19:32:53 -07:00
|
|
|
import dev.esophose.playerparticles.util.StringPlaceholders;
|
2019-12-09 12:04:06 -07:00
|
|
|
import java.text.DecimalFormat;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.stream.Collectors;
|
2019-12-12 19:32:53 -07:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.util.StringUtil;
|
2018-09-26 02:07:46 -06:00
|
|
|
|
|
|
|
public class FixedCommandModule implements CommandModule {
|
|
|
|
|
2018-09-27 18:16:50 -06:00
|
|
|
public void onCommandExecute(PPlayer pplayer, String[] args) {
|
2019-12-12 19:32:53 -07:00
|
|
|
LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class);
|
|
|
|
|
2018-09-27 18:16:50 -06:00
|
|
|
Player p = pplayer.getPlayer();
|
|
|
|
|
2019-12-09 12:04:06 -07:00
|
|
|
if (!PlayerParticles.getInstance().getManager(PermissionManager.class).canUseFixedEffects(p)) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-no-permission");
|
2018-09-27 18:16:50 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.length == 0) { // General information on command
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "command-description-fixed-create");
|
|
|
|
localeManager.sendMessage(pplayer, "command-description-fixed-edit");
|
|
|
|
localeManager.sendMessage(pplayer, "command-description-fixed-remove");
|
|
|
|
localeManager.sendMessage(pplayer, "command-description-fixed-list");
|
|
|
|
localeManager.sendMessage(pplayer, "command-description-fixed-info");
|
|
|
|
localeManager.sendMessage(pplayer, "command-description-fixed-clear");
|
2018-09-27 18:16:50 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
String cmd = args[0];
|
|
|
|
|
|
|
|
String[] cmdArgs = new String[args.length - 1];
|
2019-04-28 00:17:08 -06:00
|
|
|
System.arraycopy(args, 1, cmdArgs, 0, args.length - 1);
|
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
switch (cmd.toLowerCase()) {
|
|
|
|
case "create":
|
2019-04-28 00:17:08 -06:00
|
|
|
this.handleCreate(pplayer, p, cmdArgs);
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
2018-11-08 04:46:38 -07:00
|
|
|
case "edit":
|
2019-04-28 00:17:08 -06:00
|
|
|
this.handleEdit(pplayer, p, cmdArgs);
|
2018-11-08 04:46:38 -07:00
|
|
|
return;
|
2018-10-07 21:18:19 -06:00
|
|
|
case "remove":
|
2019-04-28 00:17:08 -06:00
|
|
|
this.handleRemove(pplayer, p, cmdArgs);
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
case "list":
|
2019-04-28 00:17:08 -06:00
|
|
|
this.handleList(pplayer, p, cmdArgs);
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
case "info":
|
2019-04-28 00:17:08 -06:00
|
|
|
this.handleInfo(pplayer, p, cmdArgs);
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
case "clear":
|
2019-04-28 00:17:08 -06:00
|
|
|
this.handleClear(pplayer, p, cmdArgs);
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
default:
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-invalid-command");
|
|
|
|
localeManager.sendMessage(pplayer, "command-description-fixed-create");
|
|
|
|
localeManager.sendMessage(pplayer, "command-description-fixed-edit");
|
|
|
|
localeManager.sendMessage(pplayer, "command-description-fixed-remove");
|
|
|
|
localeManager.sendMessage(pplayer, "command-description-fixed-list");
|
|
|
|
localeManager.sendMessage(pplayer, "command-description-fixed-info");
|
|
|
|
localeManager.sendMessage(pplayer, "command-description-fixed-clear");
|
2018-10-07 21:18:19 -06:00
|
|
|
}
|
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
/**
|
|
|
|
* Handles the command /pp fixed create
|
2019-04-28 00:17:08 -06:00
|
|
|
*
|
2018-10-07 21:18:19 -06:00
|
|
|
* @param pplayer The PPlayer
|
|
|
|
* @param p The Player
|
|
|
|
* @param args The command arguments
|
|
|
|
*/
|
|
|
|
private void handleCreate(PPlayer pplayer, Player p, String[] args) {
|
2019-12-12 19:32:53 -07:00
|
|
|
LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class);
|
2019-12-09 12:04:06 -07:00
|
|
|
PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class);
|
|
|
|
boolean reachedMax = permissionManager.hasPlayerReachedMaxFixedEffects(pplayer);
|
2018-10-07 21:18:19 -06:00
|
|
|
if (reachedMax) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-max-reached");
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-10-28 04:18:34 -06:00
|
|
|
if (args.length < 5 && !(args.length > 0 && args[0].equalsIgnoreCase("looking") && args.length >= 3)) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-create-missing-args", StringPlaceholders.single("amount", 5 - args.length));
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2019-04-28 00:17:08 -06:00
|
|
|
double xPos, yPos, zPos;
|
|
|
|
|
2018-10-28 04:18:34 -06:00
|
|
|
if (args[0].equalsIgnoreCase("looking")) {
|
2019-12-12 19:32:53 -07:00
|
|
|
Block targetBlock = p.getTargetBlock((Set<Material>) null, 8); // Need the Set<Material> cast for 1.9 support
|
2018-10-28 04:18:34 -06:00
|
|
|
int maxDistanceSqrd = 6 * 6;
|
|
|
|
if (targetBlock.getLocation().distanceSquared(p.getLocation()) > maxDistanceSqrd) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-create-looking-too-far");
|
2018-10-28 04:18:34 -06:00
|
|
|
return;
|
2018-09-27 18:16:50 -06:00
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
|
2018-10-28 04:18:34 -06:00
|
|
|
Location blockLocation = targetBlock.getLocation().clone().add(0.5, 0.5, 0.5); // Center of block
|
2019-04-28 00:17:08 -06:00
|
|
|
|
2018-10-28 04:18:34 -06:00
|
|
|
xPos = blockLocation.getX();
|
|
|
|
yPos = blockLocation.getY();
|
|
|
|
zPos = blockLocation.getZ();
|
2019-04-28 00:17:08 -06:00
|
|
|
|
2018-10-28 04:18:34 -06:00
|
|
|
// Pad the args with the coordinates so we don't have to adjust all the indices
|
|
|
|
String[] paddedArgs = new String[args.length + 2];
|
|
|
|
paddedArgs[0] = String.valueOf(xPos);
|
|
|
|
paddedArgs[1] = String.valueOf(yPos);
|
|
|
|
paddedArgs[2] = String.valueOf(zPos);
|
2019-04-28 00:17:08 -06:00
|
|
|
System.arraycopy(args, 1, paddedArgs, 3, args.length - 1);
|
2018-10-28 04:18:34 -06:00
|
|
|
args = paddedArgs;
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
if (args[0].startsWith("~")) {
|
|
|
|
if (args[0].equals("~")) xPos = p.getLocation().getX();
|
|
|
|
else xPos = p.getLocation().getX() + Double.parseDouble(args[0].substring(1));
|
|
|
|
} else {
|
|
|
|
xPos = Double.parseDouble(args[0]);
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-10-28 04:18:34 -06:00
|
|
|
if (args[1].startsWith("~")) {
|
|
|
|
if (args[1].equals("~")) yPos = p.getLocation().getY() + 1;
|
|
|
|
else yPos = p.getLocation().getY() + 1 + Double.parseDouble(args[1].substring(1));
|
|
|
|
} else {
|
|
|
|
yPos = Double.parseDouble(args[1]);
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-10-28 04:18:34 -06:00
|
|
|
if (args[2].startsWith("~")) {
|
|
|
|
if (args[2].equals("~")) zPos = p.getLocation().getZ();
|
|
|
|
else zPos = p.getLocation().getZ() + Double.parseDouble(args[2].substring(1));
|
|
|
|
} else {
|
|
|
|
zPos = Double.parseDouble(args[2]);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-create-invalid-coords");
|
2018-10-28 04:18:34 -06:00
|
|
|
return;
|
2018-09-27 18:16:50 -06:00
|
|
|
}
|
2018-10-07 21:18:19 -06:00
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
double distanceFromEffect = p.getLocation().distance(new Location(p.getWorld(), xPos, yPos, zPos));
|
2019-12-09 12:04:06 -07:00
|
|
|
int maxCreationDistance = permissionManager.getMaxFixedEffectCreationDistance();
|
2018-10-07 21:18:19 -06:00
|
|
|
if (maxCreationDistance != 0 && distanceFromEffect > maxCreationDistance) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-create-out-of-range", StringPlaceholders.single("range", maxCreationDistance));
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-10-13 16:38:01 -06:00
|
|
|
ParticleEffect effect = ParticleEffect.fromName(args[3]);
|
2018-10-07 21:18:19 -06:00
|
|
|
if (effect == null) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-create-effect-invalid", StringPlaceholders.single("effect", args[3]));
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
2019-12-09 12:04:06 -07:00
|
|
|
} else if (!permissionManager.hasEffectPermission(p, effect)) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-create-effect-no-permission", StringPlaceholders.single("effect", effect.getName()));
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-10-16 02:38:12 -06:00
|
|
|
ParticleStyle style = ParticleStyle.fromName(args[4]);
|
2018-10-07 21:18:19 -06:00
|
|
|
if (style == null) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-create-style-invalid", StringPlaceholders.single("style", args[4]));
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
2019-12-09 12:04:06 -07:00
|
|
|
} else if (!permissionManager.hasStylePermission(p, style)) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-create-style-no-permission", StringPlaceholders.single("style", args[4]));
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
if (!style.canBeFixed()) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-create-style-non-fixable", StringPlaceholders.single("style", style.getName()));
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
Material itemData = null;
|
|
|
|
Material blockData = null;
|
|
|
|
OrdinaryColor colorData = null;
|
|
|
|
NoteColor noteColorData = null;
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
if (args.length > 5) {
|
|
|
|
if (effect.hasProperty(ParticleProperty.COLORABLE)) {
|
|
|
|
if (effect == ParticleEffect.NOTE) {
|
|
|
|
if (args[5].equalsIgnoreCase("rainbow")) {
|
|
|
|
noteColorData = new NoteColor(99);
|
2018-11-07 20:06:08 -07:00
|
|
|
} else if (args[5].equalsIgnoreCase("random")) {
|
|
|
|
noteColorData = new NoteColor(98);
|
2018-09-27 18:16:50 -06:00
|
|
|
} else {
|
2019-04-28 00:17:08 -06:00
|
|
|
int note;
|
2018-10-07 21:18:19 -06:00
|
|
|
try {
|
|
|
|
note = Integer.parseInt(args[5]);
|
|
|
|
} catch (Exception e) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-create-data-error");
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-11-07 03:21:46 -07:00
|
|
|
if (note < 0 || note > 24) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-create-data-error");
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
2018-09-27 18:16:50 -06:00
|
|
|
}
|
2018-10-07 21:18:19 -06:00
|
|
|
|
|
|
|
noteColorData = new NoteColor(note);
|
2018-09-27 18:16:50 -06:00
|
|
|
}
|
2018-10-07 21:18:19 -06:00
|
|
|
} else {
|
|
|
|
if (args[5].equalsIgnoreCase("rainbow")) {
|
|
|
|
colorData = new OrdinaryColor(999, 999, 999);
|
2018-11-07 20:06:08 -07:00
|
|
|
} else if (args[5].equalsIgnoreCase("random")) {
|
|
|
|
colorData = new OrdinaryColor(998, 998, 998);
|
2018-10-07 21:18:19 -06:00
|
|
|
} else {
|
2019-04-28 00:17:08 -06:00
|
|
|
int r, g, b;
|
2018-10-07 21:18:19 -06:00
|
|
|
|
2018-09-27 18:16:50 -06:00
|
|
|
try {
|
2018-10-07 21:18:19 -06:00
|
|
|
r = Integer.parseInt(args[5]);
|
|
|
|
g = Integer.parseInt(args[6]);
|
|
|
|
b = Integer.parseInt(args[7]);
|
2018-09-27 18:16:50 -06:00
|
|
|
} catch (Exception e) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-create-data-error");
|
2018-09-27 18:16:50 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-create-data-error");
|
2018-09-27 18:16:50 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
colorData = new OrdinaryColor(r, g, b);
|
2018-09-27 18:16:50 -06:00
|
|
|
}
|
|
|
|
}
|
2018-10-07 21:18:19 -06:00
|
|
|
} else if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
|
|
|
|
if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) {
|
2019-04-28 00:17:08 -06:00
|
|
|
Material material;
|
2018-10-07 21:18:19 -06:00
|
|
|
try {
|
|
|
|
material = ParticleUtils.closestMatch(args[5]);
|
|
|
|
if (material == null) material = Material.matchMaterial(args[5]);
|
2018-10-16 02:38:12 -06:00
|
|
|
if (material == null || !material.isBlock()) throw new Exception();
|
2018-10-07 21:18:19 -06:00
|
|
|
} catch (Exception e) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-create-data-error");
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
blockData = material;
|
|
|
|
} else if (effect == ParticleEffect.ITEM) {
|
2019-04-28 00:17:08 -06:00
|
|
|
Material material;
|
2018-10-07 21:18:19 -06:00
|
|
|
try {
|
|
|
|
material = ParticleUtils.closestMatch(args[5]);
|
|
|
|
if (material == null) material = Material.matchMaterial(args[5]);
|
2018-10-16 02:38:12 -06:00
|
|
|
if (material == null || material.isBlock()) throw new Exception();
|
2018-10-07 21:18:19 -06:00
|
|
|
} catch (Exception e) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-create-data-error");
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
itemData = material;
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
}
|
2018-10-07 21:18:19 -06:00
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
int nextFixedEffectId = pplayer.getNextFixedEffectId();
|
|
|
|
ParticlePair particle = new ParticlePair(pplayer.getUniqueId(), nextFixedEffectId, effect, style, itemData, blockData, colorData, noteColorData);
|
2019-12-30 18:36:57 -07:00
|
|
|
FixedParticleEffect fixedEffect = new FixedParticleEffect(p.getUniqueId(), nextFixedEffectId, p.getLocation().getWorld(), xPos, yPos, zPos, particle);
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-create-success");
|
2019-12-09 12:04:06 -07:00
|
|
|
PlayerParticles.getInstance().getManager(DataManager.class).saveFixedEffect(fixedEffect);
|
2018-10-07 21:18:19 -06:00
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
|
2018-11-08 04:46:38 -07:00
|
|
|
/**
|
|
|
|
* Handles the command /pp fixed edit
|
2019-04-28 00:17:08 -06:00
|
|
|
*
|
2018-11-08 04:46:38 -07:00
|
|
|
* @param pplayer The PPlayer
|
|
|
|
* @param p The Player
|
|
|
|
* @param args The command arguments
|
|
|
|
*/
|
|
|
|
private void handleEdit(PPlayer pplayer, Player p, String[] args) {
|
2019-12-12 19:32:53 -07:00
|
|
|
LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class);
|
2019-12-09 12:04:06 -07:00
|
|
|
PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class);
|
|
|
|
|
2018-11-08 04:46:38 -07:00
|
|
|
if (args.length < 3) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-edit-missing-args");
|
2018-11-08 04:46:38 -07:00
|
|
|
return;
|
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
|
|
|
|
int id;
|
2018-11-08 04:46:38 -07:00
|
|
|
try {
|
|
|
|
id = Integer.parseInt(args[0]);
|
|
|
|
} catch (Exception ex) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-edit-invalid-id");
|
2018-11-08 04:46:38 -07:00
|
|
|
return;
|
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
|
2018-11-08 04:46:38 -07:00
|
|
|
FixedParticleEffect fixedEffect = pplayer.getFixedEffectById(id);
|
|
|
|
if (fixedEffect == null) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-edit-invalid-id");
|
2018-11-08 04:46:38 -07:00
|
|
|
return;
|
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
|
2018-11-08 04:46:38 -07:00
|
|
|
String editType = args[1].toLowerCase();
|
2019-04-28 00:17:08 -06:00
|
|
|
switch (editType) {
|
|
|
|
case "location":
|
|
|
|
double xPos, yPos, zPos;
|
|
|
|
|
|
|
|
if (args[2].equalsIgnoreCase("looking")) {
|
2019-12-12 19:32:53 -07:00
|
|
|
Block targetBlock = p.getTargetBlock((Set<Material>) null, 8); // Need the Set<Material> cast for 1.9 support
|
2019-04-28 00:17:08 -06:00
|
|
|
int maxDistanceSqrd = 6 * 6;
|
|
|
|
if (targetBlock.getLocation().distanceSquared(p.getLocation()) > maxDistanceSqrd) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-edit-looking-too-far");
|
2019-04-28 00:17:08 -06:00
|
|
|
return;
|
2018-11-08 04:46:38 -07:00
|
|
|
}
|
|
|
|
|
2019-04-28 00:17:08 -06:00
|
|
|
Location blockLocation = targetBlock.getLocation().clone().add(0.5, 0.5, 0.5); // Center of block
|
2018-11-08 04:46:38 -07:00
|
|
|
|
2019-04-28 00:17:08 -06:00
|
|
|
xPos = blockLocation.getX();
|
|
|
|
yPos = blockLocation.getY();
|
|
|
|
zPos = blockLocation.getZ();
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
if (args[2].startsWith("~")) {
|
|
|
|
if (args[2].equals("~")) xPos = p.getLocation().getX();
|
|
|
|
else xPos = p.getLocation().getX() + Double.parseDouble(args[2].substring(1));
|
|
|
|
} else {
|
|
|
|
xPos = Double.parseDouble(args[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args[3].startsWith("~")) {
|
|
|
|
if (args[3].equals("~")) yPos = p.getLocation().getY() + 1;
|
|
|
|
else yPos = p.getLocation().getY() + 1 + Double.parseDouble(args[3].substring(1));
|
|
|
|
} else {
|
|
|
|
yPos = Double.parseDouble(args[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args[4].startsWith("~")) {
|
|
|
|
if (args[4].equals("~")) zPos = p.getLocation().getZ();
|
|
|
|
else zPos = p.getLocation().getZ() + Double.parseDouble(args[4].substring(1));
|
|
|
|
} else {
|
|
|
|
zPos = Double.parseDouble(args[4]);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-edit-invalid-coords");
|
2019-04-28 00:17:08 -06:00
|
|
|
return;
|
2018-11-08 04:46:38 -07:00
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
double distanceFromEffect = p.getLocation().distance(new Location(p.getWorld(), xPos, yPos, zPos));
|
2019-12-09 12:04:06 -07:00
|
|
|
int maxCreationDistance = permissionManager.getMaxFixedEffectCreationDistance();
|
2019-04-28 00:17:08 -06:00
|
|
|
if (maxCreationDistance != 0 && distanceFromEffect > maxCreationDistance) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-edit-out-of-range", StringPlaceholders.single("range", maxCreationDistance));
|
2018-11-08 04:46:38 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-28 00:17:08 -06:00
|
|
|
fixedEffect.setCoordinates(xPos, yPos, zPos);
|
|
|
|
break;
|
|
|
|
case "effect": {
|
|
|
|
ParticleEffect effect = ParticleEffect.fromName(args[2]);
|
|
|
|
if (effect == null) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-edit-effect-invalid", StringPlaceholders.single("effect", args[2]));
|
2019-04-28 00:17:08 -06:00
|
|
|
return;
|
2019-12-09 12:04:06 -07:00
|
|
|
} else if (!permissionManager.hasEffectPermission(pplayer.getPlayer(), effect)) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-edit-effect-no-permission", StringPlaceholders.single("effect", effect.getName()));
|
2019-04-28 00:17:08 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fixedEffect.getParticlePair().setEffect(effect);
|
|
|
|
break;
|
2018-11-08 04:46:38 -07:00
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
case "style":
|
|
|
|
ParticleStyle style = ParticleStyle.fromName(args[2]);
|
|
|
|
if (style == null) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-edit-style-invalid", StringPlaceholders.single("style", args[2]));
|
2019-04-28 00:17:08 -06:00
|
|
|
return;
|
2019-12-09 12:04:06 -07:00
|
|
|
} else if (!permissionManager.hasStylePermission(pplayer.getPlayer(), style)) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-edit-style-no-permission", StringPlaceholders.single("style", style.getName()));
|
2019-04-28 00:17:08 -06:00
|
|
|
return;
|
|
|
|
} else if (!style.canBeFixed()) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-edit-style-non-fixable", StringPlaceholders.single("style", style.getName()));
|
2019-04-28 00:17:08 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-11-08 04:46:38 -07:00
|
|
|
|
2019-04-28 00:17:08 -06:00
|
|
|
fixedEffect.getParticlePair().setStyle(style);
|
|
|
|
break;
|
|
|
|
case "data": {
|
|
|
|
Material itemData = null;
|
|
|
|
Material blockData = null;
|
|
|
|
OrdinaryColor colorData = null;
|
|
|
|
NoteColor noteColorData = null;
|
|
|
|
|
|
|
|
ParticleEffect effect = fixedEffect.getParticlePair().getEffect();
|
|
|
|
if (effect.hasProperty(ParticleProperty.COLORABLE)) {
|
|
|
|
if (effect == ParticleEffect.NOTE) {
|
|
|
|
if (args[2].equalsIgnoreCase("rainbow")) {
|
|
|
|
noteColorData = new NoteColor(99);
|
|
|
|
} else if (args[2].equalsIgnoreCase("random")) {
|
|
|
|
noteColorData = new NoteColor(98);
|
|
|
|
} else {
|
|
|
|
int note;
|
|
|
|
try {
|
|
|
|
note = Integer.parseInt(args[2]);
|
|
|
|
} catch (Exception e) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-edit-data-error");
|
2019-04-28 00:17:08 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-11-08 04:46:38 -07:00
|
|
|
|
2019-04-28 00:17:08 -06:00
|
|
|
if (note < 0 || note > 24) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-edit-data-error");
|
2019-04-28 00:17:08 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
noteColorData = new NoteColor(note);
|
|
|
|
}
|
2018-11-08 04:46:38 -07:00
|
|
|
} else {
|
2019-04-28 00:17:08 -06:00
|
|
|
if (args[2].equalsIgnoreCase("rainbow")) {
|
|
|
|
colorData = new OrdinaryColor(999, 999, 999);
|
|
|
|
} else if (args[2].equalsIgnoreCase("random")) {
|
|
|
|
colorData = new OrdinaryColor(998, 998, 998);
|
|
|
|
} else {
|
|
|
|
int r, g, b;
|
|
|
|
|
|
|
|
try {
|
|
|
|
r = Integer.parseInt(args[2]);
|
|
|
|
g = Integer.parseInt(args[3]);
|
|
|
|
b = Integer.parseInt(args[4]);
|
|
|
|
} catch (Exception e) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-edit-data-error");
|
2019-04-28 00:17:08 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-edit-data-error");
|
2019-04-28 00:17:08 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-11-08 04:46:38 -07:00
|
|
|
|
2019-04-28 00:17:08 -06:00
|
|
|
colorData = new OrdinaryColor(r, g, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
|
|
|
|
if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) {
|
|
|
|
Material material;
|
2018-11-08 04:46:38 -07:00
|
|
|
try {
|
2019-04-28 00:17:08 -06:00
|
|
|
material = ParticleUtils.closestMatch(args[2]);
|
|
|
|
if (material == null) material = Material.matchMaterial(args[2]);
|
|
|
|
if (material == null || !material.isBlock()) throw new Exception();
|
2018-11-08 04:46:38 -07:00
|
|
|
} catch (Exception e) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-edit-data-error");
|
2018-11-08 04:46:38 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-28 00:17:08 -06:00
|
|
|
blockData = material;
|
|
|
|
} else if (effect == ParticleEffect.ITEM) {
|
|
|
|
Material material;
|
|
|
|
try {
|
|
|
|
material = ParticleUtils.closestMatch(args[2]);
|
|
|
|
if (material == null) material = Material.matchMaterial(args[2]);
|
|
|
|
if (material == null || material.isBlock()) throw new Exception();
|
|
|
|
} catch (Exception e) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-edit-data-error");
|
2018-11-08 04:46:38 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-28 00:17:08 -06:00
|
|
|
itemData = material;
|
2018-11-08 04:46:38 -07:00
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
} else {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-edit-data-none");
|
2019-04-28 00:17:08 -06:00
|
|
|
return;
|
2018-11-08 04:46:38 -07:00
|
|
|
}
|
|
|
|
|
2019-04-28 00:17:08 -06:00
|
|
|
fixedEffect.getParticlePair().setColor(colorData);
|
|
|
|
fixedEffect.getParticlePair().setNoteColor(noteColorData);
|
|
|
|
fixedEffect.getParticlePair().setItemMaterial(itemData);
|
|
|
|
fixedEffect.getParticlePair().setBlockMaterial(blockData);
|
|
|
|
break;
|
2018-11-08 04:46:38 -07:00
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
default:
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-edit-invalid-property");
|
2019-04-28 00:17:08 -06:00
|
|
|
return;
|
2018-11-08 04:46:38 -07:00
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
|
2019-12-09 12:04:06 -07:00
|
|
|
PlayerParticles.getInstance().getManager(DataManager.class).updateFixedEffect(fixedEffect);
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-edit-success", StringPlaceholders.builder("prop", editType).addPlaceholder("id", id).build());
|
2018-11-08 04:46:38 -07:00
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
/**
|
|
|
|
* Handles the command /pp fixed remove
|
2019-04-28 00:17:08 -06:00
|
|
|
*
|
2018-10-07 21:18:19 -06:00
|
|
|
* @param pplayer The PPlayer
|
|
|
|
* @param p The Player
|
|
|
|
* @param args The command arguments
|
|
|
|
*/
|
|
|
|
private void handleRemove(PPlayer pplayer, Player p, String[] args) {
|
2019-12-12 19:32:53 -07:00
|
|
|
LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class);
|
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
if (args.length < 1) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-remove-no-args");
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2019-04-28 00:17:08 -06:00
|
|
|
int id;
|
2018-10-07 21:18:19 -06:00
|
|
|
try {
|
|
|
|
id = Integer.parseInt(args[0]);
|
|
|
|
} catch (Exception e) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-remove-args-invalid");
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
if (pplayer.getFixedEffectById(id) != null) {
|
2019-12-09 12:04:06 -07:00
|
|
|
PlayerParticles.getInstance().getManager(DataManager.class).removeFixedEffect(pplayer.getUniqueId(), id);
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-remove-success", StringPlaceholders.single("id", id));
|
2018-10-07 21:18:19 -06:00
|
|
|
} else {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-remove-invalid", StringPlaceholders.single("id", id));
|
2018-10-07 21:18:19 -06:00
|
|
|
}
|
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
/**
|
|
|
|
* Handles the command /pp fixed list
|
2019-04-28 00:17:08 -06:00
|
|
|
*
|
2018-10-07 21:18:19 -06:00
|
|
|
* @param pplayer The PPlayer
|
|
|
|
* @param p The Player
|
|
|
|
* @param args The command arguments
|
|
|
|
*/
|
|
|
|
private void handleList(PPlayer pplayer, Player p, String[] args) {
|
2019-12-12 19:32:53 -07:00
|
|
|
LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class);
|
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
List<Integer> ids = pplayer.getFixedEffectIds();
|
|
|
|
Collections.sort(ids);
|
|
|
|
|
|
|
|
if (ids.isEmpty()) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-list-none");
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2019-04-28 00:17:08 -06:00
|
|
|
StringBuilder msg = new StringBuilder();
|
2018-10-07 21:18:19 -06:00
|
|
|
boolean first = true;
|
|
|
|
for (int id : ids) {
|
2019-04-28 00:17:08 -06:00
|
|
|
if (!first) msg.append(", ");
|
2018-10-07 21:18:19 -06:00
|
|
|
else first = false;
|
2019-04-28 00:17:08 -06:00
|
|
|
msg.append(id);
|
2018-10-07 21:18:19 -06:00
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-list-success", StringPlaceholders.single("ids", msg.toString()));
|
2018-10-07 21:18:19 -06:00
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
/**
|
|
|
|
* Handles the command /pp fixed info
|
2019-04-28 00:17:08 -06:00
|
|
|
*
|
2018-10-07 21:18:19 -06:00
|
|
|
* @param pplayer The PPlayer
|
|
|
|
* @param p The Player
|
|
|
|
* @param args The command arguments
|
|
|
|
*/
|
|
|
|
private void handleInfo(PPlayer pplayer, Player p, String[] args) {
|
2019-12-12 19:32:53 -07:00
|
|
|
LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class);
|
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
if (args.length < 1) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-info-no-args");
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2019-04-28 00:17:08 -06:00
|
|
|
int id;
|
2018-10-07 21:18:19 -06:00
|
|
|
try {
|
|
|
|
id = Integer.parseInt(args[0]);
|
|
|
|
} catch (Exception e) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-info-invalid-args");
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
FixedParticleEffect fixedEffect = pplayer.getFixedEffectById(id);
|
|
|
|
if (fixedEffect == null) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-info-invalid", StringPlaceholders.single("id", id));
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
ParticlePair particle = fixedEffect.getParticlePair();
|
|
|
|
|
|
|
|
DecimalFormat df = new DecimalFormat("0.##"); // Decimal formatter so the coords aren't super long
|
2019-12-12 19:32:53 -07:00
|
|
|
StringPlaceholders stringPlaceholders = StringPlaceholders.builder("id", fixedEffect.getId())
|
|
|
|
.addPlaceholder("world", fixedEffect.getLocation().getWorld().getName())
|
|
|
|
.addPlaceholder("x", df.format(fixedEffect.getLocation().getX()))
|
|
|
|
.addPlaceholder("y", df.format(fixedEffect.getLocation().getY()))
|
|
|
|
.addPlaceholder("z", df.format(fixedEffect.getLocation().getZ()))
|
|
|
|
.addPlaceholder("effect", particle.getEffect().getName())
|
|
|
|
.addPlaceholder("style", particle.getStyle().getName())
|
|
|
|
.addPlaceholder("data", particle.getDataString())
|
|
|
|
.build();
|
|
|
|
localeManager.sendMessage(pplayer, "fixed-info-success", stringPlaceholders);
|
2018-10-07 21:18:19 -06:00
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
/**
|
|
|
|
* Handles the command /pp fixed clear
|
2019-04-28 00:17:08 -06:00
|
|
|
*
|
2018-10-07 21:18:19 -06:00
|
|
|
* @param pplayer The PPlayer
|
|
|
|
* @param p The Player
|
|
|
|
* @param args The command arguments
|
|
|
|
*/
|
|
|
|
private void handleClear(PPlayer pplayer, Player p, String[] args) {
|
2019-12-12 19:32:53 -07:00
|
|
|
LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class);
|
2019-12-09 12:04:06 -07:00
|
|
|
PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class);
|
|
|
|
ParticleManager particleManager = PlayerParticles.getInstance().getManager(ParticleManager.class);
|
|
|
|
DataManager dataManager = PlayerParticles.getInstance().getManager(DataManager.class);
|
|
|
|
|
|
|
|
if (!permissionManager.canClearFixedEffects(p)) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-clear-no-permission");
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
if (args.length < 1) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-clear-no-args");
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2019-04-28 00:17:08 -06:00
|
|
|
int radius;
|
2018-10-07 21:18:19 -06:00
|
|
|
try {
|
|
|
|
radius = Math.abs(Integer.parseInt(args[0]));
|
|
|
|
} catch (Exception e) {
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-clear-invalid-args");
|
2018-10-07 21:18:19 -06:00
|
|
|
return;
|
|
|
|
}
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2019-04-28 00:17:08 -06:00
|
|
|
ArrayList<FixedParticleEffect> fixedEffectsToRemove = new ArrayList<>();
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2019-12-09 12:04:06 -07:00
|
|
|
for (PPlayer ppl : particleManager.getPPlayers())
|
2018-10-07 21:18:19 -06:00
|
|
|
for (FixedParticleEffect fixedEffect : ppl.getFixedParticles())
|
2019-12-09 12:04:06 -07:00
|
|
|
if (fixedEffect.getLocation().getWorld() == p.getLocation().getWorld() && fixedEffect.getLocation().distance(p.getLocation()) <= radius)
|
2018-10-07 21:18:19 -06:00
|
|
|
fixedEffectsToRemove.add(fixedEffect);
|
2018-09-27 18:16:50 -06:00
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
for (FixedParticleEffect fixedEffect : fixedEffectsToRemove)
|
2019-12-09 12:04:06 -07:00
|
|
|
dataManager.removeFixedEffect(fixedEffect.getOwnerUniqueId(), fixedEffect.getId());
|
2018-10-07 21:18:19 -06:00
|
|
|
|
2019-12-12 19:32:53 -07:00
|
|
|
localeManager.sendMessage(pplayer, "fixed-clear-success", StringPlaceholders.builder("amount", fixedEffectsToRemove.size()).addPlaceholder("range", radius).build());
|
2018-09-27 18:16:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<String> onTabComplete(PPlayer pplayer, String[] args) {
|
2019-12-12 19:32:53 -07:00
|
|
|
LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class);
|
2019-12-09 12:04:06 -07:00
|
|
|
PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class);
|
2018-10-07 21:18:19 -06:00
|
|
|
Player p = pplayer.getPlayer();
|
2019-04-28 00:17:08 -06:00
|
|
|
List<String> matches = new ArrayList<>();
|
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
if (args.length <= 1) {
|
2019-04-28 00:17:08 -06:00
|
|
|
List<String> possibleCmds = new ArrayList<>(Arrays.asList("create", "edit", "remove", "list", "info", "clear"));
|
2018-10-07 21:18:19 -06:00
|
|
|
if (args.length == 0) matches = possibleCmds;
|
|
|
|
else StringUtil.copyPartialMatches(args[0], possibleCmds, matches);
|
|
|
|
} else {
|
|
|
|
switch (args[0].toLowerCase()) {
|
2019-04-28 00:17:08 -06:00
|
|
|
case "create":
|
|
|
|
if (args.length <= 4) {
|
|
|
|
List<String> possibleValues = new ArrayList<>();
|
|
|
|
if (args.length == 4) {
|
2018-11-08 04:46:38 -07:00
|
|
|
possibleValues.add("~");
|
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
if (args.length == 3) {
|
2018-11-08 04:46:38 -07:00
|
|
|
possibleValues.add("~ ~");
|
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
if (args.length == 2) {
|
2018-11-08 04:46:38 -07:00
|
|
|
possibleValues.add("~ ~ ~");
|
|
|
|
possibleValues.add("looking");
|
|
|
|
}
|
|
|
|
StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches);
|
2019-04-28 00:17:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pad arguments if the first coordinate is "looking"
|
|
|
|
if (args[1].equalsIgnoreCase("looking")) {
|
|
|
|
String[] paddedArgs = new String[args.length + 2];
|
|
|
|
paddedArgs[0] = paddedArgs[1] = paddedArgs[2] = paddedArgs[3] = "";
|
|
|
|
System.arraycopy(args, 2, paddedArgs, 4, args.length - 2);
|
|
|
|
args = paddedArgs;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.length == 5) {
|
2019-12-09 12:04:06 -07:00
|
|
|
StringUtil.copyPartialMatches(args[4], permissionManager.getEffectNamesUserHasPermissionFor(p), matches);
|
2019-04-28 00:17:08 -06:00
|
|
|
} else if (args.length == 6) {
|
2019-12-09 12:04:06 -07:00
|
|
|
StringUtil.copyPartialMatches(args[5], permissionManager.getFixableStyleNamesUserHasPermissionFor(p), matches);
|
2019-04-28 00:17:08 -06:00
|
|
|
} else if (args.length >= 7) {
|
|
|
|
ParticleEffect effect = ParticleEffect.fromName(args[4]);
|
|
|
|
if (effect != null) {
|
2018-11-08 04:46:38 -07:00
|
|
|
if (effect.hasProperty(ParticleProperty.COLORABLE)) {
|
2019-04-28 00:17:08 -06:00
|
|
|
List<String> possibleValues = new ArrayList<>();
|
2018-11-08 04:46:38 -07:00
|
|
|
if (effect == ParticleEffect.NOTE) { // Note data
|
2019-04-28 00:17:08 -06:00
|
|
|
if (args.length == 7) {
|
2018-11-08 04:46:38 -07:00
|
|
|
possibleValues.add("<0-24>");
|
|
|
|
possibleValues.add("rainbow");
|
|
|
|
possibleValues.add("random");
|
|
|
|
}
|
|
|
|
} else { // Color data
|
2019-04-28 00:17:08 -06:00
|
|
|
if (args.length <= 9 && !args[2].equalsIgnoreCase("rainbow") && !args[2].equalsIgnoreCase("random")) {
|
2018-11-08 04:46:38 -07:00
|
|
|
possibleValues.add("<0-255>");
|
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
if (args.length <= 8 && !args[2].equalsIgnoreCase("rainbow") && !args[2].equalsIgnoreCase("random")) {
|
2018-11-08 04:46:38 -07:00
|
|
|
possibleValues.add("<0-255> <0-255>");
|
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
if (args.length <= 7) {
|
2018-11-08 04:46:38 -07:00
|
|
|
possibleValues.add("<0-255> <0-255> <0-255>");
|
|
|
|
possibleValues.add("rainbow");
|
|
|
|
possibleValues.add("random");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches);
|
2019-04-28 00:17:08 -06:00
|
|
|
} else if (args.length == 7 && effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
|
2018-11-08 04:46:38 -07:00
|
|
|
if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) { // Block material
|
2019-04-28 00:17:08 -06:00
|
|
|
StringUtil.copyPartialMatches(args[6], ParticleUtils.getAllBlockMaterials(), matches);
|
2018-11-08 04:46:38 -07:00
|
|
|
} else if (effect == ParticleEffect.ITEM) { // Item material
|
2019-04-28 00:17:08 -06:00
|
|
|
StringUtil.copyPartialMatches(args[6], ParticleUtils.getAllItemMaterials(), matches);
|
2018-11-08 04:46:38 -07:00
|
|
|
}
|
|
|
|
}
|
2018-10-07 21:18:19 -06:00
|
|
|
}
|
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
break;
|
|
|
|
case "edit":
|
|
|
|
if (args.length == 2) {
|
|
|
|
StringUtil.copyPartialMatches(args[1], pplayer.getFixedEffectIds().stream().map(String::valueOf).collect(Collectors.toList()), matches);
|
|
|
|
} else if (args.length == 3) {
|
|
|
|
String[] validProperties = new String[] { "location", "effect", "style", "data" };
|
|
|
|
StringUtil.copyPartialMatches(args[2], Arrays.asList(validProperties), matches);
|
|
|
|
} else {
|
|
|
|
String property = args[2].toLowerCase();
|
|
|
|
if (property.equals("location")) {
|
|
|
|
List<String> possibleValues = new ArrayList<String>();
|
|
|
|
if (args.length == 6 && !args[3].equalsIgnoreCase("looking")) {
|
|
|
|
possibleValues.add("~");
|
|
|
|
}
|
|
|
|
if (args.length == 5 && !args[3].equalsIgnoreCase("looking")) {
|
|
|
|
possibleValues.add("~ ~");
|
|
|
|
}
|
|
|
|
if (args.length == 4) {
|
|
|
|
possibleValues.add("~ ~ ~");
|
|
|
|
possibleValues.add("looking");
|
|
|
|
}
|
|
|
|
StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches);
|
|
|
|
} else if (property.equals("effect") && args.length == 4) {
|
2019-12-09 12:04:06 -07:00
|
|
|
StringUtil.copyPartialMatches(args[3], permissionManager.getEffectNamesUserHasPermissionFor(p), matches);
|
2019-04-28 00:17:08 -06:00
|
|
|
} else if (property.equals("style") && args.length == 4) {
|
2019-12-09 12:04:06 -07:00
|
|
|
StringUtil.copyPartialMatches(args[3], permissionManager.getFixableStyleNamesUserHasPermissionFor(p), matches);
|
2019-04-28 00:17:08 -06:00
|
|
|
} else if (property.equals("data")) {
|
|
|
|
int id = -1;
|
|
|
|
try {
|
|
|
|
id = Integer.parseInt(args[1]);
|
|
|
|
} catch (Exception e) { }
|
|
|
|
|
|
|
|
FixedParticleEffect fixedEffect = pplayer.getFixedEffectById(id);
|
|
|
|
if (fixedEffect != null) {
|
|
|
|
ParticleEffect effect = fixedEffect.getParticlePair().getEffect();
|
|
|
|
if (effect.hasProperty(ParticleProperty.COLORABLE)) {
|
|
|
|
List<String> possibleValues = new ArrayList<>();
|
|
|
|
if (effect == ParticleEffect.NOTE) { // Note data
|
|
|
|
if (args.length == 4) {
|
|
|
|
possibleValues.add("<0-24>");
|
|
|
|
possibleValues.add("rainbow");
|
|
|
|
possibleValues.add("random");
|
|
|
|
}
|
|
|
|
} else { // Color data
|
|
|
|
if (args.length == 6 && !args[3].equalsIgnoreCase("rainbow") && !args[3].equalsIgnoreCase("random")) {
|
|
|
|
possibleValues.add("<0-255>");
|
|
|
|
}
|
|
|
|
if (args.length == 5 && !args[3].equalsIgnoreCase("rainbow") && !args[3].equalsIgnoreCase("random")) {
|
|
|
|
possibleValues.add("<0-255> <0-255>");
|
|
|
|
}
|
|
|
|
if (args.length == 4) {
|
|
|
|
possibleValues.add("<0-255> <0-255> <0-255>");
|
|
|
|
possibleValues.add("rainbow");
|
|
|
|
possibleValues.add("random");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches);
|
|
|
|
} else if (args.length == 4 && effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
|
|
|
|
if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) { // Block material
|
|
|
|
StringUtil.copyPartialMatches(args[3], ParticleUtils.getAllBlockMaterials(), matches);
|
|
|
|
} else if (effect == ParticleEffect.ITEM) { // Item material
|
|
|
|
StringUtil.copyPartialMatches(args[3], ParticleUtils.getAllItemMaterials(), matches);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "remove":
|
|
|
|
case "info":
|
|
|
|
StringUtil.copyPartialMatches(args[1], pplayer.getFixedEffectIds().stream().map(String::valueOf).collect(Collectors.toList()), matches);
|
|
|
|
break;
|
|
|
|
case "clear":
|
|
|
|
matches.add("<radius>");
|
|
|
|
break;
|
|
|
|
case "list":
|
|
|
|
break;
|
2018-10-07 21:18:19 -06:00
|
|
|
}
|
|
|
|
}
|
2019-04-28 00:17:08 -06:00
|
|
|
|
2018-10-07 21:18:19 -06:00
|
|
|
return matches;
|
2018-09-27 18:16:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getName() {
|
|
|
|
return "fixed";
|
|
|
|
}
|
|
|
|
|
2019-12-09 12:04:06 -07:00
|
|
|
public String getDescriptionKey() {
|
|
|
|
return "command-description-fixed";
|
2018-09-27 18:16:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getArguments() {
|
2018-10-16 19:09:20 -06:00
|
|
|
return "<sub-command>";
|
2018-09-27 18:16:50 -06:00
|
|
|
}
|
|
|
|
|
2020-01-05 04:22:02 -07:00
|
|
|
public boolean requiresEffectsAndStyles() {
|
2018-09-27 18:16:50 -06:00
|
|
|
return true;
|
|
|
|
}
|
2018-09-26 23:31:00 -06:00
|
|
|
|
2019-07-16 01:32:45 -06:00
|
|
|
public boolean canConsoleExecute() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-26 02:07:46 -06:00
|
|
|
}
|