mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-23 19:16:40 +01:00
Add deny-message flag to adjust the region "don't have permission" message.
Also add color code parsing for the flag set command.
This commit is contained in:
parent
8098211d01
commit
bd0917d34b
@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldguard.bukkit.commands;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
@ -35,6 +36,76 @@ public final class CommandUtils {
|
||||
private CommandUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace color macros in a string.
|
||||
*
|
||||
* @param str the string
|
||||
* @return the new string
|
||||
*/
|
||||
public static String replaceColorMacros(String str) {
|
||||
// TODO: Make this more efficient
|
||||
|
||||
str = str.replace("`r", ChatColor.RED.toString());
|
||||
str = str.replace("`R", ChatColor.DARK_RED.toString());
|
||||
|
||||
str = str.replace("`y", ChatColor.YELLOW.toString());
|
||||
str = str.replace("`Y", ChatColor.GOLD.toString());
|
||||
|
||||
str = str.replace("`g", ChatColor.GREEN.toString());
|
||||
str = str.replace("`G", ChatColor.DARK_GREEN.toString());
|
||||
|
||||
str = str.replace("`c", ChatColor.AQUA.toString());
|
||||
str = str.replace("`C", ChatColor.DARK_AQUA.toString());
|
||||
|
||||
str = str.replace("`b", ChatColor.BLUE.toString());
|
||||
str = str.replace("`B", ChatColor.DARK_BLUE.toString());
|
||||
|
||||
str = str.replace("`p", ChatColor.LIGHT_PURPLE.toString());
|
||||
str = str.replace("`P", ChatColor.DARK_PURPLE.toString());
|
||||
|
||||
str = str.replace("`0", ChatColor.BLACK.toString());
|
||||
str = str.replace("`1", ChatColor.DARK_GRAY.toString());
|
||||
str = str.replace("`2", ChatColor.GRAY.toString());
|
||||
str = str.replace("`w", ChatColor.WHITE.toString());
|
||||
|
||||
str = str.replace("`k", ChatColor.MAGIC.toString());
|
||||
|
||||
str = str.replace("`l", ChatColor.BOLD.toString());
|
||||
str = str.replace("`m", ChatColor.STRIKETHROUGH.toString());
|
||||
str = str.replace("`n", ChatColor.UNDERLINE.toString());
|
||||
str = str.replace("`o", ChatColor.ITALIC.toString());
|
||||
|
||||
str = str.replace("`x", ChatColor.RESET.toString());
|
||||
|
||||
// MC classic
|
||||
|
||||
str = str.replace("&c", ChatColor.RED.toString());
|
||||
str = str.replace("&4", ChatColor.DARK_RED.toString());
|
||||
|
||||
str = str.replace("&e", ChatColor.YELLOW.toString());
|
||||
str = str.replace("&6", ChatColor.GOLD.toString());
|
||||
|
||||
str = str.replace("&a", ChatColor.GREEN.toString());
|
||||
str = str.replace("&2", ChatColor.DARK_GREEN.toString());
|
||||
|
||||
str = str.replace("&b", ChatColor.AQUA.toString());
|
||||
str = str.replace("&3", ChatColor.DARK_AQUA.toString());
|
||||
|
||||
str = str.replace("&9", ChatColor.BLUE.toString());
|
||||
str = str.replace("&1", ChatColor.DARK_BLUE.toString());
|
||||
|
||||
str = str.replace("&d", ChatColor.LIGHT_PURPLE.toString());
|
||||
str = str.replace("&5", ChatColor.DARK_PURPLE.toString());
|
||||
|
||||
str = str.replace("&0", ChatColor.BLACK.toString());
|
||||
str = str.replace("&8", ChatColor.DARK_GRAY.toString());
|
||||
str = str.replace("&7", ChatColor.GRAY.toString());
|
||||
str = str.replace("&f", ChatColor.WHITE.toString());
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the given owner object.
|
||||
*
|
||||
|
@ -442,6 +442,9 @@ public void flag(CommandContext args, CommandSender sender) throws CommandExcept
|
||||
RegionGroup groupValue = null;
|
||||
RegionPermissionModel permModel = getPermissionModel(sender);
|
||||
|
||||
// Add color codes
|
||||
value = CommandUtils.replaceColorMacros(value);
|
||||
|
||||
// Lookup the existing region
|
||||
RegionManager manager = checkRegionManager(plugin, world);
|
||||
ProtectedRegion existing = checkExistingRegion(manager, args.getString(0), true);
|
||||
@ -473,8 +476,7 @@ public void flag(CommandContext args, CommandSender sender) throws CommandExcept
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.RED + "Unknown flag specified: " + flagName);
|
||||
sender.sendMessage(ChatColor.RED + "Available " +
|
||||
"flags: " + list);
|
||||
sender.sendMessage(ChatColor.RED + "Available " + "flags: " + list);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -517,7 +519,7 @@ public void flag(CommandContext args, CommandSender sender) throws CommandExcept
|
||||
|
||||
sender.sendMessage(ChatColor.YELLOW
|
||||
+ "Region flag " + foundFlag.getName() + " set on '" +
|
||||
existing.getId() + "' to '" + value + "'.");
|
||||
existing.getId() + "' to '" + ChatColor.stripColor(value) + "'.");
|
||||
|
||||
// No value? Clear the flag, if -g isn't specified
|
||||
} else if (!args.hasFlag('g')) {
|
||||
|
@ -126,13 +126,13 @@ public void appendFlagsList(boolean useColors) {
|
||||
group = region.getFlag(groupFlag);
|
||||
}
|
||||
|
||||
if(group == null) {
|
||||
if (group == null) {
|
||||
builder.append(flag.getName()).append(": ")
|
||||
.append(val);
|
||||
.append(ChatColor.stripColor(String.valueOf(val)));
|
||||
} else {
|
||||
builder.append(flag.getName()).append(" -g ")
|
||||
.append(group).append(": ")
|
||||
.append(val);
|
||||
.append(group).append(": ")
|
||||
.append(ChatColor.stripColor(String.valueOf(val)));
|
||||
}
|
||||
|
||||
hasFlags = true;
|
||||
|
@ -36,7 +36,6 @@
|
||||
import com.sk89q.worldguard.protection.association.Associables;
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -63,13 +62,15 @@ public RegionProtectionListener(WorldGuardPlugin plugin) {
|
||||
* Tell a sender that s/he cannot do something 'here'.
|
||||
*
|
||||
* @param cause the cause
|
||||
* @param subject the subject that the sender was blocked from touching
|
||||
* @param location the location
|
||||
*/
|
||||
private void tellErrorMessage(Cause cause, Object subject) {
|
||||
private void tellErrorMessage(Cause cause, Location location) {
|
||||
Object rootCause = cause.getRootCause();
|
||||
|
||||
if (rootCause instanceof Player) {
|
||||
((Player) rootCause).sendMessage(ChatColor.DARK_RED + "Sorry, but you are not allowed to do that here.");
|
||||
RegionQuery query = getPlugin().getRegionContainer().createQuery();
|
||||
Player player = (Player) rootCause;
|
||||
player.sendMessage(query.queryValue(location, player, DefaultFlag.DENY_MESSAGE));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,11 +19,14 @@
|
||||
|
||||
package com.sk89q.worldguard.protection;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -57,12 +60,20 @@ public boolean testBuild(RegionAssociable subject, StateFlag... flags) {
|
||||
@Nullable
|
||||
@Override
|
||||
public <V> V queryValue(@Nullable RegionAssociable subject, Flag<V> flag) {
|
||||
if (flag == DefaultFlag.BUILD) {
|
||||
return (V) State.DENY;
|
||||
}
|
||||
return flag.getDefault();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <V> Collection<V> queryAllValues(@Nullable RegionAssociable subject, Flag<V> flag) {
|
||||
return Collections.emptySet();
|
||||
if (flag == DefaultFlag.BUILD) {
|
||||
return (Collection<V>) ImmutableList.of(State.DENY);
|
||||
}
|
||||
V fallback = flag.getDefault();
|
||||
return fallback != null ? ImmutableList.of(fallback) : (Collection<V>) ImmutableList.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -378,12 +378,8 @@ public <V> Collection<V> queryAllValues(@Nullable RegionAssociable subject, Flag
|
||||
}
|
||||
|
||||
if (consideredValues.isEmpty()) {
|
||||
if (flag instanceof StateFlag) {
|
||||
V fallback = flag.getDefault();
|
||||
return fallback != null
|
||||
? ImmutableList.of(fallback)
|
||||
: (Collection<V>) ImmutableList.of();
|
||||
}
|
||||
V fallback = flag.getDefault();
|
||||
return fallback != null ? ImmutableList.of(fallback) : (Collection<V>) ImmutableList.of();
|
||||
}
|
||||
|
||||
return consideredValues.values();
|
||||
|
@ -19,11 +19,14 @@
|
||||
|
||||
package com.sk89q.worldguard.protection;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -57,12 +60,20 @@ public boolean testBuild(RegionAssociable subject, StateFlag... flags) {
|
||||
@Nullable
|
||||
@Override
|
||||
public <V> V queryValue(@Nullable RegionAssociable subject, Flag<V> flag) {
|
||||
if (flag == DefaultFlag.BUILD) {
|
||||
return (V) State.DENY;
|
||||
}
|
||||
return flag.getDefault();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <V> Collection<V> queryAllValues(@Nullable RegionAssociable subject, Flag<V> flag) {
|
||||
return Collections.emptySet();
|
||||
if (flag == DefaultFlag.BUILD) {
|
||||
return (Collection<V>) ImmutableList.of(State.DENY);
|
||||
}
|
||||
V fallback = flag.getDefault();
|
||||
return fallback != null ? ImmutableList.of(fallback) : (Collection<V>) ImmutableList.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldguard.protection.flags;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
@ -79,6 +80,8 @@ public final class DefaultFlag {
|
||||
public static final StateFlag ENTITY_ITEM_FRAME_DESTROY = new StateFlag("entity-item-frame-destroy", true);
|
||||
public static final StateFlag POTION_SPLASH = new StateFlag("potion-splash", true);
|
||||
|
||||
public static final StringFlag DENY_MESSAGE = new StringFlag("deny-message",
|
||||
"" + ChatColor.RED + ChatColor.BOLD + "Hey!" + ChatColor.GRAY + " Sorry, but you can't do that here.");
|
||||
public static final StringFlag GREET_MESSAGE = new StringFlag("greeting");
|
||||
public static final StringFlag FAREWELL_MESSAGE = new StringFlag("farewell");
|
||||
public static final BooleanFlag NOTIFY_ENTER = new BooleanFlag("notify-enter");
|
||||
@ -108,7 +111,7 @@ public final class DefaultFlag {
|
||||
TNT, LIGHTER, USE, PLACE_VEHICLE, DESTROY_VEHICLE, SLEEP,
|
||||
MOB_DAMAGE, MOB_SPAWNING, DENY_SPAWN, INVINCIBILITY, EXP_DROPS,
|
||||
CREEPER_EXPLOSION, OTHER_EXPLOSION, ENDERDRAGON_BLOCK_DAMAGE, GHAST_FIREBALL, ENDER_BUILD,
|
||||
GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER, NOTIFY_LEAVE,
|
||||
DENY_MESSAGE, GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER, NOTIFY_LEAVE,
|
||||
EXIT, ENTRY, LIGHTNING, ENTITY_PAINTING_DESTROY, ENDERPEARL,
|
||||
ENTITY_ITEM_FRAME_DESTROY, ITEM_DROP, /*MAX_PLAYERS, MAX_PLAYERS_MESSAGE,*/
|
||||
HEAL_AMOUNT, HEAL_DELAY, MIN_HEAL, MAX_HEAL,
|
||||
|
Loading…
Reference in New Issue
Block a user