diff --git a/TotalFreedomMod.iml b/TotalFreedomMod.iml index d37fef58..e705fbd3 100644 --- a/TotalFreedomMod.iml +++ b/TotalFreedomMod.iml @@ -52,9 +52,8 @@ - - + @@ -161,5 +160,8 @@ + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 9ba7a4e7..03c0129d 100644 --- a/pom.xml +++ b/pom.xml @@ -142,13 +142,6 @@ provided - - com.github.Pravian - Aero - 5f82926 - provided - - com.github.TotalFreedom BukkitTelnet @@ -238,6 +231,18 @@ provided + + org.reflections + reflections + 0.9.11 + + + + javassist + javassist + 3.12.1.GA + + @@ -396,12 +401,22 @@ commons-io:commons-io org.apache.commons:commons-lang3 commons-codec:commons-codec + org.reflections:reflections + javassist:javassist + + org.apache.maven.plugins + maven-jar-plugin + 2.3.1 + + C:\Users\Jax\Desktop\STUFF\ts116\plugins + + diff --git a/src/main/java/me/totalfreedom/totalfreedommod/Announcer.java b/src/main/java/me/totalfreedom/totalfreedommod/Announcer.java index 62a32038..2fd04e50 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/Announcer.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/Announcer.java @@ -21,13 +21,8 @@ public class Announcer extends FreedomService private String prefix; private BukkitTask announcer; - public Announcer(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { enabled = ConfigEntry.ANNOUNCER_ENABLED.getBoolean(); interval = ConfigEntry.ANNOUNCER_INTERVAL.getInteger() * 20L; @@ -64,7 +59,7 @@ public class Announcer extends FreedomService } @Override - protected void onStop() + public void onStop() { if (announcer == null) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/AntiNuke.java b/src/main/java/me/totalfreedom/totalfreedommod/AntiNuke.java index 48f34c09..444368d0 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/AntiNuke.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/AntiNuke.java @@ -12,19 +12,13 @@ import org.bukkit.event.block.BlockPlaceEvent; public class AntiNuke extends FreedomService { - - public AntiNuke(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java b/src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java index 59bdcb16..d603a485 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java @@ -24,13 +24,8 @@ public class AntiSpam extends FreedomService // public BukkitTask cycleTask = null; - public AntiSpam(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { new BukkitRunnable() { @@ -44,7 +39,7 @@ public class AntiSpam extends FreedomService } @Override - protected void onStop() + public void onStop() { FUtil.cancel(cycleTask); } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/AutoEject.java b/src/main/java/me/totalfreedom/totalfreedommod/AutoEject.java index 42dee85a..a3055f1f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/AutoEject.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/AutoEject.java @@ -8,7 +8,6 @@ import java.util.Map; import me.totalfreedom.totalfreedommod.banning.Ban; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.util.Ips; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameMode; @@ -19,25 +18,20 @@ public class AutoEject extends FreedomService private final Map ejects = new HashMap<>(); // ip -> amount - public AutoEject(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } public void autoEject(Player player, String kickMessage) { EjectMethod method = EjectMethod.STRIKE_ONE; - final String ip = Ips.getIp(player); + final String ip = FUtil.getIp(player); if (!ejects.containsKey(ip)) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/AutoKick.java b/src/main/java/me/totalfreedom/totalfreedommod/AutoKick.java index e4bb380c..b7016dc3 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/AutoKick.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/AutoKick.java @@ -15,13 +15,8 @@ public class AutoKick extends FreedomService private long autoKickTicks; private double autoKickThreshold; - public AutoKick(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { autoKickTicks = (long)ConfigEntry.AUTOKICK_TIME.getInteger() * 1000L; autoKickThreshold = ConfigEntry.AUTOKICK_THRESHOLD.getDouble(); @@ -43,7 +38,7 @@ public class AutoKick extends FreedomService } @Override - protected void onStop() + public void onStop() { FUtil.cancel(kickTask); kickTask = null; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/BackupManager.java b/src/main/java/me/totalfreedom/totalfreedommod/BackupManager.java index 52a29576..ec73ddc7 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/BackupManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/BackupManager.java @@ -1,18 +1,21 @@ package me.totalfreedom.totalfreedommod; import java.io.File; +import me.totalfreedom.totalfreedommod.config.YamlConfig; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.component.PluginComponent; -import net.pravian.aero.config.YamlConfig; import org.bukkit.util.FileUtil; -public class BackupManager extends PluginComponent +public class BackupManager extends FreedomService { - - public BackupManager(TotalFreedomMod plugin) + @Override + public void onStart() + { + } + + @Override + public void onStop() { - super(plugin); } public void createBackups(String file) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java b/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java index 1c0ebb51..5b82c183 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java @@ -23,19 +23,13 @@ import org.bukkit.SoundCategory; public class ChatManager extends FreedomService { - - public ChatManager(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/CommandSpy.java b/src/main/java/me/totalfreedom/totalfreedommod/CommandSpy.java index db9a157a..1629887d 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/CommandSpy.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/CommandSpy.java @@ -9,19 +9,13 @@ import org.bukkit.ChatColor; public class CommandSpy extends FreedomService { - - public CommandSpy(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java b/src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java index 5bd0099d..61c2400c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/EntityWiper.java @@ -16,11 +16,6 @@ public class EntityWiper extends FreedomService { private BukkitTask wiper; - public EntityWiper(TotalFreedomMod plugin) - { - super(plugin); - } - public List BLACKLIST = Arrays.asList( EntityType.ARMOR_STAND, EntityType.PAINTING, @@ -31,7 +26,7 @@ public class EntityWiper extends FreedomService ); @Override - protected void onStart() + public void onStart() { // Continuous Entity Wiper wiper = new BukkitRunnable() @@ -45,7 +40,7 @@ public class EntityWiper extends FreedomService } @Override - protected void onStop() + public void onStop() { wiper.cancel(); wiper = null; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/FreedomService.java b/src/main/java/me/totalfreedom/totalfreedommod/FreedomService.java index 3cce8459..e324847c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/FreedomService.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/FreedomService.java @@ -1,13 +1,24 @@ package me.totalfreedom.totalfreedommod; -import net.pravian.aero.component.service.AbstractService; +import me.totalfreedom.totalfreedommod.util.FLog; +import org.bukkit.Server; +import org.bukkit.event.Listener; -public abstract class FreedomService extends AbstractService +public abstract class FreedomService implements Listener { + protected final TotalFreedomMod plugin; + protected final Server server; + protected final FLog logger; - public FreedomService(TotalFreedomMod plugin) + public FreedomService() { - super(plugin); + plugin = TotalFreedomMod.getPlugin(); + server = plugin.getServer(); + logger = new FLog(); + plugin.getServer().getPluginManager().registerEvents(this, plugin); + plugin.fsh.add(this); } + public abstract void onStart(); + public abstract void onStop(); } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/FreedomServiceHandler.java b/src/main/java/me/totalfreedom/totalfreedommod/FreedomServiceHandler.java new file mode 100644 index 00000000..d8960ab8 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/FreedomServiceHandler.java @@ -0,0 +1,26 @@ +package me.totalfreedom.totalfreedommod; + +import java.util.ArrayList; +import java.util.List; +import lombok.Getter; + +public class FreedomServiceHandler +{ + @Getter + private List services; + + public FreedomServiceHandler() + { + this.services = new ArrayList<>(); + } + + public void add(FreedomService service) + { + services.add(service); + } + + public int getServiceAmount() + { + return services.size(); + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/Fuckoff.java b/src/main/java/me/totalfreedom/totalfreedommod/Fuckoff.java index 716fc94a..06b03f89 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/Fuckoff.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/Fuckoff.java @@ -9,18 +9,13 @@ import org.bukkit.event.player.PlayerMoveEvent; public class Fuckoff extends FreedomService { - public Fuckoff(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/GameRuleHandler.java b/src/main/java/me/totalfreedom/totalfreedommod/GameRuleHandler.java index cfa202cc..36490da8 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/GameRuleHandler.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/GameRuleHandler.java @@ -13,10 +13,8 @@ public class GameRuleHandler extends FreedomService private final Map rules = new EnumMap<>(GameRule.class); - public GameRuleHandler(TotalFreedomMod plugin) + public GameRuleHandler() { - super(plugin); - for (GameRule gameRule : GameRule.values()) { rules.put(gameRule, gameRule.getDefaultValue()); @@ -24,7 +22,7 @@ public class GameRuleHandler extends FreedomService } @Override - protected void onStart() + public void onStart() { setGameRule(GameRule.DO_DAYLIGHT_CYCLE, !ConfigEntry.DISABLE_NIGHT.getBoolean(), false); setGameRule(GameRule.DO_FIRE_TICK, ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean(), false); @@ -41,7 +39,7 @@ public class GameRuleHandler extends FreedomService } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/LogViewer.java b/src/main/java/me/totalfreedom/totalfreedommod/LogViewer.java index b7fe358c..802256bc 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/LogViewer.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/LogViewer.java @@ -23,19 +23,13 @@ import org.bukkit.scheduler.BukkitRunnable; public class LogViewer extends FreedomService { - - public LogViewer(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java b/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java index 286f3af3..02ea6eb6 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java @@ -11,7 +11,6 @@ import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FSync; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.util.Ips; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -37,18 +36,13 @@ public class LoginProcess extends FreedomService @Setter private static boolean lockdownEnabled = false; - public LoginProcess(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } @@ -209,9 +203,9 @@ public class LoginProcess extends FreedomService return; } - if (!playerData.hasVerification() && !playerData.getIps().contains(Ips.getIp(player))) + if (!playerData.hasVerification() && !playerData.getIps().contains(FUtil.getIp(player))) { - playerData.addIp(Ips.getIp(player)); + playerData.addIp(FUtil.getIp(player)); plugin.pl.save(playerData); } @@ -242,7 +236,11 @@ public class LoginProcess extends FreedomService if (!plugin.al.isAdmin(player)) { - fPlayer.setTag(FUtil.colorize(playerData.getTag())); + String tag = playerData.getTag(); + if (tag != null) + { + fPlayer.setTag(FUtil.colorize(tag)); + } int noteCount = playerData.getNotes().size(); if (noteCount != 0) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/Monitors.java b/src/main/java/me/totalfreedom/totalfreedommod/Monitors.java index e9616fb9..7147f9a0 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/Monitors.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/Monitors.java @@ -18,18 +18,13 @@ public class Monitors extends FreedomService private final DecimalFormat decimalFormat = new DecimalFormat("#"); private String potionSpyPrefix = ChatColor.DARK_GRAY + "[" + ChatColor.YELLOW + "PotionSpy" + ChatColor.DARK_GRAY + "] "; - public Monitors(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java b/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java index a248738f..413c55ed 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java @@ -27,18 +27,13 @@ public class MovementValidator extends FreedomService public static final int MAX_XYZ_COORD = 29999998; public static final int MAX_DISTANCE_TRAVELED = 100; - public MovementValidator(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/Muter.java b/src/main/java/me/totalfreedom/totalfreedommod/Muter.java index fee55d43..97891bef 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/Muter.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/Muter.java @@ -21,20 +21,15 @@ public class Muter extends FreedomService { public static final List MUTE_COMMANDS = Arrays.asList(StringUtils.split("say,me,msg,tell,reply,mail", ",")); - public final List MUTED_PLAYERS = new ArrayList(); - - public Muter(TotalFreedomMod plugin) - { - super(plugin); - } + public final List MUTED_PLAYERS = new ArrayList<>(); @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/Orbiter.java b/src/main/java/me/totalfreedom/totalfreedommod/Orbiter.java index fee5e8b7..d830199c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/Orbiter.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/Orbiter.java @@ -9,19 +9,13 @@ import org.bukkit.util.Vector; public class Orbiter extends FreedomService { - - public Orbiter(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/ProtectArea.java b/src/main/java/me/totalfreedom/totalfreedommod/ProtectArea.java index 6172695e..9dbcde21 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/ProtectArea.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/ProtectArea.java @@ -32,13 +32,8 @@ public class ProtectArea extends FreedomService // private final Map areas = Maps.newHashMap(); - public ProtectArea(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { if (!ConfigEntry.PROTECTAREA_ENABLED.getBoolean()) { @@ -68,7 +63,7 @@ public class ProtectArea extends FreedomService } @Override - protected void onStop() + public void onStop() { save(); } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/SavedFlags.java b/src/main/java/me/totalfreedom/totalfreedommod/SavedFlags.java index 20371d6b..8a0cd287 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/SavedFlags.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/SavedFlags.java @@ -12,19 +12,13 @@ import static me.totalfreedom.totalfreedommod.util.FUtil.SAVED_FLAGS_FILENAME; public class SavedFlags extends FreedomService { - - public SavedFlags(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/ServerInterface.java b/src/main/java/me/totalfreedom/totalfreedommod/ServerInterface.java index 968397bc..033281ad 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/ServerInterface.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/ServerInterface.java @@ -11,21 +11,15 @@ import org.bukkit.craftbukkit.v1_16_R1.CraftServer; public class ServerInterface extends FreedomService { - public static final String COMPILE_NMS_VERSION = "v1_16_R1"; - public ServerInterface(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/ServerPing.java b/src/main/java/me/totalfreedom/totalfreedommod/ServerPing.java index c4657fa2..a5a91ab8 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/ServerPing.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/ServerPing.java @@ -9,19 +9,13 @@ import org.bukkit.event.server.ServerListPingEvent; public class ServerPing extends FreedomService { - - public ServerPing(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index d26ac1d0..403f406f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -3,6 +3,7 @@ package me.totalfreedom.totalfreedommod; import java.io.File; import java.io.InputStream; import java.util.Properties; +import java.util.Set; import me.totalfreedom.totalfreedommod.admin.ActivityLog; import me.totalfreedom.totalfreedommod.admin.AdminList; import me.totalfreedom.totalfreedommod.banning.BanManager; @@ -24,6 +25,7 @@ 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.command.FreedomCommand; import me.totalfreedom.totalfreedommod.config.MainConfig; import me.totalfreedom.totalfreedommod.discord.Discord; import me.totalfreedom.totalfreedommod.freeze.Freezer; @@ -48,18 +50,23 @@ 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 net.coreprotect.command.CommandHandler; import org.bstats.Metrics; import org.bukkit.Bukkit; import org.bukkit.generator.ChunkGenerator; import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; +import org.reflections.Reflections; import org.spigotmc.SpigotConfig; -public class TotalFreedomMod extends AeroPlugin +public class TotalFreedomMod extends JavaPlugin { - + private static TotalFreedomMod plugin; + public static TotalFreedomMod getPlugin() + { + return plugin; + } public static final String CONFIG_FILENAME = "config.yml"; // public static final BuildProperties build = new BuildProperties(); @@ -70,8 +77,11 @@ public class TotalFreedomMod extends AeroPlugin public MainConfig config; public PermissionConfig permissions; // + // Service Handler + public FreedomServiceHandler fsh; + // Command Loader + public CommandLoader cl; // Services - public ServiceManager services; public ServerInterface si; public SavedFlags sf; public WorldManager wm; @@ -79,7 +89,6 @@ public class TotalFreedomMod extends AeroPlugin public AdminList al; public ActivityLog acl; public RankManager rm; - public CommandLoader cl; public CommandBlocker cb; public EventBlocker eb; public BlockBlocker bb; @@ -128,7 +137,6 @@ public class TotalFreedomMod extends AeroPlugin //public HubWorldRestrictions hwr; // // Bridges - public ServiceManager bridges; public BukkitTelnetBridge btb; public EssentialsBridge esb; public LibsDisguisesBridge ldb; @@ -137,19 +145,20 @@ public class TotalFreedomMod extends AeroPlugin public WorldGuardBridge wgb; @Override - public void load() + public void onLoad() { + plugin = this; TotalFreedomMod.pluginName = plugin.getDescription().getName(); TotalFreedomMod.pluginVersion = plugin.getDescription().getVersion(); FLog.setPluginLogger(plugin.getLogger()); - FLog.setServerLogger(server.getLogger()); + FLog.setServerLogger(getServer().getLogger()); build.load(plugin); } @Override - public void enable() + public void onEnable() { FLog.info("Created by Madgeek1450 and Prozza"); FLog.info("Version " + build.version); @@ -165,7 +174,26 @@ public class TotalFreedomMod extends AeroPlugin FUtil.deleteCoreDumps(); FUtil.deleteFolder(new File("./_deleteme")); - BackupManager backups = new BackupManager(this); + fsh = new FreedomServiceHandler(); + cl = new CommandLoader(); + + Reflections commandDir = new Reflections("me.totalfreedom.totalfreedommod.command"); + + Set> commandClasses = commandDir.getSubTypesOf(FreedomCommand.class); + + for (Class commandClass : commandClasses) + { + try + { + cl.add(commandClass.newInstance()); + } + catch (InstantiationException | IllegalAccessException | ExceptionInInitializerError ex) + { + FLog.warning("Failed to register command: /" + commandClass.getSimpleName().replace("Command_" , "")); + } + } + + BackupManager backups = new BackupManager(); backups.createBackups(TotalFreedomMod.CONFIG_FILENAME, true); backups.createBackups(PermbanList.CONFIG_FILENAME); backups.createBackups(PermissionConfig.PERMISSIONS_FILENAME, true); @@ -179,78 +207,78 @@ public class TotalFreedomMod extends AeroPlugin 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); + si = new ServerInterface(); + sf = new SavedFlags(); + wm = new WorldManager(); + lv = new LogViewer(); + sql = new SQLite(); + al = new AdminList(); + acl = new ActivityLog(); + rm = new RankManager(); + cb = new CommandBlocker(); + eb = new EventBlocker(); + bb = new BlockBlocker(); + mb = new MobBlocker(); + ib = new InteractBlocker(); + pb = new PotionBlocker(); + lp = new LoginProcess(); + nu = new AntiNuke(); + as = new AntiSpam(); + wr = new WorldRestrictions(); + pl = new PlayerList(); + sh = new Shop(); + an = new Announcer(); + cm = new ChatManager(); + dc = new Discord(); + pul = new PunishmentList(); + bm = new BanManager(); + pm = new PermbanList(); + pem = new PermissionManager(); + pa = new ProtectArea(); + gr = new GameRuleHandler(); + snp = new SignBlocker(); + ew = new EntityWiper(); // 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); + cs = new CommandSpy(); + ca = new Cager(); + fm = new Freezer(); + or = new Orbiter(); + mu = new Muter(); + ebl = new EditBlocker(); + pbl = new PVPBlocker(); + fo = new Fuckoff(); + ak = new AutoKick(); + ae = new AutoEject(); + mo = new Monitors(); - mv = services.registerService(MovementValidator.class); - sp = services.registerService(ServerPing.class); + mv = new MovementValidator(); + sp = new ServerPing(); // 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); + cul = new CurseListener(); + it = new ItemFun(); + lm = new Landminer(); + ms = new MobStacker(); + mp = new MP44(); + jp = new Jumppads(); + tr = new Trailer(); // HTTPD - hd = services.registerService(HTTPDaemon.class); - services.start(); + hd = new HTTPDaemon(); // 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(); + btb = new BukkitTelnetBridge(); + cpb = new CoreProtectBridge(); + esb = new EssentialsBridge(); + ldb = new LibsDisguisesBridge(); + web = new WorldEditBridge(); + wgb = new WorldGuardBridge(); + + for (FreedomService service : fsh.getServices()) + service.onStart(); + + FLog.info("Started " + fsh.getServiceAmount() + "services."); timer.update(); FLog.info("Version " + pluginVersion + " for " + ServerInterface.COMPILE_NMS_VERSION + " enabled in " + timer.getTotal() + "ms"); @@ -272,13 +300,15 @@ public class TotalFreedomMod extends AeroPlugin } @Override - public void disable() + public void onDisable() { // Stop services and bridges - bridges.stop(); - services.stop(); + for (FreedomService service : fsh.getServices()) + { + service.onStop(); + } - server.getScheduler().cancelTasks(plugin); + getServer().getScheduler().cancelTasks(plugin); FLog.info("Plugin disabled"); } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLog.java b/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLog.java index c36b130a..41ab9505 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLog.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLog.java @@ -4,10 +4,9 @@ import com.google.common.collect.Maps; import java.util.Map; import lombok.Getter; import me.totalfreedom.totalfreedommod.FreedomService; -import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.config.YamlConfig; import me.totalfreedom.totalfreedommod.util.FLog; -import net.pravian.aero.config.YamlConfig; -import net.pravian.aero.util.Ips; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; @@ -28,21 +27,19 @@ public class ActivityLog extends FreedomService private final YamlConfig config; - public ActivityLog(TotalFreedomMod plugin) + public ActivityLog() { - super(plugin); - this.config = new YamlConfig(plugin, FILENAME, true); } @Override - protected void onStart() + public void onStart() { load(); } @Override - protected void onStop() + public void onStop() { save(); } @@ -110,7 +107,7 @@ public class ActivityLog extends FreedomService ActivityLogEntry activityLog = getEntryByName(player.getName()); if (activityLog == null) { - String ip = Ips.getIp(player); + String ip = FUtil.getIp(player); activityLog = getEntryByIp(ip); if (activityLog != null) { @@ -129,7 +126,7 @@ public class ActivityLog extends FreedomService config.save(); } } - String ip = Ips.getIp(player); + String ip = FUtil.getIp(player); if (!activityLog.getIps().contains(ip)) { activityLog.addIp(ip); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLogEntry.java b/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLogEntry.java index db7ae845..6ff54333 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLogEntry.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLogEntry.java @@ -6,15 +6,13 @@ import java.util.Date; import java.util.List; import lombok.Getter; import lombok.Setter; +import me.totalfreedom.totalfreedommod.config.IConfig; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.base.ConfigLoadable; -import net.pravian.aero.base.ConfigSavable; -import net.pravian.aero.base.Validatable; import org.apache.commons.lang.Validate; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; -public class ActivityLogEntry implements ConfigLoadable, ConfigSavable, Validatable +public class ActivityLogEntry implements IConfig { @Getter diff --git a/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java b/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java index 1f7e31fe..5f29993d 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java @@ -15,7 +15,6 @@ import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.util.Ips; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -58,7 +57,7 @@ public class Admin public Admin(Player player) { this.name = player.getName(); - this.ips.add(Ips.getIp(player)); + this.ips.add(FUtil.getIp(player)); } public Admin(ResultSet resultSet) @@ -107,7 +106,7 @@ public class Admin { name = player.getName(); ips.clear(); - ips.add(Ips.getIp(player)); + ips.add(FUtil.getIp(player)); } public Map toSQLStorable() diff --git a/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java b/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java index 29c519b1..deb5a7a7 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java @@ -1,6 +1,5 @@ package me.totalfreedom.totalfreedommod.admin; -import com.google.common.base.Function; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import java.sql.ResultSet; @@ -13,16 +12,13 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import lombok.Getter; import me.totalfreedom.totalfreedommod.FreedomService; -import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.util.Ips; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.plugin.ServicePriority; public class AdminList extends FreedomService { @@ -37,20 +33,15 @@ public class AdminList extends FreedomService public final Map> verifiedNoAdminIps = Maps.newHashMap(); public static ArrayList vanished = new ArrayList<>(); - public AdminList(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { load(); deactivateOldEntries(false); } @Override - protected void onStop() + public void onStop() { } @@ -139,7 +130,7 @@ public class AdminList extends FreedomService public Admin getAdmin(Player player) { // Find admin - String ip = Ips.getIp(player); + String ip = FUtil.getIp(player); Admin admin = getEntryByName(player.getName()); // Admin by name @@ -223,7 +214,7 @@ public class AdminList extends FreedomService public boolean isVerifiedAdmin(Player player) { - return verifiedNoAdmins.contains(player.getName()) && verifiedNoAdminIps.get(player.getName()).contains(Ips.getIp(player)); + return verifiedNoAdmins.contains(player.getName()) && verifiedNoAdminIps.get(player.getName()).contains(FUtil.getIp(player)); } public boolean isIdentityMatched(Player player) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/banning/Ban.java b/src/main/java/me/totalfreedom/totalfreedommod/banning/Ban.java index 681474a3..0fd9c6cb 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/banning/Ban.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/banning/Ban.java @@ -14,14 +14,14 @@ import java.util.Set; import lombok.Getter; import lombok.Setter; import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.config.IConfig; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.base.Validatable; -import net.pravian.aero.util.Ips; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; -public class Ban implements Validatable +public class Ban implements IConfig { public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z"); @@ -81,7 +81,7 @@ public class Ban implements Validatable public static Ban forPlayerIp(Player player, CommandSender by, Date expiry, String reason) { - return new Ban(null, Arrays.asList(Ips.getIp(player)), by.getName(), Date.from(Instant.now()), expiry, reason); + return new Ban(null, Arrays.asList(FUtil.getIp(player)), by.getName(), Date.from(Instant.now()), expiry, reason); } public static Ban forPlayerIp(String ip, CommandSender by, Date expiry, String reason) @@ -116,7 +116,7 @@ public class Ban implements Validatable public static Ban forPlayer(Player player, CommandSender by, Date expiry, String reason) { return new Ban(player.getName(), - Ips.getIp(player), + FUtil.getIp(player), by.getName(), Date.from(Instant.now()), expiry, @@ -126,7 +126,7 @@ public class Ban implements Validatable public static Ban forPlayerFuzzy(Player player, CommandSender by, Date expiry, String reason) { return new Ban(player.getName(), - FUtil.getFuzzyIp(Ips.getIp(player)), + FUtil.getFuzzyIp(FUtil.getIp(player)), by.getName(), Date.from(Instant.now()), expiry, @@ -235,6 +235,16 @@ public class Ban implements Validatable return hash; } + @Override + public void loadFrom(ConfigurationSection cs) + { + } + + @Override + public void saveTo(ConfigurationSection cs) + { + } + @Override public boolean isValid() { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/banning/BanManager.java b/src/main/java/me/totalfreedom/totalfreedommod/banning/BanManager.java index 0a844332..76ee3c27 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/banning/BanManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/banning/BanManager.java @@ -13,12 +13,10 @@ import java.util.List; import java.util.Map; import java.util.Set; import me.totalfreedom.totalfreedommod.FreedomService; -import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.util.Ips; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -35,13 +33,8 @@ public class BanManager extends FreedomService // - public BanManager(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { bans.clear(); try @@ -78,7 +71,7 @@ public class BanManager extends FreedomService } @Override - protected void onStop() + public void onStop() { } @@ -120,7 +113,7 @@ public class BanManager extends FreedomService continue; } - if (Ips.fuzzyIpMatch(ip, loopIp, 4)) + if (FUtil.fuzzyIpMatch(ip, loopIp, 4)) { return loopBan; } @@ -231,7 +224,7 @@ public class BanManager extends FreedomService public void onPlayerLogin(PlayerLoginEvent event) { final String username = event.getPlayer().getName(); - final String ip = Ips.getIp(event); + final String ip = FUtil.getIp(event); // Regular ban Ban ban = getByUsername(username); @@ -265,7 +258,7 @@ public class BanManager extends FreedomService } else { - ban = getByIp(Ips.getIp(player)); + ban = getByIp(FUtil.getIp(player)); if (ban != null) { removeBan(ban); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/banning/PermbanList.java b/src/main/java/me/totalfreedom/totalfreedommod/banning/PermbanList.java index 2c4c38c2..7265bab6 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/banning/PermbanList.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/banning/PermbanList.java @@ -4,12 +4,10 @@ import com.google.common.collect.Sets; import java.util.Set; import lombok.Getter; import me.totalfreedom.totalfreedommod.FreedomService; -import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.config.YamlConfig; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.config.YamlConfig; -import net.pravian.aero.util.Ips; import org.bukkit.ChatColor; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -25,13 +23,8 @@ public class PermbanList extends FreedomService @Getter private final Set permbannedIps = Sets.newHashSet(); - public PermbanList(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { permbannedNames.clear(); permbannedIps.clear(); @@ -49,7 +42,7 @@ public class PermbanList extends FreedomService } @Override - protected void onStop() + public void onStop() { } @@ -57,7 +50,7 @@ public class PermbanList extends FreedomService public void onPlayerLogin(PlayerLoginEvent event) { final String username = event.getPlayer().getName(); - final String ip = Ips.getIp(event); + final String ip = FUtil.getIp(event); // Permbanned IPs for (String testIp : getPermbannedIps()) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java index 9ddf4e98..08220f25 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java @@ -23,19 +23,13 @@ import org.bukkit.inventory.meta.SkullMeta; public class BlockBlocker extends FreedomService { - - public BlockBlocker(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/EditBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/EditBlocker.java index e41f0b00..7bf9d370 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/EditBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/EditBlocker.java @@ -12,19 +12,13 @@ import org.bukkit.event.block.BlockPlaceEvent; public class EditBlocker extends FreedomService { - - public EditBlocker(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java index 33050e97..aa7826ce 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java @@ -35,19 +35,13 @@ import org.bukkit.event.player.PlayerRespawnEvent; public class EventBlocker extends FreedomService { - - public EventBlocker(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java index 0d35b04f..52244fd2 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java @@ -16,19 +16,13 @@ import org.bukkit.inventory.ItemStack; public class InteractBlocker extends FreedomService { - - public InteractBlocker(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/MobBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/MobBlocker.java index 521f5140..b2eb1c02 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/MobBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/MobBlocker.java @@ -22,19 +22,13 @@ import org.bukkit.event.entity.EntitySpawnEvent; public class MobBlocker extends FreedomService { - - public MobBlocker(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/PVPBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/PVPBlocker.java index 3850660e..d76e2da6 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/PVPBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/PVPBlocker.java @@ -14,19 +14,13 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; public class PVPBlocker extends FreedomService { - - public PVPBlocker(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/PotionBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/PotionBlocker.java index 935274c4..e023409d 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/PotionBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/PotionBlocker.java @@ -19,18 +19,13 @@ public class PotionBlocker extends FreedomService public static final int POTION_BLOCK_RADIUS_SQUARED = 20 * 20; - public PotionBlocker(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/SignBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/SignBlocker.java index e09cc0f6..6b018ca6 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/SignBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/SignBlocker.java @@ -19,19 +19,13 @@ import org.bukkit.inventory.ItemStack; public class SignBlocker extends FreedomService { - - public SignBlocker(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlocker.java index 55243c78..5e9d9bdb 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlocker.java @@ -7,11 +7,10 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import me.totalfreedom.totalfreedommod.FreedomService; -import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.command.FreedomCommand; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.command.CommandReflection; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -29,19 +28,14 @@ public class CommandBlocker extends FreedomService private final Map entryList = Maps.newHashMap(); private final List unknownCommands = Lists.newArrayList(); - public CommandBlocker(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { load(); } @Override - protected void onStop() + public void onStop() { entryList.clear(); } @@ -51,13 +45,6 @@ public class CommandBlocker extends FreedomService entryList.clear(); unknownCommands.clear(); - final CommandMap commandMap = CommandReflection.getCommandMap(); - if (commandMap == null) - { - FLog.severe("Error loading commandMap."); - return; - } - @SuppressWarnings("unchecked") List blockedCommands = (List)ConfigEntry.BLOCKED_COMMANDS.getList(); for (String rawEntry : blockedCommands) @@ -88,7 +75,7 @@ public class CommandBlocker extends FreedomService subCommand = StringUtils.join(commandParts, " ", 1, commandParts.length).trim().toLowerCase(); } - final Command command = commandMap.getCommand(commandName); + final FreedomCommand command = plugin.cl.getByName(commandName); // Obtain command from alias if (command == null) @@ -111,7 +98,7 @@ public class CommandBlocker extends FreedomService if (command != null) { - for (String alias : command.getAliases()) + for (String alias : command.getAliases().split(",")) { entryList.put(alias.toLowerCase(), blockedCommandEntry); } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/BukkitTelnetBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/BukkitTelnetBridge.java index 384ea886..c37f4979 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/BukkitTelnetBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/BukkitTelnetBridge.java @@ -24,18 +24,13 @@ public class BukkitTelnetBridge extends FreedomService private BukkitTelnet bukkitTelnetPlugin = null; - public BukkitTelnetBridge(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java index 98d94a0e..2a1ce9ad 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java @@ -28,18 +28,13 @@ public class CoreProtectBridge extends FreedomService private BukkitTask wiper; - public CoreProtectBridge(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java index 324c05f2..f89988dd 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java @@ -26,18 +26,13 @@ public class EssentialsBridge extends FreedomService private Essentials essentialsPlugin = null; - public EssentialsBridge(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/LibsDisguisesBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/LibsDisguisesBridge.java index c9f58bd4..757c83b2 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/LibsDisguisesBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/LibsDisguisesBridge.java @@ -13,18 +13,13 @@ public class LibsDisguisesBridge extends FreedomService private LibsDisguises libsDisguisesPlugin = null; - public LibsDisguisesBridge(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldEditBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldEditBridge.java index 7e33051b..acb888ac 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldEditBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldEditBridge.java @@ -15,18 +15,13 @@ public class WorldEditBridge extends FreedomService // private WorldEditPlugin worldeditPlugin = null; - public WorldEditBridge(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldGuardBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldGuardBridge.java index 364c9983..c2d5241c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldGuardBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldGuardBridge.java @@ -13,21 +13,15 @@ import org.bukkit.plugin.Plugin; public class WorldGuardBridge extends FreedomService { - - public WorldGuardBridge(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { plugin.wr.protectWorld(plugin.wm.hubworld.getWorld()); plugin.wr.protectWorld(plugin.wm.masterBuilderWorld.getWorld()); } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/caging/Cager.java b/src/main/java/me/totalfreedom/totalfreedommod/caging/Cager.java index 4a4e8945..b419494c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/caging/Cager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/caging/Cager.java @@ -17,19 +17,13 @@ import org.bukkit.event.player.PlayerQuitEvent; public class Cager extends FreedomService { - - public Cager(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java b/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java index c0920815..3b39a0cf 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/CommandLoader.java @@ -1,45 +1,48 @@ package me.totalfreedom.totalfreedommod.command; +import java.util.ArrayList; +import java.util.List; import lombok.Getter; import me.totalfreedom.totalfreedommod.FreedomService; -import me.totalfreedom.totalfreedommod.TotalFreedomMod; -import me.totalfreedom.totalfreedommod.util.FLog; -import net.pravian.aero.command.handler.SimpleCommandHandler; -import org.bukkit.ChatColor; public class CommandLoader extends FreedomService { - @Getter - private final SimpleCommandHandler handler; + private final List commands; - public CommandLoader(TotalFreedomMod plugin) + public CommandLoader() { - super(plugin); - - handler = new SimpleCommandHandler<>(plugin); + commands = new ArrayList<>(); } @Override - protected void onStart() + public void onStart() { - handler.clearCommands(); - handler.setExecutorFactory(new FreedomCommandExecutor.FreedomExecutorFactory(plugin)); - handler.setCommandClassPrefix("Command_"); - handler.setPermissionMessage(ChatColor.RED + "You do not have permission to use this command."); - handler.setOnlyConsoleMessage(ChatColor.RED + "This command can only be used from the console."); - handler.setOnlyPlayerMessage(ChatColor.RED + "This command can only be used by players."); - - handler.loadFrom(FreedomCommand.class.getPackage()); - handler.registerAll(plugin.getDescription().getName(), true); - - FLog.info("Loaded " + handler.getExecutors().size() + " commands."); } @Override - protected void onStop() + public void onStop() { - handler.clearCommands(); } + public void add(FreedomCommand command) + { + commands.add(command); + command.register(); + } + + public FreedomCommand getByName(String name) + { + for (FreedomCommand command : commands) + { + if (name.equals(command.getName())) + return command; + } + return null; + } + + public int getCommandAmount() + { + return commands.size(); + } } \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_announce.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_announce.java index d22fb4f7..4abaf2b0 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_announce.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_announce.java @@ -12,7 +12,7 @@ public class Command_announce extends FreedomCommand { @Override - protected boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { if (args.length < 1) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ban.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ban.java index fd6afc22..dce660e1 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ban.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ban.java @@ -8,7 +8,6 @@ import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.util.Ips; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; @@ -82,7 +81,7 @@ public class Command_ban extends FreedomCommand final PlayerData entry = plugin.pl.getData(player); username = player.getName(); //ips.addAll(entry.getIps());/ - ips.add(Ips.getIp(player)); + ips.add(FUtil.getIp(player)); // Deop player.setOp(false); @@ -152,7 +151,7 @@ public class Command_ban extends FreedomCommand player.kickPlayer(ban.bakeKickMessage()); for (Player p : Bukkit.getOnlinePlayers()) { - if (Ips.getIp(p).equals(Ips.getIp(player))) + if (FUtil.getIp(p).equals(FUtil.getIp(player))) { p.kickPlayer(ChatColor.RED + "You've been kicked because someone on your IP has been banned."); } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_clearinventory.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_clearinventory.java index 1c22b100..f005d52f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_clearinventory.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_clearinventory.java @@ -67,7 +67,7 @@ public class Command_clearinventory extends FreedomCommand @Override public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) { - if (args.length == 1 && plugin.al.isAdmin(playerSender)) + if (args.length == 1 && plugin.al.isAdmin(sender)) { List players = FUtil.getPlayerList(); players.add("-a"); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java index 03671d58..dbcac1e9 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_doom.java @@ -7,8 +7,6 @@ import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; -import static me.totalfreedom.totalfreedommod.util.FUtil.playerMsg; -import net.pravian.aero.util.Ips; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; @@ -100,7 +98,7 @@ public class Command_doom extends FreedomCommand final String kickReason = (reason == null ? "FUCKOFF, and get your shit together!" : reason); // Log doom - plugin.pul.logPunishment(new Punishment(player.getName(), Ips.getIp(player), sender.getName(), PunishmentType.DOOM, reason)); + plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player), sender.getName(), PunishmentType.DOOM, reason)); new BukkitRunnable() { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kick.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kick.java index c5515873..4b8edaf2 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kick.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_kick.java @@ -4,7 +4,6 @@ import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.util.Ips; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -16,7 +15,7 @@ import org.bukkit.entity.Player; public class Command_kick extends FreedomCommand { @Override - protected boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { if (args.length == 0) { @@ -53,7 +52,7 @@ public class Command_kick extends FreedomCommand player.kickPlayer(builder.toString()); - plugin.pul.logPunishment(new Punishment(player.getName(), Ips.getIp(player), sender.getName(), PunishmentType.KICK, reason)); + plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player), sender.getName(), PunishmentType.KICK, reason)); return true; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_links.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_links.java index c1d2efa0..5bd21b6d 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_links.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_links.java @@ -16,7 +16,7 @@ import org.bukkit.entity.Player; public class Command_links extends FreedomCommand { @Override - protected boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { YamlConfiguration config = plugin.config.configuration; ConfigurationSection section = config.getConfigurationSection("social_links"); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java index 4a9c975e..f2b71eae 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java @@ -7,7 +7,6 @@ import me.totalfreedom.totalfreedommod.admin.AdminList; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.rank.Displayable; import me.totalfreedom.totalfreedommod.rank.Rank; -import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; import org.apache.commons.lang.StringUtils; import net.md_5.bungee.api.ChatColor; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_massmurder.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_massmurder.java index 3b565aa4..e5ed5857 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_massmurder.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_massmurder.java @@ -7,7 +7,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.BOTH) -@CommandParameters(description = "seth's personal command", usage = "/ ") +@CommandParameters(description = "seth's personal command", usage = "/ ", aliases = "genocide") public class Command_massmurder extends FreedomCommand { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mute.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mute.java index 898dd696..6a79f1ae 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mute.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mute.java @@ -9,7 +9,6 @@ import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.util.Ips; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.bukkit.ChatColor; @@ -153,7 +152,7 @@ public class Command_mute extends FreedomCommand msg(player, "You have been muted by " + ChatColor.YELLOW + sender.getName(), ChatColor.RED); msg("Muted " + player.getName()); - plugin.pul.logPunishment(new Punishment(player.getName(), Ips.getIp(player), sender.getName(), PunishmentType.MUTE, reason)); + plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player), sender.getName(), PunishmentType.MUTE, reason)); } else { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myadmin.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myadmin.java index ec564f4f..ac929fdf 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myadmin.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myadmin.java @@ -9,7 +9,6 @@ import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.util.Ips; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -22,7 +21,7 @@ public class Command_myadmin extends FreedomCommand { @Override - protected boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { if (args.length < 1) { @@ -60,7 +59,7 @@ public class Command_myadmin extends FreedomCommand } } - final String targetIp = Ips.getIp(targetPlayer); + final String targetIp = FUtil.getIp(targetPlayer); switch (args[0]) { @@ -285,7 +284,7 @@ public class Command_myadmin extends FreedomCommand if (args[0].equals("clearip")) { List ips = plugin.al.getAdmin(sender).getIps(); - ips.remove(Ips.getIp(playerSender)); + ips.remove(FUtil.getIp((Player) sender)); return ips; } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_permban.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_permban.java index 893d6864..ba8f8ef8 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_permban.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_permban.java @@ -25,8 +25,8 @@ public class Command_permban extends FreedomCommand } msg("Reloading permban list...", ChatColor.RED); - plugin.pm.stop(); - plugin.pm.start(); + plugin.pm.onStop(); + plugin.pm.onStart(); msg("Reloaded permban list."); msg(plugin.pm.getPermbannedIps().size() + " IPs and " + plugin.pm.getPermbannedNames().size() + " usernames loaded."); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_playerverification.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_playerverification.java index f10c8599..3ae7b928 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_playerverification.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_playerverification.java @@ -6,7 +6,7 @@ import java.util.Collections; import java.util.List; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.rank.Rank; -import net.pravian.aero.util.Ips; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -17,7 +17,7 @@ import org.bukkit.entity.Player; public class Command_playerverification extends FreedomCommand { @Override - protected boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { PlayerData target = plugin.pl.getData(playerSender); @@ -31,14 +31,14 @@ public class Command_playerverification extends FreedomCommand int cleared = 0; for (String ip : ips) { - if (!ip.equals(Ips.getIp(playerSender))) + if (!ip.equals(FUtil.getIp(playerSender))) { target.removeIp(ip); cleared++; } } - msg("Cleared all IP's except your current IP \"" + Ips.getIp(playerSender) + "\""); + msg("Cleared all IP's except your current IP \"" + FUtil.getIp(playerSender) + "\""); msg("Cleared " + cleared + " IP's."); plugin.pl.save(target); plugin.pl.syncIps(target); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java index 828ddc60..c64707ce 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java @@ -106,12 +106,6 @@ public class Command_ride extends FreedomCommand return true; } - if (player.getName().equals("Catholic_Mario")) - { - msg("no", ChatColor.RED); - return true; - } - if (playerData.getRideMode().equals("ask") && !FUtil.isExecutive(playerSender.getName())) { msg("Sent a request to the player.", ChatColor.GREEN); @@ -120,7 +114,7 @@ public class Command_ride extends FreedomCommand player.sendMessage(ChatColor.AQUA + "Type " + ChatColor.RED + "/ride deny" + ChatColor.AQUA + " to deny the player permission."); player.sendMessage(ChatColor.AQUA + "Request will expire after 30 seconds."); RIDE_REQUESTS.put(player, playerSender); - FreedomCommandExecutor.timer.schedule(new TimerTask() + timer.schedule(new TimerTask() { @Override public void run() diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java index 429cc6ac..67f2e6c7 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java @@ -10,7 +10,6 @@ import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.util.Ips; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -175,7 +174,7 @@ public class Command_saconfig extends FreedomCommand Admin admin = null; for (Admin loopAdmin : plugin.al.getAllAdmins()) { - if (loopAdmin.getName().equalsIgnoreCase(name) || loopAdmin.getIps().contains(Ips.getIp(player))) + if (loopAdmin.getName().equalsIgnoreCase(name) || loopAdmin.getIps().contains(FUtil.getIp(player))) { admin = loopAdmin; break; @@ -212,7 +211,7 @@ public class Command_saconfig extends FreedomCommand if (oldName != player.getName()) admin.setName(player.getName()); plugin.sql.updateAdminName(oldName, admin.getName()); - admin.addIp(Ips.getIp(player)); + admin.addIp(FUtil.getIp(player)); } admin.setActive(true); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_smite.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_smite.java index b2212dc0..f6066ec7 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_smite.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_smite.java @@ -4,7 +4,6 @@ import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.util.Ips; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; @@ -60,7 +59,7 @@ public class Command_smite extends FreedomCommand smite(sender, player, reason, silent); - plugin.pul.logPunishment(new Punishment(player.getName(), Ips.getIp(player), sender.getName(), PunishmentType.SMITE, reason)); + plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player), sender.getName(), PunishmentType.SMITE, reason)); return true; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spawnmob.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spawnmob.java index 9ba087ae..2d8ff5c6 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spawnmob.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spawnmob.java @@ -20,7 +20,7 @@ public class Command_spawnmob extends FreedomCommand { @Override - protected boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { if (args.length > 0 && args[0].equalsIgnoreCase("list")) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java index 49299cc4..dacca6ab 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java @@ -10,7 +10,6 @@ import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.util.Ips; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.Location; @@ -97,7 +96,7 @@ public class Command_tempban extends FreedomCommand plugin.bm.addBan(ban); player.kickPlayer(ban.bakeKickMessage()); - plugin.pul.logPunishment(new Punishment(player.getName(), Ips.getIp(player), sender.getName(), PunishmentType.TEMPBAN, reason)); + plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player), sender.getName(), PunishmentType.TEMPBAN, reason)); return true; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_totalfreedommod.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_totalfreedommod.java index f1e80b09..a29b4ffa 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_totalfreedommod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_totalfreedommod.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.rank.Rank; @@ -34,8 +35,11 @@ public class Command_totalfreedommod extends FreedomCommand } plugin.config.load(); - plugin.services.stop(); - plugin.services.start(); + for (FreedomService service : plugin.fsh.getServices()) + { + service.onStop(); + service.onStart(); + } final String message = String.format("%s v%s reloaded.", TotalFreedomMod.pluginName, diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_verify.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_verify.java index 95576721..0fdc0173 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_verify.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_verify.java @@ -4,7 +4,6 @@ import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.util.Ips; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -50,7 +49,7 @@ public class Command_verify extends FreedomCommand { String code = plugin.dc.generateCode(10); plugin.dc.addVerificationCode(code, playerData); - plugin.dc.bot.getUserById(discordId).openPrivateChannel().complete().sendMessage("A user with the IP `" + Ips.getIp(playerSender) + "` has sent a verification request. Please run the following in-game command: `/verify " + code + "`").complete(); + plugin.dc.bot.getUserById(discordId).openPrivateChannel().complete().sendMessage("A user with the IP `" + FUtil.getIp(playerSender) + "` has sent a verification request. Please run the following in-game command: `/verify " + code + "`").complete(); msg("A verification code has been sent to your account, please copy the code and run /verify ", ChatColor.GREEN); return true; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_verifynoadmin.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_verifynoadmin.java index 0b3af27e..9b786908 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_verifynoadmin.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_verifynoadmin.java @@ -6,7 +6,6 @@ import java.util.List; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.util.Ips; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -39,7 +38,7 @@ public class Command_verifynoadmin extends FreedomCommand { plugin.al.verifiedNoAdmins.add(player.getName()); } - String ip = Ips.getIp(player); + String ip = FUtil.getIp(player); if (!plugin.al.verifiedNoAdminIps.containsKey(player.getName())) { List ips = new ArrayList<>(); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wildcard.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wildcard.java index 0ae10af1..23549198 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wildcard.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wildcard.java @@ -30,17 +30,20 @@ public class Command_wildcard extends FreedomCommand return false; } - Command runCmd = server.getPluginCommand(args[0]); - if (runCmd == null) + FreedomCommand command = plugin.cl.getByName(args[0]); + if (command == null) { msg("Unknown command: " + args[0], ChatColor.RED); return true; } - if (BLOCKED_COMMANDS.contains(runCmd.getName())) + for (String blockedCommand : BLOCKED_COMMANDS) { - msg("Did you really think that was going to work?", ChatColor.RED); - return true; + if (blockedCommand.equals(command.getName()) || command.getAliases().contains(blockedCommand)) + { + msg("Did you really think that was going to work?", ChatColor.RED); + return true; + } } String baseCommand = StringUtils.join(args, " "); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java b/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java index 1c134786..9efc04a2 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java @@ -1,7 +1,13 @@ package me.totalfreedom.totalfreedommod.command; import com.google.common.collect.Lists; +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; import lombok.Getter; import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.admin.Admin; @@ -9,90 +15,225 @@ import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.command.AbstractCommandBase; -import net.pravian.aero.util.Players; +import org.apache.commons.lang.StringUtils; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Server; import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandMap; import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.PluginCommand; +import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; import org.bukkit.util.StringUtil; import org.spigotmc.SpigotConfig; -public abstract class FreedomCommand extends AbstractCommandBase +public abstract class FreedomCommand implements CommandExecutor, TabCompleter { + public static final String COMMAND_PREFIX = "Command_"; + + @Getter + private static CommandMap commandMap; + @Getter + private final String name; + private final String description; + private final String usage; + @Getter + private final String aliases; + private final Rank level; + private final SourceType source; + private final boolean blockHostConsole; + private final int cooldown; + private final CommandParameters params; + @Getter + private final CommandPermissions perms; + + protected CommandSender sender; + + protected final TotalFreedomMod plugin = TotalFreedomMod.getPlugin(); + protected final Server server = plugin.getServer(); public static final String UNKNOWN_COMMAND = ChatColor.WHITE + SpigotConfig.unknownCommandMessage; public static final String YOU_ARE_OP = ChatColor.YELLOW + "You are now op!"; public static final String YOU_ARE_NOT_OP = ChatColor.YELLOW + "You are no longer op!"; public static final String PLAYER_NOT_FOUND = ChatColor.GRAY + "Player not found!"; - // - @Getter - private final CommandParameters params; - @Getter - private final CommandPermissions perms; - // + public static final String ONLY_CONSOLE = ChatColor.RED + "Only console senders may execute this command!"; + public static final String ONLY_IN_GAME = ChatColor.RED + "Only in-game players may execute this command!"; + public static final String NO_PERMISSION = ChatColor.RED + "You do not have permission to execute this command."; - public FreedomCommand() + public static final Timer timer = new Timer(); + public static final Map COOLDOWN_TIMERS = new HashMap<>(); + + FreedomCommand() { - this.params = getClass().getAnnotation(CommandParameters.class); - if (params == null) - { - FLog.warning("Ignoring command usage for command " + getClass().getSimpleName() + ". Command is not annotated!"); - } - - this.perms = getClass().getAnnotation(CommandPermissions.class); - if (perms == null) - { - FLog.warning("Ignoring permissions for command " + getClass().getSimpleName() + ". Command is not annotated!"); - } + params = getClass().getAnnotation(CommandParameters.class); + perms = getClass().getAnnotation(CommandPermissions.class); + this.name = getClass().getSimpleName().replace(COMMAND_PREFIX, "").toLowerCase(); + this.description = params.description(); + this.usage = params.usage(); + this.aliases = params.aliases(); + this.level = perms.level(); + this.source = perms.source(); + this.blockHostConsole = perms.blockHostConsole(); + this.cooldown = perms.cooldown(); } - @Override - public final boolean runCommand(final CommandSender sender, final Command command, final String label, final String[] args) + public void register() { - setVariables(sender, command, label, args); - - try - { - return run(sender, playerSender, command, label, args, isConsole()); - } - catch (CommandFailException ex) - { - msg(ex.getMessage()); - return true; - } - catch (Exception ex) - { - FLog.severe("Uncaught exception executing command: " + command.getName()); - FLog.severe(ex); - sender.sendMessage(ChatColor.RED + "Command error: " + (ex.getMessage() == null ? "Unknown cause" : ex.getMessage())); - return true; - } + FCommand cmd = new FCommand(this.name); + if (this.aliases != null) cmd.setAliases(Arrays.asList(StringUtils.split(this.aliases, ","))); + if (this.description != null) cmd.setDescription(this.description); + if (this.usage != null) cmd.setUsage(this.usage); + getCommandMap().register("", cmd); + cmd.setExecutor(this); } - protected List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) { - return null; + public static final CommandMap getCommandMap() + { + if (commandMap == null) + { + try + { + final Field f = Bukkit.getServer().getClass().getDeclaredField("commandMap"); + f.setAccessible(true); + commandMap = (CommandMap) f.get(Bukkit.getServer()); + return getCommandMap(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + else if (commandMap != null) + { + return commandMap; + } + return getCommandMap(); } - @Override - public List tabComplete(CommandSender sender, Command command, String alias, String[] args) + private final class FCommand extends Command { - List options = getTabCompleteOptions(sender, command, alias, args); - if (options == null) + private FreedomCommand cmd = null; + private FCommand(String command) { + super(command); + } + public void setExecutor(FreedomCommand cmd) + { + this.cmd = cmd; + } + + public boolean execute(CommandSender sender, String commandLabel, String[] args) + { + if (cmd != null) + { + cmd.sender = sender; + + if (COOLDOWN_TIMERS.containsKey(sender) && COOLDOWN_TIMERS.containsValue(cmd)) + { + msg(ChatColor.RED + "You are on cooldown for this command."); + return true; + } + + if (perms.blockHostConsole() && FUtil.isFromHostConsole(sender.getName())) + { + msg(ChatColor.RED + "Host console is not allowed to use this command!"); + return true; + } + + if (!plugin.rm.getRank(sender).isAtLeast(perms.level())) + { + msg(NO_PERMISSION); + return true; + } + + if (perms.source() == SourceType.ONLY_CONSOLE && sender instanceof Player) + { + msg(ONLY_CONSOLE); + return true; + } + + if (perms.source() == SourceType.ONLY_IN_GAME && sender instanceof ConsoleCommandSender) + { + msg(ONLY_IN_GAME); + return true; + } + + if (perms.cooldown() != 0 && !isAdmin(sender)) + { + COOLDOWN_TIMERS.put(sender, cmd); + timer.schedule(new TimerTask() + { + @Override + public void run() + { + COOLDOWN_TIMERS.remove(sender); + } + }, perms.cooldown() * 1000); + } + return cmd.onCommand(sender, this, commandLabel, args); + } + return false; + } + + @Override + public List tabComplete(CommandSender sender, String alias, String[] args) + { + if (cmd != null) + { + return cmd.onTabComplete(sender, this, alias, args); + } return null; } - return StringUtil.copyPartialMatches(args[args.length - 1], options, Lists.newArrayList()); } - protected abstract boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole); + protected void msg(CommandSender sender, String message) + { + sender.sendMessage(ChatColor.GRAY + message); + } + + protected void msg(Player player, String message) + { + player.sendMessage(ChatColor.GRAY + message); + } + + protected void msg(Player player, String message, ChatColor color) + { + player.sendMessage(color + message); + } + + protected void msg(String message) + { + msg(sender, message); + } + + protected void msg(String message, ChatColor color) + { + msg(color + message); + } + + protected void msg(String message, net.md_5.bungee.api.ChatColor color) + { + msg(color + message); + } + + protected boolean isAdmin(Player player) + { + return plugin.al.isAdmin(player); + } + + protected boolean isAdmin(CommandSender sender) + { + return plugin.al.isAdmin(sender); + } protected void checkConsole() { if (!isConsole()) { - throw new CommandFailException(getHandler().getOnlyConsoleMessage()); + throw new CommandFailException(ONLY_CONSOLE); } } @@ -100,15 +241,7 @@ public abstract class FreedomCommand extends AbstractCommandBase", cmd.getLabel())); + return true; + } + } + catch (CommandFailException ex) + { + msg(ChatColor.RED + ex.getMessage()); + } + return false; + } + + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) + { + List options = getTabCompleteOptions(sender, command, alias, args); + if (options == null) + { + return null; + } + return StringUtil.copyPartialMatches(args[args.length - 1], options, Lists.newArrayList()); + } + + public abstract boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole); + + protected List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + return null; } protected boolean isConsole() { - return !(sender instanceof Player); + return sender instanceof ConsoleCommandSender; } protected Player getPlayer(String name) { - return Players.getPlayer(name); + return Bukkit.getPlayer(name); } protected Player getPlayer(String name, Boolean nullVanished) { - Player player = Players.getPlayer(name); + Player player = Bukkit.getPlayer(name); if (nullVanished && plugin.al.vanished.contains(player) && !plugin.al.isAdmin(sender)) { return null; } - return Players.getPlayer(name); - } - - protected void msg(final CommandSender sender, final String message, final ChatColor color) - { - if (sender == null) - { - return; - } - sender.sendMessage(color + message); - } - - protected void msg(final CommandSender sender, final String message, final net.md_5.bungee.api.ChatColor color) - { - if (sender == null) - { - return; - } - sender.sendMessage(color + message); - } - - protected void msg(final String message, final net.md_5.bungee.api.ChatColor color) - { - msg(sender, message, color); - } - - protected void msg(final String message, final ChatColor color) - { - msg(sender, message, color); - } - - protected void msg(final CommandSender sender, final String message) - { - msg(sender, message, ChatColor.GRAY); - } - - protected void msg(final String message) - { - msg(sender, message); - } - - protected boolean isAdmin(CommandSender sender) - { - return plugin.al.isAdmin(sender); + return player; } protected Admin getAdmin(CommandSender sender) @@ -203,12 +331,16 @@ public abstract class FreedomCommand extends AbstractCommandBase> extends AbstractCommandExecutor -{ - - private final TotalFreedomMod plugin; - // - public static Map commandCooldown = new HashMap<>(); - public static final Timer timer = new Timer(); - - public FreedomCommandExecutor(TotalFreedomMod plugin, AeroCommandHandler handler, String name, C command) - { - super(handler, name, command); - this.plugin = plugin; - } - - protected FreedomCommand getCommand() - { - return commandBase instanceof FreedomCommand ? (FreedomCommand)commandBase : null; - } - - @Override - public void setupCommand(PluginCommand pluginCommand) - { - final FreedomCommand command = getCommand(); - if (command == null) - { - return; - } - - final CommandParameters params = command.getParams(); - if (params == null) - { - return; - } - - String aliasString = params.aliases(); - - if (aliasString.length() > 0) - { - pluginCommand.setAliases(Arrays.asList(params.aliases().split(","))); - } - pluginCommand.setDescription(params.description()); - pluginCommand.setUsage(params.usage()); - - // Check if permisions are correctly set up - CommandPermissions perms = command.getPerms(); - if (perms != null) - { - if (perms.level().isConsole()) - { - FLog.warning("[Command] " + pluginCommand.getName() + " - permission is set to a console rank, " - + "should be set to player variant with 'source = SourceType.ONLY_CONSOLE'"); - } - } - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) - { - if (!hasPermission(sender, true)) - { - return true; - } - - if (isOnCooldown(sender)) - { - return true; - } - - try - { - boolean run = commandBase.runCommand(sender, command, label, args); - FreedomCommand c = getCommand(); - CommandPermissions perms = c.getPerms(); - if (perms.cooldown() > 0 && !plugin.al.isAdmin(sender)) - { - commandCooldown.put(sender, c); - timer.schedule(new TimerTask() - { - @Override - public void run() - { - commandCooldown.remove(sender); - } - }, perms.cooldown() * 1000); - } - return run; - } - catch (Exception ex) - { - // If this is ever ran, TFM failed : - FLog.severe("Unhandled command exception: " + command.getName()); - FLog.severe(ex); - sender.sendMessage(ChatColor.RED + "Unhandled Command Error: " + command.getName()); - return true; - } - } - - @Override - public boolean hasPermission(CommandSender sender, boolean sendMsg) - { - final FreedomCommand command = getCommand(); - if (command == null) - { - return true; - } - - final CommandPermissions perms = command.getPerms(); - if (perms == null) - { - return true; - } - - // Block host console - if (FUtil.isFromHostConsole(sender.getName()) - && perms.blockHostConsole()) - { - if (sendMsg) - { - sender.sendMessage(handler.getPermissionMessage()); - } - return false; - } - - final Player player = sender instanceof Player ? (Player)sender : null; - - // Only console - if (perms.source() == SourceType.ONLY_CONSOLE - && player != null) - { - if (sendMsg) - { - sender.sendMessage(handler.getOnlyConsoleMessage()); - } - return false; - } - - // Only in game - if (perms.source() == SourceType.ONLY_IN_GAME - && player == null) - { - if (sendMsg) - { - sender.sendMessage(handler.getOnlyPlayerMessage()); - } - return false; - } - - // Player permissions - if (player != null) - { - Rank rank = plugin.rm.getRank(player); - boolean result = rank.isAtLeast(perms.level()); - if (!result && sendMsg) - { - sender.sendMessage(handler.getPermissionMessage()); - } - return result; - } - - // Console permissions - Rank rank = plugin.rm.getRank(sender); - boolean result = rank.isAtLeast(perms.level()); - if (!result && sendMsg) - { - sender.sendMessage(handler.getPermissionMessage()); - } - return result; - } - - public boolean isOnCooldown(CommandSender sender) - { - final FreedomCommand command = getCommand(); - if (commandCooldown.containsKey(sender) && commandCooldown.containsValue(command)) - { - sender.sendMessage(ChatColor.RED + "You're on cooldown for this command."); - return true; - } - return false; - } - - public static class FreedomExecutorFactory implements AeroCommandExecutorFactory - { - - private final TotalFreedomMod plugin; - - public FreedomExecutorFactory(TotalFreedomMod plugin) - { - this.plugin = plugin; - } - - @Override - public AeroCommandExecutor> newExecutor(AeroCommandHandler handler, String name, AeroCommandBase command) - { - return new FreedomCommandExecutor<>(plugin, handler, name, command); - } - - } - -} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/IConfig.java b/src/main/java/me/totalfreedom/totalfreedommod/config/IConfig.java new file mode 100644 index 00000000..8da9901e --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/config/IConfig.java @@ -0,0 +1,10 @@ +package me.totalfreedom.totalfreedommod.config; + +import org.bukkit.configuration.ConfigurationSection; + +public interface IConfig +{ + void loadFrom(ConfigurationSection cs); + void saveTo(ConfigurationSection cs); + boolean isValid(); +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/MainConfig.java b/src/main/java/me/totalfreedom/totalfreedommod/config/MainConfig.java index 8da95ec1..bfcf6cba 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/config/MainConfig.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/config/MainConfig.java @@ -6,14 +6,14 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.util.EnumMap; import java.util.List; +import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.util.FLog; -import net.pravian.aero.component.PluginComponent; import org.apache.commons.io.FileUtils; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; -public class MainConfig extends PluginComponent +public class MainConfig extends FreedomService { public static final String CONFIG_FILENAME = "config.yml"; @@ -22,10 +22,20 @@ public class MainConfig extends PluginComponent private final ConfigDefaults defaults; public YamlConfiguration configuration; + @Override + public void onStart() + { + + } + + @Override + public void onStop() + { + + } + public MainConfig(TotalFreedomMod plugin) { - super(plugin); - entries = new EnumMap<>(ConfigEntry.class); ConfigDefaults tempDefaults = null; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/YamlConfig.java b/src/main/java/me/totalfreedom/totalfreedommod/config/YamlConfig.java new file mode 100644 index 00000000..bd4585b8 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/config/YamlConfig.java @@ -0,0 +1,67 @@ +package me.totalfreedom.totalfreedommod.config; + +import java.io.File; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import org.bukkit.configuration.file.YamlConfiguration; + +public class YamlConfig extends YamlConfiguration +{ + private final TotalFreedomMod plugin; + private final File file; + private final boolean copyDefaults; + + public YamlConfig(TotalFreedomMod plugin, String name, boolean copyDefaults) + { + this.plugin = plugin; + this.file = new File(plugin.getDataFolder(), name); + this.copyDefaults = copyDefaults; + + if (copyDefaults) + { + options().copyDefaults(true); + } + + if (!file.exists()) + { + plugin.saveResource(name, false); + } + load(); + } + + public YamlConfig(TotalFreedomMod plugin, String name) + { + this(plugin, name, true); + } + + public void load() + { + try + { + super.load(file); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public void save() + { + try + { + super.save(file); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public void clear() + { + for (String key : super.getKeys(false)) + { + super.set(key, null); + } + } +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java index a777d22e..a7f06317 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java @@ -16,7 +16,6 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import javax.security.auth.login.LoginException; import me.totalfreedom.totalfreedommod.FreedomService; -import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.PlayerData; @@ -37,8 +36,8 @@ import net.dv8tion.jda.api.entities.SelfUser; import net.dv8tion.jda.api.events.ReadyEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.internal.utils.concurrent.CountingThreadFactory; -import net.pravian.aero.util.StringUtils; import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.WordUtils; import org.bukkit.GameRule; import org.bukkit.entity.Player; @@ -60,11 +59,6 @@ public class Discord extends FreedomService Random random = new Random(); - public Discord(TotalFreedomMod plugin) - { - super(plugin); - } - public void startBot() { enabled = !Strings.isNullOrEmpty(ConfigEntry.DISCORD_TOKEN.getString()); @@ -285,7 +279,7 @@ public class Discord extends FreedomService } @Override - protected void onStart() + public void onStart() { startBot(); } @@ -323,7 +317,7 @@ public class Discord extends FreedomService } @Override - protected void onStop() + public void onStop() { if (bot != null) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/freeze/Freezer.java b/src/main/java/me/totalfreedom/totalfreedommod/freeze/Freezer.java index 8e5b704f..1bbf20e2 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/freeze/Freezer.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/freeze/Freezer.java @@ -16,19 +16,14 @@ public class Freezer extends FreedomService @Getter private boolean globalFreeze = false; - public Freezer(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { globalFreeze = false; } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/CurseListener.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/CurseListener.java index 0f219a52..4574ca9d 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/CurseListener.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/CurseListener.java @@ -16,18 +16,13 @@ public class CurseListener extends FreedomService public HashMap cursedPlayers = new HashMap(); - public CurseListener(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java index bcb6cd13..c6d89a1d 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java @@ -89,18 +89,13 @@ public class ItemFun extends FreedomService return cooldownTracker.get(player.getName()).contains(item.getDataName()); } - public ItemFun(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/Jumppads.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/Jumppads.java index 89da7781..2f75c8d8 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/Jumppads.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/Jumppads.java @@ -27,11 +27,6 @@ public class Jumppads extends FreedomService private double strength = 1 + 0.1F; public HashMap players = new HashMap<>(); - public Jumppads(TotalFreedomMod plugin) - { - super(plugin); - } - @Override public void onStart() { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/Landminer.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/Landminer.java index afe11dfb..d8e347c3 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/Landminer.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/Landminer.java @@ -23,19 +23,14 @@ public class Landminer extends FreedomService @Getter private final List landmines = new ArrayList<>(); - public Landminer(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { landmines.clear(); } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/MP44.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/MP44.java index 763aa278..44790252 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/MP44.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/MP44.java @@ -8,19 +8,13 @@ import org.bukkit.event.player.PlayerQuitEvent; public class MP44 extends FreedomService { - - public MP44(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/MobStacker.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/MobStacker.java index 3885b066..7ae9a68f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/MobStacker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/MobStacker.java @@ -11,19 +11,13 @@ import org.bukkit.inventory.ItemStack; public class MobStacker extends FreedomService { - - public MobStacker(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java index 85536957..00c7fda3 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/Trailer.java @@ -20,18 +20,13 @@ public class Trailer extends FreedomService private final Random random = new Random(); private final Set trailPlayers = new HashSet<>(); // player name - public Trailer(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java index 867b0a96..d65b4a89 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java @@ -39,11 +39,6 @@ public class HTTPDaemon extends FreedomService private HTTPD httpd; public Map modules = new HashMap<>(); - public HTTPDaemon(TotalFreedomMod plugin) - { - super(plugin); - } - @Override public void onStart() { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/HTTPDModule.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/HTTPDModule.java index 36f2a848..74b3b2da 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/HTTPDModule.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/HTTPDModule.java @@ -3,15 +3,15 @@ package me.totalfreedom.totalfreedommod.httpd.module; import java.net.Socket; import java.util.HashMap; import java.util.Map; +import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.httpd.HTTPDPageBuilder; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.HTTPSession; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Method; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Response; import me.totalfreedom.totalfreedommod.util.FLog; -import net.pravian.aero.component.PluginComponent; -public abstract class HTTPDModule extends PluginComponent +public abstract class HTTPDModule extends FreedomService { protected final String uri; @@ -23,7 +23,6 @@ public abstract class HTTPDModule extends PluginComponent public HTTPDModule(TotalFreedomMod plugin, HTTPSession session) { - super(plugin); this.uri = session.getUri(); this.method = session.getMethod(); this.headers = session.getHeaders(); @@ -32,6 +31,16 @@ public abstract class HTTPDModule extends PluginComponent this.session = session; } + @Override + public void onStart() + { + } + + @Override + public void onStop() + { + } + public String getBody() { return null; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_admins.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_admins.java index 405617c5..064b109e 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_admins.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_admins.java @@ -1,9 +1,7 @@ package me.totalfreedom.totalfreedommod.httpd.module; -import java.io.File; import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.admin.Admin; -import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD; public class Module_admins extends HTTPDModule diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_help.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_help.java index 703b0b7e..19afdd68 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_help.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_help.java @@ -12,7 +12,6 @@ import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.command.FreedomCommand; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD; import me.totalfreedom.totalfreedommod.rank.Displayable; -import net.pravian.aero.command.CommandReflection; import org.apache.commons.lang.StringUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandMap; @@ -33,7 +32,7 @@ public class Module_help extends HTTPDModule @Override public String getBody() { - final CommandMap map = CommandReflection.getCommandMap(); + final CommandMap map = FreedomCommand.getCommandMap(); if (map == null || !(map instanceof SimpleCommandMap)) { return paragraph("Error loading commands."); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/permissions/PermissionConfig.java b/src/main/java/me/totalfreedom/totalfreedommod/permissions/PermissionConfig.java index bdcf3f9f..e1a004da 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/permissions/PermissionConfig.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/permissions/PermissionConfig.java @@ -6,14 +6,14 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.util.EnumMap; import java.util.List; +import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.util.FLog; -import net.pravian.aero.component.PluginComponent; import org.apache.commons.io.FileUtils; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; -public class PermissionConfig extends PluginComponent +public class PermissionConfig extends FreedomService { public static final String PERMISSIONS_FILENAME = "permissions.yml"; @@ -24,8 +24,6 @@ public class PermissionConfig extends PluginComponent public PermissionConfig(TotalFreedomMod plugin) { - super(plugin); - entries = new EnumMap<>(PermissionEntry.class); PermissionDefaults tempDefaults = null; @@ -59,6 +57,18 @@ public class PermissionConfig extends PluginComponent defaults = tempDefaults; } + @Override + public void onStart() + { + + } + + @Override + public void onStop() + { + + } + public void load() { try diff --git a/src/main/java/me/totalfreedom/totalfreedommod/permissions/PermissionManager.java b/src/main/java/me/totalfreedom/totalfreedommod/permissions/PermissionManager.java index fe421a3d..7b48562c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/permissions/PermissionManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/permissions/PermissionManager.java @@ -23,19 +23,14 @@ public class PermissionManager extends FreedomService public Map attachments = Maps.newHashMap(); - public PermissionManager(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { loadPermissionNodes(); } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/player/FPlayer.java b/src/main/java/me/totalfreedom/totalfreedommod/player/FPlayer.java index d341969c..00324db8 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/player/FPlayer.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/player/FPlayer.java @@ -9,7 +9,6 @@ import me.totalfreedom.totalfreedommod.caging.CageData; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.freeze.FreezeData; import me.totalfreedom.totalfreedommod.util.FUtil; -import net.pravian.aero.util.Ips; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Arrow; @@ -79,7 +78,7 @@ public class FPlayer public FPlayer(TotalFreedomMod plugin, Player player) { - this(plugin, player.getName(), Ips.getIp(player)); + this(plugin, player.getName(), FUtil.getIp(player)); } private FPlayer(TotalFreedomMod plugin, String name, String ip) @@ -100,7 +99,7 @@ public class FPlayer { for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { - if (Ips.getIp(onlinePlayer).equals(ip)) + if (FUtil.getIp(onlinePlayer).equals(ip)) { player = onlinePlayer; break; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerList.java b/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerList.java index 80dff508..a752e47f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerList.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerList.java @@ -14,7 +14,7 @@ import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FLog; -import net.pravian.aero.util.Ips; +import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -27,20 +27,15 @@ public class PlayerList extends FreedomService @Getter public final Map dataMap = Maps.newHashMap(); // username, data - public PlayerList(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { dataMap.clear(); loadMasterBuilders(); } @Override - protected void onStop() + public void onStop() { } @@ -79,7 +74,7 @@ public class PlayerList extends FreedomService { if (player.isOnline()) { - return Ips.getIp(player.getPlayer()); + return FUtil.getIp(player.getPlayer()); } final PlayerData entry = getData(player.getName()); @@ -128,14 +123,14 @@ public class PlayerList extends FreedomService // May not return null public FPlayer getPlayer(Player player) { - FPlayer tPlayer = playerMap.get(Ips.getIp(player)); + FPlayer tPlayer = playerMap.get(FUtil.getIp(player)); if (tPlayer != null) { return tPlayer; } tPlayer = new FPlayer(plugin, player); - playerMap.put(Ips.getIp(player), tPlayer); + playerMap.put(FUtil.getIp(player), tPlayer); return tPlayer; } @@ -164,7 +159,7 @@ public class PlayerList extends FreedomService PlayerData playerData = getData(player); return !plugin.al.isAdmin(player) && (playerData.hasVerification()) - && !playerData.getIps().contains(Ips.getIp(player)); + && !playerData.getIps().contains(FUtil.getIp(player)); } public boolean isImposter(Player player) @@ -179,7 +174,7 @@ public class PlayerList extends FreedomService { playerData.removeBackupCode(backupCode); } - playerData.addIp(Ips.getIp(player)); + playerData.addIp(FUtil.getIp(player)); save(playerData); if (plugin.al.isAdminImpostor(player)) @@ -194,7 +189,7 @@ public class PlayerList extends FreedomService } } admin.setLastLogin(new Date()); - admin.addIp(Ips.getIp(player)); + admin.addIp(FUtil.getIp(player)); plugin.al.updateTables(); plugin.al.save(admin); } @@ -257,7 +252,7 @@ public class PlayerList extends FreedomService if (playerData == null) { - playerData = loadByIp(Ips.getIp(player)); + playerData = loadByIp(FUtil.getIp(player)); if (playerData != null) { plugin.sql.updatePlayerName(playerData.getName(),player.getName()); @@ -279,7 +274,7 @@ public class PlayerList extends FreedomService // Create new player playerData = new PlayerData(player); - playerData.addIp(Ips.getIp(player)); + playerData.addIp(FUtil.getIp(player)); // Store player dataMap.put(player.getName(), playerData); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/punishments/Punishment.java b/src/main/java/me/totalfreedom/totalfreedommod/punishments/Punishment.java index bba9c3ca..f315f30f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/punishments/Punishment.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/punishments/Punishment.java @@ -5,12 +5,10 @@ import java.text.SimpleDateFormat; import java.util.Date; import lombok.Getter; import lombok.Setter; -import net.pravian.aero.base.ConfigLoadable; -import net.pravian.aero.base.ConfigSavable; -import net.pravian.aero.base.Validatable; +import me.totalfreedom.totalfreedommod.config.IConfig; import org.bukkit.configuration.ConfigurationSection; -public class Punishment implements ConfigLoadable, ConfigSavable, Validatable +public class Punishment implements IConfig { public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z"); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/punishments/PunishmentList.java b/src/main/java/me/totalfreedom/totalfreedommod/punishments/PunishmentList.java index dae9374f..dd6938c0 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/punishments/PunishmentList.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/punishments/PunishmentList.java @@ -5,9 +5,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; import me.totalfreedom.totalfreedommod.FreedomService; -import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.config.YamlConfig; import me.totalfreedom.totalfreedommod.util.FLog; -import net.pravian.aero.config.YamlConfig; public class PunishmentList extends FreedomService { @@ -18,14 +17,13 @@ public class PunishmentList extends FreedomService // private final YamlConfig config; - public PunishmentList(TotalFreedomMod plugin) + public PunishmentList() { - super(plugin); this.config = new YamlConfig(plugin, CONFIG_FILENAME); } @Override - protected void onStart() + public void onStart() { config.load(); @@ -54,7 +52,7 @@ public class PunishmentList extends FreedomService } @Override - protected void onStop() + public void onStop() { saveAll(); logger.info("Saved " + punishments.size() + " player bans"); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java b/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java index 2afae002..abd8f5d0 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java @@ -20,19 +20,13 @@ import org.bukkit.scoreboard.Team; public class RankManager extends FreedomService { - - public RankManager(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java b/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java index 1bbe8a6c..af8437b5 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java @@ -32,13 +32,8 @@ public class Shop extends FreedomService public Date reactionStartTime; public final int coinsPerReactionWin = ConfigEntry.SHOP_REACTIONS_COINS_PER_WIN.getInteger(); - public Shop(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { if (ConfigEntry.SHOP_REACTIONS_ENABLED.getBoolean()) { @@ -68,7 +63,7 @@ public class Shop extends FreedomService } @Override - protected void onStop() + public void onStop() { if (ConfigEntry.SHOP_REACTIONS_ENABLED.getBoolean()) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java b/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java index fa4ce745..9ef6e7e0 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java @@ -21,20 +21,15 @@ public class SQLite extends FreedomService private Connection connection; - public SQLite(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { connect(); checkTables(); } @Override - protected void onStop() + public void onStop() { disconnect(); } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/util/FLog.java b/src/main/java/me/totalfreedom/totalfreedommod/util/FLog.java index f58c1a50..0be5c19f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/util/FLog.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/util/FLog.java @@ -10,10 +10,6 @@ public class FLog private static Logger serverLogger = null; private static Logger pluginLogger = null; - private FLog() - { - } - // Level.INFO: public static void info(String message) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java index f83c2351..10d3dba2 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java @@ -40,6 +40,7 @@ import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.scheduler.BukkitTask; @@ -704,6 +705,16 @@ public class FUtil return tz < -12 || tz > 12; } + public static String getIp(Player player) + { + return player.getAddress().getAddress().getHostAddress().trim(); + } + + public static String getIp(PlayerLoginEvent event) + { + return event.getAddress().getHostAddress().trim(); + } + private static class MojangResponse { String id; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/CustomWorld.java b/src/main/java/me/totalfreedom/totalfreedommod/world/CustomWorld.java index e7909067..ec2ff8f2 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/CustomWorld.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/CustomWorld.java @@ -1,14 +1,13 @@ package me.totalfreedom.totalfreedommod.world; import lombok.Getter; -import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.util.FLog; -import net.pravian.aero.component.PluginComponent; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; -public abstract class CustomWorld extends PluginComponent +public abstract class CustomWorld extends FreedomService { @Getter @@ -21,6 +20,16 @@ public abstract class CustomWorld extends PluginComponent this.name = name; } + @Override + public void onStart() + { + } + + @Override + public void onStop() + { + } + public final World getWorld() { if (world == null || !Bukkit.getWorlds().contains(world)) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java b/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java index 45548150..3252c024 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java @@ -26,10 +26,8 @@ public class WorldManager extends FreedomService public MasterBuilderWorld masterBuilderWorld; public HubWorld hubworld; - public WorldManager(TotalFreedomMod plugin) + public WorldManager() { - super(plugin); - this.flatlands = new Flatlands(); this.adminworld = new AdminWorld(); this.masterBuilderWorld = new MasterBuilderWorld(); @@ -37,7 +35,7 @@ public class WorldManager extends FreedomService } @Override - protected void onStart() + public void onStart() { flatlands.getWorld(); adminworld.getWorld(); @@ -58,7 +56,7 @@ public class WorldManager extends FreedomService } @Override - protected void onStop() + public void onStop() { flatlands.getWorld().save(); adminworld.getWorld().save(); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/WorldRestrictions.java b/src/main/java/me/totalfreedom/totalfreedommod/world/WorldRestrictions.java index d8620742..1a26a3cd 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/WorldRestrictions.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/WorldRestrictions.java @@ -43,18 +43,13 @@ public class WorldRestrictions extends FreedomService put(net.goldtreeservers.worldguardextraflags.flags.Flags.WORLDEDIT, StateFlag.State.DENY); }}; - public WorldRestrictions(TotalFreedomMod plugin) - { - super(plugin); - } - @Override - protected void onStart() + public void onStart() { } @Override - protected void onStop() + public void onStop() { } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 77bb4df0..6dde1542 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,7 +2,6 @@ name: TotalFreedomMod main: me.totalfreedom.totalfreedommod.TotalFreedomMod version: ${project.version} description: Plugin for the Total Freedom server. -depend: [Aero] softdepend: [BukkitTelnet, Essentials, LibsDisguises, WorldEdit] authors: [Madgeek1450, Prozza] api-version: 1.15