Search in sources :

Example 1 with SharedLangData

use of pw.codehusky.huskycrates.lang.SharedLangData in project HuskyCrates-Sponge by codeHusky.

the class CrateRewardHolderParser method fromConfig.

public static CrateRewardHolder fromConfig(ConfigurationNode holderNode, VirtualCrate vc) {
    ItemStack dispItem = itemFromNode(holderNode);
    CrateReward reward = new CrateReward(null, "CODE ERROR, CONTACT DEVELOPER", false);
    boolean dispAwardSimilar = false;
    String name;
    boolean single = false;
    SharedLangData langData = HuskyCrates.instance.langData;
    if (!holderNode.getNode("huskydata", "lang").isVirtual()) {
        langData = new SharedLangData(vc.langData, holderNode.getNode("huskydata", "lang"));
    }
    //System.out.println(dispItem.get(Keys.DISPLAY_NAME));
    if (holderNode.getNode("huskydata", "reward").getNode("overrideRewardName").isVirtual()) {
        //System.out.println("Virtual");
        if (dispItem.get(Keys.DISPLAY_NAME).isPresent()) {
            name = dispItem.get(Keys.DISPLAY_NAME).get().toPlain();
        } else {
            name = dispItem.getItem().getName();
        }
    } else {
        //System.out.println("Real");
        name = holderNode.getNode("huskydata", "reward").getNode("overrideRewardName").getString("strings, please.");
    }
    if (!holderNode.getNode("huskydata", "reward").getNode("treatAsSingle").isVirtual()) {
        single = holderNode.getNode("huskydata", "reward").getNode("treatAsSingle").getBoolean();
    }
    if (holderNode.getNode("huskydata", "reward", "type").getString().equalsIgnoreCase("item")) {
        ItemStack rewardItem;
        if (holderNode.getNode("huskydata", "reward").getNode("overrideItem").isVirtual()) {
            ItemStack rr = dispItem.copy();
            if (!holderNode.getNode("huskydata", "reward").getNode("overrideCount").isVirtual()) {
                rr.setQuantity(holderNode.getNode("huskydata", "reward").getNode("overrideCount").getInt());
            }
            reward = new CrateReward(rr, name, single);
            dispAwardSimilar = true;
        } else {
            reward = new CrateReward(itemFromNode(holderNode.getNode("huskydata", "reward", "overrideItem")), name, single);
        }
    } else if (holderNode.getNode("huskydata", "reward", "type").getString().equalsIgnoreCase("command")) {
        reward = new CrateReward(holderNode.getNode("huskydata", "reward", "command").getString("/say You didn't set a command or something..."), name, single);
    } else {
        System.out.println("?! Invalid Reward Type !? " + holderNode.getNode("huskydata", "reward", "type").getString());
    }
    return new CrateRewardHolder(dispItem, reward, holderNode.getNode("huskydata", "weight").getDouble(1), dispAwardSimilar, langData);
}
Also used : SharedLangData(pw.codehusky.huskycrates.lang.SharedLangData) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 2 with SharedLangData

use of pw.codehusky.huskycrates.lang.SharedLangData in project HuskyCrates-Sponge by codeHusky.

the class HuskyCrates method gameReloaded.

@Listener
public void gameReloaded(GameReloadEvent event) {
    for (World bit : Sponge.getServer().getWorlds()) {
        for (Entity ent : bit.getEntities()) {
            if (ent instanceof ArmorStand) {
                ArmorStand arm = (ArmorStand) ent;
                if (arm.getCreator().isPresent()) {
                    if (arm.getCreator().get().equals(UUID.fromString(armorStandIdentifier))) {
                        arm.remove();
                    }
                }
            }
        }
    }
    langData = new SharedLangData("", "You won %a %R&rfrom a %C&r!", "&e%p just won %a %R&r&e from a %C&r!", "You need a %K&r to open this crate.");
    CommentedConfigurationNode conf = null;
    try {
        conf = crateConfig.load();
        if (!conf.getNode("lang").isVirtual())
            langData = new SharedLangData(conf.getNode("lang"));
        else
            logger.info("Using default lang settings.");
    } catch (IOException e) {
        e.printStackTrace();
        logger.warn("Lang load failed, using defaults.");
    }
    crateUtilities.generateVirtualCrates(crateConfig);
    CommentedConfigurationNode root = null;
    try {
        root = crateConfig.load();
        for (CommentedConfigurationNode node : root.getNode("positions").getChildrenList()) {
            Location<World> ee;
            try {
                ee = node.getNode("location").getValue(TypeToken.of(Location.class));
            } catch (InvalidDataException err2) {
                logger.warn("Bug sponge developers about world UUIDs!");
                ee = new Location<World>(Sponge.getServer().getWorld(node.getNode("location", "WorldName").getString()).get(), node.getNode("location", "X").getDouble(), node.getNode("location", "Y").getDouble(), node.getNode("location", "Z").getDouble());
            }
            if (!crateUtilities.physicalCrates.containsKey(ee))
                crateUtilities.physicalCrates.put(ee, new PhysicalCrate(ee, node.getNode("crateID").getString(), HuskyCrates.instance));
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ObjectMappingException e) {
        e.printStackTrace();
    }
    crateUtilities.startParticleEffects();
}
Also used : Entity(org.spongepowered.api.entity.Entity) ArmorStand(org.spongepowered.api.entity.living.ArmorStand) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) SharedLangData(pw.codehusky.huskycrates.lang.SharedLangData) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException) PhysicalCrate(pw.codehusky.huskycrates.crate.PhysicalCrate) IOException(java.io.IOException) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) Listener(org.spongepowered.api.event.Listener)

Example 3 with SharedLangData

use of pw.codehusky.huskycrates.lang.SharedLangData in project HuskyCrates-Sponge by codeHusky.

the class HuskyCrates method gameInit.

@Listener
public void gameInit(GamePreInitializationEvent event) {
    logger = LoggerFactory.getLogger(pC.getName());
    CommentedConfigurationNode conf = null;
    try {
        conf = crateConfig.load();
        if (!conf.getNode("lang").isVirtual()) {
            langData = new SharedLangData(conf.getNode("lang"));
        } else
            logger.info("Using default lang settings.");
    } catch (IOException e) {
        e.printStackTrace();
        logger.warn("Lang load failed, using defaults.");
    }
    logger.info("Let's not init VCrates here anymore. ://)");
    instance = this;
}
Also used : CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) SharedLangData(pw.codehusky.huskycrates.lang.SharedLangData) IOException(java.io.IOException) Listener(org.spongepowered.api.event.Listener)

Aggregations

SharedLangData (pw.codehusky.huskycrates.lang.SharedLangData)3 IOException (java.io.IOException)2 CommentedConfigurationNode (ninja.leaping.configurate.commented.CommentedConfigurationNode)2 Listener (org.spongepowered.api.event.Listener)2 ObjectMappingException (ninja.leaping.configurate.objectmapping.ObjectMappingException)1 InvalidDataException (org.spongepowered.api.data.persistence.InvalidDataException)1 Entity (org.spongepowered.api.entity.Entity)1 ArmorStand (org.spongepowered.api.entity.living.ArmorStand)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1 Location (org.spongepowered.api.world.Location)1 World (org.spongepowered.api.world.World)1 PhysicalCrate (pw.codehusky.huskycrates.crate.PhysicalCrate)1