[CHAT] Memo v1.0 - Really basic offline messaging (OffLine) [953]

Discussion in 'Inactive/Unsupported Plugins' started by Protected, Apr 30, 2011.

  1. Offline

    Protected

    Memo - Really basic offline messaging
    Version 1.0 - Download JAR
    Required dependencies: OffLine

    A bit late but here it is - An input layer for players to send messages using OffLine, and it also doubles as the example plugin (see below for source code). If you want something more advanced for offline message handling (inboxes, outboxes, long-term message storage, etc.) I'm pretty sure there are a couple of other plugins, go look for them.

    Features
    • Allows players to send private messages to players who may be offline.
    • Very simple, absolutely no extras.
    • Uses my OffLine plugin for message delivery.
    Installation (open)

    Installation

    Put Memo.jar and OffLine.jar in the plugins folder and restart/reload your server. That's all!

    How to use (open)

    How to use

    This plugin provides only one command.

    /memo PLAYERNAME MESSAGE
    Sends a MESSAGE from you to user PLAYERNAME via OffLine. If the user is online he receives it immediately, otherwise it is stored for later delivery.​

    If you're the server owner you can change the message formatting string in config.yml (for example if you want to add colors). The default is:

    Code:
    msg-format: '<%sender%> %msg%'

    The complete source code (open)

    Code:
    package net.myshelter.minecraft.memo;
    
    import java.util.logging.Logger;
    
    import net.myshelter.minecraft.OffLine;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    class MessengerSet implements Runnable {
        
        Memo plugin;
        MessengerSet(Memo plugin) {
            this.plugin = plugin;
        }
    
        public void run() {
            plugin.offline = (OffLine)plugin.getServer().getPluginManager().getPlugin("OffLine");
            if (plugin.offline == null) Memo.dolog("WARNING: Plugin not loaded! Messages will not be sent!");
        }
        
    }
    
    public class Memo extends JavaPlugin {
    
        protected static Logger log = Logger.getLogger("Minecraft");
        protected static void dolog(String msg) {
            log.info("[Memo] " + msg);
        }
        
        String msgFormat = null;
        
        protected OffLine offline = null;
        protected final void prepareMessenger() {
            getServer().getScheduler().scheduleSyncDelayedTask(this, new MessengerSet(this));
        }
        public boolean msg(String player, String message) {
            if (offline == null) return false;
            return offline.msg(getDescription().getName(), player, message);
        }
        
        public void onEnable() {
            prepareMessenger();
            msgFormat = getConfiguration().getString("msg-format");
            if (msgFormat == null) msgFormat = "<%sender%> %msg%";
            dolog("Enabled! Version is " + getDescription().getVersion());
        }
        
        public void onDisable() {
            dolog("Disabled...");
        }
        
        public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args)  {
            if (!(sender instanceof Player)) return false;
            Player player = (Player)sender;
            if (command.getName().equalsIgnoreCase("memo")) {
                if (args.length < 2) {
                    player.sendMessage("Syntax: /memo PLAYER MESSAGE");
                    return true;
                }
                if (args[0].equals(player.getName())) {
                    player.sendMessage("You're right there!");
                    return true;
                }
                String message = args[1];
                for (int i = 2; i < args.length; i++) message = message + " " + args[i];
                msg(args[0], msgFormat.replace("%sender%", player.getName()).replace("%msg%", message));
                player.sendMessage("Message for " + args[0] + " sent.");
                dolog(player.getName() + " sent a message for " + args[0]);
                return true;
            }
            return false;
        }
        
    }
    

    Changelog
    v1.0
    The first!
     
    Zenithas likes this.
  2. Offline

    Applebule5

    Why not use /mail...
     
  3. Offline

    Protected

    Applebule: I'll leave /mail free for other plugins to use. Also, I think conceptually speaking a mail should be something you can keep in your inbox.
     
    jasonznack likes this.
  4. Offline

    Zenithas

    Sounds interesting - I'll give this a go.
     
  5. Offline

    Thumm

    Awesome! thank you my friend this was just what I was looking for :)
     
  6. Offline

    Jake_Mul

    On our server only ops can do this. What is the permissions for it?
     
  7. Offline

    Protected

    As you can see from the source code, everyone can use it; If it's being restricted it's another plugin doing it. Or one of the server owners modified the source code to filter out non-ops.
     

Share This Page