org.bukkit.event.hanging.HangingPlaceEvent Java Examples

The following examples show how to use org.bukkit.event.hanging.HangingPlaceEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerLeashHitch(final HangingPlaceEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
        plugin.getLogger().info("DEBUG: block placed " + e.getBlock().getType());
        plugin.getLogger().info("DEBUG: entity " + e.getEntity().getType());
    }
    if (Settings.allowedFakePlayers.contains(e.getPlayer().getName())) return;

    // plugin.getLogger().info(e.getEventName());
    if (inWorld(e.getPlayer())) {
        if (e.getEntity() != null && e.getEntity().getType().equals(EntityType.LEASH_HITCH)) {
            if (!actionAllowed(e.getPlayer(), e.getBlock().getLocation(), SettingsFlag.LEASH)) {
                Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                e.setCancelled(true);
                return;
            }
        }
    }
}
 
Example #2
Source File: ProtectionHandler.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPaintingPlace(HangingPlaceEvent event) {
    boolean setCancelled = event.isCancelled() ||
            shouldBlockAction(event.getBlock(), event.getPlayer(), "block_build");
    if (setCancelled) {
        event.setCancelled(true);
    }
    if (event.isCancelled() && event.getPlayer() != null) {
        event.getPlayer().sendMessage(Civs.getPrefix() +
                LocaleManager.getInstance().getTranslationWithPlaceholders(event.getPlayer(), LocaleConstants.REGION_PROTECTED));
    }
}
 
Example #3
Source File: RegionInteractListener.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handles placing paintings, item frames, leashes
 *
 * @param event The event
 */
@EventHandler
public void onHangingPlace(HangingPlaceEvent event) {
	Player player = event.getPlayer();
	NovaPlayer nPlayer = PlayerManager.getPlayer(player);
	Location location = event.getEntity().getLocation();

	if(RegionManager.get(location) != null
			&& (!plugin.getRegionManager().canInteract(player, location) || (!nPlayer.getPreferences().getBypass() && !nPlayer.hasPermission(GuildPermission.BLOCK_PLACE)))) {
		event.setCancelled(true);
		Message.CHAT_REGION_DENY_INTERACT.send(player);
	}
}
 
Example #4
Source File: BukkitPlotListener.java    From PlotMe-Core with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onHangingPlace(HangingPlaceEvent event) {
    IPlayer player = plugin.wrapPlayer(event.getPlayer());
    Location location = BukkitUtil.adapt(event.getBlock().getLocation());

    if (manager.isPlotWorld(location.getWorld())) {
        if (player.hasPermission(PermissionNames.ADMIN_BUILDANYWHERE)) {
            return;
        }

        Plot plot = manager.getPlot(location);

        if (plot == null) {
            player.sendMessage(api.C("CannotBuild"));
            event.setCancelled(true);
        } else {
            if (plot.getOwnerId().equals(event.getPlayer().getUniqueId())) {
                return;
            }
            Optional<Plot.AccessLevel> member = plot.isMember(player.getUniqueId());
            if (member.isPresent()) {
                if (member.get().equals(Plot.AccessLevel.TRUSTED) && !api.getServerBridge().getOfflinePlayer(plot.getOwnerId()).isOnline()) {
                    player.sendMessage(api.C("CannotBuild"));
                    event.setCancelled(true);
                } else if (api.isPlotLocked(plot.getId())) {
                    player.sendMessage(api.C("PlotLocked"));
                    event.setCancelled(true);
                }
            } else {
                player.sendMessage(api.C("CannotBuild"));
                event.setCancelled(true);
            }
        }
    }

}
 
Example #5
Source File: ItemHanging.java    From Carbon with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean interactWith(ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l, float f, float f1, float f2) {
	if (l == 0) {
		return false;
	}
	if (l == 1) {
		return false;
	}
	int i1 = Direction.e[l];
	EntityHanging entityhanging = a(world, i, j, k, i1);
	if (!entityhuman.a(i, j, k, l, itemstack)) {
		return false;
	}
	if ((entityhanging != null) && (entityhanging.survives())) {
		if (!world.isStatic) {
			Player who = entityhuman == null ? null : (Player) entityhuman.getBukkitEntity();
			Block blockClicked = world.getWorld().getBlockAt(i, j, k);
			BlockFace blockFace = CraftBlock.notchToBlockFace(l);

			HangingPlaceEvent event = new HangingPlaceEvent((Hanging) entityhanging.getBukkitEntity(), who, blockClicked, blockFace);
			world.getServer().getPluginManager().callEvent(event);

			PaintingPlaceEvent paintingEvent = null;
			if ((entityhanging instanceof EntityPainting)) {
				paintingEvent = new PaintingPlaceEvent((Painting) entityhanging.getBukkitEntity(), who, blockClicked, blockFace);
				paintingEvent.setCancelled(event.isCancelled());
				world.getServer().getPluginManager().callEvent(paintingEvent);
			}
			if ((event.isCancelled()) || ((paintingEvent != null) && (paintingEvent.isCancelled()))) {
				return false;
			}
			world.addEntity(entityhanging);
		}
		itemstack.count -= 1;
	}
	return true;
}
 
