use of org.spongepowered.api.data.persistence.InvalidDataException 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();
}
use of org.spongepowered.api.data.persistence.InvalidDataException in project HuskyCrates-Sponge by codeHusky.
the class HuskyCrates method postGameStart.
@Listener(order = Order.POST)
public void postGameStart(GameStartedServerEvent event) {
Sponge.getScheduler().createTaskBuilder().async().execute(new Consumer<Task>() {
@Override
public void accept(Task task) {
try {
JSONObject obj = JsonReader.readJsonFromUrl("https://api.github.com/repos/codehusky/HuskyCrates-Sponge/releases");
String[] thisVersion = pC.getVersion().get().split("\\.");
String[] remoteVersion = obj.getJSONArray("releases").getJSONObject(0).getString("tag_name").replace("v", "").split("\\.");
for (int i = 0; i < Math.min(remoteVersion.length, thisVersion.length); i++) {
if (!thisVersion[i].equals(remoteVersion[i])) {
if (Integer.parseInt(thisVersion[i]) > Integer.parseInt(remoteVersion[i])) {
//we're ahead
logger.warn("----------------------------------------------------");
logger.warn("Running unreleased version. (Developer build?)");
logger.warn("----------------------------------------------------");
} else {
//we're behind
logger.warn("----------------------------------------------------");
logger.warn("Your version of HuskyCrates is out of date!");
logger.warn("Your version: v" + pC.getVersion().get());
logger.warn("Latest version: " + obj.getJSONArray("releases").getJSONObject(0).getString("tag_name"));
logger.warn("Update here: https://goo.gl/hgtPMR");
logger.warn("----------------------------------------------------");
}
return;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}).submit(this);
Sponge.getScheduler().createTaskBuilder().execute(new Consumer<Task>() {
@Override
public void accept(Task task) {
logger.info("Deleting existing armor stands...");
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();
}
}
}
}
}
logger.info("Initalizing config...");
if (!crateUtilities.hasInitalizedVirtualCrates) {
crateUtilities.generateVirtualCrates(crateConfig);
}
// doublecheck
crateUtilities.hasInitalizedVirtualCrates = true;
logger.info("Done initalizing config.");
logger.info("Populating physical crates...");
CommentedConfigurationNode root = null;
try {
root = crateConfig.load();
double max = root.getNode("positions").getChildrenList().size();
double count = 0;
for (CommentedConfigurationNode node : root.getNode("positions").getChildrenList()) {
count++;
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));
logger.info("PROGRESS: " + Math.round((count / max) * 100) + "%");
}
} catch (IOException e) {
e.printStackTrace();
} catch (ObjectMappingException e) {
e.printStackTrace();
}
crateUtilities.startParticleEffects();
logger.info("Done populating physical crates.");
logger.info("Initalization complete.");
}
}).delayTicks(1).submit(this);
}
Aggregations