mirror of
https://github.com/plexusorg/Module-TFMExtras.git
synced 2026-06-05 15:56:54 +00:00
More refactoring
This commit is contained in:
@@ -13,25 +13,28 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class AdminInfoCommand extends SimplePlexCommand
|
||||
{
|
||||
public AdminInfoCommand()
|
||||
private final TFMExtras module;
|
||||
|
||||
public AdminInfoCommand(TFMExtras module)
|
||||
{
|
||||
super(command("admininfo")
|
||||
.description("Information on how to apply for admin")
|
||||
.aliases("ai,si,staffinfo")
|
||||
.permission("plex.tfmextras.admininfo")
|
||||
.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
|
||||
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");
|
||||
}
|
||||
ADMIN_INFO.forEach(component -> send(sender, component));
|
||||
adminInfo.forEach(component -> send(sender, component));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class AutoClearCommand extends SimplePlexCommand
|
||||
{
|
||||
public AutoClearCommand()
|
||||
private final TFMExtras module;
|
||||
|
||||
public AutoClearCommand(TFMExtras module)
|
||||
{
|
||||
super(command("autoclear")
|
||||
.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")
|
||||
.permission("plex.tfmextras.autoclear")
|
||||
.build());
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
|
||||
{
|
||||
@@ -30,8 +34,8 @@ public class AutoClearCommand extends SimplePlexCommand
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
PlexPlayerView target = TFMExtras.plexApi().players().byName(args[0]).orElseThrow(PlayerNotFoundException::new);
|
||||
List<String> names = TFMExtras.getModule().getConfig().getStringList("server.clear-on-join");
|
||||
PlexPlayerView target = api().players().byName(args[0]).orElseThrow(PlayerNotFoundException::new);
|
||||
List<String> names = module.getConfig().getStringList("server.clear-on-join");
|
||||
boolean isEnabled = names.contains(target.name());
|
||||
if (!isEnabled)
|
||||
{
|
||||
@@ -41,8 +45,8 @@ public class AutoClearCommand extends SimplePlexCommand
|
||||
{
|
||||
names.remove(target.name());
|
||||
}
|
||||
TFMExtras.getModule().getConfig().set("server.clear-on-join", names);
|
||||
TFMExtras.getModule().getConfig().save();
|
||||
module.getConfig().set("server.clear-on-join", names);
|
||||
module.getConfig().save();
|
||||
isEnabled = !isEnabled;
|
||||
return messageComponent("modifiedAutoClear", target.name(), isEnabled ? "now" : "no longer");
|
||||
}
|
||||
|
||||
@@ -15,7 +15,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class AutoTeleportCommand extends SimplePlexCommand
|
||||
{
|
||||
public AutoTeleportCommand()
|
||||
private final TFMExtras module;
|
||||
|
||||
public AutoTeleportCommand(TFMExtras module)
|
||||
{
|
||||
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")
|
||||
@@ -23,7 +25,9 @@ public class AutoTeleportCommand extends SimplePlexCommand
|
||||
.aliases("autotp,rtp,randomtp,tpr")
|
||||
.permission("plex.tfmextras.autotp")
|
||||
.build());
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
|
||||
{
|
||||
@@ -33,12 +37,12 @@ public class AutoTeleportCommand extends SimplePlexCommand
|
||||
{
|
||||
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;
|
||||
}
|
||||
checkPermission(sender, "plex.tfmextras.autotp.other");
|
||||
PlexPlayerView target = TFMExtras.plexApi().players().byName(args[0]).orElseThrow(PlayerNotFoundException::new);
|
||||
List<String> names = TFMExtras.getModule().getConfig().getStringList("server.teleport-on-join");
|
||||
PlexPlayerView target = api().players().byName(args[0]).orElseThrow(PlayerNotFoundException::new);
|
||||
List<String> names = module.getConfig().getStringList("server.teleport-on-join");
|
||||
boolean isEnabled = names.contains(target.name());
|
||||
if (!isEnabled)
|
||||
{
|
||||
@@ -48,8 +52,8 @@ public class AutoTeleportCommand extends SimplePlexCommand
|
||||
{
|
||||
names.remove(target.name());
|
||||
}
|
||||
TFMExtras.getModule().getConfig().set("server.teleport-on-join", names);
|
||||
TFMExtras.getModule().getConfig().save();
|
||||
module.getConfig().set("server.teleport-on-join", names);
|
||||
module.getConfig().save();
|
||||
isEnabled = !isEnabled;
|
||||
return messageComponent("modifiedAutoTeleport", target.name(), isEnabled ? "now" : "no longer");
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package dev.plex.extras.command;
|
||||
|
||||
import dev.plex.command.SimplePlexCommand;
|
||||
import dev.plex.extras.TFMExtras;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -29,7 +28,7 @@ public class CakeCommand extends SimplePlexCommand
|
||||
@Override
|
||||
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"));
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package dev.plex.extras.command;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.SimplePlexCommand;
|
||||
import dev.plex.extras.TFMExtras;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
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!");
|
||||
}
|
||||
Entity entity = findNearestEntity(player, minecart);
|
||||
TFMExtras.plexApi().scheduler().runEntity(entity, () -> entity.addPassenger(player));
|
||||
api().scheduler().runEntity(entity, () -> entity.addPassenger(player));
|
||||
return null;
|
||||
}
|
||||
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() + "!");
|
||||
}
|
||||
Entity entity = findNearestEntity(target, minecart);
|
||||
TFMExtras.plexApi().scheduler().runEntity(entity, () -> entity.addPassenger(target));
|
||||
api().scheduler().runEntity(entity, () -> entity.addPassenger(target));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package dev.plex.extras.command;
|
||||
|
||||
import dev.plex.command.SimplePlexCommand;
|
||||
import dev.plex.extras.TFMExtras;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
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"))
|
||||
.forEach(p ->
|
||||
{
|
||||
TFMExtras.plexApi().scheduler().runEntity(p, () ->
|
||||
api().scheduler().runEntity(p, () ->
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package dev.plex.extras.command;
|
||||
|
||||
import dev.plex.command.SimplePlexCommand;
|
||||
import dev.plex.extras.TFMExtras;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
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 ->
|
||||
{
|
||||
removed.incrementAndGet();
|
||||
TFMExtras.plexApi().scheduler().runEntity(entity, entity::remove);
|
||||
api().scheduler().runEntity(entity, entity::remove);
|
||||
});
|
||||
broadcast(messageComponent("areaEffectCloudClear", sender.getName()));
|
||||
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 ClownfishCommand()
|
||||
private final TFMExtras module;
|
||||
|
||||
public ClownfishCommand(TFMExtras module)
|
||||
{
|
||||
super(command("clownfish")
|
||||
.description("Gives a player a clownfish capable of knocking people back")
|
||||
.usage("/<command> [<toggle>]")
|
||||
.permission("plex.tfmextras.clownfish")
|
||||
.build());
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
@Override
|
||||
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"));
|
||||
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... ><_>");
|
||||
}
|
||||
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());
|
||||
if (isToggled)
|
||||
@@ -56,8 +60,8 @@ public class ClownfishCommand extends SimplePlexCommand
|
||||
toggledPlayers.add(player.getUniqueId().toString());
|
||||
}
|
||||
|
||||
TFMExtras.getModule().getConfig().set("server.clownfish.toggled_players", toggledPlayers);
|
||||
TFMExtras.getModule().getConfig().save();
|
||||
module.getConfig().set("server.clownfish.toggled_players", toggledPlayers);
|
||||
module.getConfig().save();
|
||||
|
||||
return messageComponent("toggleClownfish", isToggled ? "now" : "no longer");
|
||||
}
|
||||
@@ -65,9 +69,9 @@ public class ClownfishCommand extends SimplePlexCommand
|
||||
{
|
||||
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());
|
||||
if (isRestricted)
|
||||
@@ -79,8 +83,8 @@ public class ClownfishCommand extends SimplePlexCommand
|
||||
restrictedPlayers.add(target.uuid().toString());
|
||||
}
|
||||
|
||||
TFMExtras.getModule().getConfig().set("server.clownfish.restricted", restrictedPlayers);
|
||||
TFMExtras.getModule().getConfig().save();
|
||||
module.getConfig().set("server.clownfish.restricted", restrictedPlayers);
|
||||
module.getConfig().save();
|
||||
|
||||
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.source.RequiredCommandSource;
|
||||
import dev.plex.extras.TFMExtras;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
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)
|
||||
{
|
||||
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.");
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package dev.plex.extras.command;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.SimplePlexCommand;
|
||||
import dev.plex.extras.TFMExtras;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -33,7 +32,7 @@ public class EnglishMfCommand extends SimplePlexCommand
|
||||
return usage();
|
||||
}
|
||||
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.setHealth(0);
|
||||
|
||||
@@ -18,7 +18,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class JumpPadsCommand extends SimplePlexCommand
|
||||
{
|
||||
public JumpPadsCommand()
|
||||
private final JumpPads jumpPads;
|
||||
|
||||
public JumpPadsCommand(TFMExtras module)
|
||||
{
|
||||
super(command("jumppads")
|
||||
.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")
|
||||
.permission("plex.tfmextras.jumppads")
|
||||
.build());
|
||||
this.jumpPads = module.getJumpPads();
|
||||
}
|
||||
JumpPads jumpPads = TFMExtras.getModule().jumpPads;
|
||||
|
||||
@Override
|
||||
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 dev.plex.command.SimplePlexCommand;
|
||||
import dev.plex.extras.TFMExtras;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -85,7 +84,7 @@ public class OrbitCommand extends SimplePlexCommand
|
||||
|
||||
private void startOrbiting(Player player, int strength)
|
||||
{
|
||||
TFMExtras.plexApi().scheduler().runEntity(player, () ->
|
||||
api().scheduler().runEntity(player, () ->
|
||||
{
|
||||
player.setGameMode(org.bukkit.GameMode.SURVIVAL);
|
||||
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)
|
||||
{
|
||||
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)
|
||||
|
||||
@@ -2,7 +2,6 @@ package dev.plex.extras.command;
|
||||
|
||||
import dev.plex.command.SimplePlexCommand;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.extras.TFMExtras;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
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.");
|
||||
}
|
||||
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:");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user