当前位置: 首页>>代码示例>>Java>>正文


Java Converter类代码示例

本文整理汇总了Java中ch.njol.skript.classes.Converter的典型用法代码示例。如果您正苦于以下问题:Java Converter类的具体用法?Java Converter怎么用?Java Converter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Converter类属于ch.njol.skript.classes包,在下文中一共展示了Converter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getConvertedExpr

import ch.njol.skript.classes.Converter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
@Nullable
protected <R> ConvertedExpression<Object, ? extends R> getConvertedExpr(final Class<R>... to) {
	if (isVariableLoop && !isIndex) {
		return new ConvertedExpression<Object, R>(this, (Class<R>) Utils.getSuperType(to), new Converter<Object, R>() {
			@Override
			@Nullable
			public R convert(final Object o) {
				return Converters.convert(o, to);
			}
		});
	} else {
		return super.getConvertedExpr(to);
	}
}
 
开发者ID:nfell2009,项目名称:Skript,代码行数:17,代码来源:ExprLoopValue.java

示例2: get

import ch.njol.skript.classes.Converter; //导入依赖的package包/类
@Override
protected Entity[] get(final Event e, final Entity[] source) {
	return get(source, new Converter<Entity, Entity>() {
		@Override
		@Nullable
		public Entity convert(final Entity p) {
			if (getTime() >= 0 && e instanceof VehicleEnterEvent && p.equals(((VehicleEnterEvent) e).getEntered()) && !Delay.isDelayed(e)) {
				return ((VehicleEnterEvent) e).getVehicle();
			}
			if (getTime() >= 0 && e instanceof VehicleExitEvent && p.equals(((VehicleExitEvent) e).getExited()) && !Delay.isDelayed(e)) {
				return ((VehicleExitEvent) e).getVehicle();
			}
			return p.getVehicle();
		}
	});
}
 
开发者ID:nfell2009,项目名称:Skript,代码行数:17,代码来源:ExprVehicle.java

示例3: get

import ch.njol.skript.classes.Converter; //导入依赖的package包/类
@Override
protected Integer[] get(final Event e, final ItemType[] source) {
	final Enchantment ench = enchantment.getSingle(e);
	if (ench == null)
		return new Integer[0];
	return get(source, new Converter<ItemType, Integer>() {
		@Override
		@Nullable
		public Integer convert(final ItemType i) {
			final Map<Enchantment, Integer> enchs = i.getEnchantments();
			if (enchs == null)
				return Integer.valueOf(0);
			final Integer l = enchs.get(ench);
			return l == null ? Integer.valueOf(0) : l;
		}
	});
}
 
开发者ID:nfell2009,项目名称:Skript,代码行数:18,代码来源:ExprEnchantmentLevel.java

示例4: get

import ch.njol.skript.classes.Converter; //导入依赖的package包/类
@Override
protected Entity[] get(final Event e, final LivingEntity[] source) {
	return get(source, new Converter<LivingEntity, Entity>() {
		@Override
		@Nullable
		public Entity convert(final LivingEntity en) {
			if (getTime() >= 0 && e instanceof EntityTargetEvent && en.equals(((EntityTargetEvent) e).getEntity()) && !Delay.isDelayed(e)) {
				final Entity t = ((EntityTargetEvent) e).getTarget();
				if (t == null || type != null && !type.isInstance(t))
					return null;
				return t;
			}
			return Utils.getTarget(en, type);
		}
	});
}
 
开发者ID:nfell2009,项目名称:Skript,代码行数:17,代码来源:ExprTarget.java

示例5: init

import ch.njol.skript.classes.Converter; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) {
	if (exprs.length > 0) {
		setExpr(new ConvertedExpression<Location, Block>(Direction.combine((Expression<? extends Direction>) exprs[0], (Expression<? extends Location>) exprs[1]), Block.class, new Converter<Location, Block>() {
			@Override
			public Block convert(final Location l) {
				return l.getBlock();
			}
		}));
		return true;
	} else {
		setExpr(new EventValueExpression<Block>(Block.class));
		return ((EventValueExpression<Block>) getExpr()).init();
	}
}
 
开发者ID:nfell2009,项目名称:Skript,代码行数:17,代码来源:ExprBlock.java

示例6: get

import ch.njol.skript.classes.Converter; //导入依赖的package包/类
@Override
protected Entity[] get(final Event e, final Entity[] source) {
	return get(source, new Converter<Entity, Entity>() {
		@Override
		@Nullable
		public Entity convert(final Entity v) {
			if (getTime() >= 0 && e instanceof VehicleEnterEvent && v.equals(((VehicleEnterEvent) e).getVehicle()) && !Delay.isDelayed(e)) {
				return ((VehicleEnterEvent) e).getEntered();
			}
			if (getTime() >= 0 && e instanceof VehicleExitEvent && v.equals(((VehicleExitEvent) e).getVehicle()) && !Delay.isDelayed(e)) {
				return ((VehicleExitEvent) e).getExited();
			}
			return v.getPassenger();
		}
	});
}
 
