From 3ef805f22f88452597ad117bd0c30ecc8412c7a4 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Mon, 29 Mar 2021 13:00:19 +0200 Subject: [PATCH] Fix when some signs does not work with sign states Fixes #1134 --- .../com/gamingmesh/jobs/Signs/SignUtil.java | 2 +- .../blockOwnerShip/BlockOwnerShip.java | 3 +- .../java/com/gamingmesh/jobs/dao/JobsDAO.java | 5 ++-- .../com/gamingmesh/jobs/dao/JobsManager.java | 30 ++++++++----------- .../com/gamingmesh/jobs/dao/JobsMySQL.java | 2 +- .../com/gamingmesh/jobs/dao/JobsSQLite.java | 9 ++---- .../jobs/economy/BufferedPayment.java | 2 +- .../jobs/listeners/JobsListener.java | 7 ++--- .../jobs/stuff/complement/Complement2.java | 7 +++-- 9 files changed, 29 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java index c41bddfd..e3ccbc2f 100644 --- a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java +++ b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java @@ -201,7 +201,7 @@ public class SignUtil { Map> temp = new HashMap<>(); boolean save = false; - for (jobsSign jSign : (new HashMap<>(signs)).values()) { + for (jobsSign jSign : new HashMap<>(signs).values()) { Location loc = jSign.getLocation(); if (loc == null) continue; diff --git a/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java b/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java index 1112bb9d..940b8cd6 100644 --- a/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java +++ b/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java @@ -39,9 +39,8 @@ public class BlockOwnerShip { } material = type; - this.type = BlockTypes.getFromCMIMaterial(type); - switch (this.type) { + switch (this.type = BlockTypes.getFromCMIMaterial(type)) { case BLAST_FURNACE: metadataName = "jobsBlastFurnaceOwner"; break; diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index d4297665..52600833 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -551,9 +551,8 @@ public abstract class JobsDAO { private boolean checkDefaultCollumns() { for (DBTables one : DBTables.values()) { for (JobsTableInterface oneT : one.getInterface()) { - if (isCollumn(one.getTableName(), oneT.getCollumn())) - continue; - addCollumn(one.getTableName(), oneT.getCollumn(), oneT.getType()); + if (!isCollumn(one.getTableName(), oneT.getCollumn())) + addCollumn(one.getTableName(), oneT.getCollumn(), oneT.getType()); } } diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsManager.java b/src/main/java/com/gamingmesh/jobs/dao/JobsManager.java index 2be695f5..370080fd 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsManager.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsManager.java @@ -1,17 +1,14 @@ package com.gamingmesh.jobs.dao; -import java.io.File; import java.io.IOException; -import org.bukkit.configuration.file.YamlConfiguration; - import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.CMILib.ConfigReader; public class JobsManager { private JobsDAO dao; private Jobs plugin; - private DataBaseType DbType = DataBaseType.SqLite; + private DataBaseType dbType = DataBaseType.SqLite; public enum DataBaseType { MySQL, SqLite @@ -30,31 +27,30 @@ public class JobsManager { dao.closeConnections(); // Picking opposite database then it is currently - switch (DbType) { + switch (dbType) { case MySQL: // If it MySQL lets change to SqLite - DbType = DataBaseType.SqLite; + dbType = DataBaseType.SqLite; dao = startSqlite(); if (dao != null) - dao.setDbType(DbType); + dao.setDbType(dbType); break; case SqLite: // If it SqLite lets change to MySQL - DbType = DataBaseType.MySQL; + dbType = DataBaseType.MySQL; dao = startMysql(); if (dao != null) - dao.setDbType(DbType); + dao.setDbType(dbType); break; default: break; } - File f = new File(Jobs.getFolder(), "generalConfig.yml"); - YamlConfiguration config = YamlConfiguration.loadConfiguration(f); + ConfigReader config = Jobs.getGCManager().getConfig(); - config.set("storage.method", DbType.toString().toLowerCase()); + config.set("storage.method", dbType.toString().toLowerCase()); try { - config.save(f); + config.save(config.getFile()); } catch (IOException e) { e.printStackTrace(); } @@ -84,15 +80,15 @@ public class JobsManager { encoding = c.get("mysql.encoding", "UTF-8"); if (storageMethod.equalsIgnoreCase("mysql")) { - DbType = DataBaseType.MySQL; + dbType = DataBaseType.MySQL; dao = startMysql(); } else if (storageMethod.equalsIgnoreCase("sqlite")) { - DbType = DataBaseType.SqLite; + dbType = DataBaseType.SqLite; dao = startSqlite(); } else { Jobs.consoleMsg("&cInvalid storage method! Changing method to sqlite!"); c.set("storage.method", "sqlite"); - DbType = DataBaseType.SqLite; + dbType = DataBaseType.SqLite; dao = startSqlite(); } Jobs.setDAO(dao); @@ -134,7 +130,7 @@ public class JobsManager { } public DataBaseType getDbType() { - return DbType; + return dbType; } } diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsMySQL.java b/src/main/java/com/gamingmesh/jobs/dao/JobsMySQL.java index ae9a95b5..68cf656a 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsMySQL.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsMySQL.java @@ -51,7 +51,7 @@ public class JobsMySQL extends JobsDAO { try { return conn.prepareStatement(query); - } catch (SQLException | NumberFormatException e) { + } catch (SQLException e) { e.printStackTrace(); } return null; diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsSQLite.java b/src/main/java/com/gamingmesh/jobs/dao/JobsSQLite.java index fbe70404..2292b23c 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsSQLite.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsSQLite.java @@ -15,17 +15,14 @@ public class JobsSQLite extends JobsDAO { } public JobsSQLite initialize(File dir) { - if (!dir.exists()) - dir.mkdirs(); - + dir.mkdirs(); setUp(); return this; } JobsSQLite(Jobs plugin, File file) { super(plugin, "org.sqlite.JDBC", "jdbc:sqlite:" + new File(file, "jobs.sqlite.db").getPath(), null, null, ""); - if (!file.exists()) - file.mkdirs(); + file.mkdirs(); setDbType(DataBaseType.SqLite); } @@ -49,7 +46,7 @@ public class JobsSQLite extends JobsDAO { try { return conn.prepareStatement(query); - } catch (SQLException | NumberFormatException e) { + } catch (SQLException e) { e.printStackTrace(); } return null; diff --git a/src/main/java/com/gamingmesh/jobs/economy/BufferedPayment.java b/src/main/java/com/gamingmesh/jobs/economy/BufferedPayment.java index 6d74a57f..6c1f47d7 100644 --- a/src/main/java/com/gamingmesh/jobs/economy/BufferedPayment.java +++ b/src/main/java/com/gamingmesh/jobs/economy/BufferedPayment.java @@ -42,7 +42,7 @@ public class BufferedPayment { return offlinePlayer; } - public Double get(CurrencyType type) { + public double get(CurrencyType type) { return payments.getOrDefault(type, 0d); } diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java index 269bfabd..1006c296 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java @@ -267,15 +267,14 @@ public class JobsListener implements Listener { return; } - Sign sign = (Sign) block.getState(); - final Job job = Jobs.getJob(CMIChatColor.stripColor(plugin.getComplement().getLine(sign, 2)).toLowerCase()); + final Job job = Jobs.getJob(CMIChatColor.stripColor(plugin.getComplement().getLine(event, 2)).toLowerCase()); if (type == SignTopType.toplist && job == null) { player.sendMessage(Jobs.getLanguage().getMessage("command.top.error.nojob")); return; } boolean special = false; - String numberString = CMIChatColor.stripColor(plugin.getComplement().getLine(sign, 3)).toLowerCase(); + String numberString = CMIChatColor.stripColor(plugin.getComplement().getLine(event, 3)).toLowerCase(); if (numberString.contains("s")) { numberString = numberString.replace("s", ""); special = true; @@ -291,7 +290,7 @@ public class JobsListener implements Listener { jobsSign signInfo = new jobsSign(); - signInfo.setLoc(sign.getLocation()); + signInfo.setLoc(block.getLocation()); signInfo.setNumber(number); if (job != null) signInfo.setJobName(job.getName()); diff --git a/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement2.java b/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement2.java index e870ef65..75468a0e 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement2.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement2.java @@ -12,12 +12,12 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.meta.ItemMeta; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; public class Complement2 implements Complement { protected String serialize(Component component) { - return PlainComponentSerializer.plain().serialize(component); + return LegacyComponentSerializer.legacyAmpersand().serialize(component); } protected Component deserialize(String t) { @@ -31,7 +31,8 @@ public class Complement2 implements Complement { @Override public String getLine(SignChangeEvent event, int line) { - return event.line(line) == null ? "" : serialize(event.line(line)); + Component l = event.line(line); + return l == null ? "" : serialize(l); } @Override