Example #6
Source File: RegionMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void checkHangingPlace(final HangingPlaceEvent event) {
  this.handleHangingPlace(event, getHangingBlockState(event.getEntity()), event.getPlayer());
}
 
Example #7
Source File: LWCEntityListener.java    From Modern-LWC with MIT License 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onHangingPlace(HangingPlaceEvent event) {
    Player player = event.getPlayer();
    Entity block = event.getEntity();
    entityCreatedByPlayer(block, player);
}
 
Example #8
Source File: EventRuleMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void checkHangingPlace(final HangingPlaceEvent event) {
    this.handleHangingPlace(event, getHangingBlockState(event.getEntity()), event.getPlayer());
}
 
Example #9
Source File: CancellableChunkEvents.java    From ClaimChunk with MIT License 4 votes vote down vote up
@EventHandler
public void onItemFramePlaced(HangingPlaceEvent e) {
    if (e != null && e.getPlayer() != null) {
        ChunkEventHelper.handleBlockEvent(e.getPlayer(), e.getEntity().getLocation().getChunk(), e);
    }
}
 
Example #10
Source File: EntityLimits.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerBlockPlace(final HangingPlaceEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
        plugin.getLogger().info("DEBUG: block placed " + e.getBlock().getType());
        plugin.getLogger().info("DEBUG: entity " + e.getEntity().getType());
    }

    if (Settings.allowedFakePlayers.contains(e.getPlayer().getName())) return;

    // plugin.getLogger().info(e.getEventName());
    if (IslandGuard.inWorld(e.getPlayer())) {
        // This permission bypasses protection
        if (e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
            return;
        }
        Island island = plugin.getGrid().getProtectedIslandAt(e.getBlock().getLocation());
        // Outside of island protection zone
        if (island == null) {
            if (!Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) {
                Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
                e.setCancelled(true);
            }
            return;
        }
        if (island.getIgsFlag(SettingsFlag.PLACE_BLOCKS) || island.getMembers().contains(e.getPlayer().getUniqueId()))  {
            // Check how many placed
            String type = e.getEntity().getType().toString();
            if (e.getEntity().getType().equals(EntityType.ITEM_FRAME) || e.getEntity().getType().equals(EntityType.PAINTING)) {
                // tile entity placed
                if (Settings.limitedBlocks.containsKey(type) && Settings.limitedBlocks.get(type) > -1) {
                    // Convert from EntityType to Material via string - ugh
                    int count = island.getTileEntityCount(Material.valueOf(type),e.getEntity().getWorld());
                    if (Settings.limitedBlocks.get(type) <= count) {
                        Util.sendMessage(e.getPlayer(), ChatColor.RED + (plugin.myLocale(e.getPlayer().getUniqueId()).entityLimitReached.replace("[entity]",
                                Util.prettifyText(type))).replace("[number]", String.valueOf(Settings.limitedBlocks.get(type))));
                        e.setCancelled(true);
                    }
                }
            }
        } else {
            // Visitor
            Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
            e.setCancelled(true);
        }
    }
}
 
Example #11
Source File: HangingPlace.java    From FunnyGuilds with Apache License 2.0 4 votes vote down vote up
@EventHandler
public void onPlace(HangingPlaceEvent e) {
    if (ProtectionSystem.build(e.getPlayer(), e.getEntity().getLocation())) {
        e.setCancelled(true);
    }
}
 
Example #12
Source File: BlockEventRegion.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onHangingPlace(HangingPlaceEvent event) {
    if (region.contains(event.getEntity().getLocation().toVector()) && filter.evaluate(event.getEntity(), event).equals(FilterState.DENY)) {
        event.setCancelled(true);
    }
}
 
Example #13
Source File: ObserverModule.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onHangingPlace(HangingPlaceEvent event) {
    if (testObserverOrDead(event.getPlayer())) {
        event.setCancelled(true);
    }
}