applied code styling
This commit is contained in:
parent
78ba105291
commit
3dc25d63fd
@ -1,28 +1,28 @@
|
||||
package eu.mhsl.craftattack.spawn;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.appliances.displayName.DisplayName;
|
||||
import eu.mhsl.craftattack.spawn.api.HttpServer;
|
||||
import eu.mhsl.craftattack.spawn.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.appliances.adminMarker.AdminMarker;
|
||||
import eu.mhsl.craftattack.spawn.appliances.customAdvancements.CustomAdvancements;
|
||||
import eu.mhsl.craftattack.spawn.appliances.fleischerchest.Fleischerchest;
|
||||
import eu.mhsl.craftattack.spawn.appliances.kick.Kick;
|
||||
import eu.mhsl.craftattack.spawn.appliances.chatMessages.ChatMessages;
|
||||
import eu.mhsl.craftattack.spawn.appliances.customAdvancements.CustomAdvancements;
|
||||
import eu.mhsl.craftattack.spawn.appliances.debug.Debug;
|
||||
import eu.mhsl.craftattack.spawn.appliances.displayName.DisplayName;
|
||||
import eu.mhsl.craftattack.spawn.appliances.event.Event;
|
||||
import eu.mhsl.craftattack.spawn.appliances.fleischerchest.Fleischerchest;
|
||||
import eu.mhsl.craftattack.spawn.appliances.help.Help;
|
||||
import eu.mhsl.craftattack.spawn.appliances.kick.Kick;
|
||||
import eu.mhsl.craftattack.spawn.appliances.outlawed.Outlawed;
|
||||
import eu.mhsl.craftattack.spawn.appliances.panicBan.PanicBan;
|
||||
import eu.mhsl.craftattack.spawn.appliances.projectStart.ProjectStart;
|
||||
import eu.mhsl.craftattack.spawn.appliances.debug.Debug;
|
||||
import eu.mhsl.craftattack.spawn.appliances.event.Event;
|
||||
import eu.mhsl.craftattack.spawn.appliances.help.Help;
|
||||
import eu.mhsl.craftattack.spawn.appliances.playerlimit.PlayerLimit;
|
||||
import eu.mhsl.craftattack.spawn.appliances.projectStart.ProjectStart;
|
||||
import eu.mhsl.craftattack.spawn.appliances.report.Report;
|
||||
import eu.mhsl.craftattack.spawn.appliances.restart.Restart;
|
||||
import eu.mhsl.craftattack.spawn.appliances.settings.Settings;
|
||||
import eu.mhsl.craftattack.spawn.appliances.tablist.Tablist;
|
||||
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.appliances.worldmuseum.WorldMuseum;
|
||||
import eu.mhsl.craftattack.spawn.config.Configuration;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -35,6 +35,7 @@ public final class Main extends JavaPlugin {
|
||||
|
||||
private List<Appliance> appliances;
|
||||
private HttpServer httpApi;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
|
@ -15,6 +15,7 @@ public class HttpServer {
|
||||
protected final Gson gson = new Gson();
|
||||
|
||||
public static Object nothing = null;
|
||||
|
||||
public HttpServer() {
|
||||
Spark.port(8080);
|
||||
|
||||
@ -41,6 +42,7 @@ public class HttpServer {
|
||||
}
|
||||
|
||||
private final String applianceName;
|
||||
|
||||
private ApiBuilder(Appliance appliance) {
|
||||
this.applianceName = appliance.getClass().getSimpleName().toLowerCase();
|
||||
}
|
||||
@ -69,7 +71,7 @@ public class HttpServer {
|
||||
HttpServer.Response response;
|
||||
try {
|
||||
response = new Response(Response.Status.SUCCESS, null, exec.get());
|
||||
} catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
response = new Response(Response.Status.FAILURE, e, null);
|
||||
}
|
||||
return HttpServer.this.gson.toJson(response);
|
||||
|
@ -24,10 +24,12 @@ public abstract class Appliance {
|
||||
private List<Listener> listeners;
|
||||
private List<ApplianceCommand<?>> commands;
|
||||
|
||||
public Appliance() {}
|
||||
public Appliance() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this constructor to specify a config sub-path for use with the localConfig() method.
|
||||
*
|
||||
* @param localConfigPath sub path, if not found, the whole config will be used
|
||||
*/
|
||||
public Appliance(String localConfigPath) {
|
||||
@ -36,6 +38,7 @@ public abstract class Appliance {
|
||||
|
||||
/**
|
||||
* Provides a list of listeners for the appliance. All listeners will be automatically registered.
|
||||
*
|
||||
* @return List of listeners
|
||||
*/
|
||||
@NotNull
|
||||
@ -45,6 +48,7 @@ public abstract class Appliance {
|
||||
|
||||
/**
|
||||
* Provides a list of commands for the appliance. All commands will be automatically registered.
|
||||
*
|
||||
* @return List of commands
|
||||
*/
|
||||
@NotNull
|
||||
@ -55,12 +59,15 @@ public abstract class Appliance {
|
||||
/**
|
||||
* Called on initialization to add all needed API Routes.
|
||||
* The routeBuilder can be used to get the correct Path prefixes
|
||||
*
|
||||
* @param apiBuilder holds data for needed route prefixes.
|
||||
*/
|
||||
public void httpApi(HttpServer.ApiBuilder apiBuilder) {}
|
||||
public void httpApi(HttpServer.ApiBuilder apiBuilder) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a localized config section. Path can be set in appliance constructor.
|
||||
*
|
||||
* @return Section of configuration for your appliance
|
||||
*/
|
||||
@NotNull
|
||||
@ -68,8 +75,11 @@ public abstract class Appliance {
|
||||
return Optional.ofNullable(Configuration.cfg.getConfigurationSection(localConfigPath)).orElse(Configuration.cfg);
|
||||
}
|
||||
|
||||
public void onEnable() {}
|
||||
public void onDisable() {}
|
||||
public void onEnable() {
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
}
|
||||
|
||||
public void initialize(@NotNull JavaPlugin plugin) {
|
||||
this.listeners = eventHandlers();
|
||||
|
@ -20,6 +20,7 @@ import java.util.Optional;
|
||||
public abstract class ApplianceCommand<T extends Appliance> extends ApplianceSupplier<T> implements TabCompleter, CommandExecutor {
|
||||
public String commandName;
|
||||
protected Component errorMessage = Component.text("Fehler: ").color(NamedTextColor.RED);
|
||||
|
||||
public ApplianceCommand(String command) {
|
||||
this.commandName = command;
|
||||
}
|
||||
@ -33,9 +34,9 @@ public abstract class ApplianceCommand<T extends Appliance> extends ApplianceSup
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
try {
|
||||
execute(sender, command, label, args);
|
||||
} catch (Error e) {
|
||||
} catch(Error e) {
|
||||
sender.sendMessage(errorMessage.append(Component.text(e.getMessage())));
|
||||
} catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
sender.sendMessage(errorMessage.append(Component.text("Interner Fehler")));
|
||||
Bukkit.getLogger().warning("Error executing appliance command " + commandName + ": " + e.getMessage());
|
||||
e.printStackTrace(System.err);
|
||||
@ -50,7 +51,7 @@ public abstract class ApplianceCommand<T extends Appliance> extends ApplianceSup
|
||||
}
|
||||
|
||||
protected List<String> tabCompleteReducer(List<String> response, String[] args) {
|
||||
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;
|
||||
@ -61,6 +62,7 @@ public abstract class ApplianceCommand<T extends Appliance> extends ApplianceSup
|
||||
public static abstract class PlayerChecked<T extends Appliance> extends ApplianceCommand<T> {
|
||||
private Player player;
|
||||
private Component notPlayerMessage = Component.text("Dieser Command kann nur von Spielern ausgeführt werden!").color(NamedTextColor.RED);
|
||||
|
||||
public PlayerChecked(String command) {
|
||||
super(command);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import org.bukkit.event.Listener;
|
||||
/**
|
||||
* Utility class which provides a specific, type save appliance.
|
||||
* You can access the appliance with the protected 'appliance' field.
|
||||
*
|
||||
* @param <T> the type of your appliance
|
||||
*/
|
||||
public abstract class ApplianceListener<T extends Appliance> extends ApplianceSupplier<T> implements Listener {
|
||||
|
@ -11,7 +11,8 @@ import java.util.List;
|
||||
|
||||
public class AdminMarker extends Appliance {
|
||||
public TextColor getPlayerColor(Player player) {
|
||||
if (player.hasPermission("chatcolor")) return TextColor.color(Color.AQUA.asRGB()); // TODO read permission from config
|
||||
if(player.hasPermission("chatcolor"))
|
||||
return TextColor.color(Color.AQUA.asRGB()); // TODO read permission from config
|
||||
return TextColor.color(Color.WHITE.asRGB());
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,8 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class AdminMarkerListener extends ApplianceListener<AdminMarker> {
|
||||
private TextColor getPlayerColor(Player player) {
|
||||
if (player.hasPermission("chatcolor")) return TextColor.color(Color.AQUA.asRGB()); // TODO read permission from config
|
||||
if(player.hasPermission("chatcolor"))
|
||||
return TextColor.color(Color.AQUA.asRGB()); // TODO read permission from config
|
||||
return TextColor.color(Color.WHITE.asRGB());
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import eu.mhsl.craftattack.spawn.appliances.debug.command.UserInfoCommand;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Debug extends Appliance {
|
||||
@Override
|
||||
@NotNull
|
||||
|
@ -39,7 +39,7 @@ public class DisplayName extends Appliance {
|
||||
player.customName(component);
|
||||
player.displayName(component);
|
||||
player.playerListName(component);
|
||||
} catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
//TODO this throws often exceptions, but still works, don't know why
|
||||
//Main.instance().getLogger().log(Level.SEVERE, e, e::getMessage);
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ import eu.mhsl.craftattack.spawn.appliances.event.command.*;
|
||||
import eu.mhsl.craftattack.spawn.appliances.event.listener.ApplyPendingRewardsListener;
|
||||
import eu.mhsl.craftattack.spawn.util.IteratorUtil;
|
||||
import eu.mhsl.craftattack.spawn.util.entity.DisplayVillager;
|
||||
import eu.mhsl.craftattack.spawn.util.server.PluginMessage;
|
||||
import eu.mhsl.craftattack.spawn.util.listener.DismissInventoryOpenFromHolder;
|
||||
import eu.mhsl.craftattack.spawn.util.listener.PlayerInteractAtEntityEventListener;
|
||||
import eu.mhsl.craftattack.spawn.util.server.PluginMessage;
|
||||
import eu.mhsl.craftattack.spawn.util.text.ComponentUtil;
|
||||
import eu.mhsl.craftattack.spawn.util.text.Countdown;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -39,6 +39,7 @@ public class Event extends Appliance {
|
||||
ADVERTISED,
|
||||
DONE
|
||||
}
|
||||
|
||||
Countdown advertiseCountdown = new Countdown(
|
||||
120,
|
||||
announcementData -> Component.text()
|
||||
@ -57,8 +58,12 @@ public class Event extends Appliance {
|
||||
private final HttpClient eventServerClient = HttpClient.newHttpClient();
|
||||
private final List<Reward> pendingRewards = new ArrayList<>();
|
||||
|
||||
record RewardConfiguration(String memorialMaterial, String memorialTitle, String memorialLore, List<UUID> memorials, String material, Map<UUID, Integer> rewards) {}
|
||||
record Reward(UUID playerUuid, ItemStack itemStack) {}
|
||||
record RewardConfiguration(String memorialMaterial, String memorialTitle, String memorialLore, List<UUID> memorials,
|
||||
String material, Map<UUID, Integer> rewards) {
|
||||
}
|
||||
|
||||
record Reward(UUID playerUuid, ItemStack itemStack) {
|
||||
}
|
||||
|
||||
public Event() {
|
||||
super("event");
|
||||
@ -86,9 +91,11 @@ public class Event extends Appliance {
|
||||
.build();
|
||||
|
||||
HttpResponse<String> rawResponse = eventServerClient.send(createRoomRequest, HttpResponse.BodyHandlers.ofString());
|
||||
if(rawResponse.statusCode() != 200) throw new ApplianceCommand.Error("Event-Server meldet Fehler: " + rawResponse.statusCode());
|
||||
if(rawResponse.statusCode() != 200)
|
||||
throw new ApplianceCommand.Error("Event-Server meldet Fehler: " + rawResponse.statusCode());
|
||||
|
||||
record Response(UUID uuid) {}
|
||||
record Response(UUID uuid) {
|
||||
}
|
||||
Response response = new Gson().fromJson(rawResponse.body(), Response.class);
|
||||
|
||||
isOpen = true;
|
||||
@ -114,14 +121,16 @@ public class Event extends Appliance {
|
||||
try {
|
||||
Main.instance().getLogger().info("Verbinde mit eventserver: " + p.getName());
|
||||
p.sendMessage(Component.text("Authentifiziere...", NamedTextColor.GREEN));
|
||||
record Request(UUID player, UUID room) {}
|
||||
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();
|
||||
|
||||
record Response(String error) {}
|
||||
record Response(String error) {
|
||||
}
|
||||
HttpResponse<String> rawResponse = eventServerClient.send(queueRoomRequest, HttpResponse.BodyHandlers.ofString());
|
||||
Main.instance().getLogger().info("Response: " + rawResponse.body());
|
||||
Response response = new Gson().fromJson(rawResponse.body(), Response.class);
|
||||
@ -134,7 +143,7 @@ public class Event extends Appliance {
|
||||
p.sendMessage(Component.text("Betrete...", NamedTextColor.GREEN));
|
||||
PluginMessage.connect(p, localConfig().getString("connect-server-name"));
|
||||
|
||||
} catch (URISyntaxException | IOException | InterruptedException e) {
|
||||
} catch(URISyntaxException | IOException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
@ -163,7 +172,7 @@ public class Event extends Appliance {
|
||||
memorialItem.setItemMeta(meta);
|
||||
Reward memorial = new Reward(uuid, memorialItem);
|
||||
|
||||
if (Bukkit.getPlayer(uuid) == null) {
|
||||
if(Bukkit.getPlayer(uuid) == null) {
|
||||
pendingRewards.add(memorial);
|
||||
return;
|
||||
}
|
||||
|
@ -12,13 +12,15 @@ import java.util.Objects;
|
||||
|
||||
public class SpawnCommand extends ApplianceCommand<Help> {
|
||||
private static final String spawnKey = "spawn";
|
||||
|
||||
public SpawnCommand() {
|
||||
super("spawn");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if(!getAppliance().localConfig().isString(spawnKey)) throw new ApplianceCommand.Error("Es wurde kein Spawnbereich hinterlegt!");
|
||||
if(!getAppliance().localConfig().isString(spawnKey))
|
||||
throw new ApplianceCommand.Error("Es wurde kein Spawnbereich hinterlegt!");
|
||||
sender.sendMessage(Component.text(Objects.requireNonNull(getAppliance().localConfig().getString(spawnKey)), NamedTextColor.GOLD));
|
||||
}
|
||||
}
|
||||
|
@ -10,13 +10,15 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TeamspeakCommand extends ApplianceCommand<Help> {
|
||||
private static final String teamspeakKey = "teamspeak";
|
||||
|
||||
public TeamspeakCommand() {
|
||||
super("teamspeak");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if(!getAppliance().localConfig().isString(teamspeakKey)) throw new ApplianceCommand.Error("Es wurde kein Teamspeak hinterlegt!");
|
||||
if(!getAppliance().localConfig().isString(teamspeakKey))
|
||||
throw new ApplianceCommand.Error("Es wurde kein Teamspeak hinterlegt!");
|
||||
sender.sendMessage(
|
||||
Component.text()
|
||||
.append(Component.text("Joine unserem Teamspeak: ", NamedTextColor.GOLD))
|
||||
|
@ -1,9 +1,9 @@
|
||||
package eu.mhsl.craftattack.spawn.appliances.outlawed;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.Main;
|
||||
import eu.mhsl.craftattack.spawn.appliances.displayName.DisplayName;
|
||||
import eu.mhsl.craftattack.spawn.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||
import eu.mhsl.craftattack.spawn.appliances.displayName.DisplayName;
|
||||
import eu.mhsl.craftattack.spawn.appliances.whitelist.Whitelist;
|
||||
import eu.mhsl.craftattack.spawn.config.Configuration;
|
||||
import eu.mhsl.craftattack.spawn.util.text.DisconnectInfo;
|
||||
@ -18,8 +18,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.*;
|
||||
|
||||
public class Outlawed extends Appliance {
|
||||
public final int timeoutInMs = 1000*60*60*6;
|
||||
public final int timeoutInMs = 1000 * 60 * 60 * 6;
|
||||
private final Map<UUID, Long> timeouts = new HashMap<>();
|
||||
|
||||
public enum Status {
|
||||
DISABLED,
|
||||
VOLUNTARILY,
|
||||
@ -38,12 +39,12 @@ public class Outlawed extends Appliance {
|
||||
if(status != Status.FORCED) return;
|
||||
try {
|
||||
Main.instance().getAppliance(Whitelist.class).integrityCheck(player);
|
||||
} catch (DisconnectInfo.Throwable e) {
|
||||
} catch(DisconnectInfo.Throwable e) {
|
||||
Bukkit.getScheduler().runTask(Main.instance(), () -> e.getDisconnectScreen().applyKick(player));
|
||||
}
|
||||
}),
|
||||
20*60,
|
||||
20*60*5
|
||||
20 * 60,
|
||||
20 * 60 * 5
|
||||
);
|
||||
}
|
||||
|
||||
@ -66,7 +67,8 @@ public class Outlawed extends Appliance {
|
||||
|
||||
public Status getLawStatus(Player player) {
|
||||
return playerStatusMap.computeIfAbsent(player, p -> {
|
||||
if(localConfig().getStringList(voluntarilyEntry).contains(p.getUniqueId().toString())) return Status.VOLUNTARILY;
|
||||
if(localConfig().getStringList(voluntarilyEntry).contains(p.getUniqueId().toString()))
|
||||
return Status.VOLUNTARILY;
|
||||
return Status.DISABLED;
|
||||
});
|
||||
}
|
||||
@ -99,7 +101,7 @@ public class Outlawed extends Appliance {
|
||||
}
|
||||
|
||||
public Component getStatusDescription(Status status) {
|
||||
return switch (status) {
|
||||
return switch(status) {
|
||||
case DISABLED -> Component.text("Vogelfreistatus inaktiv: ", NamedTextColor.GREEN)
|
||||
.append(Component.text("Es gelten die Standard Regeln!", NamedTextColor.GOLD));
|
||||
|
||||
|
@ -20,7 +20,7 @@ public class OutlawedCommand extends ApplianceCommand.PlayerChecked<Outlawed> {
|
||||
getAppliance()
|
||||
.getStatusDescription(getAppliance().getLawStatus(getPlayer()))
|
||||
);
|
||||
} catch (OutlawChangeNotPermitted e) {
|
||||
} catch(OutlawChangeNotPermitted e) {
|
||||
sender.sendMessage(Component.text(e.getMessage(), NamedTextColor.RED));
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,10 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PanicBan extends Appliance {
|
||||
private final Map<UUID, Long> panicBans = new HashMap<>();
|
||||
|
@ -12,6 +12,7 @@ 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);
|
||||
|
@ -8,11 +8,11 @@ import eu.mhsl.craftattack.spawn.appliances.projectStart.command.ProjectStartRes
|
||||
import eu.mhsl.craftattack.spawn.appliances.projectStart.listener.NoAdvancementsListener;
|
||||
import eu.mhsl.craftattack.spawn.appliances.projectStart.listener.PlayerInvincibleListener;
|
||||
import eu.mhsl.craftattack.spawn.config.Configuration;
|
||||
import eu.mhsl.craftattack.spawn.util.IteratorUtil;
|
||||
import eu.mhsl.craftattack.spawn.util.entity.PlayerUtils;
|
||||
import eu.mhsl.craftattack.spawn.util.world.BlockCycle;
|
||||
import eu.mhsl.craftattack.spawn.util.text.ComponentUtil;
|
||||
import eu.mhsl.craftattack.spawn.util.text.Countdown;
|
||||
import eu.mhsl.craftattack.spawn.util.IteratorUtil;
|
||||
import eu.mhsl.craftattack.spawn.util.world.BlockCycle;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
@ -35,13 +35,17 @@ public class Report extends Appliance {
|
||||
}
|
||||
|
||||
private final URI apiEndpoint;
|
||||
|
||||
public Report() {
|
||||
super("report");
|
||||
this.apiEndpoint = URI.create(Objects.requireNonNull(localConfig().getString("api")));
|
||||
}
|
||||
|
||||
private record Request(@NotNull UUID reporter, @Nullable UUID reported, String reason) {}
|
||||
private record Response(@NotNull String url) {}
|
||||
private record Request(@NotNull UUID reporter, @Nullable UUID reported, String reason) {
|
||||
}
|
||||
|
||||
private record Response(@NotNull String url) {
|
||||
}
|
||||
|
||||
public void reportToUnknown(@NotNull Player issuer) {
|
||||
Request request = new Request(issuer.getUniqueId(), null, "");
|
||||
@ -72,7 +76,7 @@ public class Report extends Appliance {
|
||||
|
||||
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
||||
this.printResultMessage(issuer, httpResponse);
|
||||
} catch (IOException | InterruptedException e) {
|
||||
} catch(IOException | InterruptedException e) {
|
||||
issuer.sendMessage(
|
||||
Component.text("Internal server description: " + e.getMessage()).color(NamedTextColor.RED)
|
||||
);
|
||||
@ -81,7 +85,7 @@ public class Report extends Appliance {
|
||||
}
|
||||
|
||||
private void printResultMessage(Player issuer, HttpResponse<String> httpResponse) {
|
||||
switch (httpResponse.statusCode()) {
|
||||
switch(httpResponse.statusCode()) {
|
||||
case 201:
|
||||
Response response = new Gson().fromJson(httpResponse.body(), Response.class);
|
||||
issuer.sendMessage(
|
||||
|
@ -1,7 +1,6 @@
|
||||
package eu.mhsl.craftattack.spawn.appliances.report;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||
import eu.mhsl.craftattack.spawn.appliances.report.Report;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -4,9 +4,9 @@ import eu.mhsl.craftattack.spawn.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||
import eu.mhsl.craftattack.spawn.appliances.restart.command.CancelRestartCommand;
|
||||
import eu.mhsl.craftattack.spawn.appliances.restart.command.ScheduleRestartCommand;
|
||||
import eu.mhsl.craftattack.spawn.util.IteratorUtil;
|
||||
import eu.mhsl.craftattack.spawn.util.text.Countdown;
|
||||
import eu.mhsl.craftattack.spawn.util.text.DisconnectInfo;
|
||||
import eu.mhsl.craftattack.spawn.util.IteratorUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -24,7 +24,7 @@ public class Restart extends Appliance {
|
||||
public void scheduleRestart() {
|
||||
try {
|
||||
this.countdown.start();
|
||||
} catch (IllegalStateException e) {
|
||||
} catch(IllegalStateException e) {
|
||||
throw new ApplianceCommand.Error(e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -33,7 +33,7 @@ public class Restart extends Appliance {
|
||||
try {
|
||||
this.countdown.cancel();
|
||||
this.announce(Component.text("Der geplante Serverneustart wurde abgebrochen!", NamedTextColor.RED));
|
||||
} catch (IllegalStateException e) {
|
||||
} catch(IllegalStateException e) {
|
||||
throw new ApplianceCommand.Error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,9 @@ public class Settings extends Appliance {
|
||||
return Main.instance().getAppliance(Settings.class);
|
||||
}
|
||||
|
||||
public record OpenSettingsInventory(Inventory inventory, List<Setting<?>> settings) {}
|
||||
public record OpenSettingsInventory(Inventory inventory, List<Setting<?>> settings) {
|
||||
}
|
||||
|
||||
private final WeakHashMap<Player, OpenSettingsInventory> openSettingsInventories = new WeakHashMap<>();
|
||||
private final WeakHashMap<Player, List<Setting<?>>> settingsCache = new WeakHashMap<>();
|
||||
|
||||
@ -49,8 +51,10 @@ public class Settings extends Appliance {
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
|
||||
if(!clazz.equals(setting.dataType())) throw new IllegalStateException("Tried to retrieve Setting with Datatype " + clazz.getSimpleName() + " but expected " + setting.dataType().getSimpleName());
|
||||
if(!clazz.isInstance(setting.state())) throw new ClassCastException(clazz.getSimpleName() + " is not an instance of " + setting.dataType().getSimpleName());
|
||||
if(!clazz.equals(setting.dataType()))
|
||||
throw new IllegalStateException("Tried to retrieve Setting with Datatype " + clazz.getSimpleName() + " but expected " + setting.dataType().getSimpleName());
|
||||
if(!clazz.isInstance(setting.state()))
|
||||
throw new ClassCastException(clazz.getSimpleName() + " is not an instance of " + setting.dataType().getSimpleName());
|
||||
return clazz.cast(setting.state());
|
||||
}
|
||||
|
||||
|
@ -4,9 +4,9 @@ import eu.mhsl.craftattack.spawn.Main;
|
||||
import eu.mhsl.craftattack.spawn.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.appliances.report.Report;
|
||||
import eu.mhsl.craftattack.spawn.appliances.settings.Settings;
|
||||
import eu.mhsl.craftattack.spawn.util.IteratorUtil;
|
||||
import eu.mhsl.craftattack.spawn.util.statistics.NetworkMonitor;
|
||||
import eu.mhsl.craftattack.spawn.util.text.ComponentUtil;
|
||||
import eu.mhsl.craftattack.spawn.util.IteratorUtil;
|
||||
import eu.mhsl.craftattack.spawn.util.text.RainbowComponent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
@ -11,6 +11,7 @@ public class TitleClear extends Appliance {
|
||||
public void clearTitle(Player player) {
|
||||
player.clearTitle();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected List<Listener> eventHandlers() {
|
||||
|
@ -10,7 +10,7 @@ public class PlayerJoinListener extends ApplianceListener<Whitelist> {
|
||||
public void preLoginEvent(PlayerLoginEvent preLoginEvent) {
|
||||
try {
|
||||
getAppliance().integrityCheck(preLoginEvent.getPlayer());
|
||||
} catch (DisconnectInfo.Throwable e) {
|
||||
} catch(DisconnectInfo.Throwable e) {
|
||||
preLoginEvent.disallow(
|
||||
PlayerLoginEvent.Result.KICK_WHITELIST,
|
||||
e.getDisconnectScreen().getComponent()
|
||||
|
@ -23,11 +23,16 @@ import java.time.Instant;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Whitelist extends Appliance {
|
||||
private record UserData(UUID uuid, String username, String firstname, String lastname, Long banned_until, Long outlawed_until) {}
|
||||
private record UserData(UUID uuid, String username, String firstname, String lastname, Long banned_until,
|
||||
Long outlawed_until) {
|
||||
}
|
||||
|
||||
private final URI apiEndpoint = URI.create(Objects.requireNonNull(localConfig().getString("api")));
|
||||
|
||||
@ -73,9 +78,9 @@ public class Whitelist extends Appliance {
|
||||
player.getUniqueId()
|
||||
);
|
||||
|
||||
} catch (DisconnectInfo.Throwable e) {
|
||||
} catch(DisconnectInfo.Throwable e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
Main.instance().getLogger().log(Level.SEVERE, e, e::getMessage);
|
||||
throw new DisconnectInfo.Throwable(
|
||||
"Interner Serverfehler",
|
||||
@ -115,21 +120,22 @@ public class Whitelist extends Appliance {
|
||||
|
||||
return new Gson().fromJson(httpResponse.body(), UserData.class);
|
||||
|
||||
} catch (IOException | InterruptedException | URISyntaxException e) {
|
||||
} catch(IOException | InterruptedException | URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpApi(HttpServer.ApiBuilder apiBuilder) {
|
||||
record User(UUID user) {}
|
||||
record User(UUID user) {
|
||||
}
|
||||
apiBuilder.post("update", User.class, (user, request) -> {
|
||||
Main.instance().getLogger().info(String.format("API Triggered Profile update for %s", user.user));
|
||||
Player player = Bukkit.getPlayer(user.user);
|
||||
if(player != null) {
|
||||
try {
|
||||
this.integrityCheck(player);
|
||||
} catch (DisconnectInfo.Throwable e) {
|
||||
} catch(DisconnectInfo.Throwable e) {
|
||||
e.getDisconnectScreen().applyKick(player);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package eu.mhsl.craftattack.spawn.appliances.worldmuseum;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||
import eu.mhsl.craftattack.spawn.appliances.worldmuseum.WorldMuseum;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -3,15 +3,16 @@ package eu.mhsl.craftattack.spawn.appliances.worldmuseum;
|
||||
import eu.mhsl.craftattack.spawn.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||
import eu.mhsl.craftattack.spawn.util.entity.DisplayVillager;
|
||||
import eu.mhsl.craftattack.spawn.util.server.Floodgate;
|
||||
import eu.mhsl.craftattack.spawn.util.server.PluginMessage;
|
||||
import eu.mhsl.craftattack.spawn.util.listener.DismissInventoryOpenFromHolder;
|
||||
import eu.mhsl.craftattack.spawn.util.listener.PlayerInteractAtEntityEventListener;
|
||||
import eu.mhsl.craftattack.spawn.util.server.Floodgate;
|
||||
import eu.mhsl.craftattack.spawn.util.server.PluginMessage;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.geysermc.cumulus.form.SimpleForm;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -36,6 +37,7 @@ public class WorldMuseum extends Appliance {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public void updateVillagerPosition(Location location) {
|
||||
this.villager.updateLocation(location);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public class Configuration {
|
||||
public static void saveChanges() {
|
||||
try {
|
||||
cfg.save(configFile);
|
||||
} catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
Bukkit.getLogger().warning("Could not save configuration: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public class DisplayVillager {
|
||||
ChunkUtils.loadChunkAtLocation(this.location);
|
||||
this.villager = (Villager) this.location.getWorld().getEntity(uuid);
|
||||
Objects.requireNonNull(this.villager);
|
||||
} catch (NullPointerException | IllegalArgumentException e) {
|
||||
} catch(NullPointerException | IllegalArgumentException e) {
|
||||
this.villager = getBaseVillager();
|
||||
villagerCreator.accept(this.villager);
|
||||
}
|
||||
@ -51,6 +51,7 @@ public class DisplayVillager {
|
||||
public static class ConfigBound {
|
||||
private final DisplayVillager villager;
|
||||
private final ConfigurationSection config;
|
||||
|
||||
public ConfigBound(ConfigurationSection configurationSection, Consumer<Villager> villagerCreator) {
|
||||
this.config = configurationSection;
|
||||
|
||||
|
@ -11,7 +11,7 @@ public class PlayerUtils {
|
||||
for(Material material : Material.values()) {
|
||||
try {
|
||||
player.setStatistic(statistic, material, 0);
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch(IllegalArgumentException e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -19,14 +19,15 @@ public class PlayerUtils {
|
||||
for(EntityType entityType : EntityType.values()) {
|
||||
try {
|
||||
player.setStatistic(statistic, entityType, 0);
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch(IllegalArgumentException e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
player.setStatistic(statistic, 0);
|
||||
} catch (IllegalArgumentException ignored){}
|
||||
} catch(IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ public class PlayerInteractAtEntityEventListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractAtEntityEvent event) {
|
||||
if (!event.getRightClicked().getUniqueId().equals(this.interactableEntityUUID)) return;
|
||||
if(!event.getRightClicked().getUniqueId().equals(this.interactableEntityUUID)) return;
|
||||
this.callback.accept(event);
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import java.util.function.Consumer;
|
||||
|
||||
public class Floodgate {
|
||||
private static final FloodgateApi instance = FloodgateApi.getInstance();
|
||||
|
||||
public static boolean isBedrock(Player p) {
|
||||
return instance.isFloodgatePlayer(p.getUniqueId());
|
||||
}
|
||||
|
@ -37,8 +37,11 @@ public class NetworkMonitor {
|
||||
);
|
||||
}
|
||||
|
||||
public record Traffic(long rxBytes, long txBytes) {}
|
||||
public record Packets(long rxCount, long txCount) {}
|
||||
public record Traffic(long rxBytes, long txBytes) {
|
||||
}
|
||||
|
||||
public record Packets(long rxCount, long txCount) {
|
||||
}
|
||||
|
||||
public Traffic getTraffic() {
|
||||
return new Traffic(rxBytesLastDuration, txBytesLastDuration);
|
||||
@ -74,7 +77,7 @@ public class NetworkMonitor {
|
||||
String path = String.format("/sys/class/net/%s/statistics/%s", this.iFace, statistic);
|
||||
String content = new String(Files.readAllBytes(Paths.get(path)));
|
||||
return Long.parseLong(content.trim());
|
||||
} catch (IOException e) {
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException("Failed recieving Network statistic", e);
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,6 @@ public class ColorUtil {
|
||||
hue = Math.abs(hue - 120);
|
||||
}
|
||||
|
||||
return TextColor.color(Color.getHSBColor(hue/360, 1f, 1f).getRGB());
|
||||
return TextColor.color(Color.getHSBColor(hue / 360, 1f, 1f).getRGB());
|
||||
}
|
||||
}
|
||||
|
@ -26,15 +26,15 @@ public class ComponentUtil {
|
||||
String[] words = text.split(" ");
|
||||
StringBuilder line = new StringBuilder();
|
||||
|
||||
for (String word : words) {
|
||||
if (line.length() + word.length() + 1 > charactersPerLine) {
|
||||
for(String word : words) {
|
||||
if(line.length() + word.length() + 1 > charactersPerLine) {
|
||||
lines.add(line.toString().trim());
|
||||
line = new StringBuilder();
|
||||
}
|
||||
line.append(word).append(" ");
|
||||
}
|
||||
|
||||
if (!line.isEmpty()) {
|
||||
if(!line.isEmpty()) {
|
||||
lines.add(line.toString().trim());
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ public class ComponentUtil {
|
||||
public static Component createRainbowText(String text, int step) {
|
||||
Component builder = Component.empty();
|
||||
int hue = 0;
|
||||
for (char c : text.toCharArray()) {
|
||||
for(char c : text.toCharArray()) {
|
||||
TextColor color = TextColor.color(Color.getHSBColor((float) hue / 360, 1, 1).getRGB());
|
||||
builder = builder.append(Component.text(c).color(color));
|
||||
hue += step;
|
||||
|
@ -21,8 +21,11 @@ public class Countdown {
|
||||
private final Runnable onDone;
|
||||
|
||||
|
||||
public record AnnouncementData(int count, String unit) {}
|
||||
public record CustomAnnouncements(Function<Integer, Boolean> test, Consumer<Integer> task) {}
|
||||
public record AnnouncementData(int count, String unit) {
|
||||
}
|
||||
|
||||
public record CustomAnnouncements(Function<Integer, Boolean> test, Consumer<Integer> task) {
|
||||
}
|
||||
|
||||
public Countdown(int countdownFrom, Function<AnnouncementData, Component> announcementBuilder, Consumer<Component> announcementConsumer, Runnable onDone) {
|
||||
this.countdownFrom = countdownFrom;
|
||||
|
@ -5,7 +5,7 @@ public class DataSizeConverter {
|
||||
double kbits = bytes * 8.0 / 1000.0;
|
||||
double mbits = kbits / 1000.0;
|
||||
|
||||
if (mbits >= 1) {
|
||||
if(mbits >= 1) {
|
||||
return String.format("%.2f Mbit", mbits);
|
||||
} else {
|
||||
return String.format("%.2f Kbit", kbits);
|
||||
|
@ -12,6 +12,7 @@ public record DisconnectInfo(String error, String description, String help, UUID
|
||||
public void applyKick(Player player) {
|
||||
Bukkit.getScheduler().runTask(Main.instance(), () -> player.kick(this.getComponent()));
|
||||
}
|
||||
|
||||
public Component getComponent() {
|
||||
return Component.text()
|
||||
.appendNewline().appendNewline()
|
||||
|
@ -3,9 +3,9 @@ package eu.mhsl.craftattack.spawn.util.text;
|
||||
public class NumberAbbreviation {
|
||||
public static <T extends Number & Comparable<T>> String abbreviateNumber(T number) {
|
||||
double value = number.doubleValue();
|
||||
if (value >= 1_000_000) {
|
||||
if(value >= 1_000_000) {
|
||||
return String.format("%.1fM", value / 1_000_000.0);
|
||||
} else if (value >= 1_000) {
|
||||
} else if(value >= 1_000) {
|
||||
return String.format("%.1fk", value / 1_000.0);
|
||||
} else {
|
||||
return number.toString();
|
||||
|
@ -20,7 +20,7 @@ public class RainbowComponent {
|
||||
public Component getRainbowState() {
|
||||
Component builder = Component.empty();
|
||||
int hue = this.hueOffset;
|
||||
for (char c : text.toCharArray()) {
|
||||
for(char c : text.toCharArray()) {
|
||||
TextColor color = TextColor.color(Color.getHSBColor((float) hue / 360, 1, 1).getRGB());
|
||||
builder = builder.append(Component.text(c).color(color));
|
||||
hue += density;
|
||||
|
@ -4,7 +4,8 @@ import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class ChunkUtils {
|
||||
public record ChunkPos(int x, int z) {}
|
||||
public record ChunkPos(int x, int z) {
|
||||
}
|
||||
|
||||
public static Chunk loadChunkAtLocation(Location location) {
|
||||
ChunkPos chunkPos = locationToChunk(location);
|
||||
|
@ -27,9 +27,9 @@ commands:
|
||||
help:
|
||||
spawn:
|
||||
teamspeak:
|
||||
aliases: ["ts"]
|
||||
aliases: [ "ts" ]
|
||||
discord:
|
||||
aliases: ["dc"]
|
||||
aliases: [ "dc" ]
|
||||
setPlayerLimit:
|
||||
scheduleRestart:
|
||||
cancelRestart:
|
||||
|
Loading…
x
Reference in New Issue
Block a user