Search in sources :

Example 21 with CString

use of com.laytonsmith.core.constructs.CString in project CommandHelper by EngineHub.

the class ProcKeyword method process.

@Override
public int process(List<ParseTree> list, int keywordPosition) throws ConfigCompileException {
    if (list.get(keywordPosition).getData() instanceof CKeyword) {
        // It's a lone keyword, so we expect some function to follow, which is the proc name + variables
        if (list.get(keywordPosition + 1).getData() instanceof CFunction) {
            ParseTree proc = new ParseTree(new CFunction(PROC, list.get(keywordPosition).getTarget()), list.get(keywordPosition).getFileOptions());
            proc.addChild(new ParseTree(new CString(list.get(keywordPosition + 1).getData().val(), list.get(keywordPosition + 1).getTarget()), list.get(keywordPosition + 1).getFileOptions()));
            // Grab the functions children, and put them on the stack
            for (ParseTree child : list.get(keywordPosition + 1).getChildren()) {
                proc.addChild(child);
            }
            if (list.size() > keywordPosition + 2) {
                validateCodeBlock(list.get(keywordPosition + 2), "Expected braces to follow proc definition");
                proc.addChild(getArgumentOrNull(list.get(keywordPosition + 2)));
            } else {
                throw new ConfigCompileException("Expected braces to follow proc definition", list.get(keywordPosition + 1).getTarget());
            }
            // Remove the keyword
            list.remove(keywordPosition);
            // Remove the function definition
            list.remove(keywordPosition);
            // Remove the cbrace
            list.remove(keywordPosition);
            // Add in the new proc definition
            list.add(keywordPosition, proc);
        } else {
            throw new ConfigCompileException("Unexpected use of \"proc\" keyword", list.get(keywordPosition).getTarget());
        }
    } else if (nodeIsProcFunction(list.get(keywordPosition))) {
        // It's the functional usage, possibly followed by a cbrace. If so, pull the cbrace in, and that's it
        if (list.size() > keywordPosition + 1) {
            if (isValidCodeBlock(list.get(keywordPosition + 1))) {
                list.get(keywordPosition).addChild(getArgumentOrNull(list.get(keywordPosition + 1)));
                list.remove(keywordPosition + 1);
            }
        }
    } else {
        // Random keyword in the middle of nowhere
        throw new ConfigCompileException("Unexpected use of \"proc\" keyword", list.get(keywordPosition).getTarget());
    }
    return keywordPosition;
}
Also used : CFunction(com.laytonsmith.core.constructs.CFunction) CKeyword(com.laytonsmith.core.constructs.CKeyword) ConfigCompileException(com.laytonsmith.core.exceptions.ConfigCompileException) ParseTree(com.laytonsmith.core.ParseTree) CString(com.laytonsmith.core.constructs.CString)

Example 22 with CString

use of com.laytonsmith.core.constructs.CString in project CommandHelper by EngineHub.

the class EventUtils method DumpEvents.

public static Construct DumpEvents() {
    CArray ca = new CArray(Target.UNKNOWN);
    for (SortedSet<BoundEvent> set : event_handles.values()) {
        Iterator<BoundEvent> i = set.iterator();
        while (i.hasNext()) {
            BoundEvent b = i.next();
            ca.push(new CString(b.toString() + ":" + b.getFile() + ":" + b.getLineNum(), Target.UNKNOWN), Target.UNKNOWN);
        }
    }
    return ca;
}
Also used : CArray(com.laytonsmith.core.constructs.CArray) CString(com.laytonsmith.core.constructs.CString)

Example 23 with CString

use of com.laytonsmith.core.constructs.CString in project CommandHelper by EngineHub.

the class BukkitMCWorld method spawnMob.

