package nautilus.game.arcade; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.InputStreamReader; import mineplex.core.CustomTagFix; import mineplex.core.account.CoreClientManager; import mineplex.core.antihack.AntiHack; import mineplex.core.antistack.AntiStack; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.blood.Blood; import mineplex.core.command.CommandCenter; import mineplex.core.common.util.*; import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.creature.Creature; import mineplex.core.disguise.DisguiseManager; import mineplex.core.donation.DonationManager; import mineplex.core.gadget.GadgetManager; import mineplex.core.inventory.InventoryManager; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.logger.Logger; import mineplex.core.memory.MemoryFix; import mineplex.core.message.MessageManager; import mineplex.core.monitor.LagMeter; import mineplex.core.mount.MountManager; import mineplex.core.npc.NpcManager; import mineplex.core.packethandler.PacketHandler; import mineplex.core.pet.PetManager; import mineplex.core.playerTracker.PlayerTracker; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; import mineplex.core.projectile.ProjectileManager; import mineplex.core.punish.Punish; import mineplex.core.recharge.Recharge; import mineplex.core.spawn.Spawn; import mineplex.core.status.ServerStatusManager; import mineplex.core.teleport.Teleport; import mineplex.core.updater.FileUpdater; import mineplex.core.updater.Updater; import mineplex.minecraft.game.core.combat.CombatManager; import mineplex.minecraft.game.core.damage.DamageManager; import nautilus.game.arcade.game.GameServerConfig; import net.minecraft.server.v1_7_R4.MinecraftServer; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; public class Arcade extends JavaPlugin { private String WEB_CONFIG = "webServer"; //Modules private CoreClientManager _clientManager; private DonationManager _donationManager; private DamageManager _damageManager; private ArcadeManager _gameManager; @Override public void onEnable() { //Delete Old Games Folders DeleteFolders(); //Configs getConfig().addDefault(WEB_CONFIG, "http://accounts.mineplex.com/"); getConfig().set(WEB_CONFIG, getConfig().getString(WEB_CONFIG)); saveConfig(); String webServerAddress = getConfig().getString(WEB_CONFIG); Logger.initialize(this); //Static Modules CommandCenter.Initialize(this); _clientManager = new CoreClientManager(this, webServerAddress); CommandCenter.Instance.setClientManager(_clientManager); ItemStackFactory.Initialize(this, false); Recharge.Initialize(this); _donationManager = new DonationManager(this, webServerAddress); PreferencesManager preferenceManager = new PreferencesManager(this, _clientManager, _donationManager); new MessageManager(this, _clientManager, preferenceManager); AntiStack antistack = new AntiStack(this); Creature creature = new Creature(this); Spawn spawn = new Spawn(this); Teleport teleport = new Teleport(this, _clientManager, spawn); ServerStatusManager serverStatusManager = new ServerStatusManager(this, new LagMeter(this, _clientManager)); Portal portal = new Portal(this, serverStatusManager.getCurrentServerName()); new FileUpdater(this, portal); DisguiseManager disguiseManager = new DisguiseManager(this); _damageManager = new DamageManager(this, new CombatManager(this), new NpcManager(this, creature), disguiseManager); Punish punish = new Punish(this, webServerAddress, _clientManager); AntiHack.Initialize(this, punish, portal); BlockRestore blockRestore = new BlockRestore(this); ProjectileManager projectileManager = new ProjectileManager(this); //Inventory InventoryManager inventoryManager = new InventoryManager(this); PetManager petManager = new PetManager(this, _clientManager, _donationManager, creature, webServerAddress); MountManager mountManager = new MountManager(this, _clientManager, _donationManager, blockRestore, disguiseManager); GadgetManager gadgetManager = new GadgetManager(this, _clientManager, _donationManager, inventoryManager, mountManager, petManager, preferenceManager, disguiseManager, blockRestore, projectileManager); CosmeticManager cosmeticManager = new CosmeticManager(this, _clientManager, _donationManager, inventoryManager, gadgetManager, mountManager, petManager, true); cosmeticManager.setInterfaceSlot(7); new CustomTagFix(this); new PacketHandler(this); //Arcade Manager _gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, disguiseManager, creature, teleport, new Blood(this), antistack, portal, preferenceManager, inventoryManager, cosmeticManager, projectileManager, webServerAddress); new PlayerTracker(this, serverStatusManager.getCurrentServerName(), serverStatusManager.getUs()); new MemoryFix(this); //Updates getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1); MinecraftServer.getServer().getPropertyManager().setProperty("debug", true); } @Override public void onDisable() { for (Player player : UtilServer.getPlayers()) player.kickPlayer("Server Shutdown"); if (_gameManager.GetGame() != null) if (_gameManager.GetGame().WorldData != null) _gameManager.GetGame().WorldData.Uninitialize(); } public GameServerConfig ReadServerConfig() { GameServerConfig config = new GameServerConfig(); //Load Track Data String line = null; try { File file = new File("ArcadeSettings.config"); if (!file.exists()) WriteServerConfig(GetDefaultConfig()); FileInputStream fstream = new FileInputStream("ArcadeSettings.config"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); while ((line = br.readLine()) != null) { String[] tokens = line.split("="); if (tokens.length < 2) continue; if (tokens[0].equals("SERVER_TYPE")) { config.ServerType = tokens[1]; } else if (tokens[0].equals("PLAYERS_MIN")) { config.MinPlayers = Integer.parseInt(tokens[1]); } else if (tokens[0].equals("PLAYERS_MAX")) { config.MaxPlayers = Integer.parseInt(tokens[1]); } else if (tokens[0].equals("TOURNAMENT")) { config.Tournament = Boolean.parseBoolean(tokens[1]); } else if (tokens[0].equals("TEAM_REJOIN")) { config.TeamRejoin = Boolean.parseBoolean(tokens[1]); } else if (tokens[0].equals("TEAM_AUTO_JOIN")) { config.TeamAutoJoin = Boolean.parseBoolean(tokens[1]); } else if (tokens[0].equals("TEAM_FORCE_BALANCE")) { config.TeamForceBalance = Boolean.parseBoolean(tokens[1]); } else if (tokens[0].equals("GAME_AUTO_START")) { config.GameAutoStart = Boolean.parseBoolean(tokens[1]); } else if (tokens[0].equals("GAME_TIMEOUT")) { config.GameTimeout = Boolean.parseBoolean(tokens[1]); } else if (tokens[0].equals("REWARD_GEMS")) { config.RewardGems = Boolean.parseBoolean(tokens[1]); } else if (tokens[0].equals("REWARD_ITEMS")) { config.RewardItems = Boolean.parseBoolean(tokens[1]); } else if (tokens[0].equals("REWARD_STATS")) { config.RewardStats = Boolean.parseBoolean(tokens[1]); } else if (tokens[0].equals("REWARD_ACHIEVEMENTS")) { config.RewardAchievements = Boolean.parseBoolean(tokens[1]); } else if (tokens[0].equals("HOTBAR_INVENTORY")) { config.HotbarInventory = Boolean.parseBoolean(tokens[1]); } else if (tokens[0].equals("HOTBAR_HUB_CLOCK")) { config.HotbarHubClock = Boolean.parseBoolean(tokens[1]); } else if (tokens[0].equals("PLAYER_KICK_IDLE")) { config.PlayerKickIdle = Boolean.parseBoolean(tokens[1]); } //Games else { try { GameType type = GameType.valueOf(tokens[0]); boolean enabled = Boolean.valueOf(tokens[1]); if (enabled) config.GameList.add(type); } catch (Exception e) { } } } in.close(); } catch (Exception e) { } if (!config.IsValid()) config = GetDefaultConfig(); WriteServerConfig(config); return config; } public GameServerConfig GetDefaultConfig() { GameServerConfig config = new GameServerConfig(); config.ServerType = "Minigames"; config.MinPlayers = 8; config.MaxPlayers = 16; config.Tournament = false; return config; } public void WriteServerConfig(GameServerConfig config) { try { FileWriter fstream = new FileWriter("ArcadeSettings.config"); BufferedWriter out = new BufferedWriter(fstream); out.write("SERVER_TYPE=" + config.ServerType + "\n"); out.write("PLAYERS_MIN=" + config.MinPlayers + "\n"); out.write("PLAYERS_MAX=" + config.MaxPlayers + "\n"); out.write("\nTOURNAMENT=" + config.Tournament + "\n"); out.write("\nTEAM_REJOIN=" + config.TeamRejoin + "\n"); out.write("TEAM_AUTO_JOIN=" + config.TeamAutoJoin + "\n"); out.write("TEAM_FORCE_BALANCE=" + config.TeamForceBalance + "\n"); out.write("\nGAME_AUTO_START=" + config.GameAutoStart + "\n"); out.write("GAME_TIMEOUT=" + config.GameTimeout + "\n"); out.write("\nREWARD_GEMS=" + config.RewardGems + "\n"); out.write("REWARD_ITEMS=" + config.RewardItems + "\n"); out.write("REWARD_STATS=" + config.RewardStats + "\n"); out.write("REWARD_ACHIEVEMENTS=" + config.RewardAchievements + "\n"); out.write("\nHOTBAR_INVENTORY=" + config.HotbarInventory + "\n"); out.write("HOTBAR_HUB_CLOCK=" + config.HotbarHubClock + "\n"); out.write("\nPLAYER_KICK_IDLE=" + config.PlayerKickIdle + "\n"); out.write("\n\nGames List;\n"); for (GameType type : GameType.values()) { out.write(type.toString() + "=" + config.GameList.contains(type) + "\n"); } out.close(); } catch (Exception e) { } } private void DeleteFolders() { File curDir = new File("."); File[] filesList = curDir.listFiles(); for(File file : filesList) { if (!file.isDirectory()) continue; if (file.getName().length() < 4) continue; if (!file.getName().substring(0, 4).equalsIgnoreCase("Game")) continue; FileUtil.DeleteFolder(file); System.out.println("Deleted Old Game: " + file.getName()); } } }