Compare commits

...

17 commits

Author SHA1 Message Date
864839a96b Bump version 2025-09-03 19:37:24 +05:00
dfca65436f Don't check source if plugin is velocity 2025-09-03 19:37:14 +05:00
f8dc4752c1 Change update check link 2025-09-03 19:35:59 +05:00
44ac8386c9 Project and plugin name refactor 2025-09-03 19:35:43 +05:00
8de4ee24ef Project and plugin name refactor 2025-09-03 19:35:38 +05:00
41d7c7e864 Remove the use of the getAsyncExecutor method because it is missing 2025-09-03 19:35:25 +05:00
fd161ddef1 Add implementation for paper (paper really likes to do crap) 2025-09-03 19:34:08 +05:00
4fc4f7fdd3 Fix ConcurrentModificationException 2025-09-03 19:33:03 +05:00
1978baa131 Add recursive flag 2025-09-03 19:32:22 +05:00
a4ccfe99bb Add stacktrace print 2025-09-03 19:31:59 +05:00
730b0d6191 Add recursively loaded & unloaded message keys 2025-09-03 19:31:27 +05:00
68dbdbcda0 Add recursively loaded & unloaded message keys 2025-09-03 19:31:19 +05:00
c0d0ad0974 Refactor project name 2025-09-03 19:30:58 +05:00
4a09e91517 Add recursive flag 2025-09-03 19:30:42 +05:00
20112987a9 Add recursive flag 2025-09-03 19:30:24 +05:00
c95619439d Remove unnecessary methods 2025-09-03 19:30:11 +05:00
bcdf6d510d Bump version, refactor commandframework groupId, refactor project name 2025-09-03 19:29:41 +05:00
21 changed files with 254 additions and 105 deletions

View file