@Override
public CArray spawnMob(MCMobs name, String subClass, int qty, MCLocation l, Target t) {
    Class mobType = null;
    CArray ids = new CArray(t);
    Location location = (Location) l.getHandle();
    MCVersion version = Static.getServer().getMinecraftVersion();
    String[] subTypes = subClass.toUpperCase().split("-");
    try {
        switch(name) {
            case BAT:
                mobType = Bat.class;
                break;
            case BLAZE:
                mobType = Blaze.class;
                break;
            case CAVESPIDER:
                mobType = CaveSpider.class;
                break;
            case CHICKEN:
                mobType = Chicken.class;
                break;
            case COW:
                mobType = Cow.class;
                break;
            case CREEPER:
                mobType = Creeper.class;
                break;
            case ELDERGUARDIAN:
                mobType = ElderGuardian.class;
                break;
            case ENDERDRAGON:
                mobType = EnderDragon.class;
                break;
            case ENDERMAN:
                mobType = Enderman.class;
                break;
            case ENDERMITE:
                mobType = Endermite.class;
                break;
            case EVOKER:
                mobType = Evoker.class;
                break;
            case GHAST:
                mobType = Ghast.class;
                break;
            case GUARDIAN:
                mobType = Guardian.class;
                break;
            case GIANT:
                mobType = Giant.class;
                break;
            case HORSE:
                mobType = Horse.class;
                if (!(subClass.isEmpty()) && version.gte(MCVersion.MC1_11)) {
                    for (String type : subTypes) {
                        try {
                            MCHorse.MCHorseVariant htype = MCHorse.MCHorseVariant.valueOf(type);
                            switch(htype) {
                                case DONKEY:
                                    mobType = Donkey.class;
                                    break;
                                case MULE:
                                    mobType = Mule.class;
                                    break;
                                case SKELETON:
                                    mobType = SkeletonHorse.class;
                                    break;
                                case ZOMBIE:
                                    mobType = ZombieHorse.class;
                                    break;
                            }
                            subClass = "";
                            break;
                        } catch (IllegalArgumentException notVar) {
                        // not variant
                        }
                    }
                }
                break;
            case ILLUSIONER:
                mobType = Illusioner.class;
                break;
            case IRONGOLEM:
                mobType = IronGolem.class;
                break;
            case LLAMA:
                mobType = Llama.class;
                break;
            case MAGMACUBE:
                mobType = MagmaCube.class;
                break;
            case MOOSHROOM:
                mobType = MushroomCow.class;
                break;
            case OCELOT:
                mobType = Ocelot.class;
                break;
            case PARROT:
                mobType = Parrot.class;
                break;
            case PIG:
                mobType = Pig.class;
                break;
            case PIGZOMBIE:
                mobType = PigZombie.class;
                break;
            case POLARBEAR:
                mobType = PolarBear.class;
                break;
            case RABBIT:
                mobType = Rabbit.class;
                break;
            case SHEEP:
                mobType = Sheep.class;
                break;
            case SHULKER:
                mobType = Shulker.class;
                break;
            case SILVERFISH:
                mobType = Silverfish.class;
                break;
            case SKELETON:
                mobType = Skeleton.class;
                if (!(subClass.isEmpty()) && version.gte(MCVersion.MC1_11)) {
                    MCSkeletonType stype = MCSkeletonType.NORMAL;
                    for (String type : subTypes) {
                        try {
                            stype = MCSkeletonType.valueOf(type);
                        } catch (IllegalArgumentException ex) {
                            throw new CREFormatException(type + " is not a skeleton type", t);
                        }
                    }
                    if (stype == MCSkeletonType.WITHER) {
                        mobType = WitherSkeleton.class;
                    } else if (stype == MCSkeletonType.STRAY) {
                        mobType = Stray.class;
                    }
                    subClass = "";
                }
                break;
            case SLIME:
                mobType = Slime.class;
                break;
            case SNOWGOLEM:
                mobType = Snowman.class;
                break;
            case SPIDER:
                mobType = Spider.class;
                break;
            case SPIDERJOCKEY:
                mobType = Spider.class;
                break;
            case SQUID:
                mobType = Squid.class;
                break;
            case VEX:
                mobType = Vex.class;
                break;
            case VILLAGER:
                mobType = Villager.class;
                break;
            case VINDICATOR:
                mobType = Vindicator.class;
                break;
            case WITCH:
                mobType = Witch.class;
                break;
            case WITHER:
                mobType = Wither.class;
                break;
            case WOLF:
                mobType = Wolf.class;
                break;
            case ZOMBIE:
                mobType = Zombie.class;
                if (!subClass.isEmpty() && version.gte(MCVersion.MC1_11)) {
                    for (int i = 0; i < subTypes.length; i++) {
                        try {
                            MCZombieType ztype = MCZombieType.valueOf(subTypes[i]);
                            switch(ztype) {
                                case HUSK:
                                    mobType = Husk.class;
                                case BABY:
                                    continue;
                                case VILLAGER_BLACKSMITH:
                                    subTypes[i] = "BLACKSMITH";
                                    break;
                                case VILLAGER_BUTCHER:
                                    subTypes[i] = "BUTCHER";
                                    break;
                                case VILLAGER_LIBRARIAN:
                                    subTypes[i] = "LIBRARIAN";
                                    break;
                                case VILLAGER_PRIEST:
                                    subTypes[i] = "PRIEST";
                                    break;
                                case VILLAGER:
                                    subTypes[i] = "FARMER";
                                    break;
                            }
                            mobType = ZombieVillager.class;
                        } catch (IllegalArgumentException ex) {
                        // not a ZombieType
                        }
                    }
                }
                break;
        }
    } catch (NoClassDefFoundError e) {
        throw new CREFormatException("No mob of type " + name + " exists", t);
    }
    for (int i = 0; i < qty; i++) {
        Entity e = w.spawn(location, mobType);
        if (name == MCMobs.SPIDERJOCKEY) {
            e.setPassenger(w.spawn(location, Skeleton.class));
        }
        if (!subClass.isEmpty()) {
            // if subClass is blank, none of this needs to run at all
            if (e instanceof Sheep) {
                Sheep s = (Sheep) e;
                MCDyeColor color;
                for (String type : subTypes) {
                    try {
                        color = MCDyeColor.valueOf(type);
                        s.setColor(BukkitMCDyeColor.getConvertor().getConcreteEnum(color));
                    } catch (IllegalArgumentException ex) {
                        throw new CREFormatException(type + " is not a valid color", t);
                    }
                }
            } else if (e instanceof Ocelot) {
                Ocelot o = (Ocelot) e;
                MCOcelotType otype;
                for (String type : subTypes) {
                    try {
                        otype = MCOcelotType.valueOf(type);
                        o.setCatType(BukkitMCOcelotType.getConvertor().getConcreteEnum(otype));
                    } catch (IllegalArgumentException ex) {
                        throw new CREFormatException(type + " is not an ocelot type", t);
                    }
                }
            } else if (e instanceof Creeper) {
                Creeper c = (Creeper) e;
                for (String type : subTypes) {
                    try {
                        MCCreeperType ctype = MCCreeperType.valueOf(type);
                        switch(ctype) {
                            case POWERED:
                                c.setPowered(true);
                                break;
                            default:
                                break;
                        }
                    } catch (IllegalArgumentException ex) {
                        throw new CREFormatException(type + " is not a creeper state", t);
                    }
                }
            } else if (e instanceof Wolf) {
                Wolf w = (Wolf) e;
                for (String type : subTypes) {
                    try {
                        MCWolfType wtype = MCWolfType.valueOf(type);
                        switch(wtype) {
                            case ANGRY:
                                w.setAngry(true);
                                break;
                            case TAMED:
                                w.setTamed(true);
                                break;
                            default:
                                break;
                        }
                    } catch (IllegalArgumentException ex) {
                        throw new CREFormatException(type + " is not a wolf state", t);
                    }
                }
            } else if (e instanceof Villager) {
                Villager v = (Villager) e;
                MCProfession job;
                for (String type : subTypes) {
                    try {
                        job = MCProfession.valueOf(type);
                        v.setProfession(BukkitMCProfession.getConvertor().getConcreteEnum(job));
                    } catch (IllegalArgumentException ex) {
                        throw new CREFormatException(type + " is not a valid profession", t);
                    }
                }
            } else if (e instanceof Enderman) {
                Enderman en = (Enderman) e;
                for (String type : subTypes) {
                    try {
                        MaterialData held = new MaterialData(Material.valueOf(type));
                        en.setCarriedMaterial(held);
                    } catch (IllegalArgumentException ex) {
                        throw new CREFormatException(type + " is not a valid material", t);
                    }
                }
            } else if (e instanceof Slime) {
                Slime sl = (Slime) e;
                for (String type : subTypes) {
                    if (!"".equals(type)) {
                        try {
                            sl.setSize(Integer.parseInt(type));
                        } catch (IllegalArgumentException ex) {
                            throw new CREFormatException(type + " is not a valid size", t);
                        }
                    }
                }
            } else if (e instanceof Skeleton) {
                Skeleton sk = (Skeleton) e;
                for (String type : subTypes) {
                    try {
                        sk.setSkeletonType(Skeleton.SkeletonType.valueOf(type));
                    } catch (IllegalArgumentException ex) {
                        throw new CREFormatException(type + " is not a skeleton type", t);
                    }
                }
            } else if (e instanceof Zombie) {
                if (e instanceof PigZombie) {
                    PigZombie pz = (PigZombie) e;
                    for (String value : subTypes) {
                        if (value.equals("BABY")) {
                            pz.setBaby(true);
                            continue;
                        }
                        try {
                            pz.setAnger(Integer.valueOf(value));
                        } catch (IllegalArgumentException iae) {
                            throw new CREFormatException(value + " is not a number.", t);
                        }
                    }
                } else if (version.gte(MCVersion.MC1_11) && e instanceof ZombieVillager) {
                    ZombieVillager zv = (ZombieVillager) e;
                    for (String type : subTypes) {
                        if (type.equals("BABY")) {
                            zv.setBaby(true);
                            continue;
                        }
                        try {
                            MCProfession job = MCProfession.valueOf(type);
                            zv.setVillagerProfession(BukkitMCProfession.getConvertor().getConcreteEnum(job));
                        } catch (IllegalArgumentException ex) {
                            throw new CREFormatException(type + " is not a valid profession", t);
                        }
                    }
                } else {
                    Zombie z = (Zombie) e;
                    for (String type : subTypes) {
                        try {
                            MCZombieType ztype = MCZombieType.valueOf(type);
                            switch(ztype) {
                                case BABY:
                                    z.setBaby(true);
                                    break;
                                case VILLAGER:
                                    z.setVillager(true);
                                    break;
                                case VILLAGER_BLACKSMITH:
                                case VILLAGER_BUTCHER:
                                case VILLAGER_LIBRARIAN:
                                case VILLAGER_PRIEST:
                                    if (version.gte(MCVersion.MC1_9)) {
                                        // < MC 1.11
                                        z.setVillagerProfession(Villager.Profession.valueOf(type.substring(9).toUpperCase()));
                                    } else {
                                        z.setVillager(true);
                                    }
                                    break;
                                case HUSK:
                                    if (version.gte(MCVersion.MC1_10) && version.lt(MCVersion.MC1_11)) {
                                        z.setVillagerProfession(Villager.Profession.HUSK);
                                    }
                                    break;
                            }
                        } catch (IllegalArgumentException ex) {
                            throw new CREFormatException(type + " is not a zombie state", t);
                        }
                    }
                }
            } else if (e instanceof Pig) {
                Pig p = (Pig) e;
                for (String type : subTypes) {
                    try {
                        MCPigType ptype = MCPigType.valueOf(type);
                        switch(ptype) {
                            case SADDLED:
                                p.setSaddle(true);
                                break;
                            default:
                                break;
                        }
                    } catch (IllegalArgumentException ex) {
                        throw new CREFormatException(type + " is not a pig state", t);
                    }
                }
            } else if (e instanceof Horse) {
                Horse h = (Horse) e;
                for (String type : subTypes) {
                    if (version.lt(MCVersion.MC1_11)) {
                        try {
                            MCHorse.MCHorseVariant htype = MCHorse.MCHorseVariant.valueOf(type);
                            h.setVariant(BukkitMCHorse.BukkitMCHorseVariant.getConvertor().getConcreteEnum(htype));
                            // no other variants can have colors or patterns
                            break;
                        } catch (IllegalArgumentException ex) {
                        // not variant
                        }
                    }
                    try {
                        MCHorse.MCHorseColor hcolor = MCHorse.MCHorseColor.valueOf(type);
                        h.setColor(BukkitMCHorse.BukkitMCHorseColor.getConvertor().getConcreteEnum(hcolor));
                        continue;
                    } catch (IllegalArgumentException ex) {
                    // not color
                    }
                    try {
                        MCHorse.MCHorsePattern hpattern = MCHorse.MCHorsePattern.valueOf(type);
                        h.setStyle(BukkitMCHorse.BukkitMCHorsePattern.getConvertor().getConcreteEnum(hpattern));
                    } catch (IllegalArgumentException notAnything) {
                        throw new CREFormatException("Type " + type + " did not match any horse variants," + " colors, or patterns.", t);
                    }
                }
            }
        }
        ids.push(new CString(e.getUniqueId().toString(), t), t);
    }
    return ids;
}
Also used : BukkitMCLivingEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCLivingEntity) BukkitMCEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCEntity) MCLivingEntity(com.laytonsmith.abstraction.MCLivingEntity) MCEntity(com.laytonsmith.abstraction.MCEntity) CArray(com.laytonsmith.core.constructs.CArray) BukkitMCProfession(com.laytonsmith.abstraction.enums.bukkit.BukkitMCProfession) CString(com.laytonsmith.core.constructs.CString) CString(com.laytonsmith.core.constructs.CString) BukkitMCDyeColor(com.laytonsmith.abstraction.enums.bukkit.BukkitMCDyeColor) BukkitMCHorse(com.laytonsmith.abstraction.bukkit.entities.BukkitMCHorse) MCHorse(com.laytonsmith.abstraction.entities.MCHorse) BukkitMCHorse(com.laytonsmith.abstraction.bukkit.entities.BukkitMCHorse) MCHorse(com.laytonsmith.abstraction.entities.MCHorse) BukkitMCOcelotType(com.laytonsmith.abstraction.enums.bukkit.BukkitMCOcelotType) MaterialData(org.bukkit.material.MaterialData) CREFormatException(com.laytonsmith.core.exceptions.CRE.CREFormatException) Location(org.bukkit.Location) MCLocation(com.laytonsmith.abstraction.MCLocation)

