geforkt von Mirrors/FastAsyncWorldEdit
Added support for specifying color names instead of data values for cloth.
Dieser Commit ist enthalten in:
Ursprung
5e01f50d93
Commit
40a3a6fbe6
@ -259,16 +259,6 @@ public class WorldEdit {
|
|||||||
|
|
||||||
int data;
|
int data;
|
||||||
|
|
||||||
// Parse the block data (optional)
|
|
||||||
try {
|
|
||||||
data = args1.length > 1 ? Integer.parseInt(args1[1]) : 0;
|
|
||||||
if (data > 15 || data < 0) {
|
|
||||||
data = 0;
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
data = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 {
|
||||||
@ -287,6 +277,26 @@ public class WorldEdit {
|
|||||||
throw new UnknownItemException(arg);
|
throw new UnknownItemException(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse the block data (optional)
|
||||||
|
try {
|
||||||
|
data = args1.length > 1 ? Integer.parseInt(args1[1]) : 0;
|
||||||
|
if (data > 15 || data < 0) {
|
||||||
|
data = 0;
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
if (blockType == BlockType.CLOTH) {
|
||||||
|
ClothColor col = ClothColor.lookup(args1[1]);
|
||||||
|
|
||||||
|
if (col != null) {
|
||||||
|
data = col.getID();
|
||||||
|
} else {
|
||||||
|
throw new InvalidItemException(arg, "Unknown cloth color '" + args1[1] + "'");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new InvalidItemException(arg, "Unknown data value '" + args1[1] + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the item is allowed
|
// Check if the item is allowed
|
||||||
if (allAllowed || player.hasPermission("worldeditanyblock")
|
if (allAllowed || player.hasPermission("worldeditanyblock")
|
||||||
|| !config.disallowedBlocks.contains(blockType.getID())) {
|
|| !config.disallowedBlocks.contains(blockType.getID())) {
|
||||||
@ -301,7 +311,7 @@ public class WorldEdit {
|
|||||||
text[3] = args0.length > 4 ? args0[4] : "";
|
text[3] = args0.length > 4 ? args0[4] : "";
|
||||||
return new SignBlock(blockType.getID(), data, text);
|
return new SignBlock(blockType.getID(), data, text);
|
||||||
|
|
||||||
// Alow setting mob spawn type
|
// Allow setting mob spawn type
|
||||||
} else if (blockType == BlockType.MOB_SPAWNER) {
|
} else if (blockType == BlockType.MOB_SPAWNER) {
|
||||||
if (args0.length > 1) {
|
if (args0.length > 1) {
|
||||||
if (!server.isValidMobType(args0[1])) {
|
if (!server.isValidMobType(args0[1])) {
|
||||||
@ -311,6 +321,19 @@ public class WorldEdit {
|
|||||||
} else {
|
} else {
|
||||||
return new MobSpawnerBlock(data, "Pig");
|
return new MobSpawnerBlock(data, "Pig");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allow setting note
|
||||||
|
} else if (blockType == BlockType.NOTE_BLOCK) {
|
||||||
|
if (args0.length > 1) {
|
||||||
|
byte note = Byte.parseByte(args0[1]);
|
||||||
|
if (note < 0 || note > 24) {
|
||||||
|
throw new InvalidItemException(arg, "Out of range note value: '" + args0[1] + "'");
|
||||||
|
} else {
|
||||||
|
return new NoteBlock(data, note);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return new NoteBlock(data, (byte)0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new BaseBlock(blockType.getID(), data);
|
return new BaseBlock(blockType.getID(), data);
|
||||||
|
133
src/com/sk89q/worldedit/blocks/ClothColor.java
Normale Datei
133
src/com/sk89q/worldedit/blocks/ClothColor.java
Normale Datei
@ -0,0 +1,133 @@
|
|||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* WorldEdit
|
||||||
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||||
|
*
|
||||||
|
* 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.blocks;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cloth colors.
|
||||||
|
*
|
||||||
|
* @author sk89q
|
||||||
|
*/
|
||||||
|
public enum ClothColor {
|
||||||
|
WHITE(0, "White", "white"),
|
||||||
|
ORANGE(1, "Orange", "orange"),
|
||||||
|
MAGENTA(2, "Magenta", "magenta"),
|
||||||
|
LIGHT_BLUE(3, "Light blue", "lightblue"),
|
||||||
|
YELLOW(4, "Yellow", "yellow"),
|
||||||
|
LIGHT_GREEN(5, "Light green", "lightgreen"),
|
||||||
|
PINK(6, "Pink", new String[] {"pink", "lightred"}),
|
||||||
|
GRAY(7, "Gray", new String[] {"grey", "gray"}),
|
||||||
|
LIGHT_GRAY(8, "Light gray", new String[] {"lightgrey", "lightgray"}),
|
||||||
|
CYAN(9, "Cyan", new String[] {"cyan", "turquoise"}),
|
||||||
|
PURPLE(10, "Purple", new String[] {"purple", "violet"}),
|
||||||
|
BLUE(11, "Blue", "blue"),
|
||||||
|
BROWN(12, "Brown", new String[] {"brown", "cocoa", "coffee"}),
|
||||||
|
DARK_GREEN(13, "Dark green", new String[] {"green", "darkgreen", "cactusgreen", "cactigreen"}),
|
||||||
|
RED(14, "Red", "red"),
|
||||||
|
BLACK(15, "Black", "black");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores a map of the IDs for fast access.
|
||||||
|
*/
|
||||||
|
private static final Map<Integer,ClothColor> ids = new HashMap<Integer,ClothColor>();
|
||||||
|
/**
|
||||||
|
* Stores a map of the names for fast access.
|
||||||
|
*/
|
||||||
|
private static final Map<String,ClothColor> lookup = new HashMap<String,ClothColor>();
|
||||||
|
|
||||||
|
private final int id;
|
||||||
|
private final String name;
|
||||||
|
private final String[] lookupKeys;
|
||||||
|
|
||||||
|
static {
|
||||||
|
for (ClothColor type : EnumSet.allOf(ClothColor.class)) {
|
||||||
|
ids.put(type.id, type);
|
||||||
|
for (String key : type.lookupKeys) {
|
||||||
|
lookup.put(key, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the type.
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @param name
|
||||||
|
*/
|
||||||
|
ClothColor(int id, String name, String lookupKey) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.lookupKeys = new String[]{lookupKey};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the type.
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @param name
|
||||||
|
*/
|
||||||
|
ClothColor(int id, String name, String[] lookupKeys) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.lookupKeys = lookupKeys;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return type from ID. May return null.
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static ClothColor fromID(int id) {
|
||||||
|
return ids.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return type from name. May return null.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static ClothColor lookup(String name) {
|
||||||
|
return lookup.get(name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get item numeric ID.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getID() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get user-friendly item name.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren