Merge remote-tracking branch 'origin/master' into feature/mapping

This commit is contained in:
sk89q 2014-07-02 12:54:30 -07:00
commit b2e953a95f
3 changed files with 92 additions and 74 deletions

View File

@ -124,7 +124,7 @@ public final class BlockData {
/* FALL-THROUGH */
case BlockID.COCOA_PLANT:
case BlockID.TRIPWIRE_HOOK:
case BlockID.TRIPWIRE_HOOK: {
int extra = data & ~0x3;
int withoutFlags = data & 0x3;
switch (withoutFlags) {
@ -134,7 +134,7 @@ public final class BlockData {
case 3: return 0 | extra;
}
break;
}
case BlockID.SIGN_POST:
return (data + 4) % 16;
@ -145,15 +145,17 @@ public final class BlockData {
case BlockID.BURNING_FURNACE:
case BlockID.ENDER_CHEST:
case BlockID.TRAPPED_CHEST:
case BlockID.HOPPER:
switch (data) {
case 2: return 5;
case 3: return 4;
case 4: return 2;
case 5: return 3;
case BlockID.HOPPER: {
int extra = data & 0x8;
int withoutFlags = data & ~0x8;
switch (withoutFlags) {
case 2: return 5 | extra;
case 3: return 4 | extra;
case 4: return 2 | extra;
case 5: return 3 | extra;
}
break;
}
case BlockID.DISPENSER:
case BlockID.DROPPER:
int dispPower = data & 0x8;
@ -343,7 +345,7 @@ public final class BlockData {
/* FALL-THROUGH */
case BlockID.COCOA_PLANT:
case BlockID.TRIPWIRE_HOOK:
case BlockID.TRIPWIRE_HOOK: {
int extra = data & ~0x3;
int withoutFlags = data & 0x3;
switch (withoutFlags) {
@ -353,7 +355,7 @@ public final class BlockData {
case 0: return 3 | extra;
}
break;
}
case BlockID.SIGN_POST:
return (data + 12) % 16;
@ -364,15 +366,17 @@ public final class BlockData {
case BlockID.BURNING_FURNACE:
case BlockID.ENDER_CHEST:
case BlockID.TRAPPED_CHEST:
case BlockID.HOPPER:
switch (data) {
case 5: return 2;
case 4: return 3;
case 2: return 4;
case 3: return 5;
case BlockID.HOPPER: {
int extra = data & 0x8;
int withoutFlags = data & ~0x8;
switch (withoutFlags) {
case 5: return 2 | extra;
case 4: return 3 | extra;
case 2: return 4 | extra;
case 3: return 5 | extra;
}
break;
}
case BlockID.DISPENSER:
case BlockID.DROPPER:
int dispPower = data & 0x8;
@ -615,13 +619,15 @@ public final class BlockData {
case BlockID.ENDER_CHEST:
case BlockID.TRAPPED_CHEST:
case BlockID.HOPPER:
switch (data) {
int extra = data & 0x8;
int withoutFlags = data & ~0x8;
switch (withoutFlags) {
case 2:
case 3:
return data ^ flipZ;
return (data ^ flipZ) | extra;
case 4:
case 5:
return data ^ flipX;
return (data ^ flipX) | extra;
}
break;
@ -910,8 +916,10 @@ public final class BlockData {
case BlockID.ENDER_CHEST:
case BlockID.TRAPPED_CHEST:
case BlockID.HOPPER:
if (data < 2 || data > 5) return -1;
return mod((data - 2 + increment), 4) + 2;
int extra = data & 0x8;
int withoutFlags = data & ~0x8;
if (withoutFlags < 2 || withoutFlags > 5) return -1;
return (mod((withoutFlags - 2 + increment), 4) + 2) | extra;
case BlockID.DISPENSER:
case BlockID.DROPPER:

View File

@ -375,9 +375,9 @@ public class UtilityCommands {
)
@CommandPermissions("worldedit.butcher")
@Logging(PLACEMENT)
public void butcher(Actor actor, @Optional Player player, @Optional LocalSession session, CommandContext args) throws WorldEditException {
public void butcher(Actor actor, CommandContext args) throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
Player player = actor instanceof Player ? (Player) actor : null;
// technically the default can be larger than the max, but that's not my problem
int radius = config.butcherDefaultRadius;
@ -407,6 +407,7 @@ public class UtilityCommands {
int killed;
if (player != null) {
LocalSession session = we.getSessionManager().get(player);
killed = player.getWorld().killMobs(session.getPlacementPosition(player), radius, flags.flags);
} else {
killed = 0;

View File

@ -19,7 +19,7 @@
package com.sk89q.worldedit.util.command.parametric;
import com.google.common.base.Joiner;
import com.google.common.primitives.Chars;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandException;
@ -56,6 +56,8 @@ class ParametricCallable implements CommandCallable {
private final Method method;
private final ParameterData[] parameters;
private final Set<Character> valueFlags = new HashSet<Character>();
private final boolean anyFlags;
private final Set<Character> legacyFlags = new HashSet<Character>();
private final SimpleDescription description = new SimpleDescription();
private final CommandPermissions commandPermissions;
@ -109,8 +111,7 @@ class ParametricCallable implements CommandCallable {
}
// Special annotation bindings
} else if (parameter.getBinding() == null) {
parameter.setBinding(builder.getBindings().get(
annotation.annotationType()));
parameter.setBinding(builder.getBindings().get(annotation.annotationType()));
parameter.setClassifier(annotation);
}
}
@ -159,6 +160,10 @@ class ParametricCallable implements CommandCallable {
}
}
// Gather legacy flags
anyFlags = definition.anyFlags();
legacyFlags.addAll(Chars.asList(definition.flags().toCharArray()));
// Finish description
description.setDescription(!definition.desc().isEmpty() ? definition.desc() : null);
description.setHelp(!definition.help().isEmpty() ? definition.help() : null);
@ -188,7 +193,6 @@ class ParametricCallable implements CommandCallable {
// Provide help if -? is specified
if (context.hasFlag('?')) {
String title = Joiner.on(" ").join(parentCommands);
throw new InvalidUsageException(null, this, true);
}
@ -314,8 +318,7 @@ class ParametricCallable implements CommandCallable {
CommandContext context = existing.getContext();
if (parameter.isValueFlag()) {
return new StringArgumentStack(
context, context.getFlag(parameter.getFlag()), false);
return new StringArgumentStack(context, context.getFlag(parameter.getFlag()), false);
} else {
String v = context.hasFlag(parameter.getFlag()) ? "true" : "false";
return new StringArgumentStack(context, v, true);
@ -342,19 +345,23 @@ class ParametricCallable implements CommandCallable {
// - Before required parameters: Consume if there are 'left over' args
// - At the end: Always consumes
if (parameter.isOptional() && parameter.getFlag() == null) {
int numberFree = context.argsLength() - scoped.position();
for (int j = i; j < parameters.length; j++) {
if (parameters[j].isNonFlagConsumer() && !parameters[j].isOptional()) {
// We already checked if the consumed count was > -1
// when we created this object
numberFree -= parameters[j].getConsumedCount();
if (parameter.isOptional()) {
if (parameter.getFlag() != null) {
return !parameter.isValueFlag() || context.hasFlag(parameter.getFlag());
} else {
int numberFree = context.argsLength() - scoped.position();
for (int j = i; j < parameters.length; j++) {
if (parameters[j].isNonFlagConsumer() && !parameters[j].isOptional()) {
// We already checked if the consumed count was > -1
// when we created this object
numberFree -= parameters[j].getConsumedCount();
}
}
}
// Skip this optional parameter
if (numberFree < 1) {
return false;
// Skip this optional parameter
if (numberFree < 1) {
return false;
}
}
}
@ -370,17 +377,14 @@ class ParametricCallable implements CommandCallable {
* @throws ParameterException on an error
* @throws CommandException on an error
*/
private Object getDefaultValue(int i, ContextArgumentStack scoped)
throws ParameterException, CommandException, InvocationTargetException {
private Object getDefaultValue(int i, ContextArgumentStack scoped) throws ParameterException, CommandException, InvocationTargetException {
CommandContext context = scoped.getContext();
ParameterData parameter = parameters[i];
String[] defaultValue = parameter.getDefaultValue();
if (defaultValue != null) {
try {
return parameter.getBinding().bind(
parameter, new StringArgumentStack(
context, defaultValue, false), false);
return parameter.getBinding().bind(parameter, new StringArgumentStack(context, defaultValue, false), false);
} catch (MissingParameterException e) {
throw new ParametricException(
"The default value of the parameter using the binding " +
@ -399,8 +403,7 @@ class ParametricCallable implements CommandCallable {
* @param scoped the argument scope
* @throws UnconsumedParameterException thrown if parameters were not consumed
*/
private void checkUnconsumed(ContextArgumentStack scoped)
throws UnconsumedParameterException {
private void checkUnconsumed(ContextArgumentStack scoped) throws UnconsumedParameterException {
CommandContext context = scoped.getContext();
String unconsumed;
String unconsumedFlags = getUnusedFlags(context);
@ -420,33 +423,39 @@ class ParametricCallable implements CommandCallable {
* @param context the command context
*/
private String getUnusedFlags(CommandContext context) {
Set<Character> unusedFlags = null;
for (char flag : context.getFlags()) {
boolean found = false;
if (!anyFlags) {
Set<Character> unusedFlags = null;
for (char flag : context.getFlags()) {
boolean found = false;
for (ParameterData parameter : parameters) {
Character paramFlag = parameter.getFlag();
if (paramFlag != null && flag == paramFlag) {
found = true;
if (legacyFlags.contains(flag)) {
break;
}
}
if (!found) {
if (unusedFlags == null) {
unusedFlags = new HashSet<Character>();
for (ParameterData parameter : parameters) {
Character paramFlag = parameter.getFlag();
if (paramFlag != null && flag == paramFlag) {
found = true;
break;
}
}
unusedFlags.add(flag);
}
}
if (unusedFlags != null) {
StringBuilder builder = new StringBuilder();
for (Character flag : unusedFlags) {
builder.append("-").append(flag).append(" ");
if (!found) {
if (unusedFlags == null) {
unusedFlags = new HashSet<Character>();
}
unusedFlags.add(flag);
}
}
return builder.toString().trim();
if (unusedFlags != null) {
StringBuilder builder = new StringBuilder();
for (Character flag : unusedFlags) {
builder.append("-").append(flag).append(" ");
}
return builder.toString().trim();
}
}
return null;