mirror of
https://github.com/LordBoos/boosCooldowns.git
synced 2024-11-01 08:20:32 +01:00
fixed crash when economy is disabled
This commit is contained in:
parent
422a1abd1f
commit
4a08b166e0
@ -53,8 +53,10 @@ public class boosConfigManager {
|
||||
"&6Wait&e &seconds& &unit&&6 before command&e &command& &6has warmed up.&f");
|
||||
conf.setProperty("commands.options.message_warmup_alreadystarted",
|
||||
"&6Warm-Up process for&e &command& &6has already started.&f");
|
||||
conf.setProperty("commands.options.paid_error", "&6An error has occured:&e %s");
|
||||
conf.setProperty("commands.options.paid_for_command_message", "&6Price of&e &command& &6was&e %s &6and you now have&e %s");
|
||||
conf.setProperty("commands.options.paid_error",
|
||||
"&6An error has occured:&e %s");
|
||||
conf.setProperty("commands.options.paid_for_command_message",
|
||||
"&6Price of&e &command& &6was&e %s &6and you now have&e %s");
|
||||
conf.save();
|
||||
}
|
||||
}
|
||||
@ -80,7 +82,7 @@ public class boosConfigManager {
|
||||
warmUp = conf.getInt("commands.warmup." + pre, warmUp);
|
||||
return warmUp;
|
||||
}
|
||||
|
||||
|
||||
public static int getPrice(Player player, String pre) {
|
||||
int price = 0;
|
||||
pre = pre.toLowerCase();
|
||||
@ -144,11 +146,13 @@ public class boosConfigManager {
|
||||
}
|
||||
|
||||
public static String getPaidForCommandMessage() {
|
||||
return conf.getString("commands.options.paid_for_command_message", "Price of &command& was %s and you now have %s");
|
||||
return conf.getString("commands.options.paid_for_command_message",
|
||||
"Price of &command& was %s and you now have %s");
|
||||
}
|
||||
|
||||
public static String getPaidErrorMessage() {
|
||||
return conf.getString("commands.options.paid_error", "An error has occured: %s");
|
||||
return conf.getString("commands.options.paid_error",
|
||||
"An error has occured: %s");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ public class boosCoolDown extends JavaPlugin {
|
||||
private static Economy economy = null;
|
||||
@SuppressWarnings("unused")
|
||||
private static Vault vault = null;
|
||||
private static boolean usingVault;
|
||||
private static boolean usingEconomy;
|
||||
private static boolean usingPermissions;
|
||||
private static boolean usingVault = false;
|
||||
private static boolean usingEconomy = false;
|
||||
private static boolean usingPermissions = false;
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
public void onEnable() {
|
||||
@ -88,11 +88,12 @@ public class boosCoolDown extends JavaPlugin {
|
||||
+ pdfFile.getName()
|
||||
+ "]"
|
||||
+ "] permissions pluging not found, disabling permissions support.");
|
||||
} else if (!setupEconomy() && setupPermissions()){
|
||||
} else if (!setupEconomy() && setupPermissions()) {
|
||||
log.info("["
|
||||
+ pdfFile.getName()
|
||||
+ "]"
|
||||
+ " economy plugin not found, disabling prices support.");
|
||||
usingEconomy = false;
|
||||
log.info("[" + pdfFile.getName() + "]" + " found ["
|
||||
+ permissions.getName()
|
||||
+ "] plugin, enabling permissions support.");
|
||||
@ -107,7 +108,9 @@ public class boosCoolDown extends JavaPlugin {
|
||||
+ "] permissions pluging not found, disabling permissions support.");
|
||||
}
|
||||
} else {
|
||||
log.info("[" + pdfFile.getName() + "]"
|
||||
log.info("["
|
||||
+ pdfFile.getName()
|
||||
+ "]"
|
||||
+ " [Vault] not found disabling economy and permissions support.");
|
||||
usingVault = false;
|
||||
}
|
||||
@ -140,19 +143,19 @@ public class boosCoolDown extends JavaPlugin {
|
||||
public static Economy getEconomy() {
|
||||
return economy;
|
||||
}
|
||||
|
||||
public static Permission getPermissions(){
|
||||
|
||||
public static Permission getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public boolean isUsingVault() {
|
||||
public static boolean isUsingVault() {
|
||||
return usingVault;
|
||||
}
|
||||
|
||||
public static boolean isUsingEconomy() {
|
||||
return usingEconomy;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isUsingPermissions() {
|
||||
return usingPermissions;
|
||||
}
|
||||
|
@ -24,13 +24,26 @@ public class boosCoolDownEntityListener extends EntityListener {
|
||||
Entity entity = event.getEntity();
|
||||
if (entity != null && entity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
if (player != null && !boosCoolDown.getPermissions().has(player, "boosCooldowns.nocancel.damage")) {
|
||||
if (boosWarmUpManager.hasWarmUps(player)) {
|
||||
boosChat.sendMessageToPlayer(player, boosConfigManager
|
||||
.getWarmUpCancelledByDamageMessage());
|
||||
boosWarmUpManager.cancelWarmUps(player);
|
||||
}
|
||||
if (boosCoolDown.isUsingPermissions()) {
|
||||
if (player != null
|
||||
&& !boosCoolDown.getPermissions().has(player,
|
||||
"boosCooldowns.nocancel.damage")) {
|
||||
if (boosWarmUpManager.hasWarmUps(player)) {
|
||||
boosChat.sendMessageToPlayer(player, boosConfigManager
|
||||
.getWarmUpCancelledByDamageMessage());
|
||||
boosWarmUpManager.cancelWarmUps(player);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
if (player != null) {
|
||||
if (boosWarmUpManager.hasWarmUps(player)) {
|
||||
boosChat.sendMessageToPlayer(player, boosConfigManager
|
||||
.getWarmUpCancelledByDamageMessage());
|
||||
boosWarmUpManager.cancelWarmUps(player);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,44 +96,92 @@ public class boosCoolDownManager {
|
||||
static boolean coolDown(Player player, String pre, String message) {
|
||||
pre = pre.toLowerCase();
|
||||
int coolDownSeconds = boosConfigManager.getCoolDown(player, pre);
|
||||
if (coolDownSeconds > 0 && !boosCoolDown.getPermissions().has(player, "boosCooldowns.nocooldown")) {
|
||||
Date lastTime = getTime(player, pre);
|
||||
if (lastTime == null) {
|
||||
setTime(player, pre);
|
||||
return false;
|
||||
} else {
|
||||
Calendar calcurrTime = Calendar.getInstance();
|
||||
calcurrTime.setTime(getCurrTime());
|
||||
Calendar callastTime = Calendar.getInstance();
|
||||
callastTime.setTime(lastTime);
|
||||
long secondsBetween = secondsBetween(callastTime, calcurrTime);
|
||||
long waitSeconds = coolDownSeconds - secondsBetween;
|
||||
long waitMinutes = Math.round(waitSeconds / 60) + 1;
|
||||
long waitHours = Math.round(waitMinutes / 60) + 1;
|
||||
if (secondsBetween > coolDownSeconds) {
|
||||
if (boosCoolDown.isUsingPermissions()) {
|
||||
if (coolDownSeconds > 0
|
||||
&& !boosCoolDown.getPermissions().has(player,
|
||||
"boosCooldowns.nocooldown")) {
|
||||
Date lastTime = getTime(player, pre);
|
||||
if (lastTime == null) {
|
||||
setTime(player, pre);
|
||||
return false;
|
||||
} else {
|
||||
String msg = boosConfigManager.getCoolDownMessage();
|
||||
msg = msg.replaceAll("&command&", pre);
|
||||
if (waitSeconds >= 60 && 3600 >= waitSeconds) {
|
||||
msg = msg.replaceAll("&seconds&",
|
||||
Long.toString(waitMinutes));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
boosConfigManager.getUnitMinutesMessage());
|
||||
} else if (waitMinutes >= 60) {
|
||||
msg = msg.replaceAll("&seconds&",
|
||||
Long.toString(waitHours));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
boosConfigManager.getUnitHoursMessage());
|
||||
Calendar calcurrTime = Calendar.getInstance();
|
||||
calcurrTime.setTime(getCurrTime());
|
||||
Calendar callastTime = Calendar.getInstance();
|
||||
callastTime.setTime(lastTime);
|
||||
long secondsBetween = secondsBetween(callastTime,
|
||||
calcurrTime);
|
||||
long waitSeconds = coolDownSeconds - secondsBetween;
|
||||
long waitMinutes = Math.round(waitSeconds / 60) + 1;
|
||||
long waitHours = Math.round(waitMinutes / 60) + 1;
|
||||
if (secondsBetween > coolDownSeconds) {
|
||||
setTime(player, pre);
|
||||
return false;
|
||||
} else {
|
||||
msg = msg.replaceAll("&seconds&",
|
||||
Long.toString(waitSeconds));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
boosConfigManager.getUnitSecondsMessage());
|
||||
String msg = boosConfigManager.getCoolDownMessage();
|
||||
msg = msg.replaceAll("&command&", pre);
|
||||
if (waitSeconds >= 60 && 3600 >= waitSeconds) {
|
||||
msg = msg.replaceAll("&seconds&",
|
||||
Long.toString(waitMinutes));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
boosConfigManager.getUnitMinutesMessage());
|
||||
} else if (waitMinutes >= 60) {
|
||||
msg = msg.replaceAll("&seconds&",
|
||||
Long.toString(waitHours));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
boosConfigManager.getUnitHoursMessage());
|
||||
} else {
|
||||
msg = msg.replaceAll("&seconds&",
|
||||
Long.toString(waitSeconds));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
boosConfigManager.getUnitSecondsMessage());
|
||||
}
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (coolDownSeconds > 0) {
|
||||
Date lastTime = getTime(player, pre);
|
||||
if (lastTime == null) {
|
||||
setTime(player, pre);
|
||||
return false;
|
||||
} else {
|
||||
Calendar calcurrTime = Calendar.getInstance();
|
||||
calcurrTime.setTime(getCurrTime());
|
||||
Calendar callastTime = Calendar.getInstance();
|
||||
callastTime.setTime(lastTime);
|
||||
long secondsBetween = secondsBetween(callastTime,
|
||||
calcurrTime);
|
||||
long waitSeconds = coolDownSeconds - secondsBetween;
|
||||
long waitMinutes = Math.round(waitSeconds / 60) + 1;
|
||||
long waitHours = Math.round(waitMinutes / 60) + 1;
|
||||
if (secondsBetween > coolDownSeconds) {
|
||||
setTime(player, pre);
|
||||
return false;
|
||||
} else {
|
||||
String msg = boosConfigManager.getCoolDownMessage();
|
||||
msg = msg.replaceAll("&command&", pre);
|
||||
if (waitSeconds >= 60 && 3600 >= waitSeconds) {
|
||||
msg = msg.replaceAll("&seconds&",
|
||||
Long.toString(waitMinutes));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
boosConfigManager.getUnitMinutesMessage());
|
||||
} else if (waitMinutes >= 60) {
|
||||
msg = msg.replaceAll("&seconds&",
|
||||
Long.toString(waitHours));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
boosConfigManager.getUnitHoursMessage());
|
||||
} else {
|
||||
msg = msg.replaceAll("&seconds&",
|
||||
Long.toString(waitSeconds));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
boosConfigManager.getUnitSecondsMessage());
|
||||
}
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
return true;
|
||||
}
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,9 +28,11 @@ public class boosCoolDownPlayerListener extends PlayerListener {
|
||||
if (player.isOp()) {
|
||||
on = false;
|
||||
}
|
||||
if (boosCoolDown.isUsingPermissions() && boosCoolDown.getPermissions().has(player, "boosCooldowns.exception")) {
|
||||
if (boosCoolDown.isUsingPermissions()
|
||||
&& boosCoolDown.getPermissions().has(player,
|
||||
"boosCooldowns.exception")) {
|
||||
on = false;
|
||||
} else if (player.isOp()){
|
||||
} else if (player.isOp()) {
|
||||
on = false;
|
||||
} else {
|
||||
on = true;
|
||||
@ -69,43 +71,80 @@ public class boosCoolDownPlayerListener extends PlayerListener {
|
||||
private boolean checkCooldown(PlayerCommandPreprocessEvent event,
|
||||
Player player, String pre, String message) {
|
||||
int warmUpSeconds = boosConfigManager.getWarmUp(player, pre);
|
||||
if (warmUpSeconds > 0 && !boosCoolDown.getPermissions().has(player, "boosCooldowns.nowarmup")) {
|
||||
if (!boosCoolDownManager.checkWarmUpOK(player, pre, message)) {
|
||||
if (boosCoolDownManager.checkCoolDownOK(player, pre, message)) {
|
||||
boosWarmUpManager.startWarmUp(this.plugin, player, pre,
|
||||
message, warmUpSeconds);
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
if (boosCoolDown.isUsingPermissions()) {
|
||||
if (warmUpSeconds > 0
|
||||
&& !boosCoolDown.getPermissions().has(player,
|
||||
"boosCooldowns.nowarmup")) {
|
||||
if (!boosCoolDownManager.checkWarmUpOK(player, pre, message)) {
|
||||
if (boosCoolDownManager.checkCoolDownOK(player, pre,
|
||||
message)) {
|
||||
boosWarmUpManager.startWarmUp(this.plugin, player, pre,
|
||||
message, warmUpSeconds);
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
if (boosCoolDownManager.coolDown(player, pre, message)) {
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
} else {
|
||||
boosCoolDownManager
|
||||
.removeWarmUpOK(player, pre, message);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (boosCoolDownManager.coolDown(player, pre, message)) {
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
} else {
|
||||
boosCoolDownManager.removeWarmUpOK(player, pre, message);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (boosCoolDownManager.coolDown(player, pre, message)) {
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (boosConfigManager.getPrice(player, pre) > 0) {
|
||||
if (boosCoolDown.isUsingEconomy() && !boosCoolDown.getPermissions().has(player, "boosCooldowns.noprice")) {
|
||||
if (boosCoolDown.getEconomy().getBalance(player.getName()) >= boosConfigManager
|
||||
.getPrice(player, pre)) {
|
||||
boosPriceManager.payForCommand(player, pre, message);
|
||||
if (warmUpSeconds > 0) {
|
||||
if (!boosCoolDownManager.checkWarmUpOK(player, pre, message)) {
|
||||
if (boosCoolDownManager.checkCoolDownOK(player, pre,
|
||||
message)) {
|
||||
boosWarmUpManager.startWarmUp(this.plugin, player, pre,
|
||||
message, warmUpSeconds);
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
boosPriceManager.payForCommand(player, pre, message);
|
||||
if (boosCoolDownManager.coolDown(player, pre, message)) {
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
} else {
|
||||
boosCoolDownManager
|
||||
.removeWarmUpOK(player, pre, message);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (boosCoolDownManager.coolDown(player, pre, message)) {
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (boosCoolDown.isUsingEconomy()) {
|
||||
if (boosConfigManager.getPrice(player, pre) > 0) {
|
||||
if (!boosCoolDown.getPermissions().has(player,
|
||||
"boosCooldowns.noprice")) {
|
||||
if (boosCoolDown.getEconomy().getBalance(player.getName()) >= boosConfigManager
|
||||
.getPrice(player, pre)) {
|
||||
boosPriceManager.payForCommand(player, pre, message);
|
||||
} else {
|
||||
boosPriceManager.payForCommand(player, pre, message);
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -114,13 +153,26 @@ public class boosCoolDownPlayerListener extends PlayerListener {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
if (player != null && !boosCoolDown.getPermissions().has(player, "boosCooldowns.nocancel.move")) {
|
||||
if (boosWarmUpManager.hasWarmUps(player)) {
|
||||
boosChat.sendMessageToPlayer(player,
|
||||
boosConfigManager.getWarmUpCancelledByMoveMessage());
|
||||
boosWarmUpManager.cancelWarmUps(player);
|
||||
}
|
||||
if (boosCoolDown.isUsingPermissions()) {
|
||||
if (player != null
|
||||
&& !boosCoolDown.getPermissions().has(player,
|
||||
"boosCooldowns.nocancel.move")) {
|
||||
if (boosWarmUpManager.hasWarmUps(player)) {
|
||||
boosChat.sendMessageToPlayer(player,
|
||||
boosConfigManager.getWarmUpCancelledByMoveMessage());
|
||||
boosWarmUpManager.cancelWarmUps(player);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
if (player != null) {
|
||||
if (boosWarmUpManager.hasWarmUps(player)) {
|
||||
boosChat.sendMessageToPlayer(player,
|
||||
boosConfigManager.getWarmUpCancelledByMoveMessage());
|
||||
boosWarmUpManager.cancelWarmUps(player);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ public class boosWarmUpTimer extends TimerTask {
|
||||
|
||||
public boosWarmUpTimer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (player.isOnline() && boosWarmUpManager.hasWarmUps(player) == true) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: boosCooldown
|
||||
main: cz.boosik.boosCooldown.boosCoolDown
|
||||
version: 1.7.0
|
||||
version: 1.7.2
|
||||
author: boosik
|
||||
softdepend: [Vault, iConomy 4 & 5 & 6, BOSEconomy 6 & 7, EssentialsEcon, 3Co, MultiCurrency, MineConomy, eWallet, EconXP]
|
||||
description: >
|
||||
|
Loading…
Reference in New Issue
Block a user