Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IRC addition #7

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
<classpathentry kind="lib" path="../lib/HeroicDeath.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/Towny"/>
<classpathentry kind="output" path="bin"/>
</classpath>
</classpath>
1 change: 1 addition & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<fileset dir="./src" includes="Channels.yml"/>
<fileset dir="./src" includes="ChatConfig.yml"/>
<fileset dir="./src" includes="plugin.yml"/>
<zipfileset excludes="META-INF/*.SF" src="../lib/pircbot.jar"/>
</jar>
</target>
</project>
18 changes: 12 additions & 6 deletions src/Channels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ Channels:
channeltag: '&f[g]'
messagecolour: '&f'
permission: 'towny.chat.general'
craftIRCTag: 'admin'
IRCChannel: ''
IRCToGameChatFormat: '{Channel} {Ranked}{Sender}: &f{Message}'
IRCSendToGame: false
range: '-1'

town:
Expand All @@ -47,7 +49,7 @@ Channels:
channeltag: '&f[&3TC&f]'
messagecolour: '&b'
permission: 'towny.chat.town'
craftIRCTag: 'admin'
IRCChannel: ''
range: '-1'

nation:
Expand All @@ -56,7 +58,7 @@ Channels:
channeltag: '&f[&6NC&f]'
messagecolour: '&e'
permission: 'towny.chat.nation'
craftIRCTag: 'admin'
IRCChannel: ''
range: '-1'

admin:
Expand All @@ -65,7 +67,9 @@ Channels:
channeltag: '&f[&4ADMIN&f]'
messagecolour: '&c'
permission: 'towny.chat.admin'
craftIRCTag: 'admin'
IRCChannel: ''
IRCToGameChatFormat: '{Channel} {Ranked}{Sender}: &f{Message}'
IRCSendToGame: false
range: '-1'

mod:
Expand All @@ -74,7 +78,9 @@ Channels:
channeltag: '&f[&9MOD&f]'
messagecolour: '&5'
permission: 'towny.chat.mod'
craftIRCTag: 'admin'
IRCChannel: ''
IRCToGameChatFormat: '{Channel} {Ranked}{Sender}: &f{Message}'
IRCSendToGame: false
range: '-1'

local:
Expand All @@ -83,5 +89,5 @@ Channels:
channeltag: '&f[local]'
messagecolour: '&f'
permission: 'towny.chat.local'
craftIRCTag: 'admin'
IRCChannel: ''
range: '100'
10 changes: 10 additions & 0 deletions src/ChatConfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@
# Spam_time set the minimum time between messages to be flagged as spam
spam_time: [spam_time]

# IRC config
IRC:
enabled: [irc_enable]
server: '[irc_server]'
# Not always used.
serverpassword: '[irc_serverpassword]'
port: '[irc_port]'
botnick: '[irc_botnick]'
botpassword: '[irc_botpassword]'

# If using our updated HeroicDeath.jar and craftIRC 3.1 (dev), you can
#configure what IRC channels you want death messages relayed to.
HeroicDeathToIRC:
Expand Down
157 changes: 120 additions & 37 deletions src/com/palmergames/bukkit/TownyChat/Chat.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import org.dynmap.DynmapAPI;

