How would i make this configurable?

Discussion in 'Plugin Development' started by ThePluginMaker, Jul 11, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    ThePluginMaker

    My give inventory class:
    Code:java
    1. package com.division.freeforall.engines;
    2.  
    3. import com.division.freeforall.core.FreeForAll;
    4. import com.division.freeforall.core.PlayerStorage;
    5. import com.division.freeforall.events.*;
    6.  
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.Material;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.EventPriority;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.inventory.PlayerInventory;
    14. import org.bukkit.potion.PotionEffect;
    15.  
    16. @EngineInfo(author = "MineStomp",
    17. version = "1",
    18. depends = {"OfflineStorage", "Storage"})
    19. public class InventoryEngine extends Engine {
    20.  
    21. OfflineStorageEngine OSE = null;
    22. StorageEngine SE = null;
    23.  
    24. public InventoryEngine() {
    25. }
    26.  
    27. @Override
    28. public void runStartupChecks() throws EngineException {
    29. Engine eng = FreeForAll.getInstance().getEngineManger().getEngine("OfflineStorage");
    30. if (eng != null) {
    31. if (eng instanceof OfflineStorageEngine) {
    32. this.OSE = (OfflineStorageEngine) eng;
    33. }
    34. }
    35. eng = FreeForAll.getInstance().getEngineManger().getEngine("Storage");
    36. if (eng != null) {
    37. if (eng instanceof StorageEngine) {
    38. this.SE = (StorageEngine) eng;
    39. }
    40. }
    41. if (OSE == null || SE == null) {
    42. throw new EngineException("Missing Dependency.");
    43. }
    44. }
    45.  
    46. @EventHandler(priority = EventPriority.HIGH)
    47. public void onPlayerEnteredArena(PlayerEnteredArenaEvent evt) {
    48. if (!evt.isCancelled()) {
    49. Player evtPlayer = evt.getPlayer();
    50. if (!evtPlayer.isDead() || evt.getMethod() == MoveMethod.RESPAWNED) {
    51. evtPlayer.getInventory().clear();
    52. addItems(evtPlayer);
    53. addArmor(evtPlayer);
    54. evtPlayer.setHealth(20);
    55. evtPlayer.setFoodLevel(20);
    56. evtPlayer.sendMessage(ChatColor.YELLOW + "[FreeForAll]" + ChatColor.RED + " You have entered the arena. Your inventory has been saved.");
    57. for (PotionEffect pt : evtPlayer.getActivePotionEffects()) {
    58. evtPlayer.removePotionEffect(pt.getType());
    59. }
    60. }
    61. }
    62. }
    63.  
    64. @EventHandler(priority = EventPriority.NORMAL)
    65. public void onPlayerPreCheck(PlayerPreCheckEvent evt){
    66. Player evtPlayer = evt.getPlayer();
    67. if(OSE.hasOfflineStorage(evtPlayer.getName())){
    68. restoreInventory(evtPlayer);
    69. }
    70. }
    71.  
    72. @EventHandler(priority = EventPriority.NORMAL)
    73. public void onPlayerLeftArena(PlayerLeftArenaEvent evt) {
    74. restoreInventory(evt.getPlayer());
    75. //SE.playersInArena.remove(evt.getPlayer());
    76. }
    77.  
    78. public void addArmor(Player p) {
    79. PlayerInventory pInv = p.getInventory();
    80. pInv.setChestplate(new ItemStack(Material.IRON_CHESTPLATE, 1));
    81. pInv.setBoots(new ItemStack(Material.IRON_BOOTS, 1));
    82. pInv.setHelmet(new ItemStack(Material.IRON_HELMET, 1));
    83. pInv.setLeggings(new ItemStack(Material.IRON_LEGGINGS, 1));
    84. }
    85.  
    86. public void addItems(Player p) {
    87. PlayerInventory pInv = p.getInventory();
    88. pInv.addItem(new ItemStack(Material.IRON_SWORD, 1));
    89. pInv.addItem(new ItemStack(Material.IRON_AXE, 1));
    90. pInv.addItem(new ItemStack(Material.COOKED_BEEF, 16));
    91. int damageval = 16421;
    92. for (int i = 0; i < 6; i++)
    93. pInv.addItem(new ItemStack(Material.POTION, 1, (short)damageval));
    94. }
    95.  
    96. public boolean restoreInventory(Player player) {
    97. if (OSE.hasOfflineStorage(player.getName())) {
    98. OSE.loadOfflineStorage(player,player.getName());
    99. if (SE.hasStorage(player)) {
    100. PlayerStorage pStorage = SE.getStorage(player.getName());
    101. SE.removeStorage(pStorage);
    102. }
    103. return true;
    104. }
    105. PlayerStorage pStorage = SE.getStorage(player.getName());
    106. if (pStorage != null) {
    107. pStorage.restoreInv(player);
    108. SE.removeStorage(pStorage);
    109. player.sendMessage(ChatColor.YELLOW + "[FreeForAll]" + ChatColor.RED + " Your inventory has been restored.");
    110. return true;
    111. }
    112. return false;
    113. }
    114.  
    115. @Override
    116. public final String getName() {
    117. return ("Inventory");
    118. }
    119.  
    120. @EventHandler(priority = EventPriority.HIGHEST)
    121. public void distributeRewards(PlayerKillstreakAwardedEvent evt) {
    122. for (ItemStack is : evt.getRewards()) {
    123. evt.getPlayer().getInventory().addItem(is);
    124. }
    125. }
    126. }
    127.  

    Config:
    Code:java
    1. package com.division.freeforall.config;
    2.  
    3. import com.division.freeforall.core.FreeForAll;
    4. import com.division.freeforall.regions.HealRegion;
    5. import com.division.freeforall.regions.Region;
    6.  
    7. import java.util.ArrayList;
    8. import java.util.HashMap;
    9. import java.util.Set;
    10.  
    11. import org.bukkit.Bukkit;
    12. import org.bukkit.Location;
    13. import org.bukkit.World;
    14. import org.bukkit.configuration.file.FileConfiguration;
    15. import org.bukkit.configuration.file.YamlConfiguration;
    16. import org.bukkit.util.BlockVector;
    17.  
    18. public class FFAConfig {
    19.  
    20. FileConfiguration ffaconfig = new YamlConfiguration();
    21. FreeForAll FFA;
    22. private static HashMap<String, ArrayList<Location>> spawns = new HashMap<String, ArrayList<Location>>();
    23. private static String mysqlhost;
    24. private static String mysqlport;
    25. private static String mysqluser;
    26. private static String mysqlpass;
    27. private static String mysqldata;
    28. private boolean changed = false;
    29.  
    30. public FFAConfig(FreeForAll instance) {
    31. this.FFA = instance;
    32. instance.saveDefaultConfig();
    33. ffaconfig = instance.getConfig();
    34. }
    35.  
    36. public void load() {
    37. spawns.clear();
    38. System.out.println("[FreeForAll] loading config...");
    39. if (ffaconfig.contains("region")) {
    40. Set<String> arenaList = ffaconfig.getConfigurationSection("region").getKeys(false);
    41. Set<String> spawnList;
    42. for (String arena : arenaList) {
    43. if (!ffaconfig.contains("region." + arena + ".spawn")) {
    44. System.out.println("[FreeForAll] arena " + arena + " has no spawns defined!");
    45. continue;
    46. }
    47.  
    48. spawnList = ffaconfig.getConfigurationSection("region." + arena + ".spawn").getKeys(false);
    49. for (String s : spawnList){
    50. World world = Bukkit.getServer().getWorld(ffaconfig.getString("region." + arena + ".spawn." + s + ".world", "world"));
    51. double x = ffaconfig.getDouble("region." + arena + ".spawn." + s + ".x");
    52. double y = ffaconfig.getDouble("region." + arena + ".spawn." + s + ".y");
    53. double z = ffaconfig.getDouble("region." + arena + ".spawn." + s + ".z");
    54. float yaw = (float) ffaconfig.getDouble("region." + arena + ".spawn." + s + ".yaw");
    55. float pitch = (float) ffaconfig.getDouble("region." + arena + ".spawn." + s + ".pitch");
    56.  
    57. addSpawn(arena, new Location(world, x, y, z, yaw, pitch));
    58. }
    59. }
    60. }
    61. if (!ffaconfig.contains("mysql.host")) {
    62. ffaconfig.set("mysql.host", "localhost");
    63. changed = true;
    64. } else {
    65. mysqlhost = ffaconfig.getString("mysql.host");
    66. }
    67. if (!ffaconfig.contains("mysql.port")) {
    68. ffaconfig.set("mysql.port", "3306");
    69. changed = true;
    70. } else {
    71. mysqlport = ffaconfig.getString("mysql.port");
    72. }
    73. if (!ffaconfig.contains("mysql.username")) {
    74. ffaconfig.set("mysql.username", "root");
    75. changed = true;
    76. } else {
    77. mysqluser = ffaconfig.getString("mysql.username");
    78. }
    79. if (!ffaconfig.contains("mysql.password")) {
    80. ffaconfig.set("mysql.password", "password");
    81. changed = true;
    82. } else {
    83. mysqlpass = ffaconfig.getString("mysql.password");
    84. }
    85. if (!ffaconfig.contains("mysql.database")) {
    86. ffaconfig.set("mysql.database", "ffa");
    87. changed = true;
    88. } else {
    89. mysqldata = ffaconfig.getString("mysql.database");
    90. }
    91. if (changed) {
    92. FFA.saveConfig();
    93. } else {
    94. System.out.println("[FreeForAll] Done loading config!");
    95. }
    96. }
    97.  
    98. public void setSpawn(String arena, String rname, Location loc) {
    99. String name = rname.toLowerCase();
    100. ffaconfig.set("region." + arena + ".spawn." + name + ".world", loc.getWorld().getName());
    101. ffaconfig.set("region." + arena + ".spawn." + name + ".x", loc.getX());
    102. ffaconfig.set("region." + arena + ".spawn." + name + ".y", loc.getY());
    103. ffaconfig.set("region." + arena + ".spawn." + name + ".z", loc.getZ());
    104. ffaconfig.set("region." + arena + ".spawn." + name + ".yaw", loc.getYaw());
    105. ffaconfig.set("region." + arena + ".spawn." + name + ".pitch", loc.getPitch());
    106. FFA.saveConfig();
    107. addSpawn(arena, loc);
    108. }
    109.  
    110. public void setRegion(String arena, World world, BlockVector p1, BlockVector p2) {
    111. ffaconfig.set("region." + arena + ".world", world.getName());
    112. ffaconfig.set("region." + arena + ".p1.x", p1.getX());
    113. ffaconfig.set("region." + arena + ".p1.y", p1.getY());
    114. ffaconfig.set("region." + arena + ".p1.z", p1.getZ());
    115. ffaconfig.set("region." + arena + ".p2.x", p2.getX());
    116. ffaconfig.set("region." + arena + ".p2.y", p2.getY());
    117. ffaconfig.set("region." + arena + ".p2.z", p2.getZ());
    118. FFA.saveConfig();
    119. }
    120.  
    121. public void setHealRegion(String arena, World world, BlockVector p1, BlockVector p2) {
    122. ffaconfig.set("region." + arena + ".healregion.world", world.getName());
    123. ffaconfig.set("region." + arena + ".healregion.p1.x", p1.getX());
    124. ffaconfig.set("region." + arena + ".healregion.p1.y", p1.getY());
    125. ffaconfig.set("region." + arena + ".healregion.p1.z", p1.getZ());
    126. ffaconfig.set("region." + arena + ".healregion.p2.x", p2.getX());
    127. ffaconfig.set("region." + arena + ".healregion.p2.y", p2.getY());
    128. ffaconfig.set("region." + arena + ".healregion.p2.z", p2.getZ());
    129. FFA.saveConfig();
    130. }
    131.  
    132. public void addSpawn(String arena, Location loc){
    133. ArrayList<Location> list = spawns.get(arena);
    134. if (list == null) list = new ArrayList<Location>();
    135. list.add(loc);
    136. spawns.put(arena, list);
    137. }
    138.  
    139. public HealRegion getHealRegion(String arena) {
    140. World world = Bukkit.getServer().getWorld(ffaconfig.getString("region." + arena + "healregion.world", "world"));
    141. double p1x = ffaconfig.getDouble("region." + arena + ".healregion.p1.x");
    142. double p1y = ffaconfig.getDouble("region." + arena + ".healregion.p1.y");
    143. double p1z = ffaconfig.getDouble("region." + arena + ".healregion.p1.z");
    144. double p2x = ffaconfig.getDouble("region." + arena + ".healregion.p2.x");
    145. double p2y = ffaconfig.getDouble("region." + arena + ".healregion.p2.y");
    146. double p2z = ffaconfig.getDouble("region." + arena + ".healregion.p2.z");
    147. BlockVector p1 = new BlockVector(p1x, p1y, p1z);
    148. BlockVector p2 = new BlockVector(p2x, p2y, p2z);
    149. return new HealRegion(world, p1, p2, FFA);
    150. }
    151.  
    152. public Region getRegion(String arena) {
    153. World world = Bukkit.getWorld(ffaconfig.getString("region." + arena + ".world", "world"));
    154. double p1x = ffaconfig.getDouble("region." + arena + ".p1.x");
    155. double p1y = ffaconfig.getDouble("region." + arena + ".p1.y");
    156. double p1z = ffaconfig.getDouble("region." + arena + ".p1.z");
    157. double p2x = ffaconfig.getDouble("region." + arena + ".p2.x");
    158. double p2y = ffaconfig.getDouble("region." + arena + ".p2.y");
    159. double p2z = ffaconfig.getDouble("region." + arena + ".p2.z");
    160. BlockVector p1 = new BlockVector(p1x, p1y, p1z);
    161. BlockVector p2 = new BlockVector(p2x, p2y, p2z);
    162. return new Region(world, p1, p2);
    163. }
    164.  
    165. public ArrayList<Location> getSpawns(String arena) {
    166. return spawns.get(arena);
    167. }
    168.  
    169. public Set<String> getSpawnNames(String arena) {
    170. return ffaconfig.getConfigurationSection("region." + arena + ".spawn").getKeys(false);
    171. }
    172.  
    173. public boolean removeSpawn(String arena, String name) {
    174. if (getSpawnNames(arena).contains(name.toLowerCase())) {
    175. ffaconfig.set("region." + arena + ".spawn." + name.toLowerCase(), null);
    176. FFA.saveConfig();
    177. return true;
    178. }
    179. return false;
    180. }
    181.  
    182. public String getMySQLDatabase() {
    183. return mysqldata;
    184. }
    185.  
    186. public String getMySQLPassword() {
    187. return mysqlpass;
    188. }
    189.  
    190. public String getMySQLUsername() {
    191. return mysqluser;
    192. }
    193.  
    194. public String getMySQLHost() {
    195. return mysqlhost;
    196. }
    197.  
    198. public String getMySQLPort() {
    199. return mysqlport;
    200. }
    201.  
    202. /**
    203. * @return
    204. */
    205. public Set<String> getArenas() {
    206. return ffaconfig.getConfigurationSection("region").getKeys(false);
    207. }
    208. }
    209.  


    How would i make this configurable:
    Code:java
    1. public void addArmor(Player p) {
    2. PlayerInventory pInv = p.getInventory();
    3. pInv.setChestplate(new ItemStack(Material.IRON_CHESTPLATE, 1));
    4. pInv.setBoots(new ItemStack(Material.IRON_BOOTS, 1));
    5. pInv.setHelmet(new ItemStack(Material.IRON_HELMET, 1));
    6. pInv.setLeggings(new ItemStack(Material.IRON_LEGGINGS, 1));
    7. }
    8.  
    9. public void addItems(Player p) {
    10. PlayerInventory pInv = p.getInventory();
    11. pInv.addItem(new ItemStack(Material.IRON_SWORD, 1));
    12. pInv.addItem(new ItemStack(Material.IRON_AXE, 1));
    13. pInv.addItem(new ItemStack(Material.COOKED_BEEF, 16));
    14. int damageval = 16421;
    15. for (int i = 0; i < 6; i++)
    16. pInv.addItem(new ItemStack(Material.POTION, 1, (short)damageval));
    17. }
     
  2. Offline

    EnderTroll68

    My recommendation is to use the item ID and toss it in the config, with the amount you want etc. It will be deprecated but if the ID does change, which is why it is deprecated, the user can easily just go change it
     
  3. Offline

    ThePluginMaker

    EnderTroll68
    I've used config code before, well quite a bit, but i usually use it on the onEnable, well these are public voids, and well i've never done that, so can anyone help me with the code (i don't mind if its item id or all caps [STONE].) :)

    Also how would i make killstreaks configurable, it's kind of hard to see what's going on but if you read the code you should understand it:
    Code:java
    1. package com.division.freeforall.engines;
    2.  
    3. import com.division.freeforall.core.FreeForAll;
    4. import com.division.freeforall.core.PlayerStorage;
    5. import com.division.freeforall.events.PlayerDeathInArenaEvent;
    6. import com.division.freeforall.events.PlayerKilledPlayerInArenaEvent;
    7. import com.division.freeforall.events.PlayerKillstreakAwardedEvent;
    8. import com.division.freeforall.events.PlayerDeathInArenaEvent.DeathCause;
    9.  
    10. import java.util.ArrayList;
    11.  
    12. import org.bukkit.Bukkit;
    13. import org.bukkit.ChatColor;
    14. import org.bukkit.Material;
    15. import org.bukkit.entity.Player;
    16. import org.bukkit.event.EventHandler;
    17. import org.bukkit.event.EventPriority;
    18. import org.bukkit.inventory.ItemStack;
    19. import org.bukkit.inventory.PlayerInventory;
    20. import org.bukkit.potion.PotionEffect;
    21. import org.bukkit.potion.PotionEffectType;
    22.  
    23. @EngineInfo(author = "MineStomp",
    24. version = "0.2.23RB",
    25. depends = {"Storage", "Inventory"})
    26. public class KillStreakEngine extends Engine {
    27.  
    28. StorageEngine SE = null;
    29. InventoryEngine IE = null;
    30.  
    31. @Override
    32. public final String getName() {
    33. return ("Killstreak");
    34. }
    35.  
    36. public KillStreakEngine() {
    37. }
    38.  
    39. @Override
    40. public void runStartupChecks() throws EngineException {
    41. Engine eng = FreeForAll.getInstance().getEngineManger().getEngine("Storage");
    42. if (eng != null) {
    43. if (eng instanceof StorageEngine) {
    44. this.SE = (StorageEngine) eng;
    45. }
    46. }
    47. eng = FreeForAll.getInstance().getEngineManger().getEngine("Inventory");
    48. if (eng != null) {
    49. if (eng instanceof InventoryEngine) {
    50. this.IE = (InventoryEngine) eng;
    51. }
    52. }
    53. if (SE == null || IE == null) {
    54. throw new EngineException("Missing Dependency.");
    55. }
    56. }
    57.  
    58. @EventHandler(priority = EventPriority.LOW)
    59. public void onPlayerKill(PlayerKilledPlayerInArenaEvent evt) {
    60. int killstreak = addKill(evt.getKiller(), evt.getVictim());
    61. rewardKillStreak(evt.getKiller());
    62. FreeForAll.getInstance().getServer().getPluginManager().callEvent(new PlayerKillstreakAwardedEvent(evt.getKiller(), killstreak, new ArrayList<ItemStack>()));
    63. }
    64.  
    65. @EventHandler(priority = EventPriority.LOW)
    66. public void onPlayerKillstreakRewarded(PlayerKillstreakAwardedEvent evt) {
    67. Player p = evt.getPlayer();
    68. PlayerInventory pInv = p.getInventory();
    69. ArrayList<ItemStack> rewards = evt.getRewards();
    70. PlayerStorage pStorage = SE.getStorage(p.getName());
    71. int killStreak = evt.getKillStreak();
    72. if (!pStorage.isRewarded(killStreak)) {
    73. if (killStreak == 1) {
    74. pInv.remove(Material.IRON_SWORD);
    75. pInv.remove(Material.IRON_AXE);
    76. rewards.add(new ItemStack(Material.DIAMOND_SWORD, 1));
    77. rewards.add(new ItemStack(Material.DIAMOND_AXE, 1));
    78. pStorage.rewardKillStreak(killStreak);
    79.  
    80. } else if (killStreak == 2) {
    81. rewards.add(new ItemStack(Material.BOW, 1));
    82. rewards.add(new ItemStack(Material.ARROW, 64));
    83. pStorage.rewardKillStreak(killStreak);
    84. } else if (killStreak == 6) {
    85. rewards.add(new ItemStack(Material.GOLDEN_APPLE, 1));
    86. rewards.add(new ItemStack(Material.ROTTEN_FLESH, 32));
    87. rewards.add(new ItemStack(Material.ARROW, 32));
    88. } else if (killStreak == 9) {
    89. p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 120000, 1));
    90. IE.addArmor(p);
    91. }
    92. }
    93. int damageval = 16421;
    94. for (int i = 0; i < 2; i++)
    95. rewards.add(new ItemStack(Material.POTION, 1, (short)damageval));
    96. }
    97.  
    98. @EventHandler(priority = EventPriority.NORMAL)
    99. public void onPlayerDeathInArena(PlayerDeathInArenaEvent evt) {
    100. Player victim = evt.getVictim();
    101. if (evt.getCause() == DeathCause.ENVIRONMENT) {
    102. String lastAttacker = SE.getStorage(victim.getName()).getLastHit();
    103. Player killer = Bukkit.getServer().getPlayer(lastAttacker);
    104. if (killer != null) {
    105. Bukkit.getServer().getPluginManager().callEvent(new PlayerKilledPlayerInArenaEvent(victim, killer));
    106. }
    107. }
    108. }
    109.  
    110. public int addKill(Player killer, Player victim) {
    111. PlayerStorage pStorage;
    112. if (killer != null) {
    113. pStorage = SE.getStorage(killer.getName());
    114. if (pStorage != null) {
    115. pStorage.addKill(victim);
    116. killer.sendMessage(ChatColor.YELLOW + "[FreeForAll]" + ChatColor.RED + " You killed: " + victim.getName());
    117. victim.sendMessage(ChatColor.YELLOW + "[FreeForAll]" + ChatColor.RED + " You were killed by: " + killer.getName());
    118. return pStorage.getKillStreak();
    119. }
    120. }
    121. return -1;
    122. }
    123.  
    124. public void rewardKillStreak(Player p) {
    125. PlayerStorage pStorage = SE.getStorage(p.getName());
    126. System.out.println(pStorage);
    127.  
    128. int killStreak = pStorage.getKillStreak();
    129. double streakVal = killStreak / 3.0;
    130. if (streakVal >= 1) {
    131. if (streakVal % 1 > 0) {
    132. if (!pStorage.isRewarded(killStreak)) {
    133. FreeForAll.getEcon().depositPlayer(p.getName(), streakVal * 50);
    134. p.sendMessage(ChatColor.YELLOW + "[FreeForAll] " + ChatColor.RED + "You have been awarded $" + streakVal * 50);
    135. System.out.println("[FreeForAll] Awarded " + p.getName() + " $" + streakVal * 250);
    136. if (streakVal != 1) {
    137. Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + "[FreeForAll] " + ChatColor.RED + p.getName() + " is on a " + killStreak + " Kill Streak! Type /ffa to stop him!");
    138. }
    139. pStorage.rewardKillStreak(killStreak);
    140. }
    141. }
    142. }
    143. }
    144. }
    145.  

    How do you think i could do this part:
    Code:java
    1. @EventHandler(priority = EventPriority.LOW)
    2. public void onPlayerKillstreakRewarded(PlayerKillstreakAwardedEvent evt) {
    3. Player p = evt.getPlayer();
    4. PlayerInventory pInv = p.getInventory();
    5. ArrayList<ItemStack> rewards = evt.getRewards();
    6. PlayerStorage pStorage = SE.getStorage(p.getName());
    7. int killStreak = evt.getKillStreak();
    8. if (!pStorage.isRewarded(killStreak)) {
    9. if (killStreak == 1) {
    10. pInv.remove(Material.IRON_SWORD);
    11. pInv.remove(Material.IRON_AXE);
    12. rewards.add(new ItemStack(Material.DIAMOND_SWORD, 1));
    13. rewards.add(new ItemStack(Material.DIAMOND_AXE, 1));
    14. pStorage.rewardKillStreak(killStreak);
    15.  
    16. } else if (killStreak == 2) {
    17. rewards.add(new ItemStack(Material.BOW, 1));
    18. rewards.add(new ItemStack(Material.ARROW, 64));
    19. pStorage.rewardKillStreak(killStreak);
    20. } else if (killStreak == 6) {
    21. rewards.add(new ItemStack(Material.GOLDEN_APPLE, 1));
    22. rewards.add(new ItemStack(Material.ROTTEN_FLESH, 32));
    23. rewards.add(new ItemStack(Material.ARROW, 32));
    24. } else if (killStreak == 9) {
    25. p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 120000, 1));
    26. IE.addArmor(p);
    27. }
    28. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  4. Offline

    ThePluginMaker

  5. Offline

    ThePluginMaker

  6. Offline

    ThePluginMaker

  7. Offline

    O3Bubbles09

    ThePluginMaker What exactly do you want to make configurable? What items they get?
     
  8. Offline

    ThePluginMaker

  9. Offline

    O3Bubbles09

    ThePluginMaker Would you like to use the default configuration stuff or make one of your own? (One of your own is easy for using in multiple classes IMO).
     
  10. Offline

    ThePluginMaker

    O3Bubbles09
    one of my own, do you mean a completely different yml file instead of config? is so that'll be easier.
     
  11. Offline

    O3Bubbles09

    ThePluginMaker This is what I use to make my yml files:
    Code:java
    1. package me.robert.bubbleeconomy.files;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5. import java.util.logging.Level;
    6.  
    7. import me.robert.bubbleeconomy.BubbleEconomy;
    8.  
    9. import org.bukkit.configuration.file.FileConfiguration;
    10. import org.bukkit.configuration.file.YamlConfiguration;
    11.  
    12. public class SettingsManager {
    13.  
    14. private BubbleEconomy plugin = BubbleEconomy.getPlugin();
    15.  
    16. private SettingsManager() { }
    17. private static SettingsManager instance = new SettingsManager();
    18. public static SettingsManager getInstance() { return instance; }
    19.  
    20. private FileConfiguration config;
    21. private File cFile;
    22.  
    23. /* Reload / Create config.yml file */
    24. public void setup() {
    25. if(cFile == null) {
    26. cFile = new File(plugin.getDataFolder(), "config.yml"); /* Make the "config.yml" what ever you want the file to be called */
    27. plugin.saveDefaultConfig();
    28. }
    29. config = YamlConfiguration.loadConfiguration(cFile);
    30. saveConfig();
    31. }
    32.  
    33. /* Get the config.yml file */
    34. public FileConfiguration getConfig() {
    35. if(config == null) {
    36. setup();
    37. }
    38. return config;
    39. }
    40.  
    41. /* Save the config.yml */
    42. public void saveConfig() {
    43. if (config == null || cFile == null) {
    44. return;
    45. }
    46. try {
    47. getConfig().save(cFile);
    48. } catch (IOException ex) {
    49. plugin.getLogger().log(Level.SEVERE, "Could not save config to " + cFile, ex);
    50. }
    51. }
    52. }


    Then you can add methods to get integers or strings or whatever all you would do is:
    Code:java
    1. /* Get ints */
    2. public Integer getInt(String path) {
    3. return getConfig().getInt(path);
    4. }
     
  12. Offline

    ThePluginMaker

    Okay, how would i make MY items configurable?
     
  13. Offline

    ThePluginMaker

  14. Offline

    Bobit

    Ya know, if you took the time to explain wtf your code actually does, you wouldn't have to wait two weeks to get responses on what it should do next. I'll take a look at it anyhow.
     
  15. ThePluginMaker First of all you don't need all of that code just to save/create a config
    Just use
    Code:java
    1. saveDefaltConfig;
    and make a config.yml in your IDE and put anything in there.

    To pull from it make a Main class constructor and do plugin.getConfig() then if you want a String add .getString("path");

    If you need anymore help just ask.
     
  16. Offline

    Bobit

    I get it now. I don't know if you can parse the string "IRON_CHESTPLATE" to an actual IRON_CHESTPLATE item, which is why the old numerical itemIDs were more useful. If you need to and there is no built-in way, you could always code a custom "public Material parseStringToMaterial(String s){}"

    Apparently, you can parse strings into materials using Material.getMaterial("String").

    (offtopic)
    A Sound.getSound("String") method and many similar ones don't exist, so creating a config for those would require a massive custom parse method.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  17. Offline

    ThePluginMaker

    Bobit
    All i really want to know is make another class file that makes another .yml named really anything, and in that .yml i want it so i can change what the item is in my class files instead of IRON_CHESTPLATE. Any idea?
     
  18. Offline

    fireblast709

    Bobit Material.matchMaterial(String) supports both ids and names ;). Also there is a valueOf(String) method for all enums, which either returns a value or throws an IllegalArgumentException if no value has been found
     
    Bobit likes this.
  19. Offline

    Bobit

    Nice! valueOf wouldn't work unless someone had specifically coded it to though, right?
    You don't really need it in another class file, but you could have one. Also, why not just put it in the default config, just in a separate part? As to making multiple configs, I really can't help you.
     
  20. Offline

    fireblast709

    Bobit afaik valueOf is located inside the Enum class (which all enums 'extend')
     
    Bobit likes this.
  21. Offline

    ThePluginMaker

    Bump, i still have no idea on how to do this :(
     
  22. Offline

    Bobit

    What makes you think you need to make multiple configs? It's much harder that way.
     
  23. Offline

    ThePluginMaker

    Bobit
    it doesn't have to be i guess :p
     
  24. Offline

    Bobit

    Okay. Do this:
    1) replace IRON_CHESTPLATE with
    Material.valueOf(main.getConfig("CHESTPLATE"));
    2) Put CHESTPLATE as an option in your config, and give it the default value of IRON_CHESTPLATE
    3) If you feel necessary, make sure that the option isn't set to something that doesn't make sense, such as FISH

    If you don't have your config file set up, consult the wiki, and note that the normal setup for configuration is bad. If you add new options to the config file, with the normal set up, you are forced to either not add them to the user's file or completely delete the user's file.
     
  25. Offline

    ThePluginMaker

    Bobit
    So this is what i did:
    309f12d7dfe6c26bf7663ced3f16abb3.png
    Do i just do that this is what it puts in my ffaconfig:
    Code:java
    1. public static String getConfig(String string) {
    2. // TODO Auto-generated method stub
    3. return null;
    4. }

    Sorry i've never put items into a config before so it's a bit weird.
     
  26. Offline

    Bobit

    You're not using the default config. You should.
    It's not "FFAconfig.getConfig()", it's just "this.getConfig()", and in your onEnable() "this.saveDefaultConfig()". You don't need to make your own "FFAconfig" like that.
     
  27. Offline

    ThePluginMaker

    Bobit
    Thanks i'll try this as soon as i get home.

    Bobit
    Hey i'm getting an error this is what i have:
    Code:java
    1. pInv.setChestplate(new ItemStack(Material.valueOf(this.getConfig(),("CHESTPLATE"))));

    getting an error on getConfig for The method getConfig() is undefined for the type InventoryEngine.
    Create method 'getConfig()' and if i do that it does this:
    private Class<Enum<Enum<T>>> getConfig() {
    // TODO Auto-generated method stub
    return null;
    }
    right under it. i feel like a noob

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  28. Offline

    Bobit

    I meant "this.getConfig()" assuming this is in your main class. So, in your main class:
    "Plugin main = this"
    Then pass this on to your class
    and in your class chance this.getConfig() to main.getConfig(). If you're doing it how I do it, that should work.
     
Thread Status:
Not open for further replies.

Share This Page