Java Code Examples for org.apache.commons.lang.Validate

The following are top voted examples for showing how to use org.apache.commons.lang.Validate. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: NameTagChanger   File: NameTagChanger.java   View source code 6 votes vote down vote up
/**
 * 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"));
}
 
Example 2
Project: Uranium   File: CraftPlayer.java   View source code 6 votes vote down vote up
@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));
}
 
Example 3
Project: DragonEggDrop   File: ParticleShapeDefinition.java   View source code 6 votes vote down vote up
/**
 * 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);
}
 
Example 4
Project: Uranium   File: CraftPlayer.java   View source code 6 votes vote down vote up
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));
}
 
Example 5
Project: Pterodactyl-JAVA-API   File: POSTMethods.java   View source code 6 votes vote down vote up
/**
 * @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);
}
 
Example 6
Project: Uranium   File: CraftMetaFirework.java   View source code 6 votes vote down vote up
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);
    }
}
 
Example 7
Project: pds   File: Reflections.java   View source code 6 votes vote down vote up
/**
 * 循环向上转型, 获取对象的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;
}
 
Example 8
Project: Uranium   File: CraftMetaPotion.java   View source code 6 votes vote down vote up
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;
}
 
Example 9
Project: Uranium   File: CraftProfileBanList.java   View source code 6 votes vote down vote up
@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);
}
 
Example 10
Project: Uranium   File: CraftServer.java   View source code 6 votes vote down vote up
@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;
}
 
Example 11
Project: Uranium   File: CraftServer.java   View source code 6 votes vote down vote up
@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;
}
 
Example 12
Project: Uranium   File: CraftServer.java   View source code 6 votes vote down vote up
@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
}
 
Example 13
Project: DragonEggDrop   File: DragonTemplate.java   View source code 6 votes vote down vote up
/**
 * 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));
	}
}
 
Example 14
Project: living-documentation   File: HandlingEvent.java   View source code 6 votes vote down vote up
/**
 * @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;
}
 
Example 15
Project: Uranium   File: TileEntityCommand.java   View source code 6 votes vote down vote up
@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();
}
 
Example 16
Project: zlevels   File: Yaml.java   View source code 5 votes vote down vote up
/**
 * Creates a new {@link Yaml}, loading from the given reader.
 * <p/>
 * Any errors loading the Configuration will be logged and then ignored.
 * If the specified input is not a valid config, a blank config will be
 * returned.
 *
 * @param reader input
 * @return resulting yaml
 * @throws IllegalArgumentException Thrown if stream is null
 */
public static Yaml loadConfiguration(Reader reader) {
    Validate.notNull(reader, "Stream cannot be null");

    Yaml config = new Yaml();

    try {
        config.load(reader);
    } catch (Exception ex) {
        ZLogger.warn("Cannot load yaml from stream");
    }

    return config;
}
 
Example 17
Project: CloudLand-Server   File: ShapelessRecipe.java   View source code 5 votes vote down vote up
/**
 * Adds multiples of the specified ingredient.
 *
 * @param count How many to add (can't be more than 9!)
 * @param ingredient The ingredient to add.
 */
public ShapelessRecipe addIngredient(int count, ItemPrototype ingredient) {
    Validate.isTrue(ingredients.size() + count <= 9, "Shapeless recipes cannot have more than 9 ingredients");

    while (count-- > 0) {
        ingredients.add(ingredient.newItemInstance(1));
    }
    return this;
}
 
Example 18
Project: pine-commons   File: InventoryBase.java   View source code 5 votes vote down vote up
/**
 * Add an item to the inventory.
 *
 * @param slot The slot.
 * @param item The item.
 */
public void addItem(int slot, ItemStack item) {
    Validate.isTrue(slot >= 0 && slot <= slots);
    Validate.notNull(item);

    items.put(slot, item);
}
 
