mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 22:17:17 +00:00
Change formatting system to use MineDown (https://github.com/Phoenix616/MineDown)
Rename huskHomes1Migrator.java class to legacyVersionMigrator.java Increment version number to 2.1.0
This commit is contained in:
1 parent
8559bd6161
commit
96cc08d71b
9 files changed
+284
-223
No files matched your search
@@ -7,7 +7,7 @@ import me.william278.huskhomes2.Events.onPlayerDeath;
|
||||
import me.william278.huskhomes2.Events.onPlayerJoin;
|
||||
import me.william278.huskhomes2.Integrations.dynamicMap;
|
||||
import me.william278.huskhomes2.Integrations.economy;
|
||||
import me.william278.huskhomes2.Migrators.huskHomes1Migrator;
|
||||
import me.william278.huskhomes2.Migrators.legacyVersionMigrator;
|
||||
import me.william278.huskhomes2.Objects.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@@ -120,14 +120,14 @@ public final class HuskHomes extends JavaPlugin {
|
||||
getLogger().info(versionChecker.getVersionCheckString());
|
||||
|
||||
// MIGRATION: Check if a migration needs to occur
|
||||
huskHomes1Migrator.checkStartupMigration();
|
||||
legacyVersionMigrator.checkStartupMigration();
|
||||
|
||||
// Load the config
|
||||
configManager.loadConfig();
|
||||
|
||||
// MIGRATION: Migrate config files
|
||||
if (huskHomes1Migrator.startupMigrate) {
|
||||
new huskHomes1Migrator().migrateConfig();
|
||||
if (legacyVersionMigrator.startupMigrate) {
|
||||
new legacyVersionMigrator().migrateConfig();
|
||||
}
|
||||
|
||||
// Load the messages (in the right language)
|
||||
@@ -140,9 +140,9 @@ public final class HuskHomes extends JavaPlugin {
|
||||
dataManager.setupStorage();
|
||||
|
||||
// MIGRATION: Migrate SQL data
|
||||
if (huskHomes1Migrator.startupMigrate) {
|
||||
new huskHomes1Migrator().migratePlayerData();
|
||||
new huskHomes1Migrator().migrateHomeData();
|
||||
if (legacyVersionMigrator.startupMigrate) {
|
||||
new legacyVersionMigrator().migratePlayerData();
|
||||
new legacyVersionMigrator().migrateHomeData();
|
||||
}
|
||||
|
||||
// Setup the Dynmap integration if it is enabled
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ import java.util.UUID;
|
||||
import static org.bukkit.configuration.file.YamlConfiguration.loadConfiguration;
|
||||
|
||||
// This class migrates data from HuskHomes 1.5.x to HuskHomes 2.x
|
||||
public class huskHomes1Migrator {
|
||||
public class legacyVersionMigrator {
|
||||
|
||||
public static boolean startupMigrate;
|
||||
private static String sourcePlayerTable;
|
||||
@@ -24,11 +24,11 @@ public class editingHandler {
|
||||
private static ComponentBuilder editWarpOptions(Warp warp) {
|
||||
ComponentBuilder options = new ComponentBuilder();
|
||||
|
||||
options.append(optionButton("[Teleport] ", net.md_5.bungee.api.ChatColor.GREEN, ClickEvent.Action.RUN_COMMAND, "/warp " + warp.getName(), "Teleport to this warp"));
|
||||
options.append(optionButton("[Delete] ", net.md_5.bungee.api.ChatColor.RED, ClickEvent.Action.RUN_COMMAND, "/delwarp " + warp.getName(), "Delete this warp"));
|
||||
options.append(optionButton("[Relocate]\n", net.md_5.bungee.api.ChatColor.BLUE, ClickEvent.Action.RUN_COMMAND, "/editwarp " + warp.getName() + " location", "Update this warp's location"));
|
||||
options.append(optionButton("[Rename] ", net.md_5.bungee.api.ChatColor.YELLOW, ClickEvent.Action.SUGGEST_COMMAND, "/editwarp " + warp.getName() + " rename ", "Change the name of this warp"));
|
||||
options.append(optionButton("[Edit Description] ", net.md_5.bungee.api.ChatColor.GOLD, ClickEvent.Action.SUGGEST_COMMAND, "/editwarp " + warp.getName() + " description ", "Update this warp's description"));
|
||||
options.append(optionButton(messageManager.getRawMessage("edit_warp_teleport_button") + " ", net.md_5.bungee.api.ChatColor.GREEN, ClickEvent.Action.RUN_COMMAND, "/warp " + warp.getName(), messageManager.getRawMessage("edit_warp_teleport_button_tooltip")));
|
||||
options.append(optionButton(messageManager.getRawMessage("edit_warp_delete_button") + " ", net.md_5.bungee.api.ChatColor.RED, ClickEvent.Action.RUN_COMMAND, "/delwarp " + warp.getName(), messageManager.getRawMessage("edit_warp_delete_button_tooltip")));
|
||||
options.append(optionButton(messageManager.getRawMessage("edit_warp_relocate_button") + "\n", net.md_5.bungee.api.ChatColor.BLUE, ClickEvent.Action.RUN_COMMAND, "/editwarp " + warp.getName() + " location", messageManager.getRawMessage("edit_warp_relocate_button_tooltip")));
|
||||
options.append(optionButton(messageManager.getRawMessage("edit_warp_rename_button") + " ", net.md_5.bungee.api.ChatColor.YELLOW, ClickEvent.Action.SUGGEST_COMMAND, "/editwarp " + warp.getName() + " rename ", messageManager.getRawMessage("edit_warp_rename_button_tooltip")));
|
||||
options.append(optionButton(messageManager.getRawMessage("edit_warp_description_button") + " ", net.md_5.bungee.api.ChatColor.GOLD, ClickEvent.Action.SUGGEST_COMMAND, "/editwarp " + warp.getName() + " description ", messageManager.getRawMessage("edit_warp_description_button_tooltip")));
|
||||
|
||||
return options;
|
||||
}
|
||||
@@ -36,17 +36,17 @@ public class editingHandler {
|
||||
private static ComponentBuilder editHomeOptions(Player p, Home home) {
|
||||
ComponentBuilder options = new ComponentBuilder();
|
||||
|
||||
options.append(optionButton("[Teleport] ", net.md_5.bungee.api.ChatColor.GREEN, ClickEvent.Action.RUN_COMMAND, "/home " + home.getName(), "Teleport to your home"));
|
||||
options.append(optionButton("[Delete] ", net.md_5.bungee.api.ChatColor.RED, ClickEvent.Action.RUN_COMMAND, "/delhome " + home.getName(), "Delete your home"));
|
||||
options.append(optionButton("[Relocate]\n", net.md_5.bungee.api.ChatColor.BLUE, ClickEvent.Action.RUN_COMMAND, "/edithome " + home.getName() + " location", "Update your home's location"));
|
||||
options.append(optionButton("[Rename] ", net.md_5.bungee.api.ChatColor.YELLOW, ClickEvent.Action.SUGGEST_COMMAND, "/edithome " + home.getName() + " rename ", "Change the name of your home"));
|
||||
options.append(optionButton("[Edit Description] ", net.md_5.bungee.api.ChatColor.GOLD, ClickEvent.Action.SUGGEST_COMMAND, "/edithome " + home.getName() + " description ", "Update the description of your home"));
|
||||
options.append(optionButton(messageManager.getRawMessage("edit_home_teleport_button") + " ", net.md_5.bungee.api.ChatColor.GREEN, ClickEvent.Action.RUN_COMMAND, "/home " + home.getName(), messageManager.getRawMessage("edit_home_teleport_button_tooltip")));
|
||||
options.append(optionButton(messageManager.getRawMessage("edit_home_delete_button") + " ", net.md_5.bungee.api.ChatColor.RED, ClickEvent.Action.RUN_COMMAND, "/delhome " + home.getName(), messageManager.getRawMessage("edit_home_delete_button_tooltip")));
|
||||
options.append(optionButton(messageManager.getRawMessage("edit_home_relocate_button") + "\n", net.md_5.bungee.api.ChatColor.BLUE, ClickEvent.Action.RUN_COMMAND, "/edithome " + home.getName() + " location", messageManager.getRawMessage("edit_home_relocate_button_tooltip")));
|
||||
options.append(optionButton(messageManager.getRawMessage("edit_home_rename_button") + " ", net.md_5.bungee.api.ChatColor.YELLOW, ClickEvent.Action.SUGGEST_COMMAND, "/edithome " + home.getName() + " rename ", messageManager.getRawMessage("edit_home_rename_button_tooltip")));
|
||||
options.append(optionButton(messageManager.getRawMessage("edit_home_description_button") + " ", net.md_5.bungee.api.ChatColor.GOLD, ClickEvent.Action.SUGGEST_COMMAND, "/edithome " + home.getName() + " description ", messageManager.getRawMessage("edit_home_description_button_tooltip")));
|
||||
|
||||
if (p.hasPermission("huskhomes.edithome.public")) {
|
||||
if (!home.isPublic()) {
|
||||
options.append(optionButton("[Make Public] ", net.md_5.bungee.api.ChatColor.DARK_GREEN, ClickEvent.Action.RUN_COMMAND, "/edithome " + home.getName() + " public", "Open your home to the public"));
|
||||
options.append(optionButton(messageManager.getRawMessage("edit_home_make_public_button") + " ", net.md_5.bungee.api.ChatColor.DARK_GREEN, ClickEvent.Action.RUN_COMMAND, "/edithome " + home.getName() + " public", messageManager.getRawMessage("edit_home_make_public_button_tooltip")));
|
||||
} else {
|
||||
options.append(optionButton("[Make Private] ", net.md_5.bungee.api.ChatColor.DARK_RED, ClickEvent.Action.RUN_COMMAND, "/edithome " + home.getName() + " private", "Make your home private"));
|
||||
options.append(optionButton(messageManager.getRawMessage("edit_home_make_private_button") + " ", net.md_5.bungee.api.ChatColor.DARK_RED, ClickEvent.Action.RUN_COMMAND, "/edithome " + home.getName() + " private", messageManager.getRawMessage("edit_home_make_private_button_tooltip")));
|
||||
}
|
||||
}
|
||||
return options;
|
||||
|
||||
@@ -55,9 +55,9 @@ public class listHandler {
|
||||
|
||||
private static void displayPageButtons(Player p, int pageNumber, int homeListSize, int homeUpperBound, String command) {
|
||||
ComponentBuilder pageButtons = new ComponentBuilder();
|
||||
TextComponent nextPageButton = pageButton("[Next Page >]", net.md_5.bungee.api.ChatColor.GREEN, command + " " + (pageNumber + 1), "Click to view next 10");
|
||||
TextComponent previousPageButton = pageButton("[< Last Page]", net.md_5.bungee.api.ChatColor.RED, command + " " + (pageNumber - 1), "Click to view previous 10");
|
||||
TextComponent divider = new TextComponent(" • ");
|
||||
TextComponent nextPageButton = pageButton(messageManager.getRawMessage("list_button_next_page"), net.md_5.bungee.api.ChatColor.GREEN, command + " " + (pageNumber + 1), messageManager.getRawMessage("list_button_next_page_tooltip"));
|
||||
TextComponent previousPageButton = pageButton(messageManager.getRawMessage("list_button_previous_page"), net.md_5.bungee.api.ChatColor.RED, command + " " + (pageNumber - 1), messageManager.getRawMessage("list_button_previous_page_tooltip"));
|
||||
TextComponent divider = new TextComponent(messageManager.getRawMessage("list_item_divider"));
|
||||
divider.setColor(net.md_5.bungee.api.ChatColor.GRAY);
|
||||
|
||||
if (pageNumber != 1) {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package me.william278.huskhomes2;
|
||||
|
||||
import de.themoep.minedown.MineDown;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@@ -14,17 +15,14 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static net.md_5.bungee.api.ChatColor.COLOR_CHAR;
|
||||
import static org.bukkit.configuration.file.YamlConfiguration.loadConfiguration;
|
||||
|
||||
public class messageManager {
|
||||
|
||||
private static final int languageFileVersion = 1;
|
||||
|
||||
private static HashMap<String, String> messages = new HashMap<>();
|
||||
private static final HashMap<String, String> messages = new HashMap<>();
|
||||
|
||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||
|
||||
@@ -75,11 +73,9 @@ public class messageManager {
|
||||
"| Developed by William278 |\n" +
|
||||
" ------------------------------ \n" +
|
||||
"If you'd like to use a different language, you can change it in the config.yml \n" +
|
||||
"Change the appearance/text of messages in the plugin using this config: \n" +
|
||||
"1. Use the selection symbol (§) followed by a Minecraft color code to add color to the messages.\n" +
|
||||
"2. Use an ampersand symbol and hashtag (&#) followed by a 6 digit hex code to add custom colors.\n" +
|
||||
"3. Example 1: \"§cHello!\" will display \"Hello!\" in light red.\n" +
|
||||
"4. Example 2: \" CD32Hello\" will display \"Hello!\" in a bright green color (hex: #32CD32)");
|
||||
"Change the appearance/text of messages in the plugin using this config. \n" +
|
||||
"This config makes use of MineDown formatting, with extensive support for custom colors & formats. \n" +
|
||||
"For formatting help, see: https://github.com/Phoenix616/MineDown or check the HuskHomes Wiki.");
|
||||
InputStream defaultMessageFile = plugin.getResource("Languages/" + language + ".yml");
|
||||
if (defaultMessageFile != null) {
|
||||
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(new InputStreamReader(defaultMessageFile, StandardCharsets.UTF_8));
|
||||
@@ -93,23 +89,6 @@ public class messageManager {
|
||||
}
|
||||
}
|
||||
|
||||
// Translate hexadecimal custom color codes
|
||||
private static String translateHexColorCodes(String message) {
|
||||
final Pattern hexPattern = Pattern.compile("&#([A-Fa-f0-9]{6})");
|
||||
|
||||
Matcher matcher = hexPattern.matcher(message);
|
||||
StringBuffer buffer = new StringBuffer(message.length() + 4 * 8);
|
||||
while (matcher.find()) {
|
||||
String group = matcher.group(1);
|
||||
matcher.appendReplacement(buffer, COLOR_CHAR + "x"
|
||||
+ COLOR_CHAR + group.charAt(0) + COLOR_CHAR + group.charAt(1)
|
||||
+ COLOR_CHAR + group.charAt(2) + COLOR_CHAR + group.charAt(3)
|
||||
+ COLOR_CHAR + group.charAt(4) + COLOR_CHAR + group.charAt(5)
|
||||
);
|
||||
}
|
||||
return matcher.appendTail(buffer).toString();
|
||||
}
|
||||
|
||||
// Send a message with multiple placeholders
|
||||
public static void sendMessage(Player p, String messageID, String... placeholderReplacements) {
|
||||
sendMessage(p, ChatMessageType.CHAT, messageID, placeholderReplacements);
|
||||
@@ -122,7 +101,7 @@ public class messageManager {
|
||||
|
||||
// Send a message to the correct channel
|
||||
private static void sendMessage(Player p, ChatMessageType chatMessageType, String messageID, String... placeholderReplacements) {
|
||||
String message = messages.get(messageID);
|
||||
String message = getRawMessage(messageID);
|
||||
int replacementIndexer = 1;
|
||||
|
||||
// Replace placeholders
|
||||
@@ -132,16 +111,26 @@ public class messageManager {
|
||||
replacementIndexer = replacementIndexer + 1;
|
||||
}
|
||||
|
||||
// Get formatted base components from MineDown
|
||||
BaseComponent[] components = new MineDown(message).toComponent();
|
||||
|
||||
// Convert to text component and send
|
||||
p.spigot().sendMessage(chatMessageType, TextComponent.fromLegacyText(translateHexColorCodes(message)));
|
||||
p.spigot().sendMessage(chatMessageType, components);
|
||||
}
|
||||
|
||||
// Send a message with no placeholder parameters
|
||||
public static void sendMessage(Player p, String messageID) {
|
||||
String message = messages.get(messageID);
|
||||
String message = getRawMessage(messageID);
|
||||
|
||||
// Get formatted base components from MineDown
|
||||
BaseComponent[] components = new MineDown(message).toComponent();
|
||||
|
||||
// Convert to text component and send
|
||||
p.spigot().sendMessage(TextComponent.fromLegacyText(translateHexColorCodes(message)));
|
||||
p.spigot().sendMessage(components);
|
||||
}
|
||||
|
||||
public static String getRawMessage(String messageID) {
|
||||
return messages.get(messageID);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -69,22 +69,26 @@ public class settingHandler {
|
||||
public static void deleteHome(Player player, String homeName) {
|
||||
if (dataManager.homeExists(player, homeName)) {
|
||||
Home home = dataManager.getHome(player.getName(), homeName);
|
||||
if (home.isPublic()) {
|
||||
// Delete dynmap marker if it exists & if the home is public
|
||||
if (HuskHomes.settings.doDynmap() && HuskHomes.settings.showPublicHomesOnDynmap()) {
|
||||
dynamicMap.removeDynamicMapMarker(homeName, player.getName());
|
||||
if (home != null) {
|
||||
if (home.isPublic()) {
|
||||
// Delete Dynmap marker if it exists & if the home is public
|
||||
if (HuskHomes.settings.doDynmap() && HuskHomes.settings.showPublicHomesOnDynmap()) {
|
||||
dynamicMap.removeDynamicMapMarker(homeName, player.getName());
|
||||
}
|
||||
PlayerDeleteHomeEvent event = new PlayerDeleteHomeEvent(player, home);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
dataManager.deleteHome(homeName, player);
|
||||
publicHomeTabCompleter.updatePublicHomeTabCache();
|
||||
} else {
|
||||
dataManager.deleteHome(homeName, player);
|
||||
}
|
||||
PlayerDeleteHomeEvent event = new PlayerDeleteHomeEvent(player, home);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
dataManager.deleteHome(homeName, player);
|
||||
publicHomeTabCompleter.updatePublicHomeTabCache();
|
||||
homeTabCompleter.updatePlayerHomeCache(player);
|
||||
messageManager.sendMessage(player, "home_deleted", homeName);
|
||||
} else {
|
||||
dataManager.deleteHome(homeName, player);
|
||||
messageManager.sendMessage(player, "error_home_invalid", homeName);
|
||||
}
|
||||
homeTabCompleter.updatePlayerHomeCache(player);
|
||||
messageManager.sendMessage(player, "home_deleted", homeName);
|
||||
} else {
|
||||
messageManager.sendMessage(player, "error_home_invalid", homeName);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user