package me.totalfreedom.totalfreedommod; import me.totalfreedom.totalfreedommod.admin.AdminList; import me.totalfreedom.totalfreedommod.banning.BanManager; import me.totalfreedom.totalfreedommod.banning.PermbanList; import me.totalfreedom.totalfreedommod.blocking.*; import me.totalfreedom.totalfreedommod.blocking.command.CommandBlocker; import me.totalfreedom.totalfreedommod.bridge.*; import me.totalfreedom.totalfreedommod.caging.Cager; import me.totalfreedom.totalfreedommod.command.CommandLoader; import me.totalfreedom.totalfreedommod.config.MainConfig; import me.totalfreedom.totalfreedommod.discord.Discord; import me.totalfreedom.totalfreedommod.freeze.Freezer; import me.totalfreedom.totalfreedommod.fun.*; 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.util.MethodTimer; import me.totalfreedom.totalfreedommod.world.WorldManager; import net.pravian.aero.component.service.ServiceManager; import net.pravian.aero.plugin.AeroPlugin; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitRunnable; import org.mcstats.Metrics; import org.spigotmc.SpigotConfig; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.Properties; public class TotalFreedomMod extends AeroPlugin { public static final String CONFIG_FILENAME = "config.yml"; // public static final BuildProperties build = new BuildProperties(); // public static String pluginName; public static String pluginVersion; // public MainConfig config; // // Services public ServiceManager services; public ServerInterface si; public SavedFlags sf; public WorldManager wm; public LogViewer lv; public AdminList al; public RankManager rm; public CommandLoader cl; public CommandBlocker cb; public EventBlocker eb; public BlockBlocker bb; public MobBlocker mb; public InteractBlocker ib; public PotionBlocker pb; public LoginProcess lp; public AntiNuke nu; public AntiSpam as; public PlayerList pl; public Announcer an; public ChatManager cm; public Discord dc; public BanManager bm; public PermbanList pm; public ProtectArea pa; public GameRuleHandler gr; public RollbackManager rb; public CommandSpy cs; public Cager ca; public Freezer fm; public EditBlocker ebl; public PVPBlocker pbl; public Orbiter or; public Muter mu; public Fuckoff fo; public AutoKick ak; public AutoEject ae; public Monitors mo; 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 Trailer tr; public HTTPDaemon hd; public SignBlocker snp; // // Bridges public ServiceManager bridges; public BukkitTelnetBridge btb; public EssentialsBridge esb; public LibsDisguisesBridge ldb; public CoreProtectBridge cpb; public WorldEditBridge web; public WorldGuardBridge wgb; @Override public void load() { TotalFreedomMod.pluginName = plugin.getDescription().getName(); TotalFreedomMod.pluginVersion = plugin.getDescription().getVersion(); FLog.setPluginLogger(plugin.getLogger()); FLog.setServerLogger(server.getLogger()); build.load(plugin); } @Override public void enable() { FLog.info("Created by Madgeek1450 and Prozza"); FLog.info("Version " + build.version); FLog.info("Compiled " + build.date + " by " + build.author); final MethodTimer timer = new 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(); BackupManager backups = new BackupManager(this); backups.createBackups(TotalFreedomMod.CONFIG_FILENAME, true); backups.createBackups(AdminList.CONFIG_FILENAME); backups.createBackups(PermbanList.CONFIG_FILENAME); config = new MainConfig(this); config.load(); // Start services services = new ServiceManager<>(plugin); si = services.registerService(ServerInterface.class); sf = services.registerService(SavedFlags.class); wm = services.registerService(WorldManager.class); lv = services.registerService(LogViewer.class); al = services.registerService(AdminList.class); rm = services.registerService(RankManager.class); cl = services.registerService(CommandLoader.class); cb = services.registerService(CommandBlocker.class); eb = services.registerService(EventBlocker.class); bb = services.registerService(BlockBlocker.class); mb = services.registerService(MobBlocker.class); ib = services.registerService(InteractBlocker.class); pb = services.registerService(PotionBlocker.class); lp = services.registerService(LoginProcess.class); nu = services.registerService(AntiNuke.class); as = services.registerService(AntiSpam.class); pl = services.registerService(PlayerList.class); an = services.registerService(Announcer.class); cm = services.registerService(ChatManager.class); dc = services.registerService(Discord.class); bm = services.registerService(BanManager.class); pm = services.registerService(PermbanList.class); pa = services.registerService(ProtectArea.class); gr = services.registerService(GameRuleHandler.class); snp = services.registerService(SignBlocker.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); ebl = services.registerService(EditBlocker.class); pbl = services.registerService(PVPBlocker.class); fo = services.registerService(Fuckoff.class); ak = services.registerService(AutoKick.class); ae = services.registerService(AutoEject.class); mo = services.registerService(Monitors.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); tr = services.registerService(Trailer.class); // HTTPD hd = services.registerService(HTTPDaemon.class); services.start(); // Start bridges bridges = new ServiceManager<>(plugin); btb = bridges.registerService(BukkitTelnetBridge.class); cpb = bridges.registerService(CoreProtectBridge.class); esb = bridges.registerService(EssentialsBridge.class); ldb = bridges.registerService(LibsDisguisesBridge.class); web = bridges.registerService(WorldEditBridge.class); wgb = bridges.registerService(WorldGuardBridge.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); //little workaround to stop spigot from autorestarting - causing AMP to detach from process. SpigotConfig.config.set("settings.restart-on-crash", false); } @Override public void disable() { // Stop services and bridges bridges.stop(); services.stop(); server.getScheduler().cancelTasks(plugin); FLog.info("Plugin disabled"); } public static class BuildProperties { public String author; public String codename; public String version; public String number; public String date; public String head; public void load(TotalFreedomMod plugin) { try { final Properties props; try (InputStream in = plugin.getResource("build.properties")) { props = new Properties(); props.load(in); } author = props.getProperty("program.build.author", "unknown"); codename = props.getProperty("program.build.codename", "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/Maven?"); FLog.severe(ex); } } public String formattedVersion() { return pluginVersion + "." + number + " (" + head + ")"; } } public static TotalFreedomMod plugin() { for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { if (plugin.getName().equalsIgnoreCase(pluginName)) { return (TotalFreedomMod) plugin; } } return null; } }