@@ -27,11 +27,12 @@
package net.breiden.spout.messagechanger.events;

import net.breiden.spout.messagechanger.MessageChanger;
import net.breiden.spout.messagechanger.enums.DEFAULT_EVENTS;
import net.breiden.spout.messagechanger.messages.SpoutMessages;
import org.spout.api.event.EventHandler;
import org.spout.api.event.Listener;
import org.spout.api.event.player.PlayerJoinEvent;
import org.spout.api.event.player.PlayerKickEvent;
import org.spout.api.event.player.PlayerLoginEvent;
import org.spout.api.event.player.*;
import org.spout.api.plugin.CommonPlugin;

/**
* Contains all the Spout Player events monitored by this plugin
@@ -43,15 +44,27 @@ public class SpoutPlayerEvents implements Listener {

private final MessageChanger plugin;

public SpoutPlayerEvents(MessageChanger plugin) {
private final SpoutMessages spoutMessages;

this.plugin = plugin;
public SpoutPlayerEvents(CommonPlugin plugin) {

this.plugin = (MessageChanger) plugin;
spoutMessages = SpoutMessages.getInstance();

}

@EventHandler
public void onPlayerLogin(PlayerLoginEvent event) {
switch (event..getResult()) {
if (event.isCancelled()){
return;
}
String message = event.getMessage();
// Is the server full?
if (!event.isAllowed()){
event.setMessage(spoutMessages.getNewMessage(DEFAULT_EVENTS.KICK_FULL.toString(),event.getPlayer(),message));
}
// todo waiting for PlayerWhiteList event
/*switch (event.g) {
case KICK_BANNED:
event.setKickMessage(plugin.getMessage("KICK_BANNED", event.getPlayer(), event.getKickMessage()));
break;
@@ -61,46 +74,47 @@ public void onPlayerLogin(PlayerLoginEvent event) {
case KICK_FULL:
event.setKickMessage(plugin.getMessage("KICK_FULL", event.getPlayer(), event.getKickMessage()));
break;
}
}*/
}

@EventHandler
public void onPlayerBan(PlayerBanKickEvent event){
if (event.isCancelled()){
return;
}
event.setMessage(spoutMessages.getNewMessage(DEFAULT_EVENTS.KICK_BANNED.toString(),event.getPlayer(),event.getMessage()));
}


@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
String msg = plugin.getMessage("PLAYER_JOIN", event.getPlayer(), event.getJoinMessage());
if (msg.equals("")) {
event.setJoinMessage(null);
} else {
event.setJoinMessage(plugin.getMessage("PLAYER_JOIN", event.getPlayer(), event.getJoinMessage()));
}
if (event.isCancelled()){
return;
}
event.setMessage(spoutMessages.getNewMessage(DEFAULT_EVENTS.PLAYER_JOIN.toString(),event.getPlayer(),event.getMessage()));
}

@EventHandler
public void onPlayerKick(PlayerKickEvent event) {
if (plugin.ignore) {
plugin.ignore = false;
if (event.isCancelled()){
return;
}
if (plugin.getIgnoreKick()) {
plugin.disableIgnoreKick();
return;
}

String msg = plugin.getMessage("KICK_KICK_LEAVEMSG", event.getPlayer(), event.getReason());
if (msg.equals("")) {
event.setLeaveMessage(null);
} else {
event.setLeaveMessage(msg);
}
event.setReason(plugin.getMessage("KICK_KICK_REASON", event.getPlayer(), event.getReason()));
event.setKickReason(spoutMessages.getNewMessage(DEFAULT_EVENTS.KICK_KICK_REASON.toString(),event.getPlayer(),event.getKickReason()));
event.setMessage(spoutMessages.getNewMessage(DEFAULT_EVENTS.KICK_KICK_LEAVEMSG.toString(),event.getPlayer(),event.getMessage()));
}

@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
String msg = plugin.getMessage("PLAYER_QUIT", event.getPlayer(), event.getQuitMessage());
if (msg.equals("")) {
event.setQuitMessage(null);
} else {
event.setQuitMessage(msg);
}
public void onPlayerQuit(PlayerLeaveEvent event) {
event.setMessage(spoutMessages.getNewMessage(DEFAULT_EVENTS.PLAYER_QUIT.toString(),event.getPlayer(), event.getMessage()));
}

@EventHandler

// todo wait for implementation of PlayerChangedWorldEvent
/* @EventHandler
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
String msg = plugin.getMessage("CHANGED_WORLD", event.getPlayer(), "");
if (msg.equals("")) {
@@ -112,7 +126,7 @@ public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
}
msg = msg.replace("%fromWorld", fromWorld);
event.getPlayer().sendMessage(msg);
}
}*/


}
@@ -0,0 +1,75 @@
/******************************************************************************
* This file is part of MessageChanger (http://www.spout.org/). *
* *
* MessageChanger is licensed under the SpoutDev License Version 1. *
* *
* MessageChanger is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published by*
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* In addition, 180 days after any changes are published, you can use the *
* software, incorporating those changes, under the terms of the MIT license, *
* as described in the SpoutDev License Version 1. *
* *
* MessageChanger is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License, *
* the MIT license and the SpoutDev License Version 1 along with this program.*
* If not, see <http://www.gnu.org/licenses/> for the GNU Lesser General Public
* License and see <http://www.spout.org/SpoutDevLicenseV1.txt> for the full license,
* including the MIT license. *
******************************************************************************/

