本文整理汇总了Java中org.bukkit.event.block.BlockBreakEvent.getPlayer方法的典型用法代码示例。如果您正苦于以下问题:Java BlockBreakEvent.getPlayer方法的具体用法?Java BlockBreakEvent.getPlayer怎么用?Java BlockBreakEvent.getPlayer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.event.block.BlockBreakEvent
的用法示例。
在下文中一共展示了BlockBreakEvent.getPlayer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBlockBreak
import org.bukkit.event.block.BlockBreakEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
if (isDeathSign(block)) {
BlockState state = block.getState();
Sign sign = (Sign) state;
ItemStack stack = new ItemStack(Material.SIGN, 1);
ItemMeta meta = stack.getItemMeta();
meta.setDisplayName(DEATH_SIGN_ITEM_NAME);
meta.setLore(Arrays.asList(sign.getLines()));
stack.setItemMeta(meta);
Player player = event.getPlayer();
World world = player.getWorld();
if (player.getGameMode() != GameMode.CREATIVE && world.isGameRule("doTileDrops")) {
world.dropItemNaturally(block.getLocation(), stack);
}
// Manually handle the dropping
event.setCancelled(true);
block.setType(Material.AIR);
state.update();
}
}
示例2: onBlockBreak
import org.bukkit.event.block.BlockBreakEvent; //导入方法依赖的package包/类
/**
* So far specifically handles these cases:
*
* 1) Block broken is tracked
* 2) Block breaks by not-players
* 3) Block breaks by players
* 4) Indirect block breaks -- destroying block supporting a crop or collapsible tree, or under mushrooms
* 5) Indirect block break of cocoa bearing logs
* 6) Block broken had mushroom on top and cocoa on the sides
*
* @param e The event
*/
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent e) {
Block block = e.getBlock();
Player player = e.getPlayer();
BreakType type = player != null ? BreakType.PLAYER : BreakType.NATURAL;
UUID uuid = player != null ? player.getUniqueId() : null;
if (maybeSideTracked(block)) {
trySideBreak(block, type, uuid);
}
if (maybeBelowTracked(block)) {
block = block.getRelative(BlockFace.UP);
}
Location loc = block.getLocation();
if (!pendingChecks.contains(loc)) {
pendingChecks.add(loc);
handleBreak(block, type, uuid, null);
}
}
示例3: onWoodBreak
import org.bukkit.event.block.BlockBreakEvent; //导入方法依赖的package包/类
@EventHandler
public void onWoodBreak(BlockBreakEvent event) {
final Block b = event.getBlock();
if (b != null && (b.getType() == Material.LOG || b.getType() == Material.LOG_2)) {
Material handType = event.getPlayer().getItemInHand().getType();
if (handType == Material.WOOD_AXE || handType == Material.STONE_AXE || handType == Material.IRON_AXE || handType == Material.GOLD_AXE || handType == Material.DIAMOND_AXE) {
dataMap.put(b, b.getData());
b.setType(Material.WOOL);
b.setData(DyeColor.BLACK.getWoolData());
Player p = event.getPlayer();
event.getPlayer().sendMessage("> +1 Woodcutting EXP");
Location loc = b.getLocation();
Vector v = p.getLocation().subtract(loc).toVector().normalize().multiply(0.5);
DropManager.dropItem(new ItemStack(Material.LOG), loc, event.getPlayer().getUniqueId()).setVelocity(v);
RScheduler.schedule(plugin, () -> {
b.setType(Material.LOG);
b.setData(dataMap.getOrDefault(b, (byte) 0));
}, RTicks.seconds(2));
}
}
}
示例4: removeBlock
import org.bukkit.event.block.BlockBreakEvent; //导入方法依赖的package包/类
public void removeBlock(BlockBreakEvent e) {
for (Entity en : e.getBlock().getWorld().getEntities()) {
if (en.getCustomName() != null && en.getCustomName().equals(getName()) && en.getLocation().add(-0.5, 0, -0.5).equals(e.getBlock().getLocation())) {
en.remove();
en.getWorld().getBlockAt(en.getLocation().add(-0.5, 0, -0.5)).setType(Material.AIR);
ItemStack block = new ItemStack(Material.MONSTER_EGG, 1);
ItemMeta bmeta = block.getItemMeta();
bmeta.setDisplayName(name);
block.setItemMeta(bmeta);
if (e.getPlayer() != null && e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
e.getPlayer().getInventory().addItem(block);
} else {
e.getBlock().getWorld().dropItemNaturally(en.getLocation().add(-0.5, 0, -0.5), block);
}
}
}
//}
}
示例5: removeBlock
import org.bukkit.event.block.BlockBreakEvent; //导入方法依赖的package包/类
@Override
public void removeBlock(BlockBreakEvent e) {
if (e.getPlayer() == null) {return;}
for (Entity en : e.getPlayer().getNearbyEntities(10, 10, 10)) {
System.out.println("Removal has Begun");
if (en.getCustomName() != null && en.getCustomName().equals(getName()) && /*en.getLocation().add(-0.5, 0, -0.5).equals(e.getBlock().getLocation())*/ en.getLocation().distance(e.getBlock().getLocation()) < 2) {
for (Entity ent : en.getNearbyEntities(0.5, 0.5, 0.5)) {
if (ent.getCustomName().equals("CustomBlock")) {
ent.remove();
break;
}
}
en.remove();
//en.getWorld().getBlockAt(en.getLocation().add(-0.5, 0, -0.5)).setType(Material.AIR);
if (e.getPlayer() != null && e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
e.getPlayer().getInventory().addItem(getItem());
} else {
e.getBlock().getWorld().dropItemNaturally(en.getLocation().add(-0.5, 0, -0.5), getItem());
}
return;
}
}
}
示例6: onBlockBreakCreative
import org.bukkit.event.block.BlockBreakEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockBreakCreative(BlockBreakEvent event) {
Player player = event.getPlayer();
if (player.getGameMode() == GameMode.CREATIVE && !player.hasPermission("base.command.gamemode")) {
event.setCancelled(true);
player.sendMessage(ChatColor.RED + "You are not allowed to be in gamemode! Setting you to default gamemode!");
player.setGameMode(GameMode.SURVIVAL);
}
}
示例7: onBlockBreak
import org.bukkit.event.block.BlockBreakEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onBlockBreak(BlockBreakEvent event) {
double amount = event.getExpToDrop();
Player player = event.getPlayer();
ItemStack stack = player.getItemInHand();
if (stack != null && stack.getType() != Material.AIR && amount > 0) {
int enchantmentLevel = stack.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS);
if (enchantmentLevel > 0) {
double multiplier = enchantmentLevel * SettingsYML.EXP_MULTIPLIER_FORTUNE_PER_LEVEL;
int result = (int) Math.ceil(amount * multiplier);
event.setExpToDrop(result);
}
}
}
示例8: preventBlockBreakWithGun
import org.bukkit.event.block.BlockBreakEvent; //导入方法依赖的package包/类
/**
* Prevent using the gun-item to break blocks
* @param event the break event
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void preventBlockBreakWithGun(BlockBreakEvent event) {
if (event.getPlayer() == null || event.getPlayer().getInventory().getItemInMainHand() == null)
return;
ItemStack item = event.getPlayer().getInventory().getItemInMainHand();
StandardGun gun = findGun(item);
if (gun == null) // can't match it
return;
event.setCancelled(true);
}
示例9: preventBlockBreakWithGun
import org.bukkit.event.block.BlockBreakEvent; //导入方法依赖的package包/类
/**
* Prevent using the gun-item to break blocks
* @param event the break event
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void preventBlockBreakWithGun(BlockBreakEvent event) {
if (event.getPlayer() != null && isGun(event.getPlayer().getInventory().getItemInMainHand())) {
event.setCancelled(true);
}
}
示例10: onBreak
import org.bukkit.event.block.BlockBreakEvent; //导入方法依赖的package包/类
@EventHandler
public void onBreak(BlockBreakEvent e)
{
Player p = e.getPlayer();
if (modMode.contains(p.getName())) {
e.setCancelled(true);
}
}
示例11: onBlockBreakCreative
import org.bukkit.event.block.BlockBreakEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockBreakCreative(BlockBreakEvent event) {
Player player = event.getPlayer();
if (player.getGameMode() == GameMode.CREATIVE && !player.hasPermission("base.command.gamemode")) {
event.setCancelled(true);
player.sendMessage(ChatColor.RED + "You are not allowed to be in gamemode! Setting you to default gamemode!");
player.setGameMode(GameMode.SURVIVAL);
}
}
示例12: onBlockBreakEvent
import org.bukkit.event.block.BlockBreakEvent; //导入方法依赖的package包/类
@EventHandler
public void onBlockBreakEvent(BlockBreakEvent e) {
Player player = e.getPlayer();
if (!hasIgnorePermission(player)) {
if (inLobbyWorld(player) && SkyWarsReloaded.getCfg().playerBuildDisabled()) {
e.setCancelled(true);
}
}
}
示例13: onBlockBreak
import org.bukkit.event.block.BlockBreakEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockBreak(final BlockBreakEvent event) {
Player player = event.getPlayer();
if (player.getGameMode() != GameMode.CREATIVE) {
if (player.hasPermission("hcf.listener.autosmeltore")) {
ItemStack stack = player.getItemInHand();
if (stack != null && stack.getType() != Material.AIR
&& !stack.containsEnchantment(Enchantment.SILK_TOUCH)) {
Block block = event.getBlock();
Material dropType = null;
switch (block.getType()) {
case IRON_ORE: {
dropType = Material.IRON_INGOT;
break;
}
case GOLD_ORE: {
dropType = Material.GOLD_INGOT;
break;
}
default: {
return;
}
}
Location location = block.getLocation();
World world = location.getWorld();
ItemStack drop = new ItemStack(dropType, 1);
world.dropItemNaturally(location, drop);
block.setType(Material.AIR);
block.getState().update();
}
}
}
}
示例14: onBreakWithItemVisibility
import org.bukkit.event.block.BlockBreakEvent; //导入方法依赖的package包/类
@EventHandler(priority=EventPriority.HIGHEST)
public void onBreakWithItemVisibility(BlockBreakEvent e) {
Player p = e.getPlayer();
if (ConfigGPlayerVisibility.getConfig().getBoolean("PV.Enable")) {
if (ConfigGPlayerVisibility.getConfig().getBoolean("PV.Option.Ultimate-Protection-Of-The-Items")) {
if ((p.getItemInHand().getItemMeta().getDisplayName() == Check) || (p.getItemInHand().getItemMeta().getDisplayName() == CheckTwo)) {
e.setCancelled(true);
}
}
}
}
示例15: onBlockBreak
import org.bukkit.event.block.BlockBreakEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onBlockBreak(BlockBreakEvent event) {
if (plugin.getEotwHandler().isEndOfTheWorld())
return;
Player player = event.getPlayer();
if (player.getGameMode() == GameMode.CREATIVE && player.hasPermission(ProtectionListener.PROTECTION_BYPASS_PERMISSION)) {
return;
}
Block block = event.getBlock();
BlockState state = block.getState();
Block subclaimObjectBlock = null;
if (!(state instanceof Sign)) {
subclaimObjectBlock = block;
} else {
Sign sign = (Sign) state;
MaterialData signData = sign.getData();
if (signData instanceof org.bukkit.material.Sign) {
org.bukkit.material.Sign materialSign = (org.bukkit.material.Sign) signData;
subclaimObjectBlock = block.getRelative(materialSign.getAttachedFace());
}
}
if (subclaimObjectBlock != null && !this.checkSubclaimIntegrity(player, subclaimObjectBlock)) {
event.setCancelled(true);
player.sendMessage(ChatColor.RED + "You cannot break this subclaimed " + subclaimObjectBlock.getType().toString() + '.');
}
}