Example 24 with CString

use of com.laytonsmith.core.constructs.CString in project CommandHelper by EngineHub.

the class EntityEvents method parseEntityDamageEvent.

public static Map<String, Construct> parseEntityDamageEvent(MCEntityDamageEvent event, Map<String, Construct> map) {
    if (event != null) {
        MCEntity victim = event.getEntity();
        map.put("type", new CString(victim.getType().name(), Target.UNKNOWN));
        map.put("id", new CString(victim.getUniqueId().toString(), Target.UNKNOWN));
        map.put("cause", new CString(event.getCause().name(), Target.UNKNOWN));
        map.put("amount", new CDouble(event.getDamage(), Target.UNKNOWN));
        map.put("finalamount", new CDouble(event.getFinalDamage(), Target.UNKNOWN));
        map.put("world", new CString(event.getEntity().getWorld().getName(), Target.UNKNOWN));
        map.put("location", ObjectGenerator.GetGenerator().location(event.getEntity().getLocation()));
        if (event instanceof MCEntityDamageByEntityEvent) {
            MCEntity damager = ((MCEntityDamageByEntityEvent) event).getDamager();
            if (damager instanceof MCPlayer) {
                map.put("damager", new CString(((MCPlayer) damager).getName(), Target.UNKNOWN));
            } else {
                map.put("damager", new CString(damager.getUniqueId().toString(), Target.UNKNOWN));
            }
            if (damager instanceof MCProjectile) {
                MCProjectileSource shooter = ((MCProjectile) damager).getShooter();
                if (shooter instanceof MCPlayer) {
                    map.put("shooter", new CString(((MCPlayer) shooter).getName(), Target.UNKNOWN));
                } else if (shooter instanceof MCEntity) {
                    map.put("shooter", new CString(((MCEntity) shooter).getUniqueId().toString(), Target.UNKNOWN));
                } else if (shooter instanceof MCBlockProjectileSource) {
                    map.put("shooter", ObjectGenerator.GetGenerator().location(((MCBlockProjectileSource) shooter).getBlock().getLocation()));
                }
            }
        }
    }
    return map;
}
Also used : MCBlockProjectileSource(com.laytonsmith.abstraction.blocks.MCBlockProjectileSource) MCEntityDamageByEntityEvent(com.laytonsmith.abstraction.events.MCEntityDamageByEntityEvent) MCEntity(com.laytonsmith.abstraction.MCEntity) MCPlayer(com.laytonsmith.abstraction.MCPlayer) CDouble(com.laytonsmith.core.constructs.CDouble) CString(com.laytonsmith.core.constructs.CString) MCProjectile(com.laytonsmith.abstraction.MCProjectile) MCProjectileSource(com.laytonsmith.abstraction.MCProjectileSource)

