Dont Drop Certain Items Death

Discussion in 'Plugin Requests' started by little_dude187, Aug 6, 2014.

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

    EODCrafter

    I've been trying to update this Annihilation Plugin by Coasterman10...This method may work for you...
    Code:
    /*******************************************************************************
    * Copyright 2014 stuntguy3000 (Luke Anderson) and coasterman10.
    * 
    * This program is free software; you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation; either version 2 of the License, or
    * (at your option) any later version.
    *
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
    * GNU General Public License for more details.
    *
    * You should have received a copy of the GNU General Public License
    * along with this program; if not, write to the Free Software
    * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
    * MA 02110-1301, USA.
    ******************************************************************************/
    package net.coasterman10.Annihilation.listeners;
     
    import java.util.Arrays;
    import java.util.Iterator;
     
    import net.coasterman10.Annihilation.manager.SoundManager;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Sound;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerDropItemEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
     
    public class SoulboundListener implements Listener {
        private static final String soulboundTag = ChatColor.GOLD + "Soulbound";
     
        @EventHandler
        public void onSoulboundDrop(PlayerDropItemEvent e) {
            if (isSoulbound(e.getItemDrop().getItemStack())) {
                Player p = e.getPlayer();
                SoundManager.playSoundForPlayer(p, Sound.BLAZE_HIT, 1F, 0.25F, 0.5F);
                e.getItemDrop().remove();
            }
        }
     
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent e) {
            Iterator<ItemStack> it = e.getDrops().iterator();
            while (it.hasNext()) {
                if (isSoulbound(it.next()))
                    it.remove();
            }
        }
     
        public static boolean isSoulbound(ItemStack item) {
            ItemMeta meta = item.getItemMeta();
            if (item.hasItemMeta())
                if (meta.hasLore())
                    if (meta.getLore().contains(soulboundTag))
                        return true;
            return false;
        }
       
        public static void soulbind(ItemStack stack) {
            ItemMeta meta = stack.getItemMeta();
            if (!meta.hasLore())
                meta.setLore(Arrays.asList(soulboundTag));
            else
                meta.getLore().add(soulboundTag);
            stack.setItemMeta(meta);
        }
    }
     
  2. Offline

    little_dude187

  3. Offline

    EODCrafter

    That is exactly what that method does...The name of your Post....
     
  4. Offline

    mrCookieSlime

    He doesn't know what to do with that method if he cannot code...
     
  5. Offline

    little_dude187

    thats actully true so thats why im still bumping sorry if i dont know how to code :(
     
  6. Offline

    yewhoneydew

    what are the items, or do you want those configurable? and i might be able to fix this little_dude187
     
  7. Offline

    little_dude187

    read back in the comments ill tells you everything
     
  8. Offline

    EODCrafter

    My fault little Dude, I thought this was a plugin development forum.....I'm the one who is stupid. ;(
     
  9. Offline

    little_dude187

    its ok :)
    thanks :D
     
  10. little_dude187 Always glad to help xD

    ProgrammableCake Should a player be able to drop a blacklisted item ?

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

    little_dude187

    ?? what do u mean all i need is in the previous comments and or the first page
     
  12. little_dude187 Hello I have one question, how will the player get the premium items ?, when joining ??
     
  13. Offline

    little_dude187

    premium items?
     
  14. little_dude187 Items that you cant drop

    little_dude187 Hello, I just have one more question to get finished!
    I will need to know how will joining, respawning work, like can you have more than one premium item (Premium = Item That Cant be dropped!)

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

    little_dude187

    respawning you DONT LOOSE IT, duh joining same difference.
     
  16. Hello little_dude187, because of recent events I can not continue the plugin as I wont have enough time for it.
    Don't worry I am nearly done [Around 80%]
    Anyone can willfully continue this if they want to
    Here are instructions on how to finish the plugin
    This is the Main class and only class of the plugin, you may make it tidier if you want to
    I had finished the config.yml, plugin.yml, commands, and most events
    the only thing you will need to finish is the onPlayerRespawn event
    that will include finishing the Inventory saving, etc
    The approach I would recommend would be to save the inventory when the player dies then load it up when he spawns then delete every item that dosent have the lore of Premiun

    Btw if you are planning on publishing this on BukkitDev don't forget to make me contributor :)

    -ProgrammableCake

    Code:java
    1. package net.RPD.PremiumPlus;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.Arrays;
    5. import java.util.HashMap;
    6. import java.util.Iterator;
    7. import java.util.List;
    8.  
    9. import org.bukkit.Bukkit;
    10. import org.bukkit.ChatColor;
    11. import org.bukkit.command.Command;
    12. import org.bukkit.command.CommandSender;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.event.EventHandler;
    15. import org.bukkit.event.Listener;
    16. import org.bukkit.event.entity.PlayerDeathEvent;
    17. import org.bukkit.event.player.PlayerDropItemEvent;
    18. import org.bukkit.event.player.PlayerJoinEvent;
    19. import org.bukkit.event.player.PlayerRespawnEvent;
    20. import org.bukkit.inventory.Inventory;
    21. import org.bukkit.inventory.ItemStack;
    22. import org.bukkit.inventory.meta.ItemMeta;
    23. import org.bukkit.plugin.java.JavaPlugin;
    24.  
    25. public class Main extends JavaPlugin implements Listener {
    26.  
    27. public List<String> BlackList = getConfig().getStringList("BlackList");
    28. public List<String> Premium = new ArrayList<String>();
    29. public HashMap<String, ItemStack[]> SavedPremiumItems = new HashMap<String, ItemStack[]>();
    30. public static final String tag = ChatColor.GOLD + "Premium";
    31.  
    32. @Override
    33. public void onEnable() {
    34. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    35. this.getConfig().options().copyDefaults(true);
    36. this.saveDefaultConfig();
    37.  
    38. }
    39.  
    40. public void saveInventory(Player p) {
    41. this.SavedPremiumItems.put(p.getName(), copyInventory(p.getInventory()));
    42. }
    43.  
    44. public ItemStack[] copyInventory(Inventory inv) {
    45. ItemStack[] original = inv.getContents();
    46. ItemStack[] copy = new ItemStack[original.length];
    47. for(int i = 0; i < original.length; ++i) {
    48. if(original != null)
    49. copy = new ItemStack(original);
    50. return copy;
    51. }
    52. }
    53.  
    54. private void restoreInventory(Player p, ItemStack[] inventory) {
    55. p.getInventory().setContents(inventory);
    56. }
    57.  
    58. @Override
    59. public void onDisable() {
    60. this.saveConfig();
    61. }
    62.  
    63. @EventHandler
    64. public void onPlayerDeath(PlayerDeathEvent e) {
    65. Player p = e.getEntity();
    66. Iterator<ItemStack> it = e.getDrops().iterator();
    67. Premium.add(p.getName());
    68. while(it.hasNext()) {
    69. if (isPremium(it.next()))
    70. it.remove();
    71. }
    72.  
    73. }
    74.  
    75. @EventHandler
    76. public void onPlayerRespawn(PlayerRespawnEvent e) {
    77. final Player p = e.getPlayer();
    78. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    79. @Override
    80. public void run() {
    81.  
    82. }
    83.  
    84. }, 1L);
    85. }
    86.  
    87. public static boolean isPremium(ItemStack item) {
    88. ItemMeta meta = item.getItemMeta();
    89. if(item.hasItemMeta())
    90. if(meta.hasLore())
    91. if(meta.getLore().contains(tag)) return true;
    92. return false;
    93. }
    94.  
    95. public static void makePremium(ItemStack stack) {
    96. ItemMeta meta = stack.getItemMeta();
    97. if(!meta.hasLore())
    98. meta.setLore(Arrays.asList(tag));
    99. else
    100. meta.getLore().add(tag);
    101. stack.setItemMeta(meta);
    102. }
    103.  
    104. @EventHandler
    105. public void onDropEvent(PlayerDropItemEvent e) {
    106. Player p = e.getPlayer();
    107. String BlackListedItem = e.getItemDrop().getItemStack().getType().toString();
    108.  
    109. for(int i = 0; i < BlackList.size(); i ++) {
    110. if(BlackList.get(i).equalsIgnoreCase(BlackListedItem)) {
    111. e.setCancelled(true);
    112. p.sendMessage(ChatColor.RED + "You can not drop a premium item!");
    113. }
    114. }
    115. }
    116.  
    117. @Override
    118. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    119. if(cmd.getName().equalsIgnoreCase("add")) {
    120. if(args.length != 0) {
    121. BlackList.add(args[0].toUpperCase());
    122. getConfig().set("BlackList", BlackList);
    123. saveConfig();
    124. sender.sendMessage(ChatColor.RED + "You have added " + ChatColor.GOLD + args[0]);
    125. return true;
    126. }
    127. return false;
    128. }
    129. return true;
    130. }
    131.  
    132. }
    133.  


    Config
    Code:
    #Default Config
    BlackList:
    Plugin.yml
    Code:
    name: PremiumPlus
    version: 0.1
    description: A Plugin By  RPDRAGON
    author: RPDRAGON
    main: net.RPD.PremiumPlus.Main
    commands:
      Add:
        description: Add Item To BlackList
     
  17. Offline

    little_dude187

  18. Offline

    little_dude187

  19. Offline

    little_dude187

  20. Offline

    little_dude187

  21. Offline

    little_dude187

    bump i really really want this made its been months and i know bukkit is dieing but i really need it
     
  22. Offline

    little_dude187

    bump? its been a while since ive bumped

    @little_dude187 I believe that the plugin you have already blocks it... Not completely sure, but I've heard it does. Maybe in the config? Or already by default? Don't quote me on this, but I've heard it does :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 16, 2021
Thread Status:
Not open for further replies.

Share This Page