use of com.laytonsmith.core.constructs.CInt in project CommandHelper by EngineHub.
the class ArrayHandlingTest method setUp.
@Before
public void setUp() {
fakePlayer = StaticTest.GetOnlinePlayer();
commonArray = new CArray(Target.UNKNOWN, new CInt(1, Target.UNKNOWN), new CInt(2, Target.UNKNOWN), new CInt(3, Target.UNKNOWN));
env.getEnv(CommandHelperEnvironment.class).SetPlayer(fakePlayer);
}
use of com.laytonsmith.core.constructs.CInt in project CommandHelper by EngineHub.
the class Scoreboards method getTeam.
static CArray getTeam(MCTeam team, Target t) {
CArray to = CArray.GetAssociativeArray(t);
to.set("name", new CString(team.getName(), t), t);
to.set("displayname", new CString(team.getDisplayName(), t), t);
to.set("prefix", new CString(team.getPrefix(), t), t);
to.set("suffix", new CString(team.getSuffix(), t), t);
to.set("size", new CInt(team.getSize(), t), t);
CArray ops = CArray.GetAssociativeArray(t);
ops.set("friendlyfire", CBoolean.get(team.allowFriendlyFire()), t);
ops.set("friendlyinvisibles", CBoolean.get(team.canSeeFriendlyInvisibles()), t);
if (Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_8)) {
ops.set("nametagvisibility", new CString(team.getNameTagVisibility().name(), t), t);
}
if (Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_9)) {
ops.set("collisionrule", new CString(team.getOption(MCOption.COLLISION_RULE).name(), t), t);
ops.set("deathmessagevisibility", new CString(team.getOption(MCOption.DEATH_MESSAGE_VISIBILITY).name(), t), t);
}
to.set("options", ops, t);
CArray pl = new CArray(t);
for (String entry : team.getEntries()) {
pl.push(new CString(entry, t), t);
}
to.set("players", pl, t);
return to;
}
use of com.laytonsmith.core.constructs.CInt in project CommandHelper by EngineHub.
the class Interpreter method doBuiltin.
public boolean doBuiltin(String script) {
List<String> args = StringUtils.ArgParser(script);
if (args.size() > 0) {
String command = args.get(0);
args.remove(0);
command = command.toLowerCase(Locale.ENGLISH);
switch(command) {
case "help":
pl(getHelpMsg());
pl("Shell builtins:");
pl("cd <dir> - Runs cd() with the provided argument.");
pl("s - equivalent to cd('..').");
pl("echo - Prints the arguments. If -e is set as the first argument, arguments are sent to colorize() first.");
pl("exit - Exits shellMode, and returns back to normal mscript mode.");
pl("logout - Exits the shell entirely with a return code of 0.");
pl("pwd - Runs pwd()");
pl("help - Prints this message.");
return true;
case "cd":
case "s":
if ("s".equals(command)) {
args.add("..");
}
if (args.size() > 1) {
pl(RED + "Too many arguments passed to cd");
return true;
}
Construct[] a = new Construct[0];
if (args.size() == 1) {
a = new Construct[] { new CString(args.get(0), Target.UNKNOWN) };
}
try {
new Cmdline.cd().exec(Target.UNKNOWN, env, a);
} catch (CREIOException ex) {
pl(RED + ex.getMessage());
}
return true;
case "pwd":
pl(new Cmdline.pwd().exec(Target.UNKNOWN, env).val());
return true;
case "exit":
// We need previous code to intercept, we cannot do this here.
throw new Error("I should not run");
case "logout":
new Cmdline.exit().exec(Target.UNKNOWN, env, new CInt(0, Target.UNKNOWN));
// won't actually run
return true;
case "echo":
// TODO Probably need some variable interpolation maybe? Otherwise, I don't think this command
// is actually useful as is, because this is not supposed to be a scripting environment.. that's
// what the normal shell is for.
boolean colorize = false;
if (args.size() > 0 && "-e".equals(args.get(0))) {
colorize = true;
args.remove(0);
}
String output = StringUtils.Join(args, " ");
if (colorize) {
output = new Echoes.colorize().exec(Target.UNKNOWN, env, new CString(output, Target.UNKNOWN)).val();
}
pl(output);
return true;
}
}
return false;
}
use of com.laytonsmith.core.constructs.CInt in project CommandHelper by EngineHub.
the class ObjectGenerator method fireworkEffect.
public MCFireworkEffect fireworkEffect(CArray fe, Target t) {
MCFireworkBuilder builder = StaticLayer.GetConvertor().GetFireworkBuilder();
if (fe.containsKey("flicker")) {
builder.setFlicker(Static.getBoolean(fe.get("flicker", t), t));
}
if (fe.containsKey("trail")) {
builder.setTrail(Static.getBoolean(fe.get("trail", t), t));
}
if (fe.containsKey("colors")) {
Construct colors = fe.get("colors", t);
if (colors instanceof CArray) {
CArray ccolors = (CArray) colors;
if (ccolors.size() == 0) {
builder.addColor(MCColor.WHITE);
} else {
for (Construct color : ccolors.asList()) {
MCColor mccolor;
if (color instanceof CString) {
mccolor = StaticLayer.GetConvertor().GetColor(color.val(), t);
} else if (color instanceof CArray) {
mccolor = color((CArray) color, t);
} else if (color instanceof CInt && ccolors.size() == 3) {
// Appears to be a single color
builder.addColor(color(ccolors, t));
break;
} else {
throw new CREFormatException("Expecting individual color to be an array or string, but found " + color.typeof(), t);
}
builder.addColor(mccolor);
}
}
} else if (colors instanceof CString) {
String[] split = colors.val().split("\\|");
if (split.length == 0) {
builder.addColor(MCColor.WHITE);
} else {
for (String s : split) {
builder.addColor(StaticLayer.GetConvertor().GetColor(s, t));
}
}
} else {
throw new CREFormatException("Expecting an array or string for colors parameter, but found " + colors.typeof(), t);
}
} else {
builder.addColor(MCColor.WHITE);
}
if (fe.containsKey("fade")) {
Construct colors = fe.get("fade", t);
if (colors instanceof CArray) {
CArray ccolors = (CArray) colors;
for (Construct color : ccolors.asList()) {
MCColor mccolor;
if (color instanceof CArray) {
mccolor = color((CArray) color, t);
} else if (color instanceof CString) {
mccolor = StaticLayer.GetConvertor().GetColor(color.val(), t);
} else if (color instanceof CInt && ccolors.size() == 3) {
// Appears to be a single color
builder.addFadeColor(color(ccolors, t));
break;
} else {
throw new CREFormatException("Expecting individual color to be an array or string, but found " + color.typeof(), t);
}
builder.addFadeColor(mccolor);
}
} else if (colors instanceof CString) {
String[] split = colors.val().split("\\|");
for (String s : split) {
builder.addFadeColor(StaticLayer.GetConvertor().GetColor(s, t));
}
} else {
throw new CREFormatException("Expecting an array or string for fade parameter, but found " + colors.typeof(), t);
}
}
if (fe.containsKey("type")) {
try {
builder.setType(MCFireworkType.valueOf(fe.get("type", t).val().toUpperCase()));
} catch (IllegalArgumentException ex) {
throw new CREFormatException(ex.getMessage(), t, ex);
}
}
return builder.build();
}
use of com.laytonsmith.core.constructs.CInt in project CommandHelper by EngineHub.
the class ObjectGenerator method itemMeta.
public Construct itemMeta(MCItemStack is, Target t) {
if (!is.hasItemMeta()) {
return CNull.NULL;
} else {
Construct display, lore;
CArray ma = CArray.GetAssociativeArray(t);
MCItemMeta meta = is.getItemMeta();
if (meta.hasDisplayName()) {
display = new CString(meta.getDisplayName(), t);
} else {
display = CNull.NULL;
}
if (meta.hasLore()) {
lore = new CArray(t);
for (String l : meta.getLore()) {
((CArray) lore).push(new CString(l, t), t);
}
} else {
lore = CNull.NULL;
}
ma.set("display", display, t);
ma.set("lore", lore, t);
ma.set("enchants", enchants(meta.getEnchants(), t), t);
ma.set("repair", new CInt(meta.getRepairCost(), t), t);
// Version specific ItemMeta
if (Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_8)) {
Set<MCItemFlag> itemFlags = meta.getItemFlags();
CArray flagArray = new CArray(t);
if (itemFlags.size() > 0) {
for (MCItemFlag flag : itemFlags) {
flagArray.push(new CString(flag.name(), t), t);
}
}
ma.set("flags", flagArray, t);
if (Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_11)) {
ma.set("unbreakable", CBoolean.get(meta.isUnbreakable()), t);
}
}
// Specific ItemMeta
if (meta instanceof MCBlockStateMeta) {
MCBlockState bs = ((MCBlockStateMeta) meta).getBlockState();
if (bs instanceof MCShulkerBox) {
MCShulkerBox mcsb = (MCShulkerBox) bs;
MCInventory inv = mcsb.getInventory();
CArray box = CArray.GetAssociativeArray(t);
for (int i = 0; i < inv.getSize(); i++) {
Construct item = ObjectGenerator.GetGenerator().item(inv.getItem(i), t);
if (!(item instanceof CNull)) {
box.set(i, item, t);
}
}
ma.set("inventory", box, t);
} else if (bs instanceof MCBanner) {
MCBanner banner = (MCBanner) bs;
CArray patterns = new CArray(t, banner.numberOfPatterns());
for (MCPattern p : banner.getPatterns()) {
CArray pattern = CArray.GetAssociativeArray(t);
pattern.set("shape", new CString(p.getShape().toString(), t), t);
pattern.set("color", new CString(p.getColor().toString(), t), t);
patterns.push(pattern, t);
}
ma.set("patterns", patterns, t);
MCDyeColor dyeColor = banner.getBaseColor();
if (dyeColor != null) {
ma.set("basecolor", new CString(dyeColor.toString(), t), t);
}
} else if (bs instanceof MCCreatureSpawner) {
MCCreatureSpawner mccs = (MCCreatureSpawner) bs;
ma.set("spawntype", mccs.getSpawnedType().name());
}
} else if (meta instanceof MCFireworkEffectMeta) {
MCFireworkEffectMeta mcfem = (MCFireworkEffectMeta) meta;
MCFireworkEffect effect = mcfem.getEffect();
if (effect == null) {
ma.set("effect", CNull.NULL, t);
} else {
ma.set("effect", fireworkEffect(effect, t), t);
}
} else if (meta instanceof MCFireworkMeta) {
MCFireworkMeta mcfm = (MCFireworkMeta) meta;
CArray firework = CArray.GetAssociativeArray(t);
firework.set("strength", new CInt(mcfm.getStrength(), t), t);
CArray fe = new CArray(t);
for (MCFireworkEffect effect : mcfm.getEffects()) {
fe.push(fireworkEffect(effect, t), t);
}
firework.set("effects", fe, t);
ma.set("firework", firework, t);
} else if (meta instanceof MCLeatherArmorMeta) {
CArray color = color(((MCLeatherArmorMeta) meta).getColor(), t);
ma.set("color", color, t);
} else if (meta instanceof MCBookMeta) {
Construct title, author, pages;
if (((MCBookMeta) meta).hasTitle()) {
title = new CString(((MCBookMeta) meta).getTitle(), t);
} else {
title = CNull.NULL;
}
if (((MCBookMeta) meta).hasAuthor()) {
author = new CString(((MCBookMeta) meta).getAuthor(), t);
} else {
author = CNull.NULL;
}
if (((MCBookMeta) meta).hasPages()) {
pages = new CArray(t);
for (String p : ((MCBookMeta) meta).getPages()) {
((CArray) pages).push(new CString(p, t), t);
}
} else {
pages = CNull.NULL;
}
ma.set("title", title, t);
ma.set("author", author, t);
ma.set("pages", pages, t);
} else if (meta instanceof MCSkullMeta) {
if (Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_12_X)) {
if (((MCSkullMeta) meta).hasOwner()) {
MCOfflinePlayer player = ((MCSkullMeta) meta).getOwningPlayer();
ma.set("owner", new CString(player.getName(), t), t);
ma.set("owneruuid", new CString(player.getUniqueID().toString(), t), t);
} else {
ma.set("owner", CNull.NULL, t);
ma.set("owneruuid", CNull.NULL, t);
}
} else {
if (((MCSkullMeta) meta).hasOwner()) {
ma.set("owner", new CString(((MCSkullMeta) meta).getOwner(), t), t);
} else {
ma.set("owner", CNull.NULL, t);
}
}
} else if (meta instanceof MCEnchantmentStorageMeta) {
Construct stored;
if (((MCEnchantmentStorageMeta) meta).hasStoredEnchants()) {
stored = enchants(((MCEnchantmentStorageMeta) meta).getStoredEnchants(), t);
} else {
stored = CNull.NULL;
}
ma.set("stored", stored, t);
} else if (meta instanceof MCPotionMeta) {
MCPotionMeta potionmeta = (MCPotionMeta) meta;
CArray effects = potions(potionmeta.getCustomEffects(), t);
ma.set("potions", effects, t);
if (Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_9)) {
MCPotionData potiondata = potionmeta.getBasePotionData();
if (potiondata != null) {
ma.set("base", potionData(potiondata, t), t);
}
} else if (effects.size() > 0) {
ma.set("main", ((CArray) effects.get(0, t)).get("id", t), t);
}
} else if (meta instanceof MCBannerMeta) {
MCBannerMeta bannermeta = (MCBannerMeta) meta;
CArray patterns = new CArray(t, bannermeta.numberOfPatterns());
for (MCPattern p : bannermeta.getPatterns()) {
CArray pattern = CArray.GetAssociativeArray(t);
pattern.set("shape", new CString(p.getShape().toString(), t), t);
pattern.set("color", new CString(p.getColor().toString(), t), t);
patterns.push(pattern, t);
}
ma.set("patterns", patterns, t);
MCDyeColor dyeColor = bannermeta.getBaseColor();
if (dyeColor != null) {
ma.set("basecolor", new CString(dyeColor.toString(), t), t);
}
} else if (meta instanceof MCSpawnEggMeta) {
MCEntityType spawntype = ((MCSpawnEggMeta) meta).getSpawnedType();
if (spawntype == null) {
ma.set("spawntype", CNull.NULL, t);
} else {
ma.set("spawntype", new CString(spawntype.name(), t), t);
}
} else if (meta instanceof MCMapMeta && Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_11)) {
MCColor mapcolor = ((MCMapMeta) meta).getColor();
Construct color;
if (mapcolor == null) {
color = CNull.NULL;
} else {
color = color(mapcolor, t);
}
ma.set("color", color, t);
}
return ma;
}
}
Aggregations