unlimited admin access
This commit is contained in:
@ -27,6 +27,8 @@ public class JoinProtection extends Appliance {
|
||||
private final Map<UUID, Options> protectedPlayers = new HashMap<>();
|
||||
|
||||
public void addProtection(Player player) {
|
||||
if(player.isOp()) return;
|
||||
|
||||
this.protectedPlayers.put(player.getUniqueId(), new Options());
|
||||
PotionEffect resistance = new PotionEffect(PotionEffectType.RESISTANCE, Ticks.TICKS_PER_SECOND * resistanceDuration, 1);
|
||||
PotionEffect blindness = new PotionEffect(PotionEffectType.DARKNESS, Ticks.TICKS_PER_SECOND * 3, 1);
|
||||
|
@ -13,7 +13,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class PlayTimerCommand extends ApplianceCommand<PlayTimer> {
|
||||
@ -33,20 +32,18 @@ public class PlayTimerCommand extends ApplianceCommand<PlayTimer> {
|
||||
VaroTeam team = switch (mode) {
|
||||
case "user" -> {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
|
||||
try {
|
||||
yield teamAppliance.getTeamFromPlayer(player.getUniqueId());
|
||||
} catch(NoSuchElementException e) {
|
||||
throw new Error("Dieser Spieler konnte keinem Team zugeordnet werden!");
|
||||
}
|
||||
yield teamAppliance.getTeamFromPlayer(player.getUniqueId());
|
||||
}
|
||||
case "team" -> {
|
||||
VaroTeam targetTeam = teamAppliance.findTeamByName(identifier);
|
||||
if (targetTeam == null) throw new Error("Team nicht gefunden.");
|
||||
yield targetTeam;
|
||||
case "team" -> teamAppliance.findTeamByName(identifier);
|
||||
case "incallbyone" -> {
|
||||
this.getAppliance().incrementAll();
|
||||
throw new Error("Incremented all Teams by one!");
|
||||
}
|
||||
default -> throw new Error("Ungültiger Modus: " + mode + ". Erlaubt: user | team");
|
||||
};
|
||||
|
||||
if(team == null) throw new Error("Team nicht gefunden.");
|
||||
|
||||
switch (action) {
|
||||
case "get" -> {
|
||||
int ticketCount = this.getAppliance().getTickets(team);
|
||||
@ -67,7 +64,7 @@ public class PlayTimerCommand extends ApplianceCommand<PlayTimer> {
|
||||
List<VaroTeam> teams = Main.instance().getAppliance(Teams.class).getAllTeams();
|
||||
|
||||
return switch (args.length) {
|
||||
case 1 -> Stream.of("user", "team")
|
||||
case 1 -> Stream.of("user", "team", "incAllByOne")
|
||||
.filter(opt -> opt.startsWith(args[0].toLowerCase()))
|
||||
.toList();
|
||||
|
||||
|
@ -12,6 +12,7 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.util.Ticks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -65,15 +66,18 @@ public class Teams extends Appliance implements DisplayName.Prefixed, DisplayNam
|
||||
}
|
||||
|
||||
public boolean canLogin(UUID playerId) {
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerId);
|
||||
if(offlinePlayer.isOp()) return true;
|
||||
|
||||
return this.teams.stream()
|
||||
.anyMatch(varoTeam -> varoTeam.hasMember(playerId) && !Objects.requireNonNull(varoTeam.getMemberById(playerId)).isDead);
|
||||
}
|
||||
|
||||
public VaroTeam getTeamFromPlayer(UUID playerId) {
|
||||
public @Nullable VaroTeam getTeamFromPlayer(UUID playerId) {
|
||||
return this.teams.stream()
|
||||
.filter(varoTeam -> varoTeam.hasMember(playerId))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public List<VaroTeam> getAllTeams() {
|
||||
@ -81,6 +85,8 @@ public class Teams extends Appliance implements DisplayName.Prefixed, DisplayNam
|
||||
}
|
||||
|
||||
public void enforceTeamJoin(Player joinedPlayer) {
|
||||
if(joinedPlayer.isOp()) return;
|
||||
|
||||
DisconnectInfo teamNotCompleteInfo = new DisconnectInfo(
|
||||
"Teampartner nicht beigetreten",
|
||||
"Deine Verbindung wurde getrennt, da dein Teampartner keine Verbindung zum Server hergestellt hat!",
|
||||
@ -96,6 +102,7 @@ public class Teams extends Appliance implements DisplayName.Prefixed, DisplayNam
|
||||
);
|
||||
|
||||
VaroTeam team = this.getTeamFromPlayer(joinedPlayer.getUniqueId());
|
||||
if(team == null) throw new IllegalStateException("Player must be in a Team");
|
||||
|
||||
PlayTimer playTimer = Main.instance().getAppliance(PlayTimer.class);
|
||||
boolean isAllowed = playTimer.tryConsumeTicket(team);
|
||||
@ -150,7 +157,7 @@ public class Teams extends Appliance implements DisplayName.Prefixed, DisplayNam
|
||||
leftPlayer.getUniqueId()
|
||||
);
|
||||
VaroTeam team = this.getTeamFromPlayer(leftPlayer.getUniqueId());
|
||||
team.kickTeam(disconnectInfo);
|
||||
if(team != null) team.kickTeam(disconnectInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -162,8 +169,8 @@ public class Teams extends Appliance implements DisplayName.Prefixed, DisplayNam
|
||||
public @Nullable Component getNamePrefix(Player player) {
|
||||
VaroTeam team = this.getTeamFromPlayer(player.getUniqueId());
|
||||
return Component.text(
|
||||
String.format("[%s]", team.name),
|
||||
TextColor.fromCSSHexString(team.color)
|
||||
String.format("[%s]", team != null ? team.name : "?"),
|
||||
TextColor.fromCSSHexString(team != null ? team.color : "#ffffff")
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,39 @@
|
||||
package eu.mhsl.craftattack.spawn.varo.appliances.tooling.adminInvisibility;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AdminInvisibility extends Appliance {
|
||||
public void updateVisibility(PlayerJoinEvent event) {
|
||||
Player target = event.getPlayer();
|
||||
boolean shouldBeHidden = target.isOp();
|
||||
for (Player viewer : Bukkit.getOnlinePlayers()) {
|
||||
if (viewer.equals(target)) continue;
|
||||
|
||||
if (shouldBeHidden) {
|
||||
viewer.hidePlayer(Main.instance(), target);
|
||||
} else {
|
||||
viewer.showPlayer(Main.instance(), target);
|
||||
}
|
||||
}
|
||||
|
||||
if(shouldBeHidden) {
|
||||
target.playerListName(Component.empty());
|
||||
event.joinMessage(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(new OnAdminJoinListener());
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package eu.mhsl.craftattack.spawn.varo.appliances.tooling.adminInvisibility;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
class OnAdminJoinListener extends ApplianceListener<AdminInvisibility> {
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
this.getAppliance().updateVisibility(event);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user