[Solved] How to warn an offline player and send them the warning when they login

Discussion in 'Plugin Development' started by JOPHESTUS, Aug 11, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    JOPHESTUS

    Title ^

    I have a warning plugin as you may know, and some users are requesting the feature to warn offline users.

    Warning them when they're offline is not too much of a problem (I think) but sending them the warning when they login is what I need help with.

    Some info:
    Warnings get saved in warnings.yml under the players name (stringlist)
    It saves the warning and adds "- By <playername>" onto the end of it
    If you need anymore info please ask

    Your help is appreciated.

    People who might help:
    evilmidget38 (If you get sick of me tagging you just say so :p )
     
  2. Offline

    evilmidget38

    There's a lot of different ways you could go about doing this. One example would be adding something like "NEEDSWARNING" to the end of the string put into the player's warnings. Then, when they log in you check if any of their warnings end with "NEEDSWARNING". If they do, you warn them and remove that from the end of the string.
     
  3. Offline

    EnvisionRed

    Maybe add another trigger to the end of the strings in the string list such as "Warned - false", then handle player login events to check if that player is mentioned in any "Warned - false" statements. If he is, warn as appropriate and change to "Warned - true"

    You can use the bukkit config API to make manipulating the Warnings.yml file much easier even though it's not a config.
     
  4. Offline

    one4me

    I would probably do something like this

    onplayerjoinevent
    if player is in list
    send player message
    remove player from list
     
  5. Offline

    JOPHESTUS

    When warning what I will do is if le player is offline it will put the warning to the string list "<playername>offline"

    Then when they login it will send them the warnings and clear them.

    I hope this works, thanks for your support :)
     
  6. Offline

    Cirno

    There's no way to check weather a player is offline; and ever since the new Protocol Encryption, I doubt you can be willynilly with HTTP's and readers.
     
  7. Offline

    JOPHESTUS

    Wouldn't I just use

    Player warnee = Bukkit.getServer().getPlayer(args[0]);
    if (warnee == null) {
    //do stuff
    }

    I've tried to do this
    Code:java
    1.  
    2. if (warnee == null) {
    3.  
    4. OfflinePlayer offline = Bukkit.getServer()
    5. .getOfflinePlayer(args[0]);
    6. warnings.add(b.toString() + " - By: " + sender.getName());
    7. getCustomConfig().set(offline.getName() + "offline", warnings);
    8. saveCustomConfig();
    9. reloadCustomConfig();
    10. }


    But I get a "dead code" error
    All my code: HERE

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  8. Make sure you check if offline == null before using it (Just sayin!)
     
  9. Offline

    JOPHESTUS

    I got it to put it into the warnings.yml file as JOPHESTUSoffline, I am having trouble getting the listener to work

    Code:
    package me.jophestus.JOPHWarn;
     
    import java.util.List;
     
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
     
    public class JOPHWarnListener implements Listener {
    public static JOPHWarn plugin;
     
    public JOPHWarnListener(JOPHWarn instance) {
    plugin = instance;
    }
     
    public void onPlayerJoin(PlayerJoinEvent e) {
    Player p = e.getPlayer();
     
    List<String> warnings = plugin.getCustomConfig().getStringList(
    p.getName() + "offline");
    int size = warnings.size();
    if (size > 0) {
    p.sendMessage(ChatColor.GREEN + "While you were away "
    + p.getName() + " You were warned " + size + " times. For:");
    for (String s : warnings) {
     
    p.sendMessage(ChatColor.GOLD + s);
    plugin.getCustomConfig().set(p.getName() + "offline", null);
    plugin.saveCustomConfig();
    plugin.reloadCustomConfig();
    }
    }
     
    }
     
    }
    
     
  10. Don't quote me on this, but I think there is a getOfflinePlayers() method. If there isn't, he could easily just search the list of online players and determine if they're offline.
     
  11. Offline

    Cirno

    Oh, I thought offline meant a non-paid account.
     
Thread Status:
Not open for further replies.

Share This Page