Improved handling of Listeners. They are not registered when feature

that needs specific Listener is disabled.
This commit is contained in:
Boosik 2013-03-11 17:06:41 +01:00
parent a64cccc3c2
commit 15fc4048ae
35 changed files with 1387 additions and 1225 deletions

View File

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

View File

@ -0,0 +1,34 @@
package cz.boosik.boosCooldown.Listeners;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import util.boosChat;
import cz.boosik.boosCooldown.boosConfigManager;
import cz.boosik.boosCooldown.boosWarmUpManager;
public class boosEntityDamageListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL)
private void onEntityDamage(EntityDamageEvent event) {
if (event.isCancelled())
return;
Entity entity = event.getEntity();
if (entity != null && entity instanceof Player) {
Player player = (Player) entity;
if (player != null
&& !player.hasPermission("booscooldowns.nocancel.damage")) {
if (boosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player, boosConfigManager
.getWarmUpCancelledByDamageMessage());
boosWarmUpManager.cancelWarmUps(player);
}
}
}
}
}

View File

@ -0,0 +1,41 @@
package cz.boosik.boosCooldown.Listeners;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import cz.boosik.boosCooldown.boosConfigManager;
import cz.boosik.boosCooldown.boosCoolDownManager;
public class boosPlayerDeathListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL)
private void onPlayerDeath(PlayerDeathEvent event) {
Entity entity = event.getEntity();
if (entity != null && entity instanceof Player) {
Player player = (Player) entity;
if (player != null
&& player
.hasPermission("booscooldowns.clear.cooldowns.death")) {
if (boosConfigManager.getCleanCooldownsOnDeath()) {
boosCoolDownManager.clearSomething("cooldown", player
.getName().toLowerCase());
}
}
if (player != null
&& player.hasPermission("booscooldowns.clear.uses.death")) {
if (boosConfigManager.getCleanUsesOnDeath()) {
boosCoolDownManager.clearSomething("uses", player.getName()
.toLowerCase());
}
}
if (player != null) {
if (boosConfigManager.getStartCooldownsOnDeath()) {
boosCoolDownManager.startAllCooldowns(player);
}
}
}
}
}

View File

@ -0,0 +1,35 @@
package cz.boosik.boosCooldown.Listeners;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import util.boosChat;
import cz.boosik.boosCooldown.boosConfigManager;
import cz.boosik.boosCooldown.boosWarmUpManager;
public class boosPlayerGameModeChangeListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL)
private void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
if (event.isCancelled())
return;
Entity entity = event.getPlayer();
if (entity != null && entity instanceof Player) {
Player player = (Player) entity;
if (player != null
&& !player
.hasPermission("booscooldowns.nocancel.gamemodechange")) {
if (boosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player, boosConfigManager
.getCancelWarmupByGameModeChangeMessage());
boosWarmUpManager.cancelWarmUps(player);
}
}
}
}
}

View File

@ -0,0 +1,58 @@
package cz.boosik.boosCooldown.Listeners;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import util.boosChat;
import cz.boosik.boosCooldown.boosConfigManager;
import cz.boosik.boosCooldown.boosWarmUpManager;
public class boosPlayerInteractListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL)
private void onPlayerInteract(PlayerInteractEvent event) {
if (event.isCancelled())
return;
Entity entity = event.getPlayer();
if (entity != null && entity instanceof Player) {
Player player = (Player) entity;
if (player != null
&& !player
.hasPermission("booscooldowns.dontblock.interact")) {
if (boosWarmUpManager.hasWarmUps(player)) {
if (event.getClickedBlock().getType().name()
.equals("CHEST")
|| event.getClickedBlock().getType().name()
.equals("FURNACE")
|| event.getClickedBlock().getType().name()
.equals("BURNING_FURNACE")
|| event.getClickedBlock().getType().name()
.equals("WORKBENCH")
|| event.getClickedBlock().getType().name()
.equals("DISPENSER")
|| event.getClickedBlock().getType().name()
.equals("JUKEBOX")
|| event.getClickedBlock().getType().name()
.equals("LOCKED_CHEST")
|| event.getClickedBlock().getType().name()
.equals("ENCHANTMENT_TABLE")
|| event.getClickedBlock().getType().name()
.equals("BREWING_STAND")
|| event.getClickedBlock().getType().name()
.equals("CAULDRON")
|| event.getClickedBlock().getType().name()
.equals("STORAGE_MINECART")) {
event.setCancelled(true);
boosChat.sendMessageToPlayer(player,
boosConfigManager.getInteractBlockedMessage());
}
}
}
}
}
}

View File

@ -0,0 +1,47 @@
package cz.boosik.boosCooldown.Listeners;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import util.boosChat;
import cz.boosik.boosCooldown.boosConfigManager;
import cz.boosik.boosCooldown.boosCoolDownListener;
import cz.boosik.boosCooldown.boosWarmUpManager;
public class boosPlayerMoveListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL)
private void onPlayerMove(PlayerMoveEvent event) {
if (event.isCancelled())
return;
Player player = event.getPlayer();
if (player != null
&& !player.hasPermission("booscooldowns.nocancel.move")) {
if (boosWarmUpManager.hasWarmUps(player) && hasMoved(player)) {
boosCoolDownListener.clearLocWorld(player);
boosChat.sendMessageToPlayer(player,
boosConfigManager.getWarmUpCancelledByMoveMessage());
boosWarmUpManager.cancelWarmUps(player);
}
}
}
private static boolean hasMoved(Player player) {
String curworld = player.getWorld().getName();
String cmdworld = boosCoolDownListener.playerworld.get(player);
Location curloc = player.getLocation();
Location cmdloc = boosCoolDownListener.playerloc.get(player);
if (!curworld.equals(cmdworld)) {
return true;
} else if (cmdloc.distanceSquared(curloc) > 2) {
return true;
}
return false;
}
}

View File

@ -0,0 +1,30 @@
package cz.boosik.boosCooldown.Listeners;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import util.boosChat;
import cz.boosik.boosCooldown.boosConfigManager;
import cz.boosik.boosCooldown.boosWarmUpManager;
public class boosPlayerToggleSneakListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL)
private void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
if (event.isCancelled())
return;
Player player = event.getPlayer();
if (player != null
&& !player.hasPermission("booscooldowns.nocancel.sneak")) {
if (boosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player,
boosConfigManager.getCancelWarmupOnSneakMessage());
boosWarmUpManager.cancelWarmUps(player);
}
}
}
}

View File

@ -0,0 +1,30 @@
package cz.boosik.boosCooldown.Listeners;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerToggleSprintEvent;
import util.boosChat;
import cz.boosik.boosCooldown.boosConfigManager;
import cz.boosik.boosCooldown.boosWarmUpManager;
public class boosPlayerToggleSprintListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL)
private void onPlayerToggleSprint(PlayerToggleSprintEvent event) {
if (event.isCancelled())
return;
Player player = event.getPlayer();
if (player != null
&& !player.hasPermission("booscooldowns.nocancel.sprint")) {
if (boosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player,
boosConfigManager.getCancelWarmupOnSprintMessage());
boosWarmUpManager.cancelWarmUps(player);
}
}
}
}

View File

@ -0,0 +1,42 @@
package cz.boosik.boosCooldown.Listeners;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;
import util.boosChat;
import cz.boosik.boosCooldown.boosConfigManager;
public class boosSignChangeListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL)
public void onSignChange(SignChangeEvent event) {
if (event.isCancelled())
return;
Player player = event.getPlayer();
String line1 = event.getLine(0);
String line2 = event.getLine(1);
if (line1.equals("[boosCooldowns]")) {
if (line2.equals("player")
&& !player
.hasPermission("booscooldowns.signs.player.place")) {
boosChat.sendMessageToPlayer(player,
boosConfigManager.getCannotCreateSignMessage());
event.getBlock().breakNaturally();
event.setCancelled(true);
return;
}
if (line2.equals("server")
&& !player
.hasPermission("booscooldowns.signs.server.place")) {
boosChat.sendMessageToPlayer(player,
boosConfigManager.getCannotCreateSignMessage());
event.getBlock().breakNaturally();
event.setCancelled(true);
return;
}
}
}
}

View File

@ -0,0 +1,66 @@
package cz.boosik.boosCooldown.Listeners;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import util.boosChat;
import cz.boosik.boosCooldown.boosConfigManager;
import cz.boosik.boosCooldown.boosCoolDown;
public class boosSignInteractListener implements Listener {
private final boosCoolDown plugin;
public boosSignInteractListener(boosCoolDown instance) {
plugin = instance;
}
@EventHandler(priority = EventPriority.NORMAL)
private void onSignInteract(PlayerInteractEvent event) {
String msg;
if (event.isCancelled())
return;
if (event.hasBlock() && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (event.getClickedBlock().getType() == Material.SIGN_POST
|| event.getClickedBlock().getType() == Material.WALL_SIGN) {
Sign s = (Sign) event.getClickedBlock().getState();
String line1 = s.getLine(0);
String line2 = s.getLine(1);
String line3 = s.getLine(2);
String line4 = s.getLine(3);
Player player = event.getPlayer();
if (line1.equals("[boosCooldowns]")) {
if (line2.equals("player")
&& player
.hasPermission("booscooldowns.signs.player.use")) {
msg = line3;
if (line3.endsWith("+") || !line4.isEmpty()) {
msg = line3.substring(0, line3.length() - 1) + " "
+ line4;
}
event.getPlayer().chat(msg);
} else if (line2.equals("server")
&& player
.hasPermission("booscooldowns.signs.server.use")) {
msg = line3;
if (line3.endsWith("+") || !line4.isEmpty()) {
msg = line3.substring(0, line3.length() - 1) + " "
+ line4;
}
plugin.getServer().dispatchCommand(
plugin.getServer().getConsoleSender(), msg);
} else {
boosChat.sendMessageToPlayer(player,
boosConfigManager.getCannotUseSignMessage());
}
}
}
}
}
}

