From dcb18d94bb4dfdca301320c2be2481e7ef90fb58 Mon Sep 17 00:00:00 2001 From: Esophose Date: Sun, 26 Jan 2020 00:02:27 -0700 Subject: [PATCH] Added the ability for the console to manage its own fixed effects --- changelog.txt | 1 + .../api/PlayerParticlesAPI.java | 146 ++++++---- .../command/FixedCommandModule.java | 264 ++++++++++++------ .../command/HelpCommandModule.java | 4 +- .../playerparticles/locale/EnglishLocale.java | 4 +- .../playerparticles/locale/FrenchLocale.java | 4 +- .../playerparticles/locale/GermanLocale.java | 4 +- .../playerparticles/locale/RussianLocale.java | 10 +- .../locale/SimplifiedChineseLocale.java | 4 +- .../locale/VietnameseLocale.java | 4 +- .../manager/CommandManager.java | 17 +- .../playerparticles/manager/DataManager.java | 8 +- .../manager/ParticleManager.java | 2 + .../particles/ConsolePPlayer.java | 38 +++ .../particles/OtherPPlayer.java | 1 + .../parsable/ParsableLocation.java | 26 +- 16 files changed, 371 insertions(+), 166 deletions(-) create mode 100644 src/main/java/dev/esophose/playerparticles/particles/ConsolePPlayer.java diff --git a/changelog.txt b/changelog.txt index 74f1a4f..e075adf 100644 --- a/changelog.txt +++ b/changelog.txt @@ -6,6 +6,7 @@ + Added sub-command '/pp fixed teleport ' that requires the permission playerparticles.fixed.teleport + Added named colors to the color data autocomplete + Added an API, accessible through the dev.esophose.playerparticles.api.PlayerParticlesAPI class ++ Added the ability for the console to manage its own fixed effects + Added PlaceholderAPI support + Added permission playerparticles.override for /ppo + Added permission playerparticles.gui to open the GUI. Disabled in the config by default diff --git a/src/main/java/dev/esophose/playerparticles/api/PlayerParticlesAPI.java b/src/main/java/dev/esophose/playerparticles/api/PlayerParticlesAPI.java index dddbaf2..bc8de2e 100644 --- a/src/main/java/dev/esophose/playerparticles/api/PlayerParticlesAPI.java +++ b/src/main/java/dev/esophose/playerparticles/api/PlayerParticlesAPI.java @@ -5,6 +5,7 @@ import dev.esophose.playerparticles.manager.DataManager; import dev.esophose.playerparticles.manager.GuiManager; import dev.esophose.playerparticles.manager.ParticleManager; import dev.esophose.playerparticles.manager.ParticleStyleManager; +import dev.esophose.playerparticles.particles.ConsolePPlayer; import dev.esophose.playerparticles.particles.FixedParticleEffect; import dev.esophose.playerparticles.particles.PPlayer; import dev.esophose.playerparticles.particles.ParticleEffect; @@ -23,6 +24,8 @@ import java.util.Set; import java.util.UUID; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -81,6 +84,35 @@ public final class PlayerParticlesAPI { return this.getPPlayer(player.getUniqueId()); } + /** + * Gets a PPlayer from a CommandSender + * + * @param sender The CommandSender, either a Player or ConsoleCommandSender + * @return The PPlayer, or null if not found + */ + @Nullable + public PPlayer getPPlayer(@NotNull CommandSender sender) { + Objects.requireNonNull(sender); + + if (sender instanceof Player) { + return this.getPPlayer((Player) sender); + } else if (sender instanceof ConsoleCommandSender) { + return this.getConsolePPlayer(); + } + + return null; + } + + /** + * Gets the PPlayer representing the console + * + * @return The PPlayer, or null if not found + */ + @Nullable + public PPlayer getConsolePPlayer() { + return this.getPPlayer(ConsolePPlayer.getUUID()); + } + //endregion //region Manage Active Player Particles @@ -489,21 +521,21 @@ public final class PlayerParticlesAPI { /** * Creates a fixed particle effect for a player * - * @param player The player to create for + * @param sender The sender to create for, either a Player or ConsoleCommandSender * @param location The location to create at * @param particle The particle to display */ - public void createFixedParticleEffect(@NotNull Player player, @NotNull Location location, @NotNull ParticlePair particle) { + public void createFixedParticleEffect(@NotNull CommandSender sender, @NotNull Location location, @NotNull ParticlePair particle) { Objects.requireNonNull(location); Objects.requireNonNull(location.getWorld()); Objects.requireNonNull(particle); DataManager dataManager = this.playerParticles.getManager(DataManager.class); - PPlayer pplayer = this.getPPlayer(player); + PPlayer pplayer = this.getPPlayer(sender); if (pplayer == null) return; - FixedParticleEffect fixedEffect = new FixedParticleEffect(player.getUniqueId(), pplayer.getNextFixedEffectId(), location, particle); + FixedParticleEffect fixedEffect = new FixedParticleEffect(pplayer.getUniqueId(), pplayer.getNextFixedEffectId(), location, particle); pplayer.addFixedEffect(fixedEffect); dataManager.saveFixedEffect(fixedEffect); } @@ -511,58 +543,58 @@ public final class PlayerParticlesAPI { /** * Creates a fixed particle effect for a player * - * @param player The player to create for + * @param sender The sender to create for, either a Player or ConsoleCommandSender * @param location The location to create at * @param effect The effect of the particle * @param style The style of the particle */ - public void createFixedParticleEffect(@NotNull Player player, @NotNull Location location, @NotNull ParticleEffect effect, @NotNull ParticleStyle style) { - this.createFixedParticleEffect(player, location, effect, style, null, null, null); + public void createFixedParticleEffect(@NotNull CommandSender sender, @NotNull Location location, @NotNull ParticleEffect effect, @NotNull ParticleStyle style) { + this.createFixedParticleEffect(sender, location, effect, style, null, null, null); } /** * Creates a fixed particle effect for a player * - * @param player The player to create for + * @param sender The sender to create for, either a Player or ConsoleCommandSender * @param location The location to create at * @param effect The effect of the particle * @param style The style of the particle * @param colorData The color data of the particle */ - public void createFixedParticleEffect(@NotNull Player player, @NotNull Location location, @NotNull ParticleEffect effect, @NotNull ParticleStyle style, @NotNull OrdinaryColor colorData) { - this.createFixedParticleEffect(player, location, effect, style, colorData, null, null); + public void createFixedParticleEffect(@NotNull CommandSender sender, @NotNull Location location, @NotNull ParticleEffect effect, @NotNull ParticleStyle style, @NotNull OrdinaryColor colorData) { + this.createFixedParticleEffect(sender, location, effect, style, colorData, null, null); } /** * Creates a fixed particle effect for a player * - * @param player The player to create for + * @param sender The sender to create for, either a Player or ConsoleCommandSender * @param location The location to create at * @param effect The effect of the particle * @param style The style of the particle * @param noteColorData The note color data of the particle */ - public void createFixedParticleEffect(@NotNull Player player, @NotNull Location location, @NotNull ParticleEffect effect, @NotNull ParticleStyle style, @NotNull NoteColor noteColorData) { - this.createFixedParticleEffect(player, location, effect, style, null, noteColorData, null); + public void createFixedParticleEffect(@NotNull CommandSender sender, @NotNull Location location, @NotNull ParticleEffect effect, @NotNull ParticleStyle style, @NotNull NoteColor noteColorData) { + this.createFixedParticleEffect(sender, location, effect, style, null, noteColorData, null); } /** * Creates a fixed particle effect for a player * - * @param player The player to create for + * @param sender The sender to create for, either a Player or ConsoleCommandSender * @param location The location to create at * @param effect The effect of the particle * @param style The style of the particle * @param materialData The material data of the particle */ - public void createFixedParticleEffect(@NotNull Player player, @NotNull Location location, @NotNull ParticleEffect effect, @NotNull ParticleStyle style, @NotNull Material materialData) { - this.createFixedParticleEffect(player, location, effect, style, null, null, materialData); + public void createFixedParticleEffect(@NotNull CommandSender sender, @NotNull Location location, @NotNull ParticleEffect effect, @NotNull ParticleStyle style, @NotNull Material materialData) { + this.createFixedParticleEffect(sender, location, effect, style, null, null, materialData); } /** * Creates a fixed particle effect for a player * - * @param player The player to create for + * @param sender The sender to create for, either a Player or ConsoleCommandSender * @param location The location to create at * @param effect The effect of the particle * @param style The style of the particle @@ -570,13 +602,13 @@ public final class PlayerParticlesAPI { * @param noteColorData The note color data of the particle * @param materialData The material data of the particle */ - private void createFixedParticleEffect(@NotNull Player player, @NotNull Location location, @NotNull ParticleEffect effect, @NotNull ParticleStyle style, @Nullable OrdinaryColor colorData, @Nullable NoteColor noteColorData, @Nullable Material materialData) { + private void createFixedParticleEffect(@NotNull CommandSender sender, @NotNull Location location, @NotNull ParticleEffect effect, @NotNull ParticleStyle style, @Nullable OrdinaryColor colorData, @Nullable NoteColor noteColorData, @Nullable Material materialData) { Objects.requireNonNull(location); Objects.requireNonNull(location.getWorld()); Objects.requireNonNull(effect); Objects.requireNonNull(style); - PPlayer pplayer = this.getPPlayer(player); + PPlayer pplayer = this.getPPlayer(sender); if (pplayer == null) return; @@ -590,25 +622,25 @@ public final class PlayerParticlesAPI { } } - ParticlePair particle = new ParticlePair(player.getUniqueId(), 1, effect, style, itemMaterialData, blockMaterialData, colorData, noteColorData); - this.createFixedParticleEffect(player, location, particle); + ParticlePair particle = new ParticlePair(pplayer.getUniqueId(), 1, effect, style, itemMaterialData, blockMaterialData, colorData, noteColorData); + this.createFixedParticleEffect(sender, location, particle); } /** * Edits a fixed particle effect for a player * - * @param player The player to edit from + * @param sender The sender to edit from, either a Player or ConsoleCommandSender * @param fixedEffect The modified fixed effect to edit */ - public void editFixedParticleEffect(@NotNull Player player, @NotNull FixedParticleEffect fixedEffect) { + public void editFixedParticleEffect(@NotNull CommandSender sender, @NotNull FixedParticleEffect fixedEffect) { Objects.requireNonNull(fixedEffect); - PPlayer pplayer = this.getPPlayer(player); + PPlayer pplayer = this.getPPlayer(sender); if (pplayer == null) return; DataManager dataManager = this.playerParticles.getManager(DataManager.class); - if (this.validateFixedParticleEffect(player, fixedEffect.getId()) != null) { + if (this.validateFixedParticleEffect(sender, fixedEffect.getId()) != null) { pplayer.removeFixedEffect(fixedEffect.getId()); pplayer.addFixedEffect(fixedEffect); dataManager.updateFixedEffect(fixedEffect); @@ -618,16 +650,16 @@ public final class PlayerParticlesAPI { /** * Edits a fixed particle effect for a player * - * @param player The player to edit from + * @param sender The sender to edit from, either a Player or ConsoleCommandSender * @param id The ID of the fixed particle effect * @param location The new location */ - public void editFixedParticleEffect(@NotNull Player player, int id, @NotNull Location location) { + public void editFixedParticleEffect(@NotNull CommandSender sender, int id, @NotNull Location location) { Objects.requireNonNull(location); Objects.requireNonNull(location.getWorld()); DataManager dataManager = this.playerParticles.getManager(DataManager.class); - FixedParticleEffect fixedEffect = this.validateFixedParticleEffect(player, id); + FixedParticleEffect fixedEffect = this.validateFixedParticleEffect(sender, id); if (fixedEffect != null) { fixedEffect.setCoordinates(location.getX(), location.getY(), location.getZ()); dataManager.saveFixedEffect(fixedEffect); @@ -637,15 +669,15 @@ public final class PlayerParticlesAPI { /** * Edits a fixed particle effect for a player * - * @param player The player to edit from + * @param sender The sender to edit from, either a Player or ConsoleCommandSender * @param id The ID of the fixed particle effect * @param effect The new effect */ - public void editFixedParticleEffect(@NotNull Player player, int id, @NotNull ParticleEffect effect) { + public void editFixedParticleEffect(@NotNull CommandSender sender, int id, @NotNull ParticleEffect effect) { Objects.requireNonNull(effect); DataManager dataManager = this.playerParticles.getManager(DataManager.class); - FixedParticleEffect fixedEffect = this.validateFixedParticleEffect(player, id); + FixedParticleEffect fixedEffect = this.validateFixedParticleEffect(sender, id); if (fixedEffect != null) { fixedEffect.getParticlePair().setEffect(effect); dataManager.saveFixedEffect(fixedEffect); @@ -655,15 +687,15 @@ public final class PlayerParticlesAPI { /** * Edits a fixed particle effect for a player * - * @param player The player to edit from + * @param sender The sender to edit from, either a Player or ConsoleCommandSender * @param id The ID of the fixed particle effect * @param style The new style */ - public void editFixedParticleEffect(@NotNull Player player, int id, @NotNull ParticleStyle style) { + public void editFixedParticleEffect(@NotNull CommandSender sender, int id, @NotNull ParticleStyle style) { Objects.requireNonNull(style); DataManager dataManager = this.playerParticles.getManager(DataManager.class); - FixedParticleEffect fixedEffect = this.validateFixedParticleEffect(player, id); + FixedParticleEffect fixedEffect = this.validateFixedParticleEffect(sender, id); if (fixedEffect != null) { fixedEffect.getParticlePair().setStyle(style); dataManager.saveFixedEffect(fixedEffect); @@ -673,15 +705,15 @@ public final class PlayerParticlesAPI { /** * Edits a fixed particle effect for a player * - * @param player The player to edit from + * @param sender The sender to edit from, either a Player or ConsoleCommandSender * @param id The ID of the fixed particle effect * @param colorData The new color data */ - public void editFixedParticleEffect(@NotNull Player player, int id, @NotNull OrdinaryColor colorData) { + public void editFixedParticleEffect(@NotNull CommandSender sender, int id, @NotNull OrdinaryColor colorData) { Objects.requireNonNull(colorData); DataManager dataManager = this.playerParticles.getManager(DataManager.class); - FixedParticleEffect fixedEffect = this.validateFixedParticleEffect(player, id); + FixedParticleEffect fixedEffect = this.validateFixedParticleEffect(sender, id); if (fixedEffect != null) { fixedEffect.getParticlePair().setColor(colorData); dataManager.saveFixedEffect(fixedEffect); @@ -691,15 +723,15 @@ public final class PlayerParticlesAPI { /** * Edits a fixed particle effect for a player * - * @param player The player to edit from + * @param sender The sender to edit from, either a Player or ConsoleCommandSender * @param id The ID of the fixed particle effect * @param noteColorData The new note color data */ - public void editFixedParticleEffect(@NotNull Player player, int id, @NotNull NoteColor noteColorData) { + public void editFixedParticleEffect(@NotNull CommandSender sender, int id, @NotNull NoteColor noteColorData) { Objects.requireNonNull(noteColorData); DataManager dataManager = this.playerParticles.getManager(DataManager.class); - FixedParticleEffect fixedEffect = this.validateFixedParticleEffect(player, id); + FixedParticleEffect fixedEffect = this.validateFixedParticleEffect(sender, id); if (fixedEffect != null) { fixedEffect.getParticlePair().setNoteColor(noteColorData); dataManager.saveFixedEffect(fixedEffect); @@ -709,15 +741,15 @@ public final class PlayerParticlesAPI { /** * Edits a fixed particle effect for a player * - * @param player The player to edit from + * @param sender The sender to edit from, either a Player or ConsoleCommandSender * @param id The ID of the fixed particle effect * @param materialData The new material data */ - public void editFixedParticleEffect(@NotNull Player player, int id, @NotNull Material materialData) { + public void editFixedParticleEffect(@NotNull CommandSender sender, int id, @NotNull Material materialData) { Objects.requireNonNull(materialData); DataManager dataManager = this.playerParticles.getManager(DataManager.class); - FixedParticleEffect fixedEffect = this.validateFixedParticleEffect(player, id); + FixedParticleEffect fixedEffect = this.validateFixedParticleEffect(sender, id); if (fixedEffect != null) { if (materialData.isBlock()) { fixedEffect.getParticlePair().setBlockMaterial(materialData); @@ -731,19 +763,19 @@ public final class PlayerParticlesAPI { /** * Removes a fixed particle effect from a player * - * @param player The player to remove from + * @param sender The sender to remove from, either a Player or ConsoleCommandSender * @param id The ID of the fixed particle effect */ - public void removeFixedEffect(@NotNull Player player, int id) { + public void removeFixedEffect(@NotNull CommandSender sender, int id) { DataManager dataManager = this.playerParticles.getManager(DataManager.class); - FixedParticleEffect fixedEffect = this.validateFixedParticleEffect(player, id); + FixedParticleEffect fixedEffect = this.validateFixedParticleEffect(sender, id); if (fixedEffect != null) { - PPlayer pplayer = this.getPPlayer(player); + PPlayer pplayer = this.getPPlayer(sender); if (pplayer == null) return; pplayer.removeFixedEffect(id); - dataManager.removeFixedEffect(player.getUniqueId(), fixedEffect.getId()); + dataManager.removeFixedEffect(pplayer.getUniqueId(), fixedEffect.getId()); } } @@ -780,13 +812,13 @@ public final class PlayerParticlesAPI { /** * Validates that a fixed particle effect with the given ID exists for a player * - * @param player The player to check + * @param sender The sender to check, either a Player or CommandSender * @param id The ID of the fixed particle effect * @return The fixed particle effect */ @Nullable - private FixedParticleEffect validateFixedParticleEffect(@NotNull Player player, int id) { - PPlayer pplayer = this.getPPlayer(player); + private FixedParticleEffect validateFixedParticleEffect(@NotNull CommandSender sender, int id) { + PPlayer pplayer = this.getPPlayer(sender); if (pplayer == null) return null; @@ -800,13 +832,13 @@ public final class PlayerParticlesAPI { /** * Gets a fixed particle effect for a player * - * @param player The player to get from + * @param sender The sender to get from, either a Player or CommandSender * @param id The ID of the fixed particle effect * @return The fixed particle effect, or null if not found */ @Nullable - public FixedParticleEffect getFixedParticleEffect(@NotNull Player player, int id) { - PPlayer pplayer = this.getPPlayer(player); + public FixedParticleEffect getFixedParticleEffect(@NotNull CommandSender sender, int id) { + PPlayer pplayer = this.getPPlayer(sender); if (pplayer == null) return null; @@ -816,12 +848,12 @@ public final class PlayerParticlesAPI { /** * Gets a collection of a player's fixed particle effects * - * @param player The player to get from + * @param sender The sender to get from, either a Player or CommandSender * @return A collection of the player's fixed particle effects */ @NotNull - public Collection getFixedParticleEffects(@NotNull Player player) { - PPlayer pplayer = this.getPPlayer(player); + public Collection getFixedParticleEffects(@NotNull CommandSender sender) { + PPlayer pplayer = this.getPPlayer(sender); if (pplayer == null) return new ArrayList<>(); diff --git a/src/main/java/dev/esophose/playerparticles/command/FixedCommandModule.java b/src/main/java/dev/esophose/playerparticles/command/FixedCommandModule.java index b3060c2..edcb215 100644 --- a/src/main/java/dev/esophose/playerparticles/command/FixedCommandModule.java +++ b/src/main/java/dev/esophose/playerparticles/command/FixedCommandModule.java @@ -22,6 +22,8 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -32,21 +34,13 @@ public class FixedCommandModule implements CommandModule { public void onCommandExecute(PPlayer pplayer, String[] args) { LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class); - Player p = pplayer.getPlayer(); - if (!PlayerParticles.getInstance().getManager(PermissionManager.class).canUseFixedEffects(pplayer)) { localeManager.sendMessage(pplayer, "fixed-no-permission"); return; } if (args.length == 0) { // General information on 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"); - localeManager.sendMessage(pplayer, "command-description-fixed-teleport"); + this.sendCommandsList(pplayer); return; } @@ -56,36 +50,54 @@ public class FixedCommandModule implements CommandModule { System.arraycopy(args, 1, cmdArgs, 0, args.length - 1); switch (cmd.toLowerCase()) { - case "create": - this.handleCreate(pplayer, p, cmdArgs); - return; - case "edit": - this.handleEdit(pplayer, p, cmdArgs); - return; - case "remove": - this.handleRemove(pplayer, p, cmdArgs); - return; - case "list": - this.handleList(pplayer, p, cmdArgs); - return; - case "info": - this.handleInfo(pplayer, p, cmdArgs); - return; - case "clear": - this.handleClear(pplayer, p, cmdArgs); - return; - case "teleport": - this.handleTeleport(pplayer, p, cmdArgs); - return; - default: - localeManager.sendMessage(pplayer, "fixed-invalid-command"); + case "create": + this.handleCreate(pplayer, cmdArgs); + return; + case "edit": + this.handleEdit(pplayer, cmdArgs); + return; + case "remove": + this.handleRemove(pplayer, cmdArgs); + return; + case "list": + this.handleList(pplayer, cmdArgs); + return; + case "info": + this.handleInfo(pplayer, cmdArgs); + return; + case "clear": + this.handleClear(pplayer, cmdArgs); + return; + case "teleport": + if (pplayer.getPlayer() != null) { + this.handleTeleport(pplayer, cmdArgs); + } else { + pplayer.getUnderlyingExecutor().sendMessage(ChatColor.RED + "Error: This command can only be executed by a player."); + } + return; + default: + this.sendCommandsList(pplayer); + } + } + + private void sendCommandsList(PPlayer pplayer) { + LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class); + + localeManager.sendMessage(pplayer, "fixed-invalid-command"); + if (pplayer.getPlayer() != null) { 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"); + } else { + localeManager.sendMessage(pplayer, "command-description-fixed-create-console"); + } + 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"); + if (pplayer.getPlayer() != null) { localeManager.sendMessage(pplayer, "command-description-fixed-clear"); localeManager.sendMessage(pplayer, "command-description-fixed-teleport"); + } else { + localeManager.sendMessage(pplayer, "command-description-fixed-clear-console"); } } @@ -93,20 +105,26 @@ public class FixedCommandModule implements CommandModule { * Handles the command /pp fixed create * * @param pplayer The PPlayer - * @param p The Player * @param args The command arguments */ - private void handleCreate(PPlayer pplayer, Player p, String[] args) { + private void handleCreate(PPlayer pplayer, String[] args) { LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class); PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class); + Player player = pplayer.getPlayer(); boolean reachedMax = permissionManager.hasPlayerReachedMaxFixedEffects(pplayer); if (reachedMax) { localeManager.sendMessage(pplayer, "fixed-max-reached"); return; } - if (args.length < 5 && !(args.length > 0 && args[0].equalsIgnoreCase("looking") && args.length >= 3)) { - localeManager.sendMessage(pplayer, "fixed-create-missing-args", StringPlaceholders.single("amount", 5 - args.length)); + int argAmount; + if (player != null) { + argAmount = 5; + } else { + argAmount = 6; + } + if (args.length < argAmount && !(args.length > 0 && args[0].equalsIgnoreCase("looking") && args.length >= 3)) { + localeManager.sendMessage(pplayer, "fixed-create-missing-args", StringPlaceholders.single("amount", argAmount - args.length)); return; } @@ -121,11 +139,13 @@ public class FixedCommandModule implements CommandModule { return; } - 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; + if (player != null) { + double distanceFromEffect = player.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 = inputParser.next(ParticleEffect.class); @@ -189,7 +209,7 @@ public class FixedCommandModule implements CommandModule { } ParticlePair particle = new ParticlePair(pplayer.getUniqueId(), pplayer.getNextFixedEffectId(), effect, style, itemData, blockData, colorData, noteColorData); - PlayerParticlesAPI.getInstance().createFixedParticleEffect(pplayer.getPlayer(), location, particle); + PlayerParticlesAPI.getInstance().createFixedParticleEffect(player == null ? Bukkit.getConsoleSender() : player, location, particle); localeManager.sendMessage(pplayer, "fixed-create-success"); } @@ -197,12 +217,12 @@ public class FixedCommandModule implements CommandModule { * Handles the command /pp fixed edit * * @param pplayer The PPlayer - * @param p The Player * @param args The command arguments */ - private void handleEdit(PPlayer pplayer, Player p, String[] args) { + private void handleEdit(PPlayer pplayer, String[] args) { LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class); PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class); + Player player = pplayer.getPlayer(); if (args.length < 3) { localeManager.sendMessage(pplayer, "fixed-edit-missing-args"); @@ -236,11 +256,13 @@ public class FixedCommandModule implements CommandModule { return; } - 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; + if (player != null) { + double distanceFromEffect = player.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(location.getX(), location.getY(), location.getZ()); @@ -324,7 +346,7 @@ public class FixedCommandModule implements CommandModule { return; } - PlayerParticlesAPI.getInstance().editFixedParticleEffect(pplayer.getPlayer(), fixedEffect); + PlayerParticlesAPI.getInstance().editFixedParticleEffect(player == null ? Bukkit.getConsoleSender() : player, fixedEffect); localeManager.sendMessage(pplayer, "fixed-edit-success", StringPlaceholders.builder("prop", editType).addPlaceholder("id", id).build()); } @@ -332,11 +354,11 @@ public class FixedCommandModule implements CommandModule { * Handles the command /pp fixed remove * * @param pplayer The PPlayer - * @param p The Player * @param args The command arguments */ - private void handleRemove(PPlayer pplayer, Player p, String[] args) { + private void handleRemove(PPlayer pplayer, String[] args) { LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class); + Player player = pplayer.getPlayer(); if (args.length < 1) { localeManager.sendMessage(pplayer, "fixed-remove-no-args"); @@ -352,7 +374,7 @@ public class FixedCommandModule implements CommandModule { } if (pplayer.getFixedEffectById(id) != null) { - PlayerParticlesAPI.getInstance().removeFixedEffect(pplayer.getPlayer(), id); + PlayerParticlesAPI.getInstance().removeFixedEffect(player == null ? Bukkit.getConsoleSender() : player, id); localeManager.sendMessage(pplayer, "fixed-remove-success", StringPlaceholders.single("id", id)); } else { localeManager.sendMessage(pplayer, "fixed-remove-invalid", StringPlaceholders.single("id", id)); @@ -363,10 +385,9 @@ public class FixedCommandModule implements CommandModule { * Handles the command /pp fixed list * * @param pplayer The PPlayer - * @param p The Player * @param args The command arguments */ - private void handleList(PPlayer pplayer, Player p, String[] args) { + private void handleList(PPlayer pplayer, String[] args) { LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class); List ids = new ArrayList<>(pplayer.getFixedEffectIds()); @@ -392,10 +413,9 @@ public class FixedCommandModule implements CommandModule { * Handles the command /pp fixed info * * @param pplayer The PPlayer - * @param p The Player * @param args The command arguments */ - private void handleInfo(PPlayer pplayer, Player p, String[] args) { + private void handleInfo(PPlayer pplayer, String[] args) { LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class); if (args.length < 1) { @@ -436,12 +456,12 @@ public class FixedCommandModule implements CommandModule { * Handles the command /pp fixed clear * * @param pplayer The PPlayer - * @param p The Player * @param args The command arguments */ - private void handleClear(PPlayer pplayer, Player p, String[] args) { + private void handleClear(PPlayer pplayer, String[] args) { LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class); PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class); + Player player = pplayer.getPlayer(); if (!permissionManager.canClearFixedEffects(pplayer)) { localeManager.sendMessage(pplayer, "fixed-clear-no-permission"); @@ -462,7 +482,19 @@ public class FixedCommandModule implements CommandModule { } radius = Math.abs(radius); - int amountRemoved = PlayerParticlesAPI.getInstance().removeFixedEffectsInRange(p.getLocation(), radius); + Location location; + if (player != null) { + location = player.getLocation(); + } else { + location = inputParser.next(Location.class); + } + + if (location == null) { + localeManager.sendMessage(pplayer, "fixed-clear-invalid-args"); + return; + } + + int amountRemoved = PlayerParticlesAPI.getInstance().removeFixedEffectsInRange(location, radius); localeManager.sendMessage(pplayer, "fixed-clear-success", StringPlaceholders.builder("amount", amountRemoved).addPlaceholder("range", radius).build()); } @@ -470,12 +502,12 @@ public class FixedCommandModule implements CommandModule { * 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) { + private void handleTeleport(PPlayer pplayer, String[] args) { LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class); PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class); + Player player = pplayer.getPlayer(); if (!permissionManager.canTeleportToFixedEffects(pplayer)) { localeManager.sendMessage(pplayer, "fixed-teleport-no-permission"); @@ -501,45 +533,73 @@ public class FixedCommandModule implements CommandModule { return; } - p.teleport(fixedEffect.getLocation()); + player.teleport(fixedEffect.getLocation()); localeManager.sendMessage(pplayer, "fixed-teleport-success", StringPlaceholders.single("id", id)); } public List onTabComplete(PPlayer pplayer, String[] args) { PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class); - Player p = pplayer.getPlayer(); List matches = new ArrayList<>(); + Player player = pplayer.getPlayer(); + boolean isConsole = player == null; if (args.length <= 1) { - List possibleCmds = new ArrayList<>(Arrays.asList("create", "edit", "remove", "list", "info", "clear", "teleport")); + List possibleCmds; + if (!isConsole) { + possibleCmds = new ArrayList<>(Arrays.asList("create", "edit", "remove", "list", "info", "clear", "teleport")); + } else { + possibleCmds = new ArrayList<>(Arrays.asList("create", "edit", "remove", "list", "info", "clear")); + } if (args.length == 0) matches = possibleCmds; else StringUtil.copyPartialMatches(args[0], possibleCmds, matches); } else { switch (args[0].toLowerCase()) { case "create": - if (args.length <= 4) { + if (args.length <= 4 || (isConsole && args.length <= 5)) { List possibleValues = new ArrayList<>(); - if (args.length == 4) { - possibleValues.add("~"); + if (args.length == 5) { // console only + possibleValues.add(""); } - if (args.length == 3) { - possibleValues.add("~ ~"); + if (args.length == 4 && !args[1].equalsIgnoreCase("looking")) { + if (!isConsole) { + possibleValues.add("~"); + } else { + possibleValues.add(" "); + } + } + if (args.length == 3 && !args[1].equalsIgnoreCase("looking")) { + if (!isConsole) { + possibleValues.add("~ ~"); + } else { + possibleValues.add(" "); + } } if (args.length == 2) { - possibleValues.add("~ ~ ~"); - possibleValues.add("looking"); + if (!isConsole) { + possibleValues.add("~ ~ ~"); + possibleValues.add("looking"); + } else { + possibleValues.add(" "); + } } StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches); } // Pad arguments if the first coordinate is "looking" - if (args[1].equalsIgnoreCase("looking")) { + if (!isConsole && 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; } + // Pad arguments to compensate for the extra 'world' parameter + if (isConsole) { + String[] paddedArgs = Arrays.copyOf(args, args.length + 1); + paddedArgs[args.length] = ""; + args = paddedArgs; + } + if (args.length == 5) { StringUtil.copyPartialMatches(args[4], permissionManager.getEffectNamesUserHasPermissionFor(pplayer), matches); } else if (args.length == 6) { @@ -587,15 +647,30 @@ public class FixedCommandModule implements CommandModule { String property = args[2].toLowerCase(); if (property.equals("location")) { List possibleValues = new ArrayList<>(); + if (args.length == 7 && isConsole) { + possibleValues.add(""); + } if (args.length == 6 && !args[3].equalsIgnoreCase("looking")) { - possibleValues.add("~"); + if (!isConsole) { + possibleValues.add("~"); + } else { + possibleValues.add(" "); + } } if (args.length == 5 && !args[3].equalsIgnoreCase("looking")) { - possibleValues.add("~ ~"); + if (!isConsole) { + possibleValues.add("~ ~"); + } else { + possibleValues.add(" "); + } } if (args.length == 4) { - possibleValues.add("~ ~ ~"); - possibleValues.add("looking"); + if (!isConsole) { + possibleValues.add("~ ~ ~"); + possibleValues.add("looking"); + } else { + possibleValues.add(" "); + } } StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches); } else if (property.equals("effect") && args.length == 4) { @@ -644,11 +719,32 @@ 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 "teleport": + if (!isConsole) + StringUtil.copyPartialMatches(args[1], pplayer.getFixedEffectIds().stream().map(String::valueOf).collect(Collectors.toList()), matches); + break; case "clear": - matches.add(""); + if (isConsole) { + if (args.length == 6) { + matches.add(""); + } + if (args.length == 5) { + matches.add(" "); + } + if (args.length == 4) { + matches.add(" "); + } + if (args.length == 3) { + matches.add(" "); + } + if (args.length == 2) { + matches.add(" "); + } + } else { + matches.add(""); + } break; case "list": break; @@ -675,7 +771,7 @@ public class FixedCommandModule implements CommandModule { } public boolean canConsoleExecute() { - return false; + return true; } } diff --git a/src/main/java/dev/esophose/playerparticles/command/HelpCommandModule.java b/src/main/java/dev/esophose/playerparticles/command/HelpCommandModule.java index ab216e8..7412671 100644 --- a/src/main/java/dev/esophose/playerparticles/command/HelpCommandModule.java +++ b/src/main/java/dev/esophose/playerparticles/command/HelpCommandModule.java @@ -11,12 +11,14 @@ public class HelpCommandModule implements CommandModule { public void onCommandExecute(PPlayer pplayer, String[] args) { LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class); + boolean isConsole = pplayer.getPlayer() == null; localeManager.sendMessage(pplayer, "command-descriptions"); List cmds = PlayerParticles.getInstance().getManager(CommandManager.class).getCommands(); for (CommandModule cmd : cmds) - if (!(cmd instanceof DefaultCommandModule)) + if (!(cmd instanceof DefaultCommandModule) && (!isConsole || cmd.canConsoleExecute())) CommandModule.printUsageWithDescription(pplayer, cmd); + localeManager.sendSimpleMessage(pplayer, "command-descriptions-help-other"); } diff --git a/src/main/java/dev/esophose/playerparticles/locale/EnglishLocale.java b/src/main/java/dev/esophose/playerparticles/locale/EnglishLocale.java index a126b28..51f741e 100644 --- a/src/main/java/dev/esophose/playerparticles/locale/EnglishLocale.java +++ b/src/main/java/dev/esophose/playerparticles/locale/EnglishLocale.java @@ -50,11 +50,13 @@ public class EnglishLocale implements Locale { this.put("#2", "Fixed Particle Command Description Messages"); this.put("command-description-fixed-create", "&e/pp fixed create < |>