Search in sources :

Example 6 with JSFunction

use of org.mozilla.javascript.annotations.JSFunction in project Dragonet-Legacy by DragonetMC.

the class ServerAPI method stop.

@JSFunction
public static void stop(String msg) {
    org.dragonet.DragonetServer.instance().getServer().savePlayers();
    for (Player plr : org.dragonet.DragonetServer.instance().getServer().getOnlinePlayers()) {
        plr.kickPlayer(msg);
    }
    org.dragonet.DragonetServer.instance().getServer().shutdown();
}
Also used : Player(org.bukkit.entity.Player) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 7 with JSFunction

use of org.mozilla.javascript.annotations.JSFunction in project Dragonet-Legacy by DragonetMC.

the class ConfigAPI method readEntry.

@JSFunction
public static String readEntry(String name, String entry) {
    File config = new File("plugins/" + name + "/" + name + ".yml");
    String content = "EMPTY_NODE";
    if (exists(name)) {
        try {
            for (String s : FileUtils.readLines(config)) {
                if (s.contains(new StringBuffer(entry))) {
                    content = s.replace(new StringBuffer(entry + ": "), new StringBuffer(""));
                }
            }
        } catch (IOException IOe) {
            System.err.println(IOe.getMessage());
        }
    } else {
        org.dragonet.DragonetServer.instance().getLogger().warn("[DragonetAPI] Script tried to read a nonexistant config file!");
    }
    return content;
}
Also used : IOException(java.io.IOException) File(java.io.File) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 8 with JSFunction

use of org.mozilla.javascript.annotations.JSFunction in project Dragonet-Legacy by DragonetMC.

the class ConfigAPI method addNewEntry.

@JSFunction
public static void addNewEntry(String name, String entry, String value) {
    File config = new File("plugins/" + name + "/" + name + ".yml");
    String fullEntry = entry + ": " + value;
    try {
        Files.write(fullEntry.getBytes(), config);
    } catch (IOException IOe) {
        System.err.print(IOe.getMessage());
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Aggregations

JSFunction (org.mozilla.javascript.annotations.JSFunction)8 Player (org.bukkit.entity.Player)4 File (java.io.File)3 IOException (java.io.IOException)3 DragonetPlayer (org.dragonet.entity.DragonetPlayer)3 Material (org.bukkit.Material)1 ItemStack (org.bukkit.inventory.ItemStack)1 PotionEffect (org.bukkit.potion.PotionEffect)1 CustomMethod (org.dragonet.rhino.CustomMethod)1 Script (org.dragonet.rhino.Script)1 WrappedException (org.mozilla.javascript.WrappedException)1