added new warmup cancels, created new methods to clean up overloaded

onEnable
This commit is contained in:
Boos 2011-12-31 16:49:08 +01:00
parent e11751193b
commit cef9e5b8bd
3 changed files with 165 additions and 63 deletions

View File

@ -37,6 +37,8 @@ public class boosConfigManager {
conf.setProperty("commands.price./home", 20); conf.setProperty("commands.price./home", 20);
conf.setProperty("commands.options.cancel_warmup_on_damage", false); conf.setProperty("commands.options.cancel_warmup_on_damage", false);
conf.setProperty("commands.options.cancel_warmup_on_move", false); conf.setProperty("commands.options.cancel_warmup_on_move", false);
conf.setProperty("commands.options.cancel_warmup_on_sneak", false);
conf.setProperty("commands.options.cancel_warmup_on_sprint", false);
conf.setProperty("commands.options.clear_on_restart", false); conf.setProperty("commands.options.clear_on_restart", false);
conf.setProperty("commands.options.unit_seconds", "seconds"); conf.setProperty("commands.options.unit_seconds", "seconds");
conf.setProperty("commands.options.unit_minutes", "minutes"); conf.setProperty("commands.options.unit_minutes", "minutes");
@ -47,6 +49,12 @@ public class boosConfigManager {
conf.setProperty( conf.setProperty(
"commands.options.message_warmup_cancelled_by_move", "commands.options.message_warmup_cancelled_by_move",
"&6Warm-ups have been cancelled due to moving.&f"); "&6Warm-ups have been cancelled due to moving.&f");
conf.setProperty(
"commands.options.message_warmup_cancelled_by_sprint",
"&6Warm-ups have been cancelled due to sprinting.&f");
conf.setProperty(
"commands.options.message_warmup_cancelled_by_sneak",
"&6Warm-ups have been cancelled due to sneaking.&f");
conf.setProperty("commands.options.message_cooldown", conf.setProperty("commands.options.message_cooldown",
"&6Wait&e &seconds& &unit&&6 before you can use command&e &command& &6again.&f"); "&6Wait&e &seconds& &unit&&6 before you can use command&e &command& &6again.&f");
conf.setProperty("commands.options.message_warmup", conf.setProperty("commands.options.message_warmup",
@ -136,7 +144,7 @@ public class boosConfigManager {
return conf.getBoolean("commands.options.clear_on_restart", false); return conf.getBoolean("commands.options.clear_on_restart", false);
} }
static boolean getCancelWarmUpOnDamage() { public static boolean getCancelWarmUpOnDamage() {
return conf.getBoolean("commands.options.cancel_warmup_on_damage", return conf.getBoolean("commands.options.cancel_warmup_on_damage",
false); false);
} }
@ -155,4 +163,26 @@ public class boosConfigManager {
"An error has occured: %s"); "An error has occured: %s");
} }
public static boolean getCancelWarmupOnSprint() {
return conf.getBoolean("commands.options.cancel_warmup_on_sprint",
false);
}
public static boolean getCancelWarmupOnSneak() {
return conf
.getBoolean("commands.options.cancel_warmup_on_sneak", false);
}
public static String getCancelWarmupOnSneakMessage() {
return conf.getString(
"commands.options.message_warmup_cancelled_by_sneak",
"&6Warm-ups have been cancelled due to sneaking.&f");
}
public static String getCancelWarmupOnSprintMessage() {
return conf.getString(
"commands.options.message_warmup_cancelled_by_sprint",
"&6Warm-ups have been cancelled due to sprinting.&f");
}
} }

View File

