- * This method adds a plugin's commands to help and sets their executor.
- *
- * > cmds = rf.getSubTypesOf(TBMCCommandBase.class);
- for (Class extends TBMCCommandBase> cmd : cmds) {
- try {
- if (!cmd.getPackage().getName().startsWith(acmdclass.getPackage().getName()))
- continue; // It keeps including the commands from here
- if (Modifier.isAbstract(cmd.getModifiers()))
- continue;
- TBMCCommandBase c = cmd.newInstance();
- c.plugin = plugin;
- CommandCaller.RegisterCommand(c); //Will check for nulls
- commands.put(c.GetCommandPath(), c);
- } catch (Exception e) {
- TBMCCoreAPI.SendException("An error occured while registering command " + cmd.getName(), e);
- }
- }
- }
-
- /**
- *
- * This method adds a plugin's command to help and sets it's executor. They will be automatically unregistered on plugin disable.
- *
- *
- * The command must be registered in the caller plugin's plugin.yml. Otherwise the plugin will output a messsage to console.
- *
- *
- * Using this method after the server is done loading will have no effect.
- *
- *
- * @param plugin The caller plugin
- * @param thecmdclass The command's class to create it (because why let you create the command class)
- */
- public static void AddCommand(JavaPlugin plugin, Class extends TBMCCommandBase> thecmdclass, Object... params) {
- // plugin.getLogger().info("Registering command " + thecmdclass.getSimpleName() + " for " + plugin.getName());
- try {
- TBMCCommandBase c;
- if (params.length > 0)
- c = thecmdclass.getConstructor(Arrays.stream(params).map(Object::getClass).toArray(Class[]::new))
- .newInstance(params);
- else
- c = thecmdclass.newInstance();
- c.plugin = plugin;
- CommandCaller.RegisterCommand(c); //Will check for nulls
- commands.put(c.GetCommandPath(), c);
- } catch (Exception e) {
- TBMCCoreAPI.SendException("An error occured while registering command " + thecmdclass.getSimpleName(), e);
- }
- }
-
- /**
- *
- * This method adds a plugin's command to help and sets its executor. They will be automatically unregistered on plugin disable.
- *
- *
- * The command must be registered in the caller plugin's plugin.yml. Otherwise the plugin will output a message to console.
- *
- *
- * Using this method after the server is done loading will have no effect.
- *
- *
- * @param plugin The caller plugin
- * @param cmd The command to add
- */
- public static void AddCommand(JavaPlugin plugin, TBMCCommandBase cmd) {
- try {
- if (plugin == null) throw new IllegalArgumentException("The plugin is null!");
- if (cmd == null) throw new IllegalArgumentException("The command is null!");
- cmd.plugin = plugin;
- CommandCaller.RegisterCommand(cmd); //Checks for other nulls
- commands.put(cmd.GetCommandPath(), cmd);
- } catch (Exception e) {
- TBMCCoreAPI.SendException("An error occured while registering command " + (cmd == null ? "n u l l" : cmd.GetCommandPath()), e);
- }
- }
-
- /**
- *
- * This method adds a plugin's command to help and sets its executor. They will be automatically unregistered on component disable.
- *
- *
- * The command must be registered in the caller plugin's plugin.yml. Otherwise the plugin will output a message to console.
- *
- *
- * Using this method after the server is done loading will have no effect.
- *
- *
- * @param component The caller component
- * @param cmd The command to add
- */
- public static void AddCommand(Component component, TBMCCommandBase cmd) {
- try {
- if (component == null) throw new IllegalArgumentException("The component is null!");
- if (cmd == null) throw new IllegalArgumentException("The command is null!");
- cmd.plugin = component.getPlugin();
- cmd.component = component;
- CommandCaller.RegisterCommand(cmd); //Checks for other nulls
- commands.put(cmd.GetCommandPath(), cmd);
- } catch (Exception e) {
- TBMCCoreAPI.SendException("An error occured while registering command " + (cmd == null ? "n u l l" : cmd.GetCommandPath()), e);
- }
- }
-
- /**
- * Removes all commands from the plugin
- *
- * @param plugin The plugin to remove commands from
- */
- public static void RemoveCommands(JavaPlugin plugin) {
- commands.values().removeIf(c -> {
- try {
- if (c.plugin == plugin) {
- CommandCaller.UnregisterCommand(c);
- return true; //Remove
- }
- return false;
- } catch (Exception e) {
- TBMCCoreAPI.SendException("An error occured while unregistering commands for " + plugin.getName(), e);
- return true; //Remove if it couldn't get the plugin command
- }
- });
- }
-
- /**
- * Removes all commands from the component
- *
- * @param component The component to remove commands from
- */
- public static void RemoveCommands(Component component) {
- commands.values().removeIf(c -> {
- try {
- if (c.component == component) {
- CommandCaller.UnregisterCommand(c);
- return true; //Remove
- }
- return false;
- } catch (Exception e) {
- TBMCCoreAPI.SendException("An error occured while unregistering commands for " + component.getClass().getSimpleName(), e);
- return true; //Remove if it couldn't get the plugin command
- }
- });
- }
-
/**
* Sends a chat message to Minecraft. Make sure that the channel is registered with {@link #RegisterChatChannel(Channel)}.
* This will also send the error message to the sender, if they can't send the message.
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java
deleted file mode 100755
index dbd3b9f..0000000
--- a/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java
+++ /dev/null
@@ -1,111 +0,0 @@
-package buttondevteam.lib.chat;
-
-import buttondevteam.lib.architecture.Component;
-import javassist.Modifier;
-import lombok.Getter;
-import org.bukkit.command.CommandSender;
-import org.bukkit.plugin.Plugin;
-
-import java.util.function.Function;
-
-/**
- * Extend this class to create new TBMCCommand and use {@link TBMCChatAPI#AddCommand(org.bukkit.plugin.java.JavaPlugin, TBMCCommandBase)} to add it. Note: The command path (command name
- * and subcommand arguments) will be the class name by default, removing any "command" from it. To change it (especially for subcommands), use the path field in the {@link CommandClass} annotation.
- *
- * @author Norbi
- *
- */
-@TBMCCommandEnforcer
-public abstract class TBMCCommandBase {
-
- public TBMCCommandBase() {
- path = getcmdpath();
- modonly = ismodonly();
- }
-
- public abstract boolean OnCommand(CommandSender sender, String alias, String[] args);
-
- public abstract String[] GetHelpText(String alias);
-
- private final String path;
-
- /**
- * The command's path, or name if top-level command.
- * For example:
- * "u admin updateplugin" or "u" for the top level one
- * The path must be lowercase!
- * Abstract classes with no {@link CommandClass} annotations will be ignored.
- *
- * @return The command path, which is the command class name by default (removing any "command" from it) - Change via the {@link CommandClass} annotation
- */
- public final String GetCommandPath() {
- return path;
- }
-
- private String getcmdpath() {
- if (!getClass().isAnnotationPresent(CommandClass.class))
- throw new RuntimeException(
- "No @CommandClass annotation on command class " + getClass().getSimpleName() + "!");
- Function, String> getFromClass = cl -> cl.getSimpleName().toLowerCase().replace("commandbase", "") // <-- ...
- .replace("command", "");
- String path = getClass().getAnnotation(CommandClass.class).path(),
- prevpath = path = path.length() == 0 ? getFromClass.apply(getClass()) : path;
- for (Class> cl = getClass().getSuperclass(); cl != null
- && !cl.getPackage().getName().equals(TBMCCommandBase.class.getPackage().getName()); cl = cl
- .getSuperclass()) { //
- String newpath;
- if (!cl.isAnnotationPresent(CommandClass.class)
- || (newpath = cl.getAnnotation(CommandClass.class).path()).length() == 0
- || newpath.equals(prevpath)) {
- if ((Modifier.isAbstract(cl.getModifiers()) && !cl.isAnnotationPresent(CommandClass.class))
- || cl.getAnnotation(CommandClass.class).excludeFromPath()) // <--
- continue;
- newpath = getFromClass.apply(cl);
- }
- path = (prevpath = newpath) + " " + path;
- }
- return path;
- }
-
- Plugin plugin; // Used By TBMCChatAPI
-
- public final Plugin getPlugin() { // Used by CommandCaller (ButtonChat)
- return plugin;
- }
-
- public final boolean isPlayerOnly() {
- return this instanceof PlayerCommandBase ||
- (this instanceof OptionallyPlayerCommandBase &&
- (!getClass().isAnnotationPresent(OptionallyPlayerCommandClass.class)
- || getClass().getAnnotation(OptionallyPlayerCommandClass.class).playerOnly()));
- }
-
- private final boolean modonly;
-
- /**
- * Returns true if this class' or any superclass' modOnly property is set to true.
- */
- public final boolean isModOnly() {
- return modonly;
- }
-
- private boolean ismodonly() {
- if (!getClass().isAnnotationPresent(CommandClass.class))
- throw new RuntimeException(
- "No @CommandClass annotation on command class " + getClass().getSimpleName() + "!");
- boolean modOnly = getClass().getAnnotation(CommandClass.class).modOnly();
- for (Class> cl = getClass().getSuperclass(); cl != null
- && !cl.getPackage().getName().equals(TBMCCommandBase.class.getPackage().getName()); cl = cl
- .getSuperclass()) { //
- if (cl.isAnnotationPresent(CommandClass.class) && !modOnly
- && cl.getAnnotation(CommandClass.class).modOnly()) {
- modOnly = true;
- break;
- }
- }
- return modOnly;
- }
-
- @Getter
- Component component; //May be null
-}
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCCommandEnforcer.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCCommandEnforcer.java
deleted file mode 100644
index b644679..0000000
--- a/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCCommandEnforcer.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package buttondevteam.lib.chat;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.CLASS)
-@Target(ElementType.TYPE)
-@Inherited
-public @interface TBMCCommandEnforcer {
-
-}
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/player/TBMCPlayerBase.java b/ButtonCore/src/main/java/buttondevteam/lib/player/TBMCPlayerBase.java
index 0093c4e..f6caff0 100755
--- a/ButtonCore/src/main/java/buttondevteam/lib/player/TBMCPlayerBase.java
+++ b/ButtonCore/src/main/java/buttondevteam/lib/player/TBMCPlayerBase.java
@@ -36,7 +36,7 @@ public abstract class TBMCPlayerBase extends ChromaGamerBase {
/**
* Use from a method with the name of the key. For example, use flair() for the enclosing method to save to and load from "flair"
- *
+ *
* @return A data object with methods to get and set
*/
@Override
@@ -46,7 +46,7 @@ public abstract class TBMCPlayerBase extends ChromaGamerBase {
/**
* Use from a method with the name of the key. For example, use flair() for the enclosing method to save to and load from "flair"
- *
+ *
* @return A data object with methods to get and set
*/
@Override
@@ -56,11 +56,9 @@ public abstract class TBMCPlayerBase extends ChromaGamerBase {
/**
* Get player as a plugin player
- *
- * @param uuid
- * The UUID of the player to get
- * @param cl
- * The type of the player
+ *
+ * @param uuid The UUID of the player to get
+ * @param cl The type of the player
* @return The requested player object
*/
@SuppressWarnings("unchecked")
@@ -79,7 +77,7 @@ public abstract class TBMCPlayerBase extends ChromaGamerBase {
return player;
} catch (Exception e) {
TBMCCoreAPI.SendException(
- "Failed to get player with UUID " + uuid + " and class " + cl.getSimpleName() + "!", e);
+ "Failed to get player with UUID " + uuid + " and class " + cl.getSimpleName() + "!", e);
return null;
}
}
@@ -92,9 +90,8 @@ public abstract class TBMCPlayerBase extends ChromaGamerBase {
/**
* Gets the TBMCPlayer object as a specific plugin player, keeping it's data
* Make sure to use try-with-resources with this to save the data, as it may need to load the file
- *
- * @param cl
- * The TBMCPlayer subclass
+ *
+ * @param cl The TBMCPlayer subclass
*/
public T asPluginPlayer(Class cl) {
return getPlayer(uuid, cl);
@@ -122,10 +119,9 @@ public abstract class TBMCPlayerBase extends ChromaGamerBase {
player.PlayerName().set(p.getName());
Bukkit.getLogger().info("Player name saved: " + player.PlayerName().get());
} else if (!p.getName().equals(player.PlayerName().get())) {
- Bukkit.getLogger().info("Renaming " + player.PlayerName().get() + " to " + p.getName());
TownyComponent.renameInTowny(player.PlayerName().get(), p.getName());
player.PlayerName().set(p.getName());
- Bukkit.getLogger().info("Renaming done.");
+ Bukkit.getLogger().info("Renamed to " + p.getName());
}
playermap.put(p.getUniqueId() + "-" + TBMCPlayer.class.getSimpleName(), player);
@@ -142,16 +138,16 @@ public abstract class TBMCPlayerBase extends ChromaGamerBase {
final TBMCPlayerBase player = playermap.get(p.getUniqueId() + "-" + TBMCPlayer.class.getSimpleName());
player.save();
Bukkit.getServer().getPluginManager().callEvent(new TBMCPlayerQuitEvent(player, p));
- playermap.entrySet().removeIf(entry -> entry.getKey().startsWith(p.getUniqueId().toString()));
+ playermap.entrySet().removeIf(entry -> entry.getKey().startsWith(p.getUniqueId().toString()));
}
public static void savePlayers() {
- playermap.values().forEach(p -> {
+ playermap.values().forEach(p -> {
try {
p.close();
} catch (Exception e) {
TBMCCoreAPI.SendException("Error while saving player " + p.PlayerName().get() + " (" + p.getFolder()
- + "/" + p.getFileName() + ")!", e);
+ + "/" + p.getFileName() + ")!", e);
}
});
}
@@ -159,7 +155,7 @@ public abstract class TBMCPlayerBase extends ChromaGamerBase {
/**
* This method returns a TBMC player from their name. Calling this method may return an offline player which will load it, therefore it's highly recommended to use {@link #close()} to unload the
* player data. Using try-with-resources may be the easiest way to achieve this. Example:
- *
+ *
*
* {@code
* try(TBMCPlayer player = getFromName(p))
@@ -167,9 +163,8 @@ public abstract class TBMCPlayerBase extends ChromaGamerBase {
* ...
* }
*
- *
- * @param name
- * The player's name
+ *
+ * @param name The player's name
* @return The {@link TBMCPlayer} object for the player
*/
public static T getFromName(String name, Class cl) {
diff --git a/ButtonCore/src/main/resources/plugin.yml b/ButtonCore/src/main/resources/plugin.yml
index 81c2ccf..c277429 100755
--- a/ButtonCore/src/main/resources/plugin.yml
+++ b/ButtonCore/src/main/resources/plugin.yml
@@ -1,7 +1,7 @@
name: ChromaCore
main: buttondevteam.core.MainPlugin
version: 1.0
-author: TBMCPlugins
+author: NorbiPeti
commands:
updateplugin:
description: Update a TBMC plugin
@@ -21,4 +21,5 @@ depend:
softdepend:
- Towny
- Votifier
- - Multiverse-Core
\ No newline at end of file
+ - Multiverse-Core
+ - Essentials
\ No newline at end of file
diff --git a/ButtonProcessor/src/main/java/buttondevteam/buttonproc/ConfigProcessor.java b/ButtonProcessor/src/main/java/buttondevteam/buttonproc/ConfigProcessor.java
index c06169a..4225e12 100644
--- a/ButtonProcessor/src/main/java/buttondevteam/buttonproc/ConfigProcessor.java
+++ b/ButtonProcessor/src/main/java/buttondevteam/buttonproc/ConfigProcessor.java
@@ -1,5 +1,8 @@
package buttondevteam.buttonproc;
+import org.bukkit.configuration.InvalidConfigurationException;
+import org.bukkit.configuration.file.YamlConfiguration;
+
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
@@ -10,29 +13,40 @@ import javax.lang.model.type.TypeMirror;
import javax.tools.FileObject;
import javax.tools.StandardLocation;
import java.io.File;
-import java.io.FileWriter;
import java.io.IOException;
public class ConfigProcessor {
private final ProcessingEnvironment procEnv;
- private final FileWriter sw;
+ private final YamlConfiguration yc = new YamlConfiguration();
+ private final FileObject fo;
public ConfigProcessor(ProcessingEnvironment procEnv) {
+ FileObject fo1;
this.procEnv = procEnv;
- FileWriter sw = null;
try {
- FileObject file = procEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "configHelp.md");
- sw = new FileWriter(new File(file.toUri()));
- System.out.println(file.toUri());
+ fo1 = procEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "configHelp.yml");
} catch (IOException e) {
e.printStackTrace();
+ fo1 = null;
}
- this.sw = sw;
+ this.fo = fo1;
}
public void process(Element targetcl) {
if (targetcl.getModifiers().contains(Modifier.ABSTRACT)) return;
- final String path = "components." + targetcl.getSimpleName();
+ HasConfig hasConfig = targetcl.getAnnotation(HasConfig.class);
+ if (hasConfig == null) {
+ System.out.println("That's not our HasConfig annotation...");
+ return;
+ }
+ final String path = hasConfig.global() ? "global" : "components." + targetcl.getSimpleName();
+ File file = new File(fo.toUri());
+ try {
+ if (file.exists())
+ yc.load(file);
+ } catch (IOException | InvalidConfigurationException e) {
+ e.printStackTrace();
+ }
for (Element e : targetcl.getEnclosedElements()) {
/*System.out.println("Element: "+e);
System.out.println("Type: "+e.getClass()+" - "+e.getKind());
@@ -49,30 +63,18 @@ public class ConfigProcessor {
String doc = procEnv.getElementUtils().getDocComment(e);
if (doc == null) continue;
System.out.println("DOC: " + doc);
- try {
- sw.append(path).append(".").append(String.valueOf(e.getSimpleName())).append(System.lineSeparator()).append(System.lineSeparator());
- sw.append(doc.trim()).append(System.lineSeparator()).append(System.lineSeparator());
- } catch (IOException e1) {
- e1.printStackTrace();
- }
+ yc.set(path + "." + e.getSimpleName(), doc.trim());
}
String javadoc = procEnv.getElementUtils().getDocComment(targetcl);
+ if (javadoc != null) {
+ System.out.println("JAVADOC");
+ System.out.println(javadoc.trim());
+ yc.set(path, javadoc.trim());
+ }
try {
- if (javadoc != null) {
- System.out.println("JAVADOC");
- System.out.println(javadoc.trim());
- sw.append(path).append(System.lineSeparator()).append(System.lineSeparator());
- sw.append(javadoc).append(System.lineSeparator()).append(System.lineSeparator());
- }
- sw.flush();
+ yc.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
-
- @Override
- protected void finalize() throws Throwable {
- sw.close();
- super.finalize();
- }
}
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/architecture/HasConfig.java b/ButtonProcessor/src/main/java/buttondevteam/buttonproc/HasConfig.java
similarity index 82%
rename from ButtonCore/src/main/java/buttondevteam/lib/architecture/HasConfig.java
rename to ButtonProcessor/src/main/java/buttondevteam/buttonproc/HasConfig.java
index 8e1e63a..7ffdbc1 100644
--- a/ButtonCore/src/main/java/buttondevteam/lib/architecture/HasConfig.java
+++ b/ButtonProcessor/src/main/java/buttondevteam/buttonproc/HasConfig.java
@@ -1,4 +1,4 @@
-package buttondevteam.lib.architecture;
+package buttondevteam.buttonproc;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
@@ -10,4 +10,5 @@ import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Inherited
public @interface HasConfig {
+ boolean global();
}
diff --git a/CorePOM/CorePOM.iml b/CorePOM/CorePOM.iml
index 0e07dc2..b42e4ee 100644
--- a/CorePOM/CorePOM.iml
+++ b/CorePOM/CorePOM.iml
@@ -5,7 +5,7 @@