mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27: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 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,31 +64,25 @@ 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");
|
// This does check for aliases
|
||||||
for (String commandAliases : cmd.getAliases())
|
boolean isWeCommand = command instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand)command).getPlugin().equals(Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit"));
|
||||||
|
if (isWeCommand)
|
||||||
{
|
{
|
||||||
PlexLog.debug("Matches an alias");
|
event.getPlayer().sendMessage(Component.text("You do not have permission to use WorldEdit in this world!").color(NamedTextColor.RED));
|
||||||
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);
|
event.setCancelled(true);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add an entry setting in the config.yml and allow checking for all worlds
|
// 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;
|
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,11 +181,14 @@ public class WorldListener extends PlexListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (showMessage)
|
||||||
|
{
|
||||||
String noEdit = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".noEdit");
|
String noEdit = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".noEdit");
|
||||||
if (noEdit != null)
|
if (noEdit != null)
|
||||||
{
|
{
|
||||||
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(noEdit));
|
player.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(noEdit));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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());
|
||||||
}
|
}
|
||||||
|
@ -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