@ -36,84 +36,26 @@ public class boosCoolDown extends JavaPlugin {
private static boolean usingVault = false; private static boolean usingVault = false;
private static boolean usingEconomy = false; private static boolean usingEconomy = false;
private static boolean usingPermissions = false; private static boolean usingPermissions = false;
private PluginManager pm = getServer().getPluginManager();
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
public void onEnable() { public void onEnable() {
pdfFile = this.getDescription(); pdfFile = this.getDescription();
PluginManager pm = getServer().getPluginManager();
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 " log.info("[" + pdfFile.getName() + "]" + " version "
+ pdfFile.getVersion() + " by " + pdfFile.getAuthors() + pdfFile.getVersion() + " by " + pdfFile.getAuthors()
+ " is enabled!"); + " is enabled!");
registerEvents();
initializeVault();
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()) {
pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener,
Event.Priority.Normal, this);
}
if (boosConfigManager.getCancelWarmupOnMove()) {
pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener,
Event.Priority.Normal, this);
}
if (boosConfigManager.getClearOnRestart()) { if (boosConfigManager.getClearOnRestart()) {
boosCoolDownManager.clear(); boosCoolDownManager.clear();
} }
Plugin x = this.getServer().getPluginManager().getPlugin("Vault");
if (x != null & x instanceof Vault) {
vault = (Vault) x;
log.info("[" + pdfFile.getName() + "]"
+ " found [Vault] searching for economy plugin.");
log.info("[" + pdfFile.getName() + "]"
+ " found [Vault] searching for permissions plugin.");
usingVault = true;
if (setupEconomy() && setupPermissions()) {
log.info("[" + pdfFile.getName() + "]" + " found ["
+ economy.getName()
+ "] plugin, enabling prices support.");
log.info("[" + pdfFile.getName() + "]" + " found ["
+ permissions.getName()
+ "] plugin, enabling permissions support.");
} else if (setupEconomy() && !setupPermissions()) {
log.info("[" + pdfFile.getName() + "]" + " found ["
+ economy.getName()
+ "] plugin, enabling prices support.");
log.info("["
+ pdfFile.getName()
+ "]"
+ "] permissions pluging not found, disabling permissions support.");
} else if (!setupEconomy() && setupPermissions()) {
log.info("["
+ pdfFile.getName()
+ "]"
+ " economy plugin not found, disabling prices support.");
usingEconomy = false;
log.info("[" + pdfFile.getName() + "]" + " found ["
+ permissions.getName()
+ "] plugin, enabling permissions support.");
} else {
log.info("["
+ pdfFile.getName()
+ "]"
+ " economy plugin not found, disabling prices support.");
log.info("["
+ pdfFile.getName()
+ "]"
+ "] permissions pluging not found, disabling permissions support.");
}
} else {
log.info("["
+ pdfFile.getName()
+ "]"
+ " [Vault] not found disabling economy and permissions support.");
usingVault = false;
}
confusers = boosCoolDownManager.confusers; confusers = boosCoolDownManager.confusers;
} }
@ -199,4 +141,76 @@ public class boosCoolDown extends JavaPlugin {
usingPermissions = false; usingPermissions = false;
return false; return false;
} }
private void registerEvents(){
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener,
Event.Priority.Lowest, this);
if (boosConfigManager.getCancelWarmUpOnDamage()) {
pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener,
Event.Priority.Normal, this);
}
if (boosConfigManager.getCancelWarmupOnMove()) {
pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener,
Event.Priority.Normal, this);
}
if (boosConfigManager.getCancelWarmupOnSprint()){
pm.registerEvent(Event.Type.PLAYER_TOGGLE_SPRINT, playerListener, Event.Priority.Normal, this);
}
if(boosConfigManager.getCancelWarmupOnSneak()){
pm.registerEvent(Event.Type.PLAYER_TOGGLE_SNEAK, playerListener, Event.Priority.Normal, this);
}
}
private void initializeVault() {
Plugin x = this.getServer().getPluginManager().getPlugin("Vault");
if (x != null & x instanceof Vault) {
vault = (Vault) x;
log.info("[" + pdfFile.getName() + "]"
+ " found [Vault] searching for economy plugin.");
log.info("[" + pdfFile.getName() + "]"
+ " found [Vault] searching for permissions plugin.");
usingVault = true;
if (setupEconomy() && setupPermissions()) {
log.info("[" + pdfFile.getName() + "]" + " found ["
+ economy.getName()
+ "] plugin, enabling prices support.");
log.info("[" + pdfFile.getName() + "]" + " found ["
+ permissions.getName()
+ "] plugin, enabling permissions support.");
} else if (setupEconomy() && !setupPermissions()) {
log.info("[" + pdfFile.getName() + "]" + " found ["
+ economy.getName()
+ "] plugin, enabling prices support.");
log.info("["
+ pdfFile.getName()
+ "]"
+ "] permissions pluging not found, disabling permissions support.");
} else if (!setupEconomy() && setupPermissions()) {
log.info("["
+ pdfFile.getName()
+ "]"
+ " economy plugin not found, disabling prices support.");
usingEconomy = false;
log.info("[" + pdfFile.getName() + "]" + " found ["
+ permissions.getName()
+ "] plugin, enabling permissions support.");
} else {
log.info("["
+ pdfFile.getName()
+ "]"
+ " economy plugin not found, disabling prices support.");
log.info("["
+ pdfFile.getName()
+ "]"
+ "] permissions pluging not found, disabling permissions support.");
}
} else {
log.info("["
+ pdfFile.getName()
+ "]"
+ " [Vault] not found disabling economy and permissions support.");
usingVault = false;
}
}
} }

View File

@ -7,6 +7,8 @@ import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.event.player.PlayerToggleSprintEvent;
import util.boosChat; import util.boosChat;
@ -198,4 +200,60 @@ public class boosCoolDownPlayerListener extends PlayerListener {
} }
return false; return false;
} }
public void onPlayerToggleSneak(PlayerToggleSneakEvent event){
if (event.isCancelled()) {
return;
}
Player player = event.getPlayer();
if (boosCoolDown.isUsingPermissions()) {
if (player != null
&& !boosCoolDown.getPermissions().has(player,
"booscooldowns.nocancel.sneak") ) {
if (boosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player,
boosConfigManager.getCancelWarmupOnSneakMessage());
boosWarmUpManager.cancelWarmUps(player);
}
}
} else {
if (player != null) {
if (boosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player,
boosConfigManager.getCancelWarmupOnSneakMessage());
boosWarmUpManager.cancelWarmUps(player);
}
}
}
}
public void onPlayerToggleSprint(PlayerToggleSprintEvent event){
if (event.isCancelled()) {
return;
}
Player player = event.getPlayer();
if (boosCoolDown.isUsingPermissions()) {
if (player != null
&& !boosCoolDown.getPermissions().has(player,
"booscooldowns.nocancel.sprint") ) {
if (boosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player,
boosConfigManager.getCancelWarmupOnSprintMessage());
boosWarmUpManager.cancelWarmUps(player);
}
}
} else {
if (player != null) {
if (boosWarmUpManager.hasWarmUps(player)) {
boosChat.sendMessageToPlayer(player,
boosConfigManager.getCancelWarmupOnSprintMessage());
boosWarmUpManager.cancelWarmUps(player);
}
}
}
}
} }