Add GUI permission, API methods for custom styles, update some locales

This commit is contained in:
Esophose 2020-01-07 21:32:35 -07:00
parent f997676ee7
commit 2c172f6ff7
15 changed files with 88 additions and 69 deletions

View file

@ -21,12 +21,14 @@
* * The style 'normal' is no longer granted permission by default
* * Fixed an issue where 'random' data would not parse properly in preset_groups.yml
* * Fixed an issue where preset groups would not display in the GUI even if the player has permission for them
* + Added permission playerparticles.override for /ppo
*/
/*
* Changed messages (NEEDS UPDATING IN OTHER LANGUAGES):
* UPDATED LOCALE MESSAGES:
* Renamed command-error-no-effects to command-error-missing-effects-or-styles
* Changed message for command-error-missing-effects-or-styles
* Added message gui-no-permission
*/
package dev.esophose.playerparticles;

View file

@ -3,6 +3,7 @@ package dev.esophose.playerparticles.api;
import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.manager.DataManager;
import dev.esophose.playerparticles.manager.GuiManager;
import dev.esophose.playerparticles.manager.ParticleStyleManager;
import dev.esophose.playerparticles.particles.PPlayer;
import dev.esophose.playerparticles.particles.ParticleEffect;
import dev.esophose.playerparticles.particles.ParticleEffect.NoteColor;
@ -292,9 +293,17 @@ public final class PlayerParticlesAPI {
//endregion
//region Registering Custom Styles
// TODO: Register custom styles
// TODO: Register custom handled styles
// TODO Note: This is currently accessible through ParticleStyleManager
public void registerParticleStyle(@NotNull ParticleStyle particleStyle) {
Objects.requireNonNull(particleStyle);
this.playerParticles.getManager(ParticleStyleManager.class).registerStyle(particleStyle);
}
public void registerEventParticleStyle(@NotNull ParticleStyle particleStyle) {
Objects.requireNonNull(particleStyle);
this.playerParticles.getManager(ParticleStyleManager.class).registerEventStyle(particleStyle);
}
//endregion
}

View file

