mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-23 05:36:45 +01:00
Add blocked-cmds flag :D
This commit is contained in:
parent
9bd019399a
commit
bc7703ac33
@ -1139,6 +1139,7 @@ public class PS {
|
|||||||
FlagManager.addFlag(new AbstractFlag("place", new FlagValue.PlotBlockListValue()));
|
FlagManager.addFlag(new AbstractFlag("place", new FlagValue.PlotBlockListValue()));
|
||||||
FlagManager.addFlag(new AbstractFlag("break", new FlagValue.PlotBlockListValue()));
|
FlagManager.addFlag(new AbstractFlag("break", new FlagValue.PlotBlockListValue()));
|
||||||
FlagManager.addFlag(new AbstractFlag("use", 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") {
|
FlagManager.addFlag(new AbstractFlag("gamemode") {
|
||||||
|
|
||||||
public String parseValueRaw(final String value) {
|
public String parseValueRaw(final String value) {
|
||||||
|
@ -105,7 +105,7 @@ public enum C {
|
|||||||
WORLDEDIT_UNMASKED("$1Your WorldEdit is now unrestricted.", "WorldEdit Masks"),
|
WORLDEDIT_UNMASKED("$1Your WorldEdit is now unrestricted.", "WorldEdit Masks"),
|
||||||
WORLDEDIT_RESTRICTED("$1Your WorldEdit is now restricted.", "WorldEdit Masks"),
|
WORLDEDIT_RESTRICTED("$1Your WorldEdit is now restricted.", "WorldEdit Masks"),
|
||||||
|
|
||||||
GAMEMODE_WAS_BYPASSED("$1You bypassed the gamemode ($2{gamemode}) $1set for this plot", "Gamemode"),
|
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"),
|
HEIGHT_LIMIT("$1This plot world has a height limit of $2{limit}", "Height Limit"),
|
||||||
/*
|
/*
|
||||||
* Records
|
* Records
|
||||||
@ -162,6 +162,8 @@ public enum C {
|
|||||||
*/
|
*/
|
||||||
TOGGLE_ENABLED("$2Enabled setting: %s", "Toggle"),
|
TOGGLE_ENABLED("$2Enabled setting: %s", "Toggle"),
|
||||||
TOGGLE_DISABLED("$2Disabled setting: %s", "Toggle"),
|
TOGGLE_DISABLED("$2Disabled setting: %s", "Toggle"),
|
||||||
|
|
||||||
|
COMMAND_BLOCKED("$2That command is not allowed in this plot", "Blocked Command"),
|
||||||
/*
|
/*
|
||||||
* Ratings
|
* Ratings
|
||||||
*/
|
*/
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.intellectualcrafters.plot.flag;
|
package com.intellectualcrafters.plot.flag;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
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 {
|
public static class DoubleListValue extends FlagValue<List<Double>> implements ListValue {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
package com.intellectualcrafters.plot.listeners;
|
package com.intellectualcrafters.plot.listeners;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
import java.util.regex.Pattern;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.util.*;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -76,6 +72,7 @@ import org.bukkit.event.vehicle.VehicleCreateEvent;
|
|||||||
import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
||||||
import org.bukkit.event.world.ChunkLoadEvent;
|
import org.bukkit.event.world.ChunkLoadEvent;
|
||||||
import org.bukkit.event.world.StructureGrowEvent;
|
import org.bukkit.event.world.StructureGrowEvent;
|
||||||
|
import org.bukkit.help.HelpTopic;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.projectiles.BlockProjectileSource;
|
import org.bukkit.projectiles.BlockProjectileSource;
|
||||||
import org.bukkit.projectiles.ProjectileSource;
|
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.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
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.BukkitUtil;
|
||||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
|
import javax.annotation.RegEx;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Player Events involving plots
|
* Player Events involving plots
|
||||||
*
|
*
|
||||||
@ -289,9 +282,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
|
|||||||
final String message = event.getMessage().toLowerCase().replaceAll("/", "");
|
final String message = event.getMessage().toLowerCase().replaceAll("/", "");
|
||||||
String[] split = message.split(" ");
|
String[] split = message.split(" ");
|
||||||
PluginCommand cmd = Bukkit.getServer().getPluginCommand(split[0]);
|
PluginCommand cmd = Bukkit.getServer().getPluginCommand(split[0]);
|
||||||
if (cmd != null) {
|
if (cmd == null) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (split[0].equals("plotme") || split[0].equals("ap")) {
|
if (split[0].equals("plotme") || split[0].equals("ap")) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
if (Settings.USE_PLOTME_ALIAS) {
|
if (Settings.USE_PLOTME_ALIAS) {
|
||||||
@ -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)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onChunkLoad(final ChunkLoadEvent event) {
|
public void onChunkLoad(final ChunkLoadEvent event) {
|
||||||
final String worldname = event.getWorld().getName();
|
final String worldname = event.getWorld().getName();
|
||||||
|
@ -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<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user