Solved Why doesn't this work?

Discussion in 'Plugin Development' started by Faith, Mar 19, 2015.

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

    Faith

    I don't know if I am being completely stupid or what but my plugin just isn't working.


    Code:
    package me.faithcodes.ChatActivation;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    public class ChatActivation extends JavaPlugin implements Listener{
        
            World w = (World)Bukkit.getWorlds().get(0);
            World world;
        
            public void onEnable() {
                    Bukkit.getPluginManager().registerEvents(this, this);
                    getConfig().options().copyDefaults(true);
                    saveConfig();
                    world = getServer().getWorlds().get(0);
            }
        
            public void onPlayerLogin(PlayerLoginEvent pje) {
                    Player player = pje.getPlayer();
                    if(!(player.hasPermission("cactivation.chat"))) {
                            player.sendMessage(ChatColor.GREEN + getConfig().getString("joinmessage"));
                    }
            }
        
            public void AsyncPlayerChat(AsyncPlayerChatEvent apce) {
                    Player player = apce.getPlayer();
                    if(!(player.hasPermission("cactivation.chat"))) {
                            apce.setCancelled(true);
                    }
                    if(apce.getMessage().toLowerCase().contains(getConfig().getString("activationword"))){
                            player.sendMessage(getConfig().getString("activatedmessage"));
                            apce.setCancelled(false);
                            player.sendMessage(getConfig().getString("correctmessage"));
                player.teleport(w.getSpawnLocation());
                    } else {
                            player.sendMessage(getConfig().getString("joinmessage"));
                    }
            }
    }
    EDIT: This is not the finished plugin. I was just testing what I had and it doesn't do anything.

    EDIT by Timtower: we don't remove stuff that can be used to learn.
     
    Last edited by a moderator: Mar 19, 2015
  2. @Faith
    1. You're making Bukkit calls before the plugin has been enabled:
      Code:
      World w = (World)Bukkit.getWorlds().get(0);
      (not to mention that you have another variable that is also equal to the Bukkit.getWorlds().get(0))
    2. You don't have @EventHandler annotations on top of your events.
     
  3. Offline

    Kilorbine

    try adding this in your onEnable()
    Code:
    PluginManager pm = getServer().getPluginManager();
               pm.addPermission(new Permission("cactivation.chat");
    Then, you set yourself the permision
    I don't have faith in your code...
     
  4. Offline

    sgavster

    Just do what @Assist said, and it should work.. @EventHandler is the most important things for events.
     
  5. Offline

    MordorKing78

    You forgot the @EventHandler on your event
     
  6. Offline

    Faith

    Like I said, I think I'm just being stupid. Lol thanks.
     
Thread Status:
Not open for further replies.

Share This Page