optimisation
This commit is contained in:
parent
bd6d6859a6
commit
046df72e38
|
@ -111,8 +111,13 @@ public class BoosConfigManager {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static Set<String> getAliases() {
|
static Set<String> getAliases() {
|
||||||
Set<String> aliases = conf.getConfigurationSection("commands.aliases")
|
Set<String> aliases = null;
|
||||||
.getKeys(false);
|
ConfigurationSection aliasesSection = conf
|
||||||
|
.getConfigurationSection("commands.aliases");
|
||||||
|
if (aliasesSection != null) {
|
||||||
|
aliases = conf.getConfigurationSection("commands.aliases").getKeys(
|
||||||
|
false);
|
||||||
|
}
|
||||||
return aliases;
|
return aliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,9 +253,12 @@ public class BoosConfigManager {
|
||||||
*/
|
*/
|
||||||
static String getCommandGroup(Player player) {
|
static String getCommandGroup(Player player) {
|
||||||
String cmdGroup = "default";
|
String cmdGroup = "default";
|
||||||
for (String group : getCommandGroups()) {
|
Set<String> groups = getCommandGroups();
|
||||||
if (player.hasPermission("booscooldowns." + group)) {
|
if (groups != null) {
|
||||||
cmdGroup = group;
|
for (String group : groups) {
|
||||||
|
if (player.hasPermission("booscooldowns." + group)) {
|
||||||
|
cmdGroup = group;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cmdGroup;
|
return cmdGroup;
|
||||||
|
@ -260,8 +268,12 @@ public class BoosConfigManager {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static Set<String> getCommandGroups() {
|
static Set<String> getCommandGroups() {
|
||||||
Set<String> groups = conf.getConfigurationSection("commands.groups")
|
ConfigurationSection groupsSection = conf
|
||||||
.getKeys(false);
|
.getConfigurationSection("commands.groups");
|
||||||
|
Set<String> groups = null;
|
||||||
|
if (groupsSection != null) {
|
||||||
|
groups = groupsSection.getKeys(false);
|
||||||
|
}
|
||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,8 +290,12 @@ public class BoosConfigManager {
|
||||||
*/
|
*/
|
||||||
static Set<String> getCommands(Player player) {
|
static Set<String> getCommands(Player player) {
|
||||||
String group = getCommandGroup(player);
|
String group = getCommandGroup(player);
|
||||||
Set<String> commands = conf.getConfigurationSection(
|
Set<String> commands = null;
|
||||||
"commands.groups." + group).getKeys(false);
|
ConfigurationSection commandsSection = conf
|
||||||
|
.getConfigurationSection("commands.groups." + group);
|
||||||
|
if (commandsSection != null) {
|
||||||
|
commands = commandsSection.getKeys(false);
|
||||||
|
}
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -861,7 +877,7 @@ public class BoosConfigManager {
|
||||||
|
|
||||||
static int parseTime(String time) {
|
static int parseTime(String time) {
|
||||||
String[] timeString = time.split(" ", 2);
|
String[] timeString = time.split(" ", 2);
|
||||||
if (timeString[0].equals("cancel")){
|
if (timeString[0].equals("cancel")) {
|
||||||
return -65535;
|
return -65535;
|
||||||
}
|
}
|
||||||
int timeNumber = Integer.valueOf(timeString[0]);
|
int timeNumber = Integer.valueOf(timeString[0]);
|
||||||
|
@ -886,9 +902,7 @@ public class BoosConfigManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLimitResetNowMessage() {
|
public static String getLimitResetNowMessage() {
|
||||||
return conf
|
return conf.getString("options.messages.limit_reset_now",
|
||||||
.getString(
|
"&6Reseting limits for command&e &command& &6now.&f");
|
||||||
"options.messages.limit_reset_now",
|
|
||||||
"&6Reseting limits for command&e &command& &6now.&f");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,8 +57,11 @@ public class BoosCoolDownListener implements Listener {
|
||||||
Player player, String regexCommad, String originalCommand,
|
Player player, String regexCommad, String originalCommand,
|
||||||
int warmupTime, int cooldownTime, double price, String item,
|
int warmupTime, int cooldownTime, double price, String item,
|
||||||
int count, int limit, int xpPrice) {
|
int count, int limit, int xpPrice) {
|
||||||
boolean blocked = BoosLimitManager.blocked(player, regexCommad,
|
boolean blocked = false;
|
||||||
originalCommand, limit);
|
if (limit != -1) {
|
||||||
|
blocked = BoosLimitManager.blocked(player, regexCommad,
|
||||||
|
originalCommand, limit);
|
||||||
|
}
|
||||||
if (!blocked) {
|
if (!blocked) {
|
||||||
if (warmupTime > 0) {
|
if (warmupTime > 0) {
|
||||||
if (!player.hasPermission("booscooldowns.nowarmup")
|
if (!player.hasPermission("booscooldowns.nowarmup")
|
||||||
|
@ -180,15 +183,7 @@ public class BoosCoolDownListener implements Listener {
|
||||||
originalCommand = originalCommand.replace("$", "S");
|
originalCommand = originalCommand.replace("$", "S");
|
||||||
originalCommand = originalCommand.trim().replaceAll(" +", " ");
|
originalCommand = originalCommand.trim().replaceAll(" +", " ");
|
||||||
String regexCommad = "";
|
String regexCommad = "";
|
||||||
Set<String> aliases = null;
|
Set<String> aliases = BoosConfigManager.getAliases();
|
||||||
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> commands = BoosConfigManager.getCommands(player);
|
Set<String> commands = BoosConfigManager.getCommands(player);
|
||||||
boolean on = true;
|
boolean on = true;
|
||||||
String item = "";
|
String item = "";
|
||||||
|
@ -199,10 +194,12 @@ public class BoosCoolDownListener implements Listener {
|
||||||
int cooldownTime = 0;
|
int cooldownTime = 0;
|
||||||
int xpPrice = 0;
|
int xpPrice = 0;
|
||||||
on = BoosCoolDown.isPluginOnForPlayer(player);
|
on = BoosCoolDown.isPluginOnForPlayer(player);
|
||||||
originalCommand = BoosAliasManager.checkCommandAlias(originalCommand,
|
if (aliases != null) {
|
||||||
aliases, player);
|
originalCommand = BoosAliasManager.checkCommandAlias(
|
||||||
event.setMessage(originalCommand);
|
originalCommand, aliases, player);
|
||||||
if (on) {
|
event.setMessage(originalCommand);
|
||||||
|
}
|
||||||
|
if (on && commands != null) {
|
||||||
for (String group : commands) {
|
for (String group : commands) {
|
||||||
String group2 = group.replace("*", ".+");
|
String group2 = group.replace("*", ".+");
|
||||||
if (originalCommand.matches("(?i)" + group2)) {
|
if (originalCommand.matches("(?i)" + group2)) {
|
||||||
|
@ -237,14 +234,6 @@ public class BoosCoolDownListener implements Listener {
|
||||||
this.checkRestrictions(event, player, regexCommad, originalCommand,
|
this.checkRestrictions(event, player, regexCommad, originalCommand,
|
||||||
warmupTime, cooldownTime, price, item, count, limit,
|
warmupTime, cooldownTime, price, item, count, limit,
|
||||||
xpPrice);
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,114 +1,117 @@
|
||||||
package cz.boosik.boosCooldown;
|
package cz.boosik.boosCooldown;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import util.boosChat;
|
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.
|
* 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>
|
* @author Jakub Kol<EFBFBD><EFBFBD>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class BoosItemCostManager {
|
public class BoosItemCostManager {
|
||||||
private static String msg = "";
|
private static String msg = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metoda zaji<EFBFBD><EFBFBD>uje funkci platby za p<EFBFBD><EFBFBD>kaz. Vrac<EFBFBD> hodnotu v z<EFBFBD>vislosti na
|
* 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.
|
* <EFBFBD>sp<EFBFBD>nosti platby.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* specifikovan<EFBFBD> hr<EFBFBD><EFBFBD>
|
* specifikovan<EFBFBD> hr<EFBFBD><EFBFBD>
|
||||||
* @param regexCommand
|
* @param regexCommand
|
||||||
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
|
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
|
||||||
* @param originalCommand
|
* @param originalCommand
|
||||||
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
|
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
|
||||||
* @param item
|
* @param item
|
||||||
* @param price
|
* @param price
|
||||||
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
|
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
|
||||||
* @param name
|
* @param name
|
||||||
* jm<EFBFBD>no specifick<EFBFBD>ho hr<EFBFBD><EFBFBD>e
|
* 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
|
* @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
|
* ekonomick<EFBFBD> plugin; false pokud do<EFBFBD>lo k chyb<EFBFBD> nebo hr<EFBFBD><EFBFBD> nem<EFBFBD>l
|
||||||
* dostatek financ<EFBFBD>
|
* dostatek financ<EFBFBD>
|
||||||
*/
|
*/
|
||||||
static boolean payItemForCommand(Player player, String regexCommand,
|
static boolean payItemForCommand(Player player, String regexCommand,
|
||||||
String originalCommand, String item, int count, String name) {
|
String originalCommand, String item, int count, String name) {
|
||||||
Material material = Material.getMaterial(item);
|
Material material = Material.getMaterial(item);
|
||||||
Inventory inventory = player.getInventory();
|
Inventory inventory = player.getInventory();
|
||||||
Boolean trans = false;
|
Boolean trans = false;
|
||||||
if (inventory.contains(material, count)) {
|
if (inventory.contains(material, count)) {
|
||||||
ItemStack itemstack = new ItemStack(material, count);
|
ItemStack itemstack = new ItemStack(material, count);
|
||||||
inventory.removeItem(itemstack);
|
inventory.removeItem(itemstack);
|
||||||
trans = true;
|
trans = true;
|
||||||
}
|
}
|
||||||
if (trans) {
|
if (trans) {
|
||||||
msg = String.format(
|
msg = String.format(
|
||||||
BoosConfigManager.getPaidItemsForCommandMessage(), count
|
BoosConfigManager.getPaidItemsForCommandMessage(), count
|
||||||
+ " " + item);
|
+ " " + item);
|
||||||
msg = msg.replaceAll("&command&", originalCommand);
|
msg = msg.replaceAll("&command&", originalCommand);
|
||||||
boosChat.sendMessageToPlayer(player, msg);
|
boosChat.sendMessageToPlayer(player, msg);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// msg = String.format(
|
// msg = String.format(
|
||||||
// BoosConfigManager.getInsufficientItemsMessage(), (count
|
// BoosConfigManager.getInsufficientItemsMessage(), (count
|
||||||
// + " " + item));
|
// + " " + item));
|
||||||
// msg = msg.replaceAll("&command&", originalCommand);
|
// msg = msg.replaceAll("&command&", originalCommand);
|
||||||
// boosChat.sendMessageToPlayer(player, msg);
|
// boosChat.sendMessageToPlayer(player, msg);
|
||||||
return false;
|
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,
|
* 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
|
* jakou hodnotu vr<EFBFBD>tila metoda payForCommand(Player player, String
|
||||||
* regexCommand, String originalCommand, double price, String name);.
|
* regexCommand, String originalCommand, double price, String name);.
|
||||||
*
|
*
|
||||||
* @param event
|
* @param event
|
||||||
* ud<EFBFBD>lost PlayerCommandPreprocessEvent
|
* ud<EFBFBD>lost PlayerCommandPreprocessEvent
|
||||||
* @param player
|
* @param player
|
||||||
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
|
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
|
||||||
* @param regexCommand
|
* @param regexCommand
|
||||||
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
|
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
|
||||||
* @param originalCommand
|
* @param originalCommand
|
||||||
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
|
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
|
||||||
* @param item
|
* @param item
|
||||||
* @param price
|
* @param price
|
||||||
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
|
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
|
||||||
*/
|
*/
|
||||||
static void payItemForCommand(PlayerCommandPreprocessEvent event,
|
static void payItemForCommand(PlayerCommandPreprocessEvent event,
|
||||||
Player player, String regexCommand, String originalCommand,
|
Player player, String regexCommand, String originalCommand,
|
||||||
String item, int count) {
|
String item, int count) {
|
||||||
String name = player.getName();
|
String name = player.getName();
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
if (!player.hasPermission("booscooldowns.noitemcost")
|
if (!player.hasPermission("booscooldowns.noitemcost")
|
||||||
&& !player.hasPermission("booscooldowns.noitemcost."
|
&& !player.hasPermission("booscooldowns.noitemcost."
|
||||||
+ originalCommand)) {
|
+ originalCommand)) {
|
||||||
if (payItemForCommand(player, regexCommand, originalCommand,
|
if (payItemForCommand(player, regexCommand, originalCommand,
|
||||||
item, count, name)) {
|
item, count, name)) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
BoosCoolDownManager.cancelCooldown(player, regexCommand);
|
BoosCoolDownManager.cancelCooldown(player, regexCommand);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean has(Player player, String item, int count) {
|
public static boolean has(Player player, String item, int count) {
|
||||||
if (item.equals("")) {
|
if (item.equals("")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Material material = Material.getMaterial(item);
|
if (count <= 0) {
|
||||||
Inventory inventory = player.getInventory();
|
return true;
|
||||||
if (inventory.contains(material, count)) {
|
}
|
||||||
return true;
|
Material material = Material.getMaterial(item);
|
||||||
}
|
Inventory inventory = player.getInventory();
|
||||||
return false;
|
if (inventory.contains(material, count)) {
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,116 +1,118 @@
|
||||||
package cz.boosik.boosCooldown;
|
package cz.boosik.boosCooldown;
|
||||||
|
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import net.milkbowl.vault.economy.EconomyResponse;
|
import net.milkbowl.vault.economy.EconomyResponse;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
|
||||||
import util.boosChat;
|
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
|
* 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.
|
* p<EFBFBD><EFBFBD>kazy.
|
||||||
*
|
*
|
||||||
* @author Jakub Kol<EFBFBD><EFBFBD>
|
* @author Jakub Kol<EFBFBD><EFBFBD>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class BoosPriceManager {
|
public class BoosPriceManager {
|
||||||
private static Economy economy = BoosCoolDown.getEconomy();
|
private static Economy economy = BoosCoolDown.getEconomy();
|
||||||
private static String msg = "";
|
private static String msg = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metoda zaji<EFBFBD><EFBFBD>uje funkci platby za p<EFBFBD><EFBFBD>kaz. Vrac<EFBFBD> hodnotu v z<EFBFBD>vislosti na
|
* 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.
|
* <EFBFBD>sp<EFBFBD>nosti platby.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* specifikovan<EFBFBD> hr<EFBFBD><EFBFBD>
|
* specifikovan<EFBFBD> hr<EFBFBD><EFBFBD>
|
||||||
* @param regexCommand
|
* @param regexCommand
|
||||||
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
|
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
|
||||||
* @param originalCommand
|
* @param originalCommand
|
||||||
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
|
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
|
||||||
* @param price
|
* @param price
|
||||||
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
|
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
|
||||||
* @param name
|
* @param name
|
||||||
* jm<EFBFBD>no specifick<EFBFBD>ho hr<EFBFBD><EFBFBD>e
|
* 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
|
* @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
|
* ekonomick<EFBFBD> plugin; false pokud do<EFBFBD>lo k chyb<EFBFBD> nebo hr<EFBFBD><EFBFBD> nem<EFBFBD>l
|
||||||
* dostatek financ<EFBFBD>
|
* dostatek financ<EFBFBD>
|
||||||
*/
|
*/
|
||||||
static boolean payForCommand(Player player, String regexCommand,
|
static boolean payForCommand(Player player, String regexCommand,
|
||||||
String originalCommand, double price, String name) {
|
String originalCommand, double price, String name) {
|
||||||
if (economy == null) {
|
if (economy == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
EconomyResponse r = economy.withdrawPlayer(player, price);
|
EconomyResponse r = economy.withdrawPlayer(player, price);
|
||||||
if (r.transactionSuccess()) {
|
if (r.transactionSuccess()) {
|
||||||
msg = String.format(BoosConfigManager.getPaidForCommandMessage(),
|
msg = String.format(BoosConfigManager.getPaidForCommandMessage(),
|
||||||
economy.format(r.amount), economy.format(r.balance));
|
economy.format(r.amount), economy.format(r.balance));
|
||||||
msg = msg.replaceAll("&command&", originalCommand);
|
msg = msg.replaceAll("&command&", originalCommand);
|
||||||
boosChat.sendMessageToPlayer(player, msg);
|
boosChat.sendMessageToPlayer(player, msg);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (r.errorMessage.equals("Insufficient funds")) {
|
if (r.errorMessage.equals("Insufficient funds")) {
|
||||||
// String unit;
|
// String unit;
|
||||||
// if (price == 1) {
|
// if (price == 1) {
|
||||||
// unit = economy.currencyNameSingular();
|
// unit = economy.currencyNameSingular();
|
||||||
// } else {
|
// } else {
|
||||||
// unit = economy.currencyNamePlural();
|
// unit = economy.currencyNamePlural();
|
||||||
// }
|
// }
|
||||||
// msg = String.format(
|
// msg = String.format(
|
||||||
// BoosConfigManager.getInsufficientFundsMessage(), (price
|
// BoosConfigManager.getInsufficientFundsMessage(), (price
|
||||||
// + " " + unit), economy.format(r.balance));
|
// + " " + unit), economy.format(r.balance));
|
||||||
// msg = msg.replaceAll("&command&", originalCommand);
|
// msg = msg.replaceAll("&command&", originalCommand);
|
||||||
} else {
|
} else {
|
||||||
msg = String.format(BoosConfigManager.getPaidErrorMessage(),
|
msg = String.format(BoosConfigManager.getPaidErrorMessage(),
|
||||||
r.errorMessage);
|
r.errorMessage);
|
||||||
}
|
}
|
||||||
boosChat.sendMessageToPlayer(player, msg);
|
boosChat.sendMessageToPlayer(player, msg);
|
||||||
return false;
|
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,
|
* 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
|
* jakou hodnotu vr<EFBFBD>tila metoda payForCommand(Player player, String
|
||||||
* regexCommand, String originalCommand, double price, String name);.
|
* regexCommand, String originalCommand, double price, String name);.
|
||||||
*
|
*
|
||||||
* @param event
|
* @param event
|
||||||
* ud<EFBFBD>lost PlayerCommandPreprocessEvent
|
* ud<EFBFBD>lost PlayerCommandPreprocessEvent
|
||||||
* @param player
|
* @param player
|
||||||
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
|
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
|
||||||
* @param regexCommand
|
* @param regexCommand
|
||||||
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
|
* p<EFBFBD><EFBFBD>kaz z konfigurace vyhovuj<EFBFBD>c<EFBFBD> origin<EFBFBD>ln<EFBFBD>mu p<EFBFBD><EFBFBD>kazu
|
||||||
* @param originalCommand
|
* @param originalCommand
|
||||||
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
|
* origin<EFBFBD>ln<EFBFBD> p<EFBFBD><EFBFBD>kaz pou<EFBFBD>it<EFBFBD> hr<EFBFBD><EFBFBD>em
|
||||||
* @param price
|
* @param price
|
||||||
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
|
* cena pou<EFBFBD>it<EFBFBD> p<EFBFBD><EFBFBD>kazu
|
||||||
*/
|
*/
|
||||||
static void payForCommand(PlayerCommandPreprocessEvent event,
|
static void payForCommand(PlayerCommandPreprocessEvent event,
|
||||||
Player player, String regexCommand, String originalCommand,
|
Player player, String regexCommand, String originalCommand,
|
||||||
double price) {
|
double price) {
|
||||||
String name = player.getName();
|
String name = player.getName();
|
||||||
if (price > 0) {
|
if (price > 0) {
|
||||||
if (!player.hasPermission("booscooldowns.noprice")
|
if (!player.hasPermission("booscooldowns.noprice")
|
||||||
&& !player.hasPermission("booscooldowns.noprice."
|
&& !player.hasPermission("booscooldowns.noprice."
|
||||||
+ originalCommand)) {
|
+ originalCommand)) {
|
||||||
if (payForCommand(player, regexCommand, originalCommand, price,
|
if (payForCommand(player, regexCommand, originalCommand, price,
|
||||||
name)) {
|
name)) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
BoosCoolDownManager.cancelCooldown(player, regexCommand);
|
BoosCoolDownManager.cancelCooldown(player, regexCommand);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean has(Player player, double price) {
|
public static boolean has(Player player, double price) {
|
||||||
if (economy == null) {
|
if (economy == null) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else if (price <= 0){
|
||||||
return economy.has(player, price);
|
return true;
|
||||||
}
|
} else {
|
||||||
}
|
return economy.has(player, price);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package cz.boosik.boosCooldown;
|
package cz.boosik.boosCooldown;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@ -62,7 +63,8 @@ public class BoosWarmUpManager {
|
||||||
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
|
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
|
||||||
*/
|
*/
|
||||||
public static void cancelWarmUps(Player player) {
|
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()) {
|
while (iter.hasNext()) {
|
||||||
if (iter.next().startsWith(player.getUniqueId() + "@")) {
|
if (iter.next().startsWith(player.getUniqueId() + "@")) {
|
||||||
killTimer(player);
|
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
|
* @return true pokud hr<EFBFBD><EFBFBD> m<EFBFBD> aktivn<EFBFBD> warmup <EFBFBD>asova<EFBFBD>e, jinak false
|
||||||
*/
|
*/
|
||||||
public static boolean hasWarmUps(Player player) {
|
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() + "@")) {
|
if (key.startsWith(player.getUniqueId() + "@")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -149,7 +152,8 @@ public class BoosWarmUpManager {
|
||||||
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
|
* specifick<EFBFBD> hr<EFBFBD><EFBFBD>
|
||||||
*/
|
*/
|
||||||
static void killTimer(Player player) {
|
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() + "@")) {
|
if (key.startsWith(player.getUniqueId() + "@")) {
|
||||||
playercommands.get(key).cancel();
|
playercommands.get(key).cancel();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,56 +1,59 @@
|
||||||
package cz.boosik.boosCooldown;
|
package cz.boosik.boosCooldown;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
|
||||||
import util.boosChat;
|
import util.boosChat;
|
||||||
|
|
||||||
public class BoosXpCostManager {
|
public class BoosXpCostManager {
|
||||||
private static String msg = "";
|
private static String msg = "";
|
||||||
|
|
||||||
static boolean payXPForCommand(Player player, String regexCommand,
|
static boolean payXPForCommand(Player player, String regexCommand,
|
||||||
String originalCommand, int xpPrice) {
|
String originalCommand, int xpPrice) {
|
||||||
int xp = player.getLevel();
|
int xp = player.getLevel();
|
||||||
Boolean trans = false;
|
Boolean trans = false;
|
||||||
if (xp >= xpPrice) {
|
if (xp >= xpPrice) {
|
||||||
player.setLevel(xp - xpPrice);
|
player.setLevel(xp - xpPrice);
|
||||||
trans = true;
|
trans = true;
|
||||||
}
|
}
|
||||||
if (trans) {
|
if (trans) {
|
||||||
msg = String.format(BoosConfigManager.getPaidXPForCommandMessage(),
|
msg = String.format(BoosConfigManager.getPaidXPForCommandMessage(),
|
||||||
xpPrice);
|
xpPrice);
|
||||||
msg = msg.replaceAll("&command&", originalCommand);
|
msg = msg.replaceAll("&command&", originalCommand);
|
||||||
boosChat.sendMessageToPlayer(player, msg);
|
boosChat.sendMessageToPlayer(player, msg);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void payXPForCommand(PlayerCommandPreprocessEvent event,
|
static void payXPForCommand(PlayerCommandPreprocessEvent event,
|
||||||
Player player, String regexCommand, String originalCommand,
|
Player player, String regexCommand, String originalCommand,
|
||||||
int xpPrice) {
|
int xpPrice) {
|
||||||
if (xpPrice > 0) {
|
if (xpPrice > 0) {
|
||||||
if (!player.hasPermission("booscooldowns.noxpcost")
|
if (!player.hasPermission("booscooldowns.noxpcost")
|
||||||
&& !player.hasPermission("booscooldowns.noxpcost."
|
&& !player.hasPermission("booscooldowns.noxpcost."
|
||||||
+ originalCommand)) {
|
+ originalCommand)) {
|
||||||
if (payXPForCommand(player, regexCommand, originalCommand,
|
if (payXPForCommand(player, regexCommand, originalCommand,
|
||||||
xpPrice)) {
|
xpPrice)) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
BoosCoolDownManager.cancelCooldown(player, regexCommand);
|
BoosCoolDownManager.cancelCooldown(player, regexCommand);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean has(Player player, int xpPrice) {
|
public static boolean has(Player player, int xpPrice) {
|
||||||
int xp = player.getLevel();
|
if (xpPrice <= 0){
|
||||||
if (xp >= xpPrice) {
|
return true;
|
||||||
return true;
|
}
|
||||||
}
|
int xp = player.getLevel();
|
||||||
return false;
|
if (xp >= xpPrice) {
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: boosCooldowns
|
name: boosCooldowns
|
||||||
main: cz.boosik.boosCooldown.BoosCoolDown
|
main: cz.boosik.boosCooldown.BoosCoolDown
|
||||||
version: 3.9.5
|
version: 3.9.5c
|
||||||
authors: [LordBoos (ingame name boosik)]
|
authors: [LordBoos (ingame name boosik)]
|
||||||
softdepend: [Vault]
|
softdepend: [Vault]
|
||||||
description: >
|
description: >
|
||||||
|
|
Loading…
Reference in New Issue