mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-24 02:56:17 +01:00
Merge branch 'development'
This commit is contained in:
commit
e32f5bab8b
@ -4,7 +4,7 @@ stages:
|
|||||||
variables:
|
variables:
|
||||||
name: "SongodaCore"
|
name: "SongodaCore"
|
||||||
path: "/builds/$CI_PROJECT_PATH"
|
path: "/builds/$CI_PROJECT_PATH"
|
||||||
version: "2.2.4"
|
version: "2.2.6"
|
||||||
|
|
||||||
build:
|
build:
|
||||||
stage: build
|
stage: build
|
||||||
|
@ -251,7 +251,7 @@ public class CommandManager implements CommandExecutor, TabCompleter {
|
|||||||
// grab the specific command that's being called
|
// grab the specific command that's being called
|
||||||
SimpleNestedCommand nested = commands.get(command.getName().toLowerCase());
|
SimpleNestedCommand nested = commands.get(command.getName().toLowerCase());
|
||||||
if (nested != null) {
|
if (nested != null) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0 || nested.children.isEmpty()) {
|
||||||
return nested.parent != null ? nested.parent.onTab(sender, args) : null;
|
return nested.parent != null ? nested.parent.onTab(sender, args) : null;
|
||||||
}
|
}
|
||||||
// check for each sub-command that they have access to
|
// check for each sub-command that they have access to
|
||||||
|
@ -1171,7 +1171,7 @@ public enum CompatibleMaterial {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lookup a Legacy Material by its modern id name. <br />
|
* Lookup a Material by its modern id name. <br />
|
||||||
* This also can grab materials by their legacy, but only if there is no
|
* This also can grab materials by their legacy, but only if there is no
|
||||||
* modern material by that name.
|
* modern material by that name.
|
||||||
*
|
*
|
||||||
@ -1183,7 +1183,7 @@ public enum CompatibleMaterial {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lookup a Legacy Material by its modern id name. <br />
|
* Lookup a Material by its modern id name. <br />
|
||||||
* This also can grab materials by their legacy, but only if there is no
|
* This also can grab materials by their legacy, but only if there is no
|
||||||
* modern material by that name.
|
* modern material by that name.
|
||||||
*
|
*
|
||||||
@ -1196,7 +1196,7 @@ public enum CompatibleMaterial {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lookup a Legacy Material by bukkit material.
|
* Lookup a Material by bukkit material.
|
||||||
*
|
*
|
||||||
* @param mat item to lookup
|
* @param mat item to lookup
|
||||||
* @return LegacyMaterial or null if none found
|
* @return LegacyMaterial or null if none found
|
||||||
@ -1206,7 +1206,7 @@ public enum CompatibleMaterial {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lookup a Legacy Material by Itemstack.
|
* Lookup a Material by Itemstack.
|
||||||
*
|
*
|
||||||
* @param item item to lookup
|
* @param item item to lookup
|
||||||
* @return LegacyMaterial or null if none found
|
* @return LegacyMaterial or null if none found
|
||||||
@ -1218,7 +1218,66 @@ public enum CompatibleMaterial {
|
|||||||
String key = item.getType() + ":";
|
String key = item.getType() + ":";
|
||||||
CompatibleMaterial m = lookupMap.get(key);
|
CompatibleMaterial m = lookupMap.get(key);
|
||||||
return m != null ? m : lookupMap.get(key + item.getDurability());
|
return m != null ? m : lookupMap.get(key + item.getDurability());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lookup a Block Material by its modern id name. <br />
|
||||||
|
* This also can grab materials by their legacy, but only if there is no
|
||||||
|
* modern material by that name.
|
||||||
|
*
|
||||||
|
* @param name item to lookup
|
||||||
|
* @return LegacyMaterial or null if none found
|
||||||
|
*/
|
||||||
|
public static CompatibleMaterial getBlockMaterial(String name) {
|
||||||
|
if (name == null) {
|
||||||
|
return null;
|
||||||
|
} else if (useLegacy) {
|
||||||
|
LegacyMaterialBlockType legacyBlock = LegacyMaterialBlockType.getFromLegacy(name.toUpperCase());
|
||||||
|
if (legacyBlock != null) {
|
||||||
|
return lookupMap.get(legacyBlock.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lookupMap.get(name.toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lookup a Block Material by its modern id name. <br />
|
||||||
|
* This also can grab materials by their legacy, but only if there is no
|
||||||
|
* modern material by that name.
|
||||||
|
*
|
||||||
|
* @param name item to lookup
|
||||||
|
* @param def default item if this is not a valid material
|
||||||
|
* @return LegacyMaterial or null if none found
|
||||||
|
*/
|
||||||
|
public static CompatibleMaterial getBlockMaterial(String name, CompatibleMaterial def) {
|
||||||
|
if (name == null) {
|
||||||
|
return def;
|
||||||
|
} else if (useLegacy) {
|
||||||
|
LegacyMaterialBlockType legacyBlock = LegacyMaterialBlockType.getFromLegacy(name.toUpperCase());
|
||||||
|
if (legacyBlock != null) {
|
||||||
|
return lookupMap.get(legacyBlock.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lookupMap.getOrDefault(name.toUpperCase(), def);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lookup a Block Material by bukkit material.
|
||||||
|
*
|
||||||
|
* @param mat item to lookup
|
||||||
|
* @return LegacyMaterial or null if none found
|
||||||
|
*/
|
||||||
|
public static CompatibleMaterial getBlockMaterial(Material mat) {
|
||||||
|
if (mat == null) {
|
||||||
|
return null;
|
||||||
|
} else if (useLegacy) {
|
||||||
|
LegacyMaterialBlockType legacyBlock = LegacyMaterialBlockType.getFromLegacy(mat.name());
|
||||||
|
if (legacyBlock != null) {
|
||||||
|
return lookupMap.get(legacyBlock.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lookupMap.get(mat.name());
|
||||||
|
}
|
||||||
|
|
||||||
static LinkedHashSet<CompatibleMaterial> all = null;
|
static LinkedHashSet<CompatibleMaterial> all = null;
|
||||||
|
|
||||||
@ -2057,12 +2116,14 @@ public enum CompatibleMaterial {
|
|||||||
case BEETROOTS:
|
case BEETROOTS:
|
||||||
case CACTUS:
|
case CACTUS:
|
||||||
case CARROTS:
|
case CARROTS:
|
||||||
|
case CARROT:
|
||||||
case CHORUS_FLOWER:
|
case CHORUS_FLOWER:
|
||||||
// FROSTED_ICE is Ageable, but not a crop
|
// FROSTED_ICE is Ageable, but not a crop
|
||||||
case KELP:
|
case KELP:
|
||||||
case MELON_STEM:
|
case MELON_STEM:
|
||||||
case NETHER_WART:
|
case NETHER_WART:
|
||||||
case POTATOES:
|
case POTATOES:
|
||||||
|
case POTATO:
|
||||||
case PUMPKIN_STEM:
|
case PUMPKIN_STEM:
|
||||||
case SUGAR_CANE:
|
case SUGAR_CANE:
|
||||||
case WHEAT:
|
case WHEAT:
|
||||||
|
@ -18,6 +18,7 @@ public enum LegacyMaterialBlockType {
|
|||||||
BIRCH_DOOR("BIRCH_DOOR", true),
|
BIRCH_DOOR("BIRCH_DOOR", true),
|
||||||
FURNACE("FURNACE", "BURNING_FURNACE"),
|
FURNACE("FURNACE", "BURNING_FURNACE"),
|
||||||
CAKE("CAKE_BLOCK"),
|
CAKE("CAKE_BLOCK"),
|
||||||
|
CARROTS("CARROT"), // totally makes sense, lol
|
||||||
CAULDRON("CAULDRON_BLOCK"),
|
CAULDRON("CAULDRON_BLOCK"),
|
||||||
COMPARATOR("REDSTONE_COMPARATOR_OFF", "REDSTONE_COMPARATOR_ON"),
|
COMPARATOR("REDSTONE_COMPARATOR_OFF", "REDSTONE_COMPARATOR_ON"),
|
||||||
DARK_OAK_DOOR("DARK_OAK_DOOR", true),
|
DARK_OAK_DOOR("DARK_OAK_DOOR", true),
|
||||||
@ -29,29 +30,33 @@ public enum LegacyMaterialBlockType {
|
|||||||
FLOWER_POT("FLOWER_POT"),
|
FLOWER_POT("FLOWER_POT"),
|
||||||
IRON_DOOR("IRON_DOOR_BLOCK", true),
|
IRON_DOOR("IRON_DOOR_BLOCK", true),
|
||||||
JUNGLE_DOOR("JUNGLE_DOOR", true),
|
JUNGLE_DOOR("JUNGLE_DOOR", true),
|
||||||
|
LAVA("STATIONARY_LAVA"),
|
||||||
NETHER_WART("NETHER_WARTS"),
|
NETHER_WART("NETHER_WARTS"),
|
||||||
/*
|
/*
|
||||||
< PURPUR_DOUBLE_SLAB
|
< PURPUR_DOUBLE_SLAB
|
||||||
*/
|
*/
|
||||||
|
POTATOES("POTATO"),
|
||||||
REDSTONE_LAMP("REDSTONE_LAMP_OFF", "REDSTONE_LAMP_ON"),
|
REDSTONE_LAMP("REDSTONE_LAMP_OFF", "REDSTONE_LAMP_ON"),
|
||||||
REDSTONE_ORE("REDSTONE_ORE", "GLOWING_REDSTONE_ORE"),
|
REDSTONE_ORE("REDSTONE_ORE", "GLOWING_REDSTONE_ORE"),
|
||||||
REDSTONE_TORCH("REDSTONE_TORCH_ON", "REDSTONE_TORCH_OFF"),
|
REDSTONE_TORCH("REDSTONE_TORCH_ON", "REDSTONE_TORCH_OFF"),
|
||||||
SPRUCE_DOOR("SPRUCE_DOOR"),
|
SPRUCE_DOOR("SPRUCE_DOOR"),
|
||||||
/*
|
|
||||||
< STATIONARY_LAVA,
|
|
||||||
< STATIONARY_WATER,
|
|
||||||
*/
|
|
||||||
SUGAR_CANE("SUGAR_CANE_BLOCK"),
|
SUGAR_CANE("SUGAR_CANE_BLOCK"),
|
||||||
|
WATER("STATIONARY_WATER"),
|
||||||
WHEAT("CROPS");
|
WHEAT("CROPS");
|
||||||
final String blockMaterialName;
|
final String blockMaterialName;
|
||||||
final String alternateBlockMaterialName;
|
final String alternateBlockMaterialName;
|
||||||
final Material blockMaterial, alternateBlockMaterial;
|
final Material blockMaterial, alternateBlockMaterial;
|
||||||
final boolean requiresData; // some blocks require data to render properly (double blocks)
|
final boolean requiresData; // some blocks require data to render properly (double blocks)
|
||||||
final static Map<String, LegacyMaterialBlockType> lookupTable = new HashMap();
|
final static Map<String, LegacyMaterialBlockType> lookupTable = new HashMap();
|
||||||
|
final static Map<String, LegacyMaterialBlockType> reverseLookupTable = new HashMap();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
for (LegacyMaterialBlockType t : values()) {
|
for (LegacyMaterialBlockType t : values()) {
|
||||||
lookupTable.put(t.name(), t);
|
lookupTable.put(t.name(), t);
|
||||||
|
reverseLookupTable.put(t.blockMaterialName, t);
|
||||||
|
if(t.alternateBlockMaterialName != null) {
|
||||||
|
reverseLookupTable.put(t.alternateBlockMaterialName, t);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,4 +104,8 @@ public enum LegacyMaterialBlockType {
|
|||||||
return lookupTable.get(lookup);
|
return lookupTable.get(lookup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static LegacyMaterialBlockType getFromLegacy(String lookup) {
|
||||||
|
return reverseLookupTable.get(lookup);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -94,13 +94,13 @@ public class WorldGuardFlagHandler {
|
|||||||
flags.put(flag, addFlag);
|
flags.put(flag, addFlag);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not add flag {0} to WorldGuard", addFlag.getName());
|
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not add flag {0} to WorldGuard", addFlag.getName());
|
||||||
Flag wgFlag = (StateFlag) WorldGuard.getInstance().getFlagRegistry().get(addFlag.getName());
|
Object wgFlag = WorldGuard.getInstance().getFlagRegistry().get(addFlag.getName());
|
||||||
if (wgFlag == null) {
|
if (wgFlag == null || !(wgFlag instanceof StateFlag)) {
|
||||||
wgPlugin = false;
|
wgPlugin = false;
|
||||||
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not hook WorldGuard");
|
Bukkit.getServer().getLogger().log(Level.WARNING, "Could not hook WorldGuard");
|
||||||
} else {
|
} else {
|
||||||
flags.put(flag, wgFlag);
|
flags.put(flag, wgFlag);
|
||||||
Bukkit.getServer().getLogger().log(Level.WARNING, "Loaded existing {1} {0}", new Object[]{wgFlag.getName(), wgFlag.getClass().getSimpleName()});
|
Bukkit.getServer().getLogger().log(Level.WARNING, "Loaded existing {1} {0}", new Object[]{((Flag) wgFlag).getName(), wgFlag.getClass().getSimpleName()});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package com.songoda.core.locale;
|
package com.songoda.core.locale;
|
||||||
|
|
||||||
|
import com.songoda.core.configuration.Config;
|
||||||
|
import com.songoda.core.configuration.ConfigSection;
|
||||||
import com.songoda.core.utils.TextUtils;
|
import com.songoda.core.utils.TextUtils;
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -17,23 +20,25 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assists in the utilization of localization files. <br>
|
* Assists in the utilization of localization files. <br>
|
||||||
* Created to be used by the Songoda Team. <br>
|
* Created to be used by the Songoda Team. <br>
|
||||||
* NOTE: Using this class in multiple plugins requires shading! <br>
|
|
||||||
* Updated 2019-09-01 to support UTF encoded lang files - jascotty2
|
* Updated 2019-09-01 to support UTF encoded lang files - jascotty2
|
||||||
*
|
*
|
||||||
* @author Brianna O'Keefe - Songoda
|
* @author Brianna O'Keefe - Songoda
|
||||||
*/
|
*/
|
||||||
public class Locale {
|
public class Locale {
|
||||||
|
|
||||||
private static final Pattern NODE_PATTERN = Pattern.compile("^([^ ]+)\\s*=\\s*\"?(.*?)\"?$");
|
private static final Pattern OLD_NODE_PATTERN = Pattern.compile("^([^ ]+)\\s*=\\s*\"?(.*?)\"?$");
|
||||||
private static final String FILE_EXTENSION = ".lang";
|
private static final String FILE_EXTENSION = ".lang";
|
||||||
|
|
||||||
private final Map<String, String> nodes = new HashMap<>();
|
private final Map<String, String> nodes = new HashMap<>();
|
||||||
@ -189,8 +194,10 @@ public class Locale {
|
|||||||
Charset existingCharset = TextUtils.detectCharset(existingIn, StandardCharsets.UTF_8);
|
Charset existingCharset = TextUtils.detectCharset(existingIn, StandardCharsets.UTF_8);
|
||||||
|
|
||||||
try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(existingFile, true), existingCharset);
|
try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(existingFile, true), existingCharset);
|
||||||
BufferedReader defaultReader = new BufferedReader(new InputStreamReader(defaultIn, defaultCharset));
|
BufferedReader defaultReaderOriginal = new BufferedReader(new InputStreamReader(defaultIn, defaultCharset));
|
||||||
BufferedReader existingReader = new BufferedReader(new InputStreamReader(existingIn, existingCharset));) {
|
BufferedReader existingReaderOriginal = new BufferedReader(new InputStreamReader(existingIn, existingCharset));
|
||||||
|
BufferedReader defaultReader = translatePropertyToYAML(defaultReaderOriginal, defaultCharset);
|
||||||
|
BufferedReader existingReader = translatePropertyToYAML(existingReaderOriginal, existingCharset);) {
|
||||||
defaultLines = defaultReader.lines().map(s -> s.replaceAll("[\uFEFF\uFFFE\u200B]", "")).collect(Collectors.toList());
|
defaultLines = defaultReader.lines().map(s -> s.replaceAll("[\uFEFF\uFFFE\u200B]", "")).collect(Collectors.toList());
|
||||||
existingLines = existingReader.lines().map(s -> s.replaceAll("[\uFEFF\uFFFE\u200B]", "").split("\\s*=")[0]).collect(Collectors.toList());
|
existingLines = existingReader.lines().map(s -> s.replaceAll("[\uFEFF\uFFFE\u200B]", "").split("\\s*=")[0]).collect(Collectors.toList());
|
||||||
|
|
||||||
@ -200,7 +207,7 @@ public class Locale {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String key = defaultValue.split("\\s*=")[0];
|
String key = defaultValue.split("\\s*:")[0];
|
||||||
|
|
||||||
if (!existingLines.contains(key)) {
|
if (!existingLines.contains(key)) {
|
||||||
if (!changed) {
|
if (!changed) {
|
||||||
@ -259,36 +266,72 @@ public class Locale {
|
|||||||
|
|
||||||
// load in the file!
|
// load in the file!
|
||||||
try (FileInputStream stream = new FileInputStream(file);
|
try (FileInputStream stream = new FileInputStream(file);
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream) stream, charset));) {
|
BufferedReader source = new BufferedReader(new InputStreamReader((InputStream) stream, charset));
|
||||||
String line;
|
BufferedReader reader = translatePropertyToYAML(source, charset);) {
|
||||||
for (int lineNumber = 0; (line = reader.readLine()) != null; lineNumber++) {
|
Config lang = new Config(file);
|
||||||
if (lineNumber == 0){
|
lang.load(reader);
|
||||||
// remove BOM markers, if any
|
translateMsgRoot(lang, file, charset);
|
||||||
line = line.replaceAll("[\uFEFF\uFFFE\u200B]", "");
|
// todo: how should string lists be handled?
|
||||||
}
|
lang.getValues(true).forEach((k, v) -> nodes.put(k, v.toString()));
|
||||||
// convert to UTF-8 ?
|
|
||||||
/*if (charset == StandardCharsets.UTF_16LE || charset == StandardCharsets.UTF_16BE) {
|
|
||||||
byte[] encoded = line.getBytes(charset);
|
|
||||||
line = new String(encoded, 0, encoded.length, StandardCharsets.UTF_8);
|
|
||||||
} */
|
|
||||||
|
|
||||||
if ((line = line.trim()).isEmpty() || line.startsWith("#") /* Comment */) continue;
|
|
||||||
|
|
||||||
Matcher matcher = NODE_PATTERN.matcher(line);
|
|
||||||
if (!matcher.find()) {
|
|
||||||
System.err.println("Invalid locale syntax at (line=" + lineNumber + "): " + line);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
nodes.put(matcher.group(1), matcher.group(2));
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
|
} catch (InvalidConfigurationException ex) {
|
||||||
|
Logger.getLogger(Locale.class.getName()).log(Level.SEVERE, "Configuration error in language file \"" + file.getName() + "\"", ex);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static BufferedReader translatePropertyToYAML(BufferedReader source, Charset charset) throws IOException {
|
||||||
|
StringBuilder output = new StringBuilder();
|
||||||
|
String line, line1;
|
||||||
|
for (int lineNumber = 0; (line = source.readLine()) != null; lineNumber++) {
|
||||||
|
if (lineNumber == 0) {
|
||||||
|
// remove BOM markers, if any
|
||||||
|
line1 = line;
|
||||||
|
line = line.replaceAll("[\uFEFF\uFFFE\u200B]", "");
|
||||||
|
if(line1.length() != line.length()) {
|
||||||
|
output.append(line1.substring(0, line1.length() - line.length()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Matcher matcher;
|
||||||
|
if ((line = line.trim().replace('\r', ' ')).isEmpty() || line.startsWith("#") /* Comment */
|
||||||
|
|| !(matcher = OLD_NODE_PATTERN.matcher(line)).find()) {
|
||||||
|
output.append(line).append("\n");
|
||||||
|
} else {
|
||||||
|
output.append(matcher.group(1)).append(": \"").append(matcher.group(2)).append("\"\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// I hate Java sometimes because of crap like this:
|
||||||
|
return new BufferedReader(new InputStreamReader(new BufferedInputStream(new ByteArrayInputStream(output.toString().getBytes(charset))), charset));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void translateMsgRoot(Config lang, File file, Charset charset) throws IOException {
|
||||||
|
List<String> msgs = lang.getValues(true).entrySet().stream()
|
||||||
|
.filter(e -> e.getValue() instanceof ConfigSection)
|
||||||
|
.map(e -> e.getKey())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (!msgs.isEmpty()) {
|
||||||
|
try (FileInputStream stream = new FileInputStream(file);
|
||||||
|
BufferedReader source = new BufferedReader(new InputStreamReader((InputStream) stream, charset))) {
|
||||||
|
String line;
|
||||||
|
for (int lineNumber = 0; (line = source.readLine()) != null; lineNumber++) {
|
||||||
|
if (lineNumber == 0) {
|
||||||
|
// remove BOM markers, if any
|
||||||
|
line = line.replaceAll("[\uFEFF\uFFFE\u200B]", "");
|
||||||
|
}
|
||||||
|
Matcher matcher;
|
||||||
|
if (!(line = line.trim()).isEmpty() && !line.startsWith("#")
|
||||||
|
&& (matcher = OLD_NODE_PATTERN.matcher(line)).find()) {
|
||||||
|
if (msgs.contains(matcher.group(1))) {
|
||||||
|
lang.set(matcher.group(1) + ".message", matcher.group(2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supply the Message object with the plugins prefix.
|
* Supply the Message object with the plugins prefix.
|
||||||
@ -317,6 +360,9 @@ public class Locale {
|
|||||||
* @return the message for the specified node
|
* @return the message for the specified node
|
||||||
*/
|
*/
|
||||||
public Message getMessage(String node) {
|
public Message getMessage(String node) {
|
||||||
|
if(this.nodes.containsKey(node + ".message")) {
|
||||||
|
node += ".message";
|
||||||
|
}
|
||||||
return this.getMessageOrDefault(node, node);
|
return this.getMessageOrDefault(node, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,6 +374,9 @@ public class Locale {
|
|||||||
* @return the message for the specified node. Default if none found
|
* @return the message for the specified node. Default if none found
|
||||||
*/
|
*/
|
||||||
public Message getMessageOrDefault(String node, String defaultValue) {
|
public Message getMessageOrDefault(String node, String defaultValue) {
|
||||||
|
if(this.nodes.containsKey(node + ".message")) {
|
||||||
|
node += ".message";
|
||||||
|
}
|
||||||
return supplyPrefix(new Message(this.nodes.getOrDefault(node, defaultValue)));
|
return supplyPrefix(new Message(this.nodes.getOrDefault(node, defaultValue)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,16 @@ import org.bukkit.entity.Player;
|
|||||||
*/
|
*/
|
||||||
public class Message {
|
public class Message {
|
||||||
|
|
||||||
|
private static boolean canActionBar = false;
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
Class.forName("net.md_5.bungee.api.ChatMessageType");
|
||||||
|
Class.forName("net.md_5.bungee.api.chat.TextComponent");
|
||||||
|
Player.Spigot.class.getDeclaredMethod("sendMessage", net.md_5.bungee.api.ChatMessageType.class, net.md_5.bungee.api.chat.TextComponent.class);
|
||||||
|
canActionBar = true;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
private String prefix = null;
|
private String prefix = null;
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
@ -70,6 +80,22 @@ public class Message {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format and send the held message to a player as an actionbar message
|
||||||
|
*
|
||||||
|
* @param sender command sender to send the message to
|
||||||
|
*/
|
||||||
|
public void sendActionBar(CommandSender sender) {
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
sender.sendMessage(this.getMessage());
|
||||||
|
} else if (!canActionBar) {
|
||||||
|
sendTitle(sender);
|
||||||
|
} else {
|
||||||
|
((Player) sender).spigot().sendMessage(net.md_5.bungee.api.ChatMessageType.ACTION_BAR,
|
||||||
|
new net.md_5.bungee.api.chat.TextComponent(getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format and send the held message with the
|
* Format and send the held message with the
|
||||||
* appended plugin prefix to a command sender
|
* appended plugin prefix to a command sender
|
||||||
|
@ -359,7 +359,7 @@ public class BlockUtils {
|
|||||||
} else if (!useLegacy) {
|
} else if (!useLegacy) {
|
||||||
return BlockUtilsModern._isCropFullyGrown(block);
|
return BlockUtilsModern._isCropFullyGrown(block);
|
||||||
}
|
}
|
||||||
CompatibleMaterial mat = CompatibleMaterial.getMaterial(block.getType());
|
CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType());
|
||||||
if (mat == null || !mat.isCrop()) {
|
if (mat == null || !mat.isCrop()) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@ -379,7 +379,7 @@ public class BlockUtils {
|
|||||||
} else if (!useLegacy) {
|
} else if (!useLegacy) {
|
||||||
return BlockUtilsModern._getMaxGrowthStage(block);
|
return BlockUtilsModern._getMaxGrowthStage(block);
|
||||||
}
|
}
|
||||||
CompatibleMaterial mat = CompatibleMaterial.getMaterial(block.getType());
|
CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType());
|
||||||
if (mat == null || !mat.isCrop()) {
|
if (mat == null || !mat.isCrop()) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
@ -399,7 +399,7 @@ public class BlockUtils {
|
|||||||
} else if (!useLegacy) {
|
} else if (!useLegacy) {
|
||||||
return BlockUtilsModern._getMaxGrowthStage(material);
|
return BlockUtilsModern._getMaxGrowthStage(material);
|
||||||
}
|
}
|
||||||
CompatibleMaterial mat = CompatibleMaterial.getMaterial(material);
|
CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(material);
|
||||||
if (mat == null || !mat.isCrop()) {
|
if (mat == null || !mat.isCrop()) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
@ -418,7 +418,7 @@ public class BlockUtils {
|
|||||||
} else if (!useLegacy) {
|
} else if (!useLegacy) {
|
||||||
BlockUtilsModern._setGrowthStage(block, stage);
|
BlockUtilsModern._setGrowthStage(block, stage);
|
||||||
} else {
|
} else {
|
||||||
CompatibleMaterial mat = CompatibleMaterial.getMaterial(block.getType());
|
CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType());
|
||||||
if (mat != null && mat.isCrop()) {
|
if (mat != null && mat.isCrop()) {
|
||||||
try {
|
try {
|
||||||
legacySetBlockData.invoke(block, (byte) Math.max(0, Math.min(stage, mat == CompatibleMaterial.BEETROOTS ? 3 : 7)));
|
legacySetBlockData.invoke(block, (byte) Math.max(0, Math.min(stage, mat == CompatibleMaterial.BEETROOTS ? 3 : 7)));
|
||||||
@ -439,7 +439,7 @@ public class BlockUtils {
|
|||||||
} else if (!useLegacy) {
|
} else if (!useLegacy) {
|
||||||
BlockUtilsModern._incrementGrowthStage(block);
|
BlockUtilsModern._incrementGrowthStage(block);
|
||||||
} else {
|
} else {
|
||||||
CompatibleMaterial mat = CompatibleMaterial.getMaterial(block.getType());
|
CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType());
|
||||||
if (mat != null && mat.isCrop() && block.getData() < (mat == CompatibleMaterial.BEETROOTS ? 3 : 7)) {
|
if (mat != null && mat.isCrop() && block.getData() < (mat == CompatibleMaterial.BEETROOTS ? 3 : 7)) {
|
||||||
try {
|
try {
|
||||||
legacySetBlockData.invoke(block, (byte) (block.getData() + 1));
|
legacySetBlockData.invoke(block, (byte) (block.getData() + 1));
|
||||||
@ -460,7 +460,7 @@ public class BlockUtils {
|
|||||||
} else if (!useLegacy) {
|
} else if (!useLegacy) {
|
||||||
BlockUtilsModern._resetGrowthStage(block);
|
BlockUtilsModern._resetGrowthStage(block);
|
||||||
} else {
|
} else {
|
||||||
CompatibleMaterial mat = CompatibleMaterial.getMaterial(block.getType());
|
CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType());
|
||||||
if (mat != null && mat.isCrop()) {
|
if (mat != null && mat.isCrop()) {
|
||||||
try {
|
try {
|
||||||
legacySetBlockData.invoke(block, (byte) 0);
|
legacySetBlockData.invoke(block, (byte) 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user