Guest User

Untitled

a guest
Apr 5th, 2015
172
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.bizarreplatinum.AssassinsCreed;
  2.  
  3. import java.util.Map.Entry;
  4. import java.util.Random;
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.Material;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.event.EventHandler;
  9. import org.bukkit.event.Listener;
  10. import org.bukkit.event.block.Action;
  11. import org.bukkit.event.inventory.InventoryType;
  12. import org.bukkit.event.player.PlayerInteractEvent;
  13. import org.bukkit.inventory.Inventory;
  14. import org.bukkit.inventory.ItemStack;
  15. import org.bukkit.plugin.java.JavaPlugin;
  16.  
  17. public class Main extends JavaPlugin implements Listener {
  18.  
  19. private Random random;
  20. private Material[] items;
  21.  
  22. public void onEnable() {
  23.  
  24. getConfig().options().copyDefaults(true);
  25. saveDefaultConfig();
  26. this.random = new Random();
  27. this.items = new Material[100];
  28.  
  29. int index = 0;
  30. for(Entry<String, Object> entry : getConfig().getConfigurationSection("items").getValues(false).entrySet()) {
  31. for(int i = 0; i < Integer.valueOf(entry.getValue().toString()); i++){
  32. items[index++] = Material.valueOf(entry.getKey().toUpperCase());
  33. }
  34. }
  35.  
  36. Bukkit.getServer().getPluginManager().registerEvents(this, this);
  37. }
  38.  
  39. @EventHandler
  40. public void onInteract(PlayerInteractEvent e) {
  41.  
  42. e.getAction();
  43. Player player = e.getPlayer();
  44. Inventory acChest = Bukkit.getServer().createInventory(player, InventoryType.CHEST, "Chest");
  45.  
  46. if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && e.getClickedBlock().getType().equals(Material.CHEST)) {
  47. player.openInventory(acChest);
  48. acChest.addItem(new ItemStack(items[random.nextInt(items.length)]));
  49. e.getClickedBlock().setType(Material.AIR);
  50. }
  51.  
  52. }
  53.  
  54. }
RAW Paste Data