this is wip

This commit is contained in:
Telesphoreo 2022-04-20 16:37:15 -05:00
parent 4eeaf051ad
commit 57eab45b43
7 changed files with 122 additions and 83 deletions

View File

@ -15,7 +15,7 @@ import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.consolesay", source = RequiredCommandSource.CONSOLE)
@CommandParameters(name = "consolesay", usage = "/<command> <message>", description = "Displays a message to everyone", aliases = "csay")
public class ConsoleSayCommand extends PlexCommand
public class ConsoleSayCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)

View File

@ -12,15 +12,20 @@ import dev.plex.util.PlexUtils;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.CommandMap;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.jetbrains.annotations.NotNull;
@ -29,84 +34,18 @@ public class WorldListener extends PlexListener
@EventHandler
public void onBlockPlace(BlockPlaceEvent e)
{
Player player = e.getPlayer();
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
World world = player.getWorld();
if (plugin.getSystem().equalsIgnoreCase("permissions"))
if (!checkPermission(e.getPlayer()))
{
String permission = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".permission");
if (permission == null)
{
return;
}
if (player.hasPermission(permission))
{
return;
}
}
else if (plugin.getSystem().equalsIgnoreCase("ranks"))
{
if (plugin.config.contains("worlds." + world.getName().toLowerCase() + ".requiredLevels"))
{
@NotNull List<String> requiredLevel = plugin.config.getStringList("worlds." + world.getName().toLowerCase() + ".requiredLevels");
if (checkLevel(plexPlayer, requiredLevel.toArray(String[]::new)))
{
return;
}
}
else
{
return;
}
}
e.setCancelled(true);
String noEdit = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".noEdit");
if (noEdit != null)
{
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(noEdit));
e.setCancelled(true);
}
}
@EventHandler
public void onBlockBreak(BlockBreakEvent e)
{
Player player = e.getPlayer();
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
World world = player.getWorld();
if (plugin.getSystem().equalsIgnoreCase("permissions"))
if (!checkPermission(e.getPlayer()))
{
String permission = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".permission");
if (permission == null)
{
return;
}
if (player.hasPermission(permission))
{
return;
}
}
else if (plugin.getSystem().equalsIgnoreCase("ranks"))
{
if (plugin.config.contains("worlds." + world.getName().toLowerCase() + ".requiredLevels"))
{
@NotNull List<String> requiredLevel = plugin.config.getStringList("worlds." + world.getName().toLowerCase() + ".requiredLevels");
if (checkLevel(plexPlayer, requiredLevel.toArray(String[]::new)))
{
return;
}
}
else
{
return;
}
}
e.setCancelled(true);
String noEdit = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".noEdit");
if (noEdit != null)
{
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(noEdit));
e.setCancelled(true);
}
}
@ -120,6 +59,37 @@ public class WorldListener extends PlexListener
e.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
{
// If the person has permission to modify the world, we don't need to block WorldEdit
if (!checkPermission(event.getPlayer()))
{
PlexLog.debug("We got here");
String message = event.getMessage();
message = message.replaceAll("\\s.*", "").replaceAll("/", "");
CommandMap commandMap = plugin.getServer().getCommandMap();
String finalMessage = message;
commandMap.getKnownCommands().values().stream().filter(cmd -> cmd.getName().toLowerCase().startsWith("fastasyncworldedit:"))
.forEach(cmd ->
{
PlexLog.debug("Matches a command");
for (String commandAliases : cmd.getAliases())
{
PlexLog.debug("Matches an alias");
if (finalMessage.equalsIgnoreCase(cmd.getName()) || finalMessage.equalsIgnoreCase(commandAliases))
{
PlexLog.debug("Blocking it");
event.getPlayer().sendMessage(Component.text("You do not have permission to use WorldEdit in this world.").color(NamedTextColor.RED));
event.setCancelled(true);
break;
}
}
});
}
}
// TODO: Add an entry setting in the config.yml and allow checking for all worlds
@EventHandler
public void onWorldTeleport(PlayerTeleportEvent e)
@ -136,7 +106,7 @@ public class WorldListener extends PlexListener
{
e.setCancelled(true);
}
else if (plugin.getSystem().equals("permissions") && !e.getPlayer().hasPermission("plex.enter.adminworld"))
else if (plugin.getSystem().equals("permissions") && !e.getPlayer().hasPermission("plex.adminworld.enter"))
{
e.setCancelled(true);
}
@ -183,4 +153,44 @@ public class WorldListener extends PlexListener
}
return hasAccess;
}
private boolean checkPermission(Player player)
{
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
World world = player.getWorld();
if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
String permission = plugin.config.getString("plex." + world.getName().toLowerCase() + ".modify");
if (permission == null)
{
return true;
}
if (player.hasPermission(permission))
{
return true;
}
}
else if (plugin.getSystem().equalsIgnoreCase("ranks"))
{
if (plugin.config.contains("worlds." + world.getName().toLowerCase() + ".requiredLevels"))
{
@NotNull List<String> requiredLevel = plugin.config.getStringList("worlds." + world.getName().toLowerCase() + ".requiredLevels");
if (checkLevel(plexPlayer, requiredLevel.toArray(String[]::new)))
{
return true;
}
}
else
{
return true;
}
}
String noEdit = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".noEdit");
if (noEdit != null)
{
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(noEdit));
}
return false;
}
}

