Java Code Examples for org.bukkit.util.NumberConversions#toInt()

The following examples show how to use org.bukkit.util.NumberConversions#toInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CronusUtils.java    From TabooLib with MIT License 6 votes vote down vote up
public static long toMillis(String in) {
    long time = 0;
    StringBuilder current = new StringBuilder();
    for (String charAt : in.toLowerCase().split("")) {
        if (isInt(charAt)) {
            current.append(charAt);
        } else {
            switch (charAt) {
                case "d":
                    time += NumberConversions.toInt(current.toString()) * 24L * 60L * 60L * 1000L;
                    break;
                case "h":
                    time += NumberConversions.toInt(current.toString()) * 60L * 60L * 1000L;
                    break;
                case "m":
                    time += NumberConversions.toInt(current.toString()) * 60L * 1000L;
                    break;
                case "s":
                    time += NumberConversions.toInt(current.toString()) * 1000L;
                    break;
            }
            current = new StringBuilder();
        }
    }
    return time;
}
 
Example 2
Source File: CronusParser.java    From TabooLib with MIT License 6 votes vote down vote up
public static Location toLocation(Object in) {
    String str = String.valueOf(in);
    // 区域
    // world:0,80,0~0,90,0
    if (str.contains(":") && str.contains("~")) {
        String[] area = str.split("~");
        try {
            return new Location(Location.Mode.AREA, new org.bukkit.Location[] {toBukkitLocation(area[0].replace(":", ",")), toBukkitLocation(area[0].split(":")[0] + "," + area[1])}, null);
        } catch (Throwable ignored) {
            return new Location(Location.Mode.AREA, null, null);
        }
    }
    // 范围
    // world:0,80,0 r:10
    else if (str.contains("r:")) {
        String[] range = str.split("r:");
        return new Location(Location.Mode.RANGE, new org.bukkit.Location[] {toBukkitLocation(range[0].replace(":", ","))}, NumberConversions.toInt(range[1]));
    }
    // 单项
    // world,0,80,0;world,0,90,0
    else {
        return new Location(Location.Mode.POINT, null, Arrays.stream(str.split(";")).map(CronusParser::toBukkitLocation).toArray(org.bukkit.Location[]::new));
    }
}
 
Example 3
Source File: CronusParser.java    From TabooLib with MIT License 5 votes vote down vote up
public static ItemStack toItemStack(Object in) {
    String type = null;
    String name = null;
    String lore = null;
    int damage = -1;
    int amount = 1;
    for (String v : String.valueOf(in).split(",")) {
        if (v.toLowerCase().startsWith("type=")) {
            type = v.substring("type=".length());
        } else if (v.toLowerCase().startsWith("t=")) {
            type = v.substring("t=".length());
        } else if (v.toLowerCase().startsWith("name=")) {
            name = v.substring("name=".length());
        } else if (v.toLowerCase().startsWith("n=")) {
            name = v.substring("n=".length());
        } else if (v.toLowerCase().startsWith("lore=")) {
            lore = v.substring("lore=".length());
        } else if (v.toLowerCase().startsWith("l=")) {
            lore = v.substring("l=".length());
        } else if (v.toLowerCase().startsWith("damage=")) {
            damage = NumberConversions.toInt(v.substring("damage=".length()));
        } else if (v.toLowerCase().startsWith("d=")) {
            damage = NumberConversions.toInt(v.substring("d=".length()));
        } else if (v.toLowerCase().startsWith("amount=")) {
            amount = NumberConversions.toInt(v.substring("amount=".length()));
        } else if (v.toLowerCase().startsWith("a=")) {
            amount = NumberConversions.toInt(v.substring("a=".length()));
        } else {
            type = v;
        }
    }
    return new ItemStack(type, name, lore, damage, amount);
}
 
Example 4
Source File: TLocaleBossBar.java    From TabooLib with MIT License 5 votes vote down vote up
public static TLocaleBossBar valueOf(Map<String, Object> map) {
    return new TLocaleBossBar(
            map.getOrDefault("text", "§4* Invalid Text*").toString(),
            getColor(String.valueOf(map.get("color"))),
            getStyle(String.valueOf(map.get("style"))),
            NumberConversions.toFloat(map.getOrDefault("progress", 1)),
            NumberConversions.toInt(map.getOrDefault("timeout", 20)),
            NumberConversions.toInt(map.getOrDefault("timeout-interval", 2)),
            isPlaceholderEnabled(map));
}
 
Example 5
Source File: ActionTakeItem.java    From TrMenu with MIT License 4 votes vote down vote up
public static RequiredItem valueOf(String source) {
    String material = null;
    String name = null;
    String lore = null;
    int amount = 1;
    int damage = -1;
    Boolean hasName = null;
    Boolean hasLore = null;
    for (String condition : source.split(",")) {
        String[] data = condition.split(":");
        if (data.length == 2) {
            switch (data[0].toLowerCase()) {
                case "material": {
                    material = data[1];
                    break;
                }
                case "name": {
                    name = data[1];
                    break;
                }
                case "lore": {
                    lore = data[1];
                    break;
                }
                case "amount": {
                    amount = NumberConversions.toInt(data[1]);
                    break;
                }
                case "damage": {
                    damage = NumberConversions.toInt(data[1]);
                    break;
                }
                case "isname":
                case "hasname": {
                    hasName = Boolean.parseBoolean(data[1]);
                    break;
                }
                case "islore":
                case "haslore": {
                    hasLore = Boolean.parseBoolean(data[1]);
                    break;
                }
                default:
            }
        }
    }
    return new RequiredItem(material, name, lore, damage, amount, hasName, hasLore);
}
 
Example 6
Source File: AttributeModifier.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public static AttributeModifier deserialize(Map<String, Object> args) {
    return new AttributeModifier(UUID.fromString((String) args.get("uuid")), (String) args.get("name"), NumberConversions.toDouble(args.get("amount")), Operation.values()[NumberConversions.toInt(args.get("operation"))]);
}
 
Example 7
Source File: MetadataValueAdapter.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public int asInt() {
    return NumberConversions.toInt(value());
}
 
Example 8
Source File: CronusUtils.java    From TabooLib with MIT License 4 votes vote down vote up
public static boolean isInt(double in) {
    return NumberConversions.toInt(in) == in;
}
 
Example 9
Source File: NBTBase.java    From TabooLib with MIT License 4 votes vote down vote up
public int asInt() {
    return NumberConversions.toInt(data);
}
 
Example 10
Source File: ClientConnection.java    From TabooLib with MIT License 4 votes vote down vote up
public boolean isAlive() {
    return System.currentTimeMillis() - latestResponse < NumberConversions.toInt(TabooLibSettings.getSettings().getProperty("channel.timeout"));
}
 
Example 11
Source File: TabooLibClient.java    From TabooLib with MIT License 4 votes vote down vote up
public static void reconnect() {
    if (System.currentTimeMillis() - latestResponse > NumberConversions.toInt(TabooLibSettings.getSettings().getProperty("channel.timeout"))) {
        connect();
    }
}
 
Example 12
Source File: Numbers.java    From TabooLib with MIT License 4 votes vote down vote up
public static int toInt(Object in) {
    return NumberConversions.toInt(in);
}
 
Example 13
Source File: ListenerCommand.java    From TabooLib with MIT License 4 votes vote down vote up
private static int orInt(List<String> list, int index, int def) {
    return list.size() > index ? NumberConversions.toInt(list.get(index)) : def;
}