Plugin list gen, fixes
It'll generate a plugin list file on each start #37
This commit is contained in:
parent
a24c4a5e54
commit
75ab715c6e
9 changed files with 156 additions and 128 deletions
|
@ -1,13 +1,13 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Maven: net.md-5:bungeecord-chat:1.12-SNAPSHOT">
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
</library>
|
||||
</component>
|
|
@ -1,13 +1,13 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Maven: org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT">
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
</library>
|
||||
</component>
|
|
@ -6,6 +6,13 @@
|
|||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</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 name="ProjectRootManager" version="2" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
|
||||
</project>
|
|
@ -3,7 +3,6 @@
|
|||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<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$/ButtonProcessor/ButtonProcessor.iml" filepath="$PROJECT_DIR$/ButtonProcessor/ButtonProcessor.iml" />
|
||||
</modules>
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<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="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" />
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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<CommandSender, RecipientTestResult> 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<CommandSender, RecipientTestResult> filteranderrormsg;
|
||||
|
||||
private static List<Channel> channels = new ArrayList<>();
|
||||
private static List<Channel> channels = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Creates a channel.
|
||||
*
|
||||
* @param displayname
|
||||
* 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 command
|
||||
* The command to be used for the channel <i>without /</i>. 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.<br>
|
||||
* May be null to send to everyone.
|
||||
*/
|
||||
public Channel(String displayname, Color color, String command,
|
||||
Function<CommandSender, RecipientTestResult> 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. <b>A chat color is expected at the beginning (§9).</b>
|
||||
* @param color The default color of the messages sent in the channel
|
||||
* @param command The command to be used for the channel <i>without /</i>. 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.<br>
|
||||
* May be null to send to everyone.
|
||||
*/
|
||||
public Channel(String displayname, Color color, String command,
|
||||
Function<CommandSender, RecipientTestResult> 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 <T extends Channel> Channel(String displayname, Color color, String command,
|
||||
BiFunction<T, CommandSender, RecipientTestResult> 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 <T extends Channel> Channel(String displayname, Color color, String command,
|
||||
BiFunction<T, CommandSender, RecipientTestResult> filteranderrormsg) {
|
||||
DisplayName = displayname;
|
||||
this.color = color;
|
||||
ID = command;
|
||||
this.filteranderrormsg = s -> filteranderrormsg.apply((T) this, s);
|
||||
}
|
||||
|
||||
public static List<Channel> getChannels() {
|
||||
return channels;
|
||||
}
|
||||
public static List<Channel> 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 <b>null</b> to only allow OPs.
|
||||
* @return
|
||||
*/
|
||||
public static Function<CommandSender, RecipientTestResult> 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 <b>null</b> to only allow OPs.
|
||||
* @return
|
||||
*/
|
||||
public static Function<CommandSender, RecipientTestResult> 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<CommandSender, RecipientTestResult> noScoreResult(Predicate<CommandSender> filter,
|
||||
String errormsg) {
|
||||
return s -> filter.test(s) ? new RecipientTestResult(0) : new RecipientTestResult(errormsg);
|
||||
}
|
||||
public static Function<CommandSender, RecipientTestResult> noScoreResult(Predicate<CommandSender> filter,
|
||||
String errormsg) {
|
||||
return s -> filter.test(s) ? new RecipientTestResult(0) : new RecipientTestResult(errormsg);
|
||||
}
|
||||
|
||||
public static <T extends Channel> BiFunction<T, CommandSender, RecipientTestResult> noScoreResult(
|
||||
BiPredicate<T, CommandSender> filter, String errormsg) {
|
||||
return (this_, s) -> filter.test(this_, s) ? new RecipientTestResult(0) : new RecipientTestResult(errormsg);
|
||||
}
|
||||
public static <T extends Channel> BiFunction<T, CommandSender, RecipientTestResult> noScoreResult(
|
||||
BiPredicate<T, CommandSender> 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 <b>error</b>
|
||||
*
|
||||
* @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 <b>error</b>
|
||||
*
|
||||
* @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 <b>success</b>
|
||||
*
|
||||
* @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 <b>success</b>
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
|
|
|
@ -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<? 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();
|
||||
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<? 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<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);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true; // claim the annotations
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceVersion getSupportedSourceVersion() {
|
||||
return SourceVersion.latestSupported();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue