diff --git a/ButtonCore/ButtonCore (1) (com.github.TBMCPlugins.ButtonCore).iml b/ButtonCore/ButtonCore (1) (com.github.TBMCPlugins.ButtonCore).iml
deleted file mode 100644
index c89b771..0000000
--- a/ButtonCore/ButtonCore (1) (com.github.TBMCPlugins.ButtonCore).iml
+++ /dev/null
@@ -1,38 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java b/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java
index e810c67..9f67ecb 100755
--- a/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java
+++ b/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java
@@ -69,6 +69,13 @@ public class MainPlugin extends ButtonPlugin {
"{channel}] <{name}> {message}");
}
+ /**
+ * The permission group for users that aren't online on the server. Currently this can happen for people using commands from Discord.
+ */
+ public ConfigData unconnPermGroup() {
+ return getIConfig().getData("unconnPermGroup", "unconnected");
+ }
+
@Override
public void pluginEnable() {
// Logs "Plugin Enabled", registers commands
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java b/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java
index b98466b..8632c1c 100644
--- a/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java
+++ b/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java
@@ -132,10 +132,12 @@ public abstract class Component {
if (component.enabled == enabled) return; //Don't do anything
if (component.enabled = enabled) {
updateConfig(component.getPlugin(), component);
+ System.out.println("Enabling component " + component.getClassName());
component.enable();
if (ButtonPlugin.configGenAllowed(component))
IHaveConfig.pregenConfig(component, null);
} else {
+ System.out.println("Disabling component " + component.getClassName());
component.disable();
component.plugin.saveConfig();
TBMCChatAPI.RemoveCommands(component);
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2MC.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2MC.java
index 5976b3d..e62f9e5 100644
--- a/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2MC.java
+++ b/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2MC.java
@@ -4,6 +4,9 @@ import buttondevteam.core.MainPlugin;
import lombok.experimental.var;
import lombok.val;
import org.bukkit.Bukkit;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.command.ConsoleCommandSender;
+import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
@@ -25,7 +28,7 @@ public class Command2MC extends Command2 {
for (val method : command.getClass().getMethods()) {
if (!method.isAnnotationPresent(Subcommand.class)) continue;
String pg = permGroup(command, method);
- if (pg == null) continue;
+ if (pg.length() == 0) continue;
perm = "thorpe." + pg;
if (Bukkit.getPluginManager().getPermission(perm) == null) //It may occur multiple times
System.out.println("Adding perm " + perm + " with default: "
@@ -39,15 +42,26 @@ public class Command2MC extends Command2 {
@Override
public boolean hasPermission(Command2MCSender sender, ICommand2MC command, Method method) {
+ if (sender.getSender() instanceof ConsoleCommandSender) return true; //Always allow the console
String pg;
- String perm = modOnly(command)
- ? "tbmc.admin"
- : (pg = permGroup(command, method)) != null //TODO: This way we can't grant specific perms if it has a perm group
- ? "thorpe." + pg
- : "thorpe.command." + command.getCommandPath().replace(' ', '.');
- //noinspection deprecation
- System.out.println("Has permission " + perm + ": " + MainPlugin.permission.playerHas((String) null, sender.getSender().getName(), perm));
- return MainPlugin.permission.playerHas((String) null, sender.getSender().getName(), perm);
+ boolean p = true;
+ String[] perms = {
+ "thorpe.command." + command.getCommandPath().replace(' ', '.'),
+ (pg = permGroup(command, method)).length() > 0 ? "thorpe." + pg : null,
+ modOnly(command) ? "tbmc.admin" : null
+ };
+ for (String perm : perms) {
+ if (perm != null) {
+ if (p) { //Use OfflinePlayer to avoid fetching player data
+ if (sender.getSender() instanceof Player)
+ p = MainPlugin.permission.playerHas(null, (OfflinePlayer) sender.getSender(), perm);
+ else
+ p = MainPlugin.permission.groupHas((String) null, MainPlugin.Instance.unconnPermGroup().get(), perm);
+ System.out.println("Has permission " + perm + ": " + p);
+ } else break; //If any of the permissions aren't granted then don't allow
+ }
+ }
+ return p;
}
/**
@@ -64,7 +78,7 @@ public class Command2MC extends Command2 {
* Returns true if this class or any of the superclasses are mod only.
*
* @param method The subcommand to check
- * @return The permission group for the subcommand or null
+ * @return The permission group for the subcommand or empty string
*/
private String permGroup(ICommand2MC command, Method method) {
//System.out.println("Perm group for command " + command.getClass().getSimpleName() + " and method " + method.getName());
@@ -74,7 +88,7 @@ public class Command2MC extends Command2 {
return sc.permGroup();
}
//System.out.println("Returning getAnnForValue(" + command.getClass().getSimpleName() + ", ...): " + getAnnForValue(command.getClass(), CommandClass.class, CommandClass::permGroup, null));
- return getAnnForValue(command.getClass(), CommandClass.class, CommandClass::permGroup, null);
+ return getAnnForValue(command.getClass(), CommandClass.class, CommandClass::permGroup, "");
}
/**