WARNING:
Originally Posted by
Professor Oak
To everyone who have added this snippet, you
must make sure that your characters are probably synced.
This basically means that you can not remove/add characters (players or npcs) whenever you want.
Instead, you must add "requests" using queues or whatever, and add/remove the characters before the server updates.
Something like this:
------------------------------------------
Hey.
Since I'm using the same CharacterList as Ruse, I figured I could release this small piece of code to the public.
Quote from OSRS-wiki:
When the server processes players, it goes through them each in turn. If you are first in the list, you get processed first. In early versions of Classic, you always got put at the end of the list (if I remember rightly), so if you stayed logged in you would end up at the beginning of the list eventually. Being processed first meant you could catch up with people more easily when following them, which gave an advantage particularly in the wilderness with PVP. A low PID means you were at the beginning of the list, high PIDs were at the end.
This is no longer true, as you are now placed in a random place in the list and everyone else is shuffled up, so you don’t retain the same PID throughout your session. This makes things much fairer.
— Game Engine Team
Open CharacterList.java and add the following code however you want.
I'd recommend keeping it clean!
NOTE: The forEach method already exists. Make sure to replace it with mine.
Code:
/**
* This collections characters in a shuffled ArrayList.
* Used for battling PID.
*/
private final List<E> shuffled_characters = new ArrayList<E>();
/**
* Shuffles this collections list of characters.
*/
public void shuffle() {
shuffled_characters.clear();
for (E e : characters) {
if (e == null)
continue;
shuffled_characters.add(e);
}
Collections.shuffle(shuffled_characters);
}
/**
* {@inheritDoc}
* <p>
* This implementation will exclude all elements with a value of
* {@code null} to avoid {@link NullPointerException}s.
*
*
*
* UPDATED:
* Now uses a shuffle_list to battle PID.
* This means that all characters are always processed
* in an random order instead of having higher priority
* than other characters because of a higher PID.
*/
@Override
public void forEach(Consumer<? super E> action) {
//Make sure both lists have the same size, otherwise
//we should re-shuffle.
if(size != shuffled_characters.size()) {
shuffle();
}
//Perform the action on the shuffled characters
for(E e : shuffled_characters) {
if (e == null)
continue;
action.accept(e);
}
}
Now open World.java and FIND this code:
Code:
//Then we execute pre-updating code.
players.forEach(playerUpdate::executePreUpdate);
npcs.forEach(npcUpdate::executePreUpdate);
ABOVE it, add this:
Code:
//Now we shuffle our characters
//This will make sure each character gets processed
//In a random order each cycle.
players.shuffle();
npcs.shuffle();
And you should be done!
As you can see it's now processing the players (and npcs) in a random order every cycle.
Your server is now fairer, especially to stakers.
I got the idea from Stuart's post back in 2014, click here for link.
Honestly he deserves most credit, I simply made it work for Ruse-based servers.