localization resets on internal update

This commit is contained in:
Tyler Murphy 2021-12-20 16:51:44 -05:00
parent 4ae9510e16
commit d09daa4682
8 changed files with 44 additions and 41 deletions

View file

@ -88,6 +88,7 @@ public class Main extends JavaPlugin implements Listener {
} }
public void onDisable() { public void onDisable() {
if(onTickTask != null)
onTickTask.cancel(); onTickTask.cancel();
} }

View file

@ -1,16 +1,7 @@
package net.tylermurphy.hideAndSeek.configuration; package net.tylermurphy.hideAndSeek.configuration;
import java.io.File;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import net.tylermurphy.hideAndSeek.Main;
public class Config { public class Config {
private static ConfigManager manager; private static ConfigManager manager;

View file

@ -73,6 +73,10 @@ public class ConfigManager {
} }
} }
public void reset(String path){
config.set(path, defaultConfig.get(path));
}
public boolean getBoolean(String path){ public boolean getBoolean(String path){
boolean value = config.getBoolean(path); boolean value = config.getBoolean(path);
if(value == false){ if(value == false){
@ -107,7 +111,6 @@ public class ConfigManager {
String yamlString = textBuilder.toString(); String yamlString = textBuilder.toString();
Map<String, Object> temp = config.getValues(true); Map<String, Object> temp = config.getValues(true);
for(Map.Entry<String, Object> entry: temp.entrySet()){ for(Map.Entry<String, Object> entry: temp.entrySet()){
System.out.println(entry.getKey() + " " + entry.getValue().getClass().getName());
if(entry.getValue() instanceof Integer || entry.getValue() instanceof Double || entry.getValue() instanceof String || entry.getValue() instanceof Boolean){ if(entry.getValue() instanceof Integer || entry.getValue() instanceof Double || entry.getValue() instanceof String || entry.getValue() instanceof Boolean){
String[] parts = entry.getKey().split("\\."); String[] parts = entry.getKey().split("\\.");
int index = 0; int index = 0;
@ -131,7 +134,7 @@ public class ConfigManager {
replace = "\"" + replace + "\""; replace = "\"" + replace + "\"";
} }
StringBuilder builder = new StringBuilder(yamlString); StringBuilder builder = new StringBuilder(yamlString);
builder.replace(start+1, end, replace); builder.replace(start+1, end == -1 ? yamlString.length() : end, replace);
yamlString = builder.toString(); yamlString = builder.toString();
} }
} }

View file

@ -16,16 +16,14 @@ import java.util.Objects;
public class Items { public class Items {
private static ConfigManager manager;
public static List<ItemStack> HIDER_ITEMS, SEEKER_ITEMS; public static List<ItemStack> HIDER_ITEMS, SEEKER_ITEMS;
public static List<PotionEffect> HIDER_EFFECTS, SEEKER_EFFECTS; public static List<PotionEffect> HIDER_EFFECTS, SEEKER_EFFECTS;
public static void loadItems() { public static void loadItems() {
manager = new ConfigManager("items.yml"); ConfigManager manager = new ConfigManager("items.yml");
SEEKER_ITEMS = new ArrayList<ItemStack>(); SEEKER_ITEMS = new ArrayList<>();
ConfigurationSection SeekerItems = manager.getConfigurationSection("items.seeker"); ConfigurationSection SeekerItems = manager.getConfigurationSection("items.seeker");
int i = 1; int i = 1;
while (true) { while (true) {
@ -36,7 +34,7 @@ public class Items {
i++; i++;
} }
HIDER_ITEMS = new ArrayList<ItemStack>(); HIDER_ITEMS = new ArrayList<>();
ConfigurationSection HiderItems = manager.getConfigurationSection("items.hider"); ConfigurationSection HiderItems = manager.getConfigurationSection("items.hider");
i = 1; i = 1;
while (true) { while (true) {
@ -47,7 +45,7 @@ public class Items {
i++; i++;
} }
SEEKER_EFFECTS = new ArrayList<PotionEffect>(); SEEKER_EFFECTS = new ArrayList<>();
ConfigurationSection SeekerEffects = manager.getConfigurationSection("effects.seeker"); ConfigurationSection SeekerEffects = manager.getConfigurationSection("effects.seeker");
i = 1; i = 1;
while (true) { while (true) {
@ -58,7 +56,7 @@ public class Items {
i++; i++;
} }
HIDER_EFFECTS = new ArrayList<PotionEffect>(); HIDER_EFFECTS = new ArrayList<>();
ConfigurationSection HiderEffects = manager.getConfigurationSection("effects.hider"); ConfigurationSection HiderEffects = manager.getConfigurationSection("effects.hider");
i = 1; i = 1;
while (true) { while (true) {

View file

@ -1,26 +1,32 @@
package net.tylermurphy.hideAndSeek.configuration; package net.tylermurphy.hideAndSeek.configuration;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.bukkit.configuration.file.YamlConfiguration;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.Main;
public class Localization { public class Localization {
public static final Map<String,LocalizationString> LOCAL = new HashMap<String,LocalizationString>(); public static final Map<String,LocalizationString> LOCAL = new HashMap<>();
private static ConfigManager manager; private static String[][] CHANGES = {{"WORLDBORDER_DECREASING"}};
public static boolean loadLocalization() { public static void loadLocalization() {
ConfigManager manager = new ConfigManager("localization.yml");
int PLUGIN_VERSION = 2;
int VERSION = manager.getInt("version");
if(VERSION < PLUGIN_VERSION){
for(int i = VERSION; i < PLUGIN_VERSION; i++){
if(i < 1) continue;
String[] changeList = CHANGES[i-1];
for(String change : changeList)
manager.reset("Localization." + change);
}
manager.reset("version");
}
manager = new ConfigManager("localization.yml");
manager.saveConfig(); manager.saveConfig();
for(String key : manager.getConfigurationSection("Localization").getKeys(false)) { for(String key : manager.getConfigurationSection("Localization").getKeys(false)) {
@ -29,8 +35,6 @@ public class Localization {
new LocalizationString( ChatColor.translateAlternateColorCodes('&', manager.getString("Localization."+key) ) ) new LocalizationString( ChatColor.translateAlternateColorCodes('&', manager.getString("Localization."+key) ) )
); );
} }
return true;
} }
public static LocalizationString message(String key) { public static LocalizationString message(String key) {

View file

@ -36,6 +36,9 @@ autoJoin: false
# default: false # default: false
teleportToExit: false teleportToExit: false
countdown:
# The worldborder closes every interval, which is evey [delay] in minutes. # The worldborder closes every interval, which is evey [delay] in minutes.
# Thw worldborder starts at [size], and decreases 100 blocks every interval. # Thw worldborder starts at [size], and decreases 100 blocks every interval.
# x & z are the center location. [enabled] is whenever the border is enabled. # x & z are the center location. [enabled] is whenever the border is enabled.

View file

@ -40,12 +40,6 @@ items:
material: POTION material: POTION
amount: 2 amount: 2
type: INSTANT_HEAL type: INSTANT_HEAL
'4':
type: DOLPHINS_GRACE
duration: 1000000
amplifier: 1
ambient: false
particles: false
effects: effects:
seeker: seeker:
'1': '1':
@ -72,6 +66,12 @@ effects:
amplifier: 10 amplifier: 10
ambient: false ambient: false
particles: false particles: false
'5':
type: DOLPHINS_GRACE
duration: 1000000
amplifier: 1
ambient: false
particles: false
hider: hider:
'1': '1':
type: WATER_BREATHING type: WATER_BREATHING

View file

@ -27,7 +27,7 @@ Localization:
WORLDBORDER_MIN_SIZE: "World border cannot be smaller than 100 blocks." WORLDBORDER_MIN_SIZE: "World border cannot be smaller than 100 blocks."
WORLDBORDER_POSITION: "Spawn position must be 100 from world border center." WORLDBORDER_POSITION: "Spawn position must be 100 from world border center."
WORLDBORDER_ENABLE: "Set border center to current location, size to {AMOUNT}, and delay to {AMOUNT}." WORLDBORDER_ENABLE: "Set border center to current location, size to {AMOUNT}, and delay to {AMOUNT}."
WORLDBORDER_DECREASING: "Would border decreasing by 100 blocks over the next 30s." WORLDBORDER_DECREASING: "World border decreasing by 100 blocks over the next 30s."
TAUNTED: "$c$oOh no! You have been chosen to be taunted." TAUNTED: "$c$oOh no! You have been chosen to be taunted."
TAUNT: "A random hider will be taunted in the next 30s." TAUNT: "A random hider will be taunted in the next 30s."
TAUNT_ACTIVATE: "Taunt has been activated." TAUNT_ACTIVATE: "Taunt has been activated."
@ -52,3 +52,6 @@ Localization:
BOUNDS_WRONG_WORLD: "Please run this command in the game world." BOUNDS_WRONG_WORLD: "Please run this command in the game world."
BOUNDS: "Successfully set bounds at this position ({AMOUNT}/2)." BOUNDS: "Successfully set bounds at this position ({AMOUNT}/2)."
NOT_AT_ZERO: "Please do not set at a location containing a coordinate at 0." NOT_AT_ZERO: "Please do not set at a location containing a coordinate at 0."
# DO NOT EDIT
version: 2