Example 19
Project: SurvivalAPI   File: PotentialHeartsModule.java   View source code 5 votes vote down vote up
/**
 * Constructor
 *
 * @param plugin Parent plugin
 * @param api API instance
 * @param moduleConfiguration Module configuration
 */
public PotentialHeartsModule(SurvivalPlugin plugin, SurvivalAPI api, Map<String, Object> moduleConfiguration)
{
    super(plugin, api, moduleConfiguration);
    Validate.notNull(moduleConfiguration, "Configuration cannot be null!");

    this.maxHealth = (double) moduleConfiguration.get("max-health");
}
 
Example 20
Project: Uranium   File: CraftTeam.java   View source code 5 votes vote down vote up
public void setSuffix(String suffix) throws IllegalStateException, IllegalArgumentException {
    Validate.notNull(suffix, "Suffix cannot be null");
    Validate.isTrue(suffix.length() <= 32, "Suffix '" + suffix + "' is longer than the limit of 32 characters");
    CraftScoreboard scoreboard = checkState();

    team.setNameSuffix(suffix);
}
 
Example 21
Project: SurvivalAPI   File: RottenPotionsModule.java   View source code 5 votes vote down vote up
/**
 * Constructor
 *
 * @param plugin Parent plugin
 * @param api API instance
 * @param moduleConfiguration Module configuration
 */
public RottenPotionsModule(SurvivalPlugin plugin, SurvivalAPI api, Map<String, Object> moduleConfiguration)
{
    super(plugin, api, moduleConfiguration);
    Validate.notNull(moduleConfiguration, "Configuration cannot be null!");

    this.random = new Random();
}
 
Example 22
Project: Uranium   File: CraftPlayer.java   View source code 5 votes vote down vote up
@Override
public void awardAchievement(Achievement achievement) {
    Validate.notNull(achievement, "Achievement cannot be null");
    if (achievement.hasParent() && !hasAchievement(achievement.getParent())) {
        awardAchievement(achievement.getParent());
    }
    getHandle().func_147099_x().func_150873_a(getHandle(), CraftStatistic.getNMSAchievement(achievement), 1);
    getHandle().func_147099_x().func_150884_b(getHandle());
}
 
Example 23
Project: geode-examples   File: Example.java   View source code 5 votes vote down vote up
private static void adminUserCanPutAndGetEverywhere() throws Exception {
  String valueFromRegion;
  try (Example example = new Example("superUser")) {
    // All puts and gets should pass
    example.region1.put(AUTHOR_ABERCROMBIE, BOOK_BY_ABERCROMBIE);
    example.region2.put(AUTHOR_GROSSMAN, BOOK_BY_GROSSMAN);

    valueFromRegion = example.region1.get(AUTHOR_ABERCROMBIE);
    Validate.isTrue(BOOK_BY_ABERCROMBIE.equals(valueFromRegion));

    valueFromRegion = example.region2.get(AUTHOR_GROSSMAN);
    Validate.isTrue(BOOK_BY_GROSSMAN.equals(valueFromRegion));
  }
}
 
Example 24
Project: Chambers   File: BukkitCommand.java   View source code 5 votes vote down vote up
@Override
public java.util.List<String> tabComplete(CommandSender sender, String alias, String[] args) throws CommandException, IllegalArgumentException {
	Validate.notNull(sender, "Sender cannot be null");
	Validate.notNull(args, "Arguments cannot be null");
	Validate.notNull(alias, "Alias cannot be null");

	List<String> completions = null;
	try {
		if (completer != null) {
			completions = completer.onTabComplete(sender, this, alias, args);
		}
		if (completions == null && executor instanceof TabCompleter) {
			completions = ((TabCompleter) executor).onTabComplete(sender, this, alias, args);
		}
	} catch (Throwable ex) {
		StringBuilder message = new StringBuilder();
		message.append("Unhandled exception during tab completion for command '/").append(alias).append(' ');
		for (String arg : args) {
			message.append(arg).append(' ');
		}
		message.deleteCharAt(message.length() - 1).append("' in plugin ")
				.append(owningPlugin.getDescription().getFullName());
		throw new CommandException(message.toString(), ex);
	}

	if (completions == null) {
		return super.tabComplete(sender, alias, args);
	}
	return completions;
}
 
