Rejoin Feature
* add settings.rejoin config option to enable rejoining the running game (default = false) * fix bossbar so it shows up for rejoined players * fix duplicate entries in scoreboard for rejoined players
This commit is contained in:
parent
da17cf1d9b
commit
40f0711a05
|
@ -88,7 +88,7 @@ public class ArenaImpl implements Arena
|
|||
private ConfigurationSection settings;
|
||||
|
||||
// Run-time settings and critical config settings
|
||||
private boolean enabled, protect, running, edit;
|
||||
private boolean enabled, protect, running, edit, rejoin;
|
||||
|
||||
// World stuff
|
||||
private boolean allowMonsters, allowAnimals;
|
||||
|
@ -166,6 +166,7 @@ public class ArenaImpl implements Arena
|
|||
|
||||
this.enabled = settings.getBoolean("enabled", false);
|
||||
this.protect = settings.getBoolean("protect", true);
|
||||
this.rejoin = settings.getBoolean("rejoin", false);
|
||||
this.running = false;
|
||||
this.edit = false;
|
||||
|
||||
|
@ -488,7 +489,7 @@ public class ArenaImpl implements Arena
|
|||
announce(msg.toString());
|
||||
}
|
||||
|
||||
private boolean justAddReadyPlayers() {
|
||||
private boolean addReadyPlayers() {
|
||||
for (Player p : readyPlayers) {
|
||||
lobbyPlayers.remove(p);
|
||||
arenaPlayers.add(p);
|
||||
|
@ -523,10 +524,15 @@ public class ArenaImpl implements Arena
|
|||
price.takeFrom(p);
|
||||
}
|
||||
|
||||
monsterManager.getBossMonsters().forEach(entity -> {
|
||||
MABoss boss = monsterManager.getBoss(entity);
|
||||
if (boss != null) {
|
||||
boss.getHealthBar().addPlayer(p);
|
||||
}
|
||||
});
|
||||
|
||||
scoreboard.removePlayer(p);
|
||||
scoreboard.addPlayer(p);
|
||||
|
||||
getMessenger().tell(p, "Maybe Rejoined?");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -535,8 +541,8 @@ public class ArenaImpl implements Arena
|
|||
@Override
|
||||
public boolean startArena() {
|
||||
// Sanity-checks
|
||||
if (running) {
|
||||
return justAddReadyPlayers();
|
||||
if (running && rejoin) {
|
||||
return addReadyPlayers();
|
||||
}
|
||||
|
||||
if (running || lobbyPlayers.isEmpty() || !readyPlayers.containsAll(lobbyPlayers)) {
|
||||
|
@ -1510,6 +1516,11 @@ public class ArenaImpl implements Arena
|
|||
return deadPlayers.contains(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRejoin() {
|
||||
return rejoin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String configName()
|
||||
{
|
||||
|
@ -1630,10 +1641,8 @@ public class ArenaImpl implements Arena
|
|||
messenger.tell(p, Msg.JOIN_ARENA_EDIT_MODE);
|
||||
else if (arenaPlayers.contains(p) || lobbyPlayers.contains(p))
|
||||
messenger.tell(p, Msg.JOIN_ALREADY_PLAYING);
|
||||
else if (running) {
|
||||
return true;
|
||||
//messenger.tell(p, Msg.JOIN_ARENA_IS_RUNNING);
|
||||
}
|
||||
else if (running && !rejoin)
|
||||
messenger.tell(p, Msg.JOIN_ARENA_IS_RUNNING);
|
||||
else if (!hasPermission(p))
|
||||
messenger.tell(p, Msg.JOIN_ARENA_PERMISSION);
|
||||
else if (getMaxPlayers() > 0 && lobbyPlayers.size() >= getMaxPlayers())
|
||||
|
|
|
@ -81,11 +81,6 @@ public class ScoreboardManager {
|
|||
return;
|
||||
}
|
||||
|
||||
String name = ChatColor.GRAY + player.getName();
|
||||
if (name.length() > 16) {
|
||||
name = name.substring(0, 15);
|
||||
}
|
||||
|
||||
Score score = kills.getScore(player.getName());
|
||||
if (score == null) {
|
||||
return;
|
||||
|
@ -94,18 +89,25 @@ public class ScoreboardManager {
|
|||
int value = score.getScore();
|
||||
scoreboard.resetScores(player.getName());
|
||||
|
||||
/* In case the player has no kills, they will not show up on the
|
||||
* scoreboard unless they are first given a different score.
|
||||
* If zero kills, the score is set to 8 (which looks a bit like
|
||||
* 0), and then in the next tick, it's set to 0. Otherwise, the
|
||||
* score is just set to its current value.
|
||||
*/
|
||||
final Score fake = kills.getScore(name);
|
||||
if (value == 0) {
|
||||
fake.setScore(8);
|
||||
arena.scheduleTask(() -> fake.setScore(0), 1);
|
||||
} else {
|
||||
fake.setScore(value);
|
||||
if (!arena.canRejoin()) {
|
||||
/* In case the player has no kills, they will not show up on the
|
||||
* scoreboard unless they are first given a different score.
|
||||
* If zero kills, the score is set to 8 (which looks a bit like
|
||||
* 0), and then in the next tick, it's set to 0. Otherwise, the
|
||||
* score is just set to its current value.
|
||||
*/
|
||||
String name = ChatColor.GRAY + player.getName();
|
||||
if (name.length() > 16) {
|
||||
name = name.substring(0, 15);
|
||||
}
|
||||
|
||||
final Score fake = kills.getScore(name);
|
||||
if (value == 0) {
|
||||
fake.setScore(8);
|
||||
arena.scheduleTask(() -> fake.setScore(0), 1);
|
||||
} else {
|
||||
fake.setScore(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -219,6 +219,8 @@ public interface Arena
|
|||
|
||||
boolean isDead(Player p);
|
||||
|
||||
boolean canRejoin();
|
||||
|
||||
String configName();
|
||||
|
||||
/**
|
||||
|
|
|
@ -48,3 +48,4 @@ announcer-type: title
|
|||
global-join-announce: false
|
||||
global-end-announce: false
|
||||
show-death-messages: true
|
||||
rejoin: false
|
||||
|
|
Loading…
Reference in New Issue