use of org.spongepowered.api.command.CommandSource in project HuskyCrates-Sponge by codeHusky.
the class HuskyCrates method postGameStart.
@Listener(order = Order.POST)
public void postGameStart(GameStartedServerEvent event) {
checkVersion();
if (forceStop) {
// logger.error("Since a blacklisted mod is loaded, HuskyCrates will not start. Please check higher in your logs for the reasoning.");
return;
}
Sponge.getScheduler().createTaskBuilder().execute(new Consumer<Task>() {
@Override
public void accept(Task task) {
logger.info("Deleting existing armor stands...");
removeArmorstands();
logger.info("Initalizing config...");
if (!crateUtilities.hasInitalizedVirtualCrates) {
crateUtilities.generateVirtualCrates(crateConfig);
}
// doublecheck
crateUtilities.hasInitalizedVirtualCrates = true;
logger.info("Done initalizing config.");
logger.info("Attempting legacy Physical Crates method (this will be removed in a later version)");
CommentedConfigurationNode root = null;
boolean convertFired = false;
try {
root = crateConfig.load();
double max = root.getNode("positions").getChildrenList().size();
double count = 0;
for (VirtualCrate vc : crateUtilities.crateTypes.values()) {
if (vc.pendingKeys.size() > 0) {
logger.warn("legacy keys loaded! warn warn warn.");
if (!root.getNode("keys").isVirtual()) {
root.removeChild("keys");
}
convertFired = true;
}
}
if (!root.getNode("positions").isVirtual()) {
convertFired = true;
logger.warn("Legacy position data detected. Will convert.");
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, node.getNode("location", "BlockType").getString().equals("minecraft:air")));
logger.info("(LEGACY) PROGRESS: " + Math.round((count / max) * 100) + "%");
}
root.removeChild("positions");
}
if (!root.getNode("users").isVirtual()) {
for (Object uuidPre : root.getNode("users").getChildrenMap().keySet()) {
for (Object crateIDPre : root.getNode("users", uuidPre, "keys").getChildrenMap().keySet()) {
String uuid = uuidPre.toString();
String crateID = crateIDPre.toString();
int amount = root.getNode("users", uuid, "keys", crateID).getInt(0);
HuskyCrates.instance.crateUtilities.crateTypes.get(crateID).virtualBalances.put(uuid, amount);
}
}
root.removeChild("users");
}
crateConfig.save(root);
} catch (Exception e) {
crateUtilities.exceptionHandler(e);
if (event.getCause().root() instanceof Player) {
CommandSource cs = (CommandSource) event.getCause().root();
cs.sendMessage(Text.of(TextColors.GOLD, "HuskyCrates", TextColors.WHITE, ":", TextColors.RED, " An error has occured. Please check the console for more information."));
}
return;
}
logger.info("Done with legacy loading technique");
logger.info("Running DB routine.");
try {
DBReader.dbInitCheck();
if (convertFired) {
logger.info("Saving data.");
DBReader.saveHuskyData();
logger.info("Done saving data.");
} else {
logger.info("Loading data.");
DBReader.loadHuskyData();
logger.info("Done loading data.");
}
} catch (SQLException e) {
e.printStackTrace();
}
logger.info("DB Data routine finished.");
crateUtilities.startParticleEffects();
logger.info("Initalization complete.");
Sponge.getScheduler().createTaskBuilder().execute(() -> {
try {
DBReader.dbInitCheck();
DBReader.saveHuskyData();
logger.info("Updated Database.");
} catch (SQLException e) {
e.printStackTrace();
}
}).interval(15, TimeUnit.MINUTES).delay(15, TimeUnit.MINUTES).async().submit(HuskyCrates.instance);
}
}).delayTicks(1).submit(this);
}
Aggregations