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; 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.config.ModuleConfig;
import dev.plex.extras.command.AdminInfoCommand; import dev.plex.extras.command.AdminInfoCommand;
import dev.plex.extras.command.AutoClearCommand; 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.OrbitCommand;
import dev.plex.extras.command.RandomFishCommand; import dev.plex.extras.command.RandomFishCommand;
import dev.plex.extras.jumppads.JumpPads; 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 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.List;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Location; import org.bukkit.Location;
@@ -36,65 +31,47 @@ import org.bukkit.World;
public class TFMExtras extends PlexModule public class TFMExtras extends PlexModule
{ {
@Getter @Getter
private static TFMExtras module; private JumpPads jumpPads;
public JumpPads jumpPads;
@Getter @Getter
private ModuleConfig config; private ModuleConfig config;
public static PlexApi plexApi()
{
return module.api();
}
@Override @Override
public void load() public void load()
{ {
module = this;
config = new ModuleConfig(this, "tfmextras/config.yml", "config.yml"); config = new ModuleConfig(this, "tfmextras/config.yml", "config.yml");
config.load(); config.load();
loadMessages("tfmextras/messages.yml"); loadMessages("tfmextras/messages.yml");
jumpPads = new JumpPads(); jumpPads = new JumpPads(config.getInt("server.jumppad_strength", 1));
} }
@Override @Override
public void enable() public void enable()
{ {
List.of( List.of(
new AdminInfoCommand(), new AdminInfoCommand(this),
new AutoClearCommand(), new AutoClearCommand(this),
new AutoTeleportCommand(), new AutoTeleportCommand(this),
new CakeCommand(), new CakeCommand(),
new CartSitCommand(), new CartSitCommand(),
new ClearChatCommand(), new ClearChatCommand(),
new ClownfishCommand(), new ClownfishCommand(this),
new CloudClearCommand(), new CloudClearCommand(),
new EjectCommand(), new EjectCommand(),
new EnchantCommand(), new EnchantCommand(),
new EnglishMfCommand(), new EnglishMfCommand(),
new ExpelCommand(), new ExpelCommand(),
new JumpPadsCommand(), new JumpPadsCommand(this),
new OrbitCommand(), new OrbitCommand(),
new RandomFishCommand() new RandomFishCommand()
).forEach(this::registerCommand); ).forEach(this::registerCommand);
getClassesFrom("dev.plex.extras.listener").forEach(aClass -> List.of(
{ new ClownfishListener(this),
if (PlexListener.class.isAssignableFrom(aClass)) new JumpPadsListener(this),
{ new OrbitEffectListener(this),
try new PlayerListener(this)
{ ).forEach(this::registerListener);
PlexListener plexListener = (PlexListener)aClass.getConstructors()[0].newInstance();
registerListener(plexListener);
}
catch (InstantiationException | IllegalAccessException | InvocationTargetException e)
{
throw new RuntimeException(e);
}
}
});
} }
@Override @Override
@@ -103,42 +80,11 @@ public class TFMExtras extends PlexModule
// Unregistering listeners / commands is handled by Plex // 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 x = ThreadLocalRandom.current().nextDouble(-100000, 100000);
double z = ThreadLocalRandom.current().nextDouble(-100000, 100000); double z = ThreadLocalRandom.current().nextDouble(-100000, 100000);
double y = world.getHighestBlockYAt((int)x, (int)z) + 1; double y = world.getHighestBlockYAt((int)x, (int)z) + 1;
return new Location(world, x, y, z); 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);
}
} }
@@ -13,25 +13,28 @@ import org.jetbrains.annotations.Nullable;
public class AdminInfoCommand extends SimplePlexCommand public class AdminInfoCommand extends SimplePlexCommand
{ {
public AdminInfoCommand() private final TFMExtras module;
public AdminInfoCommand(TFMExtras module)
{ {
super(command("admininfo") super(command("admininfo")
.description("Information on how to apply for admin") .description("Information on how to apply for admin")
.aliases("ai,si,staffinfo") .aliases("ai,si,staffinfo")
.permission("plex.tfmextras.admininfo") .permission("plex.tfmextras.admininfo")
.build()); .build());
this.module = module;
} }
private static final List<Component> ADMIN_INFO = TFMExtras.getModule().getConfig().getStringList("server.admininfo")
.stream().map(info -> MiniMessage.miniMessage().deserialize(info)).toList();
@Override @Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args) protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
{ {
if (ADMIN_INFO.isEmpty()) List<Component> adminInfo = module.getConfig().getStringList("server.admininfo")
.stream().map(info -> MiniMessage.miniMessage().deserialize(info)).toList();
if (adminInfo.isEmpty())
{ {
return messageComponent("emptyAdminInfo"); return messageComponent("emptyAdminInfo");
} }
ADMIN_INFO.forEach(component -> send(sender, component)); adminInfo.forEach(component -> send(sender, component));
return null; return null;
} }
@@ -14,7 +14,9 @@ import org.jetbrains.annotations.Nullable;
public class AutoClearCommand extends SimplePlexCommand public class AutoClearCommand extends SimplePlexCommand
{ {
public AutoClearCommand() private final TFMExtras module;
public AutoClearCommand(TFMExtras module)
{ {
super(command("autoclear") super(command("autoclear")
.description("Toggle whether or not a player has their inventory automatically cleared when they join") .description("Toggle whether or not a player has their inventory automatically cleared when they join")
@@ -22,7 +24,9 @@ public class AutoClearCommand extends SimplePlexCommand
.aliases("aclear,ac") .aliases("aclear,ac")
.permission("plex.tfmextras.autoclear") .permission("plex.tfmextras.autoclear")
.build()); .build());
this.module = module;
} }
@Override @Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args) protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
{ {
@@ -30,8 +34,8 @@ public class AutoClearCommand extends SimplePlexCommand
{ {
return usage(); return usage();
} }
PlexPlayerView target = TFMExtras.plexApi().players().byName(args[0]).orElseThrow(PlayerNotFoundException::new); PlexPlayerView target = api().players().byName(args[0]).orElseThrow(PlayerNotFoundException::new);
List<String> names = TFMExtras.getModule().getConfig().getStringList("server.clear-on-join"); List<String> names = module.getConfig().getStringList("server.clear-on-join");
boolean isEnabled = names.contains(target.name()); boolean isEnabled = names.contains(target.name());
if (!isEnabled) if (!isEnabled)
{ {
@@ -41,8 +45,8 @@ public class AutoClearCommand extends SimplePlexCommand
{ {
names.remove(target.name()); names.remove(target.name());
} }
TFMExtras.getModule().getConfig().set("server.clear-on-join", names); module.getConfig().set("server.clear-on-join", names);
TFMExtras.getModule().getConfig().save(); module.getConfig().save();
isEnabled = !isEnabled; isEnabled = !isEnabled;
return messageComponent("modifiedAutoClear", target.name(), isEnabled ? "now" : "no longer"); return messageComponent("modifiedAutoClear", target.name(), isEnabled ? "now" : "no longer");
} }
@@ -15,7 +15,9 @@ import org.jetbrains.annotations.Nullable;
public class AutoTeleportCommand extends SimplePlexCommand public class AutoTeleportCommand extends SimplePlexCommand
{ {
public AutoTeleportCommand() private final TFMExtras module;
public AutoTeleportCommand(TFMExtras module)
{ {
super(command("autoteleport") super(command("autoteleport")
.description("If a player is specified, it will toggle whether or not the player is automatically teleported when they join. If no player is specified, you will be randomly teleported") .description("If a player is specified, it will toggle whether or not the player is automatically teleported when they join. If no player is specified, you will be randomly teleported")
@@ -23,7 +25,9 @@ public class AutoTeleportCommand extends SimplePlexCommand
.aliases("autotp,rtp,randomtp,tpr") .aliases("autotp,rtp,randomtp,tpr")
.permission("plex.tfmextras.autotp") .permission("plex.tfmextras.autotp")
.build()); .build());
this.module = module;
} }
@Override @Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args) protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
{ {
@@ -33,12 +37,12 @@ public class AutoTeleportCommand extends SimplePlexCommand
{ {
return usage(); return usage();
} }
TFMExtras.plexApi().scheduler().runEntity(player, () -> player.teleportAsync(TFMExtras.getRandomLocation(player.getWorld()))); api().scheduler().runEntity(player, () -> player.teleportAsync(module.getRandomLocation(player.getWorld())));
return null; return null;
} }
checkPermission(sender, "plex.tfmextras.autotp.other"); checkPermission(sender, "plex.tfmextras.autotp.other");
PlexPlayerView target = TFMExtras.plexApi().players().byName(args[0]).orElseThrow(PlayerNotFoundException::new); PlexPlayerView target = api().players().byName(args[0]).orElseThrow(PlayerNotFoundException::new);
List<String> names = TFMExtras.getModule().getConfig().getStringList("server.teleport-on-join"); List<String> names = module.getConfig().getStringList("server.teleport-on-join");
boolean isEnabled = names.contains(target.name()); boolean isEnabled = names.contains(target.name());
if (!isEnabled) if (!isEnabled)
{ {
@@ -48,8 +52,8 @@ public class AutoTeleportCommand extends SimplePlexCommand
{ {
names.remove(target.name()); names.remove(target.name());
} }
TFMExtras.getModule().getConfig().set("server.teleport-on-join", names); module.getConfig().set("server.teleport-on-join", names);
TFMExtras.getModule().getConfig().save(); module.getConfig().save();
isEnabled = !isEnabled; isEnabled = !isEnabled;
return messageComponent("modifiedAutoTeleport", target.name(), isEnabled ? "now" : "no longer"); return messageComponent("modifiedAutoTeleport", target.name(), isEnabled ? "now" : "no longer");
} }
@@ -1,7 +1,6 @@
package dev.plex.extras.command; package dev.plex.extras.command;
import dev.plex.command.SimplePlexCommand; import dev.plex.command.SimplePlexCommand;
import dev.plex.extras.TFMExtras;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@@ -29,7 +28,7 @@ public class CakeCommand extends SimplePlexCommand
@Override @Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args) protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
{ {
Bukkit.getOnlinePlayers().forEach(p -> TFMExtras.plexApi().scheduler().runEntity(p, () -> p.getInventory().addItem(CAKE.clone()))); Bukkit.getOnlinePlayers().forEach(p -> api().scheduler().runEntity(p, () -> p.getInventory().addItem(CAKE.clone())));
broadcast(messageComponent("cakeLyrics")); broadcast(messageComponent("cakeLyrics"));
return null; return null;
} }
@@ -2,7 +2,6 @@ package dev.plex.extras.command;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import dev.plex.command.SimplePlexCommand; import dev.plex.command.SimplePlexCommand;
import dev.plex.extras.TFMExtras;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -46,7 +45,7 @@ public class CartSitCommand extends SimplePlexCommand
return MiniMessage.miniMessage().deserialize("<red>Could not find a nearby minecart!"); return MiniMessage.miniMessage().deserialize("<red>Could not find a nearby minecart!");
} }
Entity entity = findNearestEntity(player, minecart); Entity entity = findNearestEntity(player, minecart);
TFMExtras.plexApi().scheduler().runEntity(entity, () -> entity.addPassenger(player)); api().scheduler().runEntity(entity, () -> entity.addPassenger(player));
return null; return null;
} }
Player target = getNonNullPlayer(args[0]); Player target = getNonNullPlayer(args[0]);
@@ -60,7 +59,7 @@ public class CartSitCommand extends SimplePlexCommand
return MiniMessage.miniMessage().deserialize("<red>Could not find a nearby minecart near " + target.getName() + "!"); return MiniMessage.miniMessage().deserialize("<red>Could not find a nearby minecart near " + target.getName() + "!");
} }
Entity entity = findNearestEntity(target, minecart); Entity entity = findNearestEntity(target, minecart);
TFMExtras.plexApi().scheduler().runEntity(entity, () -> entity.addPassenger(target)); api().scheduler().runEntity(entity, () -> entity.addPassenger(target));
return null; return null;
} }
@@ -1,7 +1,6 @@
package dev.plex.extras.command; package dev.plex.extras.command;
import dev.plex.command.SimplePlexCommand; import dev.plex.command.SimplePlexCommand;
import dev.plex.extras.TFMExtras;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@@ -27,7 +26,7 @@ public class ClearChatCommand extends SimplePlexCommand
Bukkit.getOnlinePlayers().stream().filter(p -> !silentCheckPermission(p, "plex.tfmextras.clearchat")) Bukkit.getOnlinePlayers().stream().filter(p -> !silentCheckPermission(p, "plex.tfmextras.clearchat"))
.forEach(p -> .forEach(p ->
{ {
TFMExtras.plexApi().scheduler().runEntity(p, () -> api().scheduler().runEntity(p, () ->
{ {
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
{ {
@@ -1,7 +1,6 @@
package dev.plex.extras.command; package dev.plex.extras.command;
import dev.plex.command.SimplePlexCommand; import dev.plex.command.SimplePlexCommand;
import dev.plex.extras.TFMExtras;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@@ -33,7 +32,7 @@ public class CloudClearCommand extends SimplePlexCommand
Bukkit.getWorlds().stream().map(World::getEntities).flatMap(Collection::stream).filter(entity -> entity.getType() == EntityType.AREA_EFFECT_CLOUD).forEach(entity -> Bukkit.getWorlds().stream().map(World::getEntities).flatMap(Collection::stream).filter(entity -> entity.getType() == EntityType.AREA_EFFECT_CLOUD).forEach(entity ->
{ {
removed.incrementAndGet(); removed.incrementAndGet();
TFMExtras.plexApi().scheduler().runEntity(entity, entity::remove); api().scheduler().runEntity(entity, entity::remove);
}); });
broadcast(messageComponent("areaEffectCloudClear", sender.getName())); broadcast(messageComponent("areaEffectCloudClear", sender.getName()));
return MiniMessage.miniMessage().deserialize("<gray>" + removed.get() + " area effect clouds removed."); return MiniMessage.miniMessage().deserialize("<gray>" + removed.get() + " area effect clouds removed.");
@@ -20,14 +20,18 @@ import java.util.List;
public class ClownfishCommand extends SimplePlexCommand public class ClownfishCommand extends SimplePlexCommand
{ {
public ClownfishCommand() private final TFMExtras module;
public ClownfishCommand(TFMExtras module)
{ {
super(command("clownfish") super(command("clownfish")
.description("Gives a player a clownfish capable of knocking people back") .description("Gives a player a clownfish capable of knocking people back")
.usage("/<command> [<toggle>]") .usage("/<command> [<toggle>]")
.permission("plex.tfmextras.clownfish") .permission("plex.tfmextras.clownfish")
.build()); .build());
this.module = module;
} }
@Override @Override
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args) protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args)
{ {
@@ -39,12 +43,12 @@ public class ClownfishCommand extends SimplePlexCommand
meta.displayName(Component.text("Clownfish")); meta.displayName(Component.text("Clownfish"));
clownfish.setItemMeta(meta); clownfish.setItemMeta(meta);
TFMExtras.plexApi().scheduler().runEntity(player, () -> player.getInventory().addItem(clownfish)); api().scheduler().runEntity(player, () -> player.getInventory().addItem(clownfish));
return MiniMessage.miniMessage().deserialize("<rainbow>blub blub... ><_>"); return MiniMessage.miniMessage().deserialize("<rainbow>blub blub... ><_>");
} }
else if (args[0].equals("toggle")) else if (args[0].equals("toggle"))
{ {
List<String> toggledPlayers = TFMExtras.getModule().getConfig().getStringList("server.clownfish.toggled_players"); List<String> toggledPlayers = module.getConfig().getStringList("server.clownfish.toggled_players");
boolean isToggled = toggledPlayers.contains(player.getUniqueId().toString()); boolean isToggled = toggledPlayers.contains(player.getUniqueId().toString());
if (isToggled) if (isToggled)
@@ -56,8 +60,8 @@ public class ClownfishCommand extends SimplePlexCommand
toggledPlayers.add(player.getUniqueId().toString()); toggledPlayers.add(player.getUniqueId().toString());
} }
TFMExtras.getModule().getConfig().set("server.clownfish.toggled_players", toggledPlayers); module.getConfig().set("server.clownfish.toggled_players", toggledPlayers);
TFMExtras.getModule().getConfig().save(); module.getConfig().save();
return messageComponent("toggleClownfish", isToggled ? "now" : "no longer"); return messageComponent("toggleClownfish", isToggled ? "now" : "no longer");
} }
@@ -65,9 +69,9 @@ public class ClownfishCommand extends SimplePlexCommand
{ {
if (silentCheckPermission(commandSender, "plex.tfmextras.clownfish.restrict")) if (silentCheckPermission(commandSender, "plex.tfmextras.clownfish.restrict"))
{ {
PlexPlayerView target = TFMExtras.plexApi().players().byName(args[1]).orElseThrow(PlayerNotFoundException::new); PlexPlayerView target = api().players().byName(args[1]).orElseThrow(PlayerNotFoundException::new);
List<String> restrictedPlayers = TFMExtras.getModule().getConfig().getStringList("server.clownfish.restricted"); List<String> restrictedPlayers = module.getConfig().getStringList("server.clownfish.restricted");
boolean isRestricted = restrictedPlayers.contains(target.uuid().toString()); boolean isRestricted = restrictedPlayers.contains(target.uuid().toString());
if (isRestricted) if (isRestricted)
@@ -79,8 +83,8 @@ public class ClownfishCommand extends SimplePlexCommand
restrictedPlayers.add(target.uuid().toString()); restrictedPlayers.add(target.uuid().toString());
} }
TFMExtras.getModule().getConfig().set("server.clownfish.restricted", restrictedPlayers); module.getConfig().set("server.clownfish.restricted", restrictedPlayers);
TFMExtras.getModule().getConfig().save(); module.getConfig().save();
return messageComponent("restrictClownfish", target.name(), isRestricted ? "now" : "no longer"); return messageComponent("restrictClownfish", target.name(), isRestricted ? "now" : "no longer");
} }
@@ -2,7 +2,6 @@ package dev.plex.extras.command;
import dev.plex.command.SimplePlexCommand; import dev.plex.command.SimplePlexCommand;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.extras.TFMExtras;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@@ -26,7 +25,7 @@ public class EjectCommand extends SimplePlexCommand
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args) protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
{ {
final int passengers = player.getPassengers().size(); final int passengers = player.getPassengers().size();
TFMExtras.plexApi().scheduler().runEntity(player, player::eject); api().scheduler().runEntity(player, player::eject);
return MiniMessage.miniMessage().deserialize("<gray>Ejected " + passengers + " passengers."); return MiniMessage.miniMessage().deserialize("<gray>Ejected " + passengers + " passengers.");
} }
@@ -2,7 +2,6 @@ package dev.plex.extras.command;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import dev.plex.command.SimplePlexCommand; import dev.plex.command.SimplePlexCommand;
import dev.plex.extras.TFMExtras;
import java.util.List; import java.util.List;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -33,7 +32,7 @@ public class EnglishMfCommand extends SimplePlexCommand
return usage(); return usage();
} }
Player target = getNonNullPlayer(args[0]); Player target = getNonNullPlayer(args[0]);
TFMExtras.plexApi().scheduler().runEntity(target, () -> api().scheduler().runEntity(target, () ->
{ {
target.sendMessage(mmString("<red>ENGLISH MOTHERFUCKER, Do you speak it!?")); target.sendMessage(mmString("<red>ENGLISH MOTHERFUCKER, Do you speak it!?"));
target.setHealth(0); target.setHealth(0);
@@ -18,7 +18,9 @@ import org.jetbrains.annotations.Nullable;
public class JumpPadsCommand extends SimplePlexCommand public class JumpPadsCommand extends SimplePlexCommand
{ {
public JumpPadsCommand() private final JumpPads jumpPads;
public JumpPadsCommand(TFMExtras module)
{ {
super(command("jumppads") super(command("jumppads")
.description("Enables jump pads for yourself or another player. Mode types available: none, regular, enhanced, extreme") .description("Enables jump pads for yourself or another player. Mode types available: none, regular, enhanced, extreme")
@@ -26,8 +28,8 @@ public class JumpPadsCommand extends SimplePlexCommand
.aliases("jp,pads,launchpads") .aliases("jp,pads,launchpads")
.permission("plex.tfmextras.jumppads") .permission("plex.tfmextras.jumppads")
.build()); .build());
this.jumpPads = module.getJumpPads();
} }
JumpPads jumpPads = TFMExtras.getModule().jumpPads;
@Override @Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args) protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
@@ -2,7 +2,6 @@ package dev.plex.extras.command;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import dev.plex.command.SimplePlexCommand; import dev.plex.command.SimplePlexCommand;
import dev.plex.extras.TFMExtras;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -85,7 +84,7 @@ public class OrbitCommand extends SimplePlexCommand
private void startOrbiting(Player player, int strength) private void startOrbiting(Player player, int strength)
{ {
TFMExtras.plexApi().scheduler().runEntity(player, () -> api().scheduler().runEntity(player, () ->
{ {
player.setGameMode(org.bukkit.GameMode.SURVIVAL); player.setGameMode(org.bukkit.GameMode.SURVIVAL);
player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, Integer.MAX_VALUE, strength, false, false)); player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, Integer.MAX_VALUE, strength, false, false));
@@ -96,7 +95,7 @@ public class OrbitCommand extends SimplePlexCommand
private void stopOrbiting(Player player) private void stopOrbiting(Player player)
{ {
isOrbited.remove(player.getUniqueId()); isOrbited.remove(player.getUniqueId());
TFMExtras.plexApi().scheduler().runEntity(player, () -> player.removePotionEffect(PotionEffectType.LEVITATION)); api().scheduler().runEntity(player, () -> player.removePotionEffect(PotionEffectType.LEVITATION));
} }
public static boolean isPlayerOrbited(UUID playerId) public static boolean isPlayerOrbited(UUID playerId)
@@ -2,7 +2,6 @@ package dev.plex.extras.command;
import dev.plex.command.SimplePlexCommand; import dev.plex.command.SimplePlexCommand;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.extras.TFMExtras;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@@ -39,7 +38,7 @@ public class RandomFishCommand extends SimplePlexCommand
return MiniMessage.miniMessage().deserialize("<red>There is no block within 15 blocks of you."); return MiniMessage.miniMessage().deserialize("<red>There is no block within 15 blocks of you.");
} }
Location location = block.getLocation().add(0, 1, 0); Location location = block.getLocation().add(0, 1, 0);
TFMExtras.plexApi().scheduler().runRegion(location, () -> location.getWorld().spawnEntity(location, randomFish())); api().scheduler().runRegion(location, () -> location.getWorld().spawnEntity(location, randomFish()));
return MiniMessage.miniMessage().deserialize(":goodbird:"); return MiniMessage.miniMessage().deserialize(":goodbird:");
} }
@@ -1,6 +1,5 @@
package dev.plex.extras.jumppads; package dev.plex.extras.jumppads;
import dev.plex.extras.TFMExtras;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@@ -17,10 +16,16 @@ public class JumpPads
{ {
public final Map<UUID, Mode> playerModeMap = new ConcurrentHashMap<>(); public final Map<UUID, Mode> playerModeMap = new ConcurrentHashMap<>();
public final double SCALAR = 0.8; public final double SCALAR = 0.8;
public final double STRENGTH = TFMExtras.getModule().getConfig().getInt("server.jumppad_strength", 1) + 0.1F; public final double STRENGTH;
public final double EXTREME = STRENGTH + 0.5; public final double EXTREME;
public final Tag<Material> wool = Tag.WOOL; public final Tag<Material> wool = Tag.WOOL;
public JumpPads(double strength)
{
STRENGTH = strength + 0.1F;
EXTREME = STRENGTH + 0.5;
}
public Vector extreme(Vector vector) public Vector extreme(Vector vector)
{ {
return vector.multiply(STRENGTH * SCALAR * ThreadLocalRandom.current().nextInt(3, 6)); return vector.multiply(STRENGTH * SCALAR * ThreadLocalRandom.current().nextInt(3, 6));
@@ -26,6 +26,12 @@ import java.util.Random;
public class ClownfishListener extends PlexListener public class ClownfishListener extends PlexListener
{ {
private final TFMExtras module;
public ClownfishListener(TFMExtras module)
{
this.module = module;
}
@EventHandler @EventHandler
public void onPlayerInteract(PlayerInteractEvent event) public void onPlayerInteract(PlayerInteractEvent event)
@@ -47,20 +53,20 @@ public class ClownfishListener extends PlexListener
if (meta.hasDisplayName() && Objects.equals(meta.displayName(), Component.text("Clownfish"))) if (meta.hasDisplayName() && Objects.equals(meta.displayName(), Component.text("Clownfish")))
{ {
final List<String> restrictedPlayers = TFMExtras.getModule().getConfig().getStringList("server.clownfish.restricted"); final List<String> restrictedPlayers = module.getConfig().getStringList("server.clownfish.restricted");
if (restrictedPlayers.contains(player.getUniqueId().toString())) if (restrictedPlayers.contains(player.getUniqueId().toString()))
{ {
player.sendMessage(MiniMessage.miniMessage().deserialize("<gray>You have been restricted from using the clownfish")); player.sendMessage(MiniMessage.miniMessage().deserialize("<gray>You have been restricted from using the clownfish"));
return; return;
} }
double radius = TFMExtras.getModule().getConfig().getInt("server.clownfish.radius"); double radius = module.getConfig().getInt("server.clownfish.radius");
double strength = TFMExtras.getModule().getConfig().getInt("server.clownfish.strength"); double strength = module.getConfig().getInt("server.clownfish.strength");
List<String> pushedPlayers = new ArrayList<>(); List<String> pushedPlayers = new ArrayList<>();
final Vector senderPos = player.getLocation().toVector(); final Vector senderPos = player.getLocation().toVector();
final List<Player> players = player.getWorld().getPlayers(); final List<Player> players = player.getWorld().getPlayers();
final List<String> toggledPlayers = TFMExtras.getModule().getConfig().getStringList("server.clownfish.toggled_players"); final List<String> toggledPlayers = module.getConfig().getStringList("server.clownfish.toggled_players");
for (final Player target : players) for (final Player target : players)
{ {
@@ -16,7 +16,14 @@ import org.bukkit.util.Vector;
public class JumpPadsListener extends PlexListener public class JumpPadsListener extends PlexListener
{ {
JumpPads jumpPads = TFMExtras.getModule().jumpPads; private final TFMExtras module;
private final JumpPads jumpPads;
public JumpPadsListener(TFMExtras module)
{
this.module = module;
this.jumpPads = module.getJumpPads();
}
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void jumppadsAction(PlayerMoveEvent event) public void jumppadsAction(PlayerMoveEvent event)
@@ -43,7 +50,7 @@ public class JumpPadsListener extends PlexListener
{ {
vector = vector.multiply(new Vector(0, -1, 0)); vector = vector.multiply(new Vector(0, -1, 0));
} }
TFMExtras.plexApi().logging().debug("New Velocity: {0}", vector.toString()); module.api().logging().debug("New Velocity: {0}", vector.toString());
player.setFallDistance(0); player.setFallDistance(0);
player.setVelocity(vector); player.setVelocity(vector);
} }
@@ -14,6 +14,13 @@ import org.bukkit.potion.PotionEffectType;
public class OrbitEffectListener extends PlexListener public class OrbitEffectListener extends PlexListener
{ {
private final TFMExtras module;
public OrbitEffectListener(TFMExtras module)
{
this.module = module;
}
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onPotionEffectRemove(EntityPotionEffectEvent event) public void onPotionEffectRemove(EntityPotionEffectEvent event)
{ {
@@ -22,7 +29,7 @@ public class OrbitEffectListener extends PlexListener
if ((event.getAction() == EntityPotionEffectEvent.Action.CLEARED || event.getAction() == EntityPotionEffectEvent.Action.REMOVED) if ((event.getAction() == EntityPotionEffectEvent.Action.CLEARED || event.getAction() == EntityPotionEffectEvent.Action.REMOVED)
&& event.getModifiedType() == PotionEffectType.LEVITATION) && event.getModifiedType() == PotionEffectType.LEVITATION)
{ {
TFMExtras.plexApi().scheduler().runEntityLater(player, () -> module.api().scheduler().runEntityLater(player, () ->
{ {
if (OrbitCommand.isPlayerOrbited(player.getUniqueId())) if (OrbitCommand.isPlayerOrbited(player.getUniqueId()))
{ {
@@ -40,7 +47,7 @@ public class OrbitEffectListener extends PlexListener
Player player = event.getPlayer(); Player player = event.getPlayer();
GameMode newGameMode = event.getNewGameMode(); GameMode newGameMode = event.getNewGameMode();
TFMExtras.plexApi().scheduler().runEntityLater(player, () -> module.api().scheduler().runEntityLater(player, () ->
{ {
if (OrbitCommand.isPlayerOrbited(player.getUniqueId()) && newGameMode != GameMode.SURVIVAL) if (OrbitCommand.isPlayerOrbited(player.getUniqueId()) && newGameMode != GameMode.SURVIVAL)
{ {
@@ -7,16 +7,23 @@ import org.bukkit.event.player.PlayerJoinEvent;
public class PlayerListener extends PlexListener public class PlayerListener extends PlexListener
{ {
private final TFMExtras module;
public PlayerListener(TFMExtras module)
{
this.module = module;
}
@EventHandler @EventHandler
public void onAuto(PlayerJoinEvent event) public void onAuto(PlayerJoinEvent event)
{ {
if (TFMExtras.getModule().getConfig().getStringList("server.clear-on-join").contains(event.getPlayer().getName())) if (module.getConfig().getStringList("server.clear-on-join").contains(event.getPlayer().getName()))
{ {
TFMExtras.plexApi().scheduler().runEntityLater(event.getPlayer(), () -> event.getPlayer().getInventory().clear(), 1); module.api().scheduler().runEntityLater(event.getPlayer(), () -> event.getPlayer().getInventory().clear(), 1);
} }
if (TFMExtras.getModule().getConfig().getStringList("server.teleport-on-join").contains(event.getPlayer().getName())) if (module.getConfig().getStringList("server.teleport-on-join").contains(event.getPlayer().getName()))
{ {
TFMExtras.plexApi().scheduler().runEntityLater(event.getPlayer(), () -> event.getPlayer().teleportAsync(TFMExtras.getRandomLocation(event.getPlayer().getWorld())), 1); module.api().scheduler().runEntityLater(event.getPlayer(), () -> event.getPlayer().teleportAsync(module.getRandomLocation(event.getPlayer().getWorld())), 1);
} }
} }