Merge remote-tracking branch 'origin/master'

Conflicts:
	src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java
This commit is contained in:
boy0001 2015-07-18 21:21:38 +10:00
commit 12453e0f6c
8 changed files with 171 additions and 25 deletions

View File

@ -1119,6 +1119,7 @@ public class PS {
FlagManager.addFlag(new AbstractFlag("place", new FlagValue.PlotBlockListValue()));
FlagManager.addFlag(new AbstractFlag("break", new FlagValue.PlotBlockListValue()));
FlagManager.addFlag(new AbstractFlag("use", new FlagValue.PlotBlockListValue()));
FlagManager.addFlag(new AbstractFlag("blocked-cmds", new FlagValue.StringListValue()));
FlagManager.addFlag(new AbstractFlag("gamemode") {
public String parseValueRaw(final String value) {

View File

@ -104,6 +104,9 @@ public enum C {
WORLDEDIT_BYPASS("$2&oTo bypass your restrictions use $4/plot wea", "WorldEdit Masks"),
WORLDEDIT_UNMASKED("$1Your WorldEdit is now unrestricted.", "WorldEdit Masks"),
WORLDEDIT_RESTRICTED("$1Your WorldEdit is now restricted.", "WorldEdit Masks"),
GAMEMODE_WAS_BYPASSED("$1You bypassed the gamemode ($2{gamemode}$1) $1set for this plot", "Gamemode"),
HEIGHT_LIMIT("$1This plot world has a height limit of $2{limit}", "Height Limit"),
/*
* Records
*/
@ -159,6 +162,8 @@ public enum C {
*/
TOGGLE_ENABLED("$2Enabled setting: %s", "Toggle"),
TOGGLE_DISABLED("$2Disabled setting: %s", "Toggle"),
COMMAND_BLOCKED("$2That command is not allowed in this plot", "Blocked Command"),
/*
* Ratings
*/

View File

@ -1,6 +1,7 @@
package com.intellectualcrafters.plot.flag;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
@ -399,6 +400,47 @@ public abstract class FlagValue<T> {
}
}
@SuppressWarnings("ALL")
public static class StringListValue extends FlagValue<List<String>> implements ListValue {
@Override
public String toString(final Object t) {
return StringUtils.join((List<String>) t, ",");
}
@Override
public List<String> getValue(final Object t) {
return (List<String>) t;
}
@Override
public List<String> parse(final String t) {
return Arrays.asList(t.split(","));
}
@Override
public String getDescription() {
return "Flag value must be a string list";
}
@Override
public void add(final Object t, final String value) {
try {
((List<String>) t).addAll(parse(value));
} catch (final Exception ignored) {}
}
@Override
public void remove(final Object t, final String value) {
try {
for (final String item : parse(value)) {
((List<String>) t).remove(item);
}
} catch (final Exception e) {
}
}
}
public static class DoubleListValue extends FlagValue<List<Double>> implements ListValue {
@SuppressWarnings("unchecked")
@Override

View File

@ -1,13 +1,9 @@
package com.intellectualcrafters.plot.listeners;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.regex.Pattern;
import com.intellectualcrafters.plot.util.*;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -76,6 +72,7 @@ import org.bukkit.event.vehicle.VehicleCreateEvent;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.help.HelpTopic;
import org.bukkit.inventory.ItemStack;
import org.bukkit.projectiles.BlockProjectileSource;
import org.bukkit.projectiles.ProjectileSource;
@ -99,15 +96,11 @@ import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import javax.annotation.RegEx;
/**
* Player Events involving plots
*
@ -289,10 +282,8 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
final String message = event.getMessage().toLowerCase().replaceAll("/", "");
String[] split = message.split(" ");
PluginCommand cmd = Bukkit.getServer().getPluginCommand(split[0]);
if (cmd != null) {
return;
}
if (split[0].equals("plotme") || split[0].equals("ap") || split[0].equals("plotz")) {
if (cmd == null) {
if (split[0].equals("plotme") || split[0].equals("ap")) {
final Player player = event.getPlayer();
if (Settings.USE_PLOTME_ALIAS) {
player.performCommand("plots " + StringUtils.join(Arrays.copyOfRange(split, 1, split.length), " "));
@ -303,6 +294,78 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
}
}
Player player = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(player);
if (!PS.get().isPlotWorld(BukkitUtil.getWorld(player))) {
return;
}
final Plot plot = MainUtil.getPlot(BukkitUtil.getLocation(player));
if (plot == null) {
return;
}
Flag flag;
if (!player.hasPermission("plots.admin.interact.blockedcommands") && (flag = FlagManager.getPlotFlag(plot, "blocked-cmds")) != null) {
List<String> v = (List<String>) flag.getValue();
String msg = event.getMessage().toLowerCase().replaceFirst("/", "");
String[] parts = msg.split(" ");
String c = parts[0];
if (parts[0].contains(":")) {
c = parts[0].split(":")[1];
msg = msg.replace(parts[0].split(":")[0] + ":", "");
}
String l = c;
List<String> aliases = new ArrayList<>();
for (HelpTopic cmdLabel : Bukkit.getServer().getHelpMap().getHelpTopics()) {
if (c.equals(cmdLabel.getName())) {
break;
}
PluginCommand p;
String label = cmdLabel.getName().replaceFirst("/", "");
if (aliases.contains(label)) {
continue;
}
if ((p = Bukkit.getPluginCommand(label)) != null) {
for (String a : p.getAliases()) {
if (aliases.contains(a))
continue;
aliases.add(a);
a = a.replaceFirst("/", "");
if (!a.equals(label) && a.equals(c)) {
c = label;
break;
}
}
}
}
if (!l.equals(c)) {
msg = msg.replace(l, c);
}
for (String s : v) {
Pattern pattern;
if (!RegExUtil.compiledPatterns.containsKey(s)) {
RegExUtil.compiledPatterns.put(s, ((pattern = Pattern.compile(s))));
} else {
pattern = RegExUtil.compiledPatterns.get(s);
}
if (pattern.matcher(msg).matches()) {
MainUtil.sendMessage(pp, C.COMMAND_BLOCKED);
event.setCancelled(true);
return;
}
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onChunkLoad(final ChunkLoadEvent event) {
final String worldname = event.getWorld().getName();
@ -1858,6 +1921,12 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
Block block = event.getBlockPlaced();
sendBlockChange(block.getLocation(), block.getType(), block.getData());
}
int temporary;
if (!player.hasPermission("plots.admin.build.heightlimit") && loc.getY() >= (temporary = PS.get().getPlotWorld(world).MAX_BUILD_HEIGHT)) {
event.setCancelled(true);
MainUtil.sendMessage(pp, C.HEIGHT_LIMIT.s().replace("{limit}", "" + temporary));
return;
}
return;
}
else if (!Permissions.hasPermission(pp, "plots.admin.build.road")) {

View File

@ -133,7 +133,15 @@ public class PlotListener extends APlotListener {
final Flag gamemodeFlag = flags.get("gamemode");
if (gamemodeFlag != null) {
if (!player.hasPermission("plots.gamemode.bypass")) {
player.setGameMode(getGameMode(gamemodeFlag.getValueString()));
} else {
MainUtil.sendMessage(
pp,
C.GAMEMODE_WAS_BYPASSED.s().replace("{plot}", plot.getId().toString()).replace("{gamemode}", gamemodeFlag.getValueString()),
true
);
}
}
final Flag flyFlag = flags.get("fly");
if (flyFlag != null) {

View File

@ -60,6 +60,7 @@ public abstract class PlotWorld {
public final static boolean SPAWN_BREEDING_DEFAULT = false;
public final static boolean WORLD_BORDER_DEFAULT = false;
public final static int MAX_PLOT_MEMBERS_DEFAULT = 128;
public final static int MAX_BUILD_HEIGHT_DEFAULT = 256;
// are plot clusters enabled
// require claim in cluster
// TODO make this configurable
@ -94,6 +95,7 @@ public abstract class PlotWorld {
public int TERRAIN = 0;
public boolean HOME_ALLOW_NONMEMBER;
public PlotLoc DEFAULT_HOME;
public int MAX_BUILD_HEIGHT;
public PlotWorld(final String worldname) {
this.worldname = worldname;
@ -149,6 +151,7 @@ public abstract class PlotWorld {
this.SELL_PRICE = config.getDouble("economy.prices.sell");
this.PLOT_CHAT = config.getBoolean("chat.enabled");
this.WORLD_BORDER = config.getBoolean("world.border");
this.MAX_BUILD_HEIGHT = config.getInt("world.max_height");
this.HOME_ALLOW_NONMEMBER = config.getBoolean("home.allow-nonmembers");
String homeDefault = config.getString("home.default");
@ -229,6 +232,7 @@ public abstract class PlotWorld {
options.put("limits.max-members", PlotWorld.MAX_PLOT_MEMBERS_DEFAULT);
options.put("home.default", "side");
options.put("home.allow-nonmembers", false);
options.put("world.max_height", PlotWorld.MAX_BUILD_HEIGHT_DEFAULT);
if (Settings.ENABLE_CLUSTERS && (this.TYPE != 0)) {
options.put("generator.terrain", this.TERRAIN);

View File

@ -0,0 +1,15 @@
package com.intellectualcrafters.plot.util;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
public class RegExUtil {
public static Map<String, Pattern> compiledPatterns;
static {
compiledPatterns = new HashMap<>();
}
}

View File

@ -124,3 +124,5 @@ permissions:
plots.kick: true
plots.worldedit.bypass:
default: false
plots.gamemode.bypass:
default: op