From 533e4fe369816c1e3c114d94f67d272177b5c27c Mon Sep 17 00:00:00 2001 From: Seth <13510767+ZeroEpoch1969@users.noreply.github.com> Date: Fri, 2 Oct 2020 02:27:06 -0700 Subject: [PATCH 01/12] Login messages for players. Still need to come up with login messaghes --- .../command/Command_loginmessage.java | 52 ++++++++++++++++ ...mand_mystaff.java => Command_myadmin.java} | 50 +-------------- .../totalfreedommod/config/ConfigEntry.java | 7 +-- .../httpd/module/Module_list.java | 4 +- .../httpd/module/Module_players.java | 2 +- .../totalfreedommod/player/PlayerData.java | 23 +++---- .../totalfreedommod/rank/Displayable.java | 5 +- .../totalfreedommod/rank/Rank.java | 26 +++++--- .../totalfreedommod/rank/RankManager.java | 35 +++++++---- .../totalfreedommod/rank/Title.java | 21 +++++-- .../totalfreedommod/shop/Shop.java | 62 ++++++++++++++++++- .../totalfreedommod/shop/ShopItem.java | 7 ++- .../totalfreedommod/sql/SQLite.java | 41 +++++++----- .../totalfreedommod/staff/StaffMember.java | 11 ---- .../totalfreedommod/util/FUtil.java | 4 +- src/main/resources/config.yml | 12 ++-- 16 files changed, 228 insertions(+), 134 deletions(-) create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/command/Command_loginmessage.java rename src/main/java/me/totalfreedom/totalfreedommod/command/{Command_mystaff.java => Command_myadmin.java} (79%) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_loginmessage.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_loginmessage.java new file mode 100644 index 00000000..c3e4987b --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_loginmessage.java @@ -0,0 +1,52 @@ +package me.totalfreedom.totalfreedommod.command; + +import me.totalfreedom.totalfreedommod.player.PlayerData; +import me.totalfreedom.totalfreedommod.rank.Rank; +import me.totalfreedom.totalfreedommod.shop.ShopItem; +import org.apache.commons.lang.StringUtils; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME) +@CommandParameters(description = "Change your login message", usage = "/ [message]") +public class Command_loginmessage extends FreedomCommand +{ + + @Override + public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + if (!plugin.pl.getData(playerSender).hasItem(ShopItem.LOGIN_MESSAGES) && !isStaff(playerSender)) + { + msg("You did not purchase the ability to use login messages! Purchase the ability from the shop.", ChatColor.RED); + return true; + } + + if (args.length == 0) + { + playerSender.openInventory(plugin.sh.generateLoginMessageGUI(playerSender)); + return true; + } + + checkRank(Rank.ADMIN); + + String message = StringUtils.join(args, " "); + if (!message.contains("%rank%") && !message.contains("%coloredrank%")) + { + msg("Your login message must contain your rank. Use either %rank% or %coloredrank% to specify where you want the rank", ChatColor.RED); + return true; + } + int length = message.replace("%name%", "").replace("%rank%", "").replace("%coloredrank%", "").replace("%det%", "").length(); + if (length > 100) + { + msg("Your login message cannot be more than 100 characters (excluding your rank and your name)", ChatColor.RED); + return true; + } + PlayerData data = getData(playerSender); + data.setLoginMessage(message); + plugin.pl.save(data); + msg("Your login message is now the following:\n" + plugin.rm.craftLoginMessage(playerSender, message), ChatColor.GREEN); + return true; + } +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mystaff.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myadmin.java similarity index 79% rename from src/main/java/me/totalfreedom/totalfreedommod/command/Command_mystaff.java rename to src/main/java/me/totalfreedom/totalfreedommod/command/Command_myadmin.java index 5beb27ed..2483494e 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mystaff.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_myadmin.java @@ -17,7 +17,7 @@ import org.bukkit.entity.Player; @CommandPermissions(level = Rank.ADMIN, source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Manage your staff entry.", usage = "/ [-o ] | setlogin | clearlogin | setscformat | clearscformat> | oldtags | logstick | syncroles>") -public class Command_mystaff extends FreedomCommand +public class Command_myadmin extends FreedomCommand { @Override @@ -139,46 +139,6 @@ public class Command_mystaff extends FreedomCommand return true; } - case "setlogin": - { - checkRank(Rank.ADMIN); - if (args.length < 2) - { - return false; - } - - String message = StringUtils.join(args, " ", 1, args.length); - if (!message.contains("%rank%") && !message.contains("%coloredrank%")) - { - msg("Your login message must contain your rank. Use either %rank% or %coloredrank% to specify where you want the rank", ChatColor.RED); - return true; - } - int length = message.replace("%name%", "").replace("%rank%", "").replace("%coloredrank%", "").length(); - if (length > 100) - { - msg("Your login message cannot be more than 100 characters (excluding your rank and your name)", ChatColor.RED); - return true; - } - FUtil.staffAction(sender.getName(), "Setting personal login message" + (init == null ? "" : " for " + targetPlayer.getName()), false); - target.setLoginMessage(message); - String previewMessage = plugin.rm.craftLoginMessage(targetPlayer, message); - msg((init == null ? "Your" : targetPlayer.getName() + "'s") + " login message is now: "); - msg("> " + previewMessage); - plugin.sl.save(target); - plugin.sl.updateTables(); - return true; - } - - case "clearlogin": - { - checkRank(Rank.ADMIN); - FUtil.staffAction(sender.getName(), "Clearing personal login message" + (init == null ? "" : " for " + targetPlayer.getName()), false); - target.setLoginMessage(null); - plugin.sl.save(target); - plugin.sl.updateTables(); - return true; - } - case "setscformat": { String format = StringUtils.join(args, " ", 1, args.length); @@ -229,10 +189,6 @@ public class Command_mystaff extends FreedomCommand return true; } - case "genbackupcodes": - msg("Moved to /pv genbackupcodes", ChatColor.RED); - return true; - default: { return false; @@ -248,8 +204,8 @@ public class Command_mystaff extends FreedomCommand return Collections.emptyList(); } - List singleArguments = Arrays.asList("clearips", "setlogin", "setscformat"); - List doubleArguments = Arrays.asList("clearip", "clearlogin", "clearscformat", "oldtags", "syncroles"); + List singleArguments = Arrays.asList("clearips", "setscformat"); + List doubleArguments = Arrays.asList("clearip", "clearscformat", "syncroles"); if (args.length == 1) { List options = new ArrayList<>(); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java index 872d5f62..929a693c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java @@ -99,11 +99,6 @@ public enum ConfigEntry PTERO_ADMIN_KEY(String.class, "ptero.admin_key"), PTERO_SERVER_KEY(String.class, "ptero.server_key"), // - DONATION_PROBOARDS_URL(String.class, "donation.proboards_url"), - DONATION_GROUP_ID(String.class, "donation.donator_group_id"), - DONATION_SESSION_ID(String.class, "donation.session_id"), - DONATION_CSRF_TOKEN(String.class, "donation.csrf_token"), - // SHOP_ENABLED(Boolean.class, "shop.enabled"), SHOP_TITLE(String.class, "shop.title"), SHOP_PREFIX(String.class, "shop.prefix"), @@ -113,12 +108,14 @@ public enum ConfigEntry SHOP_REACTIONS_TIME(Double.class, "shop.reactions.time"), SHOP_REACTIONS_COINS_PER_WIN(Integer.class, "shop.reactions.coins_per_win"), SHOP_REACTIONS_STRING_LENGTH(Integer.class, "shop.reactions.string_length"), + SHOP_LOGIN_MESSAGES(List.class, "shop.login_messages"), SHOP_PRICES_GRAPPLING_HOOK(Integer.class, "shop.prices.grappling_hook"), SHOP_PRICES_LIGHTNING_ROD(Integer.class, "shop.prices.lightning_rod"), SHOP_PRICES_FIRE_BALL(Integer.class, "shop.prices.fire_ball"), SHOP_PRICES_RIDEABLE_PEARL(Integer.class, "shop.prices.rideable_pearl"), SHOP_PRICES_STACKING_POTATO(Integer.class, "shop.prices.stacking_potato"), SHOP_PRICES_CLOWN_FISH(Integer.class, "shop.prices.clown_fish"), + SHOP_PRICES_LOGIN_MESSAGES(Integer.class, "shop.prices.login_messages"), // STAFFLIST_CLEAN_THESHOLD_HOURS(Integer.class, "stafflist.clean_threshold_hours"), STAFFLIST_CONSOLE_IS_ADMIN(Boolean.class, "stafflist.console_is_admin"), diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_list.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_list.java index 4ce26f86..c8cb29fb 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_list.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_list.java @@ -73,7 +73,7 @@ public class Module_list extends HTTPDModule operators.add(player.getName()); } - if (!hasSpecialTitle(player) && plugin.sl.isStaff(player)) + if (!hasSpecialTitle(player) && plugin.sl.isStaff(player) && !plugin.sl.isVanished(player.getName())) { StaffMember staffMember = plugin.sl.getAdmin(player); switch (staffMember.getRank()) @@ -142,7 +142,7 @@ public class Module_list extends HTTPDModule public boolean hasSpecialTitle(Player player) { - if (FUtil.DEVELOPERS.contains(player.getName()) || ConfigEntry.SERVER_EXECUTIVES.getList().contains(player.getName()) || ConfigEntry.SERVER_OWNERS.getList().contains(player.getName())) + if (FUtil.DEVELOPERS.contains(player.getUniqueId().toString()) || ConfigEntry.SERVER_EXECUTIVES.getList().contains(player.getName()) || ConfigEntry.SERVER_OWNERS.getList().contains(player.getName())) { return true; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_players.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_players.java index 8e09263d..89003d18 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_players.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_players.java @@ -64,7 +64,7 @@ public class Module_players extends HTTPDModule masterbuilders.addAll(plugin.pl.getMasterBuilderNames()); // Developers - developers.addAll(FUtil.DEVELOPERS); + developers.addAll(FUtil.DEVELOPER_NAMES); // Executives executives.addAll(ConfigEntry.SERVER_EXECUTIVES.getList()); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java b/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java index 8bac6c98..789c9af9 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java @@ -33,8 +33,6 @@ public class PlayerData private String discordID = null; private final List backupCodes = Lists.newArrayList(); @Setter - private boolean donator = false; - @Setter private Boolean masterBuilder = false; @Setter private Boolean verification = false; @@ -53,6 +51,9 @@ public class PlayerData @Getter @Setter private String redditUsername; + @Getter + @Setter + private String loginMessage; public PlayerData(ResultSet resultSet) { @@ -67,7 +68,6 @@ public class PlayerData discordID = resultSet.getString("discord_id"); backupCodes.clear(); backupCodes.addAll(FUtil.stringToList(resultSet.getString("backup_codes"))); - donator = resultSet.getBoolean("donator"); masterBuilder = resultSet.getBoolean("master_builder"); verification = resultSet.getBoolean("verification"); rideMode = resultSet.getString("ride_mode"); @@ -77,6 +77,7 @@ public class PlayerData totalVotes = resultSet.getInt("total_votes"); displayDiscord = resultSet.getBoolean("display_discord"); redditUsername = resultSet.getString("reddit_username"); + loginMessage = resultSet.getString("login_message"); } catch (SQLException e) { @@ -104,7 +105,6 @@ public class PlayerData output.append("Player: ").append(name).append("\n") .append("- IPs: ").append(StringUtils.join(ips, ", ")).append("\n") .append("- Discord ID: ").append(discordID).append("\n") - .append("- Donator: ").append(donator).append("\n") .append("- Master Builder: ").append(masterBuilder).append("\n") .append("- Has Verification: ").append(verification).append("\n") .append("- Coins: ").append(coins).append("\n") @@ -113,7 +113,8 @@ public class PlayerData .append("- Tag: ").append(FUtil.colorize(tag)).append(ChatColor.GRAY).append("\n") .append("- Ride Mode: ").append(rideMode).append("\n") .append("- Backup Codes: ").append(backupCodes.size()).append("/10").append("\n") - .append("- Reddit Username: ").append(redditUsername); + .append("- Reddit Username: ").append(redditUsername) + .append("- Login Message: ").append(loginMessage); return output.toString(); } @@ -128,6 +129,11 @@ public class PlayerData return Collections.unmodifiableList(ips); } + public boolean hasLoginMessage() + { + return loginMessage != null && !loginMessage.isEmpty(); + } + public boolean addIp(String ip) { return !ips.contains(ip) && ips.add(ip); @@ -221,11 +227,6 @@ public class PlayerData return verification; } - public boolean isDonator() - { - return donator; - } - public boolean isMasterBuilder() { return masterBuilder; @@ -241,7 +242,6 @@ public class PlayerData put("tag", tag); put("discord_id", discordID); put("backup_codes", FUtil.listToString(backupCodes)); - put("donator", donator); put("master_builder", masterBuilder); put("verification", verification); put("ride_mode", rideMode); @@ -250,6 +250,7 @@ public class PlayerData put("total_votes", totalVotes); put("display_discord", displayDiscord); put("reddit_username", redditUsername); + put("login_message", loginMessage); }}; return map; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/rank/Displayable.java b/src/main/java/me/totalfreedom/totalfreedommod/rank/Displayable.java index 863e573f..db4ea54e 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/rank/Displayable.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/rank/Displayable.java @@ -5,6 +5,8 @@ import net.md_5.bungee.api.ChatColor; public interface Displayable { + public String getDeterminer(); + public String getName(); public String getTag(); @@ -21,7 +23,8 @@ public interface Displayable public String getColoredLoginMessage(); - public boolean hasTeam(); + public boolean hasDefaultLoginMessage(); + } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/rank/Rank.java b/src/main/java/me/totalfreedom/totalfreedommod/rank/Rank.java index abfd706e..cbedc2d4 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/rank/Rank.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/rank/Rank.java @@ -5,19 +5,20 @@ import net.md_5.bungee.api.ChatColor; public enum Rank implements Displayable { - IMPOSTOR("an", "Impostor", Type.PLAYER, "Imp", ChatColor.YELLOW, null, false), - NON_OP("a", "Non-Op", Type.PLAYER, "", ChatColor.WHITE, null, false), - OP("an", "Operator", Type.PLAYER, "OP", ChatColor.GREEN, null, false), - ADMIN("an", "Admin", Type.STAFF, "Admin", ChatColor.DARK_GREEN, org.bukkit.ChatColor.DARK_GREEN, true), - SENIOR_ADMIN("a", "Senior Admin", Type.STAFF, "SrA", ChatColor.GOLD, org.bukkit.ChatColor.GOLD, true), - ADMIN_CONSOLE("the", "Console", Type.STAFF_CONSOLE, "Console", ChatColor.DARK_PURPLE, null, false), - SENIOR_CONSOLE("the", "Console", Type.STAFF_CONSOLE, "Console", ChatColor.DARK_PURPLE, null, false); + IMPOSTOR("an", "Impostor", Type.PLAYER, "Imp", ChatColor.YELLOW, null, false, false), + NON_OP("a", "Non-Op", Type.PLAYER, "", ChatColor.WHITE, null, false, false), + OP("an", "Operator", Type.PLAYER, "OP", ChatColor.GREEN, null, false, false), + ADMIN("an", "Admin", Type.STAFF, "Admin", ChatColor.DARK_GREEN, org.bukkit.ChatColor.DARK_GREEN, true, true), + SENIOR_ADMIN("a", "Senior Admin", Type.STAFF, "SrA", ChatColor.GOLD, org.bukkit.ChatColor.GOLD, true, true), + ADMIN_CONSOLE("the", "Console", Type.STAFF_CONSOLE, "Console", ChatColor.DARK_PURPLE, null, false, false), + SENIOR_CONSOLE("the", "Console", Type.STAFF_CONSOLE, "Console", ChatColor.DARK_PURPLE, null, false, false); @Getter private final Type type; @Getter private final String name; @Getter private final String abbr; + @Getter private final String determiner; @Getter private final String tag; @@ -29,8 +30,10 @@ public enum Rank implements Displayable private final org.bukkit.ChatColor teamColor; @Getter private final boolean hasTeam; + @Getter + private final boolean hasDefaultLoginMessage; - Rank(String determiner, String name, Type type, String abbr, ChatColor color, org.bukkit.ChatColor teamColor, Boolean hasTeam) + Rank(String determiner, String name, Type type, String abbr, ChatColor color, org.bukkit.ChatColor teamColor, Boolean hasTeam, Boolean hasDefaultLoginMessage) { this.type = type; this.name = name; @@ -41,6 +44,7 @@ public enum Rank implements Displayable this.color = color; this.teamColor = teamColor; this.hasTeam = hasTeam; + this.hasDefaultLoginMessage = hasDefaultLoginMessage; } @Override @@ -61,6 +65,12 @@ public enum Rank implements Displayable return hasTeam; } + @Override + public boolean hasDefaultLoginMessage() + { + return hasDefaultLoginMessage; + } + @Override public String getAbbr() { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java b/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java index 7d6bb30a..b099e187 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java @@ -168,7 +168,7 @@ public class RankManager extends FreedomService FPlayer fPlayer = plugin.pl.getPlayer(player); PlayerData data = plugin.pl.getData(player); Displayable display = getDisplay(player); - if (plugin.sl.isStaff(player) || data.isMasterBuilder() || data.isDonator() || FUtil.isDeveloper(player)) + if (plugin.sl.isStaff(player) || data.isMasterBuilder() || FUtil.isDeveloper(player)) { String displayName = display.getColor() + player.getName(); player.setPlayerListName(displayName); @@ -237,7 +237,7 @@ public class RankManager extends FreedomService } // Broadcast login message - if (isStaff || FUtil.isDeveloper(player) || plugin.pl.getData(player).isMasterBuilder() || plugin.pl.getData(player).isDonator()) + if (isStaff || FUtil.isDeveloper(player) || plugin.pl.getData(player).isMasterBuilder() || plugin.pl.getData(player).hasLoginMessage()) { if (!plugin.sl.isVanished(player.getName())) { @@ -260,23 +260,32 @@ public class RankManager extends FreedomService public String craftLoginMessage(Player player, String message) { Displayable display = plugin.rm.getDisplay(player); - String loginMessage = ChatColor.AQUA + player.getName() + " is " + display.getColoredLoginMessage(); - if (plugin.sl.isStaff(player)) + PlayerData playerData = plugin.pl.getData(player); + if (message == null) { - StaffMember staffMember = plugin.sl.getAdmin(player); - if (staffMember.hasLoginMessage()) + if (playerData.hasLoginMessage()) { - if (message == null) + message = playerData.getLoginMessage(); + } + else + { + if (display.hasDefaultLoginMessage()) { - message = staffMember.getLoginMessage(); + message = "%name% is %det% %coloredrank%"; } - loginMessage = FUtil.colorize(ChatColor.AQUA + (message.contains("%name%") ? "" : player.getName() + " is ") - + FUtil.colorize(message).replace("%name%", player.getName()) - .replace("%rank%", display.getName()) - .replace("%coloredrank%", display.getColoredName())); } } - return loginMessage; + if (message != null) + { + String loginMessage = FUtil.colorize(ChatColor.AQUA + (message.contains("%name%") ? "" : player.getName() + " is ") + + FUtil.colorize(message).replace("%name%", player.getName()) + .replace("%rank%", display.getName()) + .replace("%coloredrank%", display.getColoredName()) + .replace("%det%", display.getDeterminer())); + return loginMessage; + } + + return null; } public void updatePlayerTeam(Player player) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java b/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java index ff6fc3bf..6f67e7e3 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java @@ -6,12 +6,13 @@ import net.md_5.bungee.api.ChatColor; public enum Title implements Displayable { - MASTER_BUILDER("a", "Master Builder", ChatColor.DARK_AQUA, org.bukkit.ChatColor.DARK_AQUA, "MB", true), - VERIFIED_STAFF("a", "Verified Staff", ChatColor.LIGHT_PURPLE, org.bukkit.ChatColor.LIGHT_PURPLE, "VS", false), - EXECUTIVE("an", "Executive", ChatColor.RED, org.bukkit.ChatColor.RED, "Exec", true), - DEVELOPER("a", "Developer", ChatColor.DARK_PURPLE, org.bukkit.ChatColor.DARK_PURPLE, "Dev", true), - OWNER("the", "Owner", ChatColor.of("#ff0000"), org.bukkit.ChatColor.DARK_RED, "Owner", true); + MASTER_BUILDER("a", "Master Builder", ChatColor.DARK_AQUA, org.bukkit.ChatColor.DARK_AQUA, "MB", true, true), + VERIFIED_STAFF("a", "Verified Staff Member", ChatColor.LIGHT_PURPLE, org.bukkit.ChatColor.LIGHT_PURPLE, "VS", false, true), + EXECUTIVE("an", "Executive", ChatColor.RED, org.bukkit.ChatColor.RED, "Exec", true, true), + DEVELOPER("a", "Developer", ChatColor.DARK_PURPLE, org.bukkit.ChatColor.DARK_PURPLE, "Dev", true, true), + OWNER("the", "Owner", ChatColor.of("#ff0000"), org.bukkit.ChatColor.DARK_RED, "Owner", true, true); + @Getter private final String determiner; @Getter private final String name; @@ -27,8 +28,9 @@ public enum Title implements Displayable private final org.bukkit.ChatColor teamColor; @Getter private final boolean hasTeam; + private final boolean hasDefaultLoginMessage; - Title(String determiner, String name, ChatColor color, org.bukkit.ChatColor teamColor, String tag, Boolean hasTeam) + Title(String determiner, String name, ChatColor color, org.bukkit.ChatColor teamColor, String tag, Boolean hasTeam, Boolean hasDefaultLoginMessage) { this.determiner = determiner; this.name = name; @@ -38,6 +40,7 @@ public enum Title implements Displayable this.color = color; this.teamColor = teamColor; this.hasTeam = hasTeam; + this.hasDefaultLoginMessage = hasDefaultLoginMessage; } @Override @@ -52,6 +55,12 @@ public enum Title implements Displayable return hasTeam; } + @Override + public boolean hasDefaultLoginMessage() + { + return hasDefaultLoginMessage; + } + @Override public String getColoredLoginMessage() { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java b/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java index aa0a73b2..2e92cd63 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java @@ -35,6 +35,7 @@ public class Shop extends FreedomService public final String prefix = ChatColor.DARK_GRAY + "[" + ChatColor.YELLOW + "Reaction" + ChatColor.DARK_GRAY + "] "; public BukkitTask countdownTask; private BossBar countdownBar = null; + private final String LOGIN_MESSAGE_GUI_TITLE = ChatColor.DARK_GREEN + ChatColor.BOLD.toString() + "Login Messages"; @Override public void onStart() @@ -174,6 +175,27 @@ public class Shop extends FreedomService return gui; } + public Inventory generateLoginMessageGUI(Player player) + { + Inventory gui = server.createInventory(null, 36, LOGIN_MESSAGE_GUI_TITLE); + int slot = 0; + for (String loginMessage : ConfigEntry.SHOP_LOGIN_MESSAGES.getStringList()) + { + ItemStack icon = new ItemStack(Material.NAME_TAG); + ItemMeta meta = icon.getItemMeta(); + meta.setDisplayName(FUtil.colorize(plugin.rm.craftLoginMessage(player, loginMessage))); + icon.setItemMeta(meta); + gui.setItem(slot, icon); + slot++; + } + ItemStack clear = new ItemStack(Material.BARRIER); + ItemMeta meta = clear.getItemMeta(); + meta.setDisplayName(ChatColor.RED + "Clear login message"); + clear.setItemMeta(meta); + gui.setItem(35, clear); + return gui; + } + public boolean isRealItem(PlayerData data, ShopItem shopItem, PlayerInventory inventory, ItemStack realItem) { if (isRealItem(data, shopItem, inventory.getItemInMainHand(), realItem) || isRealItem(data, shopItem, inventory.getItemInOffHand(), realItem)) @@ -306,7 +328,7 @@ public class Shop extends FreedomService } @EventHandler(priority = EventPriority.HIGH) - public void onInventoryClick(InventoryClickEvent event) + public void onShopGUIClick(InventoryClickEvent event) { if (!(event.getWhoClicked() instanceof Player)) { @@ -350,6 +372,44 @@ public class Shop extends FreedomService } } + @EventHandler(priority = EventPriority.HIGH) + public void onLoginMessageGUIClick(InventoryClickEvent event) + { + if (!(event.getWhoClicked() instanceof Player)) + { + return; + } + + Inventory inventory = event.getInventory(); + if (inventory.getSize() != 36 || !event.getView().getTitle().equals(LOGIN_MESSAGE_GUI_TITLE)) + { + return; + } + event.setCancelled(true); + + int slot = event.getSlot(); + + Player player = (Player)event.getWhoClicked(); + PlayerData data = plugin.pl.getData(player); + + if (slot == 35) + { + data.setLoginMessage(null); + plugin.pl.save(data); + player.sendMessage(ChatColor.GREEN + "Removed your login message"); + } + else + { + String message = ConfigEntry.SHOP_LOGIN_MESSAGES.getStringList().get(slot); + data.setLoginMessage(message); + plugin.pl.save(data); + player.sendMessage(ChatColor.GREEN + "Your login message is now the following:\n" + plugin.rm.craftLoginMessage(player, message)); + } + + player.closeInventory(); + + } + public ShopItem getShopItem(int slot) { for (ShopItem shopItem : ShopItem.values()) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopItem.java b/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopItem.java index 6eac77c6..f7aadccd 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopItem.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/shop/ShopItem.java @@ -12,17 +12,18 @@ public enum ShopItem FIRE_BALL("Fire Ball", Material.FIRE_CHARGE, 14, ConfigEntry.SHOP_PRICES_FIRE_BALL, ChatColor.RED, "fireBall", "/fireball"), RIDEABLE_PEARL("Rideable Ender Pearl", Material.ENDER_PEARL, 16, ConfigEntry.SHOP_PRICES_RIDEABLE_PEARL, ChatColor.DARK_PURPLE, "rideablePearl", "/rideablepearl"), STACKING_POTATO("Stacking Potato", Material.POTATO, 20, ConfigEntry.SHOP_PRICES_STACKING_POTATO, ChatColor.YELLOW, "stackingPotato", "/stackingpotato"), - CLOWN_FISH("Clown Fish", Material.TROPICAL_FISH, 24, ConfigEntry.SHOP_PRICES_CLOWN_FISH, ChatColor.GOLD, "clownFish", "/clownfish"); + CLOWN_FISH("Clown Fish", Material.TROPICAL_FISH, 22, ConfigEntry.SHOP_PRICES_CLOWN_FISH, ChatColor.GOLD, "clownFish", "/clownfish"), + LOGIN_MESSAGES("Login Messages", Material.NAME_TAG, 24, ConfigEntry.SHOP_PRICES_LOGIN_MESSAGES, ChatColor.DARK_GREEN, "loginMessages", "/loginmessage"); /* Shop GUI Layout: Dimensions: 9x4 = 36 - Key: g = Grappling Hook, l = Lightning Rod, f = Fire Ball, r = Rideable Ender Pearl, s = Stacking Potato, c = Clown Fish, $ = Coins} + Key: g = Grappling Hook, l = Lightning Rod, f = Fire Ball, r = Rideable Ender Pearl, s = Stacking Potato, c = Clown Fish, x = Login Messages $ = Coins} --------- -g-l-f-r- - --s---c-- + --s-c-x-- --------$ */ diff --git a/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java b/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java index 763e6eca..91b453b2 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java @@ -82,7 +82,7 @@ public class SQLite extends FreedomService { try { - connection.createStatement().execute("CREATE TABLE `staff` (`username` VARCHAR NOT NULL, `ips` VARCHAR NOT NULL, `rank` VARCHAR NOT NULL, `active` BOOLEAN NOT NULL, `last_login` LONG NOT NULL, `login_message` VARCHAR, `command_spy` BOOLEAN NOT NULL, `potion_spy` BOOLEAN NOT NULL, `ac_format` VARCHAR, `ptero_id` VARCHAR);"); + connection.createStatement().execute("CREATE TABLE `staff` (`username` VARCHAR NOT NULL, `ips` VARCHAR NOT NULL, `rank` VARCHAR NOT NULL, `active` BOOLEAN NOT NULL, `last_login` LONG NOT NULL, `command_spy` BOOLEAN NOT NULL, `potion_spy` BOOLEAN NOT NULL, `ac_format` VARCHAR, `ptero_id` VARCHAR);"); } catch (SQLException e) { @@ -93,7 +93,7 @@ public class SQLite extends FreedomService { try { - connection.createStatement().execute("CREATE TABLE `players` (`username` VARCHAR NOT NULL, `ips` VARCHAR NOT NULL, `notes` VARCHAR, `tag` VARCHAR, `discord_id` VARCHAR, `backup_codes` VARCHAR, `donator` BOOLEAN NOT NULL, `master_builder` BOOLEAN NOT NULL,`verification` BOOLEAN NOT NULL, `ride_mode` VARCHAR NOT NULL, `coins` INT NOT NULL, `items` VARCHAR, `total_votes` INT NOT NULL, `display_discord` BOOLEAN NOT NULL, `reddit_username` VARCHAR NOT NULL);"); + connection.createStatement().execute("CREATE TABLE `players` (`username` VARCHAR NOT NULL, `ips` VARCHAR NOT NULL, `notes` VARCHAR, `tag` VARCHAR, `discord_id` VARCHAR, `backup_codes` VARCHAR, `donator` BOOLEAN NOT NULL, `master_builder` BOOLEAN NOT NULL,`verification` BOOLEAN NOT NULL, `ride_mode` VARCHAR NOT NULL, `coins` INT NOT NULL, `items` VARCHAR, `total_votes` INT NOT NULL, `display_discord` BOOLEAN NOT NULL, `reddit_username` VARCHAR NOT NULL, `login_message` VARCHAR);"); } catch (SQLException e) { @@ -141,7 +141,8 @@ public class SQLite extends FreedomService } catch (SQLException e) { - FLog.severe("Failed to update staff member value: " + e.getMessage()); + FLog.severe("Failed to update staff member value:"); + FLog.severe(e); } } @@ -252,7 +253,6 @@ public class SQLite extends FreedomService statement.setString(3, staffMember.getRank().toString()); statement.setBoolean(4, staffMember.isActive()); statement.setLong(5, staffMember.getLastLogin().getTime()); - statement.setString(6, staffMember.getLoginMessage()); statement.setBoolean(7, staffMember.getCommandSpy()); statement.setBoolean(8, staffMember.getPotionSpy()); statement.setString(9, staffMember.getAcFormat()); @@ -261,7 +261,8 @@ public class SQLite extends FreedomService } catch (SQLException e) { - FLog.severe("Failed to add staff member: " + e); + FLog.severe("Failed to add staff member:"); + FLog.severe(e); } } @@ -269,27 +270,28 @@ public class SQLite extends FreedomService { try { - PreparedStatement statement = connection.prepareStatement("INSERT INTO players VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + PreparedStatement statement = connection.prepareStatement("INSERT INTO players VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); statement.setString(1, player.getName()); statement.setString(2, FUtil.listToString(player.getIps())); statement.setString(3, FUtil.listToString(player.getNotes())); statement.setString(4, player.getTag()); statement.setString(5, player.getDiscordID()); statement.setString(6, FUtil.listToString(player.getBackupCodes())); - statement.setBoolean(7, player.isDonator()); - statement.setBoolean(8, player.isMasterBuilder()); - statement.setBoolean(9, player.hasVerification()); - statement.setString(10, player.getRideMode()); - statement.setInt(11, player.getCoins()); + statement.setBoolean(7, player.isMasterBuilder()); + statement.setBoolean(8, player.hasVerification()); + statement.setString(9, player.getRideMode()); + statement.setInt(10, player.getCoins()); statement.setString(12, FUtil.listToString(player.getItems())); statement.setInt(13, player.getTotalVotes()); statement.setBoolean(14, player.doesDisplayDiscord()); statement.setString(15, player.getRedditUsername()); + statement.setString(16, player.getLoginMessage()); statement.executeUpdate(); } catch (SQLException e) { - FLog.severe("Failed to add player: " + e); + FLog.severe("Failed to add player:"); + FLog.severe(e); } } @@ -305,7 +307,8 @@ public class SQLite extends FreedomService } catch (SQLException e) { - FLog.severe("Failed to get staff member by name: " + e); + FLog.severe("Failed to get staff member by name:"); + FLog.severe(e); } return null; @@ -323,7 +326,8 @@ public class SQLite extends FreedomService } catch (SQLException e) { - FLog.severe("Failed to get player by name: " + e); + FLog.severe("Failed to get player by name:"); + FLog.severe(e); } return null; @@ -337,7 +341,8 @@ public class SQLite extends FreedomService } catch (SQLException e) { - FLog.severe("Failed to get Master Builders: " + e); + FLog.severe("Failed to get Master Builders:"); + FLog.severe(e); } return null; @@ -355,7 +360,8 @@ public class SQLite extends FreedomService } catch (SQLException e) { - FLog.severe("Failed to get player by ip: " + e.getMessage()); + FLog.severe("Failed to get player by ip:"); + FLog.severe(e); } return null; @@ -369,7 +375,8 @@ public class SQLite extends FreedomService } catch (SQLException e) { - FLog.severe("Failed to remove staff member: " + e.getMessage()); + FLog.severe("Failed to remove staff member:"); + FLog.severe(e); } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/staff/StaffMember.java b/src/main/java/me/totalfreedom/totalfreedommod/staff/StaffMember.java index d0dd9f9e..525f85c5 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/staff/StaffMember.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/staff/StaffMember.java @@ -35,9 +35,6 @@ public class StaffMember private Date lastLogin = new Date(); @Getter @Setter - private String loginMessage = null; - @Getter - @Setter private Boolean commandSpy = false; @Getter @Setter @@ -65,7 +62,6 @@ public class StaffMember this.ips.clear(); this.ips.addAll(FUtil.stringToList(resultSet.getString("ips"))); this.lastLogin = new Date(resultSet.getLong("last_login")); - this.loginMessage = resultSet.getString("login_message"); this.commandSpy = resultSet.getBoolean("command_spy"); this.potionSpy = resultSet.getBoolean("potion_spy"); this.acFormat = resultSet.getString("ac_format"); @@ -85,7 +81,6 @@ public class StaffMember output.append("Staff: ").append(name).append("\n") .append("- IPs: ").append(StringUtils.join(ips, ", ")).append("\n") .append("- Last Login: ").append(FUtil.dateToString(lastLogin)).append("\n") - .append("- Custom Login Message: ").append(loginMessage).append("\n") .append("- Rank: ").append(rank.getName()).append("\n") .append("- Is Active: ").append(active).append("\n") .append("- Potion Spy: ").append(potionSpy).append("\n") @@ -104,7 +99,6 @@ public class StaffMember put("rank", rank.toString()); put("ips", FUtil.listToString(ips)); put("last_login", lastLogin.getTime()); - put("login_message", loginMessage); put("command_spy", commandSpy); put("potion_spy", potionSpy); put("ac_format", acFormat); @@ -113,11 +107,6 @@ public class StaffMember return map; } - public boolean hasLoginMessage() - { - return loginMessage != null && !loginMessage.isEmpty(); - } - // Util IP methods public void addIp(String ip) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java index fae626bd..931ee0fb 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java @@ -56,7 +56,7 @@ public class FUtil public static final String SAVED_FLAGS_FILENAME = "savedflags.dat"; /* See https://github.com/TotalFreedom/License - None of the listed names may be removed. Leaving this list here for anyone running TFM on a cracked server: - public static final List DEVELOPERS = Arrays.asList("Madgeek1450", "Prozza", "WickedGamingUK", "Wild1145", "aggelosQQ", "scripthead", "supernt", "Telesphoreo", "CoolJWB"); + public static final List DEVELOPERS = Arrays.asList("Madgeek1450", "Prozza", "WickedGamingUK", "Wild1145", "aggelosQQ", "scripthead", "Telesphoreo", "CoolJWB"); */ public static final List DEVELOPERS = Arrays.asList( "1156a81a-23fb-435e-9aff-fe9c2ea7e82d", // Madgeek1450 @@ -65,10 +65,10 @@ public class FUtil "604cbb51-842d-4b43-8b0a-d1d7c6cd2869", // Wild1145 "e67d77c4-fff9-4cea-94cc-9f1f1ab7806b", // aggelosQQ "0061326b-8b3d-44c8-830a-5f2d59f5dc1b", // scripthead - "53b1512e-3481-4702-9f4f-63cb9c8be6a1", // supernt "78408086-1991-4c33-a571-d8fa325465b2", // Telesphoreo "67ce0e28-3d6b-469c-ab71-304eec81b614" // CoolJWB ); + public static final List DEVELOPER_NAMES = Arrays.asList("Madgeek1450", "Prozza", "WickedGamingUK", "Wild1145", "aggelosQQ", "scripthead", "Telesphoreo", "CoolJWB"); public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z"; public static final Map CHAT_COLOR_NAMES = new HashMap<>(); public static final List CHAT_COLOR_POOL = Arrays.asList( diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index bf6270f4..a633aa65 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -146,6 +146,11 @@ shop: # How long is the random string (in characters)? string_length: 10 + # Login messages. Use %name% for usernames, and %rank% for ranks/titles + login_messages: + - '&b%name% is a terrible %coloredrank%' + - '&bthat %name% dude is a shitty %coloredrank%' + # Item prices prices: grappling_hook: 100 @@ -154,6 +159,7 @@ shop: rideable_pearl: 700 stacking_potato: 300 clown_fish: 1500 + login_messages: 5000 # Staff list stafflist: @@ -190,12 +196,6 @@ social_links: Website: 'https://totalfreedom.me/' Discord: 'https://discordapp.com/invite/XXjmAmV/' -donation: - proboards_url: '' - donator_group_id: '' - session_id: '' - csrf_token: '' - # Blocking certain events allow: fire_place: false From 82d92565e7b8e8945edbea15e94b2f99791d9c5a Mon Sep 17 00:00:00 2001 From: Seth <13510767+ZeroEpoch1969@users.noreply.github.com> Date: Tue, 13 Oct 2020 13:37:11 -0700 Subject: [PATCH 02/12] lol --- .../totalfreedommod/command/Command_manageshop.java | 2 +- .../java/me/totalfreedom/totalfreedommod/fun/ItemFun.java | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manageshop.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manageshop.java index be3466a2..b7207d93 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manageshop.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_manageshop.java @@ -88,7 +88,7 @@ public class Command_manageshop extends FreedomCommand msg(PLAYER_NOT_FOUND); return true; } - playerData.setCoins(playerData.getCoins() + amount); + playerData.setCoins(playerData.getCoins() - amount); if (playerData.getCoins() < 0) { playerData.setCoins(0); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java index dcf04c75..f1875723 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java @@ -256,12 +256,6 @@ public class ItemFun extends FreedomService break; } - if (onCooldown(player, ShopItem.CLOWN_FISH)) - { - player.sendMessage(ChatColor.RED + "You're currently on a cool-down for 30 seconds."); - break; - } - event.setCancelled(true); boolean didHit = false; From a8f95bcb191b915b9ac1cccf92daad608235b81e Mon Sep 17 00:00:00 2001 From: Nathan Curran <30569566+Focusvity@users.noreply.github.com> Date: Fri, 16 Oct 2020 13:20:20 +1100 Subject: [PATCH 03/12] Use Component API for attachments --- .../discord/DiscordToMinecraftListener.java | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java index 5244eb1e..2f4754a4 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java @@ -7,8 +7,12 @@ import me.totalfreedom.totalfreedommod.rank.Title; import me.totalfreedom.totalfreedommod.util.FLog; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -20,7 +24,7 @@ public class DiscordToMinecraftListener extends ListenerAdapter String chat_channel_id = ConfigEntry.DISCORD_CHAT_CHANNEL_ID.getString(); if (event.getMember() != null && !chat_channel_id.isEmpty() && event.getChannel().getId().equals(chat_channel_id)) { - if (!event.getAuthor().getId().equals(Discord.bot.getSelfUser().getId()) && !event.getMessage().getContentDisplay().isEmpty()) + if (!event.getAuthor().getId().equals(Discord.bot.getSelfUser().getId())) { Member member = event.getMember(); String tag = getDisplay(member); @@ -29,15 +33,40 @@ public class DiscordToMinecraftListener extends ListenerAdapter { message += " " + tag; } - message += " " + ChatColor.RED + ChatColor.stripColor(member.getEffectiveName()) + ChatColor.DARK_GRAY + ": " + ChatColor.RESET + ChatColor.stripColor(event.getMessage().getContentDisplay()); - for (Player player : Bukkit.getOnlinePlayers()) + message += " " + ChatColor.RED + ChatColor.stripColor(member.getEffectiveName()) + ChatColor.DARK_GRAY + ": " + ChatColor.RESET; + if (!event.getMessage().getContentDisplay().isEmpty()) { - if (TotalFreedomMod.getPlugin().pl.getData(player).doesDisplayDiscord()) + message += ChatColor.stripColor(event.getMessage().getContentDisplay()); + for (Player player : Bukkit.getOnlinePlayers()) { - player.sendMessage(message); + if (TotalFreedomMod.getPlugin().pl.getData(player).doesDisplayDiscord()) + { + player.sendMessage(message); + } + } + FLog.info(message); + } + else + { + ComponentBuilder builder = new ComponentBuilder(message); + for (Message.Attachment attachment : event.getMessage().getAttachments()) + { + if (attachment.getUrl() == null) + { + continue; + } + TextComponent text = new TextComponent(net.md_5.bungee.api.ChatColor.YELLOW + "[Media]"); + text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl())); + builder.append(text).append(" "); + } + for (Player player : Bukkit.getOnlinePlayers()) + { + if (TotalFreedomMod.getPlugin().pl.getData(player).doesDisplayDiscord()) + { + player.spigot().sendMessage(builder.create()); + } } } - FLog.info(message); } } } From 82e7a3b65916d767f1cfdc6d72d5957a59cd05fa Mon Sep 17 00:00:00 2001 From: Nathan Curran <30569566+Focusvity@users.noreply.github.com> Date: Fri, 16 Oct 2020 13:37:25 +1100 Subject: [PATCH 04/12] Fix NPE (https://github.com/TFPatches/TotalFreedomMod/issues/287) --- src/main/resources/permissions.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/resources/permissions.yml b/src/main/resources/permissions.yml index 1913553e..2f7876f4 100644 --- a/src/main/resources/permissions.yml +++ b/src/main/resources/permissions.yml @@ -60,15 +60,12 @@ master_builders: - "voxelsniper.goto" - "voxelsniper.brush.*" -# Trial Mod permission nodes -trial_mods: +# Admin permission nodes +admins: - "coreprotect.*" - "worldedit.*" - "worldguard.*" - "bending.*" -# Moderator permission nodes -mods: [] - -# Admin permission nodes -admins: [] \ No newline at end of file +# Senior Admin permission nodes +senior_admins: [] From 3bd72dacda6b95b4fe15dee07d205f1f2200fe13 Mon Sep 17 00:00:00 2001 From: Nathan Curran <30569566+Focusvity@users.noreply.github.com> Date: Fri, 16 Oct 2020 17:33:58 +1100 Subject: [PATCH 05/12] Enable media tag to be included in messages --- .../discord/DiscordToMinecraftListener.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java index 2f4754a4..2ad627b0 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java @@ -29,19 +29,35 @@ public class DiscordToMinecraftListener extends ListenerAdapter Member member = event.getMember(); String tag = getDisplay(member); String message = ChatColor.DARK_GRAY + "[" + ChatColor.DARK_AQUA + "Discord" + ChatColor.DARK_GRAY + "]"; + Message msg = event.getMessage(); if (tag != null) { message += " " + tag; } message += " " + ChatColor.RED + ChatColor.stripColor(member.getEffectiveName()) + ChatColor.DARK_GRAY + ": " + ChatColor.RESET; - if (!event.getMessage().getContentDisplay().isEmpty()) + if (!msg.getContentDisplay().isEmpty()) { - message += ChatColor.stripColor(event.getMessage().getContentDisplay()); + message += ChatColor.stripColor(msg.getContentDisplay()); + ComponentBuilder builder = new ComponentBuilder(message); + if (!msg.getAttachments().isEmpty()) + { + for (Message.Attachment attachment : msg.getAttachments()) + { + if (attachment.getUrl() == null) + { + continue; + } + builder.append(" "); + TextComponent text = new TextComponent(net.md_5.bungee.api.ChatColor.YELLOW + "[Media]"); + text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl())); + builder.append(text).append(" "); + } + } for (Player player : Bukkit.getOnlinePlayers()) { if (TotalFreedomMod.getPlugin().pl.getData(player).doesDisplayDiscord()) { - player.sendMessage(message); + player.spigot().sendMessage(builder.create()); } } FLog.info(message); @@ -49,7 +65,7 @@ public class DiscordToMinecraftListener extends ListenerAdapter else { ComponentBuilder builder = new ComponentBuilder(message); - for (Message.Attachment attachment : event.getMessage().getAttachments()) + for (Message.Attachment attachment : msg.getAttachments()) { if (attachment.getUrl() == null) { From 5a96204f1be9d0960e30082cb57c3f5fc058ea3d Mon Sep 17 00:00:00 2001 From: Nathan Curran <30569566+Focusvity@users.noreply.github.com> Date: Fri, 16 Oct 2020 17:51:21 +1100 Subject: [PATCH 06/12] Tidy things up a bit --- .../discord/DiscordToMinecraftListener.java | 53 ++++++------------- 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java index 2ad627b0..889fc10e 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java @@ -34,55 +34,36 @@ public class DiscordToMinecraftListener extends ListenerAdapter { message += " " + tag; } - message += " " + ChatColor.RED + ChatColor.stripColor(member.getEffectiveName()) + ChatColor.DARK_GRAY + ": " + ChatColor.RESET; + message += " " + ChatColor.RED + ChatColor.stripColor(member.getEffectiveName()) + ChatColor.DARK_GRAY + ":" + ChatColor.RESET; + ComponentBuilder builder = new ComponentBuilder(message); if (!msg.getContentDisplay().isEmpty()) { - message += ChatColor.stripColor(msg.getContentDisplay()); - ComponentBuilder builder = new ComponentBuilder(message); - if (!msg.getAttachments().isEmpty()) - { - for (Message.Attachment attachment : msg.getAttachments()) - { - if (attachment.getUrl() == null) - { - continue; - } - builder.append(" "); - TextComponent text = new TextComponent(net.md_5.bungee.api.ChatColor.YELLOW + "[Media]"); - text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl())); - builder.append(text).append(" "); - } - } - for (Player player : Bukkit.getOnlinePlayers()) - { - if (TotalFreedomMod.getPlugin().pl.getData(player).doesDisplayDiscord()) - { - player.spigot().sendMessage(builder.create()); - } - } - FLog.info(message); + builder.append(" ").append(ChatColor.stripColor(msg.getContentDisplay())); + message += " " + ChatColor.stripColor(msg.getContentDisplay()); // for logging } - else + if (!msg.getAttachments().isEmpty()) { - ComponentBuilder builder = new ComponentBuilder(message); for (Message.Attachment attachment : msg.getAttachments()) { if (attachment.getUrl() == null) { continue; } - TextComponent text = new TextComponent(net.md_5.bungee.api.ChatColor.YELLOW + "[Media]"); + builder.append(" "); + TextComponent text = new TextComponent(ChatColor.YELLOW + "[Media]"); text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl())); - builder.append(text).append(" "); - } - for (Player player : Bukkit.getOnlinePlayers()) - { - if (TotalFreedomMod.getPlugin().pl.getData(player).doesDisplayDiscord()) - { - player.spigot().sendMessage(builder.create()); - } + builder.append(text); + message += " [Media]"; // for logging } } + for (Player player : Bukkit.getOnlinePlayers()) + { + if (TotalFreedomMod.getPlugin().pl.getData(player).doesDisplayDiscord()) + { + player.spigot().sendMessage(builder.create()); + } + } + FLog.info(message); } } } From bb33778fc91a0b64b2ea19dc49a9c5e256a9feb3 Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Fri, 16 Oct 2020 22:33:33 -0500 Subject: [PATCH 07/12] [Maven] FAWE --- pom.xml | 2 +- .../bridge/CoreProtectBridge.java | 5 +- .../totalfreedommod/bridge/FAWEBridge.java | 101 ++++++++---------- .../bridge/WorldEditBridge.java | 2 +- 4 files changed, 52 insertions(+), 58 deletions(-) diff --git a/pom.xml b/pom.xml index 7e3cebad..275f24ec 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ me.totalfreedom TotalFreedomMod - 2020.10 + 2020.11 jar diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java index 1665f317..47f1a83c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java @@ -7,6 +7,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Arrays; +import java.util.Collections; import java.util.List; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.config.ConfigEntry; @@ -103,7 +104,7 @@ public class CoreProtectBridge extends FreedomService @Override public void run() { - coreProtect.performRollback(86400, Arrays.asList(name), null, null, null, null, 0, null); + coreProtect.performRollback(86400, Collections.singletonList(name), null, null, null, null, 0, null); } }.runTaskAsynchronously(plugin); } @@ -123,7 +124,7 @@ public class CoreProtectBridge extends FreedomService @Override public void run() { - coreProtect.performRestore(86400, Arrays.asList(name), null, null, null, null, 0, null); + coreProtect.performRestore(86400, Collections.singletonList(name), null, null, null, null, 0, null); } }.runTaskAsynchronously(plugin); } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/FAWEBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/FAWEBridge.java index 4f6adbb3..789f7f28 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/FAWEBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/FAWEBridge.java @@ -12,6 +12,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.util.FLog; import net.coreprotect.CoreProtect; import net.coreprotect.CoreProtectAPI; import org.bukkit.Bukkit; @@ -24,7 +25,7 @@ import org.bukkit.block.data.BlockData; public class FAWEBridge extends FreedomService { - private CoreProtectAPI api; + private final CoreProtectAPI api = plugin.cpb.getCoreProtectAPI();; private World world = null; private final Map, Map> blocksBroken = new HashMap<>(); private final Map, Map.Entry>> blocksPlaced = new HashMap<>(); @@ -32,68 +33,62 @@ public class FAWEBridge extends FreedomService @Override public void onStart() { - api = ((CoreProtect)Bukkit.getPluginManager().getPlugin("CoreProtect")).getAPI(); - /* * Iterates over blocks placed by GenerationCommands (in the EditSession) and adds them to the CoreProtect logs. */ - server.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() + server.getScheduler().scheduleSyncRepeatingTask(plugin, () -> { - @Override - public void run() + if (!(blocksBroken.isEmpty() && blocksPlaced.isEmpty())) { - if (!(blocksBroken.isEmpty() && blocksPlaced.isEmpty())) + // Send all broken blocks from the last ticks to the CoreProtect API. + Map.Entry playerAndSessionEntry = null; + for (Map.Entry, Map> entry : blocksBroken.entrySet()) { - // Send all broken blocks from the last ticks to the CoreProtect API. - Map.Entry playerAndSessionEntry = null; - for (Map.Entry, Map> entry : blocksBroken.entrySet()) - { - playerAndSessionEntry = entry.getKey(); - Map dataAndVectorEntry = entry.getValue(); - List blockVector3List = new ArrayList<>(); - blockVector3List.addAll(dataAndVectorEntry.keySet()); // Deep clone the block vector to avoid a change later in the code. + playerAndSessionEntry = entry.getKey(); + Map dataAndVectorEntry = entry.getValue(); + List blockVector3List = new ArrayList<>(); + blockVector3List.addAll(dataAndVectorEntry.keySet()); // Deep clone the block vector to avoid a change later in the code. - for (BlockVector3 blockVector3 : blockVector3List) + for (BlockVector3 blockVector3 : blockVector3List) + { + if (blockVector3 != null) { - if (blockVector3 != null) - { - EditSession editSession = playerAndSessionEntry.getValue(); - World world = server.getWorld(editSession.getWorld().getName()); - Location location = new Location(world, blockVector3.getX(), blockVector3.getY(), blockVector3.getZ()); - BlockData blockData = server.createBlockData(dataAndVectorEntry.get(blockVector3)); - api.logRemoval(playerAndSessionEntry.getKey(), location, blockData.getMaterial(), blockData); - } + EditSession editSession = playerAndSessionEntry.getValue(); + World world = server.getWorld(editSession.getWorld().getName()); + Location location = new Location(world, blockVector3.getX(), blockVector3.getY(), blockVector3.getZ()); + BlockData blockData = server.createBlockData(dataAndVectorEntry.get(blockVector3)); + api.logRemoval(playerAndSessionEntry.getKey(), location, blockData.getMaterial(), blockData); } } - - // Clear after broken blocks have been updated. - blocksBroken.values().clear(); - blocksBroken.putIfAbsent(playerAndSessionEntry, new HashMap<>()); - - // Send all blocks placed to the CoreProtect API (except from the air as it's only a broken block). - for (Map.Entry, Map.Entry>> entry : blocksPlaced.entrySet()) - { - playerAndSessionEntry = entry.getKey(); - Map.Entry> patternAndListEntry = entry.getValue(); - Pattern pattern = patternAndListEntry.getKey(); - List blockVector3List = new ArrayList<>(); - blockVector3List.addAll(patternAndListEntry.getValue()); // Deep clone the block vector to avoid a change later in the code. - - for (BlockVector3 blockVector3 : blockVector3List) - { - if (blockVector3 != null && !pattern.apply(blockVector3).getBlockType().getMaterial().isAir()) - { - World world = server.getWorld(playerAndSessionEntry.getValue().getWorld().getName()); - Location location = new Location(world, blockVector3.getX(), blockVector3.getY(), blockVector3.getZ()); - BaseBlock block = pattern.apply(blockVector3); - Material material = Material.getMaterial(block.getBlockType().getId().replaceFirst("minecraft:", "").toUpperCase()); - api.logPlacement(playerAndSessionEntry.getKey(), location, material, material.createBlockData()); - } - } - } - - blocksPlaced.values().forEach(collection -> collection.getValue().clear()); } + + // Clear after broken blocks have been updated. + blocksBroken.values().clear(); + blocksBroken.putIfAbsent(playerAndSessionEntry, new HashMap<>()); + + // Send all blocks placed to the CoreProtect API (except from the air as it's only a broken block). + for (Map.Entry, Map.Entry>> entry : blocksPlaced.entrySet()) + { + playerAndSessionEntry = entry.getKey(); + Map.Entry> patternAndListEntry = entry.getValue(); + Pattern pattern = patternAndListEntry.getKey(); + List blockVector3List = new ArrayList<>(); + blockVector3List.addAll(patternAndListEntry.getValue()); // Deep clone the block vector to avoid a change later in the code. + + for (BlockVector3 blockVector3 : blockVector3List) + { + if (blockVector3 != null && !pattern.apply(blockVector3).getBlockType().getMaterial().isAir()) + { + World world = server.getWorld(playerAndSessionEntry.getValue().getWorld().getName()); + Location location = new Location(world, blockVector3.getX(), blockVector3.getY(), blockVector3.getZ()); + BaseBlock block = pattern.apply(blockVector3); + Material material = Material.getMaterial(block.getBlockType().getId().replaceFirst("minecraft:", "").toUpperCase()); + api.logPlacement(playerAndSessionEntry.getKey(), location, material, material.createBlockData()); + } + } + } + + blocksPlaced.values().forEach(collection -> collection.getValue().clear()); } }, 0L, 40L); } @@ -101,10 +96,8 @@ public class FAWEBridge extends FreedomService @Override public void onStop() { - } - public void logBlockEdit(String playerName, EditSession editSession, Pattern pattern, BlockVector3 blockVector3) { // Cache the world used for the next iterations to come. diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldEditBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldEditBridge.java index b254c1b4..90e02e66 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldEditBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/WorldEditBridge.java @@ -60,7 +60,7 @@ public class WorldEditBridge extends FreedomService { for (int i = 0; i < count; i++) { - com.sk89q.worldedit.entity.Player fuckyou = (com.sk89q.worldedit.entity.Player)bukkitPlayer; + com.sk89q.worldedit.entity.Player fuckyou = bukkitPlayer; session.undo(session.getBlockBag(fuckyou), fuckyou); } } From 2ecfd9610fe06050e6d6eea897b19cbaca65b97d Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Mon, 19 Oct 2020 19:07:44 -0500 Subject: [PATCH 08/12] br --- pom.xml | 2 +- .../java/me/totalfreedom/totalfreedommod/bridge/FAWEBridge.java | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 275f24ec..6db6020d 100644 --- a/pom.xml +++ b/pom.xml @@ -197,7 +197,7 @@ com.sk89q.worldguard worldguard-bukkit - 7.0.3 + 7.0.4 provided diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/FAWEBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/FAWEBridge.java index 789f7f28..b497bb8f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/FAWEBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/FAWEBridge.java @@ -12,10 +12,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import me.totalfreedom.totalfreedommod.FreedomService; -import me.totalfreedom.totalfreedommod.util.FLog; import net.coreprotect.CoreProtect; import net.coreprotect.CoreProtectAPI; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; From 6e84fdad23b9f1585cfc6f12b0f2ae7bcd6893e0 Mon Sep 17 00:00:00 2001 From: Seth <13510767+ZeroEpoch1969@users.noreply.github.com> Date: Sun, 25 Oct 2020 09:27:56 -0700 Subject: [PATCH 09/12] Login messages Last commit from me. Don't have the power but to me Packs is the new Lead Developer --- .../command/Command_loginmessage.java | 2 +- .../totalfreedommod/rank/Displayable.java | 2 +- .../totalfreedom/totalfreedommod/rank/Rank.java | 8 ++++---- .../totalfreedommod/rank/RankManager.java | 4 ++-- .../totalfreedommod/rank/Title.java | 8 ++++---- src/main/resources/config.yml | 17 +++++++++++++++-- 6 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_loginmessage.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_loginmessage.java index c3e4987b..f83cf8b9 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_loginmessage.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_loginmessage.java @@ -37,7 +37,7 @@ public class Command_loginmessage extends FreedomCommand msg("Your login message must contain your rank. Use either %rank% or %coloredrank% to specify where you want the rank", ChatColor.RED); return true; } - int length = message.replace("%name%", "").replace("%rank%", "").replace("%coloredrank%", "").replace("%det%", "").length(); + int length = message.replace("%name%", "").replace("%rank%", "").replace("%coloredrank%", "").replace("%art%", "").length(); if (length > 100) { msg("Your login message cannot be more than 100 characters (excluding your rank and your name)", ChatColor.RED); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/rank/Displayable.java b/src/main/java/me/totalfreedom/totalfreedommod/rank/Displayable.java index db4ea54e..d63d4fa8 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/rank/Displayable.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/rank/Displayable.java @@ -5,7 +5,7 @@ import net.md_5.bungee.api.ChatColor; public interface Displayable { - public String getDeterminer(); + public String getArticle(); public String getName(); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/rank/Rank.java b/src/main/java/me/totalfreedom/totalfreedommod/rank/Rank.java index cbedc2d4..ce6f4169 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/rank/Rank.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/rank/Rank.java @@ -19,7 +19,7 @@ public enum Rank implements Displayable @Getter private final String abbr; @Getter - private final String determiner; + private final String article; @Getter private final String tag; @Getter @@ -33,12 +33,12 @@ public enum Rank implements Displayable @Getter private final boolean hasDefaultLoginMessage; - Rank(String determiner, String name, Type type, String abbr, ChatColor color, org.bukkit.ChatColor teamColor, Boolean hasTeam, Boolean hasDefaultLoginMessage) + Rank(String article, String name, Type type, String abbr, ChatColor color, org.bukkit.ChatColor teamColor, Boolean hasTeam, Boolean hasDefaultLoginMessage) { this.type = type; this.name = name; this.abbr = abbr; - this.determiner = determiner; + this.article = article; this.tag = abbr.isEmpty() ? "" : "[" + abbr + "]"; this.coloredTag = abbr.isEmpty() ? "" : ChatColor.DARK_GRAY + "[" + color + abbr + ChatColor.DARK_GRAY + "]" + color; this.color = color; @@ -56,7 +56,7 @@ public enum Rank implements Displayable @Override public String getColoredLoginMessage() { - return determiner + " " + color + name; + return article + " " + color + name; } @Override diff --git a/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java b/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java index b099e187..8c013f5b 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java @@ -271,7 +271,7 @@ public class RankManager extends FreedomService { if (display.hasDefaultLoginMessage()) { - message = "%name% is %det% %coloredrank%"; + message = "%name% is %art% %coloredrank%"; } } } @@ -281,7 +281,7 @@ public class RankManager extends FreedomService + FUtil.colorize(message).replace("%name%", player.getName()) .replace("%rank%", display.getName()) .replace("%coloredrank%", display.getColoredName()) - .replace("%det%", display.getDeterminer())); + .replace("%art%", display.getDeterminer())); return loginMessage; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java b/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java index 6f67e7e3..0af577f3 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java @@ -13,7 +13,7 @@ public enum Title implements Displayable OWNER("the", "Owner", ChatColor.of("#ff0000"), org.bukkit.ChatColor.DARK_RED, "Owner", true, true); @Getter - private final String determiner; + private final String article; @Getter private final String name; @Getter @@ -30,9 +30,9 @@ public enum Title implements Displayable private final boolean hasTeam; private final boolean hasDefaultLoginMessage; - Title(String determiner, String name, ChatColor color, org.bukkit.ChatColor teamColor, String tag, Boolean hasTeam, Boolean hasDefaultLoginMessage) + Title(String article, String name, ChatColor color, org.bukkit.ChatColor teamColor, String tag, Boolean hasTeam, Boolean hasDefaultLoginMessage) { - this.determiner = determiner; + this.article = article; this.name = name; this.coloredTag = ChatColor.DARK_GRAY + "[" + color + tag + ChatColor.DARK_GRAY + "]" + color; this.abbr = tag; @@ -64,6 +64,6 @@ public enum Title implements Displayable @Override public String getColoredLoginMessage() { - return determiner + " " + color + name; + return article + " " + color + name; } } \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index a633aa65..316cb770 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -148,8 +148,21 @@ shop: # Login messages. Use %name% for usernames, and %rank% for ranks/titles login_messages: - - '&b%name% is a terrible %coloredrank%' - - '&bthat %name% dude is a shitty %coloredrank%' + - '%name% is a terrible %coloredrank%' + - 'that %name% dude is a shitty %coloredrank%' + - 'Hi, my name is %name% and I'm %art% %coloredrank%&b that wasted coins on this login message.' + - '&aDo not fear, %coloredrank% &b%name% &ais here!' + - '%name% is %art% %coloredrank%&b, say hi to them before they gets banned for doing something stupid' + - 'Oh. It's &l%name%&r&b the %coloredrank%&b again. Great.' + - 'Make way for %name% the %coloredrank%&b!' + - 'It's a bird! It's a plane! No, it's %art% %rank%! It's %name%' + - '%rank% %name%' + - '%coloredrank%&b %name%' + - 'A wild %name%, %art% %coloredrank%&b, appeared!' + - 'All in all, the %rank% %name% is just another brick in the wall' + - '&a%name% &bis a a geeky &6%rank%' + - '%name% is the %rank% who just exists' + - '%name% based cringe poggers based based %rank%' # Item prices prices: From adf71cb020b6d30c153b5590fe13e1298238cbe4 Mon Sep 17 00:00:00 2001 From: speed <43330808+speedxx@users.noreply.github.com> Date: Sun, 25 Oct 2020 13:24:41 -0400 Subject: [PATCH 10/12] Update RankManager.java --- .../me/totalfreedom/totalfreedommod/rank/RankManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java b/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java index 8c013f5b..4da69ce2 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java @@ -281,7 +281,7 @@ public class RankManager extends FreedomService + FUtil.colorize(message).replace("%name%", player.getName()) .replace("%rank%", display.getName()) .replace("%coloredrank%", display.getColoredName()) - .replace("%art%", display.getDeterminer())); + .replace("%art%", display.getArticle())); return loginMessage; } @@ -313,4 +313,4 @@ public class RankManager extends FreedomService team.addPlayer(player); } } -} \ No newline at end of file +} From 9bcdb2bcdce6cefb508aafba52fc717f5dc7678f Mon Sep 17 00:00:00 2001 From: speed <43330808+speedxx@users.noreply.github.com> Date: Wed, 28 Oct 2020 18:06:12 -0400 Subject: [PATCH 11/12] fix ride request expire messages fixes /ride sending request expired message even after accepting & properly remove player from map after accepting, #291 --- .../totalfreedommod/command/Command_ride.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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 69247c8e..0e01496f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java @@ -3,7 +3,6 @@ package me.totalfreedom.totalfreedommod.command; import io.papermc.lib.PaperLib; import java.util.HashMap; import java.util.Map; -import java.util.TimerTask; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.rank.Rank; @@ -12,6 +11,7 @@ import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; @CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME) @CommandParameters(description = "Ride on the top of the specified player.", usage = "/ >") @@ -39,7 +39,7 @@ public class Command_ride extends FreedomCommand { if (!RIDE_REQUESTS.containsKey(playerSender)) { - msg("You don't have a request currently."); + msg("You don't have any pending requests."); return true; } @@ -59,6 +59,7 @@ public class Command_ride extends FreedomCommand PaperLib.teleportAsync(requester, playerSender.getLocation()); } + RIDE_REQUESTS.remove(playerSender); playerSender.addPassenger(requester); return true; } @@ -67,7 +68,7 @@ public class Command_ride extends FreedomCommand { if (!RIDE_REQUESTS.containsKey(playerSender)) { - msg("You don't have a request currently."); + msg("You don't have any pending requests."); return true; } Player requester = RIDE_REQUESTS.get(playerSender); @@ -125,22 +126,23 @@ public class Command_ride extends FreedomCommand player.sendMessage(ChatColor.AQUA + sender.getName() + " has requested to ride you."); player.sendMessage(ChatColor.AQUA + "Type " + ChatColor.GREEN + "/ride accept" + ChatColor.AQUA + " to allow the player to ride you."); 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."); + player.sendMessage(ChatColor.AQUA + "Request will expire in 30 seconds."); RIDE_REQUESTS.put(player, playerSender); - timer.schedule(new TimerTask() + + new BukkitRunnable() { - @Override public void run() { if (!RIDE_REQUESTS.containsKey(player)) { return; } + RIDE_REQUESTS.remove(player); - msg("Request expired.", ChatColor.RED); + playerSender.sendMessage(ChatColor.RED + "It has been 30 seconds and " + player.getName() + " has not accepted your request."); player.sendMessage(ChatColor.RED + "Request expired."); } - }, 30000); + }.runTaskLater(plugin, 20 * 30); return true; } From fadcb9ad5d177686edbebb90061f0c2312b66913 Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Thu, 29 Oct 2020 18:47:53 -0500 Subject: [PATCH 12/12] TotalFreedomMod 2020.11 --- pom.xml | 58 +- .../mojangson/MojangsonFinder.java | 23 - .../momothereal/mojangson/MojangsonToken.java | 53 -- .../mojangson/ex/MojangsonParseException.java | 42 - .../mojangson/value/MojangsonCompound.java | 144 --- .../mojangson/value/MojangsonString.java | 57 -- .../mojangson/value/MojangsonValue.java | 42 - .../totalfreedommod/TotalFreedomMod.java | 2 +- .../command/Command_coins.java | 1 - .../totalfreedommod/sql/SQLite.java | 2 +- src/main/java/org/bstats/Metrics.java | 847 ------------------ src/main/resources/config.yml | 7 +- 12 files changed, 49 insertions(+), 1229 deletions(-) delete mode 100644 src/main/java/ca/momothereal/mojangson/MojangsonFinder.java delete mode 100644 src/main/java/ca/momothereal/mojangson/MojangsonToken.java delete mode 100644 src/main/java/ca/momothereal/mojangson/ex/MojangsonParseException.java delete mode 100644 src/main/java/ca/momothereal/mojangson/value/MojangsonCompound.java delete mode 100644 src/main/java/ca/momothereal/mojangson/value/MojangsonString.java delete mode 100644 src/main/java/ca/momothereal/mojangson/value/MojangsonValue.java delete mode 100644 src/main/java/org/bstats/Metrics.java diff --git a/pom.xml b/pom.xml index 6db6020d..eaae8cf6 100644 --- a/pom.xml +++ b/pom.xml @@ -114,20 +114,25 @@ ess-repo https://ci.ender.zone/plugin/repository/everything/ + + + telesphoreo-repo + https://telesphoreo.me/repo/maven/ + org.projectlombok lombok - 1.18.12 + 1.18.16 provided commons-io commons-io - 2.7 + 2.8.0 compile @@ -141,35 +146,49 @@ commons-codec commons-codec - 1.14 + 1.15 + compile + + + + me.telesphoreo + mojangson + 1.0 + compile + + + + org.bstats + bstats-bukkit + 1.7 compile org.spigotmc spigot - 1.16.2-R0.1-SNAPSHOT + 1.16.3-R0.1-SNAPSHOT provided - com.github.TotalFreedom + com.github.TotalFreedomMC BukkitTelnet - 4.5-pre1 + 541e9fdb84 provided - com.github.TFPatches + com.github.TotalFreedomMC TF-LibsDisguises - 0cfa32159a + 48f01cf2fe provided com.sk89q.worldedit worldedit-bukkit - 7.1.0 + 7.2.0-SNAPSHOT provided @@ -232,19 +251,21 @@ org.reflections reflections - 0.9.11 + 0.9.12 + compile - javassist + org.javassist javassist - 3.12.1.GA + 3.27.0-GA + compile - com.github.TFPatches + com.github.TotalFreedomMC TFGuilds - ad93b9ed00 + db036fb187 provided @@ -252,6 +273,7 @@ org.apache.maven.plugins maven-checkstyle-plugin 3.1.1 + compile @@ -419,6 +441,10 @@ io.papermc.lib me.totalfreedom.totalfreedommod.paperlib + + org.bstats + me.totalfreedom.totalfreedommod + @@ -426,9 +452,11 @@ org.apache.commons:commons-lang3 commons-codec:commons-codec org.reflections:reflections - javassist:javassist + org.javassist:javassist me.rayzr522:jsonmessage io.papermc:paperlib + me.telesphoreo:mojangson + org.bstats:bstats-bukkit diff --git a/src/main/java/ca/momothereal/mojangson/MojangsonFinder.java b/src/main/java/ca/momothereal/mojangson/MojangsonFinder.java deleted file mode 100644 index 26d1c7c1..00000000 --- a/src/main/java/ca/momothereal/mojangson/MojangsonFinder.java +++ /dev/null @@ -1,23 +0,0 @@ -package ca.momothereal.mojangson; - -import ca.momothereal.mojangson.ex.MojangsonParseException; -import ca.momothereal.mojangson.value.MojangsonString; -import ca.momothereal.mojangson.value.MojangsonValue; - -public class MojangsonFinder -{ - - /** - * Automatically detects the appropriate MojangsonValue from the given value. - * - * @param value The value to parse - * @return The resulting MojangsonValue. If the type couldn't be found, it falls back to MojangsonString - * @throws MojangsonParseException if the given value could not be parsed - */ - public static MojangsonValue readFromValue(String value) throws MojangsonParseException - { - MojangsonValue val = new MojangsonString(); - val.read(value); - return val; - } -} diff --git a/src/main/java/ca/momothereal/mojangson/MojangsonToken.java b/src/main/java/ca/momothereal/mojangson/MojangsonToken.java deleted file mode 100644 index 3345887e..00000000 --- a/src/main/java/ca/momothereal/mojangson/MojangsonToken.java +++ /dev/null @@ -1,53 +0,0 @@ -package ca.momothereal.mojangson; - -public enum MojangsonToken -{ - - COMPOUND_START(0, "Compound_Start", '{'), - COMPOUND_END(1, "Compound_End", '}'), - ELEMENT_SEPERATOR(2, "Element_Seperator", ','), - ARRAY_START(3, "Array_Start", '['), - ARRAY_END(4, "Array_End", ']'), - ELEMENT_PAIR_SEPERATOR(5, "Pair_Seperator", ':'), - - STRING_QUOTES(6, "String_Quotes", '\"'), - DOUBLE_SUFFIX(8, "Double_Suffix", 'd'), - BYTE_SUFFIX(9, "Byte_Suffix", 'b'), - FLOAT_SUFFIX(10, "Float_Suffix", 'f'), - SHORT_SUFFIX(11, "Short_Suffix", 's'), - LONG_SUFFIX(12, "Long_Suffix", 'l'), - - WHITE_SPACE(13, "WhiteSpace", ' '); - - private int id; - private String name; - private char symbol; - - MojangsonToken(int id, String name, char symbol) - { - this.id = id; - this.name = name; - this.symbol = symbol; - } - - public int getId() - { - return id; - } - - public String getName() - { - return name; - } - - public char getSymbol() - { - return symbol; - } - - @Override - public String toString() - { - return String.valueOf(symbol); - } -} diff --git a/src/main/java/ca/momothereal/mojangson/ex/MojangsonParseException.java b/src/main/java/ca/momothereal/mojangson/ex/MojangsonParseException.java deleted file mode 100644 index 4409dcba..00000000 --- a/src/main/java/ca/momothereal/mojangson/ex/MojangsonParseException.java +++ /dev/null @@ -1,42 +0,0 @@ -package ca.momothereal.mojangson.ex; - -public class MojangsonParseException extends Exception -{ - - private ParseExceptionReason reason; - - public MojangsonParseException(String message, ParseExceptionReason reason) - { - super(message); - this.reason = reason; - } - - public ParseExceptionReason getReason() - { - return reason; - } - - @Override - public String getMessage() - { - return reason.getMessage() + ": " + super.getMessage(); - } - - public enum ParseExceptionReason - { - INVALID_FORMAT_NUM("Given value is not numerical"), - UNEXPECTED_SYMBOL("Unexpected symbol in Mojangson string"); - - private String message; - - ParseExceptionReason(String message) - { - this.message = message; - } - - public String getMessage() - { - return message; - } - } -} diff --git a/src/main/java/ca/momothereal/mojangson/value/MojangsonCompound.java b/src/main/java/ca/momothereal/mojangson/value/MojangsonCompound.java deleted file mode 100644 index b2bb6724..00000000 --- a/src/main/java/ca/momothereal/mojangson/value/MojangsonCompound.java +++ /dev/null @@ -1,144 +0,0 @@ -package ca.momothereal.mojangson.value; - -import ca.momothereal.mojangson.MojangsonFinder; -import ca.momothereal.mojangson.ex.MojangsonParseException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import static ca.momothereal.mojangson.MojangsonToken.*; - -public class MojangsonCompound extends HashMap> implements MojangsonValue> -{ - - private final int C_COMPOUND_START = 0; // Parsing context - private final int C_COMPOUND_PAIR_KEY = 1; // Parsing context - private final int C_COMPOUND_PAIR_VALUE = 2; // Parsing context - - public MojangsonCompound() - { - - } - - public MojangsonCompound(Map map) - { - super(map); - } - - @Override - public void write(StringBuilder builder) - { - builder.append(COMPOUND_START); - boolean start = true; - - for (String key : keySet()) - { - if (start) - { - start = false; - } - else - { - builder.append(ELEMENT_SEPERATOR); - } - - builder.append(key).append(ELEMENT_PAIR_SEPERATOR); - List value = get(key); - for (MojangsonValue val : value) - { - val.write(builder); - } - } - builder.append(COMPOUND_END); - } - - @Override - public void read(String string) throws MojangsonParseException - { - int context = C_COMPOUND_START; - String tmp_key = "", tmp_val = ""; - int scope = 0; - boolean inString = false; - - for (int index = 0; index < string.length(); index++) - { - Character character = string.charAt(index); - - if (character == STRING_QUOTES.getSymbol()) - { - inString = !inString; - } - if (character == WHITE_SPACE.getSymbol()) - { - if (!inString) - { - continue; - } - } - if ((character == COMPOUND_START.getSymbol() || character == ARRAY_START.getSymbol()) && !inString) - { - scope++; - } - if ((character == COMPOUND_END.getSymbol() || character == ARRAY_END.getSymbol()) && !inString) - { - scope--; - } - if (context == C_COMPOUND_START) - { - if (character != COMPOUND_START.getSymbol()) - { - parseException(index, character); - return; - } - context++; - continue; - } - if (context == C_COMPOUND_PAIR_KEY) - { - if (character == ELEMENT_PAIR_SEPERATOR.getSymbol() && scope <= 1) - { - context++; - continue; - } - tmp_key += character; - continue; - } - if (context == C_COMPOUND_PAIR_VALUE) - { - if ((character == ELEMENT_SEPERATOR.getSymbol() || character == COMPOUND_END.getSymbol()) && scope <= 1 && !inString) - { - context = C_COMPOUND_PAIR_KEY; - computeIfAbsent(tmp_key, k -> new ArrayList<>()).add(MojangsonFinder.readFromValue(tmp_val)); - tmp_key = tmp_val = ""; - continue; - } - tmp_val += character; - } - } - } - - @Override - public Map getValue() - { - HashMap hack = new HashMap<>(); - for (String string : keySet()) - { - for (MojangsonValue value : get(string)) - { - hack.put(string, value); - } - } - return hack; - } - - @Override - public Class getValueClass() - { - return Map.class; - } - - private void parseException(int index, char symbol) throws MojangsonParseException - { - throw new MojangsonParseException("Index: " + index + ", symbol: \'" + symbol + "\'", MojangsonParseException.ParseExceptionReason.UNEXPECTED_SYMBOL); - } -} diff --git a/src/main/java/ca/momothereal/mojangson/value/MojangsonString.java b/src/main/java/ca/momothereal/mojangson/value/MojangsonString.java deleted file mode 100644 index 386b7974..00000000 --- a/src/main/java/ca/momothereal/mojangson/value/MojangsonString.java +++ /dev/null @@ -1,57 +0,0 @@ -package ca.momothereal.mojangson.value; - -import ca.momothereal.mojangson.MojangsonToken; -import ca.momothereal.mojangson.ex.MojangsonParseException; - -public class MojangsonString implements MojangsonValue -{ - private String value; - - public MojangsonString() - { - - } - - public MojangsonString(String value) - { - this.value = value; - } - - public String getValue() - { - return value; - } - - public void setValue(String value) - { - this.value = value; - } - - @Override - public void write(StringBuilder builder) - { - builder.append(MojangsonToken.STRING_QUOTES).append(value).append(MojangsonToken.STRING_QUOTES); - } - - @Override - public Class getValueClass() - { - return String.class; - } - - @Override - public void read(String string) throws MojangsonParseException - { - Character lastChar = string.charAt(string.length() - 1); - Character firstChar = string.charAt(0); - - if (firstChar == MojangsonToken.STRING_QUOTES.getSymbol() && lastChar == MojangsonToken.STRING_QUOTES.getSymbol()) - { - value = string.substring(1, string.length() - 1); - } - else - { - value = string; - } - } -} diff --git a/src/main/java/ca/momothereal/mojangson/value/MojangsonValue.java b/src/main/java/ca/momothereal/mojangson/value/MojangsonValue.java deleted file mode 100644 index 088238b4..00000000 --- a/src/main/java/ca/momothereal/mojangson/value/MojangsonValue.java +++ /dev/null @@ -1,42 +0,0 @@ -package ca.momothereal.mojangson.value; - -import ca.momothereal.mojangson.ex.MojangsonParseException; - -/** - * Represents a value inside a compound or array. - * - * @param The type of value this MojangsonValue holds - */ -public interface MojangsonValue -{ - - /** - * Writes the value to a StringBuilder buffer. - * - * @param builder The buffer to write to - */ - void write(StringBuilder builder); - - /** - * Parses and updates the current value to the given string representation - * - * @param string The string representation of the value - * @throws MojangsonParseException if the given value cannot be parsed - */ - void read(String string) throws MojangsonParseException; - - /** - * Gets the current literal value - * - * @return The current literal value of the MojangsonValue - */ - T getValue(); - - /** - * Gets the literal value's class - * - * @return The literal value's class - */ - Class getValueClass(); - -} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index 7fc45659..034629a1 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -50,7 +50,7 @@ import me.totalfreedom.totalfreedommod.util.MethodTimer; import me.totalfreedom.totalfreedommod.world.CleanroomChunkGenerator; import me.totalfreedom.totalfreedommod.world.WorldManager; import me.totalfreedom.totalfreedommod.world.WorldRestrictions; -import org.bstats.Metrics; +import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.generator.ChunkGenerator; import org.bukkit.plugin.Plugin; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_coins.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_coins.java index 36bf5758..50ab4b63 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_coins.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_coins.java @@ -13,7 +13,6 @@ import org.bukkit.entity.Player; @CommandParameters(description = "Shows the amount of coins you have or another player has", usage = "/ [playername]") public class Command_coins extends FreedomCommand { - @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java b/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java index 91b453b2..ce5fb786 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java @@ -93,7 +93,7 @@ public class SQLite extends FreedomService { try { - connection.createStatement().execute("CREATE TABLE `players` (`username` VARCHAR NOT NULL, `ips` VARCHAR NOT NULL, `notes` VARCHAR, `tag` VARCHAR, `discord_id` VARCHAR, `backup_codes` VARCHAR, `donator` BOOLEAN NOT NULL, `master_builder` BOOLEAN NOT NULL,`verification` BOOLEAN NOT NULL, `ride_mode` VARCHAR NOT NULL, `coins` INT NOT NULL, `items` VARCHAR, `total_votes` INT NOT NULL, `display_discord` BOOLEAN NOT NULL, `reddit_username` VARCHAR NOT NULL, `login_message` VARCHAR);"); + connection.createStatement().execute("CREATE TABLE `players` (`username` VARCHAR NOT NULL, `ips` VARCHAR NOT NULL, `notes` VARCHAR, `tag` VARCHAR, `discord_id` VARCHAR, `backup_codes` VARCHAR, `donator` BOOLEAN NOT NULL, `master_builder` BOOLEAN NOT NULL,`verification` BOOLEAN NOT NULL, `ride_mode` VARCHAR NOT NULL, `coins` INT NOT NULL, `items` VARCHAR, `total_votes` INT NOT NULL, `display_discord` BOOLEAN NOT NULL, `reddit_username` VARCHAR, `login_message` VARCHAR);"); } catch (SQLException e) { diff --git a/src/main/java/org/bstats/Metrics.java b/src/main/java/org/bstats/Metrics.java deleted file mode 100644 index 4fd5ae54..00000000 --- a/src/main/java/org/bstats/Metrics.java +++ /dev/null @@ -1,847 +0,0 @@ -package org.bstats; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.JsonPrimitive; -import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Timer; -import java.util.TimerTask; -import java.util.UUID; -import java.util.concurrent.Callable; -import java.util.logging.Level; -import java.util.zip.GZIPOutputStream; -import javax.net.ssl.HttpsURLConnection; -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.RegisteredServiceProvider; -import org.bukkit.plugin.ServicePriority; - -/** - * bStats collects some data for plugin authors. - *

- * Check out https://bStats.org/ to learn more about bStats! - */ -@SuppressWarnings({"WeakerAccess", "unused"}) -public class Metrics -{ - static - { - // You can use the property to disable the check in your test environment - if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) - { - // Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D - final String defaultPackage = new String( - new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'}); - final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'}); - // We want to make sure nobody just copy & pastes the example and use the wrong package names - if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) - { - throw new IllegalStateException("bStats Metrics class has not been relocated correctly!"); - } - } - } - - // The version of this bStats class - public static final int B_STATS_VERSION = 1; - - // The url to which the data is sent - private static final String URL = "https://bStats.org/submitData/bukkit"; - - // Is bStats enabled on this server? - private boolean enabled; - - // Should failed requests be logged? - private static boolean logFailedRequests; - - // Should the sent data be logged? - private static boolean logSentData; - - // Should the response text be logged? - private static boolean logResponseStatusText; - - // The uuid of the server - private static String serverUUID; - - // The plugin - private final Plugin plugin; - - // The plugin id - private final int pluginId; - - // A list with all custom charts - private final List charts = new ArrayList<>(); - - /** - * Class constructor. - * - * @param plugin The plugin which stats should be submitted. - * @param pluginId The id of the plugin. - * It can be found at What is my plugin id? - */ - public Metrics(Plugin plugin, int pluginId) - { - if (plugin == null) - { - throw new IllegalArgumentException("Plugin cannot be null!"); - } - this.plugin = plugin; - this.pluginId = pluginId; - - // Get the config file - File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats"); - File configFile = new File(bStatsFolder, "config.yml"); - YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); - - // Check if the config file exists - if (!config.isSet("serverUuid")) - { - - // Add default values - config.addDefault("enabled", true); - // Every server gets it's unique random id. - config.addDefault("serverUuid", UUID.randomUUID().toString()); - // Should failed request be logged? - config.addDefault("logFailedRequests", false); - // Should the sent data be logged? - config.addDefault("logSentData", false); - // Should the response text be logged? - config.addDefault("logResponseStatusText", false); - - // Inform the server owners about bStats - config.options().header( - "bStats collects some data for plugin authors like how many servers are using their plugins.\n" + - "To honor their work, you should not disable it.\n" + - "This has nearly no effect on the server performance!\n" + - "Check out https://bStats.org/ to learn more :)" - ).copyDefaults(true); - try - { - config.save(configFile); - } - catch (IOException ignored) - { - } - } - - // Load the data - enabled = config.getBoolean("enabled", true); - serverUUID = config.getString("serverUuid"); - logFailedRequests = config.getBoolean("logFailedRequests", false); - logSentData = config.getBoolean("logSentData", false); - logResponseStatusText = config.getBoolean("logResponseStatusText", false); - - if (enabled) - { - boolean found = false; - // Search for all other bStats Metrics classes to see if we are the first one - for (Class service : Bukkit.getServicesManager().getKnownServices()) - { - try - { - service.getField("B_STATS_VERSION"); // Our identifier :) - found = true; // We aren't the first - break; - } - catch (NoSuchFieldException ignored) - { - } - } - // Register our service - Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal); - if (!found) - { - // We are the first! - startSubmitting(); - } - } - } - - /** - * Checks if bStats is enabled. - * - * @return Whether bStats is enabled or not. - */ - public boolean isEnabled() - { - return enabled; - } - - /** - * Adds a custom chart. - * - * @param chart The chart to add. - */ - public void addCustomChart(CustomChart chart) - { - if (chart == null) - { - throw new IllegalArgumentException("Chart cannot be null!"); - } - charts.add(chart); - } - - /** - * Starts the Scheduler which submits our data every 30 minutes. - */ - private void startSubmitting() - { - final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags - timer.scheduleAtFixedRate(new TimerTask() - { - @Override - public void run() - { - if (!plugin.isEnabled()) - { // Plugin was disabled - timer.cancel(); - return; - } - // Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler - // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;) - Bukkit.getScheduler().runTask(plugin, () -> submitData()); - } - }, 1000 * 60 * 5, 1000 * 60 * 30); - // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start - // WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted! - // WARNING: Just don't do it! - } - - /** - * Gets the plugin specific data. - * This method is called using Reflection. - * - * @return The plugin specific data. - */ - public JsonObject getPluginData() - { - JsonObject data = new JsonObject(); - - String pluginName = plugin.getDescription().getName(); - String pluginVersion = plugin.getDescription().getVersion(); - - data.addProperty("pluginName", pluginName); // Append the name of the plugin - data.addProperty("id", pluginId); // Append the id of the plugin - data.addProperty("pluginVersion", pluginVersion); // Append the version of the plugin - JsonArray customCharts = new JsonArray(); - for (CustomChart customChart : charts) - { - // Add the data of the custom charts - JsonObject chart = customChart.getRequestJsonObject(); - if (chart == null) - { // If the chart is null, we skip it - continue; - } - customCharts.add(chart); - } - data.add("customCharts", customCharts); - - return data; - } - - /** - * Gets the server specific data. - * - * @return The server specific data. - */ - private JsonObject getServerData() - { - // Minecraft specific data - int playerAmount; - try - { - // Around MC 1.8 the return type was changed to a collection from an array, - // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection; - Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers"); - playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class) - ? ((Collection)onlinePlayersMethod.invoke(Bukkit.getServer())).size() - : ((Player[])onlinePlayersMethod.invoke(Bukkit.getServer())).length; - } - catch (Exception e) - { - playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed - } - int onlineMode = Bukkit.getOnlineMode() ? 1 : 0; - String bukkitVersion = Bukkit.getVersion(); - String bukkitName = Bukkit.getName(); - - // OS/Java specific data - String javaVersion = System.getProperty("java.version"); - String osName = System.getProperty("os.name"); - String osArch = System.getProperty("os.arch"); - String osVersion = System.getProperty("os.version"); - int coreCount = Runtime.getRuntime().availableProcessors(); - - JsonObject data = new JsonObject(); - - data.addProperty("serverUUID", serverUUID); - - data.addProperty("playerAmount", playerAmount); - data.addProperty("onlineMode", onlineMode); - data.addProperty("bukkitVersion", bukkitVersion); - data.addProperty("bukkitName", bukkitName); - - data.addProperty("javaVersion", javaVersion); - data.addProperty("osName", osName); - data.addProperty("osArch", osArch); - data.addProperty("osVersion", osVersion); - data.addProperty("coreCount", coreCount); - - return data; - } - - /** - * Collects the data and sends it afterwards. - */ - private void submitData() - { - final JsonObject data = getServerData(); - - JsonArray pluginData = new JsonArray(); - // Search for all other bStats Metrics classes to get their plugin data - for (Class service : Bukkit.getServicesManager().getKnownServices()) - { - try - { - service.getField("B_STATS_VERSION"); // Our identifier :) - - for (RegisteredServiceProvider provider : Bukkit.getServicesManager().getRegistrations(service)) - { - try - { - Object plugin = provider.getService().getMethod("getPluginData").invoke(provider.getProvider()); - if (plugin instanceof JsonObject) - { - pluginData.add((JsonObject)plugin); - } - else - { // old bstats version compatibility - try - { - Class jsonObjectJsonSimple = Class.forName("org.json.simple.JSONObject"); - if (plugin.getClass().isAssignableFrom(jsonObjectJsonSimple)) - { - Method jsonStringGetter = jsonObjectJsonSimple.getDeclaredMethod("toJSONString"); - jsonStringGetter.setAccessible(true); - String jsonString = (String)jsonStringGetter.invoke(plugin); - JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject(); - pluginData.add(object); - } - } - catch (ClassNotFoundException e) - { - // minecraft version 1.14+ - if (logFailedRequests) - { - this.plugin.getLogger().log(Level.SEVERE, "Encountered unexpected exception", e); - } - } - } - } - catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) - { - } - } - } - catch (NoSuchFieldException ignored) - { - } - } - - data.add("plugins", pluginData); - - // Create a new thread for the connection to the bStats server - new Thread(() -> - { - try - { - // Send the data - sendData(plugin, data); - } - catch (Exception e) - { - // Something went wrong! :( - if (logFailedRequests) - { - plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e); - } - } - }).start(); - } - - /** - * Sends the data to the bStats server. - * - * @param plugin Any plugin. It's just used to get a logger instance. - * @param data The data to send. - * @throws Exception If the request failed. - */ - private static void sendData(Plugin plugin, JsonObject data) throws Exception - { - if (data == null) - { - throw new IllegalArgumentException("Data cannot be null!"); - } - if (Bukkit.isPrimaryThread()) - { - throw new IllegalAccessException("This method must not be called from the main thread!"); - } - if (logSentData) - { - plugin.getLogger().info("Sending data to bStats: " + data); - } - HttpsURLConnection connection = (HttpsURLConnection)new URL(URL).openConnection(); - - // Compress the data to save bandwidth - byte[] compressedData = compress(data.toString()); - - // Add headers - connection.setRequestMethod("POST"); - connection.addRequestProperty("Accept", "application/json"); - connection.addRequestProperty("Connection", "close"); - connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request - connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length)); - connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format - connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION); - - // Send data - connection.setDoOutput(true); - try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) - { - outputStream.write(compressedData); - } - - StringBuilder builder = new StringBuilder(); - try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) - { - String line; - while ((line = bufferedReader.readLine()) != null) - { - builder.append(line); - } - } - - if (logResponseStatusText) - { - plugin.getLogger().info("Sent data to bStats and received response: " + builder); - } - } - - /** - * Gzips the given String. - * - * @param str The string to gzip. - * @return The gzipped String. - * @throws IOException If the compression failed. - */ - private static byte[] compress(final String str) throws IOException - { - if (str == null) - { - return null; - } - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) - { - gzip.write(str.getBytes(StandardCharsets.UTF_8)); - } - return outputStream.toByteArray(); - } - - /** - * Represents a custom chart. - */ - public static abstract class CustomChart - { - - // The id of the chart - final String chartId; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - */ - CustomChart(String chartId) - { - if (chartId == null || chartId.isEmpty()) - { - throw new IllegalArgumentException("ChartId cannot be null or empty!"); - } - this.chartId = chartId; - } - - private JsonObject getRequestJsonObject() - { - JsonObject chart = new JsonObject(); - chart.addProperty("chartId", chartId); - try - { - JsonObject data = getChartData(); - if (data == null) - { - // If the data is null we don't send the chart. - return null; - } - chart.add("data", data); - } - catch (Throwable t) - { - if (logFailedRequests) - { - Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t); - } - return null; - } - return chart; - } - - protected abstract JsonObject getChartData() throws Exception; - - } - - /** - * Represents a custom simple pie. - */ - public static class SimplePie extends CustomChart - { - - private final Callable callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public SimplePie(String chartId, Callable callable) - { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObject getChartData() throws Exception - { - JsonObject data = new JsonObject(); - String value = callable.call(); - if (value == null || value.isEmpty()) - { - // Null = skip the chart - return null; - } - data.addProperty("value", value); - return data; - } - } - - /** - * Represents a custom advanced pie. - */ - public static class AdvancedPie extends CustomChart - { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public AdvancedPie(String chartId, Callable> callable) - { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObject getChartData() throws Exception - { - JsonObject data = new JsonObject(); - JsonObject values = new JsonObject(); - Map map = callable.call(); - if (map == null || map.isEmpty()) - { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) - { - if (entry.getValue() == 0) - { - continue; // Skip this invalid - } - allSkipped = false; - values.addProperty(entry.getKey(), entry.getValue()); - } - if (allSkipped) - { - // Null = skip the chart - return null; - } - data.add("values", values); - return data; - } - } - - /** - * Represents a custom drilldown pie. - */ - public static class DrilldownPie extends CustomChart - { - - private final Callable>> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public DrilldownPie(String chartId, Callable>> callable) - { - super(chartId); - this.callable = callable; - } - - @Override - public JsonObject getChartData() throws Exception - { - JsonObject data = new JsonObject(); - JsonObject values = new JsonObject(); - Map> map = callable.call(); - if (map == null || map.isEmpty()) - { - // Null = skip the chart - return null; - } - boolean reallyAllSkipped = true; - for (Map.Entry> entryValues : map.entrySet()) - { - JsonObject value = new JsonObject(); - boolean allSkipped = true; - for (Map.Entry valueEntry : map.get(entryValues.getKey()).entrySet()) - { - value.addProperty(valueEntry.getKey(), valueEntry.getValue()); - allSkipped = false; - } - if (!allSkipped) - { - reallyAllSkipped = false; - values.add(entryValues.getKey(), value); - } - } - if (reallyAllSkipped) - { - // Null = skip the chart - return null; - } - data.add("values", values); - return data; - } - } - - /** - * Represents a custom single line chart. - */ - public static class SingleLineChart extends CustomChart - { - - private final Callable callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public SingleLineChart(String chartId, Callable callable) - { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObject getChartData() throws Exception - { - JsonObject data = new JsonObject(); - int value = callable.call(); - if (value == 0) - { - // Null = skip the chart - return null; - } - data.addProperty("value", value); - return data; - } - - } - - /** - * Represents a custom multi line chart. - */ - public static class MultiLineChart extends CustomChart - { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public MultiLineChart(String chartId, Callable> callable) - { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObject getChartData() throws Exception - { - JsonObject data = new JsonObject(); - JsonObject values = new JsonObject(); - Map map = callable.call(); - if (map == null || map.isEmpty()) - { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) - { - if (entry.getValue() == 0) - { - continue; // Skip this invalid - } - allSkipped = false; - values.addProperty(entry.getKey(), entry.getValue()); - } - if (allSkipped) - { - // Null = skip the chart - return null; - } - data.add("values", values); - return data; - } - - } - - /** - * Represents a custom simple bar chart. - */ - public static class SimpleBarChart extends CustomChart - { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public SimpleBarChart(String chartId, Callable> callable) - { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObject getChartData() throws Exception - { - JsonObject data = new JsonObject(); - JsonObject values = new JsonObject(); - Map map = callable.call(); - if (map == null || map.isEmpty()) - { - // Null = skip the chart - return null; - } - for (Map.Entry entry : map.entrySet()) - { - JsonArray categoryValues = new JsonArray(); - categoryValues.add(new JsonPrimitive(entry.getValue())); - values.add(entry.getKey(), categoryValues); - } - data.add("values", values); - return data; - } - - } - - /** - * Represents a custom advanced bar chart. - */ - public static class AdvancedBarChart extends CustomChart - { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public AdvancedBarChart(String chartId, Callable> callable) - { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObject getChartData() throws Exception - { - JsonObject data = new JsonObject(); - JsonObject values = new JsonObject(); - Map map = callable.call(); - if (map == null || map.isEmpty()) - { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) - { - if (entry.getValue().length == 0) - { - continue; // Skip this invalid - } - allSkipped = false; - JsonArray categoryValues = new JsonArray(); - for (int categoryValue : entry.getValue()) - { - categoryValues.add(new JsonPrimitive(categoryValue)); - } - values.add(entry.getKey(), categoryValues); - } - if (allSkipped) - { - // Null = skip the chart - return null; - } - data.add("values", values); - return data; - } - } -} \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 316cb770..13f36a8e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -150,12 +150,12 @@ shop: login_messages: - '%name% is a terrible %coloredrank%' - 'that %name% dude is a shitty %coloredrank%' - - 'Hi, my name is %name% and I'm %art% %coloredrank%&b that wasted coins on this login message.' + - 'Hi, my name is %name% and I''m %art% %coloredrank%&b that wasted coins on this login message.' - '&aDo not fear, %coloredrank% &b%name% &ais here!' - '%name% is %art% %coloredrank%&b, say hi to them before they gets banned for doing something stupid' - - 'Oh. It's &l%name%&r&b the %coloredrank%&b again. Great.' + - 'Oh. It''s &l%name%&r&b the %coloredrank%&b again. Great.' - 'Make way for %name% the %coloredrank%&b!' - - 'It's a bird! It's a plane! No, it's %art% %rank%! It's %name%' + - 'It''s a bird! It''s a plane! No, it''s %art% %rank%! It''s %name%' - '%rank% %name%' - '%coloredrank%&b %name%' - 'A wild %name%, %art% %coloredrank%&b, appeared!' @@ -163,6 +163,7 @@ shop: - '&a%name% &bis a a geeky &6%rank%' - '%name% is the %rank% who just exists' - '%name% based cringe poggers based based %rank%' + - '%name% thinks that &dWindows Server 2019 &bis the best server OS' # Item prices prices: