Improvements to the Clans ban system in general as it was performing more operations than required, and accessing the database more than was necessary. Polished up the Clans ban GUI as well.

This commit is contained in:
Ben 2016-05-01 01:42:11 +01:00
parent f63a872bd4
commit 2337e89a93
10 changed files with 231 additions and 276 deletions

View File

@ -141,7 +141,12 @@ public class UtilServer
public static boolean IsOnline(String name)
{
return !UtilStreams.IsEmpty(getPlayersCollection().stream().filter(player -> player.getName().equals(name)));
return !UtilStreams.IsEmpty(getPlayersCollection().stream().filter(name::equals));
}
public static boolean IsOffline(String name)
{
return !UtilStreams.IsEmpty(getPlayersCollection().stream().filter(name::equals));
}
public static Player GetPlayer(String name)

View File

@ -2,10 +2,13 @@ package mineplex.core.common.util;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.List;
import java.util.stream.Stream;
import org.apache.commons.lang.Validate;
import com.google.common.collect.Lists;
public class UtilStreams
{
public static boolean IsEmpty(Stream<?> stream)
@ -55,4 +58,9 @@ public class UtilStreams
return read;
}
public static <T> List<T> ToList(Stream<T> filter)
{
return Lists.newArrayList((T[]) ToArray(filter));
}
}

View File

@ -24,6 +24,7 @@ import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.SkullMeta;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilInv;
public class ItemBuilder
{
@ -56,6 +57,7 @@ public class ItemBuilder
private Material _mat;
private String _title = null;
private boolean _unbreakable;
private boolean _dullEnchantment;
private String _playerHeadName = null;
private HashSet<ItemFlag> _itemFlags = new HashSet<ItemFlag>();
@ -268,6 +270,11 @@ public class ItemBuilder
item.addUnsafeEnchantments(_enchants);
if (_dullEnchantment)
{
UtilInv.addDullEnchantment(item);
}
return item;
}
@ -413,4 +420,11 @@ public class ItemBuilder
return this;
}
public ItemBuilder addDullEnchantment(boolean dullEnchantment)
{
_dullEnchantment = dullEnchantment;
return this;
}
}

View File

@ -642,11 +642,11 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
return;
}
if (_clansBans.willBeKicked(event.getPlayer()))
if (_clansBans.Get(event.getPlayer().getName()).isBanned())
{
return;
}
for (Player other : UtilServer.getPlayers())
{
if (_tutorial.inTutorial(other))
@ -655,7 +655,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
continue;
}
other.sendMessage(F.sys("Quit", event.getPlayer().getName()));
other.sendMessage(F.sys("Quit ", event.getPlayer().getName()));
}
}

View File

@ -6,6 +6,9 @@ import java.util.UUID;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilTime;
/**
* Stores the information about a ban in Clans.
*/
public class ClansBan
{
private int _id;
@ -90,4 +93,9 @@ public class ClansBan
{
return _uuid;
}
public void remove()
{
_removed = true;
}
}

View File

@ -1,17 +1,22 @@
package mineplex.game.clans.clans.ban;
import java.util.List;
import java.util.Set;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilTime;
/**
* Signifies a player on clans, and a Set of their current clan bans.
*/
public class ClansBanClient
{
public String Name;
public String UUID;
public List<ClansBan> Bans;
public Set<ClansBan> Bans;
public ClansBanClient(String uuid, List<ClansBan> bans)
public ClansBanClient(String name, String uuid, Set<ClansBan> bans)
{
Name = name;
UUID = uuid;
Bans = bans;
}
@ -75,7 +80,7 @@ public class ClansBanClient
continue;
}
if (ban.getTimeLeft() > longest.getTimeLeft())
if (ban.getTimeLeft() > longest.getTimeLeft() || ban.isPermanent())
{
longest = ban;
}

View File

