Add fixed teleport command, now using InputParser system, fixed issues

This commit is contained in:
Esophose 2020-01-09 18:58:50 -07:00
parent c69860622d
commit f7b4a38b68
25 changed files with 641 additions and 415 deletions

View file

@ -9,6 +9,7 @@
* + Add effect/style settings folder that lets you disable effects/style and edit style properties
* + Add setting to disable particles while in combat
* + Add a command aliases section to the config
* * /ppo now uses your permissions instead of the player you are targetting
*/
/*
@ -29,6 +30,9 @@
* Renamed command-error-no-effects to command-error-missing-effects-or-styles
* Changed message for command-error-missing-effects-or-styles
* Added message gui-no-permission
*
* NEEDS TRANSLATING:
* SECTION TITLED this.put("#23.5", "Fixed Teleport Message");
*/
package dev.esophose.playerparticles;

View file

@ -16,8 +16,10 @@ import dev.esophose.playerparticles.styles.ParticleStyle;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.Material;
@ -476,18 +478,20 @@ public final class PlayerParticlesAPI {
DataManager dataManager = this.playerParticles.getManager(DataManager.class);
ParticleManager particleManager = this.playerParticles.getManager(ParticleManager.class);
int removed = 0;
int removedAmount = 0;
for (PPlayer pplayer : particleManager.getPPlayers()) {
for (FixedParticleEffect fixedEffect : pplayer.getFixedParticles()) {
if (fixedEffect.getLocation().getWorld() == location.getWorld() && fixedEffect.getLocation().distance(location) <= radius) {
pplayer.removeFixedEffect(fixedEffect.getId());
dataManager.removeFixedEffect(pplayer.getUniqueId(), fixedEffect.getId());
removed++;
}
Set<Integer> removedIds = new HashSet<>();
for (FixedParticleEffect fixedEffect : pplayer.getFixedParticles())
if (fixedEffect.getLocation().getWorld() == location.getWorld() && fixedEffect.getLocation().distance(location) <= radius)
removedIds.add(fixedEffect.getId());
for (int id : removedIds) {
dataManager.removeFixedEffect(pplayer.getUniqueId(), id);
pplayer.removeFixedEffect(id);
}
removedAmount += removedIds.size();
}
return removed;
return removedAmount;
}
@Nullable

View file

@ -2,7 +2,6 @@ package dev.esophose.playerparticles.command;
import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.api.PlayerParticlesAPI;
import dev.esophose.playerparticles.manager.DataManager;
import dev.esophose.playerparticles.manager.LocaleManager;
import dev.esophose.playerparticles.manager.ParticleStyleManager;
import dev.esophose.playerparticles.manager.PermissionManager;
@ -16,6 +15,8 @@ import dev.esophose.playerparticles.particles.ParticlePair;
import dev.esophose.playerparticles.styles.ParticleStyle;
import dev.esophose.playerparticles.util.ParticleUtils;
import dev.esophose.playerparticles.util.StringPlaceholders;
import dev.esophose.playerparticles.util.inputparser.InputParser;
import dev.esophose.playerparticles.util.inputparser.parsable.ParsableOrdinaryColor;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material;
@ -38,8 +39,10 @@ public class AddCommandModule implements CommandModule {
localeManager.sendMessage(pplayer, "add-reached-max", StringPlaceholders.single("amount", maxParticlesAllowed));
return;
}
InputParser inputParser = new InputParser(pplayer, args);
ParticleEffect effect = ParticleEffect.fromName(args[0]);
ParticleEffect effect = inputParser.next(ParticleEffect.class);
if (effect == null) {
localeManager.sendMessage(pplayer, "effect-invalid", StringPlaceholders.single("effect", args[0]));
return;
@ -48,7 +51,7 @@ public class AddCommandModule implements CommandModule {
return;
}
ParticleStyle style = ParticleStyle.fromName(args[1]);
ParticleStyle style = inputParser.next(ParticleStyle.class);
if (style == null) {
localeManager.sendMessage(pplayer, "style-invalid", StringPlaceholders.single("style", args[1]));
return;
@ -65,65 +68,28 @@ public class AddCommandModule implements CommandModule {
if (args.length > 2) {
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) {
localeManager.sendMessage(pplayer, "data-invalid-note");
return;
}
if (note < 0 || note > 24) {
localeManager.sendMessage(pplayer, "data-invalid-note");
return;
}
noteColorData = new NoteColor(note);
noteColorData = inputParser.next(NoteColor.class);
if (noteColorData == null) {
localeManager.sendMessage(pplayer, "data-invalid-note");
return;
}
} else {
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) {
localeManager.sendMessage(pplayer, "data-invalid-color");
return;
}
if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
localeManager.sendMessage(pplayer, "data-invalid-color");
return;
}
colorData = new OrdinaryColor(r, g, b);
colorData = inputParser.next(OrdinaryColor.class);
if (colorData == null) {
localeManager.sendMessage(pplayer, "data-invalid-color");
return;
}
}
} else if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) {
try {
blockData = ParticleUtils.closestMatch(args[2]);
if (blockData == null || !blockData.isBlock()) throw new Exception();
} catch (Exception e) {
blockData = inputParser.next(Material.class);
if (blockData == null || !blockData.isBlock()) {
localeManager.sendMessage(pplayer, "data-invalid-block");
return;
}
} else if (effect == ParticleEffect.ITEM) {
try {
itemData = ParticleUtils.closestMatch(args[2]);
if (itemData == null || itemData.isBlock()) throw new Exception();
} catch (Exception e) {
itemData = inputParser.next(Material.class);
if (itemData == null || itemData.isBlock()) {
localeManager.sendMessage(pplayer, "data-invalid-item");
return;
}
@ -168,16 +134,14 @@ public class AddCommandModule implements CommandModule {
possibleValues.add("random");
}
} else { // Color data
if (args.length <= 5 && !args[2].equalsIgnoreCase("rainbow") && !args[2].equalsIgnoreCase("random")) {
possibleValues.add("<0-255>");
}
if (args.length <= 4 && !args[2].equalsIgnoreCase("rainbow") && !args[2].equalsIgnoreCase("random")) {
possibleValues.add("<0-255> <0-255>");
}
if (args.length <= 3) {
possibleValues.add("<0-255> <0-255> <0-255>");
possibleValues.add("rainbow");
possibleValues.add("random");
possibleValues.addAll(ParsableOrdinaryColor.getColorNameMap().keySet());
possibleValues.add("<#hexCode>");
} else if (args.length <= 4 && !ParsableOrdinaryColor.getColorNameMap().containsKey(args[2].toLowerCase())) {
possibleValues.add("<0-255> <0-255>");
} else if (args.length <= 5 && !ParsableOrdinaryColor.getColorNameMap().containsKey(args[2].toLowerCase())) {
possibleValues.add("<0-255>");
}
}
StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches);

View file

@ -15,6 +15,8 @@ import dev.esophose.playerparticles.particles.ParticlePair;
import dev.esophose.playerparticles.styles.ParticleStyle;
import dev.esophose.playerparticles.util.ParticleUtils;
import dev.esophose.playerparticles.util.StringPlaceholders;
import dev.esophose.playerparticles.util.inputparser.InputParser;
import dev.esophose.playerparticles.util.inputparser.parsable.ParsableOrdinaryColor;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material;
@ -30,11 +32,11 @@ public class EditCommandModule implements CommandModule {
CommandModule.printUsage(pplayer, this);
return;
}
int id;
try {
id = Integer.parseInt(args[0]);
} catch (Exception e) {
InputParser inputParser = new InputParser(pplayer, args);
Integer id = inputParser.next(Integer.class);
if (id == null) {
localeManager.sendMessage(pplayer, "id-invalid");
return;
}
@ -78,7 +80,8 @@ public class EditCommandModule implements CommandModule {
private void editEffect(PPlayer pplayer, int id, String[] args) {
LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class);
ParticleEffect effect = ParticleEffect.fromName(args[0]);
InputParser inputParser = new InputParser(pplayer, args);
ParticleEffect effect = inputParser.next(ParticleEffect.class);
if (effect == null) {
localeManager.sendMessage(pplayer, "effect-invalid", StringPlaceholders.single("effect", args[0]));
return;
@ -109,7 +112,8 @@ public class EditCommandModule implements CommandModule {
private void editStyle(PPlayer pplayer, int id, String[] args) {
LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class);
ParticleStyle style = ParticleStyle.fromName(args[0]);
InputParser inputParser = new InputParser(pplayer, args);
ParticleStyle style = inputParser.next(ParticleStyle.class);
if (style == null) {
localeManager.sendMessage(pplayer, "style-invalid", StringPlaceholders.single("style", args[0]));
return;
@ -144,70 +148,34 @@ public class EditCommandModule implements CommandModule {
Material blockData = null;
OrdinaryColor colorData = null;
NoteColor noteColorData = null;
ParticleEffect effect = pplayer.getActiveParticle(id).getEffect();
InputParser inputParser = new InputParser(pplayer, args);
if (effect.hasProperty(ParticleProperty.COLORABLE)) {
if (effect == ParticleEffect.NOTE) {
if (args[0].equalsIgnoreCase("rainbow")) {
noteColorData = new NoteColor(99);
} else if (args[0].equalsIgnoreCase("random")) {
noteColorData = new NoteColor(98);
} else {
int note;
try {
note = Integer.parseInt(args[0]);
} catch (Exception e) {
localeManager.sendMessage(pplayer, "data-invalid-note");
return;
}
if (note < 0 || note > 24) {
localeManager.sendMessage(pplayer, "data-invalid-note");
return;
}
noteColorData = new NoteColor(note);
noteColorData = inputParser.next(NoteColor.class);
if (noteColorData == null) {
localeManager.sendMessage(pplayer, "data-invalid-note");
return;
}
} else {
if (args[0].equalsIgnoreCase("rainbow")) {
colorData = new OrdinaryColor(999, 999, 999);
} else if (args[0].equalsIgnoreCase("random")) {
colorData = new OrdinaryColor(998, 998, 998);
} else {
int r, g, b;
try {
r = Integer.parseInt(args[0]);
g = Integer.parseInt(args[1]);
b = Integer.parseInt(args[2]);
} catch (Exception e) {
localeManager.sendMessage(pplayer, "data-invalid-color");
return;
}
if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
localeManager.sendMessage(pplayer, "data-invalid-color");
return;
}
colorData = new OrdinaryColor(r, g, b);
colorData = inputParser.next(OrdinaryColor.class);
if (colorData == null) {
localeManager.sendMessage(pplayer, "data-invalid-color");
return;
}
}
} else if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) {
try {
blockData = ParticleUtils.closestMatch(args[0]);
if (blockData == null || !blockData.isBlock()) throw new Exception();
} catch (Exception e) {
blockData = inputParser.next(Material.class);
if (blockData == null || !blockData.isBlock()) {
localeManager.sendMessage(pplayer, "data-invalid-block");
return;
}
} else if (effect == ParticleEffect.ITEM) {
try {
itemData = ParticleUtils.closestMatch(args[0]);
if (itemData == null || itemData.isBlock()) throw new Exception();
} catch (Exception e) {
itemData = inputParser.next(Material.class);
if (itemData == null || itemData.isBlock()) {
localeManager.sendMessage(pplayer, "data-invalid-item");
return;
}
@ -279,16 +247,14 @@ public class EditCommandModule implements CommandModule {
possibleValues.add("random");
}
} else { // Color data
if (args.length <= 5 && !args[2].equalsIgnoreCase("rainbow") && !args[2].equalsIgnoreCase("random")) {
possibleValues.add("<0-255>");
}
if (args.length <= 4 && !args[2].equalsIgnoreCase("rainbow") && !args[2].equalsIgnoreCase("random")) {
possibleValues.add("<0-255> <0-255>");
}
if (args.length <= 3) {
possibleValues.add("<0-255> <0-255> <0-255>");
possibleValues.add("rainbow");
possibleValues.add("random");
possibleValues.addAll(ParsableOrdinaryColor.getColorNameMap().keySet());
possibleValues.add("<#hexCode>");
} else if (args.length <= 4 && !ParsableOrdinaryColor.getColorNameMap().containsKey(args[2].toLowerCase())) {
possibleValues.add("<0-255> <0-255>");
} else if (args.length <= 5 && !ParsableOrdinaryColor.getColorNameMap().containsKey(args[2].toLowerCase())) {
possibleValues.add("<0-255>");
}
}
StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches);

View file

@ -2,9 +2,7 @@ package dev.esophose.playerparticles.command;
import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.api.PlayerParticlesAPI;
import dev.esophose.playerparticles.manager.DataManager;
import dev.esophose.playerparticles.manager.LocaleManager;
import dev.esophose.playerparticles.manager.ParticleManager;
import dev.esophose.playerparticles.manager.PermissionManager;
import dev.esophose.playerparticles.particles.FixedParticleEffect;
import dev.esophose.playerparticles.particles.PPlayer;
@ -16,16 +14,16 @@ import dev.esophose.playerparticles.particles.ParticlePair;
import dev.esophose.playerparticles.styles.ParticleStyle;
import dev.esophose.playerparticles.util.ParticleUtils;
import dev.esophose.playerparticles.util.StringPlaceholders;
import dev.esophose.playerparticles.util.inputparser.InputParser;
import dev.esophose.playerparticles.util.inputparser.parsable.ParsableOrdinaryColor;
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;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
@ -48,6 +46,7 @@ public class FixedCommandModule implements CommandModule {
localeManager.sendMessage(pplayer, "command-description-fixed-list");
localeManager.sendMessage(pplayer, "command-description-fixed-info");
localeManager.sendMessage(pplayer, "command-description-fixed-clear");
localeManager.sendMessage(pplayer, "command-description-fixed-teleport");
return;
}
@ -75,6 +74,9 @@ public class FixedCommandModule implements CommandModule {
case "clear":
this.handleClear(pplayer, p, cmdArgs);
return;
case "teleport":
this.handleTeleport(pplayer, p, cmdArgs);
return;
default:
localeManager.sendMessage(pplayer, "fixed-invalid-command");
localeManager.sendMessage(pplayer, "command-description-fixed-create");
@ -83,6 +85,7 @@ public class FixedCommandModule implements CommandModule {
localeManager.sendMessage(pplayer, "command-description-fixed-list");
localeManager.sendMessage(pplayer, "command-description-fixed-info");
localeManager.sendMessage(pplayer, "command-description-fixed-clear");
localeManager.sendMessage(pplayer, "command-description-fixed-teleport");
}
}
@ -107,65 +110,25 @@ public class FixedCommandModule implements CommandModule {
return;
}
double xPos, yPos, zPos;
if (args[0].equalsIgnoreCase("looking")) {
Block targetBlock = p.getTargetBlock((Set<Material>) null, 8); // Need the Set<Material> cast for 1.9 support
int maxDistanceSqrd = 6 * 6;
if (targetBlock.getLocation().distanceSquared(p.getLocation()) > maxDistanceSqrd) {
InputParser inputParser = new InputParser(pplayer, args);
Location location = inputParser.next(Location.class);
if (location == null) {
if (args[0].equalsIgnoreCase("looking")) {
localeManager.sendMessage(pplayer, "fixed-create-looking-too-far");
return;
}
Location blockLocation = targetBlock.getLocation().clone().add(0.5, 0.5, 0.5); // Center of block
xPos = blockLocation.getX();
yPos = blockLocation.getY();
zPos = blockLocation.getZ();
// 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);
System.arraycopy(args, 1, paddedArgs, 3, args.length - 1);
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]);
}
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]);
}
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) {
} else {
localeManager.sendMessage(pplayer, "fixed-create-invalid-coords");
return;
}
return;
}
double distanceFromEffect = p.getLocation().distance(new Location(p.getWorld(), xPos, yPos, zPos));
double distanceFromEffect = p.getLocation().distance(location);
int maxCreationDistance = permissionManager.getMaxFixedEffectCreationDistance();
if (maxCreationDistance != 0 && distanceFromEffect > maxCreationDistance) {
localeManager.sendMessage(pplayer, "fixed-create-out-of-range", StringPlaceholders.single("range", maxCreationDistance));
return;
}
ParticleEffect effect = ParticleEffect.fromName(args[3]);
ParticleEffect effect = inputParser.next(ParticleEffect.class);
if (effect == null) {
localeManager.sendMessage(pplayer, "fixed-create-effect-invalid", StringPlaceholders.single("effect", args[3]));
return;
@ -174,7 +137,7 @@ public class FixedCommandModule implements CommandModule {
return;
}
ParticleStyle style = ParticleStyle.fromName(args[4]);
ParticleStyle style = inputParser.next(ParticleStyle.class);
if (style == null) {
localeManager.sendMessage(pplayer, "fixed-create-style-invalid", StringPlaceholders.single("style", args[4]));
return;
@ -193,85 +156,40 @@ public class FixedCommandModule implements CommandModule {
OrdinaryColor colorData = null;
NoteColor noteColorData = null;
if (args.length > 5) {
if (inputParser.hasNext() && (effect.hasProperty(ParticleProperty.COLORABLE) || effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA))) {
if (effect.hasProperty(ParticleProperty.COLORABLE)) {
if (effect == ParticleEffect.NOTE) {
if (args[5].equalsIgnoreCase("rainbow")) {
noteColorData = new NoteColor(99);
} else if (args[5].equalsIgnoreCase("random")) {
noteColorData = new NoteColor(98);
} else {
int note;
try {
note = Integer.parseInt(args[5]);
} catch (Exception e) {
localeManager.sendMessage(pplayer, "fixed-create-data-error");
return;
}
if (note < 0 || note > 24) {
localeManager.sendMessage(pplayer, "fixed-create-data-error");
return;
}
noteColorData = new NoteColor(note);
noteColorData = inputParser.next(NoteColor.class);
if (noteColorData == null) {
localeManager.sendMessage(pplayer, "fixed-create-data-error");
return;
}
} else {
if (args[5].equalsIgnoreCase("rainbow")) {
colorData = new OrdinaryColor(999, 999, 999);
} else if (args[5].equalsIgnoreCase("random")) {
colorData = new OrdinaryColor(998, 998, 998);
} else {
int r, g, b;
try {
r = Integer.parseInt(args[5]);
g = Integer.parseInt(args[6]);
b = Integer.parseInt(args[7]);
} catch (Exception e) {
localeManager.sendMessage(pplayer, "fixed-create-data-error");
return;
}
if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
localeManager.sendMessage(pplayer, "fixed-create-data-error");
return;
}
colorData = new OrdinaryColor(r, g, b);
colorData = inputParser.next(OrdinaryColor.class);
if (colorData == null) {
localeManager.sendMessage(pplayer, "fixed-create-data-error");
return;
}
}
} else if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) {
Material material;
try {
material = ParticleUtils.closestMatch(args[5]);
if (material == null) material = Material.matchMaterial(args[5]);
if (material == null || !material.isBlock()) throw new Exception();
} catch (Exception e) {
blockData = inputParser.next(Material.class);
if (blockData == null || !blockData.isBlock()) {
localeManager.sendMessage(pplayer, "fixed-create-data-error");
return;
}
blockData = material;
} else if (effect == ParticleEffect.ITEM) {
Material material;
try {
material = ParticleUtils.closestMatch(args[5]);
if (material == null) material = Material.matchMaterial(args[5]);
if (material == null || material.isBlock()) throw new Exception();
} catch (Exception e) {
itemData = inputParser.next(Material.class);
if (itemData == null || itemData.isBlock()) {
localeManager.sendMessage(pplayer, "fixed-create-data-error");
return;
}
itemData = material;
}
}
}
ParticlePair particle = new ParticlePair(pplayer.getUniqueId(), pplayer.getNextFixedEffectId(), effect, style, itemData, blockData, colorData, noteColorData);
PlayerParticlesAPI.getInstance().createFixedParticleEffect(pplayer.getPlayer(), new Location(p.getLocation().getWorld(), xPos, yPos, zPos), particle);
PlayerParticlesAPI.getInstance().createFixedParticleEffect(pplayer.getPlayer(), location, particle);
localeManager.sendMessage(pplayer, "fixed-create-success");
}
@ -291,10 +209,10 @@ public class FixedCommandModule implements CommandModule {
return;
}
int id;
try {
id = Integer.parseInt(args[0]);
} catch (Exception ex) {
InputParser inputParser = new InputParser(pplayer, args);
Integer id = inputParser.next(Integer.class);
if (id == null) {
localeManager.sendMessage(pplayer, "fixed-edit-invalid-id");
return;
}
@ -305,63 +223,30 @@ public class FixedCommandModule implements CommandModule {
return;
}
String editType = args[1].toLowerCase();
String editType = inputParser.next(String.class);
switch (editType) {
case "location":
double xPos, yPos, zPos;
if (args[2].equalsIgnoreCase("looking")) {
Block targetBlock = p.getTargetBlock((Set<Material>) null, 8); // Need the Set<Material> cast for 1.9 support
int maxDistanceSqrd = 6 * 6;
if (targetBlock.getLocation().distanceSquared(p.getLocation()) > maxDistanceSqrd) {
Location location = inputParser.next(Location.class);
if (location == null) {
if (args[2].equalsIgnoreCase("looking")) {
localeManager.sendMessage(pplayer, "fixed-edit-looking-too-far");
return;
}
Location blockLocation = targetBlock.getLocation().clone().add(0.5, 0.5, 0.5); // Center of block
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) {
} else {
localeManager.sendMessage(pplayer, "fixed-edit-invalid-coords");
return;
}
return;
}
double distanceFromEffect = p.getLocation().distance(new Location(p.getWorld(), xPos, yPos, zPos));
double distanceFromEffect = p.getLocation().distance(location);
int maxCreationDistance = permissionManager.getMaxFixedEffectCreationDistance();
if (maxCreationDistance != 0 && distanceFromEffect > maxCreationDistance) {
localeManager.sendMessage(pplayer, "fixed-edit-out-of-range", StringPlaceholders.single("range", maxCreationDistance));
return;
}
fixedEffect.setCoordinates(xPos, yPos, zPos);
fixedEffect.setCoordinates(location.getX(), location.getY(), location.getZ());
break;
case "effect": {
ParticleEffect effect = ParticleEffect.fromName(args[2]);
ParticleEffect effect = inputParser.next(ParticleEffect.class);
if (effect == null) {
localeManager.sendMessage(pplayer, "fixed-edit-effect-invalid", StringPlaceholders.single("effect", args[2]));
return;
@ -374,7 +259,7 @@ public class FixedCommandModule implements CommandModule {
break;
}
case "style":
ParticleStyle style = ParticleStyle.fromName(args[2]);
ParticleStyle style = inputParser.next(ParticleStyle.class);
if (style == null) {
localeManager.sendMessage(pplayer, "fixed-edit-style-invalid", StringPlaceholders.single("style", args[2]));
return;
@ -397,76 +282,31 @@ public class FixedCommandModule implements CommandModule {
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) {
localeManager.sendMessage(pplayer, "fixed-edit-data-error");
return;
}
if (note < 0 || note > 24) {
localeManager.sendMessage(pplayer, "fixed-edit-data-error");
return;
}
noteColorData = new NoteColor(note);
noteColorData = inputParser.next(NoteColor.class);
if (noteColorData == null) {
localeManager.sendMessage(pplayer, "fixed-edit-data-error");
return;
}
} else {
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) {
localeManager.sendMessage(pplayer, "fixed-edit-data-error");
return;
}
if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
localeManager.sendMessage(pplayer, "fixed-edit-data-error");
return;
}
colorData = new OrdinaryColor(r, g, b);
colorData = inputParser.next(OrdinaryColor.class);
if (colorData == null) {
localeManager.sendMessage(pplayer, "fixed-edit-data-error");
return;
}
}
} else if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) {
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) {
blockData = inputParser.next(Material.class);
if (blockData == null || !blockData.isBlock()) {
localeManager.sendMessage(pplayer, "fixed-edit-data-error");
return;
}
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) {
itemData = inputParser.next(Material.class);
if (itemData == null || itemData.isBlock()) {
localeManager.sendMessage(pplayer, "fixed-edit-data-error");
return;
}
itemData = material;
}
} else {
localeManager.sendMessage(pplayer, "fixed-edit-data-none");
@ -503,10 +343,10 @@ public class FixedCommandModule implements CommandModule {
return;
}
int id;
try {
id = Integer.parseInt(args[0]);
} catch (Exception e) {
InputParser inputParser = new InputParser(pplayer, args);
Integer id = inputParser.next(Integer.class);
if (id == null) {
localeManager.sendMessage(pplayer, "fixed-remove-args-invalid");
return;
}
@ -563,10 +403,10 @@ public class FixedCommandModule implements CommandModule {
return;
}
int id;
try {
id = Integer.parseInt(args[0]);
} catch (Exception e) {
InputParser inputParser = new InputParser(pplayer, args);
Integer id = inputParser.next(Integer.class);
if (id == null) {
localeManager.sendMessage(pplayer, "fixed-info-invalid-args");
return;
}
@ -602,8 +442,6 @@ public class FixedCommandModule implements CommandModule {
private void handleClear(PPlayer pplayer, Player p, String[] args) {
LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class);
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)) {
localeManager.sendMessage(pplayer, "fixed-clear-no-permission");
@ -615,25 +453,65 @@ public class FixedCommandModule implements CommandModule {
return;
}
int radius;
try {
radius = Math.abs(Integer.parseInt(args[0]));
} catch (Exception e) {
InputParser inputParser = new InputParser(pplayer, args);
Integer radius = inputParser.next(Integer.class);
if (radius == null) {
localeManager.sendMessage(pplayer, "fixed-clear-invalid-args");
return;
}
radius = Math.abs(radius);
int amountRemoved = PlayerParticlesAPI.getInstance().removeFixedEffectsInRange(p.getLocation(), radius);
localeManager.sendMessage(pplayer, "fixed-clear-success", StringPlaceholders.builder("amount", amountRemoved).addPlaceholder("range", radius).build());
}
/**
* Handles the command /pp fixed teleport
*
* @param pplayer The PPlayer
* @param p The Player
* @param args The command arguments
*/
private void handleTeleport(PPlayer pplayer, Player p, String[] args) {
LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class);
PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class);
if (!permissionManager.canTeleportToFixedEffects(p)) {
localeManager.sendMessage(pplayer, "fixed-teleport-no-permission");
return;
}
if (args.length < 1) {
localeManager.sendMessage(pplayer, "fixed-teleport-no-args");
return;
}
InputParser inputParser = new InputParser(pplayer, args);
Integer id = inputParser.next(Integer.class);
if (id == null) {
localeManager.sendMessage(pplayer, "fixed-teleport-invalid-args");
return;
}
FixedParticleEffect fixedEffect = pplayer.getFixedEffectById(id);
if (fixedEffect == null) {
localeManager.sendMessage(pplayer, "fixed-teleport-invalid-args");
return;
}
p.teleport(fixedEffect.getLocation());
localeManager.sendMessage(pplayer, "fixed-teleport-success", StringPlaceholders.single("id", id));
}
public List<String> onTabComplete(PPlayer pplayer, String[] args) {
PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class);
Player p = pplayer.getPlayer();
List<String> matches = new ArrayList<>();
if (args.length <= 1) {
List<String> possibleCmds = new ArrayList<>(Arrays.asList("create", "edit", "remove", "list", "info", "clear"));
List<String> possibleCmds = new ArrayList<>(Arrays.asList("create", "edit", "remove", "list", "info", "clear", "teleport"));
if (args.length == 0) matches = possibleCmds;
else StringUtil.copyPartialMatches(args[0], possibleCmds, matches);
} else {
@ -678,16 +556,14 @@ public class FixedCommandModule implements CommandModule {
possibleValues.add("random");
}
} else { // Color data
if (args.length <= 9 && !args[2].equalsIgnoreCase("rainbow") && !args[2].equalsIgnoreCase("random")) {
possibleValues.add("<0-255>");
}
if (args.length <= 8 && !args[2].equalsIgnoreCase("rainbow") && !args[2].equalsIgnoreCase("random")) {
possibleValues.add("<0-255> <0-255>");
}
if (args.length <= 7) {
possibleValues.add("<0-255> <0-255> <0-255>");
possibleValues.add("rainbow");
possibleValues.add("random");
possibleValues.addAll(ParsableOrdinaryColor.getColorNameMap().keySet());
possibleValues.add("<#hexCode>");
} else if (args.length <= 8 && !ParsableOrdinaryColor.getColorNameMap().containsKey(args[2].toLowerCase())) {
possibleValues.add("<0-255> <0-255>");
} else if (args.length <= 9 && !ParsableOrdinaryColor.getColorNameMap().containsKey(args[2].toLowerCase())) {
possibleValues.add("<0-255>");
}
}
StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches);
@ -710,7 +586,7 @@ public class FixedCommandModule implements CommandModule {
} else {
String property = args[2].toLowerCase();
if (property.equals("location")) {
List<String> possibleValues = new ArrayList<String>();
List<String> possibleValues = new ArrayList<>();
if (args.length == 6 && !args[3].equalsIgnoreCase("looking")) {
possibleValues.add("~");
}
@ -744,16 +620,14 @@ public class FixedCommandModule implements CommandModule {
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) {
if (args.length <= 4) {
possibleValues.add("<0-255> <0-255> <0-255>");
possibleValues.add("rainbow");
possibleValues.add("random");
possibleValues.addAll(ParsableOrdinaryColor.getColorNameMap().keySet());
possibleValues.add("<#hexCode>");
} else if (args.length <= 5 && !ParsableOrdinaryColor.getColorNameMap().containsKey(args[3].toLowerCase())) {
possibleValues.add("<0-255> <0-255>");
} else if (args.length <= 6 && !ParsableOrdinaryColor.getColorNameMap().containsKey(args[3].toLowerCase())) {
possibleValues.add("<0-255>");
}
}
StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches);
@ -770,6 +644,7 @@ public class FixedCommandModule implements CommandModule {
break;
case "remove":
case "info":
case "teleport":
StringUtil.copyPartialMatches(args[1], pplayer.getFixedEffectIds().stream().map(String::valueOf).collect(Collectors.toList()), matches);
break;
case "clear":

View file

@ -55,6 +55,9 @@ public class EnglishLocale implements Locale {
this.put("command-description-fixed-list", "&e/pp fixed list - Lists all IDs of your fixed effects");
this.put("command-description-fixed-info", "&e/pp fixed info <ID> - Gets info on one of your fixed effects");
this.put("command-description-fixed-clear", "&e/pp fixed clear <radius> - Clears all fixed effects of all players within the given radius");
this.put("command-description-fixed-teleport", "&e/pp fixed teleport <id> - Teleports you to one of your fixed effects");
this.put("#2.5", "Group Command Description Messages");
this.put("command-description-group-save", "&e/pp group save <name> - Saves all active particles in a new group");
this.put("command-description-group-load", "&e/pp group load <name> - Loads all particles saved in a group");
this.put("command-description-group-remove", "&e/pp group remove <name> - Removes a group you have saved");
@ -213,6 +216,12 @@ public class EnglishLocale implements Locale {
this.put("fixed-clear-invalid-args", "&cThe radius you provided is invalid, it must be a positive whole number!");
this.put("fixed-clear-success", "&aCleared &b%amount% &afixed effects within &b%range% &ablocks of your location!");
this.put("#23.5", "Fixed Teleport Message");
this.put("fixed-teleport-no-permission", "&cYou do not have permission to teleport to fixed effects!");
this.put("fixed-teleport-no-args", "&cYou did not specify an ID to teleport to!");
this.put("fixed-teleport-invalid-args", "&cUnable to teleport, the ID specified is invalid!");
this.put("fixed-teleport-success", "&eTeleported to your fixed effect with an ID of &b%id%&e!");
this.put("#24", "Fixed Other Messages");
this.put("fixed-no-permission", "&cYou do not have permission to use fixed effects!");
this.put("fixed-max-reached", "&cYou have reached the maximum allowed fixed effects!");

View file

@ -51,10 +51,13 @@ public class FrenchLocale implements Locale {
this.put("#2", "Fixed Particle Command Description Messages");
this.put("command-description-fixed-create", "&e/pp fixed create <<x> <y> <z>|<looking>> <effect> <style> [data] - Créez une particule fixe");
this.put("command-description-fixed-edit", "&e/pp fixed edit <id> <effect|style|data> <args> - Modifiez une partie d'une particule fixe par son ID");
this.put("command-description-fixed-remove", "&e/pp fixed remove <ID> - Supprimez une particule fixe par son ID");
this.put("command-description-fixed-remove", "&e/pp fixed remove <id> - Supprimez une particule fixe par son ID");
this.put("command-description-fixed-list", "&e/pp fixed list - Affiche l'ID de tous vos effets fixes");
this.put("command-description-fixed-info", "&e/pp fixed info <ID> - Voir des informations sur l'une de vos particules fixe");
this.put("command-description-fixed-info", "&e/pp fixed info <id> - Voir des informations sur l'une de vos particules fixe");
this.put("command-description-fixed-clear", "&e/pp fixed clear <radius> - Supprimez tous les effets fixe de tous les joueurs d'un rayon");
this.put("command-description-fixed-teleport", "&e/pp fixed teleport <id> - Vous téléporte vers un de vos effets fixes");
this.put("#2.5", "Group Command Description Messages");
this.put("command-description-group-save", "&e/pp group save <name> - Sauvegardez toutes les particules actives dans un nouveau groupe");
this.put("command-description-group-load", "&e/pp group load <name> - Chargez toutes les particules sauvegardées dans un groupe");
this.put("command-description-group-remove", "&e/pp group remove <name> - Supprimez un groupe que vous avez créé");
@ -213,6 +216,12 @@ public class FrenchLocale implements Locale {
this.put("fixed-clear-invalid-args", "&cLe rayon rentré n'est pas valide, il doit être un nombre rond !");
this.put("fixed-clear-success", "&b%amount% &aeffets ont été supprimés dans un rayon &b%range% &cblocs !");
this.put("#23.5", "Fixed Teleport Message");
this.put("fixed-teleport-no-permission", "&cVous n'avez pas l'autorisation de vous téléporter dans les effets fixes !");
this.put("fixed-teleport-no-args", "&cVous n'avez pas spécifié d'identifiant pour la téléportation !");
this.put("fixed-teleport-invalid-args", "&cImpossible de se téléporter, l'ID spécifié n'est pas valide !");
this.put("fixed-teleport-success", "&eTéléporté à votre effet fixe avec un ID de &b%id%&e !");
this.put("#24", "Fixed Other Messages");
this.put("fixed-no-permission", "&cVous n'avez pas la permission d'ajouter des effets fixes !");
this.put("fixed-max-reached", "&cVous avez atteint le nombre maximum de particules fixes !");

View file

@ -51,10 +51,13 @@ public class GermanLocale implements Locale {
this.put("#2", "Fixed Particle Command Description Messages");
this.put("command-description-fixed-create", "&e/pp fixed create <<x> <y> <z>|<looking>> <effect> <style> [data] - Erstellt einen neun fixen Effekt");
this.put("command-description-fixed-edit", "&e/pp fixed edit <id> <effect|style|data> <args> - Bearbeiten Sie einen Teil eines festen Effekts anhand seiner ID");
this.put("command-description-fixed-remove", "&e/pp fixed remove <ID> - Entfernt einen festen Effekt anhand seiner ID");
this.put("command-description-fixed-remove", "&e/pp fixed remove <id> - Entfernt einen festen Effekt anhand seiner ID");
this.put("command-description-fixed-list", "&e/pp fixed list - Listet alle IDs Ihrer festen Effekte auf");
this.put("command-description-fixed-info", "&e/pp fixed info <ID> - Ruft Informationen zu einem Ihrer Fixen Effekte ab");
this.put("command-description-fixed-info", "&e/pp fixed info <id> - Ruft Informationen zu einem Ihrer Fixen Effekte ab");
this.put("command-description-fixed-clear", "&e/pp fixed clear <radius> - Löscht alle festen Effekte aller Spieler innerhalb des angegebenen Radius");
this.put("command-description-fixed-teleport", "&e/pp fixed teleport <id> - Teleportiert Sie zu einem Ihrer festen Effekte");
this.put("#2.5", "Group Command Description Messages");
this.put("command-description-group-save", "&e/pp group save <name> - Speichert alle aktiven Partikel in einer neuen Gruppe");
this.put("command-description-group-load", "&e/pp group load <name> - Lädt alle in einer Gruppe gespeicherten Partikel");
this.put("command-description-group-remove", "&e/pp group remove <name> - Entfernt eine gespeicherte Gruppe");
@ -213,6 +216,12 @@ public class GermanLocale implements Locale {
this.put("fixed-clear-invalid-args", "&cDer von Ihnen angegebene Radius ist ungültig. Es muss sich um eine positive ganze Zahl handeln.");
this.put("fixed-clear-success", "&aEntfernte &b%amount% &aEffekte in &b%range% &aBlöcken von Ihrem Standort entfernt!");
this.put("#23.5", "Fixed Teleport Message");
this.put("fixed-teleport-no-permission", "&cSie haben nicht die Erlaubnis, sich zu festen Effekten zu teleportieren!");
this.put("fixed-teleport-no-args", "&cSie haben keine ID zum Teleportieren angegeben!");
this.put("fixed-teleport-invalid-args", "&cEs kann nicht teleportiert werden, die angegebene ID ist ungültig!");
this.put("fixed-teleport-success", "&eTeleportiert zu Ihrem festen Effekt mit einer ID von &b%id%&e!");
this.put("#24", "Fixed Other Messages");
this.put("fixed-no-permission", "&cSie haben keine Berechtigung, Fixeffekte zu verwenden!");
this.put("fixed-max-reached", "&cSie haben die maximal zulässigen festen Effekte erreicht!");

View file

@ -51,10 +51,13 @@ public class RussianLocale implements Locale {
this.put("#2", "Fixed Particle Command Description Messages");
this.put("command-description-fixed-create", "&e/pp fixed create «x> <y> <z>|<looking» <Эффект> <Стиль> [данные] - Создаёт новый эффект.");
this.put("command-description-fixed-edit", "&e/pp fixed edit <id> <Эффект|Стиль|Данные> <аргумент> - Изменяет чать эффекта по его ID.");
this.put("command-description-fixed-remove", "&e/pp fixed remove <ID> - Удаляет эффект по его ID.");
this.put("command-description-fixed-remove", "&e/pp fixed remove <id> - Удаляет эффект по его ID.");
this.put("command-description-fixed-list", "&e/pp fixed list - Показывает список ID всех Ваших эффектов.");
this.put("command-description-fixed-info", "&e/pp fixed info <ID> - Показывает информацию об одном из Ваших эффектов.");
this.put("command-description-fixed-info", "&e/pp fixed info <id> - Показывает информацию об одном из Ваших эффектов.");
this.put("command-description-fixed-clear", "&e/pp fixed clear <Радиус> - Удаляет все эффекты игроков, находящихся в заданном радиусе.");
this.put("command-description-fixed-teleport", "&e/pp fixed teleport <id> - Телепортирует вас к одному из ваших фиксированных эффектов");
this.put("#2.5", "Group Command Description Messages");
this.put("command-description-group-save", "&e/pp group save <Имя> - Сохраняет все активные частицы в новой группе.");
this.put("command-description-group-load", "&e/pp group load <name> - Загружает все частицы, сохранённые в группе.");
this.put("command-description-group-remove", "&e/pp group remove <name> - Удаляет сохранённую Вами группу.");
@ -213,6 +216,12 @@ public class RussianLocale implements Locale {
this.put("fixed-clear-invalid-args", "&cВведённый радиус недействителен, это должно быть целое число!");
this.put("fixed-clear-success", "&aУбрано эффектов - &b%amount%&a!");
this.put("#23.5", "Fixed Teleport Message");
this.put("fixed-teleport-no-permission", "&cВы не имеете права телепортироваться на фиксированные эффекты!");
this.put("fixed-teleport-no-args", "&cВы не указали ID для телепортации!");
this.put("fixed-teleport-invalid-args", "&cНевозможно телепортироваться, указанный идентификатор недействителен!");
this.put("fixed-teleport-success", "&eТелепортироваться на ваш фиксированный эффект с ID &b%id%&e!");
this.put("#24", "Fixed Other Messages");
this.put("fixed-no-permission", "&cУ Вас нет права, чтобы использовать этот эффект!");
this.put("fixed-max-reached", "&cВы достигли максимального количества эффектов!");

View file

@ -51,10 +51,13 @@ public class SimplifiedChineseLocale implements Locale {
this.put("#2", "Fixed Particle Command Description Messages");
this.put("command-description-fixed-create", "&e/pp fixed create <<x> <y> <z>|<looking>> <特效名> <风格名> [数据名] - 创建新的定点特效");
this.put("command-description-fixed-edit", "&e/pp fixed edit <id> <特效名|风格名|数据名> <参数> - 根据ID编辑定点特效");
this.put("command-description-fixed-remove", "&e/pp fixed remove <ID> - 根据ID删除定点特效");
this.put("command-description-fixed-remove", "&e/pp fixed remove <id> - 根据ID删除定点特效");
this.put("command-description-fixed-list", "&e/pp fixed list - 列出所有定点特效的ID");
this.put("command-description-fixed-info", "&e/pp fixed info <ID> - 获取定点特效的详细信息");
this.put("command-description-fixed-info", "&e/pp fixed info <id> - 获取定点特效的详细信息");
this.put("command-description-fixed-clear", "&e/pp fixed clear <半径> - 清空指定范围内的所有定点特效");
this.put("command-description-fixed-teleport", "&e/pp fixed teleport <id> - 传送你到固定效果之一");
this.put("#2.5", "Group Command Description Messages");
this.put("command-description-group-save", "&e/pp group save <组名> - 保存所有你使用的特效到新的组内");
this.put("command-description-group-load", "&e/pp group load <组名> - 加载所有你保存组内的特效");
this.put("command-description-group-remove", "&e/pp group remove <组名> - 删除一组你保存的特效");
@ -213,6 +216,12 @@ public class SimplifiedChineseLocale implements Locale {
this.put("fixed-clear-invalid-args", "&c你输入的范围无效范围必须是正整数!");
this.put("fixed-clear-success", "&a已清除&b%amount%&a个&b%range%&a格内的定点特效!");
this.put("#23.5", "Fixed Teleport Message");
this.put("fixed-teleport-no-permission", "&c您无权传送到固定效果!");
this.put("fixed-teleport-no-args", "&c您没有指定要传送到的ID!");
this.put("fixed-teleport-invalid-args", "&c无法传送指定的ID无效!");
this.put("fixed-teleport-success", "&e传送到ID&b%id%&e的固定效果!");
this.put("#24", "Fixed Other Messages");
this.put("fixed-no-permission", "&c你没有使用定点特效的权限!");
this.put("fixed-max-reached", "&c你已达到可使用定点特效的数量上限!");

View file

@ -51,10 +51,13 @@ public class VietnameseLocale implements Locale {
this.put("#2", "Fixed Particle Command Description Messages");
this.put("command-description-fixed-create", "&e/pp fixed create <<x> <y> <z>|<looking>> <effect> <style> [data] - Tạo mới một hiệu ứng cố định");
this.put("command-description-fixed-edit", "&e/pp fixed edit <id> <effect|style|data> <args> - Chỉnh sửa hiệu ứng cố định bằng IDs của nó");
this.put("command-description-fixed-remove", "&e/pp fixed remove <ID> - Xóa hiệu ứng cố định");
this.put("command-description-fixed-remove", "&e/pp fixed remove <id> - Xóa hiệu ứng cố định");
this.put("command-description-fixed-list", "&e/pp fixed list - Danh sách các hiệu ứng cố định dưới dạng IDs");
this.put("command-description-fixed-info", "&e/pp fixed info <ID> - Hiển thị thông tin về hiệu ứng cố định");
this.put("command-description-fixed-info", "&e/pp fixed info <id> - Hiển thị thông tin về hiệu ứng cố định");
this.put("command-description-fixed-clear", "&e/pp fixed clear <radius> - Xóa toàn bộ hiệu ứng trong khu vực bán kính");
this.put("command-description-fixed-teleport", "&e/pp fixed teleport <id> - Dịch chuyển bạn đến một trong những hiệu ứng cố định của bạn");
this.put("#2.5", "Group Command Description Messages");
this.put("command-description-group-save", "&e/pp group save <name> - Lưu toàn bộ hiêu ứng hoạt động vào Group mới");
this.put("command-description-group-load", "&e/pp group load <name> - Load toàn bộ hiệu ứng hoạt động trong group");
this.put("command-description-group-remove", "&e/pp group remove <name> - Xóa một group bạn đã lưu");
@ -213,6 +216,12 @@ public class VietnameseLocale implements Locale {
this.put("fixed-clear-invalid-args", "&cbán kính được cung cấp không hợp lệ, nó phải là một số nguyên dương!");
this.put("fixed-clear-success", "&aĐã xóa &b%amount% &aHiệu ứng cố định trong bán kính &b%range% &akhối từ vị trí của bạn!");
this.put("#23.5", "Fixed Teleport Message");
this.put("fixed-teleport-no-permission", "&cBạn không có quyền dịch chuyển tức thời đến các hiệu ứng cố định!");
this.put("fixed-teleport-no-args", "&cBạn đã không chỉ định một ID để dịch chuyển đến!");
this.put("fixed-teleport-invalid-args", "&cKhông thể dịch chuyển tức thời, ID được chỉ định không hợp lệ!");
this.put("fixed-teleport-success", "&eĐược dịch chuyển đến hiệu ứng cố định của bạn với ID &b%id%&e!");
this.put("#24", "Fixed Other Messages");
this.put("fixed-no-permission", "&cBạn không có quyền để làm điều này!");
this.put("fixed-max-reached", "&cBạn đã đạt tới giới hạn số Hiệu ứng cố định có thể sử dụng!");

View file

@ -50,6 +50,7 @@ public class ConfigurationManager extends Manager {
PARTICLE_RENDER_RANGE_PLAYER("particle-render-range-player", 48, "From how many blocks away should a player be able to see the particles from another player?"),
PARTICLE_RENDER_RANGE_FIXED_EFFECT("particle-render-range-fixed-effect", 32, "From how many blocks away should a player be able to see the particles from a fixed effect?"),
RAINBOW_CYCLE_SPEED("rainbow-cycle-speed", 2, "How many out of 360 hue ticks to move per game tick", "Higher values make the rainbow cycle faster", "Note: Must be a positive whole number"),
DUST_SIZE("dust-size", 1, "How large should dust particles appear?", "Note: Can include decimals"),
MYSQL_SETTINGS("mysql-settings", null, "Settings for if you want to use MySQL for data management"),
MYSQL_ENABLED("mysql-settings.enabled", false, "Enable MySQL", "If false, SQLite will be used instead"),
@ -227,6 +228,14 @@ public class ConfigurationManager extends Manager {
return this.getNumber();
}
/**
* @return the setting as a float
*/
public float getFloat() {
this.loadValue();
return (float) this.getNumber();
}
/**
* @return the setting as a String
*/

View file

@ -22,6 +22,7 @@ public class PermissionManager extends Manager {
FIXED("fixed"),
FIXED_UNLIMITED("fixed.unlimited"),
FIXED_CLEAR("fixed.clear"),
FIXED_TELEPORT("fixed.teleport"),
RELOAD("reload"),
OVERRIDE("override"),
@ -281,6 +282,16 @@ public class PermissionManager extends Manager {
return PPermission.FIXED_CLEAR.check(player);
}
/**
* Checks if a player has permission to teleport to fixed effects
*
* @param player The player to check the permission for
* @return True if the player has permission to use /pp fixed teleport
*/
public boolean canTeleportToFixedEffects(Player player) {
return PPermission.FIXED_TELEPORT.check(player);
}
/**
* Checks if a player has permission to open the GUI
*

View file

@ -223,7 +223,7 @@ public enum ParticleEffect {
if (this == DUST && NMSUtil.getVersionNumber() >= 13) { // DUST uses a special data object for spawning in 1.13
OrdinaryColor dustColor = (OrdinaryColor) color;
DustOptions dustOptions = new DustOptions(Color.fromRGB(dustColor.getRed(), dustColor.getGreen(), dustColor.getBlue()), 1);
DustOptions dustOptions = new DustOptions(Color.fromRGB(dustColor.getRed(), dustColor.getGreen(), dustColor.getBlue()), Setting.DUST_SIZE.getFloat());
for (Player player : this.getPlayersInRange(center, isFixedEffect, owner)) {
player.spawnParticle(this.internalEnum, center.getX(), center.getY(), center.getZ(), 1, 0, 0, 0, 0, dustOptions);
}
@ -555,6 +555,10 @@ public enum ParticleEffect {
}
public interface ParticleData {
}
/**
* Represents a runtime exception that is thrown either if the displayed
* particle effect requires data and has none or vice-versa or if the data

View file

@ -1,22 +0,0 @@
package dev.esophose.playerparticles.util;
import dev.esophose.playerparticles.particles.PPlayer;
import dev.esophose.playerparticles.particles.ParticleEffect;
import dev.esophose.playerparticles.styles.ParticleStyle;
import org.bukkit.Location;
public final class InputParser {
public static ParticleEffect parseEffect(PPlayer pplayer, String input) {
return null;
}
public static ParticleStyle parseStyle(PPlayer pplayer, String input) {
return null;
}
public static Location parseLocation(PPlayer pplayer, String input) {
return null;
}
}

View file

@ -0,0 +1,75 @@
package dev.esophose.playerparticles.util.inputparser;
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.styles.ParticleStyle;
import dev.esophose.playerparticles.util.inputparser.parsable.ParsableInteger;
import dev.esophose.playerparticles.util.inputparser.parsable.ParsableLocation;
import dev.esophose.playerparticles.util.inputparser.parsable.ParsableMaterial;
import dev.esophose.playerparticles.util.inputparser.parsable.ParsableNoteColor;
import dev.esophose.playerparticles.util.inputparser.parsable.ParsableOrdinaryColor;
import dev.esophose.playerparticles.util.inputparser.parsable.ParsableParticleEffect;
import dev.esophose.playerparticles.util.inputparser.parsable.ParsableParticleStyle;
import dev.esophose.playerparticles.util.inputparser.parsable.ParsableString;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.Material;
public class InputParser {
private static Map<Class<?>, Parsable<?>> inputTypes;
static {
inputTypes = new HashMap<Class<?>, Parsable<?>>() {{
this.put(Integer.class, new ParsableInteger());
this.put(Location.class, new ParsableLocation());
this.put(Material.class, new ParsableMaterial());
this.put(NoteColor.class, new ParsableNoteColor());
this.put(OrdinaryColor.class, new ParsableOrdinaryColor());
this.put(ParticleEffect.class, new ParsableParticleEffect());
this.put(ParticleStyle.class, new ParsableParticleStyle());
this.put(String.class, new ParsableString());
}};
}
private PPlayer pplayer;
private List<String> input;
public InputParser(PPlayer pplayer, String[] inputs) {
this.pplayer = pplayer;
this.input = new ArrayList<>(Arrays.asList(inputs));
}
/**
* Gets the next input parsed and casted to the desired type
*
* @param type The type of input to parse
* @param <T> The input class type
* @return The parsed input, casted to the desired type, or null if it was unable to be parsed
*/
@SuppressWarnings("unchecked")
public <T> T next(Class<T> type) {
if (!inputTypes.containsKey(type))
throw new IllegalArgumentException("Cannot handle given type: " + type.getName());
try {
return (T) inputTypes.get(type).parse(this.pplayer, this.input);
} catch (Exception e) {
return null;
}
}
/**
* @return true if there are remaining inputs to be parsed
*/
public boolean hasNext() {
return !this.input.isEmpty();
}
}

View file

@ -0,0 +1,23 @@
package dev.esophose.playerparticles.util.inputparser;
import dev.esophose.playerparticles.particles.PPlayer;
import java.util.List;
public abstract class Parsable<T> {
protected Class<T> targetType;
public Parsable(Class<T> targetType) {
this.targetType = targetType;
}
/**
* Consumes and parses input from the list
*
* @param pplayer The PPlayer who entered the input
* @param inputs The input contents to try parsing
* @return The parsed value or null if parsing failed
*/
public abstract T parse(PPlayer pplayer, List<String> inputs);
}

View file

@ -0,0 +1,19 @@
package dev.esophose.playerparticles.util.inputparser.parsable;
import dev.esophose.playerparticles.particles.PPlayer;
import dev.esophose.playerparticles.util.inputparser.Parsable;
import java.util.List;
public class ParsableInteger extends Parsable<Integer> {
public ParsableInteger() {
super(Integer.class);
}
@Override
public Integer parse(PPlayer pplayer, List<String> inputs) {
String input = inputs.remove(0);
return Integer.parseInt(input);
}
}

View file

@ -0,0 +1,61 @@
package dev.esophose.playerparticles.util.inputparser.parsable;
import dev.esophose.playerparticles.particles.PPlayer;
import dev.esophose.playerparticles.util.inputparser.Parsable;
import java.util.List;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
public class ParsableLocation extends Parsable<Location> {
public ParsableLocation() {
super(Location.class);
}
@Override
public Location parse(PPlayer pplayer, List<String> inputs) {
String input = inputs.remove(0);
Player player = pplayer.getPlayer();
if (input.equalsIgnoreCase("looking")) {
Block targetBlock = player.getTargetBlock((Set<Material>) null, 8); // Need the Set<Material> cast for 1.9 support
int maxDistanceSqrd = 6 * 6;
if (targetBlock.getLocation().distanceSquared(player.getLocation()) > maxDistanceSqrd)
return null; // Looking at a block too far away
return targetBlock.getLocation().clone().add(0.5, 0.5, 0.5); // Center of block
}
String input2 = inputs.remove(0);
String input3 = inputs.remove(0);
double x, y, z;
if (input.startsWith("~")) {
if (input.equals("~")) x = player.getLocation().getX();
else x = player.getLocation().getX() + Double.parseDouble(input.substring(1));
} else {
x = Double.parseDouble(input);
}
if (input2.startsWith("~")) {
if (input2.equals("~")) y = player.getLocation().getY();
else y = player.getLocation().getY() + Double.parseDouble(input2.substring(1));
} else {
y = Double.parseDouble(input);
}
if (input3.startsWith("~")) {
if (input3.equals("~")) z = player.getLocation().getZ();
else z = player.getLocation().getZ() + Double.parseDouble(input3.substring(1));
} else {
z = Double.parseDouble(input);
}
return new Location(player.getWorld(), x, y, z);
}
}

View file

@ -0,0 +1,20 @@
package dev.esophose.playerparticles.util.inputparser.parsable;
import dev.esophose.playerparticles.particles.PPlayer;
import dev.esophose.playerparticles.util.inputparser.Parsable;
import java.util.List;
import org.bukkit.Material;
public class ParsableMaterial extends Parsable<Material> {
public ParsableMaterial() {
super(Material.class);
}
@Override
public Material parse(PPlayer pplayer, List<String> inputs) {
String input = inputs.remove(0);
return Material.getMaterial(input);
}
}

View file

@ -0,0 +1,27 @@
package dev.esophose.playerparticles.util.inputparser.parsable;
import dev.esophose.playerparticles.particles.PPlayer;
import dev.esophose.playerparticles.particles.ParticleEffect.NoteColor;
import dev.esophose.playerparticles.util.inputparser.Parsable;
import java.util.List;
public class ParsableNoteColor extends Parsable<NoteColor> {
public ParsableNoteColor() {
super(NoteColor.class);
}
@Override
public NoteColor parse(PPlayer pplayer, List<String> inputs) {
String input = inputs.remove(0);
if (input.equalsIgnoreCase("rainbow")) {
return new NoteColor(99);
} else if (input.equalsIgnoreCase("random")) {
return new NoteColor(98);
}
int note = Integer.parseInt(input);
return new NoteColor(note);
}
}

View file

@ -0,0 +1,74 @@
package dev.esophose.playerparticles.util.inputparser.parsable;
import dev.esophose.playerparticles.particles.PPlayer;
import dev.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor;
import dev.esophose.playerparticles.util.inputparser.Parsable;
import java.awt.Color;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ParsableOrdinaryColor extends Parsable<OrdinaryColor> {
private static Map<String, OrdinaryColor> colorNameMap;
static {
colorNameMap = new HashMap<String, OrdinaryColor>() {{
this.put("red", new OrdinaryColor(255, 0, 0));
this.put("orange", new OrdinaryColor(255, 140, 0));
this.put("yellow", new OrdinaryColor(255, 255, 0));
this.put("lime", new OrdinaryColor(50, 205, 50));
this.put("green", new OrdinaryColor(0, 128, 0));
this.put("blue", new OrdinaryColor(0, 0, 255));
this.put("cyan", new OrdinaryColor(0, 139, 139));
this.put("light_blue", new OrdinaryColor(173, 216, 230));
this.put("purple", new OrdinaryColor(138, 43, 226));
this.put("magenta", new OrdinaryColor(202, 31, 123));
this.put("pink", new OrdinaryColor(255, 182, 193));
this.put("brown", new OrdinaryColor(139, 69, 19));
this.put("black", new OrdinaryColor(0, 0, 0));
this.put("gray", new OrdinaryColor(128, 128, 128));
this.put("light_gray", new OrdinaryColor(192, 192, 192));
this.put("white", new OrdinaryColor(255, 255, 255));
this.put("rainbow", new OrdinaryColor(999, 999, 999));
this.put("random", new OrdinaryColor(998, 998, 998));
}};
}
public ParsableOrdinaryColor() {
super(OrdinaryColor.class);
}
@Override
public OrdinaryColor parse(PPlayer pplayer, List<String> inputs) {
String input = inputs.remove(0);
// Try hex values first
if (input.startsWith("#")) {
try {
Color color = Color.decode(input);
return new OrdinaryColor(color.getRed(), color.getGreen(), color.getBlue());
} catch (NumberFormatException ignored) { }
}
// Try color names
OrdinaryColor namedColor = colorNameMap.get(input.toLowerCase());
if (namedColor != null)
return namedColor;
String input2 = inputs.remove(0);
String input3 = inputs.remove(0);
// Use rgb
return new OrdinaryColor(Integer.parseInt(input), Integer.parseInt(input2), Integer.parseInt(input3));
}
/**
* @return the color String to OrdinaryColor mapping
*/
public static Map<String, OrdinaryColor> getColorNameMap() {
return Collections.unmodifiableMap(colorNameMap);
}
}

View file

@ -0,0 +1,20 @@
package dev.esophose.playerparticles.util.inputparser.parsable;
import dev.esophose.playerparticles.particles.PPlayer;
import dev.esophose.playerparticles.particles.ParticleEffect;
import dev.esophose.playerparticles.util.inputparser.Parsable;
import java.util.List;
public class ParsableParticleEffect extends Parsable<ParticleEffect> {
public ParsableParticleEffect() {
super(ParticleEffect.class);
}
@Override
public ParticleEffect parse(PPlayer pplayer, List<String> inputs) {
String input = inputs.remove(0);
return ParticleEffect.fromName(input);
}
}

View file

@ -0,0 +1,20 @@
package dev.esophose.playerparticles.util.inputparser.parsable;
import dev.esophose.playerparticles.particles.PPlayer;
import dev.esophose.playerparticles.styles.ParticleStyle;
import dev.esophose.playerparticles.util.inputparser.Parsable;
import java.util.List;
public class ParsableParticleStyle extends Parsable<ParticleStyle> {
public ParsableParticleStyle() {
super(ParticleStyle.class);
}
@Override
public ParticleStyle parse(PPlayer pplayer, List<String> inputs) {
String input = inputs.remove(0);
return ParticleStyle.fromName(input);
}
}

View file

@ -0,0 +1,18 @@
package dev.esophose.playerparticles.util.inputparser.parsable;
import dev.esophose.playerparticles.particles.PPlayer;
import dev.esophose.playerparticles.util.inputparser.Parsable;
import java.util.List;
public class ParsableString extends Parsable<String> {
public ParsableString() {
super(String.class);
}
@Override
public String parse(PPlayer pplayer, List<String> inputs) {
return inputs.remove(0);
}
}