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

View File

@ -375,9 +375,9 @@ public class UtilityCommands {
) )
@CommandPermissions("worldedit.butcher") @CommandPermissions("worldedit.butcher")
@Logging(PLACEMENT) @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(); 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 // technically the default can be larger than the max, but that's not my problem
int radius = config.butcherDefaultRadius; int radius = config.butcherDefaultRadius;
@ -407,6 +407,7 @@ public class UtilityCommands {
int killed; int killed;
if (player != null) { if (player != null) {
LocalSession session = we.getSessionManager().get(player);
killed = player.getWorld().killMobs(session.getPlacementPosition(player), radius, flags.flags); killed = player.getWorld().killMobs(session.getPlacementPosition(player), radius, flags.flags);
} else { } else {
killed = 0; killed = 0;

View File

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