forked from BLOCKFANTASY/LOOHP-Limbo
Improved kick command logic & player class internal code
This commit is contained in:
parent
6847f46a3b
commit
9eb2060457
|
|
@ -57,15 +57,17 @@ 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 (args.length > 1) {
|
||||
Player player = Limbo.getInstance().getPlayer(args[1]);
|
||||
if (player != null) {
|
||||
if (args.length < 2) {
|
||||
player.disconnect(reason);
|
||||
} else {
|
||||
reason = new TextComponent(String.join(" ", Arrays.copyOfRange(args, 2, args.length)));
|
||||
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);
|
||||
}
|
||||
}
|
||||
player.disconnect(reason);
|
||||
if (customReason) {
|
||||
sender.sendMessage(ChatColor.RED + "Kicked the player " + player.getName() + " for the reason: " + reason.toLegacyText());
|
||||
} else {
|
||||
|
|
@ -74,6 +76,9 @@ public class DefaultCommands implements CommandExecutor, TabCompletor {
|
|||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Player is not online!");
|
||||
}
|
||||
} else {
|
||||
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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue