Java Code Examples for org.bukkit.event.hanging.HangingPlaceEvent#setCancelled()

The following examples show how to use org.bukkit.event.hanging.HangingPlaceEvent#setCancelled() . 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: 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 6
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 7
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 8
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);
    }
}