mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 11:55:38 +01:00
Add a list of blocks that cannot be used in /plot set <component>
This commit is contained in:
parent
3c17b76b1c
commit
df01f9bea7
@ -27,6 +27,7 @@ package com.plotsquared.core.command;
|
|||||||
|
|
||||||
import com.plotsquared.core.configuration.CaptionUtility;
|
import com.plotsquared.core.configuration.CaptionUtility;
|
||||||
import com.plotsquared.core.configuration.Captions;
|
import com.plotsquared.core.configuration.Captions;
|
||||||
|
import com.plotsquared.core.configuration.Settings;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
import com.plotsquared.core.plot.Plot;
|
import com.plotsquared.core.plot.Plot;
|
||||||
import com.plotsquared.core.plot.PlotManager;
|
import com.plotsquared.core.plot.PlotManager;
|
||||||
@ -36,10 +37,14 @@ import com.plotsquared.core.util.PatternUtil;
|
|||||||
import com.plotsquared.core.util.Permissions;
|
import com.plotsquared.core.util.Permissions;
|
||||||
import com.plotsquared.core.util.StringMan;
|
import com.plotsquared.core.util.StringMan;
|
||||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||||
|
import com.sk89q.worldedit.world.block.BlockCategory;
|
||||||
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
@CommandDeclaration(command = "set",
|
@CommandDeclaration(command = "set",
|
||||||
description = "Set a plot value",
|
description = "Set a plot value",
|
||||||
@ -71,6 +76,34 @@ public class Set extends SubCommand {
|
|||||||
String material =
|
String material =
|
||||||
StringMan.join(Arrays.copyOfRange(args, 1, args.length), ",").trim();
|
StringMan.join(Arrays.copyOfRange(args, 1, args.length), ",").trim();
|
||||||
|
|
||||||
|
final List<String> forbiddenTypes = Settings.General.INVALID_BLOCKS;
|
||||||
|
if (!Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_ALLOW_UNSAFE) &&
|
||||||
|
!forbiddenTypes.isEmpty()) {
|
||||||
|
for (String forbiddenType : forbiddenTypes) {
|
||||||
|
forbiddenType = forbiddenType.toLowerCase(Locale.ENGLISH);
|
||||||
|
if (forbiddenType.startsWith("minecraft:")) {
|
||||||
|
forbiddenType = forbiddenType.substring(10);
|
||||||
|
}
|
||||||
|
for (String blockType : material.split(",")) {
|
||||||
|
blockType = blockType.toLowerCase(Locale.ENGLISH);
|
||||||
|
if (blockType.startsWith("minecraft:")) {
|
||||||
|
blockType = blockType.substring(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blockType.startsWith("##")) {
|
||||||
|
final BlockCategory category = BlockCategory.REGISTRY.get(blockType.substring(2).toLowerCase(Locale.ROOT));
|
||||||
|
if (category == null || !category.contains(BlockTypes.get(forbiddenType))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if (!blockType.contains(forbiddenType)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Captions.COMPONENT_ILLEGAL_BLOCK.send(player, forbiddenType);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (String component : components) {
|
for (String component : components) {
|
||||||
if (component.equalsIgnoreCase(args[0])) {
|
if (component.equalsIgnoreCase(args[0])) {
|
||||||
if (!Permissions.hasPermission(player, CaptionUtility
|
if (!Permissions.hasPermission(player, CaptionUtility
|
||||||
@ -86,7 +119,8 @@ public class Set extends SubCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pattern pattern = PatternUtil.parse(player, material);
|
Pattern pattern = PatternUtil.parse(player, material, false);
|
||||||
|
|
||||||
if (plot.getRunning() > 0) {
|
if (plot.getRunning() > 0) {
|
||||||
MainUtil.sendMessage(player, Captions.WAIT_FOR_TIMER);
|
MainUtil.sendMessage(player, Captions.WAIT_FOR_TIMER);
|
||||||
return false;
|
return false;
|
||||||
|
@ -184,6 +184,7 @@ public enum Captions implements Caption {
|
|||||||
PERMISSION_ALIAS_SET("plots.alias.set", "static.permissions"),
|
PERMISSION_ALIAS_SET("plots.alias.set", "static.permissions"),
|
||||||
PERMISSION_ALIAS_REMOVE("plots.alias.remove", "static.permissions"),
|
PERMISSION_ALIAS_REMOVE("plots.alias.remove", "static.permissions"),
|
||||||
PERMISSION_ADMIN_CHAT_BYPASS("plots.admin.chat.bypass", "static.permissions"),
|
PERMISSION_ADMIN_CHAT_BYPASS("plots.admin.chat.bypass", "static.permissions"),
|
||||||
|
PERMISSION_ADMIN_ALLOW_UNSAFE("plots.admin.unsafe", "static.permissions"),
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
//<editor-fold desc="Confirm">
|
//<editor-fold desc="Confirm">
|
||||||
EXPIRED_CONFIRM("$2Confirmation has expired, please run the command again!", "Confirm"),
|
EXPIRED_CONFIRM("$2Confirmation has expired, please run the command again!", "Confirm"),
|
||||||
@ -425,6 +426,7 @@ public enum Captions implements Caption {
|
|||||||
COMMAND_SYNTAX("$1Usage: $2%s", "CommandConfig"),
|
COMMAND_SYNTAX("$1Usage: $2%s", "CommandConfig"),
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
//<editor-fold desc="Errors">
|
//<editor-fold desc="Errors">
|
||||||
|
COMPONENT_ILLEGAL_BLOCK("$2You are not allowed to generate a component containg the block '%s'", "Invalid"),
|
||||||
INVALID_PLAYER("$2Player not found: $1%s$2.", "Errors"),
|
INVALID_PLAYER("$2Player not found: $1%s$2.", "Errors"),
|
||||||
INVALID_PLAYER_OFFLINE("$2The player must be online: $1%s.", "Errors"),
|
INVALID_PLAYER_OFFLINE("$2The player must be online: $1%s.", "Errors"),
|
||||||
INVALID_COMMAND_FLAG("$2Invalid command flag: %s0", "Errors"),
|
INVALID_COMMAND_FLAG("$2Invalid command flag: %s0", "Errors"),
|
||||||
|
@ -29,6 +29,7 @@ import com.plotsquared.core.configuration.file.YamlConfiguration;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -245,6 +246,8 @@ public class Settings extends Config {
|
|||||||
public static final class General {
|
public static final class General {
|
||||||
@Comment("Display scientific numbers (4.2E8)") public static boolean SCIENTIFIC = false;
|
@Comment("Display scientific numbers (4.2E8)") public static boolean SCIENTIFIC = false;
|
||||||
@Comment("Replace wall when merging") public static boolean MERGE_REPLACE_WALL = true;
|
@Comment("Replace wall when merging") public static boolean MERGE_REPLACE_WALL = true;
|
||||||
|
@Comment("Blocks that may not be used in plot components") public static List<String> INVALID_BLOCKS =
|
||||||
|
Arrays.asList("command_block", "chain_command_block", "repeating_command_block");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,6 +56,10 @@ public class PatternUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Pattern parse(PlotPlayer plotPlayer, String input) {
|
public static Pattern parse(PlotPlayer plotPlayer, String input) {
|
||||||
|
return parse(plotPlayer, input, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Pattern parse(PlotPlayer plotPlayer, String input, boolean allowLegacy) {
|
||||||
ParserContext context = new ParserContext();
|
ParserContext context = new ParserContext();
|
||||||
if (plotPlayer != null) {
|
if (plotPlayer != null) {
|
||||||
Actor actor = plotPlayer.toActor();
|
Actor actor = plotPlayer.toActor();
|
||||||
@ -69,7 +73,7 @@ public class PatternUtil {
|
|||||||
context.setRestricted(false);
|
context.setRestricted(false);
|
||||||
}
|
}
|
||||||
context.setPreferringWildcard(false);
|
context.setPreferringWildcard(false);
|
||||||
context.setTryLegacy(true);
|
context.setTryLegacy(allowLegacy);
|
||||||
try {
|
try {
|
||||||
return WorldEdit.getInstance().getPatternFactory().parseFromInput(input, context);
|
return WorldEdit.getInstance().getPatternFactory().parseFromInput(input, context);
|
||||||
} catch (InputParseException e) {
|
} catch (InputParseException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user