Mineplex2018-withcommit/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/HubManager.java

912 lines
27 KiB
Java
Raw Normal View History

2016-07-25 16:55:18 +02:00
package mineplex.clanshub;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import mineplex.clanshub.commands.ForcefieldRadius;
import mineplex.clanshub.commands.GadgetToggle;
import mineplex.clanshub.commands.GameModeCommand;
import mineplex.clanshub.profile.gui.GUIProfile;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager;
import mineplex.core.achievement.AchievementManager;
import mineplex.core.benefit.BenefitManager;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.bonuses.BonusManager;
import mineplex.core.boosters.BoosterManager;
import mineplex.core.botspam.BotSpamManager;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilTextTop;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.cosmetic.CosmeticManager;
import mineplex.core.customdata.CustomDataManager;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.disguise.PlayerDisguiseManager;
import mineplex.core.disguise.disguises.DisguiseBase;
import mineplex.core.disguise.disguises.DisguiseWither;
import mineplex.core.donation.DonationManager;
import mineplex.core.facebook.FacebookManager;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.event.GadgetCollideEntityEvent;
import mineplex.core.gadget.gadgets.morph.MorphWither;
import mineplex.core.gadget.types.Gadget;
import mineplex.core.gadget.types.GadgetType;
import mineplex.core.hologram.HologramManager;
import mineplex.core.incognito.IncognitoManager;
import mineplex.core.incognito.events.IncognitoHidePlayerEvent;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.message.PrivateMessageEvent;
import mineplex.core.mount.Mount;
import mineplex.core.mount.MountManager;
import mineplex.core.mount.types.MountDragon;
import mineplex.core.notifier.NotificationManager;
import mineplex.core.npc.NpcManager;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
import mineplex.core.pet.PetManager;
import mineplex.core.playerCount.PlayerCountManager;
import mineplex.core.poll.PollManager;
import mineplex.core.portal.Portal;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.projectile.ProjectileManager;
import mineplex.core.punish.Punish;
import mineplex.core.stats.StatsManager;
import mineplex.core.status.ServerStatusManager;
import mineplex.core.task.TaskManager;
import mineplex.core.treasure.TreasureLocation;
import mineplex.core.treasure.TreasureManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.valentines.ValentinesGiftManager;
import mineplex.core.youtube.YoutubeManager;
import mineplex.minecraft.game.core.combat.DeathMessageType;
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
import mineplex.minecraft.game.core.condition.ConditionManager;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.HoverEvent.Action;
import net.md_5.bungee.api.chat.TextComponent;
import net.minecraft.server.v1_8_R3.EntityInsentient;
import net.minecraft.server.v1_8_R3.EntityPlayer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Egg;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerVelocityEvent;
import org.bukkit.event.server.ServerListPingEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
public class HubManager extends MiniPlugin
{
private BlockRestore _blockRestore;
private CoreClientManager _clientManager;
private ConditionManager _conditionManager;
private DonationManager _donationManager;
private DisguiseManager _disguiseManager;
private PartyManager _partyManager;
private ForcefieldManager _forcefieldManager;
private PollManager _pollManager;
private Portal _portal;
private StatsManager _statsManager;
private GadgetManager _gadgetManager;
private MountManager _mountManager;
private HubVisibilityManager _visibilityManager;
private PreferencesManager _preferences;
private InventoryManager _inventoryManager;
private AchievementManager _achievementManager;
private TreasureManager _treasureManager;
private PetManager _petManager;
private PacketHandler _packetHandler;
private PlayerCountManager _playerCountManager;
private CustomDataManager _customDataManager;
private Punish _punishManager;
private IncognitoManager _incognito;
private BonusManager _bonusManager;
private Location _spawn;
private int _scoreboardTick = 0;
private HashMap<Player, Scoreboard> _scoreboards = new HashMap<Player, Scoreboard>();
private String _serverName = "";
private int _lastPlayerCount = 0;
private boolean _shuttingDown;
private HashMap<String, Long> _portalTime = new HashMap<String, Long>();
private HashMap<String, ArrayList<String>> _creativeAdmin = new HashMap<String, ArrayList<String>>();
public HubManager(JavaPlugin plugin, BlockRestore blockRestore, CoreClientManager clientManager, IncognitoManager incognito, DonationManager donationManager, InventoryManager inventoryManager, ConditionManager conditionManager, DisguiseManager disguiseManager, TaskManager taskManager, Portal portal, PartyManager partyManager, PreferencesManager preferences, PetManager petManager, PollManager pollManager, StatsManager statsManager, AchievementManager achievementManager, HologramManager hologramManager, NpcManager npcManager, PacketHandler packetHandler, Punish punish, ServerStatusManager serverStatusManager, CustomDataManager customDataManager, BoosterManager boosterManager)
{
super("Hub Manager", plugin);
_incognito = incognito;
_blockRestore = blockRestore;
_clientManager = clientManager;
_conditionManager = conditionManager;
_donationManager = donationManager;
_disguiseManager = disguiseManager;
_pollManager = pollManager;
_portal = portal;
_spawn = new Location(UtilWorld.getWorld("world"), 0.5, 179, 0.5);
((CraftWorld) _spawn.getWorld()).getHandle().spigotConfig.itemMerge = 0;
new WorldManager(this);
_mountManager = new MountManager(_plugin, clientManager, donationManager, blockRestore, _disguiseManager);
_inventoryManager = inventoryManager;
new BenefitManager(plugin, clientManager, _inventoryManager);
_gadgetManager = new GadgetManager(_plugin, clientManager, donationManager, _inventoryManager, _mountManager, petManager, preferences, disguiseManager, blockRestore, new ProjectileManager(plugin), achievementManager, packetHandler, hologramManager);
FacebookManager facebookManager = new FacebookManager(plugin, clientManager, donationManager, inventoryManager);
YoutubeManager youtubeManager = new YoutubeManager(plugin, clientManager, donationManager);
_bonusManager = new BonusManager(plugin, clientManager, serverStatusManager, donationManager, pollManager , npcManager, hologramManager, statsManager, _inventoryManager, petManager, facebookManager, youtubeManager, _gadgetManager, boosterManager);
World world = _spawn.getWorld();
_treasureManager = new TreasureManager(_plugin, clientManager, serverStatusManager, donationManager, _inventoryManager, petManager, _gadgetManager, _blockRestore, hologramManager, statsManager, _bonusManager.getRewardManager());
_treasureManager.disable();
{
Block chestBlock = world.getBlockAt(-1, 178, -9);
Block chestLoc1 = world.getBlockAt(-4, 178, -8);
Block chestLoc2 = world.getBlockAt(-4, 178, -10);
Block chestLoc3 = world.getBlockAt(-2, 178, -12);
Block chestLoc4 = world.getBlockAt(0, 178, -12);
Block chestLoc5 = world.getBlockAt(2, 178, -10);
Block chestLoc6 = world.getBlockAt(2, 178, -8);
Block chestLoc7 = world.getBlockAt(0, 178, -6);
Block chestLoc8 = world.getBlockAt(-2, 178, -6);
TreasureLocation loc = new TreasureLocation(_treasureManager, _inventoryManager, clientManager, donationManager, chestBlock, new Block[]{chestLoc1, chestLoc2, chestLoc3, chestLoc4, chestLoc5, chestLoc6, chestLoc7, chestLoc8}, _spawn, hologramManager, _gadgetManager, serverStatusManager);
_treasureManager.addTreasureLocation(loc);
}
{
Block chestBlock = world.getBlockAt(-1, 178, 9);
Block chestLoc1 = world.getBlockAt(-4, 178, 10);
Block chestLoc2 = world.getBlockAt(-4, 178, 8);
Block chestLoc3 = world.getBlockAt(-2, 178, 6);
Block chestLoc4 = world.getBlockAt(0, 178, 6);
Block chestLoc5 = world.getBlockAt(2, 178, 8);
Block chestLoc6 = world.getBlockAt(2, 178, 10);
Block chestLoc7 = world.getBlockAt(0, 178, 12);
Block chestLoc8 = world.getBlockAt(-2, 178, 12);
TreasureLocation loc = new TreasureLocation(_treasureManager, _inventoryManager, clientManager, donationManager, chestBlock, new Block[]{chestLoc1, chestLoc2, chestLoc3, chestLoc4, chestLoc5, chestLoc6, chestLoc7, chestLoc8}, _spawn, hologramManager, _gadgetManager, serverStatusManager);
_treasureManager.addTreasureLocation(loc);
}
new CosmeticManager(_plugin, clientManager, donationManager, _inventoryManager, _gadgetManager, _mountManager, petManager, _treasureManager, boosterManager);
_petManager = petManager;
_partyManager = partyManager;
_preferences = preferences;
_visibilityManager = new HubVisibilityManager(this);
_forcefieldManager = new ForcefieldManager(this);
addCommand(new ForcefieldRadius(_forcefieldManager));
_statsManager = statsManager;
_achievementManager = achievementManager;
_achievementManager.setGiveInterfaceItem(true);
_packetHandler = packetHandler;
new NotificationManager(getPlugin(), clientManager, _preferences);
new BotSpamManager(plugin, clientManager, punish);
((CraftWorld)Bukkit.getWorlds().get(0)).getHandle().pvpMode = true;
new PlayerDisguiseManager(plugin, _clientManager);
new ValentinesGiftManager(plugin, clientManager, _bonusManager.getRewardManager(), inventoryManager, _gadgetManager, statsManager);
_playerCountManager = new PlayerCountManager(plugin);
_customDataManager = new CustomDataManager(plugin, clientManager);
_punishManager = punish;
_serverName = getPlugin().getConfig().getString("serverstatus.name");
_serverName = _serverName.substring(0, Math.min(16, _serverName.length()));
}
@Override
public void addCommands()
{
addCommand(new GadgetToggle(this));
addCommand(new GameModeCommand(this));
}
@EventHandler(priority = EventPriority.HIGHEST)
public void reflectMotd(ServerListPingEvent event)
{
if (_shuttingDown)
{
event.setMotd("Restarting soon");
}
}
public boolean BumpDisabled(Entity ent)
{
if (ent == null)
return false;
if (ent instanceof Player)
{
return !_preferences.Get((Player)ent).HubGames;
}
return true;
}
@EventHandler
public void redirectStopCommand(PlayerCommandPreprocessEvent event)
{
if (event.getPlayer().isOp() && event.getMessage().equalsIgnoreCase("/stop"))
{
_shuttingDown = true;
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(_plugin, new Runnable()
{
public void run()
{
_portal.sendAllPlayers("Lobby");
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(_plugin, new Runnable()
{
public void run()
{
Bukkit.shutdown();
}
}, 40L);
}
}, 60L);
event.setCancelled(true);
}
}
@EventHandler
public void preventEggSpawn(ItemSpawnEvent event)
{
if (event.getEntity() instanceof Egg)
{
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.LOW)
public void login(final PlayerLoginEvent event)
{
CoreClient client = _clientManager.Get(event.getPlayer().getName());
// Reserved Slot Check
if (Bukkit.getOnlinePlayers().size() - Bukkit.getServer().getMaxPlayers() >= 20)
{
if (!client.GetRank().has(Rank.ULTRA))
{
Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable()
{
public void run()
{
_portal.sendPlayerToServer(event.getPlayer(), "Lobby");
}
});
event.allow();
}
}
else
event.allow();
}
@EventHandler(priority = EventPriority.LOW)
public void handleOP(PlayerJoinEvent event)
{
if (_clientManager.Get(event.getPlayer()).GetRank().has(Rank.ADMIN))
event.getPlayer().setOp(true);
else
event.getPlayer().setOp(false);
}
@EventHandler
public void PlayerRespawn(PlayerRespawnEvent event)
{
event.setRespawnLocation(GetSpawn());
}
@EventHandler(priority = EventPriority.LOW)
public void PlayerJoin(PlayerJoinEvent event)
{
Player player = event.getPlayer();
//Public Message
event.setJoinMessage(null);
//Teleport
player.teleport(GetSpawn());
//Survival
player.setGameMode(GameMode.SURVIVAL);
//Clear Inv
UtilInv.Clear(player);
//Health
player.setHealth(20);
//Scoreboard
Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
player.setScoreboard(board);
_scoreboards.put(player, board);
//Objective
Objective obj = board.registerNewObjective(C.Bold + "Player Data", "dummy");
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
for (Rank rank : Rank.values())
{
if (rank != Rank.ALL)
board.registerNewTeam(rank.Name).setPrefix(rank.getTag(true, true) + ChatColor.RESET + " ");
else
board.registerNewTeam(rank.Name).setPrefix("");
}
for (Player otherPlayer : Bukkit.getOnlinePlayers())
{
if (_clientManager.Get(otherPlayer) == null)
continue;
String rankName = _clientManager.Get(player).GetRank().Name;
String otherRankName = _clientManager.Get(otherPlayer).GetRank().Name;
//Add Other to Self
board.getTeam(otherRankName).addPlayer(otherPlayer);
//Add Self to Other
otherPlayer.getScoreboard().getTeam(rankName).addPlayer(player);
}
}
@EventHandler
public void PlayerQuit(PlayerQuitEvent event)
{
event.setQuitMessage(null);
event.getPlayer().leaveVehicle();
event.getPlayer().eject();
event.getPlayer().setOp(false);
for (Player player : UtilServer.getPlayers())
player.getScoreboard().resetScores(event.getPlayer().getName());
_scoreboards.remove(event.getPlayer());
_portalTime.remove(event.getPlayer().getName());
}
@EventHandler
public void playerPrivateMessage(PrivateMessageEvent event)
{
//Dont Let PM Near Spawn!
if (UtilMath.offset2d(GetSpawn(), event.getSender().getLocation()) == 0 && !_clientManager.Get(event.getSender()).GetRank().has(Rank.HELPER))
{
UtilPlayer.message(event.getSender(), F.main("Chat", "You must leave spawn before you can Private Message!"));
event.setCancelled(true);
}
}
@EventHandler
public void Incog(IncognitoHidePlayerEvent event)
{
if (!_clientManager.hasRank(event.getPlayer(), Rank.CMOD))
{
event.setCancelled(true);
}
}
@EventHandler
public void PlayerChat(AsyncPlayerChatEvent event)
{
if (event.isCancelled())
return;
//Dont Let Chat Near Spawn!
if (UtilMath.offset2d(GetSpawn(), event.getPlayer().getLocation()) == 0 && !_clientManager.Get(event.getPlayer()).GetRank().has(Rank.HELPER))
{
UtilPlayer.message(event.getPlayer(), F.main("Chat", "You must leave spawn before you can chat!"));
event.setCancelled(true);
return;
}
Player player = event.getPlayer();
String playerName = player.getName();
Rank rank = GetClients().Get(player).GetRank();
if (GetClients().Get(player).isDisguised())
rank = GetClients().Get(player).getDisguisedRank();
//Level Prefix
String levelStr = _achievementManager.getMineplexLevel(player, rank);
//Rank Prefix
String rankStr = "";
if (rank != Rank.ALL)
rankStr = rank.getTag(true, true) + " ";
//Party Chat
if (event.getMessage().charAt(0) == '#')
{
Party party = _partyManager.getParty(player);
if (party != null)
{
event.getRecipients().clear();
event.setMessage(event.getMessage().substring(1, event.getMessage().length()));
event.setFormat(levelStr + C.cDPurple + C.Bold + "Party " + C.cWhite + C.Bold + playerName + " " + C.cPurple + "%2$s");
for (String name : party.getMembers())
{
Player other = UtilPlayer.searchExact(name);
if (other != null)
event.getRecipients().add(other);
}
}
else
{
UtilPlayer.message(player, F.main("Party", "You are not in a Party."));
event.setCancelled(true);
}
return;
}
else
{
TextComponent rankComponent = new TextComponent(rankStr);
TextComponent playerNameText = new TextComponent(ChatColor.YELLOW + playerName);
TextComponent component = new TextComponent();
rankComponent.setHoverEvent(new HoverEvent(Action.SHOW_TEXT, new ComponentBuilder(rank.getColor() + rank.getTag(true, true) + ChatColor.WHITE + "\n" + rank.getDescription()).create()));
component.setText(levelStr);
component.addExtra(rankComponent);
component.addExtra(playerNameText);
component.addExtra(" " + ChatColor.WHITE + event.getMessage());
for (Player other : UtilServer.getPlayers())
{
if (!event.isCancelled())
other.spigot().sendMessage(component);
}
event.setCancelled(true);
}
}
@EventHandler
public void Damage(EntityDamageEvent event)
{
if (event.getCause() == DamageCause.VOID)
{
if (event.getEntity() instanceof Player)
{
event.getEntity().eject();
event.getEntity().leaveVehicle();
event.getEntity().teleport(GetSpawn());
}
else
{
event.getEntity().remove();
}
}
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.LOWEST)
public void handleDeath(PlayerDeathEvent event)
{
event.setKeepInventory(true);
event.getDrops().clear();
event.getEntity().setHealth(20);
event.getEntity().teleport(GetSpawn());
}
@EventHandler
public void combatDeath(CombatDeathEvent event)
{
event.SetBroadcastType(DeathMessageType.None);
}
@EventHandler
public void FoodHealthUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
for (Player player : UtilServer.getPlayers())
{
player.setFoodLevel(20);
player.setExhaustion(0f);
player.setSaturation(3f);
}
}
@EventHandler
public void InventoryCancel(InventoryClickEvent event)
{
if (event.getWhoClicked() instanceof Player && ((Player)event.getWhoClicked()).getGameMode() != GameMode.CREATIVE)
event.setCancelled(true);
}
@EventHandler
public void UpdateScoreboard(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
_scoreboardTick = (_scoreboardTick + 1)%3;
if (_scoreboardTick != 0)
return;
int playerCount = _playerCountManager.getPlayerCount();
for (Player player : UtilServer.getPlayers())
{
//Return to Main Scoreboard
if (!player.getScoreboard().equals(_scoreboards.get(player)))
player.setScoreboard(_scoreboards.get(player));
//Objective
Objective obj = player.getScoreboard().getObjective(DisplaySlot.SIDEBAR);
//Title
obj.setDisplayName(C.cRed + C.Bold + C.Line + "Mineplex Clans");
int line = 15;
//Space
obj.getScore(" ").setScore(line--);
//Server
obj.getScore(C.cAqua + C.Bold + "Server").setScore(line--);
obj.getScore(_serverName).setScore(line--);
//Space
obj.getScore(" ").setScore(line--);
//Players
obj.getScore(C.cYellow + C.Bold + "Players").setScore(line--);
player.getScoreboard().resetScores(_lastPlayerCount + "");
obj.getScore(playerCount + "").setScore(line--);
//Space
obj.getScore(" ").setScore(line--);
//Display Rank
obj.getScore(C.cGold + C.Bold + "Rank").setScore(line--);
//Remove Old
player.getScoreboard().resetScores(_clientManager.Get(player).GetLastRank(false).Name);
player.getScoreboard().resetScores(_clientManager.Get(player).GetLastRank(true).Name);
player.getScoreboard().resetScores("No Rank");
//Add New
if (GetClients().Get(player).GetRank() != Rank.ALL)
obj.getScore(GetClients().Get(player).GetRank().Name).setScore(line--);
else
obj.getScore("No Rank").setScore(line--);
//Space
obj.getScore(" ").setScore(line--);
//Website
obj.getScore(C.cRed + C.Bold + "Website").setScore(line--);
obj.getScore("www.mineplex.com").setScore(line--);
}
_lastPlayerCount = playerCount;
Bukkit.getOnlinePlayers().stream().filter(player -> _clientManager.Get(player).GetRank() == Rank.ALL).forEach(player ->
{
UtilTextBottom.display(C.cGray + "Visit " + F.elem("http://www.mineplex.com/shop") + " for exclusive perks!", player);
});
}
public BlockRestore GetBlockRestore()
{
return _blockRestore;
}
public CoreClientManager GetClients()
{
return _clientManager;
}
public ConditionManager GetCondition()
{
return _conditionManager;
}
public DonationManager GetDonation()
{
return _donationManager;
}
public DisguiseManager GetDisguise()
{
return _disguiseManager;
}
public GadgetManager GetGadget()
{
return _gadgetManager;
}
public TreasureManager GetTreasure()
{
return _treasureManager;
}
public MountManager GetMount()
{
return _mountManager;
}
public PreferencesManager getPreferences()
{
return _preferences;
}
public Location GetSpawn()
{
return _spawn.clone();
}
public PetManager getPetManager()
{
return _petManager;
}
public BonusManager getBonusManager()
{
return _bonusManager;
}
public StatsManager GetStats()
{
return _statsManager;
}
public HubVisibilityManager GetVisibility()
{
return _visibilityManager;
}
public CustomDataManager getCustomDataManager()
{
return _customDataManager;
}
public Punish getPunishments()
{
return _punishManager;
}
public IncognitoManager getIncognitoManager()
{
return _incognito;
}
@EventHandler(priority = EventPriority.MONITOR)
public void gadgetCollide(GadgetCollideEntityEvent event)
{
if (!event.isCancelled())
{
SetPortalDelay(event.getOther());
}
}
public void SetPortalDelay(Entity ent)
{
if (ent instanceof Player)
{
_portalTime.put(((Player)ent).getName(), System.currentTimeMillis());
}
}
public boolean CanPortal(Player player)
{
//Riding
if (player.getVehicle() != null || player.getPassenger() != null)
return false;
//Portal Delay
if (!_portalTime.containsKey(player.getName()))
return true;
return UtilTime.elapsed(_portalTime.get(player.getName()), 5000);
}
@EventHandler
public void ignoreVelocity(PlayerVelocityEvent event)
{
if (_clientManager.Get(event.getPlayer()).GetRank().has(Rank.TWITCH) && _preferences.Get(event.getPlayer()).IgnoreVelocity)
{
event.setCancelled(true);
}
}
public void ToggleGadget(Player caller)
{
toggleGadget();
}
public void toggleGadget()
{
GetGadget().toggleGadgetEnabled();
for (Player player : UtilServer.getPlayers())
player.sendMessage(C.cWhite + C.Bold + "Gadgets/Mounts are now " + F.elem(GetGadget().isGadgetEnabled() ? C.cGreen + C.Bold + "Enabled" : C.cRed + C.Bold + "Disabled"));
}
public void addGameMode(Player caller, Player target)
{
if (!_creativeAdmin.containsKey(caller.getName()))
_creativeAdmin.put(caller.getName(), new ArrayList<String>());
if (target.getGameMode() == GameMode.CREATIVE)
{
_creativeAdmin.get(caller.getName()).add(target.getName());
}
else
{
_creativeAdmin.get(caller.getName()).remove(target.getName());
}
}
@EventHandler
public void clearEntityTargets(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
for (Entity entity : Bukkit.getWorlds().get(0).getEntities())
{
if (entity instanceof EntityInsentient)
{
EntityInsentient entityMonster = (EntityInsentient)entity;
if (entityMonster.getGoalTarget() != null && entityMonster.getGoalTarget() instanceof EntityPlayer)
{
if (((EntityPlayer)entityMonster.getGoalTarget()).playerConnection.isDisconnected())
entityMonster.setGoalTarget(null, TargetReason.FORGOT_TARGET, false);
}
}
}
}
@EventHandler
public void clearGameMode(PlayerQuitEvent event)
{
ArrayList<String> creative = _creativeAdmin.remove(event.getPlayer().getName());
if (creative == null)
return;
for (String name : creative)
{
Player player = UtilPlayer.searchExact(name);
if (player == null)
continue;
player.setGameMode(GameMode.SURVIVAL);
UtilPlayer.message(player, F.main("Game Mode", event.getPlayer().getName() + " left the game. Creative Mode: " + F.tf(false)));
}
}
public PacketHandler getPacketHandler()
{
return _packetHandler;
}
@EventHandler
public void openProfile(PlayerInteractEvent event)
{
if(event.getItem() == null || event.getItem().getType() != Material.SKULL_ITEM)
return;
new GUIProfile(getPlugin(), event.getPlayer(), _preferences, _achievementManager).openInventory();;
}
@EventHandler
public void trackPortalDelayPlayers(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
for (Iterator<String> playerNameIterator = _portalTime.keySet().iterator(); playerNameIterator.hasNext();)
{
String playerName = playerNameIterator.next();
if (UtilTime.elapsed(_portalTime.get(playerName), 5000))
{
playerNameIterator.remove();
}
}
}
@EventHandler
public void showHeader(UpdateEvent event)
{
if (event.getType() != UpdateType.FASTEST)
{
return;
}
String text = C.cRed + "Welcome to Mineplex Clans";
UtilTextTop.display(text, UtilServer.getPlayers());
//Fix Entity Names
for (Creature pet : _petManager.getPets())
{
DisguiseBase disguise = _disguiseManager.getDisguise(pet);
if (disguise instanceof DisguiseWither)
{
((DisguiseWither) disguise).setName(text);
disguise.resendMetadata();
}
}
for (Mount mount : _mountManager.getMounts())
{
if (mount instanceof MountDragon)
{
((MountDragon)mount).SetName(text);
}
}
for (Gadget gadget : _gadgetManager.getGadgets(GadgetType.MORPH))
{
if (gadget instanceof MorphWither)
{
((MorphWither)gadget).setWitherData(text, 100);
}
}
}
}