From 0a66fad271a72ae6df5ae629854ac93e4f74f0a1 Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Sun, 16 Nov 2014 09:43:30 +0100 Subject: [PATCH] Should work better :D --- .../java/com/intellectualcrafters/plot/C.java | 6 +-- .../plot/database/SQLManager.java | 52 ++++++++++++------- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java index 012f83cdc..9e57d521b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java @@ -381,6 +381,7 @@ public enum C { * Custom */ CUSTOM_STRING("-"); + static TranslationLanguage lang = new TranslationLanguage("PlotSquared", "this", "use"); private static TranslationManager manager; private static TranslationFile defaultFile; /** @@ -422,9 +423,8 @@ public enum C { // FIXME: generating a blank file // FIXME: translations aren't customizable // FIXME: Some messages still have the %arg stuff in them - if (defaultFile == null) { - defaultFile = new YamlTranslationFile(BukkitTranslation.getParent(PlotMain.getPlugin(PlotMain.class)), TranslationLanguage.englishAmerican, "PlotSquared", manager) + defaultFile = new YamlTranslationFile(BukkitTranslation.getParent(PlotMain.getPlugin(PlotMain.class)), lang, "PlotSquared", manager) .read(); } // register everything in this class @@ -455,7 +455,7 @@ public enum C { * @return translated if exists else default */ public String s() { - return manager.getTranslated(toString(), TranslationLanguage.englishAmerican).getTranslated().replaceAll("&-", "\n").replaceAll("\\n", "\n"); + return manager.getTranslated(toString(), lang).getTranslated().replaceAll("&-", "\n").replaceAll("\\n", "\n"); /* if (PlotMain.translations != null) { final String t = PlotMain.translations.getString(this.toString()); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 82ea4446d..e7b973371 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -36,31 +36,47 @@ import java.util.*; */ public class SQLManager extends AbstractDB { - private Connection connection; - private String prefix; - public final String SET_OWNER = - "UPDATE `" + prefix + "plot` SET `owner` = ? WHERE `plot_id_x` = ? AND `plot_id_z` = ?"; - // TODO MongoDB @Brandon - public String GET_ALL_PLOTS = - "SELECT `id`, `plot_id_x`, `plot_id_z`, `world` FROM `" + prefix + "plot`"; - public String CREATE_PLOTS = - "INSERT INTO `" + prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) values "; - public String CREATE_SETTINGS = - "INSERT INTO `" + prefix + "plot_settings` (`plot_plot_id`) values "; - public String CREATE_HELPERS = - "INSERT INTO `" + prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) values "; - public String CREATE_PLOT = - "INSERT INTO `" + prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) VALUES(?, ?, ?, ?)"; + // Public final + public final String SET_OWNER; + public final String GET_ALL_PLOTS; + public final String CREATE_PLOTS; + public final String CREATE_SETTINGS; + public final String CREATE_HELPERS; + public final String CREATE_PLOT; + // Private Final + private final Connection connection; + private final String prefix; + + /** + * Constructor + * + * @param c connection + * @param p prefix + */ public SQLManager(Connection c, String p) { + // Private final connection = c; prefix = p; + // Public final + SET_OWNER = + "UPDATE `" + prefix + "plot` SET `owner` = ? WHERE `plot_id_x` = ? AND `plot_id_z` = ?"; + GET_ALL_PLOTS = + "SELECT `id`, `plot_id_x`, `plot_id_z`, `world` FROM `" + prefix + "plot`"; + CREATE_PLOTS = + "INSERT INTO `" + prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) values "; + CREATE_SETTINGS = + "INSERT INTO `" + prefix + "plot_settings` (`plot_plot_id`) values "; + CREATE_HELPERS = + "INSERT INTO `" + prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) values "; + CREATE_PLOT = + "INSERT INTO `" + prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) VALUES(?, ?, ?, ?)"; } /** * Set Plot owner * - * @param plot - * @param uuid + * @param plot Plot Object + * @param uuid Owner UUID */ @Override public void setOwner(final Plot plot, final UUID uuid) { @@ -123,7 +139,7 @@ public class SQLManager extends AbstractDB { } // add plot settings - final Integer[] ids = helpers.keySet().toArray(new Integer[0]); + final Integer[] ids = helpers.keySet().toArray(new Integer[helpers.keySet().size()]); StringBuilder statement = new StringBuilder(CREATE_SETTINGS); for (int i = 0; i < (ids.length - 1); i++) { statement.append("(?),");