Arctic_Wolfy

TileEntity to Item

Oct 3rd, 2015
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.87 KB | None | 0 0
  1. //From Tile Entity
  2. @Override
  3.     public void updateEntity() {
  4.         if (cardStack!=null){
  5.             NBTTagCompound tag = cardStack.stackTagCompound;
  6.             if (tag == null) tag = new NBTTagCompound();
  7.             boolean isCardLinked = tag.getBoolean(NBTTags.Card.IS_LINKED_TAG);
  8.             if (!isCardLinked&&player!=null){
  9.                 GameProfile profile = player.getGameProfile();
  10.                 if (profile!=null) {
  11.                     UUID id = profile.getId();
  12.                     if (!id.equals(new UUID(0L,0L))) {
  13.                         BankAccount account = new BankAccount(this, id);
  14.                         //if (account!=null) {
  15.                             tag.setTag(NBTTags.Card.ACCOUNTS_TAG, BankAccount.toNBT(account, true));
  16.                             tag.setBoolean(NBTTags.Card.IS_LINKED_TAG, true);
  17.                             //tag.setString(NBTTags.Card.NAME_TAG,player.getDisplayName());
  18.                             cardStack.stackTagCompound = tag;
  19.  
  20.                             this.addAccount(account);
  21.  
  22.                             markForUpDate();
  23.                         //}
  24.                     }
  25.                 }
  26.             }
  27.  
  28.             if (currencyStack!=null){
  29.                 if (tick >= time){
  30.                     long ownerIDLeast, ownerIDMost;
  31.  
  32.                     NBTTagCompound ownerTag = tag.getCompoundTag(NBTTags.Card.ACCOUNTS_TAG).getCompoundTag(NBTTags.Card.UUID_OWNER_TAG);
  33.  
  34.                     ownerIDLeast = ownerTag.getLong(NBTTags.Card.UUID_LEAST_TAG);
  35.                     ownerIDMost = ownerTag.getLong(NBTTags.Card.UUID_MOST_TAG);
  36.  
  37.                     UUID id = new UUID(ownerIDMost,ownerIDLeast);
  38.  
  39.                     BankAccount account = getAccount(id);
  40.  
  41.                     if (account!=null) {
  42.                         account.addCredit(getValue(currencyStack.getItem()));
  43.                         decrStackSize(1, 1);
  44.                     }
  45.  
  46.                     markForUpDate();
  47.  
  48.                     tick = 0;
  49.                 } else tick++;
  50.             }else tick = 0;
  51.         }else tick = 0;
  52.     }
  53.  
  54. // From Item
  55.  
  56. @Override
  57.     public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean p_77624_4_) {
  58.         NBTTagCompound tag = stack.stackTagCompound;
  59.         if (tag != null) {
  60.             if (tag.hasKey(NBTTags.Card.ACCOUNTS_TAG)) {
  61.                 NBTTagCompound accountTag = tag.getCompoundTag(NBTTags.Card.ACCOUNTS_TAG);
  62.                 BankAccount account = BankAccount.fromNBT(accountTag, null);
  63.                 if (account!=null) {
  64.                     if (account.getPlayer() != null) list.add("Owner: " + ((account.getPlayer()==player) ? EnumChatFormatting.GREEN : EnumChatFormatting.DARK_RED) + account.getPlayer().getDisplayName());
  65.                     else{
  66.                         CompletableFuture<String> playerName;
  67.  
  68.                         long ownerIDLeast, ownerIDMost;
  69.                         NBTTagCompound ownerTag = tag.getCompoundTag(NBTTags.Card.UUID_OWNER_TAG);
  70.                         ownerIDLeast = ownerTag.getLong(NBTTags.Card.UUID_LEAST_TAG);
  71.                         ownerIDMost = ownerTag.getLong(NBTTags.Card.UUID_MOST_TAG);
  72.                         UUID id = new UUID(ownerIDMost,ownerIDLeast);
  73.  
  74.                         playerName = UsernameCache.get(id);
  75.  
  76.                         String name;
  77.  
  78.                         if (playerName.isDone()) {
  79.                             try {name = playerName.get();}
  80.                             catch (InterruptedException |
  81.                                     ExecutionException e) {name = "<"+id+">";e.printStackTrace();}
  82.                         } else name = "<"+id+">";
  83.                         list.add("Owner: " + EnumChatFormatting.DARK_RED + name);
  84.                     }
  85.                     if (account.getBank()!=null) list.add("Bank: " + EnumChatFormatting.GREEN + account.getBank().getName());
  86.                     else list.add("Bank: " + EnumChatFormatting.DARK_RED + "Bankrupt");
  87.                     list.add(String.format("Credit: %s\u20a9%.3f",
  88.                             ((account.getCredit() > 0) ? EnumChatFormatting.GREEN :
  89.                                     ((account.getCredit() < 0) ? EnumChatFormatting.DARK_RED :
  90.                                             EnumChatFormatting.YELLOW)),
  91.                             account.getCredit()));
  92.                 } else {
  93.                     LogHelper.warn("Account not found.");
  94.  
  95.                     NBTTagCompound ownerTag = accountTag.getCompoundTag(NBTTags.Card.UUID_OWNER_TAG);
  96.  
  97.                     long ownerIDLeast = ownerTag.getLong(NBTTags.Card.UUID_LEAST_TAG);
  98.                     long ownerIDMost = ownerTag.getLong(NBTTags.Card.UUID_MOST_TAG);
  99.  
  100.                     UUID id = new UUID(ownerIDMost, ownerIDLeast);
  101.  
  102.                     list.add("Owner: " + EnumChatFormatting.DARK_RED + id);
  103.                 }
  104.             }
  105.         }
  106.     }
Advertisement
Add Comment
Please, Sign In to add comment