Added the ability for the console to manage its own fixed effects

This commit is contained in:
Esophose 2020-01-26 00:02:27 -07:00
parent 4886f10656
commit dcb18d94bb
16 changed files with 371 additions and 166 deletions

View file

@ -6,6 +6,7 @@
+ Added sub-command '/pp fixed teleport <id>' 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

View file

@ -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<FixedParticleEffect> getFixedParticleEffects(@NotNull Player player) {
PPlayer pplayer = this.getPPlayer(player);
public Collection<FixedParticleEffect> getFixedParticleEffects(@NotNull CommandSender sender) {
PPlayer pplayer = this.getPPlayer(sender);
if (pplayer == null)
return new ArrayList<>();

View file

@ -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<Integer> 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<String> onTabComplete(PPlayer pplayer, String[] args) {
PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class);
Player p = pplayer.getPlayer();
List<String> matches = new ArrayList<>();
Player player = pplayer.getPlayer();
boolean isConsole = player == null;
if (args.length <= 1) {
List<String> possibleCmds = new ArrayList<>(Arrays.asList("create", "edit", "remove", "list", "info", "clear", "teleport"));
List<String> 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<String> possibleValues = new ArrayList<>();
if (args.length == 4) {
possibleValues.add("~");
if (args.length == 5) { // console only
possibleValues.add("<world>");
}
if (args.length == 3) {
possibleValues.add("~ ~");
if (args.length == 4 && !args[1].equalsIgnoreCase("looking")) {
if (!isConsole) {
possibleValues.add("~");
} else {
possibleValues.add("<z> <world>");
}
}
if (args.length == 3 && !args[1].equalsIgnoreCase("looking")) {
if (!isConsole) {
possibleValues.add("~ ~");
} else {
possibleValues.add("<y> <z> <world>");
}
}
if (args.length == 2) {
possibleValues.add("~ ~ ~");
possibleValues.add("looking");
if (!isConsole) {
possibleValues.add("~ ~ ~");
possibleValues.add("looking");
} else {
possibleValues.add("<x> <y> <z> <world>");
}
}
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<String> possibleValues = new ArrayList<>();
if (args.length == 7 && isConsole) {
possibleValues.add("<world>");
}
if (args.length == 6 && !args[3].equalsIgnoreCase("looking")) {
possibleValues.add("~");
if (!isConsole) {
possibleValues.add("~");
} else {
possibleValues.add("<z> <world>");
}
}
if (args.length == 5 && !args[3].equalsIgnoreCase("looking")) {
possibleValues.add("~ ~");
if (!isConsole) {
possibleValues.add("~ ~");
} else {
possibleValues.add("<y> <z> <world>");
}
}
if (args.length == 4) {
possibleValues.add("~ ~ ~");
possibleValues.add("looking");
if (!isConsole) {
possibleValues.add("~ ~ ~");
possibleValues.add("looking");
} else {
possibleValues.add("<x> <y> <z> <world>");
}
}
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("<radius>");
if (isConsole) {
if (args.length == 6) {
matches.add("<world>");
}
if (args.length == 5) {
matches.add("<z> <world>");
}
if (args.length == 4) {
matches.add("<y> <z> <world>");
}
if (args.length == 3) {
matches.add("<x> <y> <z> <world>");
}
if (args.length == 2) {
matches.add("<radius> <x> <y> <z> <world>");
}
} else {
matches.add("<radius>");
}
break;
case "list":
break;
@ -675,7 +771,7 @@ public class FixedCommandModule implements CommandModule {
}
public boolean canConsoleExecute() {
return false;
return true;
}
}

View file

@ -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<CommandModule> 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");
}

View file

@ -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 <<x> <y> <z>|<looking>> <effect> <style> [data] - Creates a new fixed effect");
this.put("command-description-fixed-edit", "&e/pp fixed edit <id> <effect|style|data> <args> - Edit part of a fixed effect by its ID");
this.put("command-description-fixed-create-console", "&e/pp fixed create <x> <y> <z> <world> <effect> <style> [data] - Creates a new fixed effect");
this.put("command-description-fixed-edit", "&e/pp fixed edit <id> <effect|style|data|location> <args> - Edit part of a fixed effect by its ID");
this.put("command-description-fixed-remove", "&e/pp fixed remove <ID> - Removes a fixed effect by its ID");
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-clear-console", "&e/pp fixed clear <radius> <x> <y> <z> <world> - 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");

View file

@ -50,11 +50,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-create-console", "&e/pp fixed create <x> <y> <z> <world> <effect> <style> [data] - Créez une particule fixe");
this.put("command-description-fixed-edit", "&e/pp fixed edit <id> <effect|style|data|location> <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-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-clear", "&e/pp fixed clear <radius> - Supprimez tous les effets fixe de tous les joueurs d'un rayon");
this.put("command-description-fixed-clear-console", "&e/pp fixed clear <radius> <x> <y> <z> <world> - 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");

View file

@ -50,11 +50,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-create-console", "&e/pp fixed create <x> <y> <z> <world> <effect> <style> [data] - Erstellt einen neun fixen Effekt");
this.put("command-description-fixed-edit", "&e/pp fixed edit <id> <effect|style|data|location> <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-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-clear", "&e/pp fixed clear <radius> - Löscht alle festen Effekte aller Spieler innerhalb des angegebenen Radius");
this.put("command-description-fixed-clear-console", "&e/pp fixed clear <radius> <x> <y> <z> <world> - 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");

View file

@ -49,12 +49,14 @@ public class RussianLocale implements Locale {
this.put("command-description-worlds", "Узнать, в каком мире Ваши частицы отключены.");
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-create", "&e/pp fixed create <<x> <y> <z>|<looking>> <Эффект> <Стиль> [данные] - Создаёт новый эффект.");
this.put("command-description-fixed-create-console", "&e/pp fixed create <x> <y> <z> <Мир> <Эффект> <Стиль> [данные] - Создаёт новый эффект.");
this.put("command-description-fixed-edit", "&e/pp fixed edit <id> <effect|style|data|location> <аргумент> - Изменяет чать эффекта по его 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-clear", "&e/pp fixed clear <Радиус> - Удаляет все эффекты игроков, находящихся в заданном радиусе.");
this.put("command-description-fixed-clear-console", "&e/pp fixed clear <Радиус> <x> <y> <z> <Мир> - Удаляет все эффекты игроков, находящихся в заданном радиусе.");
this.put("command-description-fixed-teleport", "&e/pp fixed teleport <id> - Телепортирует вас к одному из ваших фиксированных эффектов");
this.put("#2.5", "Group Command Description Messages");
@ -147,11 +149,11 @@ public class RussianLocale implements Locale {
this.put("data-usage-none", "&eЭффект &b%effect% &eне использует какие-либо данные!");
this.put("data-usage-block", "&eЭффект &b%effect% &eзапрашивает &bблок &eданных! &bФормат: <названиеБлока>");
this.put("data-usage-item", "&eЭффект &b%effect% &eзапрашивает &bпредмет &eданных! &bФормат: <названиеПредмета>");
this.put("data-usage-color", "&eЭффект &b%effect% &eзапрашивает &bцвет &eданных! &bФормат: «0-255> <0-255> <0-255»|<rainbow>|<random>");
this.put("data-usage-color", "&eЭффект &b%effect% &eзапрашивает &bцвет &eданных! &bФормат: <0-255> <0-255> <0-255>|<rainbow>|<random>");
this.put("data-usage-note", "&eЭффект &b%effect% &eзапрашивает &bноту &eданных! &bФормат: <0-24>|<rainbow>|<random>");
this.put("data-invalid-block", "&bБлок &cданных, который Вы ввели, недействителен! &bФормат: <названиеБлока>");
this.put("data-invalid-item", "&bПредмет &cданных, который Вы ввели, недействителен! &bФормат: <названиеПредмета>");
this.put("data-invalid-color", "&bЦвет &cданных, который Вы ввели, недействителен! &bФормат: «0-255> <0-255> <0-255»|<rainbow>|<random>");
this.put("data-invalid-color", "&bЦвет &cданных, который Вы ввели, недействителен! &bФормат: <0-255> <0-255> <0-255>|<rainbow>|<random>");
this.put("data-invalid-note", "&bНота &cданных, которую Вы ввели, недействительна! &bФормат: <0-24>|<rainbow>|<random>");
this.put("data-invalid-material-not-item", "&bМатериал &cпредмета&b%material%&c, который Вы ввели, не является предметом!");
this.put("data-invalid-material-not-block", "&bМатериал &cблока&b%material%&c, который Вы ввели, не является блоком!");

View file

@ -50,11 +50,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-create-console", "&e/pp fixed create <x> <y> <z> <世界> <特效名> <风格名> [数据名] - 创建新的定点特效");
this.put("command-description-fixed-edit", "&e/pp fixed edit <id> <effect|style|data|location> <参数> - 根据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-clear", "&e/pp fixed clear <半径> - 清空指定范围内的所有定点特效");
this.put("command-description-fixed-clear-console", "&e/pp fixed clear <半径> <x> <y> <z> <世界> - 清空指定范围内的所有定点特效");
this.put("command-description-fixed-teleport", "&e/pp fixed teleport <id> - 传送你到固定效果之一");
this.put("#2.5", "Group Command Description Messages");

View file

@ -50,11 +50,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-create-console", "&e/pp fixed create <x> <y> <z> <world> <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|location> <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-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-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-clear-console", "&e/pp fixed clear <radius> <x> <y> <z> <world> - 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");

View file

@ -1,6 +1,7 @@
package dev.esophose.playerparticles.manager;
import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.api.PlayerParticlesAPI;
import dev.esophose.playerparticles.command.AddCommandModule;
import dev.esophose.playerparticles.command.CommandModule;
import dev.esophose.playerparticles.command.CommandModuleSecondary;
@ -21,7 +22,6 @@ import dev.esophose.playerparticles.command.StylesCommandModule;
import dev.esophose.playerparticles.command.ToggleCommandModule;
import dev.esophose.playerparticles.command.VersionCommandModule;
import dev.esophose.playerparticles.command.WorldsCommandModule;
import dev.esophose.playerparticles.particles.OtherPPlayer;
import dev.esophose.playerparticles.particles.PPlayer;
import java.util.ArrayList;
import java.util.Arrays;
@ -31,6 +31,7 @@ import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
@ -152,8 +153,8 @@ public class CommandManager extends Manager implements CommandExecutor, TabCompl
sender.sendMessage(ChatColor.RED + "Error: This command can only be executed by a player.");
return true;
}
} else {
commandModule.onCommandExecute(new OtherPPlayer(sender), cmdArgs);
} else if (sender instanceof ConsoleCommandSender) {
commandModule.onCommandExecute(PlayerParticlesAPI.getInstance().getConsolePPlayer(), cmdArgs);
return true;
}
@ -185,10 +186,9 @@ public class CommandManager extends Manager implements CommandExecutor, TabCompl
*/
public List<String> onTabComplete(CommandSender sender, Command cmd, String alias, String[] args) {
if (cmd.getName().equalsIgnoreCase("pp")) {
if (!(sender instanceof Player)) return new ArrayList<>();
PPlayer pplayer = this.playerParticles.getManager(DataManager.class).getPPlayer(((Player) sender).getUniqueId());
if (pplayer == null) return new ArrayList<>();
PPlayer pplayer = PlayerParticlesAPI.getInstance().getPPlayer(sender);
if (pplayer == null)
return new ArrayList<>();
if (args.length <= 1) {
CommandModule commandModule = this.findMatchingCommand(""); // Get the default command module
@ -196,6 +196,9 @@ public class CommandManager extends Manager implements CommandExecutor, TabCompl
} else {
CommandModule commandModule = this.findMatchingCommand(args[0]);
if (commandModule != null) {
if (sender instanceof ConsoleCommandSender && !commandModule.canConsoleExecute())
return new ArrayList<>();
String[] cmdArgs = Arrays.copyOfRange(args, 1, args.length);
return commandModule.onTabComplete(pplayer, cmdArgs);
}

View file

@ -5,6 +5,7 @@ import dev.esophose.playerparticles.database.DatabaseConnector;
import dev.esophose.playerparticles.database.MySQLConnector;
import dev.esophose.playerparticles.database.SQLiteConnector;
import dev.esophose.playerparticles.manager.ConfigurationManager.Setting;
import dev.esophose.playerparticles.particles.ConsolePPlayer;
import dev.esophose.playerparticles.particles.FixedParticleEffect;
import dev.esophose.playerparticles.particles.PPlayer;
import dev.esophose.playerparticles.particles.ParticleEffect;
@ -244,7 +245,12 @@ public class DataManager extends Manager {
groups.put(activeGroup.getName(), activeGroup);
}
PPlayer loadedPPlayer = new PPlayer(playerUUID, groups, fixedParticles, particlesHidden);
PPlayer loadedPPlayer;
if (!playerUUID.equals(ConsolePPlayer.getUUID())) {
loadedPPlayer = new PPlayer(playerUUID, groups, fixedParticles, particlesHidden);
} else {
loadedPPlayer = new ConsolePPlayer(groups, fixedParticles);
}
this.sync(() -> {
synchronized (loadedPPlayer) {

View file

@ -2,6 +2,7 @@ package dev.esophose.playerparticles.manager;
import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.manager.ConfigurationManager.Setting;
import dev.esophose.playerparticles.particles.ConsolePPlayer;
import dev.esophose.playerparticles.particles.FixedParticleEffect;
import dev.esophose.playerparticles.particles.PParticle;
import dev.esophose.playerparticles.particles.PPlayer;
@ -68,6 +69,7 @@ public class ParticleManager extends Manager implements Listener, Runnable {
dataManager.loadFixedEffects();
for (Player player : Bukkit.getOnlinePlayers())
dataManager.getPPlayer(player.getUniqueId(), (pplayer) -> { }); // Loads the PPlayer from the database
dataManager.getPPlayer(ConsolePPlayer.getUUID(), (pplayer) -> { }); // Load the console PPlayer
}
@Override

View file

@ -0,0 +1,38 @@
package dev.esophose.playerparticles.particles;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ConsolePPlayer extends PPlayer {
private static final UUID uuid;
static {
uuid = UUID.fromString("ffffffff-ffff-ffff-ffff-ffffffffffff");
}
public ConsolePPlayer(Map<String, ParticleGroup> particleGroups, Map<Integer, FixedParticleEffect> fixedParticles) {
super(uuid, particleGroups, fixedParticles, false);
}
/**
* @return the underlying ConsoleCommandSender who executed the command
*/
@Override
public CommandSender getUnderlyingExecutor() {
return Bukkit.getConsoleSender();
}
@Override
public Player getPlayer() {
return null;
}
public static UUID getUUID() {
return uuid;
}
}

View file

@ -23,6 +23,7 @@ public class OtherPPlayer extends PPlayer {
/**
* @return the underlying CommandSender who executed the command
*/
@Override
public CommandSender getUnderlyingExecutor() {
return this.sender;
}

View file

@ -4,8 +4,10 @@ import dev.esophose.playerparticles.particles.PPlayer;
import dev.esophose.playerparticles.util.inputparser.Parsable;
import java.util.List;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
@ -20,7 +22,7 @@ public class ParsableLocation extends Parsable<Location> {
String input = inputs.remove(0);
Player player = pplayer.getPlayer();
if (input.equalsIgnoreCase("looking")) {
if (player != null && 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)
@ -34,28 +36,38 @@ public class ParsableLocation extends Parsable<Location> {
double x, y, z;
if (input.startsWith("~")) {
if (player != null && 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 (player != null && input2.startsWith("~")) {
if (input2.equals("~")) y = player.getLocation().getY();
else y = player.getLocation().getY() + Double.parseDouble(input2.substring(1));
} else {
y = Double.parseDouble(input);
y = Double.parseDouble(input2);
}
if (input3.startsWith("~")) {
if (player != null && input3.startsWith("~")) {
if (input3.equals("~")) z = player.getLocation().getZ();
else z = player.getLocation().getZ() + Double.parseDouble(input3.substring(1));
} else {
z = Double.parseDouble(input);
z = Double.parseDouble(input3);
}
return new Location(player.getWorld(), x, y, z);
World world;
if (player == null) {
world = Bukkit.getWorld(inputs.remove(0));
} else {
world = player.getWorld();
}
if (world == null)
return null;
return new Location(world, x, y, z);
}
}