Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. package fr.emalios.saoplugin.commands;
  2.  
  3. import org.spongepowered.api.command.CommandException;
  4. import org.spongepowered.api.command.CommandResult;
  5. import org.spongepowered.api.command.CommandSource;
  6. import org.spongepowered.api.command.args.CommandContext;
  7. import org.spongepowered.api.command.spec.CommandExecutor;
  8. import org.spongepowered.api.data.DataContainer;
  9. import org.spongepowered.api.data.DataQuery;
  10. import org.spongepowered.api.data.type.HandTypes;
  11. import org.spongepowered.api.entity.living.player.Player;
  12. import org.spongepowered.api.item.inventory.ItemStack;
  13.  
  14. import static fr.emalios.saoplugin.commands.AddTag.containers;
  15.  
  16. public class SetTag implements CommandExecutor {
  17. @Override
  18. public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
  19. if(src instanceof Player)
  20. {
  21. Player player = (Player) src;
  22. player.getItemInHand(HandTypes.MAIN_HAND).ifPresent(itemStack -> {
  23.  
  24. if(containers == null)
  25. {
  26. System.out.println("NULL");
  27. }
  28. DataContainer c = itemStack.toContainer();
  29. c.set(DataQuery.of("UnsafeData","AttributeModifiers"),containers);
  30.  
  31. ItemStack modifiedItem = ItemStack.builder().fromContainer(c).build();
  32. player.setItemInHand(HandTypes.MAIN_HAND, modifiedItem);
  33.  
  34. });
  35. }
  36. return null;
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement