本文整理汇总了Java中org.spongepowered.api.entity.EntityType类的典型用法代码示例。如果您正苦于以下问题:Java EntityType类的具体用法?Java EntityType怎么用?Java EntityType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EntityType类属于org.spongepowered.api.entity包,在下文中一共展示了EntityType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getForAll
import org.spongepowered.api.entity.EntityType; //导入依赖的package包/类
@Override
public Optional<EntityTemplate> getForAll(String identifier) {
Preconditions.checkNotNull(identifier);
EntityTemplate entity = this.entities.get(identifier.toLowerCase());
if (entity != null) {
return Optional.of(entity);
}
Optional<EntityType> type = this.plugin.getGame().getRegistry().getType(EntityType.class, identifier);
if (type.isPresent()) {
return Optional.of(EntityTemplate.of(type.get()));
}
return Optional.empty();
}
示例2: tabCompleter
import org.spongepowered.api.entity.EntityType; //导入依赖的package包/类
@Override
public Collection<String> tabCompleter(final CommandSource source, final List<String> args) throws CommandException {
if (args.size() == 1) {
List<String> suggests = new ArrayList<String>();
this.plugin.getGame().getRegistry().getAllForMinecraft(EntityType.class).stream()
.filter(entity -> !entity.equals(EntityTypes.UNKNOWN) &&
(Creature.class.isAssignableFrom(entity.getEntityClass()) || Hostile.class.isAssignableFrom(entity.getEntityClass())))
.forEach(entity -> suggests.add(entity.getId().replaceAll("minecraft:", "")));
this.plugin.getGame().getRegistry().getAllOf(EntityType.class).stream()
.filter(entity -> !entity.equals(EntityTypes.UNKNOWN) &&
(Creature.class.isAssignableFrom(entity.getEntityClass()) || Hostile.class.isAssignableFrom(entity.getEntityClass())))
.forEach(entity -> suggests.add(entity.getId()));
this.plugin.getEverAPI().getManagerService().getEntity().getAll()
.forEach(entity -> suggests.add(entity.getId()));
return suggests;
} else if (args.size() == 2){
Arrays.asList("1", String.valueOf(this.limit));
}
return Arrays.asList();
}
示例3: commandButcherType
import org.spongepowered.api.entity.EntityType; //导入依赖的package包/类
private CompletableFuture<Boolean> commandButcherType(EPlayer player, EntityType type, int radius) {
Collection<Entity> list = player.getWorld().getEntities(entity ->
entity.getType().equals(type) && entity.getLocation().getPosition().distance(player.getLocation().getPosition()) <= radius);
if (!list.isEmpty()){
list.forEach(entity -> entity.remove());
EEMessages.BUTCHER_TYPE_RADIUS.sender()
.replace("{radius}", String.valueOf(radius))
.replace("{count}", String.valueOf(list.size()))
.replace("{entity}", getButtomEntity(type))
.sendTo(player);
return CompletableFuture.completedFuture(true);
} else {
EEMessages.BUTCHER_NOENTITY.sendTo(player);
return CompletableFuture.completedFuture(false);
}
}
示例4: onEntityDamage
import org.spongepowered.api.entity.EntityType; //导入依赖的package包/类
@Listener
public void onEntityDamage(DamageEntityEvent event, @Root EntityDamageSource dmgSource) {
if(dmgSource.getSource() instanceof Player) {
Player player = (Player)dmgSource.getSource();
EntityType entityType = event.getTargetEntity().getType();
String entityId = entityType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.entity.damage." + entityId + ".deal")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to damage " + entityType.getName() + "s!"));
}
}
}
示例5: onInteractEntitySecondaryMain
import org.spongepowered.api.entity.EntityType; //导入依赖的package包/类
@Listener
public void onInteractEntitySecondaryMain(InteractEntityEvent.Secondary event, @Root Player player) {
Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
if(itemStackOptional.isPresent()) {
EntityType entityType = event.getTargetEntity().getType();
String entityId = entityType.getId();
ItemType itemType = itemStackOptional.get().getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + entityId + ".primary")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to secondary use " + itemType.getName() + " on " + entityType.getName() + "s!"));
}
}
}
示例6: onInteractEntityPrimaryMain
import org.spongepowered.api.entity.EntityType; //导入依赖的package包/类
@Listener
public void onInteractEntityPrimaryMain(InteractEntityEvent.Primary event, @Root Player player) {
Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
if(itemStackOptional.isPresent()) {
EntityType entityType = event.getTargetEntity().getType();
String entityId = entityType.getId();
ItemType itemType = itemStackOptional.get().getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + entityId + ".primary")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to primary use " + itemType.getName() + " on " + entityType.getName() + "s!"));
}
}
}
示例7: deserialize
import org.spongepowered.api.entity.EntityType; //导入依赖的package包/类
@Override
public NPCguard deserialize(TypeToken<?> arg0, ConfigurationNode cfg) throws ObjectMappingException {
NPCguard npc = new NPCguard(UUID.fromString(cfg.getNode("uuid").getString()));
InvPrep ip = new InvPrep();
ip.items = cfg.getNode("items").getValue(tokenListStockItem);
if (ip.items==null) ip.items = new LinkedList<>();
npc.setPreparator(ip);
npc.setLoc(cfg.getNode("location").getValue(tokenLocationWorld));
npc.setRot(new Vector3d(0.0, cfg.getNode("rotation").getDouble(0.0), 0.0 ));
npc.setNpcType((EntityType)FieldResolver.getFinalStaticByName(EntityTypes.class, cfg.getNode("entitytype").getString("VILLAGER")));
npc.setVariant(cfg.getNode("variant").getString("NONE"));
npc.setDisplayName(TextSerializers.FORMATTING_CODE.deserialize(cfg.getNode("displayName").getString("VillagerShop")));
String tmp = cfg.getNode("playershop").getString(null);
if (tmp != null && !tmp.isEmpty())
npc.playershopholder=UUID.fromString(tmp);
npc.playershopcontainer=cfg.getNode("stocklocation").getValue(tokenLocationWorld);
return npc;
}
示例8: execute
import org.spongepowered.api.entity.EntityType; //导入依赖的package包/类
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
int amount = ctx.<Integer> getOne("amount").get();
EntityType type = ctx.<EntityType> getOne("mob").get();
if (src instanceof Player)
{
Player player = (Player) src;
if (!Living.class.isAssignableFrom(type.getEntityClass()))
{
player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "The mob type you inputted is not a living entity."));
return CommandResult.success();
}
this.spawnEntity(getSpawnLocFromPlayerLoc(player).add(0, 1, 0), player, type, amount);
player.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Spawned mob(s)!"));
}
else
{
src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /mobspawn!"));
}
return CommandResult.success();
}
示例9: execute
import org.spongepowered.api.entity.EntityType; //导入依赖的package包/类
@Override
@Nonnull
public CommandResult execute(@Nonnull CommandSource src, @Nonnull CommandContext args)
throws CommandException {
SurvivalGame survivalGame = (SurvivalGame) getOrThrow(args, CommandKeys.SURVIVAL_GAME);
Vector3d vector1 = (Vector3d) getOrThrow(args, CommandKeys.VECTOR1);
Vector3d vector2 = (Vector3d) getOrThrow(args, CommandKeys.VECTOR2);
EntityType entityType = (EntityType) getOrThrow(args, CommandKeys.ENTITY_TYPE);
Integer spawnRatePerMinute = (Integer) getOrThrow(args, CommandKeys.SPAWN_RATE_PER_MINUTE);
MobSpawnArea mobSpawnArea = new MobSpawnArea();
mobSpawnArea.addBoundaryVector(vector1);
mobSpawnArea.addBoundaryVector(vector2);
mobSpawnArea.setEntityType(entityType);
mobSpawnArea.setSpawnRatePerMinute(spawnRatePerMinute);
survivalGame.getConfig().getMobSpawnAreas().add(mobSpawnArea);
sendSuccess(src, "Added mob-spawn-area");
return CommandResult.success();
}
示例10: onEntityMovement
import org.spongepowered.api.entity.EntityType; //导入依赖的package包/类
@Listener
public void onEntityMovement(MoveEntityEvent e) {
Transform<World> f = e.getFromTransform();
Transform<World> t = e.getToTransform();
if (f.getLocation().getBlockX() == t.getLocation().getBlockX() &&
t.getLocation().getBlockZ() == f.getLocation().getBlockZ()) {
return;
}
int x = t.getLocation().getBlockX();
int z = t.getLocation().getBlockZ();
if (x == (x >> 4) << 4 && z == (z >> 4) << 4) {
EntityType type = e.getTargetEntity().getType();
if (type == EntityTypes.PLAYER) {
Citizen citizen = playerService.getCitizen(e.getTargetEntity().getUniqueId());
ClaimedArea nextArea = worldService.getClaimedArea(t.getLocation());
worldService.handleChunkChange(citizen, nextArea);
}
}
}
示例11: initialize
import org.spongepowered.api.entity.EntityType; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void initialize() {
Player player = getPlayer();
CreatingJob parent = getParent();
JobManager jobManager = JobsLite.getJobManager();
if (jobManager.createJob((String) parent.getData(DataTypes.NAME).getValue(), (String) parent.getData(DataTypes.DISPLAY_NAME).getValue(),
(Integer) parent.getData(DataTypes.MAX_LEVEL).getValue(), (TextColor) parent.getData(DataTypes.COLOR).getValue(),
(Boolean) parent.getData(DataTypes.SILK_TOUCH).getValue(), (Boolean) parent.getData(DataTypes.WORLD_GEN).getValue(),
(Boolean) parent.getData(DataTypes.BLOCK_DATA).getValue(),
(HashMap<BlockState, Reward>) parent.getData(DataTypes.BREAK_REWARDS).getValue(),
(HashMap<BlockState, Reward>) parent.getData(DataTypes.PLACE_REWARDS).getValue(),
(HashMap<EntityType, Reward>) parent.getData(DataTypes.KILL_REWARDS).getValue())) {
getParent().cancel();
player.sendMessage(messages.getMessage("creation.success"));
} else {
player.sendMessage(messages.getMessage("creation.fail"));
}
}
示例12: spawn
import org.spongepowered.api.entity.EntityType; //导入依赖的package包/类
private Optional<Entity> spawn(EntityType entityType, Entity causeAndLocation) {
Location<World> location = causeAndLocation.getLocation();
EntityUniverse entityUniverse = location.getExtent();
Optional<Entity> optionalEntity = entityUniverse.createEntity(entityType, location.getPosition());
if (optionalEntity.isPresent()) {
Entity newEntity = optionalEntity.get();
Cause cause = Cause.source(EntitySpawnCause.builder().entity(causeAndLocation).type(SpawnTypes.PLUGIN).build()).build();
boolean isSpawned = entityUniverse.spawnEntity(newEntity, cause);
if (!isSpawned) {
logger.error("Could not spawn new Entity: " + entityType.getName());
return Optional.empty();
}
return Optional.of(newEntity);
} else {
logger.error("Could not create new Entity: " + entityType.getName());
return Optional.empty();
}
}
示例13: onMobDamage
import org.spongepowered.api.entity.EntityType; //导入依赖的package包/类
private void onMobDamage(DamageEntityEvent event, Entity target)
{
Entity entitySource = getEntitySource(event);
Player playerSource = null;
if (entitySource instanceof Player)
{
playerSource = ((Player) entitySource);
}
List<Region> regionsAt = manager.getRegionsAt(target.getLocation());
Tristate defaultTo = this.checkSetting(event, playerSource, regionsAt, () -> entityDamageAll, s -> s.entityDamage.all, UNDEFINED);
if (entitySource instanceof Living)
{
defaultTo = this.checkSetting(event, playerSource, regionsAt, () -> entityDamageLiving, s -> s.entityDamage.byLiving, defaultTo);
}
if (entitySource != null)
{
EntityType type = entitySource.getType();
this.checkSetting(event, null, regionsAt, () -> null, s -> s.entityDamage.byEntity.getOrDefault(type, UNDEFINED), defaultTo);
}
}
示例14: invasion
import org.spongepowered.api.entity.EntityType; //导入依赖的package包/类
@Command(desc = "Spawns a mob next to every player on the server")
public void invasion(CommandSource context, String mob)
{
EntityType entityType = em.mob(mob, context.getLocale());
if (entityType == null)
{
i18n.send(context, MessageType.NEGATIVE, "EntityType {input} not found", mob);
return;
}
Sponge.getCauseStackManager().pushCause(context);
for (Player player : Sponge.getServer().getOnlinePlayers())
{
Optional<BlockRayHit<World>> end =
BlockRay.from(player).stopFilter(BlockRay.onlyAirFilter())
.distanceLimit(module.getConfig().command.invasion.distance).build().end();
if (end.isPresent())
{
Location<World> location = end.get().getLocation();
Entity entity = location.getExtent().createEntity(entityType, location.getPosition());
location.getExtent().spawnEntity(entity);
}
}
}
示例15: reload
import org.spongepowered.api.entity.EntityType; //导入依赖的package包/类
public static void reload() {
effects.clear();
ModuleConfig config = Modules.BLOOD.get().getConfig().get();
for (EntityType type : Sponge.getRegistry().getAllOf(CatalogTypes.ENTITY_TYPE)) {
CommentedConfigurationNode node = config.get().getNode("types", type.getId());
try {
BloodEffect effect = node.getValue(TypeToken.of(BloodEffect.class));
if (effect == null) {
continue;
}
effects.put(type, effect);
} catch (ObjectMappingException e) {
ErrorLogger.log(e, "Failed to deserialize bloodeffect for " + type.getId() + " (" + e.getMessage() + ")");
}
}
}