Java Code Examples for org.apache.commons.lang.Validate.notNull()

The following are Jave code examples for showing how to use notNull() of the org.apache.commons.lang.Validate class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Uranium   File: EntityCommand.java   View Source Code Vote up 6 votes
@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])){
        MinecraftServer.getServer();
        MinecraftServer.getServer();
        return StringUtil.copyPartialMatches(args[1],MinecraftServer.entityConfig.getSettings().keySet(),new ArrayList<String>(MinecraftServer.tileEntityConfig.getSettings().size()));
    }

    return ImmutableList.of();
}
 
Example 2
Project: Uranium   File: CraftObjective.java   View Source Code Vote up 5 votes
public void setDisplayName(String displayName) throws IllegalStateException, IllegalArgumentException {
    Validate.notNull(displayName, "Display name cannot be null");
    Validate.isTrue(displayName.length() <= 32, "Display name '" + displayName + "' is longer than the limit of 32 characters");
    CraftScoreboard scoreboard = checkState();

    objective.setDisplayName(displayName);
}
 
Example 3
Project: zlevels   File: MemoryConfiguration.java   View Source Code Vote up 5 votes
public void addDefaults( Map<String, Object> defaults )
{
	Validate.notNull( defaults, "Defaults may not be null" );

	for ( Map.Entry<String, Object> entry : defaults.entrySet() ) {
		addDefault( entry.getKey(), entry.getValue() );
	}
}
 
Example 4
Project: Uranium   File: CraftItemStack.java   View Source Code Vote up 5 votes
@Override
public int getEnchantmentLevel(Enchantment ench) {
    Validate.notNull(ench, "Cannot find null enchantment");
    if (handle == null) {
        return 0;
    }
    return net.minecraft.enchantment.EnchantmentHelper.getEnchantmentLevel(ench.getId(), handle);
}
 
Example 5
Project: AlphaLibary   File: AddonClassLoader.java   View Source Code Vote up 5 votes
private synchronized void initialize(Addon addon) {
    Validate.notNull(addon, "Initializing addon cannot be null");
    Validate.isTrue(addon.getClass().getClassLoader() == this, "Cannot initialize plugin outside of this class loader");
    if (this.addon.getDescription() != null) {
        throw new IllegalArgumentException("Addon already initialized!");
    } else {
        addon.init(this, this.dataFolder, this.description);
    }
}
 
Example 6
Project: zlevels   File: MemorySection.java   View Source Code Vote up 5 votes
/**
 * Creates an empty MemorySection with the specified parent and path.
 *
 * @param parent Parent section that contains this own section.
 * @param path   Path that you may access this section from via the root
 *               {@link Configuration}.
 * @throws IllegalArgumentException Thrown is parent or path is null, or
 *                                  if parent contains no root Configuration.
 */
protected MemorySection( ConfigurationSection parent, String path )
{
	Validate.notNull( parent, "Parent cannot be null" );
	Validate.notNull( path, "Path cannot be null" );

	this.path = path;
	this.parent = parent;
	this.root = parent.getRoot();

	Validate.notNull( root, "Path cannot be orphaned" );

	this.fullPath = createPath( parent, path );
}
 
Example 7
Project: DragonEggDrop   File: DragonTemplate.java   View Source Code Vote up 5 votes
/**
 * Construct a new DragonTemplate object
 * 
 * @param file the file holding this template data
 * @param name the name of the dragon. Can be null
 * @param barStyle the style of the bar. Can be null
 * @param barColour the colour of the bar. Can be null
 */
public DragonTemplate(File file, String name, BarStyle barStyle, BarColor barColour) {
	Validate.notNull(file, "File cannot be null. See DragonTemplate(String, String, BarStyle, BarColor) for null files");
	
	this.file = file;
	this.configFile = YamlConfiguration.loadConfiguration(file);
	this.identifier = file.getName().substring(0, file.getName().lastIndexOf('.'));
	
	this.name = (name != null ? ChatColor.translateAlternateColorCodes('&', name) : null);
	this.barStyle = (barStyle != null ? barStyle : BarStyle.SOLID);
	this.barColour = (barColour != null ? barColour : BarColor.PINK);
	this.loot = new DragonLoot(this);
}
 
Example 8
Project: DragonEggDrop   File: DragonTemplate.java   View Source Code Vote up 5 votes
/**
 * Remove an attribute from this template and set its value back to default
 * 
 * @param attribute the attribute to remove
 * @param updateFile whether to update the dragon file or not
 */
public void removeAttribute(Attribute attribute, boolean updateFile) {
	Validate.notNull(attribute, "Cannot remove a null attribute");
	
	this.attributes.remove(attribute);
	
	if (updateFile) {
		this.updateConfig("attributes." + attribute.name(), null);
	}
}
 
