mirror of
https://github.com/garbagemule/MobArena.git
synced 2024-11-27 13:07:16 +01:00
Attempt to fix auto-start-timer issues.
This commit is contained in:
parent
349172b3b6
commit
42d656863f
@ -1,7 +1,7 @@
|
|||||||
name: MobArena
|
name: MobArena
|
||||||
author: garbagemule
|
author: garbagemule
|
||||||
main: com.garbagemule.MobArena.MobArena
|
main: com.garbagemule.MobArena.MobArena
|
||||||
version: 0.95.5.32
|
version: 0.95.5.34
|
||||||
softdepend: [Multiverse-Core,Towny,Heroes,MagicSpells,Vault]
|
softdepend: [Multiverse-Core,Towny,Heroes,MagicSpells,Vault]
|
||||||
commands:
|
commands:
|
||||||
ma:
|
ma:
|
||||||
|
@ -637,11 +637,16 @@ public class ArenaImpl implements Arena
|
|||||||
refund(p);
|
refund(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArenaPlayer ap = arenaPlayerMap.get(p);
|
|
||||||
if (inLobby(p)) {
|
if (inLobby(p)) {
|
||||||
|
ArenaPlayer ap = arenaPlayerMap.get(p);
|
||||||
if (ap.getArenaClass() != null) {
|
if (ap.getArenaClass() != null) {
|
||||||
limitManager.playerLeftClass(ap.getArenaClass(), ap.getPlayer());
|
limitManager.playerLeftClass(ap.getArenaClass(), ap.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Last lobby player leaving? Stop the timer
|
||||||
|
if (lobbyPlayers.size() == 1) {
|
||||||
|
autoStartTimer.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
movePlayerToEntry(p);
|
movePlayerToEntry(p);
|
||||||
@ -1290,6 +1295,11 @@ public class ArenaImpl implements Arena
|
|||||||
return arenaPlayerMap.values();
|
return arenaPlayerMap.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AutoStartTimer getAutoStartTimer() {
|
||||||
|
return autoStartTimer;
|
||||||
|
}
|
||||||
|
|
||||||
/*@Override
|
/*@Override
|
||||||
public List<ArenaPlayerStatistics> getArenaPlayerStatistics(Comparator<ArenaPlayerStatistics> comparator)
|
public List<ArenaPlayerStatistics> getArenaPlayerStatistics(Comparator<ArenaPlayerStatistics> comparator)
|
||||||
{
|
{
|
||||||
|
@ -1,22 +1,25 @@
|
|||||||
package com.garbagemule.MobArena.autostart;
|
package com.garbagemule.MobArena.autostart;
|
||||||
|
|
||||||
|
import com.garbagemule.MobArena.MobArena;
|
||||||
import com.garbagemule.MobArena.Msg;
|
import com.garbagemule.MobArena.Msg;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.garbagemule.MobArena.Messenger;
|
import com.garbagemule.MobArena.Messenger;
|
||||||
import com.garbagemule.MobArena.framework.Arena;
|
import com.garbagemule.MobArena.framework.Arena;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
public class AutoStartTimer {
|
public class AutoStartTimer {
|
||||||
|
private MobArena plugin;
|
||||||
private Arena arena;
|
private Arena arena;
|
||||||
private int seconds;
|
private int seconds;
|
||||||
private Timer timer;
|
private Timer timer;
|
||||||
private boolean started;
|
|
||||||
private boolean useLevels;
|
private boolean useLevels;
|
||||||
|
|
||||||
public AutoStartTimer(Arena arena, int seconds) {
|
public AutoStartTimer(Arena arena, int seconds) {
|
||||||
|
this.plugin = arena.getPlugin();
|
||||||
this.arena = arena;
|
this.arena = arena;
|
||||||
this.seconds = seconds;
|
this.seconds = seconds;
|
||||||
this.started = false;
|
|
||||||
this.useLevels = arena.getSettings().getBoolean("display-timer-as-level", false);
|
this.useLevels = arena.getSettings().getBoolean("display-timer-as-level", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,19 +29,27 @@ public class AutoStartTimer {
|
|||||||
* started, nothing happens if the method is called again.
|
* started, nothing happens if the method is called again.
|
||||||
*/
|
*/
|
||||||
public void start() {
|
public void start() {
|
||||||
if (seconds > 5 && !started) {
|
if (seconds > 5 && timer == null) {
|
||||||
timer = new Timer(seconds);
|
timer = new Timer(seconds);
|
||||||
timer.start();
|
timer.runTaskTimer(plugin, 20, 20);
|
||||||
started = true;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops the timer.
|
||||||
|
*/
|
||||||
|
public void stop() {
|
||||||
|
if (timer != null) {
|
||||||
|
timer.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRunning() {
|
public boolean isRunning() {
|
||||||
return (timer != null && started);
|
return (timer != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRemaining() {
|
public int getRemaining() {
|
||||||
return (timer != null ? timer.getRemaining() : -1);
|
return (isRunning() ? timer.getRemaining() : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,7 +58,7 @@ public class AutoStartTimer {
|
|||||||
* timer, followed by the creation of a new. Thus, no timers should
|
* timer, followed by the creation of a new. Thus, no timers should
|
||||||
* ever interfere with each other.
|
* ever interfere with each other.
|
||||||
*/
|
*/
|
||||||
private class Timer implements Runnable {
|
private class Timer extends BukkitRunnable {
|
||||||
private int remaining;
|
private int remaining;
|
||||||
private int countdownIndex;
|
private int countdownIndex;
|
||||||
private int[] intervals = new int[]{1, 2, 3, 4, 5, 10, 30};
|
private int[] intervals = new int[]{1, 2, 3, 4, 5, 10, 30};
|
||||||
@ -65,39 +76,34 @@ public class AutoStartTimer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Start the timer
|
|
||||||
*/
|
|
||||||
public synchronized void start() {
|
|
||||||
arena.scheduleTask(this, 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the remaining number of seconds
|
* Get the remaining number of seconds
|
||||||
* @return number of seconds left
|
* @return number of seconds left
|
||||||
*/
|
*/
|
||||||
public synchronized int getRemaining() {
|
public int getRemaining() {
|
||||||
return remaining;
|
return remaining;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
cancel();
|
||||||
|
AutoStartTimer.this.timer = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
synchronized(this) {
|
|
||||||
// Abort if the arena is running, or if players have left
|
// Abort if the arena is running, or if players have left
|
||||||
if (arena.isRunning() || arena.getPlayersInLobby().isEmpty()) {
|
if (arena.isRunning() || arena.getPlayersInLobby().isEmpty()) {
|
||||||
started = false;
|
stop();
|
||||||
this.notifyAll();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Count down
|
// Count down and start if 0
|
||||||
remaining--;
|
if (--remaining <= 0) {
|
||||||
|
stop();
|
||||||
// Start if 0
|
|
||||||
if (remaining <= 0) {
|
|
||||||
arena.forceStart();
|
arena.forceStart();
|
||||||
started = false;
|
return;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
// If using levels, update 'em
|
// If using levels, update 'em
|
||||||
if (useLevels) {
|
if (useLevels) {
|
||||||
for (Player p : arena.getPlayersInLobby()) {
|
for (Player p : arena.getPlayersInLobby()) {
|
||||||
@ -106,15 +112,9 @@ public class AutoStartTimer {
|
|||||||
}
|
}
|
||||||
// Otherwise, warn at x seconds left
|
// Otherwise, warn at x seconds left
|
||||||
else if (remaining == intervals[countdownIndex]) {
|
else if (remaining == intervals[countdownIndex]) {
|
||||||
Messenger.announce(arena, Msg.ARENA_AUTO_START, ""+remaining);
|
Messenger.announce(arena, Msg.ARENA_AUTO_START, String.valueOf(remaining));
|
||||||
countdownIndex--;
|
countdownIndex--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reschedule
|
|
||||||
arena.scheduleTask(this, 20);
|
|
||||||
}
|
|
||||||
this.notifyAll();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.garbagemule.MobArena.framework;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import com.garbagemule.MobArena.autostart.AutoStartTimer;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -243,4 +244,6 @@ public interface Arena
|
|||||||
public boolean hasIsolatedChat();
|
public boolean hasIsolatedChat();
|
||||||
|
|
||||||
public Player getLastPlayerStanding();
|
public Player getLastPlayerStanding();
|
||||||
|
|
||||||
|
public AutoStartTimer getAutoStartTimer();
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ public class InventoryManager
|
|||||||
|
|
||||||
// And clear the inventory
|
// And clear the inventory
|
||||||
clearInventory(p);
|
clearInventory(p);
|
||||||
|
p.updateInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void restoreInv(Player p) throws FileNotFoundException, IOException, InvalidConfigurationException {
|
public void restoreInv(Player p) throws FileNotFoundException, IOException, InvalidConfigurationException {
|
||||||
|
Loading…
Reference in New Issue
Block a user