Add support for PlayerPoints prices

This commit is contained in:
Jakub Kolář 2016-12-11 20:54:08 +01:00
parent 70a6f3ea04
commit cace3a4a2d
21 changed files with 222 additions and 85 deletions

View File

@ -9,6 +9,7 @@ import java.util.Set;
import java.util.UUID;
import java.util.logging.Logger;
import org.black_ixx.playerpoints.PlayerPoints;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -40,13 +41,14 @@ import cz.boosik.boosCooldown.Runnables.BoosGlobalLimitResetRunnable;
import net.milkbowl.vault.Vault;
import net.milkbowl.vault.economy.Economy;
import nms.NMSSetupResponse;
import util.boosChat;
import util.BoosChat;
public class BoosCoolDown extends JavaPlugin implements Runnable {
private static final Logger log = Logger.getLogger("Minecraft");
private static PluginDescriptionFile pdfFile;
private static Economy economy = null;
private static PlayerPoints playerPoints = null;
private static boolean usingVault = false;
private PluginManager pm;
@ -58,6 +60,10 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
return economy;
}
public static PlayerPoints getPlayerPoints() {
return playerPoints;
}
public static Logger getLog() {
return log;
}
@ -183,7 +189,7 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
if (args.length == 1) {
if (sender.hasPermission("booscooldowns.reload") && args[0].equalsIgnoreCase("reload")) {
reload();
boosChat.sendMessageToCommandSender(sender, "&6[" + pdfFile.getName() + "]&e" + " config reloaded");
BoosChat.sendMessageToCommandSender(sender, "&6[" + pdfFile.getName() + "]&e" + " config reloaded");
return true;
} else if (sender.hasPermission("booscooldowns.list.limits") && args[0].equalsIgnoreCase("limits")) {
try {
@ -214,20 +220,20 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
} else if (sender.hasPermission("booscooldowns.clearcooldowns") && args[0].equalsIgnoreCase("clearcooldowns")) {
String co = "cooldown";
BoosConfigManager.clearSomething(co, uuid);
boosChat.sendMessageToCommandSender(sender,
BoosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e" + " cooldowns of player " + jmeno + " cleared");
return true;
} else if (sender.hasPermission("booscooldowns.clearuses") && command.equalsIgnoreCase("booscooldowns") && args[0].equalsIgnoreCase(
"clearuses")) {
String co = "uses";
BoosConfigManager.clearSomething(co, uuid);
boosChat.sendMessageToCommandSender(sender, "&6[" + pdfFile.getName() + "]&e" + " uses of player " + jmeno + " cleared");
BoosChat.sendMessageToCommandSender(sender, "&6[" + pdfFile.getName() + "]&e" + " uses of player " + jmeno + " cleared");
return true;
} else if (sender.hasPermission("booscooldowns.clearwarmups") && command.equalsIgnoreCase("booscooldowns")
&& args[0].equalsIgnoreCase("clearwarmups")) {
String co = "warmup";
BoosConfigManager.clearSomething(co, uuid);
boosChat.sendMessageToCommandSender(sender, "&6[" + pdfFile.getName() + "]&e" + " warmups of player " + jmeno + " cleared");
BoosChat.sendMessageToCommandSender(sender, "&6[" + pdfFile.getName() + "]&e" + " warmups of player " + jmeno + " cleared");
return true;
}
} else if (args.length == 3) {
@ -238,19 +244,19 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
if (sender.hasPermission("booscooldowns.clearcooldowns") && args[0].equalsIgnoreCase("clearcooldowns")) {
String co = "cooldown";
BoosConfigManager.clearSomething(co, uuid, command2);
boosChat.sendMessageToCommandSender(sender,
BoosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e" + " cooldown for command " + command2 + " of player " + uuid + " cleared");
return true;
} else if (sender.hasPermission("booscooldowns.clearuses") && args[0].equalsIgnoreCase("clearuses")) {
String co = "uses";
BoosConfigManager.clearSomething(co, uuid, command2);
boosChat.sendMessageToCommandSender(sender,
BoosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e" + " uses for command " + command2 + " of player " + jmeno + " cleared");
return true;
} else if (sender.hasPermission("booscooldowns.clearwarmups") && args[0].equalsIgnoreCase("clearwarmups")) {
String co = "warmup";
BoosConfigManager.clearSomething(co, uuid, command2);
boosChat.sendMessageToCommandSender(sender,
BoosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e" + " warmups for command " + command2 + " of player " + jmeno + " cleared");
return true;
@ -266,11 +272,11 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
comm = comm.replace("_", " ");
}
BoosConfigManager.setAddToConfigFile(group, comm, what, value);
boosChat.sendMessageToCommandSender(sender,
BoosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e " + what + " for command" + comm + " in group " + group + " is now set to " + value);
return true;
} else {
boosChat.sendMessageToCommandSender(sender, "&6[" + pdfFile.getName() + "]&e" + " Command has to start with \"/\".");
BoosChat.sendMessageToCommandSender(sender, "&6[" + pdfFile.getName() + "]&e" + " Command has to start with \"/\".");
return true;
}
}
@ -286,17 +292,17 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
comm = comm.replace("_", " ");
}
BoosConfigManager.setAddToConfigFile(group, comm, what, value);
boosChat.sendMessageToCommandSender(sender,
BoosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e " + what + " for command" + comm + " in group " + group + " is now set to " + value);
return true;
} else {
boosChat.sendMessageToCommandSender(sender, "&6[" + pdfFile.getName() + "]&e" + " Command has to start with \"/\".");
BoosChat.sendMessageToCommandSender(sender, "&6[" + pdfFile.getName() + "]&e" + " Command has to start with \"/\".");
return true;
}
}
} else {
// boosChat.sendMessageToCommandSender(sender,
// BoosChat.sendMessageToCommandSender(sender,
// "&6[" + pdfFile.getName() + "]&e"
// + " Invalid command or access denied!");
return false;
@ -330,6 +336,7 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
pm = getServer().getPluginManager();
registerListeners();
initializeVault();
hookPlayerPoints();
BukkitScheduler scheduler = this.getServer().getScheduler();
startLimitResetTimersGlobal();
if (BoosConfigManager.getAutoSave()) {
@ -361,6 +368,15 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
}
private boolean hookPlayerPoints() {
final Plugin plugin = this.getServer().getPluginManager().getPlugin("PlayerPoints");
playerPoints = PlayerPoints.class.cast(plugin);
if (playerPoints != null) {
log.info("[" + pdfFile.getName() + "]" + " found [PlayerPoints], enabling support.");
}
return playerPoints != null;
}
private void registerListeners() {
HandlerList.unregisterAll(this);
pm.registerEvents(new BoosCoolDownListener(this), this);

View File

@ -29,10 +29,11 @@ import cz.boosik.boosCooldown.Managers.BoosConfigManager;
import cz.boosik.boosCooldown.Managers.BoosCoolDownManager;
import cz.boosik.boosCooldown.Managers.BoosItemCostManager;
import cz.boosik.boosCooldown.Managers.BoosLimitManager;
import cz.boosik.boosCooldown.Managers.BoosPlayerPointsManager;
import cz.boosik.boosCooldown.Managers.BoosPriceManager;
import cz.boosik.boosCooldown.Managers.BoosWarmUpManager;
import cz.boosik.boosCooldown.Managers.BoosXpCostManager;
import util.boosChat;
import util.BoosChat;
public class BoosCoolDownListener implements Listener {
public static Map<String, Boolean> commandQueue = new ConcurrentHashMap<>();
@ -45,14 +46,15 @@ public class BoosCoolDownListener implements Listener {
private void checkRestrictions(PlayerCommandPreprocessEvent event,
Player player, String regexCommad, String originalCommand,
int warmupTime, int cooldownTime, double price, String item,
int count, String name, List<String> lore, List<String> enchants, int limit, int xpPrice, int xpRequirement) {
int count, String name, List<String> lore, List<String> enchants, int limit, int xpPrice,
int xpRequirement, int playerPoints) {
boolean blocked = false;
String perm = BoosConfigManager.getPermission(player, regexCommad);
if (!(perm == null)) {
if (!player.hasPermission(perm)) {
String msg = BoosConfigManager.getPermissionMessage(player, regexCommad);
if (!(msg == null)) {
boosChat.sendMessageToPlayer(player, msg);
BoosChat.sendMessageToPlayer(player, msg);
}
event.setCancelled(true);
}
@ -72,7 +74,8 @@ public class BoosCoolDownListener implements Listener {
} else if (BoosPriceManager.has(player, price)
& BoosItemCostManager.has(player, item, count, name, lore, enchants)
& BoosXpCostManager.has(player, xpPrice)
& BoosXpCostManager.has(player, xpRequirement)) {
& BoosXpCostManager.has(player, xpRequirement)
& BoosPlayerPointsManager.has(player, playerPoints)) {
if (BoosCoolDownManager.coolDown(player, regexCommad,
originalCommand, cooldownTime)) {
event.setCancelled(true);
@ -81,7 +84,8 @@ public class BoosCoolDownListener implements Listener {
if (BoosPriceManager.has(player, price)
& BoosItemCostManager.has(player, item, count, name, lore, enchants)
& BoosXpCostManager.has(player, xpPrice)
& BoosXpCostManager.has(player, xpRequirement)) {
& BoosXpCostManager.has(player, xpRequirement)
& BoosPlayerPointsManager.has(player, playerPoints)) {
if (!event.isCancelled()) {
BoosPriceManager.payForCommand(event, player, regexCommad,
originalCommand, price);
@ -94,6 +98,10 @@ public class BoosCoolDownListener implements Listener {
BoosXpCostManager.payXPForCommand(event, player,
regexCommad, originalCommand, xpPrice);
}
if (!event.isCancelled()) {
BoosPlayerPointsManager.payForCommand(event, player,
regexCommad, originalCommand, playerPoints);
}
} else {
boolean warmupInProgress = BoosWarmUpManager.isWarmUpProcess(player, regexCommad);
boolean cooldownInProgress = BoosCoolDownManager.isCoolingdown(player, regexCommad, cooldownTime);
@ -107,16 +115,15 @@ public class BoosCoolDownListener implements Listener {
BoosCoolDown.getEconomy()
.getBalance(player)));
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
BoosChat.sendMessageToPlayer(player, msg);
}
if (!BoosItemCostManager.has(player, item, count, name, lore, enchants)
&& !warmupInProgress && !cooldownInProgress) {
String msg;
msg = String.format(
BoosConfigManager.getInsufficientItemsMessage(), "");
msg = BoosConfigManager.getInsufficientItemsMessage();
JSON json = getItemStackJson(1, item, count, name, lore, enchants);
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
BoosChat.sendMessageToPlayer(player, msg);
json.send(player);
}
if (!BoosXpCostManager.has(player, xpRequirement)
@ -124,18 +131,27 @@ public class BoosCoolDownListener implements Listener {
String msg;
msg = String.format(
BoosConfigManager.getInsufficientXpRequirementMessage(),
(xpRequirement));
xpRequirement);
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
BoosChat.sendMessageToPlayer(player, msg);
}
if (!BoosXpCostManager.has(player, xpPrice)
&& !warmupInProgress && !cooldownInProgress) {
String msg;
msg = String.format(
BoosConfigManager.getInsufficientXpMessage(),
(xpPrice));
xpPrice);
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
BoosChat.sendMessageToPlayer(player, msg);
}
if (!BoosPlayerPointsManager.has(player, playerPoints)
&& !warmupInProgress && !cooldownInProgress) {
String msg;
msg = String.format(
BoosConfigManager.getInsufficientPlayerPointsMessage(),
playerPoints, BoosCoolDown.getPlayerPoints().getAPI().look(player.getUniqueId()));
msg = msg.replaceAll("&command&", originalCommand);
BoosChat.sendMessageToPlayer(player, msg);
}
event.setCancelled(true);
}
@ -143,7 +159,7 @@ public class BoosCoolDownListener implements Listener {
String msg = BoosConfigManager.getMessage(
regexCommad, player);
if (!msg.equals("")) {
boosChat.sendMessageToPlayer(player, msg);
BoosChat.sendMessageToPlayer(player, msg);
}
}
} else {
@ -181,7 +197,7 @@ public class BoosCoolDownListener implements Listener {
Matcher m = p.matcher(event.getMessage());
if (m.find()) {
{
boosChat.sendMessageToPlayer(player, BoosConfigManager
BoosChat.sendMessageToPlayer(player, BoosConfigManager
.getInvalidCommandSyntaxMessage());
event.setCancelled(true);
return;
@ -197,7 +213,7 @@ public class BoosCoolDownListener implements Listener {
commandQueue.remove(key);
String commandCancelMessage = BoosConfigManager.getCommandCanceledMessage();
commandCancelMessage = commandCancelMessage.replace("&command&", keyList[1]);
boosChat.sendMessageToPlayer(player, commandCancelMessage);
BoosChat.sendMessageToPlayer(player, commandCancelMessage);
event.setCancelled(true);
return;
}
@ -223,6 +239,7 @@ public class BoosCoolDownListener implements Listener {
int cooldownTime = 0;
int xpPrice = 0;
int xpRequirement = 0;
int playerPoints = 0;
on = BoosCoolDown.isPluginOnForPlayer(player);
if (aliases != null) {
originalCommand = BoosAliasManager.checkCommandAlias(
@ -250,6 +267,10 @@ public class BoosCoolDownListener implements Listener {
player);
xpRequirement = BoosConfigManager.getXpRequirement(regexCommad, player);
}
if (BoosConfigManager.getPlayerPointsEnabled()) {
playerPoints = BoosConfigManager.getPlayerPointsPrice(regexCommad,
player);
}
if (BoosConfigManager.getItemCostEnabled()) {
item = BoosConfigManager.getItemCostItem(regexCommad,
player);
@ -273,15 +294,15 @@ public class BoosCoolDownListener implements Listener {
.contains(uuid + "@" + originalCommand) && commandQueue.get(uuid + "@" + originalCommand))) {
this.checkRestrictions(event, player, regexCommad, originalCommand,
warmupTime, cooldownTime, price, item, count, name, lore, enchants, limit,
xpPrice, xpRequirement);
xpPrice, xpRequirement, playerPoints);
} else {
if ((price > 0 || xpPrice > 0 || count > 0 || limit > 0) && !BoosWarmUpManager.isWarmUpProcess(player,
if ((price > 0 || xpPrice > 0 || count > 0 || limit > 0 || playerPoints > 0) && !BoosWarmUpManager.isWarmUpProcess(player,
regexCommad) && !BoosCoolDownManager.isCoolingdown(player, regexCommad, cooldownTime)) {
if (BoosConfigManager.getConfirmCommandEnabled(player)) {
commandQueue.put(uuid + "@" + originalCommand, false);
String questionMessage = BoosConfigManager.getQuestionMessage();
questionMessage = questionMessage.replace("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, questionMessage);
BoosChat.sendMessageToPlayer(player, questionMessage);
}
if (BoosCoolDown.getEconomy() != null) {
if (BoosConfigManager.getPriceEnabled()) {
@ -289,20 +310,31 @@ public class BoosCoolDownListener implements Listener {
String priceMessage = BoosConfigManager.getItsPriceMessage();
priceMessage = priceMessage.replace("&price&", BoosCoolDown.getEconomy().format(price))
.replace("&balance&", BoosCoolDown.getEconomy().format(BoosCoolDown.getEconomy().getBalance(player)));
boosChat.sendMessageToPlayer(player, " " + priceMessage);
BoosChat.sendMessageToPlayer(player, " " + priceMessage);
}
}
}
if (BoosCoolDown.getPlayerPoints() != null) {
if (BoosConfigManager.getPlayerPointsEnabled()) {
if (playerPoints > 0) {
String playerPointsMessage = BoosConfigManager.getItsPlayerPointsPriceMessage();
playerPointsMessage = playerPointsMessage.replace("&ppprice&", String.valueOf(playerPoints))
.replace("&ppbalance&",
String.valueOf(BoosCoolDown.getPlayerPoints().getAPI().look(player.getUniqueId())));
BoosChat.sendMessageToPlayer(player, " " + playerPointsMessage);
}
}
}
if (xpPrice > 0) {
String xpMessage = BoosConfigManager.getItsXpPriceMessage();
xpMessage = xpMessage.replace("&xpprice&", String.valueOf(xpPrice));
boosChat.sendMessageToPlayer(player, " " + xpMessage);
BoosChat.sendMessageToPlayer(player, " " + xpMessage);
}
if (count > 0) {
String itemMessage = BoosConfigManager.getItsItemCostMessage();
itemMessage = itemMessage.replace("&itemprice&", "").replace("&itemname&", "");
JSON json = getItemStackJson(2, item, count, name, lore, enchants);
boosChat.sendMessageToPlayer(player, " " + itemMessage);
BoosChat.sendMessageToPlayer(player, " " + itemMessage);
json.send(player);
}
if (limit > 0) {
@ -310,7 +342,7 @@ public class BoosCoolDownListener implements Listener {
String limitMessage = BoosConfigManager.getItsLimitMessage();
limitMessage = limitMessage.replace("&limit&", String.valueOf(limit))
.replace("&uses&", String.valueOf(limit - uses));
boosChat.sendMessageToPlayer(player, " " + limitMessage);
BoosChat.sendMessageToPlayer(player, " " + limitMessage);
}
String yesString = BoosConfigManager.getConfirmCommandMessage();
JSONClickAction yesClick = new JSONClickAction.RunCommand(yesString);
@ -335,7 +367,7 @@ public class BoosCoolDownListener implements Listener {
} else {
this.checkRestrictions(event, player, regexCommad, originalCommand,
warmupTime, cooldownTime, price, item, count, name, lore, enchants, limit,
xpPrice, xpRequirement);
xpPrice, xpRequirement, playerPoints);
}
}
}
@ -364,7 +396,7 @@ public class BoosCoolDownListener implements Listener {
commandQueue.remove(key);
String commandCancelMessage = BoosConfigManager.getCommandCanceledMessage();
commandCancelMessage = commandCancelMessage.replace("&command&", keyList[1]);
boosChat.sendMessageToPlayer(player, commandCancelMessage);
BoosChat.sendMessageToPlayer(player, commandCancelMessage);
event.setCancelled(true);
}
}

View File

@ -9,7 +9,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
import cz.boosik.boosCooldown.Managers.BoosConfigManager;
import cz.boosik.boosCooldown.Managers.BoosWarmUpManager;
import util.boosChat;
import util.BoosChat;
public class BoosEntityDamageListener implements Listener {
@ -20,7 +20,7 @@ public class BoosEntityDamageListener implements Listener {
Player player = (Player) entity;
if (!player.hasPermission("booscooldowns.nocancel.damage")) {
if (BoosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player, BoosConfigManager
BoosChat.sendMessageToPlayer(player, BoosConfigManager
.getWarmUpCancelledByDamageMessage());
BoosWarmUpManager.cancelWarmUps(player);
}

View File

@ -9,7 +9,7 @@ import org.bukkit.event.player.PlayerGameModeChangeEvent;
import cz.boosik.boosCooldown.Managers.BoosConfigManager;
import cz.boosik.boosCooldown.Managers.BoosWarmUpManager;
import util.boosChat;
import util.BoosChat;
public class BoosPlayerGameModeChangeListener implements Listener {
@ -21,7 +21,7 @@ public class BoosPlayerGameModeChangeListener implements Listener {
if (!player
.hasPermission("booscooldowns.nocancel.gamemodechange")) {
if (BoosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player, BoosConfigManager
BoosChat.sendMessageToPlayer(player, BoosConfigManager
.getCancelWarmupByGameModeChangeMessage());
BoosWarmUpManager.cancelWarmUps(player);
}

View File

@ -9,7 +9,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
import cz.boosik.boosCooldown.Managers.BoosConfigManager;
import cz.boosik.boosCooldown.Managers.BoosWarmUpManager;
import util.boosChat;
import util.BoosChat;
public class BoosPlayerInteractListener implements Listener {
@ -50,7 +50,7 @@ public class BoosPlayerInteractListener implements Listener {
|| event.getClickedBlock().getType().name()
.equals("HOPPER")) {
event.setCancelled(true);
boosChat.sendMessageToPlayer(player,
BoosChat.sendMessageToPlayer(player,
BoosConfigManager.getInteractBlockedMessage());
}
}

View File

@ -8,7 +8,7 @@ import org.bukkit.event.player.PlayerMoveEvent;
import cz.boosik.boosCooldown.Managers.BoosConfigManager;
import cz.boosik.boosCooldown.Managers.BoosWarmUpManager;
import util.boosChat;
import util.BoosChat;
public class BoosPlayerMoveListener implements Listener {
private int tempTimer = 0;
@ -25,7 +25,7 @@ public class BoosPlayerMoveListener implements Listener {
if (BoosWarmUpManager.hasWarmUps(player) && (event.getFrom().getX() != event.getTo().getX() || event.getFrom().getZ() != event
.getTo()
.getZ() || event.getFrom().getY() != event.getTo().getY())) {
boosChat.sendMessageToPlayer(player,
BoosChat.sendMessageToPlayer(player,
BoosConfigManager.getWarmUpCancelledByMoveMessage());
BoosWarmUpManager.cancelWarmUps(player);
}

View File

@ -8,7 +8,7 @@ import org.bukkit.event.player.PlayerToggleSneakEvent;
import cz.boosik.boosCooldown.Managers.BoosConfigManager;
import cz.boosik.boosCooldown.Managers.BoosWarmUpManager;
import util.boosChat;
import util.BoosChat;
public class BoosPlayerToggleSneakListener implements Listener {
@ -18,7 +18,7 @@ public class BoosPlayerToggleSneakListener implements Listener {
if (player != null
&& !player.hasPermission("booscooldowns.nocancel.sneak")) {
if (BoosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player,
BoosChat.sendMessageToPlayer(player,
BoosConfigManager.getCancelWarmupOnSneakMessage());
BoosWarmUpManager.cancelWarmUps(player);
}

View File

@ -8,7 +8,7 @@ import org.bukkit.event.player.PlayerToggleSprintEvent;
import cz.boosik.boosCooldown.Managers.BoosConfigManager;
import cz.boosik.boosCooldown.Managers.BoosWarmUpManager;
import util.boosChat;
import util.BoosChat;
public class BoosPlayerToggleSprintListener implements Listener {
@ -18,7 +18,7 @@ public class BoosPlayerToggleSprintListener implements Listener {
if (player != null
&& !player.hasPermission("booscooldowns.nocancel.sprint")) {
if (BoosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player,
BoosChat.sendMessageToPlayer(player,
BoosConfigManager.getCancelWarmupOnSprintMessage());
BoosWarmUpManager.cancelWarmUps(player);
}

View File

@ -7,7 +7,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;
import cz.boosik.boosCooldown.Managers.BoosConfigManager;
import util.boosChat;
import util.BoosChat;
public class BoosSignChangeListener implements Listener {
@ -20,7 +20,7 @@ public class BoosSignChangeListener implements Listener {
if (line2.equals("player")
&& !player
.hasPermission("booscooldowns.signs.player.place")) {
boosChat.sendMessageToPlayer(player,
BoosChat.sendMessageToPlayer(player,
BoosConfigManager.getCannotCreateSignMessage());
event.getBlock().breakNaturally();
event.setCancelled(true);
@ -28,7 +28,7 @@ public class BoosSignChangeListener implements Listener {
if (line2.equals("server")
&& !player
.hasPermission("booscooldowns.signs.server.place")) {
boosChat.sendMessageToPlayer(player,
BoosChat.sendMessageToPlayer(player,
BoosConfigManager.getCannotCreateSignMessage());
event.getBlock().breakNaturally();
event.setCancelled(true);

View File

@ -11,7 +11,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
import cz.boosik.boosCooldown.BoosCoolDown;
import cz.boosik.boosCooldown.Managers.BoosConfigManager;
import util.boosChat;
import util.BoosChat;
public class BoosSignInteractListener implements Listener {
private final BoosCoolDown plugin;
@ -57,7 +57,7 @@ public class BoosSignInteractListener implements Listener {
plugin.getServer().dispatchCommand(
plugin.getServer().getConsoleSender(), msg);
} else {
boosChat.sendMessageToPlayer(player,
BoosChat.sendMessageToPlayer(player,
BoosConfigManager.getCannotUseSignMessage());
}
}

View File

@ -13,7 +13,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import cz.boosik.boosCooldown.BoosCoolDown;
import util.boosChat;
import util.BoosChat;
public class BoosConfigManager {
@ -473,9 +473,9 @@ public class BoosConfigManager {
Boolean def = confusers.getBoolean("users." + player.getUniqueId() + ".confirmations", getConfirmCommandEnabled(player));
confusers.set("users." + player.getUniqueId() + ".confirmations", !def);
if (def) {
boosChat.sendMessageToPlayer(player, "&6[boosCooldowns]&e " + getConfirmToggleMessageFalse());
BoosChat.sendMessageToPlayer(player, "&6[boosCooldowns]&e " + getConfirmToggleMessageFalse());
} else {
boosChat.sendMessageToPlayer(player, "&6[boosCooldowns]&e " + getConfirmToggleMessageTrue());
BoosChat.sendMessageToPlayer(player, "&6[boosCooldowns]&e " + getConfirmToggleMessageTrue());
}
saveConfusers();
loadConfusers();
@ -501,6 +501,17 @@ public class BoosConfigManager {
return conf.getBoolean("options.options.item_cost_enabled", true);
}
public static boolean getPlayerPointsEnabled() {
return conf.getBoolean("options.options.player_points_prices_enabled", true);
}
public static int getPlayerPointsPrice(String regexCommand, Player player) {
int price;
String group = getCommandGroup(player);
price = conf.getInt("commands.groups." + group + "." + regexCommand + ".playerpoints", 0);
return price;
}
static String getPaidXPForCommandMessage() {
return conf.getString("options.messages.paid_xp_for_command", "&6Price of&e &command& &6was &e%s");
}
@ -531,6 +542,10 @@ public class BoosConfigManager {
return conf.getString("options.messages.insufficient_xp_requirement", "&6Your level is too low to use this!&e &command& &6needs &e%s");
}
public static String getInsufficientPlayerPointsMessage() {
return conf.getString("options.messages.insufficient_player_points", "'&6You have not enough PlayerPoints!&e &command& &6needs &e%s'");
}
public static String getInvalidCommandSyntaxMessage() {
return conf.getString("options.messages.invalid_command_syntax", "&6You are not allowed to use command syntax /<pluginname>:<command>!");
}
@ -662,6 +677,10 @@ public class BoosConfigManager {
return conf.getString("options.messages.confirmation_xp_price_of_command", "&6its price is&e &xpprice& experience levels");
}
public static String getItsPlayerPointsPriceMessage() {
return conf.getString("options.messages.confirmation_player_points_price_of_command", "&6its price is&e &ppprice& PlayerPoints &6and you now have &e&ppbalance& PlayerPoints");
}
public static String getCommandCanceledMessage() {
return conf.getString("options.messages.confirmation_command_cancelled", "&6Execution of command&e &command& &6was cancelled");
}
@ -678,4 +697,9 @@ public class BoosConfigManager {
return conf.getBoolean("options.options.command_confirmation", true);
}
}
public static String getPlayerPointsForCommandMessage() {
return conf.getString("options.messages.paid_player_points_for_command", "Price of &command& was %s PlayerPoints and you now have %s" +
" PlayerPoints");
}
}

View File

@ -8,7 +8,7 @@ import java.util.List;
import org.bukkit.entity.Player;
import util.boosChat;
import util.BoosChat;
public class BoosCoolDownManager {
@ -99,7 +99,7 @@ public class BoosCoolDownManager {
msg = msg.replaceAll("&unit&", "");
msg = msg.replaceAll(" +", " ");
boosChat.sendMessageToPlayer(player, msg);
BoosChat.sendMessageToPlayer(player, msg);
return true;
}
}
@ -199,7 +199,7 @@ public class BoosCoolDownManager {
msg = msg.replaceAll("&unit&", "");
msg = msg.replaceAll(" +", " ");
boosChat.sendMessageToPlayer(player, msg);
BoosChat.sendMessageToPlayer(player, msg);
return false;
}
}

View File

@ -14,7 +14,7 @@ import com.coloredcarrot.mcapi.json.JSON;
import com.coloredcarrot.mcapi.json.JSONColor;
import com.coloredcarrot.mcapi.json.JSONComponent;
import com.coloredcarrot.mcapi.json.JSONHoverAction;
import util.boosChat;
import util.BoosChat;
public class BoosItemCostManager {
@ -35,7 +35,7 @@ public class BoosItemCostManager {
BoosConfigManager.getPaidItemsForCommandMessage(), "");
JSON json = getItemStackJson(1, item, count, name, lore, enchants);
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
BoosChat.sendMessageToPlayer(player, msg);
json.send(player);
return true;
} else {

View File

@ -9,7 +9,7 @@ import java.util.Set;
import org.bukkit.entity.Player;
import cz.boosik.boosCooldown.BoosCoolDown;
import util.boosChat;
import util.BoosChat;
public class BoosLimitManager {
@ -75,7 +75,7 @@ public class BoosLimitManager {
msg = msg.replaceAll("&unit&",
BoosConfigManager.getUnitSecondsMessage());
}
boosChat.sendMessageToPlayer(player, msg);
BoosChat.sendMessageToPlayer(player, msg);
} else if (limitResetDelayGlobal > 0) {
if (confTime != null) {
callastTimeGlobal.setTime(confTime);
@ -101,12 +101,12 @@ public class BoosLimitManager {
msg = msg.replaceAll("&unit&",
BoosConfigManager.getUnitSecondsMessage());
}
boosChat.sendMessageToPlayer(player, msg);
BoosChat.sendMessageToPlayer(player, msg);
}
} else {
String msg = String.format(BoosConfigManager
.getCommandBlockedMessage());
boosChat.sendMessageToPlayer(player, msg);
BoosChat.sendMessageToPlayer(player, msg);
}
return true;
}
@ -157,7 +157,7 @@ public class BoosLimitManager {
message = message.replaceAll("&command&", comm);
message = message.replaceAll("&limit&", String.valueOf(lim));
message = message.replaceAll("&times&", String.valueOf(num));
boosChat.sendMessageToPlayer(send, message);
BoosChat.sendMessageToPlayer(send, message);
}
}

View File

@ -0,0 +1,51 @@
package cz.boosik.boosCooldown.Managers;
import org.black_ixx.playerpoints.PlayerPoints;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import cz.boosik.boosCooldown.BoosCoolDown;
import util.BoosChat;
public class BoosPlayerPointsManager {
private static final PlayerPoints playerPoints = BoosCoolDown.getPlayerPoints();
private static boolean payForCommand(Player player,
String originalCommand, int price) {
if (playerPoints == null) {
return true;
}
String msg = "";
if(playerPoints.getAPI().take(player.getUniqueId(), price)) {
msg = String.format(BoosConfigManager.getPlayerPointsForCommandMessage(),
price, playerPoints.getAPI().look(player.getUniqueId()));
msg = msg.replaceAll("&command&", originalCommand);
BoosChat.sendMessageToPlayer(player, msg);
return true;
} else {
msg = String.format(BoosConfigManager.getInsufficientPlayerPointsMessage(),
price, playerPoints.getAPI().look(player.getUniqueId()));
BoosChat.sendMessageToPlayer(player, msg);
return false;
}
}
public static void payForCommand(PlayerCommandPreprocessEvent event,
Player player, String regexCommand, String originalCommand,
int price) {
if (price > 0) {
if (!player.hasPermission("booscooldowns.noplayerpoints")
&& !player.hasPermission("booscooldowns.noplayerpoints."
+ originalCommand)) {
if (!payForCommand(player, originalCommand, price)) {
BoosCoolDownManager.cancelCooldown(player, regexCommand);
event.setCancelled(true);
}
}
}
}
public static boolean has(Player player, int price) {
return playerPoints == null || price <= 0 || playerPoints.getAPI().look(player.getUniqueId()) >= price;
}
}

View File

@ -6,7 +6,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import cz.boosik.boosCooldown.BoosCoolDown;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import util.boosChat;
import util.BoosChat;
public class BoosPriceManager {
private static final Economy economy = BoosCoolDown.getEconomy();
@ -22,12 +22,12 @@ public class BoosPriceManager {
msg = String.format(BoosConfigManager.getPaidForCommandMessage(),
economy.format(r.amount), economy.format(r.balance));
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
BoosChat.sendMessageToPlayer(player, msg);
return true;
} else {
msg = String.format(BoosConfigManager.getPaidErrorMessage(),
r.errorMessage);
boosChat.sendMessageToPlayer(player, msg);
BoosChat.sendMessageToPlayer(player, msg);
return false;
}
}

View File

@ -10,7 +10,7 @@ import org.bukkit.potion.PotionEffectType;
import cz.boosik.boosCooldown.BoosCoolDown;
import cz.boosik.boosCooldown.Runnables.BoosWarmUpTimer;
import util.boosChat;
import util.BoosChat;
public class BoosWarmUpManager {
@ -134,7 +134,7 @@ public class BoosWarmUpManager {
msg = msg.replaceAll("&unit&", "");
msg = msg.replaceAll(" +", " ");
boosChat.sendMessageToPlayer(player, msg);
BoosChat.sendMessageToPlayer(player, msg);
Timer scheduler = new Timer();
BoosWarmUpTimer scheduleMe = new BoosWarmUpTimer(bCoolDown, player, regexCommand, originalCommand);
@ -145,7 +145,7 @@ public class BoosWarmUpManager {
} else {
String msg = BoosConfigManager.getWarmUpAlreadyStartedMessage();
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
BoosChat.sendMessageToPlayer(player, msg);
}
}
}

View File

@ -3,7 +3,7 @@ package cz.boosik.boosCooldown.Managers;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import util.boosChat;
import util.BoosChat;
public class BoosXpCostManager {
@ -19,7 +19,7 @@ public class BoosXpCostManager {
String msg = String.format(BoosConfigManager.getPaidXPForCommandMessage(),
xpPrice);
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
BoosChat.sendMessageToPlayer(player, msg);
return true;
} else {
return false;

View File

@ -9,13 +9,13 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@SuppressWarnings("ALL")
public class boosChat {
public class BoosChat {
private static final Logger log = Logger.getLogger("Minecraft");
private static final List<String> Colors = new LinkedList<>();
private static Server server;
public boosChat(Server server) {
public BoosChat(Server server) {
Colors.add("&black&");
Colors.add("&darkblue&");
Colors.add("&darkgreen&");
@ -48,11 +48,11 @@ public class boosChat {
Colors.add("&d");
Colors.add("&e");
Colors.add("&f");
boosChat.server = server;
BoosChat.server = server;
}
public static void broadcastMessage(String message) {
message = boosChat.replaceColorCodes(message);
message = BoosChat.replaceColorCodes(message);
log.info("[bColoredChat] " + message);
server.broadcastMessage(message);
}
@ -86,19 +86,19 @@ public class boosChat {
public static void sendMessageToCommandSender(CommandSender sender,
String message) {
if (sender instanceof Player) {
boosChat.sendMessageToPlayer((Player) sender, message);
BoosChat.sendMessageToPlayer((Player) sender, message);
} else {
boosChat.sendMessageToServer(message);
BoosChat.sendMessageToServer(message);
}
}
public static void sendMessageToPlayer(Player player, String message) {
message = boosChat.replaceColorCodes(message);
message = BoosChat.replaceColorCodes(message);
player.sendMessage(message);
}
private static void sendMessageToServer(String message) {
message = boosChat.replaceColorCodes(message);
message = BoosChat.replaceColorCodes(message);
log.info(message);
}
}

View File

@ -10,6 +10,8 @@ options:
item_cost_enabled: true
#should xp costs be enabled?
xp_cost_enabled: true
#should player points prices be enabled?
player_points_prices_enabled: true
#should limits be enabled?
limits_enabled: true
#do not ever use this if you like your server
@ -69,9 +71,11 @@ options:
paid_for_command: '&6Price of&e &command& &6was&e %s &6and you now have&e %s'
paid_items_for_command: '&6Price of&e &command& &6was &e%s'
paid_xp_for_command: '&6Price of&e &command& &6was &e%s levels'
paid_player_points_for_command: '&6Price of&e &command& &6was &e%s PlayerPoints &6and you now have&e %s PlayerPoints'
insufficient_items: '&6You have not enough items!&e &command& &6needs &e%s'
insufficient_xp: '&6You have not enough XP!&e &command& &6needs &e%s'
insufficient_xp_requirement: '&6Your level is too low to use this!&e &command& &6needs &e%s'
insufficient_player_points: '&6You have not enough PlayerPoints!&e &command& &6needs &e%s'
limit_achieved: '&6You cannot use this command anymore!&f'
limit_reset: '&6Wait&e &seconds& &unit&&6 before your limit for command&e &command&
&6is reset.&f'
@ -87,6 +91,7 @@ options:
confirmation_item_price_of_command: '&6its price is&e &itemprice& &itemname&'
confirmation_limit_of_command: '&6it is limited to&e &limit& &6uses and you can still use it&e &uses& &6times'
confirmation_xp_price_of_command: '&6its price is&e &xpprice& experience levels'
confirmation_price_of_command: '&6its price is&e &ppprice& PlayerPoints &6and you now have &e&ppbalance& PlayerPoints'
confirmation_confirm_command_execution: 'Yes'
confirmation_confirm_command_execution_hint: 'Click to confirm'
confirmation_cancel_command_execution: 'No'
@ -99,6 +104,9 @@ commands:
groups:
#this group will work for all players without any booscooldowns permission
default:
/playerpointstest:
#PlayerPoints required to use this command
playerpoints: 5
/permissionstest:
#permission required to use this command
permission: "nice.permission"

View File

@ -2,7 +2,7 @@ name: boosCooldowns
main: cz.boosik.boosCooldown.BoosCoolDown
version: 3.13.0
authors: [LordBoos (boosik)]
softdepend: [Vault]
softdepend: [Vault, PlayerPoints]
description: >
Shortcuts
commands:
@ -60,6 +60,12 @@ permissions:
booscooldowns.noxpcost./command:
description: Command "/command" will not be affected by xp cost for users with this permission.
default: false
booscooldowns.noplayerpoints:
description: Players commands will always be free of charge (PlayerPoints).
default: false
booscooldowns.noplayerpoints./command:
description: Command "/command" will not be affected by price for users with this permission (PlayerPoints).
default: false
booscooldowns.nocooldown:
description: Player wont be affected by cooldowns.
default: false