falling items

Discussion in 'Plugin Development' started by morha13, Jul 5, 2013.

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

    morha13

    Hello,

    how to do when player dies hes staff will not fall from him?
    i tried some things and its doesnt work...

    thank you!
     
  2. Offline

    Chinwe

    What I do:
    Have 2 maps storing player names and the contents of their inv and armour (ItemStack[]), and then on death, save their inv and armour contents to these maps and clear their inventories event.getDrops().clear()

    Then, on player respawn, check if the player's name is in these maps, and then set the contents of their armour and inv from the maps and remove them from the map.

    (Or use a wrapper class and a map (class called PlayerItems and Map<String, PlayerItems>))

    Or simply set gamerule keepInventory to true and back to its original value with a scheduler.

    Or simply clear their inv on death if you don't want to restore it.

    Will that do? :D
     
  3. Offline

    morha13

    @chinwe
    i did that:
    Code:java
    1. @EventHandler
    2. public void onDeath(PlayerDeathEvent event){
    3. Player player = event.getEntity();
    4. PlayerInventory pi = player.getInventory();
    5. pi.clear();
    6. }


    but still when player dies he stuff are falling...
     
  4. Offline

    Seadragon91

    You can remove the drops with:
    Code:
    event.getDrops.clear();
    And the xp with:
    Code:
    event.setDroppedExp(0);
     
  5. Offline

    Chinwe


    I thought there was that method, but when I looked at the docs I couldnt see it - but now I can :c
    Replace clearing the inv with what Seadragon91 said :>
     
  6. Offline

    iFamasssxD

    You could just set the vanilla minecraft gamrule keepInventory to true...
     
  7. Offline

    morha13

    i have server with multi-worlds...
    just in 1 of them i need that...
    @Seadragon91
    i am trying now..

    Code:java
    1. @EventHandler
    2. public void onDeath(PlayerDeathEvent event){
    3. Player player = event.getEntity();
    4. if(!(player.hasPermission("vaspvp.drop"))){
    5. event.getDrops().clear();
    6. } else {
    7.  
    8. }
    9. }


    Seadragon91

    doesnt work..
    please help!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  8. Offline

    chasechocolate

  9. Offline

    morha13

    i cant register my event.. its doing error..
     
  10. Offline

    xTrollxDudex

    morha13
    What's the error?
    In your MAIN class, in your onEnable() method, add
    Code:java
    1. //this is in the main class
    2. getServer().getPluginManager().registerEvents(new <listener name>(), this);
    3.  
    4. //the listener class. MUST implement listener, and MUST have the same name from the register Events line
    5. public class <listener name> implements Listener {
    6. //the listener-like public void blahblahblah...
    7. }


    It would also help to add an EventPriority. Change your @EventHandler to
    Code:java
    1. @EventHandler(priority = EventPriority.MONITOR)

    This would have the exact same place in the class as the EventHandler without the priority-
    Right above the public void....m

    Also, PlayerDeathEvent applies to player, so Player player = event.getEntity() IS REPLACED BY
    Code:java
    1. Player player = event.getPlayer()
     
    LilHambo likes this.
  11. Offline

    morha13

    i dont understand you.. sorry
    @xTrollxDudex

    my script:

    Code:java
    1. public class kit extends JavaPlugin{
    2. public static kit plugin;
    3. public final Logger logger = Logger.getLogger("Minecraft");
    4.  
    5. @EventHandler
    6. public void onDeath(PlayerDeathEvent event){
    7. Player player = event.getEntity();
    8. if(!(player.hasPermission("vaspvp.drop"))){
    9. event.getDrops().clear();
    10. } else {
    11.  
    12. }


    can you please add to my script what i need?
     
  12. Offline

    LilHambo

    morha13
    He's talking about registering events in your main class.
    If that is your main class, try making a listener.
     
  13. Offline

    xTrollxDudex

    T3h Cr33p3r He said he only wanted to disable it in one world, read before commenting.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Aug 6, 2019
  14. Offline

    Minnymin3

  15. Offline

    morha13

    @Minnymin3
    i have read that, thank you ...
    i am new in bukkit development so i still new

    @xTrollxDudex
    ok thank you i will try!
     
Thread Status:
Not open for further replies.

Share This Page