Added ability to disable mob spawning inside of arenas.
This commit is contained in:
@@ -404,6 +404,25 @@ public final class CommandHandler {
|
|||||||
this.snowbrawl.saveConfig();
|
this.snowbrawl.saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Command(hook = "set_arena_mobspawningallowed")
|
||||||
|
public void commandArenasMobSpawningAllowed(CommandSender sender, String name, boolean mobSpawningAllowed){
|
||||||
|
Arena arena = this.snowbrawl.getArenaManager().getArenaByName(name);
|
||||||
|
if (arena == null){
|
||||||
|
sender.sendMessage(failMessage("The specified arena does not exist."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
arena.setMobSpawningAllowed(mobSpawningAllowed);
|
||||||
|
|
||||||
|
if (mobSpawningAllowed){
|
||||||
|
sender.sendMessage(successMessage("Mob spawning is now allowed in arena " + arena.getName() + "."));
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(successMessage("Mob spawning is now blocked in arena " + arena.getName() + "."));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.snowbrawl.saveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets one corner of this arena's bounds to the given coordinates.
|
* Sets one corner of this arena's bounds to the given coordinates.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ public final class Snowbrawl extends JavaPlugin {
|
|||||||
newConfig.set("arenas." + id + ".graceTime", arena.getGraceTime());
|
newConfig.set("arenas." + id + ".graceTime", arena.getGraceTime());
|
||||||
newConfig.set("arenas." + id + ".matchTime", arena.getMatchTime());
|
newConfig.set("arenas." + id + ".matchTime", arena.getMatchTime());
|
||||||
newConfig.set("arenas." + id + ".damage", arena.getDamage());
|
newConfig.set("arenas." + id + ".damage", arena.getDamage());
|
||||||
|
newConfig.set("arenas." + id + ".mobspawningallowed", arena.isMobSpawningAllowed());
|
||||||
newConfig.set("arenas." + id + ".world", arena.getWorld().getName());
|
newConfig.set("arenas." + id + ".world", arena.getWorld().getName());
|
||||||
|
|
||||||
newConfig.set("arenas." + id + ".pos1.x", arena.getPos1().getX());
|
newConfig.set("arenas." + id + ".pos1.x", arena.getPos1().getX());
|
||||||
@@ -161,6 +162,7 @@ public final class Snowbrawl extends JavaPlugin {
|
|||||||
arena.setGraceTime(config.getInt("arenas." + id + ".graceTime", Arena.DEFAULT_GRACE_TIME));
|
arena.setGraceTime(config.getInt("arenas." + id + ".graceTime", Arena.DEFAULT_GRACE_TIME));
|
||||||
arena.setMatchTime(config.getInt("arenas." + id + ".matchTime", Arena.DEFAULT_MATCH_TIME));
|
arena.setMatchTime(config.getInt("arenas." + id + ".matchTime", Arena.DEFAULT_MATCH_TIME));
|
||||||
arena.setDamage(config.getInt("arenas." + id + ".damage", Arena.DEFAULT_DAMAGE));
|
arena.setDamage(config.getInt("arenas." + id + ".damage", Arena.DEFAULT_DAMAGE));
|
||||||
|
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.
|
// The world can be null because Arena overrides it with the actual world. Only the coordinates matter.
|
||||||
arena.setPos1(new Location(null, config.getDouble("arenas." + id + ".pos1.x", Arena.DEFAULT_POS1_X), config.getDouble("arenas." + id + ".pos1.y", Arena.DEFAULT_POS1_Y), config.getDouble("arenas." + id + ".pos1.z", Arena.DEFAULT_POS1_Z)));
|
arena.setPos1(new Location(null, config.getDouble("arenas." + id + ".pos1.x", Arena.DEFAULT_POS1_X), config.getDouble("arenas." + id + ".pos1.y", Arena.DEFAULT_POS1_Y), config.getDouble("arenas." + id + ".pos1.z", Arena.DEFAULT_POS1_Z)));
|
||||||
|
|||||||
@@ -575,13 +575,16 @@ public class ArenaManager implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Not implemented.
|
* Prevents entities from spawning inside of arenas with mob spawning set to disabled.
|
||||||
*
|
*
|
||||||
* @param event The event.
|
* @param event The event.
|
||||||
*/
|
*/
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onEntitySpawn(final EntitySpawnEvent event){
|
public void onEntitySpawn(final EntitySpawnEvent event){
|
||||||
// TODO: Add configurable option for preventing entity spawns in arenas.
|
final Arena arena = this.getArenaByLocation(event.getEntity().getLocation());
|
||||||
|
if (arena != null && !arena.isMobSpawningAllowed()){
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -902,6 +905,7 @@ public class ArenaManager implements Listener {
|
|||||||
logger.info(" - Grace Time: " + arena.getGraceTime() + "s");
|
logger.info(" - Grace Time: " + arena.getGraceTime() + "s");
|
||||||
logger.info(" - Match Time: " + arena.getMatchTime() + "s");
|
logger.info(" - Match Time: " + arena.getMatchTime() + "s");
|
||||||
logger.info(" - Damage: " + arena.getDamage() + " HP");
|
logger.info(" - Damage: " + arena.getDamage() + " HP");
|
||||||
|
logger.info(" - Mob Spawning Allowed: " + arena.isMobSpawningAllowed());
|
||||||
logger.info(" - World: " + arena.getWorld().getName());
|
logger.info(" - World: " + arena.getWorld().getName());
|
||||||
|
|
||||||
Location pos1 = arena.getPos1(), pos2 = arena.getPos2();
|
Location pos1 = arena.getPos1(), pos2 = arena.getPos2();
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ public class Arena {
|
|||||||
public static final int DEFAULT_GRACE_TIME = 15 * 20;
|
public static final int DEFAULT_GRACE_TIME = 15 * 20;
|
||||||
public static final int DEFAULT_MATCH_TIME = 300 * 20;
|
public static final int DEFAULT_MATCH_TIME = 300 * 20;
|
||||||
public static final int DEFAULT_DAMAGE = 4;
|
public static final int DEFAULT_DAMAGE = 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_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;
|
public static final double DEFAULT_POS2_X = 0, DEFAULT_POS2_Y = 0, DEFAULT_POS2_Z = 0;
|
||||||
|
|
||||||
@@ -39,6 +40,7 @@ public class Arena {
|
|||||||
private int playerLimit; // Maximum amount of players allowed in this arena in a match.
|
private int playerLimit; // Maximum amount of players allowed in this arena in a match.
|
||||||
private int graceTime, matchTime;
|
private int graceTime, matchTime;
|
||||||
private int damage; // Damage dealt to players per snowball hit.
|
private int damage; // Damage dealt to players per snowball hit.
|
||||||
|
private boolean allowMobSpawning;
|
||||||
private World world; // Which world the coordinates apply to.
|
private World world; // Which world the coordinates apply to.
|
||||||
private Location pos1, pos2; // Coordinates identifying the 2 corners of the arena.
|
private Location pos1, pos2; // Coordinates identifying the 2 corners of the arena.
|
||||||
|
|
||||||
@@ -60,6 +62,7 @@ public class Arena {
|
|||||||
public Arena(final String name, final World world){
|
public Arena(final String name, final World world){
|
||||||
this.setName(name);
|
this.setName(name);
|
||||||
|
|
||||||
|
this.setEnabled(DEFAULT_ENABLED);
|
||||||
this.setRefill(DEFAULT_REFILL);
|
this.setRefill(DEFAULT_REFILL);
|
||||||
this.setPlayerLimit(DEFAULT_PLAYER_LIMIT);
|
this.setPlayerLimit(DEFAULT_PLAYER_LIMIT);
|
||||||
this.setGraceTime(DEFAULT_GRACE_TIME);
|
this.setGraceTime(DEFAULT_GRACE_TIME);
|
||||||
@@ -222,6 +225,24 @@ public class Arena {
|
|||||||
this.damage = damage;
|
this.damage = damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether mobs are allowed to naturally spawn in this arena.
|
||||||
|
*
|
||||||
|
* @return True if mobs are allowed to spawn, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isMobSpawningAllowed(){
|
||||||
|
return this.allowMobSpawning;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether mobs are allowed to naturally spawn in this arena.
|
||||||
|
*
|
||||||
|
* @param allowMobSpawning
|
||||||
|
*/
|
||||||
|
public void setMobSpawningAllowed(final boolean allowMobSpawning){
|
||||||
|
this.allowMobSpawning = allowMobSpawning;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the position of one corner of the bounding box of this arena.
|
* Gets the position of one corner of the bounding box of this arena.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -96,6 +96,13 @@ command snowbrawl {
|
|||||||
help Changes the amount of damage done per snowball hit in this arena.;
|
help Changes the amount of damage done per snowball hit in this arena.;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
allowmobspawning [boolean:mobspawningallowed] {
|
||||||
|
perm redstoner.snowbrawl.arena.config.mobspawningallowed;
|
||||||
|
run set_arena_mobspawningallowed name mobspawningallowed;
|
||||||
|
type all;
|
||||||
|
help Sets whether mobs are allowed to spawn in this arena.;
|
||||||
|
}
|
||||||
|
|
||||||
bounds pos1 {
|
bounds pos1 {
|
||||||
[block_x:x] [block_y:y] [block_z:z] {
|
[block_x:x] [block_y:y] [block_z:z] {
|
||||||
run set_arena_pos1 name x y z;
|
run set_arena_pos1 name x y z;
|
||||||
|
|||||||
Reference in New Issue
Block a user