@ -25,7 +25,7 @@ jobs:
- name: Upload artififacts - name: Upload artififacts
uses: actions/upload-artifact@v2.2.1 uses: actions/upload-artifact@v2.2.1
with: with:
name: ServerUtils name: Bukman
path: jars/*.jar path: jars/*.jar
- name: Publish - name: Publish
if: ${{ github.event_name == 'push' }} if: ${{ github.event_name == 'push' }}

View file

@ -9,11 +9,11 @@ val rootDependencyDir = "${rootProject.group}.dependencies"
val dependencyDir = "${group}.bukkit.dependencies" val dependencyDir = "${group}.bukkit.dependencies"
version = rootProject.version version = rootProject.version
base { base {
archivesName.set("${rootProject.name}-Bukkit") archivesName.set("${rootProject.name}-bukkit")
} }
dependencies { dependencies {
implementation("cloud.commandframework:cloud-paper:${VersionConstants.cloudVersion}") implementation("org.zhdev.oblak:cloud-paper:${VersionConstants.cloudVersion}")
implementation("net.kyori:adventure-api:${VersionConstants.adventureVersion}") { implementation("net.kyori:adventure-api:${VersionConstants.adventureVersion}") {
exclude("net.kyori", "adventure-text-minimessage") exclude("net.kyori", "adventure-text-minimessage")
} }
@ -36,11 +36,11 @@ tasks.withType<ShadowJar> {
} }
bukkit { bukkit {
name = "ServerUtils" name = "Bukman"
main = "net.frankheijden.serverutils.bukkit.ServerUtils" main = "net.frankheijden.serverutils.bukkit.ServerUtils"
description = "A server utility" description = "A server utility"
apiVersion = "1.13" apiVersion = "1.13"
website = "https://github.com/FrankHeijden/ServerUtils" website = "https://git.zhira.net/zhdev/bukman"
softDepend = listOf("ServerUtilsUpdater") softDepend = listOf("ServerUtilsUpdater")
authors = listOf("FrankHeijden") authors = listOf("FrankHeijden", "ZhDev")
} }

View file

@ -2,6 +2,9 @@ package net.frankheijden.serverutils.bukkit.managers;
import java.io.Closeable; import java.io.Closeable;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -12,8 +15,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.regex.Matcher; import java.util.jar.JarEntry;
import java.util.regex.Pattern; import java.util.jar.JarFile;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import net.frankheijden.serverutils.bukkit.entities.BukkitPluginDescription; import net.frankheijden.serverutils.bukkit.entities.BukkitPluginDescription;
import net.frankheijden.serverutils.bukkit.events.BukkitPluginDisableEvent; import net.frankheijden.serverutils.bukkit.events.BukkitPluginDisableEvent;
@ -41,9 +44,11 @@ import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.InvalidDescriptionException;
import org.bukkit.plugin.InvalidPluginException; import org.bukkit.plugin.InvalidPluginException;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginLoader; import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.UnknownDependencyException; import org.bukkit.plugin.UnknownDependencyException;
import org.yaml.snakeyaml.error.YAMLException;
public class BukkitPluginManager extends AbstractPluginManager<Plugin, BukkitPluginDescription> { public class BukkitPluginManager extends AbstractPluginManager<Plugin, BukkitPluginDescription> {
@ -348,45 +353,43 @@ public class BukkitPluginManager extends AbstractPluginManager<Plugin, BukkitPlu
return knownCommands.get(command); return knownCommands.get(command);
} }
/**
* Retrieves all file associations, i.e. all plugin loaders.
* @return A map with all pluginloaders.
*/
public static Map<Pattern, PluginLoader> getFileAssociations() {
try {
return RSimplePluginManager.getFileAssociations(Bukkit.getPluginManager());
} catch (IllegalAccessException ex) {
ex.printStackTrace();
return null;
}
}
/**
* Retrieves the PluginLoader for the input file.
* @param file The file.
* @return The appropiate PluginLoader.
*/
public static Optional<PluginLoader> getPluginLoader(File file) {
Map<Pattern, PluginLoader> fileAssociations = getFileAssociations();
if (fileAssociations != null) {
for (Map.Entry<Pattern, PluginLoader> entry : fileAssociations.entrySet()) {
Matcher match = entry.getKey().matcher(file.getName());
if (match.find()) {
return Optional.ofNullable(entry.getValue());
}
}
}
return Optional.empty();
}
@Override @Override
public Optional<BukkitPluginDescription> getPluginDescription(File file) throws InvalidPluginDescriptionException { public Optional<BukkitPluginDescription> getPluginDescription(File file) throws InvalidPluginDescriptionException {
if (!file.exists()) return Optional.empty(); if (!file.exists()) return Optional.empty();
Optional<PluginLoader> loader = getPluginLoader(file);
if (!loader.isPresent()) throw new InvalidPluginDescriptionException("Plugin loader is not present!");
try { try {
return Optional.of(new BukkitPluginDescription(loader.get().getPluginDescription(file), file)); JarFile jar = null;
InputStream stream = null;
try {
jar = new JarFile(file);
JarEntry entry = jar.getJarEntry("plugin.yml");
if (entry == null) {
throw new InvalidDescriptionException(new FileNotFoundException("Jar does not contain plugin.yml"));
}
stream = jar.getInputStream(entry);
return Optional.of(new BukkitPluginDescription(new PluginDescriptionFile(stream), file));
} catch (IOException | YAMLException ex) {
throw new InvalidDescriptionException(ex);
} finally {
if (jar != null) {
try {
jar.close();
} catch (IOException ignored) {
// we do nothing
}
}
if (stream != null) {
try {
stream.close();
} catch (IOException ignored) {
// we do nothing
}
}
}
} catch (InvalidDescriptionException ex) { } catch (InvalidDescriptionException ex) {
throw new InvalidPluginDescriptionException(ex); throw new InvalidPluginDescriptionException(ex);
} }

View file

@ -3,6 +3,7 @@ package net.frankheijden.serverutils.bukkit.reflection;
import dev.frankheijden.minecraftreflection.MinecraftReflection; import dev.frankheijden.minecraftreflection.MinecraftReflection;
import dev.frankheijden.minecraftreflection.MinecraftReflectionVersion; import dev.frankheijden.minecraftreflection.MinecraftReflectionVersion;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -51,7 +52,7 @@ public class RCraftServer {
public static void syncCommands(Set<String> removedCommands) { public static void syncCommands(Set<String> removedCommands) {
if (MinecraftReflectionVersion.MINOR < 13) return; if (MinecraftReflectionVersion.MINOR < 13) return;
Collection children = RCommandDispatcher.getDispatcher().getRoot().getChildren(); Collection children = new ArrayList<>(RCommandDispatcher.getDispatcher().getRoot().getChildren());
reflection.invoke(Bukkit.getServer(), "syncCommands"); reflection.invoke(Bukkit.getServer(), "syncCommands");
Object root = RCommandDispatcher.getDispatcher().getRoot(); Object root = RCommandDispatcher.getDispatcher().getRoot();

View file

@ -4,25 +4,46 @@ import dev.frankheijden.minecraftreflection.MinecraftReflection;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern; import dev.frankheijden.minecraftreflection.exceptions.MinecraftReflectionException;
import net.frankheijden.serverutils.bukkit.ServerUtils;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.SimplePluginManager;
public class RSimplePluginManager { public class RSimplePluginManager {
private static final MinecraftReflection reflection = MinecraftReflection.of(Bukkit.getPluginManager().getClass());
private static final MinecraftReflection paperPluginManagerReflection;
private static final MinecraftReflection paperInstanceManagerReflection;
private static final MinecraftReflection reflection = MinecraftReflection.of(SimplePluginManager.class); static {
MinecraftReflection pluginManagerReflection;
MinecraftReflection instanceManagerReflection;
try {
pluginManagerReflection =
MinecraftReflection.of("io.papermc.paper.plugin.manager.PaperPluginManagerImpl");
instanceManagerReflection =
MinecraftReflection.of("io.papermc.paper.plugin.manager.PaperPluginInstanceManager");
} catch (MinecraftReflectionException e) {
pluginManagerReflection = null;
instanceManagerReflection = null;
}
paperPluginManagerReflection = pluginManagerReflection;
paperInstanceManagerReflection = instanceManagerReflection;
}
public static MinecraftReflection getReflection() { public static MinecraftReflection getReflection() {
return reflection; return reflection;
} }
public static Map<Pattern, PluginLoader> getFileAssociations(Object manager) throws IllegalAccessException { /**
return reflection.get(manager, "fileAssociations"); * Gets a list of plugins.
} * @param manager The SimplePluginManager instance to get plugins from.
* @return list of plugins.
*/
public static List<Plugin> getPlugins(Object manager) { public static List<Plugin> getPlugins(Object manager) {
return reflection.get(manager, "plugins"); if (paperPluginManagerReflection == null) {
return reflection.get(manager, "plugins");
}
return paperInstanceManagerReflection.get(getInstanceManager(manager), "plugins");
} }
/** /**
@ -32,9 +53,23 @@ public class RSimplePluginManager {
* @param name The name of the plugin to remove. * @param name The name of the plugin to remove.
*/ */
public static void removeLookupName(Object manager, String name) { public static void removeLookupName(Object manager, String name) {
Map<String, Plugin> lookupNames = reflection.get(manager, "lookupNames"); Map<String, Plugin> lookupNames;
if (lookupNames == null) return; if (paperPluginManagerReflection == null) {
lookupNames = reflection.get(manager, "lookupNames");
} else {
lookupNames = paperInstanceManagerReflection.get(getInstanceManager(manager), "lookupNames");
}
if (lookupNames == null) {
ServerUtils.getInstance().getLogger()
.warning("Cannot remove lookup name '" + name + "' because lookupNames is null");
return;
}
lookupNames.remove(name.replace(' ', '_')); lookupNames.remove(name.replace(' ', '_'));
lookupNames.remove(name.replace(' ', '_').toLowerCase(Locale.ENGLISH)); // Paper lookupNames.remove(name.replace(' ', '_').toLowerCase(Locale.ENGLISH)); // Paper
} }
private static Object getInstanceManager(Object manager) {
Object paperPluginManager = reflection.get(manager, "paperPluginManager");
return paperPluginManagerReflection.get(paperPluginManager, "instanceManager");
}
} }

View file

@ -9,7 +9,7 @@ val rootDependencyDir = "${group}.dependencies"
val dependencyDir = "${group}.bungee.dependencies" val dependencyDir = "${group}.bungee.dependencies"
version = rootProject.version version = rootProject.version
base { base {
archivesName.set("${rootProject.name}-Bungee") archivesName.set("${rootProject.name}-bungee")
} }
repositories { repositories {
@ -17,7 +17,7 @@ repositories {
} }
dependencies { dependencies {
implementation("cloud.commandframework:cloud-bungee:${VersionConstants.cloudVersion}") implementation("org.zhdev.oblak:cloud-bungee:${VersionConstants.cloudVersion}")
implementation("net.kyori:adventure-api:${VersionConstants.adventureVersion}") { implementation("net.kyori:adventure-api:${VersionConstants.adventureVersion}") {
exclude("net.kyori", "adventure-text-minimessage") exclude("net.kyori", "adventure-text-minimessage")
} }
@ -38,7 +38,7 @@ tasks.withType<ShadowJar> {
} }
bungee { bungee {
name = "ServerUtils" name = "Bukman"
main = "net.frankheijden.serverutils.bungee.ServerUtils" main = "net.frankheijden.serverutils.bungee.ServerUtils"
description = "A server utility" description = "A server utility"
softDepends = setOf("ServerUtilsUpdater") softDepends = setOf("ServerUtilsUpdater")

View file

@ -7,7 +7,7 @@ plugins {
group = rootProject.group group = rootProject.group
version = "${rootProject.version}" version = "${rootProject.version}"
base { base {
archivesName.set("${rootProject.name}-Common") archivesName.set("${rootProject.name}-common")
} }
repositories { repositories {

View file

@ -10,6 +10,7 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.IntFunction; import java.util.function.IntFunction;
@ -207,8 +208,13 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
return; return;
} }
if (checkDependingPlugins(context, sender, plugins, "unloadplugin")) { boolean recursive = context.flags().contains("recursive");
return;
List<P> dependingPlugins = getDependingPlugins(context, sender, plugins, "unloadplugin");
if (!recursive) {
if (!dependingPlugins.isEmpty()) return;
} else {
plugins.addAll(0, dependingPlugins);
} }
PluginResults<P> disableResults = plugin.getPluginManager().disablePlugins(plugins); PluginResults<P> disableResults = plugin.getPluginManager().disablePlugins(plugins);
@ -232,7 +238,10 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
return; return;
} }
if (checkDependingPlugins(context, sender, plugins, "reloadplugin")) { boolean recursive = context.flags().contains("recursive");
List<P> dependingPlugins = getDependingPlugins(context, sender, plugins, "reloadplugin");
if (!recursive && !dependingPlugins.isEmpty()) {
return; return;
} }
@ -240,50 +249,108 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
return; return;
} }
if (recursive && !dependingPlugins.isEmpty()) {
PluginResults<P> disableDependingResults = plugin.getPluginManager().disablePlugins(dependingPlugins);
for (PluginResult<P> disableResult : disableDependingResults.getResults()) {
if (!disableResult.isSuccess() && disableResult.getResult() != Result.ALREADY_DISABLED) {
disableResult.sendTo(sender, null);
return;
}
}
CloseablePluginResults<P> unloadDependingResults = plugin.getPluginManager()
.unloadPlugins(dependingPlugins);
unloadDependingResults.tryClose();
unloadDependingResults.sendTo(sender, MessageKey.UNLOADPLUGIN_RECURSIVELY);
}
PluginResults<P> reloadResults = plugin.getPluginManager().reloadPlugins(plugins); PluginResults<P> reloadResults = plugin.getPluginManager().reloadPlugins(plugins);
reloadResults.sendTo(sender, MessageKey.RELOADPLUGIN_SUCCESS); reloadResults.sendTo(sender, MessageKey.RELOADPLUGIN_SUCCESS);
if (recursive && !dependingPlugins.isEmpty()) {
List<String> pluginIds = new ArrayList<>(dependingPlugins.size());
for (P p : dependingPlugins) {
pluginIds.add(plugin.getPluginManager().getPluginId(p));
}
List<File> pluginFiles = new ArrayList<>(dependingPlugins.size());
for (String pluginId : pluginIds) {
Optional<File> pluginFile = plugin.getPluginManager().getPluginFile(pluginId);
if (!pluginFile.isPresent()) {
new PluginResults<P>().addResult(pluginId, Result.FILE_DELETED).sendTo(sender, null);
continue;
}
pluginFiles.add(pluginFile.get());
}
PluginResults<P> loadDependingResults = plugin.getPluginManager().loadPlugins(pluginFiles);
if (!loadDependingResults.isSuccess()) {
PluginResult<P> failedResult = loadDependingResults.last();
failedResult.sendTo(sender, null);
}
PluginResults<P> enableResults = plugin.getPluginManager().enablePlugins(loadDependingResults.getPlugins());
enableResults.sendTo(sender, MessageKey.LOADPLUGIN_RECURSIVELY);
}
} }
protected boolean checkDependingPlugins(CommandContext<C> context, C sender, List<P> plugins, String subcommand) { protected boolean checkDependingPlugins(CommandContext<C> context, C sender, List<P> plugins, String subcommand) {
if (context.flags().contains("force")) return false; return !getDependingPlugins(context, sender, plugins, subcommand).isEmpty();
}
protected List<P> getDependingPlugins(CommandContext<C> context, C sender, List<P> plugins, String subcommand) {
if (context.flags().contains("force")) return Collections.emptyList();
boolean recursive = context.flags().contains("recursive");
AbstractPluginManager<P, ?> pluginManager = plugin.getPluginManager(); AbstractPluginManager<P, ?> pluginManager = plugin.getPluginManager();
MessagesResource messages = plugin.getMessagesResource(); MessagesResource messages = plugin.getMessagesResource();
List<P> dependingPluginsAll = new ArrayList<>();
boolean hasDependingPlugins = false; boolean hasDependingPlugins = false;
for (P plugin : plugins) { for (P plugin : plugins) {
String pluginId = pluginManager.getPluginId(plugin); String pluginId = pluginManager.getPluginId(plugin);
List<P> dependingPlugins = pluginManager.getPluginsDependingOn(pluginId); List<P> dependingPlugins = pluginManager.getPluginsDependingOn(pluginId);
if (!dependingPlugins.isEmpty()) { if (!dependingPlugins.isEmpty()) {
TextComponent.Builder builder = Component.text(); if (!recursive) {
builder.append(messages.get(MessageKey.DEPENDING_PLUGINS_PREFIX).toComponent( TextComponent.Builder builder = Component.text();
Template.of("plugin", pluginId) builder.append(messages.get(MessageKey.DEPENDING_PLUGINS_PREFIX).toComponent(
)); Template.of("plugin", pluginId)
builder.append(ListComponentBuilder.create(dependingPlugins) ));
.format(p -> messages.get(MessageKey.DEPENDING_PLUGINS_FORMAT).toComponent( builder.append(ListComponentBuilder.create(dependingPlugins)
Template.of("plugin", pluginManager.getPluginId(p)) .format(p -> messages.get(MessageKey.DEPENDING_PLUGINS_FORMAT).toComponent(
)) Template.of("plugin", pluginManager.getPluginId(p))
.separator(messages.get(MessageKey.DEPENDING_PLUGINS_SEPARATOR).toComponent()) ))
.lastSeparator(messages.get(MessageKey.DEPENDING_PLUGINS_LAST_SEPARATOR).toComponent()) .separator(messages.get(MessageKey.DEPENDING_PLUGINS_SEPARATOR).toComponent())
.build()); .lastSeparator(messages.get(MessageKey.DEPENDING_PLUGINS_LAST_SEPARATOR).toComponent())
sender.sendMessage(builder.build()); .build());
sender.sendMessage(builder.build());
}
hasDependingPlugins = true; hasDependingPlugins = true;
dependingPluginsAll.addAll(dependingPlugins);
} }
} }
if (hasDependingPlugins) { if (!recursive && hasDependingPlugins) {
String flagPath = getRawPath(subcommand) + ".flags.force"; String forceFlagPath = getRawPath(subcommand) + ".flags.force";
String forceFlag = plugin.getCommandsResource().getAllFlagAliases(flagPath).stream() String forceFlag = plugin.getCommandsResource().getAllFlagAliases(forceFlagPath).stream()
.min(Comparator.comparingInt(String::length)) .min(Comparator.comparingInt(String::length))
.orElse("-f"); .orElse("-f");
String recursiveFlagPath = getRawPath(subcommand) + ".flags.recursive";
String rescuriveFlag = plugin.getCommandsResource().getAllFlagAliases(recursiveFlagPath).stream()
.min(Comparator.comparingInt(String::length))
.orElse("-r");
sender.sendMessage(messages.get(MessageKey.DEPENDING_PLUGINS_OVERRIDE).toComponent( sender.sendMessage(messages.get(MessageKey.DEPENDING_PLUGINS_OVERRIDE).toComponent(
Template.of("command", context.getRawInputJoined() + " " + forceFlag) Template.of("command", context.getRawInputJoined() + " " + forceFlag)
)); ));
sender.sendMessage(messages.get(MessageKey.DEPENDING_PLUGINS_RECURSIVELY).toComponent(
Template.of("command", context.getRawInputJoined() + " " + rescuriveFlag)
));
} }
return hasDependingPlugins; return dependingPluginsAll;
} }
protected boolean checkServerUtils(CommandContext<C> context, C sender, List<P> plugins) { protected boolean checkServerUtils(CommandContext<C> context, C sender, List<P> plugins) {

View file

@ -7,6 +7,7 @@ import cloud.commandframework.context.CommandContext;
import cloud.commandframework.exceptions.parsing.NoInputProvidedException; import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
import io.leangen.geantyref.TypeToken; import io.leangen.geantyref.TypeToken;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Queue; import java.util.Queue;
@ -64,7 +65,9 @@ public class PluginsArgument<C extends ServerUtilsAudience<?>, P> extends Comman
return ArgumentParseResult.failure(new NoInputProvidedException(PluginsParser.class, context)); return ArgumentParseResult.failure(new NoInputProvidedException(PluginsParser.class, context));
} }
Set<String> flags = plugin.getCommandsResource().getAllFlagAliases(commandConfigPath + ".flags.force"); Set<String> flags = new HashSet<>();
flags.addAll(plugin.getCommandsResource().getAllFlagAliases(commandConfigPath + ".flags.force"));
flags.addAll(plugin.getCommandsResource().getAllFlagAliases(commandConfigPath + ".flags.recursive"));
int queueSize = inputQueue.size(); int queueSize = inputQueue.size();
List<P> plugins = new ArrayList<>(queueSize); List<P> plugins = new ArrayList<>(queueSize);

View file

@ -6,7 +6,9 @@ public enum MessageKey implements PlaceholderConfigKey {
RELOAD("reload", false), RELOAD("reload", false),
LOADPLUGIN("loadplugin"), LOADPLUGIN("loadplugin"),
LOADPLUGIN_RECURSIVELY("loadplugin-recursively"),
UNLOADPLUGIN("unloadplugin"), UNLOADPLUGIN("unloadplugin"),
UNLOADPLUGIN_RECURSIVELY("unloadplugin-recursively"),
SERVERUTILS_UPDATER("serverutils-updater", false), SERVERUTILS_UPDATER("serverutils-updater", false),
RELOADPLUGIN_SUCCESS("reloadplugin.success"), RELOADPLUGIN_SUCCESS("reloadplugin.success"),
RELOADPLUGIN_SERVERUTILS("reloadplugin.serverutils"), RELOADPLUGIN_SERVERUTILS("reloadplugin.serverutils"),
@ -27,6 +29,7 @@ public enum MessageKey implements PlaceholderConfigKey {
DEPENDING_PLUGINS_SEPARATOR("depending-plugins.separator", false), DEPENDING_PLUGINS_SEPARATOR("depending-plugins.separator", false),
DEPENDING_PLUGINS_LAST_SEPARATOR("depending-plugins.last-separator", false), DEPENDING_PLUGINS_LAST_SEPARATOR("depending-plugins.last-separator", false),
DEPENDING_PLUGINS_OVERRIDE("depending-plugins.override"), DEPENDING_PLUGINS_OVERRIDE("depending-plugins.override"),
DEPENDING_PLUGINS_RECURSIVELY("depending-plugins.recursively"),
WATCHPLUGIN_START("watchplugin.start"), WATCHPLUGIN_START("watchplugin.start"),
WATCHPLUGIN_CHANGE("watchplugin.change", false), WATCHPLUGIN_CHANGE("watchplugin.change", false),
WATCHPLUGIN_STOPPED("watchplugin.stopped"), WATCHPLUGIN_STOPPED("watchplugin.stopped"),

View file

@ -37,6 +37,7 @@ public interface PluginProvider<P, D extends ServerUtilsPluginDescription> {
try { try {
pluginDescriptionOptional = getPluginDescription(file); pluginDescriptionOptional = getPluginDescription(file);
} catch (InvalidPluginDescriptionException ex) { } catch (InvalidPluginDescriptionException ex) {
ex.printStackTrace();
continue; continue;
} }
@ -57,6 +58,7 @@ public interface PluginProvider<P, D extends ServerUtilsPluginDescription> {
ServerUtilsPluginDescription description = getLoadedPluginDescription(loadedPlugin); ServerUtilsPluginDescription description = getLoadedPluginDescription(loadedPlugin);
if (description.getDependencies().contains(pluginId)) { if (description.getDependencies().contains(pluginId)) {
plugins.add(loadedPlugin); plugins.add(loadedPlugin);
plugins.addAll(getPluginsDependingOn(description.getId()));
} }
} }

View file

@ -34,7 +34,7 @@ public class UpdateCheckerTask<U extends ServerUtilsPlugin<P, ?, ?, ?, ?>, P> im
private final boolean download; private final boolean download;
private final boolean install; private final boolean install;
private static final String GITHUB_LINK = "https://api.github.com/repos/FrankHeijden/ServerUtils/releases/latest"; private static final String GITHUB_LINK = "https://git.zhira.net/api/v1/repos/zhdev/bukman/releases/latest";
private static final String GITHUB_UPDATER_LINK = "https://api.github.com/repos/FrankHeijden/ServerUtilsUpdater" private static final String GITHUB_UPDATER_LINK = "https://api.github.com/repos/FrankHeijden/ServerUtilsUpdater"
+ "/releases/latest"; + "/releases/latest";
@ -163,7 +163,7 @@ public class UpdateCheckerTask<U extends ServerUtilsPlugin<P, ?, ?, ?, ?>, P> im
if (sender.isPlayer()) { if (sender.isPlayer()) {
broadcastDownloadStatus(githubVersion, false); broadcastDownloadStatus(githubVersion, false);
} else { } else {
plugin.getLogger().log(Level.INFO, DOWNLOADED, new Object[]{ "ServerUtils", githubVersion }); plugin.getLogger().log(Level.INFO, DOWNLOADED, new Object[]{ "Bukman", githubVersion });
} }
return; return;
} }

View file

@ -73,6 +73,13 @@
"permission": "serverutils.unloadplugin", "permission": "serverutils.unloadplugin",
"description": "Force disable and unload the specified plugin(s).", "description": "Force disable and unload the specified plugin(s).",
"display-in-help": false "display-in-help": false
},
"recursive": {
"main": "recursive",
"aliases": ["r"],
"permission": "serverutils.unloadplugin",
"description": "Recursively disable and unload the specified plugin(s).",
"display-in-help": false
} }
} }
}, },
@ -89,6 +96,13 @@
"permission": "serverutils.reloadplugin", "permission": "serverutils.reloadplugin",
"description": "Force reloads the specified plugin(s).", "description": "Force reloads the specified plugin(s).",
"display-in-help": false "display-in-help": false
},
"recursive": {
"main": "recursive",
"aliases": ["r"],
"permission": "serverutils.reloadplugin",
"description": "Recursively reloads the specified plugin(s).",
"display-in-help": false
} }
} }
}, },

