New features: clear uses/cooldowns on death (configurable); new command
This commit is contained in:
parent
39893585b5
commit
de3e6f88cc
|
@ -7,8 +7,10 @@ import java.util.Arrays;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class boosConfigManager {
|
||||
|
||||
|
@ -43,6 +45,8 @@ public class boosConfigManager {
|
|||
conf.addDefault("options.options.block_interact_during_warmup",
|
||||
false);
|
||||
conf.addDefault("options.options.clear_on_restart", false);
|
||||
conf.addDefault("options.options.clear_uses_on_death", false);
|
||||
conf.addDefault("options.options.clear_cooldowns_on_death", false);
|
||||
conf.addDefault("options.options.command_logging", false);
|
||||
conf.addDefault("options.units.seconds", "seconds");
|
||||
conf.addDefault("options.units.minutes", "minutes");
|
||||
|
@ -73,6 +77,8 @@ public class boosConfigManager {
|
|||
"&6Price of&e &command& &6was&e %s &6and you now have&e %s");
|
||||
conf.addDefault("options.messages.limit_achieved",
|
||||
"&6You cannot use this command anymore!&f");
|
||||
conf.addDefault("options.messages.limit_list",
|
||||
"&6Limit for command &e&command&&6 is &e&limit&&6. You can still use it &e×&&6 times.&f");
|
||||
conf.addDefault("options.messages.interact_blocked_during_warmup",
|
||||
"&6You can't do this when command is warming-up!&f");
|
||||
}
|
||||
|
@ -115,11 +121,15 @@ public class boosConfigManager {
|
|||
conf.addDefault("commands.links.link./lol", "default");
|
||||
conf.addDefault("commands.links.link./home", "default");
|
||||
conf.addDefault("commands.links.link./warp", "default");
|
||||
conf.addDefault("commands.links.link./yourCommandHere", "yourNameHere");
|
||||
String[] def = {"/home", "/lol", "/warp"};
|
||||
conf.addDefault("commands.links.linkGroups.default", Arrays.asList(def));
|
||||
String[] def2 = {"/yourCommandHere", "/someCommand", "/otherCommand"};
|
||||
conf.addDefault("commands.links.linkGroups.yourNameHere", Arrays.asList(def2));
|
||||
conf.addDefault("commands.links.link./yourCommandHere",
|
||||
"yourNameHere");
|
||||
String[] def = { "/home", "/lol", "/warp" };
|
||||
conf.addDefault("commands.links.linkGroups.default",
|
||||
Arrays.asList(def));
|
||||
String[] def2 = { "/yourCommandHere", "/someCommand",
|
||||
"/otherCommand" };
|
||||
conf.addDefault("commands.links.linkGroups.yourNameHere",
|
||||
Arrays.asList(def2));
|
||||
conf.save(confFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -373,7 +383,7 @@ public class boosConfigManager {
|
|||
limit = conf.getInt("commands.limits.limit." + pre, limit);
|
||||
return limit;
|
||||
}
|
||||
|
||||
|
||||
public static String getLink(String pre) {
|
||||
String link = null;
|
||||
pre = pre.toLowerCase();
|
||||
|
@ -387,7 +397,7 @@ public class boosConfigManager {
|
|||
linkGroup = conf.getStringList("commands.links.linkGroups." + link);
|
||||
return linkGroup;
|
||||
}
|
||||
|
||||
|
||||
public static boolean getCancelWarmUpOnGameModeChange() {
|
||||
return conf.getBoolean(
|
||||
"options.options.cancel_warmup_on_gamemode_change", false);
|
||||
|
@ -410,6 +420,50 @@ public class boosConfigManager {
|
|||
"&6You can't do this when command is warming-up!&f");
|
||||
}
|
||||
|
||||
public static boolean getCleanUsesOnDeath() {
|
||||
return conf.getBoolean("options.options.clear_uses_on_death", false);
|
||||
}
|
||||
|
||||
public static boolean getCleanCooldownsOnDeath() {
|
||||
return conf.getBoolean("options.options.clear_cooldowns_on_death",
|
||||
false);
|
||||
}
|
||||
|
||||
public static String getLimitListMessage(){
|
||||
return conf.getString("options.messages.limit_list",
|
||||
"&6Limit for command &e&command&&6 is &e&limit&&6. You can still use it &e×&&6 times.&f");
|
||||
}
|
||||
|
||||
public static String getLimGrp(Player player){
|
||||
String lim;
|
||||
if (boosCoolDown.isUsingPermissions()) {
|
||||
if (boosCoolDown.getPermissions().has(player,
|
||||
"booscooldowns.limit2")) {
|
||||
lim = "limit2";
|
||||
} else if (boosCoolDown.getPermissions().has(player,
|
||||
"booscooldowns.limit3")) {
|
||||
lim = "limit3";
|
||||
} else if (boosCoolDown.getPermissions().has(player,
|
||||
"booscooldowns.limit4")) {
|
||||
lim = "limit4";
|
||||
} else if (boosCoolDown.getPermissions().has(player,
|
||||
"booscooldowns.limit5")) {
|
||||
lim = "limit5";
|
||||
} else {
|
||||
lim = "limit";
|
||||
}
|
||||
} else {
|
||||
lim = "limit";
|
||||
}
|
||||
return lim;
|
||||
}
|
||||
|
||||
public static ConfigurationSection getLimits(Player player){
|
||||
String lim = getLimGrp(player);
|
||||
ConfigurationSection uses = conf
|
||||
.getConfigurationSection("commands.limits." + lim);
|
||||
return uses;
|
||||
}
|
||||
// public static String getWarmUpCancelledByDeathMessage() {
|
||||
// return conf.getString(
|
||||
// "commands.options.message_warmup_cancelled_by_death",
|
||||
|
|
|
@ -8,6 +8,7 @@ import net.milkbowl.vault.permission.Permission;
|
|||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
@ -73,6 +74,16 @@ public class boosCoolDown extends JavaPlugin {
|
|||
+ " config reloaded");
|
||||
return true;
|
||||
}
|
||||
if (permissions.has(sender, "booscooldowns.list.limits")
|
||||
&& args[0].equalsIgnoreCase("limits")) {
|
||||
try {
|
||||
Player send = (Player) sender;
|
||||
boosCoolDownManager.getLimits(send);
|
||||
} catch (ClassCastException e){
|
||||
log.warning("You cannot use this command from console!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (args.length == 2) {
|
||||
String jmeno = args[1];
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.bukkit.event.EventHandler;
|
|||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
@ -137,21 +138,25 @@ public class boosCoolDownListener<a> implements Listener {
|
|||
}
|
||||
if (preSubCheck3 >= 0) {
|
||||
blocked = blocked(player, preSub3, messageSub3);
|
||||
this.checkCooldown(event, player, preSub3, messageSub3, preSubCheck3, price);
|
||||
this.checkCooldown(event, player, preSub3, messageSub3,
|
||||
preSubCheck3, price);
|
||||
used = true;
|
||||
} else if (preSubCheck2 >= 0) {
|
||||
blocked = blocked(player, preSub2, messageSub2);
|
||||
this.checkCooldown(event, player, preSub2, messageSub2, preSubCheck2, price);
|
||||
this.checkCooldown(event, player, preSub2, messageSub2,
|
||||
preSubCheck2, price);
|
||||
used = true;
|
||||
} else if (preSubCheck >= 0) {
|
||||
blocked = blocked(player, preSub, messageSub);
|
||||
this.checkCooldown(event, player, preSub, messageSub, preSubCheck, price);
|
||||
this.checkCooldown(event, player, preSub, messageSub,
|
||||
preSubCheck, price);
|
||||
used = true;
|
||||
} else {
|
||||
blocked = blocked(player, preCommand, messageCommand);
|
||||
int preCmdCheck = preSubCheck(player, preCommand);
|
||||
price = prePriceCheck(player, preCommand);
|
||||
this.checkCooldown(event, player, preCommand, messageCommand, preCmdCheck, price);
|
||||
this.checkCooldown(event, player, preCommand, messageCommand,
|
||||
preCmdCheck, price);
|
||||
used = true;
|
||||
}
|
||||
|
||||
|
@ -159,7 +164,8 @@ public class boosCoolDownListener<a> implements Listener {
|
|||
blocked = blocked(player, preCommand, messageCommand);
|
||||
int preCmdCheck = preSubCheck(player, preCommand);
|
||||
price = prePriceCheck(player, preCommand);
|
||||
this.checkCooldown(event, player, preCommand, messageCommand, preCmdCheck, price);
|
||||
this.checkCooldown(event, player, preCommand, messageCommand,
|
||||
preCmdCheck, price);
|
||||
used = false;
|
||||
}
|
||||
}
|
||||
|
@ -333,10 +339,11 @@ public class boosCoolDownListener<a> implements Listener {
|
|||
|
||||
// Returns true if the command is on cooldown, false otherwise
|
||||
private void checkCooldown(PlayerCommandPreprocessEvent event,
|
||||
Player player, String pre, String message, int warmUpSeconds, int price) {
|
||||
Player player, String pre, String message, int warmUpSeconds,
|
||||
int price) {
|
||||
if (!blocked) {
|
||||
//int warmUpSeconds = 0;
|
||||
//warmUpSeconds = preSubCheck(player, pre);
|
||||
// int warmUpSeconds = 0;
|
||||
// warmUpSeconds = preSubCheck(player, pre);
|
||||
if (boosCoolDown.isUsingPermissions()) {
|
||||
if (warmUpSeconds > 0) {
|
||||
if (!boosCoolDown.getPermissions().has(player,
|
||||
|
@ -380,15 +387,14 @@ public class boosCoolDownListener<a> implements Listener {
|
|||
Player player, String pre, String message, int price) {
|
||||
String name = player.getName();
|
||||
if (price > 0) {
|
||||
if (!boosCoolDown.getPermissions().has(player,
|
||||
if (!boosCoolDown.getPermissions().has(player,
|
||||
"booscooldowns.noprice")
|
||||
&& !boosCoolDown.getPermissions().has(player,
|
||||
&& !boosCoolDown.getPermissions().has(player,
|
||||
"booscooldowns.noprice." + pre)) {
|
||||
if (boosCoolDown.getEconomy().has(name, price)) {
|
||||
boosPriceManager.payForCommand(player, pre, price, name);
|
||||
if (boosPriceManager.payForCommand(player, pre, price, name)) {
|
||||
return;
|
||||
} else {
|
||||
boosPriceManager.payForCommand(player, pre, price, name);
|
||||
//boosPriceManager.payForCommand(player, pre, price, name);
|
||||
boosCoolDownManager.cancelCooldown(player, pre);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
|
@ -689,4 +695,44 @@ public class boosCoolDownListener<a> implements Listener {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||
if (!boosConfigManager.getCleanCooldownsOnDeath()
|
||||
&& !boosConfigManager.getCleanUsesOnDeath())
|
||||
return;
|
||||
Entity entity = event.getEntity();
|
||||
if (entity != null && entity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
if (boosCoolDown.isUsingPermissions()) {
|
||||
if (player != null
|
||||
&& boosCoolDown.getPermissions().has(player,
|
||||
"booscooldowns.clear.cooldowns.death")) {
|
||||
if (boosConfigManager.getCleanCooldownsOnDeath()) {
|
||||
boosCoolDownManager.clearSomething("cooldown",
|
||||
player.getName());
|
||||
}
|
||||
}
|
||||
if (player != null
|
||||
&& boosCoolDown.getPermissions().has(player,
|
||||
"booscooldowns.clear.uses.death")) {
|
||||
if (boosConfigManager.getCleanUsesOnDeath()) {
|
||||
boosCoolDownManager.clearSomething("uses",
|
||||
player.getName());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (player != null) {
|
||||
if (boosConfigManager.getCleanCooldownsOnDeath()) {
|
||||
boosCoolDownManager.clearSomething("cooldown",
|
||||
player.getName());
|
||||
}
|
||||
if (boosConfigManager.getCleanUsesOnDeath()) {
|
||||
boosCoolDownManager.clearSomething("uses",
|
||||
player.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -97,22 +97,56 @@ public class boosCoolDownManager {
|
|||
save();
|
||||
load();
|
||||
}
|
||||
|
||||
|
||||
static void getLimits(Player player) {
|
||||
int usesNum = 0;
|
||||
int limitNum = 0;
|
||||
int num;
|
||||
String message;
|
||||
String lim = boosConfigManager.getLimGrp(player);
|
||||
ConfigurationSection uses = boosConfigManager.getLimits(player);
|
||||
if (uses != null) {
|
||||
for (String key : uses.getKeys(false)) {
|
||||
usesNum = confusers.getInt("users." + player.getName() + ".uses." + key, usesNum);
|
||||
if (lim.equals("limit")) {
|
||||
limitNum = boosConfigManager.getLimit(key);
|
||||
} else if (lim.equals("limit2")) {
|
||||
limitNum = boosConfigManager.getLimit2(key);
|
||||
} else if (lim.equals("limit3")) {
|
||||
limitNum = boosConfigManager.getLimit3(key);
|
||||
} else if (lim.equals("limit4")) {
|
||||
limitNum = boosConfigManager.getLimit4(key);
|
||||
} else if (lim.equals("limit5")) {
|
||||
limitNum = boosConfigManager.getLimit5(key);
|
||||
}
|
||||
num = limitNum - usesNum;
|
||||
if (num < 0){
|
||||
num = 0;
|
||||
}
|
||||
message = boosConfigManager.getLimitListMessage();
|
||||
message = message.replaceAll("&command&", key);
|
||||
message = message.replaceAll("&limit&", String.valueOf(limitNum));
|
||||
message = message.replaceAll("×&", String.valueOf(num));
|
||||
boosChat.sendMessageToPlayer(player, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void clearSomething(String co, String player) {
|
||||
ConfigurationSection userSection = confusers
|
||||
.getConfigurationSection("users."+player+"."+co);
|
||||
.getConfigurationSection("users." + player + "." + co);
|
||||
if (userSection == null)
|
||||
return;
|
||||
confusers.set("users." + player + "." + co, null);
|
||||
save();
|
||||
load();
|
||||
}
|
||||
|
||||
|
||||
static void clearSomething(String co, String player, String command) {
|
||||
// ConfigurationSection userSection = confusers
|
||||
// .getConfigurationSection("users."+player+"."+co+"."+command);
|
||||
// if (userSection == null)
|
||||
// return;
|
||||
// ConfigurationSection userSection = confusers
|
||||
// .getConfigurationSection("users."+player+"."+co+"."+command);
|
||||
// if (userSection == null)
|
||||
// return;
|
||||
confusers.set("users." + player + "." + co + "." + command, 0);
|
||||
save();
|
||||
load();
|
||||
|
@ -164,7 +198,8 @@ public class boosCoolDownManager {
|
|||
if (link == null) {
|
||||
setTime(player, pre);
|
||||
} else {
|
||||
List<String> linkGroup = boosConfigManager.getLinkList(link);
|
||||
List<String> linkGroup = boosConfigManager
|
||||
.getLinkList(link);
|
||||
for (String a : linkGroup) {
|
||||
setTime(player, a);
|
||||
}
|
||||
|
@ -353,19 +388,20 @@ public class boosCoolDownManager {
|
|||
pre = pre.toLowerCase();
|
||||
int uses = getUses(player, pre, message);
|
||||
uses = uses + 1;
|
||||
try{
|
||||
confusers.set("users." + player.getName() + ".uses." + pre + message,
|
||||
uses);
|
||||
try {
|
||||
confusers.set("users." + player.getName() + ".uses." + pre
|
||||
+ message, uses);
|
||||
} catch (IllegalArgumentException e) {
|
||||
boosCoolDown.log.warning("Player " + player.getName() + " used empty command and caused this error!");
|
||||
boosCoolDown.log.warning("Player " + player.getName()
|
||||
+ " used empty command and caused this error!");
|
||||
}
|
||||
}
|
||||
|
||||
static int getUses(Player player, String pre, String message) {
|
||||
pre = pre.toLowerCase();
|
||||
int uses = 0;
|
||||
uses = confusers.getInt("users." + player.getName() + ".uses." + pre + message,
|
||||
uses);
|
||||
uses = confusers.getInt("users." + player.getName() + ".uses." + pre
|
||||
+ message, uses);
|
||||
return uses;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import net.milkbowl.vault.economy.EconomyResponse;
|
|||
|
||||
public class boosPriceManager {
|
||||
private static Economy economy = boosCoolDown.getEconomy();
|
||||
public static void payForCommand(Player player, String pre, int price, String name) {
|
||||
public static boolean payForCommand(Player player, String pre, int price, String name) {
|
||||
EconomyResponse r = economy.withdrawPlayer(name, price);
|
||||
if (r.transactionSuccess()) {
|
||||
String msg = String.format(
|
||||
|
@ -17,10 +17,12 @@ public class boosPriceManager {
|
|||
economy.format(r.amount), economy.format(r.balance));
|
||||
msg = msg.replaceAll("&command&", pre);
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
return true;
|
||||
} else {
|
||||
String msg = String.format(boosConfigManager.getPaidErrorMessage(),
|
||||
r.errorMessage);
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: boosCooldown
|
||||
main: cz.boosik.boosCooldown.boosCoolDown
|
||||
version: 2.7.2
|
||||
version: 2.8.0
|
||||
author: boosik
|
||||
softdepend: [Vault,PermissionsEX]
|
||||
description: >
|
||||
|
|
Loading…
Reference in New Issue