Votifier for your RSPS, in one jar

Four short methods connect the jar to your game. It answers ::claimvote, pays players who are online by itself, and can receive Votifier votes. With a VoteScript key, or without an account.

What you need

  • The source of your RSPS
  • Java 8 or newer

Add the jar

Download votescript.jar and add it to the libraries of your project. It needs nothing else.

Start it and pass commands

Start it when your server starts, with the four methods, and give it every command a player types. The names in the code are examples: use the ones of your own server.

your server
// what your game does for each kind of reward
VoteActions<Player> actions = new VoteActions<>();
actions.on("item", (p, i) -> p.getInventory().add(i.number(0, 1, 65535), i.amount));
actions.on("vip/donator", (p, i) -> p.addDonatorDays(i.amount));
actions.on("title", (p, i) -> p.setTitle(i.words(), i.forever() ? -1 : i.amount));
actions.on("xp", (p, i) -> p.getSkills().addXp(Skill.byName(i.arg(0)), i.amount));
actions.on("storage/votePoints", (p, i) -> p.addAttribute("votePoints", i.amount));
actions.on("teleport/vote_island", (p, i) -> !p.inCombat(), (p, i) -> p.moveTo(3222, 3222, 0));
actions.on("run/daily_box", (p, i) -> DailyBox.open(p, i.amount));   // your own

// when the server starts
static final Queue<Runnable> TASKS = new ConcurrentLinkedQueue<>();
static VoteServer votes;

votes = VoteServer.start(new File("data/votes"), new VoteServer.Game() {
    public void run(Runnable task) { TASKS.add(task); }
    public Collection<String> online() {
        List<String> names = new ArrayList<>();
        for (Player p : World.getPlayers()) if (p != null) names.add(p.getUsername());
        return names;
    }
    public boolean give(String name, VoteScript.Claim claim) {
        Player p = World.getPlayer(name);
        if (p == null || p.getInventory().freeSlots() < claim.items.size()) return false; // kept for later
        return actions.give(p, claim);
    }
    public void message(String name, String text) {
        Player p = World.getPlayer(name);
        if (p != null) p.sendMessage(text);
    }
}, actions);

// in your game tick
for (Runnable t; (t = TASKS.poll()) != null; ) t.run();

// in your command handler, with the whole text the player typed
if (votes != null && votes.command(player.getUsername(), text)) return;

Set your key

Start the server once. It writes the settings file. Put in your API key from Game server and restart.

You should now see: The folder <code>data/votes</code> with the settings file.
data/votes/votescript.properties (part)
url=https://votescript.voterank.net
key=YOUR_KEY
automatic=true
every=10
data/votes/votescript.properties (part)
key=

votifier=true
port=8192

# What a vote pays, as KEY:AMOUNT,KEY:AMOUNT
reward=995:100000
hours-between=1
keep-days=60

Optional: receive Votifier votes

Set votifier=true and open the port. Give lists the token from the settings file, or the key in data/votes/rsa/public.key. If all your lists use the token, set v1=false, because the old protocol proves nothing about the sender.

data/votes/votescript.properties (part)
url=https://votescript.voterank.net
key=YOUR_KEY
automatic=true
every=10

votifier=true
host=0.0.0.0
port=8192
v1=true

Try it in the game

Send a test vote from a vote site in your dashboard. Online players are paid by themselves, and ::claimvote works too.

You should now see: The items, and a message in the game.

If it does not work

Nothing happens on ::claimvote
Pass the whole text the player typed to the command method, before your own commands.
The player has no room
Return false from give. The reward is kept and tried again later.
Crashes or strange items
Rewards must be given on the game thread. The run method must put the task into your own game tick.
Has it run on a live server?
Not yet. It was tested with real connections and a simulated game with its own tick thread, so try it on a test world first.

Next

Give your players one place to vote

Your page is live as soon as you create your server. You can connect the rest step by step.