Actually use PPlayers for permissions

This commit is contained in:
Esophose 2020-01-16 14:25:29 -07:00
parent 386a98f88f
commit 8a5479ec54
18 changed files with 50 additions and 49 deletions

View file

@ -34,7 +34,7 @@ public class AddCommandModule implements CommandModule {
PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class);
LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class);
int maxParticlesAllowed = permissionManager.getMaxParticlesAllowed(pplayer.getPlayer());
int maxParticlesAllowed = permissionManager.getMaxParticlesAllowed(pplayer);
if (pplayer.getActiveParticles().size() >= maxParticlesAllowed) {
localeManager.sendMessage(pplayer, "add-reached-max", StringPlaceholders.single("amount", maxParticlesAllowed));
return;
@ -46,7 +46,7 @@ public class AddCommandModule implements CommandModule {
if (effect == null) {
localeManager.sendMessage(pplayer, "effect-invalid", StringPlaceholders.single("effect", args[0]));
return;
} else if (!permissionManager.hasEffectPermission(pplayer.getPlayer(), effect)) {
} else if (!permissionManager.hasEffectPermission(pplayer, effect)) {
localeManager.sendMessage(pplayer, "effect-no-permission", StringPlaceholders.single("effect", effect.getName()));
return;
}
@ -55,7 +55,7 @@ public class AddCommandModule implements CommandModule {
if (style == null) {
localeManager.sendMessage(pplayer, "style-invalid", StringPlaceholders.single("style", args[1]));
return;
} else if (!permissionManager.hasStylePermission(pplayer.getPlayer(), style)) {
} else if (!permissionManager.hasStylePermission(pplayer, style)) {
localeManager.sendMessage(pplayer, "style-no-permission", StringPlaceholders.single("style", args[1]));
return;
}
@ -118,10 +118,10 @@ public class AddCommandModule implements CommandModule {
PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class);
if (args.length <= 1) { // Effect name
if (args.length == 0) matches = permissionManager.getEffectNamesUserHasPermissionFor(p);
else StringUtil.copyPartialMatches(args[0], permissionManager.getEffectNamesUserHasPermissionFor(p), matches);
if (args.length == 0) matches = permissionManager.getEffectNamesUserHasPermissionFor(pplayer);
else StringUtil.copyPartialMatches(args[0], permissionManager.getEffectNamesUserHasPermissionFor(pplayer), matches);
} else if (args.length == 2) { // Style name
StringUtil.copyPartialMatches(args[1], permissionManager.getStyleNamesUserHasPermissionFor(p), matches);
StringUtil.copyPartialMatches(args[1], permissionManager.getStyleNamesUserHasPermissionFor(pplayer), matches);
} else { // Data
ParticleEffect effect = ParticleEffect.fromName(args[0]);
if (effect != null) {

View file

@ -48,9 +48,9 @@ public class DataCommandModule implements CommandModule {
List<String> matches = new ArrayList<>();
if (args.length <= 1) {
if (args.length == 0) {
matches = permissionManager.getEffectNamesUserHasPermissionFor(pplayer.getPlayer());
matches = permissionManager.getEffectNamesUserHasPermissionFor(pplayer);
} else {
StringUtil.copyPartialMatches(args[0], permissionManager.getEffectNamesUserHasPermissionFor(pplayer.getPlayer()), matches);
StringUtil.copyPartialMatches(args[0], permissionManager.getEffectNamesUserHasPermissionFor(pplayer), matches);
}
}
return matches;

View file

@ -84,7 +84,7 @@ public class EditCommandModule implements CommandModule {
if (effect == null) {
localeManager.sendMessage(pplayer, "effect-invalid", StringPlaceholders.single("effect", args[0]));
return;
} else if (!PlayerParticles.getInstance().getManager(PermissionManager.class).hasEffectPermission(pplayer.getPlayer(), effect)) {
} else if (!PlayerParticles.getInstance().getManager(PermissionManager.class).hasEffectPermission(pplayer, effect)) {
localeManager.sendMessage(pplayer, "effect-no-permission", StringPlaceholders.single("effect", effect.getName()));
return;
}
@ -116,7 +116,7 @@ public class EditCommandModule implements CommandModule {
if (style == null) {
localeManager.sendMessage(pplayer, "style-invalid", StringPlaceholders.single("style", args[0]));
return;
} else if (!PlayerParticles.getInstance().getManager(PermissionManager.class).hasStylePermission(pplayer.getPlayer(), style)) {
} else if (!PlayerParticles.getInstance().getManager(PermissionManager.class).hasStylePermission(pplayer, style)) {
localeManager.sendMessage(pplayer, "style-no-permission", StringPlaceholders.single("style", style.getName()));
return;
}
@ -229,11 +229,11 @@ public class EditCommandModule implements CommandModule {
switch (args[1].toLowerCase()) {
case "effect":
if (args.length == 3)
StringUtil.copyPartialMatches(args[2], permissionManager.getEffectNamesUserHasPermissionFor(p), matches);
StringUtil.copyPartialMatches(args[2], permissionManager.getEffectNamesUserHasPermissionFor(pplayer), matches);
break;
case "style":
if (args.length == 3)
StringUtil.copyPartialMatches(args[2], permissionManager.getStyleNamesUserHasPermissionFor(p), matches);
StringUtil.copyPartialMatches(args[2], permissionManager.getStyleNamesUserHasPermissionFor(pplayer), matches);
break;
case "data":
ParticleEffect effect = pplayer.getActiveParticle(id).getEffect();

View file

@ -16,7 +16,7 @@ public class EffectsCommandModule implements CommandModule {
Player p = pplayer.getPlayer();
List<String> effectList = PlayerParticles.getInstance().getManager(PermissionManager.class).getEffectNamesUserHasPermissionFor(p);
List<String> effectList = PlayerParticles.getInstance().getManager(PermissionManager.class).getEffectNamesUserHasPermissionFor(pplayer);
if (effectList.isEmpty()) {
localeManager.sendMessage(pplayer, "effect-list-empty");
return;

View file

@ -34,7 +34,7 @@ public class FixedCommandModule implements CommandModule {
Player p = pplayer.getPlayer();
if (!PlayerParticles.getInstance().getManager(PermissionManager.class).canUseFixedEffects(p)) {
if (!PlayerParticles.getInstance().getManager(PermissionManager.class).canUseFixedEffects(pplayer)) {
localeManager.sendMessage(pplayer, "fixed-no-permission");
return;
}
@ -132,7 +132,7 @@ public class FixedCommandModule implements CommandModule {
if (effect == null) {
localeManager.sendMessage(pplayer, "fixed-create-effect-invalid", StringPlaceholders.single("effect", args[3]));
return;
} else if (!permissionManager.hasEffectPermission(p, effect)) {
} else if (!permissionManager.hasEffectPermission(pplayer, effect)) {
localeManager.sendMessage(pplayer, "fixed-create-effect-no-permission", StringPlaceholders.single("effect", effect.getName()));
return;
}
@ -141,7 +141,7 @@ public class FixedCommandModule implements CommandModule {
if (style == null) {
localeManager.sendMessage(pplayer, "fixed-create-style-invalid", StringPlaceholders.single("style", args[4]));
return;
} else if (!permissionManager.hasStylePermission(p, style)) {
} else if (!permissionManager.hasStylePermission(pplayer, style)) {
localeManager.sendMessage(pplayer, "fixed-create-style-no-permission", StringPlaceholders.single("style", args[4]));
return;
}
@ -250,7 +250,7 @@ public class FixedCommandModule implements CommandModule {
if (effect == null) {
localeManager.sendMessage(pplayer, "fixed-edit-effect-invalid", StringPlaceholders.single("effect", args[2]));
return;
} else if (!permissionManager.hasEffectPermission(pplayer.getPlayer(), effect)) {
} else if (!permissionManager.hasEffectPermission(pplayer, effect)) {
localeManager.sendMessage(pplayer, "fixed-edit-effect-no-permission", StringPlaceholders.single("effect", effect.getName()));
return;
}
@ -263,7 +263,7 @@ public class FixedCommandModule implements CommandModule {
if (style == null) {
localeManager.sendMessage(pplayer, "fixed-edit-style-invalid", StringPlaceholders.single("style", args[2]));
return;
} else if (!permissionManager.hasStylePermission(pplayer.getPlayer(), style)) {
} else if (!permissionManager.hasStylePermission(pplayer, style)) {
localeManager.sendMessage(pplayer, "fixed-edit-style-no-permission", StringPlaceholders.single("style", style.getName()));
return;
} else if (!style.canBeFixed()) {
@ -443,7 +443,7 @@ public class FixedCommandModule implements CommandModule {
LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class);
PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class);
if (!permissionManager.canClearFixedEffects(p)) {
if (!permissionManager.canClearFixedEffects(pplayer)) {
localeManager.sendMessage(pplayer, "fixed-clear-no-permission");
return;
}
@ -477,7 +477,7 @@ public class FixedCommandModule implements CommandModule {
LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class);
PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class);
if (!permissionManager.canTeleportToFixedEffects(p)) {
if (!permissionManager.canTeleportToFixedEffects(pplayer)) {
localeManager.sendMessage(pplayer, "fixed-teleport-no-permission");
return;
}
@ -541,9 +541,9 @@ public class FixedCommandModule implements CommandModule {
}
if (args.length == 5) {
StringUtil.copyPartialMatches(args[4], permissionManager.getEffectNamesUserHasPermissionFor(p), matches);
StringUtil.copyPartialMatches(args[4], permissionManager.getEffectNamesUserHasPermissionFor(pplayer), matches);
} else if (args.length == 6) {
StringUtil.copyPartialMatches(args[5], permissionManager.getFixableStyleNamesUserHasPermissionFor(p), matches);
StringUtil.copyPartialMatches(args[5], permissionManager.getFixableStyleNamesUserHasPermissionFor(pplayer), matches);
} else if (args.length >= 7) {
ParticleEffect effect = ParticleEffect.fromName(args[4]);
if (effect != null) {
@ -599,9 +599,9 @@ public class FixedCommandModule implements CommandModule {
}
StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches);
} else if (property.equals("effect") && args.length == 4) {
StringUtil.copyPartialMatches(args[3], permissionManager.getEffectNamesUserHasPermissionFor(p), matches);
StringUtil.copyPartialMatches(args[3], permissionManager.getEffectNamesUserHasPermissionFor(pplayer), matches);
} else if (property.equals("style") && args.length == 4) {
StringUtil.copyPartialMatches(args[3], permissionManager.getFixableStyleNamesUserHasPermissionFor(p), matches);
StringUtil.copyPartialMatches(args[3], permissionManager.getFixableStyleNamesUserHasPermissionFor(pplayer), matches);
} else if (property.equals("data")) {
int id = -1;
try {

View file

@ -16,7 +16,7 @@ public class GUICommandModule implements CommandModule {
LocaleManager localeManager = PlayerParticles.getInstance().getManager(LocaleManager.class);
GuiManager guiManager = PlayerParticles.getInstance().getManager(GuiManager.class);
if (!permissionManager.canOpenGui(pplayer.getPlayer())) {
if (!permissionManager.canOpenGui(pplayer)) {
localeManager.sendMessage(pplayer, "command-no-permission");
return;
}
@ -35,7 +35,7 @@ public class GUICommandModule implements CommandModule {
return;
}
if (!Setting.GUI_PRESETS_ONLY.getBoolean() && (permissionManager.getEffectsUserHasPermissionFor(pplayer.getPlayer()).isEmpty() || permissionManager.getStylesUserHasPermissionFor(pplayer.getPlayer()).isEmpty())) {
if (!Setting.GUI_PRESETS_ONLY.getBoolean() && (permissionManager.getEffectsUserHasPermissionFor(pplayer).isEmpty() || permissionManager.getStylesUserHasPermissionFor(pplayer).isEmpty())) {
if (byDefault) {
localeManager.sendMessage(pplayer, "command-error-missing-effects-or-styles");
} else {

View file

@ -144,7 +144,7 @@ public class GroupCommandModule implements CommandModule {
return;
}
if (!presetGroup.canPlayerUse(pplayer.getPlayer())) {
if (!presetGroup.canPlayerUse(pplayer)) {
localeManager.sendMessage(pplayer, "group-preset-no-permission", StringPlaceholders.single("group", groupName));
return;
}
@ -153,7 +153,7 @@ public class GroupCommandModule implements CommandModule {
isPreset = true;
}
if (!group.canPlayerUse(pplayer.getPlayer())) {
if (!group.canPlayerUse(pplayer)) {
localeManager.sendMessage(pplayer, "group-no-permission", StringPlaceholders.single("group", groupName));
return;
}
@ -230,7 +230,7 @@ public class GroupCommandModule implements CommandModule {
return;
}
if (!presetGroup.canPlayerUse(pplayer.getPlayer())) {
if (!presetGroup.canPlayerUse(pplayer)) {
localeManager.sendMessage(pplayer, "group-preset-no-permission", StringPlaceholders.single("group", groupName));
return;
}
@ -273,7 +273,7 @@ public class GroupCommandModule implements CommandModule {
groupsList = new StringBuilder(groupsList.substring(0, groupsList.length() - 2));
StringBuilder presetsList = new StringBuilder();
for (ParticleGroupPreset group : PlayerParticles.getInstance().getManager(ParticleGroupPresetManager.class).getPresetGroupsForPlayer(pplayer.getPlayer()))
for (ParticleGroupPreset group : PlayerParticles.getInstance().getManager(ParticleGroupPresetManager.class).getPresetGroupsForPlayer(pplayer))
presetsList.append(group.getGroup().getName()).append(", ");
if (presetsList.toString().endsWith(", "))
@ -309,7 +309,7 @@ public class GroupCommandModule implements CommandModule {
if (!group.getName().equals(ParticleGroup.DEFAULT_NAME))
groupNames.add(group.getName());
if (!args[0].equals("remove"))
for (ParticleGroupPreset group : PlayerParticles.getInstance().getManager(ParticleGroupPresetManager.class).getPresetGroupsForPlayer(pplayer.getPlayer()))
for (ParticleGroupPreset group : PlayerParticles.getInstance().getManager(ParticleGroupPresetManager.class).getPresetGroupsForPlayer(pplayer))
groupNames.add(group.getGroup().getName());
StringUtil.copyPartialMatches(args[1], groupNames, matches);
}

View file

@ -44,15 +44,15 @@ public class OtherCommandModule implements CommandModuleSecondary {
return;
}
if (commandModule.requiresEffectsAndStyles() && (permissionManager.getEffectsUserHasPermissionFor(other).isEmpty() || permissionManager.getStylesUserHasPermissionFor(other).isEmpty())) {
localeManager.sendMessage(sender, "other-success", StringPlaceholders.single("player", other.getName()));
localeManager.sendMessage(sender, "command-error-missing-effects-or-styles");
return;
}
PlayerParticles.getInstance().getManager(DataManager.class).getPPlayer(other.getUniqueId(), (pplayer) -> {
OtherPPlayer otherPPlayer = new OtherPPlayer(sender, pplayer);
if (commandModule.requiresEffectsAndStyles() && (permissionManager.getEffectsUserHasPermissionFor(otherPPlayer).isEmpty() || permissionManager.getStylesUserHasPermissionFor(otherPPlayer).isEmpty())) {
localeManager.sendMessage(sender, "other-success", StringPlaceholders.single("player", other.getName()));
localeManager.sendMessage(sender, "command-error-missing-effects-or-styles");
return;
}
localeManager.sendMessage(sender, "other-success", StringPlaceholders.single("player", other.getName()));
String[] cmdArgs = Arrays.copyOfRange(args, 2, args.length);

View file

@ -14,7 +14,7 @@ public class StylesCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) {
Player p = pplayer.getPlayer();
List<String> styleNames = PlayerParticles.getInstance().getManager(PermissionManager.class).getStyleNamesUserHasPermissionFor(p);
List<String> styleNames = PlayerParticles.getInstance().getManager(PermissionManager.class).getStyleNamesUserHasPermissionFor(pplayer);
StringBuilder toSend = new StringBuilder();
for (String name : styleNames) {
toSend.append(name).append(", ");

View file

@ -60,7 +60,7 @@ public class GuiInventoryDefault extends GuiInventory {
// Define what slots to put the icons at based on what other slots are visible
boolean manageGroupsVisible = PlayerParticles.getInstance().getManager(PermissionManager.class).canPlayerSaveGroups(pplayer);
boolean loadPresetGroupVisible = !PlayerParticles.getInstance().getManager(ParticleGroupPresetManager.class).getPresetGroupsForPlayer(pplayer.getPlayer()).isEmpty();
boolean loadPresetGroupVisible = !PlayerParticles.getInstance().getManager(ParticleGroupPresetManager.class).getPresetGroupsForPlayer(pplayer).isEmpty();
int manageParticlesSlot = -1, manageGroupsSlot = -1, loadPresetGroupSlot = -1;
if (!manageGroupsVisible && !loadPresetGroupVisible) {

View file

@ -24,7 +24,7 @@ public class GuiInventoryEditEffect extends GuiInventory {
this.fillBorder(BorderColor.LIGHT_BLUE);
// Select Effect Buttons
List<ParticleEffect> effectsUserHasPermissionFor = PlayerParticles.getInstance().getManager(PermissionManager.class).getEffectsUserHasPermissionFor(pplayer.getPlayer());
List<ParticleEffect> effectsUserHasPermissionFor = PlayerParticles.getInstance().getManager(PermissionManager.class).getEffectsUserHasPermissionFor(pplayer);
int numberOfItems = effectsUserHasPermissionFor.size();
int itemsPerPage = 28;
int maxPages = (int) Math.ceil((double) numberOfItems / itemsPerPage);

View file

@ -24,7 +24,7 @@ public class GuiInventoryEditStyle extends GuiInventory {
this.fillBorder(BorderColor.BLUE);
// Select Style Buttons
List<ParticleStyle> stylesUserHasPermissionFor = PlayerParticles.getInstance().getManager(PermissionManager.class).getStylesUserHasPermissionFor(pplayer.getPlayer());
List<ParticleStyle> stylesUserHasPermissionFor = PlayerParticles.getInstance().getManager(PermissionManager.class).getStylesUserHasPermissionFor(pplayer);
int numberOfItems = stylesUserHasPermissionFor.size();
int itemsPerPage = 28;
int maxPages = (int) Math.ceil((double) numberOfItems / itemsPerPage);

View file

@ -34,9 +34,9 @@ public class GuiInventoryLoadPresetGroups extends GuiInventory {
int index = 10;
int nextWrap = 17;
int maxIndex = 43;
List<ParticleGroupPreset> groups = PlayerParticles.getInstance().getManager(ParticleGroupPresetManager.class).getPresetGroupsForPlayer(pplayer.getPlayer());
List<ParticleGroupPreset> groups = PlayerParticles.getInstance().getManager(ParticleGroupPresetManager.class).getPresetGroupsForPlayer(pplayer);
for (ParticleGroupPreset group : groups) {
if (!group.canPlayerUse(player))
if (!group.canPlayerUse(pplayer))
continue;
List<ParticlePair> particles = new ArrayList<>(group.getGroup().getParticles().values());

View file

@ -74,7 +74,7 @@ public class GuiInventoryManageParticles extends GuiInventory {
}
// Create New Particle Button
boolean canCreate = pplayer.getActiveParticles().size() < PlayerParticles.getInstance().getManager(PermissionManager.class).getMaxParticlesAllowed(pplayer.getPlayer());
boolean canCreate = pplayer.getActiveParticles().size() < PlayerParticles.getInstance().getManager(PermissionManager.class).getMaxParticlesAllowed(pplayer);
String lore = localeManager.getLocaleMessage("gui-color-info") + localeManager.getLocaleMessage("gui-create-particle-description");
GuiActionButton createNewParticle = new GuiActionButton(
38,

View file

@ -161,7 +161,7 @@ public class CommandManager extends Manager implements CommandExecutor, TabCompl
this.playerParticles.getManager(DataManager.class).getPPlayer(p.getUniqueId(), (pplayer) -> {
PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class);
if (commandModule.requiresEffectsAndStyles() && (permissionManager.getEffectsUserHasPermissionFor(p).isEmpty() || permissionManager.getStylesUserHasPermissionFor(p).isEmpty())) {
if (commandModule.requiresEffectsAndStyles() && (permissionManager.getEffectsUserHasPermissionFor(pplayer).isEmpty() || permissionManager.getStylesUserHasPermissionFor(pplayer).isEmpty())) {
localeManager.sendMessage(pplayer, "command-error-missing-effects-or-styles");
} else {
commandModule.onCommandExecute(pplayer, cmdArgs);

View file

@ -1,6 +1,7 @@
package dev.esophose.playerparticles.manager;
import dev.esophose.playerparticles.PlayerParticles;
import dev.esophose.playerparticles.particles.PPlayer;
import dev.esophose.playerparticles.particles.ParticleEffect;
import dev.esophose.playerparticles.particles.ParticleEffect.NoteColor;
import dev.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor;
@ -171,7 +172,7 @@ public class ParticleGroupPresetManager extends Manager {
* @param player The player
* @return a List of preset ParticleGroups the player can use
*/
public List<ParticleGroupPreset> getPresetGroupsForPlayer(Player player) {
public List<ParticleGroupPreset> getPresetGroupsForPlayer(PPlayer player) {
return this.presetGroups.stream().filter(x -> x.canPlayerUse(player)).sorted(Comparator.comparing(ParticleGroupPreset::getDisplayName)).collect(Collectors.toList());
}

View file

@ -52,7 +52,7 @@ public class ParticleGroup {
* @param player The player to check
* @return True if the player has permission
*/
public boolean canPlayerUse(Player player) {
public boolean canPlayerUse(PPlayer player) {
PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class);
// Make sure the player has permission for the number of particles in this group

View file

@ -43,10 +43,10 @@ public class ParticleGroupPreset {
* @param player The player to check
* @return True if the player has permission
*/
public boolean canPlayerUse(Player player) {
public boolean canPlayerUse(PPlayer player) {
// If this particle group has a permission, does the player have it?
if (!this.permission.isEmpty())
if (!player.hasPermission(this.permission))
if (!player.getPlayer().hasPermission(this.permission))
return false;
// If allowPermissionOverride is true, always let the player apply this group