1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-07 00:38:42 +01:00

Fix when some signs does not work with sign states

Fixes #1134
This commit is contained in:
montlikadani 2021-03-29 13:00:19 +02:00
parent 8af1b51d84
commit 3ef805f22f
9 changed files with 29 additions and 38 deletions

View File

@ -201,7 +201,7 @@ public class SignUtil {
Map<String, List<TopList>> temp = new HashMap<>(); Map<String, List<TopList>> temp = new HashMap<>();
boolean save = false; boolean save = false;
for (jobsSign jSign : (new HashMap<>(signs)).values()) { for (jobsSign jSign : new HashMap<>(signs).values()) {
Location loc = jSign.getLocation(); Location loc = jSign.getLocation();
if (loc == null) if (loc == null)
continue; continue;

View File

@ -39,9 +39,8 @@ public class BlockOwnerShip {
} }
material = type; material = type;
this.type = BlockTypes.getFromCMIMaterial(type);
switch (this.type) { switch (this.type = BlockTypes.getFromCMIMaterial(type)) {
case BLAST_FURNACE: case BLAST_FURNACE:
metadataName = "jobsBlastFurnaceOwner"; metadataName = "jobsBlastFurnaceOwner";
break; break;

View File

@ -551,8 +551,7 @@ public abstract class JobsDAO {
private boolean checkDefaultCollumns() { private boolean checkDefaultCollumns() {
for (DBTables one : DBTables.values()) { for (DBTables one : DBTables.values()) {
for (JobsTableInterface oneT : one.getInterface()) { for (JobsTableInterface oneT : one.getInterface()) {
if (isCollumn(one.getTableName(), oneT.getCollumn())) if (!isCollumn(one.getTableName(), oneT.getCollumn()))
continue;
addCollumn(one.getTableName(), oneT.getCollumn(), oneT.getType()); addCollumn(one.getTableName(), oneT.getCollumn(), oneT.getType());
} }
} }

View File

@ -1,17 +1,14 @@
package com.gamingmesh.jobs.dao; package com.gamingmesh.jobs.dao;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.bukkit.configuration.file.YamlConfiguration;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.ConfigReader; import com.gamingmesh.jobs.CMILib.ConfigReader;
public class JobsManager { public class JobsManager {
private JobsDAO dao; private JobsDAO dao;
private Jobs plugin; private Jobs plugin;
private DataBaseType DbType = DataBaseType.SqLite; private DataBaseType dbType = DataBaseType.SqLite;
public enum DataBaseType { public enum DataBaseType {
MySQL, SqLite MySQL, SqLite
@ -30,31 +27,30 @@ public class JobsManager {
dao.closeConnections(); dao.closeConnections();
// Picking opposite database then it is currently // Picking opposite database then it is currently
switch (DbType) { switch (dbType) {
case MySQL: case MySQL:
// If it MySQL lets change to SqLite // If it MySQL lets change to SqLite
DbType = DataBaseType.SqLite; dbType = DataBaseType.SqLite;
dao = startSqlite(); dao = startSqlite();
if (dao != null) if (dao != null)
dao.setDbType(DbType); dao.setDbType(dbType);
break; break;
case SqLite: case SqLite:
// If it SqLite lets change to MySQL // If it SqLite lets change to MySQL
DbType = DataBaseType.MySQL; dbType = DataBaseType.MySQL;
dao = startMysql(); dao = startMysql();
if (dao != null) if (dao != null)
dao.setDbType(DbType); dao.setDbType(dbType);
break; break;
default: default:
break; break;
} }
File f = new File(Jobs.getFolder(), "generalConfig.yml"); ConfigReader config = Jobs.getGCManager().getConfig();
YamlConfiguration config = YamlConfiguration.loadConfiguration(f);
config.set("storage.method", DbType.toString().toLowerCase()); config.set("storage.method", dbType.toString().toLowerCase());
try { try {
config.save(f); config.save(config.getFile());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -84,15 +80,15 @@ public class JobsManager {
encoding = c.get("mysql.encoding", "UTF-8"); encoding = c.get("mysql.encoding", "UTF-8");
if (storageMethod.equalsIgnoreCase("mysql")) { if (storageMethod.equalsIgnoreCase("mysql")) {
DbType = DataBaseType.MySQL; dbType = DataBaseType.MySQL;
dao = startMysql(); dao = startMysql();
} else if (storageMethod.equalsIgnoreCase("sqlite")) { } else if (storageMethod.equalsIgnoreCase("sqlite")) {
DbType = DataBaseType.SqLite; dbType = DataBaseType.SqLite;
dao = startSqlite(); dao = startSqlite();
} else { } else {
Jobs.consoleMsg("&cInvalid storage method! Changing method to sqlite!"); Jobs.consoleMsg("&cInvalid storage method! Changing method to sqlite!");
c.set("storage.method", "sqlite"); c.set("storage.method", "sqlite");
DbType = DataBaseType.SqLite; dbType = DataBaseType.SqLite;
dao = startSqlite(); dao = startSqlite();
} }
Jobs.setDAO(dao); Jobs.setDAO(dao);
@ -134,7 +130,7 @@ public class JobsManager {
} }
public DataBaseType getDbType() { public DataBaseType getDbType() {
return DbType; return dbType;
} }
} }

View File

@ -51,7 +51,7 @@ public class JobsMySQL extends JobsDAO {
try { try {
return conn.prepareStatement(query); return conn.prepareStatement(query);
} catch (SQLException | NumberFormatException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;

View File

@ -15,16 +15,13 @@ public class JobsSQLite extends JobsDAO {
} }
public JobsSQLite initialize(File dir) { public JobsSQLite initialize(File dir) {
if (!dir.exists())
dir.mkdirs(); dir.mkdirs();
setUp(); setUp();
return this; return this;
} }
JobsSQLite(Jobs plugin, File file) { JobsSQLite(Jobs plugin, File file) {
super(plugin, "org.sqlite.JDBC", "jdbc:sqlite:" + new File(file, "jobs.sqlite.db").getPath(), null, null, ""); 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); setDbType(DataBaseType.SqLite);
} }
@ -49,7 +46,7 @@ public class JobsSQLite extends JobsDAO {
try { try {
return conn.prepareStatement(query); return conn.prepareStatement(query);
} catch (SQLException | NumberFormatException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;

View File

@ -42,7 +42,7 @@ public class BufferedPayment {
return offlinePlayer; return offlinePlayer;
} }
public Double get(CurrencyType type) { public double get(CurrencyType type) {
return payments.getOrDefault(type, 0d); return payments.getOrDefault(type, 0d);
} }

View File

@ -267,15 +267,14 @@ public class JobsListener implements Listener {
return; return;
} }
Sign sign = (Sign) block.getState(); final Job job = Jobs.getJob(CMIChatColor.stripColor(plugin.getComplement().getLine(event, 2)).toLowerCase());
final Job job = Jobs.getJob(CMIChatColor.stripColor(plugin.getComplement().getLine(sign, 2)).toLowerCase());
if (type == SignTopType.toplist && job == null) { if (type == SignTopType.toplist && job == null) {
player.sendMessage(Jobs.getLanguage().getMessage("command.top.error.nojob")); player.sendMessage(Jobs.getLanguage().getMessage("command.top.error.nojob"));
return; return;
} }
boolean special = false; 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")) { if (numberString.contains("s")) {
numberString = numberString.replace("s", ""); numberString = numberString.replace("s", "");
special = true; special = true;
@ -291,7 +290,7 @@ public class JobsListener implements Listener {
jobsSign signInfo = new jobsSign(); jobsSign signInfo = new jobsSign();
signInfo.setLoc(sign.getLocation()); signInfo.setLoc(block.getLocation());
signInfo.setNumber(number); signInfo.setNumber(number);
if (job != null) if (job != null)
signInfo.setJobName(job.getName()); signInfo.setJobName(job.getName());

View File

@ -12,12 +12,12 @@ import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import net.kyori.adventure.text.Component; 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 { public class Complement2 implements Complement {
protected String serialize(Component component) { protected String serialize(Component component) {
return PlainComponentSerializer.plain().serialize(component); return LegacyComponentSerializer.legacyAmpersand().serialize(component);
} }
protected Component deserialize(String t) { protected Component deserialize(String t) {
@ -31,7 +31,8 @@ public class Complement2 implements Complement {
@Override @Override
public String getLine(SignChangeEvent event, int line) { 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 @Override