mirror of
https://github.com/LordBoos/boosCooldowns.git
synced 2024-11-29 22:24:04 +01:00
Formating
This commit is contained in:
parent
08b646da0b
commit
0af02c541e
98
build.xml
98
build.xml
@ -6,69 +6,39 @@
|
||||
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||
<!-- the Compile on Save feature is turned off for the project. -->
|
||||
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||
<!-- in the project's Project Properties dialog box.-->
|
||||
<!-- in the project's Project Properties dialog box. -->
|
||||
<project name="boosCooldown" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project boosCooldown.</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
-pre-init: called before initialization of project properties
|
||||
-post-init: called after initialization of project properties
|
||||
-pre-compile: called before javac compilation
|
||||
-post-compile: called after javac compilation
|
||||
-pre-compile-single: called before javac compilation of single file
|
||||
-post-compile-single: called after javac compilation of single file
|
||||
-pre-compile-test: called before javac compilation of JUnit tests
|
||||
-post-compile-test: called after javac compilation of JUnit tests
|
||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||
-pre-jar: called before JAR building
|
||||
-post-jar: called after JAR building
|
||||
-post-clean: called after cleaning build products
|
||||
|
||||
(Targets beginning with '-' are not intended to be called on their own.)
|
||||
|
||||
Example of inserting an obfuscator after compilation could look like this:
|
||||
|
||||
<target name="-post-compile">
|
||||
<obfuscate>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</obfuscate>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
|
||||
Another way to customize the build is by overriding existing main targets.
|
||||
The targets of interest are:
|
||||
|
||||
-init-macrodef-javac: defines macro for javac compilation
|
||||
-init-macrodef-junit: defines macro for junit execution
|
||||
-init-macrodef-debug: defines macro for class debugging
|
||||
-init-macrodef-java: defines macro for class execution
|
||||
-do-jar-with-manifest: JAR building (if you are using a manifest)
|
||||
-do-jar-without-manifest: JAR building (if you are not using a manifest)
|
||||
run: execution of project
|
||||
-javadoc-build: Javadoc generation
|
||||
test-report: JUnit report generation
|
||||
|
||||
An example of overriding the target for project execution could look like this:
|
||||
|
||||
<target name="run" depends="boosCooldown-impl.jar">
|
||||
<exec dir="bin" executable="launcher.exe">
|
||||
<arg file="${dist.jar}"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
Notice that the overridden target depends on the jar target and not only on
|
||||
the compile target as the regular run target does. Again, for a list of available
|
||||
properties which you can use, check the target you are overriding in the
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
-->
|
||||
<description>Builds, tests, and runs the project boosCooldown.</description>
|
||||
<import file="nbproject/build-impl.xml" />
|
||||
<!-- There exist several targets which are by default empty and which can
|
||||
be used for execution of your tasks. These targets are usually executed before
|
||||
and after some main targets. They are: -pre-init: called before initialization
|
||||
of project properties -post-init: called after initialization of project
|
||||
properties -pre-compile: called before javac compilation -post-compile: called
|
||||
after javac compilation -pre-compile-single: called before javac compilation
|
||||
of single file -post-compile-single: called after javac compilation of single
|
||||
file -pre-compile-test: called before javac compilation of JUnit tests -post-compile-test:
|
||||
called after javac compilation of JUnit tests -pre-compile-test-single: called
|
||||
before javac compilation of single JUnit test -post-compile-test-single:
|
||||
called after javac compilation of single JUunit test -pre-jar: called before
|
||||
JAR building -post-jar: called after JAR building -post-clean: called after
|
||||
cleaning build products (Targets beginning with '-' are not intended to be
|
||||
called on their own.) Example of inserting an obfuscator after compilation
|
||||
could look like this: <target name="-post-compile"> <obfuscate> <fileset
|
||||
dir="${build.classes.dir}"/> </obfuscate> </target> For list of available
|
||||
properties check the imported nbproject/build-impl.xml file. Another way
|
||||
to customize the build is by overriding existing main targets. The targets
|
||||
of interest are: -init-macrodef-javac: defines macro for javac compilation
|
||||
-init-macrodef-junit: defines macro for junit execution -init-macrodef-debug:
|
||||
defines macro for class debugging -init-macrodef-java: defines macro for
|
||||
class execution -do-jar-with-manifest: JAR building (if you are using a manifest)
|
||||
-do-jar-without-manifest: JAR building (if you are not using a manifest)
|
||||
run: execution of project -javadoc-build: Javadoc generation test-report:
|
||||
JUnit report generation An example of overriding the target for project execution
|
||||
could look like this: <target name="run" depends="boosCooldown-impl.jar">
|
||||
<exec dir="bin" executable="launcher.exe"> <arg file="${dist.jar}"/> </exec>
|
||||
</target> Notice that the overridden target depends on the jar target and
|
||||
not only on the compile target as the regular run target does. Again, for
|
||||
a list of available properties which you can use, check the target you are
|
||||
overriding in the nbproject/build-impl.xml file. -->
|
||||
</project>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,15 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>boosCooldown</name>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
</configuration>
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>boosCooldown</name>
|
||||
<source-roots>
|
||||
<root id="src.dir" />
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir" />
|
||||
</test-roots>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
||||
|
@ -8,93 +8,111 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
public class boosConfigManager {
|
||||
|
||||
|
||||
protected static boosCoolDown bCoolDown;
|
||||
protected static Configuration conf;
|
||||
protected File confFile;
|
||||
static List<String> players = new LinkedList<String>();
|
||||
|
||||
protected static Configuration conf;
|
||||
protected File confFile;
|
||||
static List<String> players = new LinkedList<String>();
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
public boosConfigManager(boosCoolDown boosCoolDown) {
|
||||
this.bCoolDown = boosCoolDown;
|
||||
this.bCoolDown = boosCoolDown;
|
||||
|
||||
File f = new File(boosCoolDown.getDataFolder(), "config.yml");
|
||||
conf = null;
|
||||
File f = new File(boosCoolDown.getDataFolder(), "config.yml");
|
||||
conf = null;
|
||||
|
||||
if (f.exists()) {
|
||||
conf = new Configuration(f);
|
||||
conf.load();
|
||||
|
||||
} else {
|
||||
this.confFile = new File(boosCoolDown.getDataFolder(), "config.yml");
|
||||
this.conf = new Configuration(confFile);
|
||||
conf.setProperty("commands.cooldown./spawn", 60);
|
||||
conf.setProperty("commands.cooldown./home", 30);
|
||||
conf.setProperty("commands.warmup./give", 60);
|
||||
conf.setProperty("commands.warmup./home", 20);
|
||||
conf.setProperty("commands.options.cancel_warmup_on_damage", false);
|
||||
conf.setProperty("commands.options.clear_on_restart", false);
|
||||
conf.setProperty("commands.options.unit_seconds", "seconds");
|
||||
conf.setProperty("commands.options.unit_minutes", "minutes");
|
||||
conf.setProperty("commands.options.unit_hours", "hours");
|
||||
conf.setProperty("commands.options.message_warmup_cancelled",
|
||||
"&6Warm-ups have been cancelled due to receiving damage.&f");
|
||||
conf.setProperty("commands.options.message_cooldown",
|
||||
"&6Wait&e &seconds& &unit&&6 before you can use command&e &command& &6again.&f");
|
||||
conf.setProperty("commands.options.message_warmup",
|
||||
"&6Wait&e &seconds& &unit&&6 before command&e &command& &6has warmed up.&f");
|
||||
conf.setProperty("commands.options.message_warmup_alreadystarted",
|
||||
"&6Warm-Up process for&e &command& &6has already started.&f");
|
||||
conf.save();
|
||||
}
|
||||
}
|
||||
|
||||
if (f.exists())
|
||||
{
|
||||
conf = new Configuration(f);
|
||||
conf.load();
|
||||
|
||||
}
|
||||
else {
|
||||
this.confFile = new File(boosCoolDown.getDataFolder(), "config.yml");
|
||||
this.conf = new Configuration(confFile);
|
||||
conf.setProperty("commands.cooldown./spawn", 60);
|
||||
conf.setProperty("commands.cooldown./home", 30);
|
||||
conf.setProperty("commands.warmup./give", 60);
|
||||
conf.setProperty("commands.warmup./home", 20);
|
||||
conf.setProperty("commands.options.cancel_warmup_on_damage", false);
|
||||
conf.setProperty("commands.options.clear_on_restart", false);
|
||||
conf.setProperty("commands.options.unit_seconds", "seconds");
|
||||
conf.setProperty("commands.options.unit_minutes", "minutes");
|
||||
conf.setProperty("commands.options.unit_hours", "hours");
|
||||
conf.setProperty("commands.options.message_warmup_cancelled", "&6Warm-ups have been cancelled due to receiving damage.&f");
|
||||
conf.setProperty("commands.options.message_cooldown", "&6Wait&e &seconds& &unit&&6 before you can use command&e &command& &6again.&f");
|
||||
conf.setProperty("commands.options.message_warmup", "&6Wait&e &seconds& &unit&&6 before command&e &command& &6has warmed up.&f");
|
||||
conf.setProperty("commands.options.message_warmup_alreadystarted", "&6Warm-Up process for&e &command& &6has already started.&f");
|
||||
conf.save();
|
||||
}
|
||||
}
|
||||
|
||||
static void load() {
|
||||
conf.load();
|
||||
}
|
||||
|
||||
conf.load();
|
||||
}
|
||||
|
||||
static void reload() {
|
||||
load();
|
||||
}
|
||||
|
||||
|
||||
static int getCoolDown(Player player, String pre) {
|
||||
int coolDown = 0;
|
||||
pre = pre.toLowerCase();
|
||||
coolDown = conf.getInt("commands.cooldown." + pre, coolDown);
|
||||
return coolDown;
|
||||
int coolDown = 0;
|
||||
pre = pre.toLowerCase();
|
||||
coolDown = conf.getInt("commands.cooldown." + pre, coolDown);
|
||||
return coolDown;
|
||||
}
|
||||
|
||||
|
||||
static int getWarmUp(Player player, String pre) {
|
||||
int warmUp = 0;
|
||||
pre = pre.toLowerCase();
|
||||
warmUp = conf.getInt("commands.warmup." + pre, warmUp);
|
||||
return warmUp;
|
||||
int warmUp = 0;
|
||||
pre = pre.toLowerCase();
|
||||
warmUp = conf.getInt("commands.warmup." + pre, warmUp);
|
||||
return warmUp;
|
||||
}
|
||||
|
||||
|
||||
static String getCoolDownMessage() {
|
||||
return conf.getString("commands.options.message_cooldown", "&6Wait&e &seconds& seconds&6 before you can use command&e &command& &6again.&f");
|
||||
return conf
|
||||
.getString(
|
||||
"commands.options.message_cooldown",
|
||||
"&6Wait&e &seconds& seconds&6 before you can use command&e &command& &6again.&f");
|
||||
}
|
||||
|
||||
static String getWarmUpCancelledMessage() {
|
||||
return conf.getString("commands.options.message_warmup_cancelled", "&6Warm-ups have been cancelled due to receiving damage.&f");
|
||||
return conf.getString("commands.options.message_warmup_cancelled",
|
||||
"&6Warm-ups have been cancelled due to receiving damage.&f");
|
||||
}
|
||||
|
||||
static String getWarmUpMessage() {
|
||||
return conf.getString("commands.options.message_warmup", "&6Wait&e &seconds& seconds&6 before command&e &command& &6has warmed up.&f");
|
||||
}
|
||||
return conf
|
||||
.getString("commands.options.message_warmup",
|
||||
"&6Wait&e &seconds& seconds&6 before command&e &command& &6has warmed up.&f");
|
||||
}
|
||||
|
||||
static String getWarmUpAlreadyStartedMessage() {
|
||||
return conf.getString("commands.options.message_warmup_alreadystarted", "&6Warm-Up process for&e &command& &6has already started.&f");
|
||||
}
|
||||
static String getUnitSecondsMessage() {
|
||||
return conf.getString("commands.options.unit_seconds", "seconds");
|
||||
}
|
||||
static String getUnitMinutesMessage() {
|
||||
return conf.getString("commands.options.unit_minutes", "minutes");
|
||||
}
|
||||
static String getUnitHoursMessage() {
|
||||
return conf.getString("commands.options.unit_hours", "hours");
|
||||
}
|
||||
static boolean getClearOnRestart() {
|
||||
return conf.getBoolean("commands.options.clear_on_restart", false);
|
||||
}
|
||||
static boolean getCancelWarmUpOnDamage() {
|
||||
return conf.getBoolean("commands.options.cancel_warmup_on_damage", false);
|
||||
}
|
||||
|
||||
return conf.getString("commands.options.message_warmup_alreadystarted",
|
||||
"&6Warm-Up process for&e &command& &6has already started.&f");
|
||||
}
|
||||
|
||||
static String getUnitSecondsMessage() {
|
||||
return conf.getString("commands.options.unit_seconds", "seconds");
|
||||
}
|
||||
|
||||
static String getUnitMinutesMessage() {
|
||||
return conf.getString("commands.options.unit_minutes", "minutes");
|
||||
}
|
||||
|
||||
static String getUnitHoursMessage() {
|
||||
return conf.getString("commands.options.unit_hours", "hours");
|
||||
}
|
||||
|
||||
static boolean getClearOnRestart() {
|
||||
return conf.getBoolean("commands.options.clear_on_restart", false);
|
||||
}
|
||||
|
||||
static boolean getCancelWarmUpOnDamage() {
|
||||
return conf.getBoolean("commands.options.cancel_warmup_on_damage",
|
||||
false);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,58 +15,66 @@ import java.util.logging.Logger;
|
||||
|
||||
public class boosCoolDown extends JavaPlugin {
|
||||
|
||||
private final boosCoolDownPlayerListener playerListener = new boosCoolDownPlayerListener(this);
|
||||
private final boosCoolDownEntityListener entityListener = new boosCoolDownEntityListener(this);
|
||||
public static final Logger log = Logger.getLogger("Minecraft");
|
||||
public static PluginDescriptionFile pdfFile;
|
||||
public static Configuration conf;
|
||||
public static Configuration confusers;
|
||||
public static boolean permissions = false;
|
||||
private final boosCoolDownPlayerListener playerListener = new boosCoolDownPlayerListener(
|
||||
this);
|
||||
private final boosCoolDownEntityListener entityListener = new boosCoolDownEntityListener(
|
||||
this);
|
||||
public static final Logger log = Logger.getLogger("Minecraft");
|
||||
public static PluginDescriptionFile pdfFile;
|
||||
public static Configuration conf;
|
||||
public static Configuration confusers;
|
||||
public static boolean permissions = false;
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
public void onEnable() {
|
||||
@SuppressWarnings("static-access")
|
||||
public void onEnable() {
|
||||
|
||||
pdfFile = this.getDescription();
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Event.Priority.Lowest, this);
|
||||
pdfFile = this.getDescription();
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener,
|
||||
Event.Priority.Lowest, this);
|
||||
|
||||
PluginDescriptionFile pdfFile = this.getDescription();
|
||||
log.info("[" + pdfFile.getName() + "]" + " version " + pdfFile.getVersion() + " by " + pdfFile.getAuthors() + " is enabled!");
|
||||
PluginDescriptionFile pdfFile = this.getDescription();
|
||||
log.info("[" + pdfFile.getName() + "]" + " version "
|
||||
+ pdfFile.getVersion() + " by " + pdfFile.getAuthors()
|
||||
+ " is enabled!");
|
||||
|
||||
boosConfigManager boosConfigManager = new boosConfigManager(this);
|
||||
boosConfigManager.load();
|
||||
conf = boosConfigManager.conf;
|
||||
boosCoolDownManager boosCoolDownManager = new boosCoolDownManager(this);
|
||||
boosCoolDownManager.load();
|
||||
if(boosConfigManager.getCancelWarmUpOnDamage()) {
|
||||
pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Event.Priority.Normal, this);
|
||||
}
|
||||
if (boosConfigManager.getClearOnRestart() == true) {
|
||||
boosCoolDownManager.clear();
|
||||
} else {
|
||||
}
|
||||
confusers = boosCoolDownManager.confusers;
|
||||
boosConfigManager boosConfigManager = new boosConfigManager(this);
|
||||
boosConfigManager.load();
|
||||
conf = boosConfigManager.conf;
|
||||
boosCoolDownManager boosCoolDownManager = new boosCoolDownManager(this);
|
||||
boosCoolDownManager.load();
|
||||
if (boosConfigManager.getCancelWarmUpOnDamage()) {
|
||||
pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener,
|
||||
Event.Priority.Normal, this);
|
||||
}
|
||||
if (boosConfigManager.getClearOnRestart() == true) {
|
||||
boosCoolDownManager.clear();
|
||||
} else {
|
||||
}
|
||||
confusers = boosCoolDownManager.confusers;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
if (boosConfigManager.getClearOnRestart() == true) {
|
||||
boosCoolDownManager.clear();
|
||||
} else {
|
||||
}
|
||||
log.info("[" + pdfFile.getName() + "]" + " version " + pdfFile.getVersion() + " disabled!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command c, String commandLabel, String[] args) {
|
||||
String command = c.getName().toLowerCase();
|
||||
if (command.equalsIgnoreCase("boosCoolDown")) {
|
||||
boosConfigManager.reload();
|
||||
boosChat.sendMessageToCommandSender(sender, "&6[" + pdfFile.getName() + "]" + " config reloaded");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void onDisable() {
|
||||
if (boosConfigManager.getClearOnRestart() == true) {
|
||||
boosCoolDownManager.clear();
|
||||
} else {
|
||||
}
|
||||
log.info("[" + pdfFile.getName() + "]" + " version "
|
||||
+ pdfFile.getVersion() + " disabled!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command c,
|
||||
String commandLabel, String[] args) {
|
||||
String command = c.getName().toLowerCase();
|
||||
if (command.equalsIgnoreCase("boosCoolDown")) {
|
||||
boosConfigManager.reload();
|
||||
boosChat.sendMessageToCommandSender(sender,
|
||||
"&6[" + pdfFile.getName() + "]" + " config reloaded");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,27 +8,28 @@ import org.bukkit.event.entity.EntityListener;
|
||||
import util.boosChat;
|
||||
|
||||
public class boosCoolDownEntityListener extends EntityListener {
|
||||
private final boosCoolDown plugin;
|
||||
|
||||
public boosCoolDownEntityListener(boosCoolDown instance) {
|
||||
plugin = instance;
|
||||
}
|
||||
|
||||
public 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) {
|
||||
if(boosWarmUpManager.hasWarmUps(player)) {
|
||||
boosChat.sendMessageToPlayer(player,boosConfigManager.getWarmUpCancelledMessage());
|
||||
boosWarmUpManager.cancelWarmUps(player);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
private final boosCoolDown plugin;
|
||||
|
||||
public boosCoolDownEntityListener(boosCoolDown instance) {
|
||||
plugin = instance;
|
||||
}
|
||||
|
||||
public 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) {
|
||||
if (boosWarmUpManager.hasWarmUps(player)) {
|
||||
boosChat.sendMessageToPlayer(player,
|
||||
boosConfigManager.getWarmUpCancelledMessage());
|
||||
boosWarmUpManager.cancelWarmUps(player);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,244 +15,267 @@ import util.boosChat;
|
||||
|
||||
public class boosCoolDownManager {
|
||||
|
||||
protected static boosCoolDown bCoolDown;
|
||||
protected static Configuration confusers;
|
||||
protected File usersConfigFile;
|
||||
protected static boosCoolDown bCoolDown;
|
||||
protected static Configuration confusers;
|
||||
protected File usersConfigFile;
|
||||
|
||||
public boosCoolDownManager(boosCoolDown bCoolDown) {
|
||||
boosCoolDownManager.bCoolDown = bCoolDown;
|
||||
File confFile = new File(bCoolDown.getDataFolder(), "users.yml");
|
||||
public boosCoolDownManager(boosCoolDown bCoolDown) {
|
||||
boosCoolDownManager.bCoolDown = bCoolDown;
|
||||
File confFile = new File(bCoolDown.getDataFolder(), "users.yml");
|
||||
|
||||
confusers = null;
|
||||
confusers = null;
|
||||
|
||||
if (confFile.exists()) {
|
||||
confusers = new Configuration(confFile);
|
||||
confusers.load();
|
||||
} else {
|
||||
confFile = new File(bCoolDown.getDataFolder(), "users.yml");
|
||||
confusers = new Configuration(confFile);
|
||||
confusers.save();
|
||||
}
|
||||
}
|
||||
if (confFile.exists()) {
|
||||
confusers = new Configuration(confFile);
|
||||
confusers.load();
|
||||
} else {
|
||||
confFile = new File(bCoolDown.getDataFolder(), "users.yml");
|
||||
confusers = new Configuration(confFile);
|
||||
confusers.save();
|
||||
}
|
||||
}
|
||||
|
||||
static void load() {
|
||||
confusers.load();
|
||||
}
|
||||
static void load() {
|
||||
confusers.load();
|
||||
}
|
||||
|
||||
static void reload() {
|
||||
load();
|
||||
}
|
||||
static void reload() {
|
||||
load();
|
||||
}
|
||||
|
||||
static void save() {
|
||||
confusers.save();
|
||||
}
|
||||
static void save() {
|
||||
confusers.save();
|
||||
}
|
||||
|
||||
static void clear() {
|
||||
List<String> players = new LinkedList<String>();
|
||||
List<String> cooldown = new LinkedList<String>();
|
||||
List<String> warmup = new LinkedList<String>();
|
||||
try {
|
||||
players.addAll(confusers.getKeys("users."));
|
||||
} catch (Exception e) {
|
||||
return;
|
||||
}
|
||||
int i = 0;
|
||||
while (i < players.size()) {
|
||||
// clear cooldown
|
||||
cooldown.clear();
|
||||
if (confusers.getKeys("users." + players.get(i) + ".cooldown") != null) {
|
||||
cooldown.addAll(confusers.getKeys("users." + players.get(i) + ".cooldown"));
|
||||
}
|
||||
int j = 0;
|
||||
while (j < cooldown.size()) {
|
||||
confusers.removeProperty("users." + players.get(i) + ".cooldown." + cooldown.get(j));
|
||||
j++;
|
||||
}
|
||||
confusers.removeProperty("users." + players.get(i) + ".cooldown");
|
||||
// clear warmup
|
||||
warmup.clear();
|
||||
if (confusers.getKeys("users." + players.get(i) + ".warmup") != null) {
|
||||
warmup.addAll(confusers.getKeys("users." + players.get(i) + ".warmup"));
|
||||
}
|
||||
int k = 0;
|
||||
while (k < warmup.size()) {
|
||||
confusers.removeProperty("users." + players.get(i) + ".warmup." + warmup.get(k));
|
||||
k++;
|
||||
}
|
||||
confusers.removeProperty("users." + players.get(i) + ".warmup");
|
||||
static void clear() {
|
||||
List<String> players = new LinkedList<String>();
|
||||
List<String> cooldown = new LinkedList<String>();
|
||||
List<String> warmup = new LinkedList<String>();
|
||||
try {
|
||||
players.addAll(confusers.getKeys("users."));
|
||||
} catch (Exception e) {
|
||||
return;
|
||||
}
|
||||
int i = 0;
|
||||
while (i < players.size()) {
|
||||
// clear cooldown
|
||||
cooldown.clear();
|
||||
if (confusers.getKeys("users." + players.get(i) + ".cooldown") != null) {
|
||||
cooldown.addAll(confusers.getKeys("users." + players.get(i)
|
||||
+ ".cooldown"));
|
||||
}
|
||||
int j = 0;
|
||||
while (j < cooldown.size()) {
|
||||
confusers.removeProperty("users." + players.get(i)
|
||||
+ ".cooldown." + cooldown.get(j));
|
||||
j++;
|
||||
}
|
||||
confusers.removeProperty("users." + players.get(i) + ".cooldown");
|
||||
// clear warmup
|
||||
warmup.clear();
|
||||
if (confusers.getKeys("users." + players.get(i) + ".warmup") != null) {
|
||||
warmup.addAll(confusers.getKeys("users." + players.get(i)
|
||||
+ ".warmup"));
|
||||
}
|
||||
int k = 0;
|
||||
while (k < warmup.size()) {
|
||||
confusers.removeProperty("users." + players.get(i) + ".warmup."
|
||||
+ warmup.get(k));
|
||||
k++;
|
||||
}
|
||||
confusers.removeProperty("users." + players.get(i) + ".warmup");
|
||||
|
||||
confusers.removeProperty("users." + players.get(i));
|
||||
i++;
|
||||
}
|
||||
save();
|
||||
load();
|
||||
}
|
||||
confusers.removeProperty("users." + players.get(i));
|
||||
i++;
|
||||
}
|
||||
save();
|
||||
load();
|
||||
}
|
||||
|
||||
static boolean coolDown(Player player, String pre, String message) {
|
||||
pre = pre.toLowerCase();
|
||||
int coolDownSeconds = boosConfigManager.getCoolDown(player, pre);
|
||||
if (coolDownSeconds > 0) {
|
||||
Date lastTime = getTime(player, pre);
|
||||
if (lastTime == null) {
|
||||
setTime(player, pre);
|
||||
return false;
|
||||
} else {
|
||||
Calendar calcurrTime = Calendar.getInstance();
|
||||
calcurrTime.setTime(getCurrTime());
|
||||
Calendar callastTime = Calendar.getInstance();
|
||||
callastTime.setTime(lastTime);
|
||||
long secondsBetween = secondsBetween(callastTime, calcurrTime);
|
||||
long waitSeconds = coolDownSeconds - secondsBetween;
|
||||
long waitMinutes = Math.round(waitSeconds / 60)+1;
|
||||
long waitHours = Math.round(waitMinutes / 60)+1;
|
||||
if (secondsBetween > coolDownSeconds) {
|
||||
setTime(player, pre);
|
||||
return false;
|
||||
} else {
|
||||
String msg = boosConfigManager.getCoolDownMessage();
|
||||
msg = msg.replaceAll("&command&", pre);
|
||||
if (waitSeconds >= 60 && 3600 >= waitSeconds) {
|
||||
msg = msg.replaceAll("&seconds&", Long.toString(waitMinutes));
|
||||
msg = msg.replaceAll("&unit&", boosConfigManager.getUnitMinutesMessage());
|
||||
} else if (waitMinutes >= 60) {
|
||||
msg = msg.replaceAll("&seconds&", Long.toString(waitHours));
|
||||
msg = msg.replaceAll("&unit&", boosConfigManager.getUnitHoursMessage());
|
||||
} else {
|
||||
msg = msg.replaceAll("&seconds&", Long.toString(waitSeconds));
|
||||
msg = msg.replaceAll("&unit&", boosConfigManager.getUnitSecondsMessage());
|
||||
}
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static boolean coolDown(Player player, String pre, String message) {
|
||||
pre = pre.toLowerCase();
|
||||
int coolDownSeconds = boosConfigManager.getCoolDown(player, pre);
|
||||
if (coolDownSeconds > 0) {
|
||||
Date lastTime = getTime(player, pre);
|
||||
if (lastTime == null) {
|
||||
setTime(player, pre);
|
||||
return false;
|
||||
} else {
|
||||
Calendar calcurrTime = Calendar.getInstance();
|
||||
calcurrTime.setTime(getCurrTime());
|
||||
Calendar callastTime = Calendar.getInstance();
|
||||
callastTime.setTime(lastTime);
|
||||
long secondsBetween = secondsBetween(callastTime, calcurrTime);
|
||||
long waitSeconds = coolDownSeconds - secondsBetween;
|
||||
long waitMinutes = Math.round(waitSeconds / 60) + 1;
|
||||
long waitHours = Math.round(waitMinutes / 60) + 1;
|
||||
if (secondsBetween > coolDownSeconds) {
|
||||
setTime(player, pre);
|
||||
return false;
|
||||
} else {
|
||||
String msg = boosConfigManager.getCoolDownMessage();
|
||||
msg = msg.replaceAll("&command&", pre);
|
||||
if (waitSeconds >= 60 && 3600 >= waitSeconds) {
|
||||
msg = msg.replaceAll("&seconds&",
|
||||
Long.toString(waitMinutes));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
boosConfigManager.getUnitMinutesMessage());
|
||||
} else if (waitMinutes >= 60) {
|
||||
msg = msg.replaceAll("&seconds&",
|
||||
Long.toString(waitHours));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
boosConfigManager.getUnitHoursMessage());
|
||||
} else {
|
||||
msg = msg.replaceAll("&seconds&",
|
||||
Long.toString(waitSeconds));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
boosConfigManager.getUnitSecondsMessage());
|
||||
}
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void cancelCoolDowns(Player player) {
|
||||
List<String> cooldown = new LinkedList<String>();
|
||||
cooldown.clear();
|
||||
cooldown.addAll(confusers.getKeys("users." + player.getName() + ".cooldown"));
|
||||
int j = 0;
|
||||
while (j < cooldown.size()) {
|
||||
confusers.removeProperty("users." + player.getName() + ".cooldown." + cooldown.get(j));
|
||||
j++;
|
||||
}
|
||||
confusers.removeProperty("users." + player.getName() + ".cooldown");
|
||||
}
|
||||
static void cancelCoolDowns(Player player) {
|
||||
List<String> cooldown = new LinkedList<String>();
|
||||
cooldown.clear();
|
||||
cooldown.addAll(confusers.getKeys("users." + player.getName()
|
||||
+ ".cooldown"));
|
||||
int j = 0;
|
||||
while (j < cooldown.size()) {
|
||||
confusers.removeProperty("users." + player.getName() + ".cooldown."
|
||||
+ cooldown.get(j));
|
||||
j++;
|
||||
}
|
||||
confusers.removeProperty("users." + player.getName() + ".cooldown");
|
||||
}
|
||||
|
||||
static boolean checkCoolDownOK(Player player, String pre, String message) {
|
||||
pre = pre.toLowerCase();
|
||||
int coolDownSeconds = boosConfigManager.getCoolDown(player, pre);
|
||||
if (coolDownSeconds > 0) {
|
||||
Date lastTime = getTime(player, pre);
|
||||
if (lastTime == null) {
|
||||
return true;
|
||||
} else {
|
||||
Calendar calcurrTime = Calendar.getInstance();
|
||||
calcurrTime.setTime(getCurrTime());
|
||||
Calendar callastTime = Calendar.getInstance();
|
||||
callastTime.setTime(lastTime);
|
||||
long secondsBetween = secondsBetween(callastTime, calcurrTime);
|
||||
long waitSeconds = coolDownSeconds - secondsBetween;
|
||||
long waitMinutes = Math.round(waitSeconds / 60)+1;
|
||||
long waitHours = Math.round(waitMinutes / 60)+1;
|
||||
if (secondsBetween > coolDownSeconds) {
|
||||
return true;
|
||||
} else {
|
||||
String msg = boosConfigManager.getCoolDownMessage();
|
||||
msg = msg.replaceAll("&command&", pre);
|
||||
if (waitSeconds >= 60 && 3600 >= waitSeconds) {
|
||||
msg = msg.replaceAll("&seconds&", Long.toString(waitMinutes));
|
||||
msg = msg.replaceAll("&unit&", boosConfigManager.getUnitMinutesMessage());
|
||||
} else if (waitMinutes >= 60) {
|
||||
msg = msg.replaceAll("&seconds&", Long.toString(waitHours));
|
||||
msg = msg.replaceAll("&unit&", boosConfigManager.getUnitHoursMessage());
|
||||
} else {
|
||||
msg = msg.replaceAll("&seconds&", Long.toString(waitSeconds));
|
||||
msg = msg.replaceAll("&unit&", boosConfigManager.getUnitSecondsMessage());
|
||||
}
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
static boolean checkCoolDownOK(Player player, String pre, String message) {
|
||||
pre = pre.toLowerCase();
|
||||
int coolDownSeconds = boosConfigManager.getCoolDown(player, pre);
|
||||
if (coolDownSeconds > 0) {
|
||||
Date lastTime = getTime(player, pre);
|
||||
if (lastTime == null) {
|
||||
return true;
|
||||
} else {
|
||||
Calendar calcurrTime = Calendar.getInstance();
|
||||
calcurrTime.setTime(getCurrTime());
|
||||
Calendar callastTime = Calendar.getInstance();
|
||||
callastTime.setTime(lastTime);
|
||||
long secondsBetween = secondsBetween(callastTime, calcurrTime);
|
||||
long waitSeconds = coolDownSeconds - secondsBetween;
|
||||
long waitMinutes = Math.round(waitSeconds / 60) + 1;
|
||||
long waitHours = Math.round(waitMinutes / 60) + 1;
|
||||
if (secondsBetween > coolDownSeconds) {
|
||||
return true;
|
||||
} else {
|
||||
String msg = boosConfigManager.getCoolDownMessage();
|
||||
msg = msg.replaceAll("&command&", pre);
|
||||
if (waitSeconds >= 60 && 3600 >= waitSeconds) {
|
||||
msg = msg.replaceAll("&seconds&",
|
||||
Long.toString(waitMinutes));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
boosConfigManager.getUnitMinutesMessage());
|
||||
} else if (waitMinutes >= 60) {
|
||||
msg = msg.replaceAll("&seconds&",
|
||||
Long.toString(waitHours));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
boosConfigManager.getUnitHoursMessage());
|
||||
} else {
|
||||
msg = msg.replaceAll("&seconds&",
|
||||
Long.toString(waitSeconds));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
boosConfigManager.getUnitSecondsMessage());
|
||||
}
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void setTime(Player player, String pre) {
|
||||
pre = pre.toLowerCase();
|
||||
String currTime = "";
|
||||
Calendar cal = Calendar.getInstance();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
|
||||
currTime = sdf.format(cal.getTime());
|
||||
confusers.setProperty("users." + player.getName() + ".cooldown." + pre, currTime);
|
||||
confusers.save();
|
||||
}
|
||||
static void setTime(Player player, String pre) {
|
||||
pre = pre.toLowerCase();
|
||||
String currTime = "";
|
||||
Calendar cal = Calendar.getInstance();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
|
||||
currTime = sdf.format(cal.getTime());
|
||||
confusers.setProperty("users." + player.getName() + ".cooldown." + pre,
|
||||
currTime);
|
||||
confusers.save();
|
||||
}
|
||||
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
try {
|
||||
time = sdf.parse(currTime);
|
||||
return time;
|
||||
} catch (ParseException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static Date getTime(Player player, String pre) {
|
||||
pre = pre.toLowerCase();
|
||||
String confTime = "";
|
||||
confTime = confusers.getString("users." + player.getName() + ".cooldown." + pre, null);
|
||||
static Date getTime(Player player, String pre) {
|
||||
pre = pre.toLowerCase();
|
||||
String confTime = "";
|
||||
confTime = confusers.getString("users." + player.getName()
|
||||
+ ".cooldown." + pre, null);
|
||||
|
||||
if (confTime != null && !confTime.equals( "" ) ) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
|
||||
Date lastDate = 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;
|
||||
}
|
||||
try {
|
||||
lastDate = sdf.parse(confTime);
|
||||
return lastDate;
|
||||
} catch (ParseException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static long secondsBetween(Calendar startDate, Calendar endDate) {
|
||||
long secondsBetween = 0;
|
||||
public static long secondsBetween(Calendar startDate, Calendar endDate) {
|
||||
long secondsBetween = 0;
|
||||
|
||||
while (startDate.before(endDate)) {
|
||||
startDate.add(Calendar.SECOND, 1);
|
||||
secondsBetween++;
|
||||
}
|
||||
return secondsBetween;
|
||||
}
|
||||
while (startDate.before(endDate)) {
|
||||
startDate.add(Calendar.SECOND, 1);
|
||||
secondsBetween++;
|
||||
}
|
||||
return secondsBetween;
|
||||
}
|
||||
|
||||
static void setWarmUpOK(Player player, String pre, String message) {
|
||||
pre = pre.toLowerCase();
|
||||
confusers.setProperty("users." + player.getName() + ".warmup." + pre, 1);
|
||||
confusers.save();
|
||||
}
|
||||
static void setWarmUpOK(Player player, String pre, String message) {
|
||||
pre = pre.toLowerCase();
|
||||
confusers
|
||||
.setProperty("users." + player.getName() + ".warmup." + pre, 1);
|
||||
confusers.save();
|
||||
}
|
||||
|
||||
static boolean checkWarmUpOK(Player player, String pre, String message) {
|
||||
pre = pre.toLowerCase();
|
||||
int ok = 0;
|
||||
ok = confusers.getInt("users." + player.getName() + ".warmup." + pre, ok);
|
||||
if (ok == 1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static boolean checkWarmUpOK(Player player, String pre, String message) {
|
||||
pre = pre.toLowerCase();
|
||||
int ok = 0;
|
||||
ok = confusers.getInt("users." + player.getName() + ".warmup." + pre,
|
||||
ok);
|
||||
if (ok == 1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void removeWarmUpOK(Player player, String pre, String message) {
|
||||
pre = pre.toLowerCase();
|
||||
confusers.removeProperty("users." + player.getName() + ".warmup." + pre);
|
||||
confusers.save();
|
||||
}
|
||||
static void removeWarmUpOK(Player player, String pre, String message) {
|
||||
pre = pre.toLowerCase();
|
||||
confusers
|
||||
.removeProperty("users." + player.getName() + ".warmup." + pre);
|
||||
confusers.save();
|
||||
}
|
||||
}
|
||||
|
@ -7,92 +7,95 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
//import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
|
||||
public class boosCoolDownPlayerListener extends PlayerListener {
|
||||
private final boosCoolDown plugin;
|
||||
|
||||
public boosCoolDownPlayerListener(boosCoolDown instance) {
|
||||
plugin = instance;
|
||||
}
|
||||
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
String message = event.getMessage();
|
||||
Player player = event.getPlayer();
|
||||
boolean on = true;
|
||||
|
||||
if(player.isOp()) {
|
||||
on = false;
|
||||
}
|
||||
if(player.hasPermission("boosCoolDown.exception") || player.isOp()) {
|
||||
on = false;
|
||||
} else {
|
||||
on = true;
|
||||
}
|
||||
|
||||
|
||||
if(on) {
|
||||
int i = message.indexOf(' ');
|
||||
if(i < 0) { i = message.length(); }
|
||||
|
||||
String preCommand = message.substring(0, i);
|
||||
String messageCommand = message.substring(i, message.length());
|
||||
|
||||
boolean onCooldown = this.checkCooldown(event, player, preCommand, messageCommand);
|
||||
|
||||
if (!onCooldown && messageCommand.length() > 1) {
|
||||
int j = messageCommand.indexOf(' ', 1);
|
||||
if(j < 0) { j = messageCommand.length(); }
|
||||
|
||||
String preSub = messageCommand.substring(1, j);
|
||||
String messageSub = messageCommand.substring(j, messageCommand.length());
|
||||
preSub = preCommand+' '+preSub;
|
||||
|
||||
onCooldown = this.checkCooldown(event, player, preSub, messageSub);
|
||||
}
|
||||
}
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
String message = event.getMessage();
|
||||
Player player = event.getPlayer();
|
||||
boolean on = true;
|
||||
|
||||
if (player.isOp()) {
|
||||
on = false;
|
||||
}
|
||||
if (player.hasPermission("boosCoolDown.exception") || player.isOp()) {
|
||||
on = false;
|
||||
} else {
|
||||
on = true;
|
||||
}
|
||||
|
||||
if (on) {
|
||||
int i = message.indexOf(' ');
|
||||
if (i < 0) {
|
||||
i = message.length();
|
||||
}
|
||||
|
||||
String preCommand = message.substring(0, i);
|
||||
String messageCommand = message.substring(i, message.length());
|
||||
|
||||
boolean onCooldown = this.checkCooldown(event, player, preCommand,
|
||||
messageCommand);
|
||||
|
||||
if (!onCooldown && messageCommand.length() > 1) {
|
||||
int j = messageCommand.indexOf(' ', 1);
|
||||
if (j < 0) {
|
||||
j = messageCommand.length();
|
||||
}
|
||||
|
||||
String preSub = messageCommand.substring(1, j);
|
||||
String messageSub = messageCommand.substring(j,
|
||||
messageCommand.length());
|
||||
preSub = preCommand + ' ' + preSub;
|
||||
|
||||
onCooldown = this.checkCooldown(event, player, preSub,
|
||||
messageSub);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Returns true if the command is on cooldown, false otherwise
|
||||
private boolean checkCooldown(PlayerCommandPreprocessEvent event, Player player, String pre, String message) {
|
||||
int warmUpSeconds = boosConfigManager.getWarmUp(player, pre);
|
||||
if(warmUpSeconds > 0) {
|
||||
if(!boosCoolDownManager.checkWarmUpOK(player, pre, message)) {
|
||||
if(boosCoolDownManager.checkCoolDownOK(player, pre, message)) {
|
||||
boosWarmUpManager.startWarmUp(this.plugin, player, pre, message, warmUpSeconds);
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(boosCoolDownManager.coolDown(player, pre, message)) {
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
boosCoolDownManager.removeWarmUpOK(player, pre, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(boosCoolDownManager.coolDown(player, pre, message)) {
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean checkCooldown(PlayerCommandPreprocessEvent event,
|
||||
Player player, String pre, String message) {
|
||||
int warmUpSeconds = boosConfigManager.getWarmUp(player, pre);
|
||||
if (warmUpSeconds > 0) {
|
||||
if (!boosCoolDownManager.checkWarmUpOK(player, pre, message)) {
|
||||
if (boosCoolDownManager.checkCoolDownOK(player, pre, message)) {
|
||||
boosWarmUpManager.startWarmUp(this.plugin, player, pre,
|
||||
message, warmUpSeconds);
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (boosCoolDownManager.coolDown(player, pre, message)) {
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
} else {
|
||||
boosCoolDownManager.removeWarmUpOK(player, pre, message);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (boosCoolDownManager.coolDown(player, pre, message)) {
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onPlayerCommandMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
boosWarmUpManager.cancelWarmUps(player);
|
||||
boosCoolDownManager.cancelCoolDowns(player);
|
||||
|
||||
Player player = event.getPlayer();
|
||||
boosWarmUpManager.cancelWarmUps(player);
|
||||
boosCoolDownManager.cancelCoolDowns(player);
|
||||
|
||||
}
|
||||
}
|
@ -7,69 +7,74 @@ import org.bukkit.entity.Player;
|
||||
import util.boosChat;
|
||||
|
||||
public class boosWarmUpManager {
|
||||
|
||||
private static HashMap<String, boosWarmUpTimer> playercommands = new HashMap<String, boosWarmUpTimer>();
|
||||
|
||||
static Timer scheduler;
|
||||
|
||||
public static void startWarmUp(boosCoolDown bCoolDown, Player player, String pre, String message, int warmUpSeconds) {
|
||||
pre = pre.toLowerCase();
|
||||
long warmUpMinutes = Math.round(warmUpSeconds / 60)+1;
|
||||
long warmUpHours = Math.round(warmUpMinutes / 60)+1;
|
||||
if(!isWarmUpProcess(player, pre, message)) {
|
||||
boosCoolDownManager.removeWarmUpOK(player, pre, message);
|
||||
String msg = boosConfigManager.getWarmUpMessage();
|
||||
msg = msg.replaceAll("&command&", pre);
|
||||
if (warmUpSeconds >= 60 && 3600 >= warmUpSeconds) {
|
||||
msg = msg.replaceAll("&seconds&", Long.toString(warmUpMinutes));
|
||||
msg = msg.replaceAll("&unit&", boosConfigManager.getUnitMinutesMessage());
|
||||
} else if (warmUpMinutes >= 60) {
|
||||
msg = msg.replaceAll("&seconds&", Long.toString(warmUpHours));
|
||||
msg = msg.replaceAll("&unit&", boosConfigManager.getUnitHoursMessage());
|
||||
} else {
|
||||
msg = msg.replaceAll("&seconds&", Long.toString(warmUpSeconds));
|
||||
msg = msg.replaceAll("&unit&", boosConfigManager.getUnitSecondsMessage());
|
||||
}
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
|
||||
scheduler = new Timer();
|
||||
boosWarmUpTimer scheduleMe = new boosWarmUpTimer(bCoolDown, scheduler, player, pre, message);
|
||||
playercommands.put(player.getName() + "@" + pre, scheduleMe);
|
||||
scheduler.schedule(scheduleMe, warmUpSeconds * 1000);
|
||||
}
|
||||
else {
|
||||
String msg = boosConfigManager.getWarmUpAlreadyStartedMessage();
|
||||
msg = msg.replaceAll("&command&", pre);
|
||||
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 boolean hasWarmUps(Player player) {
|
||||
for(String key: playercommands.keySet()) {
|
||||
if(key.startsWith(player.getName() + "@")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static HashMap<String, boosWarmUpTimer> playercommands = new HashMap<String, boosWarmUpTimer>();
|
||||
|
||||
static Timer scheduler;
|
||||
|
||||
public static void startWarmUp(boosCoolDown bCoolDown, Player player,
|
||||
String pre, String message, int warmUpSeconds) {
|
||||
pre = pre.toLowerCase();
|
||||
long warmUpMinutes = Math.round(warmUpSeconds / 60) + 1;
|
||||
long warmUpHours = Math.round(warmUpMinutes / 60) + 1;
|
||||
if (!isWarmUpProcess(player, pre, message)) {
|
||||
boosCoolDownManager.removeWarmUpOK(player, pre, message);
|
||||
String msg = boosConfigManager.getWarmUpMessage();
|
||||
msg = msg.replaceAll("&command&", pre);
|
||||
if (warmUpSeconds >= 60 && 3600 >= warmUpSeconds) {
|
||||
msg = msg.replaceAll("&seconds&", Long.toString(warmUpMinutes));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
boosConfigManager.getUnitMinutesMessage());
|
||||
} else if (warmUpMinutes >= 60) {
|
||||
msg = msg.replaceAll("&seconds&", Long.toString(warmUpHours));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
boosConfigManager.getUnitHoursMessage());
|
||||
} else {
|
||||
msg = msg.replaceAll("&seconds&", Long.toString(warmUpSeconds));
|
||||
msg = msg.replaceAll("&unit&",
|
||||
boosConfigManager.getUnitSecondsMessage());
|
||||
}
|
||||
boosChat.sendMessageToPlayer(player, msg);
|
||||
|
||||
scheduler = new Timer();
|
||||
boosWarmUpTimer scheduleMe = new boosWarmUpTimer(bCoolDown,
|
||||
scheduler, player, pre, message);
|
||||
playercommands.put(player.getName() + "@" + pre, scheduleMe);
|
||||
scheduler.schedule(scheduleMe, warmUpSeconds * 1000);
|
||||
} else {
|
||||
String msg = boosConfigManager.getWarmUpAlreadyStartedMessage();
|
||||
msg = msg.replaceAll("&command&", pre);
|
||||
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 boolean hasWarmUps(Player player) {
|
||||
for (String key : playercommands.keySet()) {
|
||||
if (key.startsWith(player.getName() + "@")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -5,28 +5,30 @@ import java.util.TimerTask;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public class boosWarmUpTimer extends TimerTask {
|
||||
|
||||
boosCoolDown bCoolDown;
|
||||
Player player;
|
||||
String pre;
|
||||
String message;
|
||||
|
||||
public boosWarmUpTimer(boosCoolDown bCoolDown, Timer timer, Player player, String pre, String message){
|
||||
this.bCoolDown = bCoolDown;
|
||||
this.player = player;
|
||||
this.pre = pre;
|
||||
this.message = message;
|
||||
}
|
||||
public boosWarmUpTimer() {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if(player.isOnline()) {
|
||||
boosCoolDownManager.setWarmUpOK(player, pre, message);
|
||||
boosWarmUpManager.removeWarmUpProcess(this.player.getName() + "@" + pre);
|
||||
player.chat(pre + message);
|
||||
}
|
||||
}
|
||||
|
||||
boosCoolDown bCoolDown;
|
||||
Player player;
|
||||
String pre;
|
||||
String message;
|
||||
|
||||
public boosWarmUpTimer(boosCoolDown bCoolDown, Timer timer, Player player,
|
||||
String pre, String message) {
|
||||
this.bCoolDown = bCoolDown;
|
||||
this.player = player;
|
||||
this.pre = pre;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public boosWarmUpTimer() {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (player.isOnline()) {
|
||||
boosCoolDownManager.setWarmUpOK(player, pre, message);
|
||||
boosWarmUpManager.removeWarmUpProcess(this.player.getName() + "@"
|
||||
+ pre);
|
||||
player.chat(pre + message);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user