added spawnpoint
This commit is contained in:
parent
2f1aeb71ee
commit
8faf0efd60
@ -0,0 +1,12 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.appliances.spawnpoint;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.appliance.ApplianceListener;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
|
public class FirstSpawnPlayerListener extends ApplianceListener<Spawnpoint> {
|
||||||
|
@EventHandler
|
||||||
|
public void onSpawn(PlayerJoinEvent event) {
|
||||||
|
this.getAppliance().handlePlayerLogin(event.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.appliances.spawnpoint;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class SetSpawnpointCommand extends ApplianceCommand.PlayerChecked<Spawnpoint> {
|
||||||
|
public SetSpawnpointCommand() {
|
||||||
|
super("setSpawnpoint");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
|
||||||
|
this.getAppliance().setSpawnpoint(this.getPlayer().getLocation());
|
||||||
|
sender.sendMessage(Component.text("Spawnpoint updated!", NamedTextColor.GREEN));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.appliances.spawnpoint;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.appliance.Appliance;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class Spawnpoint extends Appliance {
|
||||||
|
private static final String namespace = Spawnpoint.class.getSimpleName().toLowerCase(Locale.ROOT);
|
||||||
|
public static NamespacedKey alreadySpawned = new NamespacedKey(namespace, "editable");
|
||||||
|
private static final String position = "position";
|
||||||
|
|
||||||
|
private Location spawnPoint;
|
||||||
|
|
||||||
|
public Spawnpoint() {
|
||||||
|
super("spawnpoint");
|
||||||
|
this.spawnPoint = this.localConfig().getLocation(position, new Location(Bukkit.getWorlds().getFirst(), 0, 100, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpawnpoint(Location location) {
|
||||||
|
this.localConfig().set("position", location);
|
||||||
|
this.spawnPoint = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handlePlayerLogin(Player player) {
|
||||||
|
PersistentDataContainer dataContainer = player.getPersistentDataContainer();
|
||||||
|
if(dataContainer.has(alreadySpawned)) return;
|
||||||
|
player.teleportAsync(this.spawnPoint);
|
||||||
|
dataContainer.set(alreadySpawned, PersistentDataType.BOOLEAN, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull List<ApplianceCommand<?>> commands() {
|
||||||
|
return List.of(new SetSpawnpointCommand());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull List<Listener> listeners() {
|
||||||
|
return List.of(new FirstSpawnPlayerListener());
|
||||||
|
}
|
||||||
|
}
|
@ -26,7 +26,6 @@ countdown:
|
|||||||
start-permission: admin
|
start-permission: admin
|
||||||
countdown: 60
|
countdown: 60
|
||||||
worldborder-before: 37
|
worldborder-before: 37
|
||||||
worldborder-after: 0
|
|
||||||
|
|
||||||
event:
|
event:
|
||||||
api: http://10.20.6.5:8080/
|
api: http://10.20.6.5:8080/
|
||||||
@ -71,5 +70,4 @@ packselect:
|
|||||||
endPrevent:
|
endPrevent:
|
||||||
endDisabled: true
|
endDisabled: true
|
||||||
|
|
||||||
feedback:
|
spawnpoint:
|
||||||
api: https://mhsl.eu/craftattack/api/feedback
|
|
||||||
|
@ -52,3 +52,4 @@ commands:
|
|||||||
endPrevent:
|
endPrevent:
|
||||||
feedback:
|
feedback:
|
||||||
requestFeedback:
|
requestFeedback:
|
||||||
|
setSpawnpoint:
|
Loading…
x
Reference in New Issue
Block a user