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


Java NumberConversions类代码示例

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


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

示例1: formatMessage

import org.bukkit.util.NumberConversions; //导入依赖的package包/类
private String formatMessage(String lastSkill, int level, int exp, int requiredExp, float gained, int percent) {
    ChatColor color = ChatColor.GOLD;
    String colorPath = "bar.color." + lastSkill.toLowerCase();
    if (plugin.getConfig().isSet(colorPath)) {
        //specific color for a skill type
        String configColor = plugin.getConfig().getString(colorPath);

        //filter the color char; otherwise we won't detect the color
        color = ChatColor.getByChar(configColor.replace("&", ""));
    }

    //custom variable replacement
    String format = plugin.getConfig().getString("bar.format")
            .replace("@skill", lastSkill)
            .replace("@level", Integer.toString(level))
            .replace("@nextLevel", Integer.toString(level + 1))
            .replace("@exp", Integer.toString(exp))
            .replace("@remainingExp", Integer.toString(requiredExp - exp))
            .replace("@gainedExp", Integer.toString(NumberConversions.round(gained)))
            .replace("@reqExp", Integer.toString(requiredExp))
            .replace("@percent", Integer.toString(percent));

    return color + format;
}
 
开发者ID:games647,项目名称:mcMMOExtras,代码行数:25,代码来源:PlayerData.java

示例2: onDataHolderUpdate

import org.bukkit.util.NumberConversions; //导入依赖的package包/类
@Override
public void onDataHolderUpdate() {
    final DataHolder holder = getHolder().get();
    if (holder instanceof ConfigDataHolder) {
        final ConfigDataHolder h = (ConfigDataHolder) holder;
        if (h.getConfig().isList("slots")) {
            final List<?> list = h.getConfig().getList("slots");
            final Set<Integer> ints = new HashSet<>();
            for (Object o : list) {
                if (o instanceof String) {
                    ints.addAll(parseSlots((String) o));
                } else {
                    int i = NumberConversions.toInt(o);
                    if (i < 0 || i > 36) continue;
                    ints.add(i);
                }
            }
            slots = fromCollection(ints);
            return;
        }
    }

    final Optional<String> opt = holder.get("slots", String.class);
    opt.ifPresent(s -> slots = fromCollection(parseSlots(s)));
}
 
开发者ID:t7seven7t,项目名称:CraftFX,代码行数:26,代码来源:SlotData.java

示例3: getSelectorParams

import org.bukkit.util.NumberConversions; //导入依赖的package包/类
private Map<String, Integer> getSelectorParams(String selector) {
    Matcher m = SELECTOR_PARAMS_CAPTURE.matcher(selector);
    Map<String, Integer> result = Maps.newHashMap();

    if (m.find() && m.group(1) != null) {
        String args = m.group(1);

        m = SELECTOR_PARAMS_UNNAMED.matcher(args);
        if (m.find()) {
            result.put("x", NumberConversions.toInt(m.group(1)));
            result.put("y", NumberConversions.toInt(m.group(2)));
            result.put("z", NumberConversions.toInt(m.group(3)));
            result.put("r", NumberConversions.toInt(m.group(4)));
            return result;
        }

        m = SELECTOR_PARAMS_SEPARATOR.matcher(args);
        while (m.find()) {
            result.put(m.group(1), NumberConversions.toInt(m.group(2)));
        }
    }

    return result;
}
 
开发者ID:t7seven7t,项目名称:CraftFX,代码行数:25,代码来源:PlayerArgumentProvider.java

示例4: getPotionEffects

