Fix players being able to use saved groups they don't have access to

This commit is contained in:
Esophose 2019-04-28 04:25:35 -06:00
parent f9d57c769a
commit cdb39e0155
7 changed files with 44 additions and 1 deletions

View file

@ -5,6 +5,7 @@ import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import com.esophose.playerparticles.manager.DataManager;
@ -144,6 +145,11 @@ public class GroupCommandModule implements CommandModule {
group = presetGroup.getGroup();
isPreset = true;
}
if (!group.canPlayerUse(pplayer.getPlayer())) {
LangManager.sendMessage(pplayer, Lang.GROUP_NO_PERMISSION, groupName);
return;
}
// Empty out the active group and fill it with clones from the target group
ParticleGroup activeGroup = pplayer.getActiveParticleGroup();
@ -237,7 +243,8 @@ public class GroupCommandModule implements CommandModule {
private void onList(PPlayer pplayer) {
List<ParticleGroup> groups = pplayer.getParticleGroups();
groups.sort(Comparator.comparing(ParticleGroup::getName));
Player player = pplayer.getPlayer();
StringBuilder groupsList = new StringBuilder();
for (ParticleGroup group : groups)
if (!group.getName().equals(ParticleGroup.DEFAULT_NAME))

View file

@ -12,6 +12,7 @@ import com.esophose.playerparticles.particles.ParticleGroupPreset;
import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.util.ParticleUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.Comparator;
import java.util.List;
@ -23,11 +24,16 @@ public class GuiInventoryLoadPresetGroups extends GuiInventory {
this.fillBorder(BorderColor.GREEN);
Player player = pplayer.getPlayer();
int index = 10;
int nextWrap = 17;
int maxIndex = 43;
List<ParticleGroupPreset> groups = ParticleGroupPresetManager.getPresetGroupsForPlayer(pplayer.getPlayer());
for (ParticleGroupPreset group : groups) {
if (!group.getGroup().canPlayerUse(player))
continue;
List<ParticlePair> particles = group.getGroup().getParticles();
particles.sort(Comparator.comparingInt(ParticlePair::getId));

View file

@ -92,6 +92,7 @@ public class LangManager {
// Group Command
GROUP_INVALID,
GROUP_NO_PERMISSION,
GROUP_PRESET_NO_PERMISSION,
GROUP_RESERVED,
GROUP_NO_NAME,

View file

@ -1,5 +1,8 @@
package com.esophose.playerparticles.particles;
import com.esophose.playerparticles.manager.PermissionManager;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
@ -43,4 +46,27 @@ public class ParticleGroup {
return new ParticleGroup(DEFAULT_NAME, new ArrayList<>());
}
/**
* Checks if a player has permission to use this particle group
*
* @param player The player to check
* @return True if the player has permission
*/
public boolean canPlayerUse(Player player) {
// Make sure the player has permission for the number of particles in this group
if (PermissionManager.getMaxParticlesAllowed(player) < this.particles.size())
return false;
// Make sure the player has permission for all effects/styles in the group
for (ParticlePair particle : this.particles) {
if (!PermissionManager.hasEffectPermission(player, particle.getEffect()))
return false;
if (!PermissionManager.hasStylePermission(player, particle.getStyle()))
return false;
}
return true;
}
}

View file

@ -78,6 +78,7 @@ edit-success-data: "&aYour particle with an ID of &b{0} &ahas had its data chang
# Group Command
group-invalid: "&cA saved group or preset group does not exist with the name &b{0}&c!"
group-no-permission: "&cYou are missing permission for an effect or style to use the group &b{0}&c!"
group-preset-no-permission: "&cYou are missing permission for an effect or style to use the preset group &b{0}&c!"
group-reserved: "&cThe group name &bactive &cis reserved and cannot be used!"
group-no-name: "&cYou did not provide a group name! &b/pp {0} <groupName>"

View file

@ -78,6 +78,7 @@ edit-success-data: "&aVotre particule avec l'ID de &b{0} &aa ses paramètres cha
# Group Command
group-invalid: "&cUn groupe ou un preset de groupe sauvegardé n'existe pas avec le nom &b{0} &c!"
group-no-permission: "&cVous oubliez une permission pour un style ou un effet afin d'utiliser les groupe &b{0} &c!"
group-preset-no-permission: "&cVous oubliez une permission pour un style ou un effet afin d'utiliser les presets du groupe &b{0} &c!"
group-reserved: "&cLe nom de groupe &bactive &cest réservé et ne peut pas être utiliser !"
group-no-name: "&cVous n'avez pas rentré de nom de groupe ! &b/pp {0} <groupName>"

View file

@ -78,6 +78,7 @@ edit-success-data: "&aHạt hiệu ứng của bạn với ID &b{0} &ađã thanh
# Group Command
group-invalid: "&cMột Group đã lưu hoặc Preset Group không được tìm thấy với tên &b{0}&c!"
group-no-permission: "&cBạn không có quyền for 1 effect, style để sử dụng nhóm sẵn &b{0}&c!"
group-preset-no-permission: "&cBạn không có quyền for 1 effect, style để sử dụng nhóm cài sẵn &b{0}&c!"
group-reserved: "&cGroup tên &bactive &ckhông thể được sử dụng!"
group-no-name: "&cBạn đã không cung cấp tên group! &b/pp {0} <groupName>"