@ -140,7 +140,7 @@ public class AddCommandModule implements CommandModule {
.addPlaceholder("data", newParticle.getDataString()).build();
localeManager.sendMessage(pplayer, "add-particle-applied", addParticlePlaceholders);
if (PlayerParticles.getInstance().getManager(ParticleStyleManager.class).isCustomHandled(newParticle.getStyle())) {
if (PlayerParticles.getInstance().getManager(ParticleStyleManager.class).isEventHandled(newParticle.getStyle())) {
localeManager.sendMessage(pplayer, "style-event-spawning-info", StringPlaceholders.single("style", newParticle.getStyle().getName()));
}
}

View file

@ -12,9 +12,15 @@ import java.util.List;
public class GUICommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) {
PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class);
LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class);
GuiManager guiManager = PlayerParticles.getInstance().getManager(GuiManager.class);
if (!permissionManager.canOpenGui(pplayer.getPlayer())) {
localeManager.sendMessage(pplayer, "command-no-permission");
return;
}
boolean byDefault = false;
if (args.length > 0 && args[0].equals("_byDefault_")) {
byDefault = true;
@ -29,7 +35,7 @@ public class GUICommandModule implements CommandModule {
return;
}
if (!Setting.GUI_PRESETS_ONLY.getBoolean() && PlayerParticles.getInstance().getManager(PermissionManager.class).getEffectNamesUserHasPermissionFor(pplayer.getPlayer()).isEmpty()) {
if (!Setting.GUI_PRESETS_ONLY.getBoolean() && permissionManager.getEffectNamesUserHasPermissionFor(pplayer.getPlayer()).isEmpty()) {
if (byDefault) {
localeManager.sendMessage(pplayer, "command-error-no-effects");
} else {

View file

@ -223,6 +223,7 @@ public class EnglishLocale implements Locale {
this.put("#26", "GUI Messages");
this.put("gui-disabled", "&cThe server administrator has disabled the GUI!");
this.put("gui-no-permission", "&cYou do not have permission to open the GUI!");
this.put("#27", "GUI Color Messages");
this.put("gui-color-icon-name", "&a");

View file

@ -22,7 +22,7 @@ public class FrenchLocale implements Locale {
this.put("prefix", "&7[&3PlayerParticles&7] ");
this.put("#1", "Command Description Messages");
this.put("command-error-missing-effects-or-styles", "&cVous n'avez pas la permission d'utiliser cette commande.");
this.put("command-error-missing-effects-or-styles", "&cVous devez avoir accès aux effets et aux styles pour utiliser cette commande !");
this.put("command-error-unknown", "&cCommande inconnue, utilisez &b/pp help &cpour afficher la liste des commandes disponibles pour ce plugin.");
this.put("command-descriptions", "&eLes commandes suivantes sont disponibles :");
this.put("command-descriptions-usage", "&e/pp %cmd% %args%");
@ -223,6 +223,7 @@ public class FrenchLocale implements Locale {
this.put("#26", "GUI Messages");
this.put("gui-disabled", "&cL'interface du plugin à été désactivée !");
this.put("gui-no-permission", "&cVous n'avez pas la permission d'ouvrir l'interface graphique !");
this.put("#27", "GUI Color Messages");
this.put("gui-color-icon-name", "&a");

View file

@ -22,7 +22,7 @@ public class GermanLocale implements Locale {
this.put("prefix", "&7[&3PlayerParticles&7] ");
this.put("#1", "Command Description Messages");
this.put("command-error-missing-effects-or-styles", "&cSie müssen Zugriff auf Effekte haben, um diesen Befehl verwenden zu können!");
this.put("command-error-missing-effects-or-styles", "&cSie müssen Zugriff auf Effekte und Stile haben, um diesen Befehl verwenden zu können!");
this.put("command-error-unknown", "&cUnbekannter Befehl. Verwenden Sie &b/pp help &c, um eine Liste der Befehle anzuzeigen.");
this.put("command-descriptions", "Die folgenden Befehle stehen zur Auswahl:");
this.put("command-descriptions-usage", "&e/pp %cmd% %args%");
@ -223,6 +223,7 @@ public class GermanLocale implements Locale {
this.put("#26", "GUI Messages");
this.put("gui-disabled", "&cDer Serveradministrator hat die GUI deaktiviert!");
this.put("gui-no-permission", "&cSie haben keine Berechtigung, das GUI zu öffnen!");
this.put("#27", "GUI Color Messages");
this.put("gui-color-icon-name", "&a");

View file

@ -22,7 +22,7 @@ public class RussianLocale implements Locale {
this.put("prefix", "&7[&3PlayerParticles&7] ");
this.put("#1", "Command Description Messages");
this.put("command-error-missing-effects-or-styles", "&cВы должны иметь доступ к эффектам чтобы использовать эту команду!");
this.put("command-error-missing-effects-or-styles", "&cВы должны иметь доступ к эффектам и стилям, чтобы использовать эту команду!");
this.put("command-error-unknown", "&cНеизвестная команда, напишите &b/pp help &c, чтобы узнать команды.");
this.put("command-descriptions", "&eВам доступны команды ниже:");
this.put("command-descriptions-usage", "&e/pp %cmd% %args%");
@ -223,6 +223,7 @@ public class RussianLocale implements Locale {
this.put("#26", "GUI Messages");
this.put("gui-disabled", "&cАдминистратор отключил интерфейс!");
this.put("gui-no-permission", "&cУ вас нет разрешения на открытие графического интерфейса!");
this.put("#27", "GUI Color Messages");
this.put("gui-color-icon-name", "&a");

View file

@ -22,7 +22,7 @@ public class SimplifiedChineseLocale implements Locale {
this.put("prefix", "&7[&3PlayerParticles&7] ");
this.put("#1", "Command Description Messages");
this.put("command-error-missing-effects-or-styles", "&c你必须有权限使用特效才能使用这个指令!");
this.put("command-error-missing-effects-or-styles", "&c您必须有权使用效果和样式才能使用此命令!");
this.put("command-error-unknown", "&c未知的指令 请使用 &b/pp help &c查看指令列表。");
this.put("command-descriptions", "&e你可以使用以下指令:");
this.put("command-descriptions-usage", "&e/pp %cmd% %args%");
@ -223,6 +223,7 @@ public class SimplifiedChineseLocale implements Locale {
this.put("#26", "GUI Messages");
this.put("gui-disabled", "&c服务器管理员已关闭菜单!");
this.put("gui-no-permission", "&c您无权打开菜单!");
this.put("#27", "GUI Color Messages");
this.put("gui-color-icon-name", "&a");

View file

@ -22,7 +22,7 @@ public class VietnameseLocale implements Locale {
this.put("prefix", "&7[&3PlayerParticles&7] ");
this.put("#1", "Command Description Messages");
this.put("command-error-missing-effects-or-styles", "&cBạn phải có quyền sử dụng hiệu ứng để làm điều này!");
this.put("command-error-missing-effects-or-styles", "&cBạn phải có quyền truy cập vào các hiệu ứng và phong cách để sử dụng lệnh này!");
this.put("command-error-unknown", "&cLệnh không đúng, &6/pp help &cđể xem danh sách các câu lệnh.");
this.put("command-descriptions", "&eCác lệnh có sẵn:");
this.put("command-descriptions-usage", "&e/pp %cmd% %args%");
@ -223,6 +223,7 @@ public class VietnameseLocale implements Locale {
this.put("#26", "GUI Messages");
this.put("gui-disabled", "&cAmdinistrator đã cấm GUI!");
this.put("gui-no-permission", "&cBạn không có quyền mở GUI!");
this.put("#27", "GUI Color Messages");
this.put("gui-color-icon-name", "&a");

View file

@ -45,7 +45,7 @@ public class ParticleManager extends Manager implements Listener, Runnable {
*/
private int hue = 0;
private int note = 0;
private final Random RANDOM = new Random();
private final Random random = new Random();
public ParticleManager(PlayerParticles playerParticles) {
super(playerParticles);
@ -150,7 +150,7 @@ public class ParticleManager extends Manager implements Listener, Runnable {
* @param location The location to display at
*/
private void displayParticles(PPlayer pplayer, ParticlePair particle, Location location) {
if (!this.playerParticles.getManager(ParticleStyleManager.class).isCustomHandled(particle.getStyle())) {
if (!this.playerParticles.getManager(ParticleStyleManager.class).isEventHandled(particle.getStyle())) {
if (Setting.TOGGLE_ON_MOVE.getBoolean() && particle.getStyle().canToggleWithMovement() && pplayer.isMoving()) {
for (PParticle pparticle : DefaultStyles.FEET.getParticles(particle, location))
ParticleEffect.display(particle, pparticle, false, pplayer.getPlayer());
@ -162,7 +162,7 @@ public class ParticleManager extends Manager implements Listener, Runnable {
}
/**
* An alternative method used for custom handled styles
* An alternative method used for event styles
*
* @param particle The ParticlePair to use for getting particle settings
* @param particles The particles to display
@ -208,7 +208,7 @@ public class ParticleManager extends Manager implements Listener, Runnable {
* @return A randomized OrdinaryColor for particle spawning with data 'random'
*/
public OrdinaryColor getRandomParticleColor() {
Color rgb = new Color(this.RANDOM.nextInt(256), this.RANDOM.nextInt(256), this.RANDOM.nextInt(256));
Color rgb = new Color(this.random.nextInt(256), this.random.nextInt(256), this.random.nextInt(256));
return new OrdinaryColor(rgb.getRed(), rgb.getGreen(), rgb.getBlue());
}
@ -218,6 +218,6 @@ public class ParticleManager extends Manager implements Listener, Runnable {
* @return A randomized NoteColor for particle spawning with data 'random'
*/
public NoteColor getRandomNoteParticleColor() {
return new NoteColor(this.RANDOM.nextInt(25));
return new NoteColor(this.random.nextInt(25));
}
}

View file

@ -11,12 +11,14 @@ public class ParticleStyleManager extends Manager {
/**
* Arrays that contain all registered styles
*/
private List<ParticleStyle> styles = new ArrayList<>();
private List<ParticleStyle> customHandledStyles = new ArrayList<>();
private List<ParticleStyle> styles;
private List<ParticleStyle> eventStyles;
public ParticleStyleManager(PlayerParticles playerParticles) {
super(playerParticles);
this.styles = new ArrayList<>();
this.eventStyles = new ArrayList<>();
DefaultStyles.registerStyles(this);
}
@ -47,12 +49,12 @@ public class ParticleStyleManager extends Manager {
}
for (ParticleStyle testAgainst : this.styles) {
if (testAgainst.getName().equalsIgnoreCase(style.getName())) {
PlayerParticles.getInstance().getLogger().severe("Tried to register two styles with the same name spelling: '" + style.getName() + "'");
return;
} else if (testAgainst.equals(style)) {
if (testAgainst.equals(style)) {
PlayerParticles.getInstance().getLogger().severe("Tried to register the same style twice: '" + style.getName() + "'");
return;
} else if (testAgainst.getName().equalsIgnoreCase(style.getName())) {
PlayerParticles.getInstance().getLogger().severe("Tried to register two styles with the same name spelling: '" + style.getName() + "'");
return;
}
}
@ -64,9 +66,9 @@ public class ParticleStyleManager extends Manager {
*
* @param style The style to register
*/
public void registerCustomHandledStyle(ParticleStyle style) {
public void registerEventStyle(ParticleStyle style) {
this.registerStyle(style);
this.customHandledStyles.add(style);
this.eventStyles.add(style);
}
/**
@ -75,8 +77,8 @@ public class ParticleStyleManager extends Manager {
* @param style The style to check
* @return If the style is handled in a custom manner
*/
public boolean isCustomHandled(ParticleStyle style) {
return this.customHandledStyles.contains(style);
public boolean isEventHandled(ParticleStyle style) {
return this.eventStyles.contains(style);
}
/**

View file

@ -16,19 +16,17 @@ public class PermissionManager extends Manager {
private static final String PERMISSION_PREFIX = "playerparticles.";
private enum PPermission {
ALL("*"),
EFFECT_ALL("effect.*"),
EFFECT("effect"),
STYLE_ALL("style.*"),
STYLE("style"),
FIXED("fixed"),
FIXED_UNLIMITED("fixed.unlimited"),
FIXED_CLEAR("fixed.clear"),
RELOAD("reload"),
OVERRIDE("override"),
GUI("gui"),
PARTICLES_UNLIMITED("particles.unlimited"),
GROUPS_UNLIMITED("groups.unlimited");
@ -77,19 +75,6 @@ public class PermissionManager extends Manager {
}
/**
* Checks if a player can use /ppo
*
* @param sender The CommandSender to check
* @return If the player can use /ppo
*/
public boolean canOverride(CommandSender sender) {
if (!(sender instanceof Player))
return true;
return PPermission.ALL.check(sender);
}
/**
* Checks if the given player has reached the max number of particles in their active group
*
@ -97,9 +82,6 @@ public class PermissionManager extends Manager {
* @return If the player has reached the max number of particles in their active group
*/
public boolean hasPlayerReachedMaxParticles(PPlayer pplayer) {
if (PPermission.ALL.check(pplayer.getPlayer()))
return false;
if (PPermission.PARTICLES_UNLIMITED.check(pplayer.getPlayer()))
return false;
@ -113,9 +95,6 @@ public class PermissionManager extends Manager {
* @return If the player has reached the max number of saved particle groups
*/
public boolean hasPlayerReachedMaxGroups(PPlayer pplayer) {
if (PPermission.ALL.check(pplayer.getPlayer()))
return false;
if (PPermission.GROUPS_UNLIMITED.check(pplayer.getPlayer()))
return false;
@ -129,9 +108,6 @@ public class PermissionManager extends Manager {
* @return If the player has permission to save groups
*/
public boolean canPlayerSaveGroups(PPlayer pplayer) {
if (PPermission.ALL.check(pplayer.getPlayer()))
return true;
if (PPermission.GROUPS_UNLIMITED.check(pplayer.getPlayer()))
return true;
@ -145,9 +121,6 @@ public class PermissionManager extends Manager {
* @return If the player has reached the max number of fixed effects
*/
public boolean hasPlayerReachedMaxFixedEffects(PPlayer pplayer) {
if (PPermission.ALL.check(pplayer.getPlayer()))
return false;
if (PPermission.FIXED_UNLIMITED.check(pplayer.getPlayer()))
return false;
@ -170,7 +143,7 @@ public class PermissionManager extends Manager {
* @return The maximum number of particles based on the config.yml value, or unlimited
*/
public int getMaxParticlesAllowed(Player player) {
if (PPermission.ALL.check(player) || PPermission.PARTICLES_UNLIMITED.check(player))
if (PPermission.PARTICLES_UNLIMITED.check(player))
return Integer.MAX_VALUE;
return Setting.MAX_PARTICLES.getInt();
@ -203,7 +176,6 @@ public class PermissionManager extends Manager {
* @return True if the player has permission to use the effect
*/
public boolean hasEffectPermission(Player player, ParticleEffect effect) {
if (PPermission.ALL.check(player) || PPermission.EFFECT_ALL.check(player)) return true;
return PPermission.EFFECT.check(player, effect.getName());
}
@ -216,7 +188,6 @@ public class PermissionManager extends Manager {
* @return If the player has permission to use the style
*/
public boolean hasStylePermission(Player player, ParticleStyle style) {
if (PPermission.ALL.check(player) || PPermission.STYLE_ALL.check(player)) return true;
return PPermission.STYLE.check(player, style.getName());
}
@ -297,7 +268,7 @@ public class PermissionManager extends Manager {
* @return True if the player has permission
*/
public boolean canUseFixedEffects(Player player) {
return PPermission.ALL.check(player) || PPermission.FIXED.check(player);
return PPermission.FIXED.check(player);
}
/**
@ -307,7 +278,17 @@ public class PermissionManager extends Manager {
* @return True if the player has permission to use /pp fixed clear
*/
public boolean canClearFixedEffects(Player player) {
return PPermission.ALL.check(player) || PPermission.FIXED_CLEAR.check(player);
return PPermission.FIXED_CLEAR.check(player);
}
/**
* Checks if a player has permission to open the GUI
*
* @param player The player to check the permission for
* @return True if the player has permission to open the GUI
*/
public boolean canOpenGui(Player player) {
return PPermission.GUI.check(player);
}
/**
@ -317,7 +298,20 @@ public class PermissionManager extends Manager {
* @return True if the sender has permission to reload the plugin's settings
*/
public boolean canReloadPlugin(CommandSender sender) {
return PPermission.ALL.check(sender) || PPermission.RELOAD.check(sender);
return PPermission.RELOAD.check(sender);
}
/**
* Checks if a player can use /ppo
*
* @param sender The CommandSender to check
* @return If the player can use /ppo
*/
public boolean canOverride(CommandSender sender) {
if (!(sender instanceof Player))
return true;
return PPermission.OVERRIDE.check(sender);
}
}

View file

@ -28,7 +28,7 @@ public class FixedParticleEffect {
/**
* Constructs a new FixedParticleEffect
* FixedParticleEffects can NOT use custom handled styles
* FixedParticleEffects can NOT use event styles
*
* @param pplayerUUID The UUID of the player who owns the effect
* @param id The id this effect has, unique to the owner pplayer

View file

@ -52,17 +52,17 @@ public class DefaultStyles {
particleStyleManager.registerStyle(ARROWS);
particleStyleManager.registerStyle(BATMAN);
particleStyleManager.registerStyle(BEAM);
particleStyleManager.registerCustomHandledStyle(BLOCKBREAK);
particleStyleManager.registerCustomHandledStyle(BLOCKPLACE);
particleStyleManager.registerEventStyle(BLOCKBREAK);
particleStyleManager.registerEventStyle(BLOCKPLACE);
particleStyleManager.registerStyle(CELEBRATION);
particleStyleManager.registerStyle(CHAINS);
particleStyleManager.registerStyle(COMPANION);
particleStyleManager.registerStyle(CUBE);
particleStyleManager.registerStyle(FEET);
particleStyleManager.registerStyle(HALO);
particleStyleManager.registerCustomHandledStyle(HURT);
particleStyleManager.registerEventStyle(HURT);
particleStyleManager.registerStyle(INVOCATION);
particleStyleManager.registerCustomHandledStyle(MOVE);
particleStyleManager.registerEventStyle(MOVE);
particleStyleManager.registerStyle(NORMAL);
particleStyleManager.registerStyle(ORBIT);
particleStyleManager.registerStyle(OVERHEAD);
@ -74,7 +74,7 @@ public class DefaultStyles {
particleStyleManager.registerStyle(SPHERE);
particleStyleManager.registerStyle(SPIN);
particleStyleManager.registerStyle(SPIRAL);
particleStyleManager.registerCustomHandledStyle(SWORDS);
particleStyleManager.registerEventStyle(SWORDS);
particleStyleManager.registerStyle(THICK);
particleStyleManager.registerStyle(TWINS);
particleStyleManager.registerStyle(VORTEX);