import org.bukkit.util.NumberConversions; //导入依赖的package包/类
public static List<PotionEffect> getPotionEffects(
        List<String> identifiers) throws IllegalArgumentException {
    List<PotionEffect> potionEffectList = Lists.newArrayList();
    for (String identifier : identifiers) {
        String[] split = identifier.replaceAll("\\s+", "_").split("\\W");
        if (split.length < 3) {
            throw new IllegalArgumentException(
                    "Missing argument: potion effect, duration or amplifier");
        }

        PotionEffectType type = PotionEffectType.getByName(EnumUtil.enumify(split[0]));
        if (type == null) {
            throw new IllegalArgumentException(
                    "Potion effect '" + split[0] + "' is not a valid type.");
        }

        int duration = (int) TimeUtil.parseString(split[1]);
        int amplifier = NumberConversions.toInt(split[2]);

        potionEffectList.add(new PotionEffect(type, duration, amplifier));
    }
    return potionEffectList;
}
 
开发者ID:t7seven7t,项目名称:CraftFX,代码行数:24,代码来源:PotionEffectUtil.java

示例5: StorageSign

import org.bukkit.util.NumberConversions; //导入依赖的package包/类
public StorageSign(ItemStack item) {
	String[] str = item.getItemMeta().getLore().get(0).split(" ");
	if(str[0].matches("Empty")) isEmpty = true;
	else {
		mat = getMaterial(str[0].split(":")[0]);
		if(mat == Material.ENCHANTED_BOOK){
			damage = NumberConversions.toShort(str[0].split(":")[2]);
			ench = Enchantment.getByName(str[0].split(":")[1]);//旧仕様も
			if(ench == null) ench = Enchantment.getById(NumberConversions.toInt(str[0].split(":")[1]));
		}
		else if(mat == Material.POTION || mat == Material.SPLASH_POTION || mat == Material.LINGERING_POTION){
			PotionInfo pi = new PotionInfo(mat, str[0].split(":"));
			mat = pi.getMaterial();
			damage = pi.getDamage();
			pot = pi.getPotionType();
		}else if(str[0].contains(":")) damage = NumberConversions.toShort(str[0].split(":")[1]);
		amount = NumberConversions.toInt(str[1]);
	}
	stack = item.getAmount();
}
 
开发者ID:wackyls6,项目名称:StorageSign,代码行数:21,代码来源:StorageSign.java

示例6: register

import org.bukkit.util.NumberConversions; //导入依赖的package包/类
@Override
public void register() {
    register("health").scoreSupply(player -> NumberConversions.round(player.getHealth()));
    register("lifetime").scoreSupply(player -> player.getTicksLived() / (20 * MINUTE_TO_SECOND));
    register("no_damage_ticks").scoreSupply(player -> player.getNoDamageTicks() / (20 * MINUTE_TO_SECOND));
    register("last_damage").scoreSupply(player -> (int) (player.getLastDamage()));

    register("exp").scoreSupply(Player::getTotalExperience);
    register("xp_to_level").scoreSupply(Player::getExpToLevel);


    register("helmet").scoreSupply(player -> calculateDurability(player.getInventory().getHelmet()));
    register("boots").scoreSupply(player -> calculateDurability(player.getInventory().getBoots()));
    register("leggings").scoreSupply(player -> calculateDurability(player.getInventory().getLeggings()));
    register("chestplate").scoreSupply(player -> calculateDurability(player.getInventory().getChestplate()));

    register("chestplate").scoreSupply(player -> (int) player.getWorld().getTime());
}
 
开发者ID:games647,项目名称:ScoreboardStats,代码行数:19,代码来源:BukkitVariables.java

示例7: fixXAxis

import org.bukkit.util.NumberConversions; //导入依赖的package包/类
public static double fixXAxis(double x) {
    /* For Z axis, just use Math.round(xaxis); */
    double touchedX = x;
    double rem = touchedX - Math.round(touchedX) + 0.01D;
    if (rem < 0.30D) {
        touchedX = NumberConversions.floor(x) - 1;
    }
    return touchedX;
}
 
开发者ID:Notoh,项目名称:DynamicAC,代码行数:10,代码来源:Utilities.java

示例8: deserialize

