本文整理汇总了Java中org.apache.commons.lang.Validate类的典型用法代码示例。如果您正苦于以下问题:Java Validate类的具体用法?Java Validate怎么用?Java Validate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Validate类属于org.apache.commons.lang包,在下文中一共展示了Validate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tabComplete
import org.apache.commons.lang.Validate; //导入依赖的package包/类
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args)
{
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1)
{
return StringUtil.copyPartialMatches(args[0], COMMANDS, new ArrayList<String>(COMMANDS.size()));
}
if (((args.length == 2) && "get".equalsIgnoreCase(args[0])) || "set".equalsIgnoreCase(args[0]))
{
return StringUtil.copyPartialMatches(args[1], MinecraftServer.getServer().tileEntityConfig.getSettings().keySet(), new ArrayList<String>(MinecraftServer.getServer().tileEntityConfig.getSettings().size()));
}
return ImmutableList.of();
}
示例2: enable
import org.apache.commons.lang.Validate; //导入依赖的package包/类
/**
* Enables NameTagChanger and creates necessary packet handlers.
* Is done automatically by the constructor, so only use this method
* if the disable() method has previously been called.
*/
public void enable() {
if (plugin == null) {
return;
}
if (!ReflectUtil.isVersionHigherThan(1, 7, 10)) {
printMessage("NameTagChanger has detected that you are running 1.7 or lower. This probably means that NameTagChanger will not work or throw errors, but you are still free to try and use it.\nIf you are not a developer, please consider contacting the developer of " + plugin.getName() + " and informing them about this message.");
}
ConfigurationSerialization.registerClass(Skin.class);
Validate.isTrue(!enabled, "NameTagChanger is already enabled");
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null) {
packetHandler = new ProtocolLibPacketHandler(plugin);
} else {
packetHandler = new ChannelPacketHandler(plugin);
}
enabled = true;
Metrics metrics = new Metrics(plugin);
metrics.addCustomChart(new Metrics.SimplePie("packet_implementation", () -> packetHandler instanceof ProtocolLibPacketHandler ? "ProtocolLib" : "ChannelInjector"));
}
示例3: sendSignChange
import org.apache.commons.lang.Validate; //导入依赖的package包/类
@Override
public void sendSignChange(Location loc, String[] lines) {
if (getHandle().playerNetServerHandler == null) {
return;
}
if (lines == null) {
lines = new String[4];
}
Validate.notNull(loc, "Location can not be null");
if (lines.length < 4) {
throw new IllegalArgumentException("Must have at least 4 lines");
}
// Limit to 15 chars per line and set null lines to blank
String[] astring = CraftSign.sanitizeLines(lines);
getHandle().playerNetServerHandler.sendPacket(new S33PacketUpdateSign(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), astring));
}
示例4: ParticleShapeDefinition
import org.apache.commons.lang.Validate; //导入依赖的package包/类
/**
* Construct a new ParticleShapeDefinition with a given location, and mathmatical equations
* for both the x and z axis
*
* @param initialLocation the initial starting location
* @param xExpression the expression for the x axis
* @param zExpression the expression for the y axis
*/
public ParticleShapeDefinition(Location initialLocation, String xExpression, String zExpression) {
Validate.notNull(initialLocation, "Null initial locations are not supported");
Validate.notEmpty(xExpression, "The x axis expression cannot be null or empty");
Validate.notEmpty(zExpression, "The z axis expression cannot be null or empty");
this.variables.put("x", 0.0);
this.variables.put("z", 0.0);
this.variables.put("t", 0.0);
this.variables.put("theta", 0.0);
this.initialLocation = initialLocation;
this.world = initialLocation.getWorld();
this.xExpression = MathUtils.parseExpression(xExpression, variables);
this.zExpression = MathUtils.parseExpression(zExpression, variables);
}
示例5: hidePlayer
import org.apache.commons.lang.Validate; //导入依赖的package包/类
public void hidePlayer(Player player) {
Validate.notNull(player, "hidden player cannot be null");
if (getHandle().playerNetServerHandler == null) return;
if (equals(player)) return;
if (hiddenPlayers.contains(player.getUniqueId())) return;
hiddenPlayers.add(player.getUniqueId());
//remove this player from the hidden player's EntityTrackerEntry
net.minecraft.entity.EntityTracker tracker = ((net.minecraft.world.WorldServer) entity.worldObj).theEntityTracker;
net.minecraft.entity.player.EntityPlayerMP other = ((CraftPlayer) player).getHandle();
net.minecraft.entity.EntityTrackerEntry entry = (net.minecraft.entity.EntityTrackerEntry) tracker.trackedEntityIDs.lookup(other.getEntityId());
if (entry != null) {
entry.removePlayerFromTracker(getHandle());
}
//remove the hidden player from this player user list
getHandle().playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S38PacketPlayerListItem(player.getPlayerListName(), false, 9999));
}
示例6: createNode
import org.apache.commons.lang.Validate; //导入依赖的package包/类
/**
* @param email Mail of the new user.
* @param username Username of the new user.
* @param first_name First name of the new user.
* @param last_name Last name of the new user.
* @param password Password of the new user OPTIONAL. (Leave blank will be generated by the panel randomly)
* @param root_admin Set the root admin role of the new user.
* @return if success it return the ID of the new user.
*/
public String createNode(String email, String username, String first_name, String last_name, String password, boolean root_admin){
Validate.notEmpty(email, "The MAIL is required");
Validate.notEmpty(username, "The USERNAME is required");
Validate.notEmpty(first_name, "The FIRST_NAME is required");
Validate.notEmpty(last_name, "The LAST_NAME is required");
Validate.notNull(root_admin, "The ROOT_ADMIN Boolean is required");
int admin = (root_admin) ? 1 : 0;
return call(main.getMainURL() + Methods.USERS_CREATE_USER.getURL(),
"email="+email+
"&username="+username+
"&name_first="+first_name+
"&name_last="+last_name+
"&password="+password+
"&root_admin="+admin);
}
示例7: addEffects
import org.apache.commons.lang.Validate; //导入依赖的package包/类
public void addEffects(FireworkEffect...effects) {
Validate.notNull(effects, "Effects cannot be null");
if (effects.length == 0) {
return;
}
List<FireworkEffect> list = this.effects;
if (list == null) {
list = this.effects = new ArrayList<FireworkEffect>();
}
for (FireworkEffect effect : effects) {
Validate.notNull(effect, "Effect cannot be null");
list.add(effect);
}
}
示例8: getAccessibleMethod
import org.apache.commons.lang.Validate; //导入依赖的package包/类
/**
* 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问.
* 如向上转型到Object仍无法找到, 返回null.
* 匹配函数名+参数类型。
* <p>
* 用于方法需要被多次调用的情况. 先使用本函数先取得Method,然后调用Method.invoke(Object obj, Object... args)
*/
public static Method getAccessibleMethod(final Object obj, final String methodName,
final Class<?>... parameterTypes) {
Validate.notNull(obj, "object can't be null");
Validate.notEmpty(methodName, "methodName can't be blank");
for (Class<?> searchType = obj.getClass(); searchType != Object.class; searchType = searchType.getSuperclass()) {
try {
Method method = searchType.getDeclaredMethod(methodName, parameterTypes);
makeAccessible(method);
return method;
} catch (NoSuchMethodException e) {
// Method不在当前类定义,继续向上转型
continue;// new add
}
}
return null;
}
示例9: removeCustomEffect
import org.apache.commons.lang.Validate; //导入依赖的package包/类
public boolean removeCustomEffect(PotionEffectType type) {
Validate.notNull(type, "Potion effect type must not be null");
if (!hasCustomEffects()) {
return false;
}
boolean changed = false;
Iterator<PotionEffect> iterator = customEffects.iterator();
while (iterator.hasNext()) {
PotionEffect effect = iterator.next();
if (effect.getType() == type) {
iterator.remove();
changed = true;
}
}
return changed;
}
示例10: addBan
import org.apache.commons.lang.Validate; //导入依赖的package包/类
@Override
public org.bukkit.BanEntry addBan(String target, String reason, Date expires, String source) {
Validate.notNull(target, "Ban target cannot be null");
GameProfile profile = MinecraftServer.getServer().func_152358_ax().func_152655_a(target);
if (profile == null) {
return null;
}
UserListBansEntry entry = new UserListBansEntry(profile, new Date(),
StringUtils.isBlank(source) ? null : source, expires,
StringUtils.isBlank(reason) ? null : reason);
list.func_152687_a(entry);
try {
list.func_152678_f();
} catch (IOException ex) {
MinecraftServer.getLogger().error("Failed to save banned-players.json, " + ex.getMessage());
}
return new CraftProfileBanEntry(profile, entry, list);
}
示例11: getPlayer
import org.apache.commons.lang.Validate; //导入依赖的package包/类
@Override
@Deprecated
public Player getPlayer(final String name) {
Validate.notNull(name, "Name cannot be null");
Player found = null;
String lowerName = name.toLowerCase();
int delta = Integer.MAX_VALUE;
for (Player player : getOnlinePlayers()) {
if (player.getName().toLowerCase().startsWith(lowerName)) {
int curDelta = player.getName().length() - lowerName.length();
if (curDelta < delta) {
found = player;
delta = curDelta;
}
if (curDelta == 0) break;
}
}
return found;
}
示例12: matchPlayer
import org.apache.commons.lang.Validate; //导入依赖的package包/类
@Override
@Deprecated
public List<Player> matchPlayer(String partialName) {
Validate.notNull(partialName, "PartialName cannot be null");
List<Player> matchedPlayers = new ArrayList<Player>();
for (Player iterPlayer : this.getOnlinePlayers()) {
String iterPlayerName = iterPlayer.getName();
if (partialName.equalsIgnoreCase(iterPlayerName)) {
// Exact match
matchedPlayers.clear();
matchedPlayers.add(iterPlayer);
break;
}
if (iterPlayerName.toLowerCase().contains(partialName.toLowerCase())) {
// Partial match
matchedPlayers.add(iterPlayer);
}
}
return matchedPlayers;
}
示例13: dispatchCommand
import org.apache.commons.lang.Validate; //导入依赖的package包/类
@Override
public boolean dispatchCommand(CommandSender sender, String commandLine) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(commandLine, "CommandLine cannot be null");
if (commandMap.dispatch(sender, commandLine)) {
return true;
}
// Cauldron start - handle vanilla commands called from plugins
if(sender instanceof ConsoleCommandSender) {
craftCommandMap.setVanillaConsoleSender(this.console);
}
return this.dispatchVanillaCommand(sender, commandLine);
// Cauldron end
}
示例14: applyToBattle
import org.apache.commons.lang.Validate; //导入依赖的package包/类
/**
* Apply this templates data to an EnderDragonBattle object
*
* @param nmsAbstract an instance of the NMSAbstract interface
* @param dragon the dragon to modify
* @param battle the battle to modify
*/
public void applyToBattle(NMSAbstract nmsAbstract, EnderDragon dragon, DragonBattle battle) {
Validate.notNull(nmsAbstract, "Instance of NMSAbstract cannot be null. See DragonEggDrop#getNMSAbstract()");
Validate.notNull(dragon, "Ender Dragon cannot be null");
Validate.notNull(battle, "Instance of DragonBattle cannot be null");
if (name != null) {
dragon.setCustomName(name);
battle.setBossBarTitle(name);
}
battle.setBossBarStyle(barStyle, barColour);
this.attributes.forEach((a, v) -> {
AttributeInstance attribute = dragon.getAttribute(a);
if (attribute != null) {
attribute.setBaseValue(v);
}
});
// Set health... max health attribute doesn't do that for me. -,-
if (attributes.containsKey(Attribute.GENERIC_MAX_HEALTH)) {
dragon.setHealth(attributes.get(Attribute.GENERIC_MAX_HEALTH));
}
}
示例15: HandlingEvent
import org.apache.commons.lang.Validate; //导入依赖的package包/类
/**
* @param cargo cargo
* @param completionTime completion time, the reported time that the event actually happened (e.g. the receive took place).
* @param registrationTime registration time, the time the message is received
* @param type type of event
* @param location where the event took place
*/
public HandlingEvent(final Cargo cargo,
final Date completionTime,
final Date registrationTime,
final HandlingEventType type,
final Location location) {
Validate.notNull(cargo, "Cargo is required");
Validate.notNull(completionTime, "Completion time is required");
Validate.notNull(registrationTime, "Registration time is required");
Validate.notNull(type, "Handling event type is required");
Validate.notNull(location, "Location is required");
if (type.requiresVoyage()) {
throw new IllegalArgumentException("Voyage is required for event type " + type);
}
this.completionTime = (Date) completionTime.clone();
this.registrationTime = (Date) registrationTime.clone();
this.type = type;
this.location = location;
this.cargo = cargo;
this.voyage = null;
}