本文整理汇总了Java中org.bukkit.entity.Player.getLocation方法的典型用法代码示例。如果您正苦于以下问题:Java Player.getLocation方法的具体用法?Java Player.getLocation怎么用?Java Player.getLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.entity.Player
的用法示例。
在下文中一共展示了Player.getLocation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: repellExpOrb
import org.bukkit.entity.Player; //导入方法依赖的package包/类
final void repellExpOrb(final Player player, final ExperienceOrb orb) {
final Location pLoc = player.getLocation();
final Location oLoc = orb.getLocation();
final Vector dir = oLoc.toVector().subtract(pLoc.toVector());
final double dx = Math.abs(dir.getX());
final double dz = Math.abs(dir.getZ());
if ( (dx == 0.0) && (dz == 0.0)){
// Special case probably never happens
dir.setX(0.001);
}
if ((dx < 3.0) && (dz < 3.0)){
final Vector nDir = dir.normalize();
final Vector newV = nDir.clone().multiply(0.3);
newV.setY(0);
orb.setVelocity(newV);
if ((dx < 1.0) && (dz < 1.0)){
// maybe oLoc
orb.teleport(oLoc.clone().add(nDir.multiply(1.0)), TeleportCause.PLUGIN);
}
if ((dx < 0.5) && (dz < 0.5)){
orb.remove();
}
}
}
示例2: handleWinner
import org.bukkit.entity.Player; //导入方法依赖的package包/类
/**
* Handles the winner for this event.
*
* @param winner
* the {@link Player} that won
*/
public void handleWinner(Player winner) {
if (this.eventFaction == null)
return;
PlayerFaction playerFaction = plugin.getFactionManager().getPlayerFaction(winner);
Bukkit.broadcastMessage(ChatColor.GOLD + "[" + "WIN" + "] " + ChatColor.RED + winner.getName() + ChatColor.AQUA
+ ChatColor.YELLOW + " has captured " + ChatColor.RED + this.eventFaction.getName()
+ ChatColor.YELLOW + " after " + ChatColor.RED + DurationFormatUtils.formatDurationWords(getUptime(), true, true) + " of up-time" + ChatColor.YELLOW + '.');
EventType eventType = this.eventFaction.getEventType();
World world = winner.getWorld();
Location location = winner.getLocation();
EventKey eventKey = plugin.getKeyManager().getEventKey();
Collection<Inventory> inventories = eventKey.getInventories(eventType);
ItemStack keyStack = eventKey.getItemStack(new EventKey.EventKeyData(eventType, inventories.isEmpty() ? 1 : plugin.getRandom().nextInt(inventories.size()) + 1));
Map<Integer, ItemStack> excess = winner.getInventory().addItem(keyStack, EventSignListener.getEventSign(eventFaction.getName(), winner.getName()));
for (ItemStack entry : excess.values()) {
world.dropItemNaturally(location, entry);
}
this.clearCooldown(); // must always be cooled last as this nulls some variables.
}
示例3: spawn
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public void spawn(Connection connection, Player player, String name, float percent) {
lastName = name;
lastPercent = percent;
lastPlayerLocation = player.getLocation();
WrappedDataWatcher watcher = new WrappedDataWatcher();
watcher.setObject(new WrappedDataWatcherObject(0, Constants.DW_BYTE_SERIALIZER), Byte.valueOf((byte) 0x20));
watcher.setObject(new WrappedDataWatcherObject(2, Constants.DW_STRING_SERIALIZER), lastName);
watcher.setObject(new WrappedDataWatcherObject(3, Constants.DW_BOOLEAN_SERIALIZER), Boolean.TRUE);
watcher.setObject(new WrappedDataWatcherObject(6, Constants.DW_FLOAT_SERIALIZER), Float.valueOf(lastPercent * 3F));
watcher.setObject(new WrappedDataWatcherObject(14, Constants.DW_INTEGER_SERIALIZER), Integer.valueOf(881));
PacketUtils.sendPacket(connection, PacketUtils.createEntityLivingSpawnPacket(id, EntityType.WITHER.getTypeId(), watcher));
updateEntityLocation(connection);
}
示例4: onBlockBreak
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler
public void onBlockBreak(BlockBreakEvent e) {
final Player player = e.getPlayer();
final Block block = e.getBlock();
if(player != null) {
DACManager.getBackend().checkFastBreak(player, block);
Distance distance = new Distance(player.getLocation(),block.getLocation());
DACManager.getBackend().checkLongReachBlock(player,distance.getXDifference(), distance
.getYDifference(),distance.getZDifference());
DACManager.getBackend().logBlockBreak(player);
}
}
示例5: handlePlayerTick
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@Override
public void handlePlayerTick(Connection connection, Player player) {
if (lastPlayerLocation == null) {
return;
}
Location currectLocation = player.getLocation();
if (!lastPlayerLocation.getWorld().equals(currectLocation.getWorld())) {
despawn(connection);
spawn(connection, player, lastName, lastPercent);
} else {
lastPlayerLocation = currectLocation;
updateEntityLocation(connection);
}
}
示例6: goPetToPlayer
import org.bukkit.entity.Player; //导入方法依赖的package包/类
public static void goPetToPlayer(final Player player, final LivingEntity entity) {
if (!InventoryManager.playerIsLoaded(player) || !player.isOnline() || entity.isDead()) {
return;
}
Location target = player.getLocation();
if (target.distance(entity.getLocation()) > 20) {
PetManager.respawnPet(player);
} else if (target.distance(entity.getLocation()) < 4) {
return;
}
PetType petType = PetManager.getPetFromEntity(entity, player);
double speedModifier = petType == null ? 1.0 : 0.4 / petType.getSpeed();
Class<?> entityInsentientClass = MinecraftReflection.getMinecraftClass("EntityInsentient");
Class<?> navigationAbstractClass = MinecraftReflection.getMinecraftClass("NavigationAbstract");
try {
Method getHandle = MinecraftReflection.getCraftEntityClass().getDeclaredMethod("getHandle");
Object insentient = entityInsentientClass.cast(getHandle.invoke(entity));
Object navigation = entityInsentientClass.getDeclaredMethod("getNavigation").invoke(insentient);
navigationAbstractClass.getDeclaredMethod("a", double.class, double.class, double.class, double.class)
.invoke(navigation, target.getX(), target.getY(), target.getZ(), speedModifier);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}
}
示例7: onCommand
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "This command is only executable by players.");
return true;
}
Player player = (Player) sender;
PlayerFaction playerFaction = plugin.getFactionManager().getPlayerFaction(player);
if (playerFaction == null) {
sender.sendMessage(ChatColor.RED + "You are not in a faction.");
return true;
}
if (playerFaction.isRaidable()) {
sender.sendMessage(ChatColor.RED + "You cannot claim land for your faction while raidable.");
return true;
}
if (playerFaction.getMember(player.getUniqueId()).getRole() == Role.MEMBER) {
sender.sendMessage(ChatColor.RED + "You must be an officer to claim land.");
return true;
}
Location location = player.getLocation();
plugin.getClaimHandler().tryPurchasing(
player,
new Claim(playerFaction, location.clone().add(CHUNK_RADIUS, ClaimHandler.MIN_CLAIM_HEIGHT, CHUNK_RADIUS), location.clone().add(-CHUNK_RADIUS, ClaimHandler.MAX_CLAIM_HEIGHT,
-CHUNK_RADIUS)));
return true;
}
示例8: getCheckpoint
import org.bukkit.entity.Player; //导入方法依赖的package包/类
private int getCheckpoint(Player player) {
Location location = player.getLocation();
for (int i = 0; i < checkpointLocs.size(); i++) {
Location checkpoint = checkpointLocs.get(i);
if (checkpoint.distanceSquared(location) < checkpointSize) {
return i;
}
}
return -1;
}
示例9: logJoining
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(
ignoreCancelled = false,
priority = EventPriority.HIGH)
public void logJoining(PlayerJoinEvent event) {
Player player = event.getPlayer();
StringBuilder sb = new StringBuilder();
sb.append(new SimpleDateFormat("HH:mm:ss dd/MM/yyyy").format(new Date()));
sb.append(": ");
sb.append(player.getName());
sb.append('-');
sb.append(player.getUniqueId().toString());
sb.append(": Logged in at location: [");
Location loc = player.getLocation();
sb.append(loc.getX());
sb.append(", ");
sb.append(loc.getY());
sb.append(", ");
sb.append(loc.getZ());
sb.append("] at System Time: [");
sb.append(System.currentTimeMillis());
sb.append("] IP: [");
sb.append(player.getAddress().getHostName());
sb.append(", ");
sb.append(player.getAddress().getPort());
sb.append("]");
sb.append('\n');
Bssentials.getLogcat().write(sb.toString());
}
示例10: submitReport
import org.bukkit.entity.Player; //导入方法依赖的package包/类
private static void submitReport(Player reporter, String type, String subject, String description) {
Location loc = reporter.getLocation();
String message = "" +
"New **" + type + "** report from `" + reporter.getName() + "`\n" +
"Time: `" + new Date().toString() + "`\n" +
(subject != null ? "Subject: `" + subject + "`\n" : "") +
"Teleport: `/tl " + loc.getBlockX() + " " + loc.getBlockY() + " " + loc.getBlockZ() + " " + (int) loc.getYaw() + " " + (int) loc.getPitch() + " " + loc.getWorld().getName() + "`\n" +
"Description:\n" +
"```\n" +
description + "\n" +
"```";
DiscordAPI.sendMessage(DiscordChannel.REPORTS, message);
reporter.sendMessage(prefix + Utils.randElement(exitMessages));
}
示例11: spawn
import org.bukkit.entity.Player; //导入方法依赖的package包/类
public IEntityPet spawn(IPet pet, Player owner){
Location l = owner.getLocation();
if(EchoPet.getPlugin().getVanishProvider().isVanished(owner)) return null;
PetPreSpawnEvent spawnEvent = new PetPreSpawnEvent(pet, l);
EchoPet.getPlugin().getServer().getPluginManager().callEvent(spawnEvent);
if(spawnEvent.isCancelled()){
owner.sendMessage(EchoPet.getPrefix() + ChatColor.YELLOW + "Pet spawn was cancelled externally.");
EchoPet.getManager().removePet(pet, true);
return null;
}
l = spawnEvent.getSpawnLocation();
World mcWorld = ((CraftWorld) l.getWorld()).getHandle();
EchoPet.getPetRegistry().enablePets();
EntityPet entityPet = (EntityPet) pet.getPetType().getNewEntityPetInstance(mcWorld, pet);
entityPet.setLocation(new Location(mcWorld.getWorld(), l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch()));
if(!l.getChunk().isLoaded()){
l.getChunk().load();
}
if(!mcWorld.addEntity(entityPet, CreatureSpawnEvent.SpawnReason.CUSTOM)){
owner.sendMessage(EchoPet.getPrefix() + ChatColor.YELLOW + "Failed to spawn pet entity.");
EchoPet.getManager().removePet(pet, true);
}else{
Particle.MAGIC_RUNES.builder().at(l).show();
}
EchoPet.getPetRegistry().disablePets();
return entityPet;
}
示例12: isAllowedToEnterRegionByRiding
import org.bukkit.entity.Player; //导入方法依赖的package包/类
/**
* Checks if the player is riding his pet and entering a different region. Returns false if he isn't the owner of the region
*
* @param player player
* @param cacheSpawn cacheSpawn
* @return success
* @throws InvocationTargetException exception
* @throws IllegalAccessException exception
* @throws NoSuchMethodException exception
*/
public static boolean isAllowedToEnterRegionByRiding(Player player, boolean cacheSpawn) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
final Optional<PetBlock> optPetBlock;
if (!Config.getInstance().allowRidingOnRegionChanging() && ((optPetBlock = PetBlocksApi.getDefaultPetBlockController().getFromPlayer(player)).isPresent())) {
if (((ArmorStand) optPetBlock.get().getArmorStand()).getPassenger() != null && ((ArmorStand) optPetBlock.get().getArmorStand()).getPassenger().equals(player) || cacheSpawn) {
final Location location = player.getLocation();
final WorldGuardPlugin worldGuard = getWorldGuard();
final RegionManager regionManager = worldGuard.getRegionManager(location.getWorld());
final ApplicableRegionSet set = ReflectionUtils.invokeMethodByObject(regionManager, "getApplicableRegions", new Class[]{location.getClass()}, new Object[]{location});
final Iterable<ProtectedRegion> regions = (Iterable<ProtectedRegion>) getMethod(set.getClass(), "getRegions").invoke(set);
List<ProtectedRegion> regionsList = null;
if (cacheSpawn) {
regionsList = new ArrayList<>();
}
for (final ProtectedRegion region : regions) {
if (!cacheSpawn && region.getOwners().size() > 0 && !region.getOwners().contains(player.getUniqueId())) {
if (cache.containsKey(player) && !cache.get(player).contains(region)) {
return false;
}
}
if (cacheSpawn) {
regionsList.add(region);
}
}
if (cacheSpawn) {
cache.put(player, regionsList);
}
}
}
return true;
}
示例13: frezeplayer
import org.bukkit.entity.Player; //导入方法依赖的package包/类
public void frezeplayer(Player p, Player damager){
Location pl = p.getLocation();
pl.setX( ( pl.getBlockX()) + 0.5 );
pl.setZ( ( pl.getBlockZ()) + 0.5 );
// set ice blocks
Location locs[] = new Location[7]; // actual locations
Location bla[] = new Location[7]; // before locations added
bla[0] = new Location(p.getWorld(), pl.getX(), pl.getY(), pl.getZ());
bla[1] = new Location(p.getWorld(), pl.getX()+1, pl.getY(), pl.getZ());
bla[2] = new Location(p.getWorld(), pl.getX()-1, pl.getY(), pl.getZ());
bla[3] = new Location(p.getWorld(), pl.getX(), pl.getY(), pl.getZ()+1);
bla[4] = new Location(p.getWorld(), pl.getX(), pl.getY(), pl.getZ()-1);
bla[5] = new Location(p.getWorld(), pl.getX(), pl.getY()+1, pl.getZ());
bla[6] = new Location(p.getWorld(), pl.getX(), pl.getY()+2, pl.getZ());
int arrl = 0;
for(int k = 0; k < 7; k++){
if(bla[k].getBlock().getType() == Material.AIR){
locs[k] = bla[k];
arrl++;
}else{
damager.sendMessage(ChatColor.RED + "Could not freeze player, they are too close to a wall");
return;
}
}
p.teleport(pl);
final int arrl2 = arrl;
final Location flocs[] = locs; // locations, finalled
Bukkit.getScheduler().runTaskLater(this, new Runnable(){
public void run() {
// remove ice blocks
for(int j = 0; j < arrl2; j++){
flocs[j].getBlock().setType(Material.AIR);
}
}
}, 40L
);
for(int i = 0; i < arrl2; i++){
locs[i].getBlock().setType(Material.PACKED_ICE);
}
p.teleport(pl);
}
示例14: onPlayerMoveEvent
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler
public void onPlayerMoveEvent(PlayerMoveEvent event) {
Player sender = event.getPlayer();
GamePlayer gPlayer = SkyWarsReloaded.getPC().getPlayer(sender.getUniqueId());
if (gPlayer.inGame()) {
String effect = gPlayer.getEffect();
if (effect == null) {
return;
}
World world = sender.getWorld();
Location location = sender.getLocation();
Random random = new Random();
switch(effect) {
case "flame":
SkyWarsReloaded.getNMS().sendParticles(world, "FLAME", (float) location.getX(), (float) location.getY(), (float) location.getZ(), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, random.nextInt((8 - 4) + 4) + 1);
break;
case "smoke":
SkyWarsReloaded.getNMS().sendParticles(world, "SMOKE_LARGE", (float) location.getX(), (float) location.getY(), (float) location.getZ(), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, random.nextInt((16 - 8) + 8) + 1);
break;
case "portal":
SkyWarsReloaded.getNMS().sendParticles(world, "PORTAL", (float) location.getX(), (float) location.getY(), (float) location.getZ(), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, random.nextInt((140 - 80) + 80) + 1);
break;
case "heart":
SkyWarsReloaded.getNMS().sendParticles(world, "HEART", (float) location.getX(), (float) location.getY(), (float) location.getZ(), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, random.nextInt((10 - 3) + 3) + 1);
break;
case "critical":
SkyWarsReloaded.getNMS().sendParticles(world, "CRIT", (float) location.getX(), (float) location.getY(), (float) location.getZ(), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, random.nextInt((8 - 5) + 5) + 1);
break;
case "water":
SkyWarsReloaded.getNMS().sendParticles(world, "WATER_SPLASH", (float) location.getX(), (float) location.getY(), (float) location.getZ(), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, random.nextInt((14 - 8) + 8) + 1);
break;
case "redstone":
SkyWarsReloaded.getNMS().sendParticles(world, "REDSTONE", (float) location.getX(), (float) location.getY(), (float) location.getZ(), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, random.nextInt((10 - 3) + 3) + 1);
break;
case "sparks":
SkyWarsReloaded.getNMS().sendParticles(world, "FIREWORKS_SPARK", (float) location.getX(), (float) location.getY(), (float) location.getZ(), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, random.nextInt((8 - 4) + 4) + 1);
break;
case "lava_drip":
SkyWarsReloaded.getNMS().sendParticles(world, "DRIP_LAVA", (float) location.getX(), (float) location.getY(), (float) location.getZ(), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, random.nextInt((8 - 4) + 4) + 1);
break;
case "lava":
SkyWarsReloaded.getNMS().sendParticles(world, "LAVA", (float) location.getX(), (float) location.getY(), (float) location.getZ(), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, random.nextInt((16 - 4) + 4) + 1);
break;
case "alphabet":
SkyWarsReloaded.getNMS().sendParticles(world, "ENCHANTMENT_TABLE", (float) location.getX(), (float) location.getY(), (float) location.getZ(), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, random.nextInt((16 - 8) + 8) + 1);
break;
case "happy":
SkyWarsReloaded.getNMS().sendParticles(world, "VILLAGER_HAPPY", (float) location.getX(), (float) location.getY(), (float) location.getZ(), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, random.nextInt((12 - 4) + 4) + 1);
break;
case "magic":
SkyWarsReloaded.getNMS().sendParticles(world, "SPELL_WITCH", (float) location.getX(), (float) location.getY(), (float) location.getZ(), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, random.nextInt((10 - 7) + 7) + 1);
break;
case "music":
SkyWarsReloaded.getNMS().sendParticles(world, "NOTE", (float) location.getX(), (float) location.getY(), (float) location.getZ(), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, random.nextInt((10 - 4) + 4) + 1);
break;
case "angry":
SkyWarsReloaded.getNMS().sendParticles(world, "VILLAGER_ANGRY", (float) location.getX(), (float) location.getY(), (float) location.getZ(), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, random.nextInt((5 - 2) + 2) + 1);
break;
case "clouds":
SkyWarsReloaded.getNMS().sendParticles(world, "CLOUD", (float) location.getX(), (float) location.getY(), (float) location.getZ(), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, random.nextInt((12 - 6) + 6) + 1);
break;
case "potion":
SkyWarsReloaded.getNMS().sendParticles(world, "SPELL", (float) location.getX(), (float) location.getY(), (float) location.getZ(), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, random.nextInt((12 - 6) + 6) + 1);
break;
case "poison":
SkyWarsReloaded.getNMS().sendParticles(world, "SPELL_INSTANT", (float) location.getX(), (float) location.getY(), (float) location.getZ(), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, random.nextInt((12 - 6) + 6) + 1);
break;
case "snow":
SkyWarsReloaded.getNMS().sendParticles(world, "SNOWBALL", (float) location.getX(), (float) location.getY(), (float) location.getZ(), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, random.nextInt((12 - 6) + 6) + 1);
break;
case "slime":
SkyWarsReloaded.getNMS().sendParticles(world, "SLIME", (float) location.getX(), (float) location.getY(), (float) location.getZ(), random.nextFloat(), random.nextFloat(), random.nextFloat(), 0, random.nextInt((12 - 6) + 6) + 1);
break;
default: break;
}
}
}
示例15: onPlayerQuit
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled=true, priority=EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event)
{
final Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
boolean result = this.safelyDisconnected.remove(uuid);
if ((!result) && (player.getGameMode() != GameMode.CREATIVE) && (!player.isDead()))
{
if (this.loggers.containsKey(player.getUniqueId())) {
return;
}
if (this.plugin.getTimerManager().getInvincibilityTimer().getRemaining(uuid) > 0L) {
return;
}
Location location = player.getLocation();
if (this.plugin.getFactionManager().getFactionAt(location).isSafezone()) {
return;
}
if ((this.plugin.getSotwTimer().getSotwRunnable() != null) || (this.plugin.getTimerManager().getTeleportTimer().getNearbyEnemies(player, 64) <= 0)) {
return;
}
final LoggerEntity loggerEntity = new LoggerEntityHuman(player, location.getWorld());
LoggerSpawnEvent calledEvent = new LoggerSpawnEvent(loggerEntity);
Bukkit.getPluginManager().callEvent(calledEvent);
if (!calledEvent.isCancelled())
{
this.loggers.put(player.getUniqueId(), loggerEntity);
new BukkitRunnable()
{
public void run()
{
if (!player.isOnline()) {
loggerEntity.postSpawn(CombatLogListener.this.plugin);
}
}
}
.runTaskLater(this.plugin, 1L);
}
}
}