Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.defiancecoding.defiantsecurity;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.entity.PlayerDeathEvent;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.plugin.java.JavaPlugin;
- public class TestClass extends JavaPlugin implements Listener {
- public void onEnable() {
- }
- public void onDisable() {
- //clear the list once the server crashes to prevent anything nasty
- playerItems.clear();
- }
- Map<String, List<ItemStack>> playerItems = new HashMap<String, List<ItemStack>>();
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (sender instanceof Player) {
- //casting to a player to get players class
- Player player = (Player) sender;
- if (sender.hasPermission("PermissionsHere")) {
- //we will make a for loop to scan all the items stored in the players map
- for (ItemStack items : playerItems.get(player.getUniqueId().toString())) {
- //and process the item, adding it to the players inventory.
- player.getInventory().addItem(items);
- //now the player has gotten the items we can clear the map so they dont take up space
- playerItems.remove(player.getUniqueId().toString());
- }
- } else {
- //No PermissionMessage here
- }
- } else {
- sender.sendMessage("Sender is console");
- }
- return false;
- }
- @EventHandler
- public void clearItemsOnDeath(PlayerDeathEvent e) {
- //cast entity to a player to grab permissions
- Player player = e.getEntity();
- //check if the player has permissions
- if (player.hasPermission("Permission")) {
- //if the player dies and has permission we will now add the players UUID as a string to the map
- //, with their items stored as a list
- playerItems.put(player.getUniqueId().toString(), e.getDrops());
- //now we can clear out the normal players drops
- e.getDrops().clear();
- }
- }
- //this method only colors messages such as &3TestText <- will translate &3 to its color printing a colored input message
- public String colorMessage(String message) {
- return ChatColor.translateAlternateColorCodes('&', message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement