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