mirror of
https://github.com/filoghost/ChestCommands.git
synced 2024-11-23 02:25:26 +01:00
Add PlayerPoints Support.
This commit is contained in:
parent
36e537f960
commit
7ec9acb6e0
@ -1,7 +1,7 @@
|
||||
name: ChestCommands
|
||||
main: com.gmail.filoghost.chestcommands.ChestCommands
|
||||
version: 3.0
|
||||
softdepend: [Vault, BarAPI]
|
||||
version: 3.0.1
|
||||
softdepend: [Vault, BarAPI, PlayerPoints]
|
||||
|
||||
commands:
|
||||
chestcommands:
|
||||
|
@ -16,6 +16,7 @@ import org.mcstats.MetricsLite;
|
||||
import com.gmail.filoghost.chestcommands.SimpleUpdater.ResponseHandler;
|
||||
import com.gmail.filoghost.chestcommands.bridge.BarAPIBridge;
|
||||
import com.gmail.filoghost.chestcommands.bridge.EconomyBridge;
|
||||
import com.gmail.filoghost.chestcommands.bridge.PlayerPointsBridge;
|
||||
import com.gmail.filoghost.chestcommands.command.CommandFramework;
|
||||
import com.gmail.filoghost.chestcommands.command.CommandHandler;
|
||||
import com.gmail.filoghost.chestcommands.config.AsciiPlaceholders;
|
||||
@ -80,6 +81,10 @@ public class ChestCommands extends JavaPlugin {
|
||||
getLogger().info("Hooked BarAPI");
|
||||
}
|
||||
|
||||
if (PlayerPointsBridge.setupPlugin()) {
|
||||
getLogger().info("Hooked PlayerPoints");
|
||||
}
|
||||
|
||||
String version = Utils.getBukkitVersion();
|
||||
try {
|
||||
Class<?> clazz = Class.forName("com.gmail.filoghost.chestcommands.nms." + version);
|
||||
|
@ -1,7 +1,59 @@
|
||||
package com.gmail.filoghost.chestcommands.bridge;
|
||||
|
||||
import org.black_ixx.playerpoints.PlayerPoints;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
// PlayerPoints minimum version: 2.0
|
||||
public class PlayerPointsBridge {
|
||||
|
||||
// A big TODO
|
||||
private static PlayerPoints playerPoints;
|
||||
|
||||
public static boolean setupPlugin() {
|
||||
Plugin pointsPlugin = Bukkit.getPluginManager().getPlugin("PlayerPoints");
|
||||
|
||||
if (pointsPlugin == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
playerPoints = (PlayerPoints) pointsPlugin;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean hasValidPlugin() {
|
||||
return playerPoints != null;
|
||||
}
|
||||
|
||||
public static int getPoints(Player player) {
|
||||
if (!hasValidPlugin()) throw new IllegalStateException("PlayerPoints plugin was not found!");
|
||||
return playerPoints.getAPI().look(player.getUniqueId());
|
||||
}
|
||||
|
||||
public static boolean hasPoints(Player player, int minimum) {
|
||||
if (!hasValidPlugin()) throw new IllegalStateException("PlayerPoints plugin was not found!");
|
||||
if (minimum < 0) throw new IllegalArgumentException("Invalid amount of points: " + minimum);
|
||||
|
||||
return playerPoints.getAPI().look(player.getUniqueId()) >= minimum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the operation was successful.
|
||||
*/
|
||||
public static boolean takePoints(Player player, int points) {
|
||||
if (!hasValidPlugin()) throw new IllegalStateException("PlayerPoints plugin was not found!");
|
||||
if (points < 0) throw new IllegalArgumentException("Invalid amount of points: " + points);
|
||||
|
||||
return playerPoints.getAPI().take(player.getUniqueId(), points);
|
||||
}
|
||||
|
||||
|
||||
public static boolean givePoints(Player player, int points) {
|
||||
if (!hasValidPlugin()) throw new IllegalStateException("PlayerPoints plugin was not found!");
|
||||
if (points < 0) throw new IllegalArgumentException("Invalid amount of points: " + points);
|
||||
|
||||
return playerPoints.getAPI().give(player.getUniqueId(), points);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ public class Lang extends SpecialConfig {
|
||||
public String default_no_icon_permission = "&cYou need {money}$ for this.";
|
||||
public String no_required_item = "&cYou must have &e{amount}x {material} &c(ID: {id}, data value: {datavalue}) for this.";
|
||||
public String no_money = "&cYou need {money}$ for this.";
|
||||
public String no_points = "&cYou need {points} player points for this.";
|
||||
public String menu_not_found = "&cMenu not found! Please inform the staff.";
|
||||
public String any = "any"; // Used in no_required_item when data value is not restrictive.
|
||||
|
||||
|
@ -7,6 +7,7 @@ import com.gmail.filoghost.chestcommands.ChestCommands;
|
||||
import com.gmail.filoghost.chestcommands.Permissions;
|
||||
import com.gmail.filoghost.chestcommands.api.Icon;
|
||||
import com.gmail.filoghost.chestcommands.bridge.EconomyBridge;
|
||||
import com.gmail.filoghost.chestcommands.bridge.PlayerPointsBridge;
|
||||
import com.gmail.filoghost.chestcommands.internal.RequiredItem;
|
||||
import com.gmail.filoghost.chestcommands.util.Utils;
|
||||
|
||||
@ -14,7 +15,8 @@ public class ExtendedIcon extends Icon {
|
||||
|
||||
private String permission;
|
||||
private String permissionMessage;
|
||||
private double price;
|
||||
private double moneyPrice;
|
||||
private int playerPointsPrice;
|
||||
private RequiredItem requiredItem;
|
||||
|
||||
public ExtendedIcon() {
|
||||
@ -37,12 +39,20 @@ public class ExtendedIcon extends Icon {
|
||||
this.permissionMessage = permissionMessage;
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
return price;
|
||||
public double getMoneyPrice() {
|
||||
return moneyPrice;
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
this.price = price;
|
||||
public void setMoneyPrice(double moneyPrice) {
|
||||
this.moneyPrice = moneyPrice;
|
||||
}
|
||||
|
||||
public int getPlayerPointsPrice() {
|
||||
return playerPointsPrice;
|
||||
}
|
||||
|
||||
public void setPlayerPointsPrice(int playerPointsPrice) {
|
||||
this.playerPointsPrice = playerPointsPrice;
|
||||
}
|
||||
|
||||
public RequiredItem getRequiredItem() {
|
||||
@ -68,14 +78,26 @@ public class ExtendedIcon extends Icon {
|
||||
return closeOnClick;
|
||||
}
|
||||
|
||||
if (price > 0) {
|
||||
if (moneyPrice > 0) {
|
||||
if (!EconomyBridge.hasValidEconomy()) {
|
||||
player.sendMessage(ChatColor.RED + "This command has a price, but Vault with a compatible economy plugin was not found. For security, the command has been blocked. Please inform the staff.");
|
||||
return closeOnClick;
|
||||
}
|
||||
|
||||
if (!player.hasPermission(Permissions.BYPASS_ECONOMY) && !EconomyBridge.hasMoney(player, price)) {
|
||||
player.sendMessage(ChestCommands.getLang().no_money.replace("{money}", EconomyBridge.formatMoney(price)));
|
||||
if (!player.hasPermission(Permissions.BYPASS_ECONOMY) && !EconomyBridge.hasMoney(player, moneyPrice)) {
|
||||
player.sendMessage(ChestCommands.getLang().no_money.replace("{money}", EconomyBridge.formatMoney(moneyPrice)));
|
||||
return closeOnClick;
|
||||
}
|
||||
}
|
||||
|
||||
if (playerPointsPrice > 0) {
|
||||
if (!PlayerPointsBridge.hasValidPlugin()) {
|
||||
player.sendMessage(ChatColor.RED + "This command has a price in points, but the plugin PlayerPoints was not found. For security, the command has been blocked. Please inform the staff.");
|
||||
return closeOnClick;
|
||||
}
|
||||
|
||||
if (!PlayerPointsBridge.hasPoints(player, playerPointsPrice)) {
|
||||
player.sendMessage(ChestCommands.getLang().no_points.replace("{points}", Integer.toString(playerPointsPrice)));
|
||||
return closeOnClick;
|
||||
}
|
||||
}
|
||||
@ -93,10 +115,17 @@ public class ExtendedIcon extends Icon {
|
||||
}
|
||||
}
|
||||
|
||||
// Take the money and the required item.
|
||||
// Take the money, the points and the required item.
|
||||
|
||||
if (price > 0) {
|
||||
if (!player.hasPermission(Permissions.BYPASS_ECONOMY) && !EconomyBridge.takeMoney(player, price)) {
|
||||
if (moneyPrice > 0) {
|
||||
if (!player.hasPermission(Permissions.BYPASS_ECONOMY) && !EconomyBridge.takeMoney(player, moneyPrice)) {
|
||||
player.sendMessage(ChatColor.RED + "Error: the transaction couldn't be executed. Please inform the staff.");
|
||||
return closeOnClick;
|
||||
}
|
||||
}
|
||||
|
||||
if (playerPointsPrice > 0) {
|
||||
if (!PlayerPointsBridge.takePoints(player, playerPointsPrice)) {
|
||||
player.sendMessage(ChatColor.RED + "Error: the transaction couldn't be executed. Please inform the staff.");
|
||||
return closeOnClick;
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ public class IconSerializer {
|
||||
COLOR = "COLOR",
|
||||
COMMAND = "COMMAND",
|
||||
PRICE = "PRICE",
|
||||
POINTS = "POINTS",
|
||||
REQUIRED_ITEM = "REQUIRED-ITEM",
|
||||
PERMISSION = "PERMISSION",
|
||||
PERMISSION_MESSAGE = "PERMISSION-MESSAGE",
|
||||
@ -111,11 +112,18 @@ public class IconSerializer {
|
||||
|
||||
double price = section.getDouble(Nodes.PRICE);
|
||||
if (price > 0.0) {
|
||||
icon.setPrice(price);
|
||||
icon.setMoneyPrice(price);
|
||||
} else if (price < 0.0) {
|
||||
errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has a negative PRICE: " + price);
|
||||
}
|
||||
|
||||
int points = section.getInt(Nodes.POINTS);
|
||||
if (points > 0) {
|
||||
icon.setPlayerPointsPrice(points);
|
||||
} else if (points < 0) {
|
||||
errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has negative POINTS: " + price);
|
||||
}
|
||||
|
||||
if (section.isSet(Nodes.REQUIRED_ITEM)) {
|
||||
try {
|
||||
ItemStackReader itemReader = new ItemStackReader(section.getString(Nodes.REQUIRED_ITEM), true);
|
||||
|
Loading…
Reference in New Issue
Block a user