Magic Notepaper Release
There has been some of these released before, but this one handles notepaper in both directions, as well as takes into account if you already have the item noted. if you have enough notepaper, or not, as well as checks if you actually have the item, making it a cleaner way to handle the notepaper.
MagicNotepaper.java
Code:
package com.rs.game.player.content.custom;
import com.rs.game.item.Item;
import com.rs.game.player.Player;
import com.rs.io.InputStream;
/**
*
* @author bob/zerion/pancakepal#4318
* 2/9/21
*
*/
public class MagicNotepaper {
public static void noteViaPaper (Player player, Item usedWith, Item itemUsed, InputStream stream) {
int amountUsed = player.getInventory().getAmountOf(usedWith.getId());
int paperHeld = player.getInventory().getAmountOf(itemUsed.getId());
if (usedWith.getDefinitions().isNoted() || usedWith.getDefinitions().isStackable() || usedWith.getDefinitions().getCertId() == -1) {
player.sm("You can't note this item.");
return;
}
else if ( paperHeld < amountUsed) {
if (usedWith.getDefinitions().getCertId() != -1) {
if (!player.getInventory().containsItem(usedWith.getId(), 1))
return;
if (player.getInventory().getFreeSlots() >= 1 || player.getInventory().contains(usedWith.getDefinitions().getCertId())) {
player.getInventory().deleteItem(usedWith.getId(), paperHeld);
player.getInventory().deleteItem(30372, paperHeld);
player.getInventory().addItem((usedWith.getDefinitions().getCertId()), paperHeld);
player.sendSimpleDialogue("You did not have enough magic notepaper to note all of your " +usedWith.getName()+"!");
} else
player.sm("You need at least one free inventory space to do this.");
}
}
else if (usedWith.getDefinitions().getCertId() != -1) {
if (!player.getInventory().containsItem(usedWith.getId(), 1))
/
return;
if (player.getInventory().getFreeSlots() >= 1 || player.getInventory().contains(usedWith.getDefinitions().getCertId())) {
player.getInventory().deleteItem(usedWith.getId(), amountUsed);
player.getInventory().deleteItem(30372, amountUsed);
player.getInventory().addItem((usedWith.getDefinitions().getCertId()), amountUsed);
player.sendSimpleDialogue("Your items have been noted!");
} else
player.sm("You need at least one free inventory space to do this.");
}
}
public static void noteViaItem (Player player, Item usedWith, Item itemUsed, InputStream stream) {
int paperHeld = player.getInventory().getAmountOf(usedWith.getId());
int amountUsed = player.getInventory().getAmountOf(itemUsed.getId());
if (itemUsed.getDefinitions().isNoted() || itemUsed.getDefinitions().isStackable() || itemUsed.getDefinitions().getCertId() == -1) {
player.sm("You can't note this item.");
return;
}
else if ( paperHeld < amountUsed) {
if (itemUsed.getDefinitions().getCertId() != -1) {
if (!player.getInventory().containsItem(itemUsed.getId(), 1))
return;
if (player.getInventory().getFreeSlots() >= 1 || player.getInventory().contains(itemUsed.getDefinitions().getCertId())) {
player.getInventory().deleteItem(itemUsed.getId(), paperHeld);
player.getInventory().deleteItem(30372, paperHeld);
player.getInventory().addItem((itemUsed.getDefinitions().getCertId()), paperHeld);
player.sendSimpleDialogue("You did not have enough magic notepaper to note all of your " + itemUsed.getName()+"!");
} else
player.sm("You need at least one free inventory space to do this.");
}
}
else if (itemUsed.getDefinitions().getCertId() != -1 || player.getInventory().contains(itemUsed.getDefinitions().getCertId())) {
if (!player.getInventory().containsItem(itemUsed.getId(), 1))
return;
if (player.getInventory().getFreeSlots() >= 1 || player.getInventory().contains(itemUsed.getDefinitions().getCertId())) {
player.getInventory().deleteItem(itemUsed.getId(), paperHeld);
player.getInventory().deleteItem(30372, amountUsed);
player.getInventory().addItem((itemUsed.getDefinitions().getCertId()), amountUsed);
player.sendSimpleDialogue("Your items have been noted!");
} else
player.sm("You need at least one free inventory space to do this.");
}
}
}
Put this inside your src->com->rs->game->player->content->custom. Then head into your InventoryOptionsHandler.java and put this into it in the itemOnItem method being sure to check for any existing notepaper handling in here :
InventoryOptionsHandler.java
Code:
if (usedWith.getId() == 30372) {
MagicNotepaper.noteViaItem(player, usedWith, itemUsed, stream);
return;
}
if (itemUsed.getId() == 30372) {
MagicNotepaper.noteViaPaper(player, usedWith, itemUsed, stream);
return;
}
Important!
If you don't have this method in Inventory.java :
Code:
public boolean contains(int itemId) {
return items.contains(new Item(itemId, 1));
}
You can replace this line instead :
Code:
if (player.getInventory().getFreeSlots() >= 1 || player.getInventory().contains(itemUsed.getDefinitions().getCertId())) {
With :
Code:
if (player.getInventory().getFreeSlots() >= 1 || player.getInventory().containsItems(itemUsed.getDefinitions().getCertId(), 1)) {
AND I CANNOT FORGET TO OFFER A HUGE SHOUTOUT TO MY MAN QUANTUM FOR TAKING THE TIME OUT OF HIS DAY TO MAKE THIS THREAD POST FOR ME!
MUCH LOVE!!