Add a MOTD command

This commit is contained in:
Trever Fischer 2012-03-19 00:04:03 -04:00
parent a586041145
commit e51df71725
4 changed files with 77 additions and 15 deletions

View File

@ -64,17 +64,6 @@ public class JoinListener implements Listener {
@EventHandler @EventHandler
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
Player p = event.getPlayer(); m_plugin.sendMOTD(event.getPlayer());
String[] motd = null;
try {
motd = m_plugin.api().fetchMOTD(p.getName());
} catch (IOException e) {
p.sendMessage("Could not fetch MOTD: Communication error");
}
if (motd != null) {
for(String msg : motd) {
p.sendMessage(msg);
}
}
} }
} }

View File

@ -0,0 +1,35 @@
package us.camin;
/*
This file is part of Caminus
Caminus is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Caminus 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
*/
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class MOTDCommand implements CommandExecutor {
private Plugin m_plugin;
public MOTDCommand(Plugin p) {
m_plugin = p;
}
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
m_plugin.sendMOTD(sender);
return true;
}
}

View File

@ -17,6 +17,8 @@ package us.camin;
along with Caminus. If not, see <http://www.gnu.org/licenses/>. along with Caminus. If not, see <http://www.gnu.org/licenses/>.
*/ */
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.Configuration; import org.bukkit.configuration.Configuration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event; import org.bukkit.event.Event;
@ -24,6 +26,7 @@ import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap; import java.util.HashMap;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.io.IOException;
import us.camin.api.Server; import us.camin.api.Server;
@ -32,6 +35,7 @@ public class Plugin extends JavaPlugin {
Logger log = Logger.getLogger("Caminus");//Define your logger Logger log = Logger.getLogger("Caminus");//Define your logger
private Server m_api; private Server m_api;
private JoinListener m_listener; private JoinListener m_listener;
private MOTDCommand m_motdCommand;
public Server api() { public Server api() {
return m_api; return m_api;
@ -43,14 +47,32 @@ public class Plugin extends JavaPlugin {
} }
public void onEnable() { public void onEnable() {
log.info("[Caminus] Plugin enabled");
PluginManager pm = this.getServer().getPluginManager(); PluginManager pm = this.getServer().getPluginManager();
m_motdCommand = new MOTDCommand(this);
m_listener = new JoinListener(this); m_listener = new JoinListener(this);
Configuration conf = getConfig(); Configuration conf = getConfig();
conf.addDefault("url", "http://camin.us/api/"); conf.addDefault("url", "http://camin.us/api/");
String url = conf.getString("url"); String url = conf.getString("url");
m_api = new Server(url); m_api = new Server(url);
pm.registerEvents(m_listener, this); pm.registerEvents(m_listener, this);
m_motdCommand = new MOTDCommand(this);
getCommand("motd").setExecutor(m_motdCommand);
log.info("[Caminus] Plugin enabled");
} }
public void sendMOTD(CommandSender sender) {
String[] motd = null;
try {
motd = m_api.fetchMOTD(sender.getName());
} catch (IOException e) {
sender.sendMessage("Could not fetch MOTD: Communication error");
}
if (motd != null) {
for(String msg : motd) {
sender.sendMessage(msg);
}
}
}
} }

View File

@ -1,3 +1,19 @@
name: Caminus name: Caminus
main: us.camin.Plugin main: us.camin.Plugin
version: 0.2 author: Trever Fischer <team@camin.us>
website: http://camin.us/
version: ${version}
commands:
motd:
description: Displays the MOTD
usage: /<command>
permissions:
caminus.*:
default: op
description: Allows use of all caminus permissions
children:
caminus.whitelisted: true
caminus.whitelisted:
default: op
description: Allows user to bypass caminus API whitelisting