use of com.codehusky.huskycrates.lang.LangData in project HuskyCrates-Sponge by codeHusky.
the class CrateView method handleReward.
public void handleReward(CrateReward giveToPlayer) {
for (Object reward : giveToPlayer.getRewards()) {
// System.out.println(reward);
if (reward instanceof String) {
Sponge.getCommandManager().process(new CrateCommandSource(), reward.toString().replace("%p", ourplr.getName()));
} else {
// System.out.println(giveToPlayer.getReward().treatAsSingle());
ourplr.getInventory().offer(((ItemStack) reward).copy());
}
}
boolean mult = false;
LangData thisData = giveToPlayer.getLangData();
if (!giveToPlayer.treatAsSingle() && giveToPlayer.getRewards().size() == 1 && giveToPlayer.getRewards().get(0) instanceof ItemStack) {
if (((ItemStack) giveToPlayer.getRewards().get(0)).getQuantity() > 1) {
/*ourplr.sendMessage(Text.of("You won ", TextColors.YELLOW,
((ItemStack) giveToPlayer.getReward().getReward()).getQuantity() + " ",
TextSerializers.FORMATTING_CODE.deserialize(giveToPlayer.getReward().getRewardName()), TextColors.RESET, " from a ",
TextSerializers.FORMATTING_CODE.deserialize(vc.displayName), TextColors.RESET, "!"));*/
ourplr.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(thisData.formatter(thisData.rewardMessage, ((ItemStack) giveToPlayer.getRewards().get(0)).getQuantity() + "", ourplr, vc, giveToPlayer, null, null)));
if (giveToPlayer.shouldAnnounce()) {
Sponge.getServer().getBroadcastChannel().send(TextSerializers.FORMATTING_CODE.deserialize(thisData.formatter(thisData.rewardAnnounceMessage, ((ItemStack) giveToPlayer.getRewards().get(0)).getQuantity() + "", ourplr, vc, giveToPlayer, null, null)));
}
mult = true;
}
}
if (!mult) {
String[] vowels = { "a", "e", "i", "o", "u" };
if (Arrays.asList(vowels).contains(giveToPlayer.getRewardName().substring(0, 1).toLowerCase())) {
ourplr.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(thisData.formatter(thisData.rewardMessage, "an", ourplr, vc, giveToPlayer, null, null)));
if (giveToPlayer.shouldAnnounce()) {
Sponge.getServer().getBroadcastChannel().send(TextSerializers.FORMATTING_CODE.deserialize(thisData.formatter(thisData.rewardAnnounceMessage, "an", ourplr, vc, giveToPlayer, null, null)));
}
} else {
ourplr.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(thisData.formatter(thisData.rewardMessage, "a", ourplr, vc, giveToPlayer, null, null)));
if (giveToPlayer.shouldAnnounce()) {
Sponge.getServer().getBroadcastChannel().send(TextSerializers.FORMATTING_CODE.deserialize(thisData.formatter(thisData.rewardAnnounceMessage, "a", ourplr, vc, giveToPlayer, null, null)));
}
}
}
}
use of com.codehusky.huskycrates.lang.LangData in project HuskyCrates-Sponge by codeHusky.
the class CrateConfigParser method fromConfig.
public static CrateReward fromConfig(ConfigurationNode holderNode, VirtualCrate vc) {
if (holderNode.getNode("huskydata").isVirtual()) {
HuskyCrates.instance.logger.error("CANNOT FIND HUSKYDATA: " + holderNode.getNode("name").getString("(no name)") + " (item #" + holderNode.getKey() + ") || " + holderNode.getParent().getParent().getKey());
return null;
}
ItemStack dispItem = itemFromNode(holderNode);
String name;
boolean single = false;
boolean announce = false;
LangData langData = vc.getLangData();
if (!holderNode.getNode("huskydata", "lang").isVirtual()) {
langData = new LangData(vc.getLangData(), holderNode.getNode("huskydata", "lang"));
}
// System.out.println(dispItem.get(Keys.DISPLAY_NAME));
if (!holderNode.getNode("huskydata", "reward", "announce").isVirtual()) {
// announce = holderNode.getNode("huskydata", "reward", "announce").getBoolean(false);
holderNode.getNode("huskydata", "announce").setValue(holderNode.getNode("huskydata", "reward", "announce").getValue());
holderNode.getNode("huskydata", "reward", "announce").setValue(null);
}
if (!holderNode.getNode("huskydata", "reward", "treatAsSingle").isVirtual()) {
// single = holderNode.getNode("huskydata", "reward", "treatAsSingle").getBoolean(false);
holderNode.getNode("huskydata", "treatAsSingle").setValue(holderNode.getNode("huskydata", "reward", "treatAsSingle").getValue());
holderNode.getNode("huskydata", "reward", "treatAsSingle").setValue(null);
}
if (!holderNode.getNode("huskydata", "reward", "overrideRewardName").isVirtual()) {
String premove = holderNode.getNode("huskydata", "reward", "overrideRewardName").getString("failure?");
holderNode.getNode("huskydata", "reward", "overrideRewardName").setValue(null);
holderNode.getNode("huskydata", "overrideRewardName").setValue(premove);
}
if (holderNode.getNode("huskydata", "overrideRewardName").isVirtual()) {
// System.out.println("Virtual");
if (dispItem.get(Keys.DISPLAY_NAME).isPresent()) {
name = TextSerializers.FORMATTING_CODE.serialize(dispItem.get(Keys.DISPLAY_NAME).get());
} else {
name = dispItem.getType().getName();
}
} else {
// System.out.println("Real");
name = holderNode.getNode("huskydata", "overrideRewardName").getString("strings, please.");
}
if (!holderNode.getNode("huskydata", "announce").isVirtual()) {
announce = holderNode.getNode("huskydata", "announce").getBoolean(false);
}
if (!holderNode.getNode("huskydata", "treatAsSingle").isVirtual()) {
single = holderNode.getNode("huskydata", "treatAsSingle").getBoolean(false);
}
if (!holderNode.getNode("huskydata", "reward").isVirtual()) {
holderNode.getNode("huskydata", "rewards").getAppendedNode().setValue(holderNode.getNode("huskydata", "reward"));
holderNode.getNode("huskydata", "reward").setValue(null);
}
ArrayList<Object> rewards = new ArrayList<>();
for (ConfigurationNode rewardNode : holderNode.getNode("huskydata", "rewards").getChildrenList()) {
if (rewardNode.getNode("type").isVirtual()) {
HuskyCrates.instance.logger.error("CANNOT FIND REWARD TYPE: " + holderNode.getNode("name").getString("(no name)") + " (item #" + holderNode.getKey() + ") (reward #" + rewardNode.getKey() + ") || " + holderNode.getParent().getParent().getKey());
continue;
}
if (rewardNode.getNode("type").getString().equalsIgnoreCase("item")) {
// ItemStack rewardItem;
if (rewardNode.getNode("overrideItem").isVirtual()) {
ItemStack rr = dispItem.copy();
if (!rewardNode.getNode("overrideCount").isVirtual()) {
rr.setQuantity(rewardNode.getNode("overrideCount").getInt());
}
rewards.add(rr);
} else {
rewards.add(itemFromNode(rewardNode.getNode("overrideItem")));
}
} else if (rewardNode.getNode("type").getString().equalsIgnoreCase("command")) {
rewards.add(rewardNode.getNode("command").getString("/say You didn't set a command or something..."));
} else {
HuskyCrates.instance.logger.error("INVALID REWARD TYPE: " + rewardNode.getNode("type").getString() + "@" + holderNode.getNode("name").getString("(no name)") + " (item #" + holderNode.getKey() + ") || " + holderNode.getParent().getParent().getKey());
}
}
if (!holderNode.getNode("huskydata", "announce").isVirtual()) {
announce = holderNode.getNode("huskydata", "announce").getBoolean(false);
}
if (rewards.size() == 0) {
rewards.add("/say No rewards were loaded in the " + vc.id + " crate!");
}
return new CrateReward(dispItem, rewards, name, holderNode.getNode("huskydata", "weight").getDouble(1), langData, announce, single);
}
use of com.codehusky.huskycrates.lang.LangData in project HuskyCrates-Sponge by codeHusky.
the class HuskyCrates method gameInit.
@Listener
public void gameInit(GamePreInitializationEvent event) {
logger = LoggerFactory.getLogger(pC.getName());
instance = this;
huskyAPI = new HuskyAPI();
forceStopIDs.clear();
for (PluginContainer pc : Sponge.getPluginManager().getPlugins()) {
if (pc.getId().equalsIgnoreCase("inventorytweaks") || pc.getId().equalsIgnoreCase("inventorysorter") || pc.getId().equalsIgnoreCase("mousetweaks")) {
forceStopIDs.add(pc.getName() + "(" + pc.getId() + ")");
logger.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
logger.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
logger.error(pc.getName() + " is loaded! This plugin or mod is on a blacklist for HuskyCrates, and as a result, HuskyCrates is not starting. ");
logger.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
logger.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
forceStop = true;
}
}
if (forceStop)
return;
CommentedConfigurationNode conf = null;
try {
conf = crateConfig.load();
if (!conf.getNode("lang").isVirtual()) {
langData = new LangData(conf.getNode("lang"));
} else
logger.info("Using default lang settings.");
} catch (Exception e) {
crateUtilities.exceptionHandler(e);
}
// logger.info("Let's not init VCrates here anymore. ://)");
}
use of com.codehusky.huskycrates.lang.LangData in project HuskyCrates-Sponge by codeHusky.
the class HuskyCrates method reload.
public void reload(CommandSource cs) {
if (forceStop) {
warnBlacklistMod(cs);
return;
}
if (cs.hasPermission("huskycrates.adminlog"))
cs.sendMessage(Text.of(TextColors.RED, "Please ", TextStyles.BOLD, TextColors.RED, "check your console for errors", TextStyles.RESET, TextColors.RED, " before reporting issues! <3"));
HuskyCrates.resetInitError();
try {
DBReader.dbInitCheck();
DBReader.saveHuskyData();
} catch (SQLException e) {
e.printStackTrace();
cs.sendMessage(Text.of(TextColors.RED, "A critical error occurred while saving your data. Please check the logs for more information."));
}
langData = null;
removeArmorstands();
langData = new LangData();
CommentedConfigurationNode root = null;
try {
root = crateConfig.load();
if (!root.getNode("lang").isVirtual())
langData = new LangData(root.getNode("lang"));
else
logger.info("Using default lang settings.");
crateUtilities.generateVirtualCrates(crateConfig);
} catch (Exception e) {
crateUtilities.exceptionHandler(e);
if (cs != null) {
cs.sendMessage(Text.of(TextColors.GOLD, "HuskyCrates", TextColors.WHITE, ":", TextColors.RED, " An error has occured. Please check the console for more information."));
}
return;
}
try {
DBReader.loadHuskyData();
} catch (SQLException e) {
e.printStackTrace();
}
crateUtilities.startParticleEffects();
checkVersion();
for (Player plr : Sponge.getServer().getOnlinePlayers()) {
notifyOutOfDate(plr);
notifyInitError(plr);
}
}
Aggregations