Example 9
Project: Chambers   File: BukkitCommand.java   View Source Code Vote up 5 votes
@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 10
Project: Uranium   File: CraftTeam.java   View Source Code Vote up 5 votes
@Override
public void addEntry(String player) throws IllegalStateException,IllegalArgumentException{
    Validate.notNull(player, "PlayerName cannot be null");
    CraftScoreboard scoreboard = checkState();

    scoreboard.board.func_151392_a(player, team.getRegisteredName());
}
 
Example 11
Project: SurvivalAPI   File: CocoaEffectsModule.java   View Source Code Vote up 5 votes
/**
 * Constructor
 *
 * @param plugin Parent plugin
 * @param api API instance
 * @param moduleConfiguration Module configuration
 */
public CocoaEffectsModule(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.penaltyTime = (int) moduleConfiguration.get("penalty-time");

    this.cocoa = new ItemStack(Material.INK_SACK, 5, (short) 3);
    ItemMeta meta = this.cocoa.getItemMeta();
    meta.setLore(Arrays.asList(ChatColor.GRAY + "Chaque utilisation vous donne " + this.bonusTime + " secondes", ChatColor.GRAY + " de force et vitesse améliorées", ChatColor.GRAY + " mais les effets contraires par la suite", ChatColor.GRAY + " pendant " + this.penaltyTime + " secondes."));
    meta.setDisplayName(ChatColor.AQUA + "Coco");
    this.cocoa.setItemMeta(meta);
}
 
Example 12
Project: SurvivalAPI   File: ConstantPotionModule.java   View Source Code Vote up 5 votes
/**
 * Constructor
 *
 * @param plugin Parent plugin
 * @param api API instance
 * @param moduleConfiguration Module configuration
 */
public ConstantPotionModule(SurvivalPlugin plugin, SurvivalAPI api, Map<String, Object> moduleConfiguration)
{
    super(plugin, api, moduleConfiguration);
    Validate.notNull(moduleConfiguration, "Configuration cannot be null!");

    this.potionEffects = (ArrayList<PotionEffect>) this.moduleConfiguration.get("effects");
}
 
Example 13
Project: living-documentation   File: Voyage.java   View Source Code Vote up 5 votes
public Builder(final VoyageNumber voyageNumber, final Location departureLocation) {
    Validate.notNull(voyageNumber, "Voyage number is required");
    Validate.notNull(departureLocation, "Departure location is required");

    this.voyageNumber = voyageNumber;
    this.departureLocation = departureLocation;
}
 
Example 14
Project: Uranium   File: CraftVillager.java   View Source Code Vote up 4 votes
public void setProfession(Profession profession) {
    Validate.notNull(profession);
    getHandle().setProfession(profession.getId());
}
 
Example 15
Project: Uranium   File: CraftScoreboard.java   View Source Code Vote up 4 votes
public void clearSlot(DisplaySlot slot) throws IllegalArgumentException {
    Validate.notNull(slot, "Slot cannot be null");
    board.func_96530_a(CraftScoreboardTranslations.fromBukkitSlot(slot), null);
}
 
