fix idle manager to persist teleports and make xp rewards depending on playtime
This commit is contained in:
parent
ba319599ba
commit
f6b60ad956
@ -37,6 +37,7 @@ import org.bukkit.event.hanging.HangingBreakEvent;
|
||||
import org.bukkit.event.hanging.HangingPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
import org.bukkit.scoreboard.NameTagVisibility;
|
||||
@ -149,6 +150,7 @@ public abstract class Game implements Listener
|
||||
// Player Data
|
||||
private NautHashMap<Player, HashMap<String, GemData>> _gemCount = new NautHashMap<Player, HashMap<String, GemData>>();
|
||||
private NautHashMap<Player, HashMap<String, Integer>> _stats = new NautHashMap<Player, HashMap<String, Integer>>();
|
||||
private NautHashMap<Player, Long> _playerInTime = new NautHashMap<>();
|
||||
|
||||
// Player Location Store
|
||||
private NautHashMap<String, Location> _playerLocationStore = new NautHashMap<String, Location>();
|
||||
@ -2117,6 +2119,31 @@ public abstract class Game implements Listener
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event)
|
||||
{
|
||||
if (!IsLive())
|
||||
return;
|
||||
|
||||
if (!JoinInProgress)
|
||||
return;
|
||||
|
||||
_playerInTime.put(event.getPlayer(), System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public long getPlayerIngameTime(Player player)
|
||||
{
|
||||
if (_playerInTime.containsKey(player))
|
||||
return _playerInTime.get(player);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void addPlayerInTime(Player player)
|
||||
{
|
||||
_playerInTime.put(player, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
private void addRelativeSpawns(ArrayList<Location> spawns, Location location)
|
||||
{
|
||||
//Gather Extra Spawns
|
||||
|
@ -757,6 +757,8 @@ public class GameManager implements Listener
|
||||
//Teleport
|
||||
team.SpawnTeleport(player);
|
||||
|
||||
game.addPlayerInTime(player);
|
||||
|
||||
Manager.Clear(player);
|
||||
UtilInv.Clear(player);
|
||||
|
||||
@ -820,7 +822,7 @@ public class GameManager implements Listener
|
||||
|
||||
player.eject();
|
||||
player.leaveVehicle();
|
||||
player.teleport(Manager.GetLobby().GetSpawn());
|
||||
player.teleport(Manager.GetLobby().GetSpawn());
|
||||
}
|
||||
}, i);
|
||||
}
|
||||
|
@ -1,8 +1,18 @@
|
||||
package nautilus.game.arcade.managers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
@ -13,20 +23,13 @@ import mineplex.core.updater.event.UpdateEvent;
|
||||
import nautilus.game.arcade.ArcadeManager;
|
||||
import nautilus.game.arcade.game.Game.GameState;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class IdleManager implements Listener
|
||||
{
|
||||
private final ArcadeManager _arcadeManager;
|
||||
private final Map<Player, Float> _yaw = new HashMap<>();
|
||||
private final Map<Player, Long> _idle = new HashMap<>();
|
||||
private final Map<Player, Integer> _beep = new HashMap<>();
|
||||
private final HashSet<Player> _teleported = new HashSet();
|
||||
|
||||
public IdleManager(ArcadeManager manager)
|
||||
{
|
||||
@ -65,6 +68,9 @@ public class IdleManager implements Listener
|
||||
|
||||
for (Player player : UtilServer.getPlayers())
|
||||
{
|
||||
if (_teleported.contains(player))
|
||||
continue;
|
||||
|
||||
if (!_yaw.containsKey(player) || !_idle.containsKey(player))
|
||||
{
|
||||
_yaw.put(player, player.getLocation().getYaw());
|
||||
@ -121,12 +127,28 @@ public class IdleManager implements Listener
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerTeleport(PlayerTeleportEvent event)
|
||||
{
|
||||
_teleported.add(event.getPlayer());
|
||||
_arcadeManager.runSyncLater(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
_yaw.put(event.getPlayer(), event.getPlayer().getLocation().getYaw());
|
||||
_teleported.remove(event.getPlayer());
|
||||
}
|
||||
}, 5);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
_yaw.remove(event.getPlayer());
|
||||
_idle.remove(event.getPlayer());
|
||||
_beep.remove(event.getPlayer());
|
||||
_teleported.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
public ArcadeManager getArcadeManager()
|
||||
|
@ -68,6 +68,10 @@ public class ExperienceStatTracker extends StatTracker<Game>
|
||||
|
||||
//Game Time = 1 Exp per 3 Seconds
|
||||
long time = System.currentTimeMillis();
|
||||
long playerJoin = getGame().getPlayerIngameTime(player);
|
||||
|
||||
if (playerJoin == 0)
|
||||
playerJoin = _startTime;
|
||||
|
||||
//Exp Until They Quit
|
||||
if (!player.isOnline())
|
||||
@ -80,9 +84,9 @@ public class ExperienceStatTracker extends StatTracker<Game>
|
||||
{
|
||||
time = _startTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double timeExp = (time - _startTime)/1500d;
|
||||
double timeExp = (time - playerJoin)/1500d;
|
||||
|
||||
//Mult
|
||||
double mult = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user