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,7 +345,10 @@ 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()) {
if (parameter.getFlag() != null) {
return !parameter.isValueFlag() || context.hasFlag(parameter.getFlag());
} else {
int numberFree = context.argsLength() - scoped.position(); int numberFree = context.argsLength() - scoped.position();
for (int j = i; j < parameters.length; j++) { for (int j = i; j < parameters.length; j++) {
if (parameters[j].isNonFlagConsumer() && !parameters[j].isOptional()) { if (parameters[j].isNonFlagConsumer() && !parameters[j].isOptional()) {
@ -357,6 +363,7 @@ class ParametricCallable implements CommandCallable {
return false; return false;
} }
} }
}
return true; return true;
} }
@ -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,10 +423,15 @@ class ParametricCallable implements CommandCallable {
* @param context the command context * @param context the command context
*/ */
private String getUnusedFlags(CommandContext context) { private String getUnusedFlags(CommandContext context) {
if (!anyFlags) {
Set<Character> unusedFlags = null; Set<Character> unusedFlags = null;
for (char flag : context.getFlags()) { for (char flag : context.getFlags()) {
boolean found = false; boolean found = false;
if (legacyFlags.contains(flag)) {
break;
}
for (ParameterData parameter : parameters) { for (ParameterData parameter : parameters) {
Character paramFlag = parameter.getFlag(); Character paramFlag = parameter.getFlag();
if (paramFlag != null && flag == paramFlag) { if (paramFlag != null && flag == paramFlag) {
@ -448,6 +456,7 @@ class ParametricCallable implements CommandCallable {
return builder.toString().trim(); return builder.toString().trim();
} }
}
return null; return null;
} }