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.*")
public class ButtonProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (configProcessor == null)
configProcessor = new ConfigProcessor(processingEnv);
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<String, Boolean> 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);
}
processSubcommands(targetcl, annotationMirrors);
if (hasAnnotation.apply("HasConfig"))
configProcessor.process(targetcl);
}
}
for (TypeElement te : annotations) {
Set<? extends Element> classes = roundEnv.getElementsAnnotatedWith(te);
for (Element targetcl : classes) {
List<? extends AnnotationMirror> annotationMirrors = processingEnv.getElementUtils()
.getAllAnnotationMirrors(targetcl);
Function<String, Boolean> 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);
processSubcommands(targetcl, annotationMirrors);
if (hasAnnotation.apply("HasConfig"))
configProcessor.process(targetcl);
}
}
try {
if (found) {
FileObject fo = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "commands.yml");
@ -59,38 +53,33 @@ public class ButtonProcessor extends AbstractProcessor {
} catch (IOException e) {
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 ConfigProcessor configProcessor;
private void processSubcommands(Element targetcl, List<? extends AnnotationMirror> annotationMirrors) {
if (!(targetcl instanceof ExecutableElement))
private void processSubcommands(Element method, List<? extends AnnotationMirror> annotationMirrors) {
if (!(method instanceof ExecutableElement))
return;
//System.out.println("Annotations: "+annotationMirrors);
if (annotationMirrors.stream().noneMatch(an -> an.getAnnotationType().toString().endsWith("Subcommand")))
return;
//System.out.print("Processing method: " + targetcl.getEnclosingElement()+" "+targetcl);
ConfigurationSection cs = yc.createSection(targetcl.getEnclosingElement().toString()
+ "." + targetcl.getSimpleName().toString()); //Need to do the 2 config sections at once so it doesn't overwrite the class section
System.out.println(targetcl);
cs.set("method", targetcl.toString());
cs.set("params", ((ExecutableElement) targetcl).getParameters().stream().skip(1).map(p -> {
//String tn=p.asType().toString();
//return tn.substring(tn.lastIndexOf('.')+1)+" "+p.getSimpleName();
ConfigurationSection cs = yc.createSection(method.getEnclosingElement().toString()
+ "." + method.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);
cs.set("method", method.toString());
cs.set("params", ((ExecutableElement) method).getParameters().stream().skip(1).map(p -> {
boolean optional = p.getAnnotationMirrors().stream().anyMatch(am -> am.getAnnotationType().toString().endsWith("OptionalArg"));
if (optional)
return "[" + p.getSimpleName() + "]";
return "<" + p.getSimpleName() + ">";
}).collect(Collectors.joining(" ")));
//System.out.println();
found = true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}
}

View file

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

View file

@ -30,7 +30,6 @@ public class TBMCChatEvent extends TBMCChatEventBase {
private boolean isIgnoreSenderPermissions() {
return cm.getPermCheck() != cm.getSender();
}
// TODO: Message object with data?
/**
* 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
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);
this.sender = sender;
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
public HandlerList getHandlers() {
return handlers;

View file

@ -133,7 +133,8 @@ public abstract class ButtonPlugin extends JavaPlugin {
@Override
public FileConfiguration getConfig() {
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;
}

View file

@ -217,7 +217,7 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> implemen
int x = path.indexOf(' ');
var mainPath = path.substring(0, x == -1 ? path.length() : x);
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
if (oldcmd == null) {
bukkitCommand = new BukkitCommand(mainPath);

View file

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