Added base event-system
Added Help
This commit is contained in:
parent
4e29e3b7fe
commit
889c6b77a5
@ -5,6 +5,8 @@ import eu.mhsl.craftattack.spawn.appliances.adminMarker.AdminMarker;
|
|||||||
import eu.mhsl.craftattack.spawn.appliances.chatMessages.ChatMessages;
|
import eu.mhsl.craftattack.spawn.appliances.chatMessages.ChatMessages;
|
||||||
import eu.mhsl.craftattack.spawn.appliances.countdown.Countdown;
|
import eu.mhsl.craftattack.spawn.appliances.countdown.Countdown;
|
||||||
import eu.mhsl.craftattack.spawn.appliances.debug.Debug;
|
import eu.mhsl.craftattack.spawn.appliances.debug.Debug;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliances.event.Event;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliances.help.Help;
|
||||||
import eu.mhsl.craftattack.spawn.appliances.report.Report;
|
import eu.mhsl.craftattack.spawn.appliances.report.Report;
|
||||||
import eu.mhsl.craftattack.spawn.appliances.tablist.Tablist;
|
import eu.mhsl.craftattack.spawn.appliances.tablist.Tablist;
|
||||||
import eu.mhsl.craftattack.spawn.appliances.titleClear.TitleClear;
|
import eu.mhsl.craftattack.spawn.appliances.titleClear.TitleClear;
|
||||||
@ -35,12 +37,15 @@ public final class Main extends JavaPlugin {
|
|||||||
new Tablist(),
|
new Tablist(),
|
||||||
new ChatMessages(),
|
new ChatMessages(),
|
||||||
new Report(),
|
new Report(),
|
||||||
|
new Event(),
|
||||||
|
new Help(),
|
||||||
new Debug()
|
new Debug()
|
||||||
);
|
);
|
||||||
Bukkit.getLogger().info("Loading appliances...");
|
Bukkit.getLogger().info("Loading appliances...");
|
||||||
appliances.forEach(appliance -> {
|
appliances.forEach(appliance -> {
|
||||||
appliance.initialize(this);
|
Bukkit.getLogger().info("Enabling " + appliance.getClass().getSimpleName());
|
||||||
appliance.onEnable();
|
appliance.onEnable();
|
||||||
|
appliance.initialize(this);
|
||||||
});
|
});
|
||||||
Bukkit.getLogger().info("Loaded " + appliances.size() + " appliances!");
|
Bukkit.getLogger().info("Loaded " + appliances.size() + " appliances!");
|
||||||
|
|
||||||
@ -49,12 +54,15 @@ public final class Main extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
Bukkit.getLogger().info("Disabling appliances...");
|
||||||
appliances.forEach(appliance -> {
|
appliances.forEach(appliance -> {
|
||||||
|
Bukkit.getLogger().info("Disabling " + appliance.getClass().getSimpleName());
|
||||||
appliance.onDisable();
|
appliance.onDisable();
|
||||||
appliance.destruct(this);
|
appliance.destruct(this);
|
||||||
});
|
});
|
||||||
HandlerList.unregisterAll(this);
|
HandlerList.unregisterAll(this);
|
||||||
Bukkit.getScheduler().cancelTasks(this);
|
Bukkit.getScheduler().cancelTasks(this);
|
||||||
|
Bukkit.getLogger().info("Disabled " + appliances.size() + " appliances!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Appliance> T getAppliance(Class<T> clazz) {
|
public <T extends Appliance> T getAppliance(Class<T> clazz) {
|
||||||
@ -66,6 +74,9 @@ public final class Main extends JavaPlugin {
|
|||||||
return (Class<T>) ((ParameterizedType) clazz.getGenericSuperclass()).getActualTypeArguments()[0];
|
return (Class<T>) ((ParameterizedType) clazz.getGenericSuperclass()).getActualTypeArguments()[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Appliance> getAppliances() {
|
||||||
|
return appliances;
|
||||||
|
}
|
||||||
|
|
||||||
public static Main instance() {
|
public static Main instance() {
|
||||||
return instance;
|
return instance;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package eu.mhsl.craftattack.spawn.appliance;
|
package eu.mhsl.craftattack.spawn.appliance;
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.Main;
|
|
||||||
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;
|
||||||
@ -18,12 +17,10 @@ import java.util.Optional;
|
|||||||
/**
|
/**
|
||||||
* Utility class which enables command name definition over a constructor.
|
* Utility class which enables command name definition over a constructor.
|
||||||
*/
|
*/
|
||||||
public abstract class ApplianceCommand<T extends Appliance> implements ApplianceSupplier<T>, TabCompleter, CommandExecutor {
|
public abstract class ApplianceCommand<T extends Appliance> extends ApplianceSupplier<T> implements TabCompleter, CommandExecutor {
|
||||||
public String commandName;
|
public String commandName;
|
||||||
private final T appliance;
|
protected Component errorMessage = Component.text("Fehler: ").color(NamedTextColor.RED);
|
||||||
protected Component errorMessage = Component.text("Error whilst executing command").color(NamedTextColor.RED);
|
|
||||||
public ApplianceCommand(String command) {
|
public ApplianceCommand(String command) {
|
||||||
this.appliance = Main.instance().getAppliance(Main.getApplianceType(getClass()));
|
|
||||||
this.commandName = command;
|
this.commandName = command;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,9 +33,11 @@ public abstract class ApplianceCommand<T extends Appliance> implements Appliance
|
|||||||
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) {
|
||||||
|
sender.sendMessage(errorMessage.append(Component.text(e.getMessage())));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
sender.sendMessage(errorMessage);
|
sender.sendMessage(errorMessage.append(Component.text("Interner Fehler")));
|
||||||
Bukkit.getLogger().warning("Error executing appliance command " + commandName + " with " + e.getMessage());
|
Bukkit.getLogger().warning("Error executing appliance command " + commandName + ": " + e.getMessage());
|
||||||
e.printStackTrace(System.err);
|
e.printStackTrace(System.err);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -56,17 +55,12 @@ public abstract class ApplianceCommand<T extends Appliance> implements Appliance
|
|||||||
|
|
||||||
protected abstract void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args);
|
protected abstract void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args);
|
||||||
|
|
||||||
@Override
|
|
||||||
public T getAppliance() {
|
|
||||||
return appliance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for command which can only be used as a Player. You can access the executing player with the getPlayer() method.
|
* Utility class for command which can only be used as a Player. You can access the executing player with the getPlayer() method.
|
||||||
*/
|
*/
|
||||||
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("This command can only be executed as an Player!").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);
|
||||||
}
|
}
|
||||||
@ -95,4 +89,10 @@ public abstract class ApplianceCommand<T extends Appliance> implements Appliance
|
|||||||
return this.player;
|
return this.player;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Error extends RuntimeException {
|
||||||
|
public Error(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package eu.mhsl.craftattack.spawn.appliance;
|
package eu.mhsl.craftattack.spawn.appliance;
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.Main;
|
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -8,14 +7,6 @@ import org.bukkit.event.Listener;
|
|||||||
* 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> implements ApplianceSupplier<T>, Listener {
|
public abstract class ApplianceListener<T extends Appliance> extends ApplianceSupplier<T> implements Listener {
|
||||||
private final T appliance;
|
|
||||||
protected ApplianceListener() {
|
|
||||||
this.appliance = Main.instance().getAppliance(Main.getApplianceType(getClass()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public T getAppliance() {
|
|
||||||
return appliance;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,5 +1,16 @@
|
|||||||
package eu.mhsl.craftattack.spawn.appliance;
|
package eu.mhsl.craftattack.spawn.appliance;
|
||||||
|
|
||||||
public interface ApplianceSupplier<T extends Appliance> {
|
import eu.mhsl.craftattack.spawn.Main;
|
||||||
T getAppliance();
|
|
||||||
|
public class ApplianceSupplier<T extends Appliance> implements IApplianceSupplier<T> {
|
||||||
|
private final T appliance;
|
||||||
|
|
||||||
|
public ApplianceSupplier() {
|
||||||
|
this.appliance = Main.instance().getAppliance(Main.getApplianceType(getClass()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T getAppliance() {
|
||||||
|
return this.appliance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.appliance;
|
||||||
|
|
||||||
|
public interface IApplianceSupplier<T extends Appliance> {
|
||||||
|
T getAppliance();
|
||||||
|
}
|
@ -2,6 +2,7 @@ package eu.mhsl.craftattack.spawn.appliances.debug;
|
|||||||
|
|
||||||
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.debug.command.AppliancesCommand;
|
||||||
import eu.mhsl.craftattack.spawn.appliances.debug.command.UserInfoCommand;
|
import eu.mhsl.craftattack.spawn.appliances.debug.command.UserInfoCommand;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -9,6 +10,9 @@ import java.util.List;
|
|||||||
public class Debug extends Appliance {
|
public class Debug extends Appliance {
|
||||||
@Override
|
@Override
|
||||||
protected @NotNull List<ApplianceCommand<?>> commands() {
|
protected @NotNull List<ApplianceCommand<?>> commands() {
|
||||||
return List.of(new UserInfoCommand());
|
return List.of(
|
||||||
|
new UserInfoCommand(),
|
||||||
|
new AppliancesCommand()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.appliances.debug.command;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.Main;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliances.debug.Debug;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.ComponentBuilder;
|
||||||
|
import net.kyori.adventure.text.TextComponent;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class AppliancesCommand extends ApplianceCommand<Debug> {
|
||||||
|
public AppliancesCommand() {
|
||||||
|
super("appliances");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
ComponentBuilder<TextComponent, TextComponent.Builder> componentBuilder = Component.text()
|
||||||
|
.append(Component.text(Main.instance().getAppliances().size()))
|
||||||
|
.append(Component.text(" appliances loaded:"))
|
||||||
|
.appendNewline()
|
||||||
|
.append(Component.text(Main.instance().getAppliances().stream().map(appliance -> appliance.getClass().getSimpleName()).collect(Collectors.joining(", "))));
|
||||||
|
|
||||||
|
sender.sendMessage(componentBuilder.build());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.appliances.event;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.appliance.Appliance;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliances.event.command.EventCommand;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliances.event.command.EventEndSessionCommand;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliances.event.command.EventOpenSessionCommand;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliances.event.command.MoveEventVillagerCommand;
|
||||||
|
import eu.mhsl.craftattack.spawn.util.DisplayVillager;
|
||||||
|
import eu.mhsl.craftattack.spawn.util.PluginMessage;
|
||||||
|
import eu.mhsl.craftattack.spawn.util.commonListeners.DismissInventoryOpenFromHolder;
|
||||||
|
import eu.mhsl.craftattack.spawn.util.commonListeners.PlayerInteractAtEntityEventListener;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.Villager;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Event extends Appliance {
|
||||||
|
public DisplayVillager.ConfigBound villager;
|
||||||
|
private boolean isOpen = false;
|
||||||
|
|
||||||
|
public Event() {
|
||||||
|
super("event");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
this.villager = new DisplayVillager.ConfigBound(
|
||||||
|
localConfig(),
|
||||||
|
villager -> {
|
||||||
|
villager.customName(Component.text("Events", NamedTextColor.GOLD));
|
||||||
|
villager.setProfession(Villager.Profession.LIBRARIAN);
|
||||||
|
villager.setVillagerType(Villager.Type.SNOW);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void openEvent() {
|
||||||
|
if(isOpen) throw new ApplianceCommand.Error("Es läuft derzeit bereits ein Event!");
|
||||||
|
isOpen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void joinEvent(Player p) {
|
||||||
|
if(!isOpen) {
|
||||||
|
p.sendMessage(Component.text("Zurzeit ist kein Event geöffnet.", NamedTextColor.RED));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PluginMessage.connect(p, localConfig().getString("connect-server-name"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void endEvent() {
|
||||||
|
if(!isOpen) throw new ApplianceCommand.Error("Es läuft derzeit kein Event!");
|
||||||
|
isOpen = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull List<ApplianceCommand<?>> commands() {
|
||||||
|
return List.of(
|
||||||
|
new EventCommand(),
|
||||||
|
new MoveEventVillagerCommand(),
|
||||||
|
new EventOpenSessionCommand(),
|
||||||
|
new EventEndSessionCommand()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull List<Listener> eventHandlers() {
|
||||||
|
return List.of(
|
||||||
|
new PlayerInteractAtEntityEventListener(this.villager.getUniqueId(), playerInteractAtEntityEvent -> joinEvent(playerInteractAtEntityEvent.getPlayer())),
|
||||||
|
new DismissInventoryOpenFromHolder(this.villager.getUniqueId())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.appliances.event.command;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliances.event.Event;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class EventCommand extends ApplianceCommand.PlayerChecked<Event> {
|
||||||
|
public EventCommand() {
|
||||||
|
super("event");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
getAppliance().joinEvent(getPlayer());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.appliances.event.command;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliances.event.Event;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class EventEndSessionCommand extends ApplianceCommand<Event> {
|
||||||
|
public EventEndSessionCommand() {
|
||||||
|
super("eventEndSession");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
getAppliance().endEvent();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.appliances.event.command;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliances.event.Event;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class EventOpenSessionCommand extends ApplianceCommand<Event> {
|
||||||
|
public EventOpenSessionCommand() {
|
||||||
|
super("eventOpenSession");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
getAppliance().openEvent();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.appliances.event.command;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliances.event.Event;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class MoveEventVillagerCommand extends ApplianceCommand.PlayerChecked<Event> {
|
||||||
|
public MoveEventVillagerCommand() {
|
||||||
|
super("moveEventVillager");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
getAppliance().villager.updateLocation(getPlayer().getLocation());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.appliances.help;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.appliance.Appliance;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliances.help.command.HelpCommand;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliances.help.command.SpawnCommand;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliances.help.command.TeamspeakCommand;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Help extends Appliance {
|
||||||
|
public Help() {
|
||||||
|
super("help");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull List<ApplianceCommand<?>> commands() {
|
||||||
|
return List.of(
|
||||||
|
new HelpCommand(),
|
||||||
|
new SpawnCommand(),
|
||||||
|
new TeamspeakCommand()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.appliances.help.command;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliances.help.Help;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class HelpCommand extends ApplianceCommand<Help> {
|
||||||
|
public HelpCommand() {
|
||||||
|
super("help");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
sender.sendMessage(
|
||||||
|
Component.text("Willkommen auf Craftattack!", NamedTextColor.GOLD)
|
||||||
|
.appendNewline()
|
||||||
|
.append(Component.text("Hier ist ein Hilfetext!", NamedTextColor.GRAY))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.appliances.help.command;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliances.help.Help;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
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!");
|
||||||
|
sender.sendMessage(Component.text(Objects.requireNonNull(getAppliance().localConfig().getString(spawnKey)), NamedTextColor.GOLD));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.appliances.help.command;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||||
|
import eu.mhsl.craftattack.spawn.appliances.help.Help;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class 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!");
|
||||||
|
sender.sendMessage(
|
||||||
|
Component.text()
|
||||||
|
.append(Component.text("Joine unserem Teamspeak: ", NamedTextColor.GOLD))
|
||||||
|
.append(getTeamspeakIp(getAppliance().localConfig().getString(teamspeakKey)))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Component getTeamspeakIp(String ip) {
|
||||||
|
return Component.text()
|
||||||
|
.append(Component.text(ip, NamedTextColor.AQUA))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
@ -2,13 +2,11 @@ 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.appliances.worldmuseum.listener.InventoryOpenListener;
|
|
||||||
import eu.mhsl.craftattack.spawn.config.ConfigUtil;
|
|
||||||
import eu.mhsl.craftattack.spawn.config.Configuration;
|
|
||||||
import eu.mhsl.craftattack.spawn.appliances.worldmuseum.command.MoveWorldMuseumVillagerCommand;
|
import eu.mhsl.craftattack.spawn.appliances.worldmuseum.command.MoveWorldMuseumVillagerCommand;
|
||||||
import eu.mhsl.craftattack.spawn.appliances.worldmuseum.listener.PlayerEntityInteractListener;
|
|
||||||
import eu.mhsl.craftattack.spawn.util.DisplayVillager;
|
import eu.mhsl.craftattack.spawn.util.DisplayVillager;
|
||||||
import eu.mhsl.craftattack.spawn.util.PluginMessage;
|
import eu.mhsl.craftattack.spawn.util.PluginMessage;
|
||||||
|
import eu.mhsl.craftattack.spawn.util.commonListeners.DismissInventoryOpenFromHolder;
|
||||||
|
import eu.mhsl.craftattack.spawn.util.commonListeners.PlayerInteractAtEntityEventListener;
|
||||||
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;
|
||||||
@ -18,11 +16,9 @@ import org.bukkit.event.Listener;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class WorldMuseum extends Appliance {
|
public class WorldMuseum extends Appliance {
|
||||||
public DisplayVillager villager;
|
public DisplayVillager.ConfigBound villager;
|
||||||
|
|
||||||
public WorldMuseum() {
|
public WorldMuseum() {
|
||||||
super("worldMuseum");
|
super("worldMuseum");
|
||||||
@ -30,28 +26,17 @@ public class WorldMuseum extends Appliance {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
Location location = ConfigUtil.Position.paseLocation(Objects.requireNonNull(localConfig().getConfigurationSection("villagerLocation")));
|
this.villager = new DisplayVillager.ConfigBound(
|
||||||
this.villager = new DisplayVillager(
|
localConfig(),
|
||||||
UUID.fromString(localConfig().getString("uuid", UUID.randomUUID().toString())),
|
|
||||||
location,
|
|
||||||
villager -> {
|
villager -> {
|
||||||
localConfig().set("uuid", villager.getUniqueId().toString());
|
villager.customName(Component.text("Museum der Welten").color(NamedTextColor.GOLD));
|
||||||
Configuration.saveChanges();
|
villager.setProfession(Villager.Profession.CARTOGRAPHER);
|
||||||
|
villager.setVillagerType(Villager.Type.SNOW);
|
||||||
villager.customName(Component.text("Weltenansicht").color(NamedTextColor.GOLD));
|
|
||||||
villager.setProfession(Villager.Profession.LIBRARIAN);
|
|
||||||
villager.setVillagerType(Villager.Type.SAVANNA);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
public void updateVillagerPosition(Location location) {
|
public void updateVillagerPosition(Location location) {
|
||||||
ConfigUtil.Position.writeLocation(
|
this.villager.updateLocation(location);
|
||||||
Objects.requireNonNull(localConfig().getConfigurationSection("villagerLocation")),
|
|
||||||
location
|
|
||||||
);
|
|
||||||
Configuration.saveChanges();
|
|
||||||
|
|
||||||
this.villager.getVillager().teleport(location);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleVillagerInteraction(Player player) {
|
public void handleVillagerInteraction(Player player) {
|
||||||
@ -67,8 +52,8 @@ public class WorldMuseum extends Appliance {
|
|||||||
@Override
|
@Override
|
||||||
protected @NotNull List<Listener> eventHandlers() {
|
protected @NotNull List<Listener> eventHandlers() {
|
||||||
return List.of(
|
return List.of(
|
||||||
new PlayerEntityInteractListener(),
|
new PlayerInteractAtEntityEventListener(this.villager.getUniqueId(), playerInteractAtEntityEvent -> handleVillagerInteraction(playerInteractAtEntityEvent.getPlayer())),
|
||||||
new InventoryOpenListener()
|
new DismissInventoryOpenFromHolder(this.villager.getUniqueId())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
package eu.mhsl.craftattack.spawn.appliances.worldmuseum.listener;
|
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.appliance.ApplianceListener;
|
|
||||||
import eu.mhsl.craftattack.spawn.appliances.worldmuseum.WorldMuseum;
|
|
||||||
import org.bukkit.entity.Villager;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
|
||||||
|
|
||||||
public class InventoryOpenListener extends ApplianceListener<WorldMuseum> {
|
|
||||||
@EventHandler
|
|
||||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
|
||||||
if(event.getInventory().getHolder() instanceof Villager villager) {
|
|
||||||
event.setCancelled(villager.getUniqueId().equals(getAppliance().villager.getVillager().getUniqueId()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package eu.mhsl.craftattack.spawn.appliances.worldmuseum.listener;
|
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.appliance.ApplianceListener;
|
|
||||||
import eu.mhsl.craftattack.spawn.appliances.worldmuseum.WorldMuseum;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
|
||||||
|
|
||||||
public class PlayerEntityInteractListener extends ApplianceListener<WorldMuseum> {
|
|
||||||
@EventHandler
|
|
||||||
public void onInteract(PlayerInteractAtEntityEvent event) {
|
|
||||||
if (!event.getRightClicked().getUniqueId().equals(getAppliance().villager.getVillager().getUniqueId())) return;
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
getAppliance().handleVillagerInteraction(event.getPlayer());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,9 @@
|
|||||||
package eu.mhsl.craftattack.spawn.util;
|
package eu.mhsl.craftattack.spawn.util;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.config.ConfigUtil;
|
||||||
|
import eu.mhsl.craftattack.spawn.config.Configuration;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Villager;
|
import org.bukkit.entity.Villager;
|
||||||
|
|
||||||
@ -43,4 +46,42 @@ public class DisplayVillager {
|
|||||||
villager.setCustomNameVisible(true);
|
villager.setCustomNameVisible(true);
|
||||||
return villager;
|
return villager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class ConfigBound {
|
||||||
|
private final DisplayVillager villager;
|
||||||
|
private final ConfigurationSection config;
|
||||||
|
public ConfigBound(ConfigurationSection configurationSection, Consumer<Villager> villagerCreator) {
|
||||||
|
this.config = configurationSection;
|
||||||
|
|
||||||
|
Location location = ConfigUtil.Position.paseLocation(Objects.requireNonNull(this.config.getConfigurationSection("villagerLocation")));
|
||||||
|
this.villager = new DisplayVillager(
|
||||||
|
UUID.fromString(this.config.getString("uuid", UUID.randomUUID().toString())),
|
||||||
|
location,
|
||||||
|
villager -> {
|
||||||
|
this.config.set("uuid", villager.getUniqueId().toString());
|
||||||
|
Configuration.saveChanges();
|
||||||
|
|
||||||
|
villagerCreator.accept(villager);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateLocation(Location location) {
|
||||||
|
ConfigUtil.Position.writeLocation(
|
||||||
|
Objects.requireNonNull(this.config.getConfigurationSection("villagerLocation")),
|
||||||
|
location
|
||||||
|
);
|
||||||
|
Configuration.saveChanges();
|
||||||
|
|
||||||
|
this.villager.getVillager().teleport(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Villager getVillager() {
|
||||||
|
return villager.getVillager();
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getUniqueId() {
|
||||||
|
return getVillager().getUniqueId();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.util.commonListeners;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class DismissInventoryOpenFromHolder implements Listener {
|
||||||
|
private final UUID inventoryHolder;
|
||||||
|
|
||||||
|
public DismissInventoryOpenFromHolder(UUID inventoryHolder) {
|
||||||
|
this.inventoryHolder = inventoryHolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||||
|
if(event.getInventory().getHolder() instanceof Entity holder) {
|
||||||
|
if(holder.getUniqueId().equals(this.inventoryHolder)) event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.util.commonListeners;
|
||||||
|
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class PlayerInteractAtEntityEventListener implements Listener {
|
||||||
|
private final UUID interactableEntityUUID;
|
||||||
|
private final Consumer<PlayerInteractAtEntityEvent> callback;
|
||||||
|
|
||||||
|
public PlayerInteractAtEntityEventListener(UUID interactableEntityUUID, Consumer<PlayerInteractAtEntityEvent> callback) {
|
||||||
|
this.interactableEntityUUID = interactableEntityUUID;
|
||||||
|
this.callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInteract(PlayerInteractAtEntityEvent event) {
|
||||||
|
if (!event.getRightClicked().getUniqueId().equals(this.interactableEntityUUID)) return;
|
||||||
|
this.callback.accept(event);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,4 @@
|
|||||||
worldMuseum:
|
worldMuseum:
|
||||||
enabled: false
|
|
||||||
uuid:
|
uuid:
|
||||||
connect-server-name: worldmuseum
|
connect-server-name: worldmuseum
|
||||||
villagerLocation:
|
villagerLocation:
|
||||||
@ -23,3 +22,19 @@ countdown:
|
|||||||
|
|
||||||
report:
|
report:
|
||||||
api: https://mhsl.eu/craftattack/report
|
api: https://mhsl.eu/craftattack/report
|
||||||
|
|
||||||
|
event:
|
||||||
|
api: http://10.20.0.1/
|
||||||
|
connect-server-name: event
|
||||||
|
uuid:
|
||||||
|
villagerLocation:
|
||||||
|
world: world
|
||||||
|
x: 0
|
||||||
|
y: 0
|
||||||
|
z: 0
|
||||||
|
yaw: 0
|
||||||
|
pitch: 0
|
||||||
|
|
||||||
|
help:
|
||||||
|
teamspeak: myserver.com
|
||||||
|
spawn: "Der Weltspawn befindet sich bei x:0 y:0 z:0"
|
@ -18,3 +18,12 @@ commands:
|
|||||||
description: Cancels project countdown
|
description: Cancels project countdown
|
||||||
projectStartReset:
|
projectStartReset:
|
||||||
description: Resets project countdown
|
description: Resets project countdown
|
||||||
|
moveEventVillager:
|
||||||
|
appliances:
|
||||||
|
event:
|
||||||
|
eventOpenSession:
|
||||||
|
eventEndSession:
|
||||||
|
help:
|
||||||
|
spawn:
|
||||||
|
teamspeak:
|
||||||
|
aliases: ["ts"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user