Skip to content

Commit

Permalink
📍[main/LocationManager] Location Manager implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepymalc committed Aug 15, 2021
1 parent f85a52d commit a276176
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 25 deletions.
14 changes: 1 addition & 13 deletions src/main/java/com/linyuanlin/minecraft/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import org.bson.Document;
import org.bukkit.*;

public class App extends JavaPlugin implements Listener {

public HashMap<UUID, PlayerData> allPlayers = new HashMap<>();
Expand Down Expand Up @@ -152,16 +149,7 @@ public void onJoin(PlayerJoinEvent e) {
World lobbyWorld = Bukkit.getWorld("world_lobby");
discordBotManager.sendMessage("TEST", "Project-Minecraft", msg);
if (lobbyWorld != null) {

Document doc = dbClient.findOne("Location", "tag", "lobby_spawn");
p.teleport(new Location(worldManager.getWorldData(WorldManager.world_lobby).world, doc.getInteger("x"),
doc.getInteger("y"), doc.getInteger("z")));
if (locationManager.getLocation("lobby_spawn") == null) {
p.teleport(lobbyWorld.getSpawnLocation());
p.sendMessage("null");
} else {
p.teleport(locationManager.getLocation("lobby_spawn"));
}
p.teleport(lobbyWorld.getSpawnLocation());
}
pd.sendWorldTitle(p.getWorld().getName());
} catch (Exception exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,20 @@
import java.util.*;
import org.bson.Document;
import org.bukkit.*;
import com.mongodb.client.model.Filters;

public class LocationManager {
private App app;
private HashMap<String, Location> tagLocationMap;
private HashMap<String, Location> tagLocationMap = new HashMap<>();

public LocationManager(App app) {
this.app = app;
}

public void loadLocations() {
Document newDocument = new Document();
newDocument.append("tag", "lobby_spawn");
newDocument.append("x", 0.5);
newDocument.append("y", 67);
newDocument.append("z", 0.5);

app.dbClient.replaceOne("Location", Filters.eq("tag", "lobby_spawn"), newDocument);

this.tagLocationMap = new HashMap<>();
Document doc = app.dbClient.findOne("Location", "tag", "lobby_spawn");
tagLocationMap.put("lobby_spawn",
new Location(this.app.worldManager.getWorldData(WorldManager.world_lobby).world,
doc.getInteger("x"), doc.getInteger("y"), doc.getInteger("z")));
doc.getDouble("x"), doc.getDouble("y"), doc.getDouble("z")));
}

public Location getLocation(String tag) {
Expand Down

0 comments on commit a276176

Please sign in to comment.