@ -6,7 +6,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.Bukkit;
@ -17,16 +16,15 @@ import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.collect.Lists;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.ILoginProcessor;
import mineplex.core.common.DefaultHashMap;
import mineplex.core.common.Pair;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilStreams;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.donation.DonationManager;
@ -41,7 +39,7 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
private CoreClientManager _clientManager;
private ClansBanRepository _repository;
private Map<String, ClansBanClient> _clients;
private Map<String, Pair<String, String>> _cache;
private Map<String, ClansBanCache> _cache;
private DefaultHashMap<String, List<Runnable>> _runAfterLoad;
private ClansBanShop _shop;
@ -55,7 +53,7 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
_clientManager = clientManager;
_repository = new ClansBanRepository(plugin, this);
_repository = new ClansBanRepository(plugin);
_clients = new HashMap<>();
_cache = new HashMap<>();
@ -85,29 +83,30 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
}
player.kickPlayer(reason);
runSyncLater(() -> {
_toKick.remove(name);
}, 20l);
});
}
if (!event.getType().equals(UpdateType.MIN_01))
if (event.getType().equals(UpdateType.MIN_01))
{
return;
}
synchronized (_lock)
{
List<String> purge = Lists.newArrayList();
_clients.keySet().stream().filter(name -> Bukkit.getPlayer(name) == null).forEach(purge::add);
purge.forEach(this::UnloadClient);
synchronized (_lock)
{
UtilStreams.ToList(_clients.keySet().stream().filter(UtilServer::IsOnline)).forEach(this::UnloadClient);
}
}
}
public void ban(ClansBanClient client, String name, String admin, long time, String reason, Callback<ClansBanClient> callback)
public void ban(ClansBanClient client, String admin, long time, String reason, Callback<ClansBanClient> callback)
{
_repository.ban(UUID.fromString(client.UUID), admin, time, reason, time == -1);
LoadClient(name, callback);
runAsync(() -> {
_repository.ban(UUID.fromString(client.UUID), admin, time, reason, time == -1, ban -> {
client.Bans.add(ban);
callback.run(client);
});
});
}
public CoreClientManager getClientManager()
@ -154,21 +153,7 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
public void UnloadClient(ClansBanClient client)
{
synchronized (_lock)
{
String name = "";
for (Entry<String, ClansBanClient> entry : _clients.entrySet())
{
if (entry.getValue().equals(client))
{
name = entry.getKey();
break;
}
}
_clients.remove(name);
}
UnloadClient(client.Name);
}
public void UnloadClient(String name)
@ -179,17 +164,24 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
}
}
public void LoadClient(final String name, Callback<ClansBanClient> callback)
public void LoadClient(String name, Callback<ClansBanClient> callback)
{
if (_clients.containsKey(name))
{
System.out.println("Clans Bans> Soft Warning: Loading client even though client is already loaded.");
_clients.remove(name);
}
GetRepository().loadBans(name, client -> {
GetRepository().loadClient(name, client -> {
synchronized (_lock)
{
_clients.put(name, client);
_clients.put(name.toLowerCase(), client);
System.out.println("> CLIENTS: " + _clients);
if (callback != null) callback.run(client);
if (callback != null)
{
callback.run(client);
}
}
});
}
@ -207,12 +199,12 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
return _shop;
}
public void cache(Player player, String playerName, String reason)
public void cache(Player player, String victim, String reason)
{
_cache.put(player.getName(), Pair.create(playerName, reason));
_cache.put(player.getName(), new ClansBanCache(victim, reason));
}
public Pair<String, String> getCachedData(Player player)
public ClansBanCache getCachedData(Player player)
{
return _cache.get(player.getName());
}
@ -222,50 +214,45 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
_cache.remove(name);
}
public void unban(ClansBanClient target, ClansBan ban, String name, Callback<ClansBanClient> callback)
public void unban(ClansBanClient target, ClansBan ban, Callback<ClansBanClient> callback)
{
if (!target.UUID.equals(ban.getUUID().toString()))
{
return;
}
ban.remove();
_repository.removeBan(ban);
LoadClient(name, callback);
callback.run(target);
}
public boolean willBeKicked(Player player)
{
return _toKick.containsKey(player.getName());
}
public void queueToKick(Player target, String reason)
{
_toKick.put(target.getName(), reason);
}
public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException
{
_repository.loadBans(playerName, client -> {
LoadClient(playerName, client -> {
if (client.isBanned())
{
String time = UtilTime.convertString(client.getLongestBan().getTimeLeft(), 0, TimeUnit.FIT);
if (client.getLongestBan().isPermanent())
{
time = "Permanent";
}
String reason = C.cRedB + "You are banned from Clans for " + time +
"\n" + C.cWhite + client.getLongestBan().getReason();
_toKick.put(playerName, reason);
ClansManager.getInstance().runSyncLater(() -> {
if (Bukkit.getPlayer(playerName) != null)
{
Bukkit.getPlayer(playerName).kickPlayer(_toKick.remove(playerName));
}
else
{
_runAfterLoad.get(playerName).forEach(Runnable::run);
_runAfterLoad.get(playerName).clear();
}
}, 5L);
}
});
}

View File

@ -1,14 +1,13 @@
package mineplex.game.clans.clans.ban;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.account.CoreClient;
import com.google.common.collect.Sets;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UUIDFetcher;
import mineplex.core.database.MinecraftRepository;
@ -20,65 +19,44 @@ import mineplex.serverdata.database.column.ColumnVarChar;
public class ClansBanRepository extends MinecraftRepository
{
private ClansBanManager _manager;
private static final String BAN_PLAYER = "INSERT INTO clanBans (uuid, admin, reason, banTime, unbanTime, permanent, removed) VALUES (?, ?, ?, ?, ?, ?, ?);";
private static final String REMOVE_BAN = "UPDATE clanBans SET removed = 1 WHERE id = ?;";
private static final String GET_ALL_BANS = "SELECT * FROM clanBans WHERE uuid = ?;";
public ClansBanRepository(JavaPlugin plugin, ClansBanManager manager)
public ClansBanRepository(JavaPlugin plugin)
{
super(plugin, DBPool.getAccount());
_manager = manager;
}
public void ban(UUID uuid, String admin, long time, String reason, boolean permanent)
public void ban(UUID uuid, String admin, long time, String reason, boolean permanent, Callback<ClansBan> callback)
{
executeInsert(BAN_PLAYER, null,
Timestamp banTime = new Timestamp(System.currentTimeMillis());
Timestamp unbanTime = new Timestamp(System.currentTimeMillis() + time);
executeInsert(BAN_PLAYER,
generatedKeys -> {
if (generatedKeys.next() && callback != null)
{
callback.run(new ClansBan(generatedKeys.getInt(1), uuid, admin, reason, banTime, unbanTime, permanent, false));
}
},
new ColumnVarChar("uuid", 36, uuid.toString()),
new ColumnVarChar("admin", 16, admin),
new ColumnVarChar("reason", 128, reason),
new ColumnTimestamp("banTime", new Timestamp(System.currentTimeMillis())),
new ColumnTimestamp("unbanTime", new Timestamp(System.currentTimeMillis() + time)),
new ColumnTimestamp("banTime", banTime),
new ColumnTimestamp("unbanTime", unbanTime),
new ColumnBoolean("permanent", permanent),
new ColumnBoolean("removed", false)
);
}
public void loadBans(final String name, final Callback<ClansBanClient> callback)
public void loadClient(String name, final Callback<ClansBanClient> callback)
{
loadClientByName(name, client -> {
String uuid = UUIDFetcher.getUUIDOf(client.GetPlayerName()).toString();
executeQuery(GET_ALL_BANS, resultSet -> {
final List<ClansBan> list = new ArrayList<ClansBan>();
while (resultSet.next())
{
int id = resultSet.getInt(1);
String ruuid = resultSet.getString(2);
String admin = resultSet.getString(3);
String reason = resultSet.getString(4);
Timestamp banTime = resultSet.getTimestamp(5);
Timestamp unbanTime = resultSet.getTimestamp(6);
boolean permanent = resultSet.getBoolean(7);
boolean removed = resultSet.getBoolean(8);
list.add(new ClansBan(id, UUID.fromString(ruuid), admin, reason, banTime, unbanTime, permanent, removed));
}
callback.run(new ClansBanClient(uuid, list));
}, new ColumnVarChar("uuid", 36, uuid));
});
}
public void loadBans(final String name, final String uuid, final ResultSet resultSet, final Callback<ClansBanClient> callback)
{
try
{
final List<ClansBan> list = new ArrayList<ClansBan>();
String uuid = UUIDFetcher.getUUIDOf(name).toString();
executeQuery(GET_ALL_BANS, resultSet -> {
final Set<ClansBan> bans = Sets.newConcurrentHashSet();
while (resultSet.next())
{
@ -90,33 +68,15 @@ public class ClansBanRepository extends MinecraftRepository
Timestamp unbanTime = resultSet.getTimestamp(6);
boolean permanent = resultSet.getBoolean(7);
boolean removed = resultSet.getBoolean(8);
list.add(new ClansBan(id, UUID.fromString(ruuid), admin, reason, banTime, unbanTime, permanent, removed));
System.out.println("Got ban for " + name);
bans.add(new ClansBan(id, UUID.fromString(ruuid), admin, reason, banTime, unbanTime, permanent, removed));
}
callback.run(new ClansBanClient(uuid, list));
System.out.println("> Successfully handled result");
System.out.println(">> FINISH");
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
private void loadClientByName(String name, Callback<CoreClient> client)
{
if (_manager.getClientManager().Contains(name))
{
client.run(_manager.getClientManager().Get(name));
}
else
{
_manager.getClientManager().loadClientByName(name, () -> client.run(_manager.getClientManager().Get(name)));
}
if (callback != null)
{
callback.run(new ClansBanClient(name, uuid, bans));
}
}, new ColumnVarChar("uuid", 36, uuid));
}
@Override
@ -128,7 +88,7 @@ public class ClansBanRepository extends MinecraftRepository
protected void update()
{
}
public void removeBan(ClansBan ban)
{
executeUpdate(REMOVE_BAN, new ColumnInt("id", ban.getId()));

View File

@ -5,7 +5,6 @@ import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.ban.ClansBanManager;
@ -21,7 +20,7 @@ public class ClansBanCommand extends CommandBase<ClansBanManager>
{
if (args == null || args.length < 1)
{
UtilPlayer.message(caller, C.cGold + "/cb <username> <reason> - Displays the \"Clans Punish\" GUI, allowing you to ban the player, and ");
UtilPlayer.message(caller, C.cBlue + "/cb <username> <reason>" + C.cGray + " - " + C.cYellow + "Displays the \"Clans Punish\" GUI, allowing you to ban the player, and view thier past bans.");
}
else if (args.length > 1)
{
@ -36,18 +35,6 @@ public class ClansBanCommand extends CommandBase<ClansBanManager>
final String finalReason = reason;
//Match exact online first
Player target = UtilPlayer.searchExact(playerName);
if (target != null)
{
Plugin.LoadClient(playerName, client -> {
Plugin.cache(caller, playerName, finalReason);
Plugin.getShop().attemptShopOpen(caller);
});
return;
}
Plugin.LoadClient(playerName, client -> {
Plugin.cache(caller, playerName, finalReason);
Plugin.getShop().attemptShopOpen(caller);
@ -55,7 +42,7 @@ public class ClansBanCommand extends CommandBase<ClansBanManager>
}
else
{
UtilPlayer.message(caller, C.cGold + "/cb <username> <reason> - Displays the \"Clans Punish\" GUI, allowing you to ban the player, and ");
UtilPlayer.message(caller, C.cBlue + "/cb <username> <reason>" + C.cGray + " - " + C.cYellow + "Displays the \"Clans Punish\" GUI, allowing you to ban the player, and view thier past bans.");
}
}
}

View File

@ -2,163 +2,144 @@ package mineplex.game.clans.clans.ban.ui;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Pair;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.donation.DonationManager;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.ban.ClansBan;
import mineplex.game.clans.clans.ban.ClansBanClient;
import mineplex.game.clans.clans.ban.ClansBanManager;
public class ClansBanPage extends ShopPageBase<ClansBanManager, ClansBanShop>
{
private int _days;
private int _hours;
private long _time;
private boolean _permanent;
private ClansBanClient _victimClient;
private String _victim;
private String _reason;
public ClansBanPage(final ClansBanManager banManager, final ClansBanShop shop, final CoreClientManager clientManager, final DonationManager donationManager, final String name, final Player player)
{
super(banManager, shop, clientManager, donationManager, name, player);
_victim = getPlugin().getCachedData(player).getVictim();
_reason = getPlugin().getCachedData(player).getReason();
_victimClient = getPlugin().Get(_victim);
buildPage();
}
protected void buildPage()
{
getPlugin().runAsync(() -> {
_days = Math.max(0, _days);
_hours = Math.max(0, _hours);
Pair<String, String> data = getPlugin().getCachedData(getPlayer());
getPlugin().LoadClient(data.getLeft(), client -> {
int slot = 27;
// Middle of first row
addButton(4, new ItemBuilder(Material.COAL_BLOCK)
.setTitle(C.cDGreenB + data.getLeft())
.addLore(" ")
.addLore(C.cYellow + data.getRight()).build(), (player, click) -> {});
addButton((9 * 1) + 3, new ItemBuilder(Material.PAPER)
.setTitle(C.cRed + "-1 Hour").build(),
(player, click) -> {
_hours--;
refresh();
});
addButton((9 * 1) + 2, new ItemBuilder(Material.PAPER)
.setTitle(C.cRed + "-1 Day").build(),
(player, click) -> {
_days--;
refresh();
});
addButton((9 * 1) + 1, new ItemBuilder(Material.PAPER)
.setTitle(C.cRed + "-30 Days").build(),
(player, click) -> {
_days -= 30;
refresh();
});
addButton((9 * 1) + 5, new ItemBuilder(Material.PAPER)
.setTitle(C.cGreen + "+1 Hour").build(),
(player, click) -> {
_hours++;
refresh();
});
addButton((9 * 1) + 6, new ItemBuilder(Material.PAPER)
.setTitle(C.cGreen + "+1 Day").build(),
(player, click) -> {
_days++;
refresh();
});
addButton((9 * 1) + 7, new ItemBuilder(Material.PAPER)
.setTitle(C.cGreen + "+30 Days").build(),
(player, click) -> {
_days += 30;
refresh();
});
// Middle of second row
addButton((9 * 1) + 4, new ItemBuilder(Material.WATCH)
.setTitle(C.cGold + "Time Options")
.addLore(" ")
.addLore("Permanent: " + F.elem(_permanent ? "Yes" : "No"))
.addLore("Days: " + F.elem(Integer.valueOf(_days)))
.addLore("Hours: " + F.elem(Integer.valueOf(_hours)))
.addLore(" ")
.addLore("Right-Click this button")
.addLore("to ban permanently.").build(),
(player, click) -> {
if (click == ClickType.RIGHT)
{
_permanent = !_permanent;
refresh();
}
});
// Middle of third row
addButton((9 * 2) + 4, new ItemBuilder(Material.EMERALD_BLOCK)
.setTitle(C.cRedB + "BAN PLAYER")
.addLore(" ")
.addLore("Player: " + F.elem(data.getLeft()))
.addLore("Reason: " + F.elem(data.getRight())).build(),
(player, click) -> {
getPlugin().runAsync(() -> {
double time = _days + ((1.f / 24.f) * _hours);
getPlugin().ban(client, data.getLeft(), getPlayer().getName(), _permanent ? -1 : (long) (time * 24.f * 60.f * 60.f * 1000.f), data.getRight(), c -> {
UtilPlayer.message(getPlayer(), F.main("Clans", F.elem(data.getLeft()) + " is now banned " + c.getBanTimeFormatted() + "."));
getPlugin().runSync(() -> {
Player target = Bukkit.getPlayer(data.getLeft());
if (target != null)
target.kickPlayer(C.cRedB + "You have been banned from Clans " + c.getBanTimeFormatted() + ".");
});
});
});
});
for (ClansBan ban : client.Bans)
{
ItemStack item =
new ItemBuilder(ban.isActive() ? Material.EMERALD_BLOCK : Material.REDSTONE_BLOCK)
_time = Math.max(0, _time);
int slot = 27;
// Middle of first row
addButton(4, new ItemBuilder(Material.SKULL_ITEM)
.setData((short) 3)
.setPlayerHead(_victim)
.setTitle(C.cDGreenB + _victim)
.addLore(" ")
.addLore(C.cYellow + _reason).build(), (player, click) -> {});
addTimeAdjuster((9 * 1 + 2), -(1000l * 60l * 60l));
addTimeAdjuster((9 * 1 + 1), -(1000l * 60l * 60l * 24l));
addTimeAdjuster((9 * 1 + 0), -(1000l * 60l * 60l * 24l * 30l));
addTimeAdjuster((9 * 1 + 6), (1000l * 60l * 60l));
addTimeAdjuster((9 * 1 + 7), (1000l * 60l * 60l * 24l));
addTimeAdjuster((9 * 1 + 8), (1000l * 60l * 60l * 24l * 30l));
addButton((9 * 1) + 4,
new ItemBuilder(Material.RECORD_5)
.setTitle(C.cRedB + "Ban Player")
.setLore(
" ",
C.cGray + "Player: " + F.elem(_victim),
C.cGray + "Reason: " + F.elem(_reason),
C.cGray + "Time: " + F.elem(_permanent ? "Permanent" : UtilTime.MakeStr(_time)),
"",
C.cRed + C.Italics + "Left-Click to BAN PLAYER",
C.cGray + C.Italics + "Right-Click to toggle permanent ban setting"
).build(),
(player, click) -> {
if (click == ClickType.RIGHT)
{
_permanent = !_permanent;
refresh();
}
else
{
performBan();
}
});
for (ClansBan ban : _victimClient.Bans)
{
ItemStack item = new ItemBuilder(ban.isActive() ? Material.EMERALD_BLOCK : Material.REDSTONE_BLOCK)
.setTitle(ban.isActive() ? C.cGreenB + "Active" : C.cRedB + "Inactive")
.addLore(" ")
.addLore("Date banned: " + C.cYellow + UtilTime.date(ban.getBanTime().getTime()))
.addLore("Admin: " + C.cYellow + ban.getAdmin())
.addLore("Time left: " + C.cYellow + (ban.isActive() ? ban.getBanTimeFormatted(false) : "None"))
.addLore("Permanent: " + C.cYellow + (ban.isPermanent() ? "Yes" : "No"))
.addLore(C.cGray + "Date banned: " + C.cYellow + UtilTime.date(ban.getBanTime().getTime()))
.addLore(C.cGray + "Admin: " + C.cYellow + ban.getAdmin())
.addLore(C.cGray + "Time left: " + C.cYellow + (ban.isActive() ? ban.getBanTimeFormatted(false) : "None"))
.addLore(C.cGray + "Permanent: " + C.cYellow + (ban.isPermanent() ? "Yes" : "No"))
.addLore(C.cGray + "Reason: " + C.cYellow + ban.getReason(), 16)
.addLore("Is Disabled: " + C.cYellow + (ban.isRemoved() ? "Yes" : "No"))
.addLore(!ban.isActive() ? null : C.cDAqua + "Left-Click to disable ban")
.build();
if (ban.isActive())
UtilInv.addDullEnchantment(item);
addButton(slot++, item, (player, click) -> {
if (ban.isActive())
{
getPlugin().runAsync(() -> getPlugin().unban(client, ban, data.getLeft(), c -> refresh()));
}
.addLore(C.cGray + "Is Disabled: " + C.cYellow + (ban.isRemoved() ? "Yes" : "No"))
.addLore(ban.isActive() ? " " : null)
.addLore(ban.isActive() ? C.cDAqua + "Left-Click to disable ban" : null)
.addDullEnchantment(ban.isActive())
.build();
addButton(slot++, item, (player, click) -> {
if (ban.isActive())
{
getPlugin().runAsync(() -> {
getPlugin().unban(_victimClient, ban, client -> {
refresh();
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1f, 1f);
});
});
}
});
}
}
private void performBan()
{
getPlugin().runAsync(() -> {
getPlugin().ban(_victimClient, getPlayer().getName(), _permanent ? -1 : _time, _reason, client -> {
UtilPlayer.message(getPlayer(), F.main("Clans", F.elem(_victim) + " is now banned " + client.getBanTimeFormatted() + "."));
Player target = Bukkit.getPlayer(_victim);
if (target != null)
{
getPlugin().queueToKick(target, C.cRedB + "You have been banned from Clans " + client.getBanTimeFormatted() + ".");
}
refresh();
});
});
}
private void addTimeAdjuster(int index, long time)
{
addButton(index, new ItemBuilder(Material.PAPER).setTitle(C.cRed + (time < 0 ? "-" : "") + UtilTime.MakeStr(Math.abs(time))).build(),
(player, click) -> {
_time += time;
refresh();
});
}
}