Skip to content

Commit

Permalink
cleanup reflections
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 6, 2025
1 parent 035c0a4 commit 3e26065
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 338 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import de.tr7zw.changeme.nbtapi.NBT;
import me.xginko.aef.commands.AEFCommand;
import me.xginko.aef.commands.CommandReflections;
import me.xginko.aef.config.Config;
import me.xginko.aef.config.LanguageCache;
import me.xginko.aef.modules.AEFModule;
Expand Down Expand Up @@ -54,22 +55,25 @@ public final class AnarchyExploitFixes extends JavaPlugin {

@Override
public void onLoad() {
prefixedLogger = ComponentLogger.logger(getLogger().getName());
unPrefixedLogger = ComponentLogger.logger("");
PlatformUtil.load();
CommandReflections.load(prefixedLogger);
if (CommandReflections.isBroken()) {
prefixedLogger.warn("Command reflections couldn't initialize. You won't be able to cleanly update the plugin without a server restart.");
}
// Disable info logging for Reflections because it does not provide additional value to the user and makes startup log look ugly.
Configurator.setLevel(AnarchyExploitFixes.class.getPackage().getName() + ".libs.reflections.Reflections", Level.WARN);
}

@Override
public void onEnable() {
if (!PlatformUtil.isPaper()) {
getLogger().severe("This plugin depends on Paper's API, which is not present on your server.");
prefixedLogger.error("This plugin depends on Paper's API, which is not present on your server.");
getServer().getPluginManager().disablePlugin(this);
return;
}

prefixedLogger = ComponentLogger.logger(getLogger().getName());
unPrefixedLogger = ComponentLogger.logger("");

isPacketEventsInstalled = getServer().getPluginManager().getPlugin("packetevents") != null;
if (!isPacketEventsInstalled) {
Stream.of(" ",
Expand Down Expand Up @@ -104,8 +108,7 @@ public void onEnable() {
ServerVersion serverVersion = PacketEvents.getAPI().getServerManager().getVersion();
prefixedLogger.info("Detected {} {}", PlatformUtil.getServerType().niceName(),
serverVersion.name().replace("V_", "").replace('_', '.'));
if (serverVersion.isOlderThanOrEquals(ServerVersion.V_1_19_3) ||
serverVersion.equals(ServerVersion.V_1_19_4) && !PlatformUtil.isFolia()) {
if (serverVersion.isOlderThan(ServerVersion.V_1_19_4) || (serverVersion.equals(ServerVersion.V_1_19_4) && !PlatformUtil.isFolia())) {
prefixedLogger.error("This plugin jar is incompatible with your Server. Please use the Legacy jar.");
getServer().getPluginManager().disablePlugin(this);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ public void disable() {
for (Map.Entry<String, Command> entry : knownCommands.entrySet()) {
if (entry.getValue() == this) {
entry.getValue().unregister(plugin.getServer().getCommandMap());
BukkitCommandWrap.getInstance().unwrap(entry.getKey());
CommandReflections.unwrap(entry.getKey());
knownCommands.remove(entry.getKey());
}
}
BukkitCommandWrap.getInstance().setKnownCommands(knownCommands);
BukkitCommandWrap.getInstance().sync();
CommandReflections.setKnownCommands(knownCommands);
CommandReflections.sync();
}

public static void disableAll() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import de.tr7zw.changeme.nbtapi.NBT;
import me.xginko.aef.commands.AEFCommand;
import me.xginko.aef.commands.CommandReflections;
import me.xginko.aef.config.Config;
import me.xginko.aef.config.Datastore;
import me.xginko.aef.config.LanguageCache;
Expand Down Expand Up @@ -54,28 +55,31 @@ public final class AnarchyExploitFixes extends JavaPlugin {

@Override
public void onLoad() {
prefixedLogger = LoggerFactory.getLogger(getLogger().getName());
unPrefixedLogger = LoggerFactory.getLogger("");
PlatformUtil.load();
CommandReflections.load(prefixedLogger);
if (CommandReflections.isBroken()) {
prefixedLogger.warn("Command reflections couldn't initialize. You won't be able to cleanly update the plugin without a server restart.");
}
// Disable info logging for Reflections because it does not provide additional value to the user and makes startup log look ugly.
Configurator.setLevel(AnarchyExploitFixes.class.getPackage().getName() + ".libs.reflections.Reflections", Level.WARN);
}

@Override
public void onEnable() {
if (!PlatformUtil.isPaper()) {
getLogger().severe("This plugin depends on Paper's API, which is not present on your server.");
prefixedLogger.error("This plugin depends on Paper's API, which is not present on your server.");
getServer().getPluginManager().disablePlugin(this);
return;
}

if (PlatformUtil.isFolia()) {
getLogger().severe("Please use the Folia jar instead of modifying the plugin.yml.");
prefixedLogger.error("Please use the Folia jar instead of modifying the plugin.yml.");
getServer().getPluginManager().disablePlugin(this);
return;
}

prefixedLogger = LoggerFactory.getLogger(getLogger().getName());
unPrefixedLogger = LoggerFactory.getLogger("");

isPacketEventsInstalled = getServer().getPluginManager().getPlugin("packetevents") != null;
if (!isPacketEventsInstalled) {
Stream.of(" ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ public void disable() {
for (Map.Entry<String, Command> entry : knownCommands.entrySet()) {
if (entry.getValue() == this) {
entry.getValue().unregister(plugin.getServer().getCommandMap());
BukkitCommandWrap.getInstance().unwrap(entry.getKey());
CommandReflections.unwrap(entry.getKey());
knownCommands.remove(entry.getKey());
}
}
BukkitCommandWrap.getInstance().setKnownCommands(knownCommands);
BukkitCommandWrap.getInstance().sync();
CommandReflections.setKnownCommands(knownCommands);
CommandReflections.sync();
}

public static void disableAll() {
Expand Down
Loading

0 comments on commit 3e26065

Please sign in to comment.