@@ -54,12 +54,16 @@

import net.breiden.spout.messagechanger.enums.DEFAULT_EVENTS;
import net.breiden.spout.messagechanger.events.SpoutPlayerEvents;
import net.breiden.spout.messagechanger.helper.Logger;
import net.breiden.spout.messagechanger.helper.Messenger;
import net.breiden.spout.messagechanger.helper.file.DefaultMessagesHandler;
import org.spout.api.chat.ChatArguments;
import org.spout.api.chat.style.ChatStyle;
import org.spout.api.player.Player;
import org.spout.api.plugin.CommonPlugin;

import java.util.List;

/**
* Contains code to handle the Spout specific messages
*
@@ -75,7 +79,8 @@ public class SpoutMessages implements MessagesInterface {
public SpoutMessages (CommonPlugin main){
instance = this;
defaultMessagesHandler = new DefaultMessagesHandler(main);
new SpoutPlayerEvents(main);
main.getEngine().getEventManager().registerEvents(new SpoutPlayerEvents(main), main);

// todo init the event handlers
}

@@ -86,10 +91,14 @@ public static SpoutMessages getInstance(){

@Override
public String getNewMessage(String event, Player player, String defaultMessage) {
Logger.debug("NewMessage for: " + event);
DEFAULT_EVENTS defaultEvent = DEFAULT_EVENTS.valueOf(event);
String message = defaultMessage;
if (defaultEvent != null){
String category = getCategory(player);
Logger.debug("Category",category);
message = defaultMessagesHandler.getMessage(getCategory(player),defaultEvent);
Logger.debug("message",message);
if (message == null || message.equals("%(msg)")){
message = defaultMessage;
}
@@ -98,16 +107,16 @@ public String getNewMessage(String event, Player player, String defaultMessage)
return Messenger.dictFormat(player, message);
}

public String getNewMessage(String event, Player player, Object[] defaultMessage){
public List<Object> getNewMessageFromObjects(String event, Player player, Object[] defaultMessage){
String message = "";
for (Object obj : defaultMessage){
if (obj instanceof ChatStyle){
message = message + ((ChatStyle) obj).getName();
message = message + "{{"+((ChatStyle) obj).getName() +"}}";
} else {
message = message + (String) obj;
message = message + obj;
}
}
return getNewMessage(event, player, message);
return ChatArguments.fromString(getNewMessage(event, player, message)).getArguments();
}


@@ -74,13 +74,13 @@ public enum PERMISSIONS {


/**
* Example Permission HLP_CLS_TEST which will be turned into hlp.cls.test, </p>
* has a description of "Base permission for the HelperClass" and an RequireAll permissions of false
* Example Permission MESSAGECHANGER which will be turned into messagechanger, </p>
* has a description of "Base permission for MessageChanger" and an RequireAll permissions of false
*/

HLP_CLS_TEST("Base permission for the HelperClass", false),
HLP_CLS_USER("User permission", false, HLP_CLS_TEST),
HLP_CLS_ADMIN("Admin permission, will also be used for broadcasting messages to admins", false, HLP_CLS_TEST, HLP_CLS_USER);
MESSAGECHANGER("Base permission for MessageChanger", false),
MESSAGECHANGER_MESSAGE("Base permission for the messages", false, MESSAGECHANGER),
MESSAGECHANGER_ADMIN("Admin permission, will also be used for broadcasting messages to admins", false, MESSAGECHANGER, MESSAGECHANGER_MESSAGE);


// NO CHANGES BELOW HERE!!!!!
@@ -44,17 +44,17 @@ public void testGetConfigComment() throws Exception {
*/
@Test
public void testGetConfigOption() throws Exception {
boolean bool = (Boolean) CONFIG.DEBUG_LOG_ENABLED.getConfigOption();
Assert.assertEquals(bool, false);
boolean bool = (Boolean) CONFIG.DEBUG_LOG_TO_FILE.getConfigOption();
Assert.assertEquals(bool, true);
}

/**
* Method: setConfigOption(Object configOption)
*/
@Test
public void testSetConfigOption() throws Exception {
CONFIG.DEBUG_LOG_ENABLED.setConfigOption(false);
boolean bool = (Boolean) CONFIG.DEBUG_LOG_ENABLED.getConfigOption();
CONFIG.DEBUG_LOG_TO_FILE.setConfigOption(false);
boolean bool = (Boolean) CONFIG.DEBUG_LOG_TO_FILE.getConfigOption();
Assert.assertEquals(bool, false);
}

@@ -63,8 +63,8 @@ public void testSetConfigOption() throws Exception {
*/
@Test
public void testSetConfigurationOption() throws Exception {
CONFIG.DEBUG_LOG_ENABLED.setConfigurationOption(false);
boolean bool = (Boolean) CONFIG.DEBUG_LOG_ENABLED.getConfigOption();
CONFIG.DEBUG_LOG_TO_FILE.setConfigurationOption(false);
boolean bool = (Boolean) CONFIG.DEBUG_LOG_TO_FILE.getConfigOption();
Assert.assertEquals(bool, false);
}

@@ -82,7 +82,7 @@ public void testGetString() throws Exception {
@Test
public void testGetBoolean() throws Exception {
// must be false because we did set it this way before!
Assert.assertEquals(CONFIG.DEBUG_LOG_ENABLED.getBoolean(), false);
Assert.assertEquals(CONFIG.DEBUG_LOG_TO_FILE.getBoolean(), false);
}

/**
@@ -27,8 +27,8 @@ public void after() throws Exception {
*/
@Test
public void testGetComment() throws Exception {
PERMISSIONS.HLP_CLS_ADMIN.setComment("This is a test");
Assert.assertEquals("This is a test", PERMISSIONS.HLP_CLS_ADMIN.getComment());
PERMISSIONS.MESSAGECHANGER_ADMIN.setComment("This is a test");
Assert.assertEquals("This is a test", PERMISSIONS.MESSAGECHANGER_ADMIN.getComment());

}

@@ -37,7 +37,7 @@ public void testGetComment() throws Exception {
*/
@Test
public void testToString() throws Exception {
Assert.assertEquals(PERMISSIONS.HLP_CLS_TEST.toString(), "hlp.cls.test");
Assert.assertEquals(PERMISSIONS.MESSAGECHANGER.toString(), "messagechanger");
}