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