Java Code Examples for com.dsh105.commodus.GeneralUtil#isInt()

The following examples show how to use com.dsh105.commodus.GeneralUtil#isInt() . 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: LocationFunction.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean isValid(ConversationContext context, String input) {
    if (input.contains(" ")) {
        String[] split = input.split("\\s");
        if (split.length == 4) {
            if (Bukkit.getWorld(split[0]) != null) {
                for (int i = 1; i <= 3; i++) {
                    if (!GeneralUtil.isInt(split[i])) {
                        context.setSessionData("fail_int", true);
                        return false;
                    }
                }
                this.location = new Location(Bukkit.getWorld(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3]));
            } else {
                context.setSessionData("fail_world", true);
                return false;
            }
        } else {
            context.setSessionData("fail_format", true);
            return false;
        }
    } else {
        context.setSessionData("fail_format", true);
        return false;
    }
    return true;
}
 
Example 2
Source File: AnimationBuilderInputPrompt.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean isInputValid(ConversationContext conversationContext, String s) {
    if (conversationContext.getSessionData("askingForDelay") == null) {
        conversationContext.setSessionData("askingForDelay", false);
    }
    if (conversationContext.getSessionData("nextFrame") == null) {
        conversationContext.setSessionData("nextFrame", false);
    }

    return !((Boolean) conversationContext.getSessionData("askingForDelay") && !GeneralUtil.isInt(s)) && !(this.first && s.equalsIgnoreCase("DONE")) && !(s.equalsIgnoreCase("NEXT") && this.lines.isEmpty());
}
 
Example 3
Source File: SimpleHoloManager.java    From HoloAPI with GNU General Public License v3.0 4 votes vote down vote up
public ArrayList<String> loadFileData() {
    ArrayList<String> unprepared = new ArrayList<>();
    ConfigurationSection cs = config.getConfigurationSection("holograms");
    if (cs != null) {
        for (String key : cs.getKeys(false)) {
            String path = "holograms." + key + ".";
            String worldName = config.getString(path + "worldName");
            double x = config.getDouble(path + "x");
            double y = config.getDouble(path + "y");
            double z = config.getDouble(path + "z");
            if (config.get(path + "animatedImage.image") != null) {
                if (config.getBoolean(path + "animatedImage.image")) {
                    unprepared.add(key);
                } else {
                    ArrayList<Frame> frameList = new ArrayList<>();
                    ConfigurationSection frames = config.getConfigurationSection("holograms." + key + ".animatedImage.frames");
                    if (frames != null) {
                        for (String frameKey : frames.getKeys(false)) {
                            ConfigurationSection lines = config.getConfigurationSection("holograms." + key + ".animatedImage.frames." + frameKey);
                            if (lines != null) {
                                ArrayList<String> tagList = new ArrayList<>();
                                int delay = config.getInt("holograms." + key + ".animatedImage.frames." + frameKey + ".delay", 5);
                                for (String tagKey : lines.getKeys(false)) {
                                    if (!tagKey.equalsIgnoreCase("delay")) {
                                        tagList.add(config.getString("holograms." + key + ".animatedImage.frames." + frameKey + "." + tagKey));
                                    }
                                }
                                if (!tagList.isEmpty()) {
                                    frameList.add(new Frame(delay, tagList.toArray(new String[tagList.size()])));
                                }
                            }
                        }
                    }

                    if (!frameList.isEmpty()) {
                        this.loadExtraData(new AnimatedHologramFactory(HoloAPI.getCore())
                                        .withSaveId(key)
                                        .withText(new AnimatedTextGenerator(frameList.toArray(new Frame[frameList.size()])))
                                        .withLocation(new Vector(x, y, z), worldName)
                                        .build(),
                                key);
                    }
                }
            } else {
                ConfigurationSection cs1 = config.getConfigurationSection("holograms." + key + ".lines");
                boolean containsImage = false;
                if (cs1 != null) {
                    //ArrayList<String> lines = new ArrayList<String>();
                    HologramFactory hf = new HologramFactory(HoloAPI.getCore());
                    for (String key1 : cs1.getKeys(false)) {
                        if (GeneralUtil.isInt(key1)) {
                            String type = config.getString(path + "lines." + key1 + ".type");
                            String value = config.getString(path + "lines." + key1 + ".value");
                            if (type.equalsIgnoreCase("image")) {
                                containsImage = true;
                                break;
                            } else {
                                hf.withText(value);
                            }

                        } else {
                            HoloAPI.LOG.warning("Failed to load line section of " + key1 + " for Hologram of ID " + key + ".");
                        }
                    }
                    if (containsImage) {
                        unprepared.add(key);
                        continue;
                    }
                    this.loadExtraData(hf.withSaveId(key).withLocation(new Vector(x, y, z), worldName).build(), key);
                }
            }

        }
    }
    return unprepared;
}