mirror of
https://github.com/LOOHP/Limbo.git
synced 2026-06-07 13:31:43 +00:00
Improved kick command logic & player class internal code
This commit is contained in:
@@ -57,22 +57,27 @@ public class DefaultCommands implements CommandExecutor, TabCompletor {
|
||||
if (sender.hasPermission("limboserver.kick")) {
|
||||
BaseComponent reason = new TranslatableComponent("multiplayer.disconnect.kicked");
|
||||
boolean customReason = false;
|
||||
Player player = args.length > 1 ? Limbo.getInstance().getPlayer(args[1]) : null;
|
||||
if (player != null) {
|
||||
if (args.length < 2) {
|
||||
if (args.length > 1) {
|
||||
Player player = Limbo.getInstance().getPlayer(args[1]);
|
||||
if (player != null) {
|
||||
if (args.length >= 2) {
|
||||
String reasonRaw = String.join(" ", Arrays.copyOfRange(args, 2, args.length));
|
||||
if (reasonRaw.trim().length() > 0) {
|
||||
reason = new TextComponent(reasonRaw);
|
||||
customReason = true;
|
||||
}
|
||||
}
|
||||
player.disconnect(reason);
|
||||
if (customReason) {
|
||||
sender.sendMessage(ChatColor.RED + "Kicked the player " + player.getName() + " for the reason: " + reason.toLegacyText());
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Kicked the player " + player.getName());
|
||||
}
|
||||
} else {
|
||||
reason = new TextComponent(String.join(" ", Arrays.copyOfRange(args, 2, args.length)));
|
||||
customReason = true;
|
||||
player.disconnect(reason);
|
||||
}
|
||||
if (customReason) {
|
||||
sender.sendMessage(ChatColor.RED + "Kicked the player " + player.getName() + " for the reason: " + reason.toLegacyText());
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Kicked the player " + player.getName());
|
||||
sender.sendMessage(ChatColor.RED + "Player is not online!");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Player is not online!");
|
||||
sender.sendMessage(ChatColor.RED + "You have to specifiy a player!");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You do not have permission to use that command!");
|
||||
|
||||
@@ -190,9 +190,7 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
}
|
||||
PacketPlayOutPositionAndLook positionLook = new PacketPlayOutPositionAndLook(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch(), 1, false);
|
||||
clientConnection.sendPacket(positionLook);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +199,7 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
}
|
||||
|
||||
public void sendMessage(String message, UUID uuid) {
|
||||
sendMessage(TextComponent.fromLegacyText(message), uuid);
|
||||
sendMessage(new TextComponent(message), uuid);
|
||||
}
|
||||
|
||||
public void sendMessage(BaseComponent component, UUID uuid) {
|
||||
@@ -213,13 +211,11 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
try {
|
||||
PacketPlayOutChat chat = new PacketPlayOutChat(component, 0, uuid);
|
||||
clientConnection.sendPacket(chat);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
public void sendMessage(String message) {
|
||||
sendMessage(TextComponent.fromLegacyText(message));
|
||||
sendMessage(new TextComponent(message));
|
||||
}
|
||||
|
||||
public void sendMessage(BaseComponent component) {
|
||||
@@ -231,9 +227,7 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
try {
|
||||
PacketPlayOutChat chat = new PacketPlayOutChat(component, 0, new UUID(0, 0));
|
||||
clientConnection.sendPacket(chat);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
@@ -241,7 +235,7 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
}
|
||||
|
||||
public void disconnect(String reason) {
|
||||
disconnect(TextComponent.fromLegacyText(reason));
|
||||
disconnect(new TextComponent(reason));
|
||||
}
|
||||
|
||||
public void disconnect(BaseComponent reason) {
|
||||
|
||||
Reference in New Issue
Block a user