Example 16
Project: Uranium   File: CraftWorld.java   View Source Code Vote up 4 votes
@Override
public void playEffect( Location location, Effect effect, int id, int data, float offsetX, float offsetY, float offsetZ, float speed, int particleCount, int radius )
{
    Validate.notNull( location, "Location cannot be null" );
    Validate.notNull( effect, "Effect cannot be null" );
    Validate.notNull( location.getWorld(), "World cannot be null" );
    net.minecraft.network.Packet packet;
    if ( effect.getType() != Effect.Type.PARTICLE )
    {
        int packetData = effect.getId();
        packet = new net.minecraft.network.play.server.S28PacketEffect( packetData, location.getBlockX(), location.getBlockY(), location.getBlockZ(), id, false );
    } else
    {
        StringBuilder particleFullName = new StringBuilder();
        particleFullName.append( effect.getName() );
        if ( effect.getData() != null && ( effect.getData().equals( net.minecraft.block.material.Material.class ) || effect.getData().equals( org.bukkit.material.MaterialData.class ) ) )
        {
            particleFullName.append( '_' ).append( id );
        }
        if ( effect.getData() != null && effect.getData().equals( org.bukkit.material.MaterialData.class ) )
        {
            particleFullName.append( '_' ).append( data );
        }
        packet = new net.minecraft.network.play.server.S2APacketParticles( particleFullName.toString(), (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, particleCount );
    }
    int distance;
    radius *= radius;
    for ( Player player : getPlayers() )
    {
        if ( ( (CraftPlayer) player ).getHandle().playerNetServerHandler == null )
        {
            continue;
        }
        if ( !location.getWorld().equals( player.getWorld() ) )
        {
            continue;
        }
        distance = (int) player.getLocation().distanceSquared( location );
        if ( distance <= radius )
        {
            ( (CraftPlayer) player ).getHandle().playerNetServerHandler.sendPacket( packet );
        }
    }
}
 
Example 17
Project: datax   File: AbstractScheduler.java   View Source Code Vote up 4 votes
public void schedule(List<Configuration> configurations) {
    Validate.notNull(configurations,
            "scheduler配置不能为空");
    int jobReportIntervalInMillSec = configurations.get(0).getInt(
            CoreConstant.DATAX_CORE_CONTAINER_JOB_REPORTINTERVAL, 30000);
    int jobSleepIntervalInMillSec = configurations.get(0).getInt(
            CoreConstant.DATAX_CORE_CONTAINER_JOB_SLEEPINTERVAL, 10000);

    this.jobId = configurations.get(0).getLong(
            CoreConstant.DATAX_CORE_CONTAINER_JOB_ID);

    errorLimit = new ErrorRecordChecker(configurations.get(0));

    /**
     * 给 taskGroupContainer 的 Communication 注册
     */
    this.containerCommunicator.registerCommunication(configurations);

    int totalTasks = calculateTaskCount(configurations);
    startAllTaskGroup(configurations);

    Communication lastJobContainerCommunication = new Communication();

    long lastReportTimeStamp = System.currentTimeMillis();
    try {
        while (true) {
            /**
             * step 1: collect job stat
             * step 2: getReport info, then report it
             * step 3: errorLimit do check
             * step 4: dealSucceedStat();
             * step 5: dealKillingStat();
             * step 6: dealFailedStat();
             * step 7: refresh last job stat, and then sleep for next while
             *
             * above steps, some ones should report info to DS
             *
             */
            Communication nowJobContainerCommunication = this.containerCommunicator.collect();
            nowJobContainerCommunication.setTimestamp(System.currentTimeMillis());
            LOG.debug(nowJobContainerCommunication.toString());

            //汇报周期
            long now = System.currentTimeMillis();
            if (now - lastReportTimeStamp > jobReportIntervalInMillSec) {
                Communication reportCommunication = CommunicationTool
                        .getReportCommunication(nowJobContainerCommunication, lastJobContainerCommunication, totalTasks);

                this.containerCommunicator.report(reportCommunication);
                lastReportTimeStamp = now;
                lastJobContainerCommunication = nowJobContainerCommunication;
            }

            errorLimit.checkRecordLimit(nowJobContainerCommunication);

            if (nowJobContainerCommunication.getState() == State.SUCCEEDED) {
                LOG.info("Scheduler accomplished all tasks.");
                break;
            }

            if (isJobKilling(this.getJobId())) {
                dealKillingStat(this.containerCommunicator, totalTasks);
            } else if (nowJobContainerCommunication.getState() == State.FAILED) {
                dealFailedStat(this.containerCommunicator, nowJobContainerCommunication.getThrowable());
            }

            Thread.sleep(jobSleepIntervalInMillSec);
        }
    } catch (InterruptedException e) {
        // 以 failed 状态退出
        LOG.error("捕获到InterruptedException异常!", e);

        throw DataXException.asDataXException(
                FrameworkErrorCode.RUNTIME_ERROR, e);
    }

}
 
Example 18
Project: Uranium   File: CraftServer.java   View Source Code Vote up 4 votes
@Override
public void banIP(String address) {
    Validate.notNull(address, "Address cannot be null.");

    this.getBanList(org.bukkit.BanList.Type.IP).addBan(address, null, null, null);
}
 
Example 19
Project: SurvivalAPI   File: RapidToolsModule.java   View Source Code Vote up 2 votes
/**
 * Constructor
 *
 * @param plugin Parent plugin
 * @param api API instance
 * @param moduleConfiguration Module configuration
 */
public RapidToolsModule(SurvivalPlugin plugin, SurvivalAPI api, Map<String, Object> moduleConfiguration)
{
    super(plugin, api, moduleConfiguration);
    Validate.notNull(moduleConfiguration, "Configuration cannot be null!");
}
 
Example 20
Project: SurvivalAPI   File: BloodDiamondModule.java   View Source Code Vote up 2 votes
/**
 * Constructor
 *
 * @param plugin Parent plugin
 * @param api API instance
 * @param moduleConfiguration Module configuration
 */
public BloodDiamondModule(SurvivalPlugin plugin, SurvivalAPI api, Map<String, Object> moduleConfiguration)
{
    super(plugin, api, moduleConfiguration);
    Validate.notNull(moduleConfiguration, "Configuration cannot be null!");
}