Remove outdated outlawed PvP system and related configurations
This commit is contained in:
1 parent
b06ba40d16
commit
d18ddc7b07
5 files changed
-219
No files matched your search
@@ -110,9 +110,6 @@ tablist:
|
|||||||
projectTitle: "Title"
|
projectTitle: "Title"
|
||||||
interface: eth0
|
interface: eth0
|
||||||
|
|
||||||
outlawed:
|
|
||||||
voluntarily: []
|
|
||||||
|
|
||||||
packselect:
|
packselect:
|
||||||
packs:
|
packs:
|
||||||
- somepack:
|
- somepack:
|
||||||
|
|||||||
-7
@@ -1,7 +0,0 @@
|
|||||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.outlawed;
|
|
||||||
|
|
||||||
class OutlawChangeNotPermitted extends Exception {
|
|
||||||
public OutlawChangeNotPermitted(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-165
@@ -1,165 +0,0 @@
|
|||||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.outlawed;
|
|
||||||
|
|
||||||
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.common.appliances.metaGameplay.displayName.DisplayName;
|
|
||||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.tooling.whitelist.Whitelist;
|
|
||||||
import eu.mhsl.craftattack.spawn.core.config.Configuration;
|
|
||||||
import eu.mhsl.craftattack.spawn.core.util.text.DisconnectInfo;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.event.ClickEvent;
|
|
||||||
import net.kyori.adventure.text.event.HoverEvent;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class Outlawed extends Appliance implements DisplayName.Prefixed {
|
|
||||||
public final int timeoutInMs = 1000 * 60 * 60 * 6;
|
|
||||||
private final Map<UUID, Long> timeouts = new HashMap<>();
|
|
||||||
|
|
||||||
public enum Status {
|
|
||||||
DISABLED,
|
|
||||||
VOLUNTARILY,
|
|
||||||
FORCED
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Map<Player, Status> playerStatusMap = new WeakHashMap<>();
|
|
||||||
private final String voluntarilyEntry = "voluntarily";
|
|
||||||
|
|
||||||
public Outlawed() {
|
|
||||||
super("outlawed");
|
|
||||||
Bukkit.getScheduler().runTaskTimerAsynchronously(
|
|
||||||
Main.instance(),
|
|
||||||
() -> this.playerStatusMap.forEach((player, status) -> {
|
|
||||||
if(!player.isOnline()) return;
|
|
||||||
if(status != Status.FORCED) return;
|
|
||||||
try {
|
|
||||||
this.queryAppliance(Whitelist.class).fullIntegrityCheck(player);
|
|
||||||
} catch(DisconnectInfo.Throwable e) {
|
|
||||||
e.getDisconnectScreen().applyKick(player);
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
20 * 60,
|
|
||||||
20 * 60 * 5
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void askForConfirmation(Player player) {
|
|
||||||
Component confirmationMessage = switch(this.getLawStatus(player)) {
|
|
||||||
case DISABLED -> Component.text("Wenn du den PVP-Modus aktivierst, darfst du von allen anderen PVP-Spielern grundlos angegriffen werden." +
|
|
||||||
" Du kannst den PVP-Modus erst wieder nach " + this.timeoutInMs / 1000 / 60 / 60 + " Stunden deaktivieren!");
|
|
||||||
case VOLUNTARILY -> Component.text("Wenn du den PVP-Modus deaktivierst, darfst du nicht mehr grundlos von anderen Spielern angegriffen werden.");
|
|
||||||
case FORCED -> Component.text("Du darfst zurzeit deinen PVP-Modus nicht ändern, da die˝ser als Strafe auferlegt wurde!");
|
|
||||||
};
|
|
||||||
String command = String.format("/%s confirm", OutlawedCommand.commandName);
|
|
||||||
Component changeText = Component.text(
|
|
||||||
String.format(
|
|
||||||
"Zum ändern deines PVP-Status klicke auf diese Nachricht oder tippe '%s'",
|
|
||||||
command
|
|
||||||
),
|
|
||||||
NamedTextColor.GOLD
|
|
||||||
).clickEvent(ClickEvent.suggestCommand(command));
|
|
||||||
|
|
||||||
player.sendMessage(
|
|
||||||
Component.text()
|
|
||||||
.append(confirmationMessage.color(NamedTextColor.RED))
|
|
||||||
.appendNewline()
|
|
||||||
.append(changeText)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void switchLawStatus(Player player) throws OutlawChangeNotPermitted {
|
|
||||||
if(this.getLawStatus(player).equals(Status.FORCED)) {
|
|
||||||
throw new OutlawChangeNotPermitted("Dein PVP-Status wurde als Strafe auferlegt und kann daher nicht verändert werden.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.isTimeout(player)) {
|
|
||||||
throw new OutlawChangeNotPermitted("Du kannst deinen PVP-Status nicht so schnell wechseln. Bitte warte einige Stunden bevor du umschaltest!");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setLawStatus(player, this.isOutlawed(player) ? Status.DISABLED : Status.VOLUNTARILY);
|
|
||||||
this.setTimeout(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateForcedStatus(Player player, boolean forced) {
|
|
||||||
this.setLawStatus(player, forced ? Status.FORCED : this.getLawStatus(player) == Status.FORCED ? Status.DISABLED : this.getLawStatus(player));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Status getLawStatus(Player player) {
|
|
||||||
return this.playerStatusMap.computeIfAbsent(player, p -> {
|
|
||||||
if(this.localConfig().getStringList(this.voluntarilyEntry).contains(p.getUniqueId().toString()))
|
|
||||||
return Status.VOLUNTARILY;
|
|
||||||
return Status.DISABLED;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setLawStatus(Player player, Status status) {
|
|
||||||
this.playerStatusMap.put(player, status);
|
|
||||||
this.queryAppliance(DisplayName.class).update(player);
|
|
||||||
|
|
||||||
List<String> newList = this.localConfig().getStringList(this.voluntarilyEntry);
|
|
||||||
if(status.equals(Status.VOLUNTARILY)) {
|
|
||||||
newList.add(player.getUniqueId().toString());
|
|
||||||
} else {
|
|
||||||
newList.remove(player.getUniqueId().toString());
|
|
||||||
}
|
|
||||||
this.localConfig().set(this.voluntarilyEntry, newList.stream().distinct().toList());
|
|
||||||
Configuration.saveChanges();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isOutlawed(Player player) {
|
|
||||||
return this.getLawStatus(player) != Status.DISABLED;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isTimeout(Player player) {
|
|
||||||
return this.timeouts.getOrDefault(player.getUniqueId(), 0L) > System.currentTimeMillis() - this.timeoutInMs;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setTimeout(Player player) {
|
|
||||||
this.timeouts.put(player.getUniqueId(), System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Component getStatusDescription(Status status) {
|
|
||||||
return switch(status) {
|
|
||||||
case DISABLED -> Component.text("PVP-Modus inaktiv: ", NamedTextColor.GREEN)
|
|
||||||
.append(Component.text("Es gelten die normalen Regeln!", NamedTextColor.GOLD));
|
|
||||||
|
|
||||||
case VOLUNTARILY, FORCED -> Component.text("PVP-Modus aktiv: ", NamedTextColor.RED)
|
|
||||||
.append(Component.text(
|
|
||||||
"Du darfst von allen anderen PVP-Spielern angegriffen und getötet werden!\n" +
|
|
||||||
"Wenn du getötet wirst, müssen andere Spieler deine Items *nicht* zurückerstatten!",
|
|
||||||
NamedTextColor.GOLD
|
|
||||||
));
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getNamePrefix(Player player) {
|
|
||||||
if(this.isOutlawed(player)) {
|
|
||||||
return Component.text("[☠]", NamedTextColor.RED)
|
|
||||||
.hoverEvent(HoverEvent.showText(Component.text(
|
|
||||||
"PVP-Modus Spieler dürfen von anderen vogelfreien Spielern ohne Grund angegriffen werden!"
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
protected List<ApplianceCommand<?>> commands() {
|
|
||||||
return List.of(new OutlawedCommand());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
protected List<Listener> listeners() {
|
|
||||||
return List.of(new OutlawedReminderListener());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-30
@@ -1,30 +0,0 @@
|
|||||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.outlawed;
|
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
|
||||||
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;
|
|
||||||
|
|
||||||
class OutlawedCommand extends ApplianceCommand.PlayerChecked<Outlawed> {
|
|
||||||
public static final String commandName = "pvp";
|
|
||||||
|
|
||||||
public OutlawedCommand() {
|
|
||||||
super(commandName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
|
|
||||||
if(args.length == 1 && args[0].equals("confirm")) {
|
|
||||||
try {
|
|
||||||
this.getAppliance().switchLawStatus(this.getPlayer());
|
|
||||||
sender.sendMessage(this.getAppliance().getStatusDescription(this.getAppliance().getLawStatus(this.getPlayer())));
|
|
||||||
} catch(OutlawChangeNotPermitted e) {
|
|
||||||
sender.sendMessage(Component.text(e.getMessage(), NamedTextColor.RED));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.getAppliance().askForConfirmation(this.getPlayer());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-14
@@ -1,14 +0,0 @@
|
|||||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.outlawed;
|
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
|
|
||||||
class OutlawedReminderListener extends ApplianceListener<Outlawed> {
|
|
||||||
@EventHandler
|
|
||||||
public void onJoin(PlayerJoinEvent e) {
|
|
||||||
if(this.getAppliance().isOutlawed(e.getPlayer())) {
|
|
||||||
e.getPlayer().sendMessage(this.getAppliance().getStatusDescription(this.getAppliance().getLawStatus(e.getPlayer())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user