Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. @Listener
  2.     public void onPlayerRightClick(InteractBlockEvent.Secondary event) {
  3.         Optional<ItemStackSnapshot> usedItemOption = event.getCause().getContext().get(EventContextKeys.USED_ITEM);
  4.        
  5.         Optional<User> userOption = event.getCause().getContext().get(EventContextKeys.OWNER);
  6.        
  7.         if (usedItemOption.isPresent() && userOption.isPresent()) {
  8.             Optional<Player> playerOption = userOption.get().getPlayer();
  9.            
  10.             if (playerOption.isPresent()) {
  11.                 net.minecraft.item.ItemStack usedItem = ItemStackUtil.toNative(usedItemOption.get().createStack());
  12.                 Player player = playerOption.get();
  13.                
  14.                 if (!(usedItem.getTagCompound().getString("pokemonData")).equals("")) {
  15.                     PartyStorage party = Pixelmon.storageManager.getParty(player.getUniqueId());
  16.                    
  17.                     String tempString = usedItem.getTagCompound().getString("pokemonData");
  18.                    
  19.                     NBTTagCompound pokeNBT = new NBTTagCompound();
  20.                     try {
  21.                         pokeNBT = JsonToNBT.getTagFromJson(tempString);
  22.                     } catch (NBTException e) {
  23.                         e.printStackTrace();
  24.                     }
  25.                    
  26.                     Pokemon pokemonToReturn = Pixelmon.pokemonFactory.create(pokeNBT);
  27.                    
  28.                     if (party.getTeam().size() < 6) {
  29.                        
  30.                         int slotNumber = 0;
  31.                         while (party.get(slotNumber) != null) {
  32.                             slotNumber++;
  33.                         }
  34.                        
  35.                         party.set(slotNumber, pokemonToReturn);
  36.                        
  37.                     } else {
  38.                         player.sendMessage(Text.of("Your Party is Full!"));
  39.                     }
  40.                    
  41.                     player.sendMessage(Text.of(usedItem.getTagCompound().getString("pokemonData")));
  42.                    
  43.                 }
  44.                
  45.             }
  46.         }
  47.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement