diff options
author | ementalo <ementalodev@gmx.co.uk> | 2012-06-27 13:35:39 +0100 |
---|---|---|
committer | ementalo <ementalodev@gmx.co.uk> | 2012-06-27 13:35:39 +0100 |
commit | 16d0b5c228dd8d981a0d79944c70248ea813d63b (patch) | |
tree | b76e6966bfc2b4b9b668b89b13e30307e0b81988 /EssentialsUpdate/src/com/earth2me/essentials/update/chat | |
parent | c1230bd6ae4e17539e1f6f2c82691fa7a8395e8c (diff) | |
download | Essentials-16d0b5c228dd8d981a0d79944c70248ea813d63b.tar Essentials-16d0b5c228dd8d981a0d79944c70248ea813d63b.tar.gz Essentials-16d0b5c228dd8d981a0d79944c70248ea813d63b.tar.lz Essentials-16d0b5c228dd8d981a0d79944c70248ea813d63b.tar.xz Essentials-16d0b5c228dd8d981a0d79944c70248ea813d63b.zip |
package name change to net.ess3
Diffstat (limited to 'EssentialsUpdate/src/com/earth2me/essentials/update/chat')
9 files changed, 0 insertions, 666 deletions
diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/chat/AbstractFileCommand.java b/EssentialsUpdate/src/com/earth2me/essentials/update/chat/AbstractFileCommand.java deleted file mode 100644 index 7c99d28f6..000000000 --- a/EssentialsUpdate/src/com/earth2me/essentials/update/chat/AbstractFileCommand.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.earth2me.essentials.update.chat; - -import com.earth2me.essentials.update.PastieUpload; -import java.io.*; -import java.nio.charset.Charset; -import org.bukkit.plugin.Plugin; - - -public abstract class AbstractFileCommand implements Command -{ - private final transient Plugin plugin; - private final static Charset UTF8 = Charset.forName("utf-8"); - - public AbstractFileCommand(final Plugin plugin) - { - this.plugin = plugin; - } - - protected BufferedReader getServerLogReader() throws IOException - { - final File bukkitFolder = plugin.getDataFolder().getAbsoluteFile().getParentFile().getParentFile(); - if (bukkitFolder == null || !bukkitFolder.exists()) - { - throw new IOException("Bukkit folder not found."); - } - final File logFile = new File(bukkitFolder, "server.log"); - if (!logFile.exists()) - { - throw new IOException("Server log not found."); - } - final FileInputStream fis = new FileInputStream(logFile); - try - { - if (logFile.length() > 1000000) - { - fis.skip(logFile.length() - 1000000); - } - return new BufferedReader(new InputStreamReader(fis)); - } - catch (IOException ex) - { - fis.close(); - throw ex; - } - } - - protected BufferedReader getPluginConfig(final String pluginName, final String fileName) throws IOException - { - final File configFolder = new File(plugin.getDataFolder().getAbsoluteFile().getParentFile(), pluginName); - if (!configFolder.exists()) - { - throw new IOException(pluginName + " plugin folder not found."); - } - final File configFile = new File(configFolder, fileName); - if (!configFile.exists()) - { - throw new IOException(pluginName + " plugin file " + fileName + " not found."); - } - return new BufferedReader(new InputStreamReader(new FileInputStream(configFile), UTF8)); - - } - - protected String uploadToPastie(final StringBuilder input) throws IOException - { - if (input.length() > 15000) - { - input.delete(0, input.length() - 15000); - input.append("## Cropped after 15000 bytes"); - } - final PastieUpload pastie = new PastieUpload(); - return pastie.send(input.toString()); - } -} diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/chat/Command.java b/EssentialsUpdate/src/com/earth2me/essentials/update/chat/Command.java deleted file mode 100644 index ad4c75e43..000000000 --- a/EssentialsUpdate/src/com/earth2me/essentials/update/chat/Command.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.earth2me.essentials.update.chat; - -import org.bukkit.entity.Player; - - -public interface Command -{ - void run(final IrcBot ircBot, final Player player); -} diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/chat/ConfigCommand.java b/EssentialsUpdate/src/com/earth2me/essentials/update/chat/ConfigCommand.java deleted file mode 100644 index 78563a950..000000000 --- a/EssentialsUpdate/src/com/earth2me/essentials/update/chat/ConfigCommand.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.earth2me.essentials.update.chat; - -import java.io.BufferedReader; -import java.io.IOException; -import java.util.logging.Level; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - - -public class ConfigCommand extends AbstractFileCommand implements Command -{ - public ConfigCommand(final Plugin plugin) - { - super(plugin); - } - - @Override - public void run(final IrcBot ircBot, final Player player) - { - BufferedReader page = null; - try - { - page = getPluginConfig("Essentials-3", "config.yml"); - final StringBuilder input = new StringBuilder(); - do - { - final String line = page.readLine(); - if (line == null) - { - break; - } - else - { - input.append(line).append("\n"); - } - } - while (true); - page.close(); - final String message = "Essentials config.yml: " + uploadToPastie(input); - player.sendMessage("§6" + ircBot.getNick() + ": §7" + message); - ircBot.sendMessage(message); - } - catch (IOException ex) - { - Bukkit.getLogger().log(Level.SEVERE, null, ex); - player.sendMessage(ex.getMessage()); - } - finally - { - try - { - if (page != null) - { - page.close(); - } - } - catch (IOException ex) - { - Bukkit.getLogger().log(Level.SEVERE, null, ex); - player.sendMessage(ex.getMessage()); - } - } - } -} diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/chat/ErrorsCommand.java b/EssentialsUpdate/src/com/earth2me/essentials/update/chat/ErrorsCommand.java deleted file mode 100644 index 41aa551c4..000000000 --- a/EssentialsUpdate/src/com/earth2me/essentials/update/chat/ErrorsCommand.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.earth2me.essentials.update.chat; - -import java.io.BufferedReader; -import java.io.IOException; -import java.util.logging.Level; -import java.util.regex.Pattern; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - - -public class ErrorsCommand extends AbstractFileCommand implements Command -{ - private final transient Pattern pattern = Pattern.compile("^[0-9 :-]+\\[INFO\\].*"); - - public ErrorsCommand(final Plugin plugin) - { - super(plugin); - } - - @Override - public void run(final IrcBot ircBot, final Player player) - { - BufferedReader page = null; - try - { - page = getServerLogReader(); - final StringBuilder input = new StringBuilder(); - do - { - final String line = page.readLine(); - if (line == null) - { - break; - } - else - { - if (!pattern.matcher(line).matches()) - { - input.append(line).append("\n"); - } - } - } - while (true); - page.close(); - final String message = "Errors: " + uploadToPastie(input); - player.sendMessage("§6" + ircBot.getNick() + ": §7" + message); - ircBot.sendMessage(message); - } - catch (IOException ex) - { - Bukkit.getLogger().log(Level.SEVERE, null, ex); - player.sendMessage(ex.getMessage()); - } - finally - { - try - { - if (page != null) - { - page.close(); - } - } - catch (IOException ex) - { - Bukkit.getLogger().log(Level.SEVERE, null, ex); - player.sendMessage(ex.getMessage()); - } - } - } -} diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/chat/HelpCommand.java b/EssentialsUpdate/src/com/earth2me/essentials/update/chat/HelpCommand.java deleted file mode 100644 index a6f76cece..000000000 --- a/EssentialsUpdate/src/com/earth2me/essentials/update/chat/HelpCommand.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.earth2me.essentials.update.chat; - -import org.bukkit.entity.Player; - - -public class HelpCommand implements Command -{ - @Override - public void run(final IrcBot ircBot, final Player player) - { - player.sendMessage("Commands: (Note: Files send to the chat will be public viewable.)"); - player.sendMessage("!errors - Send the last server errors to the chat."); - player.sendMessage("!startup - Send the last startup messages to the chat."); - player.sendMessage("!config - Sends your Essentials config to the chat."); - player.sendMessage("!list - List all players in chat."); - player.sendMessage("!quit - Leave chat."); - } -} diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/chat/IrcBot.java b/EssentialsUpdate/src/com/earth2me/essentials/update/chat/IrcBot.java deleted file mode 100644 index c2cc209e6..000000000 --- a/EssentialsUpdate/src/com/earth2me/essentials/update/chat/IrcBot.java +++ /dev/null @@ -1,197 +0,0 @@ -package com.earth2me.essentials.update.chat; - -import java.io.IOException; -import java.util.logging.Level; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.jibble.pircbot.Colors; -import org.jibble.pircbot.IrcException; -import org.jibble.pircbot.PircBot; -import org.jibble.pircbot.User; - - -public class IrcBot extends PircBot -{ - private static final String CHANNEL = "#essentials"; - private static final int PORT = 6667; - private static final String SERVER = "irc.esper.net"; - private transient boolean reconnect = true; - private final transient Player player; - private transient boolean kicked = false; - - public IrcBot(final Player player, final String nickName, final String versionString) - { - super(); - this.player = player; - setName(nickName); - setLogin("esshelp"); - setVersion(versionString); - connect(); - joinChannel(CHANNEL); - } - - private void connect() - { - try - { - connect(SERVER, PORT); - } - catch (IOException ex) - { - Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex); - } - catch (IrcException ex) - { - Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex); - } - } - - public void quit() - { - reconnect = false; - disconnect(); - } - - @Override - protected void onConnect() - { - reconnect = true; - } - - @Override - protected void onDisconnect() - { - if (reconnect) - { - int tries = 10; - while (!isConnected()) - { - try - { - tries--; - reconnect(); - } - catch (Exception e) - { - Bukkit.getLogger().log(Level.WARNING, e.getMessage(), e); - try - { - Thread.sleep(10000); - } - catch (InterruptedException ex) - { - Bukkit.getLogger().log(Level.WARNING, e.getMessage(), e); - } - } - if (tries <= 0) - { - player.sendMessage("Connection lost to server."); - kicked = true; - break; - } - } - } - } - - @Override - protected void onKick(final String channel, final String kickerNick, - final String kickerLogin, final String kickerHostname, - final String recipientNick, final String reason) - { - if (recipientNick.equals(getNick())) - { - player.sendMessage("You have been kicked from the channel: " + reason); - quit(); - kicked = true; - } - } - - public boolean isKicked() - { - return kicked; - } - - @Override - protected void onMessage(final String channel, final String sender, - final String login, final String hostname, - final String message) - { - player.sendMessage(formatChatMessage(sender, message, false)); - } - - @Override - protected void onAction(final String sender, final String login, - final String hostname, final String target, - final String action) - { - player.sendMessage(formatChatMessage(sender, action, true)); - } - - @Override - protected void onNotice(final String sourceNick, final String sourceLogin, - final String sourceHostname, final String target, - final String notice) - { - player.sendMessage(formatChatMessage(sourceNick, notice, false)); - } - - @Override - protected void onTopic(final String channel, final String topic, - final String setBy, final long date, - final boolean changed) - { - player.sendMessage(formatChatMessage(channel, topic, false)); - } - - public String formatChatMessage(final String nick, final String message, final boolean action) - { - final StringBuilder builder = new StringBuilder(); - builder.append("§6"); - if (action) - { - builder.append('*'); - } - builder.append(nick); - if (!action) - { - builder.append(':'); - } - builder.append(" §7"); - builder.append(replaceColors(message)); - return builder.toString(); - } - - private String replaceColors(final String message) - { - String m = Colors.removeFormatting(message); - m = m.replaceAll("\u000310(,(0?[0-9]|1[0-5]))?", "§b"); - m = m.replaceAll("\u000311(,(0?[0-9]|1[0-5]))?", "§f"); - m = m.replaceAll("\u000312(,(0?[0-9]|1[0-5]))?", "§9"); - m = m.replaceAll("\u000313(,(0?[0-9]|1[0-5]))?", "§d"); - m = m.replaceAll("\u000314(,(0?[0-9]|1[0-5]))?", "§8"); - m = m.replaceAll("\u000315(,(0?[0-9]|1[0-5]))?", "§7"); - m = m.replaceAll("\u00030?1(,(0?[0-9]|1[0-5]))?", "§0"); - m = m.replaceAll("\u00030?2(,(0?[0-9]|1[0-5]))?", "§1"); - m = m.replaceAll("\u00030?3(,(0?[0-9]|1[0-5]))?", "§2"); - m = m.replaceAll("\u00030?4(,(0?[0-9]|1[0-5]))?", "§c"); - m = m.replaceAll("\u00030?5(,(0?[0-9]|1[0-5]))?", "§4"); - m = m.replaceAll("\u00030?6(,(0?[0-9]|1[0-5]))?", "§5"); - m = m.replaceAll("\u00030?7(,(0?[0-9]|1[0-5]))?", "§6"); - m = m.replaceAll("\u00030?8(,(0?[0-9]|1[0-5]))?", "§e"); - m = m.replaceAll("\u00030?9(,(0?[0-9]|1[0-5]))?", "§a"); - m = m.replaceAll("\u00030?0(,(0?[0-9]|1[0-5]))?", "§f"); - m = m.replace("\u000f", "§7"); - m = Colors.removeColors(m); - return m; - } - - public void sendMessage(final String message) - { - sendMessage(CHANNEL, message); - } - - public User[] getUsers() - { - return getUsers(CHANNEL); - } -} diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/chat/ListCommand.java b/EssentialsUpdate/src/com/earth2me/essentials/update/chat/ListCommand.java deleted file mode 100644 index 9aa932efa..000000000 --- a/EssentialsUpdate/src/com/earth2me/essentials/update/chat/ListCommand.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.earth2me.essentials.update.chat; - -import org.bukkit.entity.Player; -import org.jibble.pircbot.User; - - -public class ListCommand implements Command -{ - @Override - public void run(final IrcBot ircBot, final Player player) - { - final User[] members = ircBot.getUsers(); - final StringBuilder message = new StringBuilder(); - for (User user : members) - { - if (message.length() > 0) - { - message.append("§f, "); - } - if (user.isOp() || user.hasVoice()) - { - message.append("§6"); - } - else - { - message.append("§7"); - } - message.append(user.getPrefix()).append(user.getNick()); - } - player.sendMessage(message.toString()); - } -} diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/chat/StartupCommand.java b/EssentialsUpdate/src/com/earth2me/essentials/update/chat/StartupCommand.java deleted file mode 100644 index f244d6e3a..000000000 --- a/EssentialsUpdate/src/com/earth2me/essentials/update/chat/StartupCommand.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.earth2me.essentials.update.chat; - -import java.io.BufferedReader; -import java.io.IOException; -import java.util.logging.Level; -import java.util.regex.Pattern; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - - -public class StartupCommand extends AbstractFileCommand implements Command -{ - private final transient Pattern patternStart = Pattern.compile("^[0-9 :-]+\\[INFO\\] Starting minecraft server version.*"); - private final transient Pattern patternEnd = Pattern.compile("^[0-9 :-]+\\[INFO\\] Done \\([0-9.,]+s\\)! For help, type \"help\".*"); - - public StartupCommand(final Plugin plugin) - { - super(plugin); - } - - @Override - public void run(final IrcBot ircBot, final Player player) - { - BufferedReader page = null; - try - { - page = getServerLogReader(); - final StringBuilder input = new StringBuilder(); - String line; - boolean log = false; - while ((line = page.readLine()) != null) - { - if (patternStart.matcher(line).matches()) - { - if (input.length() > 0) - { - input.delete(0, input.length()); - } - log = true; - } - if (log) - { - input.append(line).append("\n"); - } - if (patternEnd.matcher(line).matches()) - { - log = false; - } - } - page.close(); - final String message = "Startup: " + uploadToPastie(input); - player.sendMessage("§6" + ircBot.getNick() + ": §7" + message); - ircBot.sendMessage(message); - } - catch (IOException ex) - { - Bukkit.getLogger().log(Level.SEVERE, null, ex); - player.sendMessage(ex.getMessage()); - } - finally - { - try - { - if (page != null) - { - page.close(); - } - } - catch (IOException ex) - { - Bukkit.getLogger().log(Level.SEVERE, null, ex); - player.sendMessage(ex.getMessage()); - } - } - } -} diff --git a/EssentialsUpdate/src/com/earth2me/essentials/update/chat/UsernameUtil.java b/EssentialsUpdate/src/com/earth2me/essentials/update/chat/UsernameUtil.java deleted file mode 100644 index 2fd9a38b6..000000000 --- a/EssentialsUpdate/src/com/earth2me/essentials/update/chat/UsernameUtil.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.earth2me.essentials.update.chat; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.bukkit.Bukkit; -import org.bukkit.Server; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - - -public final class UsernameUtil -{ - private static final Pattern CB_PATTERN = Pattern.compile("git-Bukkit-([0-9]+).([0-9]+).([0-9]+)-[0-9]+-[0-9a-z]+-b([0-9]+)jnks.*"); - - private UsernameUtil() - { - } - - public static String createUsername(final Player player) - { - final StringBuilder nameBuilder = new StringBuilder(); - final Server server = Bukkit.getServer(); - nameBuilder.append(player.getName()); - - addCraftBukkitVersion(server, nameBuilder); - addEssentialsVersion(server, nameBuilder); - addGroupManagerVersion(server, nameBuilder); - addPermissionsExVersion(server, nameBuilder); - addPermissionsBukkitVersion(server, nameBuilder); - addBPermissionsVersion(server, nameBuilder); - addPermissionsVersion(server, nameBuilder); - - return nameBuilder.toString(); - } - - private static void addPermissionsVersion(final Server server, final StringBuilder nameBuilder) - { - final Plugin perm = server.getPluginManager().getPlugin("Permissions"); - if (perm != null) - { - nameBuilder.append(" P"); - if (!perm.isEnabled()) - { - nameBuilder.append('!'); - } - nameBuilder.append(perm.getDescription().getVersion()); - } - } - - private static void addBPermissionsVersion(final Server server, final StringBuilder nameBuilder) - { - final Plugin bperm = server.getPluginManager().getPlugin("bPermissions"); - if (bperm != null) - { - nameBuilder.append(" BP"); - if (!bperm.isEnabled()) - { - nameBuilder.append('!'); - } - nameBuilder.append(bperm.getDescription().getVersion()); - } - } - - private static void addPermissionsBukkitVersion(final Server server, final StringBuilder nameBuilder) - { - final Plugin permb = server.getPluginManager().getPlugin("PermissionsBukkit"); - if (permb != null) - { - nameBuilder.append(" PB"); - if (!permb.isEnabled()) - { - nameBuilder.append('!'); - } - nameBuilder.append(permb.getDescription().getVersion()); - } - } - - private static void addPermissionsExVersion(final Server server, final StringBuilder nameBuilder) - { - final Plugin pex = server.getPluginManager().getPlugin("PermissionsEx"); - if (pex != null) - { - nameBuilder.append(" PEX"); - if (!pex.isEnabled()) - { - nameBuilder.append('!'); - } - nameBuilder.append(pex.getDescription().getVersion()); - } - } - - private static void addGroupManagerVersion(final Server server, final StringBuilder nameBuilder) - { - final Plugin groupManager = server.getPluginManager().getPlugin("GroupManager"); - if (groupManager != null) - { - nameBuilder.append(" GM"); - if (!groupManager.isEnabled()) - { - nameBuilder.append('!'); - } - } - } - - private static void addEssentialsVersion(final Server server, final StringBuilder nameBuilder) - { - final Plugin essentials = server.getPluginManager().getPlugin("Essentials-3"); - if (essentials != null) - { - nameBuilder.append(" ESS"); - nameBuilder.append(essentials.getDescription().getVersion()); - } - } - - private static void addCraftBukkitVersion(final Server server, final StringBuilder nameBuilder) - { - final Matcher versionMatch = CB_PATTERN.matcher(server.getVersion()); - if (versionMatch.matches()) - { - nameBuilder.append(" CB"); - nameBuilder.append(versionMatch.group(4)); - } - } -} |