View File

@ -139,6 +139,7 @@ public class PunishmentManager implements PlexBase
public boolean isBanned(UUID uuid)
{
// TODO: If a person is using MongoDB, this will error out because it is checking for bans on a player that doesn't exist yet
/*if (!DataUtils.hasPlayedBefore(uuid))
{
return false;
@ -163,13 +164,13 @@ public class PunishmentManager implements PlexBase
}
else
{
PlexLog.debug("Checking active bans mysql");
//PlexLog.debug("Checking active bans mysql");
CompletableFuture<List<Punishment>> future = new CompletableFuture<>();
Plex.get().getSqlPunishment().getPunishments().whenComplete((punishments, throwable) ->
{
PlexLog.debug("Received Punishments");
//PlexLog.debug("Received Punishments");
List<Punishment> punishmentList = punishments.stream().filter(Punishment::isActive).filter(punishment -> punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN).toList();
PlexLog.debug("Completing with {0} punishments", punishmentList.size());
//PlexLog.debug("Completing with {0} punishments", punishmentList.size());
future.complete(punishmentList);
});
return future;

View File

@ -5,6 +5,7 @@ import dev.plex.Plex;
import dev.plex.services.impl.AutoWipeService;
import dev.plex.services.impl.BanService;
import dev.plex.services.impl.CommandBlockerService;
import dev.plex.services.impl.CommandFetcherService;
import dev.plex.services.impl.GameRuleService;
import dev.plex.services.impl.UpdateCheckerService;
import java.util.List;
@ -17,11 +18,12 @@ public class ServiceManager
public ServiceManager()
{
registerService(new AutoWipeService());
registerService(new BanService());
registerService(new CommandBlockerService());
registerService(new CommandFetcherService());
registerService(new GameRuleService());
registerService(new UpdateCheckerService());
registerService(new AutoWipeService());
registerService(new CommandBlockerService());
}
public void startServices()

View File

@ -2,11 +2,9 @@ package dev.plex.services.impl;
import dev.plex.Plex;
import dev.plex.services.AbstractService;
import java.time.LocalDateTime;
import dev.plex.util.TimeUtils;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import dev.plex.util.TimeUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
@ -36,7 +34,7 @@ public class BanService extends AbstractService
@Override
public int repeatInSeconds()
{
// Every 5 minutes
return 300;
// Every 30 seconds
return 30;
}
}

View File

@ -0,0 +1,28 @@
package dev.plex.services.impl;
import dev.plex.services.AbstractService;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
public class CommandFetcherService extends AbstractService
{
public static final List<Command> worldeditCommands = new ArrayList<>();
public CommandFetcherService()
{
super(false, false);
}
@Override
public void run()
{
}
@Override
public int repeatInSeconds()
{
return 0;
}
}

View File

@ -15,7 +15,7 @@
# So these would be valid:
# - "m:e:mail sendall:You cannot send messages to everyone on the server"
# - "r:e:^[^ :]+::Plugin specific commands are disabled"
blockedCommands:
commands:
- "r:e:^[^ :]+::<gray>Plugin specific commands are disabled."
- "m:e:mail sendall:<gray>You cannot send messages to everyone on the server."
- "m:e:mail sendtempall:<gray>You cannot send messages to everyone on the server."