use of org.bukkit.BanEntry in project Essentials by EssentialsX.
the class EssentialsPlayerListener method onPlayerLoginBanned.
@EventHandler(priority = EventPriority.LOW)
public void onPlayerLoginBanned(final PlayerLoginEvent event) {
switch(event.getResult()) {
case KICK_BANNED:
BanEntry banEntry = ess.getServer().getBanList(BanList.Type.NAME).getBanEntry(event.getPlayer().getName());
if (banEntry != null) {
Date banExpiry = banEntry.getExpiration();
if (banExpiry != null) {
String expiry = DateUtil.formatDateDiff(banExpiry.getTime());
event.setKickMessage(tl("tempbanJoin", expiry, banEntry.getReason()));
} else {
event.setKickMessage(tl("banJoin", banEntry.getReason()));
}
} else {
banEntry = ess.getServer().getBanList(BanList.Type.IP).getBanEntry(event.getAddress().getHostAddress());
if (banEntry != null) {
event.setKickMessage(tl("banIpJoin", banEntry.getReason()));
}
}
break;
default:
break;
}
}
use of org.bukkit.BanEntry in project Essentials by EssentialsX.
the class Commandseen method seenOffline.
private void seenOffline(final Server server, final CommandSource sender, User user, final boolean showBan, final boolean showIp, final boolean showLocation) throws Exception {
user.setDisplayNick();
if (user.getLastLogout() > 0) {
sender.sendMessage(tl("seenOffline", user.getName(), DateUtil.formatDateDiff(user.getLastLogout())));
} else {
sender.sendMessage(tl("userUnknown", user.getName()));
}
if (ess.getSettings().isDebug()) {
ess.getLogger().info("UUID: " + user.getBase().getUniqueId().toString());
}
List<String> history = ess.getUserMap().getUserHistory(user.getBase().getUniqueId());
if (history != null && history.size() > 1) {
sender.sendMessage(tl("seenAccounts", StringUtil.joinListSkip(", ", user.getName(), history)));
}
if (BanLookup.isBanned(ess, user)) {
final BanEntry banEntry = BanLookup.getBanEntry(ess, user.getName());
final String reason = showBan ? banEntry.getReason() : tl("true");
sender.sendMessage(tl("whoisBanned", reason));
if (banEntry.getExpiration() != null) {
Date expiry = banEntry.getExpiration();
String expireString = tl("now");
if (expiry.after(new Date())) {
expireString = DateUtil.formatDateDiff(expiry.getTime());
}
sender.sendMessage(tl("whoisTempBanned", expireString));
}
}
final String location = user.getGeoLocation();
if (location != null && (!(sender.isPlayer()) || ess.getUser(sender.getPlayer()).isAuthorized("essentials.geoip.show"))) {
sender.sendMessage(tl("whoisGeoLocation", location));
}
if (showIp) {
if (!user.getLastLoginAddress().isEmpty()) {
sender.sendMessage(tl("whoisIPAddress", user.getLastLoginAddress()));
}
}
if (showLocation) {
final Location loc = user.getLogoutLocation();
if (loc != null) {
sender.sendMessage(tl("whoisLocation", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
}
}
}
use of org.bukkit.BanEntry in project Essentials by drtshock.
the class EssentialsPlayerListener method onPlayerLoginBanned.
@EventHandler(priority = EventPriority.LOW)
public void onPlayerLoginBanned(final PlayerLoginEvent event) {
switch(event.getResult()) {
case KICK_BANNED:
BanEntry banEntry = ess.getServer().getBanList(BanList.Type.NAME).getBanEntry(event.getPlayer().getName());
if (banEntry != null) {
Date banExpiry = banEntry.getExpiration();
if (banExpiry != null) {
String expiry = DateUtil.formatDateDiff(banExpiry.getTime());
event.setKickMessage(tl("tempbanJoin", expiry, banEntry.getReason()));
} else {
event.setKickMessage(tl("banJoin", banEntry.getReason()));
}
} else {
banEntry = ess.getServer().getBanList(BanList.Type.IP).getBanEntry(event.getAddress().getHostAddress());
if (banEntry != null) {
event.setKickMessage(tl("banIpJoin", banEntry.getReason()));
}
}
break;
default:
break;
}
}
use of org.bukkit.BanEntry in project Essentials by drtshock.
the class Commandseen method seenOffline.
private void seenOffline(final Server server, final CommandSource sender, User user, final boolean showBan, final boolean showIp, final boolean showLocation) throws Exception {
user.setDisplayNick();
if (user.getLastLogout() > 0) {
sender.sendMessage(tl("seenOffline", user.getName(), DateUtil.formatDateDiff(user.getLastLogout())));
} else {
sender.sendMessage(tl("userUnknown", user.getName()));
}
if (ess.getSettings().isDebug()) {
ess.getLogger().info("UUID: " + user.getBase().getUniqueId().toString());
}
List<String> history = ess.getUserMap().getUserHistory(user.getBase().getUniqueId());
if (history != null && history.size() > 1) {
sender.sendMessage(tl("seenAccounts", StringUtil.joinListSkip(", ", user.getName(), history)));
}
if (BanLookup.isBanned(ess, user)) {
final BanEntry banEntry = BanLookup.getBanEntry(ess, user.getName());
final String reason = showBan ? banEntry.getReason() : tl("true");
sender.sendMessage(tl("whoisBanned", reason));
if (banEntry.getExpiration() != null) {
Date expiry = banEntry.getExpiration();
String expireString = tl("now");
if (expiry.after(new Date())) {
expireString = DateUtil.formatDateDiff(expiry.getTime());
}
sender.sendMessage(tl("whoisTempBanned", expireString));
}
}
final String location = user.getGeoLocation();
if (location != null && (!(sender.isPlayer()) || ess.getUser(sender.getPlayer()).isAuthorized("essentials.geoip.show"))) {
sender.sendMessage(tl("whoisGeoLocation", location));
}
if (showIp) {
if (!user.getLastLoginAddress().isEmpty()) {
sender.sendMessage(tl("whoisIPAddress", user.getLastLoginAddress()));
}
}
if (showLocation) {
final Location loc = user.getLogoutLocation();
if (loc != null) {
sender.sendMessage(tl("whoisLocation", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
}
}
}
use of org.bukkit.BanEntry in project Glowstone by GlowstoneMC.
the class BanListCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args, CommandMessages messages) {
if (!testPermission(sender, messages.getPermissionMessage())) {
return true;
}
final ResourceBundle resourceBundle = messages.getResourceBundle();
BanList.Type banType;
if (args.length > 0) {
Collator caseInsensitive = Collator.getInstance(messages.getLocale());
caseInsensitive.setStrength(Collator.PRIMARY);
if (caseInsensitive.compare(args[0], "ips") == 0) {
// NON-NLS
banType = BanList.Type.IP;
} else if (caseInsensitive.compare(args[0], "players") == 0) {
// NON-NLS
banType = BanList.Type.NAME;
} else {
sendUsageMessage(sender, messages);
return false;
}
} else {
banType = BanList.Type.NAME;
}
final Set<BanEntry> banEntries = Bukkit.getBanList(banType).getBanEntries();
if (banEntries.isEmpty()) {
new LocalizedStringImpl("banlist.empty", resourceBundle).send(sender);
} else {
final Stream<String> targets = banEntries.stream().map(BanEntry::getTarget);
new LocalizedStringImpl("banlist.non-empty", resourceBundle).send(sender, banEntries.size());
sender.sendMessage(messages.joinList(targets));
}
return true;
}
Aggregations