Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. package fr.tarkod.api;
  2.  
  3. import org.bukkit.Location;
  4. import org.bukkit.World;
  5. import org.bukkit.configuration.file.FileConfiguration;
  6. import org.bukkit.entity.Player;
  7.  
  8. public class Config {
  9.  
  10. private static FileConfiguration getConfigFile;
  11.  
  12. public Config(FileConfiguration file) {
  13. Config.getConfigFile = file;
  14. }
  15.  
  16. //To get a location with direction from "config" file
  17. public Location getLocationWithDirection(String arguments, World world) {
  18. String[] configLocation = getConfigFile.getString(arguments).split(", ");
  19.  
  20. Double X = Double.parseDouble(configLocation[0]);
  21. Double Y = Double.parseDouble(configLocation[1]);
  22. Double Z = Double.parseDouble(configLocation[2]);
  23. Float yaw = Float.parseFloat(configLocation[3]);
  24. Float pitch = Float.parseFloat(configLocation[4]);
  25.  
  26. Location finalLocation;
  27. if(yaw == null || pitch == null) {
  28. finalLocation = new Location(world, X, Y, Z);
  29. } else {
  30. finalLocation = new Location(world, X, Y, Z, yaw, pitch);
  31. }
  32.  
  33. return finalLocation;
  34. }
  35.  
  36. //To get a location without direction from "config" file
  37. public Location getLocation(String arguments, World world) {
  38. String[] configLocation = getConfigFile.getString(arguments).split(", ");
  39.  
  40. Double X = Double.parseDouble(configLocation[0]);
  41. Double Y = Double.parseDouble(configLocation[1]);
  42. Double Z = Double.parseDouble(configLocation[2]);
  43.  
  44. Location finalLocation = new Location(world, X, Y, Z);
  45.  
  46. return finalLocation;
  47. }
  48.  
  49. //To get a String from "config" file
  50. public String getString(String arguments, Player p) {
  51. String configString = getConfigFile.getString(arguments).replace("{player}", p.getPlayer().getName());
  52. if(configString == null) {
  53. throw new IllegalStateException("The " + arguments + " was not loaded correctly.");
  54. } else {
  55. return configString;
  56. }
  57. }
  58.  
  59. //To get a String from "config" file
  60. public String getString(String arguments) {
  61. String configString = getConfigFile.getString(arguments);
  62. return configString;
  63. }
  64.  
  65. //To get Integer from "config" file
  66. public Integer getInt(String arguments) {
  67. Integer configInt = getConfigFile.getInt(arguments);
  68. return configInt;
  69. }
  70.  
  71. //To get Double from "config" file
  72. public Double getDouble(String arguments) {
  73. Double configDouble = getConfigFile.getDouble(arguments);
  74. return configDouble;
  75. }
  76.  
  77. //A refaire...
  78. public String getTeamMessage(String arguments, Player p, String teamName) {
  79. String configTeamMessage = getConfigFile.getString(arguments).replace("&", "ยง").replace("{player}", p.getPlayer().getName()).replace("{team}", teamName);
  80. if(configTeamMessage == null) {
  81. throw new IllegalStateException("The " + arguments + " was not loaded correctly.");
  82. } else {
  83. return configTeamMessage;
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement