Ejemplo n.º 1
0
 /** Setup it so he can see himself when disguised */
 public static void setupFakeDisguise(final Disguise disguise) {
   Entity e = disguise.getEntity();
   // If the disguises entity is null, or the disguised entity isn't a player return
   if (e == null
       || !(e instanceof Player)
       || !getDisguises().containsKey(e.getUniqueId())
       || !getDisguises().get(e.getUniqueId()).contains(disguise)) {
     return;
   }
   Player player = (Player) e;
   // Check if he can even see this..
   if (!((TargetedDisguise) disguise).canSee(player)) {
     return;
   }
   // Remove the old disguise, else we have weird disguises around the place
   DisguiseUtilities.removeSelfDisguise(player);
   // If the disguised player can't see himself. Return
   if (!disguise.isSelfDisguiseVisible()
       || !PacketsManager.isViewDisguisesListenerEnabled()
       || player.getVehicle() != null) {
     return;
   }
   selfDisguised.add(player.getUniqueId());
   sendSelfDisguise(player, (TargetedDisguise) disguise);
   if (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf()) {
     if (PacketsManager.isInventoryListenerEnabled()) {
       player.updateInventory();
     }
   }
 }
 public Entity addRider(Entity vehicle, ISpawnableEntity riderData) {
   Location vehicleLoc = vehicle.getLocation();
   Entity rider = spawnMobAt(riderData, vehicleLoc);
   vehicle.setPassenger(rider);
   spawner.addSecondaryMob(rider.getUniqueId(), vehicle.getUniqueId());
   return rider;
 }
Ejemplo n.º 3
0
  @Override
  public synchronized void saveChunk(int cx, int cz, World world) {
    if (world == null) return;

    boolean unloaded = false;
    if (!store.containsKey(world.getName() + "," + cx + "," + cz)) {
      List<Entity> tempSpawnedMobs = new ArrayList<Entity>(spawnedMobs);
      for (Entity entity : tempSpawnedMobs) {
        if (!isEntityInChunk(entity, cx, cz, world)) continue;

        loadChunk(cx, cz, world);
        unloaded = true;
        break;
      }

      if (!unloaded) {
        List<Entity> tempSpawnedPets = new ArrayList<Entity>(spawnedPets);
        for (Entity entity : tempSpawnedPets) {
          if (!isEntityInChunk(entity, cx, cz, world)) continue;

          loadChunk(cx, cz, world);
          unloaded = true;
          break;
        }
      }
    }

    if (!store.containsKey(world.getName() + "," + cx + "," + cz) && unloaded) {
      ChunkStore cStore = ChunkStoreFactory.getChunkStore(world, cx, cz);
      store.put(world.getName() + "," + cx + "," + cz, cStore);
    }

    if (store.containsKey(world.getName() + "," + cx + "," + cz)) {
      ChunkStore out = store.get(world.getName() + "," + cx + "," + cz);

      List<Entity> tempSpawnedMobs = new ArrayList<Entity>(spawnedMobs);
      for (Entity entity : tempSpawnedMobs) {
        if (!isEntityInChunk(entity, cx, cz, world)) continue;

        out.addSpawnedMob(entity.getUniqueId());
      }

      List<Entity> tempSpawnedPets = new ArrayList<Entity>(spawnedPets);
      for (Entity entity : tempSpawnedPets) {
        if (!isEntityInChunk(entity, cx, cz, world)) continue;

        out.addSpawnedPet(entity.getUniqueId());
      }

      if (!out.isDirty()) return;

      writeChunkStore(world, cx, cz, out);
    }
  }
 public PacketEntityInformation(List<LivingEntity> entities) {
   ByteBuffer tempbuffer =
       ByteBuffer.allocate(entities.size() * 20); // 4 bytes for entity id, 16 for uuid
   for (Entity e : entities) {
     tempbuffer.putLong(e.getUniqueId().getLeastSignificantBits());
     tempbuffer.putLong(e.getUniqueId().getMostSignificantBits());
     tempbuffer.putInt(e.getEntityId());
   }
   data = tempbuffer.array();
 }
