Last active
December 21, 2016 23:06
-
-
Save ColeMundus/91e6c4ce27a7e3719991ced6a2b315a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Crates; | |
import java.util.ArrayList; | |
import java.util.List; | |
import org.bukkit.Bukkit; | |
import org.bukkit.Material; | |
import org.bukkit.command.Command; | |
import org.bukkit.command.CommandSender; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.block.Action; | |
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.plugin.java.JavaPlugin; | |
import net.md_5.bungee.api.ChatColor; | |
public class main extends JavaPlugin implements Listener{ | |
public void onEnable(){ | |
getServer().getPluginManager().registerEvents(this, this); | |
} | |
@EventHandler | |
private ItemStack getkey() { | |
ItemStack item = new ItemStack(Material.TRIPWIRE_HOOK, 1); | |
ItemMeta meta = item.getItemMeta(); | |
meta.setDisplayName("Legendary Key");{ | |
List<String> lore = new ArrayList<String>(); | |
lore.add("Legendary Key"); | |
meta.setLore(lore); | |
} | |
item.setItemMeta(meta); | |
return item; | |
} | |
static String[] itemIndex = new String[]{"BEACON","3","BOW","10","DIAMOND","0.1","DIAMOND_PICKAXE","5","EGG","20","DEAD_BUSH","20","PORK","5","STICK","20","TNT","16.9"}; //Item first, then odds of getting that item after it eg. "STICK","20" (20 is 20%) | |
int indexSize = 1000; //Size of index to create for random, higher number means more accurate random | |
@EventHandler | |
public static void splitItemIndex() { | |
int c = 0; | |
String[] itemsOfItemIndex = new String[]{}; | |
String[] constructedIndex = new String[]{}; | |
Float[] oddsOfItemIndex = new Float[]{}; | |
while (p < (itemIndex.length / 2)){ | |
if (c == 0){ | |
itemsOfItemIndex.push(itemIndex[0]); | |
oddsOfItemIndex.push(itemIndex[0]); | |
} | |
else { | |
int pO = c + c - 1; | |
oddsOfItemIndex.push(itemIndex[pO]); | |
itemsOfItemIndex.push(itemIndex[c + c]); | |
} | |
c = c++; | |
} | |
int c = 0; | |
while (p < itemsOfItemIndex.length){ | |
if (c == 0){ | |
constructedIndex.push(Math.ceil(oddsOfItemIndex[0] / 100)); | |
} | |
else{ | |
int i = 0; | |
while (i < Math.ceil(oddsOfItemIndex[c] / 100)) { | |
constructedIndex.push(itemsOfitemIndex[c]); | |
i = i++; | |
} | |
constructedIndex.push(oddsOfItemIndex[c] * (indexSize / Math.ceil(oddsOfItemIndex[c] / 100))); | |
} | |
c = c++; | |
} | |
} | |
@EventHandler | |
public void playerInteract(PlayerInteractEvent event){ | |
Player player = event.getPlayer(); // Get Player | |
if ((event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().equals(Material.CHEST) && event.getClickedBlock().getItemMeta().getLore().contains("KeyChest"))){ | |
if ((event.getPlayer().getItemInHand().getType().equals(Material.TRIPWIRE_HOOK))){ | |
if ((event.getPlayer().getItemInHand().getItemMeta().getLore().equals("Legendary Key"))){ | |
player.sendMessage(ChatColor.DARK_AQUA + "This is a Legendary key!" + ""); | |
Inventory spinnerInv = Bukkit.createInventory(null, 9, "Legendary Key Chest"); | |
public static void spinner(){ | |
int p = 0; | |
splitItemIndex(); | |
int spinnerLength = 30; //Times to run the spinner before it stops | |
while (p < spinnerLength ){ | |
spinner.setItem((p + 1), new ItemStack(Material.(itemsOfItemIndex[Math.random() * constructedIndex.length]))); | |
p = p++; | |
} | |
} | |
else if ((event.getPlayer().getItemInHand().getItemMeta().getLore().equals("Awesome Key"))){ | |
player.sendMessage(ChatColor.DARK_RED + "This is the wrong chest, use the Awesome chest!" + ""); | |
} | |
else{ | |
player.sendMessage(ChatColor.DARK_RED + "This is the wrong chest, use the Special chest!" + ""); | |
} | |
} | |
else{ | |
player.sendMessage(ChatColor.DARK_RED + "You must use a key to use this chest!" + ""); | |
} | |
} | |
} | |
@EventHandler | |
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { | |
Player player = event.getPlayer(); | |
if(cmd.getName().equalsIgnoreCase("givekey")){ | |
player.getInventory().addItem(getkey()); | |
} | |
return false; | |
} | |
public void onDisable(){ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment