removed possibility for multiple events
This commit is contained in:
@@ -23,6 +23,12 @@ public class Deathrun extends Appliance implements Event, Scorable {
|
||||
world.getWorldBorder().setSize(20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
World world = Bukkit.getWorlds().getFirst();
|
||||
world.getWorldBorder().setSize(world.getWorldBorder().getMaxSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
Title title = Title.title(Component.text("Start"), Component.text("Erreiche die höchste x-Koordinate!"));
|
||||
|
||||
@@ -6,12 +6,11 @@ import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||
import eu.mhsl.craftattack.spawn.event.appliances.eventController.commands.EventCommand;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EventController extends Appliance {
|
||||
private List<Appliance> eventAppliances = null;
|
||||
private final List<Event> selectedEvents = new ArrayList<>();
|
||||
private Event selectedEvent = null;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@@ -27,30 +26,33 @@ public class EventController extends Appliance {
|
||||
|
||||
public void loadEvent(Appliance appliance) {
|
||||
if(!(appliance instanceof Event event)) throw new IllegalArgumentException("Appliance has to implement Event.");
|
||||
this.getEventAppliances().forEach(appliance1 -> appliance1.disableSequence(Main.instance()));
|
||||
this.unloadEvent();
|
||||
Main.instance().restartAppliance(appliance.getClass());
|
||||
this.selectedEvents.add(event);
|
||||
this.selectedEvent = event;
|
||||
}
|
||||
|
||||
public void unloadEvent(Appliance appliance) {
|
||||
if(!(appliance instanceof Event event)) throw new Error("Appliance does not implement Event.");
|
||||
event.stop();
|
||||
appliance.disableSequence(Main.instance());
|
||||
this.selectedEvents.remove(event);
|
||||
public void unloadEvent() {
|
||||
if(this.selectedEvent == null) return;
|
||||
this.selectedEvent.stop();
|
||||
if(this.selectedEvent instanceof Appliance appliance) {
|
||||
appliance.disableSequence(Main.instance());
|
||||
}
|
||||
this.selectedEvent = null;
|
||||
}
|
||||
|
||||
public void startEvents() {
|
||||
this.selectedEvents.forEach(Event::start);
|
||||
public void startEvent() {
|
||||
if(this.selectedEvent == null) throw new ApplianceCommand.Error("There is no event selected!");
|
||||
this.selectedEvent.start();
|
||||
}
|
||||
|
||||
public void stopEvents() {
|
||||
this.selectedEvents.forEach(Event::stop);
|
||||
public void stopEvent() {
|
||||
if(this.selectedEvent == null) throw new ApplianceCommand.Error("There is no event selected!");
|
||||
this.selectedEvent.stop();
|
||||
}
|
||||
|
||||
public List<String> getSelectedEvents() {
|
||||
return this.selectedEvents.stream()
|
||||
.map(event -> event.getClass().getSimpleName().toLowerCase())
|
||||
.toList();
|
||||
public String getSelectedEvent() {
|
||||
if(this.selectedEvent == null) return "nothing selected";
|
||||
return this.selectedEvent.getClass().getSimpleName().toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,26 +20,25 @@ public class EventCommand extends ApplianceCommand<EventController> {
|
||||
if(args.length == 0) throw new Error("No argument selected!");
|
||||
|
||||
switch(args[0]) {
|
||||
case "unselect": {
|
||||
if(args.length == 1) throw new Error("Not enough arguments for unselect.");
|
||||
this.getAppliance().unloadEvent(this.findApplianceFromString(args[1]));
|
||||
case "unload": {
|
||||
this.getAppliance().unloadEvent();
|
||||
break;
|
||||
}
|
||||
case "select": {
|
||||
case "load": {
|
||||
if(args.length == 1) throw new Error("Not enough arguments for select.");
|
||||
this.getAppliance().loadEvent(this.findApplianceFromString(args[1]));
|
||||
break;
|
||||
}
|
||||
case "list": {
|
||||
sender.sendMessage("These Events are currently selected: \n%s".formatted(this.getAppliance().getSelectedEvents()));
|
||||
case "selected": {
|
||||
sender.sendMessage("This Event is currently selected: %s".formatted(this.getAppliance().getSelectedEvent()));
|
||||
break;
|
||||
}
|
||||
case "start": {
|
||||
this.getAppliance().startEvents();
|
||||
this.getAppliance().startEvent();
|
||||
break;
|
||||
}
|
||||
case "stop": {
|
||||
this.getAppliance().stopEvents();
|
||||
this.getAppliance().stopEvent();
|
||||
break;
|
||||
}
|
||||
default: throw new Error("No such option: '%s' !".formatted(args[0]));
|
||||
@@ -56,8 +55,8 @@ public class EventCommand extends ApplianceCommand<EventController> {
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if(args.length == 1) return List.of("select", "unselect", "list", "start", "stop");
|
||||
if(args.length == 2 && List.of("select", "unselect").contains(args[0])) return this.getAppliance().getEventAppliances().stream()
|
||||
if(args.length == 1) return List.of("load", "unload", "selected", "start", "stop");
|
||||
if(args.length == 2 && args[0].equals("load")) return this.getAppliance().getEventAppliances().stream()
|
||||
.map(appliance -> appliance.getClass().getSimpleName().toLowerCase())
|
||||
.toList();
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user