Advertisement
Guest User

timer.class

a guest
Jun 17th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.46 KB | None | 0 0
  1. package me.bricedev.wrcp;
  2.  
  3. import java.util.Map;
  4. import org.bukkit.Location;
  5. import org.bukkit.World;
  6. import org.bukkit.configuration.ConfigurationSection;
  7. import org.bukkit.scheduler.BukkitRunnable;
  8.  
  9.  
  10. public class Timer {
  11. Database data = Database.instance;
  12. static Timer instance = new Timer();
  13. LootEvent le = new LootEvent();
  14.  
  15. public ConfigurationSection chests() {
  16. return this.data.data.getConfigurationSection("Chests");
  17. }
  18.  
  19. public void loadchests() {
  20. for (String s : chests().getKeys(true)) {
  21. if (!s.contains(".")) {
  22. World world = Main.pl.getServer().getWorld(chests().getConfigurationSection(s).getString("World"));
  23. int x = chests().getConfigurationSection(s).getInt("X");
  24. int y = chests().getConfigurationSection(s).getInt("Y");
  25. int z = chests().getConfigurationSection(s).getInt("Z");
  26. Location loc = new Location(world, x, y, z);
  27. int currenttime = chests().getConfigurationSection(s).getInt("TimeToDelete");
  28. Main.pl.chests.put(loc, Integer.valueOf(currenttime));
  29. chests().set(s, null);
  30. }
  31. }
  32. this.data.saveData();
  33. }
  34.  
  35. public void saveChests() {
  36. int counter = 0;
  37. for (Map.Entry<Location, Integer> e : Main.pl.chests.entrySet()) {
  38. Location loc = (Location) e.getKey();
  39. chests().createSection("Chest" + counter);
  40. chests().getConfigurationSection("Chest" + counter).set("World", loc.getWorld().getName());
  41. chests().getConfigurationSection("Chest" + counter).set("X", Integer.valueOf(loc.getBlockX()));
  42. chests().getConfigurationSection("Chest" + counter).set("Y", Integer.valueOf(loc.getBlockY()));
  43. chests().getConfigurationSection("Chest" + counter).set("Z", Integer.valueOf(loc.getBlockZ()));
  44. chests().getConfigurationSection("Chest" + counter).set("TimeToDelete", e.getValue());
  45. this.data.saveData();
  46. counter++;
  47. }
  48. this.data.saveData();
  49. }
  50.  
  51. public void decrease() {
  52. new BukkitRunnable() {
  53. public void run() {
  54. try {
  55. for (Map.Entry<Location, Integer> e : Main.pl.chests.entrySet()) {
  56. int timetodelete = ((Integer) e.getValue()).intValue();
  57. if (timetodelete > 0) {
  58. int fixed = timetodelete - 1;
  59. e.setValue(Integer.valueOf(fixed));
  60. continue;
  61. }
  62. Location loc = (Location) e.getKey();
  63. Timer.this.le.deleteChest(loc);
  64. if (Main.pl.getConfig().getBoolean("BroadcastKillMessage")) {
  65. String string = Main.pl.getConfig().getString("BroadcastMessage").replace("&", "�");
  66. String x1 = (new StringBuilder(String.valueOf(loc.getBlockX()))).toString();
  67. String y1 = (new StringBuilder(String.valueOf(loc.getBlockY()))).toString();
  68. String z1 = (new StringBuilder(String.valueOf(loc.getBlockZ()))).toString();
  69. String string2 = string.replace("{X}", x1);
  70. String string3 = string2.replace("{Y}", y1);
  71. String string4 = string3.replace("{Z}", z1);
  72. Main.pl.getServer().broadcastMessage(string4);
  73. }
  74.  
  75. }
  76. } catch (Exception exception) {
  77. }
  78. }
  79. }.runTaskTimer(Main.pl, 20, 20L);
  80. }
  81. }package me.bricedev.wrcp;
  82.  
  83. import java.util.Map;
  84. import org.bukkit.Location;
  85. import org.bukkit.World;
  86. import org.bukkit.configuration.ConfigurationSection;
  87. import org.bukkit.scheduler.BukkitRunnable;
  88.  
  89.  
  90. public class Timer {
  91. Database data = Database.instance;
  92. static Timer instance = new Timer();
  93. LootEvent le = new LootEvent();
  94.  
  95. public ConfigurationSection chests() {
  96. return this.data.data.getConfigurationSection("Chests");
  97. }
  98.  
  99. public void loadchests() {
  100. for (String s : chests().getKeys(true)) {
  101. if (!s.contains(".")) {
  102. World world = Main.pl.getServer().getWorld(chests().getConfigurationSection(s).getString("World"));
  103. int x = chests().getConfigurationSection(s).getInt("X");
  104. int y = chests().getConfigurationSection(s).getInt("Y");
  105. int z = chests().getConfigurationSection(s).getInt("Z");
  106. Location loc = new Location(world, x, y, z);
  107. int currenttime = chests().getConfigurationSection(s).getInt("TimeToDelete");
  108. Main.pl.chests.put(loc, Integer.valueOf(currenttime));
  109. chests().set(s, null);
  110. }
  111. }
  112. this.data.saveData();
  113. }
  114.  
  115. public void saveChests() {
  116. int counter = 0;
  117. for (Map.Entry<Location, Integer> e : Main.pl.chests.entrySet()) {
  118. Location loc = (Location) e.getKey();
  119. chests().createSection("Chest" + counter);
  120. chests().getConfigurationSection("Chest" + counter).set("World", loc.getWorld().getName());
  121. chests().getConfigurationSection("Chest" + counter).set("X", Integer.valueOf(loc.getBlockX()));
  122. chests().getConfigurationSection("Chest" + counter).set("Y", Integer.valueOf(loc.getBlockY()));
  123. chests().getConfigurationSection("Chest" + counter).set("Z", Integer.valueOf(loc.getBlockZ()));
  124. chests().getConfigurationSection("Chest" + counter).set("TimeToDelete", e.getValue());
  125. this.data.saveData();
  126. counter++;
  127. }
  128. this.data.saveData();
  129. }
  130.  
  131. public void decrease() {
  132. new BukkitRunnable() {
  133. public void run() {
  134. try {
  135. for (Map.Entry<Location, Integer> e : Main.pl.chests.entrySet()) {
  136. int timetodelete = ((Integer) e.getValue()).intValue();
  137. if (timetodelete > 0) {
  138. int fixed = timetodelete - 1;
  139. e.setValue(Integer.valueOf(fixed));
  140. continue;
  141. }
  142. Location loc = (Location) e.getKey();
  143. Timer.this.le.deleteChest(loc);
  144. if (Main.pl.getConfig().getBoolean("BroadcastKillMessage")) {
  145. String string = Main.pl.getConfig().getString("BroadcastMessage").replace("&", "�");
  146. String x1 = (new StringBuilder(String.valueOf(loc.getBlockX()))).toString();
  147. String y1 = (new StringBuilder(String.valueOf(loc.getBlockY()))).toString();
  148. String z1 = (new StringBuilder(String.valueOf(loc.getBlockZ()))).toString();
  149. String string2 = string.replace("{X}", x1);
  150. String string3 = string2.replace("{Y}", y1);
  151. String string4 = string3.replace("{Z}", z1);
  152. Main.pl.getServer().broadcastMessage(string4);
  153. }
  154.  
  155. }
  156. } catch (Exception exception) {
  157. }
  158. }
  159. }.runTaskTimer(Main.pl, 20, 20L);
  160. }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement