Skip to content

Commit c33949f

Browse files
committed
Added Spawn Location saving in API not longer hard coded
1 parent f26869f commit c33949f

File tree

9 files changed

+162
-115
lines changed

9 files changed

+162
-115
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package dev.lars.utilsmanager.commands.teleport.spawn;
2+
3+
import dev.lars.apimanager.apis.languageAPI.LanguageAPI;
4+
import dev.lars.apimanager.apis.serverSettingsAPI.ServerSettingsAPI;
5+
import dev.lars.utilsmanager.utils.Statements;
6+
import io.papermc.paper.command.brigadier.BasicCommand;
7+
import io.papermc.paper.command.brigadier.CommandSourceStack;
8+
import net.kyori.adventure.text.Component;
9+
import net.kyori.adventure.text.format.NamedTextColor;
10+
import org.bukkit.Location;
11+
import org.bukkit.entity.Player;
12+
import org.jetbrains.annotations.NotNull;
13+
14+
public class SetSpawnCommand implements BasicCommand {
15+
16+
@Override
17+
public void execute(@NotNull CommandSourceStack stack, @NotNull String @NotNull [] args) {
18+
if (!(stack.getExecutor() instanceof Player player)) {
19+
stack.getSender().sendMessage(Statements.getOnlyPlayers());
20+
return;
21+
}
22+
23+
if (!(player.hasPermission("utilsmanager.feature.spawn.setspawn"))) {
24+
player.sendMessage(Statements.getNotAllowed(player));
25+
return;
26+
}
27+
28+
Location loc = player.getLocation();
29+
ServerSettingsAPI.getApi().setSpawnLocation(loc);
30+
if (LanguageAPI.getApi().getLanguage(player) == 2) {
31+
player.sendMessage(Statements.getPrefix().append(Component.text("Der Spawn wurde erfolgreich gesetzt.", NamedTextColor.GREEN)));
32+
} else {
33+
player.sendMessage(Statements.getPrefix().append(Component.text("Spawn was successfully set!", NamedTextColor.GREEN)));
34+
}
35+
}
36+
}

src/main/java/dev/lars/utilsmanager/commands/teleport/SpawnCommand.java renamed to src/main/java/dev/lars/utilsmanager/commands/teleport/spawn/SpawnCommand.java

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package dev.lars.utilsmanager.commands.teleport;
1+
package dev.lars.utilsmanager.commands.teleport.spawn;
22

33
import dev.lars.apimanager.apis.courtAPI.CourtAPI;
44
import dev.lars.apimanager.apis.languageAPI.LanguageAPI;
5+
import dev.lars.apimanager.apis.serverSettingsAPI.ServerSettingsAPI;
56
import dev.lars.utilsmanager.utils.Statements;
67
import io.papermc.paper.command.brigadier.BasicCommand;
78
import io.papermc.paper.command.brigadier.CommandSourceStack;
@@ -22,15 +23,25 @@ public void execute(@NotNull CommandSourceStack stack, @NotNull String[] args) {
2223
return;
2324
}
2425

25-
if (!(player.hasPermission("utilsmanager.spawn"))) {
26+
if (!(player.hasPermission("utilsmanager.feature.spawn"))) {
2627
player.sendMessage(Statements.getNotAllowed(player));
2728
return;
2829
}
2930
if (CourtAPI.getApi().getStatus(player) == 5) {
3031
player.sendMessage(Statements.getNotAllowed(player));
3132
return;
3233
}
33-
Location loc = new Location(Bukkit.getWorld("world"), -205.5, 78.0, -102.5, -90, 0);
34+
35+
Location loc = ServerSettingsAPI.getApi().getSpawnLocation();
36+
if (loc == null) {
37+
if (LanguageAPI.getApi().getLanguage(player) == 2) {
38+
player.sendMessage(Statements.getPrefix().append(Component.text("Es konnte keine Spawn-Location gefunden werden!", NamedTextColor.RED)));
39+
} else {
40+
player.sendMessage(Statements.getPrefix().append(Component.text("No Spawn-Location could be found!", NamedTextColor.RED)));
41+
}
42+
return;
43+
}
44+
3445
player.teleport(loc);
3546
if (LanguageAPI.getApi().getLanguage(player) == 2) {
3647
player.sendMessage(Statements.getPrefix().append(Component.text("Du wurdest zum Spawn teleportiert.", NamedTextColor.GREEN)));
@@ -39,23 +50,4 @@ public void execute(@NotNull CommandSourceStack stack, @NotNull String[] args) {
3950
}
4051
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 100, 1);
4152
}
42-
}
43-
44-
45-
46-
47-
48-
49-
50-
51-
52-
53-
54-
55-
56-
57-
58-
59-
60-
61-
53+
}

