incognito fixes and loads of other fixes

This commit is contained in:
Ben 2016-03-20 01:06:46 +00:00
parent ef1d6ede24
commit 723f62b8f9
9 changed files with 109 additions and 92 deletions

View File

@ -56,6 +56,7 @@ import mineplex.core.energy.Energy;
import mineplex.core.explosion.Explosion;
import mineplex.core.hologram.Hologram;
import mineplex.core.hologram.HologramManager;
import mineplex.core.incognito.IncognitoManager;
import mineplex.core.incognito.events.IncognitoStatusChangeEvent;
import mineplex.core.movement.Movement;
import mineplex.core.npc.NpcManager;
@ -507,7 +508,12 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
public ClanInfo getClan(Player player)
{
return _clanMemberUuidMap.get(player.getUniqueId());
return getClan(player.getUniqueId());
}
public ClanInfo getClan(UUID uuid)
{
return _clanMemberUuidMap.get(uuid);
}
public boolean isInClan(Player player)
@ -581,6 +587,54 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void Join(PlayerJoinEvent event)
{
if (IncognitoManager.Instance.Get(event.getPlayer()).Status)
{
event.setJoinMessage(null);
return;
}
if (event.getJoinMessage() != null)
{
event.setJoinMessage(null);
UtilServer.broadcast(F.sys("Join", event.getPlayer().getName()));
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void Quit(PlayerQuitEvent event)
{
if (IncognitoManager.Instance.Get(event.getPlayer()).Status)
{
event.setQuitMessage(null);
return;
}
if (event.getQuitMessage() != null)
{
event.setQuitMessage(null);
UtilServer.broadcast(F.sys("Quit", event.getPlayer().getName()));
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void Kick(PlayerKickEvent event)
{
if (IncognitoManager.Instance.Get(event.getPlayer()).Status)
{
event.setLeaveMessage(null);
return;
}
if (event.getLeaveMessage() != null)
{
event.setLeaveMessage(null);
UtilServer.broadcast(F.sys("Quit", event.getPlayer().getName()));
}
}
@EventHandler
public void disableEnderpeal(PlayerInteractEvent event)
{

View File

@ -1,6 +1,7 @@
package mineplex.game.clans.clans.ban;
import java.sql.Timestamp;
import java.util.UUID;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilTime;
@ -8,18 +9,18 @@ import mineplex.core.common.util.UtilTime;
public class ClansBan
{
private int _id;
private int _accountId;
private String _reason;
private String _admin;
private Timestamp _banTime;
private Timestamp _unbanTime;
private boolean _permanent;
private boolean _removed;
private UUID _uuid;
public ClansBan(int id, int accountId, String admin, String reason, Timestamp banTime, Timestamp unbanTime, boolean permanent, boolean removed)
public ClansBan(int id, UUID uuid, String admin, String reason, Timestamp banTime, Timestamp unbanTime, boolean permanent, boolean removed)
{
_id = id;
_accountId = accountId;
_uuid = uuid;
_reason = reason;
_admin = admin;
_banTime = banTime;
@ -33,11 +34,6 @@ public class ClansBan
return _id;
}
public int getAccountId()
{
return _accountId;
}
public String getAdmin()
{
return _admin;
@ -89,4 +85,9 @@ public class ClansBan
{
return (isPermanent() || getTimeLeft() > 0) && !isRemoved();
}
public UUID getUUID()
{
return _uuid;
}
}

View File

@ -7,12 +7,12 @@ import mineplex.core.common.util.UtilTime;
public class ClansBanClient
{
public int AccountId;
public String UUID;
public List<ClansBan> Bans;
public ClansBanClient(int accountId, List<ClansBan> bans)
public ClansBanClient(String uuid, List<ClansBan> bans)
{
AccountId = accountId;
UUID = uuid;
Bans = bans;
}

View File

@ -4,12 +4,14 @@ 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;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
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;
@ -21,15 +23,11 @@ import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Pair;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
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.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.ban.commands.ClansBanCommand;
import mineplex.game.clans.clans.ban.ui.ClansBanShop;
@ -83,7 +81,7 @@ public class ClansBanManager extends MiniPlugin
public void ban(ClansBanClient client, String name, String admin, long time, String reason, Callback<ClansBanClient> callback)
{
_repository.ban(client.AccountId, admin, time, reason, time == -1);
_repository.ban(UUID.fromString(client.UUID), admin, time, reason, time == -1);
LoadClient(name, callback);
}
@ -99,9 +97,9 @@ public class ClansBanManager extends MiniPlugin
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event)
public void onPlayerJoin(AsyncPlayerPreLoginEvent event)
{
LoadClient(event.getPlayer().getName(), client -> {
LoadClient(event.getName(), client -> {
if (client.isBanned())
{
String time = UtilTime.convertString(client.getLongestBan().getTimeLeft(), 0, TimeUnit.FIT);
@ -112,20 +110,8 @@ public class ClansBanManager extends MiniPlugin
String reason = C.cRedB + "You are banned from Clans for " + time +
"\n" + C.cWhite + client.getLongestBan().getReason();
event.getPlayer().kickPlayer(reason);
ClanInfo clan = ClansManager.getInstance().getClan(event.getPlayer());
String name = event.getPlayer().getName();
if (clan != null)
UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(getPlugin(), () -> clan.playerOffline(name), 20L);
}
else
{
if (event.getJoinMessage() == null)
return;
UtilServer.broadcast(F.sys("Join", event.getPlayer().getName()));
event.disallow(Result.KICK_BANNED, reason);
event.setKickMessage(reason);
}
});
}
@ -191,6 +177,9 @@ public class ClansBanManager extends MiniPlugin
public void LoadClient(final String name, Callback<ClansBanClient> callback)
{
if (_clients.containsKey(name))
_clients.remove(name);
GetRepository().loadBans(name, client -> {
synchronized (_lock)
{
@ -231,7 +220,7 @@ public class ClansBanManager extends MiniPlugin
public void unban(ClansBanClient target, ClansBan ban, String name, Callback<ClansBanClient> callback)
{
if (target.AccountId != ban.getAccountId())
if (!target.UUID.equals(ban.getUUID().toString()))
{
return;
}

View File

@ -3,11 +3,13 @@ package mineplex.game.clans.clans.ban;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.account.CoreClient;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UUIDFetcher;
import mineplex.core.database.MinecraftRepository;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.column.ColumnBoolean;
@ -19,10 +21,9 @@ public class ClansBanRepository extends MinecraftRepository
{
private ClansBanManager _manager;
private static final String GET_LONGEST_BAN = "SELECT * FROM clanBans WHERE (NOW() < unbanTime OR permanent=1) AND accountId = ? ORDER BY permanent DESC, unbanTime DESC LIMIT 1;";
private static final String BAN_PLAYER = "INSERT INTO clanBans (accountId, admin, reason, banTime, unbanTime, permanent, removed) VALUES (?, ?, ?, ?, ?, ?, ?);";
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 accountId = ?;";
private static final String GET_ALL_BANS = "SELECT * FROM clanBans WHERE uuid = ?;";
public ClansBanRepository(JavaPlugin plugin, ClansBanManager manager)
{
@ -31,10 +32,10 @@ public class ClansBanRepository extends MinecraftRepository
_manager = manager;
}
public void ban(int accountId, String admin, long time, String reason, boolean permanent)
public void ban(UUID uuid, String admin, long time, String reason, boolean permanent)
{
executeInsert(BAN_PLAYER, null,
new ColumnInt("accountId", accountId),
new ColumnVarChar("uuid", 36, uuid.toString()),
new ColumnVarChar("admin", 16, admin),
new ColumnVarChar("reason", 128, reason),
new ColumnTimestamp("banTime", new Timestamp(System.currentTimeMillis())),
@ -50,6 +51,8 @@ public class ClansBanRepository extends MinecraftRepository
loadClientByName(name, client -> {
System.out.println("> Successfully loaded CoreClient");
String uuid = UUIDFetcher.getUUIDOf(client.GetPlayerName()).toString();
executeQuery(GET_ALL_BANS, resultSet -> {
System.out.println("> Successfully executed query, result set object: " + resultSet);
@ -58,7 +61,7 @@ public class ClansBanRepository extends MinecraftRepository
while (resultSet.next())
{
int id = resultSet.getInt(1);
int accountId = resultSet.getInt(2);
String ruuid = resultSet.getString(2);
String admin = resultSet.getString(3);
String reason = resultSet.getString(4);
Timestamp banTime = resultSet.getTimestamp(5);
@ -66,44 +69,20 @@ public class ClansBanRepository extends MinecraftRepository
boolean permanent = resultSet.getBoolean(7);
boolean removed = resultSet.getBoolean(8);
list.add(new ClansBan(id, accountId, admin, reason, banTime, unbanTime, permanent, removed));
list.add(new ClansBan(id, UUID.fromString(ruuid), admin, reason, banTime, unbanTime, permanent, removed));
System.out.println("Got ban for " + name);
}
callback.run(new ClansBanClient(client.getAccountId(), list));
callback.run(new ClansBanClient(uuid, list));
System.out.println("> Successfully handled result");
System.out.println(">> FINISH");
}, new ColumnInt("accountId", client.getAccountId()));
}, new ColumnVarChar("uuid", 36, uuid));
});
}
public void getLongestBan(final String name, final Callback<ClansBan> callback)
{
if (callback == null)
{
return;
}
loadClientByName(name, client -> {
executeQuery(GET_LONGEST_BAN, resultSet -> {
while (resultSet.next())
{
int id = resultSet.getInt(1);
int accountId = resultSet.getInt(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);
callback.run(new ClansBan(id, accountId, admin, reason, banTime, unbanTime, permanent, removed));
}
}, new ColumnInt("accountId", client.getAccountId()));
});
}
public void loadClientByName(String name, Callback<CoreClient> client)
private void loadClientByName(String name, Callback<CoreClient> client)
{
if (_manager.getClientManager().Contains(name))
{

View File

@ -27,7 +27,7 @@ public class ClansBanCommand extends CommandBase<ClansBanManager>
{
final String playerName = args[0];
String reason = args[2];
String reason = args[1];
for (int i = 2; i < args.length; i++)
{
@ -43,10 +43,6 @@ public class ClansBanCommand extends CommandBase<ClansBanManager>
Plugin.LoadClient(playerName, client -> {
Plugin.cache(caller, playerName, finalReason);
Plugin.getShop().attemptShopOpen(caller);
// Plugin.ban(client, target.getName(), caller.getName(), permanent ? -1 : (long) (time * 24.f * 60.f * 60.f * 1000.f), finalReason, c -> {
// UtilPlayer.message(caller, F.main("Clans", F.elem(playerName) + " is now banned " + F.time(c.getBanTimeFormatted()) + "."));
// Plugin.runSync(() -> target.kickPlayer(C.cRedB + "You have been banned from Clans " + c.getBanTimeFormatted() + "."));
// });
});
return;
@ -55,9 +51,6 @@ public class ClansBanCommand extends CommandBase<ClansBanManager>
Plugin.LoadClient(playerName, client -> {
Plugin.cache(caller, playerName, finalReason);
Plugin.getShop().attemptShopOpen(caller);
// Plugin.ban(client, playerName, caller.getName(), permanent ? -1 : (long) (time * 24.f * 60.f * 60.f * 1000.f), finalReason, c -> {
// UtilPlayer.message(caller, F.main("Clans", F.elem(playerName) + " is now banned " + c.getBanTimeFormatted() + "."));
// });
});
}
else

View File

@ -147,7 +147,6 @@ public class ClansRegions extends MiniPlugin
// Only claim if the clan doesn't have claims. Speeds up startup time
if (clan == null || clan.getClaimSet().size() == 0)
{
if (clan != null)
{
_manager.getClanDataAccess().delete(clan, status -> {

View File

@ -113,10 +113,7 @@ public class SafeLog extends MiniPlugin
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerQuit(PlayerQuitEvent event)
{
if (event.getQuitMessage() != null)
event.setQuitMessage(F.sys("Quit", event.getPlayer().getName()));
onPlayerQuit(event.getPlayer());
onPlayerQuit(event.getPlayer());
}
@EventHandler(priority = EventPriority.HIGHEST)
@ -124,9 +121,7 @@ public class SafeLog extends MiniPlugin
{
if (event.getPlayer().getItemInHand() != null && event.getPlayer().getItemInHand().getItemMeta() != null && (C.cGold + "Wind Blade").equals(event.getPlayer().getItemInHand().getItemMeta().getDisplayName()))
if (event.getReason().contains("flying is not enabled"))
return;
_flying.add(event.getPlayer().getName());
_flying.add(event.getPlayer().getName());
}
@EventHandler(priority = EventPriority.LOWEST)
@ -137,17 +132,12 @@ public class SafeLog extends MiniPlugin
if (event.getReason().contains("flying is not enabled"))
return;
if (event.getLeaveMessage() != null)
event.setLeaveMessage(F.sys("Quit", event.getPlayer().getName()));
onPlayerQuit(event.getPlayer());
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event)
{
event.setJoinMessage(null);
onPlayerJoin(event.getPlayer());
}

View File

@ -694,6 +694,12 @@ public class ArcadeManager extends MiniPlugin implements IRelation
{
String name = event.getPlayer().getName();
if (IncognitoManager.Instance.Get(event.getPlayer()).Status)
{
event.setJoinMessage(null);
return;
}
if (event.getJoinMessage() == null)
return;
@ -707,6 +713,12 @@ public class ArcadeManager extends MiniPlugin implements IRelation
@EventHandler
public void MessageQuit(PlayerQuitEvent event)
{
if (IncognitoManager.Instance.Get(event.getPlayer()).Status)
{
event.setQuitMessage(null);
return;
}
String name = event.getPlayer().getName();
if (event.getQuitMessage() == null)