mirror of
https://github.com/LordBoos/boosCooldowns.git
synced 2024-11-22 18:45:15 +01:00
Improved configuration file structure and regex handling
This commit is contained in:
parent
888722c7e1
commit
21a45f8145
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -20,20 +20,20 @@ public class boosPlayerDeathListener implements Listener {
|
||||
&& player
|
||||
.hasPermission("booscooldowns.clear.cooldowns.death")) {
|
||||
if (boosConfigManager.getCleanCooldownsOnDeath()) {
|
||||
boosCoolDownManager.clearSomething("cooldown", player
|
||||
boosConfigManager.clearSomething("cooldown", player
|
||||
.getName().toLowerCase());
|
||||
}
|
||||
}
|
||||
if (player != null
|
||||
&& player.hasPermission("booscooldowns.clear.uses.death")) {
|
||||
if (boosConfigManager.getCleanUsesOnDeath()) {
|
||||
boosCoolDownManager.clearSomething("uses", player.getName()
|
||||
boosConfigManager.clearSomething("uses", player.getName()
|
||||
.toLowerCase());
|
||||
}
|
||||
}
|
||||
if (player != null) {
|
||||
if (boosConfigManager.getStartCooldownsOnDeath()) {
|
||||
boosCoolDownManager.startAllCooldowns(player);
|
||||
boosCoolDownManager.startAllCooldowns(player, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,15 +8,14 @@ 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 {
|
||||
private static boolean hasMoved(Player player) {
|
||||
String curworld = player.getWorld().getName();
|
||||
String cmdworld = boosCoolDownListener.playerworld.get(player);
|
||||
String cmdworld = boosWarmUpManager.playerworld.get(player);
|
||||
Location curloc = player.getLocation();
|
||||
Location cmdloc = boosCoolDownListener.playerloc.get(player);
|
||||
Location cmdloc = boosWarmUpManager.playerloc.get(player);
|
||||
if (!curworld.equals(cmdworld)) {
|
||||
return true;
|
||||
} else if (cmdloc.distanceSquared(curloc) > 2) {
|
||||
@ -41,7 +40,7 @@ public class boosPlayerMoveListener implements Listener {
|
||||
if (player != null
|
||||
&& !player.hasPermission("booscooldowns.nocancel.move")) {
|
||||
if (boosWarmUpManager.hasWarmUps(player) && hasMoved(player)) {
|
||||
boosCoolDownListener.clearLocWorld(player);
|
||||
boosWarmUpManager.clearLocWorld(player);
|
||||
boosChat.sendMessageToPlayer(player,
|
||||
boosConfigManager.getWarmUpCancelledByMoveMessage());
|
||||
boosWarmUpManager.cancelWarmUps(player);
|
||||
|
@ -8,6 +8,7 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -15,9 +16,63 @@ import org.bukkit.entity.Player;
|
||||
public class boosConfigManager {
|
||||
|
||||
private static YamlConfiguration conf;
|
||||
private static YamlConfiguration confusers;
|
||||
private static File confFile;
|
||||
private static File confusersFile;
|
||||
static List<String> players = new LinkedList<String>();
|
||||
|
||||
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);
|
||||
}
|
||||
saveConfusers();
|
||||
loadConfusers();
|
||||
}
|
||||
|
||||
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);
|
||||
saveConfusers();
|
||||
loadConfusers();
|
||||
}
|
||||
|
||||
static void clearSomething(String co, String player, String command) {
|
||||
int pre2 = command.toLowerCase().hashCode();
|
||||
confusers.set("users." + player.toLowerCase().hashCode() + "." + co
|
||||
+ "." + pre2, 0);
|
||||
saveConfusers();
|
||||
loadConfusers();
|
||||
}
|
||||
|
||||
public static String getAlias(String message) {
|
||||
return conf.getString("commands.aliases." + message);
|
||||
}
|
||||
@ -104,12 +159,13 @@ public class boosConfigManager {
|
||||
return conf.getBoolean("options.options.command_logging", false);
|
||||
}
|
||||
|
||||
public static YamlConfiguration getConfusers() {
|
||||
return confusers;
|
||||
}
|
||||
|
||||
static int getCoolDown(String pre, Player player) {
|
||||
int coolDown = 0;
|
||||
String group = getCoolGrp(player);
|
||||
pre = pre.toLowerCase();
|
||||
coolDown = conf.getInt("commands.cooldowns." + group + "." + pre,
|
||||
coolDown);
|
||||
coolDown = Integer.parseInt(getCommandValues(pre, player)[1]);
|
||||
return coolDown;
|
||||
}
|
||||
|
||||
@ -117,12 +173,6 @@ public class boosConfigManager {
|
||||
return conf.getBoolean("options.options.cooldowns_enabled", true);
|
||||
}
|
||||
|
||||
private static Set<String> getCooldownGroups() {
|
||||
Set<String> groups = conf.getConfigurationSection("commands.cooldowns")
|
||||
.getKeys(false);
|
||||
return groups;
|
||||
}
|
||||
|
||||
static String getCoolDownMessage() {
|
||||
return conf
|
||||
.getString(
|
||||
@ -131,20 +181,16 @@ public class boosConfigManager {
|
||||
}
|
||||
|
||||
public static Set<String> getCooldowns(Player player) {
|
||||
String cool = getCoolGrp(player);
|
||||
String cool = getCommandGroup(player);
|
||||
Set<String> cooldowns = conf.getConfigurationSection(
|
||||
"commands.cooldowns." + cool).getKeys(false);
|
||||
"commands.groups." + cool).getKeys(false);
|
||||
return cooldowns;
|
||||
}
|
||||
|
||||
private static String getCoolGrp(Player player) {
|
||||
String cool = "cooldown";
|
||||
for (String group : getCooldownGroups()) {
|
||||
if (player.hasPermission("booscooldowns." + group)) {
|
||||
cool = group;
|
||||
}
|
||||
}
|
||||
return cool;
|
||||
public static String getInsufficientFundsMessage() {
|
||||
return conf
|
||||
.getString("options.messages.insufficient_funds",
|
||||
"You have insufficient funds! &command& costs %s but you only have %s");
|
||||
}
|
||||
|
||||
public static String getInteractBlockedMessage() {
|
||||
@ -153,21 +199,9 @@ public class boosConfigManager {
|
||||
"&6You can't do this when command is warming-up!&f");
|
||||
}
|
||||
|
||||
public static String getLimGrp(Player player) {
|
||||
String lim = "limit";
|
||||
for (String group : getLimitGroups()) {
|
||||
if (player.hasPermission("booscooldowns." + group)) {
|
||||
lim = group;
|
||||
}
|
||||
}
|
||||
return lim;
|
||||
}
|
||||
|
||||
public static int getLimit(String pre, Player player) {
|
||||
int limit = -1;
|
||||
String group = getLimGrp(player);
|
||||
pre = pre.toLowerCase();
|
||||
limit = conf.getInt("commands.limits." + group + "." + pre, limit);
|
||||
limit = Integer.parseInt(getCommandValues(pre, player)[3]);
|
||||
return limit;
|
||||
}
|
||||
|
||||
@ -175,12 +209,6 @@ public class boosConfigManager {
|
||||
return conf.getBoolean("options.options.limits_enabled", true);
|
||||
}
|
||||
|
||||
private static Set<String> getLimitGroups() {
|
||||
Set<String> groups = conf.getConfigurationSection("commands.limits")
|
||||
.getKeys(false);
|
||||
return groups;
|
||||
}
|
||||
|
||||
public static String getLimitListMessage() {
|
||||
return conf
|
||||
.getString(
|
||||
@ -189,9 +217,9 @@ public class boosConfigManager {
|
||||
}
|
||||
|
||||
public static Set<String> getLimits(Player player) {
|
||||
String lim = getLimGrp(player);
|
||||
String lim = getCommandGroup(player);
|
||||
Set<String> limits = conf.getConfigurationSection(
|
||||
"commands.limits." + lim).getKeys(false);
|
||||
"commands.groups." + lim).getKeys(false);
|
||||
return limits;
|
||||
}
|
||||
|
||||
@ -223,19 +251,29 @@ public class boosConfigManager {
|
||||
"Price of &command& was %s and you now have %s");
|
||||
}
|
||||
|
||||
public static String getPotionEffect(String pre) {
|
||||
String effect = null;
|
||||
public static String getPotionEffect(String pre, Player player) {
|
||||
String effect = "";
|
||||
pre = pre.toLowerCase();
|
||||
effect = conf.getString("commands.warmupPotionEffects.effect." + pre,
|
||||
effect);
|
||||
String[] command = getCommandValues(pre, player);
|
||||
if (command.length > 4) {
|
||||
effect = getCommandValues(pre, player)[4];
|
||||
}
|
||||
return effect;
|
||||
}
|
||||
|
||||
public static int getPotionEffectStrength(String pre, Player player) {
|
||||
int effect = 0;
|
||||
pre = pre.toLowerCase();
|
||||
String[] command = getCommandValues(pre, player);
|
||||
if (command.length > 4) {
|
||||
effect = Integer.valueOf(getCommandValues(pre, player)[5]);
|
||||
}
|
||||
return effect;
|
||||
}
|
||||
|
||||
public static double getPrice(String pre, Player player) {
|
||||
double price = 0.0;
|
||||
String group = getPriceGrp(player);
|
||||
pre = pre.toLowerCase();
|
||||
price = conf.getDouble("commands.prices." + group + "." + pre, price);
|
||||
price = Double.parseDouble(getCommandValues(pre, player)[2]);
|
||||
return price;
|
||||
}
|
||||
|
||||
@ -243,29 +281,6 @@ public class boosConfigManager {
|
||||
return conf.getBoolean("options.options.prices_enabled", true);
|
||||
}
|
||||
|
||||
private static Set<String> getPriceGroups() {
|
||||
Set<String> groups = conf.getConfigurationSection("commands.prices")
|
||||
.getKeys(false);
|
||||
return groups;
|
||||
}
|
||||
|
||||
private static String getPriceGrp(Player player) {
|
||||
String price = "price";
|
||||
for (String group : getPriceGroups()) {
|
||||
if (player.hasPermission("booscooldowns." + group)) {
|
||||
price = group;
|
||||
}
|
||||
}
|
||||
return price;
|
||||
}
|
||||
|
||||
public static Set<String> getPrices(Player player) {
|
||||
String price = getPriceGrp(player);
|
||||
Set<String> prices = conf.getConfigurationSection(
|
||||
"commands.prices." + price).getKeys(false);
|
||||
return prices;
|
||||
}
|
||||
|
||||
public static int getSaveInterval() {
|
||||
return conf.getInt("options.options.save_interval_in_minutes", 15);
|
||||
}
|
||||
@ -291,21 +306,10 @@ public class boosConfigManager {
|
||||
return conf.getString("options.units.seconds", "seconds");
|
||||
}
|
||||
|
||||
public static String getWarmGrp(Player player) {
|
||||
String warm = "warmup";
|
||||
for (String group : getWarmupGroups()) {
|
||||
if (player.hasPermission("booscooldowns." + group)) {
|
||||
warm = group;
|
||||
}
|
||||
}
|
||||
return warm;
|
||||
}
|
||||
|
||||
public static int getWarmUp(String pre, Player player) {
|
||||
int warmUp = -1;
|
||||
String group = getWarmGrp(player);
|
||||
pre = pre.toLowerCase();
|
||||
warmUp = conf.getInt("commands.warmups." + group + "." + pre, warmUp);
|
||||
String[] values = getCommandValues(pre, player);
|
||||
warmUp = Integer.parseInt(values[0]);
|
||||
return warmUp;
|
||||
}
|
||||
|
||||
@ -328,25 +332,12 @@ public class boosConfigManager {
|
||||
return conf.getBoolean("options.options.warmups_enabled", true);
|
||||
}
|
||||
|
||||
public static Set<String> getWarmupGroups() {
|
||||
Set<String> groups = conf.getConfigurationSection("commands.warmups")
|
||||
.getKeys(false);
|
||||
return groups;
|
||||
}
|
||||
|
||||
static String getWarmUpMessage() {
|
||||
return conf
|
||||
.getString("options.messages.warming_up",
|
||||
"&6Wait&e &seconds& seconds&6 before command&e &command& &6has warmed up.&f");
|
||||
}
|
||||
|
||||
public static Set<String> getWarmups(Player player) {
|
||||
String warm = getWarmGrp(player);
|
||||
Set<String> warmups = conf.getConfigurationSection(
|
||||
"commands.warmups." + warm).getKeys(false);
|
||||
return warmups;
|
||||
}
|
||||
|
||||
static void load() {
|
||||
try {
|
||||
conf.load(confFile);
|
||||
@ -359,28 +350,37 @@ public class boosConfigManager {
|
||||
}
|
||||
}
|
||||
|
||||
static void loadConfusers() {
|
||||
try {
|
||||
confusers.load(confusersFile);
|
||||
} 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) {
|
||||
static void saveConfusers() {
|
||||
try {
|
||||
confFile.createNewFile();
|
||||
confusers.save(confusersFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
static void setAddToConfigFile(String coSetnout, String co, String 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);
|
||||
conf.set("commands.groups." + coSetnout + "." + co, hodnota);
|
||||
try {
|
||||
conf.save(confFile);
|
||||
} catch (IOException e) {
|
||||
@ -395,15 +395,7 @@ public class boosConfigManager {
|
||||
confFile = new File(boosCoolDown.getDataFolder(), "config.yml");
|
||||
if (confFile.exists()) {
|
||||
conf = new YamlConfiguration();
|
||||
try {
|
||||
conf.load(confFile);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
load();
|
||||
} else {
|
||||
this.confFile = new File(boosCoolDown.getDataFolder(), "config.yml");
|
||||
this.conf = new YamlConfiguration();
|
||||
@ -449,6 +441,9 @@ public class boosConfigManager {
|
||||
"&6Warm-Up process for&e &command& &6has already started.&f");
|
||||
conf.addDefault("options.messages.paid_error",
|
||||
"&6An error has occured:&e %s");
|
||||
conf.addDefault(
|
||||
"options.messages.insufficient_funds",
|
||||
"&6You have insufficient funds!&e &command& &6costs &e%s &6but you only have &e%s");
|
||||
conf.addDefault("options.messages.paid_for_command",
|
||||
"&6Price of&e &command& &6was&e %s &6and you now have&e %s");
|
||||
conf.addDefault("options.messages.limit_achieved",
|
||||
@ -475,29 +470,11 @@ public class boosConfigManager {
|
||||
}
|
||||
}
|
||||
try {
|
||||
conf.addDefault("commands.cooldowns.cooldown./command", 60);
|
||||
conf.addDefault("commands.cooldowns.cooldown./anotherCommand *", 30);
|
||||
conf.addDefault("commands.cooldowns.VIP./home", 40);
|
||||
conf.addDefault("commands.cooldowns.Premium./home", 90);
|
||||
conf.addDefault("commands.cooldowns.Donator./home", 99);
|
||||
conf.addDefault("commands.cooldowns.something./home", 542);
|
||||
conf.addDefault("commands.warmups.warmup.'*'", 1);
|
||||
conf.addDefault("commands.warmups.warmup./anotherCommand *", 0);
|
||||
conf.addDefault("commands.warmups.Donor./home", 40);
|
||||
conf.addDefault("commands.warmups.example./home", 90);
|
||||
conf.addDefault("commands.warmupPotionEffects.effect./home",
|
||||
"WEAKNESS@3");
|
||||
conf.addDefault(
|
||||
"commands.warmupPotionEffects.howto1",
|
||||
"#You can use CONFUSION, DAMAGE_RESISTANCE, FAST_DIGGING, FIRE_RESISTANCE, HARM, HEAL, HUNGER, INCREASE_DAMAGE, INVISIBILITY, JUMP, NIGHT_VISION, POISON, REGENERATION, SLOW, SLOW_DIGGING, SPEED, WATER_BREATHING, WEAKNESS, WITHER");
|
||||
conf.addDefault(
|
||||
"commands.warmupPotionEffects.howto2",
|
||||
"#After effect add @number, for example WEAKNESS@3 will apply weakness III to player for the duration of warmup.");
|
||||
conf.addDefault("commands.prices.price./command *", 10.0);
|
||||
conf.addDefault("commands.prices.price./anotherCommand", 20.0);
|
||||
conf.addDefault("commands.prices.yourGroup./home", 40.0);
|
||||
conf.addDefault("commands.limits.limit./command *", 0);
|
||||
conf.addDefault("commands.limits.limit2./lol", 100);
|
||||
conf.addDefault("commands.groups.default.*", "1,1,0.0,-1");
|
||||
conf.addDefault("commands.groups.default./anothercommand", "0,2,0.0,-1");
|
||||
conf.addDefault("commands.groups.default./yetanothercommand", "5,0,10.0,5,WEAKNESS,3");
|
||||
conf.addDefault("commands.groups.VIP./command *", "5,30,10.0,0");
|
||||
conf.addDefault("commands.groups.VIP./anothercommand", "2,10,5.0,20");
|
||||
conf.addDefault("commands.links.link./lol", "default");
|
||||
conf.addDefault("commands.links.link./example", "default");
|
||||
conf.addDefault("commands.links.link./command", "default");
|
||||
@ -517,5 +494,50 @@ public class boosConfigManager {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
confusersFile = new File(boosCoolDown.getDataFolder(), "users.yml");
|
||||
confusers = new YamlConfiguration();
|
||||
if (confusersFile.exists()) {
|
||||
loadConfusers();
|
||||
} else {
|
||||
try {
|
||||
confusersFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Set<String> getCommandGroups() {
|
||||
Set<String> groups = conf.getConfigurationSection("commands.groups")
|
||||
.getKeys(false);
|
||||
return groups;
|
||||
}
|
||||
|
||||
public static String getCommandGroup(Player player) {
|
||||
String cmdGroup = "default";
|
||||
for (String group : getCommandGroups()) {
|
||||
if (player.hasPermission("booscooldowns." + group)) {
|
||||
cmdGroup = group;
|
||||
}
|
||||
}
|
||||
return cmdGroup;
|
||||
}
|
||||
|
||||
public static Set<String> getCommands(Player player) {
|
||||
String group = getCommandGroup(player);
|
||||
Set<String> commands = conf.getConfigurationSection(
|
||||
"commands.groups." + group).getKeys(false);
|
||||
return commands;
|
||||
}
|
||||
|
||||
public static String[] getCommandValues(String regexCommand, Player player) {
|
||||
String[] values;
|
||||
String line = "";
|
||||
String group = getCommandGroup(player);
|
||||
line = conf.getString("commands.groups." + group + "." + regexCommand,
|
||||
line);
|
||||
boosCoolDown.log.info("LINE: " + line);
|
||||
values = line.split(",");
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ public class boosCoolDown extends JavaPlugin implements Runnable {
|
||||
public static PluginDescriptionFile pdfFile;
|
||||
private static Economy economy = null;
|
||||
private static boolean usingVault = false;
|
||||
|
||||
public static void commandLogger(String player, String command) {
|
||||
log.info("[" + "boosLogger" + "] " + player + " used command "
|
||||
+ command);
|
||||
@ -47,6 +48,18 @@ public class boosCoolDown extends JavaPlugin implements Runnable {
|
||||
return log;
|
||||
}
|
||||
|
||||
static boolean isPluginOnForPlayer(Player player) {
|
||||
boolean on;
|
||||
if (player.hasPermission("booscooldowns.exception")) {
|
||||
on = false;
|
||||
} else if (player.isOp()) {
|
||||
on = false;
|
||||
} else {
|
||||
on = true;
|
||||
}
|
||||
return on;
|
||||
}
|
||||
|
||||
public static boolean isUsingVault() {
|
||||
return usingVault;
|
||||
}
|
||||
@ -94,7 +107,7 @@ public class boosCoolDown extends JavaPlugin implements Runnable {
|
||||
&& args[0].equalsIgnoreCase("limits")) {
|
||||
try {
|
||||
Player send = (Player) sender;
|
||||
boosCoolDownManager.getLimits(send);
|
||||
boosConfigManager.getLimits(send);
|
||||
} catch (ClassCastException e) {
|
||||
log.warning("You cannot use this command from console!");
|
||||
}
|
||||
@ -106,7 +119,7 @@ public class boosCoolDown extends JavaPlugin implements Runnable {
|
||||
if (sender.hasPermission("booscooldowns.clearcooldowns")
|
||||
&& args[0].equalsIgnoreCase("clearcooldowns")) {
|
||||
String co = "cooldown";
|
||||
boosCoolDownManager.clearSomething(co, jmeno);
|
||||
boosConfigManager.clearSomething(co, jmeno);
|
||||
boosChat.sendMessageToCommandSender(sender,
|
||||
"&6[" + pdfFile.getName() + "]&e"
|
||||
+ " cooldowns of player " + jmeno
|
||||
@ -116,7 +129,7 @@ public class boosCoolDown extends JavaPlugin implements Runnable {
|
||||
&& command.equalsIgnoreCase("booscooldowns")
|
||||
&& args[0].equalsIgnoreCase("clearuses")) {
|
||||
String co = "uses";
|
||||
boosCoolDownManager.clearSomething(co, jmeno);
|
||||
boosConfigManager.clearSomething(co, jmeno);
|
||||
boosChat.sendMessageToCommandSender(sender,
|
||||
"&6[" + pdfFile.getName() + "]&e"
|
||||
+ " uses of player " + jmeno + " cleared");
|
||||
@ -125,7 +138,7 @@ public class boosCoolDown extends JavaPlugin implements Runnable {
|
||||
&& command.equalsIgnoreCase("booscooldowns")
|
||||
&& args[0].equalsIgnoreCase("clearwarmups")) {
|
||||
String co = "warmup";
|
||||
boosCoolDownManager.clearSomething(co, jmeno);
|
||||
boosConfigManager.clearSomething(co, jmeno);
|
||||
boosChat.sendMessageToCommandSender(sender,
|
||||
"&6[" + pdfFile.getName() + "]&e"
|
||||
+ " warmups of player " + jmeno
|
||||
@ -139,7 +152,7 @@ public class boosCoolDown extends JavaPlugin implements Runnable {
|
||||
if (sender.hasPermission("booscooldowns.clearcooldowns")
|
||||
&& args[0].equalsIgnoreCase("clearcooldowns")) {
|
||||
String co = "cooldown";
|
||||
boosCoolDownManager.clearSomething(co, jmeno, command2);
|
||||
boosConfigManager.clearSomething(co, jmeno, command2);
|
||||
boosChat.sendMessageToCommandSender(sender,
|
||||
"&6[" + pdfFile.getName() + "]&e"
|
||||
+ " cooldown for command " + command2
|
||||
@ -148,7 +161,7 @@ public class boosCoolDown extends JavaPlugin implements Runnable {
|
||||
} else if (sender.hasPermission("booscooldowns.clearuses")
|
||||
&& args[0].equalsIgnoreCase("clearuses")) {
|
||||
String co = "uses";
|
||||
boosCoolDownManager.clearSomething(co, jmeno, command2);
|
||||
boosConfigManager.clearSomething(co, jmeno, command2);
|
||||
boosChat.sendMessageToCommandSender(sender,
|
||||
"&6[" + pdfFile.getName() + "]&e"
|
||||
+ " uses for command " + command2
|
||||
@ -157,12 +170,13 @@ public class boosCoolDown extends JavaPlugin implements Runnable {
|
||||
} else if (sender.hasPermission("booscooldowns.clearwarmups")
|
||||
&& args[0].equalsIgnoreCase("clearwarmups")) {
|
||||
String co = "warmup";
|
||||
boosCoolDownManager.clearSomething(co, jmeno, command2);
|
||||
boosConfigManager.clearSomething(co, jmeno, command2);
|
||||
boosChat.sendMessageToCommandSender(sender,
|
||||
"&6[" + pdfFile.getName() + "]&e"
|
||||
+ " warmups for command " + command2
|
||||
+ " of player " + jmeno + " cleared");
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
if (args.length == 4) {
|
||||
@ -170,78 +184,53 @@ public class boosCoolDown extends JavaPlugin implements Runnable {
|
||||
&& args[0].equalsIgnoreCase("set")) {
|
||||
String coSetnout = args[1];
|
||||
String co = args[2];
|
||||
int hodnota = 0;
|
||||
try {
|
||||
hodnota = Integer.valueOf(args[3]);
|
||||
} catch (Exception e) {
|
||||
String hodnota = args[3];
|
||||
String regex1 = "(\\d+)(,)(\\d+)(,)(\\d+)(\\.)(\\d+)(,)(-?)(\\d+)(,)(CONFUSION|DAMAGE_RESISTANCE|FAST_DIGGING|FIRE_RESISTANCE|HARM|HEAL|HUNGER|INCREASE_DAMAGE|INVISIBILITY|JUMP|NIGHT_VISION|POISON|REGENERATION|SLOW|SLOW_DIGGING|SPEED|WATER_BREATHING|WEAKNESS|WITHER)(,)(\\d+)";
|
||||
String regex2 = "(\\d+)(,)(\\d+)(,)(\\d+)(\\.)(\\d+)(,)(-?)(\\d+)";
|
||||
if (!hodnota.matches(regex1) && !hodnota.matches(regex2)) {
|
||||
boosChat.sendMessageToCommandSender(sender,
|
||||
"Added value must be number!");
|
||||
"Invalid syntax!");
|
||||
return true;
|
||||
}
|
||||
if (co.startsWith("/")) {
|
||||
if (coSetnout.equals("cooldown")
|
||||
|| coSetnout.equals("cooldown2")
|
||||
|| coSetnout.equals("cooldown3")
|
||||
|| coSetnout.equals("cooldown4")
|
||||
|| coSetnout.equals("cooldown5")
|
||||
|| coSetnout.equals("warmup")
|
||||
|| coSetnout.equals("warmup2")
|
||||
|| coSetnout.equals("warmup3")
|
||||
|| coSetnout.equals("warmup4")
|
||||
|| coSetnout.equals("warmup5")
|
||||
|| coSetnout.equals("limit")
|
||||
|| coSetnout.equals("limit2")
|
||||
|| coSetnout.equals("limit3")
|
||||
|| coSetnout.equals("limit4")
|
||||
|| coSetnout.equals("limit5")
|
||||
|| coSetnout.equals("price")
|
||||
|| coSetnout.equals("price2")
|
||||
|| coSetnout.equals("price3")
|
||||
|| coSetnout.equals("price4")
|
||||
|| coSetnout.equals("price5")) {
|
||||
boosConfigManager.setAddToConfigFile(coSetnout, co,
|
||||
hodnota);
|
||||
boosChat.sendMessageToCommandSender(sender, "&6["
|
||||
+ pdfFile.getName() + "]&e" + " "
|
||||
+ coSetnout + " for command " + co
|
||||
+ " is now set to " + hodnota);
|
||||
return true;
|
||||
} else {
|
||||
boosChat.sendMessageToCommandSender(
|
||||
sender,
|
||||
"&6["
|
||||
+ pdfFile.getName()
|
||||
+ "]&e"
|
||||
+ " You can only set cooldown, cooldown2, cooldown3, cooldown4, cooldown5, warmup, warmup2, warmup3, warmup4, warmup5, limit, limit2, limit3, limit4, limit5, price, price2, price3, price4, price5.");
|
||||
return true;
|
||||
if (co.startsWith("/") || co.equals("*")) {
|
||||
if (co.contains("_")){
|
||||
co = co.replace("_", " ");
|
||||
}
|
||||
boosConfigManager.setAddToConfigFile(coSetnout, co,
|
||||
hodnota);
|
||||
boosChat.sendMessageToCommandSender(sender, "&6["
|
||||
+ pdfFile.getName() + "]&e" + " " + co
|
||||
+ " in group " + coSetnout + " is now set to "
|
||||
+ hodnota);
|
||||
return true;
|
||||
} else {
|
||||
boosChat.sendMessageToCommandSender(sender, "&6["
|
||||
+ pdfFile.getName() + "]&e"
|
||||
+ " Added command have to start with \"/\".");
|
||||
+ " Command has to start with \"/\".");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
boosChat.sendMessageToCommandSender(
|
||||
sender,
|
||||
"&6["
|
||||
+ pdfFile.getName()
|
||||
+ "]&e"
|
||||
+ " access denied, you lack required permission to do this!");
|
||||
} else {
|
||||
boosChat.sendMessageToCommandSender(
|
||||
sender,
|
||||
"&6["
|
||||
+ pdfFile.getName()
|
||||
+ "]&e"
|
||||
+ " access denied, you lack required permission to do this!");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (boosConfigManager.getClearOnRestart() == true) {
|
||||
boosCoolDownManager.clear();
|
||||
boosConfigManager.clear();
|
||||
log.info("[" + pdfFile.getName() + "]" + " cooldowns cleared!");
|
||||
} else {
|
||||
boosCoolDownManager.save();
|
||||
boosConfigManager.saveConfusers();
|
||||
log.info("[" + pdfFile.getName() + "]" + " cooldowns saved!");
|
||||
}
|
||||
log.info("[" + pdfFile.getName() + "]" + " version "
|
||||
@ -255,11 +244,9 @@ public class boosCoolDown extends JavaPlugin implements Runnable {
|
||||
log.info("[" + pdfFile.getName() + "]" + " version "
|
||||
+ pdfFile.getVersion() + " by " + pdfFile.getAuthors()
|
||||
+ " is enabled!");
|
||||
|
||||
new boosConfigManager(this);
|
||||
boosConfigManager.load();
|
||||
new boosCoolDownManager(this);
|
||||
boosCoolDownManager.load();
|
||||
boosConfigManager.loadConfusers();
|
||||
pm = getServer().getPluginManager();
|
||||
registerListeners();
|
||||
initializeVault();
|
||||
@ -268,7 +255,7 @@ public class boosCoolDown extends JavaPlugin implements Runnable {
|
||||
boosConfigManager.getSaveInterval() * 1200,
|
||||
boosConfigManager.getSaveInterval() * 1200);
|
||||
if (boosConfigManager.getClearOnRestart()) {
|
||||
boosCoolDownManager.clear();
|
||||
boosConfigManager.clear();
|
||||
}
|
||||
try {
|
||||
MetricsLite metrics = new MetricsLite(this);
|
||||
@ -281,7 +268,7 @@ public class boosCoolDown extends JavaPlugin implements Runnable {
|
||||
|
||||
private void registerListeners() {
|
||||
HandlerList.unregisterAll(this);
|
||||
pm.registerEvents(new boosCoolDownListener<Object>(this), this);
|
||||
pm.registerEvents(new boosCoolDownListener(this), this);
|
||||
if (boosConfigManager.getCancelWarmUpOnDamage()) {
|
||||
pm.registerEvents(new boosEntityDamageListener(), this);
|
||||
}
|
||||
@ -318,8 +305,8 @@ public class boosCoolDown extends JavaPlugin implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
boosCoolDownManager.save();
|
||||
boosCoolDownManager.load();
|
||||
boosConfigManager.saveConfusers();
|
||||
boosConfigManager.loadConfusers();
|
||||
log.info("[boosCooldowns] Config saved!");
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,6 @@
|
||||
package cz.boosik.boosCooldown;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -12,53 +9,35 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import util.boosChat;
|
||||
|
||||
public class boosCoolDownListener<a> implements Listener {
|
||||
private final boosCoolDown plugin;
|
||||
private boolean blocked = false;
|
||||
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 class boosCoolDownListener implements Listener {
|
||||
private static boosCoolDown plugin;
|
||||
|
||||
public boosCoolDownListener(boosCoolDown instance) {
|
||||
plugin = instance;
|
||||
}
|
||||
|
||||
private boolean blocked(Player player, String pre, int limit) {
|
||||
int uses = boosCoolDownManager.getUses(player, pre);
|
||||
if (player.hasPermission("booscooldowns.nolimit")
|
||||
|| player.hasPermission("booscooldowns.nolimit." + pre)) {
|
||||
} else {
|
||||
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 cooldownTime, double price) {
|
||||
private void checkRestrictions(PlayerCommandPreprocessEvent event,
|
||||
Player player, String regexCommad, String originalCommand,
|
||||
int warmupTime, int cooldownTime, double price, int limit) {
|
||||
boolean blocked = boosLimitManager.blocked(player, regexCommad,
|
||||
originalCommand, limit);
|
||||
if (!blocked) {
|
||||
if (warmUpSeconds > 0) {
|
||||
if (warmupTime > 0) {
|
||||
if (!player.hasPermission("booscooldowns.nowarmup")
|
||||
&& !player.hasPermission("booscooldowns.nowarmup."
|
||||
+ message)) {
|
||||
start(event, player, message, warmUpSeconds, cooldownTime);
|
||||
+ originalCommand)) {
|
||||
start(event, player, regexCommad, originalCommand,
|
||||
warmupTime, cooldownTime);
|
||||
}
|
||||
} else {
|
||||
if (boosCoolDownManager.coolDown(player, message, cooldownTime)) {
|
||||
if (boosCoolDownManager.coolDown(player, regexCommad,
|
||||
originalCommand, cooldownTime)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
if (!event.isCancelled()) {
|
||||
payForCommand(event, player, message, price);
|
||||
boosPriceManager.payForCommand(event, player, regexCommad,
|
||||
originalCommand, price);
|
||||
}
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
@ -67,52 +46,34 @@ public class boosCoolDownListener<a> implements Listener {
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
}
|
||||
if (!event.isCancelled()) {
|
||||
boosCoolDownManager.setUses(player, pre, message);
|
||||
boosLimitManager.setUses(player, regexCommad, originalCommand);
|
||||
if (boosConfigManager.getCommandLogging()) {
|
||||
boosCoolDown.commandLogger(player.getName(), message);
|
||||
boosCoolDown.commandLogger(player.getName(), originalCommand);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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.LOWEST)
|
||||
private void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
String message = event.getMessage().trim().replaceAll(" +", " ");
|
||||
String confCmd = "";
|
||||
String originalCommand = event.getMessage().trim()
|
||||
.replaceAll(" +", " ").toLowerCase();
|
||||
String regexCommad = "";
|
||||
Set<String> aliases = boosConfigManager.getAliases();
|
||||
Set<String> warmups = boosConfigManager.getWarmups(player);
|
||||
Set<String> cooldowns = boosConfigManager.getCooldowns(player);
|
||||
Set<String> limits = boosConfigManager.getLimits(player);
|
||||
Set<String> prices = boosConfigManager.getPrices(player);
|
||||
Set<String> commands = boosConfigManager.getCommands(player);
|
||||
boolean on = true;
|
||||
boolean used = false;
|
||||
int warmupTime = 0;
|
||||
double price = 0;
|
||||
int limit = -1;
|
||||
int cooldownTime = 0;
|
||||
on = isPluginOnForPlayer(player);
|
||||
on = boosCoolDown.isPluginOnForPlayer(player);
|
||||
try {
|
||||
if (aliases.contains(message)) {
|
||||
message = boosConfigManager.getAlias(message);
|
||||
event.setMessage(message);
|
||||
if (aliases.contains(originalCommand)) {
|
||||
originalCommand = boosConfigManager.getAlias(originalCommand);
|
||||
event.setMessage(originalCommand);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
boosCoolDown
|
||||
@ -121,68 +82,28 @@ public class boosCoolDownListener<a> implements Listener {
|
||||
"Aliases section in config.yml is missing! Please delete your config.yml, restart server and set it again!");
|
||||
}
|
||||
if (on) {
|
||||
if (boosConfigManager.getWarmupEnabled()) {
|
||||
for (String warmup : warmups) {
|
||||
String warmup2 = warmup.replace("*", ".+");
|
||||
if (message.matches(warmup2)) {
|
||||
warmupTime = boosConfigManager
|
||||
.getWarmUp(warmup, player);
|
||||
boosCoolDown.log.info("Regex: " + warmup + "Command: "
|
||||
+ message);
|
||||
if (warmupTime > 0) {
|
||||
confCmd = warmup;
|
||||
playerloc.put(player, player.getLocation());
|
||||
playerworld
|
||||
.put(player, player.getWorld().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (boosConfigManager.getCooldownEnabled()) {
|
||||
for (String cooldown : cooldowns) {
|
||||
String cooldown2 = cooldown.replace("*", ".+");
|
||||
if (message.matches(cooldown2)) {
|
||||
cooldownTime = boosConfigManager.getCoolDown(cooldown,
|
||||
for (String group : commands) {
|
||||
String group2 = group.replace("*", ".+");
|
||||
if (originalCommand.matches(group2)) {
|
||||
regexCommad = group;
|
||||
if (boosConfigManager.getWarmupEnabled()){
|
||||
warmupTime = boosConfigManager.getWarmUp(regexCommad,
|
||||
player);
|
||||
if (cooldownTime > 0 && confCmd.equals("")) {
|
||||
confCmd = cooldown;
|
||||
}
|
||||
}
|
||||
if (boosConfigManager.getCooldownEnabled()){
|
||||
cooldownTime = boosConfigManager.getCoolDown(regexCommad,
|
||||
player);
|
||||
}
|
||||
if (boosConfigManager.getPriceEnabled()){
|
||||
price = boosConfigManager.getPrice(regexCommad, player);
|
||||
}
|
||||
if (boosConfigManager.getLimitEnabled()){
|
||||
limit = boosConfigManager.getLimit(regexCommad, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (boosConfigManager.getPriceEnabled()) {
|
||||
for (String pric : prices) {
|
||||
String pric2 = pric.replace("*", ".+");
|
||||
if (message.matches(pric2)) {
|
||||
price = boosConfigManager.getPrice(pric, player);
|
||||
if (price > 0 && confCmd.equals("")) {
|
||||
confCmd = pric;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (boosConfigManager.getLimitEnabled()) {
|
||||
for (String lim : limits) {
|
||||
String lim2 = lim.replace("*", ".+");
|
||||
if (message.matches(lim2)) {
|
||||
limit = boosConfigManager.getLimit(lim, player);
|
||||
if (limit > -1 && confCmd.equals("")) {
|
||||
confCmd = lim;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
blocked = blocked(player, message, limit);
|
||||
this.checkCooldown(event, player, confCmd, message, warmupTime,
|
||||
cooldownTime, price);
|
||||
used = true;
|
||||
}
|
||||
|
||||
if (!used) {
|
||||
blocked = blocked(player, message, limit);
|
||||
this.checkCooldown(event, player, confCmd, message, warmupTime,
|
||||
cooldownTime, price);
|
||||
used = false;
|
||||
this.checkRestrictions(event, player, regexCommad, originalCommand,
|
||||
warmupTime, cooldownTime, price, limit);
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,61 +115,30 @@ public class boosCoolDownListener<a> implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
int cooldownTime = boosConfigManager.getCoolDown(temp, player);
|
||||
if (chatMessage.startsWith("!")) {
|
||||
if (!boosCoolDownManager
|
||||
.checkCoolDownOK(player, temp, cooldownTime)) {
|
||||
if (!boosCoolDownManager.checkCoolDownOK(player, temp, temp,
|
||||
cooldownTime)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else {
|
||||
if (boosCoolDownManager.coolDown(player, temp, cooldownTime)) {
|
||||
if (boosCoolDownManager.coolDown(player, temp, temp,
|
||||
cooldownTime)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
price = boosConfigManager.getPrice(temp, player);
|
||||
payForCommand2(event, player, temp, price);
|
||||
}
|
||||
}
|
||||
|
||||
private void payForCommand(PlayerCommandPreprocessEvent event,
|
||||
Player player, String pre, double price) {
|
||||
String name = player.getName();
|
||||
if (price > 0) {
|
||||
if (!player.hasPermission("booscooldowns.noprice")
|
||||
&& !player.hasPermission("booscooldowns.noprice." + pre)) {
|
||||
if (boosPriceManager.payForCommand(player, pre, price, name)) {
|
||||
return;
|
||||
} else {
|
||||
boosCoolDownManager.cancelCooldown(player, pre);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void payForCommand2(AsyncPlayerChatEvent event, Player player,
|
||||
String pre, double price) {
|
||||
String name = player.getName();
|
||||
if (price > 0) {
|
||||
if (!player.hasPermission("booscooldowns.noprice")
|
||||
&& !player.hasPermission("booscooldowns.noprice." + pre)) {
|
||||
if (boosPriceManager.payForCommand(player, pre, price, name)) {
|
||||
return;
|
||||
} else {
|
||||
boosCoolDownManager.cancelCooldown(player, pre);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
boosPriceManager.payForCommand2(event, player, temp, temp, price);
|
||||
}
|
||||
}
|
||||
|
||||
private void start(PlayerCommandPreprocessEvent event, Player player,
|
||||
String pre, int warmUpSeconds, int cooldownTime) {
|
||||
if (!boosCoolDownManager.checkWarmUpOK(player, pre)) {
|
||||
if (boosCoolDownManager.checkCoolDownOK(player, pre, cooldownTime)) {
|
||||
boosWarmUpManager.startWarmUp(this.plugin, player, pre,
|
||||
warmUpSeconds);
|
||||
String regexCommad, String originalCommand, int warmupTime,
|
||||
int cooldownTime) {
|
||||
if (!boosWarmUpManager.checkWarmUpOK(player, regexCommad)) {
|
||||
if (boosCoolDownManager.checkCoolDownOK(player, regexCommad,
|
||||
originalCommand, cooldownTime)) {
|
||||
boosWarmUpManager.startWarmUp(plugin, player, regexCommad,
|
||||
originalCommand, warmupTime);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else {
|
||||
@ -256,11 +146,12 @@ public class boosCoolDownListener<a> implements Listener {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (boosCoolDownManager.coolDown(player, pre, cooldownTime)) {
|
||||
if (boosCoolDownManager.coolDown(player, regexCommad,
|
||||
originalCommand, cooldownTime)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else {
|
||||
boosCoolDownManager.removeWarmUpOK(player, pre);
|
||||
boosWarmUpManager.removeWarmUpOK(player, regexCommad);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +1,28 @@
|
||||
package cz.boosik.boosCooldown;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import util.boosChat;
|
||||
|
||||
public class boosCoolDownManager {
|
||||
|
||||
private static YamlConfiguration confusers;
|
||||
private static File confFile;
|
||||
|
||||
static void cancelCooldown(Player player, String pre) {
|
||||
int pre2 = pre.toLowerCase().hashCode();
|
||||
confusers.set("users." + player.getName().toLowerCase().hashCode()
|
||||
+ ".cooldown." + pre2, null);
|
||||
static void cancelCooldown(Player player, String regexCommand) {
|
||||
int pre2 = regexCommand.toLowerCase().hashCode();
|
||||
boosConfigManager.getConfusers().set(
|
||||
"users." + player.getName().toLowerCase().hashCode()
|
||||
+ ".cooldown." + pre2, null);
|
||||
}
|
||||
|
||||
private static boolean cd(Player player, String pre, int coolDownSeconds) {
|
||||
Date lastTime = getTime(player, pre);
|
||||
String link = boosConfigManager.getLink(pre);
|
||||
private static boolean cd(Player player, String regexCommand,
|
||||
String originalCommand, int coolDownSeconds) {
|
||||
Date lastTime = getTime(player, regexCommand);
|
||||
String link = boosConfigManager.getLink(regexCommand);
|
||||
if (lastTime == null) {
|
||||
if (link == null) {
|
||||
setTime(player, pre);
|
||||
setTime(player, regexCommand);
|
||||
} else {
|
||||
List<String> linkGroup = boosConfigManager.getLinkList(link);
|
||||
for (String a : linkGroup) {
|
||||
@ -52,7 +41,7 @@ public class boosCoolDownManager {
|
||||
long waitHours = Math.round(waitMinutes / 60) + 1;
|
||||
if (secondsBetween > coolDownSeconds) {
|
||||
if (link == null) {
|
||||
setTime(player, pre);
|
||||
setTime(player, regexCommand);
|
||||
} else {
|
||||
List<String> linkGroup = boosConfigManager
|
||||
.getLinkList(link);
|
||||
@ -63,7 +52,7 @@ public class boosCoolDownManager {
|
||||
return false;
|
||||
} else {
|
||||
String msg = boosConfigManager.getCoolDownMessage();
|
||||
msg = msg.replaceAll("&command&", pre);
|
||||
msg = msg.replaceAll("&command&", originalCommand);
|
||||
if (waitSeconds >= 60 && 3600 >= waitSeconds) {
|
||||
msg = msg.replaceAll("&seconds&",
|
||||
Long.toString(waitMinutes));
|
||||
@ -88,63 +77,14 @@ public class boosCoolDownManager {
|
||||
}
|
||||
}
|
||||
|
||||
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, int time) {
|
||||
pre = pre.toLowerCase();
|
||||
if (time > 0 && !player.hasPermission("booscooldowns.nocooldown")
|
||||
&& !player.hasPermission("booscooldowns.nocooldown." + pre)) {
|
||||
return cd(player, pre, time);
|
||||
static boolean coolDown(Player player, String regexCommand,
|
||||
String originalCommand, int time) {
|
||||
regexCommand = regexCommand.toLowerCase();
|
||||
if (time > 0
|
||||
&& !player.hasPermission("booscooldowns.nocooldown")
|
||||
&& !player.hasPermission("booscooldowns.nocooldown."
|
||||
+ originalCommand)) {
|
||||
return cd(player, regexCommand, originalCommand, time);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -164,38 +104,12 @@ public class boosCoolDownManager {
|
||||
}
|
||||
}
|
||||
|
||||
static void getLimits(Player player) {
|
||||
int usesNum = 0;
|
||||
int limitNum = 0;
|
||||
int num;
|
||||
String message;
|
||||
Set<String> uses = boosConfigManager.getLimits(player);
|
||||
if (uses != null) {
|
||||
for (String key : uses) {
|
||||
usesNum = confusers.getInt("users."
|
||||
+ player.getName().toLowerCase().hashCode() + ".uses."
|
||||
+ key, usesNum);
|
||||
limitNum = boosConfigManager.getLimit(key, player);
|
||||
num = limitNum - usesNum;
|
||||
if (num < 0) {
|
||||
num = 0;
|
||||
}
|
||||
message = boosConfigManager.getLimitListMessage();
|
||||
message = message.replaceAll("&command&", key);
|
||||
message = message.replaceAll("&limit&",
|
||||
String.valueOf(limitNum));
|
||||
message = message.replaceAll("×&", String.valueOf(num));
|
||||
boosChat.sendMessageToPlayer(player, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Date getTime(Player player, String pre) {
|
||||
int pre2 = pre.toLowerCase().hashCode();
|
||||
static Date getTime(Player player, String regexCommand) {
|
||||
int pre2 = regexCommand.toLowerCase().hashCode();
|
||||
String confTime = "";
|
||||
confTime = confusers.getString("users."
|
||||
+ player.getName().toLowerCase().hashCode() + ".cooldown."
|
||||
+ pre2, null);
|
||||
confTime = boosConfigManager.getConfusers().getString(
|
||||
"users." + player.getName().toLowerCase().hashCode()
|
||||
+ ".cooldown." + pre2, null);
|
||||
|
||||
if (confTime != null && !confTime.equals("")) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
|
||||
@ -211,19 +125,11 @@ public class boosCoolDownManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
static int getUses(Player player, String message) {
|
||||
int message2 = message.toLowerCase().hashCode();
|
||||
int uses = 0;
|
||||
uses = confusers.getInt("users."
|
||||
+ player.getName().toLowerCase().hashCode() + ".uses."
|
||||
+ message2, uses);
|
||||
return uses;
|
||||
}
|
||||
|
||||
static boolean checkCoolDownOK(Player player, String pre, int time) {
|
||||
pre = pre.toLowerCase();
|
||||
static boolean checkCoolDownOK(Player player, String regexCommand,
|
||||
String originalCommand, int time) {
|
||||
regexCommand = regexCommand.toLowerCase();
|
||||
if (time > 0) {
|
||||
Date lastTime = getTime(player, pre);
|
||||
Date lastTime = getTime(player, regexCommand);
|
||||
if (lastTime == null) {
|
||||
return true;
|
||||
} else {
|
||||
@ -239,7 +145,7 @@ public class boosCoolDownManager {
|
||||
return true;
|
||||
} else {
|
||||
String msg = boosConfigManager.getCoolDownMessage();
|
||||
msg = msg.replaceAll("&command&", pre);
|
||||
msg = msg.replaceAll("&command&", originalCommand);
|
||||
if (waitSeconds >= 60 && 3600 >= waitSeconds) {
|
||||
msg = msg.replaceAll("&seconds&",
|
||||
Long.toString(waitMinutes));
|
||||
@ -264,51 +170,6 @@ public class boosCoolDownManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
static boolean checkWarmUpOK(Player player, String pre) {
|
||||
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 load() {
|
||||
try {
|
||||
confusers.load(confFile);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
static void removeWarmUp(Player player, String pre) {
|
||||
int pre2 = pre.toLowerCase().hashCode();
|
||||
confusers.set("users." + player.getName().toLowerCase().hashCode()
|
||||
+ ".warmup." + pre2, null);
|
||||
}
|
||||
|
||||
static void removeWarmUpOK(Player player, String pre) {
|
||||
int pre2 = pre.toLowerCase().hashCode();
|
||||
confusers.set("users." + player.getName().toLowerCase().hashCode()
|
||||
+ ".warmup." + pre2, null);
|
||||
}
|
||||
|
||||
static void save() {
|
||||
try {
|
||||
confFile.createNewFile();
|
||||
confusers.save(confFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static long secondsBetween(Calendar startDate, Calendar endDate) {
|
||||
long secondsBetween = 0;
|
||||
|
||||
@ -319,72 +180,23 @@ public class boosCoolDownManager {
|
||||
return secondsBetween;
|
||||
}
|
||||
|
||||
static void setTime(Player player, String pre) {
|
||||
int pre2 = pre.toLowerCase().hashCode();
|
||||
static void setTime(Player player, String regexCommand) {
|
||||
int pre2 = regexCommand.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);
|
||||
boosConfigManager.getConfusers().set(
|
||||
"users." + player.getName().toLowerCase().hashCode()
|
||||
+ ".cooldown." + pre2, currTime);
|
||||
}
|
||||
|
||||
static void setUses(Player player, String pre, String message) {
|
||||
if (boosConfigManager.getLimitsEnabled()) {
|
||||
if (boosConfigManager.getLimits(player).contains(pre)) {
|
||||
int message2 = message.toLowerCase().hashCode();
|
||||
int uses = getUses(player, message);
|
||||
uses = uses + 1;
|
||||
try {
|
||||
confusers.set("users."
|
||||
+ player.getName().toLowerCase().hashCode()
|
||||
+ ".uses." + message2, uses);
|
||||
} catch (IllegalArgumentException e) {
|
||||
boosCoolDown.log.warning("Player " + player.getName()
|
||||
+ " used empty command and caused this error!");
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void setWarmUpOK(Player player, String pre) {
|
||||
int pre2 = pre.toLowerCase().hashCode();
|
||||
confusers.set("users." + player.getName().toLowerCase().hashCode()
|
||||
+ ".warmup." + pre2, 1);
|
||||
}
|
||||
|
||||
public static void startAllCooldowns(Player player) {
|
||||
public static void startAllCooldowns(Player player, String message) {
|
||||
for (String a : boosConfigManager.getCooldowns(player)) {
|
||||
int cooldownTime = boosConfigManager.getCoolDown(a, player);
|
||||
coolDown(player, a, cooldownTime);
|
||||
coolDown(player, a, message, cooldownTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
86
src/cz/boosik/boosCooldown/boosLimitManager.java
Normal file
86
src/cz/boosik/boosCooldown/boosLimitManager.java
Normal file
@ -0,0 +1,86 @@
|
||||
package cz.boosik.boosCooldown;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import util.boosChat;
|
||||
|
||||
public class boosLimitManager {
|
||||
static boolean blocked(Player player, String regexCommand,
|
||||
String originalCommand, int limit) {
|
||||
int uses = getUses(player, regexCommand);
|
||||
if (player.hasPermission("booscooldowns.nolimit")
|
||||
|| player.hasPermission("booscooldowns.nolimit."
|
||||
+ originalCommand)) {
|
||||
} else {
|
||||
if (limit == -1) {
|
||||
return false;
|
||||
} else if (limit <= uses) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void getLimits(Player player) {
|
||||
int usesNum = 0;
|
||||
int limitNum = 0;
|
||||
int num;
|
||||
String message;
|
||||
Set<String> uses = boosConfigManager.getLimits(player);
|
||||
if (uses != null) {
|
||||
for (String key : uses) {
|
||||
usesNum = boosConfigManager.getConfusers().getInt(
|
||||
"users." + player.getName().toLowerCase().hashCode()
|
||||
+ ".uses." + key, usesNum);
|
||||
limitNum = boosConfigManager.getLimit(key, player);
|
||||
num = limitNum - usesNum;
|
||||
if (num < 0) {
|
||||
num = 0;
|
||||
}
|
||||
message = boosConfigManager.getLimitListMessage();
|
||||
message = message.replaceAll("&command&", key);
|
||||
message = message.replaceAll("&limit&",
|
||||
String.valueOf(limitNum));
|
||||
message = message.replaceAll("×&", String.valueOf(num));
|
||||
boosChat.sendMessageToPlayer(player, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int getUses(Player player, String regexCommand) {
|
||||
int regexCommand2 = regexCommand.toLowerCase().hashCode();
|
||||
int uses = 0;
|
||||
uses = boosConfigManager.getConfusers().getInt(
|
||||
"users." + player.getName().toLowerCase().hashCode() + ".uses."
|
||||
+ regexCommand2, uses);
|
||||
return uses;
|
||||
}
|
||||
|
||||
static void setUses(Player player, String regexCommand,
|
||||
String originalCommand) {
|
||||
if (boosConfigManager.getLimitsEnabled()) {
|
||||
if (boosConfigManager.getLimits(player).contains(regexCommand)) {
|
||||
boosCoolDown.log.info("regexCommand: " + regexCommand
|
||||
+ " originalCommand: " + originalCommand);
|
||||
int regexCommand2 = regexCommand.toLowerCase().hashCode();
|
||||
int uses = getUses(player, regexCommand);
|
||||
boosCoolDown.log.info("Uses: " + uses);
|
||||
uses = uses + 1;
|
||||
try {
|
||||
boosConfigManager.getConfusers().set(
|
||||
"users."
|
||||
+ player.getName().toLowerCase().hashCode()
|
||||
+ ".uses." + regexCommand2, uses);
|
||||
} catch (IllegalArgumentException e) {
|
||||
boosCoolDown.log.warning("Player " + player.getName()
|
||||
+ " used empty command and caused this error!");
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -4,30 +4,84 @@ import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.economy.EconomyResponse;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import util.boosChat;
|
||||
|
||||
public class boosPriceManager {
|
||||
private static Economy economy = boosCoolDown.getEconomy();
|
||||
static String msg = "";
|
||||
|
||||
public static boolean payForCommand(Player player, String pre,
|
||||
double price, String name) {
|
||||
public static boolean payForCommand(Player player, String regexCommand,
|
||||
String originalCommand, double price, String name) {
|
||||
if (economy == null) {
|
||||
return true;
|
||||
}
|
||||
EconomyResponse r = economy.withdrawPlayer(name, price);
|
||||
if (r.transactionSuccess()) {
|
||||
String msg = String.format(
|
||||
boosConfigManager.getPaidForCommandMessage(),
|
||||
msg = String.format(boosConfigManager.getPaidForCommandMessage(),
|
||||
economy.format(r.amount), economy.format(r.balance));
|
||||
msg = msg.replaceAll("&command&", pre);
|
||||
msg = msg.replaceAll("&command&", originalCommand);
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
return true;
|
||||
} else {
|
||||
String msg = String.format(boosConfigManager.getPaidErrorMessage(),
|
||||
r.errorMessage);
|
||||
if (r.errorMessage.equals("Insufficient funds")) {
|
||||
String unit;
|
||||
if (price == 1) {
|
||||
unit = economy.currencyNameSingular();
|
||||
} else {
|
||||
unit = economy.currencyNamePlural();
|
||||
}
|
||||
msg = String.format(
|
||||
boosConfigManager.getInsufficientFundsMessage(), (price
|
||||
+ " " + unit), economy.format(r.balance));
|
||||
msg = msg.replaceAll("&command&", originalCommand);
|
||||
} else {
|
||||
msg = String.format(boosConfigManager.getPaidErrorMessage(),
|
||||
r.errorMessage);
|
||||
}
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void payForCommand(PlayerCommandPreprocessEvent event,
|
||||
Player player, String regexCommand, String originalCommand,
|
||||
double price) {
|
||||
String name = player.getName();
|
||||
if (price > 0) {
|
||||
if (!player.hasPermission("booscooldowns.noprice")
|
||||
&& !player.hasPermission("booscooldowns.noprice."
|
||||
+ originalCommand)) {
|
||||
if (payForCommand(player, regexCommand, originalCommand, price,
|
||||
name)) {
|
||||
return;
|
||||
} else {
|
||||
boosCoolDownManager.cancelCooldown(player, regexCommand);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void payForCommand2(AsyncPlayerChatEvent event, Player player,
|
||||
String regexCommand, String originalCommand, double price) {
|
||||
String name = player.getName();
|
||||
if (price > 0) {
|
||||
if (!player.hasPermission("booscooldowns.noprice")
|
||||
&& !player.hasPermission("booscooldowns.noprice."
|
||||
+ originalCommand)) {
|
||||
if (boosPriceManager.payForCommand(player, regexCommand,
|
||||
originalCommand, price, name)) {
|
||||
return;
|
||||
} else {
|
||||
boosCoolDownManager.cancelCooldown(player, regexCommand);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.util.Iterator;
|
||||
import java.util.Timer;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
@ -12,19 +13,26 @@ import util.boosChat;
|
||||
public class boosWarmUpManager {
|
||||
|
||||
private static ConcurrentHashMap<String, boosWarmUpTimer> playercommands = new ConcurrentHashMap<String, boosWarmUpTimer>();
|
||||
public static ConcurrentHashMap<Player, Location> playerloc = new ConcurrentHashMap<Player, Location>();
|
||||
public static ConcurrentHashMap<Player, String> playerworld = new ConcurrentHashMap<Player, String>();
|
||||
|
||||
static Timer scheduler;
|
||||
|
||||
public static void applyPotionEffect(Player player, String pre,
|
||||
public static void applyPotionEffect(Player player, String regexCommand,
|
||||
int warmUpSeconds) {
|
||||
String potionTemp = boosConfigManager.getPotionEffect(pre);
|
||||
if (potionTemp == null)
|
||||
String potion = boosConfigManager.getPotionEffect(regexCommand, player);
|
||||
if (potion.equals("")) {
|
||||
return;
|
||||
String[] potion = potionTemp.split("@");
|
||||
PotionEffectType effect = PotionEffectType.getByName(potion[0]);
|
||||
}
|
||||
int potionStrength = boosConfigManager.getPotionEffectStrength(
|
||||
regexCommand, player);
|
||||
if (potionStrength == 0) {
|
||||
return;
|
||||
}
|
||||
PotionEffectType effect = PotionEffectType.getByName(potion);
|
||||
player.addPotionEffect(
|
||||
effect.createEffect(warmUpSeconds * 40,
|
||||
Integer.parseInt(potion[1]) - 1), true);
|
||||
effect.createEffect(warmUpSeconds * 40, potionStrength - 1),
|
||||
true);
|
||||
}
|
||||
|
||||
public static void cancelWarmUps(Player player) {
|
||||
@ -37,6 +45,11 @@ public class boosWarmUpManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearLocWorld(Player player) {
|
||||
boosWarmUpManager.playerloc.remove(player);
|
||||
boosWarmUpManager.playerworld.remove(player);
|
||||
}
|
||||
|
||||
public static boolean hasWarmUps(Player player) {
|
||||
for (String key : playercommands.keySet()) {
|
||||
if (key.startsWith(player.getName() + "@")) {
|
||||
@ -46,17 +59,21 @@ public class boosWarmUpManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
// public static void cancelWarmUps(Player player) {
|
||||
// for (String key : playercommands.keySet()) {
|
||||
// if (key.startsWith(player.getName() + "@")) {
|
||||
// removeWarmUpProcess(key);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
static boolean checkWarmUpOK(Player player, String regexCommand) {
|
||||
int pre2 = regexCommand.toLowerCase().hashCode();
|
||||
int ok = 0;
|
||||
ok = boosConfigManager.getConfusers().getInt(
|
||||
"users." + player.getName().toLowerCase().hashCode()
|
||||
+ ".warmup." + pre2, ok);
|
||||
if (ok == 1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isWarmUpProcess(Player player, String pre) {
|
||||
pre = pre.toLowerCase();
|
||||
if (playercommands.containsKey(player.getName() + "@" + pre)) {
|
||||
public static boolean isWarmUpProcess(Player player, String regexCommand) {
|
||||
regexCommand = regexCommand.toLowerCase();
|
||||
if (playercommands.containsKey(player.getName() + "@" + regexCommand)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -70,19 +87,40 @@ public class boosWarmUpManager {
|
||||
}
|
||||
}
|
||||
|
||||
static void removeWarmUp(Player player, String regexCommand) {
|
||||
int pre2 = regexCommand.toLowerCase().hashCode();
|
||||
boosConfigManager.getConfusers().set(
|
||||
"users." + player.getName().toLowerCase().hashCode()
|
||||
+ ".warmup." + pre2, null);
|
||||
}
|
||||
|
||||
static void removeWarmUpOK(Player player, String regexCommand) {
|
||||
int pre2 = regexCommand.toLowerCase().hashCode();
|
||||
boosConfigManager.getConfusers().set(
|
||||
"users." + player.getName().toLowerCase().hashCode()
|
||||
+ ".warmup." + pre2, null);
|
||||
}
|
||||
|
||||
public static void removeWarmUpProcess(String tag) {
|
||||
boosWarmUpManager.playercommands.remove(tag);
|
||||
}
|
||||
|
||||
static void setWarmUpOK(Player player, String regexCommand) {
|
||||
int pre2 = regexCommand.toLowerCase().hashCode();
|
||||
boosConfigManager.getConfusers().set(
|
||||
"users." + player.getName().toLowerCase().hashCode()
|
||||
+ ".warmup." + pre2, 1);
|
||||
}
|
||||
|
||||
public static void startWarmUp(boosCoolDown bCoolDown, Player player,
|
||||
String pre, int warmUpSeconds) {
|
||||
pre = pre.toLowerCase();
|
||||
String regexCommand, String originalCommand, int warmUpSeconds) {
|
||||
regexCommand = regexCommand.toLowerCase();
|
||||
long warmUpMinutes = Math.round(warmUpSeconds / 60);
|
||||
long warmUpHours = Math.round(warmUpMinutes / 60);
|
||||
if (!isWarmUpProcess(player, pre)) {
|
||||
boosCoolDownManager.removeWarmUpOK(player, pre);
|
||||
if (!isWarmUpProcess(player, regexCommand)) {
|
||||
boosWarmUpManager.removeWarmUpOK(player, regexCommand);
|
||||
String msg = boosConfigManager.getWarmUpMessage();
|
||||
msg = msg.replaceAll("&command&", pre);
|
||||
msg = msg.replaceAll("&command&", originalCommand);
|
||||
if (warmUpSeconds >= 60 && 3600 >= warmUpSeconds) {
|
||||
msg = msg.replaceAll("&seconds&", Long.toString(warmUpMinutes));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
@ -100,13 +138,14 @@ public class boosWarmUpManager {
|
||||
|
||||
scheduler = new Timer();
|
||||
boosWarmUpTimer scheduleMe = new boosWarmUpTimer(bCoolDown,
|
||||
scheduler, player, pre);
|
||||
playercommands.put(player.getName() + "@" + pre, scheduleMe);
|
||||
scheduler, player, regexCommand, originalCommand);
|
||||
playercommands.put(player.getName() + "@" + regexCommand,
|
||||
scheduleMe);
|
||||
scheduler.schedule(scheduleMe, warmUpSeconds * 1000);
|
||||
applyPotionEffect(player, pre, warmUpSeconds);
|
||||
applyPotionEffect(player, regexCommand, warmUpSeconds);
|
||||
} else {
|
||||
String msg = boosConfigManager.getWarmUpAlreadyStartedMessage();
|
||||
msg = msg.replaceAll("&command&", pre);
|
||||
msg = msg.replaceAll("&command&", originalCommand);
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
}
|
||||
}
|
||||
|
@ -12,39 +12,41 @@ public class boosWarmUpTimer extends TimerTask {
|
||||
public void run() {
|
||||
if (player.isOnline() && !player.isDead()
|
||||
&& boosWarmUpManager.hasWarmUps(player)) {
|
||||
boosCoolDownManager.setWarmUpOK(player, pre);
|
||||
boosWarmUpManager.setWarmUpOK(player, regexCommand);
|
||||
boosWarmUpManager.removeWarmUpProcess(player.getName() + "@"
|
||||
+ pre);
|
||||
boosCoolDownListener.clearLocWorld(player);
|
||||
player.chat(pre);
|
||||
+ regexCommand);
|
||||
boosWarmUpManager.clearLocWorld(player);
|
||||
player.chat(originalCommand);
|
||||
} else if (player.isOnline() && player.isDead()
|
||||
&& boosWarmUpManager.hasWarmUps(player)) {
|
||||
boosCoolDownManager.removeWarmUp(player, pre);
|
||||
boosWarmUpManager.removeWarmUp(player, regexCommand);
|
||||
boosWarmUpManager.removeWarmUpProcess(player.getName() + "@"
|
||||
+ pre);
|
||||
boosCoolDownListener.clearLocWorld(player);
|
||||
+ regexCommand);
|
||||
boosWarmUpManager.clearLocWorld(player);
|
||||
} else if (!player.isOnline()
|
||||
&& boosWarmUpManager.hasWarmUps(player)) {
|
||||
boosCoolDownManager.removeWarmUp(player, pre);
|
||||
boosWarmUpManager.removeWarmUp(player, regexCommand);
|
||||
boosWarmUpManager.removeWarmUpProcess(player.getName() + "@"
|
||||
+ pre);
|
||||
boosCoolDownListener.clearLocWorld(player);
|
||||
+ regexCommand);
|
||||
boosWarmUpManager.clearLocWorld(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boosCoolDown bCoolDown;
|
||||
private Player player;
|
||||
|
||||
private String pre;
|
||||
private String originalCommand;
|
||||
private String regexCommand;
|
||||
|
||||
public boosWarmUpTimer() {
|
||||
}
|
||||
|
||||
public boosWarmUpTimer(boosCoolDown bCoolDown, Timer timer, Player player,
|
||||
String pre) {
|
||||
String regexCommand, String originalCommand) {
|
||||
this.bCoolDown = bCoolDown;
|
||||
this.player = player;
|
||||
this.pre = pre;
|
||||
this.regexCommand = regexCommand;
|
||||
this.originalCommand = originalCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user