Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.82 KB | None | 0 0
  1. package net.nitoxym.java.spigot.unclaimfinder;
  2.  
  3. import org.bukkit.plugin.java.*;
  4. import org.bukkit.plugin.*;
  5. import org.bukkit.command.*;
  6. import org.bukkit.inventory.*;
  7. import org.bukkit.inventory.meta.*;
  8. import org.bukkit.event.player.*;
  9. import org.bukkit.event.block.*;
  10. import org.bukkit.event.*;
  11. import org.bukkit.entity.*;
  12. import java.util.*;
  13. import net.md_5.bungee.api.*;
  14. import net.md_5.bungee.api.chat.*;
  15. import java.lang.reflect.*;
  16. import org.bukkit.*;
  17.  
  18. public class Main extends JavaPlugin implements Listener
  19. {
  20. public int durability;
  21. public static final ItemStack UNCLAIM_FINDER;
  22.  
  23. static {
  24. UNCLAIM_FINDER = new ItemStack(Material.COMPASS);
  25. }
  26.  
  27. public Main() {
  28. this.durability = this.getConfig().getInt("durability");
  29. }
  30.  
  31. public void onEnable() {
  32. this.saveDefaultConfig();
  33. this.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this);
  34. this.getCommand("unclaimfinder").setExecutor((CommandExecutor)new Main.Main$1(this));
  35. this.getCommand("unclaimfinder").setTabCompleter((TabCompleter)new Main.Main$2(this));
  36. final ItemMeta im = Main.UNCLAIM_FINDER.getItemMeta();
  37. im.setDisplayName(this.getConfig().getString("display-name").replace("&", "§"));
  38. final List<String> lb = (List<String>)this.getConfig().getStringList("lore");
  39. final List<String> l = new ArrayList<String>();
  40. for (final String s : lb) {
  41. l.add(s.replace("&", "§"));
  42. }
  43. l.add("");
  44. l.add("§7Durability: " + this.durability + " / " + this.durability);
  45. im.setLore((List)l);
  46. Main.UNCLAIM_FINDER.setItemMeta(im);
  47. for (final String crafts : this.getConfig().getStringList("crafts.enabled")) {
  48. String line0 = "";
  49. String line2 = "";
  50. String line3 = "";
  51. String lines = "";
  52. final List<Material> mats = new ArrayList<Material>();
  53. final String ingredients = "ABCDEFGHI";
  54. for (int i = 0; i < 9; ++i) {
  55. if (this.getConfig().contains("crafts." + crafts + ".slot" + i)) {
  56. final Material mat = Material.getMaterial(this.getConfig().getString("crafts." + crafts + ".slot" + i).toUpperCase());
  57. mats.add(mat);
  58. if (i < 3) {
  59. if (mat.equals((Object)Material.AIR)) {
  60. line0 = String.valueOf(line0) + " ";
  61. }
  62. else {
  63. line0 = String.valueOf(line0) + ingredients.split("")[i];
  64. }
  65. }
  66. else if (i < 6) {
  67. if (mat.equals((Object)Material.AIR)) {
  68. line2 = String.valueOf(line2) + " ";
  69. }
  70. else {
  71. line2 = String.valueOf(line2) + ingredients.split("")[i];
  72. }
  73. }
  74. else if (mat.equals((Object)Material.AIR)) {
  75. line3 = String.valueOf(line3) + " ";
  76. }
  77. else {
  78. line3 = String.valueOf(line3) + ingredients.split("")[i];
  79. }
  80. }
  81. else if (i < 3) {
  82. line0 = String.valueOf(line0) + " ";
  83. }
  84. else if (i < 6) {
  85. line2 = String.valueOf(line2) + " ";
  86. }
  87. else {
  88. line3 = String.valueOf(line3) + " ";
  89. }
  90. }
  91. lines = String.valueOf(line0) + line2 + line3;
  92. final ShapedRecipe recipe = new ShapedRecipe(Main.UNCLAIM_FINDER);
  93. recipe.shape(new String[] { line0, line2, line3 });
  94. for (int j = 0; j < 9; ++j) {
  95. if (!lines.split("")[j].equals(" ")) {
  96. recipe.setIngredient(lines.charAt(j), (Material)mats.get(j));
  97. }
  98. }
  99. Bukkit.addRecipe((Recipe)recipe);
  100. }
  101. }
  102.  
  103. @EventHandler
  104. public void onInteract(final PlayerInteractEvent e) {
  105. if (this.getConfig().getBoolean("world-whitelist")) {
  106. if (!this.getConfig().getStringList("white-worlds").contains(e.getPlayer().getLocation().getWorld().getName())) {
  107. return;
  108. }
  109. }
  110. else if (this.getConfig().getBoolean("world-blacklist") && this.getConfig().getStringList("black-worlds").contains(e.getPlayer().getLocation().getWorld().getName())) {
  111. return;
  112. }
  113. if ((e.getAction().equals((Object)Action.RIGHT_CLICK_AIR) || e.getAction().equals((Object)Action.RIGHT_CLICK_BLOCK)) && e.getItem() != null && e.getItem().getType().equals((Object)Material.COMPASS)) {
  114. final List<String> lb = (List<String>)this.getConfig().getStringList("lore");
  115. final List<String> l = new ArrayList<String>();
  116. for (final String s : lb) {
  117. l.add(s.replace("&", "§"));
  118. }
  119. if (e.getItem().hasItemMeta() && e.getItem().getItemMeta().hasLore() && e.getItem().getItemMeta().getLore().containsAll(l)) {
  120. this.title(e.getPlayer(), "§f§lCalculating...");
  121. new Thread((Runnable)new Main.Main$3(this, e)).start();
  122. final ItemStack item = e.getItem();
  123. final ItemMeta im = item.getItemMeta();
  124. final List<String> lines = (List<String>)im.getLore();
  125. final String durabilityl = lines.get(lines.size() - 1);
  126. int dur = Integer.valueOf(durabilityl.substring(14, durabilityl.length() - 3 - new StringBuilder(String.valueOf(this.durability)).toString().length()));
  127. if (e.getPlayer().getGameMode().equals((Object)GameMode.SURVIVAL) || e.getPlayer().getGameMode().equals((Object)GameMode.ADVENTURE)) {
  128. --dur;
  129. }
  130. final List<String> lore = new ArrayList<String>();
  131. for (final String str : this.getConfig().getStringList("lore")) {
  132. lore.add(str.replace("&", "§"));
  133. }
  134. lore.add("");
  135. lore.add("§7Durability: " + dur + " / " + this.durability);
  136. im.setLore((List)lore);
  137. item.setItemMeta(im);
  138. if (dur < 0) {
  139. e.getPlayer().getInventory().setItemInHand((ItemStack)null);
  140. e.getPlayer().getWorld().playSound(e.getPlayer().getLocation(), Sound.ENTITY_ITEM_BREAK, 1.0f, 1.0f);
  141. e.getPlayer().updateInventory();
  142. }
  143. }
  144. }
  145. }
  146.  
  147. private Class<?> getNMSClass(final String nmsClassString) throws ClassNotFoundException {
  148. final String version = String.valueOf(Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]) + ".";
  149. final String name = "net.minecraft.server." + version + nmsClassString;
  150. final Class<?> nms = Class.forName(name);
  151. return nms;
  152. }
  153.  
  154. private Class<?> getCraftBukkitClass(final String classString) throws ClassNotFoundException {
  155. final String version = String.valueOf(Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]) + ".";
  156. final String name = "org.bukkit.craftbukkit." + version + classString;
  157. final Class<?> cb = Class.forName(name);
  158. return cb;
  159. }
  160.  
  161. private Object getConnection(final Player player) throws SecurityException, NoSuchMethodException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, ClassNotFoundException {
  162. final Object cp = this.getCraftBukkitClass("entity.CraftPlayer").cast(player);
  163. final Method handle = cp.getClass().getMethod("getHandle", (Class<?>[])new Class[0]);
  164. final Object p = handle.invoke(cp, new Object[0]);
  165. final Field field = p.getClass().getField("playerConnection");
  166. final Object connection = field.get(p);
  167. return connection;
  168. }
  169.  
  170. public void title(final Player player, final String message) {
  171. final List<String> ver = Arrays.asList("v1_8_R1", "v1_8_R2", "v1_8_R3", "v1_9_R1", "v1_9_R2", "v1_10_R1", "v1_11_R1");
  172. final String cver = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
  173. if (!ver.contains(cver)) {
  174. player.spigot().sendMessage(ChatMessageType.ACTION_BAR, (BaseComponent)new TextComponent(message));
  175. return;
  176. }
  177. try {
  178. final Constructor<?> constructor = this.getNMSClass("PacketPlayOutChat").getConstructor(this.getNMSClass("IChatBaseComponent"), Byte.TYPE);
  179. Object base = null;
  180. try {
  181. base = this.getNMSClass("ChatSerializer").getMethod("a", String.class).invoke(null, "{\"text\":\"" + message + "\"}");
  182. }
  183. catch (Exception e2) {
  184. base = this.getNMSClass("IChatBaseComponent$ChatSerializer").getMethod("a", String.class).invoke(null, "{\"text\":\"" + message + "\"}");
  185. }
  186. if (base == null) {
  187. throw new NullPointerException();
  188. }
  189. final Object packet = constructor.newInstance(base, (byte)2);
  190. final Object ep = this.getConnection(player);
  191. ep.getClass().getMethod("sendPacket", this.getNMSClass("Packet")).invoke(ep, packet);
  192. }
  193. catch (Exception e) {
  194. e.printStackTrace();
  195. }
  196. }
  197.  
  198. public void showPercentage(final Player player) {
  199. final Location l = player.getLocation();
  200. final int range = Math.abs(this.getConfig().getInt("range-radius"));
  201. int percentage = 0;
  202. for (int x = l.getBlockX() - range; x <= l.getBlockX() + range; ++x) {
  203. for (int y = 0; y <= 255; ++y) {
  204. for (int z = l.getBlockZ() - range; z <= l.getBlockZ() + range; ++z) {
  205. final Material m = l.getWorld().getBlockAt(x, y, z).getType();
  206. for (final String mat : this.getConfig().getStringList("block-list")) {
  207. final Material mm = Material.getMaterial(mat.toUpperCase());
  208. if (mm != null && mm.equals((Object)m) && this.getConfig().contains("block-percentages." + mat)) {
  209. percentage += Integer.valueOf(this.getConfig().getString("block-percentages." + mat).replaceAll("[^0-9]+", ""));
  210. break;
  211. }
  212. }
  213. }
  214. }
  215. }
  216. if (percentage > 100) {
  217. percentage = 100;
  218. }
  219. String result = "§f§l";
  220. if (percentage >= 5) {
  221. result = "§e§l";
  222. }
  223. if (percentage >= 15) {
  224. result = "§6§l";
  225. }
  226. if (percentage >= 30) {
  227. result = "§c§l";
  228. }
  229. if (percentage >= 50) {
  230. result = "§4§l";
  231. }
  232. if (percentage == 100) {
  233. result = "§0§l";
  234. }
  235. this.title(player, String.valueOf(result) + percentage + "%");
  236. }
  237.  
  238. public void showPercentage(final Player player, final int radius) {
  239. final Location l = player.getLocation();
  240. final int range = Math.abs(radius);
  241. int percentage = 0;
  242. for (int x = l.getBlockX() - range; x <= l.getBlockX() + range; ++x) {
  243. for (int y = 0; y <= 255; ++y) {
  244. for (int z = l.getBlockZ() - range; z <= l.getBlockZ() + range; ++z) {
  245. final Material m = l.getWorld().getBlockAt(x, y, z).getType();
  246. for (final String mat : this.getConfig().getStringList("block-list")) {
  247. final Material mm = Material.getMaterial(mat.toUpperCase());
  248. if (mm != null && mm.equals((Object)m) && this.getConfig().contains("block-percentages." + mat)) {
  249. percentage += Integer.valueOf(this.getConfig().getString("block-percentages." + mat).replaceAll("[^0-9]+", ""));
  250. break;
  251. }
  252. }
  253. }
  254. }
  255. }
  256. if (percentage > 100) {
  257. percentage = 100;
  258. }
  259. String result = "§f§l";
  260. if (percentage >= 5) {
  261. result = "§e§l";
  262. }
  263. if (percentage >= 15) {
  264. result = "§6§l";
  265. }
  266. if (percentage >= 30) {
  267. result = "§c§l";
  268. }
  269. if (percentage >= 50) {
  270. result = "§4§l";
  271. }
  272. if (percentage == 100) {
  273. result = "§0§l";
  274. }
  275. this.title(player, String.valueOf(result) + percentage + "%");
  276. }
  277. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement