use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayerKickedScriptEvent method applyDetermination.
@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag) {
String lower = CoreUtilities.toLowerCase(determinationObj.toString());
if (lower.startsWith("message:")) {
event.setLeaveMessage(lower.substring("message:".length()));
return true;
} else if (lower.startsWith("reason:")) {
event.setReason(lower.substring("reason:".length()));
return true;
} else if (lower.startsWith("fly_cooldown:")) {
DurationTag duration = DurationTag.valueOf(lower.substring("fly_cooldown:".length()), getTagContext(path));
if (duration != null) {
NMSHandler.getPlayerHelper().setFlyKickCooldown(player.getPlayerEntity(), (int) duration.getTicks());
cancelled = true;
return true;
}
}
}
return super.applyDetermination(path, determinationObj);
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayerPlacesBlockScriptEvent method onPlayerPlacesBlock.
@EventHandler
public void onPlayerPlacesBlock(BlockPlaceEvent event) {
if (EntityTag.isNPC(event.getPlayer())) {
return;
}
hand = new ElementTag(event.getHand().name());
material = new MaterialTag(event.getBlock());
location = new LocationTag(event.getBlock().getLocation());
item_in_hand = new ItemTag(event.getItemInHand());
this.event = event;
fire(event);
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayerPreLoginScriptEvent method applyDetermination.
@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
String determination = determinationObj.toString();
if (determinationObj instanceof ElementTag) {
if (CoreUtilities.toLowerCase(determination).startsWith("kicked")) {
String message = determination.length() > 7 ? determination.substring(7) : determination;
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, message);
return true;
}
}
if (QueueTag.matches(determination)) {
QueueTag newQueue = QueueTag.valueOf(determination, getTagContext(path));
if (newQueue != null && newQueue.getQueue() != null) {
waitForQueues.add(newQueue);
}
return true;
}
return super.applyDetermination(path, determinationObj);
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayerPreparesEnchantScriptEvent method applyDetermination.
@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag) {
String determineLow = CoreUtilities.toLowerCase(determinationObj.toString());
if (determineLow.startsWith("offers:")) {
ListTag offers = ListTag.valueOf(determineLow.substring("offers:".length()), getTagContext(path));
if (offers.size() != event.getOffers().length) {
Debug.echoError("Offer list size incorrect.");
return false;
}
for (int i = 0; i < offers.size(); i++) {
MapTag map = MapTag.getMapFor(offers.getObject(i), getTagContext(path));
event.getOffers()[i].setCost(map.getObject("cost").asElement().asInt());
ObjectTag enchantment = map.getObject("enchantment_type");
if (enchantment == null) {
enchantment = map.getObject("enchantment");
}
event.getOffers()[i].setEnchantment(enchantment.asType(EnchantmentTag.class, getTagContext(path)).enchantment);
event.getOffers()[i].setEnchantmentLevel(map.getObject("level").asElement().asInt());
}
return true;
}
}
return super.applyDetermination(path, determinationObj);
}
use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayerPreparesEnchantScriptEvent method getContext.
@Override
public ObjectTag getContext(String name) {
switch(name) {
case "item":
return new ItemTag(event.getItem());
case "location":
return new LocationTag(event.getEnchantBlock().getLocation());
case "bonus":
return new ElementTag(event.getEnchantmentBonus());
case "offers":
ListTag output = new ListTag();
for (EnchantmentOffer offer : event.getOffers()) {
MapTag map = new MapTag();
map.putObject("cost", new ElementTag(offer.getCost()));
map.putObject("enchantment", new ElementTag(offer.getEnchantment().getKey().getKey()));
map.putObject("enchantment_type", new EnchantmentTag(offer.getEnchantment()));
map.putObject("level", new ElementTag(offer.getEnchantmentLevel()));
output.addObject(map);
}
return output;
}
return super.getContext(name);
}
Aggregations