Compare commits
No commits in common. "5786b2409e2654a4fb80a2639a357d9e81ed9c8f" and "cb45047f716584a260fd3b1a81421de65e5a9f59" have entirely different histories.
5786b2409e
...
cb45047f71
@ -7,11 +7,9 @@ import eu.mhsl.craftattack.spawn.appliances.countdown.Countdown;
|
|||||||
import eu.mhsl.craftattack.spawn.appliances.debug.Debug;
|
import eu.mhsl.craftattack.spawn.appliances.debug.Debug;
|
||||||
import eu.mhsl.craftattack.spawn.appliances.event.Event;
|
import eu.mhsl.craftattack.spawn.appliances.event.Event;
|
||||||
import eu.mhsl.craftattack.spawn.appliances.help.Help;
|
import eu.mhsl.craftattack.spawn.appliances.help.Help;
|
||||||
import eu.mhsl.craftattack.spawn.appliances.playerlimit.PlayerLimit;
|
|
||||||
import eu.mhsl.craftattack.spawn.appliances.report.Report;
|
import eu.mhsl.craftattack.spawn.appliances.report.Report;
|
||||||
import eu.mhsl.craftattack.spawn.appliances.tablist.Tablist;
|
import eu.mhsl.craftattack.spawn.appliances.tablist.Tablist;
|
||||||
import eu.mhsl.craftattack.spawn.appliances.titleClear.TitleClear;
|
import eu.mhsl.craftattack.spawn.appliances.titleClear.TitleClear;
|
||||||
import eu.mhsl.craftattack.spawn.appliances.whitelist.Whitelist;
|
|
||||||
import eu.mhsl.craftattack.spawn.config.Configuration;
|
import eu.mhsl.craftattack.spawn.config.Configuration;
|
||||||
import eu.mhsl.craftattack.spawn.appliances.worldmuseum.WorldMuseum;
|
import eu.mhsl.craftattack.spawn.appliances.worldmuseum.WorldMuseum;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -41,8 +39,6 @@ public final class Main extends JavaPlugin {
|
|||||||
new Report(),
|
new Report(),
|
||||||
new Event(),
|
new Event(),
|
||||||
new Help(),
|
new Help(),
|
||||||
new PlayerLimit(),
|
|
||||||
new Whitelist(),
|
|
||||||
new Debug()
|
new Debug()
|
||||||
);
|
);
|
||||||
Bukkit.getLogger().info("Loading appliances...");
|
Bukkit.getLogger().info("Loading appliances...");
|
||||||
|
@ -8,7 +8,6 @@ import org.bukkit.event.HandlerList;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -69,16 +68,16 @@ public abstract class Appliance {
|
|||||||
|
|
||||||
public void destruct(@NotNull JavaPlugin plugin) {
|
public void destruct(@NotNull JavaPlugin plugin) {
|
||||||
eventHandlers().forEach(HandlerList::unregisterAll);
|
eventHandlers().forEach(HandlerList::unregisterAll);
|
||||||
|
commands().forEach(command -> setCommandExecutor(plugin, command.commandName, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCommandExecutor(JavaPlugin plugin, String name, ApplianceCommand<?> executor) {
|
private void setCommandExecutor(JavaPlugin plugin, String name, ApplianceCommand<?> executor) {
|
||||||
PluginCommand command = plugin.getCommand(name);
|
PluginCommand command = plugin.getCommand(name);
|
||||||
if(command != null && executor != null) {
|
if(command != null) {
|
||||||
command.setExecutor(executor);
|
command.setExecutor(executor);
|
||||||
command.setTabCompleter(executor);
|
command.setTabCompleter(executor);
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getLogger().warning("Command " + name + " is not specified in plugin.yml!");
|
Bukkit.getLogger().warning("Command " + name + " is not specified in plugin.yml!");
|
||||||
throw new RuntimeException("All commands must be registered in plugin.yml. Missing command: " + name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ public abstract class ApplianceCommand<T extends Appliance> extends ApplianceSup
|
|||||||
return response.stream().filter(s -> s.startsWith(args[args.length-1])).toList();
|
return response.stream().filter(s -> s.startsWith(args[args.length-1])).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception;
|
protected abstract void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for command which can only be used as a Player. You can access the executing player with the getPlayer() method.
|
* Utility class for command which can only be used as a Player. You can access the executing player with the getPlayer() method.
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package eu.mhsl.craftattack.spawn.appliances.event;
|
package eu.mhsl.craftattack.spawn.appliances.event;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import eu.mhsl.craftattack.spawn.appliance.Appliance;
|
import eu.mhsl.craftattack.spawn.appliance.Appliance;
|
||||||
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||||
import eu.mhsl.craftattack.spawn.appliances.event.command.EventCommand;
|
import eu.mhsl.craftattack.spawn.appliances.event.command.EventCommand;
|
||||||
@ -18,21 +17,11 @@ import org.bukkit.entity.Villager;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.net.http.HttpClient;
|
|
||||||
import java.net.http.HttpRequest;
|
|
||||||
import java.net.http.HttpResponse;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class Event extends Appliance {
|
public class Event extends Appliance {
|
||||||
public DisplayVillager.ConfigBound villager;
|
public DisplayVillager.ConfigBound villager;
|
||||||
private boolean isOpen = false;
|
private boolean isOpen = false;
|
||||||
private UUID roomId;
|
|
||||||
private HttpClient eventServerClient = HttpClient.newHttpClient();
|
|
||||||
|
|
||||||
|
|
||||||
public Event() {
|
public Event() {
|
||||||
super("event");
|
super("event");
|
||||||
@ -48,25 +37,11 @@ public class Event extends Appliance {
|
|||||||
villager.setVillagerType(Villager.Type.SNOW);
|
villager.setVillagerType(Villager.Type.SNOW);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
this.isOpen = localConfig().getBoolean("enabled", false);
|
|
||||||
if(this.isOpen) this.roomId = UUID.fromString(localConfig().getString("roomId", ""));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openEvent() throws URISyntaxException, IOException, InterruptedException {
|
public void openEvent() {
|
||||||
if(isOpen) throw new ApplianceCommand.Error("Es läuft derzeit bereits ein Event!");
|
if(isOpen) throw new ApplianceCommand.Error("Es läuft derzeit bereits ein Event!");
|
||||||
HttpRequest createRoomRequest = HttpRequest.newBuilder()
|
|
||||||
.uri(new URI(localConfig().getString("api") + "/room"))
|
|
||||||
.POST(HttpRequest.BodyPublishers.noBody())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
HttpResponse<String> rawResponse = eventServerClient.send(createRoomRequest, HttpResponse.BodyHandlers.ofString());
|
|
||||||
if(rawResponse.statusCode() != 200) throw new ApplianceCommand.Error("Event-Server meldet Fehler: " + rawResponse.statusCode());
|
|
||||||
|
|
||||||
record Response(UUID uuid) {}
|
|
||||||
Response response = new Gson().fromJson(rawResponse.body(), Response.class);
|
|
||||||
|
|
||||||
isOpen = true;
|
isOpen = true;
|
||||||
roomId = response.uuid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void joinEvent(Player p) {
|
public void joinEvent(Player p) {
|
||||||
@ -75,27 +50,7 @@ public class Event extends Appliance {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
p.sendMessage(Component.text("Authentifiziere...", NamedTextColor.GREEN));
|
|
||||||
record Request(UUID player, UUID room) {}
|
|
||||||
Request request = new Request(p.getUniqueId(), this.roomId);
|
|
||||||
HttpRequest queueRoomRequest = HttpRequest.newBuilder()
|
|
||||||
.uri(new URI(localConfig().getString("api") + "/queueRoom"))
|
|
||||||
.POST(HttpRequest.BodyPublishers.ofString(new Gson().toJson(request)))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
HttpResponse<Void> rawResponse = eventServerClient.send(queueRoomRequest, HttpResponse.BodyHandlers.discarding());
|
|
||||||
if(rawResponse.statusCode() != 200) {
|
|
||||||
p.sendMessage(Component.text("Fehler beim beitreten: " + rawResponse.statusCode(), NamedTextColor.RED));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
p.sendMessage(Component.text("Betrete...", NamedTextColor.GREEN));
|
|
||||||
PluginMessage.connect(p, localConfig().getString("connect-server-name"));
|
PluginMessage.connect(p, localConfig().getString("connect-server-name"));
|
||||||
|
|
||||||
} catch (URISyntaxException | IOException | InterruptedException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endEvent() {
|
public void endEvent() {
|
||||||
|
@ -12,7 +12,7 @@ public class EventCommand extends ApplianceCommand.PlayerChecked<Event> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
|
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
getAppliance().joinEvent(getPlayer());
|
getAppliance().joinEvent(getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,6 @@ package eu.mhsl.craftattack.spawn.appliances.event.command;
|
|||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||||
import eu.mhsl.craftattack.spawn.appliances.event.Event;
|
import eu.mhsl.craftattack.spawn.appliances.event.Event;
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -14,8 +12,7 @@ public class EventOpenSessionCommand extends ApplianceCommand<Event> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
|
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
getAppliance().openEvent();
|
getAppliance().openEvent();
|
||||||
sender.sendMessage(Component.text("Event-Server erfolgreich gestartet!", NamedTextColor.GREEN));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
package eu.mhsl.craftattack.spawn.appliances.playerlimit;
|
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.Main;
|
|
||||||
import eu.mhsl.craftattack.spawn.appliance.Appliance;
|
|
||||||
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
|
||||||
import eu.mhsl.craftattack.spawn.appliances.playerlimit.command.SetPlayerLimitCommand;
|
|
||||||
import eu.mhsl.craftattack.spawn.appliances.playerlimit.listener.PlayerJoinLimiterListener;
|
|
||||||
import eu.mhsl.craftattack.spawn.config.Configuration;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class PlayerLimit extends Appliance {
|
|
||||||
private static final String playerLimitKey = "maxPlayers";
|
|
||||||
private int limit;
|
|
||||||
public PlayerLimit() {
|
|
||||||
super("playerLimit");
|
|
||||||
this.limit = localConfig().getInt(playerLimitKey);
|
|
||||||
Bukkit.setMaxPlayers(Integer.MAX_VALUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlayerLimit(int limit) {
|
|
||||||
this.limit = limit;
|
|
||||||
localConfig().set(playerLimitKey, limit);
|
|
||||||
Configuration.saveChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLimit() {
|
|
||||||
return limit;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull List<Listener> eventHandlers() {
|
|
||||||
return List.of(
|
|
||||||
new PlayerJoinLimiterListener()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull List<ApplianceCommand<?>> commands() {
|
|
||||||
return List.of(
|
|
||||||
new SetPlayerLimitCommand()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package eu.mhsl.craftattack.spawn.appliances.playerlimit.command;
|
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
|
||||||
import eu.mhsl.craftattack.spawn.appliances.playerlimit.PlayerLimit;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class SetPlayerLimitCommand extends ApplianceCommand<PlayerLimit> {
|
|
||||||
public SetPlayerLimitCommand() {
|
|
||||||
super("setPlayerLimit");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
|
||||||
getAppliance().setPlayerLimit(Integer.parseInt(args[0]));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package eu.mhsl.craftattack.spawn.appliances.playerlimit.listener;
|
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.appliance.ApplianceListener;
|
|
||||||
import eu.mhsl.craftattack.spawn.appliances.playerlimit.PlayerLimit;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
|
||||||
|
|
||||||
public class PlayerJoinLimiterListener extends ApplianceListener<PlayerLimit> {
|
|
||||||
@EventHandler
|
|
||||||
public void onLogin(PlayerLoginEvent playerPreLoginEvent) {
|
|
||||||
playerPreLoginEvent.kickMessage(Component.text("Der Server ist derzeit voll! Versuche es bitte später erneut.", NamedTextColor.RED));
|
|
||||||
if(Bukkit.getOnlinePlayers().size() >= getAppliance().getLimit()) playerPreLoginEvent.setResult(PlayerLoginEvent.Result.KICK_FULL);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package eu.mhsl.craftattack.spawn.appliances.whitelist;
|
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.appliance.ApplianceListener;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
|
||||||
|
|
||||||
public class PlayerJoinListener extends ApplianceListener<Whitelist> {
|
|
||||||
@EventHandler
|
|
||||||
public void preLoginEvent(AsyncPlayerPreLoginEvent preLoginEvent) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
package eu.mhsl.craftattack.spawn.appliances.whitelist;
|
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.appliance.Appliance;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Whitelist extends Appliance {
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull List<Listener> eventHandlers() {
|
|
||||||
return List.of(
|
|
||||||
new PlayerJoinListener()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -24,10 +24,8 @@ report:
|
|||||||
api: https://mhsl.eu/craftattack/report
|
api: https://mhsl.eu/craftattack/report
|
||||||
|
|
||||||
event:
|
event:
|
||||||
api: http://10.20.6.5:8080/
|
api: http://10.20.0.1/
|
||||||
connect-server-name: event
|
connect-server-name: event
|
||||||
enabled: false
|
|
||||||
roomId:
|
|
||||||
uuid:
|
uuid:
|
||||||
villagerLocation:
|
villagerLocation:
|
||||||
world: world
|
world: world
|
||||||
@ -40,6 +38,3 @@ event:
|
|||||||
help:
|
help:
|
||||||
teamspeak: myserver.com
|
teamspeak: myserver.com
|
||||||
spawn: "Der Weltspawn befindet sich bei x:0 y:0 z:0"
|
spawn: "Der Weltspawn befindet sich bei x:0 y:0 z:0"
|
||||||
|
|
||||||
playerLimit:
|
|
||||||
maxPlayers: 0
|
|
@ -29,4 +29,3 @@ commands:
|
|||||||
aliases: ["ts"]
|
aliases: ["ts"]
|
||||||
discord:
|
discord:
|
||||||
aliases: ["dc"]
|
aliases: ["dc"]
|
||||||
setPlayerLimit:
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user