mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
Resolves #20
This commit is contained in:
parent
cbf4004169
commit
7c27c03d98
@ -17,7 +17,8 @@ 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.command.Command;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -34,7 +35,7 @@ public class WorldListener extends PlexListener
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent e)
|
||||
{
|
||||
if (!checkPermission(e.getPlayer()))
|
||||
if (!checkPermission(e.getPlayer(), true))
|
||||
{
|
||||
e.setCancelled(true);
|
||||
}
|
||||
@ -43,7 +44,7 @@ public class WorldListener extends PlexListener
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent e)
|
||||
{
|
||||
if (!checkPermission(e.getPlayer()))
|
||||
if (!checkPermission(e.getPlayer(), true))
|
||||
{
|
||||
e.setCancelled(true);
|
||||
}
|
||||
@ -63,31 +64,25 @@ public class WorldListener extends PlexListener
|
||||
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()))
|
||||
if (checkPermission(event.getPlayer(), false))
|
||||
{
|
||||
PlexLog.debug("We got here");
|
||||
String message = event.getMessage();
|
||||
message = message.replaceAll("\\s.*", "").replaceAll("/", "");
|
||||
return;
|
||||
}
|
||||
|
||||
CommandMap commandMap = plugin.getServer().getCommandMap();
|
||||
String finalMessage = message;
|
||||
commandMap.getKnownCommands().values().stream().filter(cmd -> cmd.getName().toLowerCase().startsWith("fastasyncworldedit:"))
|
||||
.forEach(cmd ->
|
||||
String message = event.getMessage();
|
||||
// Don't check the arguments
|
||||
message = message.replaceAll("\\s.*", "").replaceFirst("/", "");
|
||||
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"));
|
||||
if (isWeCommand)
|
||||
{
|
||||
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.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
|
||||
@ -154,13 +149,13 @@ public class WorldListener extends PlexListener
|
||||
return hasAccess;
|
||||
}
|
||||
|
||||
private boolean checkPermission(Player player)
|
||||
private boolean checkPermission(Player player, boolean showMessage)
|
||||
{
|
||||
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");
|
||||
String permission = plugin.config.getString("plex." + world.getName().toLowerCase() + ".permission");
|
||||
if (permission == null)
|
||||
{
|
||||
return true;
|
||||
@ -186,11 +181,14 @@ public class WorldListener extends PlexListener
|
||||
}
|
||||
}
|
||||
|
||||
if (showMessage)
|
||||
{
|
||||
String noEdit = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".noEdit");
|
||||
if (noEdit != null)
|
||||
{
|
||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(noEdit));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -5,7 +5,6 @@ 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;
|
||||
@ -21,7 +20,6 @@ public class ServiceManager
|
||||
registerService(new AutoWipeService());
|
||||
registerService(new BanService());
|
||||
registerService(new CommandBlockerService());
|
||||
registerService(new CommandFetcherService());
|
||||
registerService(new GameRuleService());
|
||||
registerService(new UpdateCheckerService());
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user