use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.
the class LockWeatherCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
Optional<WorldProperties> world = getWorldProperties(src, worldKey, args);
if (!world.isPresent()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.specifyworld"));
return CommandResult.empty();
}
WorldProperties wp = world.get();
Optional<ModularWorldService> ws = loader.getWorld(wp.getUniqueId());
if (!ws.isPresent()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.noworld", wp.getWorldName()));
return CommandResult.empty();
}
EnvironmentWorldDataModule environmentWorldDataModule = ws.get().get(EnvironmentWorldDataModule.class);
boolean toggle = args.<Boolean>getOne(toggleKey).orElse(!environmentWorldDataModule.isLockWeather());
environmentWorldDataModule.setLockWeather(toggle);
ws.get().set(environmentWorldDataModule);
if (toggle) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.lockweather.locked", wp.getWorldName()));
} else {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.lockweather.unlocked", wp.getWorldName()));
}
return CommandResult.success();
}
use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.
the class TimeCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
WorldProperties pr = getWorldPropertiesOrDefault(src, world, args);
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.time", pr.getWorldName(), String.valueOf(Util.getTimeFromTicks(pr.getWorldTime()))));
return CommandResult.success();
}
use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.
the class WeatherCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
// We can predict the weather on multiple worlds now!
WorldProperties wp = this.getWorldFromUserOrArgs(src, world, args);
World w = Sponge.getServer().getWorld(wp.getUniqueId()).orElseThrow(() -> ReturnMessageException.fromKey("args.worldproperties.notloaded", wp.getWorldName()));
// Get whether we locked the weather.
ModularWorldService ew = Nucleus.getNucleus().getWorldDataManager().getWorld(w).get();
if (ew.get(EnvironmentWorldDataModule.class).isLockWeather()) {
// Tell the user to unlock first.
throw ReturnMessageException.fromKey("command.weather.locked", w.getName());
}
// Houston, we have a world! Now, what was the forecast?
Weather we = args.<Weather>getOne(weather).get();
// Have we gotten an accurate forecast? Do we know how long this weather spell will go on for?
Optional<Long> oi = args.getOne(duration);
// Even weather masters have their limits. Sometimes.
if (max > 0 && oi.orElse(Long.MAX_VALUE) > max && !permissions.testSuffix(src, "exempt.length")) {
throw ReturnMessageException.fromKey("command.weather.toolong", Util.getTimeStringFromSeconds(max));
}
if (oi.isPresent()) {
// YES! I should get a job at the weather service and show them how it's done!
w.setWeather(we, oi.get());
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.weather.time", we.getName(), w.getName(), Util.getTimeStringFromSeconds(oi.get())));
} else {
// No, probably because I've already gotten a job at the weather service...
w.setWeather(we);
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.weather.set", we.getName(), w.getName()));
}
// The weather control device has been activated!
return CommandResult.success();
}
use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.
the class WorldCorrector method worldCheck.
public static void worldCheck() throws IOException, ObjectMappingException {
final Map<String, UUID> m = get();
// Now get the file out.
Path path = Nucleus.getNucleus().getDataPath().resolve("worlduuids.json");
ConfigurationLoader<ConfigurationNode> cl = GsonConfigurationLoader.builder().setPath(path).build();
Map<String, UUID> ms = cl.load().getValue(new TypeToken<Map<String, UUID>>() {
}, Maps.newHashMap());
final Map<UUID, UUID> fromToConverter = Maps.newHashMap();
for (String r : ms.keySet()) {
UUID oldUuid = ms.get(r);
@Nullable UUID newUuid = m.get(r);
if (newUuid != null && !oldUuid.equals(newUuid)) {
fromToConverter.put(newUuid, oldUuid);
}
}
cl.save(cl.createEmptyNode().setValue(new TypeToken<Map<String, UUID>>() {
}, m));
if (fromToConverter.isEmpty()) {
return;
}
MessageProvider mp = Nucleus.getNucleus().getMessageProvider();
ConsoleSource cs = Sponge.getServer().getConsole();
List<Text> msg = Lists.newArrayList();
Nucleus.getNucleus().addX(msg, 0);
msg.forEach(cs::sendMessage);
cs.sendMessage(Text.of(TextColors.RED, "--------------------"));
cs.sendMessage(mp.getTextMessageWithFormat("worldrepair.detected"));
for (Map.Entry<UUID, UUID> u : fromToConverter.entrySet()) {
cs.sendMessage(mp.getTextMessageWithFormat("worldrepair.worldlist", Sponge.getServer().getWorldProperties(u.getKey()).get().getWorldName(), u.getValue().toString(), u.getKey().toString()));
}
Method method;
try {
method = Sponge.getServer().getDefaultWorld().get().getClass().getDeclaredMethod("setUniqueId", UUID.class);
method.setAccessible(true);
} catch (NoSuchMethodException e) {
cs.sendMessage(mp.getTextMessageWithFormat("worldrepair.whitelist.nocmd"));
return;
}
cs.sendMessage(mp.getTextMessageWithFormat("worldrepair.whitelist.cmd"));
cs.sendMessage(Text.of(TextColors.RED, "--------------------"));
cs.sendMessage(mp.getTextMessageWithFormat("worldrepair.whitelist.cmd2"));
Sponge.getServer().setHasWhitelist(true);
Sponge.getCommandManager().register(Nucleus.getNucleus(), CommandSpec.builder().executor((s, a) -> {
MessageProvider mpr = Nucleus.getNucleus().getMessageProvider();
if (s instanceof ConsoleSource) {
cs.sendMessage(mpr.getTextMessageWithFormat("worldrepair.repair.start"));
Sponge.getEventManager().registerListener(Nucleus.getNucleus(), GameStoppedServerEvent.class, event -> {
for (Map.Entry<UUID, UUID> meuu : fromToConverter.entrySet()) {
// Magic!
WorldProperties wp = Sponge.getServer().getWorldProperties(meuu.getKey()).orElseThrow(() -> new NoSuchElementException(mpr.getMessageWithFormat("worldrepair.repair.nouuid", meuu.getKey().toString())));
final String name = wp.getWorldName();
try {
cs.sendMessage(mpr.getTextMessageWithFormat("worldrepair.repair.try", name));
method.invoke(wp, meuu.getValue());
Sponge.getServer().saveWorldProperties(wp);
cs.sendMessage(mpr.getTextMessageWithFormat("worldrepair.repair.success", name));
} catch (Exception e) {
cs.sendMessage(mpr.getTextMessageWithFormat("worldrepair.repair.fail", name));
e.printStackTrace();
}
}
try {
cl.save(cl.createEmptyNode().setValue(new TypeToken<Map<String, UUID>>() {
}, get()));
} catch (IOException | ObjectMappingException e) {
e.printStackTrace();
}
});
Sponge.getServer().shutdown();
return CommandResult.success();
} else {
s.sendMessage(mpr.getTextMessageWithFormat("command.consoleonly"));
return CommandResult.empty();
}
}).build(), "repairuuids");
}
use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.
the class SpawnListener method onRespawn.
@Listener(order = Order.EARLY)
public void onRespawn(RespawnPlayerEvent event) {
if (event.isBedSpawn() && !this.spawnConfig.isRedirectBedSpawn()) {
// Nope, we don't care.
return;
}
GlobalSpawnConfig sc = spawnConfig.getGlobalSpawn();
World world = event.getToTransform().getExtent();
// Get the world.
if (sc.isOnRespawn()) {
Optional<WorldProperties> oworld = sc.getWorld();
if (oworld.isPresent()) {
world = Sponge.getServer().getWorld(oworld.get().getUniqueId()).orElse(world);
}
}
Location<World> spawn = world.getSpawnLocation().add(0.5, 0, 0.5);
Transform<World> to = new Transform<>(spawn);
// Compare current transform to spawn - set rotation.
Nucleus.getNucleus().getWorldDataManager().getWorld(world).ifPresent(x -> x.get(SpawnWorldDataModule.class).getSpawnRotation().ifPresent(y -> event.setToTransform(to.setRotation(y))));
}
Aggregations