Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dcf6422
commit b0f4180
Showing
2 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/main/java/net/aufdemrand/denizen/scripts/commands/player/ActionBarCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package net.aufdemrand.denizen.scripts.commands.player; | ||
|
||
import net.aufdemrand.denizen.BukkitScriptEntryData; | ||
import net.aufdemrand.denizen.objects.dPlayer; | ||
import net.aufdemrand.denizen.scripts.containers.core.FormatScriptContainer; | ||
import net.aufdemrand.denizen.utilities.debugging.dB; | ||
import net.aufdemrand.denizen.utilities.packets.ActionBar; | ||
import net.aufdemrand.denizencore.exceptions.CommandExecutionException; | ||
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException; | ||
import net.aufdemrand.denizencore.objects.Element; | ||
import net.aufdemrand.denizencore.objects.aH; | ||
import net.aufdemrand.denizencore.objects.dList; | ||
import net.aufdemrand.denizencore.scripts.ScriptEntry; | ||
import net.aufdemrand.denizencore.scripts.ScriptRegistry; | ||
import net.aufdemrand.denizencore.scripts.commands.AbstractCommand; | ||
import net.aufdemrand.denizencore.tags.TagManager; | ||
|
||
import java.text.Format; | ||
import java.text.Normalizer; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class ActionBarCommand extends AbstractCommand { | ||
|
||
@Override | ||
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException { | ||
|
||
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) { | ||
|
||
if (arg.matchesPrefix("format", "f")) { | ||
FormatScriptContainer format = null; | ||
String formatStr = arg.getValue(); | ||
format = ScriptRegistry.getScriptContainer(formatStr); | ||
if (format == null) { | ||
dB.echoError("Could not find format script matching '" + formatStr + '\''); | ||
} | ||
scriptEntry.addObject("format", format); | ||
} | ||
if (arg.matchesPrefix("targets", "target") | ||
&& arg.matchesArgumentList(dPlayer.class)) { | ||
scriptEntry.addObject("targets", arg.asType(dList.class).filter(dPlayer.class)); | ||
} | ||
else if (!scriptEntry.hasObject("text")) { | ||
scriptEntry.addObject("text", new Element(TagManager.cleanOutputFully(arg.raw_value))); | ||
} | ||
} | ||
|
||
if (!scriptEntry.hasObject("text")) { | ||
throw new InvalidArgumentsException("Must specify a message!"); | ||
} | ||
|
||
if (!scriptEntry.hasObject("targets") && !((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer()) { | ||
throw new InvalidArgumentsException("Must specify target(s)."); | ||
} | ||
|
||
if (!scriptEntry.hasObject("targets")) { | ||
BukkitScriptEntryData data = (BukkitScriptEntryData) scriptEntry.entryData; | ||
if (!data.hasPlayer()) { | ||
throw new InvalidArgumentsException("Must specify valid player Targets!"); | ||
} | ||
else { | ||
scriptEntry.addObject("targets", | ||
Arrays.asList(data.getPlayer())); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { | ||
|
||
Element text = scriptEntry.getElement("text"); | ||
FormatScriptContainer format = (FormatScriptContainer) scriptEntry.getObject("format"); | ||
|
||
List<dPlayer> targets = (List<dPlayer>) scriptEntry.getObject("targets"); | ||
|
||
dB.report(scriptEntry, getName(), text.debug() + aH.debugList("Targets", targets)); | ||
if (format != null) { | ||
text = new Element(format.getFormattedText(scriptEntry)); | ||
} | ||
|
||
for (dPlayer player : targets) { | ||
if (player.isValid() && player.isOnline()) { | ||
ActionBar.sendActionBarMessage(player.getPlayerEntity(), text.asString()); | ||
} | ||
else { | ||
dB.echoError(scriptEntry.getResidingQueue(), "Tried to send action bar message to non-existent or offline player!"); | ||
} | ||
} | ||
|
||
} | ||
|
||
} |