Permalink
Browse files

Added block support to the matchers

  • Loading branch information...
me4502 committed Aug 6, 2018
1 parent 34efb6e commit ba61919168ef06aa1fefab96641d9b4c063a095c
@@ -0,0 +1,41 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.blacklist.target;
import com.sk89q.worldedit.world.block.BlockType;
public class ItemBlockMatcher implements TargetMatcher {
private final BlockType type;
public ItemBlockMatcher(BlockType type) {
this.type = type;
}
@Override
public String getMatchedTypeId() {
return this.type.getId();
}
@Override
public boolean test(Target target) {
return target.getTypeId().equals(getMatchedTypeId());
}
}
@@ -19,22 +19,28 @@
package com.sk89q.worldguard.blacklist.target;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
public class TargetMatcherParser {
public TargetMatcher fromInput(String input) throws TargetMatcherParseException {
return new ItemMatcher(parseType(input));
}
private ItemType parseType(String input) throws TargetMatcherParseException {
input = input.trim();
ItemType itemType = ItemTypes.get(input);
if (itemType == null) {
throw new TargetMatcherParseException("Unknown block or item name: " + input);
input = input.toLowerCase().trim();
BlockType blockType = BlockTypes.get(input);
if (blockType != null) {
if (blockType.hasItemType()) {
return new ItemBlockMatcher(blockType);
} else {
return new BlockMatcher(blockType);
}
} else {
ItemType itemType = ItemTypes.get(input);
if (itemType == null) {
throw new TargetMatcherParseException("Unknown block or item name: " + input);
}
return new ItemMatcher(itemType);
}
return itemType;
}
}
@@ -26,7 +26,9 @@
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.config.ConfigurationManager;
@@ -41,9 +43,7 @@
import com.sk89q.worldguard.util.report.SystemInfoReport;
import com.sk89q.worldguard.util.task.Task;
import com.sk89q.worldguard.util.task.TaskStateComparator;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -101,8 +101,8 @@ public void reload(CommandContext args, CommandSender sender) throws CommandExce
ConfigurationManager config = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
config.unload();
config.load();
for (World world : Bukkit.getServer().getWorlds()) {
config.get(BukkitAdapter.adapt(world));
for (World world : WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getWorlds()) {
config.get(world);
}
WorldGuard.getInstance().getPlatform().getRegionContainer().reload();
// WGBukkit.cleanCache();
@@ -200,12 +200,9 @@ public void profile(final CommandContext args, final CommandSender sender) throw
.sendMessageAfterDelay("(Please wait... profiling for %d minute(s)...)")
.thenTellErrorsOnly("CPU profiling failed.");
sampler.getFuture().addListener(new Runnable() {
@Override
public void run() {
synchronized (WorldGuardCommands.this) {
activeSampler = null;
}
sampler.getFuture().addListener(() -> {
synchronized (WorldGuardCommands.this) {
activeSampler = null;
}
}, MoreExecutors.directExecutor());
@@ -260,7 +257,7 @@ public void flushStates(CommandContext args, CommandSender sender) throws Comman
if (player != null) {
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
WorldGuard.getInstance().getPlatform().getSessionManager().resetState(localPlayer);
sender.sendMessage("Cleared states for player \"" + player.getName() + "\".");
sender.sendMessage("Cleared states for player \"" + localPlayer.getName() + "\".");
}
}
}

0 comments on commit ba61919

Please sign in to comment.