use of org.spongepowered.api.entity.EntityType in project SpongeCommon by SpongePowered.
the class TimingsExport method reportTimings.
/**
* Builds an XML report of the timings to be uploaded for parsing.
*
* @param sender Who to report to
*/
static void reportTimings(CommandSource sender) {
Platform platform = SpongeImpl.getGame().getPlatform();
JsonObjectBuilder builder = JSONUtil.objectBuilder().add("version", platform.getContainer(IMPLEMENTATION).getVersion().orElse(platform.getMinecraftVersion().getName() + "-DEV")).add("maxplayers", SpongeImpl.getGame().getServer().getMaxPlayers()).add("start", TimingsManager.timingStart / 1000).add("end", System.currentTimeMillis() / 1000).add("sampletime", (System.currentTimeMillis() - TimingsManager.timingStart) / 1000);
if (!TimingsManager.privacy) {
builder.add("server", getServerName()).add("motd", Sponge.getServer().getMotd().toPlain()).add("online-mode", Sponge.getServer().getOnlineMode()).add("icon", SpongeImpl.getServer().getServerStatusResponse().getFavicon());
}
final Runtime runtime = Runtime.getRuntime();
RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
builder.add("system", JSONUtil.objectBuilder().add("timingcost", getCost()).add("name", System.getProperty("os.name")).add("version", System.getProperty("os.version")).add("jvmversion", System.getProperty("java.version")).add("arch", System.getProperty("os.arch")).add("maxmem", runtime.maxMemory()).add("cpu", runtime.availableProcessors()).add("runtime", ManagementFactory.getRuntimeMXBean().getUptime()).add("flags", RUNTIME_FLAG_JOINER.join(runtimeBean.getInputArguments())).add("gc", JSONUtil.mapArrayToObject(ManagementFactory.getGarbageCollectorMXBeans(), (input) -> {
return JSONUtil.singleObjectPair(input.getName(), JSONUtil.arrayOf(input.getCollectionCount(), input.getCollectionTime()));
})));
Set<BlockType> blockTypeSet = Sets.newHashSet();
Set<EntityType> entityTypeSet = Sets.newHashSet();
int size = HISTORY.size();
TimingHistory[] history = new TimingHistory[size + 1];
int i = 0;
for (TimingHistory timingHistory : HISTORY) {
blockTypeSet.addAll(timingHistory.blockTypeSet);
entityTypeSet.addAll(timingHistory.entityTypeSet);
history[i++] = timingHistory;
}
// Current snapshot
history[i] = new TimingHistory();
blockTypeSet.addAll(history[i].blockTypeSet);
entityTypeSet.addAll(history[i].entityTypeSet);
JsonObjectBuilder handlersBuilder = JSONUtil.objectBuilder();
for (TimingIdentifier.TimingGroup group : TimingIdentifier.GROUP_MAP.values()) {
for (TimingHandler id : group.handlers) {
if (!id.timed && !id.isSpecial()) {
continue;
}
handlersBuilder.add(id.id, JSONUtil.arrayOf(group.id, id.name));
}
}
builder.add("idmap", JSONUtil.objectBuilder().add("groups", JSONUtil.mapArrayToObject(TimingIdentifier.GROUP_MAP.values(), (group) -> {
return JSONUtil.singleObjectPair(group.id, group.name);
})).add("handlers", handlersBuilder).add("worlds", JSONUtil.mapArrayToObject(TimingHistory.worldMap.entrySet(), (entry) -> {
return JSONUtil.singleObjectPair(entry.getValue(), entry.getKey());
})).add("tileentity", JSONUtil.mapArrayToObject(blockTypeSet, (blockType) -> {
return JSONUtil.singleObjectPair(Block.getIdFromBlock((Block) blockType), blockType.getId());
})).add("entity", JSONUtil.mapArrayToObject(entityTypeSet, (entityType) -> {
if (entityType == EntityTypes.UNKNOWN) {
return null;
}
return JSONUtil.singleObjectPair(TimingsPls.getEntityId(entityType), entityType.getId());
})));
// Information about loaded plugins
builder.add("plugins", JSONUtil.mapArrayToObject(SpongeImpl.getGame().getPluginManager().getPlugins(), (plugin) -> {
return JSONUtil.objectBuilder().add(plugin.getId(), JSONUtil.objectBuilder().add("version", plugin.getVersion().orElse("")).add("description", plugin.getDescription().orElse("")).add("website", plugin.getUrl().orElse("")).add("authors", AUTHOR_LIST_JOINER.join(plugin.getAuthors()))).build();
}));
// Information on the users Config
builder.add("config", JSONUtil.objectBuilder().add("sponge", serializeConfigNode(SpongeImpl.getGlobalConfig().getRootNode())));
new TimingsExport(sender, builder.build(), history).start();
}
use of org.spongepowered.api.entity.EntityType in project SpongeCommon by SpongePowered.
the class SelectorResolver method addTypeFilters.
private void addTypeFilters(List<Predicate<Entity>> filters) {
Selector sel = this.selector;
Optional<Argument.Invertible<EntityType>> typeOpt = sel.getArgument(ArgumentTypes.ENTITY_TYPE);
if (typeOpt.isPresent()) {
Argument.Invertible<EntityType> typeArg = typeOpt.get();
final boolean inverted = typeArg.isInverted();
final EntityType type = typeArg.getValue();
filters.add(input -> inverted ^ input.getType() == type);
}
}
use of org.spongepowered.api.entity.EntityType in project SpongeCommon by SpongePowered.
the class MixinAnvilChunkLoader method onReadChunkEntity.
/**
* @author gabizou - January 30th, 2016
*
* Attempts to redirect EntityList spawning an entity. Forge
* rewrites this method to handle it in a different method, so this
* will not actually inject in SpongeForge.
*
* @param compound
* @param world
* @return
*/
@Redirect(method = "readChunkEntity", at = @At(value = "INVOKE", target = ENTITY_LIST_CREATE_FROM_NBT), require = 0, expect = 0)
private static Entity onReadChunkEntity(NBTTagCompound compound, World world, Chunk chunk) {
if ("Minecart".equals(compound.getString(NbtDataUtil.ENTITY_TYPE_ID))) {
compound.setString(NbtDataUtil.ENTITY_TYPE_ID, EntityMinecart.Type.values()[compound.getInteger(NbtDataUtil.MINECART_TYPE)].getName());
compound.removeTag(NbtDataUtil.MINECART_TYPE);
}
Class<? extends Entity> entityClass = SpongeImplHooks.getEntityClass(new ResourceLocation(compound.getString(NbtDataUtil.ENTITY_TYPE_ID)));
if (entityClass == null) {
return null;
}
EntityType type = EntityTypeRegistryModule.getInstance().getForClass(entityClass);
if (type == null) {
return null;
}
NBTTagList positionList = compound.getTagList(NbtDataUtil.ENTITY_POSITION, NbtDataUtil.TAG_DOUBLE);
NBTTagList rotationList = compound.getTagList(NbtDataUtil.ENTITY_ROTATION, NbtDataUtil.TAG_FLOAT);
Vector3d position = new Vector3d(positionList.getDoubleAt(0), positionList.getDoubleAt(1), positionList.getDoubleAt(2));
Vector3d rotation = new Vector3d(rotationList.getFloatAt(0), rotationList.getFloatAt(1), 0);
Transform<org.spongepowered.api.world.World> transform = new Transform<>((org.spongepowered.api.world.World) world, position, rotation);
try (StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.CHUNK_LOAD);
ConstructEntityEvent.Pre event = SpongeEventFactory.createConstructEntityEventPre(Sponge.getCauseStackManager().getCurrentCause(), type, transform);
SpongeImpl.postEvent(event);
if (event.isCancelled()) {
return null;
}
return EntityList.createEntityFromNBT(compound, world);
}
}
use of org.spongepowered.api.entity.EntityType in project SpongeCommon by SpongePowered.
the class EntitySpawnTest method onInitialization.
@Listener
public void onInitialization(final GameInitializationEvent event) {
Sponge.getCommandManager().register(this, CommandSpec.builder().arguments(GenericArguments.allOf(GenericArguments.catalogedElement(Text.of("type"), EntityType.class))).executor((src, args) -> {
if (!(src instanceof Player)) {
throw new CommandException(Text.of(TextColors.RED, "You must be a player to execute this command!"));
}
final List<EntityType> types = new ArrayList<>(args.getAll("type"));
final int size = types.size();
if (size == 0) {
throw new CommandException(Text.of(TextColors.RED, "You must specify at least one entity type to spawn any."));
}
final Location location = ((Player) src).getLocation();
if (size == 1) {
boolean failed = false;
final EntityType type = types.get(0);
final Entity entity = location.createEntity(type);
try {
if (location.getExtent().spawnEntity(entity)) {
src.sendMessage(Text.of(TextColors.GOLD, "You have successfully spawned a ", TextColors.DARK_GREEN, entity.getTranslation()));
} else {
failed = true;
}
} catch (Exception e) {
failed = true;
}
if (failed) {
throw new CommandException(Text.of(TextColors.RED, "You have failed to spawn a " + type.getId()));
}
} else {
src.sendMessage(Text.of(TextColors.GOLD, "You have spawned the following entities:"));
location.getExtent().spawnEntities(types.stream().map(location::createEntity).collect(Collectors.toList())).forEach(e -> src.sendMessage(Text.of(TextColors.DARK_GREEN, e.getTranslation())));
}
return CommandResult.success();
}).build(), "spawnspongeentity");
}
use of org.spongepowered.api.entity.EntityType in project SpongeCommon by SpongePowered.
the class EntityActivationRange method initializeEntityActivationState.
/**
* These entities are excluded from Activation range checks.
*
* @param entity Entity to check
* @return boolean If it should always tick.
*/
public static boolean initializeEntityActivationState(Entity entity) {
if (((IMixinWorld) entity.world).isFake()) {
return true;
}
// types that should always be active
if (entity instanceof EntityPlayer && !SpongeImplHooks.isFakePlayer(entity) || entity instanceof EntityThrowable || entity instanceof EntityDragon || entity instanceof MultiPartEntityPart || entity instanceof EntityWither || entity instanceof EntityFireball || entity instanceof EntityWeatherEffect || entity instanceof EntityTNTPrimed || entity instanceof EntityEnderCrystal || entity instanceof EntityFireworkRocket || // Always tick falling blocks
entity instanceof EntityFallingBlock) {
return true;
}
EntityActivationRangeCategory config = ((IMixinWorldServer) entity.world).getActiveConfig().getConfig().getEntityActivationRange();
EntityType type = ((org.spongepowered.api.entity.Entity) entity).getType();
IModData_Activation spongeEntity = (IModData_Activation) entity;
if (type == EntityTypes.UNKNOWN || !(type instanceof SpongeEntityType)) {
return false;
}
final SpongeEntityType spongeType = (SpongeEntityType) type;
final byte activationType = spongeEntity.getActivationType();
if (!spongeType.isActivationRangeInitialized()) {
addEntityToConfig(entity.world, spongeType, activationType);
spongeType.setActivationRangeInitialized(true);
}
EntityActivationModCategory entityMod = config.getModList().get(spongeType.getModId().toLowerCase());
int defaultActivationRange = config.getDefaultRanges().get(activationTypeMappings.get(activationType));
if (entityMod == null) {
// use default activation range
spongeEntity.setActivationRange(defaultActivationRange);
if (defaultActivationRange <= 0) {
return true;
}
return false;
} else if (!entityMod.isEnabled()) {
spongeEntity.setActivationRange(defaultActivationRange);
return true;
}
Integer defaultModActivationRange = entityMod.getDefaultRanges().get(activationTypeMappings.get(activationType));
Integer entityActivationRange = entityMod.getEntityList().get(type.getName().toLowerCase());
if (defaultModActivationRange != null && entityActivationRange == null) {
spongeEntity.setActivationRange(defaultModActivationRange);
if (defaultModActivationRange <= 0) {
return true;
}
return false;
} else if (entityActivationRange != null) {
spongeEntity.setActivationRange(entityActivationRange);
if (entityActivationRange <= 0) {
return true;
}
}
return false;
}
Aggregations