Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.BingoRufus.ArtifactForge;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.UUID;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.Particle;
- import org.bukkit.Sound;
- import org.bukkit.block.Block;
- import org.bukkit.entity.Item;
- import org.bukkit.entity.Player;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.entity.EntityPickupItemEvent;
- import org.bukkit.event.inventory.InventoryClickEvent;
- import org.bukkit.event.inventory.InventoryCloseEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.event.EventHandler;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.util.Vector;
- //Item Slots are 10,11,12,19,20,21,28,29,30. With Output slot of 24,
- public class Main extends JavaPlugin implements Listener {
- ItemStack JustAStick;
- ItemStack InvalidRecipe;
- int PickupMsgDelay = 5000;
- List<HashMap<Integer, ItemStack>> Recipes = new ArrayList<HashMap<Integer, ItemStack>>();
- Map<Player, Long> PickupSpammer = new HashMap<Player, Long>();
- Map<UUID, Player> ItemOwner = new HashMap<UUID, Player>();
- HashMap<Integer, ItemStack> CurrentRecipe = new HashMap<Integer, ItemStack>();
- HashMap<Player, Boolean> InForgeMenu = new HashMap<Player, Boolean>();
- HashMap<Player, Integer> id = new HashMap<Player, Integer>();
- List<Integer> NotBlackTiles = new ArrayList<Integer>();
- List<Integer> BlackTiles = new ArrayList<Integer>();
- ItemStack item;
- ItemMeta meta;
- List<String> lore = new ArrayList<String>();
- int TaskId;
- public Inventory Forge;
- Runnable CircleParticles;
- public Plugin plugin;
- @Override
- public void onEnable() {
- plugin = this;
- createStuff();
- Bukkit.getPluginManager().registerEvents(this, this);
- }
- @Override
- public void onDisable() {
- }
- @EventHandler()
- public void Interact(PlayerInteractEvent e) {
- Player p = e.getPlayer();
- Block b = e.getClickedBlock();
- if (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_AIR) {
- if (e.getItem() != null) {
- ItemStack I = e.getItem();
- if (I.equals(JustAStick)) {
- p.sendMessage(ChatColor.YELLOW + "Well, what'd you think it'd do?");
- }
- if (I.equals(InvalidRecipe)) {
- e.setCancelled(true);
- p.sendMessage("Yoink");
- if (p.getInventory().getItemInOffHand() != null) {
- if (p.getInventory().getItemInOffHand().equals(InvalidRecipe)) {
- p.getInventory().setItemInOffHand(null);
- return;
- }
- }
- if (p.getInventory().getItemInMainHand() != null) {
- if (p.getInventory().getItemInMainHand().equals(InvalidRecipe)) {
- p.getInventory().setItemInMainHand(null);
- return;
- }
- }
- }
- }
- }
- // Open Artifact ForgerVVV
- if (b.getType() == Material.ANVIL) {
- if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
- if (b.getLocation().subtract(0, 1, 0).getBlock().getType() == Material.MAGMA_BLOCK) {
- if (id.get(p) != null) {
- Bukkit.getScheduler().cancelTask(id.get(p));
- id.remove(p);
- }
- e.setCancelled(true);
- InForgeMenu.put(p, true);
- TaskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
- double a;
- public void run() {
- if (id.get(p) == null) {
- id.put(p, TaskId);
- }
- if (InForgeMenu.get(p) == null) {
- Bukkit.getScheduler().cancelTask(id.get(p));
- id.remove(p);
- return;
- }
- a += Math.PI / 24;
- Location loc = e.getClickedBlock().getLocation().add(0.5, 0, 0.5);
- Location first = loc.clone()
- .add(new Vector(Math.cos(a), 1.25, Math.sin(a)).divide(new Vector(1.5, 1, 1.5)));
- Location second = loc.clone()
- .add(new Vector(Math.cos(a + Math.PI), 1.25, Math.sin(a + Math.PI))
- .divide(new Vector(1.5, 1, 1.5)));
- p.getWorld().spawnParticle(Particle.FLAME, first, 0, 0, 0, 0);
- p.getWorld().spawnParticle(Particle.FLAME, second, 0, 0, 0, 0);
- p.getWorld().spawnParticle(Particle.ENCHANTMENT_TABLE, loc.clone().add(0, 2, 0), 1);
- }
- }, 0, 1);
- Forge = Bukkit.createInventory(null, 45,
- ChatColor.translateAlternateColorCodes('&', "&b&lArtifact Forge"));
- for (int i = 0; i < 45; i++) {
- item = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
- meta = item.getItemMeta();
- meta.setDisplayName(" ");
- item.setItemMeta(meta);
- if (!NotBlackTiles.contains(i)) {
- BlackTiles.add(i);
- Forge.setItem(i, item);
- }
- }
- Forge.setItem(24, InvalidRecipe);
- p.openInventory(Forge);
- return;
- }
- }
- }
- }
- @EventHandler()
- public void onClose(InventoryCloseEvent e) {
- Inventory inv = e.getInventory();
- Player p = (Player) e.getPlayer();
- if (e.getView().getTitle().equals(ChatColor.AQUA + "" + ChatColor.BOLD + "Artifact Forge")) {
- InForgeMenu.remove(p);
- for (int i : NotBlackTiles) {
- if (i != 24) {
- giveItem(inv.getItem(i), p);
- }
- continue;
- }
- return;
- }
- }
- public void giveItem(ItemStack item, Player p) {
- if (item != null) {
- if (p.getInventory().firstEmpty() == -1) {
- Item DroppedItem = p.getWorld().dropItem(p.getLocation(), item);
- if (item.getItemMeta().hasDisplayName()) {
- p.sendMessage(
- ChatColor.DARK_RED + "" + ChatColor.BOLD + "Your " + item.getItemMeta().getDisplayName()
- + " has been dropped on the ground because your inventory is full!");
- ItemOwner.put(DroppedItem.getUniqueId(), p);
- return;
- }
- p.sendMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + "Your " + item.getType().name()
- + " has been dropped on the ground because your inventory is full!");
- ItemOwner.put(DroppedItem.getUniqueId(), p);
- return;
- }
- p.getInventory().addItem(item);
- return;
- }
- }
- @EventHandler()
- public void onItemPickup(EntityPickupItemEvent e) {
- if (!(e.getEntity() instanceof Player)) {
- e.setCancelled(true);
- return;
- }
- Player p = (Player) e.getEntity();
- if (ItemOwner.get(e.getItem().getUniqueId()) != null) {
- Player Owner = (Player) ItemOwner.get(e.getItem().getUniqueId());
- if (Owner.equals(p))
- return;
- if (p.hasPermission("ArtifactForger.pickupoverride")) {
- p.sendMessage(ChatColor.GREEN + "You picked up " + Owner.getDisplayName() + ChatColor.GREEN + "'s "
- + e.getItem().getName());
- return;
- }
- if (PickupSpammer.get(p) == null || System.currentTimeMillis() - PickupSpammer.get(p) >= PickupMsgDelay) {
- p.sendMessage(ChatColor.RED + "Only " + Owner.getName() + " can pick this item up");
- PickupSpammer.put(p, System.currentTimeMillis());
- }
- e.setCancelled(true);
- return;
- }
- return;
- }
- @EventHandler()
- public void onClick(InventoryClickEvent e) {
- // Item Slots are 10,11,12,19,20,21,28,29,30. With Output slot of 24
- Player p = (Player) e.getWhoClicked();
- if (e.getInventory().equals(Forge)) {
- Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
- public void run() {
- ItemStack Slot1 = e.getInventory().getItem(10);
- ItemStack Slot2 = e.getInventory().getItem(11);
- ItemStack Slot3 = e.getInventory().getItem(12);
- ItemStack Slot4 = e.getInventory().getItem(19);
- ItemStack Slot5 = e.getInventory().getItem(20);
- ItemStack Slot6 = e.getInventory().getItem(21);
- ItemStack Slot7 = e.getInventory().getItem(28);
- ItemStack Slot8 = e.getInventory().getItem(29);
- ItemStack Slot9 = e.getInventory().getItem(30);
- CurrentRecipe.put(1, Slot1);
- CurrentRecipe.put(2, Slot2);
- CurrentRecipe.put(3, Slot3);
- CurrentRecipe.put(4, Slot4);
- CurrentRecipe.put(5, Slot5);
- CurrentRecipe.put(6, Slot6);
- CurrentRecipe.put(7, Slot7);
- CurrentRecipe.put(8, Slot8);
- CurrentRecipe.put(9, Slot9);
- }
- }, 1L);
- if (e.getInventory().getItem(24) != InvalidRecipe) {
- e.getInventory().setItem(24, InvalidRecipe);
- }
- Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
- public void run() {
- for (int i = 0; i < Recipes.size(); i++) {
- HashMap<Integer, ItemStack> Recipe = (HashMap<Integer, ItemStack>) Recipes.get(i);
- int matches = 0;
- for (i = 1; i <= 9; i++) {
- if (Recipe.get(i) == null) {
- if (CurrentRecipe.get(i) == null) {
- matches++;
- continue;
- }
- break;
- }
- if (CurrentRecipe.get(i) == null)
- break;
- if (!(Recipe.get(i).equals(CurrentRecipe.get(i))))
- break;
- matches++;
- }
- if (matches == 9) {
- e.getInventory().setItem(24, Recipe.get(10));
- e.setCancelled(false);
- break;
- }
- }
- e.setCancelled(false);
- }
- }, 2L);
- p.updateInventory();
- }
- if (e.getClickedInventory().equals(Forge)) {
- if (BlackTiles.contains(e.getSlot())) {
- e.setCancelled(true);
- return;
- }
- if (e.getSlot() == 24) {
- if (e.getCurrentItem().equals(InvalidRecipe)) {
- e.setCancelled(true);
- return;
- }
- for (int i : NotBlackTiles) {
- if (i != 24) {
- e.getInventory().setItem(i, null);
- }
- }
- p.getWorld().playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 10, (float) 0.5);
- return;
- }
- return;
- }
- }
- @SuppressWarnings("serial")
- public void createStick() {
- JustAStick = new ItemStack(Material.STICK);
- meta = JustAStick.getItemMeta();
- meta.setDisplayName(ChatColor.GREEN + "Just a Stick");
- lore.clear();
- lore.add(ChatColor.YELLOW + "Does nothing");
- meta.setLore(lore);
- JustAStick.setItemMeta(meta);
- HashMap<Integer, ItemStack> StickRecipe1 = new HashMap<Integer, ItemStack>() {
- {
- item = new ItemStack(Material.STICK);
- item.setItemMeta(null);
- put(1, item);
- put(2, null);
- put(3, null);
- put(4, null);
- put(5, null);
- put(6, null);
- put(7, null);
- put(8, null);
- put(9, null);
- put(10, JustAStick);
- }
- };
- Recipes.add(StickRecipe1);
- HashMap<Integer, ItemStack> StickRecipe2 = new HashMap<Integer, ItemStack>() {
- {
- item = new ItemStack(Material.STICK);
- item.setItemMeta(null);
- put(2, item);
- put(1, null);
- put(3, null);
- put(4, null);
- put(5, null);
- put(6, null);
- put(7, null);
- put(8, null);
- put(9, null);
- put(10, JustAStick);
- }
- };
- Recipes.add(StickRecipe2);
- HashMap<Integer, ItemStack> StickRecipe3 = new HashMap<Integer, ItemStack>() {
- {
- item = new ItemStack(Material.STICK);
- item.setItemMeta(null);
- put(3, item);
- put(2, null);
- put(1, null);
- put(4, null);
- put(5, null);
- put(6, null);
- put(7, null);
- put(8, null);
- put(9, null);
- put(10, JustAStick);
- }
- };
- Recipes.add(StickRecipe3);
- HashMap<Integer, ItemStack> StickRecipe4 = new HashMap<Integer, ItemStack>() {
- private static final long serialVersionUID = -8987080176816314175L;
- {
- item = new ItemStack(Material.STICK);
- item.setItemMeta(null);
- put(4, item);
- put(2, null);
- put(3, null);
- put(1, null);
- put(5, null);
- put(6, null);
- put(7, null);
- put(8, null);
- put(9, null);
- put(10, JustAStick);
- }
- };
- Recipes.add(StickRecipe4);
- HashMap<Integer, ItemStack> StickRecipe5 = new HashMap<Integer, ItemStack>() {
- private static final long serialVersionUID = -8987080176816314175L;
- {
- item = new ItemStack(Material.STICK);
- item.setItemMeta(null);
- put(5, item);
- put(2, null);
- put(3, null);
- put(1, null);
- put(4, null);
- put(6, null);
- put(7, null);
- put(8, null);
- put(9, null);
- put(10, JustAStick);
- }
- };
- Recipes.add(StickRecipe5);
- HashMap<Integer, ItemStack> StickRecipe6 = new HashMap<Integer, ItemStack>() {
- {
- item = new ItemStack(Material.STICK);
- item.setItemMeta(null);
- put(6, item);
- put(2, null);
- put(3, null);
- put(4, null);
- put(5, null);
- put(1, null);
- put(7, null);
- put(8, null);
- put(9, null);
- put(10, JustAStick);
- }
- };
- Recipes.add(StickRecipe6);
- HashMap<Integer, ItemStack> StickRecipe7 = new HashMap<Integer, ItemStack>() {
- {
- item = new ItemStack(Material.STICK);
- item.setItemMeta(null);
- put(7, item);
- put(2, null);
- put(3, null);
- put(4, null);
- put(5, null);
- put(6, null);
- put(1, null);
- put(8, null);
- put(9, null);
- put(10, JustAStick);
- }
- };
- Recipes.add(StickRecipe7);
- HashMap<Integer, ItemStack> StickRecipe8 = new HashMap<Integer, ItemStack>() {
- {
- item = new ItemStack(Material.STICK);
- item.setItemMeta(null);
- put(8, item);
- put(2, null);
- put(3, null);
- put(4, null);
- put(5, null);
- put(6, null);
- put(7, null);
- put(1, null);
- put(9, null);
- put(10, JustAStick);
- }
- };
- Recipes.add(StickRecipe8);
- HashMap<Integer, ItemStack> StickRecipe9 = new HashMap<Integer, ItemStack>() {
- {
- item = new ItemStack(Material.STICK);
- item.setItemMeta(null);
- put(1, item);
- put(2, null);
- put(3, null);
- put(4, null);
- put(5, null);
- put(6, null);
- put(7, null);
- put(8, null);
- put(9, null);
- put(10, JustAStick);
- }
- };
- Recipes.add(StickRecipe9);
- }
- public void createInvalidRecipe() {
- InvalidRecipe = new ItemStack(Material.BARRIER);
- meta = InvalidRecipe.getItemMeta();
- meta.setDisplayName(ChatColor.RED + "Invalid Recipe");
- InvalidRecipe.setItemMeta(meta);
- }
- public void createStuff() {
- createStick();
- createInvalidRecipe();
- NotBlackTiles.add(10);
- NotBlackTiles.add(11);
- NotBlackTiles.add(12);
- NotBlackTiles.add(19);
- NotBlackTiles.add(20);
- NotBlackTiles.add(21);
- NotBlackTiles.add(24);
- NotBlackTiles.add(28);
- NotBlackTiles.add(29);
- NotBlackTiles.add(30);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment