Merge pull request #1 from Neptune-Whitebear/master

Add WarmUp cancellation on receiving damage
This commit is contained in:
Boosik 2011-10-02 16:21:28 -07:00
commit 2631bf40b2
5 changed files with 64 additions and 5 deletions

View File

@ -34,10 +34,12 @@ public class boosConfigManager {
conf.setProperty("commands.cooldown./home", 30); conf.setProperty("commands.cooldown./home", 30);
conf.setProperty("commands.warmup./give", 60); conf.setProperty("commands.warmup./give", 60);
conf.setProperty("commands.warmup./home", 20); 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.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");
conf.setProperty("commands.options.unit_hours", "hours"); 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_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", "&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.setProperty("commands.options.message_warmup_alreadystarted", "&6Warm-Up process for&e &command& &6has already started.&f");
@ -70,6 +72,9 @@ public class boosConfigManager {
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() {
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");
} }
@ -88,4 +93,8 @@ public class boosConfigManager {
static boolean getClearOnRestart() { static boolean getClearOnRestart() {
return conf.getBoolean("commands.options.clear_on_restart", false); return conf.getBoolean("commands.options.clear_on_restart", false);
} }
static boolean getCancelWarmUpOnDamage() {
return conf.getBoolean("commands.options.cancel_warmup_on_damage", false);
}
} }

View File

@ -19,6 +19,7 @@ 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(this);
private final boosCoolDownEntityListener entityListener = new boosCoolDownEntityListener(this);
public static final Logger log = Logger.getLogger("Minecraft"); public static final Logger log = Logger.getLogger("Minecraft");
public static PluginDescriptionFile pdfFile; public static PluginDescriptionFile pdfFile;
public static Configuration conf; public static Configuration conf;
@ -27,7 +28,6 @@ public class boosCoolDown extends JavaPlugin {
public static boolean permissions = false; public static boolean permissions = false;
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
@Override
public void onEnable() { public void onEnable() {
pdfFile = this.getDescription(); pdfFile = this.getDescription();
@ -42,6 +42,9 @@ public class boosCoolDown extends JavaPlugin {
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.getClearOnRestart() == true) { if (boosConfigManager.getClearOnRestart() == true) {
boosCoolDownManager.clear(); boosCoolDownManager.clear();
} else { } else {
@ -53,7 +56,6 @@ public class boosCoolDown extends JavaPlugin {
} }
@Override
public void onDisable() { public void onDisable() {
if (boosConfigManager.getClearOnRestart() == true) { if (boosConfigManager.getClearOnRestart() == true) {
boosCoolDownManager.clear(); boosCoolDownManager.clear();

View File

@ -0,0 +1,34 @@
package cz.boosik.boosCooldown;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
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);
}
}
}
}
}

View File

@ -4,6 +4,7 @@ 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.entity.EntityDamageEvent; //import org.bukkit.event.entity.EntityDamageEvent;

View File

@ -34,7 +34,7 @@ public class boosWarmUpManager {
scheduler = new Timer(); scheduler = new Timer();
boosWarmUpTimer scheduleMe = new boosWarmUpTimer(bCoolDown, scheduler, player, pre, message); boosWarmUpTimer scheduleMe = new boosWarmUpTimer(bCoolDown, scheduler, player, pre, message);
playercommands.put(player.getName() + pre, scheduleMe); playercommands.put(player.getName() + "@" + pre, scheduleMe);
scheduler.schedule(scheduleMe, warmUpSeconds * 1000); scheduler.schedule(scheduleMe, warmUpSeconds * 1000);
} }
else { else {
@ -46,7 +46,7 @@ public class boosWarmUpManager {
public static boolean isWarmUpProcess(Player player, String pre, String message) { public static boolean isWarmUpProcess(Player player, String pre, String message) {
pre = pre.toLowerCase(); pre = pre.toLowerCase();
if (playercommands.containsKey(player.getName() + pre)) { if (playercommands.containsKey(player.getName() + "@" + pre)) {
return true; return true;
} }
return false; return false;
@ -57,6 +57,19 @@ public class boosWarmUpManager {
} }
public static void cancelWarmUps(Player player) { public static void cancelWarmUps(Player player) {
removeWarmUpProcess(player.getName()); 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;
} }
} }