Skip to content

Commit

Permalink
location in config speichern
Browse files Browse the repository at this point in the history
language API nutzen
removed debug
  • Loading branch information
realMorgon committed Feb 9, 2025
1 parent e9caaba commit b3854a1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 62 deletions.
29 changes: 14 additions & 15 deletions src/main/java/dev/nachwahl/lobby/commands/BOTMCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import co.aikar.idb.Database;
import co.aikar.idb.DbRow;
import dev.nachwahl.lobby.Lobby;
import dev.nachwahl.lobby.utils.BOTMScoreAPI;
import dev.nachwahl.lobby.language.Language;
import eu.decentsoftware.holograms.api.DHAPI;
import org.bukkit.ChatColor;
import org.bukkit.Location;
Expand Down Expand Up @@ -33,22 +33,22 @@ public BOTMCommand(Lobby lobby) {
public void onBOTMCreate(CommandSender sender) throws SQLException {
Player player = (Player) sender;

player.sendMessage(create(player.getLocation(), this.lobby.getDatabase()));
player.sendMessage(create(player.getLocation(), this.lobby.getDatabase(), this.lobby.getLanguageAPI().getLanguage(player)));
}

@CommandPermission("bteg.lobby.botm")
@Subcommand("move")
public void onBOTMMove(CommandSender sender) throws SQLException {
DHAPI.moveHologram("BOTM", ((Player)sender).getLocation());
this.lobby.getBotmScoreAPI().saveLocation(((Player)sender).getLocation());
sender.sendMessage(ChatColor.GREEN + "[BTE] Hologramm wurde verschoben!");
this.lobby.getLocationAPI().setLocation(((Player) sender).getLocation(), "botm");
this.lobby.getLanguageAPI().sendMessageToPlayer((Player) sender, "botm.moved");
}

@CommandPermission("bteg.lobby.botm")
@Subcommand("remove")
public void onBOTMRemove(CommandSender sender) {
DHAPI.removeHologram("BOTM");
sender.sendMessage(ChatColor.GREEN + "[BTE] Hologramm wurde entfernt!");
this.lobby.getLanguageAPI().sendMessageToPlayer((Player) sender, "botm.removed");
}

@CommandPermission("bteg.lobby.botm")
Expand All @@ -59,13 +59,12 @@ public void onBOTMAdd(CommandSender sender, String target) throws SQLException {
Player player = (Player) sender;

this.lobby.getBotmScoreAPI().addPoints(target);
update(true);

player.sendMessage(ChatColor.GREEN + "[BTE] Punkte wurden hinzugefügt!");
update(player);

this.lobby.getLanguageAPI().sendMessageToPlayer(player, "botm.added");
}

public static String create(Location location, Database database) throws SQLException {
public static String create(Location location, Database database, Language language) throws SQLException {

HashMap<String, Integer> scores = new HashMap<>();
List<DbRow> dbRows = database.getResults("SELECT * FROM botm");
Expand All @@ -77,7 +76,7 @@ public static String create(Location location, Database database) throws SQLExce
});

// Create a hologram
if (scores.size() > 3) {
if (scores.size() >= 3) {

ArrayList<String> keys = new ArrayList<>(scores.keySet());

Expand All @@ -99,22 +98,22 @@ public static String create(Location location, Database database) throws SQLExce
for (int i = 0; i < entries; i++) lines.add(ChatColor.GRAY + relevantEntries[i].getValue() + ": " + ChatColor.GREEN + relevantEntries[i].getKey());

DHAPI.createHologram("BOTM", location, lines);
lobby.getBotmScoreAPI().saveLocation(location);
lobby.getLocationAPI().setLocation(location, "botm");

return ChatColor.GREEN + "[BTE] Hologramm wurde erfolgreich erstellt!";
return lobby.getLanguageAPI().getMessageString(language, "botm.create.success");
} else {
// Send feedback
return ChatColor.YELLOW + "[BTE] Es existieren nicht genügend Einträge um ein Hologramm zu erstellen!";
return lobby.getLanguageAPI().getMessageString(language, "botm.create.failed");

}
}

public void update(boolean sendFeedback) throws SQLException {
public void update(Player player) throws SQLException {
if (DHAPI.getHologram("BOTM") != null) {
Location location = DHAPI.getHologram("BOTM").getLocation();

DHAPI.removeHologram("BOTM");
create(location, this.lobby.getDatabase());
create(location, this.lobby.getDatabase(), this.lobby.getLanguageAPI().getLanguage(player));
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/dev/nachwahl/lobby/events/PlayerEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.nachwahl.lobby.Lobby;
import dev.nachwahl.lobby.commands.BOTMCommand;
import dev.nachwahl.lobby.guis.PrivacyGUI;
import dev.nachwahl.lobby.language.Language;
import dev.nachwahl.lobby.utils.Actions;
import dev.triumphteam.gui.builder.item.ItemBuilder;
import eu.decentsoftware.holograms.api.DHAPI;
Expand Down Expand Up @@ -69,12 +70,11 @@ public void onJoin(PlayerJoinEvent event) {
this.lobby.getScoreboard().initScoreboard(player);
}

if (DHAPI.getHologram("BOTM") == null && this.lobby.getBotmScoreAPI().getLocation() != null) {
if (DHAPI.getHologram("BOTM") == null && this.lobby.getLocationAPI().getLocation("botm") != null) {
try {
Location location = this.lobby.getBotmScoreAPI().getLocation();
Location location = this.lobby.getLocationAPI().getLocation("botm");
if (location != null) {
Bukkit.getLogger().info(BOTMCommand.create(location, this.lobby.getDatabase()));
Bukkit.getLogger().info(DHAPI.getHologram("BOTM").getLocation().toString());
Bukkit.getLogger().info(BOTMCommand.create(location, this.lobby.getDatabase(), Language.GERMAN));
}
} catch (SQLException e) {
Bukkit.getLogger().warning("Es wurde keine Location für das BOTM Hologramm gefunden.");
Expand Down
41 changes: 0 additions & 41 deletions src/main/java/dev/nachwahl/lobby/utils/BOTMScoreAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,45 +59,4 @@ public void addPoints(String name) throws SQLException {
}
});
}

public void saveLocation(Location location) throws SQLException {
this.lobby.getDatabase().executeUpdate("INSERT INTO botmLocation (axis, location) VALUES (?, ?) ON DUPLICATE KEY UPDATE location = VALUES (location)", "world", location.getWorld().getName());
this.lobby.getDatabase().executeUpdate("INSERT INTO botmLocation (axis, location) VALUES (?, ?) ON DUPLICATE KEY UPDATE location = VALUES (location)", "x", location.getX());
this.lobby.getDatabase().executeUpdate("INSERT INTO botmLocation (axis, location) VALUES (?, ?) ON DUPLICATE KEY UPDATE location = VALUES (location)", "y", location.getY());
this.lobby.getDatabase().executeUpdate("INSERT INTO botmLocation (axis, location) VALUES (?, ?) ON DUPLICATE KEY UPDATE location = VALUES (location)", "z", location.getZ());
}

public Location getLocation() throws SQLException {
List<DbRow> dbRows = this.lobby.getDatabase().getResults("SELECT * FROM botmLocation");
if (dbRows.isEmpty()) {
return null;
}
String world = "";
double x = 0;
double y = 0;
double z = 0;
for (DbRow dbRow : dbRows) {
switch (dbRow.getString("axis")) {
case "world":
world = dbRow.getString("location");
break;
case "x":
x = Double.parseDouble(dbRow.getString("location"));
break;
case "y":
y = Double.parseDouble(dbRow.getString("location"));
break;
case "z":
z = Double.parseDouble(dbRow.getString("location"));
break;
}
}
return new Location(Bukkit.getWorld(world), x, y, z);
}


public void clearLocation() {
this.lobby.getDatabase().executeUpdateAsync("DELETE FROM botmLocation");
}

}
8 changes: 7 additions & 1 deletion src/main/resources/lang_de_DE.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ map.tpll.description=Nutze diesen Befehl um mithilfe von Koordinaten zu einem ex
map.tpll.message=<prefix> <aqua>Schaue dir das Tutorial hier an: <red><b>youtube.com</b></red>.</aqua>
tutorials.title=<dark_gray>✕</dark_gray> <b><color:#479dff>Tutorials</color></b> <dark_gray>✕</dark_gray>

scoreboard.playtime=<gray>Spielzeit</gray>
scoreboard.playtime=<gray>Spielzeit</gray>

botm.added=<green>[BOTM] Punkte wurden hinzugefügt.</green>
botm.removed=<red>[BOTM] Hologramm wurde entfernt.</red>
botm.moved=<green>[BOTM] Hologramm wurde verschoben.</green>
botm.create.success=<green>[BOTM] Hologramm wurde erstellt.</green>
botm.create.failed=<red>[BOTM] Hologramm konnte nicht erstellt werden. Sind genug Ergebnisse eingetragen?</red>
8 changes: 7 additions & 1 deletion src/main/resources/lang_en_EN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ map.tpll.description=Use this command to get to an exact location using coordina
map.tpll.message=<prefix> <aqua>Check out the tutorial here: <red><b>youtube.com</b></red>.</aqua>
tutorials.title=<dark_gray>✕</dark_gray> <b><color:#479dff>Tutorials</color></b> <dark_gray>✕</dark_gray>

scoreboard.playtime=<gray>Playtime</gray>
scoreboard.playtime=<gray>Playtime</gray>

botm.added=<green>[BOTM] Points have been added.</green>
botm.removed=<red>[BOTM] Hologram has been removed.</red>
botm.moved=<green>[BOTM] Hologram has been moved.</green>
botm.create.success=<green>[BOTM] Hologram has been created.</green>
botm.create.failed=<red>[BOTM] Could not create hologram. Perhaps there are not enough entries.</red>

0 comments on commit b3854a1

Please sign in to comment.