Example 25
Project: living-documentation   File: Cargo.java   View source code 5 votes vote down vote up
/**
 * Attach a new itinerary to this cargo.
 *
 * @param itinerary an itinerary. May not be null.
 */
public void assignToRoute(final Itinerary itinerary) {
    Validate.notNull(itinerary, "Itinerary is required for assignment");

    this.itinerary = itinerary;
    // Handling consistency within the Cargo aggregate synchronously
    this.delivery = delivery.updateOnRouting(this.routeSpecification, this.itinerary);
}
 
Example 26
Project: EchoPet   File: DynamicPluginCommand.java   View source code 5 votes vote down vote up
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws CommandException, IllegalArgumentException {
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");

    List<String> completions = null;
    try {
        if (completer != null) {
            completions = completer.onTabComplete(sender, this, alias, args);
        }
        if (completions == null && owner instanceof TabCompleter) {
            completions = ((TabCompleter) owner).onTabComplete(sender, this, alias, args);
        }
    } catch (Throwable ex) {
        StringBuilder message = new StringBuilder();
        message.append("Unhandled exception during tab completion for command '/").append(alias).append(' ');
        for (String arg : args) {
            message.append(arg).append(' ');
        }
        message.deleteCharAt(message.length() - 1).append("' in plugin ").append(EchoPet.getPlugin().getDescription().getFullName());
        throw new CommandException(message.toString(), ex);
    }

    if (completions == null) {
        return super.tabComplete(sender, alias, args);
    }
    return completions;
}
 
Example 27
Project: SurvivalAPI   File: RapidFoodModule.java   View source code 5 votes vote down vote up
/**
 * Constructor
 *
 * @param plugin Parent plugin
 * @param api API instance
 * @param moduleConfiguration Module configuration
 */
public RapidFoodModule(SurvivalPlugin plugin, SurvivalAPI api, Map<String, Object> moduleConfiguration)
{
    super(plugin, api, moduleConfiguration);
    Validate.notNull(moduleConfiguration, "Configuration cannot be null!");

    this.drops = (Map<EntityType, List<ConfigurationBuilder.IRapidFoodHook>>) moduleConfiguration.get("drops");
    this.random = new Random();
}
 
Example 28
Project: obevo   File: DbChecksumManagerImpl.java   View source code 5 votes vote down vote up
private void applyChecksumDiffs(ImmutableCollection<ChecksumBreak> checksumBreaks) {
    for (ChecksumBreak checksumBreak : checksumBreaks) {
        if (checksumBreak.getExistingChecksum() == null) {
            Validate.notNull(checksumBreak.getNewChecksum());
            dbChecksumDao.persistEntry(checksumBreak.getNewChecksum());
        } else if (checksumBreak.getNewChecksum() == null) {
            Validate.notNull(checksumBreak.getExistingChecksum());
            dbChecksumDao.deleteEntry(checksumBreak.getExistingChecksum());
        } else {
            dbChecksumDao.persistEntry(checksumBreak.getNewChecksum());
        }
    }
}
 
Example 29
Project: NameTagChanger   File: NameTagChanger.java   View source code 5 votes vote down vote up
/**
 * Gets the skin from a game profile, if one exists, otherwise Skin.EMPTY_SKIN is returned.
 *
 * @param profile the profile
 * @return the skin of the profile
 */
public Skin getSkinFromGameProfile(GameProfileWrapper profile) {
    Validate.isTrue(enabled, "NameTagChanger is disabled");
    Validate.notNull(profile, "profile cannot be null");
    if (profile.getProperties().containsKey("textures")) {
        GameProfileWrapper.PropertyWrapper property = Iterables.getFirst(profile.getProperties().get("textures"), null);
        if (property == null) {
            return Skin.EMPTY_SKIN;
        } else {
            return new Skin(profile.getUUID(), property.getValue(), property.getSignature());
        }
    } else {
        return Skin.EMPTY_SKIN;
    }
}
 
