use of org.spongepowered.api.event.filter.Getter in project Almura by AlmuraDev.
the class ServerTitleManager method onClientConnectionEventJoin.
@Listener
public void onClientConnectionEventJoin(final ClientConnectionEvent.Join event, @Getter("getTargetEntity") final Player player) {
// Clear everything out for joining player
this.selectedTitles.remove(player.getUniqueId());
// Send titles to joiner
this.network.sendTo(player, new ClientboundTitlesRegistryPacket(this.titles.values().stream().filter(title -> {
if (!title.isHidden()) {
return true;
}
return player.hasPermission(Almura.ID + ".title.admin");
}).collect(Collectors.toSet())));
// Send selected titles to joiner
this.network.sendTo(player, new ClientboundSelectedTitleBulkPacket(this.selectedTitles.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, v -> v.getValue().getId()))));
// Cache available titles for the joiner
this.calculateAvailableTitlesFor(player);
// Send joiner available titles (to cache)
this.getAvailableTitlesFor(player).ifPresent(availableTitles -> this.network.sendTo(player, new ClientboundAvailableTitlesResponsePacket(availableTitles)));
// Query database for selected title for joiner
this.scheduler.createTaskBuilder().async().execute(() -> {
try (final DSLContext context = this.databaseManager.createContext(true)) {
final TitleSelectRecord record = TitleQueries.createFetchSelectedTitleFor(player.getUniqueId()).build(context).keepStatement(false).fetchOne();
String titleId = "lostsoul";
if (record != null && !record.getTitle().isEmpty()) {
titleId = record.getTitle();
System.err.println("[ServerTitleManager]: Assigning player configured title: [" + titleId + "] for player: [" + player.getName() + "].");
} else {
// The following are setup as fallback titles when a record doesn't exist in the DB for the player.
if (player.hasPermission("almura.title.soldier"))
titleId = "soldier";
if (player.hasPermission("almura.title.survivor"))
titleId = "survivor";
if (player.hasPermission("almura.title.citizen"))
titleId = "citizen";
if (player.hasPermission("almura.title.explorer"))
titleId = "explorer";
if (player.hasPermission("almura.title.pioneer"))
titleId = "pioneer";
if (player.hasPermission("almura.title.architect"))
titleId = "architect";
if (player.hasPermission("almura.title.ancient"))
titleId = "ancient";
// The following debug was left in place so Dockter can see how many of these are happening at the server console.
System.err.println("[ServerTitleManager]: Assigning fallback title: [" + titleId + "] for player: [" + player.getName() + "].");
}
final String finalizedTitleId = titleId;
this.scheduler.createTaskBuilder().execute(() -> {
final Title selectedTitle = this.getTitle(finalizedTitleId).orElse(null);
if (this.verifySelectedTitle(player, selectedTitle)) {
this.selectedTitles.put(player.getUniqueId(), selectedTitle);
// Send everyone joiner's selected title
this.network.sendToAll(new ClientboundSelectedTitlePacket(player.getUniqueId(), finalizedTitleId));
}
}).submit(this.container);
} catch (SQLException e) {
e.printStackTrace();
}
}).submit(this.container);
}
use of org.spongepowered.api.event.filter.Getter in project Almura by AlmuraDev.
the class ServerNickManager method playerMove.
@Listener(order = Order.LAST)
public void playerMove(final MoveEntityEvent.Teleport event, @Getter("getTargetEntity") final Player player) throws IllegalAccessException {
if (differentExtent(event.getFromTransform(), event.getToTransform())) {
this.game.getServiceManager().provide(NucleusNicknameService.class).ifPresent((service) -> {
service.getNickname(player).ifPresent((nick) -> {
final String oldNick = TextSerializers.LEGACY_FORMATTING_CODE.serialize(nick);
// Tell the Forge mods
final String newNick = ForgeEventFactory.getPlayerDisplayName((EntityPlayer) event.getTargetEntity(), TextSerializers.LEGACY_FORMATTING_CODE.serialize(nick));
if (!oldNick.equals(newNick)) {
try {
service.setNickname(player, TextSerializers.LEGACY_FORMATTING_CODE.deserialize(newNick));
} catch (NicknameException e) {
e.printStackTrace();
}
}
try {
displayNameField.set(player, newNick);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
});
// Send the joining player's nickname to others
Text nickname = service.getNickname(player).orElse(null);
if (nickname == null) {
nickname = Text.of(player.getName());
} else {
nickname = Text.of("~" + nickname.toPlain());
}
final ClientboundNucleusNameChangeMappingPacket joiningPlayerPacket = this.getMappingMessage(player, nickname);
this.game.getServer().getOnlinePlayers().stream().filter((players) -> !players.getUniqueId().equals(player.getUniqueId())).forEach((players) -> this.network.sendTo(players, joiningPlayerPacket));
Task.builder().delayTicks(40).execute(t -> {
// Send everyone's nicknames to the joining player
this.network.sendTo(player, this.getMappingMessage(service));
}).submit(this.container);
});
}
}
use of org.spongepowered.api.event.filter.Getter in project Nucleus by NucleusPowered.
the class ServerListListener method onServerListPing.
@Listener
public void onServerListPing(ClientPingServerEvent event, @Getter("getResponse") ClientPingServerEvent.Response response) {
if (this.config == null) {
try {
onReload();
} catch (Exception e) {
e.printStackTrace();
return;
}
}
if (this.config.isModifyServerList()) {
List<NucleusTextTemplateImpl> list = null;
Optional<Text> ott = plugin.getGeneralService().get(ServerListGeneralDataModule.class).getMessage();
if (ott.isPresent()) {
response.setDescription(ott.get());
} else {
if (Sponge.getServer().hasWhitelist() && !this.config.getWhitelist().isEmpty()) {
list = this.config.getWhitelist();
} else if (!this.config.getMessages().isEmpty()) {
list = this.config.getMessages();
}
if (list != null) {
NucleusTextTemplate template = list.get(this.random.nextInt(list.size()));
response.setDescription(template.getForCommandSource(Sponge.getServer().getConsole()));
}
}
}
if (this.config.isHidePlayerCount()) {
response.setHidePlayers(true);
} else if (this.config.isHideVanishedPlayers()) {
Collection<GameProfile> players = Sponge.getServer().getOnlinePlayers().stream().filter(x -> !x.get(Keys.VANISH).orElse(false)).map(User::getProfile).collect(Collectors.toList());
response.getPlayers().ifPresent(y -> {
y.getProfiles().clear();
y.getProfiles().addAll(players);
y.setOnline(players.size());
});
}
}
use of org.spongepowered.api.event.filter.Getter in project Nucleus by NucleusPowered.
the class CoreListener method onPlayerJoinLast.
@Listener
public void onPlayerJoinLast(final ClientConnectionEvent.Join event, @Getter("getTargetEntity") final Player player) {
if (Nucleus.getNucleus().getUserDataManager().get(player).map(x -> x.get(CoreUserDataModule.class).isFirstPlay()).orElse(true)) {
NucleusFirstJoinEvent firstJoinEvent = new OnFirstLoginEvent(event.getCause(), player, event.getOriginalChannel(), event.getChannel().orElse(null), event.getOriginalMessage(), event.isMessageCancelled(), event.getFormatter());
Sponge.getEventManager().post(firstJoinEvent);
event.setChannel(firstJoinEvent.getChannel().get());
event.setMessageCancelled(firstJoinEvent.isMessageCancelled());
Nucleus.getNucleus().getUserDataManager().getUnchecked(player).get(CoreUserDataModule.class).setStartedFirstJoin(false);
}
// Warn about wildcard.
if (!ServiceChangeListener.isOpOnly() && player.hasPermission("nucleus")) {
MessageProvider provider = this.plugin.getMessageProvider();
Nucleus.getNucleus().getLogger().warn("The player " + player.getName() + " has got either the nucleus wildcard or the * wildcard " + "permission. This may cause unintended side effects.");
if (this.warnOnWildcard) {
// warn
List<Text> text = Lists.newArrayList();
text.add(provider.getTextMessageWithFormat("core.permission.wildcard2"));
text.add(provider.getTextMessageWithFormat("core.permission.wildcard3"));
if (this.url != null) {
text.add(provider.getTextMessageWithFormat("core.permission.wildcard4").toBuilder().onClick(TextActions.openUrl(this.url)).build());
}
text.add(provider.getTextMessageWithFormat("core.permission.wildcard5"));
Sponge.getServiceManager().provideUnchecked(PaginationService.class).builder().title(provider.getTextMessageWithFormat("core.permission.wildcard")).contents(text).padding(Text.of(TextColors.GOLD, "-")).sendTo(player);
}
}
}
use of org.spongepowered.api.event.filter.Getter in project Nucleus by NucleusPowered.
the class KitListener method onPlayerInteractInventoryClose.
@Listener
public void onPlayerInteractInventoryClose(final InteractInventoryEvent.Close event, @Root final Player player, @Getter("getTargetInventory") final Container inventory) {
handler.getCurrentlyOpenInventoryCommandKit(inventory).ifPresent(x -> {
// Set the commands.
Kit kitInfo = x.getFirst();
List<String> c = Lists.newArrayList();
// For each slot, is it a written book?
x.getSecond().slots().forEach(slot -> slot.poll().ifPresent(item -> {
if (item.getType().equals(ItemTypes.WRITTEN_BOOK)) {
item.get(Keys.BOOK_PAGES).ifPresent(y -> c.add(fixup(y)));
} else if (item.getType().equals(ItemTypes.WRITABLE_BOOK)) {
item.get(Keys.BOOK_PAGES).ifPresent(page -> c.add(getCommandFromText(page)));
} else {
// Drop the item.
item.get(Keys.ITEM_BLOCKSTATE).ifPresent(z -> {
World world = player.getLocation().getExtent();
Entity e = world.createEntity(EntityTypes.ITEM, player.getLocation().getPosition());
e.offer(Keys.ITEM_BLOCKSTATE, z);
world.spawnEntity(e);
});
}
kitInfo.setCommands(c);
handler.saveKit(kitInfo);
}));
player.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.command.edit.success", kitInfo.getName()));
handler.removeKitCommandInventoryFromListener(inventory);
});
handler.removeViewer(inventory);
}
Aggregations