More refactoring

This commit is contained in:
2026-05-19 21:50:32 -04:00
parent d333027a03
commit 758683b824
19 changed files with 119 additions and 132 deletions
+18 -72
View File
@@ -1,8 +1,5 @@
package dev.plex.extras;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.ClassPath;
import dev.plex.api.PlexApi;
import dev.plex.config.ModuleConfig;
import dev.plex.extras.command.AdminInfoCommand;
import dev.plex.extras.command.AutoClearCommand;
@@ -20,14 +17,12 @@ import dev.plex.extras.command.JumpPadsCommand;
import dev.plex.extras.command.OrbitCommand;
import dev.plex.extras.command.RandomFishCommand;
import dev.plex.extras.jumppads.JumpPads;
import dev.plex.listener.PlexListener;
import dev.plex.extras.listener.ClownfishListener;
import dev.plex.extras.listener.JumpPadsListener;
import dev.plex.extras.listener.OrbitEffectListener;
import dev.plex.extras.listener.PlayerListener;
import dev.plex.module.PlexModule;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import lombok.Getter;
import org.bukkit.Location;
@@ -36,65 +31,47 @@ import org.bukkit.World;
public class TFMExtras extends PlexModule
{
@Getter
private static TFMExtras module;
public JumpPads jumpPads;
private JumpPads jumpPads;
@Getter
private ModuleConfig config;
public static PlexApi plexApi()
{
return module.api();
}
@Override
public void load()
{
module = this;
config = new ModuleConfig(this, "tfmextras/config.yml", "config.yml");
config.load();
loadMessages("tfmextras/messages.yml");
jumpPads = new JumpPads();
jumpPads = new JumpPads(config.getInt("server.jumppad_strength", 1));
}
@Override
public void enable()
{
List.of(
new AdminInfoCommand(),
new AutoClearCommand(),
new AutoTeleportCommand(),
new AdminInfoCommand(this),
new AutoClearCommand(this),
new AutoTeleportCommand(this),
new CakeCommand(),
new CartSitCommand(),
new ClearChatCommand(),
new ClownfishCommand(),
new ClownfishCommand(this),
new CloudClearCommand(),
new EjectCommand(),
new EnchantCommand(),
new EnglishMfCommand(),
new ExpelCommand(),
new JumpPadsCommand(),
new JumpPadsCommand(this),
new OrbitCommand(),
new RandomFishCommand()
).forEach(this::registerCommand);
getClassesFrom("dev.plex.extras.listener").forEach(aClass ->
{
if (PlexListener.class.isAssignableFrom(aClass))
{
try
{
PlexListener plexListener = (PlexListener)aClass.getConstructors()[0].newInstance();
registerListener(plexListener);
}
catch (InstantiationException | IllegalAccessException | InvocationTargetException e)
{
throw new RuntimeException(e);
}
}
});
List.of(
new ClownfishListener(this),
new JumpPadsListener(this),
new OrbitEffectListener(this),
new PlayerListener(this)
).forEach(this::registerListener);
}
@Override
@@ -103,42 +80,11 @@ public class TFMExtras extends PlexModule
// Unregistering listeners / commands is handled by Plex
}
public static Location getRandomLocation(World world)
public Location getRandomLocation(World world)
{
double x = ThreadLocalRandom.current().nextDouble(-100000, 100000);
double z = ThreadLocalRandom.current().nextDouble(-100000, 100000);
double y = world.getHighestBlockYAt((int)x, (int)z) + 1;
return new Location(world, x, y, z);
}
private Set<Class<?>> getClassesFrom(String packageName)
{
Set<Class<?>> classes = new HashSet<>();
try
{
ClassPath path = ClassPath.from(TFMExtras.class.getClassLoader());
ImmutableSet<ClassPath.ClassInfo> infoSet = path.getTopLevelClasses(packageName);
infoSet.forEach((info) ->
{
try
{
Class<?> clazz = Class.forName(info.getName());
classes.add(clazz);
}
catch (ClassNotFoundException var4)
{
plexApi().logging().error("Unable to find class {0} in {1}", info.getName(), packageName);
}
});
}
catch (IOException var4)
{
plexApi().logging().error("Something went wrong while fetching classes from {0}", packageName);
throw new RuntimeException(var4);
}
return Collections.unmodifiableSet(classes);
}
}