use of com.denizenscript.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.
the class DisguiseCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
NetworkInterceptHelper.enable();
EntityTag entity = scriptEntry.getObjectTag("entity");
EntityTag as = scriptEntry.argForPrefix("as", EntityTag.class, true);
boolean cancel = scriptEntry.argAsBoolean("cancel");
boolean global = scriptEntry.argAsBoolean("global");
boolean self = scriptEntry.argAsBoolean("self");
List<PlayerTag> players = scriptEntry.argForPrefixList("players", PlayerTag.class, true);
if (as == null && !cancel) {
throw new InvalidArgumentsRuntimeException("Must specify a valid type to disguise as!");
}
if (players == null && !global) {
PlayerTag player = Utilities.getEntryPlayer(scriptEntry);
if (player != null && player.isOnline()) {
players = Collections.singletonList(player);
} else {
throw new InvalidArgumentsRuntimeException("Must have a valid player attached, or 'global' set!");
}
}
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), entity, db("cancel", cancel), as, db("global", global), db("self", self), db("players", players));
}
HashMap<UUID, TrackedDisguise> playerMap = disguises.get(entity.getUUID());
if (playerMap != null) {
if (global) {
for (Map.Entry<UUID, TrackedDisguise> entry : playerMap.entrySet()) {
entry.getValue().isActive = false;
if (entry.getKey() == null) {
if (entry.getValue().toOthers != null) {
FakeEntity.idsToEntities.remove(entry.getValue().toOthers.overrideUUID);
}
for (Player player : entity.getWorld().getPlayers()) {
if (!EntityTag.isNPC(player)) {
entry.getValue().removeFor(new PlayerTag(player));
}
}
} else {
PlayerTag player = new PlayerTag(entry.getKey());
entry.getValue().removeFor(player);
}
}
disguises.remove(entity.getUUID());
} else {
for (PlayerTag player : players) {
TrackedDisguise disguise = playerMap.remove(player.getUUID());
if (disguise != null) {
disguise.isActive = false;
disguise.removeFor(player);
if (disguise.toOthers != null) {
FakeEntity.idsToEntities.remove(disguise.toOthers.overrideUUID);
}
if (playerMap.isEmpty()) {
disguises.remove(entity.getUUID());
}
}
}
}
}
if (!cancel) {
TrackedDisguise disguise = new TrackedDisguise(entity, as);
disguise.as.entity = NMSHandler.getPlayerHelper().sendEntitySpawn(new ArrayList<>(), as.getEntityType(), entity.getLocation(), as.mechanisms == null ? null : new ArrayList<>(as.mechanisms), -1, null, false).entity.getBukkitEntity();
if (global) {
playerMap = disguises.computeIfAbsent(entity.getUUID(), k -> new HashMap<>());
playerMap.put(null, disguise);
disguise.isActive = true;
ArrayList<PlayerTag> playerSet = players == null ? new ArrayList<>() : new ArrayList<>(players);
for (Player player : entity.getWorld().getPlayers()) {
if (!EntityTag.isNPC(player) && !playerSet.contains(new PlayerTag(player)) && (self || !player.getUniqueId().equals(entity.getUUID()))) {
playerSet.add(new PlayerTag(player));
}
}
disguise.sendTo(playerSet);
} else {
for (PlayerTag player : players) {
playerMap = disguises.computeIfAbsent(entity.getUUID(), k -> new HashMap<>());
playerMap.put(player.getUUID(), disguise);
disguise.isActive = true;
}
disguise.sendTo(players);
}
}
}
use of com.denizenscript.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.
the class TeamCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag id = scriptEntry.getElement("id");
ElementTag name = scriptEntry.getElement("name");
ListTag add = scriptEntry.getObjectTag("add");
ListTag remove = scriptEntry.getObjectTag("remove");
ElementTag prefix = scriptEntry.getElement("prefix");
ElementTag suffix = scriptEntry.getElement("suffix");
ElementTag option = scriptEntry.getElement("option");
ElementTag status = scriptEntry.getElement("status");
ElementTag color = scriptEntry.getElement("color");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), id, name, add, remove, prefix, suffix, color, option, status);
}
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) {
String low = CoreUtilities.toLowerCase(name.asString());
team = board.getTeams().stream().filter(t -> CoreUtilities.toLowerCase(t.getName()).equals(low)).findFirst().orElse(null);
if (team == null) {
team = board.registerNewTeam(name.asString());
}
}
if (add != null) {
for (String string : add) {
string = translateEntry(string, scriptEntry.context);
if (!team.hasEntry(string)) {
team.addEntry(string);
}
}
}
if (remove != null) {
for (String string : remove) {
string = translateEntry(string, scriptEntry.context);
if (team.hasEntry(string)) {
team.removeEntry(string);
}
}
}
if (option != null) {
String optName = CoreUtilities.toLowerCase(option.asString());
String statusName = CoreUtilities.toLowerCase(status.asString());
if (optName.equals("friendly_fire")) {
team.setAllowFriendlyFire(statusName.equals("always"));
} else if (optName.equals("see_invisible")) {
team.setCanSeeFriendlyInvisibles(statusName.equals("always"));
} else {
team.setOption(Team.Option.valueOf(optName.toUpperCase()), Team.OptionStatus.valueOf(statusName.toUpperCase()));
}
}
if (prefix != null) {
team.setPrefix(prefix.asString());
}
if (suffix != null) {
team.setSuffix(suffix.asString());
}
if (color != null) {
team.setColor(ChatColor.valueOf(color.asString().toUpperCase()));
}
if (team.getEntries().isEmpty()) {
team.unregister();
}
}
use of com.denizenscript.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.
the class BreakCommand method execute.
// <--[action]
// @Actions
// dig
//
// @Triggers when the NPC breaks a block with the Break Command
//
// @Context
// <context.location> returns the location the NPC Dug
// <context.material> Returns the Block dug
//
// -->
@Override
public void execute(ScriptEntry scriptEntry) {
final LocationTag location = scriptEntry.getObjectTag("location");
final NPCTag npc = scriptEntry.getObjectTag("npc");
ElementTag radius = scriptEntry.getElement("radius");
final HashMap<String, ObjectTag> context = new HashMap<>();
MaterialTag material = new MaterialTag(location.getBlock());
context.put("location", location);
context.put("material", material);
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), location, npc, radius);
}
final ScriptEntry se = scriptEntry;
BlockBreaker.BlockBreakerConfiguration config = new BlockBreaker.BlockBreakerConfiguration();
config.item(npc.getLivingEntity().getEquipment().getItemInMainHand());
config.radius(radius.asDouble());
config.callback(() -> {
npc.action("dig", null, context);
se.setFinished(true);
});
BlockBreaker breaker = npc.getCitizen().getBlockBreaker(location.getBlock(), config);
if (breaker.shouldExecute()) {
TaskRunnable run = new TaskRunnable(breaker);
run.taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(Denizen.getInstance(), run, 0, 1);
} else {
se.setFinished(true);
}
}
use of com.denizenscript.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.
the class AbstractTrigger method parse.
public boolean parse(NPCTag npc, PlayerTag player, InteractScriptContainer script, String id, Map<String, ObjectTag> context) {
if (npc == null || player == null || script == null) {
return false;
}
List<ScriptEntry> entries = script.getEntriesFor(this.getClass(), player, npc, id, true);
if (entries.isEmpty()) {
return false;
}
Debug.echoDebug(script, DebugElement.Header, "Parsing " + name + " trigger: n@" + npc.getName() + "/p@" + player.getName());
// Create Queue
long speedTicks;
if (script.contains("SPEED", String.class)) {
speedTicks = DurationTag.valueOf(script.getString("SPEED", "0"), new BukkitTagContext(script)).getTicks();
} else {
speedTicks = DurationTag.valueOf(Settings.interactQueueSpeed(), new BukkitTagContext(script)).getTicks();
}
ScriptQueue queue;
if (speedTicks > 0) {
queue = new TimedQueue(script.getName()).setSpeed(speedTicks);
} else {
queue = new InstantQueue(script.getName());
}
// Add all entries to set it up
queue.addEntries(entries);
// Add context
if (context != null) {
ContextSource.SimpleMap src = new ContextSource.SimpleMap();
src.contexts = context;
queue.setContextSource(src);
}
if (!npc.getTriggerTrait().properly_set.get(name)) {
if (missetWarning.testShouldWarn()) {
Debug.echoError(missetWarning.message.replace("{NAME}", name).replace("{NPC}", npc.getId() + "/" + npc.getName()));
}
}
// Start it
queue.start();
return true;
}
use of com.denizenscript.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.
the class CommandScriptContainer method runAllowedHelpProcedure.
public boolean runAllowedHelpProcedure(PlayerTag player, NPCTag npc, Map<String, ObjectTag> context) {
List<ScriptEntry> entries = getEntries(new BukkitScriptEntryData(player, npc), "allowed help");
ScriptQueue queue = new InstantQueue(getName());
queue.addEntries(entries);
if (context != null) {
ContextSource.SimpleMap src = new ContextSource.SimpleMap();
src.contexts = context;
queue.setContextSource(src);
}
queue.start();
return queue.determinations != null && queue.determinations.size() > 0 && queue.determinations.get(0).equalsIgnoreCase("true");
}
Aggregations