From 6c983f6b97f93f1316ff9b31ac377a03d1f97804 Mon Sep 17 00:00:00 2001 From: Video Date: Mon, 27 Mar 2023 23:23:34 -0600 Subject: [PATCH] I was on a development roll and now I need to sleep - Removes commands /aec, /attributelist, /reactionbar, /playtime, /settotalvotes, /status - Removes unused activity log functionality - Migrates many more commands to use MiniMessage - Merges /disguisetoggle with /toggle - Reimplements explosive arrows in a much better way --- .../totalfreedommod/TotalFreedomMod.java | 3 - .../totalfreedommod/admin/ActivityLog.java | 212 ------------------ .../admin/ActivityLogEntry.java | 176 --------------- .../command/Command_adminworld.java | 15 +- .../command/Command_aeclear.java | 36 --- .../command/Command_attributelist.java | 22 -- .../totalfreedommod/command/Command_ban.java | 17 +- .../command/Command_banname.java | 3 +- .../command/Command_blockedit.java | 39 ++-- .../command/Command_blockpvp.java | 171 ++++++-------- .../totalfreedommod/command/Command_cage.java | 4 +- .../command/Command_cleanchat.java | 2 +- .../command/Command_cleardiscordqueue.java | 2 +- .../command/Command_clearinventory.java | 16 +- .../command/Command_cookie.java | 43 +--- .../command/Command_denick.java | 2 +- .../totalfreedommod/command/Command_deop.java | 2 +- .../command/Command_disguisetoggle.java | 38 ---- .../command/Command_dispfill.java | 19 +- .../totalfreedommod/command/Command_doom.java | 6 +- .../command/Command_eject.java | 7 +- .../command/Command_enchant.java | 49 ++-- .../command/Command_entitywipe.java | 8 +- .../command/Command_expel.java | 7 +- .../command/Command_explosivearrows.java | 24 +- .../command/Command_findip.java | 6 +- .../command/Command_fireball.java | 12 +- .../command/Command_flatlands.java | 2 +- .../totalfreedommod/command/Command_glow.java | 4 +- .../command/Command_indefban.java | 4 +- .../command/Command_inspect.java | 7 +- .../command/Command_lockup.java | 9 +- .../command/Command_manageshop.java | 88 ++++++-- .../totalfreedommod/command/Command_mute.java | 62 ++--- .../command/Command_nicknyan.java | 13 +- .../command/Command_nickrainbow.java | 11 +- .../totalfreedommod/command/Command_ops.java | 29 +-- .../command/Command_playtime.java | 79 ------- .../command/Command_reactionbar.java | 32 --- .../command/Command_report.java | 11 +- .../totalfreedommod/command/Command_ride.java | 43 ++-- .../command/Command_saconfig.java | 33 +-- .../totalfreedommod/command/Command_say.java | 26 +-- .../command/Command_scare.java | 29 +-- .../command/Command_setlimit.java | 31 +-- .../command/Command_setplayerlimit.java | 28 +-- .../command/Command_setspawnworld.java | 4 +- .../command/Command_settotalvotes.java | 63 ------ .../totalfreedommod/command/Command_shop.java | 5 +- .../command/Command_smite.java | 11 - .../command/Command_spectate.java | 3 +- .../command/Command_stackingpotato.java | 11 +- .../command/Command_status.java | 29 --- .../command/Command_stopsound.java | 2 +- .../command/Command_toggle.java | 20 +- .../command/Command_togglediscord.java | 4 +- .../command/Command_togglepickup.java | 3 +- .../command/Command_tossmob.java | 2 +- .../command/Command_totalfreedommod.java | 40 ++-- .../command/FreedomCommand.java | 19 +- .../totalfreedommod/fun/ItemFun.java | 4 +- .../totalfreedommod/httpd/HTTPDaemon.java | 2 - .../httpd/module/Module_activitylog.java | 44 ---- .../totalfreedommod/player/FPlayer.java | 11 + commons/src/main/resources/activitylog.yml | 3 - 65 files changed, 495 insertions(+), 1267 deletions(-) delete mode 100644 commons/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLog.java delete mode 100644 commons/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLogEntry.java delete mode 100644 commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_aeclear.java delete mode 100644 commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_attributelist.java delete mode 100644 commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_disguisetoggle.java delete mode 100644 commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_playtime.java delete mode 100644 commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_reactionbar.java delete mode 100644 commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_settotalvotes.java delete mode 100644 commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_status.java delete mode 100644 commons/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_activitylog.java delete mode 100644 commons/src/main/resources/activitylog.yml 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: