下面列出了org.bukkit.Material#PAPER 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@SuppressWarnings("deprecation")
@EventHandler
public void onBandageUse(PlayerInteractEvent e) {
Player p = e.getPlayer();
Boolean active = GameManager.getInstance().isPlayerActive(p);
if (!active) {
return;
}
if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (e.getPlayer().getItemInHand().getType() == Material.PAPER) {
e.getPlayer().getInventory().removeItem(new ItemStack(Material.PAPER, 1));
double newhealth = e.getPlayer().getHealth() + 10;
if((newhealth > 20.0) || (newhealth < 0 )) { newhealth = 20.0; }
e.getPlayer().setHealth(newhealth);
e.getPlayer().sendMessage(ChatColor.GREEN + "You used a bandage and got 5 hearts.");
}
}
}
private String findPath(Inventory inventory, int slot) {
ItemStack item = inventory.getItem(slot);
if (item == null) {
return null;
}
StringBuilder sb = new StringBuilder();
sb.append(stripFormatting(item.getItemMeta().getDisplayName()));
int row = slot / 9;
int col = slot % 9;
while (col >= 1) {
ItemStack parent = inventory.getItem(getIndex(row, col));
if(parent != null && parent.getType() != Material.PAPER) {
col--;
parent = inventory.getItem(getIndex(row, col));
}
else if(parent == null || parent.getType() != Material.PAPER) {
row--;
parent = inventory.getItem(getIndex(row, col));
}
else if (parent != null && parent.getType() == Material.PAPER) {
sb.insert(0, stripFormatting(parent.getItemMeta().getDisplayName()) + ".");
col--;
}
}
return sb.toString();
}
/**
* Create an AnvilGUI and open it for the player.
*
* @param plugin A {@link org.bukkit.plugin.java.JavaPlugin} instance
* @param player The {@link Player} to open the inventory for
* @param inventoryTitle What to have the text already set to
* @param itemText The name of the item in the first slot of the anvilGui
* @param insert The material of the item in the first slot of the anvilGUI
* @param preventClose Whether to prevent the inventory from closing
* @param closeListener A {@link Consumer} when the inventory closes
* @param completeFunction A {@link BiFunction} that is called when the player clicks the {@link Slot#OUTPUT} slot
*/
private AnvilGUI(
Plugin plugin,
Player player,
String inventoryTitle,
String itemText,
ItemStack insert,
boolean preventClose,
Consumer<Player> closeListener,
BiFunction<Player, String, Response> completeFunction
) {
this.plugin = plugin;
this.player = player;
this.inventoryTitle = inventoryTitle;
this.insert = insert;
this.preventClose = preventClose;
this.closeListener = closeListener;
this.completeFunction = completeFunction;
if(itemText != null) {
if(insert == null) {
this.insert = new ItemStack(Material.PAPER);
}
ItemMeta paperMeta = this.insert.getItemMeta();
paperMeta.setDisplayName(itemText);
this.insert.setItemMeta(paperMeta);
}
openInventory();
}
public MainMenuWindow(Hawk hawk, Player player) {
super(hawk, player, 1, ChatColor.GOLD + "Hawk Anticheat");
HawkPlayer pp = hawk.getHawkPlayer(player);
/*elements[0] = new Element(Material.SAND, "dummy") {
@Override
public void doAction(Player p, Hawk hawk) {
Window testWindow = new TestWindow(hawk, p);
hawk.getGuiManager().sendWindow(p, testWindow);
}
};*/
elements[4] = new Element(Material.WORKBENCH, "Toggle Checks") {
@Override
public void doAction(Player p, Hawk hawk) {
Window checks = new ToggleChecksWindow(hawk, p);
hawk.getGuiManager().sendWindow(p, checks);
}
};
elements[5] = new Element(Material.PAPER, "Reload Configuration") {
@Override
public void doAction(Player p, Hawk hawk) {
Bukkit.dispatchCommand(p, "hawk reload");
}
};
ItemStack notify = new ItemStack(Material.INK_SACK);
notify.setDurability((short) (pp.canReceiveAlerts() ? 10 : 8));
ItemMeta notifyName = notify.getItemMeta();
notifyName.setDisplayName(pp.canReceiveAlerts() ? "Notifications: ON" : "Notifications: OFF");
notify.setItemMeta(notifyName);
elements[3] = new Element(notify) {
@Override
public void doAction(Player p, Hawk hawk) {
pp.setReceiveNotifications(!pp.canReceiveAlerts());
Window mainMenu = new MainMenuWindow(hawk, p);
hawk.getGuiManager().sendWindow(p, mainMenu);
}
};
elements[8] = new Element(Material.WOOD_DOOR, "Exit GUI") {
@Override
public void doAction(Player p, Hawk hawk) {
p.closeInventory();
}
};
prepareInventory();
}
private Element nullElement() {
return new BasicElement(new ItemStack(Material.PAPER), "nullElement");
}
private int addSection(ArrayList<ItemStack> menuList, ConfigurationSection sec, int row, int col, YmlConfiguration config, String filename) {
if (isBlackListed(filename, sec.getCurrentPath())) {
return row;
}
ItemStack item = new ItemStack(Material.PAPER, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("\u00a77\u00a7o" + sec.getName());
String comment = config.getComment(sec.getCurrentPath());
if (comment != null) {
meta.setLore(wordWrap(comment.replaceAll("\n", " "), 20, 20));
}
item.setItemMeta(meta);
int index = getIndex(row, col);
ensureCapacity(menuList, index);
menuList.set(index, item);
int colbase = ++col;
boolean lastWasSection = true;
for (String key : sec.getKeys(false)) {
index = getIndex(row, col);
ensureCapacity(menuList, index);
if (sec.isConfigurationSection(key)) {
if (!lastWasSection && col != colbase) {
row++;
col = colbase;
}
row = addSection(menuList, sec.getConfigurationSection(key), row, col, config, filename);
col = colbase;
lastWasSection = true;
} else {
String path = sec.getCurrentPath() + "." + key;
if (isBlackListed(filename, path)) {
continue; // Skip
}
boolean readonly = isReadonly(filename, path);
item = null;
if (sec.isBoolean(key)) {
item = factory.createBooleanItem(sec.getBoolean(key), path, config, readonly);
} else if (sec.isInt(key)) {
item = factory.createIntegerItem(sec.getInt(key), path, config, readonly);
} else {
item = factory.createStringItem(sec.getString(key, ""), path, config, readonly);
}
if (item != null) {
if (readonly) {
ItemMeta itemMeta = item.getItemMeta();
List<String> lore = itemMeta.getLore();
lore.set(0, READONLY + lore.get(0) + tr("\u00a77 (readonly)"));
itemMeta.setLore(lore);
item.setItemMeta(itemMeta);
}
menuList.set(index, item);
col++;
lastWasSection = false;
}
}
if (col >= 9) {
row++;
col = colbase;
}
}
return col != colbase ? row+1 : row;
}
/**
* This loads the control panel from the controlpanel.yml file
*/
public static void loadControlPanel() {
ASkyBlock plugin = ASkyBlock.getPlugin();
// Map of known panel contents by name
panels.clear();
// Map of panel inventories by name
controlPanel.clear();
cpFile = Util.loadYamlFile("controlpanel.yml");
ConfigurationSection controlPanels = cpFile.getRoot();
if (controlPanels == null) {
plugin.getLogger().severe("Controlpanel.yml is corrupted! Delete so it can be regenerated or fix!");
return;
}
// Go through the yml file and create inventories and panel maps
for (String panel : controlPanels.getKeys(false)) {
// plugin.getLogger().info("DEBUG: Panel " + panel);
ConfigurationSection panelConf = cpFile.getConfigurationSection(panel);
if (panelConf != null) {
// New panel map
HashMap<Integer, CPItem> cp = new HashMap<Integer, CPItem>();
String panelName = ChatColor.translateAlternateColorCodes('&', panelConf.getString("panelname", "Commands"));
if (panel.equalsIgnoreCase("default")) {
defaultPanelName = panelName;
}
ConfigurationSection buttons = cpFile.getConfigurationSection(panel + ".buttons");
if (buttons != null) {
// Get how many buttons can be in the CP
int size = buttons.getKeys(false).size() + 8;
size -= (size % 9);
// Add inventory to map of inventories
controlPanel.put(panelName, Bukkit.createInventory(null, size, panelName));
// Run through buttons
int slot = 0;
for (String item : buttons.getKeys(false)) {
try {
String m = buttons.getString(item + ".material", "BOOK");
// Split off damage
String[] icon = m.split(":");
Material material = Material.matchMaterial(icon[0]);
if (material == null) {
material = Material.PAPER;
plugin.getLogger().severe("Error in controlpanel.yml " + icon[0] + " is an unknown material, using paper.");
}
String description = ChatColor.translateAlternateColorCodes('&',buttons.getString(item + ".description", ""));
String command = buttons.getString(item + ".command", "").replace("[island]", Settings.ISLANDCOMMAND);
String nextSection = buttons.getString(item + ".nextsection", "");
ItemStack i = new ItemStack(material);
if (icon.length == 2) {
i.setDurability(Short.parseShort(icon[1]));
}
CPItem cpItem = new CPItem(i, description, command, nextSection);
cp.put(slot, cpItem);
controlPanel.get(panelName).setItem(slot, cpItem.getItem());
slot++;
} catch (Exception e) {
plugin.getLogger().warning("Problem loading control panel " + panel + " item #" + slot);
plugin.getLogger().warning(e.getMessage());
e.printStackTrace();
}
}
// Add overall control panel
panels.put(panelName, cp);
}
}
}
}