package me.totalfreedom.totalfreedommod; import java.io.File; import java.io.InputStream; import java.util.Properties; import me.totalfreedom.totalfreedommod.admin.ActivityLog; 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.EditBlocker; import me.totalfreedom.totalfreedommod.blocking.EventBlocker; import me.totalfreedom.totalfreedommod.blocking.InteractBlocker; import me.totalfreedom.totalfreedommod.blocking.MobBlocker; import me.totalfreedom.totalfreedommod.blocking.PVPBlocker; import me.totalfreedom.totalfreedommod.blocking.PotionBlocker; import me.totalfreedom.totalfreedommod.blocking.SignBlocker; import me.totalfreedom.totalfreedommod.blocking.command.CommandBlocker; import me.totalfreedom.totalfreedommod.bridge.BukkitTelnetBridge; import me.totalfreedom.totalfreedommod.bridge.CoreProtectBridge; import me.totalfreedom.totalfreedommod.bridge.EssentialsBridge; import me.totalfreedom.totalfreedommod.bridge.LibsDisguisesBridge; import me.totalfreedom.totalfreedommod.bridge.WorldEditBridge; import me.totalfreedom.totalfreedommod.bridge.WorldGuardBridge; 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.CurseListener; 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.fun.MobStacker; import me.totalfreedom.totalfreedommod.fun.Trailer; import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon; import me.totalfreedom.totalfreedommod.world.WorldRestrictions; import me.totalfreedom.totalfreedommod.permissions.PermissionConfig; import me.totalfreedom.totalfreedommod.permissions.PermissionManager; import me.totalfreedom.totalfreedommod.player.PlayerList; import me.totalfreedom.totalfreedommod.punishments.PunishmentList; import me.totalfreedom.totalfreedommod.rank.RankManager; import me.totalfreedom.totalfreedommod.shop.Shop; import me.totalfreedom.totalfreedommod.sql.SQLite; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.MethodTimer; import me.totalfreedom.totalfreedommod.world.CleanroomChunkGenerator; import me.totalfreedom.totalfreedommod.world.WorldManager; import net.pravian.aero.component.service.ServiceManager; import net.pravian.aero.plugin.AeroPlugin; import org.bstats.Metrics; import org.bukkit.Bukkit; import org.bukkit.generator.ChunkGenerator; import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitRunnable; import org.spigotmc.SpigotConfig; 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; public PermissionConfig permissions; // // Services public ServiceManager services; public ServerInterface si; public SavedFlags sf; public WorldManager wm; public LogViewer lv; public AdminList al; public ActivityLog acl; 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 Shop sh; public SQLite sql; public Announcer an; public ChatManager cm; public Discord dc; public PunishmentList pul; public BanManager bm; public PermbanList pm; public PermissionManager pem; public ProtectArea pa; public GameRuleHandler gr; 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 ServerPing sp; public CurseListener cul; public ItemFun it; public Landminer lm; public MobStacker ms; public MP44 mp; public Jumppads jp; public Trailer tr; public HTTPDaemon hd; public WorldRestrictions wr; public SignBlocker snp; public EntityWiper ew; //public HubWorldRestrictions hwr; // // 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")); BackupManager backups = new BackupManager(this); backups.createBackups(TotalFreedomMod.CONFIG_FILENAME, true); backups.createBackups(PermbanList.CONFIG_FILENAME); backups.createBackups(PermissionConfig.PERMISSIONS_FILENAME, true); backups.createBackups(PunishmentList.CONFIG_FILENAME); backups.createBackups("database.db"); config = new MainConfig(this); config.load(); permissions = new PermissionConfig(this); permissions.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); sql = services.registerService(SQLite.class); al = services.registerService(AdminList.class); acl = services.registerService(ActivityLog.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); wr = services.registerService(WorldRestrictions.class); pl = services.registerService(PlayerList.class); sh = services.registerService(Shop.class); an = services.registerService(Announcer.class); cm = services.registerService(ChatManager.class); dc = services.registerService(Discord.class); pul = services.registerService(PunishmentList.class); bm = services.registerService(BanManager.class); pm = services.registerService(PermbanList.class); pem = services.registerService(PermissionManager.class); pa = services.registerService(ProtectArea.class); gr = services.registerService(GameRuleHandler.class); snp = services.registerService(SignBlocker.class); ew = services.registerService(EntityWiper.class); // Single admin utils 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); sp = services.registerService(ServerPing.class); // Fun cul = services.registerService(CurseListener.class); it = services.registerService(ItemFun.class); lm = services.registerService(Landminer.class); ms = services.registerService(MobStacker.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 @ https://bstats.org/plugin/bukkit/TotalFreedomMod new Metrics(this); // 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("buildAuthor", "unknown"); codename = props.getProperty("buildCodeName", "unknown"); version = props.getProperty("buildVersion", pluginVersion); number = props.getProperty("buildNumber", "1"); date = props.getProperty("buildDate", "unknown"); // Need to do this or it will display ${git.commit.id.abbrev} head = props.getProperty("buildHead", "unknown").replace("${git.commit.id.abbrev}", "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; } @Override public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) { return new CleanroomChunkGenerator(id); } }