Search in sources :

Example 56 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class EntityScriptHelper method onEntityDeath.

@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
    Entity entity = event.getEntity();
    dEntity.rememberEntity(entity);
    EntityDespawnScriptEvent.instance.entity = new dEntity(entity);
    EntityDespawnScriptEvent.instance.cause = new Element("DEATH");
    EntityDespawnScriptEvent.instance.cancelled = false;
    EntityDespawnScriptEvent.instance.fire();
    dEntity.forgetEntity(entity);
    unlinkEntity(event.getEntity());
}
Also used : Entity(org.bukkit.entity.Entity) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) LivingEntity(org.bukkit.entity.LivingEntity) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) Element(net.aufdemrand.denizencore.objects.Element) EventHandler(org.bukkit.event.EventHandler)

Example 57 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class TeamCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    String name = null;
    String prefix = null;
    String suffix = null;
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (arg.matchesPrefix("id") && !scriptEntry.hasObject("id")) {
            scriptEntry.addObject("id", arg.asElement());
        } else if (arg.matchesPrefix("name") && !scriptEntry.hasObject("name")) {
            Element nameElement = arg.asElement();
            name = nameElement.asString();
            scriptEntry.addObject("name", nameElement);
        } else if (arg.matchesPrefix("add") && !scriptEntry.hasObject("add")) {
            scriptEntry.addObject("add", arg.asType(dList.class));
        } else if (arg.matchesPrefix("remove") && !scriptEntry.hasObject("remove")) {
            scriptEntry.addObject("remove", arg.asType(dList.class));
        } else if (arg.matchesPrefix("prefix") && !scriptEntry.hasObject("prefix")) {
            Element prefixElement = arg.asElement();
            prefix = prefixElement.asString();
            scriptEntry.addObject("prefix", prefixElement);
        } else if (arg.matchesPrefix("suffix") && !scriptEntry.hasObject("suffix")) {
            Element suffixElement = arg.asElement();
            suffix = suffixElement.asString();
            scriptEntry.addObject("suffix", suffixElement);
        }
    }
    if (name == null || name.length() == 0 || name.length() > 16) {
        throw new InvalidArgumentsException("Must specify a team name between 1 and 16 characters!");
    }
    if (!scriptEntry.hasObject("add") && !scriptEntry.hasObject("remove") && !scriptEntry.hasObject("prefix") && !scriptEntry.hasObject("suffix")) {
        throw new InvalidArgumentsException("Must specify something to do with the team!");
    }
    if ((prefix != null && prefix.length() > 16) || (suffix != null && suffix.length() > 16)) {
        throw new InvalidArgumentsException("Prefixes and suffixes must be 16 characters or less!");
    }
    scriptEntry.defaultObject("id", new Element("main"));
}
Also used : net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 58 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class TeamCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element id = scriptEntry.getElement("id");
    Element name = scriptEntry.getElement("name");
    dList add = scriptEntry.getdObject("add");
    dList remove = scriptEntry.getdObject("remove");
    Element prefix = scriptEntry.getElement("prefix");
    Element suffix = scriptEntry.getElement("suffix");
    dB.report(scriptEntry, getName(), id.debug() + name.debug() + (add != null ? add.debug() : "") + (remove != null ? remove.debug() : "") + (prefix != null ? prefix.debug() : "") + (suffix != null ? suffix.debug() : ""));
    Scoreboard board;
    if (id.asString().equalsIgnoreCase("main")) {
        board = ScoreboardHelper.getMain();
    } else {
        if (ScoreboardHelper.hasScoreboard(id.asString())) {
            board = ScoreboardHelper.getScoreboard(id.asString());
        } else {
            board = ScoreboardHelper.createScoreboard(id.asString());
        }
    }
    Team team = board.getTeam(name.asString());
    if (team == null) {
        team = board.registerNewTeam(name.asString());
    }
    if (add != null) {
        for (String string : add) {
            if (string.startsWith("p@")) {
                string = dPlayer.valueOf(string).getName();
            }
            if (!team.hasEntry(string)) {
                team.addEntry(string);
            }
        }
    }
    if (remove != null) {
        for (String string : remove) {
            if (string.startsWith("p@")) {
                string = dPlayer.valueOf(string).getName();
            }
            if (team.hasEntry(string)) {
                team.removeEntry(string);
            }
        }
    }
    if (prefix != null) {
        team.setPrefix(prefix.asString());
    }
    if (suffix != null) {
        team.setSuffix(suffix.asString());
    }
    if (team.getEntries().isEmpty()) {
        team.unregister();
    }
}
Also used : Scoreboard(org.bukkit.scoreboard.Scoreboard) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Team(org.bukkit.scoreboard.Team)

