Advertisement
Cool_boy21

1

Jan 28th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.72 KB | None | 0 0
  1. /*
  2. * Decompiled with CFR 0_118.
  3. *
  4. * Could not load the following classes:
  5. * org.bukkit.ChatColor
  6. * org.bukkit.Material
  7. * org.bukkit.Server
  8. * org.bukkit.World
  9. * org.bukkit.block.Block
  10. * org.bukkit.command.Command
  11. * org.bukkit.command.CommandExecutor
  12. * org.bukkit.command.CommandSender
  13. * org.bukkit.command.PluginCommand
  14. * org.bukkit.configuration.file.FileConfiguration
  15. * org.bukkit.configuration.file.FileConfigurationOptions
  16. * org.bukkit.entity.Player
  17. * org.bukkit.event.EventHandler
  18. * org.bukkit.event.Listener
  19. * org.bukkit.event.block.Action
  20. * org.bukkit.event.player.PlayerInteractEvent
  21. * org.bukkit.plugin.Plugin
  22. * org.bukkit.plugin.PluginManager
  23. * org.bukkit.plugin.java.JavaPlugin
  24. * pl.islandworld.api.IslandWorldApi
  25. */
  26. package pl.iwhr;
  27.  
  28. import java.io.File;
  29. import java.io.IOException;
  30. import java.util.ArrayList;
  31. import java.util.List;
  32. import java.util.logging.Logger;
  33. import org.bukkit.ChatColor;
  34. import org.bukkit.Material;
  35. import org.bukkit.Server;
  36. import org.bukkit.World;
  37. import org.bukkit.block.Block;
  38. import org.bukkit.command.Command;
  39. import org.bukkit.command.CommandExecutor;
  40. import org.bukkit.command.CommandSender;
  41. import org.bukkit.command.PluginCommand;
  42. import org.bukkit.configuration.file.FileConfiguration;
  43. import org.bukkit.configuration.file.FileConfigurationOptions;
  44. import org.bukkit.entity.Player;
  45. import org.bukkit.event.EventHandler;
  46. import org.bukkit.event.Listener;
  47. import org.bukkit.event.block.Action;
  48. import org.bukkit.event.player.PlayerInteractEvent;
  49. import org.bukkit.plugin.Plugin;
  50. import org.bukkit.plugin.PluginManager;
  51. import org.bukkit.plugin.java.JavaPlugin;
  52. import pl.islandworld.api.IslandWorldApi;
  53. import pl.iwhr.listeners.RankListener;
  54.  
  55. public class IWHeadRank
  56. extends JavaPlugin
  57. implements CommandExecutor,
  58. Listener {
  59. public static boolean DEBUG = false;
  60. private List<String> cList = new ArrayList<String>();
  61. private Player coordsPlayer = null;
  62.  
  63. public void onEnable() {
  64. File configFile = new File(this.getDataFolder(), "config.yml");
  65. if (!configFile.exists()) {
  66. this.saveDefaultConfig();
  67. this.getLogger().info("Writing default config to file.");
  68. }
  69. this.saveOurConfig(configFile);
  70. if (!IslandWorldApi.isInitialized()) {
  71. this.showWarn("IslandWorldAPI not ready, cannot start!", true);
  72. return;
  73. }
  74. this.getServer().getPluginManager().registerEvents((Listener)new RankListener(this), (Plugin)this);
  75. this.getCommand("headrank").setExecutor((CommandExecutor)this);
  76. this.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this);
  77. this.getLogger().info("Plugin enabled");
  78. }
  79.  
  80. public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
  81. if (!(sender instanceof Player)) {
  82. return false;
  83. }
  84. Player player = (Player)sender;
  85. String param1 = null;
  86. if (split.length >= 1) {
  87. param1 = split[0];
  88. }
  89. if (param1 == null) {
  90. this.showUsage(player);
  91. } else if (param1.equalsIgnoreCase("start")) {
  92. if (player.hasPermission("islandworld.headrank.start")) {
  93. if (this.coordsPlayer == null) {
  94. this.cList.clear();
  95. this.coordsPlayer = player;
  96. this.showMsg(sender, "Coords gather start");
  97. } else {
  98. this.showError(sender, "Player " + (Object)this.coordsPlayer + " already is gathering coords!");
  99. }
  100. } else {
  101. this.showError(sender, "You dont have permission to use that command!");
  102. }
  103. } else if (param1.equalsIgnoreCase("stop")) {
  104. if (player.hasPermission("islandworld.headrank.stop")) {
  105. if (this.coordsPlayer != null) {
  106. if (!this.cList.isEmpty()) {
  107. this.getConfig().set("table-coords", this.cList);
  108. this.saveConfig();
  109. this.reloadConfig();
  110. this.showMsg((CommandSender)player, "Coords saved");
  111. } else {
  112. this.showError(sender, "Nothing to write!");
  113. }
  114. this.cList.clear();
  115. this.coordsPlayer = null;
  116. } else {
  117. this.showError(sender, "Nobody is gathering coords right now!");
  118. }
  119. } else {
  120. this.showError(sender, "You dont have permission to use that command!");
  121. }
  122. } else if (param1.equalsIgnoreCase("world")) {
  123. if (player.hasPermission("islandworld.headrank.world")) {
  124. this.getConfig().set("world", (Object)player.getWorld().getName());
  125. this.saveConfig();
  126. this.reloadConfig();
  127. this.showMsg((CommandSender)player, "World saved");
  128. } else {
  129. this.showError(sender, "You dont have permission to use that command!");
  130. }
  131. }
  132. return true;
  133. }
  134.  
  135. @EventHandler
  136. public void onCoordsInteract(PlayerInteractEvent event) {
  137. Player player = event.getPlayer();
  138. Action a = event.getAction();
  139. Block b = event.getClickedBlock();
  140. if (b != null && player != null && this.coordsPlayer != null && this.coordsPlayer instanceof Player && this.coordsPlayer == player) {
  141. String option = String.valueOf(b.getX()) + " " + b.getY() + " " + b.getZ();
  142. if (b.getType() == Material.WALL_SIGN) {
  143. if (a == Action.LEFT_CLICK_BLOCK) {
  144. if (!this.cList.contains(option)) {
  145. this.cList.add(option);
  146. this.showMsg((CommandSender)player, "Added coord " + option);
  147. } else {
  148. this.showError((CommandSender)player, "Coord " + option + " already on list!");
  149. }
  150. } else if (a == Action.RIGHT_CLICK_BLOCK) {
  151. if (this.cList.contains(option)) {
  152. this.cList.remove(option);
  153. this.showMsg((CommandSender)player, "Removed coord " + option + " from coord list");
  154. } else {
  155. this.showError((CommandSender)player, "Coord " + option + " not on list.");
  156. }
  157. }
  158. } else {
  159. this.showError((CommandSender)player, "I can save only coords of Signs");
  160. }
  161. }
  162. }
  163.  
  164. private void showMsg(CommandSender sender, String text) {
  165. if (sender != null) {
  166. sender.sendMessage((Object)ChatColor.GREEN + text);
  167. }
  168. }
  169.  
  170. public boolean showError(CommandSender sender, String text) {
  171. if (sender != null) {
  172. sender.sendMessage((Object)ChatColor.DARK_RED + "IWHR: " + (Object)ChatColor.RED + text);
  173. }
  174. return false;
  175. }
  176.  
  177. public void showUsage(Player player) {
  178. }
  179.  
  180. private void showWarn(String msg, boolean isError) {
  181. this.getLogger().warning("============================");
  182. if (isError) {
  183. this.getLogger().warning("ERROR");
  184. }
  185. this.getLogger().warning(msg);
  186. this.getLogger().warning("============================");
  187. }
  188.  
  189. private void saveOurConfig(File file) {
  190. this.getConfig().options().copyHeader(true);
  191. this.getConfig().options().copyDefaults(true);
  192. try {
  193. this.getConfig().save(file);
  194. }
  195. catch (IOException e) {
  196. e.printStackTrace();
  197. }
  198. }
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement