Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.nitoxym.java.spigot.unclaimfinder;
- import org.bukkit.plugin.java.*;
- import org.bukkit.plugin.*;
- import org.bukkit.command.*;
- import org.bukkit.inventory.*;
- import org.bukkit.inventory.meta.*;
- import org.bukkit.event.player.*;
- import org.bukkit.event.block.*;
- import org.bukkit.event.*;
- import org.bukkit.entity.*;
- import java.util.*;
- import net.md_5.bungee.api.*;
- import net.md_5.bungee.api.chat.*;
- import java.lang.reflect.*;
- import org.bukkit.*;
- public class Main extends JavaPlugin implements Listener
- {
- public int durability;
- public static final ItemStack UNCLAIM_FINDER;
- static {
- UNCLAIM_FINDER = new ItemStack(Material.COMPASS);
- }
- public Main() {
- this.durability = this.getConfig().getInt("durability");
- }
- public void onEnable() {
- this.saveDefaultConfig();
- this.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this);
- this.getCommand("unclaimfinder").setExecutor((CommandExecutor)new Main.Main$1(this));
- this.getCommand("unclaimfinder").setTabCompleter((TabCompleter)new Main.Main$2(this));
- final ItemMeta im = Main.UNCLAIM_FINDER.getItemMeta();
- im.setDisplayName(this.getConfig().getString("display-name").replace("&", "§"));
- final List<String> lb = (List<String>)this.getConfig().getStringList("lore");
- final List<String> l = new ArrayList<String>();
- for (final String s : lb) {
- l.add(s.replace("&", "§"));
- }
- l.add("");
- l.add("§7Durability: " + this.durability + " / " + this.durability);
- im.setLore((List)l);
- Main.UNCLAIM_FINDER.setItemMeta(im);
- for (final String crafts : this.getConfig().getStringList("crafts.enabled")) {
- String line0 = "";
- String line2 = "";
- String line3 = "";
- String lines = "";
- final List<Material> mats = new ArrayList<Material>();
- final String ingredients = "ABCDEFGHI";
- for (int i = 0; i < 9; ++i) {
- if (this.getConfig().contains("crafts." + crafts + ".slot" + i)) {
- final Material mat = Material.getMaterial(this.getConfig().getString("crafts." + crafts + ".slot" + i).toUpperCase());
- mats.add(mat);
- if (i < 3) {
- if (mat.equals((Object)Material.AIR)) {
- line0 = String.valueOf(line0) + " ";
- }
- else {
- line0 = String.valueOf(line0) + ingredients.split("")[i];
- }
- }
- else if (i < 6) {
- if (mat.equals((Object)Material.AIR)) {
- line2 = String.valueOf(line2) + " ";
- }
- else {
- line2 = String.valueOf(line2) + ingredients.split("")[i];
- }
- }
- else if (mat.equals((Object)Material.AIR)) {
- line3 = String.valueOf(line3) + " ";
- }
- else {
- line3 = String.valueOf(line3) + ingredients.split("")[i];
- }
- }
- else if (i < 3) {
- line0 = String.valueOf(line0) + " ";
- }
- else if (i < 6) {
- line2 = String.valueOf(line2) + " ";
- }
- else {
- line3 = String.valueOf(line3) + " ";
- }
- }
- lines = String.valueOf(line0) + line2 + line3;
- final ShapedRecipe recipe = new ShapedRecipe(Main.UNCLAIM_FINDER);
- recipe.shape(new String[] { line0, line2, line3 });
- for (int j = 0; j < 9; ++j) {
- if (!lines.split("")[j].equals(" ")) {
- recipe.setIngredient(lines.charAt(j), (Material)mats.get(j));
- }
- }
- Bukkit.addRecipe((Recipe)recipe);
- }
- }
- @EventHandler
- public void onInteract(final PlayerInteractEvent e) {
- if (this.getConfig().getBoolean("world-whitelist")) {
- if (!this.getConfig().getStringList("white-worlds").contains(e.getPlayer().getLocation().getWorld().getName())) {
- return;
- }
- }
- else if (this.getConfig().getBoolean("world-blacklist") && this.getConfig().getStringList("black-worlds").contains(e.getPlayer().getLocation().getWorld().getName())) {
- return;
- }
- 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)) {
- final List<String> lb = (List<String>)this.getConfig().getStringList("lore");
- final List<String> l = new ArrayList<String>();
- for (final String s : lb) {
- l.add(s.replace("&", "§"));
- }
- if (e.getItem().hasItemMeta() && e.getItem().getItemMeta().hasLore() && e.getItem().getItemMeta().getLore().containsAll(l)) {
- this.title(e.getPlayer(), "§f§lCalculating...");
- new Thread((Runnable)new Main.Main$3(this, e)).start();
- final ItemStack item = e.getItem();
- final ItemMeta im = item.getItemMeta();
- final List<String> lines = (List<String>)im.getLore();
- final String durabilityl = lines.get(lines.size() - 1);
- int dur = Integer.valueOf(durabilityl.substring(14, durabilityl.length() - 3 - new StringBuilder(String.valueOf(this.durability)).toString().length()));
- if (e.getPlayer().getGameMode().equals((Object)GameMode.SURVIVAL) || e.getPlayer().getGameMode().equals((Object)GameMode.ADVENTURE)) {
- --dur;
- }
- final List<String> lore = new ArrayList<String>();
- for (final String str : this.getConfig().getStringList("lore")) {
- lore.add(str.replace("&", "§"));
- }
- lore.add("");
- lore.add("§7Durability: " + dur + " / " + this.durability);
- im.setLore((List)lore);
- item.setItemMeta(im);
- if (dur < 0) {
- e.getPlayer().getInventory().setItemInHand((ItemStack)null);
- e.getPlayer().getWorld().playSound(e.getPlayer().getLocation(), Sound.ENTITY_ITEM_BREAK, 1.0f, 1.0f);
- e.getPlayer().updateInventory();
- }
- }
- }
- }
- private Class<?> getNMSClass(final String nmsClassString) throws ClassNotFoundException {
- final String version = String.valueOf(Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]) + ".";
- final String name = "net.minecraft.server." + version + nmsClassString;
- final Class<?> nms = Class.forName(name);
- return nms;
- }
- private Class<?> getCraftBukkitClass(final String classString) throws ClassNotFoundException {
- final String version = String.valueOf(Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]) + ".";
- final String name = "org.bukkit.craftbukkit." + version + classString;
- final Class<?> cb = Class.forName(name);
- return cb;
- }
- private Object getConnection(final Player player) throws SecurityException, NoSuchMethodException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, ClassNotFoundException {
- final Object cp = this.getCraftBukkitClass("entity.CraftPlayer").cast(player);
- final Method handle = cp.getClass().getMethod("getHandle", (Class<?>[])new Class[0]);
- final Object p = handle.invoke(cp, new Object[0]);
- final Field field = p.getClass().getField("playerConnection");
- final Object connection = field.get(p);
- return connection;
- }
- public void title(final Player player, final String message) {
- 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");
- final String cver = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
- if (!ver.contains(cver)) {
- player.spigot().sendMessage(ChatMessageType.ACTION_BAR, (BaseComponent)new TextComponent(message));
- return;
- }
- try {
- final Constructor<?> constructor = this.getNMSClass("PacketPlayOutChat").getConstructor(this.getNMSClass("IChatBaseComponent"), Byte.TYPE);
- Object base = null;
- try {
- base = this.getNMSClass("ChatSerializer").getMethod("a", String.class).invoke(null, "{\"text\":\"" + message + "\"}");
- }
- catch (Exception e2) {
- base = this.getNMSClass("IChatBaseComponent$ChatSerializer").getMethod("a", String.class).invoke(null, "{\"text\":\"" + message + "\"}");
- }
- if (base == null) {
- throw new NullPointerException();
- }
- final Object packet = constructor.newInstance(base, (byte)2);
- final Object ep = this.getConnection(player);
- ep.getClass().getMethod("sendPacket", this.getNMSClass("Packet")).invoke(ep, packet);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void showPercentage(final Player player) {
- final Location l = player.getLocation();
- final int range = Math.abs(this.getConfig().getInt("range-radius"));
- int percentage = 0;
- for (int x = l.getBlockX() - range; x <= l.getBlockX() + range; ++x) {
- for (int y = 0; y <= 255; ++y) {
- for (int z = l.getBlockZ() - range; z <= l.getBlockZ() + range; ++z) {
- final Material m = l.getWorld().getBlockAt(x, y, z).getType();
- for (final String mat : this.getConfig().getStringList("block-list")) {
- final Material mm = Material.getMaterial(mat.toUpperCase());
- if (mm != null && mm.equals((Object)m) && this.getConfig().contains("block-percentages." + mat)) {
- percentage += Integer.valueOf(this.getConfig().getString("block-percentages." + mat).replaceAll("[^0-9]+", ""));
- break;
- }
- }
- }
- }
- }
- if (percentage > 100) {
- percentage = 100;
- }
- String result = "§f§l";
- if (percentage >= 5) {
- result = "§e§l";
- }
- if (percentage >= 15) {
- result = "§6§l";
- }
- if (percentage >= 30) {
- result = "§c§l";
- }
- if (percentage >= 50) {
- result = "§4§l";
- }
- if (percentage == 100) {
- result = "§0§l";
- }
- this.title(player, String.valueOf(result) + percentage + "%");
- }
- public void showPercentage(final Player player, final int radius) {
- final Location l = player.getLocation();
- final int range = Math.abs(radius);
- int percentage = 0;
- for (int x = l.getBlockX() - range; x <= l.getBlockX() + range; ++x) {
- for (int y = 0; y <= 255; ++y) {
- for (int z = l.getBlockZ() - range; z <= l.getBlockZ() + range; ++z) {
- final Material m = l.getWorld().getBlockAt(x, y, z).getType();
- for (final String mat : this.getConfig().getStringList("block-list")) {
- final Material mm = Material.getMaterial(mat.toUpperCase());
- if (mm != null && mm.equals((Object)m) && this.getConfig().contains("block-percentages." + mat)) {
- percentage += Integer.valueOf(this.getConfig().getString("block-percentages." + mat).replaceAll("[^0-9]+", ""));
- break;
- }
- }
- }
- }
- }
- if (percentage > 100) {
- percentage = 100;
- }
- String result = "§f§l";
- if (percentage >= 5) {
- result = "§e§l";
- }
- if (percentage >= 15) {
- result = "§6§l";
- }
- if (percentage >= 30) {
- result = "§c§l";
- }
- if (percentage >= 50) {
- result = "§4§l";
- }
- if (percentage == 100) {
- result = "§0§l";
- }
- this.title(player, String.valueOf(result) + percentage + "%");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement