Added ability to award health to players for getting kills.

This commit is contained in:
2022-06-04 17:30:38 -04:00
parent aba6223442
commit 304fcf995b
6 changed files with 77 additions and 1 deletions

View File

@@ -225,11 +225,14 @@ public final class CommandHandler {
}
sender.sendMessage(successMessage("Configuration variables for arena " + arena.getName()) + ":");
sender.sendMessage(successMessage(" - Enabled: " + arena.isEnabled()));
sender.sendMessage(successMessage(" - Refill: " + arena.getRefill() + " snowballs"));
sender.sendMessage(successMessage(" - Player Limit: " + arena.getPlayerLimit() + " players"));
sender.sendMessage(successMessage(" - Grace Time: " + (arena.getGraceTime() / 20) + "s"));
sender.sendMessage(successMessage(" - Match Time: " + (arena.getMatchTime() / 20) + "s"));
sender.sendMessage(successMessage(" - Damage: " + arena.getDamage() + " HP"));
sender.sendMessage(successMessage(" - Regen: " + arena.getRegen() + " HP"));
sender.sendMessage(successMessage(" - Mob Spawning Allowed: " + arena.isMobSpawningAllowed()));
sender.sendMessage(successMessage(" - World: " + arena.getWorld().getName()));
Location pos1 = arena.getPos1(), pos2 = arena.getPos2();
@@ -378,7 +381,7 @@ public final class CommandHandler {
}
/**
* Changes the amount of damage done per snowball hit in this arena.
* Changes the amount of damage done per snowball hit in an arena.
*
* @param sender The user who executed the command.
* @param name The name of the arena.
@@ -404,6 +407,40 @@ public final class CommandHandler {
this.snowbrawl.saveConfig();
}
/**
* Changes the amount of regen awarded to players per kill in an arena.
*
* @param sender The user who executed the command.
* @param name The name of the arena.
* @param regen The amount of regen for this arena.
*/
@Command(hook = "set_arena_regen")
public void commandArenasRegen(CommandSender sender, String name, int regen){
Arena arena = this.snowbrawl.getArenaManager().getArenaByName(name);
if (arena == null){
sender.sendMessage(failMessage("The specified arena does not exist."));
return;
}
int oldRegen = arena.getRegen();
try{
arena.setRegen(regen);
} catch (final IllegalArgumentException exception){
sender.sendMessage(failMessage(exception.getMessage()));
return;
}
sender.sendMessage(successMessage("The regen for arena " + arena.getName() + " has been changed from " + oldRegen + " HP to " + arena.getRegen() + " HP."));
this.snowbrawl.saveConfig();
}
/**
* Changes whether mobs can spawn inside an arena.
*
* @param sender The use who executed the command.
* @param name The name of the arena.
* @param mobSpawningAllowed Whether mobs are allowed to spawn or not.
*/
@Command(hook = "set_arena_mobspawningallowed")
public void commandArenasMobSpawningAllowed(CommandSender sender, String name, boolean mobSpawningAllowed){
Arena arena = this.snowbrawl.getArenaManager().getArenaByName(name);

View File

@@ -90,6 +90,7 @@ public final class Snowbrawl extends JavaPlugin {
newConfig.set("arenas." + id + ".graceTime", arena.getGraceTime());
newConfig.set("arenas." + id + ".matchTime", arena.getMatchTime());
newConfig.set("arenas." + id + ".damage", arena.getDamage());
newConfig.set("arenas." + id + ".regen", arena.getRegen());
newConfig.set("arenas." + id + ".mobspawningallowed", arena.isMobSpawningAllowed());
newConfig.set("arenas." + id + ".world", arena.getWorld().getName());
@@ -162,6 +163,7 @@ public final class Snowbrawl extends JavaPlugin {
arena.setGraceTime(config.getInt("arenas." + id + ".graceTime", Arena.DEFAULT_GRACE_TIME));
arena.setMatchTime(config.getInt("arenas." + id + ".matchTime", Arena.DEFAULT_MATCH_TIME));
arena.setDamage(config.getInt("arenas." + id + ".damage", Arena.DEFAULT_DAMAGE));
arena.setRegen(config.getInt("arenas." + id + ".regen", Arena.DEFAULT_REGEN));
arena.setMobSpawningAllowed(config.getBoolean("arenas." + id + ".mobspawningallowed", Arena.DEFAULT_MOB_SPAWNING_ALLOWED));
// The world can be null because Arena overrides it with the actual world. Only the coordinates matter.

View File

@@ -906,6 +906,7 @@ public class ArenaManager implements Listener {
logger.info(" - Grace Time: " + arena.getGraceTime() + "s");
logger.info(" - Match Time: " + arena.getMatchTime() + "s");
logger.info(" - Damage: " + arena.getDamage() + " HP");
logger.info(" - Regen: " + arena.getRegen() + " HP");
logger.info(" - Mob Spawning Allowed: " + arena.isMobSpawningAllowed());
logger.info(" - World: " + arena.getWorld().getName());

View File

@@ -26,6 +26,7 @@ public class Arena {
public static final int DEFAULT_GRACE_TIME = 15 * 20;
public static final int DEFAULT_MATCH_TIME = 300 * 20;
public static final int DEFAULT_DAMAGE = 4;
public static final int DEFAULT_REGEN = 4;
public static final boolean DEFAULT_MOB_SPAWNING_ALLOWED = false;
public static final double DEFAULT_POS1_X = 0, DEFAULT_POS1_Y = 0, DEFAULT_POS1_Z = 0;
public static final double DEFAULT_POS2_X = 0, DEFAULT_POS2_Y = 0, DEFAULT_POS2_Z = 0;
@@ -40,6 +41,7 @@ public class Arena {
private int playerLimit; // Maximum amount of players allowed in this arena in a match.
private int graceTime, matchTime;
private int damage; // Damage dealt to players per snowball hit.
private int regen; // Damage dealt to players per snowball hit.
private boolean allowMobSpawning;
private World world; // Which world the coordinates apply to.
private Location pos1, pos2; // Coordinates identifying the 2 corners of the arena.
@@ -225,6 +227,28 @@ public class Arena {
this.damage = damage;
}
/**
* Gets the amount of HP awarded to players per kill.
*
* @return The amount of HP awarded.
*/
public int getRegen(){
return this.regen;
}
/**
* Sets the amount of HP awards to players per kill.
*
* @param regen The amount of HP awarded.
*/
public void setRegen(final int regen){
if (regen < 0 || regen > 20){
throw new IllegalArgumentException("The regen must be between 0 and 20.");
}
this.regen = regen;
}
/**
* Gets whether mobs are allowed to naturally spawn in this arena.
*

View File

@@ -20,6 +20,8 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.ArrayList;
import java.util.Comparator;
@@ -335,6 +337,9 @@ public class Match {
MatchParticipant killer = this.getParticipant(victim.getPlayer().getKiller());
if (killer != null && killer != victim){
killer.awardKill();
if (this.getArena().getRegen() > 0){
killer.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, (int) (Math.round(this.getArena().getRegen() / 1.67 * 20)), 2)); // Award the killer with health regeneration over a period of time based on the arena's configured regen amount.
}
}
// Suppress global death message and only send to match participants.