use of org.spongepowered.api.event.Listener in project Almura by AlmuraDev.
the class ServerHeadUpDisplayManager method onEconomyTransaction.
@Listener(order = Order.LAST)
public void onEconomyTransaction(EconomyTransactionEvent event) {
final TransactionResult result = event.getTransactionResult();
final Account account = result.getAccount();
if (account instanceof UniqueAccount) {
Sponge.getServer().getPlayer(((UniqueAccount) account).getUniqueId()).ifPresent(player -> Task.builder().delayTicks(1).execute(() -> {
final ClientboundPlayerCurrencyPacket packet = this.createPlayerCurrencyPacket(player);
if (packet != null) {
this.network.sendTo(player, packet);
}
}).submit(this.container));
}
}
use of org.spongepowered.api.event.Listener in project Almura by AlmuraDev.
the class ServerNickManager method onClientConnectionEventJoin.
@Listener
public void onClientConnectionEventJoin(final ClientConnectionEvent.Join event) {
this.game.getServiceManager().provide(NucleusNicknameService.class).ifPresent((service) -> {
service.getNickname(event.getTargetEntity()).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(event.getTargetEntity(), TextSerializers.LEGACY_FORMATTING_CODE.deserialize(newNick));
} catch (NicknameException e) {
e.printStackTrace();
}
}
try {
displayNameField.set(event.getTargetEntity(), newNick);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
});
// Send the joining player's nickname to others
Text nickname = service.getNickname(event.getTargetEntity()).orElse(null);
if (nickname == null) {
nickname = Text.of(event.getTargetEntity().getName());
} else {
nickname = Text.of("~" + nickname.toPlain());
}
final ClientboundNucleusNameChangeMappingPacket joiningPlayerPacket = this.getMappingMessage(event.getTargetEntity(), nickname);
this.game.getServer().getOnlinePlayers().stream().filter((player) -> !player.getUniqueId().equals(event.getTargetEntity().getUniqueId())).forEach((player) -> this.network.sendTo(player, joiningPlayerPacket));
Task.builder().delayTicks(40).execute(t -> {
// Send everyone's nicknames to the joining player
this.network.sendTo(event.getTargetEntity(), this.getMappingMessage(service));
}).submit(this.container);
});
}
use of org.spongepowered.api.event.Listener in project Almura by AlmuraDev.
the class ServerNickManager method onChangeNickname.
@Listener(order = Order.POST)
public void onChangeNickname(final NucleusChangeNicknameEvent event, @Getter("getTargetUser") final Player player) throws IllegalAccessException {
final EntityPlayerMP mcPlayer = (EntityPlayerMP) player;
final String oldNick = mcPlayer.getDisplayNameString();
final String newNick = TextSerializers.LEGACY_FORMATTING_CODE.serialize(event.getNewNickname());
if (!oldNick.equals(newNick)) {
// Tell the Forge mods
final String modNick = ForgeEventFactory.getPlayerDisplayName(mcPlayer, newNick);
final Text finalNick = TextSerializers.LEGACY_FORMATTING_CODE.deserialize(modNick);
if (!newNick.equals(modNick)) {
// Mod says our nick needs to be something else
this.game.getServiceManager().provide(NucleusNicknameService.class).ifPresent((service) -> {
try {
service.setNickname(player, finalNick);
} catch (NicknameException e) {
e.printStackTrace();
}
});
}
displayNameField.set(mcPlayer, modNick);
// Tell everyone about the new nick
this.network.sendToAll(this.getMappingMessage(player, Text.of("~" + finalNick.toPlain())));
}
}
use of org.spongepowered.api.event.Listener in project Almura by AlmuraDev.
the class SignEditFeature method interact.
@Listener
public void interact(final InteractBlockEvent.Secondary.MainHand event, @Root final Player player) {
if (!(player instanceof EntityPlayerMP) || !player.require(Keys.IS_SNEAKING)) {
return;
}
final BlockSnapshot snapshot = event.getTargetBlock();
final BlockType type = snapshot.getState().getType();
if (type == BlockTypes.STANDING_SIGN || type == BlockTypes.WALL_SIGN) {
snapshot.getLocation().flatMap(Location::getTileEntity).ifPresent((be) -> {
if (be instanceof TileEntitySign) {
((EntityPlayerMP) player).connection.sendPacket(new SPacketSignEditorOpen(VecHelper.toBlockPos(snapshot.getPosition())));
}
});
}
}
use of org.spongepowered.api.event.Listener in project Almura by AlmuraDev.
the class ServerTitleManager method onClientConnectionEventJoin.
@Listener
public void onClientConnectionEventJoin(ClientConnectionEvent.Join event, @Getter("getTargetEntity") Player player) {
// Send joining player's title to everyone
Text selectedTitle = this.getSelectedTitleFor(player).orElse(null);
if (selectedTitle == null) {
selectedTitle = this.getTitlesFor(player).stream().findFirst().orElse(null);
if (selectedTitle != null) {
this.putSelectedTitle(player.getUniqueId(), selectedTitle);
}
}
Task.builder().async().delayTicks(40).execute(() -> this.createPlayerSelectedTitlesPacket().ifPresent((packet) -> {
// Send joining player everyone's title (including itself)
this.network.sendTo(player, packet);
})).submit(this.container);
if (selectedTitle != null) {
// Java, just why
final Text found = selectedTitle;
this.game.getServer().getOnlinePlayers().stream().filter((p) -> !p.getUniqueId().equals(player.getUniqueId())).forEach((p) -> this.network.sendTo(p, this.createAddPlayerSelectedTitlePacket(player.getUniqueId(), found)));
}
}
Aggregations