ticketing enable and disable
This commit is contained in:
@ -6,6 +6,7 @@ import eu.mhsl.craftattack.spawn.core.Main;
|
|||||||
import eu.mhsl.craftattack.spawn.core.api.server.HttpServer;
|
import eu.mhsl.craftattack.spawn.core.api.server.HttpServer;
|
||||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.config.Configuration;
|
||||||
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.teams.Teams;
|
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.teams.Teams;
|
||||||
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.teams.VaroTeam;
|
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.teams.VaroTeam;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -29,9 +30,18 @@ public class PlayTimer extends Appliance {
|
|||||||
private final Path saveFile = Paths.get(Main.instance().getDataFolder().getAbsolutePath() + "/playtime.json");
|
private final Path saveFile = Paths.get(Main.instance().getDataFolder().getAbsolutePath() + "/playtime.json");
|
||||||
|
|
||||||
public PlayTimer() {
|
public PlayTimer() {
|
||||||
|
super("playTimer");
|
||||||
this.load();
|
this.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void changeEnabled(boolean enabled) {
|
||||||
|
this.localConfig().set("enableTicketing", enabled);
|
||||||
|
Configuration.saveChanges();
|
||||||
|
}
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return this.localConfig().getBoolean("enableTicketing", true);
|
||||||
|
}
|
||||||
|
|
||||||
private void load() {
|
private void load() {
|
||||||
if (!Files.exists(this.saveFile)) return;
|
if (!Files.exists(this.saveFile)) return;
|
||||||
try (Reader reader = Files.newBufferedReader(this.saveFile)) {
|
try (Reader reader = Files.newBufferedReader(this.saveFile)) {
|
||||||
@ -99,6 +109,9 @@ public class PlayTimer extends Appliance {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected @NotNull List<ApplianceCommand<?>> commands() {
|
protected @NotNull List<ApplianceCommand<?>> commands() {
|
||||||
return List.of(new PlayTimerCommand());
|
return List.of(
|
||||||
|
new PlayTimerCommand(),
|
||||||
|
new TicketingCommand()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ public class PlayTimerCommand extends ApplianceCommand<PlayTimer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
|
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
if (args.length < 3) throw new Error("Usage: playTimer <user|team> <identifier> <get|set> [amount]");
|
if (args.length < 3) throw new Error("Usage: playTimer <user|team> <identifier> <get|set> [amount]");
|
||||||
|
|
||||||
String mode = args[0].toLowerCase();
|
String mode = args[0].toLowerCase();
|
||||||
@ -37,7 +37,7 @@ public class PlayTimerCommand extends ApplianceCommand<PlayTimer> {
|
|||||||
case "team" -> teamAppliance.findTeamByName(identifier);
|
case "team" -> teamAppliance.findTeamByName(identifier);
|
||||||
case "incallbyone" -> {
|
case "incallbyone" -> {
|
||||||
this.getAppliance().incrementAll();
|
this.getAppliance().incrementAll();
|
||||||
throw new Error("Incremented all Teams by one!");
|
throw new Error("KEIN FEHLER!: Incremented all Teams by one!");
|
||||||
}
|
}
|
||||||
default -> throw new Error("Ungültiger Modus: " + mode + ". Erlaubt: user | team");
|
default -> throw new Error("Ungültiger Modus: " + mode + ". Erlaubt: user | team");
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.playTimer;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.Main;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||||
|
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.teams.Teams;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class TicketingCommand extends ApplianceCommand<PlayTimer> {
|
||||||
|
public TicketingCommand() {
|
||||||
|
super("ticketing");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
sender.sendMessage(String.format("Ticketing was %b", this.getAppliance().isEnabled()));
|
||||||
|
if(args.length < 1)
|
||||||
|
throw new Error("Stop Ticketing with 'stop' or start ticketing (now subtracting one) and start team-countdown with 'start'");
|
||||||
|
|
||||||
|
switch(args[0]) {
|
||||||
|
case "stop" -> this.getAppliance().changeEnabled(false);
|
||||||
|
case "start" -> {
|
||||||
|
this.getAppliance().changeEnabled(true);
|
||||||
|
Main.instance().getAppliance(Teams.class).getAllTeams().forEach(team -> {
|
||||||
|
boolean isAllowed = this.getAppliance().tryConsumeTicket(team);
|
||||||
|
if(!isAllowed) {
|
||||||
|
Main.logger().warning(String.format("Team %s already on Server, Ticketing got enabled but no Tickets were left! KICKING!", team.name));
|
||||||
|
team.kickTeam();
|
||||||
|
}
|
||||||
|
|
||||||
|
team.startCountDown();
|
||||||
|
});
|
||||||
|
sender.sendMessage(String.format("Ticketing (ticket reduction on join) is now %b", this.getAppliance().isEnabled()));
|
||||||
|
}
|
||||||
|
default -> sender.sendMessage("Unknown command");
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(String.format("Ticketing is now %b", this.getAppliance().isEnabled()));
|
||||||
|
}
|
||||||
|
}
|
@ -3,12 +3,9 @@ package eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.teams;
|
|||||||
import eu.mhsl.craftattack.spawn.core.Main;
|
import eu.mhsl.craftattack.spawn.core.Main;
|
||||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||||
import eu.mhsl.craftattack.spawn.core.util.text.Countdown;
|
|
||||||
import eu.mhsl.craftattack.spawn.core.util.text.DisconnectInfo;
|
import eu.mhsl.craftattack.spawn.core.util.text.DisconnectInfo;
|
||||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.displayName.DisplayName;
|
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.displayName.DisplayName;
|
||||||
import eu.mhsl.craftattack.spawn.varo.api.repositories.TeamRepository;
|
import eu.mhsl.craftattack.spawn.varo.api.repositories.TeamRepository;
|
||||||
import eu.mhsl.craftattack.spawn.varo.appliances.internal.teamTasks.TeamTasks;
|
|
||||||
import eu.mhsl.craftattack.spawn.varo.appliances.internal.teamTasks.tasks.CountdownTeamTask;
|
|
||||||
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.joinProtection.JoinProtection;
|
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.joinProtection.JoinProtection;
|
||||||
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.playTimer.PlayTimer;
|
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.playTimer.PlayTimer;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@ -119,12 +116,16 @@ public class Teams extends Appliance implements DisplayName.Prefixed {
|
|||||||
if(team == null) throw new IllegalStateException("Player must be in a Team");
|
if(team == null) throw new IllegalStateException("Player must be in a Team");
|
||||||
|
|
||||||
PlayTimer playTimer = Main.instance().getAppliance(PlayTimer.class);
|
PlayTimer playTimer = Main.instance().getAppliance(PlayTimer.class);
|
||||||
|
if(playTimer.isEnabled()) {
|
||||||
boolean isAllowed = playTimer.tryConsumeTicket(team);
|
boolean isAllowed = playTimer.tryConsumeTicket(team);
|
||||||
if(!isAllowed) {
|
if(!isAllowed) {
|
||||||
Main.logger().warning(String.format("Team %s joined, but got denied from Ticketing. Team will be kicked!", team.name));
|
Main.logger().warning(String.format("Team %s joined, but got denied from Ticketing. Team will be kicked!", team.name));
|
||||||
team.kickTeam(teamNoPlaytime);
|
team.kickTeam(teamNoPlaytime);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Main.logger().info(String.format("Allowing team %s to join, because PlayTimer is not active. Not subtracting from PlayTimer!", team.name));
|
||||||
|
}
|
||||||
|
|
||||||
int leftTickets = playTimer.getTickets(team);
|
int leftTickets = playTimer.getTickets(team);
|
||||||
Main.logger().info(String.format("Player %s joined. There are %d tickets left!", joinedPlayer.getName(), leftTickets));
|
Main.logger().info(String.format("Player %s joined. There are %d tickets left!", joinedPlayer.getName(), leftTickets));
|
||||||
@ -153,32 +154,7 @@ public class Teams extends Appliance implements DisplayName.Prefixed {
|
|||||||
.findAny()
|
.findAny()
|
||||||
.ifPresentOrElse(
|
.ifPresentOrElse(
|
||||||
member -> team.kickTeam(teamNotCompleteInfo),
|
member -> team.kickTeam(teamNotCompleteInfo),
|
||||||
() -> {
|
team::startCountDown
|
||||||
Main.logger().info(String.format("Starting Time countdown for Team %s with %d", team.name, PlayTimer.PLAYTIME_MINUTES));
|
|
||||||
CountdownTeamTask countdown = new CountdownTeamTask(
|
|
||||||
60 * PlayTimer.PLAYTIME_MINUTES,
|
|
||||||
announcementData -> Component.text(
|
|
||||||
String.format("Es verbleiben noch %d %s Spielzeit!", announcementData.count(), announcementData.unit()),
|
|
||||||
NamedTextColor.RED
|
|
||||||
),
|
|
||||||
component -> team.getOnlinePlayers().forEach(player -> player.sendMessage(component)),
|
|
||||||
team::timeOverKick
|
|
||||||
);
|
|
||||||
countdown.setDefaultAnnouncements(count -> {
|
|
||||||
if(count > 300) return null;
|
|
||||||
if(count > 60 && count % 60 == 0) {
|
|
||||||
return new Countdown.AnnouncementData(count / 60, "Minuten");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(count <= 30 && (count <= 10 || count % 10 == 0)) {
|
|
||||||
return new Countdown.AnnouncementData(count, "Sekunden");
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
countdown.start();
|
|
||||||
this.queryAppliance(TeamTasks.class).addTask(team, TeamTasks.Type.TIME_KICK, countdown);
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
Ticks.TICKS_PER_SECOND * (JoinProtection.resistanceDuration / 2)
|
Ticks.TICKS_PER_SECOND * (JoinProtection.resistanceDuration / 2)
|
||||||
);
|
);
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
package eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.teams;
|
package eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.teams;
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.core.Main;
|
import eu.mhsl.craftattack.spawn.core.Main;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.util.text.Countdown;
|
||||||
import eu.mhsl.craftattack.spawn.core.util.text.DisconnectInfo;
|
import eu.mhsl.craftattack.spawn.core.util.text.DisconnectInfo;
|
||||||
import eu.mhsl.craftattack.spawn.varo.appliances.internal.teamTasks.TeamTasks;
|
import eu.mhsl.craftattack.spawn.varo.appliances.internal.teamTasks.TeamTasks;
|
||||||
|
import eu.mhsl.craftattack.spawn.varo.appliances.internal.teamTasks.tasks.CountdownTeamTask;
|
||||||
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.fightDetector.FightDetector;
|
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.fightDetector.FightDetector;
|
||||||
|
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.playTimer.PlayTimer;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.util.Ticks;
|
import net.kyori.adventure.util.Ticks;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -68,6 +73,38 @@ public class VaroTeam {
|
|||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void startCountDown() {
|
||||||
|
if(!Main.instance().getAppliance(PlayTimer.class).isEnabled()) {
|
||||||
|
Main.logger().warning(String.format("PlayTimer for %s not started, because it is deactivated!", this.name));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Main.logger().info(String.format("Starting Time countdown for Team %s with %d", this.name, PlayTimer.PLAYTIME_MINUTES));
|
||||||
|
CountdownTeamTask countdown = new CountdownTeamTask(
|
||||||
|
60 * PlayTimer.PLAYTIME_MINUTES,
|
||||||
|
announcementData -> Component.text(
|
||||||
|
String.format("Es verbleiben noch %d %s Spielzeit!", announcementData.count(), announcementData.unit()),
|
||||||
|
NamedTextColor.RED
|
||||||
|
),
|
||||||
|
component -> this.getOnlinePlayers().forEach(player -> player.sendMessage(component)),
|
||||||
|
this::timeOverKick
|
||||||
|
);
|
||||||
|
countdown.setDefaultAnnouncements(count -> {
|
||||||
|
if(count > 300) return null;
|
||||||
|
if(count > 60 && count % 60 == 0) {
|
||||||
|
return new Countdown.AnnouncementData(count / 60, "Minuten");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(count <= 30 && (count <= 10 || count % 10 == 0)) {
|
||||||
|
return new Countdown.AnnouncementData(count, "Sekunden");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
countdown.start();
|
||||||
|
Main.instance().getAppliance(TeamTasks.class).addTask(this, TeamTasks.Type.TIME_KICK, countdown);
|
||||||
|
}
|
||||||
|
|
||||||
public void kickTeam(DisconnectInfo disconnectInfo) {
|
public void kickTeam(DisconnectInfo disconnectInfo) {
|
||||||
this.getOnlinePlayers()
|
this.getOnlinePlayers()
|
||||||
.forEach(player -> player.kick(disconnectInfo.getComponent()));
|
.forEach(player -> player.kick(disconnectInfo.getComponent()));
|
||||||
|
Reference in New Issue
Block a user