TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java

269 lines
9.3 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import me.totalfreedom.totalfreedommod.admin.AdminList;
import me.totalfreedom.totalfreedommod.banning.BanManager;
import me.totalfreedom.totalfreedommod.banning.PermbanList;
import me.totalfreedom.totalfreedommod.blocking.BlockBlocker;
import me.totalfreedom.totalfreedommod.blocking.EventBlocker;
import me.totalfreedom.totalfreedommod.blocking.InteractBlocker;
import me.totalfreedom.totalfreedommod.blocking.MobBlocker;
import me.totalfreedom.totalfreedommod.blocking.command.CommandBlocker;
import me.totalfreedom.totalfreedommod.bridge.BukkitTelnetBridge;
import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge;
import me.totalfreedom.totalfreedommod.bridge.WorldEditBridge;
import me.totalfreedom.totalfreedommod.caging.Cager;
import me.totalfreedom.totalfreedommod.command.CommandLoader;
import me.totalfreedom.totalfreedommod.freeze.Freezer;
import me.totalfreedom.totalfreedommod.fun.ItemFun;
import me.totalfreedom.totalfreedommod.fun.Jumppads;
import me.totalfreedom.totalfreedommod.fun.Landminer;
import me.totalfreedom.totalfreedommod.fun.MP44;
import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon;
import me.totalfreedom.totalfreedommod.player.PlayerList;
import me.totalfreedom.totalfreedommod.rank.RankManager;
import me.totalfreedom.totalfreedommod.rollback.RollbackManager;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import me.totalfreedom.totalfreedommod.world.WorldManager;
import net.pravian.aero.component.service.ServiceManager;
import net.pravian.aero.plugin.AeroPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.mcstats.Metrics;
public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
{
public static final String CONFIG_FILENAME = "config.yml";
//
public static final BuildProperties build = new BuildProperties();
//
@SuppressWarnings("FieldNameHidesFieldInSuperclass")
public static TotalFreedomMod plugin;
public static String pluginName;
public static String pluginVersion;
//
// Services
public ServiceManager<TotalFreedomMod> services;
public ServerInterface si;
public WorldManager wm;
public AdminList al;
public EventBlocker eb;
public BlockBlocker bb;
public MobBlocker mb;
public InteractBlocker ib;
public LoginProcess lp;
public AntiNuke nu;
public AntiSpam as;
public RankManager rm;
public PlayerList pl;
public CommandLoader cl;
public CommandBlocker cb;
public Announcer an;
public ChatManager cm;
public BanManager bm;
public PermbanList pb;
public ProtectArea pa;
public ServiceChecker sc;
public GameRuleHandler gr;
public RollbackManager rb;
public CommandSpy cs;
public Cager ca;
public Freezer fm;
public Orbiter or;
public Muter mu;
public Fuckoff fo;
public AutoKick ak;
public MovementValidator mv;
public EntityWiper ew;
public FrontDoor fd;
public ServerPing sp;
public ItemFun it;
public Landminer lm;
public MP44 mp;
public Jumppads jp;
public HTTPDaemon hd;
//
// Bridges
public ServiceManager<TotalFreedomMod> bridges;
public BukkitTelnetBridge btb;
public EssentialsBridge esb;
public WorldEditBridge web;
@Override
public void load()
{
TotalFreedomMod.plugin = this;
TotalFreedomMod.pluginName = plugin.getDescription().getName();
TotalFreedomMod.pluginVersion = plugin.getDescription().getVersion();
FLog.setPluginLogger(plugin.getLogger());
FLog.setServerLogger(server.getLogger());
build.load();
}
@Override
public void enable()
{
TotalFreedomMod.plugin = this;
FLog.info("Created by Madgeek1450 and Prozza");
FLog.info("Version " + build.formattedVersion());
FLog.info("Compiled " + build.date + " by " + build.author);
final FUtil.MethodTimer timer = new FUtil.MethodTimer();
timer.start();
// Warn if we're running on a wrong version
ServerInterface.warnVersion();
// Delete unused files
FUtil.deleteCoreDumps();
FUtil.deleteFolder(new File("./_deleteme"));
// Convert old config files
new ConfigConverter(plugin).convert();
FUtil.createBackups(TotalFreedomMod.CONFIG_FILENAME, true);
FUtil.createBackups(AdminList.CONFIG_FILENAME);
FUtil.createBackups(PermbanList.CONFIG_FILENAME);
// Start services
services = new ServiceManager<>(plugin);
si = services.registerService(ServerInterface.class);
wm = services.registerService(WorldManager.class);
al = services.registerService(AdminList.class);
eb = services.registerService(EventBlocker.class);
bb = services.registerService(BlockBlocker.class);
mb = services.registerService(MobBlocker.class);
ib = services.registerService(InteractBlocker.class);
lp = services.registerService(LoginProcess.class);
nu = services.registerService(AntiNuke.class);
as = services.registerService(AntiSpam.class);
rm = services.registerService(RankManager.class);
pl = services.registerService(PlayerList.class);
cl = services.registerService(CommandLoader.class);
cb = services.registerService(CommandBlocker.class);
an = services.registerService(Announcer.class);
cm = services.registerService(ChatManager.class);
bm = services.registerService(BanManager.class);
pb = services.registerService(PermbanList.class);
pa = services.registerService(ProtectArea.class);
sc = services.registerService(ServiceChecker.class);
gr = services.registerService(GameRuleHandler.class);
// Single admin utils
rb = services.registerService(RollbackManager.class);
cs = services.registerService(CommandSpy.class);
ca = services.registerService(Cager.class);
fm = services.registerService(Freezer.class);
or = services.registerService(Orbiter.class);
mu = services.registerService(Muter.class);
fo = services.registerService(Fuckoff.class);
ak = services.registerService(AutoKick.class);
mv = services.registerService(MovementValidator.class);
ew = services.registerService(EntityWiper.class);
fd = services.registerService(FrontDoor.class);
sp = services.registerService(ServerPing.class);
// Fun
it = services.registerService(ItemFun.class);
lm = services.registerService(Landminer.class);
mp = services.registerService(MP44.class);
jp = services.registerService(Jumppads.class);
// HTTPD
hd = services.registerService(HTTPDaemon.class);
services.start();
// Start bridges
bridges = new ServiceManager<>(plugin);
btb = bridges.registerService(BukkitTelnetBridge.class);
esb = bridges.registerService(EssentialsBridge.class);
web = bridges.registerService(WorldEditBridge.class);
bridges.start();
timer.update();
FLog.info("Version " + pluginVersion + " for " + ServerInterface.COMPILE_NMS_VERSION + " enabled in " + timer.getTotal() + "ms");
// Metrics @ http://mcstats.org/plugin/TotalFreedomMod
try
{
final Metrics metrics = new Metrics(plugin);
metrics.start();
}
catch (IOException ex)
{
FLog.warning("Failed to submit metrics data: " + ex.getMessage());
}
// Add spawnpoints later - https://github.com/TotalFreedom/TotalFreedomMod/issues/438
new BukkitRunnable()
{
@Override
public void run()
{
plugin.pa.autoAddSpawnpoints();
}
}.runTaskLater(plugin, 60L);
}
@Override
public void disable()
{
// Stop services and bridges
bridges.stop();
services.stop();
server.getScheduler().cancelTasks(plugin);
FLog.info("Plugin disabled");
TotalFreedomMod.plugin = null;
}
public static class BuildProperties
{
public String author;
public String version;
public String number;
public String date;
public String head;
public void load()
{
try
{
final InputStream in = plugin.getResource("build.properties");
final Properties props = new Properties();
props.load(in);
in.close();
author = props.getProperty("program.build.author", "unknown");
version = props.getProperty("program.build.version", "unknown");
number = props.getProperty("program.build.number", "1");
date = props.getProperty("program.build.date", "unknown");
head = props.getProperty("program.build.head", "unknown");
}
catch (Exception ex)
{
FLog.severe("Could not load build properties! Did you compile with Netbeans/ANT?");
FLog.severe(ex);
}
}
public String formattedVersion()
{
return pluginVersion + "." + number + " (" + head + ")";
}
}
}