public void spawnEntity(Location<World> location, Vector3d velocity, CommandSource src) {
    Extent extent = location.getExtent();
    Optional<Entity> optional = extent.createEntity(EntityTypes.FIREBALL, location.getPosition());

    Entity fireball = optional.get();
    fireball.offer(Keys.VELOCITY, velocity);
    extent.spawnEntity(fireball, Cause.of(src));
  }
Example #2
0
 @Subscribe
 public void onBlockChange(EntityChangeBlockEvent event) {
   Entity entity = event.getEntity();
   if (entity.getType() == EntityTypes.PLAYER) {
     return;
   }
   if (PS.get().isPlotWorld(entity.getWorld().getName())) {
     event.setCancelled(true);
   }
 }
Example #3
0
 public List<Entity> getEntities() {
   List<Entity> entities = new ArrayList<Entity>();
   for (Location<World> loc : POS2) {
     Location<World> pos2 = loc.getRelative(Direction.UP);
     for (Entity entity : loc.getExtent().getEntities()) {
       if (entity.getLocation().getBlockPosition().equals(pos2.getBlockPosition())) {
         entities.add(entity);
       }
     }
   }
   return entities;
 }
 @Override
 public List<? extends Entity> filterEntityLocations(Predicate<Location<World>> predicate) {
   if (((net.minecraftforge.event.world.ExplosionEvent.Detonate) (Object) this).isCancelable()) {
     Iterator<? extends Entity> iterator = this.getEntities().iterator();
     while (iterator.hasNext()) {
       Entity entity = iterator.next();
       Location<World> location = entity.getLocation();
       if (!predicate.apply(location)) {
         iterator.remove();
       }
     }
   }
   return this.getEntities();
 }
Example #5
0
  @Listener
  public void onSpawnEntityEvent(SpawnEntityEvent event, @Root SpawnCause cause) {
    WorldSettings settings = WorldSettings.get(event.getTargetWorld());

    if (!settings.isVanillaSpawnerAllowed() && cause.getType().equals(SpawnTypes.MOB_SPAWNER)) {
      return;
    } else if (!settings.isModSpawnerAllowed() && cause.getType().equals(SpawnTypes.CUSTOM)) {
      return;
    } else if (!settings.isPluginSpawnerAllowed() && cause.getType().equals(SpawnTypes.PLUGIN)) {
      return;
    } else if (!settings.isEggSpawnerAllowed() && cause.getType().equals(SpawnTypes.SPAWN_EGG)) {
      return;
    }

    for (Entity entity : event.getEntities()) {
      entity.offer(Sponge.getDataManager().getManipulatorBuilder(MoneyData.class).get().create());
    }
  }
  public static SpawnEntityEvent callEntityJoinWorldEvent(Event event) {
    if (!(event instanceof SpawnEntityEvent)) {
      throw new IllegalArgumentException("Event is not a valiud SpawnEntityEvent.");
    }

    SpawnEntityEvent spongeEvent = (SpawnEntityEvent) event;
    Iterator<org.spongepowered.api.entity.Entity> iterator = spongeEvent.getEntities().iterator();
    while (iterator.hasNext()) {
      org.spongepowered.api.entity.Entity entity = iterator.next();
      EntityJoinWorldEvent forgeEvent =
          new EntityJoinWorldEvent(
              (net.minecraft.entity.Entity) entity,
              (net.minecraft.world.World) entity.getLocation().getExtent());

      ((IMixinEventBus) MinecraftForge.EVENT_BUS).post(forgeEvent, true);
      if (forgeEvent.isCanceled()) {
        iterator.remove();
      }
    }
    return spongeEvent;
  }