import org.bukkit.util.NumberConversions; //导入依赖的package包/类
public static Cuboid deserialize(Map<String, Object> args) {
    World world = Bukkit.getWorld((String)args.get("world"));
    if (world == null) {
        throw new IllegalArgumentException("unknown world");
    }
    return new Cuboid(world, NumberConversions.toInt(args.get("minX")), NumberConversions.toInt(args.get("minY")), NumberConversions.toInt(args.get("minZ")),
            NumberConversions.toInt(args.get("minX")), NumberConversions.toInt(args.get("minY")), NumberConversions.toInt(args.get("minZ")));
}
 
开发者ID:GameBoxx,项目名称:GameBoxx,代码行数:9,代码来源:Cuboid.java

示例9: setDirection

import org.bukkit.util.NumberConversions; //导入依赖的package包/类
/**
 * Sets the {@link #getYaw() yaw} and {@link #getPitch() pitch} to point
 * in the direction of the vector.
 */
public Location setDirection(Vector vector) {
    /*
     * Sin = Opp / Hyp
     * Cos = Adj / Hyp
     * Tan = Opp / Adj
     *
     * x = -Opp
     * z = Adj
     */
    final double _2PI = 2 * Math.PI;
    final double x = vector.getX();
    final double z = vector.getZ();

    if (x == 0 && z == 0) {
        pitch = vector.getY() > 0 ? -90 : 90;
        return this;
    }

    double theta = Math.atan2(-x, z);
    yaw = (float) Math.toDegrees((theta + _2PI) % _2PI);

    double x2 = NumberConversions.square(x);
    double z2 = NumberConversions.square(z);
    double xz = Math.sqrt(x2 + z2);
    pitch = (float) Math.toDegrees(Math.atan(-vector.getY() / xz));

    return this;
}
 
开发者ID:CyberdyneCC,项目名称:Thermos-Bukkit,代码行数:33,代码来源:Location.java

示例10: distanceSquared

import org.bukkit.util.NumberConversions; //导入依赖的package包/类
/**
 * Get the squared distance between this location and another.
 *
 * @see Vector
 * @param o The other location
 * @return the distance
 * @throws IllegalArgumentException for differing worlds
 */
public double distanceSquared(Location o) {
    if (o == null) {
        throw new IllegalArgumentException("Cannot measure distance to a null location");
    } else if (o.getWorld() == null || getWorld() == null) {
        throw new IllegalArgumentException("Cannot measure distance to a null world");
    } else if (o.getWorld() != getWorld()) {
        throw new IllegalArgumentException("Cannot measure distance between " + getWorld().getName() + " and " + o.getWorld().getName());
    }

    return NumberConversions.square(x - o.x) + NumberConversions.square(y - o.y) + NumberConversions.square(z - o.z);
}
 
开发者ID:CyberdyneCC,项目名称:Thermos-Bukkit,代码行数:20,代码来源:Location.java

示例11: fixXAxis

import org.bukkit.util.NumberConversions; //导入依赖的package包/类
public static double fixXAxis(double x) {
    double touchedX = x;
    double rem = touchedX - (double)Math.round(touchedX) + 0.01;
    if (rem < 0.3) {
        touchedX = NumberConversions.floor((double)x) - 1;
    }
    return touchedX;
}
 
开发者ID:cumpe,项目名称:Janitor,代码行数:9,代码来源:UtilCheat.java

示例12: getDistanceDifference

import org.bukkit.util.NumberConversions; //导入依赖的package包/类
/**
 * Calculates the difference between the player's last location and his current one.
 * 
 * @param player
 * @param previousLocation
 * @return difference
 */
private int getDistanceDifference(Player player, Location previousLocation) {
	// Distance difference since last runnable; ignore the vertical axis or not.
	double difference;
	if (configIgnoreVerticalDistance) {
		difference = Math.sqrt(NumberConversions.square(previousLocation.getX() - player.getLocation().getX())
				+ NumberConversions.square(previousLocation.getZ() - player.getLocation().getZ()));
	} else {
		difference = previousLocation.distance(player.getLocation());
	}
	return (int) difference;
}
 
开发者ID:PyvesB,项目名称:AdvancedAchievements,代码行数:19,代码来源:AchieveDistanceRunnable.java

