本文整理汇总了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;
}
示例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)));
}
示例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;
}
示例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;
}
示例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();
}
示例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());
}
示例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;
}
示例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")));
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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.");
}