Halp plox

Discussion in 'Plugin Development' started by stelar7, Sep 13, 2011.

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

    stelar7

    Why wont this work?
    Getting "Unknown console command"
    Code:java
    1. public void onPlayerCommandPreprocess(PlayerChatEvent event) {
    2. if (event.getMessage().toLowerCase().startsWith("/m") || event.getMessage().toLowerCase().startsWith("/msg")) {
    3. event.getPlayer().sendMessage("WHY WONT THIS WORK?????");
    4. }
    5. }
     
  2. Offline

    stelar7

    @Bone008
    Is there no way of doing it in that event (player chat event)?
     
  3. There is, but why on earth would you want to do that?!
     
  4. Offline

    stelar7

    not sure xD
     
  5. Offline

    Relick

    Also, have you referenced the commands in your plugin.yml?
     
  6. Offline

    stelar7

    @Bone008 , @Relick
    nvm that, onto the problem!

    I'm trying to make a PM plugin (will probably never be released...)
    The PM part is working fine, but i want people to be able to spy on the conversation with "/mlog <playername>"
    That part wont work...

    Code here: https://github.com/stelar7/messenger
     
  7. Now if you would bother to tell us what exactly does not work it would help us to help you ...
    Don't always make us help you help us help you ;)
     
  8. Offline

    stelar7

    wat?


    I'm getting an NPE on line 48 in CommandMLOG and I've no idea why...
     
  9. That's more like it.

    Now look at your main class. Especially those two lines:
    Code:
    public static HashMap<Player, List<Player>> players = new HashMap<Player, List<Player>>();
    public static List<Player> spies;
    While you can successfully access the "players" member, trying to do something with "spies" fails.

    Not what is the huge difference between those two lines? (apart from the fact that one is a Map and the other a List, that's not what I mean here)

    Hint: It has something to with the "=" char ...
     
  10. Offline

    stelar7

    @Bone008
    Wow, that was a fail :/

    Ok, now there's no errors. :D
    But it still wont work...

    Mind giving me a few hints? :rolleyes:
     
  11. Offline

    Relick

    What won't work about it? You don't receive the chat log?
     
  12. Offline

    stelar7

    I'm not "spying" on the player...
     
  13. Offline

    Relick

    Code:java
    1. Main.spies.add(watched);
    2. Main.players
    3. .put(player, Main.spies);
    4. Main.spies.clear();


    That is what you use to define who spies who.
    However, not only do you not use a reverse method of this to post the messages, it isn't a very good way of going about it.

    Your HashMap should be <Player, Player> with the first Player being who is being spied, and the second being who the spyer is. E.g. I type /spy bob, it records into the hashmap 'bob', 'zantom07'

    Then when you check, here:
    Code:java
    1. Player spy = (Player) Main.players.get(msender);
    2. if (Main.players.containsKey(sender) && spy.isOnline() && spy != null) {
    3. // send to spyer
    4. }


    It should be:
    Code:java
    1. if (Main.players.containsKey(msender) {
    2. Player spy = (Player) Main.players.get(msender);
    3. if (spy.isOnline() && spy != null) {
    4. //send to spyer
    5. }
    6. }


    Now it checks to see if 'bob' is the sender, if he is, and 'zantom07' is online, then send the message to 'zantom07'

    There is also an even better way of doing it, so that multiple people can spy on bob, but I'll only tell you if you really can't figure it out.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  14. Offline

    stelar7

    That's what I've been trying to do xD
     
Thread Status:
Not open for further replies.

Share This Page