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