View File

@ -19,6 +19,413 @@ public class boosConfigManager {
private static File confFile;
static List<String> players = new LinkedList<String>();
public static String getAlias(String message) {
return conf.getString("commands.aliases." + message);
}
public static ConfigurationSection getAliases() {
ConfigurationSection aliases = conf
.getConfigurationSection("commands.aliases");
return aliases;
}
public static boolean getBlockInteractDuringWarmup() {
return conf.getBoolean("options.options.block_interact_during_warmup",
false);
}
public static String getCancelWarmupByGameModeChangeMessage() {
return conf.getString(
"options.messages.warmup_cancelled_by_gamemode_change",
"&6Warm-ups have been cancelled due to changing gamemode.&f");
}
public static boolean getCancelWarmUpOnDamage() {
return conf
.getBoolean("options.options.cancel_warmup_on_damage", false);
}
public static boolean getCancelWarmUpOnGameModeChange() {
return conf.getBoolean(
"options.options.cancel_warmup_on_gamemode_change", false);
}
public static boolean getCancelWarmupOnMove() {
return conf.getBoolean("options.options.cancel_warmup_on_move", false);
}
public static boolean getCancelWarmupOnSneak() {
return conf.getBoolean("options.options.cancel_warmup_on_sneak", false);
}
public static String getCancelWarmupOnSneakMessage() {
return conf.getString("options.messages.warmup_cancelled_by_sneak",
"&6Warm-ups have been cancelled due to sneaking.&f");
}
public static boolean getCancelWarmupOnSprint() {
return conf
.getBoolean("options.options.cancel_warmup_on_sprint", false);
}
public static String getCancelWarmupOnSprintMessage() {
return conf.getString("options.messages.warmup_cancelled_by_sprint",
"&6Warm-ups have been cancelled due to sprinting.&f");
}
public static String getCannotCreateSignMessage() {
return conf.getString("options.messages.cannot_create_sign",
"&6You are not allowed to create this kind of signs!&f");
}
public static String getCannotUseSignMessage() {
return conf.getString("options.messages.cannot_use_sign",
"&6You are not allowed to use this sign!&f");
}
public static boolean getCleanCooldownsOnDeath() {
return conf.getBoolean("options.options.clear_cooldowns_on_death",
false);
}
public static boolean getCleanUsesOnDeath() {
return conf.getBoolean("options.options.clear_uses_on_death", false);
}
static boolean getClearOnRestart() {
return conf.getBoolean("options.options.clear_on_restart", false);
}
public static String getCommandBlockedMessage() {
return conf.getString("options.messages.limit_achieved",
"&6You cannot use this command anymore!&f");
}
public static boolean getCommandLogging() {
return conf.getBoolean("options.options.command_logging", false);
}
static int getCoolDown(String pre) {
int coolDown = 0;
pre = pre.toLowerCase();
coolDown = conf.getInt("commands.cooldowns.cooldown." + pre, coolDown);
return coolDown;
}
public static int getCoolDown2(String pre) {
int coolDown = 0;
pre = pre.toLowerCase();
coolDown = conf.getInt("commands.cooldowns.cooldown2." + pre, coolDown);
return coolDown;
}
public static int getCoolDown3(String pre) {
int coolDown = 0;
pre = pre.toLowerCase();
coolDown = conf.getInt("commands.cooldowns.cooldown3." + pre, coolDown);
return coolDown;
}
public static int getCoolDown4(String pre) {
int coolDown = 0;
pre = pre.toLowerCase();
coolDown = conf.getInt("commands.cooldowns.cooldown4." + pre, coolDown);
return coolDown;
}
public static int getCoolDown5(String pre) {
int coolDown = 0;
pre = pre.toLowerCase();
coolDown = conf.getInt("commands.cooldowns.cooldown5." + pre, coolDown);
return coolDown;
}
static String getCoolDownMessage() {
return conf
.getString(
"options.messages.cooling_down",
"&6Wait&e &seconds& seconds&6 before you can use command&e &command& &6again.&f");
}
public static String getCooldownsGrp(Player player) {
String cooldown;
if (player.hasPermission("booscooldowns.cooldown2")) {
cooldown = "cooldown2";
} else if (player.hasPermission("booscooldowns.cooldown3")) {
cooldown = "cooldown3";
} else if (player.hasPermission("booscooldowns.cooldown4")) {
cooldown = "cooldown4";
} else if (player.hasPermission("booscooldowns.cooldown5")) {
cooldown = "cooldown5";
} else {
cooldown = "cooldown";
}
return cooldown;
}
public static Set<String> getCooldownsList(Player player) {
String cool = getCooldownsGrp(player);
boosCoolDown.log.info("Cooldown group: " + cool);
ConfigurationSection cooldownsList;
cooldownsList = conf.getConfigurationSection("commands.cooldowns."
+ cool);
Set<String> cooldowns = cooldownsList.getKeys(false);
return cooldowns;
}
public static String getInteractBlockedMessage() {
return conf.getString(
"options.messages.interact_blocked_during_warmup",
"&6You can't do this when command is warming-up!&f");
}
public static String getLimGrp(Player player) {
String lim;
if (player.hasPermission("booscooldowns.limit2")) {
lim = "limit2";
} else if (player.hasPermission("booscooldowns.limit3")) {
lim = "limit3";
} else if (player.hasPermission("booscooldowns.limit4")) {
lim = "limit4";
} else if (player.hasPermission("booscooldowns.limit5")) {
lim = "limit5";
} else {
lim = "limit";
}
return lim;
}
public static int getLimit(String pre) {
int limit = -1;
pre = pre.toLowerCase();
limit = conf.getInt("commands.limits.limit." + pre, limit);
return limit;
}
public static int getLimit2(String pre) {
int limit = -1;
pre = pre.toLowerCase();
limit = conf.getInt("commands.limits.limit2." + pre, limit);
return limit;
}
public static int getLimit3(String pre) {
int limit = -1;
pre = pre.toLowerCase();
limit = conf.getInt("commands.limits.limit3." + pre, limit);
return limit;
}
public static int getLimit4(String pre) {
int limit = -1;
pre = pre.toLowerCase();
limit = conf.getInt("commands.limits.limit4." + pre, limit);
return limit;
}
public static int getLimit5(String pre) {
int limit = -1;
pre = pre.toLowerCase();
limit = conf.getInt("commands.limits.limit5." + pre, limit);
return limit;
}
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&times&&6 times.&f");
}
public static ConfigurationSection getLimits(Player player) {
String lim = getLimGrp(player);
ConfigurationSection uses = conf
.getConfigurationSection("commands.limits." + lim);
return uses;
}
public static boolean getLimitsEnabled() {
return conf.getBoolean("options.options.enable_limits", true);
}
public static String getLink(String pre) {
String link = null;
pre = pre.toLowerCase();
link = conf.getString("commands.links.link." + pre, link);
return link;
}
public static List<String> getLinkList(String link) {
List<String> linkGroup;
link = link.toLowerCase();
linkGroup = conf.getStringList("commands.links.linkGroups." + link);
return linkGroup;
}
public static String getPaidErrorMessage() {
return conf.getString("options.messages.paid_error",
"An error has occured: %s");
}
public static String getPaidForCommandMessage() {
return conf.getString("options.messages.paid_for_command",
"Price of &command& was %s and you now have %s");
}
public static int getPrice(String pre) {
int price = 0;
pre = pre.toLowerCase();
price = conf.getInt("commands.prices.price." + pre, price);
return price;
}
public static int getPrice2(String pre) {
int price = 0;
pre = pre.toLowerCase();
price = conf.getInt("commands.prices.price2." + pre, price);
return price;
}
public static int getPrice3(String pre) {
int price = 0;
pre = pre.toLowerCase();
price = conf.getInt("commands.prices.price3." + pre, price);
return price;
}
public static int getPrice4(String pre) {
int price = 0;
pre = pre.toLowerCase();
price = conf.getInt("commands.prices.price4." + pre, price);
return price;
}
public static int getPrice5(String pre) {
int price = 0;
pre = pre.toLowerCase();
price = conf.getInt("commands.prices.price5." + pre, price);
return price;
}
public static boolean getSignCommands() {
return conf.getBoolean("options.options.command_signs", false);
}
public static boolean getStartCooldownsOnDeath() {
return conf.getBoolean("options.options.start_cooldowns_on_death",
false);
}
static String getUnitHoursMessage() {
return conf.getString("options.units.hours", "hours");
}
static String getUnitMinutesMessage() {
return conf.getString("options.units.minutes", "minutes");
}
static String getUnitSecondsMessage() {
return conf.getString("options.units.seconds", "seconds");
}
public static int getWarmUp(String pre) {
int warmUp = -1;
pre = pre.toLowerCase();
warmUp = conf.getInt("commands.warmups.warmup." + pre, warmUp);
return warmUp;
}
public static int getWarmUp2(String pre) {
int warmUp = -1;
pre = pre.toLowerCase();
warmUp = conf.getInt("commands.warmups.warmup2." + pre, warmUp);
return warmUp;
}
public static int getWarmUp3(String pre) {
int warmUp = -1;
pre = pre.toLowerCase();
warmUp = conf.getInt("commands.warmups.warmup3." + pre, warmUp);
return warmUp;
}
public static int getWarmUp4(String pre) {
int warmUp = -1;
pre = pre.toLowerCase();
warmUp = conf.getInt("commands.warmups.warmup4." + pre, warmUp);
return warmUp;
}
public static int getWarmUp5(String pre) {
int warmUp = -1;
pre = pre.toLowerCase();
warmUp = conf.getInt("commands.warmups.warmup5." + pre, warmUp);
return warmUp;
}
static String getWarmUpAlreadyStartedMessage() {
return conf.getString("options.messages.warmup_already_started",
"&6Warm-Up process for&e &command& &6has already started.&f");
}
public static String getWarmUpCancelledByDamageMessage() {
return conf.getString("options.messages.warmup_cancelled_by_damage",
"&6Warm-ups have been cancelled due to receiving damage.&f");
}
public static String getWarmUpCancelledByMoveMessage() {
return conf.getString("options.messages.warmup_cancelled_by_move",
"&6Warm-ups have been cancelled due to moving.&f");
}
static String getWarmUpMessage() {
return conf
.getString("options.messages.warming_up",
"&6Wait&e &seconds& seconds&6 before command&e &command& &6has warmed up.&f");
}
static void load() {
try {
conf.load(confFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InvalidConfigurationException e) {
e.printStackTrace();
}
}
static void reload() {
conf = new YamlConfiguration();
load();
}
static void setAddToConfigFile(String coSetnout, String co, int hodnota) {
co = co.toLowerCase();
coSetnout = coSetnout.toLowerCase();
String sekce = null;
if (coSetnout.contains("cooldown")) {
sekce = "cooldowns";
} else if (coSetnout.contains("warmup")) {
sekce = "warmups";
} else if (coSetnout.contains("limit")) {
sekce = "limits";
} else if (coSetnout.contains("price")) {
sekce = "prices";
} else {
return;
}
reload();
conf.set("commands." + sekce + "." + coSetnout + "." + co, hodnota);
try {
conf.save(confFile);
} catch (IOException e) {
e.printStackTrace();
}
reload();
}
// test
@SuppressWarnings("static-access")
public boosConfigManager(boosCoolDown boosCoolDown) {
@ -38,6 +445,7 @@ public class boosConfigManager {
this.confFile = new File(boosCoolDown.getDataFolder(), "config.yml");
this.conf = new YamlConfiguration();
conf.options().copyDefaults(true);
conf.addDefault("options.options.save_interval_in_minutes", 15);
conf.addDefault("options.options.cancel_warmup_on_damage", false);
conf.addDefault("options.options.cancel_warmup_on_move", false);
conf.addDefault("options.options.cancel_warmup_on_sneak", false);
@ -146,408 +554,7 @@ public class boosConfigManager {
}
}
static void load() {
try {
conf.load(confFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InvalidConfigurationException e) {
e.printStackTrace();
}
}
static void reload() {
conf = new YamlConfiguration();
load();
}
static int getCoolDown(String pre) {
int coolDown = 0;
pre = pre.toLowerCase();
coolDown = conf.getInt("commands.cooldowns.cooldown." + pre, coolDown);
return coolDown;
}
public static int getCoolDown2(String pre) {
int coolDown = 0;
pre = pre.toLowerCase();
coolDown = conf.getInt("commands.cooldowns.cooldown2." + pre, coolDown);
return coolDown;
}
public static int getCoolDown3(String pre) {
int coolDown = 0;
pre = pre.toLowerCase();
coolDown = conf.getInt("commands.cooldowns.cooldown3." + pre, coolDown);
return coolDown;
}
public static int getCoolDown4(String pre) {
int coolDown = 0;
pre = pre.toLowerCase();
coolDown = conf.getInt("commands.cooldowns.cooldown4." + pre, coolDown);
return coolDown;
}
public static int getCoolDown5(String pre) {
int coolDown = 0;
pre = pre.toLowerCase();
coolDown = conf.getInt("commands.cooldowns.cooldown5." + pre, coolDown);
return coolDown;
}
static void setAddToConfigFile(String coSetnout, String co, int hodnota) {
co = co.toLowerCase();
coSetnout = coSetnout.toLowerCase();
String sekce = null;
if (coSetnout.contains("cooldown")) {
sekce = "cooldowns";
} else if (coSetnout.contains("warmup")) {
sekce = "warmups";
} else if (coSetnout.contains("limit")) {
sekce = "limits";
} else if (coSetnout.contains("price")) {
sekce = "prices";
} else {
return;
}
reload();
conf.set("commands." + sekce + "." + coSetnout + "." + co, hodnota);
try {
conf.save(confFile);
} catch (IOException e) {
e.printStackTrace();
}
reload();
}
public static int getWarmUp(String pre) {
int warmUp = -1;
pre = pre.toLowerCase();
warmUp = conf.getInt("commands.warmups.warmup." + pre, warmUp);
return warmUp;
}
public static int getWarmUp2(String pre) {
int warmUp = -1;
pre = pre.toLowerCase();
warmUp = conf.getInt("commands.warmups.warmup2." + pre, warmUp);
return warmUp;
}
public static int getWarmUp3(String pre) {
int warmUp = -1;
pre = pre.toLowerCase();
warmUp = conf.getInt("commands.warmups.warmup3." + pre, warmUp);
return warmUp;
}
public static int getWarmUp4(String pre) {
int warmUp = -1;
pre = pre.toLowerCase();
warmUp = conf.getInt("commands.warmups.warmup4." + pre, warmUp);
return warmUp;
}
public static int getWarmUp5(String pre) {
int warmUp = -1;
pre = pre.toLowerCase();
warmUp = conf.getInt("commands.warmups.warmup5." + pre, warmUp);
return warmUp;
}
public static int getPrice(String pre) {
int price = 0;
pre = pre.toLowerCase();
price = conf.getInt("commands.prices.price." + pre, price);
return price;
}
public static int getPrice2(String pre) {
int price = 0;
pre = pre.toLowerCase();
price = conf.getInt("commands.prices.price2." + pre, price);
return price;
}
public static int getPrice3(String pre) {
int price = 0;
pre = pre.toLowerCase();
price = conf.getInt("commands.prices.price3." + pre, price);
return price;
}
public static int getPrice4(String pre) {
int price = 0;
pre = pre.toLowerCase();
price = conf.getInt("commands.prices.price4." + pre, price);
return price;
}
public static int getPrice5(String pre) {
int price = 0;
pre = pre.toLowerCase();
price = conf.getInt("commands.prices.price5." + pre, price);
return price;
}
static String getCoolDownMessage() {
return conf
.getString(
"options.messages.cooling_down",
"&6Wait&e &seconds& seconds&6 before you can use command&e &command& &6again.&f");
}
static String getWarmUpCancelledByMoveMessage() {
return conf.getString("options.messages.warmup_cancelled_by_move",
"&6Warm-ups have been cancelled due to moving.&f");
}
static String getWarmUpCancelledByDamageMessage() {
return conf.getString("options.messages.warmup_cancelled_by_damage",
"&6Warm-ups have been cancelled due to receiving damage.&f");
}
static String getWarmUpMessage() {
return conf
.getString("options.messages.warming_up",
"&6Wait&e &seconds& seconds&6 before command&e &command& &6has warmed up.&f");
}
static String getWarmUpAlreadyStartedMessage() {
return conf.getString("options.messages.warmup_already_started",
"&6Warm-Up process for&e &command& &6has already started.&f");
}
public static String getPaidForCommandMessage() {
return conf.getString("options.messages.paid_for_command",
"Price of &command& was %s and you now have %s");
}
public static String getPaidErrorMessage() {
return conf.getString("options.messages.paid_error",
"An error has occured: %s");
}
public static String getCancelWarmupOnSneakMessage() {
return conf.getString("options.messages.warmup_cancelled_by_sneak",
"&6Warm-ups have been cancelled due to sneaking.&f");
}
public static String getCancelWarmupOnSprintMessage() {
return conf.getString("options.messages.warmup_cancelled_by_sprint",
"&6Warm-ups have been cancelled due to sprinting.&f");
}
public static String getCommandBlockedMessage() {
return conf.getString("options.messages.limit_achieved",
"&6You cannot use this command anymore!&f");
}
static String getUnitSecondsMessage() {
return conf.getString("options.units.seconds", "seconds");
}
static String getUnitMinutesMessage() {
return conf.getString("options.units.minutes", "minutes");
}
static String getUnitHoursMessage() {
return conf.getString("options.units.hours", "hours");
}
static boolean getClearOnRestart() {
return conf.getBoolean("options.options.clear_on_restart", false);
}
public static boolean getCancelWarmUpOnDamage() {
return conf
.getBoolean("options.options.cancel_warmup_on_damage", false);
}
public static boolean getCancelWarmupOnMove() {
return conf.getBoolean("options.options.cancel_warmup_on_move", false);
}
public static boolean getCancelWarmupOnSprint() {
return conf
.getBoolean("options.options.cancel_warmup_on_sprint", false);
}
public static boolean getCancelWarmupOnSneak() {
return conf.getBoolean("options.options.cancel_warmup_on_sneak", false);
}
public static boolean getCommandLogging() {
return conf.getBoolean("options.options.command_logging", false);
}
public static int getLimit2(String pre) {
int limit = -1;
pre = pre.toLowerCase();
limit = conf.getInt("commands.limits.limit2." + pre, limit);
return limit;
}
public static int getLimit3(String pre) {
int limit = -1;
pre = pre.toLowerCase();
limit = conf.getInt("commands.limits.limit3." + pre, limit);
return limit;
}
public static int getLimit4(String pre) {
int limit = -1;
pre = pre.toLowerCase();
limit = conf.getInt("commands.limits.limit4." + pre, limit);
return limit;
}
public static int getLimit5(String pre) {
int limit = -1;
pre = pre.toLowerCase();
limit = conf.getInt("commands.limits.limit5." + pre, limit);
return limit;
}
public static int getLimit(String pre) {
int limit = -1;
pre = pre.toLowerCase();
limit = conf.getInt("commands.limits.limit." + pre, limit);
return limit;
}
public static String getLink(String pre) {
String link = null;
pre = pre.toLowerCase();
link = conf.getString("commands.links.link." + pre, link);
return link;
}
public static List<String> getLinkList(String link) {
List<String> linkGroup;
link = link.toLowerCase();
linkGroup = conf.getStringList("commands.links.linkGroups." + link);
return linkGroup;
}
public static boolean getCancelWarmUpOnGameModeChange() {
return conf.getBoolean(
"options.options.cancel_warmup_on_gamemode_change", false);
}
public static String getCancelWarmupByGameModeChangeMessage() {
return conf.getString(
"options.messages.warmup_cancelled_by_gamemode_change",
"&6Warm-ups have been cancelled due to changing gamemode.&f");
}
public static boolean getBlockInteractDuringWarmup() {
return conf.getBoolean("options.options.block_interact_during_warmup",
false);
}
public static String getInteractBlockedMessage() {
return conf.getString(
"options.messages.interact_blocked_during_warmup",
"&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&times&&6 times.&f");
}
public static String getLimGrp(Player player) {
String lim;
if (player.hasPermission("booscooldowns.limit2")) {
lim = "limit2";
} else if (player.hasPermission("booscooldowns.limit3")) {
lim = "limit3";
} else if (player.hasPermission("booscooldowns.limit4")) {
lim = "limit4";
} else if (player.hasPermission("booscooldowns.limit5")) {
lim = "limit5";
} else {
lim = "limit";
}
return lim;
}
public static String getCooldownsGrp(Player player) {
String cooldown;
if (player.hasPermission("booscooldowns.cooldown2")) {
cooldown = "cooldown2";
} else if (player.hasPermission("booscooldowns.cooldown3")) {
cooldown = "cooldown3";
} else if (player.hasPermission("booscooldowns.cooldown4")) {
cooldown = "cooldown4";
} else if (player.hasPermission("booscooldowns.cooldown5")) {
cooldown = "cooldown5";
} else {
cooldown = "cooldown";
}
return cooldown;
}
public static ConfigurationSection getLimits(Player player) {
String lim = getLimGrp(player);
ConfigurationSection uses = conf
.getConfigurationSection("commands.limits." + lim);
return uses;
}
public static Set<String> getCooldownsList(Player player) {
String cool = getCooldownsGrp(player);
boosCoolDown.log.info("Cooldown group: "+cool);
ConfigurationSection cooldownsList;
cooldownsList = conf.getConfigurationSection("commands.cooldowns." + cool);
Set<String> cooldowns = cooldownsList.getKeys(false);
return cooldowns;
}
public static ConfigurationSection getAliases() {
ConfigurationSection aliases = conf
.getConfigurationSection("commands.aliases");
return aliases;
}
public static String getAlias(String message) {
return conf.getString("commands.aliases." + message);
}
public static boolean getSignCommands() {
return conf.getBoolean("options.options.command_signs", false);
}
public static String getCannotUseSignMessage() {
return conf.getString("options.messages.cannot_use_sign",
"&6You are not allowed to use this sign!&f");
}
public static String getCannotCreateSignMessage() {
return conf.getString("options.messages.cannot_create_sign",
"&6You are not allowed to create this kind of signs!&f");
}
public static boolean getLimitsEnabled() {
return conf.getBoolean("options.options.enable_limits", true);
}
public static boolean getStartCooldownsOnDeath() {
return conf.getBoolean("options.options.start_cooldowns_on_death", false);
public static int getSaveInterval() {
return conf.getInt("options.options.save_interval_in_minutes", 15);
}
}

View File

@ -5,61 +5,75 @@ import java.util.logging.Logger;
import net.milkbowl.vault.Vault;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;
import org.mcstats.MetricsLite;
import util.boosChat;
import cz.boosik.boosCooldown.Listeners.boosEntityDamageListener;
import cz.boosik.boosCooldown.Listeners.boosPlayerDeathListener;
import cz.boosik.boosCooldown.Listeners.boosPlayerGameModeChangeListener;
import cz.boosik.boosCooldown.Listeners.boosPlayerInteractListener;
import cz.boosik.boosCooldown.Listeners.boosPlayerMoveListener;
import cz.boosik.boosCooldown.Listeners.boosPlayerToggleSneakListener;
import cz.boosik.boosCooldown.Listeners.boosPlayerToggleSprintListener;
import cz.boosik.boosCooldown.Listeners.boosSignChangeListener;
import cz.boosik.boosCooldown.Listeners.boosSignInteractListener;
public class boosCoolDown extends JavaPlugin {
public class boosCoolDown extends JavaPlugin implements Runnable {
public static final Logger log = Logger.getLogger("Minecraft");
public static PluginDescriptionFile pdfFile;
private static Economy economy = null;
private static boolean usingVault = false;
private PluginManager pm;
public void onEnable() {
pdfFile = this.getDescription();
PluginDescriptionFile pdfFile = this.getDescription();
log.info("[" + pdfFile.getName() + "]" + " version "
+ pdfFile.getVersion() + " by " + pdfFile.getAuthors()
+ " is enabled!");
new boosConfigManager(this);
boosConfigManager.load();
new boosCoolDownManager(this);
boosCoolDownManager.load();
pm = getServer().getPluginManager();
pm.registerEvents(new boosCoolDownListener<Object>(this), this);
initializeVault();
if (boosConfigManager.getClearOnRestart()) {
boosCoolDownManager.clear();
}
try {
MetricsLite metrics = new MetricsLite(this);
metrics.start();
} catch (IOException e) {
// Failed to submit the stats :-(
}
public static void commandLogger(String player, String command) {
log.info("[" + "boosLogger" + "] " + player + " used command "
+ command);
}
public void onDisable() {
if (boosConfigManager.getClearOnRestart() == true) {
boosCoolDownManager.clear();
log.info("[" + pdfFile.getName() + "]" + " cooldowns cleared!");
public static Economy getEconomy() {
return economy;
}
public static Logger getLog() {
return log;
}
public static boolean isUsingVault() {
return usingVault;
}
private void initializeVault() {
Plugin x = this.getServer().getPluginManager().getPlugin("Vault");
if (x != null & x instanceof Vault) {
log.info("[" + pdfFile.getName() + "]"
+ " found [Vault] searching for economy plugin.");
usingVault = true;
if (setupEconomy()) {
log.info("[" + pdfFile.getName() + "]" + " found ["
+ economy.getName()
+ "] plugin, enabling prices support.");
} else {
log.info("["
+ pdfFile.getName()
+ "]"
+ " economy plugin not found, disabling prices support.");
}
} else {
boosCoolDownManager.save();
log.info("[" + pdfFile.getName() + "]" + " cooldowns saved!");
log.info("[" + pdfFile.getName() + "]"
+ " [Vault] not found disabling economy support.");
usingVault = false;
}
log.info("[" + pdfFile.getName() + "]" + " version "
+ pdfFile.getVersion() + " disabled!");
}
@Override
@ -70,7 +84,7 @@ public class boosCoolDown extends JavaPlugin {
if (args.length == 1) {
if (sender.hasPermission("booscooldowns.reload")
&& args[0].equalsIgnoreCase("reload")) {
boosConfigManager.reload();
reload();
boosChat.sendMessageToCommandSender(sender,
"&6[" + pdfFile.getName() + "]&e"
+ " config reloaded");
@ -221,17 +235,88 @@ public class boosCoolDown extends JavaPlugin {
return false;
}
public static Economy getEconomy() {
return economy;
public void onDisable() {
if (boosConfigManager.getClearOnRestart() == true) {
boosCoolDownManager.clear();
log.info("[" + pdfFile.getName() + "]" + " cooldowns cleared!");
} else {
boosCoolDownManager.save();
log.info("[" + pdfFile.getName() + "]" + " cooldowns saved!");
}
log.info("[" + pdfFile.getName() + "]" + " version "
+ pdfFile.getVersion() + " disabled!");
}
public static boolean isUsingVault() {
return usingVault;
public void onEnable() {
pdfFile = this.getDescription();
PluginDescriptionFile pdfFile = this.getDescription();
log.info("[" + pdfFile.getName() + "]" + " version "
+ pdfFile.getVersion() + " by " + pdfFile.getAuthors()
+ " is enabled!");
new boosConfigManager(this);
boosConfigManager.load();
new boosCoolDownManager(this);
boosCoolDownManager.load();
pm = getServer().getPluginManager();
registerListeners();
initializeVault();
BukkitScheduler scheduler = this.getServer().getScheduler();
scheduler.scheduleSyncRepeatingTask(this, this, boosConfigManager.getSaveInterval()*1200, boosConfigManager.getSaveInterval()*1200);
if (boosConfigManager.getClearOnRestart()) {
boosCoolDownManager.clear();
}
try {
MetricsLite metrics = new MetricsLite(this);
metrics.start();
} catch (IOException e) {
// Failed to submit the stats :-(
}
}
public static void commandLogger(String player, String command) {
log.info("[" + "boosLogger" + "] " + player + " used command "
+ command);
private void registerListeners() {
HandlerList.unregisterAll(this);
pm.registerEvents(new boosCoolDownListener<Object>(this), this);
if (boosConfigManager.getCancelWarmUpOnDamage()) {
pm.registerEvents(new boosEntityDamageListener(), this);
}
if (boosConfigManager.getCleanCooldownsOnDeath()
|| boosConfigManager.getCleanUsesOnDeath()
|| boosConfigManager.getStartCooldownsOnDeath()) {
pm.registerEvents(new boosPlayerDeathListener(), this);
}
if (boosConfigManager.getCancelWarmUpOnGameModeChange()) {
pm.registerEvents(new boosPlayerGameModeChangeListener(), this);
}
if (boosConfigManager.getBlockInteractDuringWarmup()) {
pm.registerEvents(new boosPlayerInteractListener(), this);
}
if (boosConfigManager.getCancelWarmupOnMove()) {
pm.registerEvents(new boosPlayerMoveListener(), this);
}
if (boosConfigManager.getCancelWarmupOnSneak()) {
pm.registerEvents(new boosPlayerToggleSneakListener(), this);
}
if (boosConfigManager.getCancelWarmupOnSprint()) {
pm.registerEvents(new boosPlayerToggleSprintListener(), this);
}
if (boosConfigManager.getSignCommands()) {
pm.registerEvents(new boosSignChangeListener(), this);
pm.registerEvents(new boosSignInteractListener(this), this);
}
}
private void reload() {
boosConfigManager.reload();
registerListeners();
}
@Override
public void run() {
boosCoolDownManager.save();
boosCoolDownManager.load();
log.info("[boosCooldowns] Config saved!");
}
private boolean setupEconomy() {
@ -246,31 +331,4 @@ public class boosCoolDown extends JavaPlugin {
}
return false;
}
private void initializeVault() {
Plugin x = this.getServer().getPluginManager().getPlugin("Vault");
if (x != null & x instanceof Vault) {
log.info("[" + pdfFile.getName() + "]"
+ " found [Vault] searching for economy plugin.");
usingVault = true;
if (setupEconomy()) {
log.info("[" + pdfFile.getName() + "]" + " found ["
+ economy.getName()
+ "] plugin, enabling prices support.");
} else {
log.info("["
+ pdfFile.getName()
+ "]"
+ " economy plugin not found, disabling prices support.");
}
} else {
log.info("[" + pdfFile.getName() + "]"
+ " [Vault] not found disabling economy support.");
usingVault = false;
}
}
public static Logger getLog() {
return log;
}
}

View File

@ -3,38 +3,125 @@ package cz.boosik.boosCooldown;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.event.player.PlayerToggleSprintEvent;
import util.boosChat;
public class boosCoolDownListener<a> implements Listener {
private final boosCoolDown plugin;
private boolean blocked = false;
private static ConcurrentHashMap<Player, Location> playerloc = new ConcurrentHashMap<Player, Location>();
private static ConcurrentHashMap<Player, String> playerworld = new ConcurrentHashMap<Player, String>();
public static ConcurrentHashMap<Player, Location> playerloc = new ConcurrentHashMap<Player, Location>();
public static ConcurrentHashMap<Player, String> playerworld = new ConcurrentHashMap<Player, String>();
public static void clearLocWorld(Player player) {
boosCoolDownListener.playerloc.remove(player);
boosCoolDownListener.playerworld.remove(player);
}
public boosCoolDownListener(boosCoolDown instance) {
plugin = instance;
}
private boolean blocked(Player player, String pre, String msg) {
int limit = -1;
int uses = boosCoolDownManager.getUses(player, pre, msg);
if (player.hasPermission("booscooldowns.nolimit")
|| player.hasPermission("booscooldowns.nolimit." + pre)) {
} else {
if (player.hasPermission("booscooldowns.limit2")) {
limit = boosConfigManager.getLimit2(pre);
if (limit == -1) {
return false;
} else if (limit <= uses) {
return true;
}
} else if (player.hasPermission("booscooldowns.limit3")) {
limit = boosConfigManager.getLimit3(pre);
if (limit == -1) {
return false;
} else if (limit <= uses) {
return true;
}
} else if (player.hasPermission("booscooldowns.limit4")) {
limit = boosConfigManager.getLimit4(pre);
if (limit == -1) {
return false;
} else if (limit <= uses) {
return true;
}
} else if (player.hasPermission("booscooldowns.limit5")) {
limit = boosConfigManager.getLimit5(pre);
if (limit == -1) {
return false;
} else if (limit <= uses) {
return true;
}
} else {
limit = boosConfigManager.getLimit(pre);
if (limit == -1) {
return false;
} else if (limit <= uses) {
return true;
}
}
}
return false;
}
// 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) {
if (!blocked) {
if (warmUpSeconds > 0) {
if (!player.hasPermission("booscooldowns.nowarmup")
&& !player.hasPermission("booscooldowns.nowarmup."
+ pre)) {
start(event, player, pre, message, warmUpSeconds);
}
} else {
if (boosCoolDownManager.coolDown(player, pre)) {
event.setCancelled(true);
}
}
if (!event.isCancelled()) {
payForCommand(event, player, pre, price);
}
} else {
event.setCancelled(true);
String msg = String.format(boosConfigManager
.getCommandBlockedMessage());
boosChat.sendMessageToPlayer(player, msg);
}
if (!event.isCancelled()) {
boosCoolDownManager.setUses(player, pre, message);
if (boosConfigManager.getCommandLogging()) {
boosCoolDown.commandLogger(player.getName(), pre + message);
}
}
}
private boolean isPluginOnForPlayer(Player player) {
boolean on;
if (player.isOp()) {
on = false;
}
if (player.hasPermission("booscooldowns.exception")) {
on = false;
} else if (player.isOp()) {
on = false;
} else {
on = true;
}
return on;
}
@EventHandler(priority = EventPriority.LOW)
private void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
if (event.isCancelled()) {
@ -190,155 +277,24 @@ public class boosCoolDownListener<a> implements Listener {
}
}
private int preSubCheck(Player player, String preSub) {
if (player.hasPermission("booscooldowns.warmup2")) {
return boosConfigManager.getWarmUp2(preSub);
} else if (player.hasPermission("booscooldowns.warmup3")) {
return boosConfigManager.getWarmUp3(preSub);
} else if (player.hasPermission("booscooldowns.warmup4")) {
return boosConfigManager.getWarmUp4(preSub);
} else if (player.hasPermission("booscooldowns.warmup5")) {
return boosConfigManager.getWarmUp5(preSub);
} else {
return boosConfigManager.getWarmUp(preSub);
}
}
private int preLimitCheck(Player player, String preSub) {
if (player.hasPermission("booscooldowns.limit2")) {
return boosConfigManager.getLimit2(preSub);
} else if (player.hasPermission("booscooldowns.limit3")) {
return boosConfigManager.getLimit3(preSub);
} else if (player.hasPermission("booscooldowns.limit4")) {
return boosConfigManager.getLimit4(preSub);
} else if (player.hasPermission("booscooldowns.limit5")) {
return boosConfigManager.getLimit5(preSub);
} else {
return boosConfigManager.getLimit(preSub);
}
}
private int preCDCheck(Player player, String preSub) {
if (player.hasPermission("booscooldowns.cooldown2")) {
return boosConfigManager.getCoolDown2(preSub);
} else if (player.hasPermission("booscooldowns.cooldown3")) {
return boosConfigManager.getCoolDown3(preSub);
} else if (player.hasPermission("booscooldowns.cooldown4")) {
return boosConfigManager.getCoolDown4(preSub);
} else if (player.hasPermission("booscooldowns.cooldown5")) {
return boosConfigManager.getCoolDown5(preSub);
} else {
return boosConfigManager.getCoolDown(preSub);
}
}
private int prePriceCheck(Player player, String preSub) {
if (player.hasPermission("booscooldowns.cooldown2")) {
return boosConfigManager.getPrice2(preSub);
} else if (player.hasPermission("booscooldowns.cooldown3")) {
return boosConfigManager.getPrice3(preSub);
} else if (player.hasPermission("booscooldowns.cooldown4")) {
return boosConfigManager.getPrice4(preSub);
} else if (player.hasPermission("booscooldowns.cooldown5")) {
return boosConfigManager.getPrice5(preSub);
} else {
return boosConfigManager.getPrice(preSub);
}
}
private boolean blocked(Player player, String pre, String msg) {
int limit = -1;
int uses = boosCoolDownManager.getUses(player, pre, msg);
if (player.hasPermission("booscooldowns.nolimit")
|| player.hasPermission("booscooldowns.nolimit." + pre)) {
} else {
if (player.hasPermission("booscooldowns.limit2")) {
limit = boosConfigManager.getLimit2(pre);
if (limit == -1) {
return false;
} else if (limit <= uses) {
return true;
}
} else if (player.hasPermission("booscooldowns.limit3")) {
limit = boosConfigManager.getLimit3(pre);
if (limit == -1) {
return false;
} else if (limit <= uses) {
return true;
}
} else if (player.hasPermission("booscooldowns.limit4")) {
limit = boosConfigManager.getLimit4(pre);
if (limit == -1) {
return false;
} else if (limit <= uses) {
return true;
}
} else if (player.hasPermission("booscooldowns.limit5")) {
limit = boosConfigManager.getLimit5(pre);
if (limit == -1) {
return false;
} else if (limit <= uses) {
return true;
}
@EventHandler(priority = EventPriority.LOW)
private void onPlayerChat(AsyncPlayerChatEvent event) {
String chatMessage = event.getMessage();
String temp = "globalchat";
int price = 0;
Player player = event.getPlayer();
if (chatMessage.startsWith("!")) {
if (!boosCoolDownManager.checkCoolDownOK(player, temp, chatMessage)) {
event.setCancelled(true);
return;
} else {
limit = boosConfigManager.getLimit(pre);
if (limit == -1) {
return false;
} else if (limit <= uses) {
return true;
}
}
}
return false;
}
private boolean isPluginOnForPlayer(Player player) {
boolean on;
if (player.isOp()) {
on = false;
}
if (player.hasPermission("booscooldowns.exception")) {
on = false;
} else if (player.isOp()) {
on = false;
} else {
on = true;
}
return on;
}
// 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) {
if (!blocked) {
if (warmUpSeconds > 0) {
if (!player.hasPermission("booscooldowns.nowarmup")
&& !player.hasPermission("booscooldowns.nowarmup."
+ pre)) {
start(event, player, pre, message, warmUpSeconds);
}
} else {
if (boosCoolDownManager.coolDown(player, pre)) {
if (boosCoolDownManager.coolDown(player, temp)) {
event.setCancelled(true);
return;
}
}
if (!event.isCancelled()) {
payForCommand(event, player, pre, price);
}
} else {
event.setCancelled(true);
String msg = String.format(boosConfigManager
.getCommandBlockedMessage());
boosChat.sendMessageToPlayer(player, msg);
}
if (!event.isCancelled()) {
boosCoolDownManager.setUses(player, pre, message);
if (boosConfigManager.getCommandLogging()) {
boosCoolDown.commandLogger(player.getName(), pre + message);
}
price = prePriceCheck(player, temp);
payForCommand2(event, player, temp, price);
}
}
@ -376,6 +332,64 @@ public class boosCoolDownListener<a> implements Listener {
}
}
private int preCDCheck(Player player, String preSub) {
if (player.hasPermission("booscooldowns.cooldown2")) {
return boosConfigManager.getCoolDown2(preSub);
} else if (player.hasPermission("booscooldowns.cooldown3")) {
return boosConfigManager.getCoolDown3(preSub);
} else if (player.hasPermission("booscooldowns.cooldown4")) {
return boosConfigManager.getCoolDown4(preSub);
} else if (player.hasPermission("booscooldowns.cooldown5")) {
return boosConfigManager.getCoolDown5(preSub);
} else {
return boosConfigManager.getCoolDown(preSub);
}
}
private int preLimitCheck(Player player, String preSub) {
if (player.hasPermission("booscooldowns.limit2")) {
return boosConfigManager.getLimit2(preSub);
} else if (player.hasPermission("booscooldowns.limit3")) {
return boosConfigManager.getLimit3(preSub);
} else if (player.hasPermission("booscooldowns.limit4")) {
return boosConfigManager.getLimit4(preSub);
} else if (player.hasPermission("booscooldowns.limit5")) {
return boosConfigManager.getLimit5(preSub);
} else {
return boosConfigManager.getLimit(preSub);
}
}
private int prePriceCheck(Player player, String preSub) {
if (player.hasPermission("booscooldowns.cooldown2")) {
return boosConfigManager.getPrice2(preSub);
} else if (player.hasPermission("booscooldowns.cooldown3")) {
return boosConfigManager.getPrice3(preSub);
} else if (player.hasPermission("booscooldowns.cooldown4")) {
return boosConfigManager.getPrice4(preSub);
} else if (player.hasPermission("booscooldowns.cooldown5")) {
return boosConfigManager.getPrice5(preSub);
} else {
return boosConfigManager.getPrice(preSub);
}
}
private int preSubCheck(Player player, String preSub) {
if (player.hasPermission("booscooldowns.warmup2")) {
return boosConfigManager.getWarmUp2(preSub);
} else if (player.hasPermission("booscooldowns.warmup3")) {
return boosConfigManager.getWarmUp3(preSub);
} else if (player.hasPermission("booscooldowns.warmup4")) {
return boosConfigManager.getWarmUp4(preSub);
} else if (player.hasPermission("booscooldowns.warmup5")) {
return boosConfigManager.getWarmUp5(preSub);
} else {
return boosConfigManager.getWarmUp(preSub);
}
}
private void start(PlayerCommandPreprocessEvent event, Player player,
String pre, String message, int warmUpSeconds) {
if (!boosCoolDownManager.checkWarmUpOK(player, pre, message)) {
@ -398,311 +412,4 @@ public class boosCoolDownListener<a> implements Listener {
}
}
}
@EventHandler(priority = EventPriority.NORMAL)
private void onPlayerMove(PlayerMoveEvent event) {
if (!boosConfigManager.getCancelWarmupOnMove())
return;
if (event.isCancelled())
return;
Player player = event.getPlayer();
if (player != null
&& !player.hasPermission("booscooldowns.nocancel.move")) {
if (boosWarmUpManager.hasWarmUps(player) && hasMoved(player)) {
clearLocWorld(player);
boosChat.sendMessageToPlayer(player,
boosConfigManager.getWarmUpCancelledByMoveMessage());
boosWarmUpManager.cancelWarmUps(player);
}
}
}
private static boolean hasMoved(Player player) {
String curworld = player.getWorld().getName();
String cmdworld = playerworld.get(player);
Location curloc = player.getLocation();
Location cmdloc = playerloc.get(player);
if (!curworld.equals(cmdworld)) {
return true;
} else if (cmdloc.distanceSquared(curloc) > 2) {
return true;
}
return false;
}
public static void clearLocWorld(Player player) {
playerloc.remove(player);
playerworld.remove(player);
}
@EventHandler(priority = EventPriority.NORMAL)
private void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
if (!boosConfigManager.getCancelWarmupOnSneak())
return;
if (event.isCancelled())
return;
Player player = event.getPlayer();
if (player != null
&& !player.hasPermission("booscooldowns.nocancel.sneak")) {
if (boosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player,
boosConfigManager.getCancelWarmupOnSneakMessage());
boosWarmUpManager.cancelWarmUps(player);
}
}
}
@EventHandler(priority = EventPriority.NORMAL)
private void onPlayerToggleSprint(PlayerToggleSprintEvent event) {
if (!boosConfigManager.getCancelWarmupOnSprint())
return;
if (event.isCancelled())
return;
Player player = event.getPlayer();
if (player != null
&& !player.hasPermission("booscooldowns.nocancel.sprint")) {
if (boosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player,
boosConfigManager.getCancelWarmupOnSprintMessage());
boosWarmUpManager.cancelWarmUps(player);
}
}
}
@EventHandler(priority = EventPriority.NORMAL)
private void onEntityDamage(EntityDamageEvent event) {
if (!boosConfigManager.getCancelWarmUpOnDamage())
return;
if (event.isCancelled())
return;
Entity entity = event.getEntity();
if (entity != null && entity instanceof Player) {
Player player = (Player) entity;
if (player != null
&& !player.hasPermission("booscooldowns.nocancel.damage")) {
if (boosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player, boosConfigManager
.getWarmUpCancelledByDamageMessage());
boosWarmUpManager.cancelWarmUps(player);
}
}
}
}
@EventHandler(priority = EventPriority.NORMAL)
private void onPlayerInteract(PlayerInteractEvent event) {
if (!boosConfigManager.getBlockInteractDuringWarmup())
return;
if (event.isCancelled())
return;
Entity entity = event.getPlayer();
if (entity != null && entity instanceof Player) {
Player player = (Player) entity;
if (player != null
&& !player
.hasPermission("booscooldowns.dontblock.interact")) {
if (boosWarmUpManager.hasWarmUps(player)) {
if (event.getClickedBlock().getType().name()
.equals("CHEST")
|| event.getClickedBlock().getType().name()
.equals("FURNACE")
|| event.getClickedBlock().getType().name()
.equals("BURNING_FURNACE")
|| event.getClickedBlock().getType().name()
.equals("WORKBENCH")
|| event.getClickedBlock().getType().name()
.equals("DISPENSER")
|| event.getClickedBlock().getType().name()
.equals("JUKEBOX")
|| event.getClickedBlock().getType().name()
.equals("LOCKED_CHEST")
|| event.getClickedBlock().getType().name()
.equals("ENCHANTMENT_TABLE")
|| event.getClickedBlock().getType().name()
.equals("BREWING_STAND")
|| event.getClickedBlock().getType().name()
.equals("CAULDRON")
|| event.getClickedBlock().getType().name()
.equals("STORAGE_MINECART")) {
event.setCancelled(true);
boosChat.sendMessageToPlayer(player,
boosConfigManager.getInteractBlockedMessage());
}
}
}
}
}
@EventHandler(priority = EventPriority.NORMAL)
private void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
if (!boosConfigManager.getCancelWarmUpOnGameModeChange())
return;
if (event.isCancelled())
return;
Entity entity = event.getPlayer();
if (entity != null && entity instanceof Player) {
Player player = (Player) entity;
if (player != null
&& !player
.hasPermission("booscooldowns.nocancel.gamemodechange")) {
if (boosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player, boosConfigManager
.getCancelWarmupByGameModeChangeMessage());
boosWarmUpManager.cancelWarmUps(player);
}
}
}
}
@EventHandler(priority = EventPriority.NORMAL)
private void onPlayerDeath(PlayerDeathEvent event) {
if (!boosConfigManager.getCleanCooldownsOnDeath()
&& !boosConfigManager.getCleanUsesOnDeath()
&& !boosConfigManager.getStartCooldownsOnDeath()){
return;}
Entity entity = event.getEntity();
if (entity != null && entity instanceof Player) {
Player player = (Player) entity;
if (player != null
&& player
.hasPermission("booscooldowns.clear.cooldowns.death")) {
if (boosConfigManager.getCleanCooldownsOnDeath()) {
boosCoolDownManager.clearSomething("cooldown", player
.getName().toLowerCase());
}
}
if (player != null
&& player.hasPermission("booscooldowns.clear.uses.death")) {
if (boosConfigManager.getCleanUsesOnDeath()) {
boosCoolDownManager.clearSomething("uses", player.getName()
.toLowerCase());
}
}
if (player != null){
if (boosConfigManager.getStartCooldownsOnDeath()) {
boosCoolDownManager.startAllCooldowns(player);
}
}
}
}
@EventHandler(priority = EventPriority.LOW)
private void onPlayerChat(AsyncPlayerChatEvent event) {
String chatMessage = event.getMessage();
String temp = "globalchat";
int price = 0;
Player player = event.getPlayer();
if (chatMessage.startsWith("!")) {
if (!boosCoolDownManager.checkCoolDownOK(player, temp, chatMessage)) {
event.setCancelled(true);
return;
} else {
if (boosCoolDownManager.coolDown(player, temp)) {
event.setCancelled(true);
return;
}
}
price = prePriceCheck(player, temp);
payForCommand2(event, player, temp, price);
}
}
@EventHandler(priority = EventPriority.NORMAL)
private void onSignInteract(PlayerInteractEvent event) {
String msg;
if (!boosConfigManager.getSignCommands()) {
return;
}
if (event.isCancelled()) {
return;
}
if (event.hasBlock() && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (event.getClickedBlock().getType() == Material.SIGN_POST
|| event.getClickedBlock().getType() == Material.WALL_SIGN) {
Sign s = (Sign) event.getClickedBlock().getState();
String line1 = s.getLine(0);
String line2 = s.getLine(1);
String line3 = s.getLine(2);
String line4 = s.getLine(3);
Player player = event.getPlayer();
if (line1.equals("[boosCooldowns]")) {
if (line2.equals("player")
&& player
.hasPermission("booscooldowns.signs.player.use")) {
msg = line3;
if (line3.endsWith("+") || !line4.isEmpty()) {
msg = line3.substring(0, line3.length() - 1) + " "
+ line4;
}
event.getPlayer().chat(msg);
} else if (line2.equals("server")
&& player
.hasPermission("booscooldowns.signs.server.use")) {
msg = line3;
if (line3.endsWith("+") || !line4.isEmpty()) {
msg = line3.substring(0, line3.length() - 1) + " "
+ line4;
}
plugin.getServer().dispatchCommand(
plugin.getServer().getConsoleSender(), msg);
} else {
boosChat.sendMessageToPlayer(player,
boosConfigManager.getCannotUseSignMessage());
}
}
}
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onSignChange(SignChangeEvent event) {
if (!boosConfigManager.getSignCommands()) {
return;
}
if (event.isCancelled()) {
return;
}
Player player = event.getPlayer();
String line1 = event.getLine(0);
String line2 = event.getLine(1);
if (line1.equals("[boosCooldowns]")) {
if (line2.equals("player")
&& !player
.hasPermission("booscooldowns.signs.player.place")) {
boosChat.sendMessageToPlayer(player,
boosConfigManager.getCannotCreateSignMessage());
event.getBlock().breakNaturally();
event.setCancelled(true);
return;
}
if (line2.equals("server")
&& !player
.hasPermission("booscooldowns.signs.server.place")) {
boosChat.sendMessageToPlayer(player,
boosConfigManager.getCannotCreateSignMessage());
event.getBlock().breakNaturally();
event.setCancelled(true);
return;
}
}
}
}

View File

@ -21,147 +21,10 @@ public class boosCoolDownManager {
private static YamlConfiguration confusers;
private static File confFile;
public boosCoolDownManager(boosCoolDown bCoolDown) {
confFile = new File(bCoolDown.getDataFolder(), "users.yml");
confusers = new YamlConfiguration();
if (confFile.exists()) {
try {
confusers.load(confFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InvalidConfigurationException e) {
e.printStackTrace();
}
} else {
try {
confFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
}
static void load() {
try {
confusers.load(confFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InvalidConfigurationException e) {
e.printStackTrace();
}
}
static void save() {
try {
confFile.createNewFile();
confusers.save(confFile);
} catch (IOException e) {
e.printStackTrace();
}
}
static void clear() {
ConfigurationSection userSection = confusers
.getConfigurationSection("users");
if (userSection == null)
return;
for (String user : userSection.getKeys(false)) {
// clear cooldown
ConfigurationSection cooldown = confusers
.getConfigurationSection("users." + user + ".cooldown");
if (cooldown != null) {
for (String key : cooldown.getKeys(false)) {
confusers.set("users." + user + ".cooldown." + key, null);
}
}
confusers.set("users." + user + ".cooldown", null);
// clear warmup
ConfigurationSection warmup = confusers
.getConfigurationSection("users." + user + ".warmup");
if (warmup != null) {
for (String key : warmup.getKeys(false)) {
confusers.set("users." + user + ".warmup." + key, null);
}
}
confusers.set("users." + user + ".warmup", null);
confusers.set("users." + user, null);
}
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().toLowerCase().hashCode() + ".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("&times&", String.valueOf(num));
boosChat.sendMessageToPlayer(player, message);
}
}
}
static void clearSomething(String co, String player) {
ConfigurationSection userSection = confusers
.getConfigurationSection("users." + player.toLowerCase().hashCode() + "." + co);
if (userSection == null)
return;
confusers.set("users." + player.toLowerCase().hashCode() + "." + co, null);
save();
load();
}
static void clearSomething(String co, String player, String command) {
int pre2 = command.toLowerCase().hashCode();
confusers.set("users." + player.toLowerCase().hashCode() + "." + co + "." + pre2, 0);
save();
load();
}
static boolean coolDown(Player player, String pre) {
pre = pre.toLowerCase();
int coolDownSeconds = 0;
coolDownSeconds = getCooldownGroup(player, pre, coolDownSeconds);
if (coolDownSeconds > 0
&& !player.hasPermission("booscooldowns.nocooldown")
&& !player.hasPermission("booscooldowns.nocooldown." + pre)) {
return cd(player, pre, coolDownSeconds);
}
return false;
static void cancelCooldown(Player player, String pre) {
int pre2 = pre.toLowerCase().hashCode();
confusers.set("users." + player.getName().toLowerCase().hashCode()
+ ".cooldown." + pre2, null);
}
private static boolean cd(Player player, String pre, int coolDownSeconds) {
@ -224,10 +87,167 @@ public class boosCoolDownManager {
}
}
static void cancelCooldown(Player player, String pre) {
static void clear() {
ConfigurationSection userSection = confusers
.getConfigurationSection("users");
if (userSection == null)
return;
for (String user : userSection.getKeys(false)) {
// clear cooldown
ConfigurationSection cooldown = confusers
.getConfigurationSection("users." + user + ".cooldown");
if (cooldown != null) {
for (String key : cooldown.getKeys(false)) {
confusers.set("users." + user + ".cooldown." + key, null);
}
}
confusers.set("users." + user + ".cooldown", null);
// clear warmup
ConfigurationSection warmup = confusers
.getConfigurationSection("users." + user + ".warmup");
if (warmup != null) {
for (String key : warmup.getKeys(false)) {
confusers.set("users." + user + ".warmup." + key, null);
}
}
confusers.set("users." + user + ".warmup", null);
confusers.set("users." + user, null);
}
save();
load();
}
public static void clearSomething(String co, String player) {
ConfigurationSection userSection = confusers
.getConfigurationSection("users."
+ player.toLowerCase().hashCode() + "." + co);
if (userSection == null)
return;
confusers.set("users." + player.toLowerCase().hashCode() + "." + co,
null);
save();
load();
}
static void clearSomething(String co, String player, String command) {
int pre2 = command.toLowerCase().hashCode();
confusers.set("users." + player.toLowerCase().hashCode() + "." + co
+ "." + pre2, 0);
save();
load();
}
static boolean coolDown(Player player, String pre) {
pre = pre.toLowerCase();
int coolDownSeconds = 0;
coolDownSeconds = getCooldownGroup(player, pre, coolDownSeconds);
if (coolDownSeconds > 0
&& !player.hasPermission("booscooldowns.nocooldown")
&& !player.hasPermission("booscooldowns.nocooldown." + pre)) {
return cd(player, pre, coolDownSeconds);
}
return false;
}
private static int getCooldownGroup(Player player, String pre,
int coolDownSeconds) {
if (player.hasPermission("booscooldowns.cooldown2")) {
coolDownSeconds = boosConfigManager.getCoolDown2(pre);
} else if (player.hasPermission("booscooldowns.cooldown3")) {
coolDownSeconds = boosConfigManager.getCoolDown3(pre);
} else if (player.hasPermission("booscooldowns.cooldown4")) {
coolDownSeconds = boosConfigManager.getCoolDown4(pre);
} else if (player.hasPermission("booscooldowns.cooldown5")) {
coolDownSeconds = boosConfigManager.getCoolDown5(pre);
} else {
coolDownSeconds = boosConfigManager.getCoolDown(pre);
}
return coolDownSeconds;
}
static Date getCurrTime() {
String currTime = "";
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
currTime = sdf.format(cal.getTime());
Date time = null;
try {
time = sdf.parse(currTime);
return time;
} catch (ParseException e) {
return null;
}
}
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().toLowerCase().hashCode() + ".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("&times&", String.valueOf(num));
boosChat.sendMessageToPlayer(player, message);
}
}
}
static Date getTime(Player player, String pre) {
int pre2 = pre.toLowerCase().hashCode();
confusers.set("users." + player.getName().toLowerCase().hashCode() + ".cooldown."
String confTime = "";
confTime = confusers.getString("users."
+ player.getName().toLowerCase().hashCode() + ".cooldown."
+ pre2, null);
if (confTime != null && !confTime.equals("")) {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
Date lastDate = null;
try {
lastDate = sdf.parse(confTime);
return lastDate;
} catch (ParseException e) {
return null;
}
}
return null;
}
static int getUses(Player player, String pre, String message) {
int pre2 = pre.toLowerCase().hashCode();
int message2 = message.toLowerCase().hashCode();
int uses = 0;
uses = confusers.getInt("users."
+ player.getName().toLowerCase().hashCode() + ".uses." + pre2
+ message2, uses);
return uses;
}
static boolean checkCoolDownOK(Player player, String pre, String message) {
@ -276,65 +296,49 @@ public class boosCoolDownManager {
return true;
}
private static int getCooldownGroup(Player player, String pre,
int coolDownSeconds) {
if (player.hasPermission("booscooldowns.cooldown2")) {
coolDownSeconds = boosConfigManager.getCoolDown2(pre);
} else if (player.hasPermission("booscooldowns.cooldown3")) {
coolDownSeconds = boosConfigManager.getCoolDown3(pre);
} else if (player.hasPermission("booscooldowns.cooldown4")) {
coolDownSeconds = boosConfigManager.getCoolDown4(pre);
} else if (player.hasPermission("booscooldowns.cooldown5")) {
coolDownSeconds = boosConfigManager.getCoolDown5(pre);
} else {
coolDownSeconds = boosConfigManager.getCoolDown(pre);
}
return coolDownSeconds;
}
static void setTime(Player player, String pre) {
static boolean checkWarmUpOK(Player player, String pre, String message) {
int pre2 = pre.toLowerCase().hashCode();
String currTime = "";
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
currTime = sdf.format(cal.getTime());
confusers.set("users." + player.getName().toLowerCase().hashCode() + ".cooldown."
+ pre2, currTime);
int ok = 0;
ok = confusers.getInt(
"users." + player.getName().toLowerCase().hashCode()
+ ".warmup." + pre2, ok);
if (ok == 1) {
return true;
}
return false;
}
static Date getCurrTime() {
String currTime = "";
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
currTime = sdf.format(cal.getTime());
Date time = null;
static void load() {
try {
time = sdf.parse(currTime);
return time;
} catch (ParseException e) {
return null;
confusers.load(confFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InvalidConfigurationException e) {
e.printStackTrace();
}
}
static Date getTime(Player player, String pre) {
static void removeWarmUp(Player player, String pre, String message) {
int pre2 = pre.toLowerCase().hashCode();
String confTime = "";
confTime = confusers.getString("users."
+ player.getName().toLowerCase().hashCode() + ".cooldown." + pre2, null);
confusers.set("users." + player.getName().toLowerCase().hashCode()
+ ".warmup." + pre2, null);
}
if (confTime != null && !confTime.equals("")) {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
Date lastDate = null;
static void removeWarmUpOK(Player player, String pre, String message) {
int pre2 = pre.toLowerCase().hashCode();
confusers.set("users." + player.getName().toLowerCase().hashCode()
+ ".warmup." + pre2, null);
}
try {
lastDate = sdf.parse(confTime);
return lastDate;
} catch (ParseException e) {
return null;
}
static void save() {
try {
confFile.createNewFile();
confusers.save(confFile);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static long secondsBetween(Calendar startDate, Calendar endDate) {
@ -347,33 +351,14 @@ public class boosCoolDownManager {
return secondsBetween;
}
static void setWarmUpOK(Player player, String pre, String message) {
static void setTime(Player player, String pre) {
int pre2 = pre.toLowerCase().hashCode();
confusers.set("users." + player.getName().toLowerCase().hashCode() + ".warmup."
+ pre2, 1);
}
static boolean checkWarmUpOK(Player player, String pre, String message) {
int pre2 = pre.toLowerCase().hashCode();
int ok = 0;
ok = confusers.getInt("users." + player.getName().toLowerCase().hashCode()
+ ".warmup." + pre2, ok);
if (ok == 1) {
return true;
}
return false;
}
static void removeWarmUpOK(Player player, String pre, String message) {
int pre2 = pre.toLowerCase().hashCode();
confusers.set("users." + player.getName().toLowerCase().hashCode() + ".warmup."
+ pre2, null);
}
static void removeWarmUp(Player player, String pre, String message) {
int pre2 = pre.toLowerCase().hashCode();
confusers.set("users." + player.getName().toLowerCase().hashCode() + ".warmup."
+ pre2, null);
String currTime = "";
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
currTime = sdf.format(cal.getTime());
confusers.set("users." + player.getName().toLowerCase().hashCode()
+ ".cooldown." + pre2, currTime);
}
static void setUses(Player player, String pre, String message) {
@ -383,8 +368,9 @@ public class boosCoolDownManager {
int uses = getUses(player, pre, message);
uses = uses + 1;
try {
confusers.set("users." + player.getName().toLowerCase().hashCode()
+ ".uses." + pre2 + message2, uses);
confusers.set("users."
+ player.getName().toLowerCase().hashCode() + ".uses."
+ pre2 + message2, uses);
} catch (IllegalArgumentException e) {
boosCoolDown.log.warning("Player " + player.getName()
+ " used empty command and caused this error!");
@ -394,21 +380,41 @@ public class boosCoolDownManager {
}
}
static int getUses(Player player, String pre, String message) {
static void setWarmUpOK(Player player, String pre, String message) {
int pre2 = pre.toLowerCase().hashCode();
int message2 = message.toLowerCase().hashCode();
int uses = 0;
uses = confusers.getInt("users." + player.getName().toLowerCase().hashCode()
+ ".uses." + pre2 + message2, uses);
return uses;
confusers.set("users." + player.getName().toLowerCase().hashCode()
+ ".warmup." + pre2, 1);
}
public static void startAllCooldowns(Player player) {
for (String a : boosConfigManager.getCooldownsList(player)) {
coolDown(player, a);
}
}
public boosCoolDownManager(boosCoolDown bCoolDown) {
confFile = new File(bCoolDown.getDataFolder(), "users.yml");
confusers = new YamlConfiguration();
if (confFile.exists()) {
try {
confusers.load(confFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InvalidConfigurationException e) {
e.printStackTrace();
}
} else {
try {
confFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

View File

@ -1,12 +1,12 @@
package cz.boosik.boosCooldown;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.entity.Player;
import util.boosChat;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
public class boosPriceManager {
private static Economy economy = boosCoolDown.getEconomy();

View File

@ -14,6 +14,54 @@ public class boosWarmUpManager {
static Timer scheduler;
public static void cancelWarmUps(Player player) {
Iterator<String> iter = playercommands.keySet().iterator();
while (iter.hasNext()) {
if (iter.next().startsWith(player.getName() + "@")) {
killTimer(player);
iter.remove();
}
}
}
public static boolean hasWarmUps(Player player) {
for (String key : playercommands.keySet()) {
if (key.startsWith(player.getName() + "@")) {
return true;
}
}
return false;
}
public static boolean isWarmUpProcess(Player player, String pre,
String message) {
pre = pre.toLowerCase();
if (playercommands.containsKey(player.getName() + "@" + pre)) {
return true;
}
return false;
}
// public static void cancelWarmUps(Player player) {
// for (String key : playercommands.keySet()) {
// if (key.startsWith(player.getName() + "@")) {
// removeWarmUpProcess(key);
// }
// }
// }
public static void killTimer(Player player) {
for (String key : playercommands.keySet()) {
if (key.startsWith(player.getName() + "@")) {
playercommands.get(key).cancel();
}
}
}
public static void removeWarmUpProcess(String tag) {
boosWarmUpManager.playercommands.remove(tag);
}
public static void startWarmUp(boosCoolDown bCoolDown, Player player,
String pre, String message, int warmUpSeconds) {
pre = pre.toLowerCase();
@ -49,52 +97,4 @@ public class boosWarmUpManager {
boosChat.sendMessageToPlayer(player, msg);
}
}
public static boolean isWarmUpProcess(Player player, String pre,
String message) {
pre = pre.toLowerCase();
if (playercommands.containsKey(player.getName() + "@" + pre)) {
return true;
}
return false;
}
public static void removeWarmUpProcess(String tag) {
boosWarmUpManager.playercommands.remove(tag);
}
// public static void cancelWarmUps(Player player) {
// for (String key : playercommands.keySet()) {
// if (key.startsWith(player.getName() + "@")) {
// removeWarmUpProcess(key);
// }
// }
// }
public static void cancelWarmUps(Player player) {
Iterator<String> iter = playercommands.keySet().iterator();
while (iter.hasNext()) {
if (iter.next().startsWith(player.getName() + "@")) {
killTimer(player);
iter.remove();
}
}
}
public static void killTimer(Player player) {
for (String key : playercommands.keySet()) {
if (key.startsWith(player.getName() + "@")) {
playercommands.get(key).cancel();
}
}
}
public static boolean hasWarmUps(Player player) {
for (String key : playercommands.keySet()) {
if (key.startsWith(player.getName() + "@")) {
return true;
}
}
return false;
}
}

View File

@ -2,6 +2,7 @@ package cz.boosik.boosCooldown;
import java.util.Timer;
import java.util.TimerTask;
import org.bukkit.entity.Player;
public class boosWarmUpTimer extends TimerTask {

View File

@ -28,13 +28,6 @@
package org.mcstats;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.scheduler.BukkitTask;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
@ -48,6 +41,13 @@ import java.net.URLEncoder;
import java.util.UUID;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.scheduler.BukkitTask;
public class MetricsLite {
/**

View File

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