Java Code Examples for com.dsh105.commodus.GeneralUtil#toInteger()
The following examples show how to use
com.dsh105.commodus.GeneralUtil#toInteger() .
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: EditCommand.java From HoloAPI with GNU General Public License v3.0 | 5 votes |
@Command( command = "edit <id> <line> <content...>", description = "Edit a line of an existing hologram", permission = "holoapi.holo.edit", help = "The content can be more than one word" ) public boolean editWithContent(CommandEvent event) { final Hologram hologram = HoloAPI.getManager().getHologram(event.variable("id")); if (hologram == null) { event.respond(Lang.HOLOGRAM_NOT_FOUND.getValue("id", event.variable("id"))); return true; } int lineNumber; try { lineNumber = GeneralUtil.toInteger(event.variable("line_number")); } catch (NumberFormatException e) { event.respond(Lang.INT_ONLY.getValue("string", event.variable("line_number"))); return true; } if (lineNumber > hologram.getLines().length) { event.respond(Lang.LINE_INDEX_TOO_BIG.getValue("index", event.variable("line_number"))); return true; } hologram.updateLine(lineNumber - 1, event.variable("content")); event.respond(Lang.HOLOGRAM_UPDATE_LINE.getValue("index", lineNumber, "input", ChatColor.translateAlternateColorCodes('&', event.variable("content")))); return true; }
Example 2
Source File: NearbyCommand.java From HoloAPI with GNU General Public License v3.0 | 5 votes |
@Command( command = "nearby <radius>", description = "View information on all nearby holograms within the specified radius", permission = "holoapi.holo.nearby" ) public boolean command(CommandEvent<Player> event) { int radius; try { radius = GeneralUtil.toInteger(event.variable("radius")); } catch (NumberFormatException e) { event.respond(Lang.INT_ONLY.getValue("string", event.variable("radius"))); return true; } ArrayList<Hologram> nearby = new ArrayList<Hologram>(); for (Hologram hologram : HoloAPI.getManager().getAllComplexHolograms().keySet()) { if (GeometryUtil.getNearbyEntities(hologram.getDefaultLocation(), radius).contains(event.sender())) { nearby.add(hologram); } } if (nearby.isEmpty()) { event.respond(Lang.NO_NEARBY_HOLOGRAMS.getValue("radius", radius)); return true; } event.respond(Lang.HOLOGRAM_NEARBY.getValue("radius", radius)); InfoCommand.info(event.sender(), nearby); if (MinecraftReflection.isUsingNetty()) { event.respond(Lang.TIP_HOVER_PREVIEW.getValue()); } return true; }
Example 3
Source File: ScriptCommand.java From HoloAPI with GNU General Public License v3.0 | 5 votes |
@Command( command = "script editcurrent <line>", description = "Edits a script currently being built. Not intended for general use outside of context.", includeInHelp = false // No permission, as this cannot be called without another command executing it ) public boolean editCurrentScript(CommandEvent event) { if (!(event.sender() instanceof Conversable)) { event.respond(Lang.NOT_CONVERSABLE.getValue()); return true; } ScriptBuilderPrompt scriptBuilder = SCRIPT_EDITORS.get(getIdent((Conversable) event.sender())); if (scriptBuilder == null) { event.respond(Lang.PROMPT_SCRIPT_NOT_EDITING.getValue()); return true; } int line = 0; try { line = GeneralUtil.toInteger(event.variable("line")); } catch (NumberFormatException e) { event.respond(Lang.INT_ONLY.getValue("string", event.variable("line"))); } event.respond(Lang.PROMPT_SCRIPT_LINE_CHANGE.getValue("line", event.variable("line"))); scriptBuilder.setCurrentlyEditing(line); return true; }