Java Code Examples for cn.nukkit.Player#kick()
The following examples show how to use
cn.nukkit.Player#kick() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KickAllCommand.java From EssentialsNK with GNU General Public License v3.0 | 6 votes |
public boolean execute(CommandSender sender, String label, String[] args) { if (!this.testPermission(sender)) { return false; } if (args.length != 0) { this.sendUsage(sender); return false; } int count = api.getServer().getOnlinePlayers().size(); if (count == 0 || (sender instanceof Player && count == 1)) { sender.sendMessage(TextFormat.RED + Language.translate("commands.kickall.noplayer")); return false; } String reason = String.join(" ", args); for (Player player : api.getServer().getOnlinePlayers().values()) { if (player != sender) { player.kick(reason); } } sender.sendMessage(Language.translate("commands.kickall.success")); return true; }
Example 2
Source File: BanCommand.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { if (!this.testPermission(sender)) { return true; } if (args.length == 0) { sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage)); return false; } String name = args[0]; String reason = ""; for (int i = 1; i < args.length; i++) { reason += args[i] + " "; } if (reason.length() > 0) { reason = reason.substring(0, reason.length() - 1); } sender.getServer().getNameBans().addBan(name, reason, null, sender.getName()); Player player = sender.getServer().getPlayerExact(name); if (player != null) { player.kick(PlayerKickEvent.Reason.NAME_BANNED, !reason.isEmpty() ? "Banned by admin. Reason: " + reason : "Banned by admin"); } Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.ban.success", player != null ? player.getName() : name)); return true; }
Example 3
Source File: BanIpCommand.java From Jupiter with GNU General Public License v3.0 | 5 votes |
private void processIPBan(String ip, CommandSender sender, String reason) { sender.getServer().getIPBans().addBan(ip, reason, null, sender.getName()); for (Player player : new ArrayList<>(sender.getServer().getOnlinePlayers().values())) { if (player.getAddress().equals(ip)) { player.kick(PlayerKickEvent.Reason.IP_BANNED, !reason.isEmpty() ? reason : "IP banned"); } } sender.getServer().getNetwork().blockAddress(ip, -1); }
Example 4
Source File: KickCommand.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { if (!this.testPermission(sender)) { return true; } if (args.length == 0) { sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage)); return false; } String name = args[0]; String reason = ""; for (int i = 1; i < args.length; i++) { reason += args[i] + " "; } if (reason.length() > 0) { reason = reason.substring(0, reason.length() - 1); } Player player = sender.getServer().getPlayer(name); if (player != null) { player.kick(PlayerKickEvent.Reason.KICKED_BY_ADMIN, reason); if (reason.length() >= 1) { Command.broadcastCommandMessage(sender, new TranslationContainer("commands.kick.success.reason", new String[]{player.getName(), reason}) ); } else { Command.broadcastCommandMessage(sender, new TranslationContainer("commands.kick.success", player.getName())); } } else { sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound")); } return true; }
Example 5
Source File: BanCommand.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { if (!this.testPermission(sender)) { return true; } if (args.length == 0) { sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage)); return false; } String name = args[0]; String reason = ""; for (int i = 1; i < args.length; i++) { reason += args[i] + " "; } if (reason.length() > 0) { reason = reason.substring(0, reason.length() - 1); } sender.getServer().getNameBans().addBan(name, reason, null, sender.getName()); Player player = sender.getServer().getPlayerExact(name); if (player != null) { player.kick(PlayerKickEvent.Reason.NAME_BANNED, !reason.isEmpty() ? "Banned by admin. Reason: " + reason : "Banned by admin"); } Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.ban.success", player != null ? player.getName() : name)); return true; }
Example 6
Source File: BanIpCommand.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private void processIPBan(String ip, CommandSender sender, String reason) { sender.getServer().getIPBans().addBan(ip, reason, null, sender.getName()); for (Player player : new ArrayList<>(sender.getServer().getOnlinePlayers().values())) { if (player.getAddress().equals(ip)) { player.kick(PlayerKickEvent.Reason.IP_BANNED, !reason.isEmpty() ? reason : "IP banned"); } } sender.getServer().getNetwork().blockAddress(ip, -1); }
Example 7
Source File: KickCommand.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { if (!this.testPermission(sender)) { return true; } if (args.length == 0) { sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage)); return false; } String name = args[0]; String reason = ""; for (int i = 1; i < args.length; i++) { reason += args[i] + " "; } if (reason.length() > 0) { reason = reason.substring(0, reason.length() - 1); } Player player = sender.getServer().getPlayer(name); if (player != null) { player.kick(PlayerKickEvent.Reason.KICKED_BY_ADMIN, reason); if (reason.length() >= 1) { Command.broadcastCommandMessage(sender, new TranslationContainer("commands.kick.success.reason", player.getName(), reason) ); } else { Command.broadcastCommandMessage(sender, new TranslationContainer("commands.kick.success", player.getName())); } } else { sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound")); } return true; }
Example 8
Source File: BanCommand.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { if (!this.testPermission(sender)) { return true; } if (args.length == 0) { sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage)); return false; } String name = args[0]; String reason = ""; for (int i = 1; i < args.length; i++) { reason += args[i] + " "; } if (reason.length() > 0) { reason = reason.substring(0, reason.length() - 1); } sender.getServer().getNameBans().addBan(name, reason, null, sender.getName()); Player player = sender.getServer().getPlayerExact(name); if (player != null) { player.kick(PlayerKickEvent.Reason.NAME_BANNED, !reason.isEmpty() ? "Banned by admin. Reason: " + reason : "Banned by admin"); } Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.ban.success", player != null ? player.getName() : name)); return true; }
Example 9
Source File: BanIpCommand.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private void processIPBan(String ip, CommandSender sender, String reason) { sender.getServer().getIPBans().addBan(ip, reason, null, sender.getName()); for (Player player : new ArrayList<>(sender.getServer().getOnlinePlayers().values())) { if (player.getAddress().equals(ip)) { player.kick(PlayerKickEvent.Reason.IP_BANNED, !reason.isEmpty() ? reason : "IP banned"); } } sender.getServer().getNetwork().blockAddress(ip, -1); }
Example 10
Source File: KickCommand.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { if (!this.testPermission(sender)) { return true; } if (args.length == 0) { sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage)); return false; } String name = args[0]; String reason = ""; for (int i = 1; i < args.length; i++) { reason += args[i] + " "; } if (reason.length() > 0) { reason = reason.substring(0, reason.length() - 1); } Player player = sender.getServer().getPlayer(name); if (player != null) { player.kick(PlayerKickEvent.Reason.KICKED_BY_ADMIN, reason); if (reason.length() >= 1) { Command.broadcastCommandMessage(sender, new TranslationContainer("commands.kick.success.reason", new String[]{player.getName(), reason}) ); } else { Command.broadcastCommandMessage(sender, new TranslationContainer("commands.kick.success", player.getName())); } } else { sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound")); } return true; }