Fixed error while checking permissions

This commit is contained in:
LOOHP 2020-08-09 17:45:33 +08:00
parent f8e2cd0915
commit 8164571920
4 changed files with 24 additions and 18 deletions

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>Limbo</groupId> <groupId>Limbo</groupId>
<artifactId>Limbo</artifactId> <artifactId>Limbo</artifactId>
<version>0.2.2-ALPHA</version> <version>0.2.3-ALPHA</version>
<build> <build>
<sourceDirectory>src</sourceDirectory> <sourceDirectory>src</sourceDirectory>
<resources> <resources>

View File

@ -2,6 +2,7 @@ package com.loohp.limbo;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
@ -11,7 +12,7 @@ import com.loohp.limbo.Utils.DataTypeIO;
public class DeclareCommands { public class DeclareCommands {
public static PacketPlayOutDeclareCommands getDeclareCommandsPacket(CommandSender sender) throws Exception { public static PacketPlayOutDeclareCommands getDeclareCommandsPacket(CommandSender sender) throws IOException {
List<String> commands = Limbo.getInstance().getPluginManager().getTabOptions(sender, new String[0]); List<String> commands = Limbo.getInstance().getPluginManager().getTabOptions(sender, new String[0]);
if (commands.isEmpty()) { if (commands.isEmpty()) {

View File

@ -25,18 +25,23 @@ public class PermissionsManager {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void loadDefaultPermissionFile(File file) throws FileNotFoundException { public void loadDefaultPermissionFile(File file) throws FileNotFoundException {
FileConfiguration config = new FileConfiguration(file); FileConfiguration config = new FileConfiguration(file);
for (Object obj : config.get("groups", Map.class).keySet()) { permissions.put("default", new ArrayList<>());
String key = (String) obj; try {
List<String> nodes = new ArrayList<>(); for (Object obj : config.get("groups", Map.class).keySet()) {
nodes.addAll(config.get("groups." + key, List.class)); String key = (String) obj;
permissions.put(key, nodes); List<String> nodes = new ArrayList<>();
} nodes.addAll(config.get("groups." + key, List.class));
for (Object obj : config.get("players", Map.class).keySet()) { permissions.put(key, nodes);
String key = (String) obj; }
List<String> groups = new ArrayList<>(); } catch (Exception e) {}
groups.addAll(config.get("players." + key, List.class)); try {
users.put(key, groups); for (Object obj : config.get("players", Map.class).keySet()) {
} String key = (String) obj;
List<String> groups = new ArrayList<>();
groups.addAll(config.get("players." + key, List.class));
users.put(key, groups);
}
} catch (Exception e) {}
} }
public boolean hasPermission(CommandSender sender, String permission) { public boolean hasPermission(CommandSender sender, String permission) {
@ -44,7 +49,7 @@ public class PermissionsManager {
return true; return true;
} else if (sender instanceof Player) { } else if (sender instanceof Player) {
Player player = (Player) sender; Player player = (Player) sender;
if (users.get(player.getName()).stream().anyMatch(each -> permissions.get(each).stream().anyMatch(node -> node.equalsIgnoreCase(permission)))) { if (users.get(player.getName()) != null && users.get(player.getName()).stream().anyMatch(each -> permissions.get(each).stream().anyMatch(node -> node.equalsIgnoreCase(permission)))) {
return true; return true;
} else { } else {
return permissions.get("default").stream().anyMatch(node -> node.equalsIgnoreCase(permission)); return permissions.get("default").stream().anyMatch(node -> node.equalsIgnoreCase(permission));

View File

@ -94,14 +94,14 @@ public class PluginManager {
} }
} }
public List<String> getTabOptions(CommandSender sender, String[] args) throws Exception { public List<String> getTabOptions(CommandSender sender, String[] args) {
List<String> options = new ArrayList<>(); List<String> options = new ArrayList<>();
for (Executor entry : executors) { for (Executor entry : executors) {
if (entry.tab.isPresent()) { if (entry.tab.isPresent()) {
try { try {
options.addAll(entry.tab.get().tabComplete(sender, args)); options.addAll(entry.tab.get().tabComplete(sender, args));
} catch (Exception e) { } catch (Exception e) {
System.err.println("Error while passing tab completion \"" + args[0] + "\" to the plugin \"" + entry.plugin.getName() + "\""); System.err.println("Error while passing tab completion to the plugin \"" + entry.plugin.getName() + "\"");
e.printStackTrace(); e.printStackTrace();
} }
} }