use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class BanCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag action = scriptEntry.getElement("action");
List<PlayerTag> targets = (List<PlayerTag>) scriptEntry.getObject("targets");
ListTag addresses = scriptEntry.getObjectTag("addresses");
ElementTag reason = scriptEntry.getElement("reason");
TimeTag expire = scriptEntry.getObjectTag("expire");
ElementTag source = scriptEntry.getElement("source");
Date expiration = expire == null ? null : new Date(expire.millis());
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), action, db("targets", targets), addresses, reason, expire, source);
}
Actions banAction = Actions.valueOf(action.toString().toUpperCase());
switch(banAction) {
case ADD:
if (targets != null) {
for (PlayerTag player : targets) {
if (player.isValid()) {
Bukkit.getBanList(BanList.Type.NAME).addBan(player.getName(), reason.toString(), expiration, source.toString());
if (player.isOnline()) {
player.getPlayerEntity().kickPlayer(reason.toString());
}
}
}
}
if (addresses != null) {
for (String address : addresses) {
Bukkit.getBanList(BanList.Type.IP).addBan(address, reason.toString(), expiration, source.toString());
}
}
break;
case REMOVE:
if (targets != null) {
for (PlayerTag player : targets) {
if (player.isValid()) {
if (player.getOfflinePlayer().isBanned()) {
Bukkit.getBanList(BanList.Type.NAME).pardon(player.getName());
}
}
}
}
if (addresses != null) {
for (String address : addresses) {
Bukkit.getBanList(BanList.Type.IP).pardon(address);
}
}
break;
}
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class FakeEquipCommand method parseArgs.
// <--[command]
// @Name FakeEquip
// @Syntax fakeequip [<entity>|...] (for:<player>|...) (duration:<duration>/reset) (hand:<item>) (offhand:<item>) (head:<item>) (chest:<item>) (legs:<item>) (boots:<item>)
// @Required 1
// @Maximum 9
// @Short Fake-equips items and armor on a list of entities for players to see without real change.
// @Group entity
//
// @Description
// This command fake-equips items and armor on a list of entities.
//
// The change doesn't happen on-server, and no armor effects will happen from it.
//
// The equipment can only be seen by certain players. By default, the linked player is used.
//
// The changes will remain in place for as long as the duration is specified (even if the real equipment is changed).
// The changes can be manually reset early by using the 'reset' argument.
// If you do not provide a duration, the fake equipment will last until manually reset.
// This does not persist across server restarts.
//
// Set the item to 'air' to unequip any slot.
//
// @Tags
// <EntityTag.equipment>
// <InventoryTag.equipment>
//
// @Usage
// Use to fake-equip a stone block on the player's head.
// - fakeequip <player> head:stone duration:10s
//
// @Usage
// Use to fake-equip an iron helmet on two defined players.
// - fakeequip <[player]>|<[someplayer]> head:iron_helmet duration:1m
//
// @Usage
// Use to fake-unequip all armor off the player.
// - fakeequip <player> head:air chest:air legs:air boots:air duration:5s
//
// @Usage
// Use to make all players within 30 blocks of an entity see it permanently equip a shield.
// - fakeequip <[entity]> offhand:shield for:<[entity].find_players_within[30]> duration:0
//
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
EquipmentOverride equipment = new EquipmentOverride();
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
} else if (arg.matchesPrefix("duration") && arg.matchesArgumentType(DurationTag.class)) {
scriptEntry.addObject("duration", arg.asType(DurationTag.class));
} else if (arg.matches("reset")) {
scriptEntry.addObject("reset", new ElementTag(true));
} else if (arg.matchesPrefix("for") && arg.matchesArgumentList(PlayerTag.class)) {
scriptEntry.addObject("for", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
} else if (arg.matchesPrefix("head", "helmet") && arg.matchesArgumentType(ItemTag.class)) {
equipment.head = arg.asType(ItemTag.class);
} else if (arg.matchesPrefix("chest", "chestplate") && arg.matchesArgumentType(ItemTag.class)) {
equipment.chest = arg.asType(ItemTag.class);
} else if (arg.matchesPrefix("legs", "leggings") && arg.matchesArgumentType(ItemTag.class)) {
equipment.legs = arg.asType(ItemTag.class);
} else if (arg.matchesPrefix("boots", "feet") && arg.matchesArgumentType(ItemTag.class)) {
equipment.boots = arg.asType(ItemTag.class);
} else if (arg.matchesPrefix("offhand") && arg.matchesArgumentType(ItemTag.class)) {
equipment.offhand = arg.asType(ItemTag.class);
} else if (arg.matchesPrefix("hand") && arg.matchesArgumentType(ItemTag.class)) {
equipment.hand = arg.asType(ItemTag.class);
} else {
arg.reportUnhandled();
}
}
if (equipment.isEmpty() && !scriptEntry.hasObject("reset")) {
throw new InvalidArgumentsException("Must specify equipment!");
}
if (!scriptEntry.hasObject("for")) {
PlayerTag player = Utilities.getEntryPlayer(scriptEntry);
if (player == null) {
throw new InvalidArgumentsException("Must specify a for player!");
}
scriptEntry.addObject("for", Collections.singletonList(player));
}
scriptEntry.addObject("equipment", equipment);
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class AssignmentCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ScriptTag script = scriptEntry.getObjectTag("script");
Action action = (Action) scriptEntry.getObject("action");
List<NPCTag> npcs = (List<NPCTag>) scriptEntry.getObject("npcs");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("action", action), script, db("npc", npcs));
}
PlayerTag player = Utilities.getEntryPlayer(scriptEntry);
for (NPCTag npc : npcs) {
switch(action) {
case SET:
{
if (script == null) {
throw new InvalidArgumentsRuntimeException("Missing script!");
}
AssignmentTrait assignment = npc.getCitizen().getOrAddTrait(AssignmentTrait.class);
assignment.clearAssignments(player);
assignment.addAssignmentScript((AssignmentScriptContainer) script.getContainer(), player);
break;
}
case ADD:
if (script == null) {
throw new InvalidArgumentsRuntimeException("Missing script!");
}
npc.getCitizen().getOrAddTrait(AssignmentTrait.class).addAssignmentScript((AssignmentScriptContainer) script.getContainer(), player);
break;
case REMOVE:
if (script == null) {
Deprecations.assignmentRemove.warn(scriptEntry);
if (npc.getCitizen().hasTrait(AssignmentTrait.class)) {
npc.getCitizen().getOrAddTrait(AssignmentTrait.class).clearAssignments(player);
npc.getCitizen().removeTrait(AssignmentTrait.class);
}
} else {
if (npc.getCitizen().hasTrait(AssignmentTrait.class)) {
AssignmentTrait trait = npc.getCitizen().getOrAddTrait(AssignmentTrait.class);
trait.removeAssignmentScript(script.getName(), player);
trait.checkAutoRemove();
}
}
break;
case CLEAR:
if (npc.getCitizen().hasTrait(AssignmentTrait.class)) {
npc.getCitizen().getOrAddTrait(AssignmentTrait.class).clearAssignments(player);
npc.getCitizen().removeTrait(AssignmentTrait.class);
}
break;
}
}
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class MoneyCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag action = scriptEntry.getElement("action");
ElementTag quantity = scriptEntry.getElement("quantity");
List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("Player(s)", players), action, quantity);
}
Economy eco = Depends.economy;
double amt = quantity.asDouble();
switch(Action.valueOf(action.asString().toUpperCase())) {
case GIVE:
for (PlayerTag player : players) {
eco.depositPlayer(player.getOfflinePlayer(), amt);
}
break;
case TAKE:
for (PlayerTag player : players) {
eco.withdrawPlayer(player.getOfflinePlayer(), amt);
}
break;
case SET:
for (PlayerTag player : players) {
double balance = eco.getBalance(player.getOfflinePlayer());
if (amt > balance) {
eco.depositPlayer(player.getOfflinePlayer(), amt - balance);
} else {
eco.withdrawPlayer(player.getOfflinePlayer(), balance - amt);
}
}
break;
}
}
use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class OpenTradesCommand method execute.
public void execute(ScriptEntry scriptEntry) {
ElementTag title = scriptEntry.getElement("title");
EntityTag entity = scriptEntry.getObjectTag("entity");
List<TradeTag> trades = (List<TradeTag>) scriptEntry.getObject("trades");
List<PlayerTag> players = (List<PlayerTag>) scriptEntry.getObject("players");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), entity, db("trades", trades), title, db("players", players));
}
if (entity != null) {
if (players.size() > 1) {
Debug.echoError("No more than one player can access the same entity!");
return;
}
if (entity.getBukkitEntity() instanceof Merchant) {
PlayerTag player = players.get(0);
if (player.isValid() && player.isOnline()) {
player.getPlayerEntity().openMerchant((Merchant) entity.getBukkitEntity(), true);
} else {
Debug.echoError("Tried to make a nonexistent or offline player trade with a villager entity!");
}
return;
}
Debug.echoError("The specified entity isn't a merchant!");
return;
}
List<MerchantRecipe> recipes = new ArrayList<>();
for (TradeTag trade : trades) {
recipes.add(trade.getRecipe());
}
for (PlayerTag player : players) {
if (player.isValid() && player.isOnline()) {
Merchant merchant = Bukkit.createMerchant(title.asString());
merchant.setRecipes(recipes);
player.getPlayerEntity().openMerchant(merchant, true);
} else {
Debug.echoError("Tried to make a nonexistent or offline player view a virtual trading inventory!");
}
}
}
Aggregations