src/main/java/dev/lars/utilsmanager/commands/teleport/ToggleBedCommand.java renamed to src/main/java/dev/lars/utilsmanager/commands/teleport/spawn/ToggleBedCommand.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package dev.lars.utilsmanager.commands.teleport;
1+
package dev.lars.utilsmanager.commands.teleport.spawn;
22

33
import dev.lars.apimanager.apis.languageAPI.LanguageAPI;
44
import dev.lars.apimanager.apis.playerSettingsAPI.PlayerSettingsAPI;
@@ -13,15 +13,17 @@
1313
public class ToggleBedCommand implements BasicCommand {
1414

1515
@Override
16-
public void execute(@NotNull CommandSourceStack stack, @NotNull String[] args) {
16+
public void execute(@NotNull CommandSourceStack stack, @NotNull String @NotNull [] args) {
1717
if (!(stack.getExecutor() instanceof Player player)) {
1818
stack.getSender().sendMessage(Statements.getOnlyPlayers());
1919
return;
2020
}
21+
2122
if (!(player.hasPermission("utilsmanager.togglebed"))) {
2223
player.sendMessage(Statements.getNotAllowed(player));
2324
return;
2425
}
26+
2527
if (PlayerSettingsAPI.getApi().getBedToggle(player)) {
2628
PlayerSettingsAPI.getApi().setBedToggle(player, false);
2729
if (LanguageAPI.getApi().getLanguage(player) == 2) {
@@ -37,7 +39,6 @@ public void execute(@NotNull CommandSourceStack stack, @NotNull String[] args) {
3739
} else {
3840
player.sendMessage(Statements.getPrefix().append(Component.text("You are now spawning on the spawn!", NamedTextColor.GRAY)));
3941
}
40-
4142
}
4243
}
4344
}

src/main/java/dev/lars/utilsmanager/features/rank/RankManager.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ public void setPermisssions(Player player) {
8383
attachment.setPermission("utilsmanager.pay", true);
8484
attachment.setPermission("utilsmanager.price", true);
8585
attachment.setPermission("utilsmanager.realtime", true);
86-
attachment.setPermission("utilsmanager.setspawn", true);
87-
attachment.setPermission("utilsmanager.spawn", true);
86+
attachment.setPermission("utilsmanager.feature.spawn", true);
8887
attachment.setPermission("utilsmanager.timer", true);
8988
attachment.setPermission("utilsmanager.timer.public", true);
9089
attachment.setPermission("utilsmanager.togglebed", true);
@@ -126,6 +125,7 @@ public void setPermisssions(Player player) {
126125
attachment.setPermission("utilsmanager.vanish", true);
127126
attachment.setPermission("utilsmanager.feature.freecam", true);
128127
attachment.setPermission("utilsmanager.maintenance", true);
128+
attachment.setPermission("utilsmanager.feature.spawn.setspawn", true);
129129
}
130130
case 9: {
131131
attachment.setPermission("utilsmanager.addcoins", true);
@@ -141,8 +141,7 @@ public void setPermisssions(Player player) {
141141
attachment.setPermission("utilsmanager.pay", true);
142142
attachment.setPermission("utilsmanager.price", true);
143143
attachment.setPermission("utilsmanager.realtime", true);
144-
attachment.setPermission("utilsmanager.setspawn", true);
145-
attachment.setPermission("utilsmanager.spawn", true);
144+
attachment.setPermission("utilsmanager.feature.spawn", true);
146145
attachment.setPermission("utilsmanager.timer", true);
147146
attachment.setPermission("utilsmanager.togglebed", true);
148147
attachment.setPermission("utilsmanager.togglescoreboard", true);
@@ -180,6 +179,7 @@ public void setPermisssions(Player player) {
180179
attachment.setPermission("utilsmanager.vanish", true);
181180
attachment.setPermission("utilsmanager.feature.freecam", true);
182181
attachment.setPermission("utilsmanager.maintenance", true);
182+
attachment.setPermission("utilsmanager.feature.spawn.setspawn", true);
183183
}
184184
case 8: {
185185
attachment.setPermission("utilsmanager.addcoins", true);
@@ -195,8 +195,7 @@ public void setPermisssions(Player player) {
195195
attachment.setPermission("utilsmanager.pay", true);
196196
attachment.setPermission("utilsmanager.price", true);
197197
attachment.setPermission("utilsmanager.realtime", true);
198-
attachment.setPermission("utilsmanager.setspawn", true);
199-
attachment.setPermission("utilsmanager.spawn", true);
198+
attachment.setPermission("utilsmanager.feature.spawn", true);
200199
attachment.setPermission("utilsmanager.timer", true);
201200
attachment.setPermission("utilsmanager.togglebed", true);
202201
attachment.setPermission("utilsmanager.togglescoreboard", true);
@@ -238,8 +237,7 @@ public void setPermisssions(Player player) {
238237
attachment.setPermission("utilsmanager.pay", true);
239238
attachment.setPermission("utilsmanager.price", true);
240239
attachment.setPermission("utilsmanager.realtime", true);
241-
attachment.setPermission("utilsmanager.setspawn", true);
242-
attachment.setPermission("utilsmanager.spawn", true);
240+
attachment.setPermission("utilsmanager.feature.spawn", true);
243241
attachment.setPermission("utilsmanager.timer", true);
244242
attachment.setPermission("utilsmanager.togglebed", true);
245243
attachment.setPermission("utilsmanager.togglescoreboard", true);
@@ -269,8 +267,7 @@ public void setPermisssions(Player player) {
269267
attachment.setPermission("utilsmanager.language", true);
270268
attachment.setPermission("utilsmanager.pay", true);
271269
attachment.setPermission("utilsmanager.price", true);
272-
attachment.setPermission("utilsmanager.setspawn", true);
273-
attachment.setPermission("utilsmanager.spawn", true);
270+
attachment.setPermission("utilsmanager.feature.spawn", true);
274271
attachment.setPermission("utilsmanager.timer", true);
275272
attachment.setPermission("utilsmanager.togglebed", true);
276273
attachment.setPermission("utilsmanager.togglescoreboard", true);
@@ -297,7 +294,7 @@ public void setPermisssions(Player player) {
297294
attachment.setPermission("utilsmanager.language", true);
298295
attachment.setPermission("utilsmanager.pay", true);
299296
attachment.setPermission("utilsmanager.price", true);
300-
attachment.setPermission("utilsmanager.spawn", true);
297+
attachment.setPermission("utilsmanager.feature.spawn", true);
301298
attachment.setPermission("utilsmanager.timer", true);
302299
attachment.setPermission("utilsmanager.togglebed", true);
303300
attachment.setPermission("utilsmanager.togglescoreboard", true);

src/main/java/dev/lars/utilsmanager/listener/player/JoinListener.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import dev.lars.apimanager.apis.playerSettingsAPI.PlayerSettingsAPI;
99
import dev.lars.apimanager.apis.prefixAPI.PrefixAPI;
1010
import dev.lars.apimanager.apis.rankAPI.RankAPI;
11+
import dev.lars.apimanager.apis.serverSettingsAPI.ServerSettingsAPI;
1112
import dev.lars.utilsmanager.UtilsManager;
1213
import dev.lars.utilsmanager.scoreboard.Scoreboard;
1314
import dev.lars.utilsmanager.utils.RankStatements;
@@ -34,6 +35,7 @@
3435
import java.time.Duration;
3536
import java.time.LocalDate;
3637
import java.util.Calendar;
38+
import java.util.Objects;
3739

3840
public class JoinListener implements Listener {
3941

@@ -58,9 +60,13 @@ public void onJoin(PlayerJoinEvent event) {
5860
if (PlayerSettingsAPI.getApi().getBedToggle(player)) {
5961
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 100, 2);
6062
} else {
61-
Location loc = new Location(Bukkit.getWorld("world"), -205.5, 78.0, -102.5, -90, 0);
62-
player.teleport(loc);
63-
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 100, 1);
63+
Location loc = ServerSettingsAPI.getApi().getSpawnLocation();
64+
if (loc == null) {
65+
player.teleport(Objects.requireNonNull(Bukkit.getWorld("world")).getSpawnLocation());
66+
} else {
67+
player.teleport(loc);
68+
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 100, 1);
69+
}
6470
}
6571
if (LanguageAPI.getApi().getLanguage(player) == 2) {
6672
Bukkit.getScheduler().runTaskLater(UtilsManager.getInstance(), () -> showTitleGe(player), 35);

src/main/java/dev/lars/utilsmanager/listener/player/RespawnListener.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import dev.lars.apimanager.apis.languageAPI.LanguageAPI;
44
import dev.lars.apimanager.apis.playerSettingsAPI.PlayerSettingsAPI;
5+
import dev.lars.apimanager.apis.serverSettingsAPI.ServerSettingsAPI;
56
import dev.lars.utilsmanager.utils.Statements;
67
import net.kyori.adventure.text.Component;
78
import net.kyori.adventure.text.format.NamedTextColor;
@@ -17,13 +18,11 @@ public class RespawnListener implements Listener {
1718

1819
@EventHandler
1920
public void onRespawn(PlayerRespawnEvent event) {
20-
2121
Player player = event.getPlayer();
2222
Location respawnLocation = event.getRespawnLocation();
2323
Location bedSpawn = player.getRespawnLocation();
2424
Location worldSpawn = player.getWorld().getSpawnLocation();
25-
26-
Location loc = new Location(Bukkit.getWorld("world"), -205.5, 78.0, -102.5, -90, 0);
25+
Location loc = ServerSettingsAPI.getApi().getSpawnLocation();
2726

2827
if (PlayerSettingsAPI.getApi().getBedToggle(player) || !respawnLocation.equals(bedSpawn)) {
2928
if (LanguageAPI.getApi().getLanguage(player ) == 2) {
@@ -33,14 +32,23 @@ public void onRespawn(PlayerRespawnEvent event) {
3332
}
3433
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 100, 2);
3534
} else {
36-
event.setRespawnLocation(loc);
37-
if (LanguageAPI.getApi().getLanguage(player ) == 2) {
38-
player.sendMessage(Statements.getPrefix().append(Component.text("Du wurdest am Offiziellen Spawn wiederbelebt.", NamedTextColor.GOLD)));
35+
if (loc != null) {
36+
event.setRespawnLocation(loc);
37+
if (LanguageAPI.getApi().getLanguage(player) == 2) {
38+
player.sendMessage(Statements.getPrefix().append(Component.text("Du wurdest am Spawn wiederbelebt.", NamedTextColor.GOLD)));
39+
} else {
40+
player.sendMessage(Statements.getPrefix().append(Component.text("You were respawned at the spawn.", NamedTextColor.GOLD)));
41+
}
42+
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 100, 1);
3943
} else {
40-
player.sendMessage(Statements.getPrefix().append(Component.text("You were respawned at the official Spawn.", NamedTextColor.GOLD)));
44+
event.setRespawnLocation(worldSpawn);
45+
if (LanguageAPI.getApi().getLanguage(player) == 2) {
46+
player.sendMessage(Statements.getPrefix().append(Component.text("Du wurdest am Welt Spawn wiederbelebt.", NamedTextColor.GOLD)));
47+
} else {
48+
player.sendMessage(Statements.getPrefix().append(Component.text("You were respawned at the world spawn.", NamedTextColor.GOLD)));
49+
}
50+
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 100, 2);
4151
}
42-
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 100, 1);
4352
}
4453
}
45-
46-
}
54+
}

0 commit comments

Comments
 (0)