Advertisement
Guest User

Untitled

a guest
May 23rd, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.41 KB | None | 0 0
  1. package subside.plugins.koth;
  2.  
  3. import java.io.File;
  4. import java.io.FileOutputStream;
  5. import java.io.FileReader;
  6. import java.io.IOException;
  7. import java.io.OutputStreamWriter;
  8. import java.lang.reflect.Field;
  9. import java.lang.reflect.Modifier;
  10.  
  11. import org.bukkit.craftbukkit.libs.com.google.gson.GsonBuilder;
  12. import org.bukkit.craftbukkit.libs.com.google.gson.JsonParser;
  13. import org.bukkit.plugin.java.JavaPlugin;
  14. import org.json.simple.JSONObject;
  15. import org.json.simple.parser.JSONParser;
  16.  
  17. public class Lang {
  18.  
  19. public static String PREFIX = "&2[KOTH] &a";
  20.  
  21. public static String KOTH_WON = "&aThe koth %area% ended! %player% won!";
  22. public static String KOTH_STARTING = "&aThe koth %area% has begun!";
  23. public static String KOTH_PLAYERCAP = "&a%player% has started to cap %area%!";
  24. public static String KOTH_CAPTIME = "&a%player% is capping the koth! %minutes_left%:%seconds_left% left!";
  25. public static String KOTH_LEFT = "&a%player% left the koth!";
  26. public static String KOTH_LOOT_CHEST = "&1&l%area%s &8&lloot";
  27.  
  28. public static String AREA_ALREADYRUNNING = "&aThe area %area% is already running!";
  29. public static String AREA_ALREADYEXISTS = "&aThe area %area% already exists!";
  30. public static String AREA_NOTEXIST = "&aThe area %area% doesn't exist!";
  31.  
  32.  
  33. public static String COMMAND_ONLYFROMINGAME = "&aThis command can only be executed from ingame!";
  34. public static String COMMAND_USAGE = "Usage: ";
  35.  
  36. public static String COMMAND_HELP_TITLE = "&8========> &2Koth &8<========";
  37. public static String COMMAND_HELP_INFO = "&a%command% &7%command_info%";
  38.  
  39. public static String COMMAND_SCHEDULE_HELP_TITLE = "&8========> &2Koth scheduler &8<========";
  40. public static String COMMAND_SCHEDULE_HELP_INFO = "&a%command% &7%command_info%";
  41.  
  42.  
  43. public static String COMMAND_AREA_TRIGGERED = "&aYou've started the area %area%!";
  44. public static String COMMAND_AREA_CREATED = "&aYou successfully created the area %area%!";
  45. public static String COMMAND_AREA_REMOVED = "&aYou've successfully removed the area %area%!";
  46. public static String COMMAND_AREA_ALREADYEXISTS = "&aThe area %area% already exists!";
  47. public static String COMMAND_AREA_SELECT = "&aYou need to select an area with worldedit!";
  48.  
  49. public static String COMMAND_SCHEDULE_CREATED = "&aYou have created a schedule for %area% on %day% at %time% (Length: %length% minutes)!";
  50. public static String COMMAND_SCHEDULE_NOVALIDDAY = "&aThis is not a valid day! (monday, tuesday etc)";
  51. public static String COMMAND_SCHEDULE_RUNTIMEERROR = "&aCould not change the run time into an integer!";
  52. public static String COMMAND_SCHEDULE_REMOVED = "&aThe schedule for %area% is removed.";
  53. public static String COMMAND_SCHEDULE_NOTEXIST = "&aThis schedule doesn't exist! (Check /koth schedule list for numbers)";
  54. public static String COMMAND_SCHEDULE_REMOVENOID = "&aThe ID must be a number! (Shown in /koth schedule list)";
  55. public static String COMMAND_SCHEDULE_EMPTY = "&aThe server owner did not schedule any Koths!";
  56.  
  57. public static String COMMAND_SCHEDULE_LIST_CURRENTDATETIME = "&aCurrent date: %date%";
  58. public static String COMMAND_SCHEDULE_LIST_DAY = "&8========> &2%day% &8<========";
  59. public static String COMMAND_SCHEDULE_LIST_ENTRY = "&a%area% at %time%";
  60. public static String COMMAND_SCHEDULE_ADMIN_LIST_CURRENTDATETIME = "&aCurrent date: %date%";
  61. public static String COMMAND_SCHEDULE_ADMIN_LIST_DAY = "&8========> &2%day% &8<========";
  62. public static String COMMAND_SCHEDULE_ADMIN_LIST_ENTRY = "&a(#%id%) %area% at %time% with length %length%";
  63. public static String COMMAND_SCHEDULE_ADMIN_EMPTY = "&aThe schedule list is currently empty!";
  64.  
  65. public static String COMMAND_LOOT_EXPLANATION = "&aThis is the loot chest for %area%!";
  66. public static String COMMAND_LOOT_NOARGSEXPLANATION = "&aThis is the loot chest for the next running koth (%area%)!";
  67. public static String COMMAND_LOOT_SETNOAREA = "&aYou need to specify an area to set the loot chest!";
  68. public static String COMMAND_LOOT_SETNOBLOCK = "&aYou need to look at the block where the chest should spawn!";
  69. public static String COMMAND_LOOT_CHESTSET= "&aYou've set the loot chest for the area %area%!";
  70.  
  71. public static String COMMAND_TERMINATE_SPECIFIC_KOTH = "&aYou have terminated %area%!";
  72. public static String COMMAND_TERMINATE_ALL_KOTHS = "&aYou have terminated all areas!";
  73.  
  74. public static String COMMAND_LIST_MESSAGE = "&2List of areas:";
  75. public static String COMMAND_LIST_ENTRY = "&a- %area%";
  76.  
  77. public static void load(JavaPlugin plugin) {
  78. try {
  79.  
  80. if (!new File(plugin.getDataFolder().getAbsolutePath() + File.separatorChar + "lang.json").exists()) {
  81. save(plugin);
  82. return;
  83. }
  84. JSONParser parser = new JSONParser();
  85. Object obj = parser.parse(new FileReader(plugin.getDataFolder().getAbsolutePath() + File.separatorChar + "lang.json"));
  86.  
  87. JSONObject jsonObject = (JSONObject) obj;
  88.  
  89. Field[] fields = Lang.class.getFields();
  90. for (Field field : fields) {
  91. try {
  92. if (Modifier.isStatic(field.getModifiers())) {
  93. if(jsonObject.containsKey(field.getName())){
  94. field.set(null, jsonObject.get(field.getName()));
  95. }
  96. }
  97. }
  98. catch (Exception e) {
  99. e.printStackTrace();
  100. }
  101. }
  102. save(plugin);
  103. }
  104. catch (Exception e) {
  105. System.out.println("///// LANG FILE NOT FOUND OR NOT CORRECTLY SET UP ////");
  106. System.out.println("Will use default variables instead.");
  107. System.out.println("You could try to delete the lang.json in the plugin folder.");
  108.  
  109. e.printStackTrace();
  110. }
  111. }
  112.  
  113. @SuppressWarnings("unchecked")
  114. public static void save(JavaPlugin plugin) {
  115. try {
  116.  
  117. if (!new File(plugin.getDataFolder().getAbsolutePath() + File.separatorChar + "lang.json").exists()) {
  118. plugin.getDataFolder().mkdirs();
  119. new File(plugin.getDataFolder().getAbsolutePath() + File.separatorChar + "lang.json").createNewFile();
  120. }
  121.  
  122. JSONObject obj = new JSONObject();
  123.  
  124. Field[] fields = Lang.class.getFields();
  125. for (Field field : fields) {
  126. if (Modifier.isStatic(field.getModifiers())) {
  127. obj.put(field.getName(), field.get(null));
  128. }
  129. }
  130.  
  131. FileOutputStream fileStream = new FileOutputStream(new File(plugin.getDataFolder().getAbsolutePath() + File.separatorChar + "lang.json"));
  132. OutputStreamWriter file = new OutputStreamWriter(fileStream, "UTF-8");
  133. try {
  134. file.write(new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create().toJson(new JsonParser().parse(obj.toJSONString())));
  135. }
  136. catch (IOException e) {
  137. e.printStackTrace();
  138.  
  139. }
  140. finally {
  141. file.flush();
  142. file.close();
  143. }
  144. }
  145. catch (Exception e) {}
  146. }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement