mirror of
https://github.com/ProjectSWGCore/Holocore.git
synced 2026-08-02 03:16:42 -04:00
Merged in M4SS/holocore/intent-factory (pull request #55)
Implemented CORE-237
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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() {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user