Example 30
Project: Uranium   File: CraftThrownPotion.java   View source code 5 votes vote down vote up
public void setItem(ItemStack item) {
    // The ItemStack must not be null.
    Validate.notNull(item, "ItemStack cannot be null.");

    // The ItemStack must be a potion.
    Validate.isTrue(item.getType() == Material.POTION, "ItemStack must be a potion. This item stack was " + item.getType() + ".");

    getHandle().potionDamage = CraftItemStack.asNMSCopy(item);
}
 
Example 31
Project: AlphaLibary   File: RayParticleForm.java   View source code 5 votes vote down vote up
public RayParticleForm(Effect effect, EffectData<?> effectData, Location location, Vector direction, double dense, double lenght) {
    super(location, direction, dense, lenght, null);

    if (effectData != null)
        Validate.isTrue(effect.getData() != null && effect.getData().isAssignableFrom(effectData.getDataValue().getClass()), "Wrong kind of effectData for this effect!");
    else {
        Validate.isTrue(effect.getData() == null, "Wrong kind of effectData for this effect!");
        effectData = new EffectData<>(null);
    }

    EffectData<?> finalEffectData = effectData;

    setAction((p, loc) -> p.playEffect(loc, effect, finalEffectData.getDataValue()));
}
 
Example 32
Project: Uranium   File: CraftFireball.java   View source code 5 votes vote down vote up
public void setDirection(Vector direction) {
    Validate.notNull(direction, "Direction can not be null");
    double x = direction.getX();
    double y = direction.getY();
    double z = direction.getZ();
    double magnitude = (double) MathHelper.sqrt_double(x * x + y * y + z * z);
    getHandle().accelerationX = x / magnitude;
    getHandle().accelerationY = y / magnitude;
    getHandle().accelerationZ = z / magnitude;
}
 
Example 33
Project: SurvivalAPI   File: PopeyeModule.java   View source code 5 votes vote down vote up
/**
 * Constructor
 *
 * @param plugin Parent plugin
 * @param api API instance
 * @param moduleConfiguration Module configuration
 */
public PopeyeModule(SurvivalPlugin plugin, SurvivalAPI api, Map<String, Object> moduleConfiguration)
{
    super(plugin, api, moduleConfiguration);
    Validate.notNull(moduleConfiguration, "Configuration cannot be null!");

    this.bonusTime = (int) moduleConfiguration.get("bonus-time");

    this.spinash = new ItemStack(Material.INK_SACK, 1, (short) 2);
    ItemMeta meta = this.spinash.getItemMeta();
    meta.setLore(Arrays.asList("Mangez les et gagnez de la force pour " + this.bonusTime + " secondes."));
    meta.setDisplayName(ChatColor.DARK_GREEN + "Epinards");
    this.spinash.setItemMeta(meta);
}
 
Example 34
Project: obevo   File: DbDeployerMain.java   View source code 5 votes vote down vote up
private void checkIfCleanBuildShouldProceed(Environment env, boolean noPrompt) {
    LOG.info("Request was made to clean the environment...");

    Validate.isTrue(env.isCleanBuildAllowed(), "Clean build not allowed for this environment [" + env.getName()
            + "] ! Exiting...");

    if (!noPrompt) {
        LOG.info("WARNING - This will wipe the whole environment!!! Are you sure you want to proceed? (Y/N)");

        String input = this.userInputReader.readLine(null);
        Validate.isTrue(input.trim().equalsIgnoreCase("Y"), "User did not enter Y. Hence, we will exit from here.");
    }
}
 
