Hashmap help

Discussion in 'Plugin Development' started by jasonderlo22, Jul 23, 2013.

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

    jasonderlo22

    I looked at a hash map video and no I understand them, a little. I was wondering how I would make this work and if I need to use a hash map(nothing happen when I run my plugin).

    Code:java
    1. @EventHandler
    2. public void onPlayerDeath(PlayerDeathEvent event){
    3. if(event.getEntity().getKiller() instanceof Player)
    4. {
    5.  
    6. Player died = (Player) event.getEntity();
    7. Player killer = (Player) died.getKiller();
    8.  
    9. event.setDeathMessage(ChatColor.RED + "Player {PlayerName} was killed by {Killer} ".replace("{PlayerName}", died.getName()).replace("{Killer}", killer.getName()) + ChatColor.RED + ".");
    10.  
    11.  
    12.  
    13.  
    14. }
    15.  
    16.  
    17.  
    18.  


    Its is supposed to say "Player {PlayerName} was killed by {KillerName}" but nothing is happening when I run the command on my server


    Also I have a command that will need a hash map to store player names but I'm not sure how to do that.

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args, Player ply){
    2. if(cmd.getName().equalsIgnoreCase("killer")){
    3. final HashMap<Player, Player> killer = new HashMap<Player, Player>();
    4. if(killer.containsValue(killer)){
    5. Player s = (Player) sender;
    6.  
    7. s.sendMessage( ChatColor.BLUE + "Player" + ChatColor.RED + "{Killer}" + " Killed you!".replace("{Killer}",(CharSequence)s.getKiller() ));
    8. }
    9.  
    10.  
    11.  
    12.  
    13.  
    14. return true;
    15.  
    16. }
    17.  
    18.  
    19. return false;





    Thanks,

    jasonderlo22
     
  2. Offline

    Miner_Fil

    Code:java
    1. @EventHandler
    2. public void onPlayerDeath(PlayerDeathEvent event){
    3. if(event.getEntity().getKiller() instanceof Player)
    4. {
    5.  
    6. Player died = (Player) event.getEntity();
    7. Player killer = (Player) died.getKiller();
    8.  
    9. event.setDeathMessage(ChatColor.RED + died.getName() + " was killed by " + killer.getName());
    10.  
    11.  
    12.  
    13.  
    14. }


    Solution to Your First Issue!
     
  3. Offline

    jasonderlo22

    Miner_Fil Thank you so much! Do I need to enter it into the plugin.yml?
     
  4. Offline

    Miner_Fil

    Enter what Exactly?
     
  5. Offline

    jasonderlo22

    I just tested this on my plugin and I killed somone it it says jedo20 was slain by jasonderlo22,

    So its just the default kill message :(
     
  6. Offline

    jasonderlo22

  7. Offline

    Chinwe

    Are you registering the listener in your onEnable()?
     
    jasonderlo22 likes this.
  8. Offline

    jasonderlo22

    No I don't think so. How would I do that?

    Code:java
    1. public void OnEnable(){
    2. getLogger().info("Has been Enabled");
     
  9. Offline

    Chinwe

Thread Status:
Not open for further replies.

Share This Page