Plugin list gen, fixes

It'll generate a plugin list file on each start
#37
This commit is contained in:
Norbi Peti 2018-05-15 22:44:55 +02:00
parent a24c4a5e54
commit 75ab715c6e
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
9 changed files with 156 additions and 128 deletions

View file

@ -1,13 +1,13 @@
<component name="libraryTable"> <component name="libraryTable">
<library name="Maven: net.md-5:bungeecord-chat:1.12-SNAPSHOT"> <library name="Maven: net.md-5:bungeecord-chat:1.12-SNAPSHOT">
<CLASSES> <CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180420.081408-78.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180513.014306-84.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC> <JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180420.081408-78-javadoc.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180513.014306-84-javadoc.jar!/" />
</JAVADOC> </JAVADOC>
<SOURCES> <SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180420.081408-78-sources.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/net/md-5/bungeecord-chat/1.12-SNAPSHOT/bungeecord-chat-1.12-20180513.014306-84-sources.jar!/" />
</SOURCES> </SOURCES>
</library> </library>
</component> </component>

View file

@ -1,13 +1,13 @@
<component name="libraryTable"> <component name="libraryTable">
<library name="Maven: org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT"> <library name="Maven: org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT">
<CLASSES> <CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/spigotmc/spigot-api/1.12.2-R0.1-SNAPSHOT/spigot-api-1.12.2-R0.1-20180506.041854-145.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/org/spigotmc/spigot-api/1.12.2-R0.1-SNAPSHOT/spigot-api-1.12.2-R0.1-SNAPSHOT.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC> <JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/spigotmc/spigot-api/1.12.2-R0.1-SNAPSHOT/spigot-api-1.12.2-R0.1-20180506.041854-145-javadoc.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/org/spigotmc/spigot-api/1.12.2-R0.1-SNAPSHOT/spigot-api-1.12.2-R0.1-SNAPSHOT-javadoc.jar!/" />
</JAVADOC> </JAVADOC>
<SOURCES> <SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/spigotmc/spigot-api/1.12.2-R0.1-SNAPSHOT/spigot-api-1.12.2-R0.1-20180506.041854-145-sources.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/org/spigotmc/spigot-api/1.12.2-R0.1-SNAPSHOT/spigot-api-1.12.2-R0.1-SNAPSHOT-sources.jar!/" />
</SOURCES> </SOURCES>
</library> </library>
</component> </component>

View file

@ -6,6 +6,13 @@
<option value="$PROJECT_DIR$/pom.xml" /> <option value="$PROJECT_DIR$/pom.xml" />
</list> </list>
</option> </option>
<option name="ignoredFiles">
<set>
<option value="$PROJECT_DIR$/pom.xml" />
</set>
</option>
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component> </component>
<component name="ProjectRootManager" version="2" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
</project> </project>

View file

@ -3,7 +3,6 @@
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/BuildConfigUpdater/BuildConfigUpdater.iml" filepath="$PROJECT_DIR$/BuildConfigUpdater/BuildConfigUpdater.iml" /> <module fileurl="file://$PROJECT_DIR$/BuildConfigUpdater/BuildConfigUpdater.iml" filepath="$PROJECT_DIR$/BuildConfigUpdater/BuildConfigUpdater.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/ButtonCore.iml" filepath="$PROJECT_DIR$/.idea/ButtonCore.iml" />
<module fileurl="file://$PROJECT_DIR$/ButtonCore/ButtonCore (1) (com.github.TBMCPlugins.ButtonCore).iml" filepath="$PROJECT_DIR$/ButtonCore/ButtonCore (1) (com.github.TBMCPlugins.ButtonCore).iml" /> <module fileurl="file://$PROJECT_DIR$/ButtonCore/ButtonCore (1) (com.github.TBMCPlugins.ButtonCore).iml" filepath="$PROJECT_DIR$/ButtonCore/ButtonCore (1) (com.github.TBMCPlugins.ButtonCore).iml" />
<module fileurl="file://$PROJECT_DIR$/ButtonProcessor/ButtonProcessor.iml" filepath="$PROJECT_DIR$/ButtonProcessor/ButtonProcessor.iml" /> <module fileurl="file://$PROJECT_DIR$/ButtonProcessor/ButtonProcessor.iml" filepath="$PROJECT_DIR$/ButtonProcessor/ButtonProcessor.iml" />
</modules> </modules>

View file

@ -11,7 +11,8 @@
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="ButtonCore (1) (com.github.TBMCPlugins.ButtonCore)" /> <orderEntry type="library" name="Maven: com.google.guava:guava:21.0" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.6" level="project" />
<orderEntry type="module" module-name="ButtonCore (1) (com.github.TBMCPlugins.ButtonCore)" /> <orderEntry type="module" module-name="ButtonCore (1) (com.github.TBMCPlugins.ButtonCore)" />
<orderEntry type="library" name="Maven: org.reflections:reflections:0.9.10" level="project" /> <orderEntry type="library" name="Maven: org.reflections:reflections:0.9.10" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:annotations:2.0.1" level="project" /> <orderEntry type="library" name="Maven: com.google.code.findbugs:annotations:2.0.1" level="project" />

