@Override public org.bukkit.BanEntry getBanEntry(String target) { Validate.notNull(target, "Target cannot be null"); GameProfile profile = MinecraftServer.getServer().func_152358_ax().func_152655_a(target); if (profile == null) { return null; } UserListBansEntry entry = (UserListBansEntry) list.func_152683_b(profile); if (entry == null) { return null; } return new CraftProfileBanEntry(profile, entry, list); }
@Override public org.bukkit.BanEntry addBan(String target, String reason, Date expires, String source) { Validate.notNull(target, "Ban target cannot be null"); GameProfile profile = MinecraftServer.getServer().func_152358_ax().func_152655_a(target); if (profile == null) { return null; } UserListBansEntry entry = new UserListBansEntry(profile, new Date(), StringUtils.isBlank(source) ? null : source, expires, StringUtils.isBlank(reason) ? null : reason); list.func_152687_a(entry); try { list.func_152678_f(); } catch (IOException ex) { MinecraftServer.getLogger().error("Failed to save banned-players.json, " + ex.getMessage()); } return new CraftProfileBanEntry(profile, entry, list); }
@Override public void run() { if (this.ban) { MinecraftServer minecraftserver = SpongeImpl.getServer(); GameProfile gameprofile = minecraftserver.getPlayerProfileCache().getGameProfileForUsername(player.getName()); UserListBansEntry userlistbansentry = new UserListBansEntry(gameprofile, null, ((EntityPlayer) player).getName(), null, this.reason.toPlain()); minecraftserver.getPlayerList().getBannedPlayers().addEntry(userlistbansentry); EntityPlayerMP entityplayermp = minecraftserver.getPlayerList().getPlayerByUsername(this.player.getName()); if (entityplayermp != null) { entityplayermp.connection.disconnect(new TextComponentTranslation("You are banned from this server.")); } } }
public CraftProfileBanEntry(GameProfile profile, UserListBansEntry entry, UserListBans list) { this.list = list; this.profile = profile; this.created = entry.getCreated() != null ? new Date(entry.getCreated().getTime()) : null; this.source = entry.getSource(); this.expiration = entry.getBanEndDate() != null ? new Date(entry.getBanEndDate().getTime()) : null; this.reason = entry.getBanReason(); }
@Override public void save() { UserListBansEntry entry = new UserListBansEntry(profile, this.created, this.source, this.expiration, this.reason); this.list.func_152687_a(entry); try { this.list.func_152678_f(); } catch (IOException ex) { MinecraftServer.getLogger().error("Failed to save banned-players.json, " + ex.getMessage()); } }
@Override public Set<org.bukkit.BanEntry> getBanEntries() { ImmutableSet.Builder<org.bukkit.BanEntry> builder = ImmutableSet.builder(); for (UserListEntry entry : list.getValues()) { GameProfile profile = (GameProfile) entry.func_152640_f(); // Should be getKey builder.add(new CraftProfileBanEntry(profile, (UserListBansEntry) entry, list)); } return builder.build(); }
/** * Callback when the command is invoked */ public void processCommand(ICommandSender sender, String[] args) throws CommandException { if (args.length >= 1 && args[0].length() > 0) { MinecraftServer minecraftserver = MinecraftServer.getServer(); GameProfile gameprofile = minecraftserver.getPlayerProfileCache().getGameProfileForUsername(args[0]); if (gameprofile == null) { throw new CommandException("commands.ban.failed", new Object[] {args[0]}); } else { String s = null; if (args.length >= 2) { s = getChatComponentFromNthArg(sender, args, 1).getUnformattedText(); } UserListBansEntry userlistbansentry = new UserListBansEntry(gameprofile, (Date)null, sender.getName(), (Date)null, s); minecraftserver.getConfigurationManager().getBannedPlayers().addEntry(userlistbansentry); EntityPlayerMP entityplayermp = minecraftserver.getConfigurationManager().getPlayerByUsername(args[0]); if (entityplayermp != null) { entityplayermp.playerNetServerHandler.kickPlayerFromServer("You are banned from this server."); } notifyOperators(sender, this, "commands.ban.success", new Object[] {args[0]}); } } else { throw new WrongUsageException("commands.ban.usage", new Object[0]); } }
/** * Callback for when the command is executed */ public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { if (args.length >= 1 && args[0].length() > 0) { GameProfile gameprofile = server.getPlayerProfileCache().getGameProfileForUsername(args[0]); if (gameprofile == null) { throw new CommandException("commands.ban.failed", new Object[] {args[0]}); } else { String s = null; if (args.length >= 2) { s = getChatComponentFromNthArg(sender, args, 1).getUnformattedText(); } UserListBansEntry userlistbansentry = new UserListBansEntry(gameprofile, (Date)null, sender.getName(), (Date)null, s); server.getPlayerList().getBannedPlayers().addEntry(userlistbansentry); EntityPlayerMP entityplayermp = server.getPlayerList().getPlayerByUsername(args[0]); if (entityplayermp != null) { entityplayermp.connection.kickPlayerFromServer("You are banned from this server."); } notifyCommandListener(sender, this, "commands.ban.success", new Object[] {args[0]}); } } else { throw new WrongUsageException("commands.ban.usage", new Object[0]); } }