added possibility to disable appliances
This commit is contained in:
@@ -3,6 +3,7 @@ package eu.mhsl.craftattack.spawn.event.appliances.deathrun;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.event.appliances.eventController.Event;
|
||||
|
||||
@Appliance.Flags(autoload = false)
|
||||
public class Deathrun extends Appliance implements Event {
|
||||
@Override
|
||||
public String displayName() {
|
||||
|
||||
@@ -2,4 +2,5 @@ package eu.mhsl.craftattack.spawn.event.appliances.eventController;
|
||||
|
||||
public interface Event {
|
||||
String displayName();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package eu.mhsl.craftattack.spawn.event.appliances.eventController;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||
import eu.mhsl.craftattack.spawn.event.appliances.eventController.commands.EventCommand;
|
||||
@@ -8,6 +9,29 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
public class EventController extends Appliance {
|
||||
private List<Appliance> eventAppliances = null;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.eventAppliances = Main.instance().getAppliances().stream()
|
||||
.filter(appliance -> appliance instanceof Event)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public List<Appliance> getEventAppliances() {
|
||||
if(eventAppliances == null) throw new IllegalStateException("Event appliances were not initialized");
|
||||
return eventAppliances;
|
||||
}
|
||||
|
||||
public void enableEvent(Appliance event) {
|
||||
getEventAppliances().forEach(appliance -> appliance.disableSequence(Main.instance()));
|
||||
Main.instance().restartAppliance(event.getClass());
|
||||
}
|
||||
|
||||
public void disableEvent(Appliance event) {
|
||||
event.disableSequence(Main.instance());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<ApplianceCommand<?>> commands() {
|
||||
return List.of(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package eu.mhsl.craftattack.spawn.event.appliances.eventController.commands;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||
import eu.mhsl.craftattack.spawn.event.appliances.eventController.EventController;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -24,28 +25,30 @@ public class EventCommand extends ApplianceCommand<EventController> {
|
||||
break;
|
||||
}
|
||||
case "start": {
|
||||
sender.sendMessage("start");
|
||||
break;
|
||||
}
|
||||
case "pause": {
|
||||
sender.sendMessage("pause");
|
||||
break;
|
||||
}
|
||||
case "resume": {
|
||||
sender.sendMessage("resume");
|
||||
if(args.length == 1) throw new Error("Not enough arguments for start.");
|
||||
this.getAppliance().enableEvent(findApplianceFromString(args[1]));
|
||||
break;
|
||||
}
|
||||
case "stop": {
|
||||
sender.sendMessage("stop");
|
||||
if(args.length == 1) throw new Error("Not enough arguments for stop.");
|
||||
this.getAppliance().disableEvent(findApplianceFromString(args[1]));
|
||||
break;
|
||||
}
|
||||
default: throw new Error("No such option: '%s' !".formatted(args[0]));
|
||||
}
|
||||
}
|
||||
|
||||
private Appliance findApplianceFromString(String name) {
|
||||
System.out.println(this.getAppliance().getEventAppliances());
|
||||
return this.getAppliance().getEventAppliances().stream()
|
||||
.filter(appliance -> appliance.getClass().getSimpleName().equalsIgnoreCase(name))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
}
|
||||
|
||||
@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", "start", "pause", "resume", "stop");
|
||||
if(args.length == 1) return List.of("select", "start", "stop");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user