more block data fixes
This commit is contained in:
parent
ea76cecba3
commit
1d6fef0eee
24 changed files with 46 additions and 48 deletions
|
@ -4,7 +4,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import common.biome.Biome;
|
||||
import common.biome.IBiome;
|
||||
import common.block.Block;
|
||||
import common.block.foliage.LeavesType;
|
||||
import common.collect.Lists;
|
||||
import common.collect.Maps;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package common.item;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
@ -74,10 +73,6 @@ public final class ItemStack
|
|||
Item item = ItemRegistry.REGISTRY.byNameExact(name);
|
||||
return item == null ? def : new ItemStack(item);
|
||||
}
|
||||
|
||||
public static Collection<String> getKeys() {
|
||||
return ItemRegistry.REGISTRY.getKeys();
|
||||
}
|
||||
|
||||
private ItemStack()
|
||||
{
|
||||
|
|
|
@ -85,16 +85,8 @@ public class State {
|
|||
if(state != null)
|
||||
return state;
|
||||
int idx = name.indexOf(",");
|
||||
if(idx >= 0) {
|
||||
Block block = BlockRegistry.REGISTRY.byNameExact(name.substring(0, idx));
|
||||
if(block != null)
|
||||
return block.getState();
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
public static Collection<String> getKeys() {
|
||||
return NAME_MAP.keySet();
|
||||
Block block = BlockRegistry.REGISTRY.byNameExact(idx >= 0 ? name.substring(0, idx) : name);
|
||||
return block != null ? block.getState() : def;
|
||||
}
|
||||
|
||||
public State(Block block, ImmutableMap<Property, Comparable> properties) {
|
||||
|
|
|
@ -87,7 +87,7 @@ public abstract class ArgumentParser {
|
|||
|
||||
public abstract Object parse(CommandEnvironment env, String input);
|
||||
public abstract Object getDefault(CommandEnvironment env);
|
||||
public abstract Collection<String> getCompletions(CommandEnvironment env);
|
||||
public abstract Collection<String> getCompletions(CommandEnvironment env, String last);
|
||||
public abstract Class<?> getTypeClass(boolean required);
|
||||
|
||||
public final String getName() {
|
||||
|
|
|
@ -141,7 +141,7 @@ public record ArgumentSplitter(Map<String, Argument> arguments, String command,
|
|||
if(param.parsers().isEmpty()) // np
|
||||
return null;
|
||||
Iterable<String> custom = exec.getCustomCompletions(env, env.getExecutor(), parsed, param.name(), param.parsers().get(0).getName(), last);
|
||||
return custom != null ? custom : param.parsers().get(0).getCompletions(env);
|
||||
return custom != null ? custom : param.parsers().get(0).getCompletions(env, last);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
|
@ -179,7 +179,7 @@ public record ArgumentSplitter(Map<String, Argument> arguments, String command,
|
|||
for(int n = pos ? 0 : 1; n < nargs + (pos ? 0 : 1); n++) {
|
||||
if(z + n == argv.length - 1) {
|
||||
Iterable<String> custom = exec.getCustomCompletions(env, env.getExecutor(), parsed, param.name(), param.parsers().get(apos).getName(), last);
|
||||
return custom != null ? custom : param.parsers().get(apos).getCompletions(env);
|
||||
return custom != null ? custom : param.parsers().get(apos).getCompletions(env, last);
|
||||
}
|
||||
String par = argv[z + n];
|
||||
if(parse && (par.startsWith("--") || (par.startsWith("-") && par.length() == 2 && (par.charAt(1) < '0' || par.charAt(1) > '9'))))
|
||||
|
|
|
@ -17,7 +17,7 @@ public abstract class CompletingParser extends ArgumentParser {
|
|||
}
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
public Collection<String> getCompletions(CommandEnvironment env, String last) {
|
||||
return this.defCompletions;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public class DimensionParser extends CompletingParser {
|
|||
// throw new ScriptException("Unbekannte Dimension '%s'");
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
public Collection<String> getCompletions(CommandEnvironment env, String last) {
|
||||
return UniverseRegistry.getWorldNames();
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ public class DoubleParser extends DefaultingParser {
|
|||
return this.hasDefault() || required ? double.class : Double.class;
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
public Collection<String> getCompletions(CommandEnvironment env, String last) {
|
||||
BlockPos pos = this.defType == null ? null : env.getExecutor().getPointedPosition();
|
||||
if(this.defType != null)
|
||||
switch(this.defType) {
|
||||
|
@ -97,6 +97,6 @@ public class DoubleParser extends DefaultingParser {
|
|||
case Z:
|
||||
return pos == null ? null : Lists.newArrayList("" + pos.getZ());
|
||||
}
|
||||
return super.getCompletions(env);
|
||||
return super.getCompletions(env, last);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,8 +123,8 @@ public class EntityListParser extends EntityParser {
|
|||
return entity == null ? null : Lists.newArrayList(entity);
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
Collection<String> comp = super.getCompletions(env);
|
||||
public Collection<String> getCompletions(CommandEnvironment env, String last) {
|
||||
Collection<String> comp = super.getCompletions(env, last);
|
||||
if(this.policy != UserPolicy.NO_PLAYERS)
|
||||
comp.add("*");
|
||||
for(Class<? extends Entity> clazz : EntityRegistry.getAllClasses()) {
|
||||
|
|
|
@ -51,10 +51,10 @@ public class EntityParser extends PlayerEntityParser {
|
|||
return this.useSender && (this.livingOnly ? (env.getExecutor() instanceof EntityLiving) : (env.getExecutor() instanceof Entity)) ? env.getExecutor() : super.getDefault(env);
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
public Collection<String> getCompletions(CommandEnvironment env, String last) {
|
||||
Entity target = env.getExecutor().getPointedEntity();
|
||||
List<String> comp = target == null || (this.livingOnly && !(target instanceof EntityLiving)) || (target instanceof EntityNPC && ((EntityNPC)target).isPlayer() && !this.policy.applies(env, env.getExecutor(), (Player)((EntityNPC)target).connection)) ? Lists.newArrayList() : Lists.newArrayList("#" + target.getId());
|
||||
comp.addAll(super.getCompletions(env));
|
||||
comp.addAll(super.getCompletions(env, last));
|
||||
return comp;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ public class IntParser extends DefaultingParser {
|
|||
return this.hasDefault() || required ? int.class : Integer.class;
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
public Collection<String> getCompletions(CommandEnvironment env, String last) {
|
||||
BlockPos pos = this.defType == null ? null : env.getExecutor().getPointedPosition();
|
||||
if(this.defType != null)
|
||||
switch(this.defType) {
|
||||
|
@ -92,6 +92,6 @@ public class IntParser extends DefaultingParser {
|
|||
case Z:
|
||||
return pos == null ? null : Lists.newArrayList("" + pos.getZ());
|
||||
}
|
||||
return super.getCompletions(env);
|
||||
return super.getCompletions(env, last);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,8 +44,8 @@ public class PlayerEntityListParser extends PlayerEntityParser {
|
|||
return entity == null ? null : Lists.newArrayList(entity);
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
Collection<String> comp = Lists.newArrayList(super.getCompletions(env));
|
||||
public Collection<String> getCompletions(CommandEnvironment env, String last) {
|
||||
Collection<String> comp = Lists.newArrayList(super.getCompletions(env, last));
|
||||
comp.add("*");
|
||||
return comp;
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ public class PlayerListParser extends PlayerParser {
|
|||
return net == null ? null : Lists.newArrayList(net);
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
Collection<String> comp = Lists.newArrayList(super.getCompletions(env));
|
||||
public Collection<String> getCompletions(CommandEnvironment env, String last) {
|
||||
Collection<String> comp = Lists.newArrayList(super.getCompletions(env, last));
|
||||
comp.add("*");
|
||||
return comp;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class PlayerParser extends CompletingParser {
|
|||
return this.useSender && env.getExecutor().isPlayer() && this.policy.applies(env, env.getExecutor(), (Player)env.getExecutor()) ? (Player)env.getExecutor() : null;
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
public Collection<String> getCompletions(CommandEnvironment env, String last) {
|
||||
return Filter.filter(env.getServer().getAllPlayerNames(), user -> this.policy.applies(env, env.getExecutor(), env.getServer().getPlayer(user))); // add Lists.newArrayList if modifying!
|
||||
}
|
||||
|
||||
|
|
|
@ -3,5 +3,5 @@ package server.command;
|
|||
import java.util.Collection;
|
||||
|
||||
public interface StringCompleter {
|
||||
Collection<String> complete(CommandEnvironment env);
|
||||
Collection<String> complete(CommandEnvironment env, String last);
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public class StringParser extends DefaultingParser {
|
|||
return String.class;
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
return this.completer != null ? this.completer.complete(env) : super.getCompletions(env);
|
||||
public Collection<String> getCompletions(CommandEnvironment env, String last) {
|
||||
return this.completer != null ? this.completer.complete(env, last) : super.getCompletions(env, last);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public class UserParser extends CompletingParser {
|
|||
return this.useSender && env.getExecutor().isPlayer() && this.policy.applies(env, env.getExecutor(), (Player)env.getExecutor()) ? (Player)env.getExecutor() : null;
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
public Collection<String> getCompletions(CommandEnvironment env, String last) {
|
||||
return Filter.filter(env.getServer().getAllUserNames(), user -> this.policy.applies(env, env.getExecutor(), env.getServer().getUser(user))); // add Lists.newArrayList if modifying!
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ public class WorldParser extends DimensionParser {
|
|||
// return world;
|
||||
}
|
||||
|
||||
public Collection<String> getCompletions(CommandEnvironment env) {
|
||||
public Collection<String> getCompletions(CommandEnvironment env, String last) {
|
||||
if(this.loadedOnly) {
|
||||
List<String> loaded = Lists.newArrayList();
|
||||
for(WorldServer world : env.getServer().getWorlds()) {
|
||||
|
@ -41,7 +41,7 @@ public class WorldParser extends DimensionParser {
|
|||
}
|
||||
return loaded;
|
||||
}
|
||||
return super.getCompletions(env);
|
||||
return super.getCompletions(env, last);
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass(boolean required) {
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
package server.command.commands;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import common.block.Block;
|
||||
import common.collect.Iterables;
|
||||
import common.collect.Lists;
|
||||
import common.init.BlockRegistry;
|
||||
import common.tags.TagObject;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.BlockPos;
|
||||
|
@ -17,8 +22,14 @@ public class CommandBlock extends Command {
|
|||
super("block");
|
||||
|
||||
this.addString("block", false, new StringCompleter() {
|
||||
public Collection<String> complete(CommandEnvironment env) {
|
||||
return State.getKeys();
|
||||
public Collection<String> complete(CommandEnvironment env, String last) {
|
||||
int idx = last.indexOf(',');
|
||||
if(idx >= 0) {
|
||||
Block block = BlockRegistry.REGISTRY.byNameExact(last.substring(0, idx));
|
||||
if(block != null)
|
||||
return Lists.newArrayList(Iterables.transform(block.getValidStates(), state -> state.getId()));
|
||||
}
|
||||
return BlockRegistry.REGISTRY.getKeys();
|
||||
}
|
||||
});
|
||||
this.addBlockPos("position", true);
|
||||
|
|
|
@ -22,7 +22,7 @@ public class CommandHelp extends Command {
|
|||
|
||||
this.setParamsOptional();
|
||||
this.addString("command", false, new StringCompleter() {
|
||||
public Collection<String> complete(CommandEnvironment env) {
|
||||
public Collection<String> complete(CommandEnvironment env, String last) {
|
||||
return env.getExecutables().keySet();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.Collection;
|
|||
import java.util.List;
|
||||
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.init.ItemRegistry;
|
||||
import common.item.ItemStack;
|
||||
import common.tags.TagObject;
|
||||
import server.command.Command;
|
||||
|
@ -18,8 +19,8 @@ public class CommandItem extends Command {
|
|||
super("item");
|
||||
|
||||
this.addString("item", false, new StringCompleter() {
|
||||
public Collection<String> complete(CommandEnvironment env) {
|
||||
return ItemStack.getKeys();
|
||||
public Collection<String> complete(CommandEnvironment env, String last) {
|
||||
return ItemRegistry.REGISTRY.getKeys();
|
||||
}
|
||||
});
|
||||
this.setParamsOptional();
|
||||
|
|
|
@ -19,7 +19,7 @@ public class CommandOfflinetp extends Command {
|
|||
super("offlinetp");
|
||||
|
||||
this.addString("user", false, new StringCompleter() {
|
||||
public Collection<String> complete(CommandEnvironment env) {
|
||||
public Collection<String> complete(CommandEnvironment env, String last) {
|
||||
return env.getServer().getPlayerFilenames();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -20,7 +20,7 @@ public class CommandSv extends Command {
|
|||
|
||||
this.setParamsOptional();
|
||||
this.addString("variable", false, new StringCompleter() {
|
||||
public Collection<String> complete(CommandEnvironment env) {
|
||||
public Collection<String> complete(CommandEnvironment env, String last) {
|
||||
return env.getServer().getVariables().keySet();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -18,7 +18,7 @@ public class CommandWarp extends Command {
|
|||
super("warp");
|
||||
|
||||
this.addString("warp", true, new StringCompleter() {
|
||||
public Collection<String> complete(CommandEnvironment env) {
|
||||
public Collection<String> complete(CommandEnvironment env, String last) {
|
||||
// List<String> warps = Lists.newArrayList("spawn");
|
||||
// warps.addAll(env.getServer().getWarps().keySet());
|
||||
return env.getServer().getWarps().keySet();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue