Advertisement
Guest User

NoFlyZone - Source code

a guest
Jun 18th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.92 KB | None | 0 0
  1. package me.noflyzone;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.HashMap;
  6. import java.util.List;
  7. import java.util.Map;
  8.  
  9. import org.bukkit.command.Command;
  10. import org.bukkit.command.CommandExecutor;
  11. import org.bukkit.command.CommandSender;
  12. import org.bukkit.entity.Entity;
  13. import org.bukkit.entity.Player;
  14.  
  15. public class NoFlyCommands
  16. implements CommandExecutor
  17. {
  18. NoFlyZone plugin;
  19.  
  20. public NoFlyCommands(NoFlyZone i)
  21. {
  22. this.plugin = i;
  23. }
  24.  
  25. @SuppressWarnings("unchecked")
  26. public boolean onCommand(CommandSender s, Command c, String label, String[] args)
  27. {
  28. if ((s instanceof Player))
  29. {
  30. Player p = (Player)s;
  31. if (!p.hasPermission("noflyzone.admin"))
  32. {
  33. this.plugin.sms(p, "&cУ вас нет прав.");
  34. return true;
  35. }
  36. }
  37. if (args.length == 0)
  38. {
  39. this.plugin.sms(s, "&8&m+----------------+");
  40. this.plugin.sms(s, "&cNo&fFly&cZone &f&o" + this.plugin.getDescription().getVersion());
  41. this.plugin.sms(s, "&7Created by: &f&oextended_clip");
  42. this.plugin.sms(s, "&7Translate/ReCoded: &f&oWinLocker");
  43. this.plugin.sms(s, "&8&m+----------------+");
  44. }
  45. else
  46. {
  47. if ((args.length != 0) && (args[0].equalsIgnoreCase("help")))
  48. {
  49. this.plugin.sms(s, "&8&m+----------------+");
  50. this.plugin.sms(s, "&cNo&fFly&cZone &f&oпомощь");
  51. this.plugin.sms(s, "&7/noflyzone - &fверсия плагина");
  52. this.plugin.sms(s, "&7/noflyzone reload - &fперезагрузить конфиг");
  53. this.plugin.sms(s, "&7/noflyzone list (world) - &fСписок регионов где запрещён &cfly&f.");
  54. this.plugin.sms(s, "&7/noflyzone add <world> <region> - &fДобавить регион, для запрета");
  55. this.plugin.sms(s, "&7/noflyzone remove <world> <region> - &fУдалить регион, для запрета.");
  56. this.plugin.sms(s, "&7/pfly - &fКоманды для Event.");
  57. this.plugin.sms(s, "&8&m+----------------+");
  58. return true;
  59. }
  60. if ((args.length != 0) && (args[0].equalsIgnoreCase("reload")))
  61. {
  62. this.plugin.reloadConfig();
  63. this.plugin.saveConfig();
  64. NoFlyZone.noFlyMessage = this.plugin.cfg.noFlyMessage();
  65. NoFlyZone.autoFlyMessage = this.plugin.cfg.autoFlyMessage();
  66. this.plugin.cfg.loadNoFlyRegions();
  67. this.plugin.cfg.loadNoFlyWorlds();
  68. this.plugin.cfg.loadFlyRegions();
  69. this.plugin.sms(s, "&8&m+----------------+");
  70. this.plugin.sms(s, "&7Конфиг перезагружен!");
  71. this.plugin.sms(s, "&8&m+----------------+");
  72. return true;
  73. }
  74. if ((args.length != 0) && (args[0].equalsIgnoreCase("list")))
  75. {
  76. if ((NoFlyZone.noFlyRegions == null) || (NoFlyZone.noFlyRegions.isEmpty()))
  77. {
  78. this.plugin.sms(s, "&8&m+----------------+");
  79. this.plugin.sms(s, "&cСписок регионов пуст.");
  80. this.plugin.sms(s, "&8&m+----------------+");
  81. return true;
  82. }
  83. if (args.length == 1)
  84. {
  85. this.plugin.sms(s, "&8&m+----------------+");
  86. this.plugin.sms(s, "&cNo&fFly&cZone &7worlds: &f" + NoFlyZone.noFlyWorlds.size());
  87. for (String world : NoFlyZone.noFlyRegions.keySet())
  88. {
  89. List<String> regions = NoFlyZone.noFlyRegions.get(world);
  90. if ((regions == null) || (regions.isEmpty())) {
  91. this.plugin.sms(s, "&a" + world + "&7: &cСписок регионов пуст.");
  92. } else {
  93. this.plugin.sms(s, "&a" + world + "&7: &f" + regions.toString().replace("[", "").replace("]", "").replace(",", "&7,&f"));
  94. }
  95. }
  96. this.plugin.sms(s, "&8&m+----------------+");
  97. return true;
  98. }
  99. String world = args[1];
  100. if ((!NoFlyZone.noFlyRegions.containsKey(world)) || (NoFlyZone.noFlyRegions.get(world) == null) || ((NoFlyZone.noFlyRegions.get(world)).isEmpty()))
  101. {
  102. this.plugin.sms(s, "&8&m+----------------+");
  103. this.plugin.sms(s, "&cРегионы в данным мире не найдены&7: &f" + world);
  104. this.plugin.sms(s, "&8&m+----------------+");
  105. return true;
  106. }
  107. Object regions = NoFlyZone.noFlyRegions.get(world);
  108. this.plugin.sms(s, "&8&m+----------------+");
  109. this.plugin.sms(s, "&a" + world + " &cNo&fFly&cZone &7регионы: &f" + ((Map<String, List<String>>) regions).size());
  110. this.plugin.sms(s, regions.toString().replace("[", "").replace("]", "").replace(",", "&7,&f"));
  111. this.plugin.sms(s, "&8&m+----------------+");
  112.  
  113. return true;
  114. }
  115. if ((args.length != 0) && (args[0].equalsIgnoreCase("add")))
  116. {
  117. if (args.length != 3)
  118. {
  119. this.plugin.sms(s, "&cВведите: &7/nfz add <world> <region>");
  120. return true;
  121. }
  122. String world = args[1];
  123.  
  124. String region = args[2];
  125. if ((NoFlyZone.noFlyRegions == null) || (NoFlyZone.noFlyRegions.isEmpty()))
  126. {
  127. NoFlyZone.noFlyRegions = new HashMap<>();
  128.  
  129. NoFlyZone.noFlyRegions.put(world, Arrays.asList(new String[] { region }));
  130.  
  131. this.plugin.sms(s, "&8&m+----------------+");
  132. this.plugin.sms(s, region + " &aв мире &f" + world + " &aбыл отмечен как &cNo&fFly&cZone&a!");
  133. this.plugin.sms(s, "&8&m+----------------+");
  134. this.plugin.getConfig().set("no_fly_regions." + world, NoFlyZone.noFlyRegions.get(world));
  135. this.plugin.saveConfig();
  136. return true;
  137. }
  138. if ((!NoFlyZone.noFlyRegions.containsKey(world)) || (NoFlyZone.noFlyRegions.get(world) == null))
  139. {
  140. NoFlyZone.noFlyRegions.put(world, Arrays.asList(new String[] { region }));
  141. this.plugin.sms(s, "&8&m+----------------+");
  142. this.plugin.sms(s, region + " &aiв мире &f" + world + " &aбыл отмечен как &cNo&fFly&cZone&a!");
  143. this.plugin.sms(s, "&8&m+----------------+");
  144. this.plugin.getConfig().set("no_fly_regions." + world, NoFlyZone.noFlyRegions.get(world));
  145. this.plugin.saveConfig();
  146. return true;
  147. }
  148. List<String> regz = new ArrayList<>();
  149.  
  150. boolean contains = false;
  151. for (String inList : NoFlyZone.noFlyRegions.get(world))
  152. {
  153. if (inList.equalsIgnoreCase(region))
  154. {
  155. contains = true;
  156. break;
  157. }
  158. regz.add(inList);
  159. }
  160. if (contains)
  161. {
  162. this.plugin.sms(s, "&8&m+----------------+");
  163. this.plugin.sms(s, "&cРегион &f" + region + " &cв мире &f" + world + " &cуже есть как &cNo&fFly&cZone&a!");
  164. this.plugin.sms(s, "&8&m+----------------+");
  165. return true;
  166. }
  167. regz.add(region);
  168.  
  169. NoFlyZone.noFlyRegions.put(world, regz);
  170. this.plugin.getConfig().set("no_fly_regions." + world, regz);
  171. this.plugin.saveConfig();
  172. this.plugin.sms(s, "&8&m+----------------+");
  173. this.plugin.sms(s, region + " &aв мире &f" + world + " &aбыл отмечен как &cNo&fFly&cZone&a!");
  174. this.plugin.sms(s, "&8&m+----------------+");
  175. return true;
  176. }
  177. if ((args.length != 0) && (args[0].equalsIgnoreCase("remove")))
  178. {
  179. if (args.length != 3)
  180. {
  181. this.plugin.sms(s, "&cВведите: &7/nfz remove <world> <region>");
  182. return true;
  183. }
  184. if ((NoFlyZone.noFlyRegions == null) || (NoFlyZone.noFlyRegions.isEmpty()))
  185. {
  186. this.plugin.sms(s, "&8&m+----------------+");
  187. this.plugin.sms(s, "&cНет регионов, загруженных для удаления!");
  188. this.plugin.sms(s, "&8&m+----------------+");
  189. return true;
  190. }
  191. String world = args[1];
  192. if ((!NoFlyZone.noFlyRegions.containsKey(world)) || (NoFlyZone.noFlyRegions.get(world) == null) || ((NoFlyZone.noFlyRegions.get(world)).isEmpty()))
  193. {
  194. this.plugin.sms(s, "&8&m+----------------+");
  195. this.plugin.sms(s, "&cНет регионов, загруженных для &f" + world + " &cчтобы удалить!");
  196. this.plugin.sms(s, "&8&m+----------------+");
  197. return true;
  198. }
  199. Object temp = new ArrayList<>();
  200.  
  201. String region = args[2];
  202.  
  203. boolean contains = false;
  204. for (String inList : NoFlyZone.noFlyRegions.get(world)) {
  205. if (inList.equalsIgnoreCase(region)) {
  206. contains = true;
  207. } else {
  208. ((List<String>) temp).add(inList);
  209. }
  210. }
  211. if (!contains)
  212. {
  213. this.plugin.sms(s, "&8&m+----------------+");
  214. this.plugin.sms(s, "&cНи один регион не отмечен как NoFlyZone в мире &f" + world + " &cс именем &f" + region + "&a!");
  215. this.plugin.sms(s, "&8&m+----------------+");
  216. return true;
  217. }
  218. if (((Entity) temp).isEmpty())
  219. {
  220. NoFlyZone.noFlyRegions.remove(world);
  221. this.plugin.getConfig().set("no_fly_regions." + world, null);
  222. }
  223. else
  224. {
  225. NoFlyZone.noFlyRegions.put(world, (List<String>) temp);
  226. this.plugin.getConfig().set("no_fly_regions." + world, temp);
  227. }
  228. this.plugin.saveConfig();
  229. this.plugin.sms(s, "&8&m+----------------+");
  230. this.plugin.sms(s, region + " &aв мире &f" + world + " &aболье нет для &cNo&fFly&cZone&a!");
  231. this.plugin.sms(s, "&8&m+----------------+");
  232. return true;
  233. }
  234. this.plugin.sms(s, "&cНеизвестная команда. Команды &7/nfz help");
  235. }
  236. return true;
  237. }
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement