diff --git a/.idea/libraries/Maven__net_md_5_bungeecord_chat_1_12_SNAPSHOT.xml b/.idea/libraries/Maven__net_md_5_bungeecord_chat_1_12_SNAPSHOT.xml index befe1ab..dbefdef 100644 --- a/.idea/libraries/Maven__net_md_5_bungeecord_chat_1_12_SNAPSHOT.xml +++ b/.idea/libraries/Maven__net_md_5_bungeecord_chat_1_12_SNAPSHOT.xml @@ -1,13 +1,13 @@ - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_spigotmc_spigot_api_1_12_2_R0_1_SNAPSHOT.xml b/.idea/libraries/Maven__org_spigotmc_spigot_api_1_12_2_R0_1_SNAPSHOT.xml index ed73ade..b6f88ae 100644 --- a/.idea/libraries/Maven__org_spigotmc_spigot_api_1_12_2_R0_1_SNAPSHOT.xml +++ b/.idea/libraries/Maven__org_spigotmc_spigot_api_1_12_2_R0_1_SNAPSHOT.xml @@ -1,13 +1,13 @@ - + - + - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 9896aeb..dd45459 100755 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -6,6 +6,13 @@ + + + + - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 3dc26c2..0b24af5 100755 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,7 +3,6 @@ - diff --git a/BuildConfigUpdater/BuildConfigUpdater.iml b/BuildConfigUpdater/BuildConfigUpdater.iml index 4902d56..56fbaa2 100644 --- a/BuildConfigUpdater/BuildConfigUpdater.iml +++ b/BuildConfigUpdater/BuildConfigUpdater.iml @@ -11,7 +11,8 @@ - + + diff --git a/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java b/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java index f39e430..c2eded4 100755 --- a/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java +++ b/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java @@ -8,6 +8,7 @@ import buttondevteam.lib.chat.Color; import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.player.TBMCPlayerBase; import net.milkbowl.vault.permission.Permission; +import org.bukkit.Bukkit; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; @@ -16,7 +17,9 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.StandardCopyOption; +import java.util.Arrays; import java.util.logging.Logger; +import java.util.stream.Collectors; public class MainPlugin extends JavaPlugin { public static MainPlugin Instance; @@ -52,6 +55,11 @@ public class MainPlugin extends JavaPlugin { TBMCChatAPI.RegisterChatChannel(new ChatRoom("§aGREEN", Color.Green, "green")); TBMCChatAPI.RegisterChatChannel(new ChatRoom("§bBLUE", Color.Blue, "blue")); TBMCChatAPI.RegisterChatChannel(new ChatRoom("§5PURPLE", Color.DarkPurple, "purple")); + try { + Files.write(new File("plugins", "plugins.txt").toPath(), Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(p -> (CharSequence) p.getDataFolder().getName())::iterator); + } catch (IOException e) { + TBMCCoreAPI.SendException("Failed to write plugin list!", e); + } logger.info(pdfFile.getName() + " has been Enabled (V." + pdfFile.getVersion() + ") Test: " + Test + "."); } @@ -67,13 +75,14 @@ public class MainPlugin extends JavaPlugin { System.out.println("Updating " + files.length + " plugins..."); for (File file : files) { try { - Files.move(file.toPath(), new File("plugins").toPath(), StandardCopyOption.REPLACE_EXISTING) + Files.move(file.toPath(), new File("plugins", file.getName()).toPath(), StandardCopyOption.REPLACE_EXISTING); + System.out.println("Updated " + file.getName()); } catch (IOException e) { e.printStackTrace(); } } System.out.println("Update complete!"); - }); + }).start(); } private boolean setupPermissions() { diff --git a/ButtonCore/src/main/java/buttondevteam/lib/chat/Channel.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/Channel.java index 5990116..b654d47 100755 --- a/ButtonCore/src/main/java/buttondevteam/lib/chat/Channel.java +++ b/ButtonCore/src/main/java/buttondevteam/lib/chat/Channel.java @@ -14,113 +14,106 @@ import java.util.function.Function; import java.util.function.Predicate; public class Channel { - public final String DisplayName; - public final Color color; - public final String ID; - public @Nullable - String[] IDs; - /** - * Filters both the sender and the targets - */ - public final Function filteranderrormsg; + public final String DisplayName; + public final Color color; + public final String ID; + @Nullable + public String[] IDs; + /** + * Filters both the sender and the targets + */ + public final Function filteranderrormsg; - private static List channels = new ArrayList<>(); + private static List channels = new ArrayList<>(); - /** - * Creates a channel. - * - * @param displayname - * The name that should appear at the start of the message. A chat color is expected at the beginning (§9). - * @param color - * The default color of the messages sent in the channel - * @param command - * The command to be used for the channel without /. For example "mod". It's also used for scoreboard objective names. - * @param filteranderrormsg - * Checks all senders against the criteria provided here and sends the message if the index matches the sender's - if no score at all, displays the error.
- * May be null to send to everyone. - */ - public Channel(String displayname, Color color, String command, - Function filteranderrormsg) { - DisplayName = displayname; - this.color = color; - ID = command; - this.filteranderrormsg = filteranderrormsg; - } + /** + * Creates a channel. + * + * @param displayname The name that should appear at the start of the message. A chat color is expected at the beginning (§9). + * @param color The default color of the messages sent in the channel + * @param command The command to be used for the channel without /. For example "mod". It's also used for scoreboard objective names. + * @param filteranderrormsg Checks all senders against the criteria provided here and sends the message if the index matches the sender's - if no score at all, displays the error.
+ * May be null to send to everyone. + */ + public Channel(String displayname, Color color, String command, + Function filteranderrormsg) { + DisplayName = displayname; + this.color = color; + ID = command; + this.filteranderrormsg = filteranderrormsg; + } - /** - * Must be only called from a subclass - otherwise it'll throw an exception. - * - * @see Channel#Channel(String, Color, String, Function) - */ - @SuppressWarnings("unchecked") - protected Channel(String displayname, Color color, String command, - BiFunction filteranderrormsg) { - DisplayName = displayname; - this.color = color; - ID = command; - this.filteranderrormsg = s -> filteranderrormsg.apply((T) this, s); - } + /** + * Must be only called from a subclass - otherwise it'll throw an exception. + * + * @see Channel#Channel(String, Color, String, Function) + */ + @SuppressWarnings("unchecked") + protected Channel(String displayname, Color color, String command, + BiFunction filteranderrormsg) { + DisplayName = displayname; + this.color = color; + ID = command; + this.filteranderrormsg = s -> filteranderrormsg.apply((T) this, s); + } - public static List getChannels() { - return channels; - } + public static List getChannels() { + return channels; + } - /** - * Convenience method for the function parameter of {@link #Channel(String, Color, String, Function)}. It checks if the sender is OP or optionally has the specified group. The error message is - * generated automatically. - * - * @param permgroup - * The group that can access the channel or null to only allow OPs. - * @return - */ - public static Function inGroupFilter(String permgroup) { - return noScoreResult( - s -> s.isOp() || (permgroup != null - ? s instanceof Player && MainPlugin.permission.playerInGroup((Player) s, permgroup) : false), - "You need to be a(n) " + (permgroup != null ? permgroup : "OP") + " to use this channel."); - } + /** + * Convenience method for the function parameter of {@link #Channel(String, Color, String, Function)}. It checks if the sender is OP or optionally has the specified group. The error message is + * generated automatically. + * + * @param permgroup The group that can access the channel or null to only allow OPs. + * @return + */ + public static Function inGroupFilter(String permgroup) { + return noScoreResult( + s -> s.isOp() || (permgroup != null + ? s instanceof Player && MainPlugin.permission.playerInGroup((Player) s, permgroup) : false), + "You need to be a(n) " + (permgroup != null ? permgroup : "OP") + " to use this channel."); + } - public static Function noScoreResult(Predicate filter, - String errormsg) { - return s -> filter.test(s) ? new RecipientTestResult(0) : new RecipientTestResult(errormsg); - } + public static Function noScoreResult(Predicate filter, + String errormsg) { + return s -> filter.test(s) ? new RecipientTestResult(0) : new RecipientTestResult(errormsg); + } - public static BiFunction noScoreResult( - BiPredicate filter, String errormsg) { - return (this_, s) -> filter.test(this_, s) ? new RecipientTestResult(0) : new RecipientTestResult(errormsg); - } + public static BiFunction noScoreResult( + BiPredicate filter, String errormsg) { + return (this_, s) -> filter.test(this_, s) ? new RecipientTestResult(0) : new RecipientTestResult(errormsg); + } - public static Channel GlobalChat; - public static Channel AdminChat; - public static Channel ModChat; + public static Channel GlobalChat; + public static Channel AdminChat; + public static Channel ModChat; - static void RegisterChannel(Channel channel) { - channels.add(channel); - Bukkit.getPluginManager().callEvent(new ChatChannelRegisterEvent(channel)); - } + static void RegisterChannel(Channel channel) { + channels.add(channel); + Bukkit.getPluginManager().callEvent(new ChatChannelRegisterEvent(channel)); + } - public static class RecipientTestResult { - public String errormessage; - public int score; + public static class RecipientTestResult { + public String errormessage; + public int score; - /** - * Creates a result that indicates an error - * - * @param errormessage - * The error message to show the sender if they don't meet the criteria. - */ - public RecipientTestResult(String errormessage) { - this.errormessage = errormessage; - } + /** + * Creates a result that indicates an error + * + * @param errormessage The error message to show the sender if they don't meet the criteria. + */ + public RecipientTestResult(String errormessage) { + this.errormessage = errormessage; + } - /** - * Creates a result that indicates a success - * - * @param score - * The score that identifies the target group. For example, the index of the town or nation to send to. - */ - public RecipientTestResult(int score) { - this.score = score; - } - } + /** + * Creates a result that indicates a success + * + * @param score The score that identifies the target group. For example, the index of the town or nation to send to. + */ + public RecipientTestResult(int score) { + this.score = score; + } + } } diff --git a/ButtonProcessor/ButtonProcessor.iml b/ButtonProcessor/ButtonProcessor.iml index 52184f9..cc79963 100755 --- a/ButtonProcessor/ButtonProcessor.iml +++ b/ButtonProcessor/ButtonProcessor.iml @@ -1,5 +1,6 @@ + diff --git a/ButtonProcessor/src/main/java/buttondevteam/buttonproc/ButtonProcessor.java b/ButtonProcessor/src/main/java/buttondevteam/buttonproc/ButtonProcessor.java index bd05e9c..63c0950 100755 --- a/ButtonProcessor/src/main/java/buttondevteam/buttonproc/ButtonProcessor.java +++ b/ButtonProcessor/src/main/java/buttondevteam/buttonproc/ButtonProcessor.java @@ -1,5 +1,9 @@ package buttondevteam.buttonproc; +import java.util.List; +import java.util.Set; +import java.util.function.Function; + import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.SupportedAnnotationTypes; @@ -7,29 +11,43 @@ import javax.annotation.processing.SupportedSourceVersion; import javax.lang.model.SourceVersion; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; +import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; -import java.util.List; -import java.util.Set; +import javax.lang.model.util.Elements; +import javax.tools.Diagnostic.Kind; -/** * A simple session bean type annotation processor. The implementation * is based on the standard annotation processing API in Java 6. */ -@SupportedSourceVersion(SourceVersion.RELEASE_8) @SupportedAnnotationTypes("buttondevteam.*") public class ButtonProcessor extends AbstractProcessor { - /** * Check if both @Stateful and @Stateless are present in an * session bean. If so, emits a warning message. */ @Override - public boolean process(Set typeElements, RoundEnvironment roundEnv) { // TODO: SEparate JAR - for (TypeElement te : typeElements) { - Set elements = roundEnv.getElementsAnnotatedWith(te); - for (Element element : elements) { - System.out.println("Processing " + element); - List annotationMirrors = element.getAnnotationMirrors(); - System.out.println("Annotations: " + annotationMirrors); - for (AnnotationMirror annotation : annotationMirrors) { - String type = annotation.getAnnotationType().toString(); - System.out.println("Type: " + type); - } - } - } - return true; // claim the annotations - } + public boolean process(Set annotations, RoundEnvironment roundEnv) { + for (TypeElement te : annotations) { + Set classes = roundEnv.getElementsAnnotatedWith(te); + for (Element targetcl : classes) { + System.out.println("Processing " + targetcl); + List annotationMirrors = processingEnv.getElementUtils() + .getAllAnnotationMirrors(targetcl); + System.out.println("Annotations: " + annotationMirrors); + Function hasAnnotation = ann -> annotationMirrors.stream() + .anyMatch(am -> am.getAnnotationType().toString().contains(ann)); + if (hasAnnotation.apply("ChromaGamerEnforcer") && !hasAnnotation.apply("UserClass") + && !targetcl.getModifiers().contains(Modifier.ABSTRACT)) + processingEnv.getMessager().printMessage(Kind.ERROR, + "No UserClass annotation found for " + targetcl.getSimpleName(), targetcl); + if (hasAnnotation.apply("TBMCPlayerEnforcer") && !hasAnnotation.apply("PlayerClass") + && !targetcl.getModifiers().contains(Modifier.ABSTRACT)) + processingEnv.getMessager().printMessage(Kind.ERROR, + "No PlayerClass annotation found for " + targetcl.getSimpleName(), targetcl); + for (AnnotationMirror annotation : annotationMirrors) { + String type = annotation.getAnnotationType().toString(); + System.out.println("Type: " + type); + } + } + } + return true; // claim the annotations + } + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latestSupported(); + } }