This commit is contained in:
Telesphoreo 2022-04-20 18:48:23 -05:00
parent cbf4004169
commit 7c27c03d98
3 changed files with 28 additions and 60 deletions

View File

@ -17,7 +17,8 @@ import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.CommandMap; import org.bukkit.command.Command;
import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -34,7 +35,7 @@ public class WorldListener extends PlexListener
@EventHandler @EventHandler
public void onBlockPlace(BlockPlaceEvent e) public void onBlockPlace(BlockPlaceEvent e)
{ {
if (!checkPermission(e.getPlayer())) if (!checkPermission(e.getPlayer(), true))
{ {
e.setCancelled(true); e.setCancelled(true);
} }
@ -43,7 +44,7 @@ public class WorldListener extends PlexListener
@EventHandler @EventHandler
public void onBlockBreak(BlockBreakEvent e) public void onBlockBreak(BlockBreakEvent e)
{ {
if (!checkPermission(e.getPlayer())) if (!checkPermission(e.getPlayer(), true))
{ {
e.setCancelled(true); e.setCancelled(true);
} }
@ -63,30 +64,24 @@ public class WorldListener extends PlexListener
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
{ {
// If the person has permission to modify the world, we don't need to block WorldEdit // If the person has permission to modify the world, we don't need to block WorldEdit
if (!checkPermission(event.getPlayer())) if (checkPermission(event.getPlayer(), false))
{ {
PlexLog.debug("We got here"); return;
String message = event.getMessage(); }
message = message.replaceAll("\\s.*", "").replaceAll("/", "");
CommandMap commandMap = plugin.getServer().getCommandMap(); String message = event.getMessage();
String finalMessage = message; // Don't check the arguments
commandMap.getKnownCommands().values().stream().filter(cmd -> cmd.getName().toLowerCase().startsWith("fastasyncworldedit:")) message = message.replaceAll("\\s.*", "").replaceFirst("/", "");
.forEach(cmd -> Command command = Bukkit.getCommandMap().getCommand(message);
{ if (command != null)
PlexLog.debug("Matches a command"); {
for (String commandAliases : cmd.getAliases()) // This does check for aliases
{ boolean isWeCommand = command instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand)command).getPlugin().equals(Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit"));
PlexLog.debug("Matches an alias"); if (isWeCommand)
if (finalMessage.equalsIgnoreCase(cmd.getName()) || finalMessage.equalsIgnoreCase(commandAliases)) {
{ event.getPlayer().sendMessage(Component.text("You do not have permission to use WorldEdit in this world!").color(NamedTextColor.RED));
PlexLog.debug("Blocking it"); event.setCancelled(true);
event.getPlayer().sendMessage(Component.text("You do not have permission to use WorldEdit in this world.").color(NamedTextColor.RED)); }
event.setCancelled(true);
break;
}
}
});
} }
} }
@ -154,13 +149,13 @@ public class WorldListener extends PlexListener
return hasAccess; return hasAccess;
} }
private boolean checkPermission(Player player) private boolean checkPermission(Player player, boolean showMessage)
{ {
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId()); PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
World world = player.getWorld(); World world = player.getWorld();
if (plugin.getSystem().equalsIgnoreCase("permissions")) if (plugin.getSystem().equalsIgnoreCase("permissions"))
{ {
String permission = plugin.config.getString("plex." + world.getName().toLowerCase() + ".modify"); String permission = plugin.config.getString("plex." + world.getName().toLowerCase() + ".permission");
if (permission == null) if (permission == null)
{ {
return true; return true;
@ -186,10 +181,13 @@ public class WorldListener extends PlexListener
} }
} }
String noEdit = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".noEdit"); if (showMessage)
if (noEdit != null)
{ {
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(noEdit)); String noEdit = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".noEdit");
if (noEdit != null)
{
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(noEdit));
}
} }
return false; return false;
} }

View File

@ -5,7 +5,6 @@ import dev.plex.Plex;
import dev.plex.services.impl.AutoWipeService; import dev.plex.services.impl.AutoWipeService;
import dev.plex.services.impl.BanService; import dev.plex.services.impl.BanService;
import dev.plex.services.impl.CommandBlockerService; import dev.plex.services.impl.CommandBlockerService;
import dev.plex.services.impl.CommandFetcherService;
import dev.plex.services.impl.GameRuleService; import dev.plex.services.impl.GameRuleService;
import dev.plex.services.impl.UpdateCheckerService; import dev.plex.services.impl.UpdateCheckerService;
import java.util.List; import java.util.List;
@ -21,7 +20,6 @@ public class ServiceManager
registerService(new AutoWipeService()); registerService(new AutoWipeService());
registerService(new BanService()); registerService(new BanService());
registerService(new CommandBlockerService()); registerService(new CommandBlockerService());
registerService(new CommandFetcherService());
registerService(new GameRuleService()); registerService(new GameRuleService());
registerService(new UpdateCheckerService()); registerService(new UpdateCheckerService());
} }

View File

@ -1,28 +0,0 @@
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;
}
}