org.bukkit.Location#equals ( )源码实例Demo

下面列出了org.bukkit.Location#equals ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: PGM   文件: GeneralizingListener.java
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);
  }
}
 
源代码2 项目: UhcCore   文件: MonstersIncListener.java
@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));
            }
        }
    }
}
 
源代码3 项目: Civs   文件: RegionManager.java
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();
}
 
源代码4 项目: NyaaUtils   文件: MailboxLocations.java
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();
        }
    }
}
 
源代码5 项目: askyblock   文件: WarpSigns.java
/**
 * @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 "";
}
 
源代码6 项目: GriefDefender   文件: BlockEventHandler.java
@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);
}
 
源代码7 项目: ShopChest   文件: Shop.java
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;
}
 
源代码8 项目: uSkyBlock   文件: uSkyBlock.java
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;
}
 
源代码9 项目: Slimefun4   文件: TestNetworkManager.java
@Override
public NetworkComponent classifyLocation(Location l) {
    if (l.equals(regulator)) return NetworkComponent.REGULATOR;
    return locations.get(l);
}
 
源代码10 项目: askyblock   文件: EntityLimits.java
/**
 * 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;
}