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());
}
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"));
}
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();
}
}
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);
}
}
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;
}
}
Aggregations