View file

@ -8,6 +8,7 @@ import buttondevteam.lib.chat.Color;
import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.player.TBMCPlayerBase; import buttondevteam.lib.player.TBMCPlayerBase;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -16,7 +17,9 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.stream.Collectors;
public class MainPlugin extends JavaPlugin { public class MainPlugin extends JavaPlugin {
public static MainPlugin Instance; 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("§aGREEN", Color.Green, "green"));
TBMCChatAPI.RegisterChatChannel(new ChatRoom("§bBLUE", Color.Blue, "blue")); TBMCChatAPI.RegisterChatChannel(new ChatRoom("§bBLUE", Color.Blue, "blue"));
TBMCChatAPI.RegisterChatChannel(new ChatRoom("§5PURPLE", Color.DarkPurple, "purple")); 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 + "."); 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..."); System.out.println("Updating " + files.length + " plugins...");
for (File file : files) { for (File file : files) {
try { 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) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
System.out.println("Update complete!"); System.out.println("Update complete!");
}); }).start();
} }
private boolean setupPermissions() { private boolean setupPermissions() {

View file

@ -14,113 +14,106 @@ import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
public class Channel { public class Channel {
public final String DisplayName; public final String DisplayName;
public final Color color; public final Color color;
public final String ID; public final String ID;
public @Nullable @Nullable
String[] IDs; public String[] IDs;
/** /**
* Filters both the sender and the targets * Filters both the sender and the targets
*/ */
public final Function<CommandSender, RecipientTestResult> filteranderrormsg; public final Function<CommandSender, RecipientTestResult> filteranderrormsg;
private static List<Channel> channels = new ArrayList<>(); private static List<Channel> channels = new ArrayList<>();
/** /**
* Creates a channel. * Creates a channel.
* *
* @param displayname * @param displayname The name that should appear at the start of the message. <b>A chat color is expected at the beginning (§9).</b>
* The name that should appear at the start of the message. <b>A chat color is expected at the beginning (§9).</b> * @param color The default color of the messages sent in the channel
* @param color * @param command The command to be used for the channel <i>without /</i>. For example "mod". It's also used for scoreboard objective names.
* The default color of the messages sent in the channel * @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.<br>
* @param command * May be null to send to everyone.
* The command to be used for the channel <i>without /</i>. For example "mod". It's also used for scoreboard objective names. */
* @param filteranderrormsg public Channel(String displayname, Color color, String command,
* 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.<br> Function<CommandSender, RecipientTestResult> filteranderrormsg) {
* May be null to send to everyone. DisplayName = displayname;
*/ this.color = color;
public Channel(String displayname, Color color, String command, ID = command;
Function<CommandSender, RecipientTestResult> filteranderrormsg) { this.filteranderrormsg = filteranderrormsg;
DisplayName = displayname; }
this.color = color;
ID = command;
this.filteranderrormsg = filteranderrormsg;
}
/** /**
* Must be only called from a subclass - otherwise it'll throw an exception. * Must be only called from a subclass - otherwise it'll throw an exception.
* *
* @see Channel#Channel(String, Color, String, Function) * @see Channel#Channel(String, Color, String, Function)
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected <T extends Channel> Channel(String displayname, Color color, String command, protected <T extends Channel> Channel(String displayname, Color color, String command,
BiFunction<T, CommandSender, RecipientTestResult> filteranderrormsg) { BiFunction<T, CommandSender, RecipientTestResult> filteranderrormsg) {
DisplayName = displayname; DisplayName = displayname;
this.color = color; this.color = color;
ID = command; ID = command;
this.filteranderrormsg = s -> filteranderrormsg.apply((T) this, s); this.filteranderrormsg = s -> filteranderrormsg.apply((T) this, s);
} }
public static List<Channel> getChannels() { public static List<Channel> getChannels() {
return channels; 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 * 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. * generated automatically.
* *
* @param permgroup * @param permgroup The group that can access the channel or <b>null</b> to only allow OPs.
* The group that can access the channel or <b>null</b> to only allow OPs. * @return
* @return */
*/ public static Function<CommandSender, RecipientTestResult> inGroupFilter(String permgroup) {
public static Function<CommandSender, RecipientTestResult> inGroupFilter(String permgroup) { return noScoreResult(
return noScoreResult( s -> s.isOp() || (permgroup != null
s -> s.isOp() || (permgroup != null ? s instanceof Player && MainPlugin.permission.playerInGroup((Player) s, permgroup) : false),
? s instanceof Player && MainPlugin.permission.playerInGroup((Player) s, permgroup) : false), "You need to be a(n) " + (permgroup != null ? permgroup : "OP") + " to use this channel.");
"You need to be a(n) " + (permgroup != null ? permgroup : "OP") + " to use this channel."); }
}
public static Function<CommandSender, RecipientTestResult> noScoreResult(Predicate<CommandSender> filter, public static Function<CommandSender, RecipientTestResult> noScoreResult(Predicate<CommandSender> filter,
String errormsg) { String errormsg) {
return s -> filter.test(s) ? new RecipientTestResult(0) : new RecipientTestResult(errormsg); return s -> filter.test(s) ? new RecipientTestResult(0) : new RecipientTestResult(errormsg);
} }
public static <T extends Channel> BiFunction<T, CommandSender, RecipientTestResult> noScoreResult( public static <T extends Channel> BiFunction<T, CommandSender, RecipientTestResult> noScoreResult(
BiPredicate<T, CommandSender> filter, String errormsg) { BiPredicate<T, CommandSender> filter, String errormsg) {
return (this_, s) -> filter.test(this_, s) ? new RecipientTestResult(0) : new RecipientTestResult(errormsg); return (this_, s) -> filter.test(this_, s) ? new RecipientTestResult(0) : new RecipientTestResult(errormsg);
} }
public static Channel GlobalChat; public static Channel GlobalChat;
public static Channel AdminChat; public static Channel AdminChat;
public static Channel ModChat; public static Channel ModChat;
static void RegisterChannel(Channel channel) { static void RegisterChannel(Channel channel) {
channels.add(channel); channels.add(channel);
Bukkit.getPluginManager().callEvent(new ChatChannelRegisterEvent(channel)); Bukkit.getPluginManager().callEvent(new ChatChannelRegisterEvent(channel));
} }
public static class RecipientTestResult { public static class RecipientTestResult {
public String errormessage; public String errormessage;
public int score; public int score;
/** /**
* Creates a result that indicates an <b>error</b> * Creates a result that indicates an <b>error</b>
* *
* @param errormessage * @param errormessage The error message to show the sender if they don't meet the criteria.
* The error message to show the sender if they don't meet the criteria. */
*/ public RecipientTestResult(String errormessage) {
public RecipientTestResult(String errormessage) { this.errormessage = errormessage;
this.errormessage = errormessage; }
}
/** /**
* Creates a result that indicates a <b>success</b> * Creates a result that indicates a <b>success</b>
* *
* @param score * @param score The score that identifies the target group. For example, the index of the town or nation to send to.
* The score that identifies the target group. For example, the index of the town or nation to send to. */
*/ public RecipientTestResult(int score) {
public RecipientTestResult(int score) { this.score = score;
this.score = score; }
} }
}
} }

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="ExternalSystem" externalSystem="Maven" />
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" /> <output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" /> <output-test url="file://$MODULE_DIR$/target/test-classes" />

View file

@ -1,5 +1,9 @@
package buttondevteam.buttonproc; 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.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes; import javax.annotation.processing.SupportedAnnotationTypes;
@ -7,29 +11,43 @@ import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion; import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element; import javax.lang.model.element.Element;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
import java.util.List; import javax.lang.model.util.Elements;
import java.util.Set; 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.*") @SupportedAnnotationTypes("buttondevteam.*")
public class ButtonProcessor extends AbstractProcessor { public class ButtonProcessor extends AbstractProcessor {
/** * Check if both @Stateful and @Stateless are present in an * session bean. If so, emits a warning message. */
@Override @Override
public boolean process(Set<? extends TypeElement> typeElements, RoundEnvironment roundEnv) { // TODO: SEparate JAR public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (TypeElement te : typeElements) { for (TypeElement te : annotations) {
Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(te); Set<? extends Element> classes = roundEnv.getElementsAnnotatedWith(te);
for (Element element : elements) { for (Element targetcl : classes) {
System.out.println("Processing " + element); System.out.println("Processing " + targetcl);
List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors(); List<? extends AnnotationMirror> annotationMirrors = processingEnv.getElementUtils()
System.out.println("Annotations: " + annotationMirrors); .getAllAnnotationMirrors(targetcl);
for (AnnotationMirror annotation : annotationMirrors) { System.out.println("Annotations: " + annotationMirrors);
String type = annotation.getAnnotationType().toString(); Function<String, Boolean> hasAnnotation = ann -> annotationMirrors.stream()
System.out.println("Type: " + type); .anyMatch(am -> am.getAnnotationType().toString().contains(ann));
} if (hasAnnotation.apply("ChromaGamerEnforcer") && !hasAnnotation.apply("UserClass")
} && !targetcl.getModifiers().contains(Modifier.ABSTRACT))
} processingEnv.getMessager().printMessage(Kind.ERROR,
return true; // claim the annotations "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();
}
} }