Mineplex2018-withcommit/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java

1176 lines
29 KiB
Java
Raw Normal View History

2013-08-27 17:14:08 +02:00
package nautilus.game.arcade;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.UUID;
2013-08-27 17:14:08 +02:00
import org.bukkit.Bukkit;
2013-08-27 17:14:08 +02:00
import org.bukkit.ChatColor;
import org.bukkit.Color;
2013-08-27 17:14:08 +02:00
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.EntityType;
2013-08-27 17:14:08 +02:00
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
2013-11-22 08:40:38 +01:00
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
2014-08-10 02:50:31 +02:00
import org.bukkit.event.inventory.InventoryType;
2014-04-21 04:55:24 +02:00
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
2013-08-27 17:14:08 +02:00
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
2013-08-27 17:14:08 +02:00
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.server.ServerListPingEvent;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.achievement.AchievementManager;
2013-08-27 17:14:08 +02:00
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.blood.Blood;
import mineplex.core.chat.Chat;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.cosmetic.CosmeticManager;
2013-08-27 17:14:08 +02:00
import mineplex.core.creature.Creature;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.elo.EloManager;
import mineplex.core.energy.Energy;
2013-08-27 17:14:08 +02:00
import mineplex.core.explosion.Explosion;
import mineplex.core.hologram.HologramManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.movement.Movement;
import mineplex.core.packethandler.PacketHandler;
2014-09-19 04:03:46 +02:00
import mineplex.core.pet.PetManager;
2013-08-27 17:14:08 +02:00
import mineplex.core.portal.Portal;
2014-06-10 02:27:25 +02:00
import mineplex.core.preferences.PreferencesManager;
2013-08-27 17:14:08 +02:00
import mineplex.core.projectile.ProjectileManager;
import mineplex.core.reward.RewardRarity;
import mineplex.core.reward.rewards.PetReward;
import mineplex.core.stats.StatsManager;
import mineplex.core.status.ServerStatusManager;
import mineplex.core.task.TaskManager;
import mineplex.core.teleport.Teleport;
2014-06-25 21:06:24 +02:00
import mineplex.core.timing.TimingManager;
import mineplex.minecraft.game.classcombat.Class.ClassManager;
import mineplex.minecraft.game.classcombat.Condition.SkillConditionManager;
import mineplex.minecraft.game.classcombat.Skill.SkillFactory;
import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent;
import mineplex.minecraft.game.classcombat.item.ItemFactory;
import mineplex.minecraft.game.classcombat.item.event.ItemTriggerEvent;
import mineplex.minecraft.game.classcombat.shop.ClassCombatShop;
import mineplex.minecraft.game.classcombat.shop.ClassShopManager;
import mineplex.minecraft.game.core.IRelation;
import mineplex.minecraft.game.core.condition.ConditionManager;
import mineplex.minecraft.game.core.damage.DamageManager;
import mineplex.minecraft.game.core.fire.Fire;
import nautilus.game.arcade.addons.CompassAddon;
import nautilus.game.arcade.addons.SoupAddon;
import nautilus.game.arcade.addons.TeamArmorAddon;
import nautilus.game.arcade.command.GameCommand;
import nautilus.game.arcade.command.WriteCommand;
import nautilus.game.arcade.command.YoutubeCommand;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameServerConfig;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.uhc.UHC;
import nautilus.game.arcade.managers.GameAchievementManager;
import nautilus.game.arcade.managers.GameChatManager;
import nautilus.game.arcade.managers.GameCreationManager;
import nautilus.game.arcade.managers.GameFlagManager;
import nautilus.game.arcade.managers.GameGemManager;
import nautilus.game.arcade.managers.GameHostManager;
import nautilus.game.arcade.managers.GameLobbyManager;
2014-09-19 04:03:46 +02:00
import nautilus.game.arcade.managers.GameLootManager;
import nautilus.game.arcade.managers.GameManager;
import nautilus.game.arcade.managers.GamePlayerManager;
import nautilus.game.arcade.managers.GameSpectatorManager;
2014-09-21 01:28:12 +02:00
import nautilus.game.arcade.managers.GameStatManager;
import nautilus.game.arcade.managers.GameTournamentManager;
import nautilus.game.arcade.managers.GameWorldManager;
import nautilus.game.arcade.managers.IdleManager;
import nautilus.game.arcade.managers.MiscManager;
import nautilus.game.arcade.shop.ArcadeShop;
2013-08-27 17:14:08 +02:00
public class ArcadeManager extends MiniPlugin implements IRelation
2013-08-27 17:14:08 +02:00
{
// Modules
2013-08-27 17:14:08 +02:00
private BlockRestore _blockRestore;
2013-08-31 05:15:16 +02:00
private Blood _blood;
private Chat _chat;
2013-08-27 17:14:08 +02:00
private CoreClientManager _clientManager;
private DisguiseManager _disguiseManager;
private DonationManager _donationManager;
private ConditionManager _conditionManager;
private PetManager _petManager;
2013-08-27 17:14:08 +02:00
private Creature _creature;
private DamageManager _damageManager;
private Explosion _explosionManager;
2013-08-27 17:14:08 +02:00
private Fire _fire;
private ProjectileManager _projectileManager;
2013-09-04 23:44:53 +02:00
private Portal _portal;
private ArcadeShop _arcadeShop;
//Champions Modules
private boolean _enabled = true;
private ClassManager _classManager;
private SkillFactory _skillFactory;
private ItemFactory _itemFactory;
private Energy _energy;
private ClassShopManager _classShopManager;
private ClassCombatShop _classShop;
private EloManager _eloManager;
// Managers
2013-08-27 17:14:08 +02:00
private GameFactory _gameFactory;
private GameCreationManager _gameCreationManager;
private GameGemManager _gameGemManager;
private GameManager _gameManager;
2013-08-27 17:14:08 +02:00
private GameLobbyManager _gameLobbyManager;
private GamePlayerManager _gamePlayerManager;
private GameTournamentManager _gameTournamentManager;
private GameWorldManager _gameWorldManager;
private GameHostManager _gameHostManager;
private ServerStatusManager _serverStatusManager;
private InventoryManager _inventoryManager;
private CosmeticManager _cosmeticManager;
2014-11-08 00:28:06 +01:00
private final IdleManager _idleManager;
private HologramManager _hologramManager;
private AchievementManager _achievementManager;
private StatsManager _statsManager;
private TaskManager _taskManager;
private ArcadeRepository _arcadeRepository;
private PacketHandler _packetHandler;
// Observers
private HashSet<Player> _specList = new HashSet<Player>();
2013-09-04 23:44:53 +02:00
// Server Games
2013-08-27 17:14:08 +02:00
private GameServerConfig _serverConfig;
// Games
2013-08-27 17:14:08 +02:00
private Game _game;
//Youtuber Kits
private HashSet<Player> _youtube = new HashSet<Player>();
public ArcadeManager(Arcade plugin, ServerStatusManager serverStatusManager, GameServerConfig serverConfig,
CoreClientManager clientManager, DonationManager donationManager, DamageManager damageManager,
2014-11-24 02:51:23 +01:00
DisguiseManager disguiseManager, Creature creature, Teleport teleport, Blood blood,
Portal portal, PreferencesManager preferences, InventoryManager inventoryManager, PacketHandler packetHandler,
CosmeticManager cosmeticManager, ProjectileManager projectileManager, PetManager petManager, HologramManager hologramManager, String webAddress)
2013-08-27 17:14:08 +02:00
{
super("Game Manager", plugin);
_serverConfig = serverConfig;
// Modules
2013-08-27 17:14:08 +02:00
_blockRestore = new BlockRestore(plugin);
2013-09-04 23:44:53 +02:00
2013-08-31 05:15:16 +02:00
_blood = blood;
2013-09-04 23:44:53 +02:00
2013-08-27 17:14:08 +02:00
_explosionManager = new Explosion(plugin, _blockRestore);
_explosionManager.SetDebris(false);
2013-09-04 23:44:53 +02:00
if (serverConfig.GameList.contains(GameType.ChampionsDominate)
|| serverConfig.GameList.contains(GameType.ChampionsTDM)
|| serverConfig.GameList.contains(GameType.ChampionsMOBA))
{
_conditionManager = new SkillConditionManager(plugin);
}
else
{
_conditionManager = new ConditionManager(plugin);
}
2013-09-04 23:44:53 +02:00
2013-08-27 17:14:08 +02:00
_clientManager = clientManager;
_serverStatusManager = serverStatusManager;
_chat = new Chat(plugin, _clientManager, preferences, _serverStatusManager.getCurrentServerName());
2013-09-04 23:44:53 +02:00
2013-08-27 17:14:08 +02:00
_creature = creature;
2013-09-04 23:44:53 +02:00
2013-08-27 17:14:08 +02:00
_damageManager = damageManager;
_damageManager.UseSimpleWeaponDamage = true;
2013-09-04 23:44:53 +02:00
2013-08-31 05:15:16 +02:00
_disguiseManager = disguiseManager;
2013-09-04 23:44:53 +02:00
2013-08-27 17:14:08 +02:00
_donationManager = donationManager;
_fire = new Fire(plugin, _conditionManager, damageManager);
2014-08-22 20:30:41 +02:00
_projectileManager = projectileManager;
_packetHandler = packetHandler;
2013-11-22 08:40:38 +01:00
_statsManager = new StatsManager(plugin, clientManager);
_taskManager = new TaskManager(plugin, webAddress);
_achievementManager = new AchievementManager(_statsManager, clientManager, donationManager);
_inventoryManager = inventoryManager;
_cosmeticManager = cosmeticManager;
_portal = portal;
_petManager = petManager;
2013-09-04 23:44:53 +02:00
// Shop
2013-08-27 17:14:08 +02:00
_arcadeShop = new ArcadeShop(this, clientManager, donationManager);
2014-09-06 03:31:55 +02:00
// Game Factory
2013-08-27 17:14:08 +02:00
_gameFactory = new GameFactory(this);
2013-09-04 23:44:53 +02:00
// Managers
new GameChatManager(this);
2013-08-27 17:14:08 +02:00
_gameCreationManager = new GameCreationManager(this);
_gameGemManager = new GameGemManager(this);
_gameManager = new GameManager(this);
_gameLobbyManager = new GameLobbyManager(this, packetHandler);
_gameHostManager = new GameHostManager(this);
2013-08-27 17:14:08 +02:00
new GameFlagManager(this);
_gamePlayerManager = new GamePlayerManager(this);
2014-08-08 09:05:11 +02:00
new GameAchievementManager(this);
_gameTournamentManager = new GameTournamentManager(this);
2014-09-21 01:28:12 +02:00
new GameStatManager(this);
2014-09-19 04:03:46 +02:00
new GameLootManager(this, petManager);
new GameSpectatorManager(this);
2013-08-27 17:14:08 +02:00
_gameWorldManager = new GameWorldManager(this);
new MiscManager(this);
_hologramManager = hologramManager;
2014-11-08 00:28:06 +01:00
_idleManager = new IdleManager(this);
//new HalloweenManager(this);
_arcadeRepository = new ArcadeRepository(plugin);
// Game Addons
2013-08-27 17:14:08 +02:00
new CompassAddon(plugin, this);
new SoupAddon(plugin, this);
new TeamArmorAddon(plugin, this);
//Champions Modules
2014-12-23 01:39:03 +01:00
_energy = new Energy(plugin);
_itemFactory = new ItemFactory(_plugin, _blockRestore, _conditionManager, damageManager, _energy,
_fire, _projectileManager, webAddress);
_skillFactory = new SkillFactory(plugin, damageManager, this, _damageManager.GetCombatManager(),
_conditionManager, _projectileManager, _disguiseManager, _blockRestore, _fire, new Movement(plugin), teleport,
_energy, webAddress);
_classManager = new ClassManager(plugin, clientManager, donationManager, _skillFactory, _itemFactory,
webAddress);
2014-12-23 01:22:41 +01:00
2014-12-23 01:39:03 +01:00
_classShopManager = new ClassShopManager(_plugin, _classManager, _skillFactory, _itemFactory, _achievementManager, clientManager);
_classShop = new ClassCombatShop(_classShopManager, clientManager, donationManager, false, "Class Shop");
2014-12-23 01:22:41 +01:00
2014-12-23 01:39:03 +01:00
_eloManager = new EloManager(_plugin, clientManager);
if (GetHost() != null && !GetHost().isEmpty())
{
Portal.transferPlayer(GetHost(), _serverStatusManager.getCurrentServerName());
}
2013-08-27 17:14:08 +02:00
}
@Override
public void AddCommands()
2013-08-27 17:14:08 +02:00
{
addCommand(new GameCommand(this));
addCommand(new WriteCommand(this));
addCommand(new YoutubeCommand(this));
2013-08-27 17:14:08 +02:00
}
2013-09-04 23:44:53 +02:00
2013-08-27 17:14:08 +02:00
public GameServerConfig GetServerConfig()
{
return _serverConfig;
}
public ArrayList<GameType> GetGameList()
{
return GetServerConfig().GameList;
}
2014-08-10 02:50:31 +02:00
public AchievementManager GetAchievement()
{
return _achievementManager;
}
2013-09-04 23:44:53 +02:00
2013-08-31 05:15:16 +02:00
public Blood GetBlood()
{
return _blood;
}
2013-08-27 17:14:08 +02:00
public Chat GetChat()
{
return _chat;
}
public BlockRestore GetBlockRestore()
{
return _blockRestore;
}
2013-09-04 23:44:53 +02:00
2013-08-27 17:14:08 +02:00
public CoreClientManager GetClients()
{
return _clientManager;
}
public ConditionManager GetCondition()
{
return _conditionManager;
}
2013-09-04 23:44:53 +02:00
2013-08-27 17:14:08 +02:00
public Creature GetCreature()
{
return _creature;
}
public PacketHandler getPacketHandler()
{
return _packetHandler;
}
2013-08-27 17:14:08 +02:00
public CosmeticManager getCosmeticManager()
{
return _cosmeticManager;
}
2014-08-10 02:50:31 +02:00
2013-08-27 17:14:08 +02:00
public DisguiseManager GetDisguise()
{
return _disguiseManager;
}
public HologramManager getHologramManager()
{
return _hologramManager;
}
2013-09-04 23:44:53 +02:00
2013-08-27 17:14:08 +02:00
public DamageManager GetDamage()
{
return _damageManager;
}
public DonationManager GetDonation()
{
return _donationManager;
}
2013-11-22 08:40:38 +01:00
public EloManager getEloManager()
{
return _eloManager;
}
public Explosion GetExplosion()
{
return _explosionManager;
}
2013-08-27 17:14:08 +02:00
public Fire GetFire()
{
return _fire;
}
2013-08-27 17:14:08 +02:00
public ProjectileManager GetProjectile()
{
return _projectileManager;
}
2013-09-04 23:44:53 +02:00
public Portal GetPortal()
{
return _portal;
}
2013-09-04 23:44:53 +02:00
2013-08-27 17:14:08 +02:00
public GameLobbyManager GetLobby()
{
return _gameLobbyManager;
}
public TaskManager GetTaskManager()
{
return _taskManager;
}
2013-09-04 23:44:53 +02:00
2013-08-27 17:14:08 +02:00
public ArcadeShop GetShop()
{
return _arcadeShop;
}
2013-08-27 17:14:08 +02:00
public GameCreationManager GetGameCreationManager()
{
return _gameCreationManager;
2013-08-27 17:14:08 +02:00
}
2013-09-04 23:44:53 +02:00
2014-11-07 02:14:33 +01:00
public GameHostManager GetGameHostManager()
{
return _gameHostManager;
}
2013-08-27 17:14:08 +02:00
public GameFactory GetGameFactory()
{
return _gameFactory;
}
2013-09-04 23:44:53 +02:00
2013-08-27 17:14:08 +02:00
public GameManager GetGameManager()
{
return _gameManager;
}
2013-09-04 23:44:53 +02:00
2013-08-27 17:14:08 +02:00
public GameGemManager GetGameGemManager()
{
return _gameGemManager;
}
public GamePlayerManager GetGamePlayerManager()
{
return _gamePlayerManager;
}
public GameTournamentManager GetGameTournamentManager()
{
return _gameTournamentManager;
}
2013-09-04 23:44:53 +02:00
2013-08-27 17:14:08 +02:00
public GameWorldManager GetGameWorldManager()
{
return _gameWorldManager;
}
public StatsManager GetStatsManager()
{
return _statsManager;
}
2014-08-10 02:50:31 +02:00
public ServerStatusManager GetServerStatusManager()
{
return _serverStatusManager;
}
2013-08-27 17:14:08 +02:00
public ChatColor GetColor(Player player)
{
if (_game == null)
return ChatColor.GRAY;
GameTeam team = _game.GetTeam(player);
if (team == null)
return ChatColor.GRAY;
return team.GetColor();
}
@Override
public boolean canHurt(String a, String b)
2013-08-27 17:14:08 +02:00
{
return canHurt(UtilPlayer.searchExact(a), UtilPlayer.searchExact(b));
2013-08-27 17:14:08 +02:00
}
public boolean canHurt(Player pA, Player pB)
2013-08-27 17:14:08 +02:00
{
if (pA == null || pB == null)
return false;
if (!_game.Damage)
return false;
if (!_game.DamagePvP)
return false;
// Self Damage
2013-08-27 17:14:08 +02:00
if (pA.equals(pB))
return _game.DamageSelf;
GameTeam tA = _game.GetTeam(pA);
if (tA == null)
return false;
GameTeam tB = _game.GetTeam(pB);
if (tB == null)
return false;
if (tA.equals(tB) && !_game.DamageTeamSelf)
return false;
if (!tA.equals(tB) && !_game.DamageTeamOther)
return false;
return true;
}
@Override
public boolean isSafe(Player player)
2013-08-27 17:14:08 +02:00
{
if (_game == null)
return true;
if (_game.IsPlaying(player))
return false;
2013-11-22 08:40:38 +01:00
2013-08-27 17:14:08 +02:00
return true;
}
@EventHandler
public void MessageMOTD(ServerListPingEvent event)
{
2014-12-22 06:31:13 +01:00
//MPS
if (_gameHostManager != null && _gameHostManager.isPrivateServer())
{
if (_gameHostManager.isHostExpired())
{
event.setMotd(ChatColor.RED + "Finished");
return;
}
if (!GetServerConfig().PublicServer)
{
event.setMotd(ChatColor.GRAY + "Private");
return;
}
}
2014-12-23 11:15:33 +01:00
String extrainformation = "|" + _serverConfig.ServerType + "|" + (_game == null ? "Unknown" : _game.GetName())
+ "|" + ((_game == null || _game.WorldData == null) ? "Unknown" : _game.WorldData.MapName);
2014-12-23 11:15:33 +01:00
if (_gameHostManager.isPrivateServer() && _gameHostManager.hasRank(Rank.MODERATOR))
extrainformation += "|StaffHosted";
//Always Joinable
// if (_game != null && _game.JoinInProgress)
// {
// event.setMotd(ChatColor.GREEN + "Recruiting" + extrainformation);
// }
//UHC Timed
if (_game != null && _game.GetType() == GameType.UHC)
{
event.setMotd(((UHC) _game).getMotdStatus() + extrainformation);
}
//Recruiting
else if (_game == null || _game.GetState() == GameState.Recruit)
2013-08-27 17:14:08 +02:00
{
if (_game != null && _game.GetCountdown() != -1)
{
event.setMotd(ChatColor.GREEN + "Starting in " + _game.GetCountdown() + " Seconds" + extrainformation);
2013-08-27 17:14:08 +02:00
}
else
{
event.setMotd(ChatColor.GREEN + "Recruiting" + extrainformation);
2013-08-27 17:14:08 +02:00
}
}
//In Progress
2013-08-27 17:14:08 +02:00
else
{
event.setMotd(ChatColor.YELLOW + "In Progress" + extrainformation);
2013-08-27 17:14:08 +02:00
}
}
2013-09-04 23:44:53 +02:00
2013-08-27 17:14:08 +02:00
@EventHandler
public void MessageJoin(PlayerJoinEvent event)
{
if (_game == null || _game.AnnounceJoinQuit)
{
Player player = event.getPlayer();
if (_clientManager.Get(player).GetRank() != Rank.LEGEND)
event.setJoinMessage(null);
else
{
event.setJoinMessage(C.cGreen + C.Bold + "Legend " + player.getName() + " has joined!");
UtilFirework.playFirework(player.getEyeLocation(), org.bukkit.FireworkEffect.Type.BALL_LARGE, Color.LIME, true, true);
player.getWorld().playSound(player.getEyeLocation(), Sound.WITHER_SPAWN, 2f, 1f);
}
}
else
event.setJoinMessage(null);
2013-08-27 17:14:08 +02:00
}
@EventHandler
public void MessageQuit(PlayerQuitEvent event)
{
if (_game == null || _game.AnnounceJoinQuit)
event.setQuitMessage(F.sys("Quit", GetColor(event.getPlayer()) + event.getPlayer().getName()));
else
event.setQuitMessage(null);
2013-08-27 17:14:08 +02:00
}
public Game GetGame()
2013-08-27 17:14:08 +02:00
{
return _game;
}
public void SetGame(Game game)
{
_game = game;
}
public int GetPlayerMin()
{
return GetServerConfig().MinPlayers;
}
public int GetPlayerFull()
{
return GetServerConfig().MaxPlayers;
}
public void HubClock(Player player)
{
if (!IsHotbarHubClock())
return;
if (_game != null && !_game.GiveClock)
return;
if (player.getOpenInventory().getType() != InventoryType.CRAFTING &&
2014-08-10 02:50:31 +02:00
player.getOpenInventory().getType() != InventoryType.CREATIVE)
return;
if (!UtilGear.isMat(player.getInventory().getItem(8), Material.WATCH))
{
player.getInventory().setItem(
8,
ItemStackFactory.Instance.CreateStack(Material.WATCH, (byte) 0, 1, (short) 0, C.cGreen
+ "Return to Hub", new String[]{"", ChatColor.RESET + "Click while holding this",
ChatColor.RESET + "to return to the Hub."}));
2014-08-10 02:50:31 +02:00
UtilInv.Update(player);
}
}
2013-11-22 08:40:38 +01:00
@EventHandler
public void Login(PlayerLoginEvent event)
{
if (Bukkit.getServer().hasWhitelist())
{
if (_clientManager.Get(event.getPlayer().getName()).GetRank().Has(event.getPlayer(), Rank.MODERATOR, false))
{
event.allow();
event.setResult(PlayerLoginEvent.Result.ALLOWED);
if (_serverConfig.Tournament)
{
event.getPlayer().setOp(true);
}
}
else
{
for (OfflinePlayer player : Bukkit.getWhitelistedPlayers())
{
if (player.getName().equalsIgnoreCase(event.getPlayer().getName()))
{
event.allow();
event.setResult(PlayerLoginEvent.Result.ALLOWED);
return;
}
}
2014-08-10 02:50:31 +02:00
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Server Whitelisted!");
}
return;
}
// Reserved Slot Check
2014-08-20 04:24:49 +02:00
if (Bukkit.getOnlinePlayers().size() >= Bukkit.getServer().getMaxPlayers())
{
if (_clientManager.Get(event.getPlayer().getName()).GetRank().Has(event.getPlayer(), Rank.HELPER, false))
{
event.allow();
event.setResult(PlayerLoginEvent.Result.ALLOWED);
return;
}
2014-12-12 11:23:01 +01:00
else if (_clientManager.Get(event.getPlayer().getName()).GetRank().Has(event.getPlayer(), Rank.ULTRA, false)
|| _donationManager.Get(event.getPlayer().getName()).OwnsUnknownPackage(_serverConfig.ServerType + " ULTRA"))
{
2014-10-11 14:56:47 +02:00
2014-12-12 11:23:01 +01:00
if (GetGame() != null && (GetGame().GetType() == GameType.UHC || GetGame().GetType() == GameType.Halloween || GetGame().GetType() == GameType.Christmas || GetGame().GetType() == GameType.ChampionsDominate || GetGame().GetType() == GameType.ChampionsTDM || GetGame().GetType() == GameType.MineStrike))
2014-10-11 14:56:47 +02:00
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, C.Bold + "Server has reached max capacity for gameplay purposes.");
return;
}
else if (Bukkit.getServer().getOnlinePlayers().size() / Bukkit.getMaxPlayers() > 1.5)
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, C.Bold + "Server has reached max capacity for gameplay purposes.");
return;
}
event.allow();
event.setResult(PlayerLoginEvent.Result.ALLOWED);
return;
}
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Server Full > Purchase Ultra at www.mineplex.com/shop");
}
}
public boolean IsAlive(Player player)
2013-08-27 17:14:08 +02:00
{
if (_game == null)
2013-08-27 17:14:08 +02:00
return false;
return _game.IsAlive(player);
}
2013-09-04 23:44:53 +02:00
2013-08-27 17:14:08 +02:00
public void Clear(Player player)
{
player.setGameMode(GameMode.SURVIVAL);
player.setAllowFlight(false);
UtilInv.Clear(player);
2013-11-22 08:40:38 +01:00
((CraftEntity) player).getHandle().getDataWatcher().watch(0, Byte.valueOf((byte) 0));
2013-11-22 08:40:38 +01:00
player.setSprinting(false);
player.setSneaking(false);
2013-08-27 17:14:08 +02:00
player.setFoodLevel(20);
player.setSaturation(3f);
player.setExhaustion(0f);
2013-11-22 08:40:38 +01:00
2014-04-12 10:22:53 +02:00
player.setMaxHealth(20);
player.setHealth(player.getMaxHealth());
2013-11-22 08:40:38 +01:00
2013-08-27 17:14:08 +02:00
player.setFireTicks(0);
player.setFallDistance(0);
2013-11-22 08:40:38 +01:00
2013-08-27 17:14:08 +02:00
player.setLevel(0);
player.setExp(0f);
2013-11-22 08:40:38 +01:00
((CraftPlayer) player).getHandle().spectating = false;
((CraftPlayer) player).getHandle().k = true;
// Arrows go bye bye.
((CraftPlayer) player).getHandle().p(0);
2013-08-27 17:14:08 +02:00
//Remove all conditions
GetCondition().EndCondition(player, null, null);
2013-08-27 17:14:08 +02:00
HubClock(player);
2013-09-04 23:44:53 +02:00
2013-09-02 01:38:32 +02:00
GetDisguise().undisguise(player);
2013-08-27 17:14:08 +02:00
}
2014-04-11 12:09:21 +02:00
public ArrayList<String> LoadFiles(String gameName)
2013-08-27 17:14:08 +02:00
{
2014-06-25 21:06:24 +02:00
TimingManager.start("ArcadeManager LoadFiles");
File folder = new File(".." + File.separatorChar + ".." + File.separatorChar + "update" + File.separatorChar
+ "maps" + File.separatorChar + gameName);
if (!folder.exists())
folder.mkdirs();
2013-08-27 17:14:08 +02:00
ArrayList<String> maps = new ArrayList<String>();
System.out.println("Searching Maps in: " + folder);
2013-09-04 23:44:53 +02:00
2013-08-27 17:14:08 +02:00
for (File file : folder.listFiles())
{
if (!file.isFile())
continue;
2013-09-04 23:44:53 +02:00
2013-08-27 17:14:08 +02:00
String name = file.getName();
if (name.length() < 5)
continue;
2013-09-04 23:44:53 +02:00
name = name.substring(name.length() - 4, name.length());
2013-08-27 17:14:08 +02:00
if (file.getName().equals(".zip"))
continue;
maps.add(file.getName().substring(0, file.getName().length() - 4));
2013-08-27 17:14:08 +02:00
}
for (String map : maps)
System.out.println("Found Map: " + map);
2014-06-25 21:06:24 +02:00
TimingManager.stop("ArcadeManager LoadFiles");
2013-08-27 17:14:08 +02:00
return maps;
}
public ClassManager getClassManager()
{
return _classManager;
}
2013-11-22 08:40:38 +01:00
public ClassCombatShop getClassShop()
{
return _classShop;
}
public void openClassShop(Player player)
{
_classShop.attemptShopOpen(player);
}
2013-11-22 08:40:38 +01:00
@EventHandler
public void BlockBurn(BlockBurnEvent event)
{
if (_game == null)
event.setCancelled(true);
}
@EventHandler
public void BlockSpread(BlockSpreadEvent event)
{
if (_game == null)
event.setCancelled(true);
}
@EventHandler
public void BlockFade(BlockFadeEvent event)
{
if (_game == null)
event.setCancelled(true);
}
@EventHandler
public void BlockDecay(LeavesDecayEvent event)
{
if (_game == null)
event.setCancelled(true);
}
2014-03-01 00:35:06 +01:00
@EventHandler
2013-11-22 08:40:38 +01:00
public void MobSpawn(CreatureSpawnEvent event)
{
if (_game == null)
event.setCancelled(true);
}
@EventHandler
public void SkillTrigger(SkillTriggerEvent event)
{
if (_game == null || !_game.IsLive())
{
event.SetCancelled(true);
}
}
@EventHandler
public void ItemTrigger(ItemTriggerEvent event)
{
if (_game == null || !_game.IsLive())
{
event.SetCancelled(true);
}
}
2014-05-02 06:35:41 +02:00
@EventHandler
public void Observer(PlayerCommandPreprocessEvent event)
{
if (event.getMessage().equalsIgnoreCase("/spec"))
{
2014-05-03 05:06:15 +02:00
event.setCancelled(true);
2014-05-03 05:06:15 +02:00
if (_game != null && _game.InProgress())
{
UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot toggle Spectator during games."));
return;
}
if (!_specList.remove(event.getPlayer()))
{
_specList.add(event.getPlayer());
UtilPlayer.message(event.getPlayer(), F.main("Game", "You are now a Spectator!"));
}
else
{
UtilPlayer.message(event.getPlayer(), F.main("Game", "You are no longer a Spectator!"));
}
// Clean
if (_game != null)
{
// Remove Data
_game.RemoveTeamPreference(event.getPlayer());
_game.GetPlayerKits().remove(event.getPlayer());
_game.GetPlayerGems().remove(event.getPlayer());
// Leave Team
GameTeam team = _game.GetTeam(event.getPlayer());
if (team != null)
{
team.RemovePlayer(event.getPlayer());
}
}
}
}
@EventHandler
public void ObserverQuit(PlayerQuitEvent event)
{
_specList.remove(event.getPlayer());
}
public boolean IsObserver(Player player)
{
return _specList.contains(player);
}
2014-05-02 06:35:41 +02:00
public boolean IsTournamentServer()
{
return _serverConfig.Tournament;
}
public boolean IsTournamentPoints()
{
return _serverConfig.TournamentPoints;
}
public boolean IsTeamRejoin()
{
return _serverConfig.TeamRejoin;
}
public boolean IsTeamAutoJoin()
{
return _serverConfig.TeamAutoJoin;
}
public boolean IsGameAutoStart()
{
return _serverConfig.GameAutoStart;
}
public boolean IsGameTimeout()
{
return _serverConfig.GameTimeout;
}
public boolean IsTeamBalance()
{
return _serverConfig.TeamForceBalance;
}
public boolean IsRewardGems()
{
return _serverConfig.RewardGems;
}
public boolean IsRewardItems()
{
return _serverConfig.RewardItems;
}
public boolean IsRewardStats()
{
return _serverConfig.RewardStats;
}
public boolean IsRewardAchievements()
{
return _serverConfig.RewardAchievements;
}
public boolean IsHotbarInventory()
{
return _serverConfig.HotbarInventory;
}
public boolean IsHotbarHubClock()
{
return _serverConfig.HotbarHubClock;
}
public boolean IsPlayerKickIdle()
{
return _serverConfig.PlayerKickIdle;
}
2014-08-26 06:42:17 +02:00
public int GetDesiredPlayerAmount()
{
return _serverConfig.MaxPlayers;
}
public String GetHost()
{
return _serverConfig.HostName;
}
2014-05-06 07:55:14 +02:00
@EventHandler
public void ObserverQuit(GameStateChangeEvent event)
{
if (_skillFactory != null)
{
_skillFactory.ResetAll();
}
}
public InventoryManager getInventoryManager()
{
return _inventoryManager;
}
2014-08-10 02:50:31 +02:00
@EventHandler(priority = EventPriority.LOWEST)
public void cosmeticState(GameStateChangeEvent event)
{
//Disable
if (event.GetState() == GameState.Recruit)
{
2014-08-11 07:33:45 +02:00
getCosmeticManager().setActive(true);
}
2014-08-09 16:21:45 +02:00
else if (event.GetState() == GameState.Prepare || event.GetState() == GameState.Loading || event.GetState() == GameState.Dead)
{
if (getCosmeticManager().isShowingInterface())
{
2014-08-11 07:33:45 +02:00
getCosmeticManager().setActive(false);
getCosmeticManager().disableItemsForGame();
}
}
}
public ArcadeRepository getArcadeRepository()
{
return _arcadeRepository;
}
public void saveBasicStats(final Game game)
{
if (!IsTournamentServer())
return;
final Map<UUID, Boolean> data = new HashMap<>();
for (Player loser : game.getLosers())
data.put(loser.getUniqueId(), false);
for (Player winner : game.getWinners())
data.put(winner.getUniqueId(), true);
Bukkit.getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
@Override
public void run()
{
getArcadeRepository().saveBasicStats(game.GetType(), IsTournamentServer(), (int) (System.currentTimeMillis() - game.getGameLiveTime()), data);
}
});
}
public void saveLeaderboardStats(Game game)
{
final TournamentType type = TournamentType.getTournamentType(game.GetType());
if (type != null)
{
final Map<UUID, Boolean> data = new HashMap<>();
for (Player loser : game.getLosers())
data.put(loser.getUniqueId(), false);
for (Player winner : game.getWinners())
data.put(winner.getUniqueId(), true);
Bukkit.getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
@Override
public void run()
{
getArcadeRepository().saveLeaderboardStats(0, type.ordinal(), data);
}
});
}
}
public boolean isYoutuber(Player player)
{
return _youtube.contains(player);
}
public void setYoutuber(Player caller)
{
if (_youtube.remove(caller))
{
UtilPlayer.message(caller, C.cRed + C.Bold + "YouTube Mode Disabled: " + ChatColor.RESET + "Kits Locked");
}
else
{
_youtube.add(caller);
UtilPlayer.message(caller, C.cGreen + C.Bold + "YouTube Mode Enabled: " + ChatColor.RESET + "All Kits Unlocked");
}
}
@EventHandler
public void quitYoutuber(PlayerQuitEvent event)
{
_youtube.remove(event.getPlayer());
}
2014-11-08 00:28:06 +01:00
public IdleManager getIdleManager()
{
return _idleManager;
}
public void rewardPet(Player player, String pet, EntityType type)
{
2014-12-15 05:49:52 +01:00
if (!player.isOnline())
return;
PetReward reward = new PetReward(_petManager, _inventoryManager, _donationManager, pet, pet, type, RewardRarity.OTHER, 0);
if (reward.canGiveReward(player))
reward.giveReward(null, player);
}
2014-12-23 01:39:03 +01:00
public void toggleChampionsModules(GameType gameType)
{
2014-12-23 01:39:03 +01:00
boolean isChamps = gameType == GameType.ChampionsDominate || gameType == GameType.ChampionsTDM || gameType == GameType.ChampionsMOBA;
if (_enabled == isChamps)
{
2014-12-23 01:39:03 +01:00
System.out.println("----------Champions Modules are still " + isChamps);
return;
}
2014-12-23 01:39:03 +01:00
System.out.println("----------Champions Modules set to " + isChamps);
_enabled = isChamps;
if (_enabled)
{
_classManager.setEnabled(true);
_classShopManager.RegisterSelf();
_skillFactory.RegisterSelf();
_itemFactory.RegisterSelf();
_energy.RegisterSelf();
_eloManager.RegisterSelf();
//Class Shop
2014-12-23 01:39:03 +01:00
_plugin.getServer().getPluginManager().registerEvents(_classShop, _plugin);
}
else
{
_classManager.setEnabled(false);
_classShopManager.DeregisterSelf();
_skillFactory.DeregisterSelf();
_itemFactory.DeregisterSelf();
_energy.DeregisterSelf();
_eloManager.DeregisterSelf();
//Class Shop
2014-12-23 01:39:03 +01:00
HandlerList.unregisterAll(_classShop);
}
}
2013-08-27 17:14:08 +02:00
}