/******************************************************************************
* This file is part of MessageChanger (http://www.spout.org/). *
* *
* MessageChanger is licensed under the SpoutDev License Version 1. *
* *
* MessageChanger is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published by*
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* In addition, 180 days after any changes are published, you can use the *
* software, incorporating those changes, under the terms of the MIT license, *
* as described in the SpoutDev License Version 1. *
* *
* MessageChanger is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License, *
* the MIT license and the SpoutDev License Version 1 along with this program.*
* If not, see <http://www.gnu.org/licenses/> for the GNU Lesser General Public
* License and see <http://www.spout.org/SpoutDevLicenseV1.txt> for the full license,
* including the MIT license. *
******************************************************************************/

package net.breiden.spout.messagechanger.events;

import org.spout.api.event.Listener;
import org.spout.api.plugin.CommonPlugin;

/**
* Checks for plugin loading so that
*
* @author $Author: dredhorse$
* @version $FullVersion$
*/
public class SpoutPluginEvents implements Listener {

private final CommonPlugin main;

public SpoutPluginEvents(CommonPlugin main) {
this.main = main;
// todo implement the triggering of additional Messages

}


}
@@ -0,0 +1,137 @@
/******************************************************************************
* This file is part of MessageChanger (http://www.spout.org/). *
* *
* MessageChanger is licensed under the SpoutDev License Version 1. *
* *
* MessageChanger is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published by*
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* In addition, 180 days after any changes are published, you can use the *
* software, incorporating those changes, under the terms of the MIT license, *
* as described in the SpoutDev License Version 1. *
* *
* MessageChanger is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License, *
* the MIT license and the SpoutDev License Version 1 along with this program.*
* If not, see <http://www.gnu.org/licenses/> for the GNU Lesser General Public
* License and see <http://www.spout.org/SpoutDevLicenseV1.txt> for the full license,
* including the MIT license. *
******************************************************************************/

package net.breiden.spout.messagechanger.helper.file;

import net.breiden.spout.messagechanger.enums.DEFAULT_EVENTS;
import org.spout.api.plugin.CommonPlugin;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
* Handels the general management of the loading / saving the messages used to display during the events.
*
* @author $Author: dredhorse$
* @version $FullVersion$
*/
public class DefaultMessagesHandler {

/**
* Instance of this class
*/
private DefaultMessagesHandler instance;

/**
* Instance of the Plugin
*/
private CommonPlugin main;

/**
* Contains a mapping between DEFAULT / PERMISSION.NODE and EVENT , MESSAGE for the Server Default Messages
*
*/
private HashMap<String, HashMap<DEFAULT_EVENTS, String>> defaultMessages = new HashMap<String, HashMap<DEFAULT_EVENTS, String>>();


/**
* Order of the permission nodes
*/
private List<String> categoryOrder = Arrays.asList("permnode1", "permnode2");


/**
* Initialize the Messages
* @param main instance of the plugin
*/
public DefaultMessagesHandler(CommonPlugin main){
instance = this;
this.main = main;
init();
}



private void init(){
// adding the default values
HashMap<DEFAULT_EVENTS,String> temp = new HashMap<DEFAULT_EVENTS, String>();
temp.put(DEFAULT_EVENTS.CHANGED_WORLD,"Welcome traveler from %(fromWorld) in %(world)");
temp.put(DEFAULT_EVENTS.KICK_BANNED,"%(msg)");
temp.put(DEFAULT_EVENTS.KICK_FULL,"%(msg)");
temp.put(DEFAULT_EVENTS.KICK_KICK_LEAVEMSG,"%(msg)");
temp.put(DEFAULT_EVENTS.KICK_KICK_REASON,"%(msg)");
temp.put(DEFAULT_EVENTS.KICK_KICK_REASON,"%(msg)");
temp.put(DEFAULT_EVENTS.KICK_WHITELIST,"%(msg)");
temp.put(DEFAULT_EVENTS.PLAYER_JOIN,"Hello &b%(player)&f in world %(world)");
temp.put(DEFAULT_EVENTS.PLAYER_QUIT,"%(msg)");
temp.put(DEFAULT_EVENTS.SERVER_STOP,"Testing the server...");
defaultMessages.put("default",temp);
temp.clear();
temp.put(DEFAULT_EVENTS.PLAYER_JOIN,"Welcome the admin");
defaultMessages.put("permnode1",temp);
temp.clear();
temp.put(DEFAULT_EVENTS.SERVER_STOP,"Oh well...");
defaultMessages.put("permnode2",temp);

//todo loading and saving the messages


}




/**
* Return the default event message
*
* @param event
* @return
*/
public String getMessage (DEFAULT_EVENTS event){
return defaultMessages.get("default").get(event);
}


/**
* Return the event message for a certain permission node
*
* @param permNode
* @param event
* @return
*/
public String getMessage (String permNode, DEFAULT_EVENTS event){
if (defaultMessages.containsKey(permNode.toLowerCase())){
return defaultMessages.get(permNode).get(event);
}
return getMessage(event);
}

public List<String> getCategoryOrder(){
return categoryOrder;
}

}
@@ -26,12 +26,17 @@

