2011-09-20 02:52:08 +00:00
|
|
|
package me.StevenLawson.TotalFreedomMod;
|
|
|
|
|
2014-04-21 17:00:39 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandHandler;
|
2014-04-11 15:24:44 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.World.TFM_Flatlands;
|
|
|
|
import me.StevenLawson.TotalFreedomMod.World.TFM_AdminWorld;
|
|
|
|
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
2011-09-26 15:26:52 +00:00
|
|
|
import java.io.File;
|
2012-12-06 11:01:51 +00:00
|
|
|
import java.io.IOException;
|
2012-03-09 19:01:04 +00:00
|
|
|
import java.io.InputStream;
|
2013-12-17 15:24:56 +00:00
|
|
|
import java.util.Date;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Properties;
|
2013-04-10 02:05:24 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
|
2013-08-27 01:48:04 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.HTTPD.TFM_HTTPD_Manager;
|
2013-07-30 01:09:20 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.Listener.*;
|
2012-03-06 19:25:22 +00:00
|
|
|
import org.bukkit.Server;
|
2012-09-20 03:17:10 +00:00
|
|
|
import org.bukkit.World;
|
2011-10-19 00:37:00 +00:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2011-10-13 23:07:52 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2011-09-23 03:22:10 +00:00
|
|
|
import org.bukkit.plugin.PluginManager;
|
2011-09-20 02:52:08 +00:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
2013-07-27 21:49:25 +00:00
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
import org.bukkit.scheduler.BukkitTask;
|
2012-12-08 01:01:52 +00:00
|
|
|
import org.mcstats.Metrics;
|
2011-09-20 02:52:08 +00:00
|
|
|
|
|
|
|
public class TotalFreedomMod extends JavaPlugin
|
|
|
|
{
|
2014-05-11 16:15:04 +00:00
|
|
|
public static final long HEARTBEAT_RATE = 5L; // Seconds
|
2013-08-09 15:08:16 +00:00
|
|
|
public static final long SERVICE_CHECKER_RATE = 120L;
|
2013-07-11 01:46:29 +00:00
|
|
|
//
|
2011-10-19 02:52:32 +00:00
|
|
|
public static final String SUPERADMIN_FILE = "superadmin.yml";
|
2012-09-18 14:40:48 +00:00
|
|
|
public static final String PERMBAN_FILE = "permban.yml";
|
2012-11-03 19:03:38 +00:00
|
|
|
public static final String PROTECTED_AREA_FILE = "protectedareas.dat";
|
2012-11-05 03:44:24 +00:00
|
|
|
public static final String SAVED_FLAGS_FILE = "savedflags.dat";
|
2013-07-11 01:46:29 +00:00
|
|
|
//
|
2014-04-21 12:37:53 +00:00
|
|
|
public static String buildNumber = "1";
|
|
|
|
public static String buildDate = TotalFreedomMod.buildDate = TFM_Util.dateToString(new Date());
|
|
|
|
public static String buildCreator = "Unknown";
|
2013-08-20 15:35:00 +00:00
|
|
|
//
|
2014-04-21 12:37:53 +00:00
|
|
|
public static Server server;
|
|
|
|
public static TotalFreedomMod plugin;
|
|
|
|
public static String pluginName;
|
|
|
|
public static String pluginVersion;
|
2013-08-20 15:35:00 +00:00
|
|
|
//
|
2011-11-08 00:29:33 +00:00
|
|
|
public static boolean allPlayersFrozen = false;
|
2013-07-27 21:49:25 +00:00
|
|
|
public static BukkitTask freezePurgeTask = null;
|
|
|
|
public static BukkitTask mutePurgeTask = null;
|
2013-08-12 18:47:36 +00:00
|
|
|
public static boolean lockdownEnabled = false;
|
2011-11-28 22:44:51 +00:00
|
|
|
public static Map<Player, Double> fuckoffEnabledFor = new HashMap<Player, Double>();
|
2012-09-14 22:49:44 +00:00
|
|
|
|
2011-10-02 16:15:16 +00:00
|
|
|
@Override
|
2013-08-21 21:42:21 +00:00
|
|
|
public void onLoad()
|
2011-10-02 16:15:16 +00:00
|
|
|
{
|
2012-09-14 22:49:44 +00:00
|
|
|
TotalFreedomMod.plugin = this;
|
2013-12-07 09:58:29 +00:00
|
|
|
TotalFreedomMod.server = plugin.getServer();
|
2013-08-20 15:35:00 +00:00
|
|
|
TotalFreedomMod.pluginName = plugin.getDescription().getName();
|
2013-11-30 17:04:43 +00:00
|
|
|
TotalFreedomMod.pluginVersion = plugin.getDescription().getVersion();
|
2013-08-21 00:04:06 +00:00
|
|
|
|
2013-11-30 17:04:43 +00:00
|
|
|
TFM_Log.setPluginLogger(plugin.getLogger());
|
|
|
|
TFM_Log.setServerLogger(server.getLogger());
|
2013-08-21 21:42:21 +00:00
|
|
|
|
2012-03-09 19:01:04 +00:00
|
|
|
setAppProperties();
|
2013-08-21 21:42:21 +00:00
|
|
|
}
|
2013-08-21 00:04:06 +00:00
|
|
|
|
2013-08-21 21:42:21 +00:00
|
|
|
@Override
|
|
|
|
public void onEnable()
|
|
|
|
{
|
2014-04-23 14:23:50 +00:00
|
|
|
TFM_Log.info("Made by Madgeek1450 and DarthSalamon");
|
|
|
|
TFM_Log.info("Compiled " + buildDate + " by " + buildCreator);
|
2012-09-18 21:25:37 +00:00
|
|
|
|
2014-05-04 22:01:57 +00:00
|
|
|
TFM_Util.deleteCoreDumps();
|
2014-04-21 21:09:10 +00:00
|
|
|
|
2014-05-04 22:01:57 +00:00
|
|
|
if (!TFM_ServerInterface.COMPILE_NMS_VERSION.equals(TFM_Util.getNmsVersion()))
|
2014-04-21 21:09:10 +00:00
|
|
|
{
|
2014-05-04 22:01:57 +00:00
|
|
|
TFM_Log.warning(pluginName + " is compiled for " + TFM_ServerInterface.COMPILE_NMS_VERSION + " but the server is running "
|
|
|
|
+ "version " + TFM_Util.getNmsVersion() + "!");
|
|
|
|
TFM_Log.warning("This might result in unexpected behaviour!");
|
2014-04-21 21:09:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Admin list
|
2014-05-11 16:41:58 +00:00
|
|
|
TFM_Util.createBackups(SUPERADMIN_FILE);
|
2014-04-21 17:00:39 +00:00
|
|
|
TFM_AdminList.load();
|
|
|
|
|
2014-04-21 21:09:10 +00:00
|
|
|
// Permban list
|
2014-05-11 16:41:58 +00:00
|
|
|
TFM_Util.createBackups(PERMBAN_FILE);
|
2014-04-21 21:09:10 +00:00
|
|
|
TFM_PermbanList.load();
|
2011-10-30 19:27:06 +00:00
|
|
|
|
2014-04-21 21:09:10 +00:00
|
|
|
// Playerlist and bans
|
2014-05-19 17:32:25 +00:00
|
|
|
TFM_PlayerList.load();
|
|
|
|
TFM_BanManager.load();
|
2012-03-09 19:01:04 +00:00
|
|
|
|
2014-04-21 21:09:10 +00:00
|
|
|
TFM_Util.deleteFolder(new File("./_deleteme"));
|
|
|
|
|
|
|
|
final PluginManager pm = server.getPluginManager();
|
|
|
|
pm.registerEvents(new TFM_EntityListener(), plugin);
|
|
|
|
pm.registerEvents(new TFM_BlockListener(), plugin);
|
|
|
|
pm.registerEvents(new TFM_PlayerListener(), plugin);
|
|
|
|
pm.registerEvents(new TFM_WeatherListener(), plugin);
|
|
|
|
pm.registerEvents(new TFM_ServerListener(), plugin);
|
|
|
|
pm.registerEvents(new TFM_TelnetListener(), plugin);
|
2011-10-30 19:27:06 +00:00
|
|
|
|
2013-08-22 00:07:14 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
TFM_Flatlands.getInstance().getWorld();
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
2012-03-06 19:25:22 +00:00
|
|
|
{
|
|
|
|
}
|
2012-09-20 03:17:10 +00:00
|
|
|
|
2013-08-22 00:07:14 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
TFM_AdminWorld.getInstance().getWorld();
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
}
|
2013-08-12 16:38:46 +00:00
|
|
|
|
2013-07-30 01:09:20 +00:00
|
|
|
// Initialize game rules
|
2013-08-18 19:27:17 +00:00
|
|
|
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_DAYLIGHT_CYCLE, !TFM_ConfigEntry.DISABLE_NIGHT.getBoolean(), false);
|
2013-08-18 18:52:46 +00:00
|
|
|
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_FIRE_TICK, TFM_ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean(), false);
|
2013-07-30 01:09:20 +00:00
|
|
|
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_MOB_LOOT, false, false);
|
2013-08-18 19:27:17 +00:00
|
|
|
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_MOB_SPAWNING, !TFM_ConfigEntry.MOB_LIMITER_ENABLED.getBoolean(), false);
|
2013-07-30 01:09:20 +00:00
|
|
|
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_TILE_DROPS, false, false);
|
|
|
|
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.MOB_GRIEFING, false, false);
|
|
|
|
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.NATURAL_REGENERATION, true, false);
|
|
|
|
TFM_GameRuleHandler.commitGameRules();
|
|
|
|
|
2014-04-21 21:09:10 +00:00
|
|
|
if (TFM_ConfigEntry.DISABLE_WEATHER.getBoolean())
|
2013-07-27 21:49:25 +00:00
|
|
|
{
|
2014-04-21 21:09:10 +00:00
|
|
|
for (World world : server.getWorlds())
|
2013-07-27 21:49:25 +00:00
|
|
|
{
|
2014-04-21 21:09:10 +00:00
|
|
|
world.setThundering(false);
|
|
|
|
world.setStorm(false);
|
|
|
|
world.setThunderDuration(0);
|
|
|
|
world.setWeatherDuration(0);
|
2013-07-27 21:49:25 +00:00
|
|
|
}
|
2014-04-21 21:09:10 +00:00
|
|
|
}
|
2013-07-27 21:49:25 +00:00
|
|
|
|
2014-05-16 13:30:02 +00:00
|
|
|
if (TFM_ConfigEntry.PROTECTAREA_ENABLED.getBoolean())
|
2013-07-27 21:49:25 +00:00
|
|
|
{
|
2014-04-21 21:09:10 +00:00
|
|
|
TFM_ProtectedArea.loadProtectedAreas();
|
|
|
|
TFM_ProtectedArea.autoAddSpawnpoints();
|
2013-07-27 21:49:25 +00:00
|
|
|
}
|
|
|
|
|
2013-07-01 08:04:43 +00:00
|
|
|
// Heartbeat
|
2013-08-20 15:35:00 +00:00
|
|
|
new TFM_Heartbeat(plugin).runTaskTimer(plugin, HEARTBEAT_RATE * 20L, HEARTBEAT_RATE * 20L);
|
2012-12-02 17:05:54 +00:00
|
|
|
|
2012-12-06 11:01:51 +00:00
|
|
|
// metrics @ http://mcstats.org/plugin/TotalFreedomMod
|
2012-12-08 01:01:52 +00:00
|
|
|
try
|
|
|
|
{
|
2014-04-21 21:09:10 +00:00
|
|
|
final Metrics metrics = new Metrics(plugin);
|
2012-12-06 11:01:51 +00:00
|
|
|
metrics.start();
|
2012-12-08 01:01:52 +00:00
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (IOException ex)
|
2012-12-08 01:01:52 +00:00
|
|
|
{
|
2013-08-14 13:28:19 +00:00
|
|
|
TFM_Log.warning("Failed to submit metrics data: " + ex.getMessage());
|
2012-12-06 11:01:51 +00:00
|
|
|
}
|
|
|
|
|
2014-05-19 17:32:25 +00:00
|
|
|
TFM_ServiceChecker.start();
|
|
|
|
TFM_HTTPD_Manager.start();
|
|
|
|
TFM_FrontDoor.start();
|
2013-09-05 14:48:57 +00:00
|
|
|
|
2014-05-04 22:01:57 +00:00
|
|
|
TFM_Log.info("Version " + pluginVersion + " for " + TFM_ServerInterface.COMPILE_NMS_VERSION + " enabled");
|
2013-09-05 14:48:57 +00:00
|
|
|
|
2014-04-21 21:09:10 +00:00
|
|
|
// Delayed Start:
|
2013-07-27 21:49:25 +00:00
|
|
|
new BukkitRunnable()
|
2013-07-20 20:06:46 +00:00
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
2014-05-19 17:32:25 +00:00
|
|
|
TFM_CommandLoader.scan();
|
|
|
|
TFM_CommandBlocker.load();
|
2013-07-20 20:06:46 +00:00
|
|
|
}
|
2013-08-20 15:35:00 +00:00
|
|
|
}.runTaskLater(plugin, 20L);
|
2011-10-02 16:15:16 +00:00
|
|
|
}
|
2011-09-26 15:26:52 +00:00
|
|
|
|
2011-10-02 16:15:16 +00:00
|
|
|
@Override
|
|
|
|
public void onDisable()
|
|
|
|
{
|
2013-08-20 15:35:00 +00:00
|
|
|
server.getScheduler().cancelTasks(plugin);
|
2013-08-21 00:04:06 +00:00
|
|
|
|
2014-05-19 17:32:25 +00:00
|
|
|
TFM_HTTPD_Manager.stop();
|
|
|
|
TFM_BanManager.save();
|
2013-08-27 00:39:30 +00:00
|
|
|
|
2013-11-30 17:04:43 +00:00
|
|
|
TFM_Log.info("Plugin disabled");
|
2011-10-12 22:45:43 +00:00
|
|
|
}
|
2011-10-19 00:37:00 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
|
|
|
|
{
|
2014-04-21 17:00:39 +00:00
|
|
|
return TFM_CommandHandler.handleCommand(sender, cmd, commandLabel, args);
|
2012-09-18 14:40:48 +00:00
|
|
|
}
|
2012-09-18 21:25:37 +00:00
|
|
|
|
2012-12-02 17:05:54 +00:00
|
|
|
private static void setAppProperties()
|
2012-03-09 19:01:04 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-04-21 12:37:53 +00:00
|
|
|
final InputStream in = plugin.getResource("appinfo.properties");
|
2012-03-09 19:01:04 +00:00
|
|
|
Properties props = new Properties();
|
|
|
|
|
2013-08-20 15:35:00 +00:00
|
|
|
// in = plugin.getClass().getResourceAsStream("/appinfo.properties");
|
2012-03-09 19:01:04 +00:00
|
|
|
props.load(in);
|
|
|
|
in.close();
|
|
|
|
|
2013-11-30 17:04:43 +00:00
|
|
|
TotalFreedomMod.buildNumber = props.getProperty("program.buildnumber");
|
|
|
|
TotalFreedomMod.buildDate = props.getProperty("program.builddate");
|
2014-04-21 12:37:53 +00:00
|
|
|
TotalFreedomMod.buildCreator = props.getProperty("program.buildcreator");
|
2012-03-09 19:01:04 +00:00
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (Exception ex)
|
2012-03-09 19:01:04 +00:00
|
|
|
{
|
2013-08-20 15:35:00 +00:00
|
|
|
TFM_Log.severe("Could not load App properties!");
|
2013-08-14 13:28:19 +00:00
|
|
|
TFM_Log.severe(ex);
|
2012-03-09 19:01:04 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-20 02:52:08 +00:00
|
|
|
}
|