import com.ensifera.animosity.craftirc.CraftIRC;
import com.palmergames.bukkit.TownyChat.CraftIRCHandler;
import com.palmergames.bukkit.TownyChat.Command.TownyChatCommand;
import com.palmergames.bukkit.TownyChat.channels.ChannelsHolder;
import com.palmergames.bukkit.TownyChat.config.ChatSettings;
import com.palmergames.bukkit.TownyChat.config.ConfigurationHandler;
import com.palmergames.bukkit.TownyChat.listener.HeroicDeathForwarder;
import com.palmergames.bukkit.TownyChat.listener.TownyChatPlayerListener;
Expand All @@ -38,7 +38,11 @@ public class Chat extends JavaPlugin {
private CraftIRC craftIRC = null;
private DynmapAPI dynMap = null;

private CraftIRCHandler irc = null;
private IRCHandler irc = null;




private HeroicDeathForwarder heroicDeathListener = null;


Expand All @@ -47,16 +51,13 @@ public void onEnable() {

pm = getServer().getPluginManager();
configuration = new ConfigurationHandler(this);
channels = new ChannelsHolder(this);

checkPlugins();

setChannels(new ChannelsHolder(this));

/*
* This executes the task with a 1 tick delay avoiding the bukkit
* depends bug.
*/
if ((towny == null) || (getServer().getScheduler().scheduleSyncDelayedTask(this, new onLoadedTask(this), 1) == -1)
|| (!load())) {
if ((!checkTowny()) || (!load()) || (getServer().getScheduler().scheduleSyncDelayedTask(this, new onLoadedTask(this), 1) == -1)) {
/*
* We either failed to find Towny or the Scheduler failed to
* register the task.
Expand All @@ -65,10 +66,14 @@ public void onEnable() {
getLogger().severe("disabling TownyChat");
pm.disablePlugin(this);
return;
}
}
checkPlugins();



getCommand("townychat").setExecutor(new TownyChatCommand(this));


}

private boolean load() {
Expand All @@ -93,7 +98,7 @@ public void onDisable() {
pm = null;

configuration = null;
channels = null;
setChannels(null);
}

/**
Expand All @@ -109,44 +114,44 @@ public void reload() {
*/
private void checkPlugins() {
Plugin test;

test = pm.getPlugin("Towny");
if (test != null && test instanceof Towny)
towny = (Towny) test;
/**
* Hook craftIRC
*/
test = pm.getPlugin("CraftIRC");
if (test != null) {
try {
if (Double.valueOf(test.getDescription().getVersion()) >= 3.1) {
craftIRC = (CraftIRC) test;
irc = new CraftIRCHandler(this, craftIRC, "towny");
} else
getLogger().warning("TownyChat requires CraftIRC version 3.1 or higher to relay chat.");
} catch (NumberFormatException e) {
getLogger().warning("Non number format found for craftIRC version string!");
}
}

/**
* If we found craftIRC check for HeroicDeath
*/
if (irc != null) {
if (ChatSettings.getIRCEnabled()) {
test = pm.getPlugin("HeroicDeath");
if (test != null) {
heroicDeathListener = new HeroicDeathForwarder(irc);
getLogger().info("[TownyChat] Found and attempting to relay Heroic Death messages to craftIRC.");
getLogger().info("[TownyChat] Found and attempting to relay Heroic Death messages to IRC.");
}
}

test = pm.getPlugin("dynmap");
if (test != null) {
dynMap = (DynmapAPI) test;
}

}

/**
* Check if towny is used.
*
* @return boolean [True, False]
*
*/
private boolean checkTowny() {
Plugin test;

test = pm.getPlugin("Towny");
if (test != null && test instanceof Towny) {
towny = (Towny) test;
} else {
return false;
}
return true;
}

/**
* Register event listeners with bukkit
*/
public void registerEvents() {

if (TownyPlayerListener == null) {
Expand All @@ -160,6 +165,11 @@ public void registerEvents() {

}

/**
*
* Register permissions with bukkit
*
*/
public void registerPermissions() {
// Register all Permissions.
for (String perm : getChannelsHandler().getAllPermissions()) {
Expand All @@ -171,18 +181,33 @@ public void registerPermissions() {
}
}

/**
*
* Unregister all custom permissions
*
*/
public void unregisterPermissions() {
// Register all Permissions.
// Unregister all custom permissions.
for (String perm : getChannelsHandler().getAllPermissions()) {
pm.removePermission(new Permission(perm, new HashMap<String, Boolean>()));
}
}


/**
* Get root path to towny
*
* @return File path
*
*/
public String getRootPath() {
return getTowny().getDataFolder().getPath();
}

/**
* Get channels folder path
*
* @return File path
*/
public String getChannelsPath() {
return getRootPath() + FileMgmt.fileSeparator() + "settings";
}
Expand All @@ -191,7 +216,7 @@ public String getChannelsPath() {
* @return the channels
*/
public ChannelsHolder getChannelsHandler() {
return channels;
return getChannels();
}

/**
Expand All @@ -201,20 +226,78 @@ public ConfigurationHandler getConfigurationHandler() {
return configuration;
}

/**
* Get towny
*
* @return Get towny
*/
public Towny getTowny() {
return towny;
}

public CraftIRCHandler getIRC() {
/**
* Get IRC handler
*
* @return IRC Instance
*
*/
public IRCHandler getIRC() {
return irc;
}

/**
* Get Dynmap handler
*
* @return Dynmap Instance
*
*/
public DynmapAPI getDynmap() {
return dynMap;
}

/**
* Get HeroicDeath listener
*
* @return heroicDeathListener Instance
*
*/
public HeroicDeathForwarder getHeroicDeath() {
return heroicDeathListener;
}

/**
* Get channels
*
* @return ChannelsHolder
*/
public ChannelsHolder getChannels() {
return channels;
}

/**
* SetChannels
*
* @param channels
*/
private void setChannels(ChannelsHolder channels) {
this.channels = channels;
}

/**
* Getter for IRC
*
* @return IRCHandler
*/
public IRCHandler getIrc() {
return irc;
}

/**
* Set IRC
*
* @param IRCHandler
*/
public void setIrc(IRCHandler irc) {
this.irc = irc;
}
}
Loading