mirror of
https://github.com/NLthijs48/AreaShop.git
synced 2024-11-16 15:25:11 +01:00
Messages: Version fixes, fallback to plain.
- Properly parse NMS version number to support 1.10 - Fallback to plain messages if sending a fancy message breaks (we try again after restart/reload)
This commit is contained in:
parent
c2bcc6008b
commit
ec57b922b8
@ -47,10 +47,19 @@ public class FancyMessageSender {
|
||||
Class<?> chatSerializerClazz;
|
||||
|
||||
String version = Reflection.getVersion();
|
||||
double majorVersion = Double.parseDouble(version.replace('_', '.').substring(1, 4));
|
||||
int lesserVersion = Integer.parseInt(version.substring(6, 7));
|
||||
if(version == null || version.length() < 2) {
|
||||
throw new RuntimeException("Could not get NMS version, found: "+version);
|
||||
}
|
||||
version = version.substring(1, version.length()-1); // Strip v and the . at the end
|
||||
String[] parts = version.split("_");
|
||||
if(parts.length < 3) {
|
||||
throw new RuntimeException("Not enough parts in the version, found: "+version);
|
||||
}
|
||||
int majorVersion = Integer.parseInt(parts[0]);
|
||||
int minorVersion = Integer.parseInt(parts[1]);
|
||||
int revision = Integer.parseInt(parts[2].substring(1));
|
||||
|
||||
if(majorVersion < 1.8 || (majorVersion == 1.8 && lesserVersion == 1)) {
|
||||
if((majorVersion <= 1 && minorVersion < 8) || (majorVersion == 1 && minorVersion == 8 && revision == 1)) {
|
||||
chatSerializerClazz = Reflection.getNMSClass("ChatSerializer");
|
||||
} else {
|
||||
chatSerializerClazz = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||
|
@ -19,6 +19,7 @@ public class Message {
|
||||
public static final String LANGUAGEVARIABLE = "lang:";
|
||||
public static final String CHATLANGUAGEVARIABLE = "prefix";
|
||||
public static final int REPLACEMENTLIMIT = 50;
|
||||
private static boolean fancyWorks = true;
|
||||
|
||||
private List<String> message;
|
||||
private Object[] replacements;
|
||||
@ -158,9 +159,18 @@ public class Message {
|
||||
}
|
||||
executeReplacements();
|
||||
if(target instanceof Player) {
|
||||
if(AreaShop.getInstance().getConfig().getBoolean("useFancyMessages")) {
|
||||
FancyMessageSender.sendJSON((Player)target, FancyMessageFormat.convertToJSON(message));
|
||||
} else {
|
||||
boolean sendPlain = true;
|
||||
if(AreaShop.getInstance().getConfig().getBoolean("useFancyMessages") && fancyWorks) {
|
||||
try {
|
||||
boolean result = FancyMessageSender.sendJSON((Player)target, FancyMessageFormat.convertToJSON(message));
|
||||
sendPlain = !result;
|
||||
fancyWorks = result;
|
||||
} catch(Exception e) {
|
||||
fancyWorks = false;
|
||||
AreaShop.getInstance().getLogger().warning("Sending fancy message did not work, falling back to plain messages. Message key: "+key);
|
||||
}
|
||||
}
|
||||
if(sendPlain) { // Fancy messages disabled or broken
|
||||
((Player)target).sendMessage(FancyMessageFormat.convertToConsole(message));
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user