clansbans

This commit is contained in:
Ben 2016-04-04 14:56:20 +01:00
parent 8330ef560d
commit 14207c2073
5 changed files with 76 additions and 21 deletions

View File

@ -107,7 +107,7 @@ public class Clans extends JavaPlugin
Portal portal = new Portal(this, _clientManager, serverStatusManager.getCurrentServerName());
new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion());
// new ClansBanManager(this, _clientManager, _donationManager);
ClansBanManager clansBans = new ClansBanManager(this, _clientManager, _donationManager);
PacketHandler packetHandler = new PacketHandler(this);
Punish punish = new Punish(this, webServerAddress, _clientManager);
@ -137,7 +137,7 @@ public class Clans extends JavaPlugin
GearManager customGear = new GearManager(this, packetHandler, _clientManager, _donationManager);
HologramManager hologram = new HologramManager(this, packetHandler);
_clansManager = new ClansManager(this, serverStatusManager.getCurrentServerName(), packetHandler, punish, _clientManager, _donationManager, preferenceManager, blockRestore, statsManager, teleport, chat, customGear, hologram, webServerAddress);
_clansManager = new ClansManager(this, clansBans, serverStatusManager.getCurrentServerName(), packetHandler, punish, _clientManager, _donationManager, preferenceManager, blockRestore, statsManager, teleport, chat, customGear, hologram, webServerAddress);
new Recipes(this);
new Farming(this);
new BuildingShop(_clansManager, _clientManager, _donationManager);

View File

@ -74,6 +74,7 @@ import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.Clans;
import mineplex.game.clans.clans.ClanTips.TipType;
import mineplex.game.clans.clans.ClansUtility.ClanRelation;
import mineplex.game.clans.clans.ban.ClansBanManager;
import mineplex.game.clans.clans.commands.ClanManagementCommand;
import mineplex.game.clans.clans.commands.ClansAllyChatCommand;
import mineplex.game.clans.clans.commands.ClansChatCommand;
@ -220,16 +221,19 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
public String UserDataDir = UtilServer.getServer().getWorlds().get(0).getWorldFolder().getPath() + File.separator + ".." + File.separator + "CLANS_USER_DATA" + File.separator;
private ClansBanManager _clansBans;
public ClanTips ClanTips;
// Spawn area
public ClansManager(JavaPlugin plugin, String serverName, PacketHandler packetHandler, Punish punish, CoreClientManager clientManager, DonationManager donationManager, PreferencesManager preferencesManager, BlockRestore blockRestore, StatsManager statsManager, Teleport teleport, Chat chat, GearManager gearManager, HologramManager hologramManager, String webServerAddress)
public ClansManager(JavaPlugin plugin, ClansBanManager clansBans, String serverName, PacketHandler packetHandler, Punish punish, CoreClientManager clientManager, DonationManager donationManager, PreferencesManager preferencesManager, BlockRestore blockRestore, StatsManager statsManager, Teleport teleport, Chat chat, GearManager gearManager, HologramManager hologramManager, String webServerAddress)
{
super("Clans Manager", plugin);
_instance = this;
_clansBans = clansBans;
_punish = punish;
_serverName = serverName;
@ -594,11 +598,21 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
{
event.setJoinMessage(null);
if (_clansBans.willBeKicked(event.getPlayer()))
{
return;
}
if (IncognitoManager.Instance.Get(event.getPlayer()).Status)
{
return;
}
_clansBans.runAfterLoad(event.getPlayer().getName(), () -> {
if (_clansBans.Get(event.getPlayer().getName()).isBanned())
{
return;
}
for (Player other : UtilServer.getPlayers())
{
@ -610,6 +624,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
other.sendMessage(F.sys("Join", event.getPlayer().getName()));
}
});
}
@EventHandler(priority = EventPriority.HIGHEST)
@ -622,6 +637,10 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
return;
}
if (_clansBans.willBeKicked(event.getPlayer()))
{
return;
}
for (Player other : UtilServer.getPlayers())
{
@ -644,6 +663,16 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
return;
}
if (_clansBans.willBeKicked(event.getPlayer()))
{
return;
}
if (event.getReason().contains("You are banned from Clans"))
{
return;
}
if (event.getLeaveMessage() != null)
{
event.setLeaveMessage(null);

View File

@ -2,6 +2,7 @@ package mineplex.game.clans.clans.ban;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -12,8 +13,6 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
@ -23,6 +22,7 @@ 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;
@ -32,6 +32,7 @@ import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.donation.DonationManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.ban.commands.ClansBanCommand;
import mineplex.game.clans.clans.ban.ui.ClansBanShop;
@ -41,6 +42,7 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
private ClansBanRepository _repository;
private Map<String, ClansBanClient> _clients;
private Map<String, Pair<String, String>> _cache;
private DefaultHashMap<String, List<Runnable>> _runAfterLoad;
private ClansBanShop _shop;
private Map<String, String> _toKick = new HashMap<>();
@ -57,7 +59,7 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
_clients = new HashMap<>();
_cache = new HashMap<>();
_runAfterLoad = new DefaultHashMap<>(name -> new ArrayList<>());
_shop = new ClansBanShop(this, clientManager, donationManager);
clientManager.addStoredProcedureLoginProcessor(this);
@ -232,6 +234,11 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
LoadClient(name, callback);
}
public boolean willBeKicked(Player player)
{
return _toKick.containsKey(player.getName());
}
public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException
{
_repository.loadBans(playerName, client -> {
@ -246,6 +253,19 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
"\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);
}
});
}
@ -254,4 +274,9 @@ public class ClansBanManager extends MiniPlugin implements ILoginProcessor
{
return "SELECT * FROM clanBans WHERE uuid = '" + uuid + "';";
}
public void runAfterLoad(String playerName, Runnable run)
{
_runAfterLoad.get(playerName).add(run);
}
}

View File

@ -210,6 +210,7 @@ public class NetherManager extends MiniPlugin
_clansManager.getItemMapManager().removeMap(player);
});
}
if (event.getType() == UpdateType.SLOW)
{
_portals.forEach(portal -> {

View File

@ -39,10 +39,10 @@ public class Portal
if (!isValidPortalBlock(from.getBlock()) || !isValidPortalBlock(to.getBlock()))
{
if (!isValidPortalBlock(from.getBlock()))
from = UtilBlock.getInRadius(from.getBlock(), 12).keySet().stream().filter(this::isValidPortalBlock).limit(1).iterator().next().getLocation();
from = UtilBlock.getInRadius(from.getBlock(), 4).keySet().stream().filter(this::isValidPortalBlock).limit(1).iterator().next().getLocation();
if (!isValidPortalBlock(to.getBlock()))
to = UtilBlock.getInRadius(to.getBlock(), 9).keySet().stream().filter(this::isValidPortalBlock).limit(1).iterator().next().getLocation();
to = UtilBlock.getInRadius(to.getBlock(), 4).keySet().stream().filter(this::isValidPortalBlock).limit(1).iterator().next().getLocation();
if (to == null || from == null)
{
@ -54,7 +54,7 @@ public class Portal
}
}
for (Block other : UtilBlock.getInRadius(from, 7.5d).keySet())
for (Block other : UtilBlock.getInRadius(from, 25).keySet())
{
if (other.getType() == Material.OBSIDIAN)
{