mirror of
https://github.com/LordBoos/boosCooldowns.git
synced 2024-11-23 19:16:03 +01:00
Merge pull request #1 from Neptune-Whitebear/master
Add WarmUp cancellation on receiving damage
This commit is contained in:
commit
2631bf40b2
@ -34,10 +34,12 @@ public class boosConfigManager {
|
||||
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");
|
||||
@ -70,6 +72,9 @@ public class boosConfigManager {
|
||||
static String getCoolDownMessage() {
|
||||
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() {
|
||||
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() {
|
||||
return conf.getBoolean("commands.options.clear_on_restart", false);
|
||||
}
|
||||
static boolean getCancelWarmUpOnDamage() {
|
||||
return conf.getBoolean("commands.options.cancel_warmup_on_damage", false);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ 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;
|
||||
@ -27,7 +28,6 @@ public class boosCoolDown extends JavaPlugin {
|
||||
public static boolean permissions = false;
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
pdfFile = this.getDescription();
|
||||
@ -42,6 +42,9 @@ public class boosCoolDown extends JavaPlugin {
|
||||
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 {
|
||||
@ -53,7 +56,6 @@ public class boosCoolDown extends JavaPlugin {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (boosConfigManager.getClearOnRestart() == true) {
|
||||
boosCoolDownManager.clear();
|
||||
|
34
src/cz/boosik/boosCooldown/boosCoolDownEntityListener.java
Normal file
34
src/cz/boosik/boosCooldown/boosCoolDownEntityListener.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
//import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
|
||||
|
@ -34,7 +34,7 @@ public class boosWarmUpManager {
|
||||
|
||||
scheduler = new Timer();
|
||||
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);
|
||||
}
|
||||
else {
|
||||
@ -46,7 +46,7 @@ public class boosWarmUpManager {
|
||||
|
||||
public static boolean isWarmUpProcess(Player player, String pre, String message) {
|
||||
pre = pre.toLowerCase();
|
||||
if (playercommands.containsKey(player.getName() + pre)) {
|
||||
if (playercommands.containsKey(player.getName() + "@" + pre)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -57,6 +57,19 @@ public class boosWarmUpManager {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user