From ccc5c1bc208312cdfe852186cb8ecd35f06a62a4 Mon Sep 17 00:00:00 2001 From: Ziggy Date: Mon, 3 Aug 2015 06:04:48 +0200 Subject: [PATCH 1/2] Created an IntentFactory which currently supports common operations such as system messages and in-game mails --- src/utilities/IntentFactory.java | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/utilities/IntentFactory.java diff --git a/src/utilities/IntentFactory.java b/src/utilities/IntentFactory.java new file mode 100644 index 000000000..f5ba6229d --- /dev/null +++ b/src/utilities/IntentFactory.java @@ -0,0 +1,42 @@ +package utilities; + +import resources.encodables.player.Mail; +import resources.objects.SWGObject; +import resources.player.Player; +import intents.chat.ChatBroadcastIntent; +import intents.chat.ChatBroadcastIntent.BroadcastType; +import intents.chat.PersistentMessageIntent; + +/** + * @author Mads + * This class is to be used exclusively in cases where using the intents directly isn't practical. + */ +public final class IntentFactory { + + private void broadcast(String message, Player source, BroadcastType type) { + new ChatBroadcastIntent(message, source, source.getCreatureObject().getTerrain(), type).broadcast(); + } + + public void broadcastArea(String message, Player source) { + broadcast(message, source, BroadcastType.AREA); + } + + public void broadcastGalaxy(String message, Player source) { + broadcast(message, source, BroadcastType.GALAXY); + } + + public void broadcastPersonal(String message, Player source) { + broadcast(message, source, BroadcastType.PERSONAL); + } + + public void broadcastPlanet(String message, Player source) { + broadcast(message, source, BroadcastType.PLANET); + } + + public void sendMail(SWGObject receiver, String sender, String subject, String message) { + Mail mail = new Mail(sender, subject, message, receiver.getObjectId()); + + new PersistentMessageIntent(receiver, mail, receiver.getOwner().getGalaxyName()).broadcast(); + } + +} From e3097069bcd415b02fd6ab4f27244b8299ba14d1 Mon Sep 17 00:00:00 2001 From: Ziggy Date: Mon, 3 Aug 2015 06:05:35 +0200 Subject: [PATCH 2/2] The IntentFactory can now be referenced in scripts without the need to import the class --- src/utilities/Scripts.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utilities/Scripts.java b/src/utilities/Scripts.java index 409bd90e5..ff8859506 100644 --- a/src/utilities/Scripts.java +++ b/src/utilities/Scripts.java @@ -41,6 +41,10 @@ public class Scripts { private static final ScriptEngine ENGINE = new ScriptEngineManager().getEngineByName("nashorn"); private static final Invocable INVOCABLE = (Invocable) ENGINE; + static { + ENGINE.put("intentFactory", new IntentFactory()); + } + // Prevents instantiation. private Scripts() {}