Example 25 with CString

use of com.laytonsmith.core.constructs.CString 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;
}
Also used : CInt(com.laytonsmith.core.constructs.CInt) CArray(com.laytonsmith.core.constructs.CArray) CString(com.laytonsmith.core.constructs.CString) CString(com.laytonsmith.core.constructs.CString)

Aggregations

CString (com.laytonsmith.core.constructs.CString)34 CArray (com.laytonsmith.core.constructs.CArray)23 Construct (com.laytonsmith.core.constructs.Construct)19 CInt (com.laytonsmith.core.constructs.CInt)12 HashMap (java.util.HashMap)10 IVariable (com.laytonsmith.core.constructs.IVariable)9 ConfigRuntimeException (com.laytonsmith.core.exceptions.ConfigRuntimeException)9 Map (java.util.Map)8 CDouble (com.laytonsmith.core.constructs.CDouble)7 CNull (com.laytonsmith.core.constructs.CNull)7 Variable (com.laytonsmith.core.constructs.Variable)6 CBoolean (com.laytonsmith.core.constructs.CBoolean)5 CFunction (com.laytonsmith.core.constructs.CFunction)5 Target (com.laytonsmith.core.constructs.Target)5 CREFormatException (com.laytonsmith.core.exceptions.CRE.CREFormatException)5 ConfigCompileException (com.laytonsmith.core.exceptions.ConfigCompileException)5 FunctionReturnException (com.laytonsmith.core.exceptions.FunctionReturnException)5 ArrayList (java.util.ArrayList)5 MCItemStack (com.laytonsmith.abstraction.MCItemStack)4 ParseTree (com.laytonsmith.core.ParseTree)4