125 lines
5.4 KiB
Java
125 lines
5.4 KiB
Java
package eu.univento.woolget.listeners;
|
|
|
|
|
|
import eu.univento.core.api.player.CustomPlayer;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.Listener;
|
|
import org.bukkit.event.block.Action;
|
|
import org.bukkit.event.inventory.InventoryType;
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
import org.bukkit.inventory.Inventory;
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.Random;
|
|
|
|
/**
|
|
* @author joethei
|
|
* @version 0.1
|
|
*/
|
|
public class ChestManager implements Listener {
|
|
|
|
private HashMap<Location, Inventory> chests = new HashMap<>();
|
|
private static ArrayList<ItemStack> normalChest = new ArrayList<>();
|
|
private static ArrayList<ItemStack> rareChest = new ArrayList<>();
|
|
private static ArrayList<ItemStack> epicChest = new ArrayList<>();
|
|
private static ArrayList<ItemStack> incredibleChest = new ArrayList<>();
|
|
|
|
public static void fillLists() {
|
|
//fillng normal chest items
|
|
normalChest.add(new ItemStack(Material.LEATHER_BOOTS));
|
|
normalChest.add(new ItemStack(Material.LEATHER_CHESTPLATE));
|
|
normalChest.add(new ItemStack(Material.WOOD_SWORD));
|
|
normalChest.add(new ItemStack(Material.LEATHER_BOOTS));
|
|
normalChest.add(new ItemStack(Material.LEATHER_HELMET));
|
|
normalChest.add(new ItemStack(Material.WHEAT));
|
|
normalChest.add(new ItemStack(Material.CHAINMAIL_BOOTS));
|
|
normalChest.add(new ItemStack(Material.STONE_AXE));
|
|
normalChest.add(new ItemStack(Material.CHAINMAIL_HELMET));
|
|
normalChest.add(new ItemStack(Material.WOOD_AXE));
|
|
normalChest.add(new ItemStack(Material.MELON));
|
|
normalChest.add(new ItemStack(Material.PORK));
|
|
normalChest.add(new ItemStack(Material.ARROW));
|
|
normalChest.add(new ItemStack(Material.APPLE));
|
|
normalChest.add(new ItemStack(Material.BREAD));
|
|
normalChest.add(new ItemStack(Material.SNOW_BALL));
|
|
normalChest.add(new ItemStack(Material.GOLD_HELMET));
|
|
normalChest.add(new ItemStack(Material.GOLD_BOOTS));
|
|
normalChest.add(new ItemStack(Material.GOLD_SWORD));
|
|
normalChest.add(new ItemStack(Material.RAW_BEEF));
|
|
normalChest.add(new ItemStack(Material.RAW_CHICKEN));
|
|
|
|
//filling rare chests
|
|
rareChest.add(new ItemStack(Material.BOW));
|
|
rareChest.add(new ItemStack(Material.IRON_AXE));
|
|
rareChest.add(new ItemStack(Material.GRILLED_PORK));
|
|
rareChest.add(new ItemStack(Material.CAKE));
|
|
rareChest.add(new ItemStack(Material.COOKED_BEEF));
|
|
rareChest.add(new ItemStack(Material.STONE_SWORD));
|
|
rareChest.add(new ItemStack(Material.FLINT_AND_STEEL));
|
|
rareChest.add(new ItemStack(Material.FISHING_ROD));
|
|
rareChest.add(new ItemStack(Material.COOKED_CHICKEN));
|
|
rareChest.add(new ItemStack(Material.IRON_HELMET));
|
|
rareChest.add(new ItemStack(Material.IRON_BOOTS));
|
|
rareChest.add(new ItemStack(Material.CHAINMAIL_LEGGINGS));
|
|
rareChest.add(new ItemStack(Material.CHAINMAIL_CHESTPLATE));
|
|
rareChest.add(new ItemStack(Material.WEB));
|
|
rareChest.add(new ItemStack(Material.SHIELD));
|
|
rareChest.add(new ItemStack(Material.PUMPKIN_PIE));
|
|
rareChest.add(new ItemStack(Material.STICK));
|
|
rareChest.add(new ItemStack(Material.IRON_INGOT));
|
|
rareChest.add(new ItemStack(Material.GOLD_LEGGINGS));
|
|
rareChest.add(new ItemStack(Material.GOLD_CHESTPLATE));
|
|
|
|
//filling epic chests
|
|
epicChest.add(new ItemStack(Material.IRON_CHESTPLATE));
|
|
epicChest.add(new ItemStack(Material.IRON_LEGGINGS));
|
|
epicChest.add(new ItemStack(Material.IRON_SWORD));
|
|
epicChest.add(new ItemStack(Material.GOLDEN_APPLE));
|
|
epicChest.add(new ItemStack(Material.DIAMOND));
|
|
epicChest.add(new ItemStack(Material.WOOD));
|
|
epicChest.add(new ItemStack(Material.DIAMOND_AXE));
|
|
|
|
//filling incredible chests
|
|
incredibleChest.add(new ItemStack(Material.DIAMOND_SWORD));
|
|
incredibleChest.add(new ItemStack(Material.DIAMOND_CHESTPLATE));
|
|
}
|
|
|
|
@EventHandler
|
|
public void onInteract(PlayerInteractEvent e) {
|
|
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer());
|
|
if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
|
if(e.getClickedBlock().getType() == Material.CHEST) {
|
|
e.setCancelled(true);
|
|
if(chests.containsKey(e.getClickedBlock().getLocation())) {
|
|
p.openInventory(chests.get(e.getClickedBlock().getLocation()));
|
|
}else{
|
|
Random random = new Random();
|
|
float r = random.nextFloat();
|
|
|
|
ArrayList<ItemStack> list = new ArrayList<>();
|
|
if(r == 0.5F) list = normalChest;
|
|
if(r == 0.3F) list = rareChest;
|
|
if(r == 0.1F) list = epicChest;
|
|
if(r == 0.1F) list = incredibleChest;
|
|
|
|
Inventory inv = Bukkit.createInventory(null, InventoryType.CHEST);
|
|
|
|
for(int i = 0; i <= 1; i++) {
|
|
int slot = new Random().nextInt(27);
|
|
int item = new Random().nextInt(list.size());
|
|
|
|
inv.setItem(slot, list.get(item));
|
|
|
|
}
|
|
chests.put(e.getClickedBlock().getLocation(), inv);
|
|
p.openInventory(inv);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |