diff --git a/ButtonCore/src/main/java/buttondevteam/core/TestPrepare.java b/ButtonCore/src/main/java/buttondevteam/core/TestPrepare.java
index 3b6c837..8d5ed80 100644
--- a/ButtonCore/src/main/java/buttondevteam/core/TestPrepare.java
+++ b/ButtonCore/src/main/java/buttondevteam/core/TestPrepare.java
@@ -7,6 +7,7 @@ import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.plugin.PluginManager;
+import org.bukkit.scheduler.BukkitScheduler;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -29,6 +30,8 @@ public class TestPrepare {
return Mockito.mock(PluginManager.class);
if (returns(invocation, Collection.class))
return Collections.EMPTY_LIST;
+ if (returns(invocation, BukkitScheduler.class))
+ return Mockito.mock(BukkitScheduler.class);
return null;
}
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/chat/Channel.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/Channel.java
index f05cc3b..6c3a353 100644
--- a/ButtonCore/src/main/java/buttondevteam/lib/chat/Channel.java
+++ b/ButtonCore/src/main/java/buttondevteam/lib/chat/Channel.java
@@ -99,8 +99,8 @@ public class Channel {
}
public static class RecipientTestResult {
- public String errormessage;
- public int score;
+ public String errormessage = null;
+ public int score = -1; // Anything below 0 is "never send"
/**
* Creates a result that indicates an error
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java
index 2f7cb2d..1627c34 100644
--- a/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java
+++ b/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java
@@ -14,6 +14,7 @@ import javassist.Modifier;
* @author Norbi
*
*/
+@TBMCCommandEnforcer
public abstract class TBMCCommandBase {
public TBMCCommandBase() {
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCCommandEnforcer.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCCommandEnforcer.java
new file mode 100644
index 0000000..b644679
--- /dev/null
+++ b/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCCommandEnforcer.java
@@ -0,0 +1,14 @@
+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 14d1c0d..7cc3d43 100644
--- a/ButtonCore/src/main/java/buttondevteam/lib/player/TBMCPlayerBase.java
+++ b/ButtonCore/src/main/java/buttondevteam/lib/player/TBMCPlayerBase.java
@@ -19,6 +19,7 @@ import com.palmergames.bukkit.towny.object.TownyUniverse;
import buttondevteam.lib.TBMCCoreAPI;
@AbstractUserClass(foldername = "minecraft", prototype = TBMCPlayer.class)
+@TBMCPlayerEnforcer
public abstract class TBMCPlayerBase extends ChromaGamerBase {
protected UUID uuid;
diff --git a/ButtonCore/src/main/java/buttondevteam/lib/player/TBMCPlayerEnforcer.java b/ButtonCore/src/main/java/buttondevteam/lib/player/TBMCPlayerEnforcer.java
new file mode 100644
index 0000000..abefeb6
--- /dev/null
+++ b/ButtonCore/src/main/java/buttondevteam/lib/player/TBMCPlayerEnforcer.java
@@ -0,0 +1,11 @@
+package buttondevteam.lib.player;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE)
+@Inherited
+public @interface TBMCPlayerEnforcer {
+
+}
diff --git a/ButtonProcessor/src/main/java/buttondevteam/buttonproc/ButtonProcessor.java b/ButtonProcessor/src/main/java/buttondevteam/buttonproc/ButtonProcessor.java
index 8f71daf..6ea6e7f 100644
--- a/ButtonProcessor/src/main/java/buttondevteam/buttonproc/ButtonProcessor.java
+++ b/ButtonProcessor/src/main/java/buttondevteam/buttonproc/ButtonProcessor.java
@@ -2,6 +2,8 @@ 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;
@@ -9,21 +11,32 @@ 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 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 extends TypeElement> typeElements, RoundEnvironment roundEnv) { // TODO: SEparate JAR
- for (TypeElement te : typeElements) {
- Set extends Element> elements = roundEnv.getElementsAnnotatedWith(te);
- for (Element element : elements) {
- System.out.println("Processing " + element);
- List extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors();
+ public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) {
+ for (TypeElement te : annotations) {
+ Set extends Element> classes = roundEnv.getElementsAnnotatedWith(te);
+ for (Element targetcl : classes) {
+ System.out.println("Processing " + targetcl);
+ List extends AnnotationMirror> 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);
@@ -32,4 +45,9 @@ public class ButtonProcessor extends AbstractProcessor {
}
return true; // claim the annotations
}
+
+ @Override
+ public SourceVersion getSupportedSourceVersion() {
+ return SourceVersion.latestSupported();
+ }
}