Example 35
Project: Uranium   File: CraftWorld.java   View source code 5 votes vote down vote up
public FallingBlock spawnFallingBlock(Location location, org.bukkit.Material material, byte data) throws IllegalArgumentException {
    Validate.notNull(location, "Location cannot be null");
    Validate.notNull(material, "Material cannot be null");
    Validate.isTrue(material.isBlock(), "Material must be a block");

    double x = location.getBlockX() + 0.5;
    double y = location.getBlockY() + 0.5;
    double z = location.getBlockZ() + 0.5;

    net.minecraft.entity.item.EntityFallingBlock entity = new net.minecraft.entity.item.EntityFallingBlock(world, x, y, z, net.minecraft.block.Block.getBlockById(material.getId()), data);
    entity.field_145812_b = 1; // ticksLived

    world.addEntity(entity, SpawnReason.CUSTOM);
    return (FallingBlock) entity.getBukkitEntity();
}
 
Example 36
Project: Uranium   File: CommandAliasHelpTopic.java   View source code 5 votes vote down vote up
public CommandAliasHelpTopic(String alias, String aliasFor, HelpMap helpMap) {
    this.aliasFor = aliasFor.startsWith("/") ? aliasFor : "/" + aliasFor;
    this.helpMap = helpMap;
    this.name = alias.startsWith("/") ? alias : "/" + alias;
    Validate.isTrue(!this.name.equals(this.aliasFor), "Command " + this.name + " cannot be alias for itself");
    this.shortText = ChatColor.YELLOW + "Alias for " + ChatColor.WHITE + this.aliasFor;
}
 
Example 37
Project: zlevels   File: Yaml.java   View source code 5 votes vote down vote up
/**
 * Creates a new {@link Yaml}, loading from the given file.
 * <p/>
 * Any errors loading the Configuration will be logged and then ignored.
 * If the specified input is not a valid config, a blank config will be
 * returned.
 * <p/>
 * The encoding used may follow the system dependent default.
 *
 * @param file Input file
 * @return Resulting yaml
 * @throws IllegalArgumentException Thrown if file is null
 */
public static Yaml loadConfiguration(File file) {
    Validate.notNull(file, "File cannot be null");

    Yaml config = new Yaml();

    try {
        config.load(file);
    } catch (Exception ex) {
        ZLogger.warn("Cannot load " + file);
    }

    return config;
}
 
Example 38
Project: Uranium   File: CraftTeam.java   View source code 5 votes vote down vote up
@Override
public boolean hasEntry(String entry) throws IllegalArgumentException,IllegalStateException{
    Validate.notNull(entry, "PlayerName cannot be null");
    CraftScoreboard scoreboard = checkState();

    return team.getMembershipCollection().contains(entry);
}
 
Example 39
Project: AlphaLibary   File: PyramidParticleForm.java   View source code 5 votes vote down vote up
public PyramidParticleForm(Effect effect, EffectData<?> effectData, Location location, String axis, double dense, double basis, double size, boolean filled, BlockFace direction) {
    super(location, axis, dense, basis, size, filled, direction, null);

    if (effectData != null)
        Validate.isTrue(effect.getData() != null && effect.getData().isAssignableFrom(effectData.getDataValue().getClass()), "Wrong kind of effectData for this effect!");
    else {
        Validate.isTrue(effect.getData() == null, "Wrong kind of effectData for this effect!");
        effectData = new EffectData<>(null);
    }

    EffectData<?> finalEffectData = effectData;

    setAction((p, loc) -> p.playEffect(loc, effect, finalEffectData.getDataValue()));
}
 
Example 40
Project: Uranium   File: CraftScoreboard.java   View source code 5 votes vote down vote up
public Team registerNewTeam(String name) throws IllegalArgumentException {
    Validate.notNull(name, "Team name cannot be null");
    Validate.isTrue(name.length() <= 16, "Team name '" + name + "' is longer than the limit of 16 characters");
    Validate.isTrue(board.getTeam(name) == null, "Team name '" + name + "' is already in use");

    return new CraftTeam(this, board.createTeam(name));
}