Add xp requirements
This commit is contained in:
parent
0b6b6cd637
commit
636179c597
|
@ -35,17 +35,17 @@ import cz.boosik.boosCooldown.Managers.BoosXpCostManager;
|
|||
import util.boosChat;
|
||||
|
||||
public class BoosCoolDownListener implements Listener {
|
||||
public static Map<String, Boolean> commandQueue = new ConcurrentHashMap();
|
||||
public static Map<String, Boolean> commandQueue = new ConcurrentHashMap<>();
|
||||
private static BoosCoolDown plugin;
|
||||
|
||||
public BoosCoolDownListener(BoosCoolDown instance) {
|
||||
BoosCoolDownListener(BoosCoolDown instance) {
|
||||
plugin = instance;
|
||||
}
|
||||
|
||||
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 count, String name, List<String> lore, List<String> enchants, int limit, int xpPrice, int xpRequirement) {
|
||||
boolean blocked = false;
|
||||
String perm = BoosConfigManager.getPermission(player, regexCommad);
|
||||
if (!(perm == null)) {
|
||||
|
@ -71,7 +71,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, xpPrice)
|
||||
& BoosXpCostManager.has(player, xpRequirement)) {
|
||||
if (BoosCoolDownManager.coolDown(player, regexCommad,
|
||||
originalCommand, cooldownTime)) {
|
||||
event.setCancelled(true);
|
||||
|
@ -79,7 +80,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, xpPrice)
|
||||
& BoosXpCostManager.has(player, xpRequirement)) {
|
||||
if (!event.isCancelled()) {
|
||||
BoosPriceManager.payForCommand(event, player, regexCommad,
|
||||
originalCommand, price);
|
||||
|
@ -97,7 +99,7 @@ public class BoosCoolDownListener implements Listener {
|
|||
boolean cooldownInProgress = BoosCoolDownManager.isCoolingdown(player, regexCommad, cooldownTime);
|
||||
if (!BoosPriceManager.has(player, price)
|
||||
&& !warmupInProgress && !cooldownInProgress) {
|
||||
String msg = "";
|
||||
String msg;
|
||||
msg = String.format(
|
||||
BoosConfigManager.getInsufficientFundsMessage(),
|
||||
BoosCoolDown.getEconomy().format(price),
|
||||
|
@ -109,7 +111,7 @@ public class BoosCoolDownListener implements Listener {
|
|||
}
|
||||
if (!BoosItemCostManager.has(player, item, count, name, lore, enchants)
|
||||
&& !warmupInProgress && !cooldownInProgress) {
|
||||
String msg = "";
|
||||
String msg;
|
||||
msg = String.format(
|
||||
BoosConfigManager.getInsufficientItemsMessage(), "");
|
||||
JSON json = getItemStackJson(1, item, count, name, lore, enchants);
|
||||
|
@ -117,9 +119,18 @@ public class BoosCoolDownListener implements Listener {
|
|||
boosChat.sendMessageToPlayer(player, msg);
|
||||
json.send(player);
|
||||
}
|
||||
if (!BoosXpCostManager.has(player, xpRequirement)
|
||||
&& !warmupInProgress && !cooldownInProgress) {
|
||||
String msg;
|
||||
msg = String.format(
|
||||
BoosConfigManager.getInsufficientXpRequirementMessage(),
|
||||
(xpRequirement));
|
||||
msg = msg.replaceAll("&command&", originalCommand);
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
}
|
||||
if (!BoosXpCostManager.has(player, xpPrice)
|
||||
&& !warmupInProgress && !cooldownInProgress) {
|
||||
String msg = "";
|
||||
String msg;
|
||||
msg = String.format(
|
||||
BoosConfigManager.getInsufficientXpMessage(),
|
||||
(xpPrice));
|
||||
|
@ -129,8 +140,8 @@ public class BoosCoolDownListener implements Listener {
|
|||
event.setCancelled(true);
|
||||
}
|
||||
if (!event.isCancelled()) {
|
||||
String msg = String.format(BoosConfigManager.getMessage(
|
||||
regexCommad, player));
|
||||
String msg = BoosConfigManager.getMessage(
|
||||
regexCommad, player);
|
||||
if (!msg.equals("")) {
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
}
|
||||
|
@ -211,6 +222,7 @@ public class BoosCoolDownListener implements Listener {
|
|||
int limit = -1;
|
||||
int cooldownTime = 0;
|
||||
int xpPrice = 0;
|
||||
int xpRequirement = 0;
|
||||
on = BoosCoolDown.isPluginOnForPlayer(player);
|
||||
if (aliases != null) {
|
||||
originalCommand = BoosAliasManager.checkCommandAlias(
|
||||
|
@ -236,6 +248,7 @@ public class BoosCoolDownListener implements Listener {
|
|||
if (BoosConfigManager.getXpPriceEnabled()) {
|
||||
xpPrice = BoosConfigManager.getXpPrice(regexCommad,
|
||||
player);
|
||||
xpRequirement = BoosConfigManager.getXpRequirement(regexCommad, player);
|
||||
}
|
||||
if (BoosConfigManager.getItemCostEnabled()) {
|
||||
item = BoosConfigManager.getItemCostItem(regexCommad,
|
||||
|
@ -260,7 +273,7 @@ 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);
|
||||
xpPrice, xpRequirement);
|
||||
} else {
|
||||
if ((price > 0 || xpPrice > 0 || count > 0 || limit > 0) && !BoosWarmUpManager.isWarmUpProcess(player,
|
||||
regexCommad) && !BoosCoolDownManager.isCoolingdown(player, regexCommad, cooldownTime)) {
|
||||
|
@ -306,7 +319,6 @@ public class BoosCoolDownListener implements Listener {
|
|||
yes.setColor(JSONColor.GREEN).setBold(true);
|
||||
yes.setClickAction(yesClick);
|
||||
yes.setHoverAction(yesHover);
|
||||
String test = yes.get();
|
||||
yes.send(player);
|
||||
|
||||
String noString = BoosConfigManager.getCancelCommandMessage();
|
||||
|
@ -323,7 +335,7 @@ public class BoosCoolDownListener implements Listener {
|
|||
} else {
|
||||
this.checkRestrictions(event, player, regexCommad, originalCommand,
|
||||
warmupTime, cooldownTime, price, item, count, name, lore, enchants, limit,
|
||||
xpPrice);
|
||||
xpPrice, xpRequirement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -512,6 +512,13 @@ public class BoosConfigManager {
|
|||
return price;
|
||||
}
|
||||
|
||||
public static int getXpRequirement(String regexCommand, Player player) {
|
||||
int price;
|
||||
String group = getCommandGroup(player);
|
||||
price = conf.getInt("commands.groups." + group + "." + regexCommand + ".xprequirement", 0);
|
||||
return price;
|
||||
}
|
||||
|
||||
public static boolean getXpPriceEnabled() {
|
||||
return conf.getBoolean("options.options.xp_cost_enabled", true);
|
||||
}
|
||||
|
@ -520,6 +527,10 @@ public class BoosConfigManager {
|
|||
return conf.getString("options.messages.insufficient_xp", "&6You have not enough XP!&e &command& &6needs &e%s");
|
||||
}
|
||||
|
||||
public static String getInsufficientXpRequirementMessage() {
|
||||
return conf.getString("options.messages.insufficient_xp_requirement", "&6Your level is too low to use this!&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>!");
|
||||
}
|
||||
|
|
|
@ -34,8 +34,7 @@ public class BoosWarmUpManager {
|
|||
}
|
||||
|
||||
public static void cancelWarmUps(Player player) {
|
||||
Map<String, BoosWarmUpTimer> playercommands2 = playercommands;
|
||||
Iterator<String> iter = playercommands2.keySet().iterator();
|
||||
Iterator<String> iter = ((Map<String, BoosWarmUpTimer>) playercommands).keySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
if (iter.next().startsWith(player.getUniqueId() + "@")) {
|
||||
killTimer(player);
|
||||
|
@ -45,8 +44,7 @@ public class BoosWarmUpManager {
|
|||
}
|
||||
|
||||
public static boolean hasWarmUps(Player player) {
|
||||
Map<String, BoosWarmUpTimer> playercommands2 = playercommands;
|
||||
for (String key : playercommands2.keySet()) {
|
||||
for (String key : ((Map<String, BoosWarmUpTimer>) playercommands).keySet()) {
|
||||
if (key.startsWith(player.getUniqueId() + "@")) {
|
||||
return true;
|
||||
}
|
||||
|
@ -69,8 +67,7 @@ public class BoosWarmUpManager {
|
|||
}
|
||||
|
||||
private static void killTimer(Player player) {
|
||||
Map<String, BoosWarmUpTimer> playercommands2 = playercommands;
|
||||
for (String key : playercommands2.keySet()) {
|
||||
for (String key : ((Map<String, BoosWarmUpTimer>) playercommands).keySet()) {
|
||||
if (key.startsWith(player.getUniqueId() + "@")) {
|
||||
playercommands.get(key).cancel();
|
||||
}
|
||||
|
|
|
@ -71,6 +71,7 @@ options:
|
|||
paid_xp_for_command: '&6Price of&e &command& &6was &e%s levels'
|
||||
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'
|
||||
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'
|
||||
|
@ -213,6 +214,9 @@ commands:
|
|||
/testxpcommand:
|
||||
#this command costs 5 experience levels to be used
|
||||
xpcost: 5
|
||||
/testxpreq:
|
||||
#this command needs player to have 30 experience levels to be used, but does not take experience levels from player
|
||||
xprequirement: 30
|
||||
#this group will only work for players that have booscooldowns.vip permission (player can only have one group at a time and no inheritance is possible atm
|
||||
vip:
|
||||
/command *:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: boosCooldowns
|
||||
main: cz.boosik.boosCooldown.BoosCoolDown
|
||||
version: 3.11.4
|
||||
version: 3.12.0
|
||||
authors: [LordBoos (boosik)]
|
||||
softdepend: [Vault]
|
||||
description: >
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -11,7 +11,7 @@
|
|||
<packaging>pom</packaging>
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
<boosCooldowns.version>3.11.4</boosCooldowns.version>
|
||||
<boosCooldowns.version>3.12.0</boosCooldowns.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<minecraft.version>1.10</minecraft.version>
|
||||
|
|
Loading…
Reference in New Issue