use of org.spongepowered.api.world.Location in project Nucleus by NucleusPowered.
the class SeenCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
User user = args.<User>getOne(uuid).isPresent() ? args.<User>getOne(uuid).get() : args.<User>getOne(playerKey).get();
if (user.isOnline()) {
// Get the player in case the User is displaying the wrong name.
user = user.getPlayer().get();
}
ModularUserService iqsu = Nucleus.getNucleus().getUserDataManager().getUnchecked(user);
CoreUserDataModule coreUserDataModule = iqsu.get(CoreUserDataModule.class);
List<Text> messages = new ArrayList<>();
final MessageProvider messageProvider = plugin.getMessageProvider();
// Everyone gets the last online time.
if (user.isOnline()) {
messages.add(messageProvider.getTextMessageWithFormat("command.seen.iscurrently.online", user.getName()));
coreUserDataModule.getLastLogin().ifPresent(x -> messages.add(messageProvider.getTextMessageWithFormat("command.seen.loggedon", Util.getTimeToNow(x))));
} else {
messages.add(messageProvider.getTextMessageWithFormat("command.seen.iscurrently.offline", user.getName()));
coreUserDataModule.getLastLogout().ifPresent(x -> messages.add(messageProvider.getTextMessageWithFormat("command.seen.loggedoff", Util.getTimeToNow(x))));
}
messages.add(messageProvider.getTextMessageWithFormat("command.seen.displayname", TextSerializers.FORMATTING_CODE.serialize(plugin.getNameUtil().getName(user))));
if (permissions.testSuffix(src, EXTENDED_SUFFIX)) {
messages.add(notEmpty);
messages.add(messageProvider.getTextMessageWithFormat("command.seen.uuid", user.getUniqueId().toString()));
if (user.isOnline()) {
Player pl = user.getPlayer().get();
messages.add(messageProvider.getTextMessageWithFormat("command.seen.ipaddress", pl.getConnection().getAddress().getAddress().toString()));
messages.add(messageProvider.getTextMessageWithFormat("command.seen.firstplayed", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(src.getLocale()).withZone(ZoneId.systemDefault()).format(pl.getJoinData().firstPlayed().get())));
messages.add(messageProvider.getTextMessageWithFormat("command.seen.speed.walk", String.valueOf(Math.round(pl.get(Keys.WALKING_SPEED).orElse(0.1d) * SpeedCommand.multiplier))));
messages.add(messageProvider.getTextMessageWithFormat("command.seen.speed.fly", String.valueOf(Math.round(pl.get(Keys.FLYING_SPEED).orElse(0.05d) * SpeedCommand.multiplier))));
messages.add(getLocationString("command.seen.currentlocation", pl.getLocation(), src));
messages.add(messageProvider.getTextMessageWithFormat("command.seen.canfly", getYesNo(pl.get(Keys.CAN_FLY).orElse(false))));
messages.add(messageProvider.getTextMessageWithFormat("command.seen.isflying", getYesNo(pl.get(Keys.IS_FLYING).orElse(false))));
messages.add(messageProvider.getTextMessageWithFormat("command.seen.gamemode", pl.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL).getName()));
} else {
coreUserDataModule.getLastIp().ifPresent(x -> messages.add(messageProvider.getTextMessageWithFormat("command.seen.lastipaddress", x)));
Optional<Instant> i = user.get(Keys.FIRST_DATE_PLAYED);
if (!i.isPresent()) {
i = coreUserDataModule.getFirstJoin();
}
i.ifPresent(x -> messages.add(messageProvider.getTextMessageWithFormat("command.seen.firstplayed", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(src.getLocale()).withZone(ZoneId.systemDefault()).format(x))));
Optional<Location<World>> olw = coreUserDataModule.getLogoutLocation();
olw.ifPresent(worldLocation -> messages.add(getLocationString("command.seen.lastlocation", worldLocation, src)));
user.get(JoinData.class).ifPresent(x -> {
Optional<Instant> oi = x.firstPlayed().getDirect();
oi.ifPresent(instant -> messages.add(messageProvider.getTextMessageWithFormat("command.seen.firstplayed", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(src.getLocale()).withZone(ZoneId.systemDefault()).format(instant))));
});
}
}
// Add the extra module information.
messages.addAll(seenHandler.buildInformation(src, user));
PaginationService ps = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
ps.builder().contents(messages).padding(Text.of(TextColors.GREEN, "-")).title(messageProvider.getTextMessageWithFormat("command.seen.title", user.getName())).sendTo(src);
return CommandResult.success();
}
use of org.spongepowered.api.world.Location 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))));
}
use of org.spongepowered.api.world.Location in project HuskyCrates-Sponge by codeHusky.
the class DBReader method loadHuskyData.
public static void loadHuskyData() throws SQLException {
connectDB();
HashMap<Integer, World> worldIDtoWorld = new HashMap<>();
ResultSet worldInfo = dbConnection.prepareStatement("SELECT * FROM WORLDINFO").executeQuery();
// HuskyCrates.instance.logger.info("isClosed: " + worldInfo.isClosed());
while (worldInfo.next()) {
// HuskyCrates.instance.logger.info("worldInfo thing!");
String worldUUID = worldInfo.getString("uuid");
String worldName = worldInfo.getString("name");
int id = worldInfo.getInt("ID");
Optional<World> preWorld = Sponge.getServer().getWorld(UUID.fromString(worldUUID));
if (!preWorld.isPresent()) {
HuskyCrates.instance.logger.warn("Invalid World UUID (BUG SPONGE DEVS)");
preWorld = Sponge.getServer().getWorld(worldName);
}
if (preWorld.isPresent()) {
worldIDtoWorld.put(id, preWorld.get());
HuskyCrates.instance.logger.info("Loaded world \"" + worldName + "\" successfully.");
} else {
HuskyCrates.instance.logger.warn("WorldInfo #" + id + " provides invalid world info. Removing from table.");
Statement removal = dbConnection.createStatement();
removal.executeQuery("SELECT * FROM WORLDINFO WHERE ID=" + id);
removal.executeUpdate("DELETE FROM WORLDINFO");
removal.close();
}
}
ResultSet cratePositions = dbConnection.prepareStatement("SELECT * FROM CRATELOCATIONS").executeQuery();
HuskyCrates.instance.crateUtilities.physicalCrates = new HashMap<>();
// HuskyCrates.instance.logger.info("isClosed: " + cratePositions.isClosed());
while (cratePositions.next()) {
// HuskyCrates.instance.logger.info("cratePositions thing!");
int id = cratePositions.getInt("ID");
double x = cratePositions.getDouble("X");
double y = cratePositions.getDouble("Y");
double z = cratePositions.getDouble("Z");
int worldID = cratePositions.getInt("worldID");
boolean entityCrate = cratePositions.getBoolean("isEntityCrate");
String crateID = cratePositions.getString("crateID");
if (worldIDtoWorld.containsKey(worldID)) {
// VALID WORLD
World world = worldIDtoWorld.get(worldID);
Location<World> loco = new Location<>(world, x, y, z);
HuskyCrates.instance.crateUtilities.physicalCrates.put(loco, new PhysicalCrate(loco, crateID, HuskyCrates.instance, entityCrate));
HuskyCrates.instance.logger.info("Loaded " + crateID + " @ " + x + "," + y + "," + z + ((entityCrate) ? " (ENTITY CRATE)" : ""));
} else {
HuskyCrates.instance.logger.warn("CrateLocation #" + id + " provides an invalid world ID. Removing from table.");
Statement removal = dbConnection.createStatement();
removal.executeQuery("SELECT * FROM CRATELOCATIONS WHERE ID=" + id);
removal.executeUpdate("DELETE FROM CRATELOCATIONS");
removal.close();
}
}
ResultSet crateKeyUUIDs = dbConnection.prepareStatement("SELECT * FROM VALIDKEYS").executeQuery();
// HuskyCrates.instance.logger.info("isClosed: " + crateKeyUUIDs.isClosed());
for (VirtualCrate vc : HuskyCrates.instance.crateUtilities.crateTypes.values()) {
vc.pendingKeys = new HashMap<>();
vc.virtualBalances = new HashMap<>();
PreparedStatement statement = dbConnection.prepareStatement("SELECT * FROM LASTUSED WHERE crateID = ?");
statement.setString(1, vc.id);
ResultSet results = statement.executeQuery();
while (results.next()) {
vc.lastUsed.put(UUID.fromString(results.getString(1)), LocalDateTime.ofInstant(Instant.ofEpochMilli(results.getLong(3)), ZoneOffset.systemDefault()));
}
}
while (crateKeyUUIDs.next()) {
// HuskyCrates.instance.logger.info("crateKeyUUIDs thing!");
UUID keyUUID = UUID.fromString(crateKeyUUIDs.getString("keyUUID"));
String crateID = crateKeyUUIDs.getString("crateID");
int amount = crateKeyUUIDs.getInt("amount");
if (HuskyCrates.instance.crateUtilities.crateTypes.containsKey(crateID)) {
VirtualCrate vc = HuskyCrates.instance.crateUtilities.crateTypes.get(crateID);
vc.pendingKeys.put(keyUUID.toString(), amount);
} else {
HuskyCrates.instance.logger.warn("ValidKeys " + keyUUID + " provides an invalid crate ID. Removing from table.");
Statement removal = dbConnection.createStatement();
removal.executeQuery("SELECT * FROM CRATELOCATIONS WHERE KEYUUID=" + keyUUID.toString());
removal.executeUpdate("DELETE FROM CRATELOCATIONS");
removal.close();
}
}
ResultSet keyBalances = dbConnection.prepareStatement("SELECT * FROM KEYBALANCES").executeQuery();
// HuskyCrates.instance.logger.info("isClosed: " + keyBalances.isClosed());
while (keyBalances.next()) {
// HuskyCrates.instance.logger.info("keyBalances thing!");
UUID userUUID = UUID.fromString(keyBalances.getString("userUUID"));
String crateID = keyBalances.getString("crateID");
int amount = keyBalances.getInt("amount");
if (HuskyCrates.instance.crateUtilities.getCrateTypes().contains(crateID)) {
HuskyCrates.instance.crateUtilities.getVirtualCrate(crateID).virtualBalances.put(userUUID.toString(), amount);
} else {
HuskyCrates.instance.logger.warn("KeyBalances for UUID " + userUUID + " provides an invalid crate ID. Removing from table.");
Statement removal = dbConnection.createStatement();
removal.executeQuery("SELECT * FROM KEYBALANCES WHERE USERUUID=" + userUUID.toString());
removal.executeUpdate("DELETE FROM KEYBALANCES");
removal.close();
}
}
/*
CRATELOCATIONS (ID INTEGER NOT NULL AUTO_INCREMENT, X DOUBLE, Y DOUBLE, Z DOUBLE, worldID INTEGER, isEntityCrate BOOLEAN, crateID CHARACTER, PRIMARY KEY(ID))
VALIDKEYS (keyUUID CHARACTER, crateID CHARACTER, amount INTEGER )
KEYBALANCES (userUUID CHARACTER, crateID CHARACTER, amount INTEGER)
WORLDINFO (ID INTEGER NOT NULL AUTO_INCREMENT,uuid CHARACTER, name CHARACTER, PRIMARY KEY(ID))
*/
}
use of org.spongepowered.api.world.Location in project Almura by AlmuraDev.
the class ServerClaimManager method sendUpdateTo.
public void sendUpdateTo(final Player player, Claim claim, List<UUID> players, final boolean everyone, final String reason) {
if (!Sponge.getPluginManager().isLoaded("griefdefender")) {
// Check here to see if its loaded because in the deobfuscated environment I force load the ClaimManager classes for testing purposes.
return;
}
if ((player == null && players == null && !everyone) || (player == null && (players != null && players.isEmpty()) && !everyone)) {
if (debug) {
System.out.println("Claim sendUpdateTo canceled because no players listed and everyone was false, reason: " + reason);
}
return;
}
if (claim != null && debug)
System.out.println("Claim sendUpdateTo: [" + reason + "] everyone: [" + everyone + "] name: [" + claim.getDisplayName() + "] owner: [" + claim.getOwnerName() + "] wilderness: [" + claim.isWilderness() + "]");
// Lookup claim where player or players is standing
if (claim == null) {
if (player != null) {
claim = GriefDefender.getCore().getClaimManager(player.getWorld().getUniqueId()).getClaimAt(player.getLocation().getPosition().toInt());
}
if (players != null) {
for (UUID playerUUID : players) {
final Player finalPlayer = (Player) FMLServerHandler.instance().getServer().getPlayerList().getPlayerByUUID(playerUUID);
if (finalPlayer != null) {
Task.builder().delayTicks(10).execute(t -> this.sendUpdate(finalPlayer, null)).submit(this.container);
}
}
}
}
// Send to specific player
if (!everyone && player != null && claim != null) {
final Claim finalClaim = claim;
Task.builder().delayTicks(10).execute(t -> this.sendUpdate(player, finalClaim)).submit(this.container);
return;
}
// Send to everyone regardless of implied list from events.
if (everyone && player == null && claim != null) {
final Claim finalClaim = claim;
for (Player onlinePlayer : Sponge.getServer().getOnlinePlayers()) {
Task.builder().delayTicks(10).execute(t -> this.sendUpdate(onlinePlayer, finalClaim)).submit(this.container);
}
return;
}
// Send to the implied list of players when claim is handed into the method.
if (players != null && claim != null) {
final Claim finalClaim = claim;
for (UUID playerUUID : players) {
final Player finalPlayer = (Player) FMLServerHandler.instance().getServer().getPlayerList().getPlayerByUUID(playerUUID);
if (finalPlayer != null) {
Task.builder().delayTicks(10).execute(t -> this.sendUpdate(finalPlayer, finalClaim)).submit(this.container);
}
}
return;
}
// Send update to everyone on server regardless of location or claim
if (player == null && players == null && claim == null && everyone) {
for (final Player onlinePlayer : Sponge.getServer().getOnlinePlayers()) {
if (onlinePlayer != null && onlinePlayer.getWorld() != null) {
claim = GriefDefender.getCore().getClaimManager(onlinePlayer.getWorld().getUniqueId()).getClaimAt(onlinePlayer.getLocation().getPosition().toInt());
if (claim != null) {
final Claim finalClaim = claim;
Task.builder().delayTicks(10).execute(t -> this.sendUpdate(onlinePlayer, finalClaim)).submit(this.container);
}
}
}
return;
}
}
use of org.spongepowered.api.world.Location in project Skree by Skelril.
the class RegionSelectCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
src.sendMessage(Text.of("You must be a player to use this command (for now ;) )!"));
return CommandResult.empty();
}
Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
if (!optService.isPresent()) {
src.sendMessage(Text.of(TextColors.DARK_RED, "The region service is not currently running."));
return CommandResult.empty();
}
RegionService service = optService.get();
Player player = (Player) src;
Optional<Player> optPlayer = args.getOne("player");
Optional<Location<World>> optLocation = args.getOne("location");
Optional<Region> optRegion;
if (optPlayer.isPresent()) {
Player targPlayer = optPlayer.get();
optRegion = service.get(targPlayer.getLocation());
player.sendMessage(Text.of(TextColors.YELLOW, "Searching for ", targPlayer.getName(), "'s local region..."));
} else if (optLocation.isPresent()) {
optRegion = service.get(optLocation.get());
player.sendMessage(Text.of(TextColors.YELLOW, "Searching for a region at the given location..."));
} else {
optRegion = service.get(player.getLocation());
player.sendMessage(Text.of(TextColors.YELLOW, "Searching for your local region..."));
}
service.setSelectedRegion(player, optRegion.orElse(null));
if (optRegion.isPresent()) {
player.sendMessage(Text.of(TextColors.YELLOW, "Region found! View information with ", Text.of(TextColors.GREEN, TextActions.runCommand("/region info"), "/region info")));
} else {
player.sendMessage(Text.of(TextColors.YELLOW, "No region found, your region selection has been cleared"));
}
return CommandResult.success();
}
Aggregations