2013-08-27 17:14:08 +02:00
|
|
|
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 me.chiss.Core.Config.Config;
|
|
|
|
import mineplex.core.account.CoreClientManager;
|
2013-10-16 03:23:23 +02:00
|
|
|
import mineplex.core.antihack.AntiHack;
|
2013-08-31 05:15:16 +02:00
|
|
|
import mineplex.core.antistack.AntiStack;
|
2013-08-27 17:14:08 +02:00
|
|
|
import mineplex.core.blockrestore.BlockRestore;
|
|
|
|
import mineplex.core.command.CommandCenter;
|
2013-10-30 23:45:11 +01:00
|
|
|
import mineplex.core.common.Rank;
|
2013-08-27 17:14:08 +02:00
|
|
|
import mineplex.core.common.util.FileUtil;
|
|
|
|
import mineplex.core.common.util.UtilServer;
|
|
|
|
import mineplex.core.creature.Creature;
|
2013-08-31 05:15:16 +02:00
|
|
|
import mineplex.core.disguise.DisguiseManager;
|
2013-08-27 17:14:08 +02:00
|
|
|
import mineplex.core.donation.DonationManager;
|
|
|
|
import mineplex.core.energy.Energy;
|
|
|
|
import mineplex.core.itemstack.ItemStackFactory;
|
|
|
|
import me.chiss.Core.Loot.LootFactory;
|
2013-10-14 06:51:38 +02:00
|
|
|
import me.chiss.Core.MemoryFix.MemoryFix;
|
2013-08-27 17:14:08 +02:00
|
|
|
import me.chiss.Core.Module.ModuleManager;
|
|
|
|
import me.chiss.Core.Modules.*;
|
|
|
|
import me.chiss.Core.Plugin.IPlugin;
|
|
|
|
import me.chiss.Core.Scheduler.Scheduler;
|
|
|
|
import mineplex.core.message.MessageManager;
|
2013-09-04 08:31:29 +02:00
|
|
|
import mineplex.core.monitor.LagMeter;
|
2013-08-27 17:14:08 +02:00
|
|
|
import mineplex.core.npc.NpcManager;
|
|
|
|
import mineplex.core.packethandler.PacketHandler;
|
|
|
|
import mineplex.core.pet.PetManager;
|
2013-09-02 13:19:56 +02:00
|
|
|
import mineplex.core.portal.Portal;
|
2013-08-27 17:14:08 +02:00
|
|
|
import mineplex.core.projectile.ProjectileManager;
|
|
|
|
import mineplex.core.punish.Punish;
|
|
|
|
import mineplex.core.recharge.Recharge;
|
|
|
|
import mineplex.core.spawn.Spawn;
|
2013-09-18 00:50:23 +02:00
|
|
|
import mineplex.core.status.ServerStatusManager;
|
2013-08-27 17:14:08 +02:00
|
|
|
import mineplex.core.teleport.Teleport;
|
2013-09-02 13:19:56 +02:00
|
|
|
import mineplex.core.updater.FileUpdater;
|
2013-08-27 17:14:08 +02:00
|
|
|
import mineplex.core.updater.Updater;
|
|
|
|
import mineplex.minecraft.game.core.combat.CombatManager;
|
|
|
|
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.game.GameServerConfig;
|
|
|
|
import nautilus.minecraft.core.INautilusPlugin;
|
|
|
|
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.plugin.PluginManager;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
|
|
|
public class Arcade extends JavaPlugin implements INautilusPlugin, IPlugin
|
|
|
|
{
|
|
|
|
private String WEB_CONFIG = "webServer";
|
|
|
|
|
|
|
|
//Modules
|
|
|
|
private ModuleManager _moduleManager;
|
|
|
|
private Config _config;
|
|
|
|
private CoreClientManager _clientManager;
|
|
|
|
private DonationManager _donationManager;
|
|
|
|
private DamageManager _damageManager;
|
2013-09-02 07:06:20 +02:00
|
|
|
private Utility _utility;
|
2013-08-27 17:14:08 +02:00
|
|
|
private BlockRegenerate _blockRegenerate;
|
|
|
|
private BlockRestore _blockRestore;
|
|
|
|
private Blood _blood;
|
|
|
|
private ConditionManager _condition;
|
|
|
|
private Creature _creature;
|
|
|
|
private Fire _fire;
|
2013-10-23 23:36:13 +02:00
|
|
|
private Logger _logger;
|
2013-08-27 17:14:08 +02:00
|
|
|
private LootFactory _lootFactory;
|
|
|
|
private Observer _observer;
|
2013-10-17 09:37:57 +02:00
|
|
|
private PetManager _petManager;
|
2013-09-02 07:06:20 +02:00
|
|
|
private me.chiss.Core.Server.Server _serverModule;
|
2013-08-27 17:14:08 +02:00
|
|
|
private Spawn _spawn;
|
|
|
|
private Teleport _teleport;
|
|
|
|
private ProjectileManager _throw;
|
|
|
|
|
|
|
|
private ArcadeManager _gameManager;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEnable()
|
|
|
|
{
|
|
|
|
//Delete Old Games Folders
|
|
|
|
DeleteFolders();
|
|
|
|
|
|
|
|
//Configs
|
|
|
|
getConfig().addDefault(WEB_CONFIG, "http://api.mineplex.com/");
|
|
|
|
getConfig().set(WEB_CONFIG, getConfig().getString(WEB_CONFIG));
|
|
|
|
saveConfig();
|
|
|
|
|
2013-10-16 03:23:23 +02:00
|
|
|
//Init Modules
|
2013-08-27 17:14:08 +02:00
|
|
|
GetModules();
|
|
|
|
|
|
|
|
_clientManager = CoreClientManager.Initialize(this, GetWebServerAddress());
|
2013-09-18 00:50:23 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
CommandCenter.Initialize(this, _clientManager);
|
2013-10-16 03:23:23 +02:00
|
|
|
|
2013-10-30 23:45:11 +01:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
ItemStackFactory.Initialize(this, false);
|
|
|
|
Recharge.Initialize(this);
|
|
|
|
|
2013-09-18 00:50:23 +02:00
|
|
|
_donationManager = new DonationManager(this, GetWebServerAddress());
|
2013-08-27 17:14:08 +02:00
|
|
|
ConditionManager conditionManager = new ConditionManager(this);
|
2013-08-31 05:15:16 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
new MessageManager(this, _clientManager);
|
|
|
|
|
2013-09-13 04:24:33 +02:00
|
|
|
AntiStack antistack = new AntiStack(this);
|
2013-08-31 05:15:16 +02:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
GetCreature();
|
2013-10-30 23:45:11 +01:00
|
|
|
GetSpawn();
|
2013-08-27 17:14:08 +02:00
|
|
|
GetTeleport();
|
2013-09-02 13:19:56 +02:00
|
|
|
new FileUpdater(this, new Portal(this));
|
2013-09-18 00:50:23 +02:00
|
|
|
new ServerStatusManager(this, new LagMeter(this, _clientManager));
|
2013-08-31 05:15:16 +02:00
|
|
|
|
2013-09-02 07:06:20 +02:00
|
|
|
PacketHandler packetHandler = new PacketHandler(this);
|
|
|
|
DisguiseManager disguiseManager = new DisguiseManager(this, packetHandler);
|
2013-08-27 17:14:08 +02:00
|
|
|
|
2013-08-31 05:15:16 +02:00
|
|
|
_damageManager = new DamageManager(this, new CombatManager(this), new NpcManager(this, GetCreature()), disguiseManager);
|
2013-08-27 17:14:08 +02:00
|
|
|
|
|
|
|
//Arcade Manager
|
2013-09-13 04:24:33 +02:00
|
|
|
_gameManager = new ArcadeManager(this, ReadServerConfig(), _clientManager, _donationManager, conditionManager, _damageManager, disguiseManager, GetCreature(), GetBlood(), antistack, packetHandler);
|
2013-08-27 17:14:08 +02:00
|
|
|
|
|
|
|
//Unreferenced Modules
|
|
|
|
//new AntiStack();
|
|
|
|
Scheduler.Initialize(this);
|
|
|
|
//new Information(this);
|
2013-10-30 23:45:11 +01:00
|
|
|
|
|
|
|
Punish punish = new Punish(this, GetWebServerAddress());
|
|
|
|
AntiHack.Initialize(this, punish);
|
|
|
|
|
2013-10-14 06:51:38 +02:00
|
|
|
new MemoryFix(this);
|
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
//Updates
|
|
|
|
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2013-10-30 23:45:11 +01:00
|
|
|
public void onDisable()
|
2013-08-27 17:14:08 +02:00
|
|
|
{
|
|
|
|
GetModules().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]);
|
|
|
|
}
|
|
|
|
//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;
|
|
|
|
|
|
|
|
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("\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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-10-17 09:37:57 +02:00
|
|
|
public JavaPlugin GetPlugin()
|
2013-08-27 17:14:08 +02:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String GetWebServerAddress()
|
|
|
|
{
|
|
|
|
String webServerAddress = getConfig().getString(WEB_CONFIG);
|
|
|
|
|
|
|
|
return webServerAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Server GetRealServer()
|
|
|
|
{
|
|
|
|
return getServer();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PluginManager GetPluginManager()
|
|
|
|
{
|
|
|
|
return GetRealServer().getPluginManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void Log(String moduleName, String data)
|
|
|
|
{
|
|
|
|
System.out.println(moduleName + " : " + data);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ModuleManager GetModules()
|
|
|
|
{
|
|
|
|
if (_moduleManager == null)
|
|
|
|
_moduleManager = new ModuleManager();
|
|
|
|
|
|
|
|
return _moduleManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Config GetConfig()
|
|
|
|
{
|
|
|
|
if (_config == null)
|
|
|
|
_config = new Config(this);
|
|
|
|
|
|
|
|
return _config;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Utility GetUtility()
|
|
|
|
{
|
|
|
|
if (_utility == null)
|
|
|
|
_utility = new Utility(this);
|
|
|
|
|
|
|
|
return _utility;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockRegenerate GetBlockRegenerate()
|
|
|
|
{
|
|
|
|
if (_blockRegenerate == null)
|
|
|
|
_blockRegenerate = new BlockRegenerate(this);
|
|
|
|
|
|
|
|
return _blockRegenerate;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockRestore GetBlockRestore()
|
|
|
|
{
|
|
|
|
if (_blockRestore == null)
|
|
|
|
_blockRestore = new BlockRestore(this);
|
|
|
|
|
|
|
|
return _blockRestore;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Blood GetBlood()
|
|
|
|
{
|
|
|
|
if (_blood == null)
|
|
|
|
_blood = new Blood(this);
|
|
|
|
|
|
|
|
return _blood;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Creature GetCreature()
|
|
|
|
{
|
|
|
|
if (_creature == null)
|
|
|
|
_creature = new Creature(this);
|
|
|
|
|
|
|
|
return _creature;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Fire GetFire()
|
|
|
|
{
|
|
|
|
if (_fire == null)
|
|
|
|
_fire = new Fire(this, _condition, _damageManager);
|
|
|
|
|
|
|
|
return _fire;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Logger GetLogger()
|
|
|
|
{
|
|
|
|
if (_logger == null)
|
|
|
|
_logger = new Logger(this);
|
|
|
|
|
|
|
|
return _logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public LootFactory GetLoot()
|
|
|
|
{
|
|
|
|
if (_lootFactory == null)
|
|
|
|
_lootFactory = new LootFactory(this);
|
|
|
|
|
|
|
|
return _lootFactory;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Observer GetObserver()
|
|
|
|
{
|
|
|
|
if (_observer == null)
|
|
|
|
_observer = new Observer(this);
|
|
|
|
|
|
|
|
return _observer;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public me.chiss.Core.Server.Server GetServer()
|
|
|
|
{
|
|
|
|
if (_serverModule == null)
|
|
|
|
_serverModule = new me.chiss.Core.Server.Server(this, _clientManager);
|
|
|
|
|
|
|
|
return _serverModule;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Spawn GetSpawn()
|
|
|
|
{
|
|
|
|
if (_spawn == null)
|
|
|
|
_spawn = new Spawn(this);
|
|
|
|
|
|
|
|
return _spawn;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-10-17 09:37:57 +02:00
|
|
|
public Teleport GetTeleport()
|
2013-08-27 17:14:08 +02:00
|
|
|
{
|
|
|
|
if (_teleport == null)
|
|
|
|
_teleport = new Teleport(this, _clientManager, GetSpawn());
|
|
|
|
|
|
|
|
return _teleport;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ProjectileManager GetThrow()
|
|
|
|
{
|
|
|
|
if (_throw == null)
|
|
|
|
_throw = new ProjectileManager(this);
|
|
|
|
|
|
|
|
return _throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Location GetSpawnLocation()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PetManager GetPetManager()
|
|
|
|
{
|
|
|
|
return _petManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Energy GetEnergy()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|