Ejemplo n.º 5
0
  @Override
  @javax.annotation.Nullable
  protected Entity[] get(Event arg0) {

    Entity returnEnt = null;
    for (World w : Bukkit.getWorlds()) {
      for (Entity e : w.getEntities()) {
        if (e.getUniqueId().toString() == uuid.getSingle(arg0)) {
          return new Entity[] {e};
        }
      }
    }
    return null;
  }
Ejemplo n.º 6
0
 public static TargetedDisguise getDisguise(Player observer, Entity entity) {
   UUID entityId = entity.getUniqueId();
   if (futureDisguises.containsKey(entity.getEntityId())) {
     for (TargetedDisguise disguise : futureDisguises.remove(entity.getEntityId())) {
       addDisguise(entityId, disguise);
     }
   }
   if (getDisguises().containsKey(entityId)) {
     for (TargetedDisguise disguise : getDisguises().get(entityId)) {
       if (disguise.canSee(observer)) {
         return disguise;
       }
     }
   }
   return null;
 }
Ejemplo n.º 7
0
  public ItemFrame getFrame(boolean force) {
    ItemFrame frame = (instance != null) ? instance.get() : null;
    if (frame == null || !frame.isValid()) {
      final World world = (worldId != null) ? Bukkit.getWorld(worldId) : null;
      if (world != null) {
        Chunk chunk = world.getChunkAt(chunk_x, chunk_z);
        if (!chunk.isLoaded() && force) chunk.load();

        if (chunk.isLoaded())
          for (Entity entity : chunk.getEntities())
            if (entity.getUniqueId().equals(id)) {
              frame = (ItemFrame) entity;
              instance = new WeakReference<ItemFrame>(frame);
              break;
            }
      }
    }

    return frame;
  }
Ejemplo n.º 8
0
 public MG10_Remove() {
   GameData data = Main.getMain().getGameData();
   ArrayList<UUID> players = new ArrayList<>();
   for (Entity e : data.getEntitys()) {
     if (!e.isEmpty()) {
       Entity p = e.getPassenger();
       if (p.getType() == EntityType.PLAYER) {
         players.add(p.getUniqueId());
         e.eject();
       }
     }
     e.remove();
   }
   data.getEntitys().clear();
   for (Player player : data.getPlayers()) {
     if (!players.contains(player.getUniqueId())) {
       data.diePlayer(player.getUniqueId());
     }
   }
 }
Ejemplo n.º 9
0
 @EventHandler
 public void onHit(EntityDamageByEntityEvent e) {
   if (((e.getEntity() instanceof Player)) && ((e.getDamager() instanceof Player))) {
     Player entity = (Player) e.getEntity();
     Entity damager = (Player) e.getDamager();
     if (getRemaining(entity) > 0L) {
       Double damage = Double.valueOf(e.getDamage() * 0.3D);
       e.setDamage(e.getDamage() + damage.doubleValue());
     }
   }
   if (((e.getEntity() instanceof Player)) && ((e.getDamager() instanceof Arrow))) {
     Player entity = (Player) e.getEntity();
     Entity damager = (Player) ((Arrow) e.getDamager()).getShooter();
     if (((damager instanceof Player)) && (getRemaining(entity) > 0L)) {
       if (((UUID) ArcherClass.tagged.get(entity.getUniqueId())).equals(damager.getUniqueId())) {
         setCooldown(entity, entity.getUniqueId());
       }
       Double damage = Double.valueOf(e.getDamage() * 0.3D);
       e.setDamage(e.getDamage() + damage.doubleValue());
     }
   }
 }
