use of ninja.leaping.configurate.objectmapping.ObjectMappingException in project HuskyCrates-Sponge by codeHusky.
the class HuskyCrates method updatePhysicalCrates.
public void updatePhysicalCrates() {
if (updating)
return;
updating = true;
try {
CommentedConfigurationNode root = crateConfig.load();
root.getNode("positions").setValue(null);
for (Object ob : ((HashMap) crateUtilities.physicalCrates.clone()).keySet()) {
Location<World> e = (Location<World>) ob;
CommentedConfigurationNode node = root.getNode("positions").getAppendedNode();
node.getNode("location").setValue(TypeToken.of(Location.class), e);
//System.out.println("echo");
try {
node.getNode("crateID").setValue(crateUtilities.physicalCrates.get(e).vc.id);
} catch (NullPointerException err) {
System.out.println("removing a crate!");
node.setValue(null);
crateUtilities.physicalCrates.remove(ob);
logger.warn("Invalid crate at (" + e.getPosition().getFloorX() + ", " + e.getPosition().getFloorY() + ", " + e.getPosition().getFloorZ() + ")!");
}
}
crateConfig.save(root);
} catch (IOException e) {
e.printStackTrace();
} catch (ObjectMappingException e) {
e.printStackTrace();
}
crateUtilities.flag = false;
updating = false;
}
use of ninja.leaping.configurate.objectmapping.ObjectMappingException 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);
}
use of ninja.leaping.configurate.objectmapping.ObjectMappingException in project SpongeAPI by SpongePowered.
the class TextConfigSerializer method deserialize.
@Override
public Text deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException {
StringWriter writer = new StringWriter();
GsonConfigurationLoader gsonLoader = GsonConfigurationLoader.builder().setIndent(0).setSink(() -> new BufferedWriter(writer)).setHeaderMode(HeaderMode.NONE).build();
try {
gsonLoader.save(value);
} catch (IOException e) {
throw new ObjectMappingException(e);
}
return Sponge.getDataManager().deserialize(Text.class, DataContainer.createNew().set(Queries.JSON, writer.toString())).get();
}
use of ninja.leaping.configurate.objectmapping.ObjectMappingException in project guardian by ichorpowered.
the class AbstractDetectionContentLoader method acquireAll.
@Override
public void acquireAll() {
if (this.contentContainer == null || this.contentContainer.getPossibleKeys() == null)
return;
this.contentContainer.getPossibleKeys().forEach(key -> {
final Optional<ConfigurationAssignment> assignment = key.getAssignments().stream().filter(contentAssignment -> contentAssignment.getClass().equals(ConfigurationAssignment.class)).map(contentAssignment -> (ConfigurationAssignment) contentAssignment).findFirst();
if (!assignment.isPresent())
return;
final ConfigurationAssignment configurationAssignment = assignment.get();
final CommentedConfigurationNode node = this.configurationFile.getNode(configurationAssignment.lookup().toArray());
if (MapValue.class.isAssignableFrom(key.getDefaultValue().getClass())) {
final Map<Object, Object> collect = Maps.newHashMap();
if (node.hasMapChildren()) {
for (final Map.Entry<Object, ? extends ConfigurationNode> entry : node.getChildrenMap().entrySet()) {
collect.put(entry.getKey(), entry.getValue().getValue());
this.contentContainer.attempt(key, GuardianMapValue.builder((Key) key).defaultElement(collect).element(collect).create());
}
return;
}
}
if (Value.class.isAssignableFrom(key.getDefaultValue().getClass())) {
try {
Object value = node.getValue(key.getElementToken());
this.contentContainer.attempt(key, GuardianValue.builder((Key) key).defaultElement(value).element(value).create());
} catch (ObjectMappingException e) {
e.printStackTrace();
}
}
});
}
use of ninja.leaping.configurate.objectmapping.ObjectMappingException in project AtherysCore by Atherys-Horizons.
the class AbstractConfigurateAdapter method serialize.
@Override
public JsonElement serialize(T src, Type typeOfSrc, JsonSerializationContext context) {
GsonConfigurationLoader loader = GsonConfigurationLoader.builder().setLenient(true).setIndent(0).build();
try {
ConfigurationNode node = loader.createEmptyNode().setValue(TypeToken.of(clazz), src);
StringWriter writer = new StringWriter();
loader.saveInternal(node, writer);
String json = writer.toString();
return parser.parse(json);
} catch (ObjectMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
Aggregations