Java Code Examples for org.bukkit.Location#equals()
The following examples show how to use
org.bukkit.Location#equals() .
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: GeneralizingListener.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
private final void handleMovementHigh(final PlayerMoveEvent event) { Player player = event.getPlayer(); Location originalFrom = event.getFrom(); Location originalTo = event.getTo(); Location oldTo = this.lastToLocation.get(player); if (oldTo != null && !oldTo.equals(originalFrom)) { // If this movement does not start where the last known movement ended, // we have to make up the missing movement. We do that by (potentially) firing // two coarse events for this one event, a "fake" one for the missing movement // and a "real" one for the current movement. // First, modify this event to look like the missing event, and fire // a coarse event that wraps it. event.setFrom(oldTo); event.setTo(originalFrom); this.updateLastToLocation(event); if (this.callCoarsePlayerMove(event)) { // If the fake coarse event was cancelled, we don't need to fire // the real one, so just return. Note that the wrapped event won't // actually be cancelled, rather its to location will be modified // to return the player to the oldTo location. Also note that if // the original event was already cancelled before the coarse event // fired, then we will never get here, and both the fake and real // events will go through. this.updateLastToLocation(event); return; } // Restore the event to its real state event.setFrom(originalFrom); event.setTo(originalTo); } this.updateLastToLocation(event); if (this.callCoarsePlayerMove(event)) { this.updateLastToLocation(event); } }
Example 2
Source File: MonstersIncListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@EventHandler (ignoreCancelled = true) public void onBlockClick(PlayerInteractEvent e) { Block block = e.getClickedBlock(); Player player = e.getPlayer(); Location goToLoc; if (e.getAction() != Action.RIGHT_CLICK_BLOCK){ return; } if (block == null){ return; } if(isDoor(block)) { Block below = block.getRelative(BlockFace.DOWN, 1); if (isDoor(below)) { block = below; } if (doorLocs.size() > 1) { do { goToLoc = doorLocs.get((int) (Math.random() * doorLocs.size())); // Door loc is no longer valid. if (!isValidDoorLocation(goToLoc)){ doorLocs.remove(goToLoc); goToLoc = null; } } while ((goToLoc == null || goToLoc.equals(block.getLocation())) && doorLocs.size() > 1); if (goToLoc != null) { player.teleport(goToLoc.clone().add(0.5, 0, 0.5)); } } } }
Example 3
Source File: RegionManager.java From Civs with GNU General Public License v3.0 | 5 votes |
private boolean withinRegion(Region region, Location location) { Location rLocation = region.getLocation(); if (rLocation.equals(location)) { return true; } if (!Objects.equals(rLocation.getWorld(), location.getWorld())) { return false; } return rLocation.getX() - 0.5 - region.getRadiusXN() <= location.getX() && rLocation.getX() + 0.5 + region.getRadiusXP() >= location.getX() && rLocation.getY() - 0.5 - region.getRadiusYN() <= location.getY() && rLocation.getY() + 0.5 + region.getRadiusYP() >= location.getY() && rLocation.getZ() - 0.5 - region.getRadiusZN() <= location.getZ() && rLocation.getZ() + 0.5 + region.getRadiusZP() >= location.getZ(); }
Example 4
Source File: MailboxLocations.java From NyaaUtils with MIT License | 5 votes |
public void updateLocationMapping(UUID uuid, Location location) { Validate.notNull(uuid); if (location == null) { // unset if (locationMap.containsKey(uuid)) { locationMap.remove(uuid); save(); } } else { if (!location.equals(locationMap.get(uuid))) { locationMap.put(uuid, location); save(); } } }
Example 5
Source File: WarpSigns.java From askyblock with GNU General Public License v2.0 | 5 votes |
/** * @param location * @return Name of warp owner */ public String getWarpOwner(Location location) { for (UUID playerUUID : warpList.keySet()) { if (location.equals(warpList.get(playerUUID))) { return plugin.getPlayers().getName(playerUUID); } } return ""; }
Example 6
Source File: BlockEventHandler.java From GriefDefender with MIT License | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onBlockNotify(BlockPhysicsEvent event) { final Block source = NMSUtil.getInstance().getSourceBlock(event); if (source == null) { return; } final Location sourceLocation = source.getLocation(); if (sourceLocation != null && sourceLocation.equals(event.getBlock().getLocation())) { return; } final GDPermissionUser user = CauseContextHelper.getEventUser(sourceLocation); final Location location = event.getBlock().getLocation(); if (user == null) { return; } final World world = event.getBlock().getWorld(); if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) { return; } final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(world, user.getUniqueId()); final GDClaim sourceClaim = this.storage.getClaimAt(sourceLocation); final Vector3i pos = VecHelper.toVector3i(location); final GDClaim targetClaim = this.storage.getClaimAt(location); if (sourceClaim.isWilderness() && targetClaim.isWilderness()) { if (playerData != null) { playerData.eventResultCache = new EventResultCache(targetClaim, "block-notify", Tristate.TRUE); } return; } else if (!sourceClaim.isWilderness() && targetClaim.isWilderness()) { if (playerData != null) { playerData.eventResultCache = new EventResultCache(targetClaim, "block-notify", Tristate.TRUE); } return; } // Redstone sources can end up in target else if (sourceClaim.getUniqueId().equals(targetClaim.getUniqueId())) { if (playerData != null) { playerData.eventResultCache = new EventResultCache(targetClaim, "block-notify", Tristate.TRUE); } return; } else { if (playerData.eventResultCache != null && playerData.eventResultCache.checkEventResultCache(targetClaim) == Tristate.TRUE) { return; } // Needed to handle levers notifying doors to open etc. if (targetClaim.isUserTrusted(user, TrustTypes.ACCESSOR)) { if (playerData != null) { playerData.eventResultCache = new EventResultCache(targetClaim, "block-notify", Tristate.TRUE); } return; } } event.setCancelled(true); }
Example 7
Source File: Shop.java From ShopChest with MIT License | 4 votes |
private Location getHologramLocation(Chest[] chests, BlockFace face) { World w = location.getWorld(); int x = location.getBlockX(); int y = location.getBlockY(); int z = location.getBlockZ(); Location holoLocation = new Location(w, x, y, z); double deltaY = -0.6; if (Config.hologramFixedBottom) deltaY = -0.85; if (chests[1] != null) { Chest c1 = Utils.getMajorVersion() >= 13 && (face == BlockFace.NORTH || face == BlockFace.EAST) ? chests[1] : chests[0]; Chest c2 = Utils.getMajorVersion() >= 13 && (face == BlockFace.NORTH || face == BlockFace.EAST) ? chests[0] : chests[1]; if (holoLocation.equals(c1.getLocation())) { if (c1.getX() != c2.getX()) { holoLocation.add(0, deltaY, 0.5); } else if (c1.getZ() != c2.getZ()) { holoLocation.add(0.5, deltaY, 0); } else { holoLocation.add(0.5, deltaY, 0.5); } } else { if (c1.getX() != c2.getX()) { holoLocation.add(1, deltaY, 0.5); } else if (c1.getZ() != c2.getZ()) { holoLocation.add(0.5, deltaY, 1); } else { holoLocation.add(0.5, deltaY, 0.5); } } } else { holoLocation.add(0.5, deltaY, 0.5); } holoLocation.add(0, Config.hologramLift, 0); return holoLocation; }
Example 8
Source File: uSkyBlock.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
public synchronized boolean devSetPlayerIsland(final Player sender, final Location l, final String player) { final PlayerInfo pi = playerLogic.getPlayerInfo(player); String islandName = WorldGuardHandler.getIslandNameAt(l); Location islandLocation = IslandUtil.getIslandLocation(islandName); final Location newLoc = LocationUtil.alignToDistance(islandLocation, Settings.island_distance); if (newLoc == null) { return false; } boolean deleteOldIsland = false; if (pi.getHasIsland()) { Location oldLoc = pi.getIslandLocation(); if (oldLoc != null && !(newLoc.getBlockX() == oldLoc.getBlockX() && newLoc.getBlockZ() == oldLoc.getBlockZ())) { deleteOldIsland = true; } } if (newLoc.equals(pi.getIslandLocation())) { sender.sendMessage(tr("\u00a74Player is already assigned to this island!")); deleteOldIsland = false; } // Purge current islandinfo and partymembers if there's an active party at this location (issue #948) getIslandLogic().purge(islandName); Runnable resetIsland = () -> { pi.setHomeLocation(null); pi.setIslandLocation(newLoc); pi.setHomeLocation(getSafeHomeLocation(pi)); IslandInfo island = islandLogic.createIslandInfo(pi.locationForParty(), player); WorldGuardHandler.updateRegion(island); pi.save(); }; if (deleteOldIsland) { deletePlayerIsland(pi.getPlayerName(), resetIsland); } else { resetIsland.run(); } return true; }
Example 9
Source File: TestNetworkManager.java From Slimefun4 with GNU General Public License v3.0 | 4 votes |
@Override public NetworkComponent classifyLocation(Location l) { if (l.equals(regulator)) return NetworkComponent.REGULATOR; return locations.get(l); }
Example 10
Source File: EntityLimits.java From askyblock with GNU General Public License v2.0 | 4 votes |
/** * Checks if new entities can be added to island * @param island * @param bypass - true if this is being done by a player with authorization to bypass limits * @param ent - the entity * @return true if at the limit, false if not */ private boolean atLimit(Island island, boolean bypass, Entity ent) { int count = 0; checkLimits: if (bypass || Settings.entityLimits.get(ent.getType()) > 0) { // If bypass, just tag the creature. If not, then we need to count creatures if (!bypass) { // Run through all the current entities on this world for (Entity entity: ent.getWorld().getEntities()) { // If it is the right one if (entity.getType().equals(ent.getType())) { if (DEBUG) plugin.getLogger().info("DEBUG: " + entity.getType() + " found"); // Check spawn location if (entity.hasMetadata("spawnLoc")) { if (DEBUG) plugin.getLogger().info("DEBUG: has meta"); // Get the meta data List<MetadataValue> values = entity.getMetadata("spawnLoc"); for (MetadataValue v : values) { // There is a chance another plugin also uses the meta data spawnLoc if (v.getOwningPlugin().equals(plugin)) { // Get the island spawn location Location spawnLoc = Util.getLocationString(v.asString()); if (DEBUG) plugin.getLogger().info("DEBUG: entity spawnLoc = " + spawnLoc); if (spawnLoc != null && spawnLoc.equals(island.getCenter())) { // Entity is on this island count++; if (DEBUG) plugin.getLogger().info("DEBUG: entity is on island. Number = " + count); if (count >= Settings.entityLimits.get(ent.getType())) { // No more allowed! if (DEBUG) plugin.getLogger().info("DEBUG: no more allowed! >=" + count); break checkLimits; } } } } } } } } // Okay to spawn, but tag it ent.setMetadata("spawnLoc", new FixedMetadataValue(plugin, Util.getStringLocation(island.getCenter()))); if (DEBUG) plugin.getLogger().info("DEBUG: spawn okay"); return false; } // Cancel - no spawning - tell nearby players if (DEBUG) plugin.getLogger().info("DEBUG: spawn cancelled"); return true; }