Ejemplo n.º 10
0
  public boolean bleed() {
    if (target == null || damager == null || target.isDead()) return false;
    if (damager instanceof Player && !Bukkit.getOfflinePlayer(damager.getUniqueId()).isOnline()) {
      return false;
    }

    EntityDamageByEntityEvent e =
        new EntityDamageByEntityEvent(damager, target, EntityDamageEvent.DamageCause.CUSTOM, 1);

    Bukkit.getPluginManager().callEvent(e);

    if (WGUtil.canGetDamage(target) && !e.isCancelled()) {
      target.damage(e.getDamage());
      target.setLastDamageCause(e);
      if (target instanceof Player) {
        target.sendMessage(ChatColor.DARK_RED + "You are bleeding..");
      }
    }
    EffectUtil.playParticle(target, Effect.CRIT);

    duration--;

    return duration > 0;
  }
Ejemplo n.º 11
0
 /**
  * Generates a unique metadata key for an {@link Entity} UUID.
  *
  * @see MetadataStoreBase#disambiguate(Object, String)
  * @param entity the entity
  * @param metadataKey The name identifying the metadata value
  * @return a unique metadata key
  */
 @Override
 protected String disambiguate(Entity entity, String metadataKey) {
   return entity.getUniqueId().toString() + ":" + metadataKey;
 }
Ejemplo n.º 12
0
  public final ABPortal getByFrame(final Entity frame) {
    final UUID uid = portalFrames.get(frame.getUniqueId());
    if (uid == null) return null;

    return allPortals.get(uid);
  }
Ejemplo n.º 13
0
 public UUID getUniqueId() {
   return e.getUniqueId();
 }
Ejemplo n.º 14
0
  public static void follow(
      final Entity target,
      final Entity follower,
      final double speed,
      final double lead,
      final double maxRange,
      final boolean allowWander) {
    if (target == null || follower == null) return;

    final net.minecraft.server.v1_8_R3.Entity nmsEntityFollower =
        ((CraftEntity) follower).getHandle();
    if (!(nmsEntityFollower instanceof EntityInsentient)) return;
    final EntityInsentient nmsFollower = (EntityInsentient) nmsEntityFollower;
    final NavigationAbstract followerNavigation = nmsFollower.getNavigation();

    UUID uuid = follower.getUniqueId();

    if (followTasks.containsKey(uuid)) followTasks.get(uuid).cancel();

    final int locationNearInt = (int) Math.floor(lead);
    final boolean hasMax = maxRange > lead;

    followTasks.put(
        follower.getUniqueId(),
        new BukkitRunnable() {

          private boolean inRadius = false;

          public void run() {
            if (!target.isValid() || !follower.isValid()) {
              this.cancel();
            }
            followerNavigation.a(2F);
            Location targetLocation = target.getLocation();
            PathEntity path;

            if (hasMax
                && !Utilities.checkLocation(targetLocation, follower.getLocation(), maxRange)
                && !target.isDead()
                && target.isOnGround()) {
              if (!inRadius) {
                follower.teleport(
                    Utilities.getWalkableLocationNear(targetLocation, locationNearInt));
              } else {
                inRadius = false;
                path =
                    followerNavigation.a(
                        targetLocation.getX(), targetLocation.getY(), targetLocation.getZ());
                if (path != null) {
                  followerNavigation.a(path, 1D);
                  followerNavigation.a(2D);
                }
              }
            } else if (!inRadius
                && !Utilities.checkLocation(targetLocation, follower.getLocation(), lead)) {
              path =
                  followerNavigation.a(
                      targetLocation.getX(), targetLocation.getY(), targetLocation.getZ());
              if (path != null) {
                followerNavigation.a(path, 1D);
                followerNavigation.a(2D);
              }
            } else {
              inRadius = true;
            }
            if (inRadius && !allowWander) {
              followerNavigation.n();
            }
            nmsFollower.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed);
          }
        }.runTaskTimer(DenizenAPI.getCurrentInstance(), 0, 20));
  }
Ejemplo n.º 15
0
 public static void stopFollowing(Entity follower) {
   if (follower == null) return;
   UUID uuid = follower.getUniqueId();
   if (followTasks.containsKey(uuid)) followTasks.get(uuid).cancel();
 }