Example 59 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class AnnounceCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Fetch objects
    Element text = scriptEntry.getElement("text");
    AnnounceType type = (AnnounceType) scriptEntry.getObject("type");
    FormatScriptContainer format = (FormatScriptContainer) scriptEntry.getObject("format");
    Element flag = scriptEntry.getElement("flag");
    // Report to dB
    dB.report(scriptEntry, getName(), aH.debugObj("Message", text) + (format != null ? aH.debugObj("Format", format.getName()) : "") + aH.debugObj("Type", type.name()) + (flag != null ? aH.debugObj("Flag_Name", flag) : ""));
    String message = format != null ? format.getFormattedText(scriptEntry) : text.asString();
    // Use Bukkit to broadcast the message to everybody in the server.
    if (type == AnnounceType.ALL) {
        DenizenAPI.getCurrentInstance().getServer().broadcastMessage(message);
    } else if (type == AnnounceType.TO_OPS) {
        for (Player player : Bukkit.getOnlinePlayers()) {
            if (player.isOp()) {
                player.sendMessage(message);
            }
        }
    } else if (type == AnnounceType.TO_FLAGGED) {
        for (Player player : Bukkit.getOnlinePlayers()) {
            if (FlagManager.playerHasFlag(dPlayer.mirrorBukkitPlayer(player), flag.asString())) {
                player.sendMessage(message);
            }
        }
    } else if (type == AnnounceType.TO_CONSOLE) {
        Bukkit.getServer().getConsoleSender().sendMessage(message);
    }
}
Also used : net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Player(org.bukkit.entity.Player) Element(net.aufdemrand.denizencore.objects.Element) FormatScriptContainer(net.aufdemrand.denizen.scripts.containers.core.FormatScriptContainer)

Example 60 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class BanCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element action = scriptEntry.getElement("action");
    List<dPlayer> targets = (List<dPlayer>) scriptEntry.getObject("targets");
    Element reason = scriptEntry.getElement("reason");
    Duration duration = scriptEntry.getdObject("duration");
    Date expiration = null;
    if (duration != null && duration.getTicks() != 0) {
        expiration = new Date(new Duration(System.currentTimeMillis() / 50 + duration.getTicks()).getTicks() * 50);
    }
    dB.report(scriptEntry, getName(), action.debug() + aH.debugObj("targets", targets) + reason.debug() + (duration != null ? duration.debug() : ""));
    Actions banAction = Actions.valueOf(action.toString().toUpperCase());
    switch(banAction) {
        case ADD:
            for (dPlayer player : targets) {
                if (player.isValid()) {
                    Bukkit.getBanList(BanList.Type.NAME).addBan(player.getName(), reason.toString(), expiration, null);
                    if (player.isOnline()) {
                        player.getPlayerEntity().kickPlayer(reason.toString());
                    }
                }
            }
            break;
        case REMOVE:
            for (dPlayer player : targets) {
                if (player.isValid()) {
                    if (player.getOfflinePlayer().isBanned()) {
                        Bukkit.getBanList(BanList.Type.NAME).pardon(player.getName());
                    }
                }
            }
            break;
    }
}
Also used : Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) BanList(org.bukkit.BanList) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Duration(net.aufdemrand.denizencore.objects.Duration) Date(java.util.Date)

Aggregations

Element (net.aufdemrand.denizencore.objects.Element)166 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)74 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)49 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)46 BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)38 InvalidArgumentsException (net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)38 EventHandler (org.bukkit.event.EventHandler)38 List (java.util.List)29 net.aufdemrand.denizencore.objects.aH (net.aufdemrand.denizencore.objects.aH)28 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)27 net.aufdemrand.denizencore.objects.dObject (net.aufdemrand.denizencore.objects.dObject)21 Duration (net.aufdemrand.denizencore.objects.Duration)20 CommandExecutionException (net.aufdemrand.denizencore.exceptions.CommandExecutionException)16 ArrayList (java.util.ArrayList)14 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)14 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)14 Player (org.bukkit.entity.Player)11 net.aufdemrand.denizen.objects.dWorld (net.aufdemrand.denizen.objects.dWorld)10 net.aufdemrand.denizencore.objects.dScript (net.aufdemrand.denizencore.objects.dScript)10 ScriptEntry (net.aufdemrand.denizencore.scripts.ScriptEntry)9