View file

@ -18,7 +18,9 @@
"reload": "<dark_aqua>Successfully reloaded <aqua>ServerUtils configurations</aqua>!", "reload": "<dark_aqua>Successfully reloaded <aqua>ServerUtils configurations</aqua>!",
"serverutils-updater": "<dark_aqua>Loaded and enabled ServerUtilsUpdater. Completion can be monitored from the console, attempting restart now...", "serverutils-updater": "<dark_aqua>Loaded and enabled ServerUtilsUpdater. Completion can be monitored from the console, attempting restart now...",
"loadplugin": "<dark_aqua>Successfully loaded <aqua><plugin></aqua>!", "loadplugin": "<dark_aqua>Successfully loaded <aqua><plugin></aqua>!",
"loadplugin-recursively": "<dark_aqua>Successfully recursively loaded <aqua><plugin></aqua>!",
"unloadplugin": "<dark_aqua>Successfully unloaded <aqua><plugin></aqua>!", "unloadplugin": "<dark_aqua>Successfully unloaded <aqua><plugin></aqua>!",
"unloadplugin-recursively": "<dark_aqua>Successfully recursively unloaded <aqua><plugin></aqua>!",
"reloadplugin": { "reloadplugin": {
"success": "<dark_aqua>Successfully reloaded <aqua><plugin></aqua>!", "success": "<dark_aqua>Successfully reloaded <aqua><plugin></aqua>!",
"serverutils": "<red>Sorry, but you can't reload ServerUtils this way. Please restart using <dark_red>/<command></dark_red>." "serverutils": "<red>Sorry, but you can't reload ServerUtils this way. Please restart using <dark_red>/<command></dark_red>."
@ -28,7 +30,8 @@
"format": "<dark_red><plugin>", "format": "<dark_red><plugin>",
"separator": "<red>, ", "separator": "<red>, ",
"last-separator": " <red>and ", "last-separator": " <red>and ",
"override": "<red>Use \"<dark_red>/<command></dark_red>\" to force command execution." "override": "<red>Use \"<dark_red>/<command></dark_red>\" to force command execution.",
"recursively": "<red>Use \"<dark_red>/<command></dark_red>\" to recursively command execution."
}, },
"watchplugin": { "watchplugin": {
"start": "<dark_aqua>Started watching <aqua><plugin></aqua>!", "start": "<dark_aqua>Started watching <aqua><plugin></aqua>!",

View file

@ -8,7 +8,7 @@ group = "${rootProject.group}"
val dependencyDir = "${group}.velocity.dependencies" val dependencyDir = "${group}.velocity.dependencies"
version = rootProject.version version = rootProject.version
base { base {
archivesName.set("${rootProject.name}-Velocity") archivesName.set("${rootProject.name}-velocity")
} }
repositories { repositories {
@ -17,7 +17,7 @@ repositories {
} }
dependencies { dependencies {
implementation("cloud.commandframework:cloud-velocity:${VersionConstants.cloudVersion}") implementation("org.zhdev.oblak:cloud-velocity:${VersionConstants.cloudVersion}")
implementation("org.bstats:bstats-velocity:${VersionConstants.bstatsVersion}") implementation("org.bstats:bstats-velocity:${VersionConstants.bstatsVersion}")
implementation(project(":Common")) implementation(project(":Common"))
implementation("net.kyori:adventure-text-minimessage:${VersionConstants.adventureMinimessageVersion}") { implementation("net.kyori:adventure-text-minimessage:${VersionConstants.adventureMinimessageVersion}") {

View file

@ -19,12 +19,12 @@ import org.bstats.velocity.Metrics;
import org.slf4j.Logger; import org.slf4j.Logger;
@Plugin( @Plugin(
id = "serverutils", id = "bukman",
name = "ServerUtils", name = "Bukman",
version = "{version}", version = "{version}",
description = "A server utility", description = "A server utility",
url = "https://github.com/FrankHeijden/ServerUtils", url = "https://git.zhira.net/zhdev/bukman",
authors = "FrankHeijden" authors = {"FrankHeijden", "ZhDev"}
) )
public class ServerUtils { public class ServerUtils {
@ -47,7 +47,7 @@ public class ServerUtils {
private Metrics.Factory metricsFactory; private Metrics.Factory metricsFactory;
@Inject @Inject
@Named("serverutils") @Named("bukman")
private PluginContainer pluginContainer; private PluginContainer pluginContainer;
private final VelocityPluginCommandManager pluginCommandManager; private final VelocityPluginCommandManager pluginCommandManager;

View file

@ -24,9 +24,16 @@ public class VelocityPluginDescription implements ServerUtilsPluginDescription {
this.description = description; this.description = description;
Optional<Path> sourceOptional = description.getSource(); Optional<Path> sourceOptional = description.getSource();
if (!sourceOptional.isPresent()) throw new InvalidPluginDescriptionException("Source path is null"); if (!sourceOptional.isPresent()) {
if (description.getId().equals("velocity")) {
this.file = null;
} else {
throw new InvalidPluginDescriptionException("Source path is null");
}
} else {
this.file = sourceOptional.get().toFile();
}
this.file = sourceOptional.get().toFile();
this.author = String.join(", ", description.getAuthors()); this.author = String.join(", ", description.getAuthors());
this.dependencies = description.getDependencies().stream() this.dependencies = description.getDependencies().stream()
.map(PluginDependency::getId) .map(PluginDependency::getId)

View file

@ -9,7 +9,6 @@ import dev.frankheijden.minecraftreflection.MinecraftReflection;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class RVelocityEventManager { public class RVelocityEventManager {
@ -65,7 +64,7 @@ public class RVelocityEventManager {
Object registrationsEmptyArray = Array.newInstance(RHandlerRegistration.reflection.getClazz(), 0); Object registrationsEmptyArray = Array.newInstance(RHandlerRegistration.reflection.getClazz(), 0);
Class<?> registrationsArrayClass = registrationsEmptyArray.getClass(); Class<?> registrationsArrayClass = registrationsEmptyArray.getClass();
ExecutorService executor = reflection.invoke(manager, "getAsyncExecutor"); /*ExecutorService executor = reflection.invoke(manager, "getAsyncExecutor");
executor.execute(() -> reflection.invoke( executor.execute(() -> reflection.invoke(
manager, manager,
"fire", "fire",
@ -74,7 +73,16 @@ public class RVelocityEventManager {
ClassObject.of(int.class, 0), ClassObject.of(int.class, 0),
ClassObject.of(boolean.class, true), ClassObject.of(boolean.class, true),
ClassObject.of(registrationsArrayClass, registrations.toArray((Object[]) registrationsEmptyArray)) ClassObject.of(registrationsArrayClass, registrations.toArray((Object[]) registrationsEmptyArray))
)); ));*/
reflection.invoke(
manager,
"fire",
ClassObject.of(CompletableFuture.class, future),
ClassObject.of(Object.class, event),
ClassObject.of(int.class, 0),
ClassObject.of(boolean.class, true),
ClassObject.of(registrationsArrayClass, registrations.toArray((Object[]) registrationsEmptyArray))
);
return future; return future;
} }

View file

@ -8,7 +8,7 @@ plugins {
group = "net.frankheijden.serverutils" group = "net.frankheijden.serverutils"
val dependencyDir = "${group}.dependencies" val dependencyDir = "${group}.dependencies"
version = "3.5.5-SNAPSHOT" version = "3.5.6-SNAPSHOT"
java { java {
sourceCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8
@ -27,17 +27,19 @@ subprojects {
} }
repositories { repositories {
mavenLocal()
mavenCentral() mavenCentral()
maven("https://jitpack.io") maven("https://jitpack.io")
maven("https://oss.sonatype.org/content/repositories/snapshots") maven("https://oss.sonatype.org/content/repositories/snapshots")
maven("https://papermc.io/repo/repository/maven-public/") maven("https://repo.papermc.io/repository/maven-public/")
maven("https://libraries.minecraft.net") maven("https://libraries.minecraft.net")
maven("https://maven.zhira.net/repository/zhdev/")
} }
dependencies { dependencies {
implementation("cloud.commandframework:cloud-core:${VersionConstants.cloudVersion}") implementation("org.zhdev.oblak:cloud-core:${VersionConstants.cloudVersion}")
implementation("cloud.commandframework:cloud-brigadier:${VersionConstants.cloudVersion}") implementation("org.zhdev.oblak:cloud-brigadier:${VersionConstants.cloudVersion}")
implementation("com.github.FrankHeijden:MinecraftReflection:1.0.0") implementation("org.zhdev:megareflection:1.0.2-SNAPSHOT")
implementation("com.google.code.gson:gson:2.8.6") implementation("com.google.code.gson:gson:2.8.6")
implementation("me.lucko:commodore:2.2") implementation("me.lucko:commodore:2.2")
compileOnly("com.mojang:brigadier:1.0.18") compileOnly("com.mojang:brigadier:1.0.18")
@ -93,6 +95,7 @@ subprojects {
} }
relocate("net.kyori.adventure.text.minimessage", "${dependencyDir}.adventure.text.minimessage") relocate("net.kyori.adventure.text.minimessage", "${dependencyDir}.adventure.text.minimessage")
relocate("dev.frankheijden.minecraftreflection", "${dependencyDir}.minecraftreflection") relocate("dev.frankheijden.minecraftreflection", "${dependencyDir}.minecraftreflection")
relocate("org.zhdev", "${dependencyDir}.zhdev")
} }
publishing { publishing {
@ -113,11 +116,11 @@ subprojects {
} }
publications { publications {
create<MavenPublication>("ServerUtils") { create<MavenPublication>("bukman") {
artifact(tasks["shadowJar"]) { artifact(tasks["shadowJar"]) {
classifier = "" classifier = ""
} }
artifactId = "ServerUtils-$artifactId" artifactId = "bukman-$artifactId"
} }
} }
} }
@ -192,11 +195,11 @@ publishing {
} }
publications { publications {
create<MavenPublication>("ServerUtils") { create<MavenPublication>("bukman") {
artifact(tasks["shadowJar"]) { artifact(tasks["shadowJar"]) {
classifier = "" classifier = ""
} }
artifactId = "ServerUtils" artifactId = "bukman"
} }
} }
} }

View file

@ -1,5 +1,5 @@
object VersionConstants { object VersionConstants {
const val cloudVersion = "1.8.0" const val cloudVersion = "1.8.5-SNAPSHOT"
const val adventureVersion = "4.11.0" const val adventureVersion = "4.11.0"
const val adventurePlatformVersion = "4.1.2" const val adventurePlatformVersion = "4.1.2"
const val adventureMinimessageVersion = "4.2.0-SNAPSHOT" const val adventureMinimessageVersion = "4.2.0-SNAPSHOT"

View file

@ -1,4 +1,4 @@
rootProject.name = "ServerUtils" rootProject.name = "bukman"
include("Common") include("Common")
include("Bukkit") include("Bukkit")
include("Bungee") include("Bungee")