optimisation

This commit is contained in:
Boosik 2015-01-24 15:22:02 +01:00
parent bd6d6859a6
commit 046df72e38
7 changed files with 342 additions and 327 deletions

View File

@ -111,8 +111,13 @@ public class BoosConfigManager {
* @return
*/
static Set<String> getAliases() {
Set<String> aliases = conf.getConfigurationSection("commands.aliases")
.getKeys(false);
Set<String> aliases = null;
ConfigurationSection aliasesSection = conf
.getConfigurationSection("commands.aliases");
if (aliasesSection != null) {
aliases = conf.getConfigurationSection("commands.aliases").getKeys(
false);
}
return aliases;
}
@ -248,9 +253,12 @@ public class BoosConfigManager {
*/
static String getCommandGroup(Player player) {
String cmdGroup = "default";
for (String group : getCommandGroups()) {
if (player.hasPermission("booscooldowns." + group)) {
cmdGroup = group;
Set<String> groups = getCommandGroups();
if (groups != null) {
for (String group : groups) {
if (player.hasPermission("booscooldowns." + group)) {
cmdGroup = group;
}
}
}
return cmdGroup;
@ -260,8 +268,12 @@ public class BoosConfigManager {
* @return
*/
static Set<String> getCommandGroups() {
Set<String> groups = conf.getConfigurationSection("commands.groups")
.getKeys(false);
ConfigurationSection groupsSection = conf
.getConfigurationSection("commands.groups");
Set<String> groups = null;
if (groupsSection != null) {
groups = groupsSection.getKeys(false);
}
return groups;
}
@ -278,8 +290,12 @@ public class BoosConfigManager {
*/
static Set<String> getCommands(Player player) {
String group = getCommandGroup(player);
Set<String> commands = conf.getConfigurationSection(
"commands.groups." + group).getKeys(false);
Set<String> commands = null;
ConfigurationSection commandsSection = conf
.getConfigurationSection("commands.groups." + group);
if (commandsSection != null) {
commands = commandsSection.getKeys(false);
}
return commands;
}
@ -861,7 +877,7 @@ public class BoosConfigManager {
static int parseTime(String time) {
String[] timeString = time.split(" ", 2);
if (timeString[0].equals("cancel")){
if (timeString[0].equals("cancel")) {
return -65535;
}
int timeNumber = Integer.valueOf(timeString[0]);
@ -886,9 +902,7 @@ public class BoosConfigManager {
}
public static String getLimitResetNowMessage() {
return conf
.getString(
"options.messages.limit_reset_now",
"&6Reseting limits for command&e &command& &6now.&f");
return conf.getString("options.messages.limit_reset_now",
"&6Reseting limits for command&e &command& &6now.&f");
}
}

View File

@ -57,8 +57,11 @@ public class BoosCoolDownListener implements Listener {
Player player, String regexCommad, String originalCommand,
int warmupTime, int cooldownTime, double price, String item,
int count, int limit, int xpPrice) {
boolean blocked = BoosLimitManager.blocked(player, regexCommad,
originalCommand, limit);
boolean blocked = false;
if (limit != -1) {
blocked = BoosLimitManager.blocked(player, regexCommad,
originalCommand, limit);
}
if (!blocked) {
if (warmupTime > 0) {
if (!player.hasPermission("booscooldowns.nowarmup")
@ -180,15 +183,7 @@ public class BoosCoolDownListener implements Listener {
originalCommand = originalCommand.replace("$", "S");
originalCommand = originalCommand.trim().replaceAll(" +", " ");
String regexCommad = "";
Set<String> aliases = null;
try {
aliases = BoosConfigManager.getAliases();
} catch (Exception e1) {
BoosCoolDown
.getLog()
.warning(
"Aliases section in config.yml is missing! Please delete your config.yml, restart server and set it again!");
}
Set<String> aliases = BoosConfigManager.getAliases();
Set<String> commands = BoosConfigManager.getCommands(player);
boolean on = true;
String item = "";
@ -199,10 +194,12 @@ public class BoosCoolDownListener implements Listener {
int cooldownTime = 0;
int xpPrice = 0;
on = BoosCoolDown.isPluginOnForPlayer(player);
originalCommand = BoosAliasManager.checkCommandAlias(originalCommand,
aliases, player);
event.setMessage(originalCommand);
if (on) {
if (aliases != null) {
originalCommand = BoosAliasManager.checkCommandAlias(
originalCommand, aliases, player);
event.setMessage(originalCommand);
}
if (on && commands != null) {
for (String group : commands) {
String group2 = group.replace("*", ".+");
if (originalCommand.matches("(?i)" + group2)) {
@ -237,14 +234,6 @@ public class BoosCoolDownListener implements Listener {
this.checkRestrictions(event, player, regexCommad, originalCommand,
warmupTime, cooldownTime, price, item, count, limit,
xpPrice);
try {
} catch (Exception e) {
BoosCoolDown
.getLog()
.warning(
"[boosCooldowns] Looks like you have deleted some important part of config file (like default group or aliases section. To get rid of this message, you have to restore it.");
return;
}
}
}

View File

@ -1,114 +1,117 @@
package cz.boosik.boosCooldown;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import util.boosChat;
/**
* T<EFBFBD><EFBFBD>da obsahuje ve<EFBFBD>ker<EFBFBD> metody pot<EFBFBD>ebn<EFBFBD> k <EFBFBD><EFBFBD>zen<EFBFBD> poplatk<EFBFBD> za p<EFBFBD><EFBFBD>kazy.
*
* @author Jakub Kol<EFBFBD><EFBFBD>
*
*/
public class BoosItemCostManager {
private static String msg = "";
/**
* Metoda zaji<EFBFBD><EFBFBD>uje funkci platby za p<EFBFBD><EFBFBD>kaz. Vrac<EFBFBD> hodnotu v z<EFBFBD>vislosti na
* <EFBFBD>sp<EFBFBD>nosti platby.
*
* @param player
* specifikovan<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
* @param originalCommand
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
* @param item
* @param price
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
* @param name
* jm<EFBFBD>no specifick<EFBFBD>ho hr<EFBFBD><EFBFBD>e
* @return true pokud byl <EFBFBD>sp<EFBFBD>n<EFBFBD> zaplacen poplatek, nebo pokud nebyl nalezen
* ekonomick<EFBFBD> plugin; false pokud do<EFBFBD>lo k chyb<EFBFBD> nebo hr<EFBFBD><EFBFBD> nem<EFBFBD>l
* dostatek financ<EFBFBD>
*/
static boolean payItemForCommand(Player player, String regexCommand,
String originalCommand, String item, int count, String name) {
Material material = Material.getMaterial(item);
Inventory inventory = player.getInventory();
Boolean trans = false;
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 = 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);
return false;
}
}
/**
* Metoda ukon<EFBFBD>uje/neukon<EFBFBD>uje ud<EFBFBD>lost pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu v z<EFBFBD>vislosti na tom,
* jakou hodnotu vr<EFBFBD>tila metoda payForCommand(Player player, String
* regexCommand, String originalCommand, double price, String name);.
*
* @param event
* ud<EFBFBD>lost PlayerCommandPreprocessEvent
* @param player
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
* @param originalCommand
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
* @param item
* @param price
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
*/
static void payItemForCommand(PlayerCommandPreprocessEvent event,
Player player, String regexCommand, String originalCommand,
String item, int count) {
String name = player.getName();
if (count > 0) {
if (!player.hasPermission("booscooldowns.noitemcost")
&& !player.hasPermission("booscooldowns.noitemcost."
+ originalCommand)) {
if (payItemForCommand(player, regexCommand, originalCommand,
item, count, name)) {
return;
} else {
BoosCoolDownManager.cancelCooldown(player, regexCommand);
event.setCancelled(true);
return;
}
}
}
}
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;
}
}
package cz.boosik.boosCooldown;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import util.boosChat;
/**
* T<EFBFBD><EFBFBD>da obsahuje ve<EFBFBD>ker<EFBFBD> metody pot<EFBFBD>ebn<EFBFBD> k <EFBFBD><EFBFBD>zen<EFBFBD> poplatk<EFBFBD> za p<EFBFBD><EFBFBD>kazy.
*
* @author Jakub Kol<EFBFBD><EFBFBD>
*
*/
public class BoosItemCostManager {
private static String msg = "";
/**
* Metoda zaji<EFBFBD><EFBFBD>uje funkci platby za p<EFBFBD><EFBFBD>kaz. Vrac<EFBFBD> hodnotu v z<EFBFBD>vislosti na
* <EFBFBD>sp<EFBFBD>nosti platby.
*
* @param player
* specifikovan<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
* @param originalCommand
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
* @param item
* @param price
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
* @param name
* jm<EFBFBD>no specifick<EFBFBD>ho hr<EFBFBD><EFBFBD>e
* @return true pokud byl <EFBFBD>sp<EFBFBD>n<EFBFBD> zaplacen poplatek, nebo pokud nebyl nalezen
* ekonomick<EFBFBD> plugin; false pokud do<EFBFBD>lo k chyb<EFBFBD> nebo hr<EFBFBD><EFBFBD> nem<EFBFBD>l
* dostatek financ<EFBFBD>
*/
static boolean payItemForCommand(Player player, String regexCommand,
String originalCommand, String item, int count, String name) {
Material material = Material.getMaterial(item);
Inventory inventory = player.getInventory();
Boolean trans = false;
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 = 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);
return false;
}
}
/**
* Metoda ukon<EFBFBD>uje/neukon<EFBFBD>uje ud<EFBFBD>lost pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu v z<EFBFBD>vislosti na tom,
* jakou hodnotu vr<EFBFBD>tila metoda payForCommand(Player player, String
* regexCommand, String originalCommand, double price, String name);.
*
* @param event
* ud<EFBFBD>lost PlayerCommandPreprocessEvent
* @param player
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
* @param originalCommand
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
* @param item
* @param price
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
*/
static void payItemForCommand(PlayerCommandPreprocessEvent event,
Player player, String regexCommand, String originalCommand,
String item, int count) {
String name = player.getName();
if (count > 0) {
if (!player.hasPermission("booscooldowns.noitemcost")
&& !player.hasPermission("booscooldowns.noitemcost."
+ originalCommand)) {
if (payItemForCommand(player, regexCommand, originalCommand,
item, count, name)) {
return;
} else {
BoosCoolDownManager.cancelCooldown(player, regexCommand);
event.setCancelled(true);
return;
}
}
}
}
public static boolean has(Player player, String item, int count) {
if (item.equals("")) {
return true;
}
if (count <= 0) {
return true;
}
Material material = Material.getMaterial(item);
Inventory inventory = player.getInventory();
if (inventory.contains(material, count)) {
return true;
}
return false;
}
}

View File

@ -1,116 +1,118 @@
package cz.boosik.boosCooldown;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import util.boosChat;
/**
* T<EFBFBD><EFBFBD>da obsahuje ve<EFBFBD>ker<EFBFBD> metody pot<EFBFBD>ebn<EFBFBD> k <EFBFBD><EFBFBD>zen<EFBFBD> poplatk<EFBFBD> pomoc<EFBFBD> v<EFBFBD>c<EFBFBD> za
* p<EFBFBD><EFBFBD>kazy.
*
* @author Jakub Kol<EFBFBD><EFBFBD>
*
*/
public class BoosPriceManager {
private static Economy economy = BoosCoolDown.getEconomy();
private static String msg = "";
/**
* Metoda zaji<EFBFBD><EFBFBD>uje funkci platby za p<EFBFBD><EFBFBD>kaz. Vrac<EFBFBD> hodnotu v z<EFBFBD>vislosti na
* <EFBFBD>sp<EFBFBD>nosti platby.
*
* @param player
* specifikovan<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
* @param originalCommand
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
* @param price
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
* @param name
* jm<EFBFBD>no specifick<EFBFBD>ho hr<EFBFBD><EFBFBD>e
* @return true pokud byl <EFBFBD>sp<EFBFBD>n<EFBFBD> zaplacen poplatek, nebo pokud nebyl nalezen
* ekonomick<EFBFBD> plugin; false pokud do<EFBFBD>lo k chyb<EFBFBD> nebo hr<EFBFBD><EFBFBD> nem<EFBFBD>l
* dostatek financ<EFBFBD>
*/
static boolean payForCommand(Player player, String regexCommand,
String originalCommand, double price, String name) {
if (economy == null) {
return true;
}
EconomyResponse r = economy.withdrawPlayer(player, price);
if (r.transactionSuccess()) {
msg = String.format(BoosConfigManager.getPaidForCommandMessage(),
economy.format(r.amount), economy.format(r.balance));
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
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);
} else {
msg = String.format(BoosConfigManager.getPaidErrorMessage(),
r.errorMessage);
}
boosChat.sendMessageToPlayer(player, msg);
return false;
}
}
/**
* Metoda ukon<EFBFBD>uje/neukon<EFBFBD>uje ud<EFBFBD>lost pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu v z<EFBFBD>vislosti na tom,
* jakou hodnotu vr<EFBFBD>tila metoda payForCommand(Player player, String
* regexCommand, String originalCommand, double price, String name);.
*
* @param event
* ud<EFBFBD>lost PlayerCommandPreprocessEvent
* @param player
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
* @param originalCommand
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
* @param price
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
*/
static void payForCommand(PlayerCommandPreprocessEvent event,
Player player, String regexCommand, String originalCommand,
double price) {
String name = player.getName();
if (price > 0) {
if (!player.hasPermission("booscooldowns.noprice")
&& !player.hasPermission("booscooldowns.noprice."
+ originalCommand)) {
if (payForCommand(player, regexCommand, originalCommand, price,
name)) {
return;
} else {
BoosCoolDownManager.cancelCooldown(player, regexCommand);
event.setCancelled(true);
return;
}
}
}
}
public static boolean has(Player player, double price) {
if (economy == null) {
return true;
} else {
return economy.has(player, price);
}
}
}
package cz.boosik.boosCooldown;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import util.boosChat;
/**
* T<EFBFBD><EFBFBD>da obsahuje ve<EFBFBD>ker<EFBFBD> metody pot<EFBFBD>ebn<EFBFBD> k <EFBFBD><EFBFBD>zen<EFBFBD> poplatk<EFBFBD> pomoc<EFBFBD> v<EFBFBD>c<EFBFBD> za
* p<EFBFBD><EFBFBD>kazy.
*
* @author Jakub Kol<EFBFBD><EFBFBD>
*
*/
public class BoosPriceManager {
private static Economy economy = BoosCoolDown.getEconomy();
private static String msg = "";
/**
* Metoda zaji<EFBFBD><EFBFBD>uje funkci platby za p<EFBFBD><EFBFBD>kaz. Vrac<EFBFBD> hodnotu v z<EFBFBD>vislosti na
* <EFBFBD>sp<EFBFBD>nosti platby.
*
* @param player
* specifikovan<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
* @param originalCommand
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
* @param price
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
* @param name
* jm<EFBFBD>no specifick<EFBFBD>ho hr<EFBFBD><EFBFBD>e
* @return true pokud byl <EFBFBD>sp<EFBFBD>n<EFBFBD> zaplacen poplatek, nebo pokud nebyl nalezen
* ekonomick<EFBFBD> plugin; false pokud do<EFBFBD>lo k chyb<EFBFBD> nebo hr<EFBFBD><EFBFBD> nem<EFBFBD>l
* dostatek financ<EFBFBD>
*/
static boolean payForCommand(Player player, String regexCommand,
String originalCommand, double price, String name) {
if (economy == null) {
return true;
}
EconomyResponse r = economy.withdrawPlayer(player, price);
if (r.transactionSuccess()) {
msg = String.format(BoosConfigManager.getPaidForCommandMessage(),
economy.format(r.amount), economy.format(r.balance));
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
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);
} else {
msg = String.format(BoosConfigManager.getPaidErrorMessage(),
r.errorMessage);
}
boosChat.sendMessageToPlayer(player, msg);
return false;
}
}
/**
* Metoda ukon<EFBFBD>uje/neukon<EFBFBD>uje ud<EFBFBD>lost pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu v z<EFBFBD>vislosti na tom,
* jakou hodnotu vr<EFBFBD>tila metoda payForCommand(Player player, String
* regexCommand, String originalCommand, double price, String name);.
*
* @param event
* ud<EFBFBD>lost PlayerCommandPreprocessEvent
* @param player
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
* @param regexCommand
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
* @param originalCommand
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
* @param price
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
*/
static void payForCommand(PlayerCommandPreprocessEvent event,
Player player, String regexCommand, String originalCommand,
double price) {
String name = player.getName();
if (price > 0) {
if (!player.hasPermission("booscooldowns.noprice")
&& !player.hasPermission("booscooldowns.noprice."
+ originalCommand)) {
if (payForCommand(player, regexCommand, originalCommand, price,
name)) {
return;
} else {
BoosCoolDownManager.cancelCooldown(player, regexCommand);
event.setCancelled(true);
return;
}
}
}
}
public static boolean has(Player player, double price) {
if (economy == null) {
return true;
} else if (price <= 0){
return true;
} else {
return economy.has(player, price);
}
}
}

View File

@ -1,6 +1,7 @@
package cz.boosik.boosCooldown;
import java.util.Iterator;
import java.util.Map;
import java.util.Timer;
import java.util.concurrent.ConcurrentHashMap;
@ -62,7 +63,8 @@ public class BoosWarmUpManager {
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
*/
public static void cancelWarmUps(Player player) {
Iterator<String> iter = playercommands.keySet().iterator();
Map<String, BoosWarmUpTimer> playercommands2 = playercommands;
Iterator<String> iter = playercommands2.keySet().iterator();
while (iter.hasNext()) {
if (iter.next().startsWith(player.getUniqueId() + "@")) {
killTimer(player);
@ -91,7 +93,8 @@ public class BoosWarmUpManager {
* @return true pokud hr<EFBFBD><EFBFBD> m<EFBFBD> aktivn<EFBFBD> warmup <EFBFBD>asova<EFBFBD>e, jinak false
*/
public static boolean hasWarmUps(Player player) {
for (String key : playercommands.keySet()) {
Map<String, BoosWarmUpTimer> playercommands2 = playercommands;
for (String key : playercommands2.keySet()) {
if (key.startsWith(player.getUniqueId() + "@")) {
return true;
}
@ -149,7 +152,8 @@ public class BoosWarmUpManager {
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
*/
static void killTimer(Player player) {
for (String key : playercommands.keySet()) {
Map<String, BoosWarmUpTimer> playercommands2 = playercommands;
for (String key : playercommands2.keySet()) {
if (key.startsWith(player.getUniqueId() + "@")) {
playercommands.get(key).cancel();
}

View File

@ -1,56 +1,59 @@
package cz.boosik.boosCooldown;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import util.boosChat;
public class BoosXpCostManager {
private static String msg = "";
static boolean payXPForCommand(Player player, String regexCommand,
String originalCommand, int xpPrice) {
int xp = player.getLevel();
Boolean trans = false;
if (xp >= xpPrice) {
player.setLevel(xp - xpPrice);
trans = true;
}
if (trans) {
msg = String.format(BoosConfigManager.getPaidXPForCommandMessage(),
xpPrice);
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
return true;
} else {
return false;
}
}
static void payXPForCommand(PlayerCommandPreprocessEvent event,
Player player, String regexCommand, String originalCommand,
int xpPrice) {
if (xpPrice > 0) {
if (!player.hasPermission("booscooldowns.noxpcost")
&& !player.hasPermission("booscooldowns.noxpcost."
+ originalCommand)) {
if (payXPForCommand(player, regexCommand, originalCommand,
xpPrice)) {
return;
} else {
BoosCoolDownManager.cancelCooldown(player, regexCommand);
event.setCancelled(true);
return;
}
}
}
}
public static boolean has(Player player, int xpPrice) {
int xp = player.getLevel();
if (xp >= xpPrice) {
return true;
}
return false;
}
}
package cz.boosik.boosCooldown;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import util.boosChat;
public class BoosXpCostManager {
private static String msg = "";
static boolean payXPForCommand(Player player, String regexCommand,
String originalCommand, int xpPrice) {
int xp = player.getLevel();
Boolean trans = false;
if (xp >= xpPrice) {
player.setLevel(xp - xpPrice);
trans = true;
}
if (trans) {
msg = String.format(BoosConfigManager.getPaidXPForCommandMessage(),
xpPrice);
msg = msg.replaceAll("&command&", originalCommand);
boosChat.sendMessageToPlayer(player, msg);
return true;
} else {
return false;
}
}
static void payXPForCommand(PlayerCommandPreprocessEvent event,
Player player, String regexCommand, String originalCommand,
int xpPrice) {
if (xpPrice > 0) {
if (!player.hasPermission("booscooldowns.noxpcost")
&& !player.hasPermission("booscooldowns.noxpcost."
+ originalCommand)) {
if (payXPForCommand(player, regexCommand, originalCommand,
xpPrice)) {
return;
} else {
BoosCoolDownManager.cancelCooldown(player, regexCommand);
event.setCancelled(true);
return;
}
}
}
}
public static boolean has(Player player, int xpPrice) {
if (xpPrice <= 0){
return true;
}
int xp = player.getLevel();
if (xp >= xpPrice) {
return true;
}
return false;
}
}

View File

@ -1,6 +1,6 @@
name: boosCooldowns
main: cz.boosik.boosCooldown.BoosCoolDown
version: 3.9.5
version: 3.9.5c
authors: [LordBoos (ingame name boosik)]
softdepend: [Vault]
description: >