Moving player data and some cleanup

This commit is contained in:
Norbi Peti 2020-10-27 22:48:39 +01:00
parent ff0d54e00b
commit 09074f1a2e
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
8 changed files with 42 additions and 67 deletions

View file

@ -21,35 +21,29 @@ import java.util.stream.Collectors;
@SupportedAnnotationTypes("buttondevteam.*") @SupportedAnnotationTypes("buttondevteam.*")
public class ButtonProcessor extends AbstractProcessor { public class ButtonProcessor extends AbstractProcessor {
@Override @Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (configProcessor == null) if (configProcessor == null)
configProcessor = new ConfigProcessor(processingEnv); configProcessor = new ConfigProcessor(processingEnv);
for (TypeElement te : annotations) { for (TypeElement te : annotations) {
Set<? extends Element> classes = roundEnv.getElementsAnnotatedWith(te); Set<? extends Element> classes = roundEnv.getElementsAnnotatedWith(te);
for (Element targetcl : classes) { for (Element targetcl : classes) {
System.out.println("Processing " + targetcl); List<? extends AnnotationMirror> annotationMirrors = processingEnv.getElementUtils()
List<? extends AnnotationMirror> annotationMirrors = processingEnv.getElementUtils() .getAllAnnotationMirrors(targetcl);
.getAllAnnotationMirrors(targetcl); Function<String, Boolean> hasAnnotation = ann -> annotationMirrors.stream()
//System.out.println("Annotations: " + annotationMirrors); .anyMatch(am -> am.getAnnotationType().toString().contains(ann));
Function<String, Boolean> hasAnnotation = ann -> annotationMirrors.stream() if (hasAnnotation.apply("ChromaGamerEnforcer") && !hasAnnotation.apply("UserClass")
.anyMatch(am -> am.getAnnotationType().toString().contains(ann)); && !targetcl.getModifiers().contains(Modifier.ABSTRACT))
if (hasAnnotation.apply("ChromaGamerEnforcer") && !hasAnnotation.apply("UserClass") processingEnv.getMessager().printMessage(Kind.ERROR,
&& !targetcl.getModifiers().contains(Modifier.ABSTRACT)) "No UserClass annotation found for " + targetcl.getSimpleName(), targetcl);
processingEnv.getMessager().printMessage(Kind.ERROR, if (hasAnnotation.apply("TBMCPlayerEnforcer") && !hasAnnotation.apply("PlayerClass")
"No UserClass annotation found for " + targetcl.getSimpleName(), targetcl); && !targetcl.getModifiers().contains(Modifier.ABSTRACT))
if (hasAnnotation.apply("TBMCPlayerEnforcer") && !hasAnnotation.apply("PlayerClass") processingEnv.getMessager().printMessage(Kind.ERROR,
&& !targetcl.getModifiers().contains(Modifier.ABSTRACT)) "No PlayerClass annotation found for " + targetcl.getSimpleName(), targetcl);
processingEnv.getMessager().printMessage(Kind.ERROR, processSubcommands(targetcl, annotationMirrors);
"No PlayerClass annotation found for " + targetcl.getSimpleName(), targetcl); if (hasAnnotation.apply("HasConfig"))
for (AnnotationMirror annotation : annotationMirrors) { configProcessor.process(targetcl);
String type = annotation.getAnnotationType().toString(); }
//System.out.println("Type: " + type); }
}
processSubcommands(targetcl, annotationMirrors);
if (hasAnnotation.apply("HasConfig"))
configProcessor.process(targetcl);
}
}
try { try {
if (found) { if (found) {
FileObject fo = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "commands.yml"); FileObject fo = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "commands.yml");
@ -59,38 +53,33 @@ public class ButtonProcessor extends AbstractProcessor {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
return true; // claim the annotations return true; // claim the annotations
} }
private YamlConfiguration yc = new YamlConfiguration(); private final YamlConfiguration yc = new YamlConfiguration();
private boolean found = false; private boolean found = false;
private ConfigProcessor configProcessor; private ConfigProcessor configProcessor;
private void processSubcommands(Element targetcl, List<? extends AnnotationMirror> annotationMirrors) { private void processSubcommands(Element method, List<? extends AnnotationMirror> annotationMirrors) {
if (!(targetcl instanceof ExecutableElement)) if (!(method instanceof ExecutableElement))
return; return;
//System.out.println("Annotations: "+annotationMirrors);
if (annotationMirrors.stream().noneMatch(an -> an.getAnnotationType().toString().endsWith("Subcommand"))) if (annotationMirrors.stream().noneMatch(an -> an.getAnnotationType().toString().endsWith("Subcommand")))
return; return;
//System.out.print("Processing method: " + targetcl.getEnclosingElement()+" "+targetcl); ConfigurationSection cs = yc.createSection(method.getEnclosingElement().toString()
ConfigurationSection cs = yc.createSection(targetcl.getEnclosingElement().toString() + "." + method.getSimpleName().toString()); //Need to do the 2 config sections at once so it doesn't overwrite the class section
+ "." + targetcl.getSimpleName().toString()); //Need to do the 2 config sections at once so it doesn't overwrite the class section System.out.println("Found subcommand: " + method);
System.out.println(targetcl); cs.set("method", method.toString());
cs.set("method", targetcl.toString()); cs.set("params", ((ExecutableElement) method).getParameters().stream().skip(1).map(p -> {
cs.set("params", ((ExecutableElement) targetcl).getParameters().stream().skip(1).map(p -> {
//String tn=p.asType().toString();
//return tn.substring(tn.lastIndexOf('.')+1)+" "+p.getSimpleName();
boolean optional = p.getAnnotationMirrors().stream().anyMatch(am -> am.getAnnotationType().toString().endsWith("OptionalArg")); boolean optional = p.getAnnotationMirrors().stream().anyMatch(am -> am.getAnnotationType().toString().endsWith("OptionalArg"));
if (optional) if (optional)
return "[" + p.getSimpleName() + "]"; return "[" + p.getSimpleName() + "]";
return "<" + p.getSimpleName() + ">"; return "<" + p.getSimpleName() + ">";
}).collect(Collectors.joining(" "))); }).collect(Collectors.joining(" ")));
//System.out.println();
found = true; found = true;
} }
@Override @Override
public SourceVersion getSupportedSourceVersion() { public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported(); return SourceVersion.latestSupported();
} }
} }

