Skip to content

Commit

Permalink
Announce to_server format, ChunkTag no world error, meta fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 27, 2021
1 parent 270dd47 commit aaa3b38
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 19 deletions.
Expand Up @@ -19,6 +19,8 @@ public class EntityFoodLevelChangeScriptEvent extends BukkitScriptEvent implemen
//
// @Regex ^on [^\s]+ changes food level$
//
// @Synonyms player hunger depletes
//
// @Group Entity
//
// @Location true
Expand Down
Expand Up @@ -90,7 +90,7 @@ public static ChunkTag valueOf(String string, TagContext context) {
String[] parts = string.split(",");
if (parts.length == 3) {
try {
return new ChunkTag(WorldTag.valueOf(parts[2], context), Integer.valueOf(parts[0]), Integer.valueOf(parts[1]));
return new ChunkTag(new WorldTag(parts[2]), Integer.valueOf(parts[0]), Integer.valueOf(parts[1]));
}
catch (Exception e) {
if (context == null || context.showErrors()) {
Expand Down
Expand Up @@ -2158,6 +2158,7 @@ else if (yaw < 315) {
// @returns LocationTag
// @description
// Returns the location of the nearest block of the given biome type (or null).
// Warning: may be extremely slow to process. Use with caution.
// -->
registerTag("find_nearest_biome", (attribute, object) -> {
if (!attribute.hasContext(1)) {
Expand Down
Expand Up @@ -41,7 +41,7 @@ public AnnounceCommand() {
// You can also use the 'to_console' argument to make it so it only shows in the server console.
//
// Announce can also utilize a format script with the 'format' argument. See <@link language Format Script Containers>.
// //
//
// Note that the default announce mode (that shows for all players) relies on the Spigot broadcast system, which requires the permission "bukkit.broadcast.user" to see broadcasts.
//
// @Tags
Expand All @@ -68,15 +68,7 @@ enum AnnounceType {ALL, TO_OPS, TO_FLAGGED, TO_CONSOLE}

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

// Users tend to forget quotes sometimes on commands like this, so
// let's check if there are more argument than usual.
if (scriptEntry.getArguments().size() > 3) {
throw new InvalidArgumentsException("Too many arguments! Did you forget a 'quote'?");
}

for (Argument arg : scriptEntry.getProcessedArgs()) {

if (!scriptEntry.hasObject("type")
&& arg.matches("to_ops")) {
scriptEntry.addObject("type", AnnounceType.TO_OPS);
Expand All @@ -103,16 +95,11 @@ else if (!scriptEntry.hasObject("format")
else if (!scriptEntry.hasObject("text")) {
scriptEntry.addObject("text", new ElementTag(arg.getRawValue()));
}

}

// If text is missing, alert the console.
if (!scriptEntry.hasObject("text")) {
throw new InvalidArgumentsException("Missing text argument!");
}

scriptEntry.defaultObject("type", AnnounceType.ALL);

}

@Override
Expand All @@ -124,17 +111,14 @@ public void execute(ScriptEntry scriptEntry) {
AnnounceType type = (AnnounceType) scriptEntry.getObject("type");
FormatScriptContainer format = (FormatScriptContainer) scriptEntry.getObject("format");
ElementTag flag = scriptEntry.getElement("flag");

if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(),
ArgumentHelper.debugObj("Message", text)
+ (format != null ? ArgumentHelper.debugObj("Format", format.getName()) : "")
+ ArgumentHelper.debugObj("Type", type.name())
+ (flag != null ? ArgumentHelper.debugObj("Flag_Name", flag) : ""));
}

String message = format != null ? format.getFormattedText(text.asString(), scriptEntry) : text.asString();

// Use Bukkit to broadcast the message to everybody in the server.
if (type == AnnounceType.ALL) {
Denizen.getInstance().getServer().spigot().broadcast(FormattedTextHelper.parse(message, ChatColor.WHITE));
Expand All @@ -155,7 +139,7 @@ else if (type == AnnounceType.TO_FLAGGED) {
}
}
else if (type == AnnounceType.TO_CONSOLE) {
Bukkit.getServer().getConsoleSender().sendMessage(message);
Bukkit.getServer().getConsoleSender().spigot().sendMessage(FormattedTextHelper.parse(message, ChatColor.WHITE));
}
}
}
Expand Down

0 comments on commit aaa3b38

Please sign in to comment.