New to Java. Simple question

Discussion in 'Plugin Development' started by Alacho, Jan 23, 2012.

  1. Offline

    Alacho

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I'm new to Bukkit and Java. Trying to learn some simple things for some startings. This may sounds weird, but what I want to test is to ban myself when I log in. It's a simple testserver so I just want to test it and try to get a hang of it.

    My code, this far:
    Code:
    @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event){
           
            Player player = event.getPlayer();
           
            if(event.getPlayer().getName().equalsIgnoreCase("Alacho")){
                if(!event.getPlayer().isBanned()){
                    event.getPlayer().setBanned(true);
                    player.kickPlayer("Derp, Håvard. Nå har du spilt for mye Minecraft");
                }
    When I try to start the server, the plugin prints this severe error:
    Code:
    20:34:10 [SEVERE] Error occurred while enabling AlachoBan v0.1 (Is it up to date?): org.bukkit.event.EventHandler missing element event
    java.lang.annotation.IncompleteAnnotationException: org.bukkit.event.EventHandler missing element event
    at sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:53)
    at $Proxy4.event(Unknown Source)
    at org.bukkit.plugin.java.JavaPluginLoader.createRegisteredListeners(JavaPluginLoader.java:990)
    at org.bukkit.plugin.SimplePluginManager.registerEvents(SimplePluginManager.java:432)
    at me.alacho.ban.Main.onEnable(Main.java:24)
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:232)
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:1034)
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:252)
    at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:190)
    at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:173)
    at net.minecraft.server.MinecraftServer.t(MinecraftServer.java:356)
    at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:343)
    at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:175)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:407)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    Can anyone help on this?
  2. Offline

    Adamki11s

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Remove the @EventHandler

    That can be @Override if you want though.
  3. Offline

    edocsyl

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Maby u have a problem with your Player Listener
  4. Offline

    Alacho

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Thanks for the tip. The error disappeared, but I still don't get banned. :/
  5. Offline

    Icyrelic

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    ok i went and made the plugin my self to test it and i made it work try this code but change my plugin name from TestAutoBan to what ever you want and the package to your package here is the files you need to make TestAutoBan.java or YourPluginName.java and PListener.java here is TestAutoBan.java

    Code:
    package me.icyrelic.com;
     
     
     
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class TestAutoBan extends JavaPlugin {
     
        @Override
        public void onDisable() {
            //you can add a logger and log.info if you wish
        }
     
        @Override
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(new PListener(this), this);
        }
     
    }
    
    here is the PListener.java

    Code:
    package me.icyrelic.com;
     
     
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
     
    public class PListener implements Listener{
        TestAutoBan plugin;
        public PListener(TestAutoBan instance) {
     
            plugin = instance;
     
            }
       
       
        @EventHandler(priority = EventPriority.MONITOR)
        public void onPlayerJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            if(player.isBanned() == true){
                //The Player is banned
            }else{
                player.setBanned(true);
                player.kickPlayer("Derp, Håvard. Nå har du spilt for mye Minecraft");
            }
               
               
       
        }
     
    }
    
  6. Offline

    Alacho

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME

    I tried out this code, but it didn't work for me. :/ At first I tried to recode it by looking at it. It didn't work. Then I tried to copy/paste it. That didn't work either. :S
  7. Offline

    Icyrelic

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    it does work i made it and tested it
    replace you entire onPlayerJoin with

    Code:
      @EventHandler(priority = EventPriority.MONITOR)
        public void onPlayerJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            if(player.isBanned() == true){
                //The Player is banned
            }else{
                player.setBanned(true);
                player.kickPlayer("Derp, Håvard. Nå har du spilt for mye Minecraft");
            }
    and at the top after Public Class Your Plugin Name extends JavaPlugin add this under it
    Code:
    YOUR-PLUGIN-NNAME plugin;
        public PListener(YOUR-PLUGIN-NAME instance) {
     
            plugin = instance;
     
            }
    make sure you name the listener PListener or rename this public PListener to what ever and in your main class on the on enable add
    Code:
     Bukkit.getServer().getPluginManager().registerEvents(new PListener(this), this);
  8. Offline

    TheUnnamedDude

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Here is what i did:

    Mainclass:
    Code:
    package me.kevin.alachoban;
     
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class AlachoBan extends JavaPlugin{
        @Override
        public void onDisable() {
       
        }
        @Override
        public void onEnable() {
            BanAlachoPlayerListener playerListener = new BanAlachoPlayerListener(this);
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(playerListener, this);
        }
    }
    
    PlayerListener:
    Code:
    package me.kevin.alachoban;
     
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
     
    public class BanAlachoPlayerListener implements Listener {
        AlachoBan plugin;
        public BanAlachoPlayerListener(AlachoBan alachoBan) {
            plugin = alachoBan;
        }
        @EventHandler
        public void playerJoin(PlayerJoinEvent event){
            if(event.getPlayer().getName().equalsIgnoreCase("Alacho")){
                if(!event.getPlayer().isBanned()){
                    event.getPlayer().setBanned(true);
                    event.getPlayer().kickPlayer("You are banned!");
                }
            }
        }
    }
    
    EDIT: så var det den macen din da :)

    This post has been edited 2 times. It was last edited by TheUnnamedDude Jan 23, 2012.
    Alacho likes this.
  9. Offline

    Alacho

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Sorry for a late answer, but I have had a lot of things on my mind. But I figured it out. Thanks guys! :D

Share This Page