diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index 7337f698..00c51f00 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -1,6 +1,5 @@ package me.totalfreedom.totalfreedommod; -import me.totalfreedom.totalfreedommod.admin.ActivityLog; import me.totalfreedom.totalfreedommod.admin.AdminList; import me.totalfreedom.totalfreedommod.api.Aggregator; import me.totalfreedom.totalfreedommod.api.ShoppeCommons; @@ -58,7 +57,6 @@ public class TotalFreedomMod extends JavaPlugin public CommandLoader cl; // Services public WorldManager wm; - public ActivityLog acl; public AdminList al; public RankManager rm; public CommandBlocker cb; @@ -285,7 +283,6 @@ public class TotalFreedomMod extends JavaPlugin wm = new WorldManager(); sql = new SQLite(); al = new AdminList(); - acl = new ActivityLog(); rm = new RankManager(); cb = new CommandBlocker(); eb = new EventBlocker(); diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLog.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLog.java deleted file mode 100644 index 8c29fdac..00000000 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLog.java +++ /dev/null @@ -1,212 +0,0 @@ -package me.totalfreedom.totalfreedommod.admin; - -import com.google.common.collect.Maps; -import java.util.Map; -import me.totalfreedom.totalfreedommod.FreedomService; -import me.totalfreedom.totalfreedommod.config.YamlConfig; -import me.totalfreedom.totalfreedommod.util.FLog; -import me.totalfreedom.totalfreedommod.util.FUtil; -import org.bukkit.command.CommandSender; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; - -public class ActivityLog extends FreedomService -{ - - public static final String FILENAME = "activitylog.yml"; - - private final Map allActivityLogs = Maps.newHashMap(); - private final Map nameTable = Maps.newHashMap(); - private final Map ipTable = Maps.newHashMap(); - - private final YamlConfig config; - - public ActivityLog() - { - this.config = new YamlConfig(plugin, FILENAME, true); - } - - public static String getFILENAME() - { - return FILENAME; - } - - @Override - public void onStart() - { - load(); - } - - @Override - public void onStop() - { - save(); - } - - public void load() - { - config.load(); - - allActivityLogs.clear(); - nameTable.clear(); - ipTable.clear(); - for (String key : config.getKeys(false)) - { - ConfigurationSection section = config.getConfigurationSection(key); - if (section == null) - { - FLog.warning("Invalid activity log format: " + key); - continue; - } - - ActivityLogEntry activityLogEntry = new ActivityLogEntry(key); - activityLogEntry.loadFrom(section); - - if (!activityLogEntry.isValid()) - { - FLog.warning("Could not load activity log: " + key + ". Missing details!"); - continue; - } - - allActivityLogs.put(key, activityLogEntry); - } - - updateTables(); - FLog.info("Loaded " + allActivityLogs.size() + " activity logs"); - } - - public void save() - { - // Clear the config - for (String key : config.getKeys(false)) - { - config.set(key, null); - } - - for (ActivityLogEntry activityLog : allActivityLogs.values()) - { - activityLog.saveTo(config.createSection(activityLog.getConfigKey())); - } - - config.save(); - } - - public ActivityLogEntry getActivityLog(CommandSender sender) - { - if (sender instanceof Player) - { - return getActivityLog((Player)sender); - } - - return getEntryByName(sender.getName()); - } - - public ActivityLogEntry getActivityLog(Player player) - { - ActivityLogEntry activityLog = getEntryByName(player.getName()); - if (activityLog == null) - { - String ip = FUtil.getIp(player); - activityLog = getEntryByIp(ip); - if (activityLog != null) - { - // Set the new username - activityLog.setName(player.getName()); - save(); - updateTables(); - } - else - { - activityLog = new ActivityLogEntry(player); - allActivityLogs.put(activityLog.getConfigKey(), activityLog); - updateTables(); - - activityLog.saveTo(config.createSection(activityLog.getConfigKey())); - config.save(); - } - } - String ip = FUtil.getIp(player); - if (!activityLog.getIps().contains(ip)) - { - activityLog.addIp(ip); - save(); - updateTables(); - } - return activityLog; - } - - public ActivityLogEntry getEntryByName(String name) - { - return nameTable.get(name.toLowerCase()); - } - - public ActivityLogEntry getEntryByIp(String ip) - { - return ipTable.get(ip); - } - - public void updateTables() - { - nameTable.clear(); - ipTable.clear(); - - for (ActivityLogEntry activityLog : allActivityLogs.values()) - { - nameTable.put(activityLog.getName().toLowerCase(), activityLog); - - for (String ip : activityLog.getIps()) - { - ipTable.put(ip, activityLog); - } - - } - } - - @EventHandler(priority = EventPriority.HIGH) - public void onPlayerJoin(PlayerJoinEvent event) - { - Player player = event.getPlayer(); - if (plugin.al.isAdmin(player)) - { - getActivityLog(event.getPlayer()).addLogin(); - plugin.acl.save(); - plugin.acl.updateTables(); - } - } - - @EventHandler(priority = EventPriority.HIGH) - public void onPlayerQuit(PlayerQuitEvent event) - { - Player player = event.getPlayer(); - if (plugin.al.isAdmin(player)) - { - getActivityLog(event.getPlayer()).addLogout(); - plugin.acl.save(); - plugin.acl.updateTables(); - } - } - - public Map getAllActivityLogs() - { - return allActivityLogs; - } - - public Map getNameTable() - { - return nameTable; - } - - public Map getIpTable() - { - return ipTable; - } - - public YamlConfig getConfig() - { - return config; - } -} \ No newline at end of file diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLogEntry.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLogEntry.java deleted file mode 100644 index eb056fcb..00000000 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLogEntry.java +++ /dev/null @@ -1,176 +0,0 @@ -package me.totalfreedom.totalfreedommod.admin; - -import com.google.common.collect.Lists; -import java.time.Instant; -import java.util.Date; -import java.util.List; -import me.totalfreedom.totalfreedommod.config.IConfig; -import me.totalfreedom.totalfreedommod.util.FUtil; -import org.apache.commons.lang.Validate; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.entity.Player; - -public class ActivityLogEntry implements IConfig -{ - - public static final String FILENAME = "activitylog.yml"; - private final List ips = Lists.newArrayList(); - private final List timestamps = Lists.newArrayList(); - private final List durations = Lists.newArrayList(); - private String configKey; - private String name; - - public ActivityLogEntry(Player player) - { - this.configKey = player.getName().toLowerCase(); - this.name = player.getName(); - } - - public ActivityLogEntry(String configKey) - { - this.configKey = configKey; - } - - public static String getFILENAME() - { - return FILENAME; - } - - public void loadFrom(Player player) - { - configKey = player.getName().toLowerCase(); - name = player.getName(); - } - - @Override - public void loadFrom(ConfigurationSection cs) - { - name = cs.getString("username", configKey); - ips.clear(); - ips.addAll(cs.getStringList("ips")); - timestamps.clear(); - timestamps.addAll(cs.getStringList("timestamps")); - durations.clear(); - durations.addAll(cs.getStringList("durations")); - } - - @Override - public void saveTo(ConfigurationSection cs) - { - Validate.isTrue(isValid(), "Could not save activity entry: " + name + ". Entry not valid!"); - cs.set("username", name); - cs.set("ips", Lists.newArrayList(ips)); - cs.set("timestamps", Lists.newArrayList(timestamps)); - cs.set("durations", Lists.newArrayList(durations)); - } - - public void addLogin() - { - Date currentTime = Date.from(Instant.now()); - timestamps.add("Login: " + FUtil.dateToString(currentTime)); - } - - public void addLogout() - { - // Fix of Array index out of bonds issue: FS-131 - String lastLoginString; - if(timestamps.size() > 1) - { - lastLoginString = timestamps.get(timestamps.size() - 1); - }else - { - lastLoginString = timestamps.get(0); - } - Date currentTime = Date.from(Instant.now()); - timestamps.add("Logout: " + FUtil.dateToString(currentTime)); - lastLoginString = lastLoginString.replace("Login: ", ""); - Date lastLogin = FUtil.stringToDate(lastLoginString); - - long duration = currentTime.getTime() - lastLogin.getTime(); - long seconds = duration / 1000 % 60; - long minutes = duration / (60 * 1000) % 60; - long hours = duration / (60 * 60 * 1000); - durations.add(hours + " hours, " + minutes + " minutes, and " + seconds + " seconds"); - } - - public void addIp(String ip) - { - if (!ips.contains(ip)) - { - ips.add(ip); - } - } - - public void addIps(List ips) - { - for (String ip : ips) - { - addIp(ip); - } - } - - public void removeIp(String ip) - { - ips.remove(ip); - } - - public void clearIPs() - { - ips.clear(); - } - - public int getTotalSecondsPlayed() - { - int result = 0; - for (String duration : durations) - { - String[] spl = duration.split(" "); - result += Integer.parseInt(spl[0]) * 60 * 60; - result += Integer.parseInt(spl[2]) * 60; - result += Integer.parseInt(spl[5]); - } - return result; - } - - @Override - public boolean isValid() - { - return configKey != null - && name != null; - } - - public String getConfigKey() - { - return configKey; - } - - public void setConfigKey(String configKey) - { - this.configKey = configKey; - } - - public String getName() - { - return name; - } - - public void setName(String name) - { - this.name = name; - } - - public List getIps() - { - return ips; - } - - public List getTimestamps() - { - return timestamps; - } - - public List getDurations() - { - return durations; - } -} diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java index 1726bb59..e691443a 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java @@ -7,6 +7,7 @@ import java.util.List; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.world.WorldTime; import me.totalfreedom.totalfreedommod.world.WorldWeather; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -67,12 +68,12 @@ public class Command_adminworld extends FreedomCommand if (adminWorld == null || playerSender.getWorld() == adminWorld) { - msg("Going to the main world."); + msgNew("Going to the main world."); PaperLib.teleportAsync(playerSender, server.getWorlds().get(0).getSpawnLocation()); } else { - msg("Going to the AdminWorld."); + msgNew("Going to the AdminWorld."); plugin.wm.adminworld.sendToWorld(playerSender); } break; @@ -87,11 +88,11 @@ public class Command_adminworld extends FreedomCommand if (timeOfDay != null) { plugin.wm.adminworld.setTimeOfDay(timeOfDay); - msg("AdminWorld time set to: " + timeOfDay.name()); + msgNew("AdminWorld time set to: