Browse files

+rough check for config.yml, minor fix to example code, build Preview 9

  • Loading branch information...
1 parent a0a3384 commit 53e2fcb9e1480bb33b4f663e321bb3d7ab4b21a6 @Animosity committed Mar 5, 2011
View
BIN beta/preview/CraftIRC.jar
Binary file not shown.
View
41 com/ensifera/animosity/craftirc/CraftIRC.java
@@ -64,25 +64,34 @@
private PermissionHandler perms = null;
private ArrayList<Minebot> instances;
private boolean debug;
- private Timer holdTimer;
+ private Timer holdTimer = new Timer();
protected HashMap<HoldType, Boolean> hold;
//Bots and channels config storage
- private ArrayList<ConfigurationNode> bots;
- private ArrayList<ConfigurationNode> colormap;
+ private ArrayList<ConfigurationNode> bots = new ArrayList<ConfigurationNode>();
+ private ArrayList<ConfigurationNode> colormap = new ArrayList<ConfigurationNode>();
private HashMap<Integer, ArrayList<ConfigurationNode>> channodes;
private HashMap<Integer, ArrayList<String>> channames;
protected HashMap<DualKey, String> chanTagMap;
public void onEnable() {
try {
PluginDescriptionFile desc = this.getDescription();
+ VERSION = desc.getVersion();
server = this.getServer();
+
Field cfield = CraftServer.class.getDeclaredField("console");
cfield.setAccessible(true);
console = (MinecraftServer) cfield.get((CraftServer)getServer());
- VERSION = desc.getVersion();
+
//Load node lists. Bukkit does it now, hurray!
+ if (null == getConfiguration().getKeys("settings")) {
+ CraftIRC.log.info(String.format(CraftIRC.NAME + " config.yml could not be found in plugins/CraftIRC/ -- disabling!"));
+ getServer().getPluginManager().disablePlugin(((Plugin) (this)));
+ return;
+ }
+ System.out.println(getConfiguration().getProperty("settings").toString());
+ System.out.println(getConfiguration().getProperty("bots").toString());
bots = new ArrayList<ConfigurationNode>(getConfiguration().getNodeList("bots", null));
colormap = new ArrayList<ConfigurationNode>(getConfiguration().getNodeList("colormap", null));
channodes = new HashMap<Integer, ArrayList<ConfigurationNode>>();
@@ -95,7 +104,6 @@ public void onEnable() {
String channelName = it.next().getString("name");
chanTagMap.put(new DualKey(botID, channelName), this.cChanTag(botID, channelName));
cn.add(channelName);
-
}
channames.put(botID, cn);
}
@@ -153,22 +161,27 @@ public void onEnable() {
holdTimer.schedule(new RemoveHoldTask(this, HoldType.BANS), now.getTime() + cHold("bans"));
} else
hold.put(HoldType.BANS, false);
-
+
+ // Not yet supported: Register custom "admins!" command alias
+ // this.getCommand("admins!").setAliases(Arrays.asList(this.cAdminsCmd()));
+
setDebug(cDebug());
} catch (Exception e) {
e.printStackTrace();
}
}
public void onDisable() {
-
- holdTimer.cancel();
-
- //Disconnect bots
- for (int i = 0; i < bots.size(); i++)
- instances.get(i).disconnect();
-
- log.info(NAME + " Disabled.");
+ try {
+ holdTimer.cancel();
+ //Disconnect bots
+ for (int i = 0; i < bots.size(); i++)
+ instances.get(i).disconnect();
+
+ log.info(NAME + " Disabled.");
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
}
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
View
11 com/ensifera/animosity/craftirc/CraftIRCListener.java
@@ -34,13 +34,18 @@ public void onPlayerCommandPreprocess(PlayerChatEvent event) {
}
public void onPlayerChat(PlayerChatEvent event) {
- if (this.plugin.isHeld(CraftIRC.HoldType.CHAT))
+
+ if (this.plugin.isHeld(CraftIRC.HoldType.CHAT)) {
return;
+
+ }
// String[] split = message.split(" ");
try {
- if (event.isCancelled() && !this.plugin.cEvents("game-to-irc.cancelled-chat", -1, null))
+ if (this.plugin.isDebug()) CraftIRC.log.info(String.format(CraftIRC.NAME + " onPlayerChat(): <%s> %s", event.getMessage(), event.getPlayer()));
+ if (event.isCancelled() && !this.plugin.cEvents("game-to-irc.cancelled-chat", -1, null)) {
+ if (this.plugin.isDebug()) CraftIRC.log.info(String.format(CraftIRC.NAME + " onPlayerChat(CHAT CANCELLED!): <%s> %s", event.getMessage(), event.getPlayer()));
return;
-
+ }
RelayedMessage msg = this.plugin.newMsg(EndPoint.GAME, EndPoint.IRC);
msg.formatting = "chat";
msg.sender = event.getPlayer().getName();
View
2 com/ensifera/animosity/craftirc/example/CraftIRCPluginExample.java
@@ -31,7 +31,7 @@
@Override
public void onEnable() {
Plugin checkplugin = this.getServer().getPluginManager().getPlugin("CraftIRC");
- if (checkplugin == null) {
+ if (checkplugin == null || !checkplugin.isEnabled()) {
log.warning("CraftIRCPluginExample cannot be loaded because CraftIRC is not enabled on the server!");
getServer().getPluginManager().disablePlugin(((org.bukkit.plugin.Plugin) (this)));
} else {
View
2 plugin.yml
@@ -1,6 +1,6 @@
name: CraftIRC
main: com.ensifera.animosity.craftirc.CraftIRC
-version: 2.0 Preview 8
+version: 2.0 Preview 9
commands:
irc:
description: Sends a message to all IRC channels

0 comments on commit 53e2fcb

Please sign in to comment.