mirror of
https://github.com/garbagemule/MobArena.git
synced 2024-11-29 06:05:15 +01:00
Clean up PvP activation logic.
The idea behind the previous implementation worked, but it was a tad bit confusing. This commit refactors the activation logic by simply removing it entirely. The "activation" part of the logic is now derived from the wave number (if 0, it means we haven't _really_ started yet), instead of relying on the spawn thread to toggle the flag on and off. This kind of dependency inversion (spawn thread -> listener, listener -> "phase") is a pretty decent (albeit super tiny) step towards cleaning up the whole session system, so I call that a victory in and of itself!
This commit is contained in:
parent
a662157cbf
commit
457bf2ffff
@ -116,7 +116,6 @@ public class ArenaListener
|
|||||||
private boolean protect;
|
private boolean protect;
|
||||||
private boolean monsterExp;
|
private boolean monsterExp;
|
||||||
private boolean monsterInfight;
|
private boolean monsterInfight;
|
||||||
private boolean pvpOn;
|
|
||||||
private boolean pvpEnabled;
|
private boolean pvpEnabled;
|
||||||
private boolean foodRegen;
|
private boolean foodRegen;
|
||||||
private boolean lockFoodLevel;
|
private boolean lockFoodLevel;
|
||||||
@ -142,7 +141,7 @@ public class ArenaListener
|
|||||||
this.protect = s.getBoolean("protect", true);
|
this.protect = s.getBoolean("protect", true);
|
||||||
this.monsterExp = s.getBoolean("monster-exp", false);
|
this.monsterExp = s.getBoolean("monster-exp", false);
|
||||||
this.monsterInfight = s.getBoolean("monster-infight", false);
|
this.monsterInfight = s.getBoolean("monster-infight", false);
|
||||||
this.pvpOn = s.getBoolean("pvp-enabled", false);
|
this.pvpEnabled = s.getBoolean("pvp-enabled", false);
|
||||||
this.foodRegen = s.getBoolean("food-regen", false);
|
this.foodRegen = s.getBoolean("food-regen", false);
|
||||||
this.lockFoodLevel = s.getBoolean("lock-food-level", true);
|
this.lockFoodLevel = s.getBoolean("lock-food-level", true);
|
||||||
this.allowTeleport = s.getBoolean("allow-teleporting", false);
|
this.allowTeleport = s.getBoolean("allow-teleporting", false);
|
||||||
@ -161,16 +160,6 @@ public class ArenaListener
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pvpActivate() {
|
|
||||||
if (arena.isRunning() && !arena.getPlayersInArena().isEmpty()) {
|
|
||||||
pvpEnabled = pvpOn;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void pvpDeactivate() {
|
|
||||||
if (pvpOn) pvpEnabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
// Check if the block is a sign, it might be a leaderboard
|
// Check if the block is a sign, it might be a leaderboard
|
||||||
if (event.getBlock() instanceof Sign) {
|
if (event.getBlock() instanceof Sign) {
|
||||||
@ -722,11 +711,15 @@ public class ArenaListener
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cancel PvP damage if disabled
|
// If this is player damage (and not self-inflicted), handle PvP
|
||||||
if (!pvpEnabled && damager instanceof Player && !damager.equals(player)) {
|
if (damager instanceof Player && !damager.equals(player)) {
|
||||||
|
// PvP must be enabled, and the first wave must have spawned
|
||||||
|
if (!pvpEnabled || arena.getWaveManager().getWaveNumber() == 0) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
event.setCancelled(false);
|
event.setCancelled(false);
|
||||||
arena.getArenaPlayer(player).getStats().add("dmgTaken", event.getDamage());
|
arena.getArenaPlayer(player).getStats().add("dmgTaken", event.getDamage());
|
||||||
|
|
||||||
@ -802,7 +795,7 @@ public class ArenaListener
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pvpEnabled) {
|
if (!pvpEnabled || arena.getWaveManager().getWaveNumber() == 0) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -913,7 +906,7 @@ public class ArenaListener
|
|||||||
|
|
||||||
if (potion.getShooter() instanceof Player) {
|
if (potion.getShooter() instanceof Player) {
|
||||||
// Check for PvP stuff if the shooter is a player
|
// Check for PvP stuff if the shooter is a player
|
||||||
if (!pvpEnabled) {
|
if (!pvpEnabled || arena.getWaveManager().getWaveNumber() == 0) {
|
||||||
// If a potion has harmful effects, remove all players.
|
// If a potion has harmful effects, remove all players.
|
||||||
for (PotionEffect effect : potion.getEffects()) {
|
for (PotionEffect effect : potion.getEffects()) {
|
||||||
PotionEffectType type = effect.getType();
|
PotionEffectType type = effect.getType();
|
||||||
|
@ -91,10 +91,7 @@ public class MASpawnThread implements Runnable
|
|||||||
}
|
}
|
||||||
|
|
||||||
int delay = arena.getSettings().getInt("first-wave-delay", 5) * 20;
|
int delay = arena.getSettings().getInt("first-wave-delay", 5) * 20;
|
||||||
task = Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
task = Bukkit.getScheduler().runTaskLater(plugin, this, delay);
|
||||||
arena.getEventListener().pvpActivate();
|
|
||||||
this.run();
|
|
||||||
}, delay);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
@ -103,8 +100,6 @@ public class MASpawnThread implements Runnable
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
arena.getEventListener().pvpDeactivate();
|
|
||||||
|
|
||||||
task.cancel();
|
task.cancel();
|
||||||
task = null;
|
task = null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user