View file

@ -48,10 +48,6 @@ public class ConfigProcessor {
e.printStackTrace(); e.printStackTrace();
} }
for (Element e : targetcl.getEnclosedElements()) { for (Element e : targetcl.getEnclosedElements()) {
/*System.out.println("Element: "+e);
System.out.println("Type: "+e.getClass()+" - "+e.getKind());
if(e instanceof ExecutableElement)
System.out.println("METHOD!");*/
TypeMirror tm; TypeMirror tm;
if (e instanceof ExecutableElement) if (e instanceof ExecutableElement)
tm = ((ExecutableElement) e).getReturnType(); tm = ((ExecutableElement) e).getReturnType();
@ -63,25 +59,19 @@ public class ConfigProcessor {
DeclaredType dt = (DeclaredType) tm; DeclaredType dt = (DeclaredType) tm;
if (!dt.asElement().getSimpleName().toString().contains("ConfigData")) if (!dt.asElement().getSimpleName().toString().contains("ConfigData"))
continue; //Ahhha! There was a return here! (MinecraftChatModule getListener()) continue; //Ahhha! There was a return here! (MinecraftChatModule getListener())
System.out.println("Config: " + e.getSimpleName());
String doc = procEnv.getElementUtils().getDocComment(e); String doc = procEnv.getElementUtils().getDocComment(e);
if (doc == null) continue; if (doc == null) continue;
System.out.println("DOC: " + doc); System.out.println("Adding docs for config: " + e.getSimpleName());
yc.set(path + "." + e.getSimpleName(), doc.trim()); yc.set(path + "." + e.getSimpleName(), doc.trim());
/*System.out.println("Set " + path + "." + e.getSimpleName() + " to " + doc.trim());
System.out.println("Check: " + yc.getString(path + "." + e.getSimpleName()));
System.out.println("Wut2: " + yc.getString("components.MemberComponent.memberGroup"));*/
} }
String javadoc = procEnv.getElementUtils().getDocComment(targetcl); String javadoc = procEnv.getElementUtils().getDocComment(targetcl);
if (javadoc != null) { if (javadoc != null) {
System.out.println("JAVADOC"); System.out.println("Adding docs for class: " + targetcl.getSimpleName());
System.out.println(javadoc.trim());
yc.set(path + ".generalDescriptionInsteadOfAConfig", javadoc.trim()); yc.set(path + ".generalDescriptionInsteadOfAConfig", javadoc.trim());
} }
try { try {
yc.save(file); yc.save(file);
//System.out.println("Wut: " + yc.getString("components.MemberComponent.memberGroup"));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View file

@ -30,7 +30,6 @@ public class TBMCChatEvent extends TBMCChatEventBase {
private boolean isIgnoreSenderPermissions() { private boolean isIgnoreSenderPermissions() {
return cm.getPermCheck() != cm.getSender(); return cm.getPermCheck() != cm.getSender();
} }
// TODO: Message object with data?
/** /**
* This will allow the sender of the message if {@link #isIgnoreSenderPermissions()} is true. * This will allow the sender of the message if {@link #isIgnoreSenderPermissions()} is true.

View file

@ -54,6 +54,6 @@ public abstract class TBMCChatEventBase extends Event implements Cancellable {
*/ */
@Nullable @Nullable
public String getGroupID(CommandSender sender) { public String getGroupID(CommandSender sender) {
return channel.getGroupID(sender); //TODO: Performance-wise it'd be much better to use serialization for player data - it's only converted once return channel.getGroupID(sender);
} }
} }

View file

@ -30,13 +30,9 @@ public class TBMCChatPreprocessEvent extends Event implements Cancellable {
super(true); super(true);
this.sender = sender; this.sender = sender;
this.channel = channel; this.channel = channel;
this.message = message; // TODO: Message object with data? this.message = message;
} }
/*
* public TBMCPlayer getPlayer() { return TBMCPlayer.getPlayer(sender); // TODO: Get Chroma user }
*/
@Override @Override
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; return handlers;

View file

@ -133,7 +133,8 @@ public abstract class ButtonPlugin extends JavaPlugin {
@Override @Override
public FileConfiguration getConfig() { public FileConfiguration getConfig() {
if (yaml == null) if (yaml == null)
justReload(); //TODO: If it fails to load, it'll probably throw an NPE justReload();
if (yaml == null) return new YamlConfiguration(); //Return a temporary instance
return yaml; return yaml;
} }

View file

@ -217,7 +217,7 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> implemen
int x = path.indexOf(' '); int x = path.indexOf(' ');
var mainPath = path.substring(0, x == -1 ? path.length() : x); var mainPath = path.substring(0, x == -1 ? path.length() : x);
Command bukkitCommand; Command bukkitCommand;
{ //TODO: Commands conflicting with Essentials have to be registered in plugin.yml { //Commands conflicting with Essentials have to be registered in plugin.yml
var oldcmd = cmdmap.getCommand(command.getPlugin().getName() + ":" + mainPath); //The label with the fallback prefix is always registered var oldcmd = cmdmap.getCommand(command.getPlugin().getName() + ":" + mainPath); //The label with the fallback prefix is always registered
if (oldcmd == null) { if (oldcmd == null) {
bukkitCommand = new BukkitCommand(mainPath); bukkitCommand = new BukkitCommand(mainPath);

View file

@ -1,6 +1,6 @@
package buttondevteam.lib.player; package buttondevteam.lib.player;
@PlayerClass(pluginname = "ButtonCore") //TODO: Migrate @PlayerClass(pluginname = "Chroma-Core")
public final class TBMCPlayer extends TBMCPlayerBase { public final class TBMCPlayer extends TBMCPlayerBase {
} }