mirror of
https://github.com/LordBoos/boosCooldowns.git
synced 2025-02-21 15:01:22 +01:00
Added Item costs and messages.
This commit is contained in:
parent
0b556fc66b
commit
f1808623c0
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
bin/cz/boosik/boosCooldown/BoosItemCostManager.class
Normal file
BIN
bin/cz/boosik/boosCooldown/BoosItemCostManager.class
Normal file
Binary file not shown.
@ -1,6 +1,6 @@
|
||||
name: boosCooldowns
|
||||
main: cz.boosik.boosCooldown.BoosCoolDown
|
||||
version: 3.7.0
|
||||
version: 3.7.1
|
||||
authors: [LordBoos (ingame name boosik)]
|
||||
softdepend: [Vault]
|
||||
description: >
|
||||
|
@ -357,6 +357,42 @@ public class BoosConfigManager {
|
||||
"options.messages.interact_blocked_during_warmup",
|
||||
"&6You can't do this when command is warming-up!&f");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param regexCommand
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
static String getItemCostItem(String regexCommand, Player player) {
|
||||
String item = "";
|
||||
String temp;
|
||||
String[] command;
|
||||
String group = getCommandGroup(player);
|
||||
temp = conf.getString("commands.groups." + group + "." + regexCommand + ".itemcost", "");
|
||||
command = temp.split(",");
|
||||
if(command.length==2){
|
||||
item = command[0];
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param regexCommand
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
static int getItemCostCount(String regexCommand, Player player) {
|
||||
int count = 0;
|
||||
String temp;
|
||||
String[] command;
|
||||
String group = getCommandGroup(player);
|
||||
temp = conf.getString("commands.groups." + group + "." + regexCommand + ".itemcost", "");
|
||||
command = temp.split(",");
|
||||
if(command.length==2){
|
||||
count = Integer.valueOf(command[1]);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param regexCommand
|
||||
@ -415,6 +451,18 @@ public class BoosConfigManager {
|
||||
linkGroup = conf.getStringList("commands.links.linkGroups." + link);
|
||||
return linkGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param regexCommand
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
static String getMessage(String regexCommand, Player player) {
|
||||
String message = "";
|
||||
String group = getCommandGroup(player);
|
||||
message = conf.getString("commands.groups." + group + "." + regexCommand + ".message", "");
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
@ -687,6 +735,7 @@ public class BoosConfigManager {
|
||||
conf.addDefault("options.options.warmups_enabled", true);
|
||||
conf.addDefault("options.options.cooldowns_enabled", true);
|
||||
conf.addDefault("options.options.prices_enabled", true);
|
||||
conf.addDefault("options.options.item_cost_enabled", true);
|
||||
conf.addDefault("options.options.limits_enabled", true);
|
||||
conf.addDefault("options.options.auto_save_enabled_CAN_CAUSE_BIG_LAGS", false);
|
||||
conf.addDefault("options.options.save_interval_in_minutes", 15);
|
||||
@ -731,6 +780,12 @@ public class BoosConfigManager {
|
||||
"&6You have insufficient funds!&e &command& &6costs &e%s &6but you only have &e%s");
|
||||
conf.addDefault("options.messages.paid_for_command",
|
||||
"&6Price of&e &command& &6was&e %s &6and you now have&e %s");
|
||||
conf.addDefault("options.messages.paid_items_for_command",
|
||||
"Price of &command& was %s");
|
||||
conf
|
||||
.addDefault(
|
||||
"options.messages.insufficient_items",
|
||||
"&6You have not enough items!&e &command& &6needs &e%s");
|
||||
conf.addDefault("options.messages.limit_achieved",
|
||||
"&6You cannot use this command anymore!&f");
|
||||
conf.addDefault(
|
||||
@ -761,6 +816,8 @@ public class BoosConfigManager {
|
||||
5);
|
||||
conf.addDefault("commands.groups.default./yetanothercommand.potion",
|
||||
"WEAKNESS,3");
|
||||
conf.addDefault("commands.groups.default./test.message", "You just used /test!");
|
||||
conf.addDefault("commands.groups.default./test.itemcost", "STONE,10");
|
||||
conf.addDefault("commands.groups.default.*.warmup", 1);
|
||||
conf.addDefault("commands.groups.default.*.cooldown", 1);
|
||||
conf.addDefault("commands.groups.default.*.price", 0.0);
|
||||
@ -802,4 +859,20 @@ public class BoosConfigManager {
|
||||
static boolean getAutoSave() {
|
||||
return conf.getBoolean("options.options.auto_save_enabled_CAN_CAUSE_BIG_LAGS", false);
|
||||
}
|
||||
|
||||
public static String getPaidItemsForCommandMessage() {
|
||||
return conf.getString("options.messages.paid_items_for_command",
|
||||
"&6Price of&e &command& &6was &e%s");
|
||||
}
|
||||
|
||||
public static String getInsufficientItemsMessage() {
|
||||
return conf
|
||||
.getString(
|
||||
"options.messages.insufficient_items",
|
||||
"&6You have not enough items!&e &command& &6needs &e%s");
|
||||
}
|
||||
|
||||
public static boolean getItemCostEnabled() {
|
||||
return conf.getBoolean("options.options.item_cost_enabled", true);
|
||||
}
|
||||
}
|
||||
|
@ -232,13 +232,6 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
|
||||
String coSetnout = args[1];
|
||||
String co = args[2];
|
||||
String hodnota = args[3];
|
||||
String regex1 = "(\\d+)(,)(\\d+)(,)(\\d+)(\\.)(\\d+)(,)(-?)(\\d+)(,)(CONFUSION|DAMAGE_RESISTANCE|FAST_DIGGING|FIRE_RESISTANCE|HARM|HEAL|HUNGER|INCREASE_DAMAGE|INVISIBILITY|JUMP|NIGHT_VISION|POISON|REGENERATION|SLOW|SLOW_DIGGING|SPEED|WATER_BREATHING|WEAKNESS|WITHER)(,)(\\d+)";
|
||||
String regex2 = "(\\d+)(,)(\\d+)(,)(\\d+)(\\.)(\\d+)(,)(-?)(\\d+)";
|
||||
if (!hodnota.matches(regex1) && !hodnota.matches(regex2)) {
|
||||
boosChat.sendMessageToCommandSender(sender,
|
||||
"Invalid syntax!");
|
||||
return true;
|
||||
}
|
||||
if (co.startsWith("/") || co.equals("*")) {
|
||||
if (co.contains("_")) {
|
||||
co = co.replace("_", " ");
|
||||
@ -264,7 +257,7 @@ public class BoosCoolDown extends JavaPlugin implements Runnable {
|
||||
"&6["
|
||||
+ pdfFile.getName()
|
||||
+ "]&e"
|
||||
+ " access denied, you lack required permission to do this!");
|
||||
+ " Invalid command or access denied!");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -53,7 +53,7 @@ public class BoosCoolDownListener implements Listener {
|
||||
*/
|
||||
private void checkRestrictions(PlayerCommandPreprocessEvent event,
|
||||
Player player, String regexCommad, String originalCommand,
|
||||
int warmupTime, int cooldownTime, double price, int limit) {
|
||||
int warmupTime, int cooldownTime, double price, String item, int count, int limit) {
|
||||
boolean blocked = BoosLimitManager.blocked(player, regexCommad,
|
||||
originalCommand, limit);
|
||||
if (!blocked) {
|
||||
@ -74,6 +74,14 @@ public class BoosCoolDownListener implements Listener {
|
||||
BoosPriceManager.payForCommand(event, player, regexCommad,
|
||||
originalCommand, price);
|
||||
}
|
||||
if (!event.isCancelled()) {
|
||||
BoosItemCostManager.payItemForCommand(event, player, regexCommad,
|
||||
originalCommand, item, count);
|
||||
}
|
||||
if (!event.isCancelled()) {
|
||||
String msg = String.format(BoosConfigManager.getMessage(regexCommad, player));
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
}
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
String msg = String.format(BoosConfigManager
|
||||
@ -111,6 +119,8 @@ public class BoosCoolDownListener implements Listener {
|
||||
Set<String> aliases = BoosConfigManager.getAliases();
|
||||
Set<String> commands = BoosConfigManager.getCommands(player);
|
||||
boolean on = true;
|
||||
String item = "";
|
||||
int count = 0;
|
||||
int warmupTime = 0;
|
||||
double price = 0;
|
||||
int limit = -1;
|
||||
@ -150,6 +160,10 @@ public class BoosCoolDownListener implements Listener {
|
||||
if (BoosConfigManager.getPriceEnabled()) {
|
||||
price = BoosConfigManager.getPrice(regexCommad, player);
|
||||
}
|
||||
if (BoosConfigManager.getItemCostEnabled()) {
|
||||
item = BoosConfigManager.getItemCostItem(regexCommad, player);
|
||||
count = BoosConfigManager.getItemCostCount(regexCommad, player);
|
||||
}
|
||||
if (BoosConfigManager.getLimitEnabled()) {
|
||||
limit = BoosConfigManager.getLimit(regexCommad, player);
|
||||
}
|
||||
@ -157,7 +171,7 @@ public class BoosCoolDownListener implements Listener {
|
||||
}
|
||||
}
|
||||
this.checkRestrictions(event, player, regexCommad, originalCommand,
|
||||
warmupTime, cooldownTime, price, limit);
|
||||
warmupTime, cooldownTime, price, item, count, limit);
|
||||
}
|
||||
}
|
||||
|
||||
|
100
src/cz/boosik/boosCooldown/BoosItemCostManager.java
Normal file
100
src/cz/boosik/boosCooldown/BoosItemCostManager.java
Normal file
@ -0,0 +1,100 @@
|
||||
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øída obsahuje veškeré metody potøebné k øízení poplatkù za pøíkazy.
|
||||
*
|
||||
* @author Jakub Koláø
|
||||
*
|
||||
*/
|
||||
public class BoosItemCostManager {
|
||||
private static String msg = "";
|
||||
|
||||
/**
|
||||
* Metoda zajiš<EFBFBD>uje funkci platby za pøíkaz. Vrací hodnotu v závislosti na
|
||||
* úspìšnosti platby.
|
||||
*
|
||||
* @param player
|
||||
* specifikovaný hráè
|
||||
* @param regexCommand
|
||||
* pøíkaz z konfigurace vyhovující originálnímu pøíkazu
|
||||
* @param originalCommand
|
||||
* originální pøíkaz použitý hráèem
|
||||
* @param item
|
||||
* @param price
|
||||
* cena použití pøíkazu
|
||||
* @param name
|
||||
* jméno specifického hráèe
|
||||
* @return true pokud byl úspìšnì zaplacen poplatek, nebo pokud nebyl
|
||||
* nalezen ekonomický plugin; false pokud došlo k chybì nebo hráè
|
||||
* nemìl dostatek financí
|
||||
*/
|
||||
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èuje/neukonèuje událost použití pøíkazu v závislosti na tom,
|
||||
* jakou hodnotu vrátila metoda payForCommand(Player player, String
|
||||
* regexCommand, String originalCommand, double price, String name);.
|
||||
*
|
||||
* @param event
|
||||
* událost PlayerCommandPreprocessEvent
|
||||
* @param player
|
||||
* specifický hráè
|
||||
* @param regexCommand
|
||||
* pøíkaz z konfigurace vyhovující originálnímu pøíkazu
|
||||
* @param originalCommand
|
||||
* originální pøíkaz použitý hráèem
|
||||
* @param item
|
||||
* @param price
|
||||
* cena použití pøí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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import util.boosChat;
|
||||
|
||||
/**
|
||||
* Třída obsahuje veškeré metody potřebné k řízení poplatků za příkazy.
|
||||
* Třída obsahuje veškeré metody potřebné k řízení poplatků pomocí věcí za příkazy.
|
||||
*
|
||||
* @author Jakub Koláø
|
||||
*
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: boosCooldowns
|
||||
main: cz.boosik.boosCooldown.BoosCoolDown
|
||||
version: 3.7.0
|
||||
version: 3.7.1
|
||||
authors: [LordBoos (ingame name boosik)]
|
||||
softdepend: [Vault]
|
||||
description: >
|
||||
|
Loading…
Reference in New Issue
Block a user