mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-26 20:45:43 +01:00
Make chat + command flag handing more sane.
* Send/receive chat and allowed/blocked cmd flags now respect deny-message flag. * Added `regions.cancel-chat-without-recipients` option to disable the default behavior.
This commit is contained in:
parent
1f85a53117
commit
b6e2bca5bc
@ -151,6 +151,7 @@ public abstract class WorldConfiguration {
|
||||
public boolean disableSoilDehydration;
|
||||
public Set<String> allowedSnowFallOver;
|
||||
public boolean regionInvinciblityRemovesMobs;
|
||||
public boolean regionCancelEmptyChatEvents;
|
||||
public boolean regionNetherPortalProtection;
|
||||
public boolean fakePlayerBuildOverride;
|
||||
public boolean explosionFlagCancellation;
|
||||
|
@ -253,6 +253,7 @@ public void loadConfiguration() {
|
||||
|
||||
useRegions = getBoolean("regions.enable", true);
|
||||
regionInvinciblityRemovesMobs = getBoolean("regions.invincibility-removes-mobs", false);
|
||||
regionCancelEmptyChatEvents = getBoolean("regions.cancel-chat-without-recipients", true);
|
||||
regionNetherPortalProtection = getBoolean("regions.nether-portal-protection", false);
|
||||
fakePlayerBuildOverride = getBoolean("regions.fake-player-build-override", true);
|
||||
explosionFlagCancellation = getBoolean("regions.explosion-flags-block-entity-damage", true);
|
||||
|
@ -105,23 +105,26 @@ private void tellErrorMessage(DelegateEvent event, Cause cause, Location locatio
|
||||
|
||||
if (rootCause instanceof Player) {
|
||||
Player player = (Player) rootCause;
|
||||
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
Long lastTime = WGMetadata.getIfPresent(player, DENY_MESSAGE_KEY, Long.class);
|
||||
if (lastTime == null || now - lastTime >= LAST_MESSAGE_DELAY) {
|
||||
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
|
||||
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
|
||||
String message = query.queryValue(BukkitAdapter.adapt(location), localPlayer, Flags.DENY_MESSAGE);
|
||||
message = WorldGuard.getInstance().getPlatform().getMatcher().replaceMacros(localPlayer, message);
|
||||
message = CommandUtils.replaceColorMacros(message);
|
||||
if (message != null && !message.isEmpty()) {
|
||||
player.sendMessage(message.replace("%what%", what));
|
||||
}
|
||||
formatAndSendDenyMessage(what, localPlayer, message);
|
||||
WGMetadata.put(player, DENY_MESSAGE_KEY, now);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void formatAndSendDenyMessage(String what, LocalPlayer localPlayer, String message) {
|
||||
if (message == null || message.isEmpty()) return;
|
||||
message = WorldGuard.getInstance().getPlatform().getMatcher().replaceMacros(localPlayer, message);
|
||||
message = CommandUtils.replaceColorMacros(message);
|
||||
localPlayer.printRaw(message.replace("%what%", what));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the given cause is whitelist (should be ignored).
|
||||
*
|
||||
|
@ -30,10 +30,10 @@
|
||||
import com.sk89q.worldguard.config.WorldConfiguration;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
import com.sk89q.worldguard.session.MoveType;
|
||||
import com.sk89q.worldguard.session.Session;
|
||||
import com.sk89q.worldguard.session.handler.GameModeFlag;
|
||||
@ -160,20 +160,26 @@ public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
WorldConfiguration wcfg =
|
||||
WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(localPlayer.getWorld());
|
||||
if (wcfg.useRegions) {
|
||||
if (!StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(localPlayer.getLocation(), localPlayer, Flags.SEND_CHAT))) {
|
||||
player.sendMessage(ChatColor.RED + "You don't have permission to chat in this region!");
|
||||
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
|
||||
ApplicableRegionSet chatFrom = query.getApplicableRegions(localPlayer.getLocation());
|
||||
|
||||
if (!chatFrom.testState(localPlayer, Flags.SEND_CHAT)) {
|
||||
String message = chatFrom.queryValue(localPlayer, Flags.DENY_MESSAGE);
|
||||
RegionProtectionListener.formatAndSendDenyMessage("chat", localPlayer, message);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean anyRemoved = false;
|
||||
for (Iterator<Player> i = event.getRecipients().iterator(); i.hasNext();) {
|
||||
Player rPlayer = i.next();
|
||||
LocalPlayer rLocal = plugin.wrapPlayer(rPlayer);
|
||||
if (!StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(rLocal.getLocation(), rLocal, Flags.RECEIVE_CHAT))) {
|
||||
if (!query.testState(rLocal.getLocation(), rLocal, Flags.RECEIVE_CHAT)) {
|
||||
i.remove();
|
||||
anyRemoved = true;
|
||||
}
|
||||
}
|
||||
if (event.getRecipients().size() == 0) {
|
||||
if (anyRemoved && event.getRecipients().size() == 0 && wcfg.regionCancelEmptyChatEvents) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@ -397,20 +403,18 @@ public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (event.getCause() == TeleportCause.CHORUS_FRUIT) {
|
||||
if (!WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())) {
|
||||
boolean allowFrom = setFrom.testState(localPlayer, Flags.CHORUS_TELEPORT);
|
||||
boolean allowTo = set.testState(localPlayer, Flags.CHORUS_TELEPORT);
|
||||
if (!allowFrom || !allowTo) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You're not allowed to teleport " +
|
||||
(!allowFrom ? "from here." : "there."));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (event.getCause() == TeleportCause.CHORUS_FRUIT) {
|
||||
if (!WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())) {
|
||||
boolean allowFrom = setFrom.testState(localPlayer, Flags.CHORUS_TELEPORT);
|
||||
boolean allowTo = set.testState(localPlayer, Flags.CHORUS_TELEPORT);
|
||||
if (!allowFrom || !allowTo) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You're not allowed to teleport " +
|
||||
(!allowFrom ? "from here." : "there."));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (NoSuchFieldError ignored) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -476,7 +480,8 @@ public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
CommandFilter test = new CommandFilter(allowedCommands, blockedCommands);
|
||||
|
||||
if (!test.apply(event.getMessage())) {
|
||||
player.sendMessage(ChatColor.RED + event.getMessage() + " is not allowed in this area.");
|
||||
String message = set.queryValue(localPlayer, Flags.DENY_MESSAGE);
|
||||
RegionProtectionListener.formatAndSendDenyMessage("use " + event.getMessage(), localPlayer, message);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user