Tidy up clans banning system
This commit is contained in:
parent
e76c9e55d2
commit
1c37c758d9
@ -18,6 +18,7 @@ public class ClansBanClient
|
|||||||
{
|
{
|
||||||
_uuid = uuid;
|
_uuid = uuid;
|
||||||
_bans = bans;
|
_bans = bans;
|
||||||
|
sortBans();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBanned()
|
public boolean isBanned()
|
||||||
@ -87,4 +88,28 @@ public class ClansBanClient
|
|||||||
|
|
||||||
return longest;
|
return longest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sortBans()
|
||||||
|
{
|
||||||
|
_bans.sort((b1, b2) ->
|
||||||
|
{
|
||||||
|
if (b1.isActive() && !b2.isActive())
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (b2.isActive() && !b1.isActive())
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if ((b1.isActive() && b1.isPermanent()) && !(b2.isActive() && b2.isPermanent()))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if ((b2.isActive() && b2.isPermanent()) && !(b1.isActive() && b1.isPermanent()))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return b1.getBanTime().compareTo(b2.getBanTime());
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
@ -108,6 +108,7 @@ public class ClansBanManager extends MiniPlugin
|
|||||||
if (ban.isPresent())
|
if (ban.isPresent())
|
||||||
{
|
{
|
||||||
target._bans.add(ban.get());
|
target._bans.add(ban.get());
|
||||||
|
target.sortBans();
|
||||||
String banTimeFormatted = target.getBanTimeFormatted();
|
String banTimeFormatted = target.getBanTimeFormatted();
|
||||||
|
|
||||||
if (targetName != null)
|
if (targetName != null)
|
||||||
@ -147,13 +148,16 @@ public class ClansBanManager extends MiniPlugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ban.remove(admin, reason);
|
_repository.removeBan(ban, admin, reason, () ->
|
||||||
_repository.removeBan(ban, admin, reason);
|
|
||||||
|
|
||||||
if (callback != null)
|
|
||||||
{
|
{
|
||||||
callback.run();
|
ban.remove(admin, reason);
|
||||||
}
|
target.sortBans();
|
||||||
|
|
||||||
|
if (callback != null)
|
||||||
|
{
|
||||||
|
callback.run();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
@ -15,6 +15,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
|
|
||||||
import mineplex.core.Managers;
|
import mineplex.core.Managers;
|
||||||
import mineplex.core.account.CoreClientManager;
|
import mineplex.core.account.CoreClientManager;
|
||||||
|
import mineplex.core.common.util.UtilServer;
|
||||||
import mineplex.serverdata.database.DBPool;
|
import mineplex.serverdata.database.DBPool;
|
||||||
import mineplex.serverdata.database.RepositoryBase;
|
import mineplex.serverdata.database.RepositoryBase;
|
||||||
import mineplex.serverdata.database.column.ColumnInt;
|
import mineplex.serverdata.database.column.ColumnInt;
|
||||||
@ -128,8 +129,16 @@ public class ClansBanRepository extends RepositoryBase
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeBan(ClansBan ban, String admin, String reason)
|
public void removeBan(ClansBan ban, String admin, String reason, Runnable onComplete)
|
||||||
{
|
{
|
||||||
executeUpdate(REMOVE_BAN, new ColumnVarChar("removeAdmin", admin.length(), admin), new ColumnVarChar("removeReason", reason.length(), reason), new ColumnInt("id", ban.getId()));
|
UtilServer.runAsync(() ->
|
||||||
|
{
|
||||||
|
executeUpdate(REMOVE_BAN, new ColumnVarChar("removeAdmin", admin.length(), admin), new ColumnVarChar("removeReason", reason.length(), reason), new ColumnInt("id", ban.getId()));
|
||||||
|
|
||||||
|
if (onComplete != null)
|
||||||
|
{
|
||||||
|
UtilServer.runSync(onComplete);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -127,13 +127,10 @@ public class ClansBanPage extends ShopPageBase<ClansBanManager, ClansBanShop>
|
|||||||
{
|
{
|
||||||
if (ban.isActive())
|
if (ban.isActive())
|
||||||
{
|
{
|
||||||
getPlugin().runAsync(() ->
|
getPlugin().unban(_victimClient, ban, getPlayer().getName(), _reason, () ->
|
||||||
{
|
{
|
||||||
getPlugin().unban(_victimClient, ban, getPlayer().getName(), _reason, () ->
|
refresh();
|
||||||
{
|
playAcceptSound(player);
|
||||||
refresh();
|
|
||||||
playAcceptSound(player);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -82,8 +82,8 @@ public class ClansServerPage extends ShopPageBase<ClansTransferManager, ClansSer
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Integer server1;
|
int server1;
|
||||||
Integer server2;
|
int server2;
|
||||||
if (o1.Name.contains("-"))
|
if (o1.Name.contains("-"))
|
||||||
{
|
{
|
||||||
server1 = Integer.parseInt(o1.Name.substring(o1.Name.lastIndexOf('-') + 1));
|
server1 = Integer.parseInt(o1.Name.substring(o1.Name.lastIndexOf('-') + 1));
|
||||||
@ -101,7 +101,7 @@ public class ClansServerPage extends ShopPageBase<ClansTransferManager, ClansSer
|
|||||||
server2 = Integer.parseInt(o2.Name);
|
server2 = Integer.parseInt(o2.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return server1.compareTo(server2);
|
return Integer.compare(server1, server2);
|
||||||
}
|
}
|
||||||
catch (NumberFormatException ex)
|
catch (NumberFormatException ex)
|
||||||
{
|
{
|
||||||
@ -184,8 +184,8 @@ public class ClansServerPage extends ShopPageBase<ClansTransferManager, ClansSer
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Integer server1;
|
int server1;
|
||||||
Integer server2;
|
int server2;
|
||||||
if (o1.Name.contains("-"))
|
if (o1.Name.contains("-"))
|
||||||
{
|
{
|
||||||
server1 = Integer.parseInt(o1.Name.substring(o1.Name.lastIndexOf('-') + 1));
|
server1 = Integer.parseInt(o1.Name.substring(o1.Name.lastIndexOf('-') + 1));
|
||||||
@ -203,7 +203,7 @@ public class ClansServerPage extends ShopPageBase<ClansTransferManager, ClansSer
|
|||||||
server2 = Integer.parseInt(o2.Name);
|
server2 = Integer.parseInt(o2.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return server1.compareTo(server2);
|
return Integer.compare(server1, server2);
|
||||||
}
|
}
|
||||||
catch (NumberFormatException ex)
|
catch (NumberFormatException ex)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user