mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-17 21:51:20 +01:00
Some MySQL changes
- Lets colorize raw message - Make configurable MySQL auto reconnect boolean
This commit is contained in:
parent
054c8f8e11
commit
40cbf67bf4
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -771,7 +771,7 @@ public class ItemManager {
|
||||
COBWEB(30, 0, 9469, "Cobweb", "WEB"),
|
||||
COCOA(127, 0, 29709, "Cocoa"),
|
||||
COCOA_BEANS(351, 3, 27381, "Coco Beans"),
|
||||
COD(349, 0, 24691, "Raw Cod"),
|
||||
COD(-1, -1, 24691, "Raw Cod"),
|
||||
COD_BUCKET(-1, -1, 28601, "Bucket of Cod"),
|
||||
COD_SPAWN_EGG(-1, -1, 27248, "Cod Spawn Egg"),
|
||||
COMMAND_BLOCK(137, 0, 4355, "Command Block", "COMMAND"),
|
||||
@ -2167,6 +2167,25 @@ public class ItemManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isAnvil(Material mat) {
|
||||
CMIMaterial m = CMIMaterial.get(mat);
|
||||
if (m == null)
|
||||
return false;
|
||||
return m.isAnvil();
|
||||
}
|
||||
|
||||
public boolean isAnvil() {
|
||||
switch (this) {
|
||||
case ANVIL:
|
||||
case CHIPPED_ANVIL:
|
||||
case DAMAGED_ANVIL:
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isSapling(Material mat) {
|
||||
CMIMaterial m = CMIMaterial.get(mat);
|
||||
if (m == null)
|
||||
@ -2390,24 +2409,15 @@ public class ItemManager {
|
||||
switch (this) {
|
||||
case OAK_DOOR:
|
||||
case IRON_DOOR:
|
||||
|
||||
case LEGACY_SPRUCE_DOOR:
|
||||
case LEGACY_BIRCH_DOOR:
|
||||
case LEGACY_JUNGLE_DOOR:
|
||||
case LEGACY_ACACIA_DOOR:
|
||||
case LEGACY_DARK_OAK_DOOR:
|
||||
case LEGACY_WOODEN_DOOR_BLOCK:
|
||||
|
||||
// case SPRUCE_DOOR_ITEM:
|
||||
// case BIRCH_DOOR_ITEM:
|
||||
// case JUNGLE_DOOR_ITEM:
|
||||
// case ACACIA_DOOR_ITEM:
|
||||
// case DARK_OAK_DOOR_ITEM:
|
||||
// case WOODEN_DOOR:
|
||||
case ACACIA_DOOR:
|
||||
case BIRCH_DOOR:
|
||||
case DARK_OAK_DOOR:
|
||||
// case IRON_DOOR_BLOCK:
|
||||
case JUNGLE_DOOR:
|
||||
case SPRUCE_DOOR:
|
||||
return true;
|
||||
|
@ -12,6 +12,7 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.CMILib.VersionChecker.Version;
|
||||
|
||||
public class ItemReflection {
|
||||
|
||||
@ -164,11 +165,11 @@ public class ItemReflection {
|
||||
return CraftServer;
|
||||
}
|
||||
|
||||
/* public ItemStack getItemInOffHand(Player player) {
|
||||
public static ItemStack getItemInOffHand(org.bukkit.entity.Player player) {
|
||||
if (Jobs.getVersionCheckManager().getVersion().isLower(Version.v1_9_R1))
|
||||
return null;
|
||||
return player.getInventory().getItemInOffHand();
|
||||
}*/
|
||||
}
|
||||
|
||||
public void setEndermiteActive(Entity ent, boolean state) {
|
||||
|
||||
|
@ -31,7 +31,7 @@ public class RawMessage {
|
||||
|
||||
private String combined = "";
|
||||
private String combinedClean = "";
|
||||
private boolean breakLine = true;
|
||||
private boolean dontBreakLine = false;
|
||||
|
||||
// private boolean colorizeEntireWithLast = true;
|
||||
|
||||
@ -80,12 +80,14 @@ public class RawMessage {
|
||||
private CMIChatColor firstBlockColor = null;
|
||||
|
||||
private String makeMessyText(String text) {
|
||||
if (text.equalsIgnoreCase(" "))
|
||||
return text;
|
||||
text = CMIChatColor.deColorize(text);
|
||||
List<String> splited = new ArrayList<>();
|
||||
|
||||
if (text.contains(" ")) {
|
||||
for (String one : text.split(" ")) {
|
||||
if (this.isBreakLine() && one.contains("\\n")) {
|
||||
/**if (this.isBreakLine() && one.contains("\\n")) {
|
||||
String[] split = one.split("\\\\n");
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
if (i < split.length - 1) {
|
||||
@ -94,9 +96,9 @@ public class RawMessage {
|
||||
splited.add(split[i]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
splited.add(one);
|
||||
}
|
||||
} else {*/
|
||||
splited.add(one);
|
||||
//}
|
||||
splited.add(" ");
|
||||
}
|
||||
if (text.length() > 1 && text.endsWith(" "))
|
||||
@ -116,6 +118,8 @@ public class RawMessage {
|
||||
String colorString = "";
|
||||
if (lastColor != null)
|
||||
colorString += lastColor.getColorCode();
|
||||
else
|
||||
colorString += CMIChatColor.WHITE.getColorCode();
|
||||
for (CMIChatColor oneC : formats) {
|
||||
colorString = colorString + oneC.getColorCode();
|
||||
}
|
||||
@ -161,15 +165,11 @@ public class RawMessage {
|
||||
public RawMessage addText(String text) {
|
||||
if (text == null)
|
||||
return this;
|
||||
if (breakLine) {
|
||||
Random rand = new Random();
|
||||
String breakLine = rand.nextDouble() + "breakLine";
|
||||
text = text.replace("\\n", breakLine);
|
||||
text = text.replace("\\", "\\\\");
|
||||
text = text.replace(breakLine, "\\n");
|
||||
text = provessText(text);
|
||||
if (dontBreakLine) {
|
||||
text = text.replace("\\\\\\n", "\\\\n");
|
||||
}
|
||||
|
||||
text = text.replace("\n", "\\n");
|
||||
unfinishedClean = text;
|
||||
unfinished += "\"text\":\"" + ChatColor.translateAlternateColorCodes('&', makeMessyText(text)).replace(colorReplacerPlaceholder, "&") + "\"";
|
||||
return this;
|
||||
@ -232,41 +232,60 @@ public class RawMessage {
|
||||
return this;
|
||||
}
|
||||
|
||||
private String provessText(String text) {
|
||||
Random rand = new Random();
|
||||
|
||||
String breakLine0 = String.valueOf(rand.nextInt(Integer.MAX_VALUE));
|
||||
text = text.replace("\\n", breakLine0);
|
||||
|
||||
String breakLine3 = String.valueOf(rand.nextInt(Integer.MAX_VALUE));
|
||||
text = text.replace("\\", breakLine3);
|
||||
|
||||
String breakLine2 = String.valueOf(rand.nextInt(Integer.MAX_VALUE));
|
||||
text = text.replace("\\\"", breakLine2);
|
||||
|
||||
String breakLine1 = String.valueOf(rand.nextInt(Integer.MAX_VALUE));
|
||||
text = text.replace("\"", breakLine1);
|
||||
|
||||
text = text.replace(breakLine3, "\\\\");
|
||||
text = text.replace(breakLine0, "\\n");
|
||||
text = text.replace(breakLine1, "\\\"");
|
||||
text = text.replace(breakLine2, "\\\"");
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
public RawMessage add(String text, String hoverText, String command, String suggestion, String url) {
|
||||
|
||||
if (text == null)
|
||||
return this;
|
||||
text = provessText(text);
|
||||
|
||||
if (breakLine) {
|
||||
Random rand = new Random();
|
||||
String breakLine = rand.nextDouble() + "breakLine";
|
||||
text = text.replace("\\n", breakLine);
|
||||
text = text.replace("\\", "\\\\");
|
||||
text = text.replace(breakLine, "\\n");
|
||||
}
|
||||
|
||||
text = text.replace("\"", "\\\"");
|
||||
if (dontBreakLine)
|
||||
text = text.replace("\\\\\\n", "\\\\n");
|
||||
|
||||
String f = "{\"text\":\"" + ChatColor.translateAlternateColorCodes('&', makeMessyText(text)).replace(colorReplacerPlaceholder, "&") + "\"";
|
||||
|
||||
// if (firstBlockColor != null) {
|
||||
// f += ",\"color\":\"" + firstBlockColor.name().toLowerCase() + "\"";
|
||||
// }
|
||||
|
||||
if (hoverText != null && !hoverText.isEmpty()) {
|
||||
hoverText = provessText(hoverText);
|
||||
hoverText = hoverText.replace(" \n", " \\n");
|
||||
hoverText = hoverText.replace("\n", "\\n");
|
||||
f += ",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + ChatColor.translateAlternateColorCodes('&', hoverText) + "\"}]}}";
|
||||
}
|
||||
|
||||
// if (suggestion != null && command != null) {
|
||||
// f += ",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"" + CMIChatColor.deColorize(suggestion) + "\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"" + command + "\"\"}";
|
||||
//
|
||||
// } else {
|
||||
if (suggestion != null) {
|
||||
|
||||
suggestion = provessText(suggestion);
|
||||
|
||||
suggestion = suggestion.replace("\\n", "\\\\n");
|
||||
suggestion = suggestion.replace(" \\n", " \\\\n");
|
||||
suggestion = suggestion.replace(" \n", " \\\\n");
|
||||
|
||||
if (suggestion != null)
|
||||
f += ",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"" + CMIChatColor.deColorize(suggestion) + "\"}";
|
||||
}
|
||||
if (url != null) {
|
||||
url = provessText(url);
|
||||
if (!url.toLowerCase().startsWith("http://") || !url.toLowerCase().startsWith("https://"))
|
||||
url = "http://" + url;
|
||||
f += ",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" + url + "\"}";
|
||||
@ -275,6 +294,7 @@ public class RawMessage {
|
||||
if (command != null) {
|
||||
if (!command.startsWith("/"))
|
||||
command = "/" + command;
|
||||
command = provessText(command);
|
||||
f += ",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"" + command + "\"}";
|
||||
}
|
||||
// }
|
||||
@ -385,8 +405,9 @@ public class RawMessage {
|
||||
if (!Lore.isEmpty()) {
|
||||
loreS = ",Lore:[" + loreS + "]";
|
||||
}
|
||||
f += ",\"hoverEvent\":{\"action\":\"show_item\",\"value\":\"{id:" + itemName + ",Count:1b,tag:{display:{Name:\\\"" + CMIChatColor.translateAlternateColorCodes(ItemName) + "\\\"" + loreS + "}"
|
||||
+ Enchants + "}}\"}";
|
||||
f += ",\"hoverEvent\":{\"action\":\"show_item\",\"value\":\"{id:" + itemName + ",Count:1b,tag:{display:{Name:\\\"" + CMIChatColor.translateAlternateColorCodes(ItemName) + "\\\"" + loreS
|
||||
+ "}"
|
||||
+ Enchants + "}}\"}";
|
||||
|
||||
if (suggestion != null)
|
||||
f += ",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"" + suggestion + "\"}";
|
||||
@ -551,12 +572,12 @@ public class RawMessage {
|
||||
return f;
|
||||
}
|
||||
|
||||
public boolean isBreakLine() {
|
||||
return breakLine;
|
||||
public boolean isDontBreakLine() {
|
||||
return dontBreakLine;
|
||||
}
|
||||
|
||||
public void setBreakLine(boolean breakLine) {
|
||||
this.breakLine = breakLine;
|
||||
public void setDontBreakLine(boolean dontBreakLine) {
|
||||
this.dontBreakLine = dontBreakLine;
|
||||
}
|
||||
|
||||
public void setCombined(String combined) {
|
||||
|
@ -65,6 +65,7 @@ public class JobsManager {
|
||||
c.get("mysql-table-prefix", "jobs_");
|
||||
c.get("verify-server-certificate", false);
|
||||
c.get("use-ssl", false);
|
||||
c.get("auto-reconnect", false);
|
||||
|
||||
if (storageMethod.equalsIgnoreCase("mysql")) {
|
||||
DbType = DataBaseType.MySQL;
|
||||
@ -107,8 +108,9 @@ public class JobsManager {
|
||||
|
||||
boolean certificate = config.getBoolean("verify-server-certificate", false);
|
||||
boolean ssl = config.getBoolean("use-ssl", false);
|
||||
boolean autoReconnect = config.getBoolean("auto-reconnect");
|
||||
if (plugin.isEnabled()) {
|
||||
JobsMySQL data = new JobsMySQL(plugin, hostname, database, username, password, prefix, certificate, ssl);
|
||||
JobsMySQL data = new JobsMySQL(plugin, hostname, database, username, password, prefix, certificate, ssl, autoReconnect);
|
||||
data.initialize();
|
||||
return data;
|
||||
}
|
||||
|
@ -13,8 +13,8 @@ public class JobsMySQL extends JobsDAO {
|
||||
@SuppressWarnings("unused")
|
||||
private Jobs plugin;
|
||||
|
||||
JobsMySQL(Jobs plugin, String hostname, String database, String username, String password, String prefix, boolean certificate, boolean ssl) {
|
||||
super(plugin, "com.mysql.jdbc.Driver", "jdbc:mysql://" + hostname + "/" + database + "?useUnicode=true&characterEncoding=UTF-8&autoReConnect=true&useSSL=" + ssl + "&verifyServerCertificate=" + certificate, username, password, prefix);
|
||||
JobsMySQL(Jobs plugin, String hostname, String database, String username, String password, String prefix, boolean certificate, boolean ssl, boolean autoReconnect) {
|
||||
super(plugin, "com.mysql.jdbc.Driver", "jdbc:mysql://" + hostname + "/" + database + "?useUnicode=true&characterEncoding=UTF-8&autoReConnect=" + autoReconnect + "&useSSL=" + ssl + "&verifyServerCertificate=" + certificate, username, password, prefix);
|
||||
this.plugin = plugin;
|
||||
this.database = database;
|
||||
this.setDbType(DataBaseType.MySQL);
|
||||
@ -28,9 +28,9 @@ public class JobsMySQL extends JobsDAO {
|
||||
}
|
||||
}
|
||||
|
||||
public JobsMySQL initialize(Jobs plugin, String hostname, String database, String username, String password, String prefix, boolean certificate, boolean ssl) {
|
||||
public JobsMySQL initialize(Jobs plugin, String hostname, String database, String username, String password, String prefix, boolean certificate, boolean ssl, boolean autoReconnect) {
|
||||
this.plugin = plugin;
|
||||
JobsMySQL dao = new JobsMySQL(plugin, hostname, database, username, password, prefix, certificate, ssl);
|
||||
JobsMySQL dao = new JobsMySQL(plugin, hostname, database, username, password, prefix, certificate, ssl, autoReconnect);
|
||||
try {
|
||||
dao.setUp();
|
||||
} catch (SQLException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user