Remove checkTab and replace with silentCheckRank

add isCancelled checks for MobListener
Modify the plugin's YAML file to load before essentials
Modify the world command to support the TFM Extras module
Add more checks in WorldListener to prevent spawning entities and interacting with anything except openable things (doors, trapdoors, gates)
This commit is contained in:
Taah
2023-08-24 02:40:52 -07:00
parent 37a649fa7a
commit 8344e3596e
18 changed files with 178 additions and 52 deletions

View File

@ -58,7 +58,7 @@ public class AdventureCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (checkTab(sender, Rank.ADMIN, "plex.gamemode.adventure.others"))
if (silentCheckRank(sender, Rank.ADMIN, "plex.gamemode.adventure.others"))
{
return PlexUtils.getPlayerNameList();
}

View File

@ -110,6 +110,6 @@ public class BanCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.ban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
return args.length == 1 && silentCheckRank(sender, Rank.ADMIN, "plex.ban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -62,7 +62,7 @@ public class CreativeCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (checkTab(sender, Rank.ADMIN, "plex.gamemode.creative.others"))
if (silentCheckRank(sender, Rank.ADMIN, "plex.gamemode.creative.others"))
{
return PlexUtils.getPlayerNameList();
}

View File

@ -69,6 +69,6 @@ public class FreezeCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.freeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
return args.length == 1 && silentCheckRank(sender, Rank.ADMIN, "plex.freeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -54,6 +54,6 @@ public class LockupCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.lockup") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
return args.length == 1 && silentCheckRank(sender, Rank.ADMIN, "plex.lockup") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -62,6 +62,6 @@ public class MuteCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.mute") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
return args.length == 1 && silentCheckRank(sender, Rank.ADMIN, "plex.mute") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -144,7 +144,7 @@ public class SmiteCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (checkTab(sender, Rank.ADMIN, "plex.smite") && args.length == 1)
if (silentCheckRank(sender, Rank.ADMIN, "plex.smite") && args.length == 1)
{
return PlexUtils.getPlayerNameList();
}

View File

@ -58,7 +58,7 @@ public class SpectatorCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (checkTab(sender, Rank.ADMIN, "plex.gamemode.spectator.others"))
if (silentCheckRank(sender, Rank.ADMIN, "plex.gamemode.spectator.others"))
{
return PlexUtils.getPlayerNameList();
}

View File

@ -59,7 +59,7 @@ public class SurvivalCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (checkTab(sender, Rank.ADMIN, "plex.gamemode.survival.others"))
if (silentCheckRank(sender, Rank.ADMIN, "plex.gamemode.survival.others"))
{
return PlexUtils.getPlayerNameList();
}

View File

@ -98,6 +98,6 @@ public class TempbanCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.tempban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
return args.length == 1 && silentCheckRank(sender, Rank.ADMIN, "plex.tempban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -61,6 +61,6 @@ public class UnbanCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.unban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
return args.length == 1 && silentCheckRank(sender, Rank.ADMIN, "plex.unban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -41,6 +41,6 @@ public class UnfreezeCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.unfreeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
return args.length == 1 && silentCheckRank(sender, Rank.ADMIN, "plex.unfreeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -41,6 +41,6 @@ public class UnmuteCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.unfreeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
return args.length == 1 && silentCheckRank(sender, Rank.ADMIN, "plex.unfreeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -1,27 +1,32 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.Plex;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexLog;
import net.kyori.adventure.text.Component;
import org.apache.commons.compress.utils.Lists;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.UUID;
import java.util.regex.Pattern;
@CommandPermissions(level = Rank.OP, permission = "plex.world", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "world", description = "Teleport to a world.", usage = "/<command> <world>")
public class WorldCMD extends PlexCommand
{
private static final Pattern UUID_PATTERN = Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
@ -30,18 +35,45 @@ public class WorldCMD extends PlexCommand
{
return usage();
}
World world = getNonNullWorld(args[0]);
boolean playerWorld = args[0].matches("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");
if (playerWorld && Plex.get().getModuleManager().getModules().stream().anyMatch(plexModule -> plexModule.getPlexModuleFile().getName().equalsIgnoreCase("Module-TFMExtras")))
{
checkRank(playerSender, Rank.ADMIN, "plex.world.playerworlds");
}
playerSender.teleportAsync(world.getSpawnLocation());
return messageComponent("playerWorldTeleport", world.getName());
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
final List<String> completions = Lists.newArrayList();
final Player player = (Player) sender;
if (args.length == 1)
{
return Bukkit.getWorlds().stream().map(World::getName).collect(Collectors.toList());
@NotNull List<World> worlds = Bukkit.getWorlds();
for (World world : worlds)
{
String worldName = world.getName();
try
{
final UUID uuid = UUID.fromString(worldName);
if (uuid.equals(player.getUniqueId()) || silentCheckRank(player, Rank.ADMIN, "plex.world.playerworlds"))
{
completions.add(worldName);
}
}
catch (Exception e)
{
completions.add(worldName);
}
}
}
return ImmutableList.of();
return completions;
}
}