diff --git a/BuildConfigUpdater/BuildConfigUpdater.iml b/BuildConfigUpdater/BuildConfigUpdater.iml
index 6fc1435..098cd57 100644
--- a/BuildConfigUpdater/BuildConfigUpdater.iml
+++ b/BuildConfigUpdater/BuildConfigUpdater.iml
@@ -18,6 +18,7 @@
+
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java b/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java
index 8632c1c..b98466b 100644
--- a/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java
+++ b/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java
@@ -132,12 +132,10 @@ 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/Command2.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2.java
index d383e28..020bc84 100644
--- a/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2.java
+++ b/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2.java
@@ -1,5 +1,6 @@
package buttondevteam.lib.chat;
+import buttondevteam.core.MainPlugin;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.ThorpeUtils;
import buttondevteam.lib.player.ChromaGamerBase;
@@ -9,7 +10,9 @@ import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.experimental.var;
import lombok.val;
+import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.scheduler.BukkitTask;
import java.io.InputStreamReader;
import java.lang.annotation.ElementType;
@@ -20,9 +23,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.NumberFormat;
import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
+import java.util.*;
import java.util.function.Function;
/**
@@ -52,6 +53,7 @@ public abstract class Command2
* Allowed for OPs only by default
*/
String MOD_GROUP = "mod";
+
/**
* Help text to show players. A usage message will be also shown below it.
*/
@@ -76,6 +78,31 @@ public abstract class Command2
public String[] helpText;
}
+ protected static class SubcommandHelpData extends SubcommandData {
+ private final TreeSet ht = new TreeSet<>();
+ private BukkitTask task;
+
+ public SubcommandHelpData(Method method, T command, String[] helpText) {
+ super(method, command, helpText);
+ }
+
+ public void addSubcommand(String command) {
+ ht.add(command);
+ if (task == null)
+ task = Bukkit.getScheduler().runTask(MainPlugin.Instance, () -> {
+ helpText = new String[ht.size() + 1]; //This will only run after the server is started List list = new ArrayList(size());
+ helpText[0] = "§6---- Subcommands ----"; //TODO: There may be more to the help text
+ int i = 1;
+ for (Iterator iterator = ht.iterator();
+ iterator.hasNext() && i < helpText.length; i++) {
+ String e = iterator.next();
+ helpText[i] = e;
+ }
+ task = null; //Run again, if needed
+ });
+ }
+ }
+
@RequiredArgsConstructor
protected static class ParamConverter {
public final Function converter;
@@ -165,10 +192,8 @@ public abstract class Command2
continue;
} else if (Number.class.isAssignableFrom(cl) || cl.isPrimitive()) {
try {
- //System.out.println("Converting "+param+" param to "+cl.getSimpleName());
//noinspection unchecked
Number n = ThorpeUtils.convertNumber(NumberFormat.getInstance().parse(param), (Class extends Number>) cl);
- //System.out.println(n.getClass().getSimpleName()+" with value "+n);
params.add(n);
} catch (ParseException e) {
sender.sendMessage("§c'" + param + "' is not a number.");
@@ -186,7 +211,6 @@ public abstract class Command2
}
params.add(cparam);
}
- //System.out.println("Our params: "+params);
try {
val ret = sd.method.invoke(sd.command, params.toArray()); //I FORGOT TO TURN IT INTO AN ARRAY (for a long time)
if (ret instanceof Boolean) {
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2MC.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2MC.java
index baff097..3a46491 100644
--- a/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2MC.java
+++ b/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2MC.java
@@ -6,7 +6,6 @@ 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;
@@ -20,9 +19,6 @@ public class Command2MC extends Command2 {
public void registerCommand(ICommand2MC command) {
super.registerCommand(command, '/');
var perm = "thorpe.command." + command.getCommandPath().replace(' ', '.');
- if (Bukkit.getPluginManager().getPermission(perm) == null) //Check needed for plugin reset
- System.out.println("Adding perm " + perm + " with default: "
- + (modOnly(command) ? PermissionDefault.OP : PermissionDefault.TRUE)); //Allow commands by default, unless it's mod only - TODO: Test
if (Bukkit.getPluginManager().getPermission(perm) == null) //Check needed for plugin reset
Bukkit.getPluginManager().addPermission(new Permission(perm,
modOnly(command) ? PermissionDefault.OP : PermissionDefault.TRUE)); //Allow commands by default, unless it's mod only - TODO: Test
@@ -31,9 +27,6 @@ public class Command2MC extends Command2 {
String pg = permGroup(command, method);
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: "
- + PermissionDefault.OP); //Do not allow any commands that belong to a group
if (Bukkit.getPluginManager().getPermission(perm) == null) //It may occur multiple times
Bukkit.getPluginManager().addPermission(new Permission(perm,
//pg.equals(Subcommand.MOD_GROUP) ? PermissionDefault.OP : PermissionDefault.TRUE)); //Allow commands by default, unless it's mod only
@@ -54,10 +47,9 @@ public class Command2MC extends Command2 {
for (String perm : perms) {
if (perm != null) {
if (p) { //Use OfflinePlayer to avoid fetching player data
- if (sender.getSender() instanceof Player)
+ if (sender.getSender() instanceof OfflinePlayer)
p = MainPlugin.permission.playerHas(null, (OfflinePlayer) sender.getSender(), perm);
else
- //p = MainPlugin.permission.groupHas((String) null, MainPlugin.Instance.unconnPermGroup().get(), perm);
p = MainPlugin.permission.playerHas(null, Bukkit.getOfflinePlayer(new UUID(0, 0)), perm);
} else break; //If any of the permissions aren't granted then don't allow
}
@@ -82,13 +74,10 @@ public class Command2MC extends Command2 {
* @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());
val sc = method.getAnnotation(Subcommand.class);
if (sc != null && sc.permGroup().length() > 0) {
- //System.out.println("Returning sc.permGroup(): " + sc.permGroup());
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, "");
}