Example #7
0
  @Subscribe
  public void onMobSpawn(EntitySpawnEvent event) {
    Entity entity = event.getEntity();
    if (entity instanceof Player) {
      return;
    }
    final Location loc = SpongeUtil.getLocation(event.getLocation());
    final String world = loc.getWorld();
    PlotWorld plotworld = PS.get().getPlotWorld(world);
    if (plotworld == null) {
      return;
    }
    Plot plot = MainUtil.getPlot(loc);
    if (plot == null) {
      if (MainUtil.isPlotRoad(loc)) {
        event.setCancelled(true);
      }
      return;
    }
    final PlotWorld pW = PS.get().getPlotWorld(world);

    // TODO selectively cancel depending on spawn reason
    // - Not sure if possible to get spawn reason (since there are no callbacks)

    if (entity.getType() == EntityTypes.DROPPED_ITEM) {
      if (FlagManager.isPlotFlagFalse(plot, "item-drop")) {
        event.setCancelled(true);
      }
      return;
    }
    int[] mobs = null;
    if (entity instanceof Living) {
      if (!plotworld.MOB_SPAWNING) {
        event.setCancelled(true);
        return;
      }
      Flag mobCap = FlagManager.getPlotFlag(plot, "mob-cap");
      if (mobCap != null) {
        Integer cap = (Integer) mobCap.getValue();
        if (cap == 0) {
          event.setCancelled(true);
          return;
        }
        if (mobs == null) mobs = ChunkManager.manager.countEntities(plot);
        if (mobs[3] >= cap) {
          event.setCancelled(true);
          return;
        }
      }
      if (entity instanceof Ambient || entity instanceof Animal) {
        Flag animalFlag = FlagManager.getPlotFlag(plot, "animal-cap");
        if (animalFlag != null) {
          int cap = ((Integer) animalFlag.getValue());
          if (cap == 0) {
            event.setCancelled(true);
            return;
          }
          if (mobs == null) mobs = ChunkManager.manager.countEntities(plot);
          if (mobs[1] >= cap) {
            event.setCancelled(true);
            return;
          }
        }
      }
      if (entity instanceof Monster) {
        Flag monsterFlag = FlagManager.getPlotFlag(plot, "hostile-cap");
        if (monsterFlag != null) {
          int cap = ((Integer) monsterFlag.getValue());
          if (cap == 0) {
            event.setCancelled(true);
            return;
          }
          if (mobs == null) mobs = ChunkManager.manager.countEntities(plot);
          if (mobs[2] >= cap) {
            event.setCancelled(true);
            return;
          }
        }
      }
      return;
    }
    if (entity instanceof Minecart || entity instanceof Boat) {
      Flag vehicleFlag = FlagManager.getPlotFlag(plot, "vehicle-cap");
      if (vehicleFlag != null) {
        int cap = ((Integer) vehicleFlag.getValue());
        if (cap == 0) {
          event.setCancelled(true);
          return;
        }
        if (mobs == null) mobs = ChunkManager.manager.countEntities(plot);
        if (mobs[4] >= cap) {
          event.setCancelled(true);
          return;
        }
      }
    }
    Flag entityCap = FlagManager.getPlotFlag(plot, "entity-cap");
    if (entityCap != null) {
      Integer cap = (Integer) entityCap.getValue();
      if (cap == 0) {
        event.setCancelled(true);
        return;
      }
      if (mobs == null) mobs = ChunkManager.manager.countEntities(plot);
      if (mobs[0] >= cap) {
        event.setCancelled(true);
        return;
      }
    }
  }
Example #8
0
 public void quickTeleport() {
   for (Entity entity : getEntities()) {
     entity.setLocation(POS1);
   }
 }
Example #9
0
  TimingHistory() {
    this.endTime = System.currentTimeMillis() / 1000;
    this.startTime = TimingsManager.historyStart / 1000;
    if (timedTicks % 1200 != 0 || MINUTE_REPORTS.isEmpty()) {
      this.minuteReports = MINUTE_REPORTS.toArray(new MinuteReport[MINUTE_REPORTS.size() + 1]);
      this.minuteReports[this.minuteReports.length - 1] = new MinuteReport();
    } else {
      this.minuteReports = MINUTE_REPORTS.toArray(new MinuteReport[MINUTE_REPORTS.size()]);
    }
    long ticks = 0;
    for (MinuteReport mp : this.minuteReports) {
      ticks += mp.ticksRecord.timed;
    }
    this.totalTicks = ticks;
    this.totalTime = FULL_SERVER_TICK.record.totalTime;
    this.entries = new TimingHistoryEntry[TimingsManager.HANDLERS.size()];

    int i = 0;
    for (TimingHandler handler : TimingsManager.HANDLERS) {
      this.entries[i++] = new TimingHistoryEntry(handler);
    }

    final Map<EntityType, Counter> entityCounts =
        MRUMapCache.of(LoadingMap.of(Maps.newHashMap(), Counter.loader()));
    final Map<BlockType, Counter> tileEntityCounts =
        MRUMapCache.of(LoadingMap.of(Maps.newHashMap(), Counter.loader()));
    // Information about all loaded chunks/entities
    this.worlds =
        JSONUtil.mapArrayToObject(
            SpongeImpl.getGame().getServer().getWorlds(),
            (world) -> {
              return JSONUtil.singleObjectPair(
                  String.valueOf(worldMap.get(world.getName())),
                  JSONUtil.mapArray(
                      world.getLoadedChunks(),
                      (chunk) -> {
                        entityCounts.clear();
                        tileEntityCounts.clear();

                        for (Entity entity : chunk.getEntities()) {
                          if (entity.getType() == null) {
                            SpongeImpl.getLogger().error("Entity is not registered {}", entity);
                            continue;
                          }
                          entityCounts.get(entity.getType()).increment();
                        }

                        for (TileEntity tileEntity : chunk.getTileEntities()) {
                          tileEntityCounts.get(tileEntity.getBlock().getType()).increment();
                        }

                        if (tileEntityCounts.isEmpty() && entityCounts.isEmpty()) {
                          return null;
                        }
                        return JSONUtil.arrayOf(
                            chunk.getPosition().getX(),
                            chunk.getPosition().getZ(),
                            JSONUtil.mapArrayToObject(
                                entityCounts.entrySet(),
                                (entry) -> {
                                  if (entry.getKey() == EntityTypes.UNKNOWN) {
                                    return null;
                                  }
                                  this.entityTypeSet.add(entry.getKey());
                                  return JSONUtil.singleObjectPair(
                                      ((SpongeEntityType) entry.getKey()).entityTypeId,
                                      entry.getValue().count());
                                }),
                            JSONUtil.mapArrayToObject(
                                tileEntityCounts.entrySet(),
                                (entry) -> {
                                  this.blockTypeSet.add(entry.getKey());
                                  return JSONUtil.singleObjectPair(
                                      Block.getIdFromBlock((Block) entry.getKey()),
                                      entry.getValue().count());
                                }));
                      }));
            });
  }