开发者ID:nfell2009,项目名称:Skript,代码行数:17,代码来源:ExprPassenger.java

示例7: get

import ch.njol.skript.classes.Converter; //导入依赖的package包/类
@Override
protected Object[] get(final Event e, final Object[] source) {
	return get(source, new Converter<Object, Object>() {
		@Override
		@Nullable
		public Object convert(final Object o) {
			final Number a = amount.getSingle(e);
			if (a == null)
				return null;
			if (o instanceof ItemStack) {
				final ItemStack is = ((ItemStack) o).clone();
				is.setAmount(a.intValue());
				return is;
			} else {
				final EntityType t = ((EntityType) o).clone();
				t.amount = a.intValue();
				return t;
			}
		}
	});
}
 
开发者ID:nfell2009,项目名称:Skript,代码行数:22,代码来源:ExprXOf.java

示例8: getConvertedGetter

import ch.njol.skript.classes.Converter; //导入依赖的package包/类
@Nullable
private final static <E extends Event, F, T> Getter<? extends T, ? super E> getConvertedGetter(final EventValueInfo<E, F> i, final Class<T> to, final boolean checkInstanceOf) {
	final Converter<? super F, ? extends T> c = Converters.getConverter(i.c, to);
	if (c == null)
		return null;
	return new Getter<T, E>() {
		@Override
		@Nullable
		public T get(final E e) {
			if (checkInstanceOf && !i.event.isInstance(e))
				return null;
			final F f = i.getter.get(e);
			if (f == null)
				return null;
			return c.convert(f);
		}
	};
}
 
开发者ID:nfell2009,项目名称:Skript,代码行数:19,代码来源:EventValues.java

示例9: renameAll

import ch.njol.skript.classes.Converter; //导入依赖的package包/类
/**
 * @param directory
 * @param renamer Renames files. Return null to leave a file as-is.
 * @return A collection of all changed files (with their new names)
 * @throws IOException If renaming one of the files caused an IOException. Some files might have been renamed already.
 */
public final static Collection<File> renameAll(final File directory, final Converter<String, String> renamer) throws IOException {
	final Collection<File> changed = new ArrayList<File>();
	for (final File f : directory.listFiles()) {
		if (f.isDirectory()) {
			changed.addAll(renameAll(f, renamer));
		} else {
			final String name = f.getName();
			if (name == null)
				continue;
			final String newName = renamer.convert(name);
			if (newName == null)
				continue;
			final File newFile = new File(f.getParent(), newName);
			move(f, newFile, false);
			changed.add(newFile);
		}
	}
	return changed;
}
 
开发者ID:nfell2009,项目名称:Skript,代码行数:26,代码来源:FileUtils.java

示例10: load

import ch.njol.skript.classes.Converter; //导入依赖的package包/类
public static void load() {
    Converters.registerConverter(World.class, WorldCreator.class, new Converter<World, WorldCreator>() {
        @Override
        public WorldCreator convert(World world) {
            WorldCreator worldCreator = new WorldCreator(world.getName());
            worldCreator.copy(world);
            worldCreator.type(world.getWorldType());
            worldCreator.generateStructures(world.canGenerateStructures());
            worldCreator.generatorSettings("");
            return worldCreator;
        }
    });
    Registration.registerEffect(EffCreateWorld.class, "create [new] world named %string%[( with|,)] [(dim[ension]|env[ironment]) %-dimension%][,] [seed %-string%][,] [type %-worldtype%][,] [gen[erator] %-string%][,] [gen[erator] settings %-string%][,] [struct[ures] %-boolean%]")
            .document("Create World", "1.6.4", "Creates a world with the specified name, optionally with a few settings. "
                    + "See the environment type and worldtype type for valid environments and worldtypes respectively. "
                    + "Generator settings can either be custom superflat codes or customized world codes (for customized world codes the worldtype needs to be 'customized').")
            .example("create world named \"Example\" with dimension nether, seed \"12345\", type flat, structures false");
    Registration.registerEffect(EffCreateWorldUsingCreator.class, "create [new] world [named %-string%] using %creator%")
            .document("Create World using Creator", "1.8", "Creates a world using the specified creator, optionally specifying the world's name (this is required if the creator doesn't specify a name)."
                    + "See the creator expressions for more information on how to specify the world's name and other settings. "
                    + "If a world with the name (specified or from the creator) already exists, this will just load that world instead of creating a new one.");
    Registration.registerEffect(EffUnloadWorld.class, "unload %world% [save %-boolean%]")
            .document("Unload World", "Before 1.4", "Unloads the specified world. You can specify whether or not to save before unloading (this defaults to true).");
    Registration.registerEffect(EffDeleteWorld.class, "delete %world%")
            .document("Delete World", "Before 1.4", "Deletes the specified world. The specified world must be loaded in order to be deleted.");
    Registration.registerEffect(EffDuplicateWorld.class, "duplicate %world% (with|using) name %string%")
            .document("Duplicate World", "Before 1.4", "Creates a copy of the specified world using the specified string as a name. The specified world must be loaded in order for this to work.");
    Registration.registerExpression(ExprCurrentWorlds.class,World.class, ExpressionType.SIMPLE,"[all] current worlds")
            .document("All Current Worlds", "1.8", "An expression for all worlds that are currently loaded. "
                    + "This differs from Skript's 'all worlds' expression in that it still parses as being a list even if there is only one world at the time of parsing.");

    loadWorldLoader();
}
 
