本文整理汇总了Java中org.bukkit.block.Block.hasMetadata方法的典型用法代码示例。如果您正苦于以下问题:Java Block.hasMetadata方法的具体用法?Java Block.hasMetadata怎么用?Java Block.hasMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.block.Block
的用法示例。
在下文中一共展示了Block.hasMetadata方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onDisable
import org.bukkit.block.Block; //导入方法依赖的package包/类
public void onDisable()
{
PluginDescriptionFile pdfFile = getDescription();
Logger logger = getLogger();
getServer().getScheduler().cancelTasks(this);
getServer().resetRecipes();
usingPlayers = new ArrayList<Player>();
//Avoid WorkbenchShare glitch
for(Player p : Bukkit.getOnlinePlayers())
{
if (p.hasMetadata("shared_workbench"))
{
Block workbench = (p.getMetadata("shared_workbench").get(0).value() instanceof Block) ? (Block)p.getMetadata("shared_workbench").get(0).value() : null;
if(workbench != null && workbench.getType() == Material.WORKBENCH)
{
if (workbench.hasMetadata("shared_players"))
workbench.removeMetadata("shared_players", Survival.instance);
else
p.getOpenInventory().getTopInventory().clear();
p.closeInventory();
}
p.removeMetadata("shared_workbench", Survival.instance);
}
}
logger.info(pdfFile.getName() + " has been disabled.");
}
示例2: onInventoryClose
import org.bukkit.block.Block; //导入方法依赖的package包/类
@EventHandler
public void onInventoryClose(InventoryCloseEvent e)
{
if (!(e.getPlayer() instanceof Player))
return;
final Player p = (Player) e.getPlayer();
if (!p.hasMetadata("shared_workbench"))
return;
if (e.getInventory().getType() == InventoryType.WORKBENCH)
{
// Workaround to get the accessed WorkBench
final Block workbench = p.getTargetBlock((Set<Material>) null, 8);
if (!workbench.hasMetadata("shared_players") || workbench.getType() != Material.WORKBENCH)
{
if (p.getOpenInventory().getTopInventory() != null)
p.getOpenInventory().getTopInventory().clear();
p.removeMetadata("shared_workbench", Survival.instance);
return;
}
@SuppressWarnings("unchecked")
List<UUID> list = (workbench.getMetadata("shared_players").get(0).value() instanceof List<?>) ? (List<UUID>)workbench.getMetadata("shared_players").get(0).value() : new ArrayList<UUID>();
list.remove(p.getUniqueId());
if (list.isEmpty())
workbench.removeMetadata("shared_players", Survival.instance);
else
{
e.getInventory().clear();
workbench.setMetadata("shared_players", new FixedMetadataValue(Survival.instance, list));
}
}
}
示例3: onPlayerQuit
import org.bukkit.block.Block; //导入方法依赖的package包/类
@EventHandler
public void onPlayerQuit(PlayerQuitEvent e)
{
if (!(e.getPlayer() instanceof Player))
return;
final Player p = (Player) e.getPlayer();
if (!p.hasMetadata("shared_workbench"))
return;
Block workbench = (p.getMetadata("shared_workbench").get(0).value() instanceof Block) ? (Block)p.getMetadata("shared_workbench").get(0).value() : null;
if (workbench != null && workbench.hasMetadata("shared_players") && workbench.getType() == Material.WORKBENCH)
{
@SuppressWarnings("unchecked")
List<UUID> list = (workbench.getMetadata("shared_players").get(0).value() instanceof List<?>) ? (List<UUID>)workbench.getMetadata("shared_players").get(0).value() : new ArrayList<UUID>();
list.remove(p.getUniqueId());
if (list.isEmpty())
workbench.removeMetadata("shared_players", Survival.instance);
else
workbench.setMetadata("shared_players", new FixedMetadataValue(Survival.instance, list));
}
p.removeMetadata("shared_workbench", Survival.instance);
}
示例4: onPlayerInteract
import org.bukkit.block.Block; //导入方法依赖的package包/类
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Gamer g = Gamer.get(event.getPlayer());
if (event.getAction() != Action.PHYSICAL)
return;
Block b = event.getClickedBlock();
if (!b.hasMetadata("Mine"))
return;
Mine mine = Mine.getList().get(b.getMetadata("Mine").get(0).asInt());
Team playerTeam = Nexus.getRotary().getCurrentMap().getTeam(g);
Team targetTeam = Nexus.getRotary().getCurrentMap().getTeam(mine.getGamer());
if (playerTeam == targetTeam)
return;
mine.setIgnited(true);
TNTPrimed e = (TNTPrimed) event.getPlayer().getWorld().spawnEntity(event.getPlayer().getEyeLocation(), EntityType.PRIMED_TNT);
e.setFuseTicks(10);
e.setYield(2.7F);
e.setMetadata("Player", new FixedMetadataValue(Nexus.getPlugin(), mine.getGamer().getName()));
e.setMetadata("Cause", new FixedMetadataValue(Nexus.getPlugin(), CustomDamageCause.TNT_MINE.name()));
event.getClickedBlock().setType(Material.AIR);
}
示例5: onBreakWorkbench
import org.bukkit.block.Block; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void onBreakWorkbench(BlockBreakEvent e)
{
if(e.isCancelled()) return;
Block workbench = e.getBlock();
if (!workbench.hasMetadata("shared_players") || workbench.getType() != Material.WORKBENCH)
return;
@SuppressWarnings("unchecked")
List<UUID> list = (workbench.getMetadata("shared_players").get(0).value() instanceof List<?>) ? (List<UUID>)workbench.getMetadata("shared_players").get(0).value() : new ArrayList<UUID>();
Iterator<UUID> iterator = list.iterator();
Inventory sharedInventory = Bukkit.createInventory(null, InventoryType.WORKBENCH);
while (iterator.hasNext())
{
UUID next = iterator.next();
iterator.remove();
final Player idPlayer = Bukkit.getPlayer(next);
if (idPlayer != null)
{
idPlayer.removeMetadata("shared_inv", Survival.instance);
if(idPlayer.isOnline())
{
final Inventory open = idPlayer.getOpenInventory().getTopInventory();
if (open != null && open.getType() == InventoryType.WORKBENCH)
{
sharedInventory.setContents(open.getContents());
open.clear();
idPlayer.closeInventory();
}
}
}
}
for(int i = 1; i < sharedInventory.getSize(); i++)
{
ItemStack item = sharedInventory.getItem(i);
if(item != null)
workbench.getWorld().dropItem(workbench.getLocation(), item);
}
workbench.removeMetadata("shared_players", Survival.instance);
}
示例6: removeTree
import org.bukkit.block.Block; //导入方法依赖的package包/类
private void removeTree(Block block, boolean nearwood, int range)
{
if (range < 0 || block.hasMetadata("placed"))
return;
this.plugin.getServer().getScheduler().runTask(this.plugin, () ->
{
if (block.getType() == Material.LEAVES || block.getType() == Material.LEAVES_2)
{
LeavesDecayEvent event = new LeavesDecayEvent(block);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled())
return;
block.breakNaturally();
if (10 > new Random().nextInt(100))
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, Material.LEAVES);
}
if (block.getType() == Material.LOG || block.getType() == Material.LOG_2)
{
for (ItemStack item : block.getDrops())
block.getWorld().dropItemNaturally(block.getLocation(), item);
block.setType(Material.AIR);
}
for (int y = -1; y <= 1; y++)
{
for (int z = -1; z <= 1; z++)
{
for (int x = -1; x <= 1; x++)
{
Block block1 = block.getRelative(x, y, z);
if (block != null)
{
if (block1.getType() == Material.LOG || block1.getType() == Material.LOG_2)
{
removeTree(block1, nearwood, range - ((z == 0 && x == 0 || nearwood) ? 0 : 1));
}
else if (block1.getType() == Material.LEAVES || block1.getType() == Material.LEAVES_2)
{
int finalZ = z;
int finalX = x;
this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, () ->
{
if (!this.isNearWood(block1, 2))
this.plugin.getServer().getScheduler().runTask(this.plugin, () -> removeTree(block1, false, nearwood ? 4 : (range - ((finalZ == 0 && finalX == 0) ? 0 : 1))));
});
}
}
}
}
}
});
}