package net.breiden.spout.messagechanger.helper.file;

import org.spout.api.plugin.CommonPlugin;

/**
* Handels the general management of the loading / saving the messages used to display during the events.
* Handels loading and saving of the Vanilla messages
*
* @author $Author: dredhorse$
* @version $FullVersion$
*/
public class MessageChangerHandler {
public class VanillaMessagesHandler {

public VanillaMessagesHandler(CommonPlugin main) {

}
}
@@ -24,20 +24,100 @@
* including the MIT license. *
******************************************************************************/

/******************************************************************************
* This file is part of MessageChanger (http://www.spout.org/). *
* *
* MessageChanger is licensed under the SpoutDev License Version 1. *
* *
* MessageChanger is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published by*
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* In addition, 180 days after any changes are published, you can use the *
* software, incorporating those changes, under the terms of the MIT license, *
* as described in the SpoutDev License Version 1. *
* *
* MessageChanger is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License, *
* the MIT license and the SpoutDev License Version 1 along with this program.*
* If not, see <http://www.gnu.org/licenses/> for the GNU Lesser General Public
* License and see <http://www.spout.org/SpoutDevLicenseV1.txt> for the full license,
* including the MIT license. *
******************************************************************************/

package net.breiden.spout.messagechanger.messages;

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

/**
* Contains code to handle the spout specific messages
* Contains code to handle the Spout specific messages
*
* @author $Author: dredhorse$
* @version $FullVersion$
*/
public class SpoutMessages implements MessagesInterface {

private DefaultMessagesHandler defaultMessagesHandler;

private static SpoutMessages instance;

public SpoutMessages (CommonPlugin main){
instance = this;
defaultMessagesHandler = new DefaultMessagesHandler(main);
new SpoutPlayerEvents(main);
// todo init the event handlers
}

public static SpoutMessages getInstance(){
return instance;
}


@Override
public String getNewMessage(String event, Player player, String defaultMessage) {
return null; //To change body of implemented methods use File | Settings | File Templates.
DEFAULT_EVENTS defaultEvent = DEFAULT_EVENTS.valueOf(event);
String message = defaultMessage;
if (defaultEvent != null){
message = defaultMessagesHandler.getMessage(getCategory(player),defaultEvent);
if (message == null || message.equals("%(msg)")){
message = defaultMessage;
}

}
return Messenger.dictFormat(player, message);
}

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


private String getCategory(Player player) {
for (String category : defaultMessagesHandler.getCategoryOrder()) {
if (player.hasPermission("messagechanger.message." + category)) {
return category;
}
}
return "default";
}

}
@@ -0,0 +1,43 @@
/******************************************************************************
* This file is part of MessageChanger (http://www.spout.org/). *
* *
* MessageChanger is licensed under the SpoutDev License Version 1. *
* *
* MessageChanger is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published by*
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* In addition, 180 days after any changes are published, you can use the *
* software, incorporating those changes, under the terms of the MIT license, *
* as described in the SpoutDev License Version 1. *
* *
* MessageChanger is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License, *
* the MIT license and the SpoutDev License Version 1 along with this program.*
* If not, see <http://www.gnu.org/licenses/> for the GNU Lesser General Public
* License and see <http://www.spout.org/SpoutDevLicenseV1.txt> for the full license,
* including the MIT license. *
******************************************************************************/

package net.breiden.spout.messagechanger.messages;

import org.spout.api.player.Player;

/**
* Contains code to handle the vanilla specific messages
*
* @author $Author: dredhorse$
* @version $FullVersion$
*/
public class VanillaMessages implements MessagesInterface {

@Override
public String getNewMessage(String event, Player player, String defaultMessage) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
}