示例13: fixXAxis

import org.bukkit.util.NumberConversions; //导入依赖的package包/类
/**
 * Fixes a player's X position to determine the block they are on, even if they're on the edge
 *
 * @param x player's x position
 * @return fixed x position
 */
public static double fixXAxis(double x) {
    /* For Z axis, just use Math.round(xaxis); */
    double touchedX = x;
    double rem = touchedX - Math.round(touchedX) + 0.01D;
    if (rem < 0.30D) {
        touchedX = NumberConversions.floor(x) - 1;
    }
    return touchedX;
}
 
开发者ID:Obsidian-Realm,项目名称:AntiCheat-COMPAT,代码行数:16,代码来源:Utilities.java

示例14: a

import org.bukkit.util.NumberConversions; //导入依赖的package包/类
public void a(PacketPlayInUseItem packetplayinuseitem) {
    PlayerConnectionUtils.ensureMainThread(packetplayinuseitem, this, this.player.x());
    if (this.player.dead) return; // CraftBukkit
    WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
    EnumHand enumhand = packetplayinuseitem.c();
    ItemStack itemstack = this.player.b(enumhand);
    BlockPosition blockposition = packetplayinuseitem.a();
    EnumDirection enumdirection = packetplayinuseitem.b();

    this.player.resetIdleTimer();
    if (blockposition.getY() >= this.minecraftServer.getMaxBuildHeight() - 1 && (enumdirection == EnumDirection.UP || blockposition.getY() >= this.minecraftServer.getMaxBuildHeight())) {
        ChatMessage chatmessage = new ChatMessage("build.tooHigh", new Object[] { Integer.valueOf(this.minecraftServer.getMaxBuildHeight())});

        chatmessage.getChatModifier().setColor(EnumChatFormat.RED);
        this.player.playerConnection.sendPacket(new PacketPlayOutChat(chatmessage));
    } else if (this.teleportPos == null && this.player.e((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) < 64.0D && !this.minecraftServer.a(worldserver, blockposition, this.player) && worldserver.getWorldBorder().a(blockposition)) {
        // CraftBukkit start - Check if we can actually do something over this large a distance
        Location eyeLoc = this.getPlayer().getEyeLocation();
        double reachDistance = NumberConversions.square(eyeLoc.getX() - blockposition.getX()) + NumberConversions.square(eyeLoc.getY() - blockposition.getY()) + NumberConversions.square(eyeLoc.getZ() - blockposition.getZ());
        if (reachDistance > (this.getPlayer().getGameMode() == org.bukkit.GameMode.CREATIVE ? CREATIVE_PLACE_DISTANCE_SQUARED : SURVIVAL_PLACE_DISTANCE_SQUARED)) {
            return;
        }
        // CraftBukkit end
        this.player.playerInteractManager.a(this.player, worldserver, itemstack, enumhand, blockposition, enumdirection, packetplayinuseitem.d(), packetplayinuseitem.e(), packetplayinuseitem.f());
    }

    this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(worldserver, blockposition));
    this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(worldserver, blockposition.shift(enumdirection)));
    itemstack = this.player.b(enumhand);
    if (itemstack != null && itemstack.count == 0) {
        this.player.a(enumhand, (ItemStack) null);
        itemstack = null;
    }

}
 
开发者ID:bergerkiller,项目名称:SpigotSource,代码行数:36,代码来源:PlayerConnection.java

示例15: distance

import org.bukkit.util.NumberConversions; //导入依赖的package包/类
public double distance(DemigodsLocation location) {
    if (location != null) {
        double squared = NumberConversions.square(X - location.X) + NumberConversions.square(Y - location.Y) + NumberConversions.square(Z = location.Z);
        return Math.sqrt(squared);
    }
    throw new NullPointerException("Cannot measure distance to a null location.");
}
 
开发者ID:DemigodsRPG,项目名称:Demigods3,代码行数:8,代码来源:DemigodsLocation.java


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