geforkt von Mirrors/FastAsyncWorldEdit
Merge pull request #277 from sk89q/hand
Added "hand" and "pos1" pseudo block types that use the current quickbar slot and the block at the current pos1, respectively.
Dieser Commit ist enthalten in:
Commit
81a76c5d4f
@ -456,6 +456,19 @@ public abstract class LocalPlayer {
|
|||||||
*/
|
*/
|
||||||
public abstract int getItemInHand();
|
public abstract int getItemInHand();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Block that the player is holding.
|
||||||
|
*
|
||||||
|
* @return the item id of the item the player is holding
|
||||||
|
*/
|
||||||
|
public BaseBlock getBlockInHand() throws WorldEditException {
|
||||||
|
final int typeId = getItemInHand();
|
||||||
|
if (!getWorld().isValidBlockType(typeId)) {
|
||||||
|
throw new NotABlockException(typeId);
|
||||||
|
}
|
||||||
|
return new BaseBlock(typeId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the name of the player.
|
* Get the name of the player.
|
||||||
*
|
*
|
||||||
|
34
src/main/java/com/sk89q/worldedit/NotABlockException.java
Normale Datei
34
src/main/java/com/sk89q/worldedit/NotABlockException.java
Normale Datei
@ -0,0 +1,34 @@
|
|||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* WorldEdit
|
||||||
|
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldedit;
|
||||||
|
|
||||||
|
public class NotABlockException extends WorldEditException {
|
||||||
|
public NotABlockException() {
|
||||||
|
super("This item is not a block.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotABlockException(String type) {
|
||||||
|
super("The item '"+type+"' is not a block.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotABlockException(int typeId) {
|
||||||
|
super("The item with the ID "+typeId+" is not a block.");
|
||||||
|
}
|
||||||
|
}
|
@ -367,7 +367,7 @@ public class WorldEdit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BaseBlock getBlock(LocalPlayer player, String arg, boolean allAllowed)
|
public BaseBlock getBlock(LocalPlayer player, String arg, boolean allAllowed)
|
||||||
throws UnknownItemException, DisallowedItemException {
|
throws WorldEditException {
|
||||||
return getBlock(player, arg, allAllowed, false);
|
return getBlock(player, arg, allAllowed, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,7 +384,7 @@ public class WorldEdit {
|
|||||||
*/
|
*/
|
||||||
public BaseBlock getBlock(LocalPlayer player, String arg,
|
public BaseBlock getBlock(LocalPlayer player, String arg,
|
||||||
boolean allAllowed, boolean allowNoData)
|
boolean allAllowed, boolean allowNoData)
|
||||||
throws UnknownItemException, DisallowedItemException {
|
throws WorldEditException {
|
||||||
BlockType blockType;
|
BlockType blockType;
|
||||||
arg = arg.replace("_", " ");
|
arg = arg.replace("_", " ");
|
||||||
arg = arg.replace(";", "|");
|
arg = arg.replace(";", "|");
|
||||||
@ -397,7 +397,29 @@ public class WorldEdit {
|
|||||||
int data = -1;
|
int data = -1;
|
||||||
|
|
||||||
boolean parseDataValue = true;
|
boolean parseDataValue = true;
|
||||||
|
if ("hand".equalsIgnoreCase(testID)) {
|
||||||
|
// Get the block type from the item in the user's hand.
|
||||||
|
final BaseBlock blockInHand = player.getBlockInHand();
|
||||||
|
if (blockInHand.getClass() != BaseBlock.class) {
|
||||||
|
return blockInHand;
|
||||||
|
}
|
||||||
|
|
||||||
|
blockId = blockInHand.getId();
|
||||||
|
blockType = BlockType.fromID(blockId);
|
||||||
|
data = blockInHand.getData();
|
||||||
|
} else if ("pos1".equalsIgnoreCase(testID)) {
|
||||||
|
// Get the block type from the "primary position"
|
||||||
|
final LocalWorld world = player.getWorld();
|
||||||
|
final BlockVector primaryPosition = getSession(player).getRegionSelector(world).getPrimaryPosition();
|
||||||
|
final BaseBlock blockInHand = world.getBlock(primaryPosition);
|
||||||
|
if (blockInHand.getClass() != BaseBlock.class) {
|
||||||
|
return blockInHand;
|
||||||
|
}
|
||||||
|
|
||||||
|
blockId = blockInHand.getId();
|
||||||
|
blockType = BlockType.fromID(blockId);
|
||||||
|
data = blockInHand.getData();
|
||||||
|
} else {
|
||||||
// Attempt to parse the item ID or otherwise resolve an item/block
|
// Attempt to parse the item ID or otherwise resolve an item/block
|
||||||
// name to its numeric ID
|
// name to its numeric ID
|
||||||
try {
|
try {
|
||||||
@ -436,6 +458,7 @@ public class WorldEdit {
|
|||||||
if (!player.getWorld().isValidBlockType(blockId)) {
|
if (!player.getWorld().isValidBlockType(blockId)) {
|
||||||
throw new UnknownItemException(arg);
|
throw new UnknownItemException(arg);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!allowNoData && data == -1) {
|
if (!allowNoData && data == -1) {
|
||||||
// No wildcards allowed => eliminate them.
|
// No wildcards allowed => eliminate them.
|
||||||
@ -620,12 +643,12 @@ public class WorldEdit {
|
|||||||
* @throws DisallowedItemException
|
* @throws DisallowedItemException
|
||||||
*/
|
*/
|
||||||
public BaseBlock getBlock(LocalPlayer player, String id)
|
public BaseBlock getBlock(LocalPlayer player, String id)
|
||||||
throws UnknownItemException, DisallowedItemException {
|
throws WorldEditException {
|
||||||
return getBlock(player, id, false);
|
return getBlock(player, id, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<BaseBlock> getBlocks(LocalPlayer player, String list, boolean allAllowed, boolean allowNoData)
|
public Set<BaseBlock> getBlocks(LocalPlayer player, String list, boolean allAllowed, boolean allowNoData)
|
||||||
throws DisallowedItemException, UnknownItemException {
|
throws WorldEditException {
|
||||||
String[] items = list.split(",");
|
String[] items = list.split(",");
|
||||||
Set<BaseBlock> blocks = new HashSet<BaseBlock>();
|
Set<BaseBlock> blocks = new HashSet<BaseBlock>();
|
||||||
for (String id : items) {
|
for (String id : items) {
|
||||||
@ -635,12 +658,12 @@ public class WorldEdit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Set<BaseBlock> getBlocks(LocalPlayer player, String list, boolean allAllowed)
|
public Set<BaseBlock> getBlocks(LocalPlayer player, String list, boolean allAllowed)
|
||||||
throws DisallowedItemException, UnknownItemException {
|
throws WorldEditException {
|
||||||
return getBlocks(player, list, allAllowed, false);
|
return getBlocks(player, list, allAllowed, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<BaseBlock> getBlocks(LocalPlayer player, String list)
|
public Set<BaseBlock> getBlocks(LocalPlayer player, String list)
|
||||||
throws DisallowedItemException, UnknownItemException {
|
throws WorldEditException {
|
||||||
return getBlocks(player, list, false);
|
return getBlocks(player, list, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -655,7 +678,7 @@ public class WorldEdit {
|
|||||||
* @throws DisallowedItemException
|
* @throws DisallowedItemException
|
||||||
*/
|
*/
|
||||||
public Pattern getBlockPattern(LocalPlayer player, String patternString)
|
public Pattern getBlockPattern(LocalPlayer player, String patternString)
|
||||||
throws UnknownItemException, DisallowedItemException {
|
throws WorldEditException {
|
||||||
|
|
||||||
String[] items = patternString.split(",");
|
String[] items = patternString.split(",");
|
||||||
|
|
||||||
@ -804,7 +827,7 @@ public class WorldEdit {
|
|||||||
*/
|
*/
|
||||||
public Set<Integer> getBlockIDs(LocalPlayer player,
|
public Set<Integer> getBlockIDs(LocalPlayer player,
|
||||||
String list, boolean allBlocksAllowed)
|
String list, boolean allBlocksAllowed)
|
||||||
throws UnknownItemException, DisallowedItemException {
|
throws WorldEditException {
|
||||||
|
|
||||||
String[] items = list.split(",");
|
String[] items = list.split(",");
|
||||||
Set<Integer> blocks = new HashSet<Integer>();
|
Set<Integer> blocks = new HashSet<Integer>();
|
||||||
|
@ -283,6 +283,39 @@ public enum BlockType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Map<Integer, BaseBlock> itemBlockMapping = new HashMap<Integer, BaseBlock>();
|
||||||
|
static {
|
||||||
|
itemBlockMapping.put(ItemID.FLINT_AND_TINDER, new BaseBlock(BlockID.FIRE, -1));
|
||||||
|
itemBlockMapping.put(ItemID.STRING, new BaseBlock(BlockID.TRIPWIRE, -1));
|
||||||
|
itemBlockMapping.put(ItemID.SEEDS, new BaseBlock(BlockID.CROPS, -1));
|
||||||
|
itemBlockMapping.put(ItemID.SIGN, new BaseBlock(BlockID.SIGN_POST, -1));
|
||||||
|
itemBlockMapping.put(ItemID.WOODEN_DOOR_ITEM, new BaseBlock(BlockID.WOODEN_DOOR, -1));
|
||||||
|
itemBlockMapping.put(ItemID.WATER_BUCKET, new BaseBlock(BlockID.STATIONARY_WATER, -1));
|
||||||
|
itemBlockMapping.put(ItemID.LAVA_BUCKET, new BaseBlock(BlockID.STATIONARY_LAVA, -1));
|
||||||
|
itemBlockMapping.put(ItemID.IRON_DOOR_ITEM, new BaseBlock(BlockID.IRON_DOOR, -1));
|
||||||
|
itemBlockMapping.put(ItemID.REDSTONE_DUST, new BaseBlock(BlockID.REDSTONE_WIRE, -1));
|
||||||
|
itemBlockMapping.put(ItemID.SUGAR_CANE_ITEM, new BaseBlock(BlockID.REED, -1));
|
||||||
|
itemBlockMapping.put(ItemID.BED_ITEM, new BaseBlock(BlockID.BED, -1));
|
||||||
|
itemBlockMapping.put(ItemID.REDSTONE_REPEATER, new BaseBlock(BlockID.REDSTONE_REPEATER_OFF, -1));
|
||||||
|
itemBlockMapping.put(ItemID.PUMPKIN_SEEDS, new BaseBlock(BlockID.PUMPKIN_STEM, -1));
|
||||||
|
itemBlockMapping.put(ItemID.MELON_SEEDS, new BaseBlock(BlockID.MELON_STEM, -1));
|
||||||
|
itemBlockMapping.put(ItemID.NETHER_WART_SEED, new BaseBlock(BlockID.NETHER_WART, -1));
|
||||||
|
itemBlockMapping.put(ItemID.BREWING_STAND, new BaseBlock(BlockID.BREWING_STAND, -1));
|
||||||
|
itemBlockMapping.put(ItemID.CAULDRON, new BaseBlock(BlockID.CAULDRON, -1));
|
||||||
|
itemBlockMapping.put(ItemID.FLOWER_POT, new BaseBlock(BlockID.FLOWER_POT, -1));
|
||||||
|
itemBlockMapping.put(ItemID.CARROT, new BaseBlock(BlockID.CARROTS, -1));
|
||||||
|
itemBlockMapping.put(ItemID.POTATO, new BaseBlock(BlockID.POTATOES, -1));
|
||||||
|
itemBlockMapping.put(ItemID.COMPARATOR, new BaseBlock(BlockID.COMPARATOR_OFF, -1));
|
||||||
|
|
||||||
|
// These are just for fun:
|
||||||
|
itemBlockMapping.put(ItemID.BUCKET, new BaseBlock(BlockID.AIR, -1)); // There's nothing in the bucket, what did you expect?
|
||||||
|
itemBlockMapping.put(ItemID.MILK_BUCKET, new BaseBlock(BlockID.SNOW, -1)); // Whoops, spilled the milk
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BaseBlock getBlockForItem(int typeId) {
|
||||||
|
return itemBlockMapping.get(typeId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get block numeric ID.
|
* Get block numeric ID.
|
||||||
*
|
*
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.bukkit;
|
package com.sk89q.worldedit.bukkit;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -49,6 +51,11 @@ public class BukkitPlayer extends LocalPlayer {
|
|||||||
return itemStack != null ? itemStack.getTypeId() : 0;
|
return itemStack != null ? itemStack.getTypeId() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BaseBlock getBlockInHand() throws WorldEditException {
|
||||||
|
ItemStack itemStack = player.getItemInHand();
|
||||||
|
return BukkitUtil.toBlock(getWorld(), itemStack);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return player.getName();
|
return player.getName();
|
||||||
|
@ -21,6 +21,14 @@ package com.sk89q.worldedit.bukkit;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.NotABlockException;
|
||||||
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
|
import com.sk89q.worldedit.blocks.BlockID;
|
||||||
|
import com.sk89q.worldedit.blocks.BlockType;
|
||||||
|
import com.sk89q.worldedit.blocks.ItemID;
|
||||||
|
import com.sk89q.worldedit.blocks.SkullBlock;
|
||||||
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -41,6 +49,8 @@ import com.sk89q.worldedit.bukkit.entity.BukkitEntity;
|
|||||||
import com.sk89q.worldedit.bukkit.entity.BukkitExpOrb;
|
import com.sk89q.worldedit.bukkit.entity.BukkitExpOrb;
|
||||||
import com.sk89q.worldedit.bukkit.entity.BukkitItem;
|
import com.sk89q.worldedit.bukkit.entity.BukkitItem;
|
||||||
import com.sk89q.worldedit.bukkit.entity.BukkitPainting;
|
import com.sk89q.worldedit.bukkit.entity.BukkitPainting;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.material.Dye;
|
||||||
|
|
||||||
public class BukkitUtil {
|
public class BukkitUtil {
|
||||||
private BukkitUtil() {
|
private BukkitUtil() {
|
||||||
@ -153,4 +163,32 @@ public class BukkitUtil {
|
|||||||
return new BukkitEntity(toLocation(e.getLocation()), e.getType(), e.getUniqueId());
|
return new BukkitEntity(toLocation(e.getLocation()), e.getType(), e.getUniqueId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static BaseBlock toBlock(LocalWorld world, ItemStack itemStack) throws WorldEditException {
|
||||||
|
final int typeId = itemStack.getTypeId();
|
||||||
|
if (world.isValidBlockType(typeId)) {
|
||||||
|
return new BaseBlock(typeId, itemStack.getDurability());
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (typeId) {
|
||||||
|
case ItemID.INK_SACK:
|
||||||
|
final Dye materialData = (Dye) itemStack.getData();
|
||||||
|
if (materialData.getColor() == DyeColor.BROWN) {
|
||||||
|
return new BaseBlock(BlockID.COCOA_PLANT, -1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ItemID.HEAD:
|
||||||
|
return new SkullBlock(0, (byte) itemStack.getDurability());
|
||||||
|
|
||||||
|
default:
|
||||||
|
final BaseBlock baseBlock = BlockType.getBlockForItem(typeId);
|
||||||
|
if (baseBlock != null) {
|
||||||
|
return baseBlock;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new NotABlockException(typeId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ import com.sk89q.worldedit.LocalSession;
|
|||||||
import com.sk89q.worldedit.ServerInterface;
|
import com.sk89q.worldedit.ServerInterface;
|
||||||
import com.sk89q.worldedit.UnknownItemException;
|
import com.sk89q.worldedit.UnknownItemException;
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
import com.sk89q.worldedit.commands.InsufficientArgumentsException;
|
import com.sk89q.worldedit.commands.InsufficientArgumentsException;
|
||||||
import com.sk89q.worldedit.patterns.Pattern;
|
import com.sk89q.worldedit.patterns.Pattern;
|
||||||
@ -156,7 +157,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
|
|||||||
* @throws DisallowedItemException
|
* @throws DisallowedItemException
|
||||||
*/
|
*/
|
||||||
public BaseBlock getBlock(String arg, boolean allAllowed)
|
public BaseBlock getBlock(String arg, boolean allAllowed)
|
||||||
throws UnknownItemException, DisallowedItemException {
|
throws WorldEditException {
|
||||||
return controller.getBlock(player, arg, allAllowed);
|
return controller.getBlock(player, arg, allAllowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +170,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
|
|||||||
* @throws DisallowedItemException
|
* @throws DisallowedItemException
|
||||||
*/
|
*/
|
||||||
public BaseBlock getBlock(String id)
|
public BaseBlock getBlock(String id)
|
||||||
throws UnknownItemException, DisallowedItemException {
|
throws WorldEditException {
|
||||||
return controller.getBlock(player, id, false);
|
return controller.getBlock(player, id, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,7 +183,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
|
|||||||
* @throws DisallowedItemException
|
* @throws DisallowedItemException
|
||||||
*/
|
*/
|
||||||
public Pattern getBlockPattern(String list)
|
public Pattern getBlockPattern(String list)
|
||||||
throws UnknownItemException, DisallowedItemException {
|
throws WorldEditException {
|
||||||
return controller.getBlockPattern(player, list);
|
return controller.getBlockPattern(player, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +197,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
|
|||||||
* @throws DisallowedItemException
|
* @throws DisallowedItemException
|
||||||
*/
|
*/
|
||||||
public Set<Integer> getBlockIDs(String list, boolean allBlocksAllowed)
|
public Set<Integer> getBlockIDs(String list, boolean allBlocksAllowed)
|
||||||
throws UnknownItemException, DisallowedItemException {
|
throws WorldEditException {
|
||||||
return controller.getBlockIDs(player, list, allBlocksAllowed);
|
return controller.getBlockIDs(player, list, allBlocksAllowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren