-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Massive improvements on loading player models
- Loading branch information
1 parent
0f360bd
commit 200e8e3
Showing
6 changed files
with
102 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 85 additions & 6 deletions
91
src/main/java/cc/ddev/feather/api/playerdata/PlayerManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,110 @@ | ||
package cc.ddev.feather.api.playerdata; | ||
|
||
import cc.ddev.feather.api.API; | ||
import cc.ddev.feather.api.config.Config; | ||
import cc.ddev.feather.api.economy.EconomyManager; | ||
import cc.ddev.feather.database.StormDatabase; | ||
import cc.ddev.feather.database.models.PlayerModel; | ||
import cc.ddev.feather.logger.Log; | ||
import cc.ddev.feather.player.PlayerProfile; | ||
import cc.ddev.feather.player.PlayerWrapper; | ||
import net.minestom.server.MinecraftServer; | ||
import net.minestom.server.coordinate.Point; | ||
import net.minestom.server.coordinate.Pos; | ||
import net.minestom.server.entity.Player; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class PlayerManager { | ||
|
||
public static Map<UUID, Point> plotWandPos1Map = new HashMap<>(); | ||
public static Map<UUID, Point> plotWandPos2Map = new HashMap<>(); | ||
private static PlayerManager instance; | ||
|
||
public static void setPlotWandPos1(UUID uuid, Point point) { | ||
public static PlayerManager getInstance() { | ||
if (instance == null) { | ||
instance = new PlayerManager(); | ||
} | ||
return instance; | ||
} | ||
|
||
public Map<UUID, Point> plotWandPos1Map = new HashMap<>(); | ||
public Map<UUID, Point> plotWandPos2Map = new HashMap<>(); | ||
|
||
public void setPlotWandPos1(UUID uuid, Point point) { | ||
plotWandPos1Map.remove(uuid); | ||
plotWandPos1Map.put(uuid, point); | ||
} | ||
|
||
public static void setPlotWandPos2(UUID uuid, Point point) { | ||
public void setPlotWandPos2(UUID uuid, Point point) { | ||
plotWandPos2Map.remove(uuid); | ||
plotWandPos2Map.put(uuid, point); | ||
} | ||
|
||
public static Point getPlotWandPos1(UUID uuid) { | ||
public Point getPlotWandPos1(UUID uuid) { | ||
return plotWandPos1Map.get(uuid); | ||
} | ||
|
||
public static Point getPlotWandPos2(UUID uuid) { | ||
public Point getPlotWandPos2(UUID uuid) { | ||
return plotWandPos2Map.get(uuid); | ||
} | ||
|
||
public PlayerProfile getPlayerProfile(Player player) { | ||
PlayerProfile playerProfile = PlayerWrapper.getPlayerProfile(player); | ||
if (playerProfile == null) { | ||
player.kick("Failed to load player profile!"); | ||
return null; | ||
} | ||
return playerProfile; | ||
} | ||
|
||
public PlayerModel getPlayerModel(Player player) { | ||
CompletableFuture<PlayerModel> future = StormDatabase.getInstance().loadPlayerModel(player.getUuid()); | ||
PlayerModel playerModel; | ||
|
||
try { | ||
// Prevent not loading the player model in time | ||
future.get(); | ||
|
||
// Load player profile | ||
PlayerProfile playerProfile = getPlayerProfile(player); | ||
|
||
// Load player model | ||
playerModel = playerProfile.getPlayerModel(); | ||
if (playerModel == null) { | ||
player.kick("Failed to load player model!"); | ||
return null; | ||
} | ||
} catch (Exception e) { | ||
Log.getLogger().info("Failed to load player profile and model for " + player.getUsername() + "!"); | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
return playerModel; | ||
} | ||
|
||
public Pos getLastLocation(Player player) { | ||
if (player == null) { | ||
return null; | ||
} | ||
PlayerModel playerModel = getPlayerModel(player); | ||
if (playerModel == null) { | ||
return null; | ||
} | ||
// Set the spawn position | ||
if (playerModel.getLastLocation() != null) { | ||
// Extract X, Y and Z from the position string | ||
String[] rawPosition = playerModel.getLastLocation().split(","); | ||
double x = Double.parseDouble(rawPosition[0].replace("Pos[x=", "")); | ||
double y = Double.parseDouble(rawPosition[1].replace("y=", "")); | ||
double z = Double.parseDouble(rawPosition[2].replace("z=", "")); | ||
float yaw = Float.parseFloat(rawPosition[3].replace("yaw=", "")); | ||
float pitch = Float.parseFloat(rawPosition[4].replace("pitch=", "").replace("]", "")); | ||
Pos pos = new Pos(x, y, z, yaw, pitch); | ||
|
||
return pos; | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters