mChatSuite additions (incomplete)

This commit is contained in:
Sleaker 2012-01-29 16:06:15 -08:00
parent 3d84e901de
commit 8057eac89a
3 changed files with 252 additions and 0 deletions

BIN
lib/mChatSuite-DEV.jar Normal file

Binary file not shown.

View File

@ -111,6 +111,13 @@
<scope>system</scope> <scope>system</scope>
<systemPath>${project.basedir}/lib/mChat.jar</systemPath> <systemPath>${project.basedir}/lib/mChat.jar</systemPath>
</dependency> </dependency>
<dependency>
<groupId>in.mDev</groupId>
<artifactId>mChatSuite</artifactId>
<version>DEV</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/mChatSuite-DEV.jar</systemPath>
</dependency>
<dependency> <dependency>
<groupId>me.mjolnir.mineconomy.MineConomy</groupId> <groupId>me.mjolnir.mineconomy.MineConomy</groupId>
<artifactId>MineConomy</artifactId> <artifactId>MineConomy</artifactId>

View File

@ -0,0 +1,245 @@
package net.milkbowl.vault.chat.plugins;
import in.mDev.MiracleM4n.mChatSuite.MInfoReader;
import in.mDev.MiracleM4n.mChatSuite.MInfoWriter;
import in.mDev.MiracleM4n.mChatSuite.mChatSuite;
import java.util.logging.Logger;
import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.plugin.Plugin;
public class Chat_mChatSuite extends Chat {
private static final Logger log = Logger.getLogger("Minecraft");
private final String name = "mChatSuite";
private Plugin plugin = null;
private mChatSuite mChat = null;
private MInfoReader mReader = null;
private MInfoWriter mWriter = null;
public Chat_mChatSuite(Plugin plugin, Permission permissions) {
super(permissions);
this.plugin = plugin;
Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin);
// Load Plugin in case it was loaded before
if (mChat == null) {
Plugin chat = plugin.getServer().getPluginManager().getPlugin("mChatSuite");
if (chat != null) {
mChat = (mChatSuite) chat;
mReader = mChat.getInfoReader();
mWriter = mChat.getInfoWriter();
log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "mChatSuite"));
}
}
}
public class PermissionServerListener implements Listener {
Chat_mChatSuite chat = null;
public PermissionServerListener(Chat_mChatSuite chat) {
this.chat = chat;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginEnable(PluginEnableEvent event) {
if (this.chat.mChat == null) {
Plugin chat = plugin.getServer().getPluginManager().getPlugin("mChat");
if (chat != null) {
this.chat.mChat = (mChatSuite) chat;
mReader = mChat.getInfoReader();
mWriter = mChat.getInfoWriter();
log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "mChat"));
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginDisable(PluginDisableEvent event) {
if (this.chat.mChat != null) {
if (event.getPlugin().getDescription().getName().equals("mChat")) {
this.chat.mChat = null;
mReader = null;
mWriter = null;
log.info(String.format("[%s][Chat] %s un-hooked.", plugin.getDescription().getName(), "mChat"));
}
}
}
}
@Override
public String getName() {
return name;
}
@Override
public boolean isEnabled() {
return mChat != null && mChat.isEnabled();
}
@Override
public String getPlayerPrefix(String world, String player) {
return mReader.getRawPrefix(player, world);
}
@Override
public void setPlayerPrefix(String world, String player, String prefix) {
setPlayerInfoValue(world, player, "prefix", prefix);
}
@Override
public String getPlayerSuffix(String world, String player) {
return mReader.getRawSuffix(player, world);
}
@Override
public void setPlayerSuffix(String world, String player, String suffix) {
setPlayerInfoValue(world, player, "suffix", suffix);
}
@Override
public String getGroupPrefix(String world, String group) {
throw new UnsupportedOperationException("mChat does not support group info nodes");
}
@Override
public void setGroupPrefix(String world, String group, String prefix) {
throw new UnsupportedOperationException("mChat does not support group info nodes");
}
@Override
public String getGroupSuffix(String world, String group) {
throw new UnsupportedOperationException("mChat does not support group info nodes");
}
@Override
public void setGroupSuffix(String world, String group, String suffix) {
throw new UnsupportedOperationException("mChat does not support group info nodes");
}
@Override
public int getPlayerInfoInteger(String world, String player, String node, int defaultValue) {
String val = getPlayerInfoValue(world, player, node);
if (val == null || val.equals("")) {
return defaultValue;
}
try {
return Integer.parseInt(val);
} catch (NumberFormatException e) {
return defaultValue;
}
}
@Override
public void setPlayerInfoInteger(String world, String player, String node, int value) {
setPlayerInfoValue(world, player, node, value);
}
@Override
public int getGroupInfoInteger(String world, String group, String node, int defaultValue) {
throw new UnsupportedOperationException("mChat does not support group info nodes");
}
@Override
public void setGroupInfoInteger(String world, String group, String node, int value) {
throw new UnsupportedOperationException("mChat does not support group info nodes");
}
@Override
public double getPlayerInfoDouble(String world, String player, String node, double defaultValue) {
String val = getPlayerInfoValue(world, player, node);
if (val == null || val.equals("")) {
return defaultValue;
}
try {
return Double.parseDouble(val);
} catch (NumberFormatException e) {
return defaultValue;
}
}
@Override
public void setPlayerInfoDouble(String world, String player, String node, double value) {
setPlayerInfoValue(world, player, node, value);
}
@Override
public double getGroupInfoDouble(String world, String group, String node,double defaultValue) {
throw new UnsupportedOperationException("mChat does not support group info nodes");
}
@Override
public void setGroupInfoDouble(String world, String group, String node, double value) {
throw new UnsupportedOperationException("mChat does not support group info nodes");
}
@Override
public boolean getPlayerInfoBoolean(String world, String player, String node, boolean defaultValue) {
String val = getPlayerInfoValue(world, player, node);
if (val == null || val.equals("")) {
return defaultValue;
}
try {
return Boolean.parseBoolean(val);
} catch (NumberFormatException e) {
return defaultValue;
}
}
@Override
public void setPlayerInfoBoolean(String world, String player, String node, boolean value) {
setPlayerInfoValue(world, player, node, value);
}
@Override
public boolean getGroupInfoBoolean(String world, String group, String node, boolean defaultValue) {
throw new UnsupportedOperationException("mChat does not support group info nodes");
}
@Override
public void setGroupInfoBoolean(String world, String group, String node, boolean value) {
throw new UnsupportedOperationException("mChat does not support group info nodes");
}
@Override
public String getPlayerInfoString(String world, String player, String node, String defaultValue) {
return getPlayerInfoValue(world, player, node);
}
@Override
public void setPlayerInfoString(String world, String player, String node, String value) {
setPlayerInfoValue(world, player, node, value);
}
@Override
public String getGroupInfoString(String world, String group, String node, String defaultValue) {
throw new UnsupportedOperationException("mChat does not support group info nodes");
}
@Override
public void setGroupInfoString(String world, String group, String node, String value) {
throw new UnsupportedOperationException("mChat does not support group info nodes");
}
private void setPlayerInfoValue(String world, String player, String node, Object value) {
if (world == null) {
mWriter.addPlayerInfoVar(player, node, value.toString());
} else {
mWriter.addPlayerWorld(player, world);
mWriter.addPlayerWorldVar(player, world, node, value.toString());
}
}
private String getPlayerInfoValue(String world, String player, String node) {
return mReader.getRawInfo(player, world, node);
}
}