下面列出了org.bukkit.Material#BARRIER 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public Inventory getScenarioMainInventory(boolean editItem){
Inventory inv = Bukkit.createInventory(null,3*ROW, Lang.SCENARIO_GLOBAL_INVENTORY);
for (Scenario scenario : getActiveScenarios()) {
if (scenario.isCompatibleWithVersion()) {
inv.addItem(scenario.getScenarioItem());
}
}
if (editItem){
// add edit item
ItemStack edit = new ItemStack(Material.BARRIER);
ItemMeta itemMeta = edit.getItemMeta();
itemMeta.setDisplayName(Lang.SCENARIO_GLOBAL_ITEM_EDIT);
edit.setItemMeta(itemMeta);
inv.setItem(26,edit);
}
return inv;
}
private GameKit(String fnam, String nam, int pos, int pag, ItemStack ico, String lore) {
inventory = new ItemStack[41];
armor = new ItemStack[4];
icon = ico;
lIcon = new ItemStack(Material.BARRIER, 1);
name = nam;
filename = fnam;
position = pos;
page = pag;
lores.put(1, lore);
for (int x = 2; x < 17; x++) {
lores.put(x, " ");
}
lockedLore = "";
enabled = true;
requirePermission = false;
}
private void calculateSpawnLocations() {
spawningBarriers.clear();
for (Floor floor : game.getFloors()) {
Region region = floor.getRegion();
RegionIterator iterator = new RegionIterator(region);
while (iterator.hasNext()) {
BlockVector vector = iterator.next();
Location location = BukkitUtil.toLocation(game.getWorld(), vector);
Block block = location.getBlock();
if (block.getType() != Material.BARRIER) {
continue;
}
spawningBarriers.add(vector.add(0.5, 0.5, 0.5));
}
}
Collections.shuffle(spawningBarriers);
}
/**
* sync method which checks if the given duct should be visible or not for the given player and shows / hides the duct
*/
public void tickDuctSpawnAndDespawn(Duct duct, Player p) {
int renderDistance = playerSettingsService.getOrCreateSettingsConf(p).getRenderDistance();
if (duct.getBlockLoc().toLocation(duct.getWorld()).distance(p.getLocation()) <= renderDistance && (duct.obfuscatedWith() == null || duct.getBlockLoc().toBlock(duct.getWorld()).getType() == Material.BARRIER)) {
// spawn globalDuctManager if not there
duct.getDuctType().getBaseDuctType().getDuctManager().notifyDuctShown(duct, p);
} else {
// despawn globalDuctManager if there
duct.getDuctType().getBaseDuctType().getDuctManager().notifyDuctHidden(duct, p);
}
}
public void loadFromNBTTag(CompoundTag compoundTag, ItemService itemService) {
if (compoundTag.containsKey("obfuscatedWith")) {
obfuscatedWith = Bukkit.createBlockData(compoundTag.getString("obfuscatedWith"));
// replace barrier block with real obfuscation block
if (getBlockLoc().toBlock(getWorld()).getType() == Material.BARRIER) {
getBlockLoc().toBlock(getWorld()).setBlockData(obfuscatedWith);
}
}
}
@Override
public boolean doActionAndCancel(Civilian civilian, String actionString, ItemStack clickedItem) {
if (actionString.equals("view-item")) {
String key = clickedItem.getItemMeta().getLore().get(0);
Player player = Bukkit.getPlayer(civilian.getUuid());
String sortType = (String) MenuManager.getData(civilian.getUuid(), "sort");
HashMap<String, String> params = new HashMap<>();
String name = ChatColor.stripColor(key).toLowerCase();
CivItem civItem = ItemManager.getInstance().getItemType(name);
if (civItem != null) {
if (civItem.getItemType() == CivItem.ItemType.REGION) {
params.put("regionType", name);
params.put("showPrice", "true");
MenuManager.getInstance().openMenu(player, "region-type", params);
return true;
} else if (civItem.getItemType() == CivItem.ItemType.TOWN) {
params.put("townType", name);
params.put("showPrice", "true");
MenuManager.getInstance().openMenu(player, "town-type", params);
return true;
}
} else if (clickedItem.getType() == Material.BARRIER) {
return true;
}
if ("level".equals(sortType)) {
int level = Integer.parseInt(name);
params.put("level", "" + level);
params.put("sort", "level");
MenuManager.getInstance().openMenu(player, "shop", params);
return true;
} else if ("category".equals(sortType)) {
params.put("sort", "category");
params.put("parent", ChatColor.stripColor(key).toLowerCase());
MenuManager.getInstance().openMenu(player, "shop", params);
return true;
}
return true;
}
return super.doActionAndCancel(civilian, actionString, clickedItem);
}
/**
* Fix for Spigot's broken occluding method.
*/
public static boolean isReallyOccluding(Material material)
{
switch (ServerVersion.getActiveServerVersion()) {
case MC188:
case MC112:
return material != Material.BARRIER && material != Material.getMaterial("MOB_SPAWNER") && material.isOccluding();
case MC113:
case MC114:
case MC115:
return material != Material.BARRIER && material != Material.SPAWNER && material.isOccluding();
default:
throw new UnknownMinecraftVersion();
}
}
public ShrinkingBorderEvent(GameMap map, boolean b) {
this.gMap = map;
this.enabled = b;
File dataDirectory = SkyWarsReloaded.get().getDataFolder();
File mapDataDirectory = new File(dataDirectory, "mapsData");
if (!mapDataDirectory.exists() && !mapDataDirectory.mkdirs()) {
return;
}
File mapFile = new File(mapDataDirectory, gMap.getName() + ".yml");
if (mapFile.exists()) {
eventName = "ShrinkingBorderEvent";
slot = 9;
material = new ItemStack(Material.BARRIER, 1);
FileConfiguration fc = YamlConfiguration.loadConfiguration(mapFile);
this.min = fc.getInt("events." + eventName + ".minStart");
this.max = fc.getInt("events." + eventName + ".maxStart");
this.length = fc.getInt("events." + eventName + ".length");
this.chance = fc.getInt("events." + eventName + ".chance");
this.title = fc.getString("events." + eventName + ".title");
this.subtitle = fc.getString("events." + eventName + ".subtitle");
this.startMessage = fc.getString("events." + eventName + ".startMessage");
this.endMessage = fc.getString("events." + eventName + ".endMessage");
this.announceEvent = fc.getBoolean("events." + eventName + ".announceTimer");
this.repeatable = fc.getBoolean("events." + eventName + ".repeatable");
this.borderSize = fc.getInt("events." + eventName + ".startingBorderSize");
this.delay = fc.getInt("events." + eventName + ".shrinkRepeatDelay");
}
}
private void displayItem(ChestMenu menu, PlayerProfile profile, Player p, Object item, ItemStack output, RecipeType recipeType, ItemStack[] recipe, RecipeChoiceTask task) {
addBackButton(menu, 0, p, profile);
MenuClickHandler clickHandler = (pl, slot, itemstack, action) -> {
try {
if (itemstack != null && itemstack.getType() != Material.BARRIER) {
displayItem(profile, itemstack, 0, true);
}
}
catch (Exception | LinkageError x) {
printErrorMessage(pl, x);
}
return false;
};
boolean isSlimefunRecipe = item instanceof SlimefunItem;
for (int i = 0; i < 9; i++) {
ItemStack recipeItem = getDisplayItem(p, isSlimefunRecipe, recipe[i]);
menu.addItem(recipeSlots[i], recipeItem, clickHandler);
if (recipeItem != null && item instanceof MultiBlockMachine) {
for (Tag<Material> tag : MultiBlock.getSupportedTags()) {
if (tag.isTagged(recipeItem.getType())) {
task.add(recipeSlots[i], tag);
break;
}
}
}
}
menu.addItem(10, recipeType.getItem(p), ChestMenuUtils.getEmptyClickHandler());
menu.addItem(16, output, ChestMenuUtils.getEmptyClickHandler());
}
private static ItemStack getDisplayItem(Player p, boolean isSlimefunRecipe, ItemStack item) {
if (isSlimefunRecipe) {
SlimefunItem slimefunItem = SlimefunItem.getByItem(item);
if (slimefunItem == null) {
return item;
}
String lore = Slimefun.hasPermission(p, slimefunItem, false) ? "&fNeeds to be unlocked elsewhere" : "&fNo Permission";
return Slimefun.hasUnlocked(p, slimefunItem, false) ? item : new CustomItem(Material.BARRIER, ItemUtils.getItemName(item), "&4&l" + SlimefunPlugin.getLocalization().getMessage(p, "guide.locked"), "", lore);
}
else {
return item;
}
}
private void showMinecraftRecipe(Recipe[] recipes, int index, ItemStack item, PlayerProfile profile, Player p, boolean addToHistory) {
Recipe recipe = recipes[index];
ItemStack[] recipeItems = new ItemStack[9];
RecipeType recipeType = RecipeType.NULL;
ItemStack result = null;
Optional<MinecraftRecipe<? super Recipe>> optional = MinecraftRecipe.of(recipe);
RecipeChoiceTask task = new RecipeChoiceTask();
if (optional.isPresent()) {
MinecraftRecipe<?> mcRecipe = optional.get();
RecipeChoice[] choices = SlimefunPlugin.getMinecraftRecipeService().getRecipeShape(recipe);
if (choices.length == 1 && choices[0] instanceof MaterialChoice) {
recipeItems[4] = new ItemStack(((MaterialChoice) choices[0]).getChoices().get(0));
if (((MaterialChoice) choices[0]).getChoices().size() > 1) {
task.add(recipeSlots[4], (MaterialChoice) choices[0]);
}
}
else {
for (int i = 0; i < choices.length; i++) {
if (choices[i] instanceof MaterialChoice) {
recipeItems[i] = new ItemStack(((MaterialChoice) choices[i]).getChoices().get(0));
if (((MaterialChoice) choices[i]).getChoices().size() > 1) {
task.add(recipeSlots[i], (MaterialChoice) choices[i]);
}
}
}
}
recipeType = new RecipeType(mcRecipe);
result = recipe.getResult();
}
else {
recipeItems = new ItemStack[] { null, null, null, null, new CustomItem(Material.BARRIER, "&4We are somehow unable to show you this Recipe :/"), null, null, null, null };
}
ChestMenu menu = create(p);
if (addToHistory) {
profile.getGuideHistory().add(item, index);
}
displayItem(menu, profile, p, item, result, recipeType, recipeItems, task);
if (recipes.length > 1) {
for (int i = 27; i < 36; i++) {
menu.addItem(i, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
}
menu.addItem(28, ChestMenuUtils.getPreviousButton(p, index + 1, recipes.length), (pl, slot, action, stack) -> {
if (index > 0) {
showMinecraftRecipe(recipes, index - 1, item, profile, p, true);
}
return false;
});
menu.addItem(34, ChestMenuUtils.getNextButton(p, index + 1, recipes.length), (pl, slot, action, stack) -> {
if (index < recipes.length - 1) {
showMinecraftRecipe(recipes, index + 1, item, profile, p, true);
}
return false;
});
}
menu.open(p);
if (!task.isEmpty()) {
task.start(menu.toInventory());
}
}