Merge branch 'clans/beta' of https://github.com/Mineplex-LLC/Minecraft-PC into clans/beta

This commit is contained in:
Ben 2016-03-10 22:12:41 +00:00
commit 33d978c6d6
5 changed files with 267 additions and 2 deletions

View File

@ -0,0 +1,149 @@
package mineplex.core.incognito;
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.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.incognito.commands.IncognitoToggleCommand;
import mineplex.core.incognito.events.IncognitoStatusChangeEvent;
import mineplex.core.incognito.repository.IncognitoClient;
import mineplex.core.incognito.repository.IncognitoRepository;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class IncognitoManager extends MiniClientPlugin<IncognitoClient>
{
private CoreClientManager _clientManager;
private IncognitoRepository _repository;
public static IncognitoManager Instance;
public IncognitoManager(JavaPlugin plugin, CoreClientManager clientManager, PacketHandler packetHandler)
{
super("Incognito", plugin);
_repository = new IncognitoRepository(this, clientManager);
_clientManager = clientManager;
Instance = this;
}
public void addCommands()
{
addCommand(new IncognitoToggleCommand(this));
}
public boolean toggle(Player caller)
{
boolean enabled = !Get(caller).Status;
IncognitoStatusChangeEvent event = UtilServer.CallEvent(new IncognitoStatusChangeEvent(caller, enabled));
if (event.isCancelled())
{
return false;
}
Get(caller).Status = enabled;
runAsync(() -> _repository.SetStatus(_clientManager.getAccountId(caller), enabled));
return enabled;
}
@EventHandler(priority = EventPriority.LOWEST)
public void Update(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
{
UtilServer.getPlayersCollection().forEach(player -> {
UtilServer.getPlayersCollection().forEach(other -> {
if (Get(other).Status && !_clientManager.hasRank(player, _clientManager.Get(other).GetRank()))
player.hidePlayer(other);
if (Get(player).Status)
{
if (!_clientManager.hasRank(other, _clientManager.Get(player).GetRank()))
other.hidePlayer(player);
}
});
});
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void ClientLoad(AsyncPlayerPreLoginEvent event)
{
_clientManager.getRepository().getAccountId(event.getUniqueId(), accountId -> {
Get(event.getName()).Status = _repository.GetStatus(accountId.intValue());
});
}
@EventHandler(priority = EventPriority.HIGHEST)
public void Join(PlayerJoinEvent event)
{
if (Get(event.getPlayer()).Status)
{
event.setJoinMessage(null);
informIncognito(event.getPlayer());
}
UtilServer.getPlayersCollection().forEach(player -> {
if (Get(event.getPlayer()).Status && !_clientManager.hasRank(player, _clientManager.Get(event.getPlayer()).GetRank()))
player.hidePlayer(event.getPlayer());
if (Get(player).Status)
{
if (!_clientManager.hasRank(event.getPlayer(), _clientManager.Get(player).GetRank()))
event.getPlayer().hidePlayer(player);
}
});
}
@EventHandler(priority = EventPriority.HIGHEST)
public void Quit(PlayerQuitEvent event)
{
if (Get(event.getPlayer()).Status)
{
event.setQuitMessage(null);
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void Kick(PlayerKickEvent event)
{
if (Get(event.getPlayer()).Status)
{
event.setLeaveMessage(null);
}
}
private void informIncognito(Player player)
{
UtilPlayer.message(player, " ");
UtilPlayer.message(player, C.cGoldB + "You are currently incognito.");
UtilPlayer.message(player, C.cYellow + "This means you are invisible to all except for those who are " + _clientManager.Get(player).GetRank().getTag(true, false) + C.mBody + "+");
UtilPlayer.message(player, " ");
}
protected IncognitoClient AddPlayer(String player)
{
return new IncognitoClient();
}
public IncognitoRepository getRepository()
{
return _repository;
}
}

View File

@ -46,7 +46,7 @@ public class ClanRepository extends MinecraftRepository
private static String RETRIEVE_CLAN_INFO = "SELECT c.id, c.name, c.description, c.home, c.admin, c.energy, c.kills, c.murder, c.deaths, c.warWins, c.warLosses, c.generator, c.generatorStock, c.dateCreated, c.lastOnline, c.eloRating FROM clans AS c WHERE lower(c.name) = ?;";
private static String RETRIEVE_PLAYER_CLAN_INFO = "SELECT clans.name, accountClan.clanRole, clanServer.serverName, clans.id FROM accountClan INNER JOIN clans ON clans.id = accountClan.clanId INNER JOIN clanServer ON clans.serverId = clanServer.id WHERE accountClan.accountId = ?;";
private static String RETRIEVE_START_CLAN_INFO = "SELECT c.id, c.name, c.description, c.home, c.admin, c.energy, c.kills, c.murder, c.deaths, c.warWins, c.warLosses, c.generator, c.generatorStock, c.dateCreated, c.lastOnline, c.eloRating ct.chunk, ct.safe FROM clans AS c LEFT JOIN clanTerritory AS ct ON ct.clanId = c.id WHERE c.serverId = ? OR c.admin = 1;";
private static String RETRIEVE_START_CLAN_INFO = "SELECT c.id, c.name, c.description, c.home, c.admin, c.energy, c.kills, c.murder, c.deaths, c.warWins, c.warLosses, c.generator, c.generatorStock, c.dateCreated, c.lastOnline, c.eloRating, ct.chunk, ct.safe FROM clans AS c LEFT JOIN clanTerritory AS ct ON ct.clanId = c.id WHERE c.serverId = ? OR c.admin = 1;";
private static String RETRIEVE_CLAN_MEMBER_INFO = "SELECT c.name, a.name, a.uuid, clanRole FROM accountClan AS ac INNER JOIN accounts AS a ON a.id = ac.accountId INNER JOIN clans AS c on c.id = ac.clanId WHERE c.serverId = ?;";
private static String RETRIEVE_CLAN_MEMBERS = "SELECT c.name, a.name, a.uuid, clanRole FROM accountClan AS ac INNER JOIN accounts AS a ON a.id = ac.accountId INNER JOIN clans AS c on c.id = ac.clanId WHERE lower(c.name) = ?;";
private static String RETRIEVE_CLAN_ALLIANCE_INFO = "SELECT c.name, cOther.name, ca.trusted FROM clanAlliances AS ca INNER JOIN clans AS c ON c.id = ca.clanId INNER JOIN clans as cOther ON cOther.id = ca.otherClanId WHERE c.serverId = ?;";

View File

@ -140,7 +140,6 @@ public class SiegeWeaponRepository extends MinecraftRepository
protected void initialize()
{
executeUpdate(CREATE);
executeUpdate("ALTER TABLE `Account`.`clans` ADD COLUMN `eloRating` INT(11) NOT NULL DEFAULT '1200' AFTER `generatorStock`;");
}
@Override

View File

@ -0,0 +1,68 @@
package mineplex.game.clans.clans.staff;
import org.bukkit.Bukkit;
import org.bukkit.block.Chest;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilCollections;
import mineplex.core.common.util.UtilServer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class SilentChestInventory implements Listener
{
private Chest _chest;
private Inventory _inventory;
private Player _viewer;
public SilentChestInventory(Chest chest, Player viewer)
{
_chest = chest;
_inventory = Bukkit.createInventory(null, 54, "Chest");
viewer.openInventory(_inventory);
UtilServer.RegisterEvents(this);
}
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
if (!UtilCollections.equal(_chest.getBlockInventory().getContents(), _inventory.getContents()))
{
_inventory.setContents(_chest.getBlockInventory().getContents());
}
}
@EventHandler
public void inventoryClick(InventoryClickEvent event)
{
if (event.getClickedInventory().equals(_inventory) && event.getWhoClicked().equals(_viewer))
{
_chest.getBlockInventory().setContents(_inventory.getContents());
}
}
@EventHandler
public void closeInventory(InventoryCloseEvent event)
{
if (event.getInventory().equals(_inventory) && event.getPlayer().equals(_viewer))
{
UtilServer.Unregister(this);
}
}
}

View File

@ -0,0 +1,49 @@
package mineplex.game.clans.clans.staff;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEvent;
import mineplex.core.MiniPlugin;
import mineplex.core.common.Rank;
import mineplex.core.common.util.UtilServer;
import mineplex.core.incognito.IncognitoManager;
import mineplex.game.clans.clans.ClansManager;
public class SilentChestOpen extends MiniPlugin
{
private ClansManager _clansManager;
public SilentChestOpen(ClansManager clansManager)
{
super("Silent Chest", clansManager.getPlugin());
_clansManager = clansManager;
}
@EventHandler
public void onInteract(PlayerInteractEvent event)
{
if (!IncognitoManager.Instance.Get(event.getPlayer()).Status)
return;
if (!ClansManager.getInstance().getClientManager().hasRank(event.getPlayer(), Rank.CMOD))
return;
if (event.getClickedBlock() == null)
return;
BlockState block = event.getClickedBlock().getState();
if (!(block instanceof Chest))
return;
Chest chest = (Chest) block;
UtilServer.RegisterEvents(new SilentChestInventory(chest, event.getPlayer()));
event.setCancelled(true);
}
}