Jump to content

Recommended Posts

Hello Runeplace!

I wrote this code for someone but they don't seem to want it so... Here.

This class is based off an Enum @Bananastreet created for god statues. Kudos to Bananastreet!

Why do you need to change how your server is handling the code for your scrolls?

Because some parts of the code are duplicated which is causing an increase in memory.

Creating an enum and storing the scrolls there is more easier for someone to add a new scroll and also more efficient, also yet again not duplicating code.

You don't have to use my code 🙂  But you really should consider it.

This code is server side only. You should not be asking if it needs to be added to the clients source code.

This code was written for Ruse framework but can be easily modified to suit your server.

  • Create a new Java file that must be an enum called MemberScrolls.
  • Scroll over all of the implemented methods and paste my code replacing yours.
import com.server.model.GameMode;
import com.server.model.PlayerRights;
import com.server.util.Misc;
import com.server.world.content.PlayerPanel;
import com.server.world.entity.impl.player.Player;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public enum MemberScrolls {

    TEN_SCROLL(10942, 10),
    TWENTY_SCROLL(10934, 20),
    FIFTY_SCROLL(10935, 50),
    ONE_HUNDRED_SCROLL(10943, 100);


    int itemId, scrollAmount;

    MemberScrolls(int itemId, int scrollAmount) {
        this.itemId = itemId;
        this.scrollAmount = scrollAmount;
    }

    static Map<Integer, MemberScrolls> scrolls = new HashMap<>();

    static {
        for (MemberScrolls scroll : MemberScrolls.values()) {
            scrolls.put(scroll.getItemId(), scroll);
        }
    }

    public int getItemId() {
        return itemId;
    }

    public int getScrollAmount() {
        return scrollAmount;
    }

    public static boolean claimScroll(Player player, int itemId) {

        MemberScrolls scroll = scrolls.get(itemId);

        if (Objects.isNull(scroll)) {
            return false;
        }

        String name = scroll.name().toLowerCase().replace("_", " ");

        //Checking if the player is doing something.
        if (player.busy()) {
            player.getPacketSender().sendMessage("You cannot perform this action right now. " +
                    "Please finish what you are doing first.");
            return false;
        } else {//If the player is not doing anything then this code will be read.
            player.getInventory().delete(scroll.getItemId(), 1);
            int points = scroll.getScrollAmount();
            //Updating points.
            player.incrementAmountDonated(points);//Updating the total donated all in all.
            //Setting the points based on the scroll.
            player.getPointsHandler().setDonationPoints(points, true);
            //Sending a messaged with the scroll name and points claimed.
            player.getPacketSender().sendMessage("You claim your "
                    + name + ". Your total funds have been updated.");
            //Checking if the player has enough points to move on to the next rank.
            checkForRank(player);
            //Refreshing the player panel ("Quest tab") to update the points gained.
            PlayerPanel.refreshPanel(player);
            return true;
        }
    }

    public static void checkForRank(Player player) {
        //Fetching the total amount a person has donated and storing the information to a new variable.
        int amountDonated = player.getAmountDonated();
        //Storing string as no reason to duplicate.
        String noRankUpdate = "Your rank did not update due to being ";
        //Setting the rights to null so we can perform our rank check.
        PlayerRights rights = null;
        //Setting the players rank based on the amount donated.
        if (amountDonated >= 10) {
            rights = PlayerRights.REGULAR;
        }
        if (amountDonated >= 50) {
            rights = PlayerRights.SUPER;
        }
        if (amountDonated >= 250) {
            rights = PlayerRights.EXTREME;
        }
        if (amountDonated >= 750) {
            rights = PlayerRights.LEGENDARY;
        }
        if (amountDonated >= 2500) {
            rights = PlayerRights.ONYX;
        }
        //Checking if the player has the right already or they are a game mode that the rank cannot be changed.
        if (rights != null && rights != player.getRights() && !player.getRights().isStaff()
                && player.getGameMode() != GameMode.IRONMAN
                && player.getGameMode() != GameMode.HARDCORE_IRONMAN) {
            //Sending a message to the player if they are eligible for the rank.
            player.getPacketSender().sendMessage("You've become a "
                    + Misc.formatText(rights.toString().toLowerCase()) + "! Congratulations!");
            //Setting the players new rank
            player.setRights(rights);
            //Updating the players rank once the rank is set.
            player.getPacketSender().sendRights();
            //Checking if the players game mode is anything other than a normal player.
        } else if (player.getGameMode() == GameMode.IRONMAN
                || player.getGameMode() == GameMode.HARDCORE_IRONMAN) {
            //If the player is not a normal player then they cannot have a rank update.
            player.getPacketSender().sendMessage(noRankUpdate
                    + player.getGameMode().name().toLowerCase().replace("_", " ") + ".");
        } else {//Checking to see if the member is staff because that is the only rank left to check.
            player.getPacketSender().sendMessage(noRankUpdate + player.getRights().name().toLowerCase() + ".");
            //If the player is indeed a staff member then they will not have a rank update.
        }
    }
}
  • Save the file then make your way to the ItemActionPacketListener file.
  • Search for:   private static void firstAction(final Player player, Packet packet) {
  • Scroll down to:   
    Location targetLocation = player.getLocation();

     

  • Call the file and the method one line before or one line after like so
Location targetLocation = player.getLocation();

MemberScrolls.claimScroll(player, itemId);

 

  • Within the same file look for the id's to all the member scrolls, delete the whole case for them. Example below
  • Delete from here
case 10942:

//all code inside

break;
  • To here for all of them and save your file then run your server and check out your fresh member scrolls!

What do you do with the old MemberScrolls.java?

click it. right click it. delete.

Do you need some help adding this class? Hmu 😉 I will be happy to help.

I do not give permission for anyone to charge for this code that I have just given for free.

Feel free to point out any flaws in my code and I will be sure to rectify it 😉

  • Like 1

Share this post


Link to post
Share on other sites
You do not have the required permissions to read this content.

Share this post


Link to post
Share on other sites
You do not have the required permissions to read this content.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...