下面列出了org.bukkit.event.block.Action#PHYSICAL 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@EventWrapper
public void onBlockTrample(final PlayerInteractEvent event) {
if (event.getAction() == Action.PHYSICAL) {
Block block = event.getClickedBlock();
if (block != null) {
Material oldType = getTrampledType(block.getType());
if (oldType != null) {
callEvent(
event,
BlockStates.cloneWithMaterial(block, oldType),
block.getState(),
event.getPlayer());
}
}
}
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (!needsPressurePlate(event.getPlayer())) return;
Player player = event.getPlayer();
if (event.getAction() == Action.PHYSICAL && !event.isCancelled() && isEnabledInWorld(player.getWorld())) {
if (event.getClickedBlock().getType() == getPlateType(player)) {
boolean apply = true;
if (isBlockRequired(player)) {
Location loc = event.getClickedBlock().getLocation().subtract(0, 1, 0);
apply = loc.getWorld().getBlockAt(loc).getType() == getMaterial(player);
}
if (apply) {
player.setVelocity(calculateVector(player));
if (getSound(player) != null) {
player.playSound(player.getLocation(), getSound(player), 1, 1);
}
if (getEffect(player) != null) {
Effect effect = this.getEffect(player);
ReflectionUtils.invokeMethod(player.spigot(), this.playEffectMethod, player.getLocation(),
getEffect(player), effect.getId(), 0, 1, 1, 1, 1, 40, 3);
}
event.setCancelled(true);
}
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void playerInteractEvent(PlayerInteractEvent e){
if(e.getAction() == Action.PHYSICAL) return;
if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
Player player = e.getPlayer();
ArmorType newArmorType = ArmorType.matchType(e.getItem());
if(newArmorType != null){
if(newArmorType.equals(ArmorType.HELMET) && isAirOrNull(e.getPlayer().getInventory().getHelmet()) || newArmorType.equals(ArmorType.CHESTPLATE) && isAirOrNull(e.getPlayer().getInventory().getChestplate()) || newArmorType.equals(ArmorType.LEGGINGS) && isAirOrNull(e.getPlayer().getInventory().getLeggings()) || newArmorType.equals(ArmorType.BOOTS) && isAirOrNull(e.getPlayer().getInventory().getBoots())){
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(e.getPlayer(), EquipMethod.HOTBAR, ArmorType.matchType(e.getItem()), null, e.getItem());
Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent);
if(armorEquipEvent.isCancelled()){
e.setCancelled(true);
player.updateInventory();
}
}
}
}
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (!needsPressurePlate(event.getPlayer())) return;
Player player = event.getPlayer();
if (event.getAction() == Action.PHYSICAL && !event.isCancelled() && isEnabledInWorld(player.getWorld())) {
if (event.getClickedBlock().getType() == getPlateType(player)) {
boolean apply = true;
if (isBlockRequired(player)) {
Location loc = event.getClickedBlock().getLocation().subtract(0, 1, 0);
apply = loc.getWorld().getBlockAt(loc).getType() == getMaterial(player);
}
if (apply) {
player.setVelocity(calculateVector(player));
if (getSound(player) != null) {
player.playSound(player.getLocation(), getSound(player), 1, 1);
}
if (getEffect(player) != null) {
particleEffect.display(getEffect(player), player.getLocation(), 1, 1, 1, 1, 40);
}
event.setCancelled(true);
}
}
}
}
/**
* This is specific to my test server to prevent Crop trample.
*/
@EventHandler
public void onTrample(PlayerInteractEvent e) {
if (e.getClickedBlock() == null) {
return;
}
if (e.getAction() == Action.PHYSICAL) {
Block block = e.getClickedBlock();
Material material = block.getType();
if (material == Material.CROPS || material == Material.SOIL) {
e.setUseInteractedBlock(PlayerInteractEvent.Result.DENY);
e.setCancelled(true);
block.setType(material);
block.setData(block.getData());
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPressurePlateEnter(PlayerInteractEvent e) {
if (e.getAction() != Action.PHYSICAL || e.getClickedBlock() == null) {
return;
}
String id = BlockStorage.checkID(e.getClickedBlock());
if (id == null) {
return;
}
if (isTeleporterPad(id, e.getClickedBlock(), e.getPlayer().getUniqueId())) {
SlimefunItem teleporter = BlockStorage.check(e.getClickedBlock().getRelative(BlockFace.DOWN));
if (teleporter instanceof Teleporter && checkForPylons(e.getClickedBlock().getRelative(BlockFace.DOWN))) {
Block block = e.getClickedBlock().getRelative(BlockFace.DOWN);
UUID owner = UUID.fromString(BlockStorage.getLocationInfo(block.getLocation(), "owner"));
SlimefunPlugin.getGPSNetwork().getTeleportationManager().openTeleporterGUI(e.getPlayer(), owner, block, SlimefunPlugin.getGPSNetwork().getNetworkComplexity(owner));
}
}
else if (id.equals(SlimefunItems.ELEVATOR_PLATE.getItemId())) {
((ElevatorPlate) SlimefunItems.ELEVATOR_PLATE.getItem()).open(e.getPlayer(), e.getClickedBlock());
}
}
private static boolean isValidProjectileAction(Action action, ClickAction clickAction) {
switch (clickAction) {
case RIGHT:
return action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK;
case LEFT:
return action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK;
case BOTH:
return action != Action.PHYSICAL;
}
return false;
}
private static boolean isValidProjectileAction(Action action, ClickAction clickAction) {
switch(clickAction) {
case RIGHT:
return action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK;
case LEFT:
return action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK;
case BOTH:
return action != Action.PHYSICAL;
}
return false;
}
@TargetedEventHandler(ignoreCancelled = true)
public void onInteract(PlayerInteractEvent event) {
if(!restrictAccess()) return;
if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
switch(event.getClickedBlock().getType()) {
case STONE_BUTTON:
case WOOD_BUTTON:
case LEVER:
case DIODE_BLOCK_OFF:
case DIODE_BLOCK_ON:
case REDSTONE_COMPARATOR_OFF:
case REDSTONE_COMPARATOR_ON:
event.setCancelled(true);
sendWarning();
break;
case TNT:
if(event.getItem() != null && event.getItem().getType() == FLINT_AND_STEEL) {
event.setCancelled(true);
sendWarning();
}
break;
}
} else if(event.getAction() == Action.PHYSICAL) {
switch(event.getClickedBlock().getType()) {
case STONE_PLATE:
case WOOD_PLATE:
case GOLD_PLATE:
case IRON_PLATE:
case TRIPWIRE:
event.setCancelled(true);
break;
}
}
}
@EventWrapper
public void onBlockTrample(final PlayerInteractEvent event) {
if(event.getAction() == Action.PHYSICAL) {
Block block = event.getClickedBlock();
if(block != null) {
Material oldType = getTrampledType(block.getType());
if(oldType != null) {
callEvent(event, BlockStateUtils.cloneWithMaterial(block, oldType), block.getState(), event.getPlayer());
}
}
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void openMenu(final PlayerInteractEvent event) {
if(event.getAction() == Action.PHYSICAL) return;
Player player = event.getPlayer();
if(player.getItemInHand().getType() == Material.GHAST_TEAR) {
GizmoUtils.openMenu(event.getPlayer());
purchasingMap.put(event.getPlayer(), null);
}
}
@GameEvent
public void onStep(@Nonnull PlayerInteractEvent event) {
if (event.getAction() == Action.PHYSICAL) {
if (!Tag.WOODEN_PRESSURE_PLATES.isTagged(event.getClickedBlock().getType()) &&
event.getClickedBlock().getType() != Material.STONE_PRESSURE_PLATE) {
return;
}
if (event.isCancelled()) {
return;
}
double strength = 1.5;
double up = 1;
if (event.getClickedBlock().getRelative(BlockFace.DOWN, 2).getState() instanceof Sign) {
Sign sign = (Sign) event.getClickedBlock().getRelative(BlockFace.DOWN, 2).getState();
if (sign.getLine(0).contains("[Boom]")) {
try {
strength = Double.parseDouble(sign.getLine(1));
up = Double.parseDouble(sign.getLine(2));
} catch (final Exception ex) {
log.warning("Invalid boom sign at " + sign.getLocation());
}
}
}
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ENTITY_ENDER_DRAGON_SHOOT, 10.0F, 1.0F);
event.getPlayer().playEffect(event.getPlayer().getLocation(), Effect.SMOKE, 10);
Vector v = event.getPlayer().getLocation().getDirection().multiply(strength / 2).setY(up / 2);
event.getPlayer().setVelocity(v);
event.setCancelled(true);
}
}
@Override
public boolean check(final Event e) {
final Block b = ((PlayerInteractEvent) e).getClickedBlock();
final Material type = b == null ? null : b.getType();
return type != null && ((PlayerInteractEvent) e).getAction() == Action.PHYSICAL &&
(tripwire ? (type == Material.TRIPWIRE || type == Material.TRIPWIRE_HOOK)
: plate.isOfType(type));
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false)
public void onInteract(PlayerInteractEvent event) {
if (event.hasItem() && event.getAction() != Action.PHYSICAL) {
for (BoundItem boundItem : ChestCommands.getBoundItems()) {
if (boundItem.isValidTrigger(event.getItem(), event.getAction())) {
if (event.getPlayer().hasPermission(boundItem.getMenu().getPermission())) {
boundItem.getMenu().open(event.getPlayer());
} else {
boundItem.getMenu().sendNoPermissionMessage(event.getPlayer());
}
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onTrampling(PlayerInteractEvent event) {
if (!tramplingEnabled || !plugin.getWorldManager().isSkyAssociatedWorld(event.getPlayer().getWorld())) {
return;
}
if (event.getAction() == Action.PHYSICAL
&& !isValidTarget(event.getPlayer())
&& event.hasBlock()
&& event.getClickedBlock().getType() == Material.FARMLAND
) {
event.setCancelled(true);
}
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
String name = player.getName();
if (event.getAction() != Action.PHYSICAL) {
if (TutorialManager.getManager().isInTutorial(name) && TutorialManager.getManager().getCurrentTutorial
(name).getViewType() != ViewType.TIME) {
if (TutorialManager.getManager().getCurrentTutorial(name).getTotalViews() == TutorialManager
.getManager().getCurrentView(name)) {
plugin.getEndTutorial().endTutorial(player);
} else {
plugin.incrementCurrentView(name);
TutorialUtils.getTutorialUtils().messageUtils(player);
Caching.getCaching().setTeleport(player, true);
player.teleport(TutorialManager.getManager().getTutorialView(name).getLocation());
}
}
}
if ((event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK) &&
!TutorialManager.getManager().isInTutorial(name)) {
Block block = event.getClickedBlock();
if (block.getType() == Material.SIGN || block.getType() == Material.WALL_SIGN) {
Sign sign = (Sign) block.getState();
String match = ChatColor.stripColor(TutorialUtils.color(TutorialManager.getManager().getConfigs()
.signSetting()));
if (sign.getLine(0).equalsIgnoreCase(match) && sign.getLine(1) != null) {
plugin.startTutorial(sign.getLine(1), player);
}
}
}
}
@EventHandler
public void onTrample(PlayerInteractEvent e) {
if (e.getAction() == Action.PHYSICAL) {
Block b = e.getClickedBlock();
if (b != null && b.getType() == Material.FARMLAND) {
ItemStack boots = e.getPlayer().getInventory().getBoots();
if (SlimefunUtils.isItemSimilar(boots, SlimefunItems.FARMER_SHOES, true) && Slimefun.hasUnlocked(e.getPlayer(), boots, true)) {
e.setCancelled(true);
}
}
}
}
@EventHandler
public void onDebug(PlayerInteractEvent e) {
if (e.getAction() == Action.PHYSICAL || e.getHand() != EquipmentSlot.HAND) {
return;
}
Player p = e.getPlayer();
if (p.isOp() && SlimefunUtils.isItemSimilar(e.getItem(), SlimefunItems.DEBUG_FISH, true)) {
e.setCancelled(true);
if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
if (p.isSneaking()) {
if (BlockStorage.hasBlockInfo(e.getClickedBlock())) {
BlockStorage.clearBlockInfo(e.getClickedBlock());
}
}
else {
e.setCancelled(false);
}
}
else if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (p.isSneaking()) {
Block b = e.getClickedBlock().getRelative(e.getBlockFace());
b.setType(Material.PLAYER_HEAD);
SkullBlock.setFromHash(b, HeadTexture.MISSING_TEXTURE.getTexture());
}
else if (BlockStorage.hasBlockInfo(e.getClickedBlock())) {
sendInfo(p, e.getClickedBlock());
}
}
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteractBlockSecondary(PlayerInteractEvent event) {
final Block clickedBlock = event.getClickedBlock();
if (clickedBlock == null) {
return;
}
final String id = GDPermissionManager.getInstance().getPermissionIdentifier(clickedBlock);
final GDBlockType gdBlock = BlockTypeRegistryModule.getInstance().getById(id).orElse(null);
if (gdBlock == null || (!gdBlock.isInteractable() && event.getAction() != Action.PHYSICAL)) {
return;
}
if (NMSUtil.getInstance().isBlockStairs(clickedBlock) && event.getAction() != Action.PHYSICAL) {
return;
}
final Player player = event.getPlayer();
GDCauseStackManager.getInstance().pushCause(player);
final GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) {
onPlayerInteractBlockPrimary(event, player);
return;
}
final Location location = clickedBlock.getLocation();
GDClaim claim = this.dataStore.getClaimAt(location);
final Sign sign = SignUtil.getSign(location);
// check sign
if (SignUtil.isSellSign(sign)) {
EconomyUtil.getInstance().buyClaimConsumerConfirmation(player, claim, sign);
return;
}
if (SignUtil.isRentSign(claim, sign)) {
EconomyUtil.getInstance().rentClaimConsumerConfirmation(player, claim, sign);
return;
}
final BlockState state = clickedBlock.getState();
final ItemStack itemInHand = event.getItem();
final boolean hasInventory = NMSUtil.getInstance().isTileInventory(location) || clickedBlock.getType() == Material.ENDER_CHEST;
if (hasInventory) {
onInventoryOpen(event, state.getLocation(), state, player);
return;
}
if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUID())) {
return;
}
if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.INTERACT_BLOCK_SECONDARY.getName(), event.getClickedBlock(), player.getWorld().getUID())) {
return;
}
GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.startTiming();
final Object source = player;
final TrustType trustType = NMSUtil.getInstance().isTileInventory(location) || clickedBlock.getType() == Material.ENDER_CHEST ? TrustTypes.CONTAINER : TrustTypes.ACCESSOR;
if (GDFlags.INTERACT_BLOCK_SECONDARY && playerData != null) {
Flag flag = Flags.INTERACT_BLOCK_SECONDARY;
if (event.getAction() == Action.PHYSICAL) {
flag = Flags.COLLIDE_BLOCK;
}
Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, flag, source, clickedBlock, player, trustType, true);
if (result == Tristate.FALSE) {
// if player is holding an item, check if it can be placed
if (GDFlags.BLOCK_PLACE && itemInHand != null && itemInHand.getType().isBlock()) {
if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.BLOCK_PLACE.getName(), itemInHand, player.getWorld().getUID())) {
GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.stopTiming();
return;
}
if (GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.BLOCK_PLACE, source, itemInHand, player, TrustTypes.BUILDER, true) == Tristate.TRUE) {
GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.stopTiming();
return;
}
}
// Don't send a deny message if the player is in claim mode or is holding an investigation tool
if (lastInteractItemCancelled != true) {
if (!playerData.claimMode && (GriefDefenderPlugin.getInstance().investigationTool == null || !NMSUtil.getInstance().hasItemInOneHand(player, GriefDefenderPlugin.getInstance().investigationTool))) {
if (event.getAction() == Action.PHYSICAL) {
if (player.getWorld().getTime() % 100 == 0L) {
this.sendInteractBlockDenyMessage(itemInHand, clickedBlock, claim, player, playerData);
}
} else {
if (gdBlock != null && gdBlock.isInteractable()) {
this.sendInteractBlockDenyMessage(itemInHand, clickedBlock, claim, player, playerData);
}
}
}
}
event.setUseInteractedBlock(Result.DENY);
GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.stopTiming();
return;
}
}
GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.stopTiming();
}
@EventHandler
public void onPressurePlate(final PlayerInteractEvent e) {
if (Util.get().isSpawnWorld(e.getPlayer().getWorld())) {
Player player = e.getPlayer();
GameMap gMap = MatchManager.get().getPlayerMap(player);
if (gMap == null) {
if (e.getAction() == Action.PHYSICAL && (e.getClickedBlock().getType() == SkyWarsReloaded.getNMS().getMaterial("STONE_PLATE").getType() ||
e.getClickedBlock().getType() == SkyWarsReloaded.getNMS().getMaterial("IRON_PLATE").getType() || e.getClickedBlock().getType() == SkyWarsReloaded.getNMS().getMaterial("GOLD_PLATE").getType())) {
if (SkyWarsReloaded.getCfg().pressurePlateJoin()) {
Location spawn = SkyWarsReloaded.getCfg().getSpawn();
if (spawn != null) {
boolean joined = false;
int count = 0;
Party party = Party.getParty(player);
while (count < 4 && !joined) {
if (party != null) {
if (party.getLeader().equals(player.getUniqueId())) {
boolean tryJoin = true;
for (UUID uuid: party.getMembers()) {
if (Util.get().isBusy(uuid)) {
tryJoin = false;
party.sendPartyMessage(new Messaging.MessageFormatter().setVariable("player", Bukkit.getPlayer(uuid).getName()).format("party.memberbusy"));
}
}
if (tryJoin) {
if (e.getClickedBlock().getType() == SkyWarsReloaded.getNMS().getMaterial("STONE_PLATE").getType()) {
joined = MatchManager.get().joinGame(party, GameType.ALL);
} else if (e.getClickedBlock().getType() == SkyWarsReloaded.getNMS().getMaterial("IRON_PLATE").getType()) {
joined = MatchManager.get().joinGame(party, GameType.SINGLE);
} else {
joined = MatchManager.get().joinGame(party, GameType.TEAM);
}
} else {
break;
}
} else {
player.sendMessage(new Messaging.MessageFormatter().format("party.onlyleader"));
joined = true;
break;
}
} else {
if (e.getClickedBlock().getType() == SkyWarsReloaded.getNMS().getMaterial("STONE_PLATE").getType()) {
joined = MatchManager.get().joinGame(player, GameType.ALL);
} else if (e.getClickedBlock().getType() == SkyWarsReloaded.getNMS().getMaterial("IRON_PLATE").getType()) {
joined = MatchManager.get().joinGame(player, GameType.SINGLE);
} else {
joined = MatchManager.get().joinGame(player, GameType.TEAM);
}
}
count++;
}
if (!joined) {
player.sendMessage(new Messaging.MessageFormatter().format("error.could-not-join"));
}
} else {
e.getPlayer().sendMessage(ChatColor.RED + "YOU MUST SET SPAWN IN THE LOBBY WORLD WITH /SWR SETSPAWN BEFORE STARTING A GAME");
SkyWarsReloaded.get().getLogger().info("YOU MUST SET SPAWN IN THE LOBBY WORLD WITH /SWR SETSPAWN BEFORE STARTING A GAME");
}
}
}
}
}
}