Go to player's death point or go to last location before teleport

Discussion in 'Plugin Development' started by x86cam, Aug 3, 2012.

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

    x86cam

    I need help, I have no clue how to do this.

    I want to make a command that goes to player's death point or last location before teleportation.

    Any people who know how to do this?

    This command is basically like Essentials' /back command.
     
  2. Offline

    Malikk

    You'll need to listen to the EntityDeathEvent, check if it's a player, and add that player/location to a HashMap. Then, on your command, get the location from your map based on the player using the command and teleport.
     
  3. Offline

    x86cam

    Malikk
    There is no getPlayer in EntityDeathEvent.

    Here is my code so far...
    Code:java
    1.  
    2. @EventHandler
    3. public void getPlayerDeathLocation(EntityDeathEvent e)
    4. {
    5. if(e.getEntity() instanceof Player){
    6. getConfig().set("loc.death." + "((playerName))", e.getEntity().getLocation());
    7. }
    8. }
    9.  


    Note that playerName is supposed to be getPlayer().getName(); or whatever
     
  4. Offline

    Malikk

    You really don't want to be putting these into the config like that. Just use a HashMap

    Code:
    HashMap<Player, Location> deathLocations = new HashMap<Player, Location>();
     
    @EventHandler
    public void onEntityDeath(EntityDeathEvent event){
        if (event.getEntity() instanceof Player){
            Player player = (Player) event.getEntity();
     
            deathLocations.put(player, player.getLocation());
        }
    }
    
     
  5. Offline

    DealerNextDoor

    And just to extend what Malikk was saying, if you REALLY want to use some sort of file storage system, just save the HashMap to a file. If you don't know how, just use the official Bukkit Plugin Tutorial.
     
  6. Offline

    x86cam

    When I put everything together, the command says it was not found.
    I put it into plugin.yml
    I put getCommand("back").setExecutor(new commandBack());
     
  7. Offline

    DealerNextDoor

    ehh... Can we see that specific section of the plugin.yml, or the entire file? Also, it may help to put the commandBack class as well.
     
Thread Status:
Not open for further replies.

Share This Page