package org.groovymud.utils;
/* Copyright 2008 Matthew Corby-Eaglen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.groovymud.engine.event.EventScope;
import org.groovymud.engine.event.messages.MessageEvent;
import org.groovymud.object.MudObject;
/**
* a statically accessed (spit) set of messenger utils
*
* sends messages to various scopes
*
* sending a message to global will send it to everyone (eventually)
* sending the message to room will send it to the room contents (and below)
* sending it to player scope will keep the message private to the player
*
* @author matt
*
*/
public class MessengerUtils {
public static void sendMessageToPlayer(MudObject source, String sourceMessage) {
sendMessage(EventScope.PLAYER_SCOPE, source, sourceMessage, null);
}
public static void sendMessageToRoom(MudObject source, String sourceMessage, String roomMessage) {
sendMessage(EventScope.ROOM_SCOPE, source, sourceMessage, roomMessage);
}
public static void sendMessageToMud(MudObject source, String sourceMessage, String roomMessage) {
sendMessage(EventScope.GLOBAL_SCOPE, source, sourceMessage, roomMessage);
}
public static void sendMessage(EventScope scope, MudObject source, String sourceMessage, String roomMessage) {
MessageEvent msgEvent = new MessageEvent(scope);
msgEvent.setSourceMessage(sourceMessage);
msgEvent.setScopeMessage(roomMessage);
source.fireEvent(msgEvent);
}
}