summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/configuration
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java10
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java13
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java131
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java5
4 files changed, 142 insertions, 17 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
index 04faca2..f2b7680 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
@@ -13,7 +13,7 @@ import net.tylermurphy.hideAndSeek.Main;
public class Config {
- static ConfigManager manager;
+ private static ConfigManager manager;
public static String
messagePrefix,
@@ -42,7 +42,10 @@ public class Config {
tauntCountdown,
tauntLast,
glowEnabled,
- glowStackable;
+ glowStackable,
+ pvpEnabled,
+ autoJoin,
+ teleportToExit;
public static int
minPlayers,
@@ -131,6 +134,9 @@ public class Config {
permissionsRequired = manager.getBoolean("permissionsRequired");
minPlayers = Math.max(2, manager.getInt("minPlayers"));
gameLength = manager.getInt("gameLength");
+ pvpEnabled = manager.getBoolean("pvp");
+ autoJoin = manager.getBoolean("autoJoin");
+ teleportToExit = manager.getBoolean("teleportToExit");
}
public static void addToConfig(String path, Object value) {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
index 7ea38db..df970bf 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
@@ -30,7 +30,6 @@ public class ConfigManager {
input.close();
reader.close();
} catch (IOException e){}
-
}
private void saveDefaultConfiguration(){
@@ -43,16 +42,6 @@ public class ConfigManager {
}
}
- public void addToSection(String sectionName, Map<String,Object> values) {
- ConfigurationSection section = config.getConfigurationSection(sectionName);
- if(section == null) section = config.createSection(sectionName);
- Map<String,Object> sectionValues = section.getValues(true);
- for(Map.Entry<String, Object> entry : values.entrySet()) {
- sectionValues.put(entry.getKey(), entry.getValue());
- }
- config.createSection(sectionName, sectionValues);
- }
-
public void addToConfig(String path, Object value) {
config.set(path, value);
}
@@ -89,7 +78,7 @@ public class ConfigManager {
if(value == false){
return defaultConfig.getBoolean(path);
} else {
- return value;
+ return true;
}
}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java
new file mode 100644
index 0000000..fbf5d2c
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java
@@ -0,0 +1,131 @@
+package net.tylermurphy.hideAndSeek.configuration;
+
+import org.bukkit.ChatColor;
+import org.bukkit.Material;
+import org.bukkit.NamespacedKey;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+import org.bukkit.inventory.meta.PotionMeta;
+import org.bukkit.potion.*;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+public class Items {
+
+ private static ConfigManager manager;
+
+ public static List<ItemStack> HIDER_ITEMS, SEEKER_ITEMS;
+ public static List<PotionEffect> HIDER_EFFECTS, SEEKER_EFFECTS;
+
+ public static void loadItems() {
+
+ manager = new ConfigManager("items.yml");
+
+ SEEKER_ITEMS = new ArrayList<ItemStack>();
+ ConfigurationSection SeekerItems = manager.getConfigurationSection("items.seeker");
+ int i = 1;
+ while (true) {
+ ConfigurationSection section = SeekerItems.getConfigurationSection(String.valueOf(i));
+ if(section == null) break;
+ ItemStack item = createItem(section);
+ if(item != null) SEEKER_ITEMS.add(item);
+ i++;
+ }
+
+ HIDER_ITEMS = new ArrayList<ItemStack>();
+ ConfigurationSection HiderItems = manager.getConfigurationSection("items.hider");
+ i = 1;
+ while (true) {
+ ConfigurationSection section = HiderItems.getConfigurationSection(String.valueOf(i));
+ if(section == null) break;
+ ItemStack item = createItem(section);
+ if(item != null) HIDER_ITEMS.add(item);
+ i++;
+ }
+
+ SEEKER_EFFECTS = new ArrayList<PotionEffect>();
+ ConfigurationSection SeekerEffects = manager.getConfigurationSection("effects.seeker");
+ i = 1;
+ while (true) {
+ ConfigurationSection section = SeekerEffects.getConfigurationSection(String.valueOf(i));
+ if(section == null) break;
+ PotionEffect effect = getPotionEffect(section);
+ if(effect != null) SEEKER_EFFECTS.add(effect);
+ i++;
+ }
+
+ HIDER_EFFECTS = new ArrayList<PotionEffect>();
+ ConfigurationSection HiderEffects = manager.getConfigurationSection("effects.hider");
+ i = 1;
+ while (true) {
+ ConfigurationSection section = HiderEffects.getConfigurationSection(String.valueOf(i));
+ if(section == null) break;
+ PotionEffect effect = getPotionEffect(section);
+ if(effect != null) HIDER_EFFECTS.add(effect);
+ i++;
+ }
+
+ }
+
+ private static ItemStack createItem(ConfigurationSection item) {
+ String material_string = item.getString("material");
+ if(material_string == null) return null;
+ Material material = Material.valueOf(material_string.toUpperCase());
+ int amount = item.getInt("amount");
+ ItemStack stack = new ItemStack(material, amount);
+ if(material == Material.POTION || material == Material.SPLASH_POTION || material == Material.LINGERING_POTION){
+ PotionMeta meta = getPotionMeta(stack, item);
+ stack.setItemMeta(meta);
+ } else {
+ ConfigurationSection enchantments = item.getConfigurationSection("enchantments");
+ if (enchantments != null)
+ for (String enchantment_string : enchantments.getKeys(false)) {
+ Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(enchantment_string));
+ if (enchantment == null) continue;
+ stack.addUnsafeEnchantment(
+ enchantment,
+ enchantments.getInt(enchantment_string)
+ );
+ }
+ ItemMeta meta = getItemMeta(stack,item);
+ stack.setItemMeta(meta);
+ }
+ return stack;
+ }
+
+ private static ItemMeta getItemMeta(ItemStack stack, ConfigurationSection item){
+ ItemMeta meta = stack.getItemMeta();
+ assert meta != null;
+ String name = item.getString("name");
+ if(name != null)
+ meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
+ meta.setUnbreakable(item.getBoolean("unbreakable"));
+ meta.setLore(item.getStringList("lore"));
+ return meta;
+ }
+
+ private static PotionMeta getPotionMeta(ItemStack stack, ConfigurationSection item){
+ String type = item.getString("type");
+ PotionMeta meta = (PotionMeta) stack.getItemMeta();
+ if(type==null) return meta;
+ assert meta != null;
+ meta.setBasePotionData(new PotionData((PotionType.valueOf(type.toUpperCase()))));
+ return meta;
+ }
+
+ private static PotionEffect getPotionEffect(ConfigurationSection item){
+ String type = item.getString("type");
+ if(type == null) return null;
+ return new PotionEffect(
+ Objects.requireNonNull(PotionEffectType.getByName(type.toUpperCase())),
+ item.getInt("duration"),
+ item.getInt("amplifier"),
+ item.getBoolean("ambient"),
+ item.getBoolean("particles")
+ );
+ }
+}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java
index 82d19d4..9980a4e 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Localization.java
@@ -21,7 +21,8 @@ public class Localization {
public static boolean loadLocalization() {
manager = new ConfigManager("localization.yml");
-
+ manager.saveConfig();
+
for(String key : manager.getConfigurationSection("Localization").getKeys(false)) {
LOCAL.put(
key,
@@ -29,8 +30,6 @@ public class Localization {
);
}
- manager.saveConfig();
-
return true;
}