[Help] Need help testing my plugin

Discussion in 'Plugin Development' started by dajako, Aug 14, 2013.

Thread Status:
Not open for further replies.
  1. So, I am making an arena type plugin for my server. The idea is to allow players to use /deadoralive which will then teleport the player to the set coordinates of the area in the arena that I want them to start. The plugin will then spawn in 5 zombies in the 4 set locations.

    The plugin isn't working though. I don't know if this is because of the plugin itself or incompatibility.

    Here is the code:
    Class file arena:
    Code:
    package me.dajakos.arena;
     
    import java.util.logging.Logger;
     
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
     
    public final class arena extends JavaPlugin {
    public final Logger logger = Logger.getLogger("Minecraft");
    public static arena plugin;
    public final arenalistener al = new arenalistener();
     
     
    @Override
    public void onEnable(){
    PluginDescriptionFile pdfFile = this.getDescription();
    this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has been enabled!");
    PluginManager pm = getServer().getPluginManager();
    pm.registerEvents(this.al, this);
    }
     
    @Override
    public void onDisable() {
    PluginDescriptionFile pdfFile = this.getDescription();
    this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has been disabled!");
    }
    }
    
    Class file arenalistener:
    package me.dajakos.arena;

    Code:
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
     
    public class arenalistener implements Listener {
    public static arena plugin;
     
    @EventHandler
    public boolean onCommand(CommandSender sender, Command cmd, String lbl, String[] args){
    Player player = (Player) sender;
    player.sendMessage("TestA");
    World world = player.getWorld();
    Location spawn1 = new Location(world, -275, 50, -425);
    Location spawn2 = new Location(world, -330, 50, -416);
    Location spawn3 = new Location(world, -343, 50, -478);
    Location spawn4 = new Location(world, -271, 50, -484);
     
    if(lbl.equalsIgnoreCase("deadoralive")){
    player.sendMessage("TestB");
    int round1 = 5;
    int endround = 0;
    player.teleport(new Location(world, -308, 50, -444));
    do{
    player.sendMessage("TestC");
    world.spawnEntity(spawn1, EntityType.ZOMBIE);
    world.spawnEntity(spawn2, EntityType.ZOMBIE);
    world.spawnEntity(spawn3, EntityType.ZOMBIE);
    world.spawnEntity(spawn4, EntityType.ZOMBIE);
    round1--;
    }while(round1 != endround);
    }
    return false;
    }
    }
    
    There are no errors inside of eclipse.

    Btw, this is only one of my first plugins so please explain in depth if there is an issue.

    If you are willing to test the plugin on your server that'd be great!
    Here's the download link: <Edit by Moderator: Redacted mediafire url>
     
    Last edited by a moderator: Nov 5, 2016
  2. Offline

    dunbaratu

    Can you repost the code with the indenting corrected? It's really frustrating to try to read it and decipher what's going on with it all on the left column like that. I'm assuming that's not *really* how you have your code indented in the editor, but it's some sort of a side-effect of how it was pasted into the forum post.
     
  3. Offline

    xTrollxDudex

    dunbaratu
    The problem seems to stem less from uncommon mistakes, Bukkit also seems to clear the tabs when you paste the code.
    dajako
    Commands aren't events
     
  4. I'm unsure to what you mean.

    Yea, I know about everything in there already other than the command thing.
    So as a test I copied this:
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if(cmd.getName().equalsIgnoreCase("HideMe") && args.length == 1) {
            if (!(sender instanceof Player)) {
                sender.sendMessage("Only players can use this command!");
                return true;
            }
            // After checking to make sure that the sender is a Player, we can safely case it to one.
            Player s = (Player) sender;
     
            // Gets the player who shouldn't see the sender.
            Player target = Bukkit.getServer().getPlayer(args[0]);
            if (target == null) {
                sender.sendMessage("Player " + args[0] + " is not online.");
                return true;
            }
            // Hides a given Player (s) from someone (target).
            target.hidePlayer(s);
            return true;
        }
        return false;
    }
    From: http://wiki.bukkit.org/Plugin_Tutorial#Creating_plugin.yml
    And well, that doesn't work for me either...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  5. dajako Did you read the part where it said you have to register them in the plugin.yml? I guess you didn't...

    Oh yeah, Command are not Events, if you want you command executed in another class then do this from within the onEnable() method:
    Code:java
    1.  
    2. getCommand("your-command").setExecutor(new YourClasss(), PluginInstance);
    3.  


    And if you want it to get executed from within the main class then just add the onCommand method to your class.
     
  6. I did register the Command in the plugin.yml...
    In game when I type the command in game nothing happens.
    When I type it in the console it just says info then the command again.
     
  7. Try adding debug messages, to see where it fails... Can you give us the code you are currently using?
     
  8. I just simplified it so that it just sends a message.
    Actual plugin code:
    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
              if(cmd.getName().equalsIgnoreCase("deadoralive")){
                Player player = (Player) sender;
                player.sendMessage("TestA");
                return true;
              }
              return false;
              }
    plugin.yml:
    Code:
    name: plugin
    main: me.dajakos.plugin.plugin
    version: 1.0
     
    commands:
      deadoralive:
    Tell me if you'd like anything else.
     
  9. dajako Does it send the message?
     
  10. No.
    Nothing happens when I send the command in game.
    This is what happens in console:
    15.08 12:36:46 [Server] INFO deadoralive
     
  11. dajako Did you test in in-game?
     
  12. Yes. Nothing happens.
    Type in the command /deadoralive
    Nothing.
     
  13. dajako And its located in your main class?
     
  14. No.
    This is my main class:
    Code:
    package me.dajakos.plugin;
     
    import java.util.logging.Logger;
     
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
     
    public final class plugin extends JavaPlugin {
        public final Logger logger = Logger.getLogger("Minecraft");
        public static plugin plugin;
        public final playereventlistener pl = new playereventlistener();
        public final blocklistener bl = new blocklistener();
       
     
        @Override
        public void onEnable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has been enabled!");
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this.pl, this);
            pm.registerEvents(this.bl, this);
            // TODO Insert logic to be performed when the plugin is enabled
        }
     
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has been disabled!");
            // TODO Insert logic to be performed when the plugin is disabled
        }
    }
    The code I sent earlier is in playereventlistener.java.
     
  15. dajako LOL! Put the onCommand method in the main class -_-"
     
    dajako likes this.
  16. Ah... IS THAT REALLY THE ISSUE?!

    DAMN!
     
  17. LOL!
     
    dajako likes this.
  18. Have my babies.
     
  19. dajako No I'm not gay -_-"
     
    dajako likes this.
  20. Offline

    Awesomeman2

    CaptainBern Sorry this has nothing to do with this but i have a question.

    If you do a command in a differnt class and put the onEnable thing in do you have to do onCommand?
     
  21. Awesomeman2 No, if you want another class to handle it then do: getCommand("your_command").setExceutor(new CommandExcecutor(), this);

    Edit: You can do many things but the most used/easiest way is by doing it like I said up here.
     
Thread Status:
Not open for further replies.

Share This Page