开发者ID:MundoSK,项目名称:MundoSK,代码行数:34,代码来源:WorldManagementMundo.java

示例11: init

import ch.njol.skript.classes.Converter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected boolean init(final Literal<?>[] exprs, final int matchedPattern, final ParseResult parseResult) {
	if (exprs.length > 0 && exprs[0] != null) {
		if ((types = Converters.convert(((Literal<ItemType>) exprs[0]).getAll(), ItemType.class, new Converter<ItemType, ItemType>() {
			@Override
			@Nullable
			public ItemType convert(ItemType t) {
				t = t.getBlock().clone();
				final Iterator<ItemData> iter = t.iterator();
				while (iter.hasNext()) {
					final int id = iter.next().getId();
					if (id <= 0 || id > Skript.MAXBLOCKID)
						iter.remove();
				}
				if (t.numTypes() == 0)
					return null;
				t.setAmount(-1);
				t.setAll(false);
				t.clearEnchantments();
				return t;
			}
		})).length == 0) {
			Skript.error(m_not_a_block_error.toString());
			return false;
		}
	}
	return true;
}
 
开发者ID:nfell2009,项目名称:Skript,代码行数:30,代码来源:FallingBlockData.java

示例12: get

import ch.njol.skript.classes.Converter; //导入依赖的package包/类
@Override
protected Long[] get(final Event e, final Number[] source) {
	return get(source, new Converter<Number, Long>() {
		@SuppressWarnings("null")
		@Override
		public Long convert(final Number n) {
			if (n instanceof Integer)
				return Long.valueOf(n.longValue());
			else if (n instanceof Long)
				return (Long) n;
			return Long.valueOf(action == -1 ? Math2.floor(n.doubleValue()) : action == 0 ? Math2.round(n.doubleValue()) : Math2.ceil(n.doubleValue()));
		}
	});
}
 
开发者ID:nfell2009,项目名称:Skript,代码行数:15,代码来源:ExprRound.java

示例13: get

import ch.njol.skript.classes.Converter; //导入依赖的package包/类
@Override
protected String[] get(final Event e, final String[] source) {
	return get(source, new Converter<String, String>() {
		@Override
		public String convert(final String s) {
			return color ? Utils.replaceChatStyles(s) : "" + ChatColor.stripColor(s);
		}
	});
}
 
开发者ID:nfell2009,项目名称:Skript,代码行数:10,代码来源:ExprColoured.java

示例14: get

import ch.njol.skript.classes.Converter; //导入依赖的package包/类
@Override
protected Integer[] get(final Event e, final Player[] source) {
	return super.get(source, new Converter<Player, Integer>() {
		@SuppressWarnings("null")
		@Override
		public Integer convert(final Player p) {
			if (e instanceof PlayerLevelChangeEvent && ((PlayerLevelChangeEvent) e).getPlayer() == p && !Delay.isDelayed(e)) {
				return getTime() < 0 ? ((PlayerLevelChangeEvent) e).getOldLevel() : ((PlayerLevelChangeEvent) e).getNewLevel();
			}
			return p.getLevel();
		}
	});
}
 
开发者ID:nfell2009,项目名称:Skript,代码行数:14,代码来源:ExprLevel.java

示例15: get

import ch.njol.skript.classes.Converter; //导入依赖的package包/类
@Override
protected Chunk[] get(final Event e, final Location[] source) {
	return get(source, new Converter<Location, Chunk>() {
		@SuppressWarnings("null")
		@Override
		public Chunk convert(final Location l) {
			return l.getChunk();
		}
	});
}
 
开发者ID:nfell2009,项目名称:Skript,代码行数:11,代码来源:ExprChunk.java


注:本文中的ch.njol.skript.classes.Converter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。