use of net.minecraft.server.MinecraftServer in project Almura by AlmuraDev.
the class ServerboundClaimGuiToggleDenyMessagesRequestPacketHandler method handleMessage.
@Override
public void handleMessage(final ServerboundClaimGuiToggleDenyMessagesRequestPacket message, final RemoteConnection connection, final Platform.Type side) {
if (side.isServer() && connection instanceof PlayerConnection && PacketUtil.checkThreadAndEnqueue((MinecraftServer) Sponge.getServer(), message, this, connection, side)) {
final Player player = ((PlayerConnection) connection).getPlayer();
final Claim claim = serverClaimManager.claimLookup(player, message.x, message.y, message.z, message.worldName);
if (claim != null) {
// if GP is loaded, claim should never be null.
final boolean isOwner = (claim.getOwnerUniqueId().equals(player.getUniqueId()));
final boolean isAdmin = player.hasPermission(ServerClaimManager.adminPermission);
if (isOwner || isAdmin) {
this.serverClaimManager.toggleClaimDenyMessages(claim, message.value);
this.serverClaimManager.sendUpdateTo(player, claim, null, true, "claimGuiToggleDenyMessage");
if (message.value) {
this.notificationManager.sendPopupNotification(player, ServerClaimManager.notificationTitle, Text.of("Deny Messages Enabled!"), 5);
} else {
this.notificationManager.sendPopupNotification(player, ServerClaimManager.notificationTitle, Text.of("Deny Messages Disabled!"), 5);
}
} else {
this.notificationManager.sendPopupNotification(player, ServerClaimManager.notificationTitle, Text.of("Insufficient Permissions!"), 5);
}
}
}
}
use of net.minecraft.server.MinecraftServer in project Almura by AlmuraDev.
the class ServerboundNucleusNameChangePacketHandler method handleMessage.
@Override
public void handleMessage(final ServerboundNucleusNameChangePacket message, final RemoteConnection connection, final Platform.Type side) {
if (side.isServer() && connection instanceof PlayerConnection && PacketUtil.checkThreadAndEnqueue((MinecraftServer) Sponge.getServer(), message, this, connection, side)) {
final Player player = ((PlayerConnection) connection).getPlayer();
if (message.nickname.isEmpty()) {
// nullify the nicknamet if the server sends an empty chance packet.
message.nickname = null;
}
final Text nickname = TextSerializers.LEGACY_FORMATTING_CODE.deserialize(message.nickname == null ? player.getName() : message.nickname);
// Validation checks
if (message.nickname != null) {
if (!player.hasPermission("nucleus.nick.base")) {
// Nucleus Nickname Permission
this.notificationManager.sendPopupNotification(player, Text.of("Nickname Error!"), Text.of("Insufficient Permissions!"), 5);
return;
}
if (!NickUtil.nickNameRegex.matcher(nickname.toPlain()).matches()) {
this.notificationManager.sendPopupNotification(player, Text.of("Nickname Error!"), Text.of("Invalid Character in Nickname!"), 5);
}
if (nickname.isEmpty() || nickname.toPlain().length() <= 3 || nickname.toPlain().length() > 20) {
this.notificationManager.sendPopupNotification(player, Text.of("Nickname Error!"), Text.of("Validation of Nickname data failed!"), 5);
return;
}
}
this.nickManager.setForgeNickname((EntityPlayer) player, message.nickname == null ? player.getName() : message.nickname);
this.game.getServiceManager().provide(NucleusNicknameService.class).ifPresent((service) -> {
try {
if (message.nickname == null || player.getName().equalsIgnoreCase(message.nickname)) {
// Detect if player name equals
// packet name, if it does, the client is attempting to remove the nickname.
this.nickManager.removeNickname(service, player);
} else {
this.nickManager.setNickname(service, player, nickname);
}
} catch (NicknameException e) {
e.printStackTrace();
return;
}
this.nickManager.sendNicknameUpdate(service, player);
});
this.game.getServer().getOnlinePlayers().forEach(onlinePlayer -> {
if (onlinePlayer.getUniqueId().equals(player.getUniqueId())) {
if (message.nickname == null || player.getName().equalsIgnoreCase(message.nickname)) {
this.notificationManager.sendPopupNotification(onlinePlayer, Text.of("Nickname Removed!"), Text.of("You are now known as ", player.getName()), 5);
} else {
this.notificationManager.sendPopupNotification(onlinePlayer, Text.of("New Nickname!"), Text.of("You are now known as ", message.nickname), 5);
}
} else {
if (message.nickname == null || player.getName().equalsIgnoreCase(message.nickname)) {
this.notificationManager.sendPopupNotification(onlinePlayer, Text.of("Nickname removed!"), Text.of(player.getName() + " has removed their nickname."), 5);
} else {
this.notificationManager.sendPopupNotification(onlinePlayer, Text.of("New Nickname!"), Text.of(player.getName() + " is now known as ", message.nickname), 5);
}
}
});
}
}
use of net.minecraft.server.MinecraftServer in project Almura by AlmuraDev.
the class ServerboundModifyExchangePacketHandler method handleMessage.
@Override
public void handleMessage(final ServerboundModifyExchangePacket message, final RemoteConnection connection, final Platform.Type side) {
if (side.isServer() && connection instanceof PlayerConnection && PacketUtil.checkThreadAndEnqueue((MinecraftServer) Sponge.getServer(), message, this, connection, side)) {
checkNotNull(message.type);
final Player player = ((PlayerConnection) connection).getPlayer();
switch(message.type) {
case ADD:
this.exchangeManager.handleExchangeAdd(player, message.id, message.name, message.permission, message.isHidden);
break;
case MODIFY:
this.exchangeManager.handleExchangeModify(player, message.id, message.name, message.permission, message.isHidden);
break;
case DELETE:
this.exchangeManager.handleExchangeDelete(player, message.id);
break;
default:
throw new UnsupportedOperationException(message.type + " is not supported yet!");
}
}
}
use of net.minecraft.server.MinecraftServer in project Almura by AlmuraDev.
the class ServerboundTransactionRequestPacketHandler method handleMessage.
@Override
public void handleMessage(final ServerboundTransactionRequestPacket message, final RemoteConnection connection, final Platform.Type side) {
if (side.isServer() && connection instanceof PlayerConnection && PacketUtil.checkThreadAndEnqueue((MinecraftServer) Sponge.getServer(), message, this, connection, side)) {
final Player player = ((PlayerConnection) connection).getPlayer();
this.exchangeManager.handleTransaction(player, message.id, message.listItemRecNo, message.quantity);
}
}
use of net.minecraft.server.MinecraftServer in project Almura by AlmuraDev.
the class ServerboundMembershipPurchaseRequestPacketHandler method handleMessage.
@Override
public void handleMessage(ServerboundMembershipPurchaseRequestPacket message, RemoteConnection connection, Platform.Type side) {
if (side.isServer() && connection instanceof PlayerConnection && Sponge.isServerAvailable()) {
final MinecraftServer server = (MinecraftServer) Sponge.getServer();
if (PacketUtil.checkThreadAndEnqueue(server, message, this, connection, side)) {
final PlayerConnection playerConnection = (PlayerConnection) connection;
final Player player = playerConnection.getPlayer();
if (message.type == 1) {
membershipHandler.handleMembershipPurchase(player, message.membershipLevel);
} else if (message.type == 2) {
membershipHandler.handleMembershipSkills(player, message.membershipLevel);
}
}
}
}
Aggregations