Creating A Player Object

Discussion in 'Plugin Development' started by MrTwiggy, Jan 9, 2013.

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

    MrTwiggy

    I'm working on a plugin that needs to be able to break blocks. However, I want it to call the BlockBreakEvent so that it will work with other plugins that may want to cancel the block break event, for things such as worldguard, reinforcements, protections, etc.

    However, the issue comes in that in order to call the BlockBreakEvent, I need to pass in the block and a player. However, since it's my plugin breaking the block, and not the player, I don't have any player to pass in. A work around is that I could just pick any random player from the online list, however, this won't work because the server could be empty, the specific player chosen could somehow be involved in the protections, etc.

    It appears from my research that I'm unable to construct a Player object. I thought about just passing in null, but most (if not all) plugins don't usually check for (event.getPlayer() != null), so I have a feeling it would just break a ton of plugins.

    Anyone have any solutions?
     
  2. Offline

    gomeow

    You can check if another plugin interfered by event.isCancelled()
     
  3. Offline

    MrTwiggy

    Yes, I know, this is entirely the point. But the issue I'm having is creating a fake Player object to pass into 'new BlockBreakEvent(BLOCK, PLAYER)' so that I don't break all the plugins who don't have '(event.getPlayer() != null)' checks in their BlockBreakEvent methods.
     
  4. Offline

    md_5

    I would avoid firing such an event if there is no player, since 99% of plugins won't be able to do anything useful.
     
  5. Offline

    EnvisionRed

    This is a bit hacky, but you can create a new instance of EntityPlayer with a name like "**YourPlugin**" and pass that in.
     
  6. Offline

    Ugleh

    You also dont want plugins with protections messing a player a message that they had no idea how it happened, i.e "You can not break that block, owned by exc"... Probably should just do what EnvisionRed said.
     
  7. Offline

    fireblast709

    Or just keep with what md_5 said. When you want to determine if you want to break a block, you should determine that programmatically (is that even a word?). If you want WorldGuard support, just softdepend it.
     
  8. Offline

    Coelho

    You could just implement Player from the Bukkit API and create your own class. Then you'll have a fresh Player instance to pass in...
     
  9. Offline

    md_5

    However that may lead to unspecified behaviour with regards to how you handle all the calls to permissions etc. Also it would break every update like CraftPlayer.
    I still don't see why he needs it.
     
  10. Offline

    Coelho

    Why would it break? You are only accessing the Bukkit API.
    tbqh I don't either. However!~
     
  11. Offline

    md_5

    Because the class he makes won't implement all the methods in Player as they are added.
     
  12. Offline

    Coelho

  13. Offline

    fireblast709

Thread Status:
Not open for further replies.

Share This Page