[Req] I need a simple command plugin.

Discussion in 'Archived: Plugin Requests' started by WC_Shill, Feb 17, 2012.

  1. Offline

    WC_Shill

    Plugin category: Automatic Console Command.

    Suggested name: ReStart

    A bit about me: I'm a struggling (obviously) new plugin writer who can't seem to get it right.

    What I want: I need a plugin to issue a command from the console when a player re-spawns

    Ideas for commands: No commands needed for this plugin.

    Ideas for permissions: Since it is done automatically by the console none needed.

    Willing to pay up to: $5.00

    When I'd like it by: As soon as possible

    Similar plugin requests: None that I know of.
     
  2. Offline

    Fell

    WC_Shill I'd be willing to make this for you... could you please provide a little bit more detailed info on what it does?

    Nvm, it does a command when a player respawns? what command?
     
  3. Offline

    Windex

    What command would it be issuing at respawn?
     
  4. Offline

    WC_Shill

    The command would be: removeIsland and it would need to pass the name of the player who respawned.

    Example: Say a player named WC_Shill dies and respawns the console would need to issue the following command

    removeIsland WC_Shill
     
  5. Offline

    blargh

    Code:
    protected static ConsoleCommandSender console;
    protected static Server server;
    protected static ConsoleCommandSender console;
    protected static Server server;
    private final MyListener listener = new MyListener();
    @Override
    public void onEnable() {
    server = getServer();
    console = server.getConsoleSender();
    Bukkit.getServer().getPluginManager().registerEvents(listener, this);
    }
    public static void com(String command) {
    server.dispatchCommand(console, command);
    }
    --------------
    MyListener:
    @EventHandler(priority = EventPriority.NORMAL)
    public void playerRespawns(final PlayerRespawnEvent event) {
            MyPlugin.com("removeIsland" + event.getPlayer().getName()
    }
    }
    
    this is just a brief example. I think this is it, i dont need to compile it etc.
    I hope i could help you
     
  6. Offline

    Wolfy9247

    Cleaning up the last post:
    Code:java
    1.  
    2. import java.util.logging.Logger;
    3.  
    4. import org.bukkit.Server;
    5. import org.bukkit.command.CommandException;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.player.PlayerRespawnEvent;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class ReStart extends JavaPlugin implements Listener {
    13.  
    14. protected static Server server;
    15. public static Logger log = Logger.getLogger("Minecraft");
    16. public static final String logTag = "[ReStart] ";
    17.  
    18. @Override
    19. public void onEnable() {
    20. getServer().getPluginManager().registerEvents(new ReStart(), this);
    21. }
    22.  
    23. @EventHandler
    24. public void onPlayerRespawn(PlayerRespawnEvent event) {
    25. server = getServer();
    26. Player player = event.getPlayer();
    27. try {
    28. server.dispatchCommand(server.getConsoleSender(), "removeIsland " + player.getName());
    29. /* Since I haven't worked with this before I'm not sure if you'd be able to put
    30.   * 'null' as a proper input to args[0] for dispatchCommand()
    31.   */
    32. }
    33. catch(CommandException ce) {
    34. log.warning(logTag + "An unhandled exception has occured!");
    35. log.warning(logTag + "If this error continues please alert "+getDescription().getAuthors() + "!");
    36. ce.printStackTrace();
    37. }
    38. }
    39. }
    40.  
     
    blargh likes this.
  7. Offline

    Steffion

    Thank you i needed that!
     
  8. Offline

    WC_Shill

    The following line has an error:

    public class ReStart extends JavaPlugin implements Listener {

    The error reads:

    The type ReStart must implement the inherited abstract method Plugin.onDisabel()

    Recomended fixes:

    Do I add onDisable or make the type abstract
    Code:
    package me.WC_Shill.restart;
     
    import java.util.logging.Logger;
     
    import org.bukkit.Server;
    import org.bukkit.command.CommandException;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerRespawnEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class ReStart extends JavaPlugin implements Listener {
       
    protected static Server server;
    public static Logger log = Logger.getLogger("Minecraft");
    public static final String logTag = "[ReStart] ";
     
    @Override
    public void onEnable() {
    getServer().getPluginManager().registerEvents(new ReStart(), this);
    }
     
    @EventHandler
    public void onPlayerRespawn(PlayerRespawnEvent event) {
    server = getServer();
    Player player = event.getPlayer();
    try {
    server.dispatchCommand(server.getConsoleSender(), "removeIsland " + player.getName());
    /* Since I haven't worked with this before I'm not sure if you'd be able to put
      * 'null' as a proper input to args[0] for dispatchCommand()
      */
    }
    catch(CommandException ce) {
    log.warning(logTag + "An unhandled exception has occured!");
    log.warning(logTag + "If this error continues please alert "+getDescription().getAuthors() + "!");
    ce.printStackTrace();
    }
    }
     
     
    }
     
  9. Offline

    blargh

  10. Offline

    Wolfy9247

  11. Offline

    WC_Shill

    I will try it with R% I think I was using R3 or R4

    Ok I tried adding the method compiled without errors but wont run on the server.
    I also tried it with the build Wolfy9247 suggested same thing compiles without error but the server gives error message:
    [SEVERE] Could not pass event org.bukkit.event.player.PlayerRespawnEvent to ReStart

    Complete error listing:

    2012-02-18 20:35:18 [SEVERE] Could not pass event org.bukkit.event.player.PlayerRespawnEvent to ReStart
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$103.execute(JavaPluginLoader.java:1026)
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:57)
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:453)
    at net.minecraft.server.ServerConfigurationManager.moveToWorld(ServerConfigurationManager.java:267)
    at net.minecraft.server.ServerConfigurationManager.moveToWorld(ServerConfigurationManager.java:226)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:965)
    at net.minecraft.server.Packet9Respawn.handle(SourceFile:30)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:226)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:100)
    at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:78)
    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:537)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:435)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.bukkit.plugin.java.JavaPluginLoader$103.execute(JavaPluginLoader.java:1024)
    ... 12 more
    Caused by: java.lang.NullPointerException
    at me.WC_Shill.restart.ReStart.onPlayerRespawn(ReStart.java:29)
    ... 17 more

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

    Wolfy9247

    WC_Shill
    I'm assuming that's because there's no ConsoleSender. This proves my suspicion of not being able to use 'null' as a valid person to execute the command.

    Hm, there's some more complicated methods you could go through... but I'm sure one of the more 'advanced' developers might know something on it.
     
  13. Offline

    WC_Shill

    Maybe this would help,

    <> = argument passed with command.

    Pseudo Code:

    Listen for player respawn event
    if event occurs
    get player name
    issue command (as op or server console) removeIsland <playername>
    else continue listening.

    Or

    Listen for player respawn event
    if event occurs
    get player name
    issue command as <player> newIsland <replace>
    else continue listening

    Any help would be appreciated.
     
  14. Offline

    Wolfy9247

    The code would compile if the part where the entity who issued the command wasn't null. If you can find a workaround to it in the Javadocs (which there most likely is) you'll be set. That's the only reason it isn't working.
     
  15. Offline

    WC_Shill

    baby steps here where ever is the entity declared as null?

    totally lost.
     
  16. Offline

    Wolfy9247

    The server.getConsoleSender() would return null if it's not being sent by the console.
     
  17. Offline

    WC_Shill

    ah thank you sir
     
  18. Offline

    Sanzennin

    Hmm, now, this might be a tad odd question, but why not just make the player the commandSender? Since ya can cast commandsender to player, it should work the otherway around too.

    Maybe do something like...
    commandSender sender = (commandSender) player;

    Then pass the sender as the command sender for dispatch command. Haven't tested or fidled with stuff like this before, but I think it might work...
     
  19. Offline

    Wolfy9247

    The only problem is if the player doesn't have permission to perform the command it might not allow it. Just a thought though.
     
  20. Offline

    gamerguy14

    What code is at line 29?

    A null pointer means that there was a method call to a null object at that line. If the line is server.dispatchCommand(server.getConsoleSender(). "removeIsland " + player.getName()); then I have two suggestions.

    1) The server variable is set at the beginning of the event so it is reset all the time. Try setting server in onEnable().

    2) Use getCommand("removeIsland").execute(server.getConsoleSender(), "removeIsland", new String[1] {player.getName()}); instead.
     
  21. Offline

    Sanzennin

    Oh, you can make the permission for that command default true. So no problem there. Ofcourse, if the command is a security risk, an extra argument could be used to make sure players don't manually run the command (like maybe the players unique ID or something). If its not a risk tho, no check is required.
     
  22. Offline

    WC_Shill

    Started over with this code, it almost works.
    Tested it in offline mode with the player name Player.
    No errors on compile or run but it prints this on the game screen:

    CraftPlayer {name=Player} /newIsland replace

    Code:
    package me.WC_Shill.restart;
    import java.util.logging.Logger;
     
    import org.bukkit.Server;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
     
    public class ReStart extends JavaPlugin implements Listener {
    public static Logger log = Logger.getLogger("Minecraft");
    public static final String logTag = "[ReStart] ";
    protected static Server server;
     
    @Override
    public void onEnable() {
    getServer().getPluginManager().registerEvents(new ReStart(), this);
    }
    @EventHandler
    public Boolean onPlayerDeath(PlayerDeathEvent event){
            Player player =  (Player)event.getEntity();
            String command = "/newIsland replace";
            player.sendMessage(player + command);
            return Boolean.valueOf(true);
    }
    @Override
    public void onDisable() {
        // TODO Auto-generated method stub
    }
    }
     
  23. Offline

    Sorroko

    WC_Shill Well thats because you added player.sendMessage(player + command); Just get rid of it or if you want player name use player.getDisplayName()
     
  24. Offline

    Score_Under

  25. Offline

    Sanzennin

    Shouldn't ya have
    server.dispatchCommand((commandSender) player, "removeIsland " + player.getName();
    Instead of

    player.sendMessage(player + command);
    ?

    Think your version would work then.
     
  26. Offline

    WC_Shill

    Thanks for trying but no it didn't work. It passed the message you had in the config file to the player as a whisper. But, when I edited the config file to put the command in it, it returned an unknown command error. Maybe I did the config wrong.

    Damn back to the null pointer error. I think I am about ready to give up on this for now.

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

    Zarius

    OtherDrops can run a command on player death if that's ok (it doesn't deal with the player respawn event at all - just player death).

    Example:
    Code:
      PLAYER:
        - tool: ANY  # deal with any cause of death
          message: "<optional message to player that died>"
          command: "/!$removeisland %v" 
          # ! means send any messages from command to console
          # $ means perform command as console
          # %v is a variable for the victims playername
    
     
  28. Offline

    Sanzennin

    Huh, which one is giving null? Do
    System.out.println("Player? "+player);
    System.out.println("Server? "+server);
    if neither of those, do
    commandSender sender = (commandSender) player;
    System.out.prinln("Sender? "+sender);
    To make sure the cast is working correctly.

    Also, to determine WHERE the null happens you could do
    System.out.println("I'm here");
    System.out.println("I'm debug");
    System.out.println("I'm me");
    System.out.println("I'm bug");
    Or something about as bright around where you think the error originates from. Primitive, but effective. The code stops on the line that gives the error, so if you put "I'm here" above server.dispatchCommand, and "I'm debug" below.
    Run the code, if you a) don't have "I'm here" in the console, the bug was somewhere before that. b) Have "I'm here" but no "I'm debug" the exception is in "server.dispatchCommand" or c) Have both of them, then the exception happens later.

    Well, I'm 99% certain that the exception originates from server.dispatchCommand, so lets just find out what is null, eh?
     
  29. Offline

    WC_Shill

    Well aren't I a dumbass. I just tried it again and the same error happened. Then I though what the heck let me try the command from the console. The command doesn't work same error.

    Back to the drawing board the player issued command newIsland replace works, guess I will have to come at it from that angle.
     
  30. Offline

    Score_Under

    The code I gave works - if it's telling you that the command was unknown, maybe it is unknown -- check that you spelled it right in the config, then if you're sure it's spelled right, type that exact command in that exact capitalization into the console and see if it works there.

    Remember that commands that usually have a slash before them, don't.


    Edit -- If the command works as a player but not from the console, then tell me what plugin you're using because that is terrible
     

Share This Page