mirror of
https://github.com/LordBoos/boosCooldowns.git
synced 2024-11-25 03:55:28 +01:00
fixed prices++itemcosts, fixed problems with $ symbol
This commit is contained in:
parent
c7ba601583
commit
3b658ddeda
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,6 +1,6 @@
|
||||
name: boosCooldowns
|
||||
main: cz.boosik.boosCooldown.BoosCoolDown
|
||||
version: 3.7.2
|
||||
version: 3.7.3
|
||||
authors: [LordBoos (ingame name boosik)]
|
||||
softdepend: [Vault]
|
||||
description: >
|
||||
|
@ -11,11 +11,11 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import util.boosChat;
|
||||
|
||||
/**
|
||||
* Hlavní posluchač, který naslouchá události použití příkazu hráčem.
|
||||
* Kontroluje, jestli jsou pro příkaz nastaveny omezení a na základě tohoto
|
||||
* spouští časovače a volá metody spojené s poplatky a limity.
|
||||
* Hlavn<EFBFBD> poslucha<EFBFBD>, kter<EFBFBD> naslouch<EFBFBD> ud<EFBFBD>losti pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu hr<EFBFBD><EFBFBD>em.
|
||||
* Kontroluje, jestli jsou pro p<EFBFBD><EFBFBD>kaz nastaveny omezen<EFBFBD> a na z<EFBFBD>klad<EFBFBD> tohoto
|
||||
* spou<EFBFBD>t<EFBFBD> <EFBFBD>asova<EFBFBD>e a vol<EFBFBD> metody spojen<EFBFBD> s poplatky a limity.
|
||||
*
|
||||
* @author Jakub Kolář
|
||||
* @author Jakub Kol<EFBFBD><EFBFBD>
|
||||
*
|
||||
*/
|
||||
public class BoosCoolDownListener implements Listener {
|
||||
@ -29,31 +29,32 @@ public class BoosCoolDownListener implements Listener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Metoda zkontroluje pomocí volání dalších metod, jestli přikaz který hráč
|
||||
* použil je nějakým způsobem omezený a na základě toho je buď událost
|
||||
* použití příkazu stornována, nebo ne.
|
||||
* Metoda zkontroluje pomoc<EFBFBD> vol<EFBFBD>n<EFBFBD> dal<EFBFBD><EFBFBD>ch metod, jestli p<EFBFBD>ikaz kter<EFBFBD> hr<EFBFBD><EFBFBD>
|
||||
* pou<EFBFBD>il je n<EFBFBD>jak<EFBFBD>m zp<EFBFBD>sobem omezen<EFBFBD> a na z<EFBFBD>klad<EFBFBD> toho je bu<EFBFBD> ud<EFBFBD>lost
|
||||
* pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu stornov<EFBFBD>na, nebo ne.
|
||||
*
|
||||
* @param event
|
||||
* událost PlayerCommandPreprocessEvent
|
||||
* ud<EFBFBD>lost PlayerCommandPreprocessEvent
|
||||
* @param player
|
||||
* hráč který spustil tuto událost
|
||||
* hr<EFBFBD><EFBFBD> kter<EFBFBD> spustil tuto ud<EFBFBD>lost
|
||||
* @param regexCommad
|
||||
* příkaz z konfiguračního souboru, který vyhovuje originálnímu
|
||||
* příkazu
|
||||
* p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu
|
||||
* p<EFBFBD><EFBFBD>kazu
|
||||
* @param originalCommand
|
||||
* originální příkaz který hráč použil
|
||||
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz kter<EFBFBD> hr<EFBFBD><EFBFBD> pou<EFBFBD>il
|
||||
* @param warmupTime
|
||||
* warmup doba nastavená pro regexCommand
|
||||
* warmup doba nastaven<EFBFBD> pro regexCommand
|
||||
* @param cooldownTime
|
||||
* cooldown doba nastavená pro regexCommand
|
||||
* cooldown doba nastaven<EFBFBD> pro regexCommand
|
||||
* @param price
|
||||
* cena nastavená pro regexCommand
|
||||
* cena nastaven<EFBFBD> pro regexCommand
|
||||
* @param limit
|
||||
* limit nastavený pro regexCommand
|
||||
* limit nastaven<EFBFBD> pro regexCommand
|
||||
*/
|
||||
private void checkRestrictions(PlayerCommandPreprocessEvent event,
|
||||
Player player, String regexCommad, String originalCommand,
|
||||
int warmupTime, int cooldownTime, double price, String item, int count, int limit) {
|
||||
int warmupTime, int cooldownTime, double price, String item,
|
||||
int count, int limit) {
|
||||
boolean blocked = BoosLimitManager.blocked(player, regexCommad,
|
||||
originalCommand, limit);
|
||||
if (!blocked) {
|
||||
@ -70,16 +71,47 @@ public class BoosCoolDownListener implements Listener {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
if (!event.isCancelled()) {
|
||||
BoosPriceManager.payForCommand(event, player, regexCommad,
|
||||
originalCommand, price);
|
||||
if (BoosPriceManager.has(player, price)
|
||||
& BoosItemCostManager.has(player, item, count)) {
|
||||
if (!event.isCancelled()) {
|
||||
BoosPriceManager.payForCommand(event, player, regexCommad,
|
||||
originalCommand, price);
|
||||
}
|
||||
if (!event.isCancelled()) {
|
||||
BoosItemCostManager.payItemForCommand(event, player,
|
||||
regexCommad, originalCommand, item, count);
|
||||
}
|
||||
} else {
|
||||
if (!BoosPriceManager.has(player, price) & !BoosWarmUpManager.isWarmUpProcess(player, regexCommad)) {
|
||||
String unit;
|
||||
String msg = "";
|
||||
if (price == 1) {
|
||||
unit = BoosCoolDown.getEconomy().currencyNameSingular();
|
||||
} else {
|
||||
unit = BoosCoolDown.getEconomy().currencyNamePlural();
|
||||
}
|
||||
msg = String.format(
|
||||
BoosConfigManager.getInsufficientFundsMessage(),
|
||||
(price + " " + unit),
|
||||
BoosCoolDown.getEconomy().format(
|
||||
BoosCoolDown.getEconomy().getBalance(
|
||||
player.getName())));
|
||||
msg = msg.replaceAll("&command&", originalCommand);
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
}
|
||||
if (!BoosItemCostManager.has(player, item, count) & !BoosWarmUpManager.isWarmUpProcess(player, regexCommad)) {
|
||||
String msg = "";
|
||||
msg = String.format(
|
||||
BoosConfigManager.getInsufficientItemsMessage(),
|
||||
(count + " " + item));
|
||||
msg = msg.replaceAll("&command&", originalCommand);
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if (!event.isCancelled()) {
|
||||
BoosItemCostManager.payItemForCommand(event, player, regexCommad,
|
||||
originalCommand, item, count);
|
||||
}
|
||||
if (!event.isCancelled()) {
|
||||
String msg = String.format(BoosConfigManager.getMessage(regexCommad, player));
|
||||
String msg = String.format(BoosConfigManager.getMessage(
|
||||
regexCommad, player));
|
||||
if (!msg.equals("")) {
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
}
|
||||
@ -99,15 +131,15 @@ public class BoosCoolDownListener implements Listener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Posluchač, který naslouchá události použití příkazu a spouští se ještě
|
||||
* před tím, než je vykonán efekt tohto příkazu. Metoda zjišťuje, jestli
|
||||
* příkaz není alias jiného příkazu a také jestli se příkaz který hráč
|
||||
* použil shoduje s příkazem nastaveným v konfiguraci. Pokud se shoduje, pak
|
||||
* jsou načteny informace o warmup době, cooldown době, poplatku a limitu.
|
||||
* Tyto hodnoty jsou poté předány metodě checkRestrictions();.
|
||||
* Poslucha<EFBFBD>, kter<EFBFBD> naslouch<EFBFBD> ud<EFBFBD>losti pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu a spou<EFBFBD>t<EFBFBD> se je<EFBFBD>t<EFBFBD>
|
||||
* p<EFBFBD>ed t<EFBFBD>m, ne<EFBFBD> je vykon<EFBFBD>n efekt tohto p<EFBFBD><EFBFBD>kazu. Metoda zji<EFBFBD><EFBFBD>uje, jestli
|
||||
* p<EFBFBD><EFBFBD>kaz nen<EFBFBD> alias jin<EFBFBD>ho p<EFBFBD><EFBFBD>kazu a tak<EFBFBD> jestli se p<EFBFBD><EFBFBD>kaz kter<EFBFBD> hr<EFBFBD><EFBFBD>
|
||||
* pou<EFBFBD>il shoduje s p<EFBFBD><EFBFBD>kazem nastaven<EFBFBD>m v konfiguraci. Pokud se shoduje, pak
|
||||
* jsou na<EFBFBD>teny informace o warmup dob<EFBFBD>, cooldown dob<EFBFBD>, poplatku a limitu.
|
||||
* Tyto hodnoty jsou pot<EFBFBD> p<EFBFBD>ed<EFBFBD>ny metod<EFBFBD> checkRestrictions();.
|
||||
*
|
||||
* @param event
|
||||
* událost PlayerCommandPreprocessEvent
|
||||
* ud<EFBFBD>lost PlayerCommandPreprocessEvent
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
private void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
@ -116,7 +148,9 @@ public class BoosCoolDownListener implements Listener {
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
String originalCommand = event.getMessage().replace("\\", "\\\\");
|
||||
originalCommand = originalCommand.trim().replaceAll(" +", " ").toLowerCase();
|
||||
originalCommand = originalCommand.replace("$", "S");
|
||||
originalCommand = originalCommand.trim().replaceAll(" +", " ")
|
||||
.toLowerCase();
|
||||
String regexCommad = "";
|
||||
Set<String> aliases = BoosConfigManager.getAliases();
|
||||
Set<String> commands = BoosConfigManager.getCommands(player);
|
||||
@ -163,8 +197,10 @@ public class BoosCoolDownListener implements Listener {
|
||||
price = BoosConfigManager.getPrice(regexCommad, player);
|
||||
}
|
||||
if (BoosConfigManager.getItemCostEnabled()) {
|
||||
item = BoosConfigManager.getItemCostItem(regexCommad, player);
|
||||
count = BoosConfigManager.getItemCostCount(regexCommad, player);
|
||||
item = BoosConfigManager.getItemCostItem(regexCommad,
|
||||
player);
|
||||
count = BoosConfigManager.getItemCostCount(regexCommad,
|
||||
player);
|
||||
}
|
||||
if (BoosConfigManager.getLimitEnabled()) {
|
||||
limit = BoosConfigManager.getLimit(regexCommad, player);
|
||||
@ -178,22 +214,22 @@ public class BoosCoolDownListener implements Listener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Metoda spouští warmup a cooldown časovače, případně je ukončuje, pokud
|
||||
* již tyto časovače skončili.
|
||||
* Metoda spou<EFBFBD>t<EFBFBD> warmup a cooldown <EFBFBD>asova<EFBFBD>e, p<EFBFBD><EFBFBD>padn<EFBFBD> je ukon<EFBFBD>uje, pokud
|
||||
* ji<EFBFBD> tyto <EFBFBD>asova<EFBFBD>e skon<EFBFBD>ili.
|
||||
*
|
||||
* @param event
|
||||
* událost PlayerCommandPreprocessEvent
|
||||
* ud<EFBFBD>lost PlayerCommandPreprocessEvent
|
||||
* @param player
|
||||
* hráč který spustil tuto událost
|
||||
* hr<EFBFBD><EFBFBD> kter<EFBFBD> spustil tuto ud<EFBFBD>lost
|
||||
* @param regexCommad
|
||||
* příkaz z konfiguračního souboru, který vyhovuje originálnímu
|
||||
* příkazu
|
||||
* p<EFBFBD><EFBFBD>kaz z konfigura<EFBFBD>n<EFBFBD>ho souboru, kter<EFBFBD> vyhovuje origin<EFBFBD>ln<EFBFBD>mu
|
||||
* p<EFBFBD><EFBFBD>kazu
|
||||
* @param originalCommand
|
||||
* originální příkaz který hráč použil
|
||||
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz kter<EFBFBD> hr<EFBFBD><EFBFBD> pou<EFBFBD>il
|
||||
* @param warmupTime
|
||||
* warmup doba nastavená pro regexCommand
|
||||
* warmup doba nastaven<EFBFBD> pro regexCommand
|
||||
* @param cooldownTime
|
||||
* cooldown doba nastavená pro regexCommand
|
||||
* cooldown doba nastaven<EFBFBD> pro regexCommand
|
||||
*/
|
||||
private void start(PlayerCommandPreprocessEvent event, Player player,
|
||||
String regexCommad, String originalCommand, int warmupTime,
|
||||
|
@ -1,4 +1,5 @@
|
||||
package cz.boosik.boosCooldown;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
@ -26,7 +27,7 @@ public class BoosItemCostManager {
|
||||
* pøíkaz z konfigurace vyhovující originálnímu pøíkazu
|
||||
* @param originalCommand
|
||||
* originální pøíkaz použitý hráèem
|
||||
* @param item
|
||||
* @param item
|
||||
* @param price
|
||||
* cena použití pøíkazu
|
||||
* @param name
|
||||
@ -40,23 +41,24 @@ public class BoosItemCostManager {
|
||||
Material material = Material.getMaterial(item);
|
||||
Inventory inventory = player.getInventory();
|
||||
Boolean trans = false;
|
||||
if(inventory.contains(material, count)){
|
||||
if (inventory.contains(material, count)) {
|
||||
ItemStack itemstack = new ItemStack(material, count);
|
||||
inventory.removeItem(itemstack);
|
||||
trans = true;
|
||||
}
|
||||
if (trans) {
|
||||
msg = String.format(BoosConfigManager.getPaidItemsForCommandMessage(),
|
||||
count+" "+ item);
|
||||
msg = String.format(
|
||||
BoosConfigManager.getPaidItemsForCommandMessage(), count
|
||||
+ " " + item);
|
||||
msg = msg.replaceAll("&command&", originalCommand);
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
return true;
|
||||
} else {
|
||||
msg = String.format(
|
||||
BoosConfigManager.getInsufficientItemsMessage(), (count
|
||||
+ " " + item));
|
||||
msg = msg.replaceAll("&command&", originalCommand);
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
// msg = String.format(
|
||||
// BoosConfigManager.getInsufficientItemsMessage(), (count
|
||||
// + " " + item));
|
||||
// msg = msg.replaceAll("&command&", originalCommand);
|
||||
// boosChat.sendMessageToPlayer(player, msg);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -74,7 +76,7 @@ public class BoosItemCostManager {
|
||||
* pøíkaz z konfigurace vyhovující originálnímu pøíkazu
|
||||
* @param originalCommand
|
||||
* originální pøíkaz použitý hráèem
|
||||
* @param item
|
||||
* @param item
|
||||
* @param price
|
||||
* cena použití pøíkazu
|
||||
*/
|
||||
@ -86,8 +88,8 @@ public class BoosItemCostManager {
|
||||
if (!player.hasPermission("booscooldowns.noitemcost")
|
||||
&& !player.hasPermission("booscooldowns.noitemcost."
|
||||
+ originalCommand)) {
|
||||
if (payItemForCommand(player, regexCommand, originalCommand, item, count,
|
||||
name)) {
|
||||
if (payItemForCommand(player, regexCommand, originalCommand,
|
||||
item, count, name)) {
|
||||
return;
|
||||
} else {
|
||||
BoosCoolDownManager.cancelCooldown(player, regexCommand);
|
||||
@ -97,4 +99,16 @@ public class BoosItemCostManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean has(Player player, String item, int count) {
|
||||
if (item.equals("")) {
|
||||
return true;
|
||||
}
|
||||
Material material = Material.getMaterial(item);
|
||||
Inventory inventory = player.getInventory();
|
||||
if (inventory.contains(material, count)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -50,16 +50,16 @@ public class BoosPriceManager {
|
||||
return true;
|
||||
} else {
|
||||
if (r.errorMessage.equals("Insufficient funds")) {
|
||||
String unit;
|
||||
if (price == 1) {
|
||||
unit = economy.currencyNameSingular();
|
||||
} else {
|
||||
unit = economy.currencyNamePlural();
|
||||
}
|
||||
msg = String.format(
|
||||
BoosConfigManager.getInsufficientFundsMessage(), (price
|
||||
+ " " + unit), economy.format(r.balance));
|
||||
msg = msg.replaceAll("&command&", originalCommand);
|
||||
// String unit;
|
||||
// if (price == 1) {
|
||||
// unit = economy.currencyNameSingular();
|
||||
// } else {
|
||||
// unit = economy.currencyNamePlural();
|
||||
// }
|
||||
// msg = String.format(
|
||||
// BoosConfigManager.getInsufficientFundsMessage(), (price
|
||||
// + " " + unit), economy.format(r.balance));
|
||||
// msg = msg.replaceAll("&command&", originalCommand);
|
||||
} else {
|
||||
msg = String.format(BoosConfigManager.getPaidErrorMessage(),
|
||||
r.errorMessage);
|
||||
@ -104,4 +104,8 @@ public class BoosPriceManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean has(Player player, double price) {
|
||||
return economy.has(player.getName(), price);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: boosCooldowns
|
||||
main: cz.boosik.boosCooldown.BoosCoolDown
|
||||
version: 3.7.2
|
||||
version: 3.7.3
|
||||
authors: [LordBoos (ingame name boosik)]
|
||||
softdepend: [Vault]
|
||||
description: >
|
||||
|
Loading…
Reference in New Issue
Block a user