package handlers.chat.commands.voiced; import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; import org.l2jmobius.commons.threads.ThreadPool; import org.l2jmobius.gameserver.config.custom.PremiumSystemConfig; import org.l2jmobius.gameserver.data.xml.SkillData; import org.l2jmobius.gameserver.entity.actor.Player; import org.l2jmobius.gameserver.entity.item.enums.ItemProcessType; import org.l2jmobius.gameserver.handler.IVoicedCommandHandler; import org.l2jmobius.gameserver.managers.PremiumManager; import net.voterank.votescript.VoteActions; import net.voterank.votescript.VoteRewards; import net.voterank.votescript.VoteScript; /** * .claimvote or .claimvote CODE for current L2J Mobius (master, 2026). Add * votescript.jar to the classpath and this class to MasterHandler. Reward keys * are item ids, or types: vip/premium (days; needs EnablePremiumSystem), title/NAME * (stays until changed), xp/experience, xp/sp, and what you allow below. Anything * else stays waiting in VoteScript. Older packs use other package and method names. */ public class VoteScriptClaim implements IVoicedCommandHandler { private static final String URL = "https://votescript.voterank.net"; private static final String KEY = ""; // API key from Game server in your dashboard // teleport/NAME: your places, e.g. PLACES.put("giran", new int[] { 83400, 147943, -3404 }); private static final Map PLACES = new HashMap<>(); // spell/ID: skills that votes may teach, with their level, e.g. SKILLS.put(1204, 2); private static final Map SKILLS = new HashMap<>(); // storage/NAME: player variables that votes may change, e.g. STORAGES.add("VOTE_POINTS"); private static final Set STORAGES = new HashSet<>(); // Your own: ACTIONS.on("run/buffs", (player, item) -> ...); also from other scripts. public static final VoteActions ACTIONS = new VoteActions<>(); private final VoteRewards _rewards; static { ACTIONS.on("item", (p, i) -> p.addItem(ItemProcessType.REWARD, Integer.parseInt(i.key), i.amount, p, true)); if (PremiumSystemConfig.PREMIUM_SYSTEM_ENABLED) { ACTIONS.on("vip/premium", (p, i) -> PremiumManager.getInstance().addPremiumTime(p.getAccountName(), i.amount, TimeUnit.DAYS)); } ACTIONS.on("title", (p, i) -> { p.setTitle(i.words().substring(0, Math.min(16, i.words().length()))); p.broadcastTitleInfo(); }); ACTIONS.on("xp/experience", (p, i) -> p.addExpAndSp(i.amount, 0)); ACTIONS.on("xp/sp", (p, i) -> p.addExpAndSp(0, i.amount)); for (Map.Entry place : PLACES.entrySet()) { ACTIONS.on("teleport/" + place.getKey(), (p, i) -> !p.isInCombat() && !p.isDead() && !p.isInOlympiadMode(), (p, i) -> p.teleToLocation(place.getValue()[0], place.getValue()[1], place.getValue()[2])); } for (Map.Entry skill : SKILLS.entrySet()) { ACTIONS.on("spell/" + skill.getKey(), (p, i) -> p.addSkill(SkillData.getInstance().getSkill(skill.getKey(), skill.getValue()), true)); } for (String name : STORAGES) { ACTIONS.on("storage/" + name, (p, i) -> { final int value = i.arg(1).isEmpty() ? p.getVariables().getInt(name, 0) + i.amount : i.number(1, 0, 999999999); p.getVariables().set(name, value); }); } } public VoteScriptClaim() throws IOException { _rewards = new VoteRewards(new VoteScript(URL, KEY), ThreadPool::execute, new File("data/votescript-pending.properties")); _rewards.can(ACTIONS); } @Override public boolean onCommand(String command, Player player, String params) { final VoteRewards.Handler handler = new VoteRewards.Handler() { @Override public boolean give(VoteScript.Claim claim) { return player.isOnline() && ACTIONS.give(player, claim); } @Override public void message(String text) { player.sendMessage(text); } }; if ((params != null) && !params.trim().isEmpty()) { _rewards.claimCode(player.getName(), params.trim(), handler); } else { _rewards.claim(player.getName(), handler); } return true; } @Override public String[] getCommandList() { return new String[] { "claimvote" }; } }