Skip to content

Commit

Permalink
fixed /hasperm and slight flaw in permission system (regarding MV-Core)
Browse files Browse the repository at this point in the history
  • Loading branch information
Niilyx committed Jun 23, 2024
1 parent 35d203e commit 14224f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/java/fr/efreicraft/ecatup/commands/HasPerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -40,12 +41,13 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
if (!player.isOnline()) fromDB = true;

permission = permission.toLowerCase();
if (permission.endsWith(".*")) permission = permission.substring(0, permission.indexOf(".*"));

if (fromDB) {
try {
List<Permission> perms = PlayerService.getPermissionOfPlayer(player.getUniqueId().toString());
for (Permission p : perms) {
if (p.getName().equalsIgnoreCase(permission)) {
if (p.getName().startsWith(permission)) {
MessageUtils.sendMessage(sender, MessageUtils.ChatPrefix.SERVER,
"%s possède la permission &a[%s]&r dans [%s].".formatted(player.getName(), permission, String.join(",", p.getServerTypes())));
return true;
Expand All @@ -71,7 +73,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command


for (Permission p : ecPlayer.getAnimusPlayer().getPerms()) {
if (p.getName().equalsIgnoreCase(permission)) {
if (p.getName().startsWith(permission)) {
MessageUtils.sendMessage(sender, MessageUtils.ChatPrefix.SERVER,
"%s possède la permission &a[%s]&r dans [%s].".formatted(player.getName(), permission, String.join(",", p.getServerTypes())));
return true;
Expand All @@ -87,7 +89,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command

@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length == 1) return Bukkit.getOnlinePlayers().stream().map(String::valueOf).sorted().toList();
if (args.length == 1) return Bukkit.getOnlinePlayers().stream().map(Player::getName).sorted().toList();
if (args.length == 3) return List.of("true", "false");
return null;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/fr/efreicraft/ecatup/players/ECPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ public void addPlayerPermissions() {
for (String permission : permissions) {
if(permission.endsWith(".*")) {
List<String> wildcardPermissions = getWildcardPermissions(permission);

// certains plugins n'enregistrent pas leurs permissions (*ahem* Multiverse-Core)
attachment.setPermission(permission, true);
for (String wildcardPermission : wildcardPermissions) {
attachment.setPermission(wildcardPermission, true);
}
Expand Down

0 comments on commit 14224f9

Please sign in to comment.