Initial commit
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>ProjectCranked</artifactId>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>RPS</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.crankedpvp</groupId>
|
||||
<artifactId>Utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.massivecraft</groupId>
|
||||
<artifactId>Factions</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,134 @@
|
||||
// =============================================== //
|
||||
// Recompile disabled. Please run Recaf with a JDK //
|
||||
// =============================================== //
|
||||
|
||||
// Decompiled with: CFR 0.152
|
||||
// Class Version: 8
|
||||
package net.crankedpvp.rps;
|
||||
|
||||
import net.crankedpvp.rps.commands.RPSCommand;
|
||||
import net.crankedpvp.rps.listeners.ChooseEvents;
|
||||
import net.crankedpvp.rps.listeners.InventoryCloseListener;
|
||||
import net.crankedpvp.rps.listeners.RPSEvents;
|
||||
import net.crankedpvp.rps.listeners.TopGuiListener;
|
||||
import net.crankedpvp.rps.players.PlayerData;
|
||||
import net.crankedpvp.rps.players.PlayerDataManager;
|
||||
import net.crankedpvp.rps.players.wages.InventoryEnum;
|
||||
import net.crankedpvp.rps.players.wages.RPS;
|
||||
import net.crankedpvp.rps.players.wages.WageManager;
|
||||
import net.crankedpvp.rps.rpsutilities.RpsUtilities;
|
||||
import net.crankedpvp.rps.utilities.CFG;
|
||||
import net.crankedpvp.rps.utilities.MessagesX;
|
||||
import net.crankedpvp.rps.utilities.VaultAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class RPSPlugin extends JavaPlugin {
|
||||
private final WageManager wageManager = new WageManager(this);
|
||||
private final PlayerDataManager playerDataManager = new PlayerDataManager(this);
|
||||
private final RpsUtilities rpsUtilities = new RpsUtilities(this);
|
||||
private final CFG options = new CFG(this, "options", true);
|
||||
private final CFG rps = new CFG(this, "rps", true);
|
||||
private final CFG playerBase = new CFG(this, "playerbase", true);
|
||||
private final CFG messages = new CFG(this, "messages", false);
|
||||
private final VaultAPI vault = new VaultAPI(this);
|
||||
|
||||
public void onEnable() {
|
||||
if (!this.vault.setupEconomy()) {
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
this.getCommand("rps").setExecutor(new RPSCommand(this));
|
||||
MessagesX.repairPaths(this.messages);
|
||||
this.playerDataManager.loadFrom();
|
||||
this.rps.getFile().getConfigurationSection("Bets").getKeys(false).forEach(name -> {
|
||||
if (!this.rps.getFile().isSet("Bets." + name + ".rps")) {
|
||||
this.rps.getFile().set("Bets." + name, null);
|
||||
this.rps.saveFile();
|
||||
return;
|
||||
}
|
||||
RPS rps = RPS.valueOf(this.rps.getFile().getString("Bets." + name + ".rps"));
|
||||
int money = this.rps.getFile().getInt("Bets." + name + ".money");
|
||||
PlayerData data = this.playerDataManager.getData(name);
|
||||
data.setMoney(money);
|
||||
data.setWageRps(rps);
|
||||
});
|
||||
PluginManager pm = Bukkit.getPluginManager();
|
||||
pm.registerEvents(this.playerDataManager, this);
|
||||
pm.registerEvents(new RPSEvents(this), this);
|
||||
pm.registerEvents(new TopGuiListener(this), this);
|
||||
pm.registerEvents(new InventoryCloseListener(this), this);
|
||||
pm.registerEvents(new ChooseEvents(this), this);
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
|
||||
FileConfiguration playerBase = this.playerBase.getFile();
|
||||
this.playerDataManager.getPlayerData().forEach((key, data) -> {
|
||||
playerBase.set("Players." + key + ".wins", data.getWins());
|
||||
playerBase.set("Players." + key + ".losses", data.getLosses());
|
||||
playerBase.set("Players." + key + ".uuid", data.getPlayer().getUniqueId().toString());
|
||||
});
|
||||
this.playerBase.saveFile();
|
||||
this.playerDataManager.getPlayerData().values().forEach(value -> {
|
||||
this.rps.getFile().set("Bets", null);
|
||||
this.rps.getFile().createSection("Bets");
|
||||
if (value.getMoney() != -1L) {
|
||||
this.rps.getFile().set("Bets." + value.getName() + ".money", value.getMoney());
|
||||
this.rps.getFile().set("Bets." + value.getName() + ".rps", value.getWageRps().toString());
|
||||
} else {
|
||||
this.rps.getFile().set("Bets." + value.getName(), null);
|
||||
}
|
||||
});
|
||||
this.rps.saveFile();
|
||||
}, 100L, 20L);
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
this.playerDataManager.loadTo();
|
||||
this.playerDataManager.getPlayerData().values().forEach(value -> {
|
||||
if (value.getInventoryEnum() != InventoryEnum.NONE) {
|
||||
Bukkit.getPlayer(value.getName()).closeInventory();
|
||||
}
|
||||
if (value.getMoney() != -1L) {
|
||||
this.rps.getFile().set("Bets." + value.getName() + ".money", value.getMoney());
|
||||
this.rps.getFile().set("Bets." + value.getName() + ".rps", value.getWageRps().toString());
|
||||
} else {
|
||||
this.rps.getFile().set("Bets." + value.getName(), null);
|
||||
}
|
||||
});
|
||||
this.rps.saveFile();
|
||||
}
|
||||
|
||||
public CFG getOptions() {
|
||||
return this.options;
|
||||
}
|
||||
|
||||
public CFG getRps() {
|
||||
return this.rps;
|
||||
}
|
||||
|
||||
public CFG getMessages() {
|
||||
return this.messages;
|
||||
}
|
||||
|
||||
public WageManager getWageManager() {
|
||||
return this.wageManager;
|
||||
}
|
||||
|
||||
public PlayerDataManager getPlayerDataManager() {
|
||||
return this.playerDataManager;
|
||||
}
|
||||
|
||||
public CFG getPlayerBase() {
|
||||
return this.playerBase;
|
||||
}
|
||||
|
||||
public VaultAPI getVault() {
|
||||
return this.vault;
|
||||
}
|
||||
|
||||
public RpsUtilities getRpsUtilities() {
|
||||
return this.rpsUtilities;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package net.crankedpvp.rps.commands;
|
||||
import net.crankedpvp.rps.RPSPlugin;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class RPSCommand implements CommandExecutor {
|
||||
private final RPSPlugin core;
|
||||
|
||||
public RPSCommand(RPSPlugin core) {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender cs, Command cmd, String lb, String[] args) {
|
||||
if (args.length == 0) {
|
||||
this.core.getRpsUtilities().openRps(cs);
|
||||
return true;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
this.core.getRpsUtilities().reloadFiles(cs);
|
||||
} else if (args[0].equalsIgnoreCase("cancel")) {
|
||||
this.core.getRpsUtilities().cancel(cs);
|
||||
} else if (args[0].equalsIgnoreCase("stats")) {
|
||||
this.core.getRpsUtilities().sendStats(cs, null);
|
||||
} else if (args[0].equalsIgnoreCase("toggle")) {
|
||||
this.core.getRpsUtilities().toggleNot(cs);
|
||||
} else {
|
||||
this.core.getRpsUtilities().sendHelp(cs);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("stats")) {
|
||||
this.core.getRpsUtilities().sendStats(cs, args[1]);
|
||||
} else if (args[0].equalsIgnoreCase("rig")) {
|
||||
this.core.getRpsUtilities().rig(cs, args[1]);
|
||||
} else if (args[0].equalsIgnoreCase("top")) {
|
||||
this.core.getRpsUtilities().topStats(cs, args[1]);
|
||||
} else {
|
||||
this.core.getRpsUtilities().createRps(cs, args[0], args[1]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
// =============================================== //
|
||||
// Recompile disabled. Please run Recaf with a JDK //
|
||||
// =============================================== //
|
||||
|
||||
// Decompiled with: CFR 0.152
|
||||
// Class Version: 8
|
||||
package net.crankedpvp.rps.listeners;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import net.crankedpvp.rps.RPSPlugin;
|
||||
import net.crankedpvp.rps.players.PlayerData;
|
||||
import net.crankedpvp.rps.players.wages.InventoryEnum;
|
||||
import net.crankedpvp.rps.players.wages.RPS;
|
||||
import net.crankedpvp.rps.utilities.MessagesX;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ChooseEvents
|
||||
implements Listener {
|
||||
private final RPSPlugin core;
|
||||
public static HashMap<File, BufferedWriter> writers = new HashMap();
|
||||
|
||||
public ChooseEvents(RPSPlugin core) {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
public BufferedWriter getBufferedWriter(File f) {
|
||||
try {
|
||||
if (writers.containsKey(f)) {
|
||||
return writers.get(f);
|
||||
}
|
||||
BufferedWriter returns = new BufferedWriter(new FileWriter(f, true));
|
||||
writers.put(f, returns);
|
||||
return returns;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void logToFile(File f, String message) {
|
||||
try {
|
||||
if (!f.exists()) {
|
||||
f.getParentFile().mkdirs();
|
||||
f.createNewFile();
|
||||
}
|
||||
BufferedWriter br = this.getBufferedWriter(f);
|
||||
br.write(message);
|
||||
br.flush();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void onClick(InventoryClickEvent e) {
|
||||
if (!(e.getWhoClicked() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) e.getWhoClicked();
|
||||
PlayerData data = this.core.getPlayerDataManager().getData(player);
|
||||
Inventory inv = e.getInventory();
|
||||
if (data.getInventoryEnum() != InventoryEnum.RPS_CHOOSE_GUI || !inv.equals(data.getInventory())) {
|
||||
return;
|
||||
}
|
||||
e.setCancelled(true);
|
||||
switch (e.getRawSlot()) {
|
||||
case 2: {
|
||||
data.setChooseRps(RPS.ROCK);
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
data.setChooseRps(RPS.PAPER);
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
data.setChooseRps(RPS.SCISSORS);
|
||||
}
|
||||
}
|
||||
if (data.getChooseRps() == null) {
|
||||
return;
|
||||
}
|
||||
PlayerData other = data.getChoosePlayer();
|
||||
PlayerData winner = this.core.getWageManager().getWinner(other, data);
|
||||
HashMap<String, String> map = Maps.newHashMap();
|
||||
other.setWageRps(null);
|
||||
data.setChooseRps(null);
|
||||
double worth = other.getMoney();
|
||||
map.put("%money%", NumberFormat.getNumberInstance(Locale.US).format(worth * 2.0));
|
||||
other.setMoney(-1L);
|
||||
data.setChoosePlayer(null);
|
||||
player.closeInventory();
|
||||
this.core.getPlayerDataManager().update();
|
||||
Set<Player> stream = this.core.getPlayerDataManager().getPlayerData().values().stream().filter(streamData -> streamData.isSendMessage() && streamData.getPlayer().isOnline()).map(streamData -> streamData.getPlayer().getPlayer()).collect(Collectors.toSet());
|
||||
if (winner == null) {
|
||||
this.core.getVault().getEconomy().depositPlayer(other.getPlayer(), worth);
|
||||
map.put("%player_one%", player.getName());
|
||||
map.put("%player_two%", other.getName());
|
||||
stream.forEach(streamPlayer -> MessagesX.NO_WINNER.msg(streamPlayer, map, false));
|
||||
return;
|
||||
}
|
||||
if (winner == other) {
|
||||
other.addWin();
|
||||
data.addLose();
|
||||
this.core.getVault().getEconomy().depositPlayer(other.getPlayer(), worth * 2.0);
|
||||
this.core.getVault().getEconomy().withdrawPlayer(data.getPlayer(), worth);
|
||||
map.put("%winner%", winner.getName());
|
||||
map.put("%loser%", data.getName());
|
||||
} else {
|
||||
data.addWin();
|
||||
other.addLose();
|
||||
this.core.getVault().getEconomy().depositPlayer(data.getPlayer(), worth);
|
||||
map.put("%winner%", data.getName());
|
||||
map.put("%loser%", other.getName());
|
||||
}
|
||||
stream.forEach(streamPlayer -> MessagesX.WINNER.msg(streamPlayer, map, false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package net.crankedpvp.rps.listeners;
|
||||
|
||||
import net.crankedpvp.rps.RPSPlugin;
|
||||
import net.crankedpvp.rps.players.PlayerData;
|
||||
import net.crankedpvp.rps.players.wages.InventoryEnum;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
|
||||
public class InventoryCloseListener implements Listener {
|
||||
private final RPSPlugin core;
|
||||
|
||||
public InventoryCloseListener(RPSPlugin core) {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void onClose(InventoryCloseEvent e) {
|
||||
if (!(e.getPlayer() instanceof Player))
|
||||
return;
|
||||
Player player = (Player)e.getPlayer();
|
||||
PlayerData data = this.core.getPlayerDataManager().getData(player);
|
||||
if (data.getInventory() != null) {
|
||||
data.setInventoryEnum(InventoryEnum.NONE);
|
||||
data.setInventory(null);
|
||||
data.setChoosePlayer(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package net.crankedpvp.rps.listeners;
|
||||
|
||||
import net.crankedpvp.rps.RPSPlugin;
|
||||
import net.crankedpvp.rps.players.PlayerData;
|
||||
import net.crankedpvp.rps.players.wages.InventoryEnum;
|
||||
import net.crankedpvp.rps.utilities.ItemBuilder;
|
||||
import net.crankedpvp.rps.utilities.NBTEditor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class RPSEvents implements Listener {
|
||||
private final RPSPlugin core;
|
||||
|
||||
private final Inventory inv;
|
||||
|
||||
public RPSEvents(RPSPlugin core) {
|
||||
this.core = core;
|
||||
this.inv = Bukkit.createInventory(null, 9, "Rock, Paper or Scissors...");
|
||||
this.inv.setItem(2, (new ItemBuilder(Material.COBBLESTONE)).setName("&a&lRock")
|
||||
.addLoreLine("&7Click to choose this type.").toItemStack());
|
||||
this.inv.setItem(4, (new ItemBuilder(Material.PAPER)).setName("&c&lPaper").addLoreLine("&7Click to choose this type.")
|
||||
.toItemStack());
|
||||
this.inv.setItem(6, (new ItemBuilder(Material.SHEARS)).setName("&6&lScissors")
|
||||
.addLoreLine("&7Click to choose this type.").toItemStack());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void onClick(InventoryClickEvent e) {
|
||||
if (!(e.getWhoClicked() instanceof Player))
|
||||
return;
|
||||
Player viewer = (Player)e.getWhoClicked();
|
||||
PlayerData viewerData = this.core.getPlayerDataManager().getData(viewer);
|
||||
Inventory inv = e.getInventory();
|
||||
if (viewerData.getInventoryEnum() != InventoryEnum.RPS_GUI || !inv.equals(viewerData.getInventory()))
|
||||
return;
|
||||
e.setCancelled(true);
|
||||
ItemStack item = e.getCurrentItem();
|
||||
if (item == null || item.getType() == Material.AIR)
|
||||
return;
|
||||
Object obj = NBTEditor.getItemTag(item, "wager");
|
||||
if (!(obj instanceof String))
|
||||
return;
|
||||
String wagerName = obj.toString();
|
||||
PlayerData wagerData = this.core.getPlayerDataManager().getData(wagerName);
|
||||
if (wagerName.equalsIgnoreCase(viewer.getName()))
|
||||
return;
|
||||
if (wagerData.getMoney() == -1L) {
|
||||
this.core.getRpsUtilities().openRps(viewer);
|
||||
return;
|
||||
}
|
||||
if (this.core.getPlayerDataManager().getBalance(viewer) < wagerData.getMoney())
|
||||
return;
|
||||
openChoose(viewer, wagerData);
|
||||
}
|
||||
|
||||
private void openChoose(Player player, PlayerData wagerData) {
|
||||
player.openInventory(this.inv);
|
||||
PlayerData data = this.core.getPlayerDataManager().getData(player);
|
||||
data.setInventory(this.inv);
|
||||
data.setChoosePlayer(wagerData);
|
||||
data.setInventoryEnum(InventoryEnum.RPS_CHOOSE_GUI);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package net.crankedpvp.rps.listeners;
|
||||
|
||||
import net.crankedpvp.rps.RPSPlugin;
|
||||
import net.crankedpvp.rps.players.PlayerData;
|
||||
import net.crankedpvp.rps.players.wages.InventoryEnum;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public class TopGuiListener implements Listener {
|
||||
private final RPSPlugin core;
|
||||
|
||||
public TopGuiListener(RPSPlugin core) {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void onClick(InventoryClickEvent e) {
|
||||
if (!(e.getWhoClicked() instanceof Player))
|
||||
return;
|
||||
Player player = (Player)e.getWhoClicked();
|
||||
PlayerData data = this.core.getPlayerDataManager().getData(player);
|
||||
Inventory inv = e.getInventory();
|
||||
if (data.getInventoryEnum() != InventoryEnum.TOP_STATS_GUI || !inv.equals(data.getInventory()))
|
||||
return;
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
// =============================================== //
|
||||
// Recompile disabled. Please run Recaf with a JDK //
|
||||
// =============================================== //
|
||||
|
||||
// Decompiled with: CFR 0.152
|
||||
// Class Version: 8
|
||||
package net.crankedpvp.rps.players;
|
||||
|
||||
import net.crankedpvp.rps.RPSPlugin;
|
||||
import net.crankedpvp.rps.players.wages.InventoryEnum;
|
||||
import net.crankedpvp.rps.players.wages.RPS;
|
||||
import net.crankedpvp.rps.utilities.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerData {
|
||||
private int wins;
|
||||
private int losses;
|
||||
private final String name;
|
||||
private Inventory inventory;
|
||||
private RPS wageRps = null;
|
||||
private RPS chooseRps = null;
|
||||
private long money = -1L;
|
||||
private PlayerData choosePlayer = null;
|
||||
private InventoryEnum inventoryEnum = InventoryEnum.NONE;
|
||||
private boolean sendMessage = true;
|
||||
private final UUID uuid;
|
||||
private boolean rig = false;
|
||||
private OfflinePlayer offPlayer;
|
||||
|
||||
public PlayerData(RPSPlugin core, String name, UUID uuid) {
|
||||
this.name = name;
|
||||
this.uuid = uuid;
|
||||
FileConfiguration file = core.getPlayerBase().getFile();
|
||||
boolean change = false;
|
||||
if (!file.isSet("Players." + name + ".wins")) {
|
||||
file.set("Players." + name + ".wins", 0);
|
||||
change = true;
|
||||
}
|
||||
if (!file.isSet("Players." + name + ".losses")) {
|
||||
file.set("Players." + name + ".losses", 0);
|
||||
change = true;
|
||||
}
|
||||
if (change) {
|
||||
core.getPlayerBase().saveFile();
|
||||
}
|
||||
this.setWins(file.getInt("Players." + name + ".wins"));
|
||||
this.setLosses(file.getInt("Players." + name + ".losses"));
|
||||
}
|
||||
|
||||
public int getLosses() {
|
||||
return this.losses;
|
||||
}
|
||||
|
||||
public int getWins() {
|
||||
return this.wins;
|
||||
}
|
||||
|
||||
public double getRatio() {
|
||||
if (this.wins > this.losses) {
|
||||
return this.losses == 0 ? (double)this.wins : Utils.round((double)this.wins / (double)this.losses, 2);
|
||||
}
|
||||
if (this.wins < this.losses) {
|
||||
return -(this.wins == 0 ? (double)this.losses : Utils.round((double)this.losses / (double)this.wins, 2));
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
public void setWins(int wins) {
|
||||
this.wins = wins;
|
||||
}
|
||||
|
||||
public void setLosses(int losses) {
|
||||
this.losses = losses;
|
||||
}
|
||||
|
||||
public void addWin() {
|
||||
this.setWins(this.wins + 1);
|
||||
}
|
||||
|
||||
public void addLose() {
|
||||
this.setLosses(this.losses + 1);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Inventory getInventory() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
public void setInventory(Inventory inventory) {
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
public OfflinePlayer getPlayer() {
|
||||
return this.offPlayer == null ? (this.offPlayer = Bukkit.getOfflinePlayer(this.uuid)) : this.offPlayer;
|
||||
}
|
||||
|
||||
public long getMoney() {
|
||||
return this.money;
|
||||
}
|
||||
|
||||
public void setMoney(long money) {
|
||||
this.money = money;
|
||||
}
|
||||
|
||||
public boolean isRig() {
|
||||
return this.rig;
|
||||
}
|
||||
|
||||
public void setRig(boolean rig) {
|
||||
this.rig = rig;
|
||||
}
|
||||
|
||||
public RPS getChooseRps() {
|
||||
return this.chooseRps;
|
||||
}
|
||||
|
||||
public void setChooseRps(RPS chooseRps) {
|
||||
this.chooseRps = chooseRps;
|
||||
}
|
||||
|
||||
public RPS getWageRps() {
|
||||
return this.wageRps;
|
||||
}
|
||||
|
||||
public void setWageRps(RPS wageRps) {
|
||||
this.wageRps = wageRps;
|
||||
}
|
||||
|
||||
public PlayerData getChoosePlayer() {
|
||||
return this.choosePlayer;
|
||||
}
|
||||
|
||||
public void setChoosePlayer(PlayerData choosePlayer) {
|
||||
if (choosePlayer == this) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
this.choosePlayer = choosePlayer;
|
||||
}
|
||||
|
||||
public boolean isSendMessage() {
|
||||
return this.sendMessage;
|
||||
}
|
||||
|
||||
public void setSendMessage(boolean sendMessage) {
|
||||
this.sendMessage = sendMessage;
|
||||
}
|
||||
|
||||
public InventoryEnum getInventoryEnum() {
|
||||
return this.inventoryEnum;
|
||||
}
|
||||
|
||||
public void setInventoryEnum(InventoryEnum inventoryEnum) {
|
||||
this.inventoryEnum = inventoryEnum;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
// =============================================== //
|
||||
// Recompile disabled. Please run Recaf with a JDK //
|
||||
// =============================================== //
|
||||
|
||||
// Decompiled with: CFR 0.152
|
||||
// Class Version: 8
|
||||
package net.crankedpvp.rps.players;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import net.crankedpvp.rps.RPSPlugin;
|
||||
import net.crankedpvp.rps.players.wages.InventoryEnum;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class PlayerDataManager implements Listener {
|
||||
private final Map<String, PlayerData> map = Maps.newHashMap();
|
||||
private final RPSPlugin core;
|
||||
|
||||
public Map<String, PlayerData> getPlayerData() {
|
||||
return this.map;
|
||||
}
|
||||
|
||||
public PlayerDataManager(RPSPlugin core) {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
public PlayerData getData(Player target) {
|
||||
return this.getData(target.getName());
|
||||
}
|
||||
|
||||
public PlayerData getData(String name) {
|
||||
if (!this.map.containsKey(name)) {
|
||||
try {
|
||||
return this.loadPlayer(name, Bukkit.getOfflinePlayer(name).getUniqueId());
|
||||
} catch (NullPointerException ignored) {
|
||||
this.core.getLogger().log(Level.WARNING, "Player: " + name + " was unable to be loaded into memory");
|
||||
}
|
||||
throw new RuntimeException("The player: " + name + " is not registered in memory.");
|
||||
}
|
||||
return this.map.get(name);
|
||||
}
|
||||
|
||||
public PlayerData loadPlayer(String name, UUID uuid) {
|
||||
if (this.isRegistered(name)) {
|
||||
return this.map.get(name);
|
||||
}
|
||||
PlayerData data = new PlayerData(this.core, name, uuid);
|
||||
this.map.put(name, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
public void purge(String name) {
|
||||
this.map.remove(name);
|
||||
}
|
||||
|
||||
public Optional<PlayerData> getDataIgnoreCase(String key) {
|
||||
return this.map.entrySet().stream().filter(entry -> entry.getKey().equalsIgnoreCase(key)).findAny().map(Map.Entry::getValue);
|
||||
}
|
||||
|
||||
public boolean isRegistered(String name) {
|
||||
return name != null && this.map.containsKey(name);
|
||||
}
|
||||
|
||||
public double getBalance(OfflinePlayer player) {
|
||||
return this.core.getVault().getEconomy().getBalance(player);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
Bukkit.getOnlinePlayers().forEach(this::update);
|
||||
}
|
||||
|
||||
public void update(Player target) {
|
||||
PlayerData data = this.getData(target);
|
||||
InventoryEnum invEnum = data.getInventoryEnum();
|
||||
if (invEnum == InventoryEnum.NONE || invEnum == InventoryEnum.TOP_STATS_GUI) {
|
||||
return;
|
||||
}
|
||||
if (invEnum == InventoryEnum.RPS_GUI) {
|
||||
this.core.getRpsUtilities().openRps(target);
|
||||
return;
|
||||
}
|
||||
if (data.getChoosePlayer() == null || data.getChoosePlayer().getMoney() == -1L) {
|
||||
this.core.getRpsUtilities().openRps(target);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadTo() {
|
||||
FileConfiguration playerBase = this.core.getPlayerBase().getFile();
|
||||
this.map.forEach((key, data) -> {
|
||||
playerBase.set("Players." + key + ".wins", data.getWins());
|
||||
playerBase.set("Players." + key + ".losses", data.getLosses());
|
||||
playerBase.set("Players." + key + ".uuid", data.getPlayer().getUniqueId().toString());
|
||||
});
|
||||
this.core.getPlayerBase().saveFile();
|
||||
}
|
||||
|
||||
public void loadFrom() {
|
||||
FileConfiguration playerBase = this.core.getPlayerBase().getFile();
|
||||
this.core.getPlayerBase().getFile().getConfigurationSection("Players").getKeys(false).forEach(name -> {
|
||||
if (!playerBase.isSet("Players." + name + ".uuid")) {
|
||||
playerBase.set("Players." + name, null);
|
||||
this.core.getPlayerBase().saveFile();
|
||||
return;
|
||||
}
|
||||
UUID uuid = UUID.fromString(playerBase.getString("Players." + name + ".uuid"));
|
||||
PlayerData data = this.loadPlayer(name, uuid);
|
||||
int wins = playerBase.getInt("Players." + name + ".wins");
|
||||
int losses = playerBase.getInt("Players." + name + ".losses");
|
||||
data.setWins(wins);
|
||||
data.setLosses(losses);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void onJoin(PlayerJoinEvent e) {
|
||||
this.loadPlayer(e.getPlayer().getName(), e.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package net.crankedpvp.rps.players.wages;
|
||||
|
||||
public enum InventoryEnum {
|
||||
RPS_GUI, RPS_CHOOSE_GUI, TOP_STATS_GUI, NONE;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package net.crankedpvp.rps.players.wages;
|
||||
|
||||
public enum RPS {
|
||||
ROCK, PAPER, SCISSORS;
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
// =============================================== //
|
||||
// Recompile disabled. Please run Recaf with a JDK //
|
||||
// =============================================== //
|
||||
|
||||
// Decompiled with: CFR 0.152
|
||||
// Class Version: 8
|
||||
package net.crankedpvp.rps.players.wages;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.crankedpvp.rps.RPSPlugin;
|
||||
import net.crankedpvp.rps.players.PlayerData;
|
||||
import net.crankedpvp.rps.utilities.MessagesX;
|
||||
import net.crankedpvp.rps.utilities.NBTEditor;
|
||||
import net.crankedpvp.rps.utilities.Utils;
|
||||
import net.minecraft.server.v1_8_R3.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class WageManager {
|
||||
private final RPSPlugin core;
|
||||
|
||||
public WageManager(RPSPlugin core) {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
public PlayerData getWinner(PlayerData data, PlayerData accept) {
|
||||
RPS wager = data.getWageRps();
|
||||
RPS accepter = accept.getChooseRps();
|
||||
if (data.isRig() && accept.isRig()) {
|
||||
return null;
|
||||
}
|
||||
if (data.isRig()) {
|
||||
return data;
|
||||
}
|
||||
if (accept.isRig()) {
|
||||
return accept;
|
||||
}
|
||||
if (wager == null || accepter == null) {
|
||||
return null;
|
||||
}
|
||||
if (accepter == wager) {
|
||||
return null;
|
||||
}
|
||||
switch (wager) {
|
||||
case PAPER: {
|
||||
return accepter == RPS.ROCK ? data : accept;
|
||||
}
|
||||
case ROCK: {
|
||||
return accepter == RPS.PAPER ? accept : data;
|
||||
}
|
||||
case SCISSORS: {
|
||||
return accepter == RPS.ROCK ? accept : data;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<PlayerData> getTopWagers(boolean wins) {
|
||||
Map<String, PlayerData> playerDataMap = this.core.getPlayerDataManager().getPlayerData();
|
||||
Map<String, PlayerData> sorted = wins ? this.sortByWins(playerDataMap) : this.sortByLosses(playerDataMap);
|
||||
return sorted.entrySet().stream().limit(9L).map(Map.Entry::getValue).collect(Collectors.toCollection(LinkedList::new));
|
||||
}
|
||||
|
||||
public static void ensureSkullTextures(Inventory inv, int slot) {
|
||||
IInventory iinv = ((CraftInventory) inv).getInventory();
|
||||
net.minecraft.server.v1_8_R3.ItemStack item = iinv.getItem(slot);
|
||||
NBTTagCompound tag = item.getTag();
|
||||
NBTTagCompound skullOwner = (NBTTagCompound)tag.get("SkullOwner");
|
||||
if (skullOwner == null) {
|
||||
throw new IllegalArgumentException("No SkullOwner NBT tag");
|
||||
}
|
||||
GameProfile profile = GameProfileSerializer.deserialize(skullOwner);
|
||||
if (!profile.getProperties().containsKey("textures")) {
|
||||
TileEntitySkull.b(profile, input -> {
|
||||
NBTTagCompound owner = new NBTTagCompound();
|
||||
GameProfileSerializer.serialize(owner, input);
|
||||
tag.set("SkullOwner", owner);
|
||||
WageManager.updateSlot(inv, slot, item);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateSlot(Inventory inventory, int slot, net.minecraft.server.v1_8_R3.ItemStack item) {
|
||||
for (HumanEntity viewer : inventory.getViewers()) {
|
||||
Player player = (Player) viewer;
|
||||
EntityPlayer ep = ((CraftPlayer) player).getHandle();
|
||||
ep.a(ep.activeContainer, slot, item);
|
||||
}
|
||||
}
|
||||
|
||||
public Set<ItemStack> getWagers(boolean operator, Player viewer) {
|
||||
LinkedHashSet<ItemStack> skulls = Sets.newLinkedHashSet();
|
||||
FileConfiguration options = this.core.getOptions().getFile();
|
||||
FPlayer fviewer = FPlayers.getInstance().getByPlayer(viewer);
|
||||
|
||||
Stream<Map.Entry<String, PlayerData>> playerDataStream = this.core.getPlayerDataManager().getPlayerData().entrySet().stream()
|
||||
.filter(data -> (data.getValue().getMoney() != -1L));
|
||||
this.sortByLongValue(playerDataStream.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))).limit(26L).forEachOrdered(wager -> {
|
||||
ItemStack item = NBTEditor.setItemTag(new ItemStack(Material.SKULL_ITEM, 1, (short) 3), wager.getKey(), "wager");
|
||||
SkullMeta meta = (SkullMeta)item.getItemMeta();
|
||||
HashMap<String, String> map = Maps.newHashMap();
|
||||
if (operator || viewer.getName().equals(wager.getKey())) {
|
||||
map.put("%rps%", StringUtils.capitalize(wager.getValue().getWageRps().name()));
|
||||
}
|
||||
FPlayer fwager = FPlayers.getInstance().getByOfflinePlayer(wager.getValue().getPlayer());
|
||||
double balance = this.core.getVault().getEconomy().getBalance(viewer);
|
||||
map.put("%enterable%", Utils.colorize(wager.getKey().equals(viewer.getName()) ? MessagesX.SELF_WAGER.getMessages()[0] : (balance >= (double) wager.getValue().getMoney() ? MessagesX.AFFORDABLE.getMessages()[0] : MessagesX.UNAFFORDABLE.getMessages()[0])));
|
||||
map.put("%name%", wager.getKey());
|
||||
map.put("%faction%", fwager.getFaction().getTag());
|
||||
map.put("%relation_color%", fviewer.getRelationTo(fwager).getColor().toString());
|
||||
map.put("%money%", NumberFormat.getNumberInstance(Locale.US).format(wager.getValue().getMoney()));
|
||||
map.put("%ratio%", String.valueOf(wager.getValue().getWins() == 0 && wager.getValue().getLosses() == 0 ? 0.0 : wager.getValue().getRatio()));
|
||||
map.put("%wins%", String.valueOf(wager.getValue().getWins()));
|
||||
map.put("%losses%", String.valueOf(wager.getValue().getLosses()));
|
||||
meta.setOwner(wager.getKey());
|
||||
meta.setDisplayName(Utils.placeHolder(Utils.colorize(options.getString(operator || viewer.getName().equals(wager.getKey()) ? "Heads.operator.name" : "Heads.normal.name")), map, false));
|
||||
meta.setLore(Utils.placeHolder(Utils.colorize(options.getStringList(operator || viewer.getName().equals(wager.getKey()) ? "Heads.operator.lore" : "Heads.normal.lore")), map, false));
|
||||
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
item.setItemMeta(meta);
|
||||
skulls.add(item);
|
||||
});
|
||||
return skulls;
|
||||
}
|
||||
|
||||
public Stream<Map.Entry<String, PlayerData>> sortByLongValue(Map<String, PlayerData> input) {
|
||||
return input.entrySet()
|
||||
.stream()
|
||||
.sorted(Map.Entry.comparingByValue(Comparator.comparingLong(this::getLongValue).reversed()));
|
||||
}
|
||||
|
||||
public Map<String, PlayerData> sortByWins(Map<String, PlayerData> input) {
|
||||
return input.entrySet()
|
||||
.stream()
|
||||
.sorted(Map.Entry.comparingByValue(Comparator.comparingLong(this::getWinsValue).reversed()))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
|
||||
}
|
||||
|
||||
private long getWinsValue(PlayerData playerData) {
|
||||
return playerData.getWins();
|
||||
}
|
||||
|
||||
private long getLossesValue(PlayerData playerData) {
|
||||
return playerData.getLosses();
|
||||
}
|
||||
|
||||
public Map<String, PlayerData> sortByLosses(Map<String, PlayerData> input) {
|
||||
return input.entrySet()
|
||||
.stream()
|
||||
.sorted(Map.Entry.comparingByValue(Comparator.comparingLong(this::getLossesValue).reversed()))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
|
||||
}
|
||||
|
||||
private long getLongValue(PlayerData playerData) {
|
||||
String name = playerData.getName();
|
||||
return this.core.getRps().getFile().getLong("Bets." + name + ".time");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,296 @@
|
||||
// =============================================== //
|
||||
// Recompile disabled. Please run Recaf with a JDK //
|
||||
// =============================================== //
|
||||
|
||||
// Decompiled with: CFR 0.152
|
||||
// Class Version: 8
|
||||
package net.crankedpvp.rps.rpsutilities;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import net.crankedpvp.rps.RPSPlugin;
|
||||
import net.crankedpvp.rps.players.PlayerData;
|
||||
import net.crankedpvp.rps.players.wages.InventoryEnum;
|
||||
import net.crankedpvp.rps.players.wages.RPS;
|
||||
import net.crankedpvp.rps.players.wages.WageManager;
|
||||
import net.crankedpvp.rps.utilities.ItemBuilder;
|
||||
import net.crankedpvp.rps.utilities.MessagesX;
|
||||
import net.crankedpvp.rps.utilities.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class RpsUtilities {
|
||||
private final RPSPlugin core;
|
||||
|
||||
public RpsUtilities(RPSPlugin core) {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
public void openRps(CommandSender cs) {
|
||||
if (!(cs instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player)cs;
|
||||
Set<ItemStack> heads = this.core.getWageManager().getWagers(player.isOp(), player);
|
||||
Inventory inv = Bukkit.createInventory(null, 27, Utils.colorize(this.core.getOptions().getFile().getString("Inventory.name").replace("%amount%", String.valueOf(heads.size()))));
|
||||
ItemStack[] stacks = heads.toArray(new ItemStack[0]);
|
||||
int i = 0;
|
||||
while (i < stacks.length) {
|
||||
inv.setItem(i, stacks[i]);
|
||||
WageManager.ensureSkullTextures(inv, i);
|
||||
++i;
|
||||
}
|
||||
FileConfiguration file = this.core.getOptions().getFile();
|
||||
ItemStack book = new ItemBuilder(Material.BOOK).setName(file.getString("Inventory.items.book.name")).setLore(file.getStringList("Inventory.items.book.lore")).toItemStack();
|
||||
inv.setItem(26, book);
|
||||
player.openInventory(inv);
|
||||
PlayerData data = this.core.getPlayerDataManager().getData(player);
|
||||
data.setInventory(inv);
|
||||
data.setInventoryEnum(InventoryEnum.RPS_GUI);
|
||||
player.updateInventory();
|
||||
}
|
||||
|
||||
public void topStats(CommandSender cs, String input) {
|
||||
boolean wins;
|
||||
if (!(cs instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player)cs;
|
||||
if (input.equalsIgnoreCase("wins")) {
|
||||
wins = true;
|
||||
} else if (input.equalsIgnoreCase("losses")) {
|
||||
wins = false;
|
||||
} else {
|
||||
this.sendHelp(cs);
|
||||
return;
|
||||
}
|
||||
List<PlayerData> datas = this.core.getWageManager().getTopWagers(wins);
|
||||
FPlayer fviewer = FPlayers.getInstance().getByPlayer(player);
|
||||
FileConfiguration options = this.core.getOptions().getFile();
|
||||
Inventory inv = Bukkit.createInventory(null, 27, Utils.colorize(options.getString(wins ? "Top-Players.Wins.name" : "Top-Players.Losses.name")));
|
||||
int i = 0;
|
||||
while (i < datas.size()) {
|
||||
PlayerData data = datas.get(i);
|
||||
ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
|
||||
SkullMeta meta = (SkullMeta)item.getItemMeta();
|
||||
HashMap<String, String> map = Maps.newHashMap();
|
||||
FPlayer fwager = FPlayers.getInstance().getByOfflinePlayer(data.getPlayer());
|
||||
map.put("%rank%", String.valueOf(i + 1));
|
||||
map.put("%name%", data.getName());
|
||||
map.put("%faction%", fwager.getFaction().getTag());
|
||||
map.put("%relation_color%", fviewer.getRelationTo(fwager).getColor().toString());
|
||||
map.put("%ratio%", String.valueOf(data.getWins() == 0 && data.getLosses() == 0 ? 0.0 : data.getRatio()));
|
||||
map.put("%wins%", String.valueOf(data.getWins()));
|
||||
map.put("%losses%", String.valueOf(data.getLosses()));
|
||||
meta.setOwner(data.getName());
|
||||
meta.setDisplayName(Utils.placeHolder(Utils.colorize(options.getString("Top-Players.Wins.items.name")), map, false));
|
||||
meta.setLore(Utils.placeHolder(Utils.colorize(options.getStringList(wins ? "Top-Players.Wins.items.lore" : "Top-Players.Losses.items.lore")), map, false));
|
||||
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
item.setItemMeta(meta);
|
||||
inv.setItem(i + 9, item);
|
||||
++i;
|
||||
}
|
||||
ItemStack item = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
meta.setDisplayName(Utils.colorize("&c"));
|
||||
item.setItemMeta(meta);
|
||||
int i2 = 0;
|
||||
while (i2 < 27) {
|
||||
if (inv.getItem(i2) == null) {
|
||||
inv.setItem(i2, item);
|
||||
}
|
||||
++i2;
|
||||
}
|
||||
player.openInventory(inv);
|
||||
PlayerData pdata = this.core.getPlayerDataManager().getData(player);
|
||||
pdata.setInventoryEnum(InventoryEnum.TOP_STATS_GUI);
|
||||
pdata.setInventory(inv);
|
||||
}
|
||||
|
||||
public void toggleNot(CommandSender cs) {
|
||||
if (!(cs instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player)cs;
|
||||
PlayerData data = this.core.getPlayerDataManager().getData(player);
|
||||
if (data.isSendMessage()) {
|
||||
data.setSendMessage(false);
|
||||
MessagesX.NOT_TOGGLE_OFF.msg(player);
|
||||
} else {
|
||||
data.setSendMessage(true);
|
||||
MessagesX.NOT_TOGGLE_ON.msg(player);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendHelp(CommandSender cs) {
|
||||
MessagesX.HELP_FORMAT.msg(cs);
|
||||
}
|
||||
|
||||
public void rig(CommandSender cs, String string) {
|
||||
if (!cs.hasPermission("rps.rig")) {
|
||||
MessagesX.NO_PERMISSION.msg(cs);
|
||||
return;
|
||||
}
|
||||
HashMap<String, String> map = Maps.newHashMap();
|
||||
Optional<PlayerData> opt = this.core.getPlayerDataManager().getDataIgnoreCase(string);
|
||||
if (!opt.isPresent()) {
|
||||
map.put("%name%", string);
|
||||
MessagesX.USER_NOT_FOUND.msg(cs, map, false);
|
||||
return;
|
||||
}
|
||||
PlayerData data = opt.get();
|
||||
map.put("%user%", data.getName());
|
||||
if (data.isRig()) {
|
||||
data.setRig(false);
|
||||
MessagesX.RIGLESS.msg(cs, map, false);
|
||||
} else {
|
||||
data.setRig(true);
|
||||
MessagesX.RIG.msg(cs, map, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void cancel(CommandSender cs) {
|
||||
if (!(cs instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player)cs;
|
||||
PlayerData data = this.core.getPlayerDataManager().getPlayerData().get(player.getName());
|
||||
if (data.getMoney() == -1L) {
|
||||
MessagesX.CANCEL_FAIL.msg(player);
|
||||
return;
|
||||
}
|
||||
this.core.getVault().getEconomy().depositPlayer(player, data.getMoney());
|
||||
data.setMoney(-1L);
|
||||
this.core.getPlayerDataManager().update();
|
||||
MessagesX.CANCEL_SUCCESSFUL.msg(player);
|
||||
}
|
||||
|
||||
public void createRps(CommandSender cs, String inputMoney, String inputRps) {
|
||||
if (!(cs instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player)cs;
|
||||
|
||||
if (!Utils.isLong(inputMoney)) {
|
||||
MessagesX.HELP_FORMAT.msg(player);
|
||||
return;
|
||||
}
|
||||
long money = Long.parseLong(inputMoney);
|
||||
PlayerData data = this.core.getPlayerDataManager().loadPlayer(player.getName(), player.getUniqueId());
|
||||
if (data.getMoney() != -1L) {
|
||||
MessagesX.ALREADY_WAGED.msg(player);
|
||||
return;
|
||||
}
|
||||
if (this.core.getPlayerDataManager().getPlayerData().values().stream().filter(datax -> datax.getMoney() != -1L).count() >= 26L) {
|
||||
MessagesX.WAGE_FULL.msg(player);
|
||||
return;
|
||||
}
|
||||
long small = this.core.getOptions().getFile().getLong("Prices.minimum");
|
||||
long maximum = this.core.getOptions().getFile().getLong("Prices.maximum");
|
||||
if (money < small) {
|
||||
MessagesX.AMOUNT_TOO_SMALL.msg(player);
|
||||
return;
|
||||
}
|
||||
if (money > maximum) {
|
||||
MessagesX.AMOUNT_TOO_BIG.msg(player);
|
||||
return;
|
||||
}
|
||||
if (this.core.getPlayerDataManager().getBalance(player) < (double)money) {
|
||||
MessagesX.INSUFFICIENT_FUNDS.msg(player);
|
||||
return;
|
||||
}
|
||||
switch (inputRps.toLowerCase()) {
|
||||
case "r":
|
||||
case "rock": {
|
||||
data.setWageRps(RPS.ROCK);
|
||||
break;
|
||||
}
|
||||
case "p":
|
||||
case "paper": {
|
||||
data.setWageRps(RPS.PAPER);
|
||||
break;
|
||||
}
|
||||
case "scissors":
|
||||
case "s": {
|
||||
data.setWageRps(RPS.SCISSORS);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
MessagesX.HELP_FORMAT.msg(player);
|
||||
return;
|
||||
}
|
||||
}
|
||||
data.setMoney(money);
|
||||
this.core.getVault().getEconomy().withdrawPlayer(player, money);
|
||||
this.core.getRps().getFile().set("Bets." + player.getName() + ".time", System.currentTimeMillis());
|
||||
this.core.getRps().saveFile();
|
||||
HashMap<String, String> map = Maps.newHashMap();
|
||||
map.put("%amount%", NumberFormat.getNumberInstance(Locale.US).format(money));
|
||||
MessagesX.WAGE_CREATE.msg(player, map, false);
|
||||
this.core.getPlayerDataManager().update();
|
||||
}
|
||||
|
||||
public void sendStats(CommandSender cs, String input) {
|
||||
PlayerData data;
|
||||
HashMap<String, String> map = Maps.newHashMap();
|
||||
if (input == null) {
|
||||
if (!(cs instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
data = this.core.getPlayerDataManager().getPlayerData().get(cs.getName());
|
||||
} else {
|
||||
Optional<PlayerData> opt = this.core.getPlayerDataManager().getDataIgnoreCase(input);
|
||||
if (!opt.isPresent()) {
|
||||
map.put("%name%", input);
|
||||
MessagesX.USER_NOT_FOUND.msg(cs, map, false);
|
||||
return;
|
||||
}
|
||||
data = opt.get();
|
||||
}
|
||||
String name = data.getName();
|
||||
double ratio = data.getRatio();
|
||||
int wins = data.getWins();
|
||||
int losses = data.getLosses();
|
||||
map.put("%player%", name);
|
||||
map.put("%ratio%", String.valueOf(ratio));
|
||||
map.put("%wins%", String.valueOf(wins));
|
||||
map.put("%losses%", String.valueOf(losses));
|
||||
MessagesX.STATS.msg(cs, map, false);
|
||||
}
|
||||
|
||||
public void reloadFiles(CommandSender cs) {
|
||||
if (!cs.hasPermission("rps.reload")) {
|
||||
MessagesX.NO_PERMISSION.msg(cs);
|
||||
return;
|
||||
}
|
||||
this.core.getOptions().reloadFile();
|
||||
this.core.getRps().reloadFile();
|
||||
this.core.getPlayerBase().reloadFile();
|
||||
this.core.getMessages().reloadFile();
|
||||
MessagesX.repairPaths(this.core.getMessages());
|
||||
MessagesX.RELOADED.msg(cs);
|
||||
this.core.getPlayerDataManager().loadFrom();
|
||||
this.core.getRps().getFile().getConfigurationSection("Bets").getKeys(false).forEach(name -> {
|
||||
RPS rps = RPS.valueOf(this.core.getRps().getFile().getString("Bets." + name + ".rps"));
|
||||
int money = this.core.getRps().getFile().getInt("Bets." + name + ".money");
|
||||
PlayerData data = this.core.getPlayerDataManager().getData(name);
|
||||
data.setMoney(money);
|
||||
data.setWageRps(rps);
|
||||
});
|
||||
this.core.getPlayerDataManager().update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package net.crankedpvp.rps.utilities;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class CFG {
|
||||
private final JavaPlugin p;
|
||||
|
||||
private final String filename;
|
||||
|
||||
private FileConfiguration file;
|
||||
|
||||
private File cfile;
|
||||
|
||||
private final boolean saveResource;
|
||||
|
||||
public CFG(JavaPlugin p, String string, boolean saveResource) {
|
||||
this.p = p;
|
||||
this.filename = String.valueOf(string) + ".yml";
|
||||
this.saveResource = saveResource;
|
||||
setup();
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
if (!this.p.getDataFolder().exists())
|
||||
this.p.getDataFolder().mkdir();
|
||||
this.cfile = new File(this.p.getDataFolder(), this.filename);
|
||||
if (!this.cfile.exists()) {
|
||||
try {
|
||||
this.cfile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (this.saveResource)
|
||||
this.p.saveResource(this.filename, true);
|
||||
}
|
||||
reloadFile();
|
||||
}
|
||||
|
||||
public void saveFile() {
|
||||
try {
|
||||
getFile().save(this.cfile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadFile() {
|
||||
this.file = (FileConfiguration)YamlConfiguration.loadConfiguration(this.cfile);
|
||||
}
|
||||
|
||||
public FileConfiguration getFile() {
|
||||
return this.file;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package net.crankedpvp.rps.utilities;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ItemBuilder {
|
||||
private ItemStack is;
|
||||
|
||||
public ItemBuilder(Material m) {
|
||||
this(m, 1);
|
||||
}
|
||||
|
||||
public ItemBuilder(ItemStack is) {
|
||||
this.is = is;
|
||||
}
|
||||
|
||||
public ItemBuilder(Material m, int amount) {
|
||||
this.is = new ItemStack(m, amount);
|
||||
}
|
||||
|
||||
public ItemBuilder(Material m, int amount, byte durability) {
|
||||
this.is = new ItemStack(m, amount, durability);
|
||||
}
|
||||
|
||||
public ItemBuilder clone() {
|
||||
return new ItemBuilder(this.is);
|
||||
}
|
||||
|
||||
public ItemBuilder setDurability(short dur) {
|
||||
this.is.setDurability(dur);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setName(String name) {
|
||||
ItemMeta im = this.is.getItemMeta();
|
||||
im.setDisplayName(Utils.colorize(name));
|
||||
this.is.setItemMeta(im);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder addUnsafeEnchantment(Enchantment ench, int level) {
|
||||
this.is.addUnsafeEnchantment(ench, level);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder removeEnchantment(Enchantment ench) {
|
||||
this.is.removeEnchantment(ench);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setSkullOwner(String owner) {
|
||||
if (!(this.is.getItemMeta() instanceof SkullMeta))
|
||||
throw new UnsupportedOperationException("Casting SkullMeta to the current ItemMeta is not possible!");
|
||||
SkullMeta im = (SkullMeta)this.is.getItemMeta();
|
||||
im.setOwner(owner);
|
||||
this.is.setItemMeta((ItemMeta)im);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder addEnchant(Enchantment ench, int level) {
|
||||
ItemMeta im = this.is.getItemMeta();
|
||||
im.addEnchant(ench, level, true);
|
||||
this.is.setItemMeta(im);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder addEnchantments(Map<Enchantment, Integer> enchantments) {
|
||||
this.is.addEnchantments(enchantments);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setLore(String... lore) {
|
||||
ItemMeta im = this.is.getItemMeta();
|
||||
im.setLore(Arrays.asList(lore));
|
||||
this.is.setItemMeta(im);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setLore(List<String> lore) {
|
||||
ItemMeta im = this.is.getItemMeta();
|
||||
im.setLore(Utils.colorize(lore));
|
||||
this.is.setItemMeta(im);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder addLoreLine(String line) {
|
||||
ItemMeta im = this.is.getItemMeta();
|
||||
List<String> lore = new ArrayList<>();
|
||||
if (im.hasLore())
|
||||
lore = new ArrayList<>(im.getLore());
|
||||
lore.add(Utils.colorize(line));
|
||||
im.setLore(lore);
|
||||
this.is.setItemMeta(im);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStack toItemStack() {
|
||||
return this.is;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
// =============================================== //
|
||||
// Recompile disabled. Please run Recaf with a JDK //
|
||||
// =============================================== //
|
||||
|
||||
// Decompiled with: CFR 0.152
|
||||
// Class Version: 8
|
||||
package net.crankedpvp.rps.utilities;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public enum MessagesX {
|
||||
NO_PERMISSION("Messages.No-Permission", "&cYou are not allowed to use this command."),
|
||||
PLAYER_OFFLINE("Messages.Player-Offline", "&c&l(!) &4%player%&c is not locally online."),
|
||||
RELOADED("Messages.Reloaded", "&a&l(!) &7Plugin has been reloaded!"),
|
||||
AFFORDABLE("Messages.Affordable", "&aYou can afford to enter this wager."),
|
||||
UNAFFORDABLE("Messages.Unaffordable", "&cYou cannot afford to enter this wager."),
|
||||
NO_WINNER("Messages.No-Win", "&6%player_one% &7went tie with &6%player_two% &7in an &e/rps &7game worth &n$%money%&7."),
|
||||
WINNER("Messages.Win", "&a%winner% &7has won against &c%loser% &7in an &e/rps &7game worth &n$%money%&7."),
|
||||
SELF_WAGER("Messages.Self-Wager", "&cYou cannot enter your own wager."),
|
||||
ALREADY_WAGED("Messages.Already-Wager", "&cYou already have a wage set."),
|
||||
WAGE_FULL("Messages.Wage-Full", "&cYou may not wage as the max capacity is reached!"),
|
||||
WAGE_CREATE("Messages.Wage-Create", "&7Created a wager with an amount of &e$%amount% &7"),
|
||||
AMOUNT_TOO_SMALL("Messages.Money-Too-Small", "&7The amount specified wasn't enough, the amount must be greater than 1."),
|
||||
AMOUNT_TOO_BIG("Messages.Money-Too-Big", "&7The amount specified wasn't enough, the amount must be smaller than 10.000."),
|
||||
USER_NOT_FOUND("MessagesX.User-Not-Found", "&cNo user found with the name: &e%name%"),
|
||||
CANCEL_FAIL("Messages.Cancel-Fail", "&cYou do not have a wage to cancel!"),
|
||||
RIG("Messages.Rig", "&aUser &e%user% &ais now rigged!"),
|
||||
RIGLESS("Messages.Rigless", "&cUser &e%user% &cis no longer rigged!"),
|
||||
INSUFFICIENT_FUNDS("Messages.Insufficient-Funds", "&cYou do not have enough money!"),
|
||||
CANCEL_SUCCESSFUL("Messages.Cancel-Successful", "&aYou have removed your wage."),
|
||||
NOT_TOGGLE_ON("Messages.Notification-On", "&aYou will now receive notification upon an rps match."),
|
||||
NOT_TOGGLE_OFF("Messages.Notification-Off", "&cYou will no longer receive notification upon an rps match."),
|
||||
STATS("MessagesX.Stats", "", "&e&l%player%'s RPS Stats", "&6- Ratio: %ratio%", "&6- Wins: %wins%", "&6- Losses: %losses%", ""),
|
||||
HELP_FORMAT("Messages.Help", "", "&e&l(!) &eRPS Commands:", " &8� &f/rps", " &8� &f/rps &7reload", " &8� &f/rps &7cancel", " &8� &f/rps &7<money> <r/p/s>", " &8� &f/rps &7toggle", " &8� &f/rps &7top <wins:losses>", "");
|
||||
|
||||
private String[] messages;
|
||||
private final String path;
|
||||
|
||||
MessagesX(String path, String... messages) {
|
||||
this.messages = messages;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
private boolean isMultiLined() {
|
||||
return this.messages.length > 1;
|
||||
}
|
||||
|
||||
public static void repairPaths(CFG cfg) {
|
||||
boolean changed = false;
|
||||
MessagesX[] messagesXArray = MessagesX.values();
|
||||
int n = messagesXArray.length;
|
||||
int n2 = 0;
|
||||
while (n2 < n) {
|
||||
MessagesX enumMessage = messagesXArray[n2];
|
||||
if (cfg.getFile().contains(enumMessage.getPath())) {
|
||||
MessagesX.setPathToMessage(cfg, enumMessage);
|
||||
} else {
|
||||
MessagesX.setMessageToPath(cfg, enumMessage);
|
||||
if (!changed) {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
++n2;
|
||||
}
|
||||
if (changed) {
|
||||
cfg.saveFile();
|
||||
}
|
||||
}
|
||||
|
||||
private static void setMessageToPath(CFG cfg, MessagesX enumMessage) {
|
||||
if (enumMessage.isMultiLined()) {
|
||||
cfg.getFile().set(enumMessage.getPath(), enumMessage.getMessages());
|
||||
} else {
|
||||
cfg.getFile().set(enumMessage.getPath(), enumMessage.getMessages()[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setPathToMessage(CFG cfg, MessagesX enumMessage) {
|
||||
if (Utils.isList(cfg.getFile(), enumMessage.getPath())) {
|
||||
enumMessage.setMessages(cfg.getFile().getStringList(enumMessage.getPath()).toArray(new String[0]));
|
||||
} else {
|
||||
enumMessage.setMessages(cfg.getFile().getString(enumMessage.getPath()));
|
||||
}
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public String[] getMessages() {
|
||||
return this.messages;
|
||||
}
|
||||
|
||||
public void setMessages(String[] messages) {
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
public void setMessages(String messages) {
|
||||
this.messages[0] = messages;
|
||||
}
|
||||
|
||||
public void msg(CommandSender target) {
|
||||
this.msg(target, null, false);
|
||||
}
|
||||
|
||||
public void msg(CommandSender target, Map<String, String> map, boolean ignoreCase) {
|
||||
if (this.isMultiLined()) {
|
||||
Utils.msg(target, this.getMessages(), map, ignoreCase);
|
||||
} else {
|
||||
Utils.msg(target, this.getMessages()[0], map, ignoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
public void msgAll() {
|
||||
if (this.isMultiLined()) {
|
||||
Bukkit.getOnlinePlayers().forEach(target -> Utils.msg(target, this.getMessages()));
|
||||
} else {
|
||||
Bukkit.getOnlinePlayers().forEach(target -> Utils.msg(target, this.getMessages()[0]));
|
||||
}
|
||||
}
|
||||
|
||||
public void msgAll(Map<String, String> map, boolean ignoreCase) {
|
||||
if (this.isMultiLined()) {
|
||||
Bukkit.getOnlinePlayers().forEach(target -> Utils.msg(target, this.getMessages(), map, ignoreCase));
|
||||
} else {
|
||||
Bukkit.getOnlinePlayers().forEach(target -> Utils.msg(target, this.getMessages()[0], map, ignoreCase));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,328 @@
|
||||
package net.crankedpvp.rps.utilities;
|
||||
|
||||
import com.google.common.primitives.Primitives;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class NBTEditor {
|
||||
private static final Map<String, Class<?>> classCache;
|
||||
|
||||
private static final Map<String, Method> methodCache;
|
||||
|
||||
private static final Map<Class<?>, Constructor<?>> constructorCache;
|
||||
|
||||
private static final Map<Class<?>, Class<?>> NBTClasses;
|
||||
|
||||
private static final Map<Class<?>, Field> NBTTagFieldCache;
|
||||
|
||||
private static Field NBTListData;
|
||||
|
||||
private static Field NBTCompoundMap;
|
||||
|
||||
private static final String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
|
||||
static {
|
||||
classCache = new HashMap<>();
|
||||
try {
|
||||
classCache.put("NBTBase", Class.forName("net.minecraft.server." + version + "." + "NBTBase"));
|
||||
classCache.put("NBTTagCompound", Class.forName("net.minecraft.server." + version + "." + "NBTTagCompound"));
|
||||
classCache.put("NBTTagList", Class.forName("net.minecraft.server." + version + "." + "NBTTagList"));
|
||||
classCache.put("NBTBase", Class.forName("net.minecraft.server." + version + "." + "NBTBase"));
|
||||
classCache.put("ItemStack", Class.forName("net.minecraft.server." + version + "." + "ItemStack"));
|
||||
classCache.put("CraftItemStack",
|
||||
Class.forName("org.bukkit.craftbukkit." + version + ".inventory." + "CraftItemStack"));
|
||||
classCache.put("Entity", Class.forName("net.minecraft.server." + version + "." + "Entity"));
|
||||
classCache.put("CraftEntity",
|
||||
Class.forName("org.bukkit.craftbukkit." + version + ".entity." + "CraftEntity"));
|
||||
classCache.put("EntityLiving", Class.forName("net.minecraft.server." + version + "." + "EntityLiving"));
|
||||
classCache.put("CraftWorld", Class.forName("org.bukkit.craftbukkit." + version + "." + "CraftWorld"));
|
||||
classCache.put("CraftBlockState",
|
||||
Class.forName("org.bukkit.craftbukkit." + version + ".block." + "CraftBlockState"));
|
||||
classCache.put("BlockPosition", Class.forName("net.minecraft.server." + version + "." + "BlockPosition"));
|
||||
classCache.put("TileEntity", Class.forName("net.minecraft.server." + version + "." + "TileEntity"));
|
||||
classCache.put("World", Class.forName("net.minecraft.server." + version + "." + "World"));
|
||||
classCache.put("TileEntitySkull",
|
||||
Class.forName("net.minecraft.server." + version + "." + "TileEntitySkull"));
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
NBTClasses = new HashMap<>();
|
||||
try {
|
||||
NBTClasses.put(Byte.class, Class.forName("net.minecraft.server." + version + "." + "NBTTagByte"));
|
||||
NBTClasses.put(String.class, Class.forName("net.minecraft.server." + version + "." + "NBTTagString"));
|
||||
NBTClasses.put(Double.class, Class.forName("net.minecraft.server." + version + "." + "NBTTagDouble"));
|
||||
NBTClasses.put(Integer.class, Class.forName("net.minecraft.server." + version + "." + "NBTTagInt"));
|
||||
NBTClasses.put(Long.class, Class.forName("net.minecraft.server." + version + "." + "NBTTagLong"));
|
||||
NBTClasses.put(Short.class, Class.forName("net.minecraft.server." + version + "." + "NBTTagShort"));
|
||||
NBTClasses.put(Float.class, Class.forName("net.minecraft.server." + version + "." + "NBTTagFloat"));
|
||||
NBTClasses.put(Class.forName("[B"),
|
||||
Class.forName("net.minecraft.server." + version + "." + "NBTTagByteArray"));
|
||||
NBTClasses.put(Class.forName("[I"),
|
||||
Class.forName("net.minecraft.server." + version + "." + "NBTTagIntArray"));
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
methodCache = new HashMap<>();
|
||||
try {
|
||||
methodCache.put("get", getNMSClass("NBTTagCompound").getMethod("get", new Class[] { String.class }));
|
||||
methodCache.put("set",
|
||||
getNMSClass("NBTTagCompound").getMethod("set", new Class[] { String.class, getNMSClass("NBTBase") }));
|
||||
methodCache.put("hasKey", getNMSClass("NBTTagCompound").getMethod("hasKey", new Class[] { String.class }));
|
||||
methodCache.put("setIndex", getNMSClass("NBTTagList").getMethod("a", new Class[] { int.class, getNMSClass("NBTBase") }));
|
||||
methodCache.put("add", getNMSClass("NBTTagList").getMethod("add", new Class[] { getNMSClass("NBTBase") }));
|
||||
methodCache.put("hasTag", getNMSClass("ItemStack").getMethod("hasTag", new Class[0]));
|
||||
methodCache.put("getTag", getNMSClass("ItemStack").getMethod("getTag", new Class[0]));
|
||||
methodCache.put("setTag", getNMSClass("ItemStack").getMethod("setTag", new Class[] { getNMSClass("NBTTagCompound") }));
|
||||
methodCache.put("asNMSCopy", getNMSClass("CraftItemStack").getMethod("asNMSCopy", new Class[] { ItemStack.class }));
|
||||
methodCache.put("asBukkitCopy",
|
||||
getNMSClass("CraftItemStack").getMethod("asBukkitCopy", new Class[] { getNMSClass("ItemStack") }));
|
||||
methodCache.put("getEntityHandle", getNMSClass("CraftEntity").getMethod("getHandle", new Class[0]));
|
||||
methodCache.put("getEntityTag", getNMSClass("Entity").getMethod("c", new Class[] { getNMSClass("NBTTagCompound") }));
|
||||
methodCache.put("setEntityTag", getNMSClass("Entity").getMethod("f", new Class[] { getNMSClass("NBTTagCompound") }));
|
||||
if (version.contains("1_12") || version.contains("1_13")) {
|
||||
methodCache.put("setTileTag",
|
||||
getNMSClass("TileEntity").getMethod("load", new Class[] { getNMSClass("NBTTagCompound") }));
|
||||
} else {
|
||||
methodCache.put("setTileTag", getNMSClass("TileEntity").getMethod("a", new Class[] { getNMSClass("NBTTagCompound") }));
|
||||
}
|
||||
methodCache.put("getTileEntity",
|
||||
getNMSClass("World").getMethod("getTileEntity", new Class[] { getNMSClass("BlockPosition") }));
|
||||
methodCache.put("getWorldHandle", getNMSClass("CraftWorld").getMethod("getHandle", new Class[0]));
|
||||
methodCache.put("setGameProfile",
|
||||
getNMSClass("TileEntitySkull").getMethod("setGameProfile", new Class[] { GameProfile.class }));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
methodCache.put("getTileTag", getNMSClass("TileEntity").getMethod("save", new Class[] { getNMSClass("NBTTagCompound") }));
|
||||
} catch (NoSuchMethodException exception) {
|
||||
try {
|
||||
methodCache.put("getTileTag", getNMSClass("TileEntity").getMethod("b", new Class[] { getNMSClass("NBTTagCompound") }));
|
||||
} catch (Exception exception2) {
|
||||
exception2.printStackTrace();
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
constructorCache = new HashMap<>();
|
||||
try {
|
||||
constructorCache.put(getNBTTag(Byte.class), getNBTTag(Byte.class).getConstructor(new Class[] { byte.class }));
|
||||
constructorCache.put(getNBTTag(String.class), getNBTTag(String.class).getConstructor(new Class[] { String.class }));
|
||||
constructorCache.put(getNBTTag(Double.class), getNBTTag(Double.class).getConstructor(new Class[] { double.class }));
|
||||
constructorCache.put(getNBTTag(Integer.class), getNBTTag(Integer.class).getConstructor(new Class[] { int.class }));
|
||||
constructorCache.put(getNBTTag(Long.class), getNBTTag(Long.class).getConstructor(new Class[] { long.class }));
|
||||
constructorCache.put(getNBTTag(Float.class), getNBTTag(Float.class).getConstructor(new Class[] { float.class }));
|
||||
constructorCache.put(getNBTTag(Short.class), getNBTTag(Short.class).getConstructor(new Class[] { short.class }));
|
||||
constructorCache.put(getNBTTag(Class.forName("[B")),
|
||||
getNBTTag(Class.forName("[B")).getConstructor(new Class[] { Class.forName("[B") }));
|
||||
constructorCache.put(getNBTTag(Class.forName("[I")),
|
||||
getNBTTag(Class.forName("[I")).getConstructor(new Class[] { Class.forName("[I") }));
|
||||
constructorCache.put(getNMSClass("BlockPosition"),
|
||||
getNMSClass("BlockPosition").getConstructor(new Class[] { int.class, int.class, int.class }));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
NBTTagFieldCache = new HashMap<>();
|
||||
try {
|
||||
for (Class<?> clazz : NBTClasses.values()) {
|
||||
Field data = clazz.getDeclaredField("data");
|
||||
data.setAccessible(true);
|
||||
NBTTagFieldCache.put(clazz, data);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
NBTListData = getNMSClass("NBTTagList").getDeclaredField("list");
|
||||
NBTListData.setAccessible(true);
|
||||
NBTCompoundMap = getNMSClass("NBTTagCompound").getDeclaredField("map");
|
||||
NBTCompoundMap.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<?> getPrimitiveClass(Class<?> clazz) {
|
||||
return Primitives.unwrap(clazz);
|
||||
}
|
||||
|
||||
public static Class<?> getNBTTag(Class<?> primitiveType) {
|
||||
if (NBTClasses.containsKey(primitiveType))
|
||||
return NBTClasses.get(primitiveType);
|
||||
return primitiveType;
|
||||
}
|
||||
|
||||
public static Object getNBTVar(Object object) {
|
||||
if (object == null)
|
||||
return null;
|
||||
Class<?> clazz = object.getClass();
|
||||
try {
|
||||
if (NBTTagFieldCache.containsKey(clazz))
|
||||
return ((Field)NBTTagFieldCache.get(clazz)).get(object);
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Method getMethod(String name) {
|
||||
return methodCache.containsKey(name) ? methodCache.get(name) : null;
|
||||
}
|
||||
|
||||
public static Constructor<?> getConstructor(Class<?> clazz) {
|
||||
return constructorCache.containsKey(clazz) ? constructorCache.get(clazz) : null;
|
||||
}
|
||||
|
||||
public static Class<?> getNMSClass(String name) {
|
||||
if (classCache.containsKey(name))
|
||||
return classCache.get(name);
|
||||
try {
|
||||
return Class.forName("net.minecraft.server." + version + "." + name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Object getItemTag(ItemStack item, Object... keys) {
|
||||
if (item == null)
|
||||
return null;
|
||||
try {
|
||||
Object stack = null;
|
||||
stack = getMethod("asNMSCopy").invoke(null, new Object[] { item });
|
||||
Object tag = null;
|
||||
if (getMethod("hasTag").invoke(stack, new Object[0]).equals(Boolean.valueOf(true))) {
|
||||
tag = getMethod("getTag").invoke(stack, new Object[0]);
|
||||
} else {
|
||||
tag = getNMSClass("NBTTagCompound").newInstance();
|
||||
}
|
||||
return getTag(tag, keys);
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack setItemTag(ItemStack item, Object value, Object... keys) {
|
||||
if (item == null)
|
||||
return null;
|
||||
try {
|
||||
Object stack = getMethod("asNMSCopy").invoke(null, new Object[] { item });
|
||||
Object tag = null;
|
||||
if (getMethod("hasTag").invoke(stack, new Object[0]).equals(Boolean.valueOf(true))) {
|
||||
tag = getMethod("getTag").invoke(stack, new Object[0]);
|
||||
} else {
|
||||
tag = getNMSClass("NBTTagCompound").newInstance();
|
||||
}
|
||||
setTag(tag, value, keys);
|
||||
getMethod("setTag").invoke(stack, new Object[] { tag });
|
||||
return (ItemStack)getMethod("asBukkitCopy").invoke(null, new Object[] { stack });
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void setTag(Object tag, Object value, Object... keys) throws Exception {
|
||||
Object notCompound = getConstructor(getNBTTag(value.getClass())).newInstance(new Object[] { value });
|
||||
Object compound = tag;
|
||||
for (int index = 0; index < keys.length; index++) {
|
||||
Object key = keys[index];
|
||||
if (index + 1 == keys.length) {
|
||||
if (key == null) {
|
||||
getMethod("add").invoke(compound, new Object[] { notCompound });
|
||||
break;
|
||||
}
|
||||
if (key instanceof Integer) {
|
||||
getMethod("setIndex").invoke(compound, new Object[] { Integer.valueOf(((Integer)key).intValue()), notCompound });
|
||||
break;
|
||||
}
|
||||
getMethod("set").invoke(compound, new Object[] { key, notCompound });
|
||||
break;
|
||||
}
|
||||
Object oldCompound = compound;
|
||||
if (key instanceof Integer) {
|
||||
compound = ((List)NBTListData.get(compound)).get(((Integer)key).intValue());
|
||||
} else if (key != null) {
|
||||
compound = getMethod("get").invoke(compound, new Object[] { key });
|
||||
}
|
||||
if (compound == null || key == null) {
|
||||
if (keys[index + 1] == null || keys[index + 1] instanceof Integer) {
|
||||
compound = getNMSClass("NBTTagList").newInstance();
|
||||
} else {
|
||||
compound = getNMSClass("NBTTagCompound").newInstance();
|
||||
}
|
||||
if (oldCompound.getClass().getSimpleName().equals("NBTTagList")) {
|
||||
getMethod("add").invoke(oldCompound, new Object[] { compound });
|
||||
} else {
|
||||
getMethod("set").invoke(oldCompound, new Object[] { key, compound });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Object getTag(Object tag, Object... keys) throws Exception {
|
||||
if (keys.length == 0)
|
||||
return getTags(tag);
|
||||
Object notCompound = tag;
|
||||
byte b;
|
||||
int i;
|
||||
Object[] arrayOfObject;
|
||||
for (i = (arrayOfObject = keys).length, b = 0; b < i; ) {
|
||||
Object key = arrayOfObject[b];
|
||||
if (notCompound == null)
|
||||
return null;
|
||||
if (getNMSClass("NBTTagCompound").isInstance(notCompound)) {
|
||||
notCompound = getMethod("get").invoke(notCompound, new Object[] { key });
|
||||
} else if (getNMSClass("NBTTagList").isInstance(notCompound)) {
|
||||
notCompound = ((List)NBTListData.get(notCompound)).get(((Integer)key).intValue());
|
||||
} else {
|
||||
return getNBTVar(notCompound);
|
||||
}
|
||||
b++;
|
||||
}
|
||||
if (notCompound == null)
|
||||
return null;
|
||||
if (getNMSClass("NBTTagList").isInstance(notCompound))
|
||||
return getTags(notCompound);
|
||||
if (getNMSClass("NBTTagCompound").isInstance(notCompound))
|
||||
return getTags(notCompound);
|
||||
return getNBTVar(notCompound);
|
||||
}
|
||||
|
||||
private static Object getTags(Object tag) {
|
||||
Map<Object, Object> tags = new HashMap<>();
|
||||
try {
|
||||
if (getNMSClass("NBTTagCompound").isInstance(tag)) {
|
||||
Map<String, Object> tagCompound = (Map<String, Object>)NBTCompoundMap.get(tag);
|
||||
for (String key : tagCompound.keySet()) {
|
||||
Object value = tagCompound.get(key);
|
||||
if (getNMSClass("NBTTagEnd").isInstance(value))
|
||||
continue;
|
||||
tags.put(key, getTag(value, new Object[0]));
|
||||
}
|
||||
} else if (getNMSClass("NBTTagList").isInstance(tag)) {
|
||||
List<Object> tagList = (List<Object>)NBTListData.get(tag);
|
||||
for (int index = 0; index < tagList.size(); index++) {
|
||||
Object value = tagList.get(index);
|
||||
if (!getNMSClass("NBTTagEnd").isInstance(value))
|
||||
tags.put(Integer.valueOf(index), getTag(value, new Object[0]));
|
||||
}
|
||||
} else {
|
||||
return getNBTVar(tag);
|
||||
}
|
||||
return tags;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return tags;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,346 @@
|
||||
// =============================================== //
|
||||
// Recompile disabled. Please run Recaf with a JDK //
|
||||
// =============================================== //
|
||||
|
||||
// Decompiled with: CFR 0.152
|
||||
// Class Version: 8
|
||||
package net.crankedpvp.rps.utilities;
|
||||
|
||||
import com.google.common.primitives.Doubles;
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.google.common.primitives.Longs;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class Utils {
|
||||
private Utils() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public static String convertSeconds(int input) {
|
||||
Validate.isTrue(input > 0, "Why are you even trying to convert: " + input + "?");
|
||||
int days = (int)TimeUnit.SECONDS.toDays(input);
|
||||
StringBuilder builder = new StringBuilder(days > 0 ? Utils.pluralize("^# day^s", days) : "");
|
||||
int hours = (int)(TimeUnit.SECONDS.toHours(input) - TimeUnit.DAYS.toHours(days));
|
||||
builder.append(hours > 0 ? (builder.toString().equals("") ? "" : ", ") + Utils.pluralize("^# hour^s", hours) : "");
|
||||
int minutes = (int)(TimeUnit.SECONDS.toMinutes(input) - TimeUnit.HOURS.toMinutes(hours) - TimeUnit.DAYS.toMinutes(days));
|
||||
builder.append(minutes > 0 ? (builder.toString().equals("") ? "" : ", ") + Utils.pluralize("^# minute^s", minutes) : "");
|
||||
int seconds = (int)(TimeUnit.SECONDS.toSeconds(input) - TimeUnit.MINUTES.toSeconds(minutes) - TimeUnit.HOURS.toSeconds(hours) - TimeUnit.DAYS.toSeconds(days));
|
||||
builder.append(seconds > 0 ? (builder.toString().equals("") ? "" : ", ") + Utils.pluralize("^# second^s", seconds) : "");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static String pluralize(String text, int value) {
|
||||
return text.replace("^s", value > 1 ? "s" : "").replace("^#", String.valueOf(value));
|
||||
}
|
||||
|
||||
public static String getMachineIP() {
|
||||
try {
|
||||
return new BufferedReader(new InputStreamReader(new URL("http://checkip.amazonaws.com").openStream())).readLine();
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isDouble(String input) {
|
||||
return Doubles.tryParse(StringUtils.deleteWhitespace(input)) != null;
|
||||
}
|
||||
|
||||
public static boolean isInt(String input) {
|
||||
return Ints.tryParse(StringUtils.deleteWhitespace(input)) != null;
|
||||
}
|
||||
|
||||
public static boolean isLong(String input) {
|
||||
return Longs.tryParse(StringUtils.deleteWhitespace(input)) != null;
|
||||
}
|
||||
|
||||
public static boolean isList(FileConfiguration file, String path) {
|
||||
return Utils.isList(file.get(path));
|
||||
}
|
||||
|
||||
public static boolean isList(Object obj) {
|
||||
return obj instanceof ArrayList;
|
||||
}
|
||||
|
||||
public static void bcMsg(String input) {
|
||||
Bukkit.broadcastMessage(Utils.colorize(input));
|
||||
}
|
||||
|
||||
public static void bcMsg(List<String> input) {
|
||||
input.forEach(Utils::bcMsg);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void bcMsg(Object input) {
|
||||
Utils.bcMsg(String.valueOf(input));
|
||||
}
|
||||
|
||||
public static void msgConsole(String message) {
|
||||
Bukkit.getConsoleSender().sendMessage(Utils.colorize(message));
|
||||
}
|
||||
|
||||
public static void msgConsole(List<String> message) {
|
||||
message.forEach(Utils::msgConsole);
|
||||
}
|
||||
|
||||
public static void msg(CommandSender target, String message) {
|
||||
Validate.notNull(target, "The commandsender can't be null");
|
||||
target.sendMessage(Utils.colorize(message));
|
||||
}
|
||||
|
||||
public static void msg(CommandSender target, List<String> message) {
|
||||
Validate.notNull(target, "The commandsender can't be null");
|
||||
Utils.colorize(message).forEach(target::sendMessage);
|
||||
}
|
||||
|
||||
public static void msg(CommandSender target, String[] message) {
|
||||
Validate.notNull(target, "The commandsender can't be null");
|
||||
target.sendMessage(Utils.colorize(message));
|
||||
}
|
||||
|
||||
public static void msg(CommandSender target, String message, Map<String, String> map, boolean ignoreCase) {
|
||||
Utils.msg(target, Utils.placeHolder(message, map, ignoreCase));
|
||||
}
|
||||
|
||||
public static void msg(CommandSender target, List<String> message, Map<String, String> map, boolean ignoreCase) {
|
||||
Utils.msg(target, Utils.placeHolder(message, map, ignoreCase));
|
||||
}
|
||||
|
||||
public static void msg(CommandSender target, String[] message, Map<String, String> map, boolean ignoreCase) {
|
||||
Utils.msg(target, Utils.placeHolder(message, map, ignoreCase));
|
||||
}
|
||||
|
||||
public static void msg(CommandSender target, FileConfiguration file, String path) {
|
||||
Utils.msg(target, null, false, file, path);
|
||||
}
|
||||
|
||||
public static void msg(CommandSender target, Map<String, String> map, boolean replace, FileConfiguration file, String path) {
|
||||
Validate.notNull(file, "The file can't be null");
|
||||
Validate.notNull(file, "The path can't be null");
|
||||
if (Utils.isList(file, path)) {
|
||||
Utils.msg(target, file.getStringList(path), map, replace);
|
||||
} else {
|
||||
Utils.msg(target, file.getString(path), map, replace);
|
||||
}
|
||||
}
|
||||
|
||||
public static String placeHolder(String str, Map<String, String> map, boolean ignoreCase) {
|
||||
Validate.notNull(str, "The string can't be null!");
|
||||
if (map == null) {
|
||||
return str;
|
||||
}
|
||||
for (Map.Entry<String, String> entr : map.entrySet()) {
|
||||
String string = str = ignoreCase ? Utils.replaceIgnoreCase(str, entr.getKey(), entr.getValue()) : str.replace(entr.getKey(), entr.getValue());
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static String[] placeHolder(String[] array, Map<String, String> map, boolean ignoreCase) {
|
||||
Validate.notNull(array, "The string array can't be null!");
|
||||
Validate.noNullElements(array, "The string array can't have null elements!");
|
||||
String[] newarr = Arrays.copyOf(array, array.length);
|
||||
if (map == null) {
|
||||
return newarr;
|
||||
}
|
||||
int i = 0;
|
||||
while (i < newarr.length) {
|
||||
newarr[i] = Utils.placeHolder(newarr[i], map, ignoreCase);
|
||||
++i;
|
||||
}
|
||||
return newarr;
|
||||
}
|
||||
|
||||
public static List<String> placeHolder(List<String> coll, Map<String, String> map, boolean ignoreCase) {
|
||||
Validate.notNull(coll, "The string collection can't be null!");
|
||||
Validate.noNullElements(coll, "The string collection can't have null elements!");
|
||||
if (map == null) {
|
||||
return coll;
|
||||
}
|
||||
return coll.stream().map(str -> Utils.placeHolder(str, map, ignoreCase)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static boolean isStringAllowed(String message, boolean ignoreSpace) {
|
||||
return ignoreSpace ? StringUtils.isAlphanumericSpace(message) : StringUtils.isAlphanumeric(message);
|
||||
}
|
||||
|
||||
public static String capitalize(String string, boolean reset) {
|
||||
Validate.notNull(string, "Null string object can't be capitalized!");
|
||||
return StringUtils.capitalize(reset ? string.toLowerCase() : string);
|
||||
}
|
||||
|
||||
public static int getRandomInt(int lowerBound, int upperBound) {
|
||||
Validate.isTrue(upperBound > lowerBound, "uppderBound should be > lowerBound, min: " + lowerBound + ", max: " + upperBound);
|
||||
return ThreadLocalRandom.current().nextInt(lowerBound, upperBound + 1);
|
||||
}
|
||||
|
||||
public static String colorize(String msg) {
|
||||
Validate.notNull(msg, "The string can't be null!");
|
||||
return ChatColor.translateAlternateColorCodes('&', msg);
|
||||
}
|
||||
|
||||
public static String[] colorize(String[] array) {
|
||||
Validate.notNull(array, "The string array can't be null!");
|
||||
Validate.noNullElements(array, "The string array can't have null elements!");
|
||||
String[] newarr = Arrays.copyOf(array, array.length);
|
||||
int i = 0;
|
||||
while (i < newarr.length) {
|
||||
newarr[i] = Utils.colorize(newarr[i]);
|
||||
++i;
|
||||
}
|
||||
return newarr;
|
||||
}
|
||||
|
||||
public static List<String> colorize(List<String> coll) {
|
||||
Validate.notNull(coll, "The string collection can't be null!");
|
||||
Validate.noNullElements(coll, "The string collection can't have null elements!");
|
||||
coll.replaceAll(Utils::colorize);
|
||||
return coll;
|
||||
}
|
||||
|
||||
public static String filterSpecialChars(String str) {
|
||||
return Objects.isNull(str) || StringUtils.deleteWhitespace(str).equals("") ? str : str.replaceAll("[^a-zA-Z0-9 ]", "");
|
||||
}
|
||||
|
||||
public static int getPlayerPing(CommandSender player) {
|
||||
if (!(player instanceof Player)) {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
Class<?> craftPlayer = Class.forName("org.bukkit.craftbukkit." + Utils.getServerVersion() + ".entity.CraftPlayer");
|
||||
Object converted = craftPlayer.cast(player);
|
||||
Method handle = converted.getClass().getMethod("getHandle");
|
||||
Object entityPlayer = handle.invoke(converted);
|
||||
Field pingField = entityPlayer.getClass().getField("ping");
|
||||
return pingField.getInt(entityPlayer);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getServerVersion() {
|
||||
String pkg;
|
||||
String version;
|
||||
Pattern brand = Pattern.compile("(v|)[0-9][_.][0-9][_.][R0-9]*");
|
||||
return brand.matcher(version = (pkg = Bukkit.getServer().getClass().getPackage().getName()).substring(pkg.lastIndexOf(46) + 1)).matches() ? version : null;
|
||||
}
|
||||
|
||||
public static Map<Integer, ItemStack> addItems(Inventory inv, ItemStack ... items) {
|
||||
ItemStack[] filteredItems = Stream.of(items).filter(Objects::nonNull).toArray(ItemStack[]::new);
|
||||
return inv.addItem(filteredItems);
|
||||
}
|
||||
|
||||
public static String replaceIgnoreCase(String text, String searchString, String replacement) {
|
||||
int start;
|
||||
if (StringUtils.isEmpty(text) || StringUtils.isEmpty(searchString) || replacement == null) {
|
||||
return text;
|
||||
}
|
||||
int max = -1;
|
||||
String searchText = text.toLowerCase();
|
||||
int end = searchText.indexOf(searchString = searchString.toLowerCase(), start = 0);
|
||||
if (end == -1) {
|
||||
return text;
|
||||
}
|
||||
int replLength = searchString.length();
|
||||
int increase = replacement.length() - replLength;
|
||||
increase = increase < 0 ? 0 : increase;
|
||||
StringBuilder buf = new StringBuilder(text.length() + (increase *= 16));
|
||||
while (end != -1) {
|
||||
buf.append(text, start, end).append(replacement);
|
||||
start = end + replLength;
|
||||
if (--max == 0) break;
|
||||
end = searchText.indexOf(searchString, start);
|
||||
}
|
||||
return buf.append(text, start, text.length()).toString();
|
||||
}
|
||||
|
||||
public static boolean isServerOld() {
|
||||
String version = Bukkit.getVersion();
|
||||
return version.contains("1.8");
|
||||
}
|
||||
|
||||
public static ItemStack getMainItem(Player player) {
|
||||
ItemStack item = player.getItemInHand();
|
||||
return item == null || item.getType() == Material.AIR ? null : item;
|
||||
}
|
||||
|
||||
public static boolean isSimilar(ItemStack stack, ItemStack stack2, boolean durability) {
|
||||
boolean a;
|
||||
boolean bl = a = stack2.getType() == stack.getType() && stack2.hasItemMeta() == stack.hasItemMeta() && (!stack2.hasItemMeta() || Bukkit.getItemFactory().equals(stack2.getItemMeta(), stack.getItemMeta()));
|
||||
return durability ? a : a && stack2.getDurability() == stack.getDurability();
|
||||
}
|
||||
|
||||
public static String arrayToUpperCase(String name, String splitter) {
|
||||
String[] split = StringUtils.splitByWholeSeparator(name, splitter);
|
||||
StringBuilder buff = new StringBuilder();
|
||||
String[] stringArray = split;
|
||||
int n = split.length;
|
||||
int n2 = 0;
|
||||
while (n2 < n) {
|
||||
String str = stringArray[n2];
|
||||
buff.append(StringUtils.capitalize(str.toLowerCase()) + " ");
|
||||
++n2;
|
||||
}
|
||||
return buff.substring(0, buff.toString().length() - 1);
|
||||
}
|
||||
|
||||
public static void debug(JavaPlugin plugin, Map<String, String> map, String ... messages) {
|
||||
System.out.println("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
|
||||
System.out.println();
|
||||
String name = plugin.getDescription().getName() + " ";
|
||||
String desc = plugin.getDescription().getVersion();
|
||||
System.out.println(" " + name + desc);
|
||||
System.out.println();
|
||||
String[] stringArray = messages;
|
||||
int n = messages.length;
|
||||
int n2 = 0;
|
||||
while (n2 < n) {
|
||||
String msg = stringArray[n2];
|
||||
System.err.println(Utils.placeHolder(msg, map, false));
|
||||
++n2;
|
||||
}
|
||||
System.out.println();
|
||||
System.out.println("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
|
||||
}
|
||||
|
||||
public static void debug(JavaPlugin plugin, String ... messages) {
|
||||
Utils.debug(plugin, null, messages);
|
||||
}
|
||||
|
||||
public static double round(double value, int places) {
|
||||
if (places < 0) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
BigDecimal bd = new BigDecimal(String.valueOf(value));
|
||||
bd = bd.setScale(places, RoundingMode.HALF_UP);
|
||||
return bd.doubleValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package net.crankedpvp.rps.utilities;
|
||||
|
||||
import net.crankedpvp.rps.RPSPlugin;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
public class VaultAPI {
|
||||
private final RPSPlugin core;
|
||||
|
||||
private Economy economy;
|
||||
|
||||
public VaultAPI(RPSPlugin core) {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
public Economy getEconomy() {
|
||||
return this.economy;
|
||||
}
|
||||
|
||||
public boolean setupEconomy() {
|
||||
RegisteredServiceProvider<Economy> economyProvider = this.core.getServer().getServicesManager()
|
||||
.getRegistration(Economy.class);
|
||||
if (economyProvider != null)
|
||||
this.economy = (Economy)economyProvider.getProvider();
|
||||
return (this.economy != null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
Inventory:
|
||||
name: 'Viewing %amount% Wages'
|
||||
items:
|
||||
book:
|
||||
name: '&a&lRPS Help'
|
||||
lore:
|
||||
- ''
|
||||
- '&e/rps'
|
||||
- '&7View all active RPS wagers.'
|
||||
- ''
|
||||
- '&e/rps <amount> <r/p/s>'
|
||||
- '&7Start a RPS match with the set wager.'
|
||||
- ''
|
||||
- '&e/rps cancel'
|
||||
- '&7Remove all your existing RPS matches.'
|
||||
- ''
|
||||
- '&e/rps stats <player>'
|
||||
- '&7View your own or a player''s RPS stats.'
|
||||
- ''
|
||||
- '&e/rps top <wins:losses>'
|
||||
- '&7View top users.'
|
||||
- ''
|
||||
- '&e/rps toggle'
|
||||
- '&7Toggle incoming win/lose messages.'
|
||||
- ''
|
||||
|
||||
Top-Players:
|
||||
Wins:
|
||||
name: 'Top 9 Winners'
|
||||
items:
|
||||
name: '&7(#%rank%) %relation_color%%name% &l%faction%'
|
||||
lore:
|
||||
- '&7Stats'
|
||||
- ' &7&l* &7Wins: &a%wins%'
|
||||
- ' &7&l* &7Losses: &c%losses%'
|
||||
- ' &7&l* &7Ratio: &6%ratio%'
|
||||
Losses:
|
||||
name: 'Top 9 Losses'
|
||||
items:
|
||||
name: '&7(#%rank%) %relation_color%%name% &l%faction%'
|
||||
lore:
|
||||
- '&7Stats'
|
||||
- ' &7&l* &7Wins: &a%wins%'
|
||||
- ' &7&l* &7Losses: &c%losses%'
|
||||
- ' &7&l* &7Ratio: &6%ratio%'
|
||||
|
||||
Prices:
|
||||
minimum: 1
|
||||
maximum: 100000000000
|
||||
|
||||
Heads:
|
||||
operator:
|
||||
name: '&r%relation_color%%name% &l%faction%'
|
||||
lore:
|
||||
- ''
|
||||
- '&e&lWager'
|
||||
- ' &7$%money%'
|
||||
- ''
|
||||
- '&e&lChosen'
|
||||
- ' &6%rps%'
|
||||
- ''
|
||||
- '&e&lStats'
|
||||
- '&7 Wins &a%wins%'
|
||||
- '&7 Losses &c%losses%'
|
||||
- ''
|
||||
- '&r%enterable%'
|
||||
normal:
|
||||
name: '&r%relation_color%%name% &l%faction%'
|
||||
lore:
|
||||
- ''
|
||||
- '&e&lWager'
|
||||
- ' &7$%money%'
|
||||
- ''
|
||||
- '&e&lStats'
|
||||
- '&7 Wins &a%wins%'
|
||||
- '&7 Losses &c%losses%'
|
||||
- ''
|
||||
- '&r%enterable%'
|
||||
@@ -0,0 +1 @@
|
||||
Players: {}
|
||||
@@ -0,0 +1,9 @@
|
||||
main: net.crankedpvp.rps.RPSPlugin
|
||||
name: CrankedRockPaperScissors
|
||||
version: ${git.total.commit.count}.0
|
||||
depend: [Factions, Vault]
|
||||
description: "§fCommit ID: §a${git.commit.id.abbrev}"
|
||||
website: https://crankedpvp.net/
|
||||
commands:
|
||||
rps:
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Bets: {}
|
||||
Reference in New Issue
Block a user