From d82fa59ed4df9cb56499cb72e8198338f7870e15 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 4 Aug 2022 17:33:53 +0200 Subject: [PATCH 1/8] WIP join anytime Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/FightSystem.java | 2 +- .../fightsystem/FightSystem.properties | 7 ++ .../fightsystem/FightSystem_de.properties | 18 ++++ .../fightsystem/commands/AcceptCommand.java | 52 +++++++++-- .../fightsystem/commands/Commands.java | 63 ------------- .../fightsystem/commands/DeclineCommand.java | 9 +- .../de/steamwar/fightsystem/commands/GUI.java | 46 +++++----- .../fightsystem/commands/InviteCommand.java | 52 ----------- .../countdown/EnternCountdown.java | 17 +++- .../de/steamwar/fightsystem/fight/Fight.java | 8 -- .../fightsystem/fight/FightPlayer.java | 9 +- .../steamwar/fightsystem/fight/FightTeam.java | 27 +++--- .../steamwar/fightsystem/fight/HotbarKit.java | 11 ++- .../fightsystem/fight/JoinRequest.java | 88 +++++++++++++++++++ .../listener/JoinRequestListener.java | 63 +++++++++++++ .../fightsystem/utils/EnterHandler.java | 5 +- FightSystem_Core/src/plugin.yml | 1 - 17 files changed, 295 insertions(+), 183 deletions(-) delete mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/commands/InviteCommand.java create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index b449484..a3f6b49 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -91,6 +91,7 @@ public class FightSystem extends JavaPlugin { new BlockFadeListener(); new LeaveableArena(); new HotbarKit.HotbarKitListener(); + new JoinRequestListener(); new OneShotStateDependent(ArenaMode.All, FightState.PreSchemSetup, () -> Fight.playSound(SWSound.BLOCK_NOTE_PLING.getSound(), 100.0f, 2.0f)); new EnterHandler(); @@ -133,7 +134,6 @@ public class FightSystem extends JavaPlugin { new TBCommand(); new DeclineCommand(); new GamemodeCommand(); - new InviteCommand(); new ReadyCommand(); new AkCommand(); new LeaderCommand(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties index ae4ae52..15cf595 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties @@ -239,3 +239,10 @@ WIN_LESS_DAMAGE={0} §7less damaged WIN_POINTS={0} has more points WIN_POINTS_EQUAL=§7Equal points WIN_TECHKO={0} §7is tech K.O. + + +# Invites +JOIN_REQUEST=§7Request participation +JOIN_REQUEST_TITLE=Request participation +JOIN_REQUEST_ALREADY=§cYou have already sent a participation request +JOIN_REQUEST_TEAM=§eJoin {0} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties index 166ddc8..69ddf0e 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties @@ -224,3 +224,21 @@ WIN_LESS_DAMAGE={0} §7weniger beschädigt WIN_POINTS={0} hat mehr Punkte WIN_POINTS_EQUAL=§7Gleicher Punktestand WIN_TECHKO={0} §7ist Tech K.O. + + +# Invites +JOIN_REQUEST=§7Teambeitritt anfragen +JOIN_REQUEST_TITLE=Teambeitritt anfragen +JOIN_REQUEST_ALREADY=§cDu hast bereits ein Team um Beitritt angefragt +JOIN_REQUEST_TEAM={0} §ebeitreten + +REQUESTS=§7Offene Beitrittsanfragen +REQUESTS_TITLE=Offene Beitrittsanfragen +REQUEST_DECLINED=§cBeitritt von {0} abgelehnt +YOUR_REQUEST_DECLINED=§cDeine Betrittsanfrage wurde abgelehnt + +UNKNOWN_PLAYER=§cUnbekannter Spieler +NO_JOIN_REQUEST=§cDer Spieler hat noch keinen Beitritt angefragt +NO_CONFIRMATION=§cKeine Zustimmung nötig +ACCEPT_USAGE=§8/§7accept §8[§eSpieler§8] +DECLINE_USAGE=§8/§7decline §8[§eSpieler§8] diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/AcceptCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/AcceptCommand.java index 0e23db4..508a831 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/AcceptCommand.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/AcceptCommand.java @@ -20,13 +20,20 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.fight.JoinRequest; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCommand; +import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.function.BiConsumer; + public class AcceptCommand implements CommandExecutor { public AcceptCommand() { @@ -35,12 +42,45 @@ public class AcceptCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(!(sender instanceof Player)) { - return false; - } - Player player = (Player) sender; - - Commands.acceptInvitation(player); + onJoinRequest(sender, args, "ACCEPT_USAGE", JoinRequest::accept); return false; } + + public static void onJoinRequest(CommandSender sender, String[] args, String usage, BiConsumer handleJoinRequest) { + if(!(sender instanceof Player)) { + return; + } + Player player = (Player) sender; + if(Commands.checkGetLeader(player) == null) + return; + + if(args.length == 0) { + FightSystem.getMessage().send(usage, sender); + return; + } + + Player target = Bukkit.getPlayer(args[0]); + if(target == null) { + FightSystem.getMessage().send("UNKNOWN_PLAYER", player); + return; + } + + onJoinRequest(player, target, handleJoinRequest); + } + + public static void onJoinRequest(Player player, Player target, BiConsumer handleJoinRequest) { + JoinRequest request = JoinRequest.get(target); + if(request == null) { + FightSystem.getMessage().send("NO_JOIN_REQUEST", player); + return; + } + + FightTeam team = Fight.getPlayerTeam(player); + if(!request.required(team)) { + FightSystem.getMessage().send("NO_CONFIRMATION", player); + return; + } + + handleJoinRequest.accept(request, team); + } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java index 5ff08b0..6102728 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java @@ -47,14 +47,6 @@ public class Commands { return false; } - private static FightTeam checkGetInvitedTeam(Player p){ - FightTeam fightTeam = Fight.getInvitedTeam(p); - if(fightTeam == null){ - FightSystem.getMessage().sendPrefixless("NO_INVITATION", p, ChatMessageType.ACTION_BAR); - } - return fightTeam; - } - private static FightPlayer checkGetPlayer(Player p){ FightPlayer fightPlayer = Fight.getFightPlayer(p); if(fightPlayer == null){ @@ -104,30 +96,6 @@ public class Commands { fightTeam.skip(); } - static void acceptInvitation(Player p){ - if(checkSetup(p)) - return; - - FightTeam team = checkGetInvitedTeam(p); - if(team == null) - return; - - team.addMember(p); - } - - static void declineInvitation(Player p){ - if(checkSetup(p)) - return; - - FightTeam team = checkGetInvitedTeam(p); - if(team == null) - return; - - FightSystem.getMessage().sendPrefixless("INVITATION_DECLINED", p, ChatMessageType.ACTION_BAR); - team.broadcast("INVITATION_DECLINED_TEAM", p.getName()); - team.getInvited().remove(p); - } - static void leaveTeam(Player p){ if(checkSetup(p)) return; @@ -139,37 +107,6 @@ public class Commands { fightTeam.removePlayer(p); } - static void invite(Player p, String invited){ - if(checkSetup(p)) - return; - - FightTeam fightTeam = checkGetTeam(p); - if(fightTeam == null) - return; - - FightPlayer fightPlayer = checkGetLeader(p); - if(fightPlayer == null) - return; - - Player target = checkGetPlayer(p, invited); - if(target == null) - return; - - if(Fight.getPlayerTeam(target) != null) { - FightSystem.getMessage().sendPrefixless("PLAYER_IN_TEAM", p, ChatMessageType.ACTION_BAR, target.getName()); - return; - } - - if(Fight.getOpposite(fightTeam).getInvited().contains(target) || fightTeam.getInvited().contains(target)) { - FightSystem.getMessage().sendPrefixless("ALREADY_INVITED", p, ChatMessageType.ACTION_BAR, target.getName()); - return; - } - - FightSystem.getMessage().sendPrefixless("INVITATION_SENT", p, ChatMessageType.ACTION_BAR, target.getName()); - fightTeam.getInvited().add(target); - GUI.invitation(p, target); - } - static void kick(Player p, String kicked){ if(checkSetup(p)) return; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/DeclineCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/DeclineCommand.java index 3fa9906..fdf9afe 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/DeclineCommand.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/DeclineCommand.java @@ -20,12 +20,12 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.fight.JoinRequest; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCommand; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class DeclineCommand implements CommandExecutor { @@ -35,12 +35,7 @@ public class DeclineCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(!(sender instanceof Player)) { - return false; - } - Player player = (Player) sender; - - Commands.declineInvitation(player); + AcceptCommand.onJoinRequest(sender, args, "DECLINE_USAGE", JoinRequest::decline); return false; } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java index 5b04b80..fd0de29 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java @@ -21,10 +21,7 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightPlayer; -import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.fight.Kit; +import de.steamwar.fightsystem.fight.*; import de.steamwar.fightsystem.listener.PersonalKitCreator; import de.steamwar.fightsystem.states.FightState; import de.steamwar.inventory.*; @@ -47,23 +44,23 @@ public class GUI { private static final Message msg = FightSystem.getMessage(); - static void invitation(Player p, Player target){ - SWInventory inv = new SWInventory(target, 9, msg.parse("INVITATION_TITLE", target, p.getName())); - inv.setItem(0, SWItem.getDye(10), (byte)10, msg.parse("INVITATION_ACCEPT", target), (ClickType click) ->{ - Commands.acceptInvitation(target); - target.closeInventory(); + private static void addTeamRequest(Player p, SWInventory inv, int pos, FightTeam team) { + int colorCode = team.getColor().ordinal(); + inv.setItem(pos, SWItem.getDye(colorCode), (byte)colorCode, msg.parse("JOIN_REQUEST_TEAM", p, team.getColoredName()), click -> { + p.closeInventory(); + new JoinRequest(p, team); }); - inv.setItem(8, SWItem.getDye(1), (byte)1, msg.parse("INVITATION_DECLINE", target), (ClickType click) ->{ - Commands.declineInvitation(target); - target.closeInventory(); - }); - inv.addCloseCallback((ClickType click) ->{ - if(Fight.getInvitedTeam(target) != null){ - msg.sendPrefixless("INVITATION_CHAT_ACCEPT", target); - msg.sendPrefixless("INVITATION_CHAT_DECLINE", target); - } - }); - inv.setCallback(-999, (ClickType click) -> target.closeInventory()); + } + + public static void joinRequest(Player p) { + if(JoinRequest.get(p) != null) { + msg.sendPrefixless("JOIN_REQUEST_ALREADY", p, ChatMessageType.ACTION_BAR); + return; + } + + SWInventory inv = new SWInventory(p, 9, msg.parse("JOIN_REQUEST_TITLE", p)); + addTeamRequest(p, inv, 0, Fight.getBlueTeam()); + addTeamRequest(p, inv, 8, Fight.getRedTeam()); inv.open(); } @@ -84,12 +81,11 @@ public class GUI { inv.open(); } - public static void chooseInvitation(Player p){ - List> players = SWListInv.createPlayerList(p.getUniqueId()); - players.removeIf(swItemUUIDPair -> Fight.getFightPlayer(Bukkit.getPlayer(swItemUUIDPair.getObject())) != null); - SWListInv inv = new SWListInv<>(p, msg.parse("INVITE_TITLE", p), players, (ClickType click, UUID player) -> { - Commands.invite(p, SteamwarUser.get(player).getUserName()); + public static void chooseJoinRequests(Player p){ + List> players = JoinRequest.openRequests(Fight.getPlayerTeam(p)); + SWListInv inv = new SWListInv<>(p, msg.parse("REQUESTS_TITLE", p), players, (ClickType click, Player player) -> { p.closeInventory(); + AcceptCommand.onJoinRequest(p, player, click.isLeftClick() ? JoinRequest::accept : JoinRequest::decline); }); inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.open(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/InviteCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/InviteCommand.java deleted file mode 100644 index 67cf6b1..0000000 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/InviteCommand.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.fightsystem.commands; - -import de.steamwar.fightsystem.ArenaMode; -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentCommand; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class InviteCommand implements CommandExecutor { - - public InviteCommand() { - new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "invite", this); - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(!(sender instanceof Player)) { - return false; - } - Player player = (Player) sender; - - if(args.length != 1){ - FightSystem.getMessage().sendPrefixless("INVITE_HELP", player); - return false; - } - - Commands.invite(player, args[0]); - return false; - } -} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java index e4acee0..fa13c7c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java @@ -25,17 +25,32 @@ import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.utils.Message; import de.steamwar.fightsystem.utils.SWSound; import de.steamwar.fightsystem.utils.TechHider; +import de.steamwar.fightsystem.winconditions.Wincondition; import net.md_5.bungee.api.ChatMessageType; import java.util.List; public class EnternCountdown extends Countdown { + private static int calcTime(FightPlayer fp) { + int time = Config.EnterStages.get(fp.getKit().getEnterStage()); + + Countdown countdown = Wincondition.getTimeOverCountdown(); + if(countdown != null) { + time -= Config.TimeoutTime - countdown.getTimeLeft(); + + if(time < 0) + time = 0; + } + + return time; + } + private final FightPlayer fightPlayer; private List chunkPos; public EnternCountdown(FightPlayer fp) { - super(Config.EnterStages.get(fp.getKit().getEnterStage()), new Message("ENTERN_COUNTDOWN"), SWSound.BLOCK_NOTE_PLING, false); + super(calcTime(fp), new Message("ENTERN_COUNTDOWN"), SWSound.BLOCK_NOTE_PLING, false); fightPlayer = fp; enable(); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index 5c2b0ee..e4d0bf2 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -63,14 +63,6 @@ public class Fight { throw new IllegalArgumentException(); } - public static FightTeam getInvitedTeam(Player player){ - if(redTeam.getInvited().contains(player)) - return redTeam; - else if(blueTeam.getInvited().contains(player)) - return blueTeam; - return null; - } - public static FightPlayer getFightPlayer(Player player) { if(redTeam.isPlayerInTeam(player)) return redTeam.getFightPlayer(player); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java index 5f3651a..2b13154 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java @@ -48,13 +48,18 @@ public class FightPlayer { kills = 0; } + public void revive() { + isOut = false; + } + public void setOut() { isOut = true; stopEnternCountdown(); } - public void setEnternCountdown(EnternCountdown countdown){ - enternCountdown = countdown; + public void startEnternCountdown() { + if(Config.EnterStages.size() > kit.getEnterStage() && kit.getEnterStage() >= 0) + enternCountdown = new EnternCountdown(this); } public void stopEnternCountdown(){ diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index e76b0fa..cb5b4b2 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -64,7 +64,7 @@ public class FightTeam { setKitButton(notReadyKit, true); if(!ArenaMode.RankedEvent.contains(Config.mode)){ - notReadyKit.setItem(2, "INVITE_PLAYERS", new ItemBuilder(Material.PAPER).removeAllAttributes().build(), GUI::chooseInvitation); + notReadyKit.setItem(2, "REQUESTS", new ItemBuilder(Material.PAPER).removeAllAttributes().build(), GUI::chooseJoinRequests); notReadyKit.setItem(3, "REMOVE_PLAYERS", new ItemBuilder(SWItem.getMaterial("FIREWORK_CHARGE")).removeAllAttributes().build(), GUI::chooseRemove); } @@ -88,7 +88,6 @@ public class FightTeam { private int schemRank; private final Map players = new HashMap<>(); - private final Set invited = new HashSet<>(); private String name; private String prefix; @@ -198,7 +197,6 @@ public class FightTeam { skip = false; ready = false; schematic.reset(); - invited.clear(); Set playerSet = new HashSet<>(players.keySet()); for(Player player : playerSet){ @@ -243,20 +241,28 @@ public class FightTeam { addMember(player, false); } - public void addMember(Player player, boolean silent) { + private void addMember(Player player, boolean silent) { final List chunksToReload = TechHider.prepareChunkReload(player, false); - FightPlayer fightPlayer = new FightPlayer(player, this); + FightPlayer fightPlayer = getFightPlayer(player) != null ? getFightPlayer(player) : new FightPlayer(player, this); + fightPlayer.revive(); players.put(player, fightPlayer); - invited.remove(player); team.addEntry(player.getName()); - Fight.setPlayerGamemode(player, GameMode.SURVIVAL); player.setHealth(20); player.setFoodLevel(20); player.getInventory().clear(); BountifulWrapper.impl.setAttackSpeed(player); player.teleport(spawn); - memberKit.loadToPlayer(player); + + if(FightState.Spectate.contains(FightState.getFightState())) { + Fight.setPlayerGamemode(player, GameMode.SPECTATOR); + } else { + Fight.setPlayerGamemode(player, GameMode.SURVIVAL); + (FightState.ingame() ? fightPlayer.getKit() : memberKit).loadToPlayer(player); + } + if(FightState.Running.contains(FightState.getFightState())) + fightPlayer.startEnternCountdown(); + GlobalRecorder.getInstance().playerJoins(player); TechHider.reloadChunks(player, chunksToReload, false); @@ -286,6 +292,7 @@ public class FightTeam { if(player.isOnline()){ TechHider.reloadChunks(player, chunksToReload, true); + HotbarKit.spectatorKit.loadToPlayer(player); } } @@ -414,10 +421,6 @@ public class FightTeam { } } - public Set getInvited() { - return invited; - } - public String getName() { return name; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java index bf0a686..9ea2135 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java @@ -23,9 +23,12 @@ import de.steamwar.core.Core; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.commands.GUI; import de.steamwar.fightsystem.listener.PersonalKitCreator; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.utils.ItemBuilder; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -42,6 +45,12 @@ import java.util.function.Consumer; public class HotbarKit extends Kit { + public static final HotbarKit spectatorKit = new HotbarKit(); + static { + for(int i = 0; i < 9; i++) + spectatorKit.setItem(i, "JOIN_REQUEST", new ItemBuilder(Material.PAPER).removeAllAttributes().build(), GUI::joinRequest); + } + private static final int HOTBAR_SIZE = 9; private final String[] nameTags; @@ -82,7 +91,7 @@ public class HotbarKit extends Kit { public static class HotbarKitListener implements Listener { public HotbarKitListener() { - new StateDependentListener(ArenaMode.AntiReplay, FightState.Setup, this); + new StateDependentListener(ArenaMode.AntiReplay, FightState.All, this); } @EventHandler diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java new file mode 100644 index 0000000..e4d54d3 --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java @@ -0,0 +1,88 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2022 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.fightsystem.fight; + +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.inventory.SWItem; +import de.steamwar.inventory.SWListInv; +import net.md_5.bungee.api.ChatMessageType; +import org.bukkit.entity.Player; + +import java.util.*; +import java.util.stream.Collectors; + +public class JoinRequest { + + private static final Map activeRequests = new HashMap<>(); + + public static List> openRequests(FightTeam team) { + //TODO set lore + return activeRequests.values().stream().filter(request -> request.waitOnApproval.contains(team)).map(request -> new SWListInv.SWListEntry<>(SWItem.getPlayerSkull(request.player), request.player)).collect(Collectors.toList()); + } + + public static void clearRequests() { + //TODO notify players + activeRequests.forEach((player, joinRequest) -> { + + }); + activeRequests.clear(); + } + + public static JoinRequest get(Player player) { + return activeRequests.get(player); + } + + private final Player player; + private final FightTeam team; + private final Set waitOnApproval; + + public JoinRequest(Player player, FightTeam team) { + this.player = player; + this.team = team; + this.waitOnApproval = new HashSet<>(FightState.ingame() ? Fight.teams() : Collections.singleton(team)); + //TODO send request out + + activeRequests.put(player, new JoinRequest(player, team)); + } + + public boolean required(FightTeam decider) { + return waitOnApproval.contains(decider); + } + + public void accept(FightTeam acceptor) { + waitOnApproval.remove(acceptor); + + if(waitOnApproval.isEmpty()) { + team.addMember(player); + activeRequests.remove(player); + } + } + + public void decline() { + FightSystem.getMessage().sendPrefixless("YOUR_REQUEST_DECLINED", player, ChatMessageType.ACTION_BAR); + waitOnApproval.forEach(t -> t.broadcast("REQUEST_DECLINED", player.getName())); + silentDecline(); + } + + public void silentDecline() { + activeRequests.remove(player); + } +} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java new file mode 100644 index 0000000..11ab3be --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java @@ -0,0 +1,63 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2022 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.fightsystem.listener; + +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.HotbarKit; +import de.steamwar.fightsystem.fight.JoinRequest; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.OneShotStateDependent; +import de.steamwar.fightsystem.states.StateDependentListener; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class JoinRequestListener implements Listener { + + public JoinRequestListener() { + new OneShotStateDependent(ArenaMode.VariableTeams, FightState.PreLeaderSetup, () -> Bukkit.getScheduler().runTask(FightSystem.getPlugin(), JoinRequest::clearRequests)); + new OneShotStateDependent(ArenaMode.VariableTeams, FightState.PreRunning, () -> Bukkit.getScheduler().runTask(FightSystem.getPlugin(), JoinRequest::clearRequests)); + + new StateDependentListener(ArenaMode.VariableTeams, FightState.All, this); + } + + @EventHandler(priority = EventPriority.HIGH) + public void onJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + + if (!Config.ArenaLeaveable && !Fight.fighting(player)) { + HotbarKit.spectatorKit.loadToPlayer(player); + } + } + + @EventHandler + public void onLeave(PlayerQuitEvent event) { + JoinRequest request = JoinRequest.get(event.getPlayer()); + if(request != null) + request.silentDecline(); + } +} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/EnterHandler.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/EnterHandler.java index cec63a4..ee5aa79 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/EnterHandler.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/EnterHandler.java @@ -19,8 +19,6 @@ package de.steamwar.fightsystem.utils; -import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.countdown.EnternCountdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; @@ -53,8 +51,7 @@ public class EnterHandler implements IStateDependent { private void registerTeam(FightTeam team){ for(FightPlayer fp : team.getPlayers()){ - if(Config.EnterStages.size() > fp.getKit().getEnterStage() && fp.getKit().getEnterStage() >= 0) - fp.setEnternCountdown(new EnternCountdown(fp)); + fp.startEnternCountdown(); } } diff --git a/FightSystem_Core/src/plugin.yml b/FightSystem_Core/src/plugin.yml index a740a86..6aa27b1 100644 --- a/FightSystem_Core/src/plugin.yml +++ b/FightSystem_Core/src/plugin.yml @@ -15,7 +15,6 @@ commands: accept: decline: leave: - invite: ready: kit: remove: -- 2.39.2 From 0020b2b152645f9e7a9a181ffa99c12a650c9246 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 5 Jun 2023 16:10:41 +0200 Subject: [PATCH 2/8] Fix build Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/JoinRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java index e4d54d3..7381290 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java @@ -76,7 +76,7 @@ public class JoinRequest { } } - public void decline() { + public void decline(FightTeam declinor) { FightSystem.getMessage().sendPrefixless("YOUR_REQUEST_DECLINED", player, ChatMessageType.ACTION_BAR); waitOnApproval.forEach(t -> t.broadcast("REQUEST_DECLINED", player.getName())); silentDecline(); -- 2.39.2 From 98a376a62b89d4f262855f1cfb3c90009dec261e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 5 Jun 2023 17:00:45 +0200 Subject: [PATCH 3/8] Bugfixes, Simplify UX to requests-Command Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/FightSystem.java | 3 +- .../fightsystem/FightSystem.properties | 17 ++++++-- .../fightsystem/FightSystem_de.properties | 6 +-- .../fightsystem/commands/DeclineCommand.java | 41 ------------------- .../de/steamwar/fightsystem/commands/GUI.java | 10 +++-- ...cceptCommand.java => RequestsCommand.java} | 34 ++++----------- .../fightsystem/fight/JoinRequest.java | 33 +++++++++++---- FightSystem_Core/src/plugin.yml | 3 +- 8 files changed, 58 insertions(+), 89 deletions(-) delete mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/commands/DeclineCommand.java rename FightSystem_Core/src/de/steamwar/fightsystem/commands/{AcceptCommand.java => RequestsCommand.java} (73%) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 2d5c04e..0e66d6d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -137,10 +137,9 @@ public class FightSystem extends JavaPlugin { new LeaveCommand(); new KitCommand(); new RemoveCommand(); - new AcceptCommand(); + new RequestsCommand(); new WGCommand(); new TBCommand(); - new DeclineCommand(); new GamemodeCommand(); new ReadyCommand(); new AkCommand(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties index 98b92ac..664a643 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties @@ -247,7 +247,18 @@ AMONG_US_IMPOSTER_AMONG_MESSAGE = §4There is an Imposter among us§8! §7Kill h # Invites -JOIN_REQUEST=§7Request participation -JOIN_REQUEST_TITLE=Request participation -JOIN_REQUEST_ALREADY=§cYou have already sent a participation request +JOIN_REQUEST=§7Request join +JOIN_REQUEST_TITLE=Request join +JOIN_REQUEST_ALREADY=§cYou have already sent a join request JOIN_REQUEST_TEAM=§eJoin {0} +JOIN_REQUEST_NOTIFICATION=§e{0} §7requests joining team {1}§8. §7Accept or decline using §8/§erequests + +REQUESTS=§7Open join requests +REQUESTS_TITLE=Open join requests +REQUEST_DECLINED=§cJoin of {0} declined +YOUR_REQUEST_DECLINED=§cYour join request was declined +REQUESTS_LEFT_CLICK=§eLeft click §7to §eaccept§8! +REQUESTS_RIGHT_CLICK=§eRight click §7to §edecline§8! + +NO_JOIN_REQUEST=§cThe player did not request joining +NO_CONFIRMATION=§cNo confirmation necessary \ No newline at end of file diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties index fb8b946..0e61182 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties @@ -235,14 +235,14 @@ JOIN_REQUEST=§7Teambeitritt anfragen JOIN_REQUEST_TITLE=Teambeitritt anfragen JOIN_REQUEST_ALREADY=§cDu hast bereits ein Team um Beitritt angefragt JOIN_REQUEST_TEAM={0} §ebeitreten +JOIN_REQUEST_NOTIFICATION=§e{0} §7möchte Team {1} §7beitreten§8. §7Akzeptiere oder lehne ab mit §8/§erequests REQUESTS=§7Offene Beitrittsanfragen REQUESTS_TITLE=Offene Beitrittsanfragen REQUEST_DECLINED=§cBeitritt von {0} abgelehnt YOUR_REQUEST_DECLINED=§cDeine Betrittsanfrage wurde abgelehnt +REQUESTS_LEFT_CLICK=§eLinksklick §7um §eanzunehmen§8! +REQUESTS_RIGHT_CLICK=§eRechtsklick §7um §eabzulehnen§8! -UNKNOWN_PLAYER=§cUnbekannter Spieler NO_JOIN_REQUEST=§cDer Spieler hat noch keinen Beitritt angefragt NO_CONFIRMATION=§cKeine Zustimmung nötig -ACCEPT_USAGE=§8/§7accept §8[§eSpieler§8] -DECLINE_USAGE=§8/§7decline §8[§eSpieler§8] diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/DeclineCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/DeclineCommand.java deleted file mode 100644 index fdf9afe..0000000 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/DeclineCommand.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.fightsystem.commands; - -import de.steamwar.fightsystem.ArenaMode; -import de.steamwar.fightsystem.fight.JoinRequest; -import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentCommand; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; - -public class DeclineCommand implements CommandExecutor { - - public DeclineCommand() { - new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "decline", this); - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - AcceptCommand.onJoinRequest(sender, args, "DECLINE_USAGE", JoinRequest::decline); - return false; - } -} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java index fd0de29..7ec6598 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java @@ -24,6 +24,7 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.*; import de.steamwar.fightsystem.listener.PersonalKitCreator; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.utils.ColorConverter; import de.steamwar.inventory.*; import de.steamwar.message.Message; import de.steamwar.sql.PersonalKit; @@ -44,9 +45,10 @@ public class GUI { private static final Message msg = FightSystem.getMessage(); + @SuppressWarnings("deprecation") private static void addTeamRequest(Player p, SWInventory inv, int pos, FightTeam team) { - int colorCode = team.getColor().ordinal(); - inv.setItem(pos, SWItem.getDye(colorCode), (byte)colorCode, msg.parse("JOIN_REQUEST_TEAM", p, team.getColoredName()), click -> { + byte colorCode = ColorConverter.chat2dye(team.getColor()).getDyeData(); + inv.setItem(pos, SWItem.getDye(colorCode), colorCode, msg.parse("JOIN_REQUEST_TEAM", p, team.getColoredName()), click -> { p.closeInventory(); new JoinRequest(p, team); }); @@ -82,10 +84,10 @@ public class GUI { } public static void chooseJoinRequests(Player p){ - List> players = JoinRequest.openRequests(Fight.getPlayerTeam(p)); + List> players = JoinRequest.openRequests(p, Fight.getPlayerTeam(p)); SWListInv inv = new SWListInv<>(p, msg.parse("REQUESTS_TITLE", p), players, (ClickType click, Player player) -> { p.closeInventory(); - AcceptCommand.onJoinRequest(p, player, click.isLeftClick() ? JoinRequest::accept : JoinRequest::decline); + RequestsCommand.onJoinRequest(p, player, click.isLeftClick() ? JoinRequest::accept : JoinRequest::decline); }); inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.open(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/AcceptCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/RequestsCommand.java similarity index 73% rename from FightSystem_Core/src/de/steamwar/fightsystem/commands/AcceptCommand.java rename to FightSystem_Core/src/de/steamwar/fightsystem/commands/RequestsCommand.java index 508a831..6ccaec9 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/AcceptCommand.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/RequestsCommand.java @@ -26,7 +26,6 @@ import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.JoinRequest; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCommand; -import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -34,38 +33,23 @@ import org.bukkit.entity.Player; import java.util.function.BiConsumer; -public class AcceptCommand implements CommandExecutor { +public class RequestsCommand implements CommandExecutor { - public AcceptCommand() { - new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "accept", this); + public RequestsCommand() { + new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "requests", this); } @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - onJoinRequest(sender, args, "ACCEPT_USAGE", JoinRequest::accept); - return false; - } - - public static void onJoinRequest(CommandSender sender, String[] args, String usage, BiConsumer handleJoinRequest) { - if(!(sender instanceof Player)) { - return; - } + if(!(sender instanceof Player)) + return false; Player player = (Player) sender; + if(Commands.checkGetLeader(player) == null) - return; + return false; - if(args.length == 0) { - FightSystem.getMessage().send(usage, sender); - return; - } - - Player target = Bukkit.getPlayer(args[0]); - if(target == null) { - FightSystem.getMessage().send("UNKNOWN_PLAYER", player); - return; - } - - onJoinRequest(player, target, handleJoinRequest); + GUI.chooseJoinRequests(player); + return false; } public static void onJoinRequest(Player player, Player target, BiConsumer handleJoinRequest) { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java index 7381290..d86df76 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java @@ -24,6 +24,7 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.ClickEvent; import org.bukkit.entity.Player; import java.util.*; @@ -33,16 +34,20 @@ public class JoinRequest { private static final Map activeRequests = new HashMap<>(); - public static List> openRequests(FightTeam team) { - //TODO set lore - return activeRequests.values().stream().filter(request -> request.waitOnApproval.contains(team)).map(request -> new SWListInv.SWListEntry<>(SWItem.getPlayerSkull(request.player), request.player)).collect(Collectors.toList()); + public static List> openRequests(Player p, FightTeam team) { + return activeRequests.values().stream().filter( + request -> request.waitOnApproval.contains(team) + ).map(request -> { + SWItem item = SWItem.getPlayerSkull(request.player); + item.setLore(Arrays.asList( + FightSystem.getMessage().parse("REQUESTS_LEFT_CLICK", p), + FightSystem.getMessage().parse("REQUESTS_RIGHT_CLICK", p) + )); + return new SWListInv.SWListEntry<>(item, request.player); + }).collect(Collectors.toList()); } public static void clearRequests() { - //TODO notify players - activeRequests.forEach((player, joinRequest) -> { - - }); activeRequests.clear(); } @@ -58,9 +63,19 @@ public class JoinRequest { this.player = player; this.team = team; this.waitOnApproval = new HashSet<>(FightState.ingame() ? Fight.teams() : Collections.singleton(team)); - //TODO send request out + for(FightTeam t : waitOnApproval) { + FightPlayer leader = t.getLeader(); + if(leader == null) + continue; - activeRequests.put(player, new JoinRequest(player, team)); + Player leaderPlayer = leader.getPlayer(); + if(leaderPlayer == null) + continue; + + FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_NOTIFICATION", leaderPlayer, "REQUESTS", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/requests"), player.getName(), team.getColoredName()); + } + + activeRequests.put(player, this); } public boolean required(FightTeam decider) { diff --git a/FightSystem_Core/src/plugin.yml b/FightSystem_Core/src/plugin.yml index 6aa27b1..e405591 100644 --- a/FightSystem_Core/src/plugin.yml +++ b/FightSystem_Core/src/plugin.yml @@ -12,8 +12,7 @@ api-version: "1.13" commands: ak: - accept: - decline: + requests: leave: ready: kit: -- 2.39.2 From 1a2eabaea4e610d49b894f4e878caee431166c60 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 6 Jun 2023 11:47:37 +0200 Subject: [PATCH 4/8] Bugfixes: No multiple player instances, spectator kit after death, confirmation message, allow request command while in team Signed-off-by: Lixfel --- .../fightsystem/FightSystem.properties | 1 + .../fightsystem/FightSystem_de.properties | 1 + .../fightsystem/commands/RequestsCommand.java | 9 ++++- .../fightsystem/fight/FightPlayer.java | 12 +++++- .../steamwar/fightsystem/fight/FightTeam.java | 40 ++++++++++++------- .../fightsystem/fight/JoinRequest.java | 1 + .../fightsystem/listener/Permanent.java | 2 + FightSystem_Core/src/plugin.yml | 1 + 8 files changed, 49 insertions(+), 18 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties index 664a643..0611c3e 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties @@ -251,6 +251,7 @@ JOIN_REQUEST=§7Request join JOIN_REQUEST_TITLE=Request join JOIN_REQUEST_ALREADY=§cYou have already sent a join request JOIN_REQUEST_TEAM=§eJoin {0} +JOIN_REQUEST_CONFIRMATION=§7Join request submitted JOIN_REQUEST_NOTIFICATION=§e{0} §7requests joining team {1}§8. §7Accept or decline using §8/§erequests REQUESTS=§7Open join requests diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties index 0e61182..0bd4755 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties @@ -235,6 +235,7 @@ JOIN_REQUEST=§7Teambeitritt anfragen JOIN_REQUEST_TITLE=Teambeitritt anfragen JOIN_REQUEST_ALREADY=§cDu hast bereits ein Team um Beitritt angefragt JOIN_REQUEST_TEAM={0} §ebeitreten +JOIN_REQUEST_CONFIRMATION=§7Teambeitritt angefragt JOIN_REQUEST_NOTIFICATION=§e{0} §7möchte Team {1} §7beitreten§8. §7Akzeptiere oder lehne ab mit §8/§erequests REQUESTS=§7Offene Beitrittsanfragen diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/RequestsCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/RequestsCommand.java index 6ccaec9..36c2a1e 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/RequestsCommand.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/RequestsCommand.java @@ -22,6 +22,7 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.JoinRequest; import de.steamwar.fightsystem.states.FightState; @@ -36,7 +37,8 @@ import java.util.function.BiConsumer; public class RequestsCommand implements CommandExecutor { public RequestsCommand() { - new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "requests", this); + new StateDependentCommand(ArenaMode.VariableTeams, FightState.AntiSpectate, "request", this); + new StateDependentCommand(ArenaMode.VariableTeams, FightState.AntiSpectate, "requests", this); } @Override @@ -44,6 +46,11 @@ public class RequestsCommand implements CommandExecutor { if(!(sender instanceof Player)) return false; Player player = (Player) sender; + FightPlayer fp = Fight.getFightPlayer(player); + if(fp == null || !(fp.isLeader() || fp.isLiving())) { + GUI.joinRequest(player); + return false; + } if(Commands.checkGetLeader(player) == null) return false; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java index 2b13154..322e6e8 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java @@ -23,11 +23,15 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.countdown.EnternCountdown; import de.steamwar.sql.PersonalKit; import de.steamwar.sql.SteamwarUser; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import java.util.UUID; + public class FightPlayer { - private final Player player; + private final UUID uuid; + private Player player; private final FightTeam team; private boolean isOut; private Kit kit; @@ -35,6 +39,7 @@ public class FightPlayer { private EnternCountdown enternCountdown = null; FightPlayer(Player player, FightTeam team) { + this.uuid = player.getUniqueId(); this.player = player; this.team = team; this.isOut = false; @@ -70,7 +75,10 @@ public class FightPlayer { } public Player getPlayer() { - return this.player; + Player bukkit = Bukkit.getPlayer(uuid); + if(bukkit != player) + player = bukkit; + return player; } public boolean isLiving() { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index b396a3e..de3609a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -46,6 +46,7 @@ import org.bukkit.scoreboard.NameTagVisibility; import org.bukkit.scoreboard.Team; import java.util.*; +import java.util.function.Consumer; public class FightTeam { @@ -90,7 +91,7 @@ public class FightTeam { private FightPlayer leader; private int schemRank; - private final Map players = new HashMap<>(); + private final Map players = new HashMap<>(); private String name; private String prefix; @@ -164,11 +165,11 @@ public class FightTeam { } public void teleportToSpawn(){ - players.forEach((player, fp) -> player.teleport(spawn)); + players.forEach((player, fp) -> Objects.requireNonNull(Bukkit.getPlayer(player)).teleport(spawn)); } public FightPlayer getFightPlayer(Player player) { - return players.get(player); + return players.get(player.getUniqueId()); } public boolean allPlayersOut() { @@ -180,7 +181,7 @@ public class FightTeam { } public boolean isPlayerInTeam(Player player) { - return players.containsKey(player); + return players.containsKey(player.getUniqueId()); } public boolean canPlayerEntern(Player player) { @@ -199,22 +200,23 @@ public class FightTeam { ready = false; schematic.reset(); - Set playerSet = new HashSet<>(players.keySet()); - for(Player player : playerSet){ - if(!Bukkit.getOnlinePlayers().contains(player)) + Set playerSet = new HashSet<>(players.keySet()); + for(UUID uuid : playerSet){ + Player player = Bukkit.getPlayer(uuid); + if(player != null) removePlayer(player); } FightPlayer leaderBackup = leader; - playerSet.removeIf(player -> !Bukkit.getOnlinePlayers().contains(player)); + playerSet.removeIf(uuid -> Bukkit.getPlayer(uuid) == null); players.clear(); leader = null; if(leaderBackup != null){ - playerSet.remove(leaderBackup.getPlayer()); + playerSet.remove(leaderBackup.getPlayer().getUniqueId()); addMember(leaderBackup.getPlayer(), true); } - playerSet.forEach(p -> addMember(p, true)); + playerSet.forEach(uuid -> addMember(Bukkit.getPlayer(uuid), true)); if(ArenaMode.VariableTeams.contains(Config.mode) && isLeaderless()){ List onlinePlayers = new ArrayList<>(Bukkit.getOnlinePlayers()); @@ -229,15 +231,23 @@ public class FightTeam { } public void broadcast(String message, Object... params) { - players.forEach((player, fp) -> FightSystem.getMessage().sendPrefixless(message, player, ChatMessageType.ACTION_BAR, params)); + broadcast(player -> FightSystem.getMessage().sendPrefixless(message, player, ChatMessageType.ACTION_BAR, params)); } public void broadcastSystem(String message, Object... params) { - players.forEach((player, fp) -> FightSystem.getMessage().send(message, player, params)); + broadcast(player -> FightSystem.getMessage().send(message, player, params)); } public void broadcastChat(Player sender, String message) { - players.forEach((player, fp) -> FightSystem.getMessage().sendPrefixless("TEAM_CHAT", player, ChatMessageType.CHAT, prefix, sender.getName(), message)); + broadcast(player -> FightSystem.getMessage().sendPrefixless("TEAM_CHAT", player, ChatMessageType.CHAT, prefix, sender.getName(), message)); + } + + private void broadcast(Consumer f) { + players.forEach((uuid, fightPlayer) -> { + Player player = Bukkit.getPlayer(uuid); + if(player != null) + f.accept(player); + }); } public void addMember(Player player) { @@ -248,7 +258,7 @@ public class FightTeam { final List chunksToReload = FightSystem.getTechHider().prepareChunkReload(player, false); FightPlayer fightPlayer = getFightPlayer(player) != null ? getFightPlayer(player) : new FightPlayer(player, this); fightPlayer.revive(); - players.put(player, fightPlayer); + players.put(player.getUniqueId(), fightPlayer); Permanent.getSpectatorTeam().removeEntry(player.getName()); team.addEntry(player.getName()); @@ -281,7 +291,7 @@ public class FightTeam { PersonalKitCreator.closeIfInKitCreator(player); List chunksToReload = FightSystem.getTechHider().prepareChunkReload(player, true); - players.remove(player); + players.remove(player.getUniqueId()); team.removeEntry(player.getName()); Permanent.getSpectatorTeam().addEntry(player.getName()); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java index d86df76..cf4acc6 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java @@ -76,6 +76,7 @@ public class JoinRequest { } activeRequests.put(player, this); + FightSystem.getMessage().sendPrefixless("JOIN_REQUEST_CONFIRMATION", player, ChatMessageType.ACTION_BAR); } public boolean required(FightTeam decider) { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java index 4ae1875..0c4fc57 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java @@ -25,6 +25,7 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.fight.HotbarKit; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.utils.BountifulWrapper; @@ -76,6 +77,7 @@ public class Permanent implements Listener { FightTeam team = Fight.getPlayerTeam(player); event.setRespawnLocation(team == null ? Config.SpecSpawn : team.getSpawn()); + HotbarKit.spectatorKit.loadToPlayer(player); } } diff --git a/FightSystem_Core/src/plugin.yml b/FightSystem_Core/src/plugin.yml index e405591..abc32f9 100644 --- a/FightSystem_Core/src/plugin.yml +++ b/FightSystem_Core/src/plugin.yml @@ -12,6 +12,7 @@ api-version: "1.13" commands: ak: + request: requests: leave: ready: -- 2.39.2 From 6081c5f5656b30dfc2fcf246eee63a5cd658152f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 6 Jun 2023 17:55:55 +0200 Subject: [PATCH 5/8] Prevent players from switching teams Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/commands/GUI.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java index 7ec6598..a160962 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java @@ -61,8 +61,10 @@ public class GUI { } SWInventory inv = new SWInventory(p, 9, msg.parse("JOIN_REQUEST_TITLE", p)); - addTeamRequest(p, inv, 0, Fight.getBlueTeam()); - addTeamRequest(p, inv, 8, Fight.getRedTeam()); + if(!Fight.getRedTeam().isPlayerInTeam(p)) + addTeamRequest(p, inv, 0, Fight.getBlueTeam()); + if(!Fight.getBlueTeam().isPlayerInTeam(p)) + addTeamRequest(p, inv, 8, Fight.getRedTeam()); inv.open(); } -- 2.39.2 From 43e63b4201ee1add6be3887e90b112d29cef46ef Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 6 Jun 2023 18:44:17 +0200 Subject: [PATCH 6/8] Bugfixes: Offline players, rejoining Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightPlayer.java | 2 +- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 2 +- .../src/de/steamwar/fightsystem/listener/Permanent.java | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java index 322e6e8..ed2e6d5 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java @@ -76,7 +76,7 @@ public class FightPlayer { public Player getPlayer() { Player bukkit = Bukkit.getPlayer(uuid); - if(bukkit != player) + if(bukkit != null) player = bukkit; return player; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index de3609a..a877f9f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -203,7 +203,7 @@ public class FightTeam { Set playerSet = new HashSet<>(players.keySet()); for(UUID uuid : playerSet){ Player player = Bukkit.getPlayer(uuid); - if(player != null) + if(player == null) removePlayer(player); } FightPlayer leaderBackup = leader; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java index 0c4fc57..de63b33 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java @@ -95,11 +95,16 @@ public class Permanent implements Listener { event.setJoinMessage(null); Player player = event.getPlayer(); + FightPlayer fp = Fight.getFightPlayer(player); - if (!Config.ArenaLeaveable && !Fight.fighting(player)) { + if (!Config.ArenaLeaveable && fp == null) { Fight.setPlayerGamemode(player, GameMode.SPECTATOR); spectatorTeam.addEntry(player.getName()); player.teleport(Config.SpecSpawn); + } else if(fp != null && !fp.isLiving()) { + Fight.setPlayerGamemode(player, GameMode.SPECTATOR); + HotbarKit.spectatorKit.loadToPlayer(player); + player.teleport(fp.getTeam().getSpawn()); } } -- 2.39.2 From cbb0dcf8ebdf4ceffb627489d07cc1599f0fada6 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 13 Jun 2023 22:00:43 +0200 Subject: [PATCH 7/8] Some of the requested changes Signed-off-by: Lixfel --- .../fightsystem/FightSystem.properties | 22 ++----------------- .../fightsystem/FightSystem_de.properties | 22 ++----------------- .../de/steamwar/fightsystem/commands/GUI.java | 9 ++++---- .../steamwar/fightsystem/fight/FightTeam.java | 2 +- .../steamwar/fightsystem/fight/HotbarKit.java | 4 ++-- .../fightsystem/fight/JoinRequest.java | 2 +- .../listener/JoinRequestListener.java | 2 +- .../fightsystem/listener/Permanent.java | 4 ++-- 8 files changed, 16 insertions(+), 51 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties index 0611c3e..a6ab2ab 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties @@ -25,13 +25,6 @@ FIGHT_ALREADY_STARTED=§cThe fight already started NOT_LEADER=§cYou aren't a leader PLAYER_UNAVAILABLE=§cThe player is not in an arena -NO_INVITATION=§cYou weren't invited by any team -INVITATION_DECLINED=§cInvitation declined -INVITATION_DECLINED_TEAM=§e{0} §chas declined the invitation -PLAYER_IN_TEAM=§e{0} §cis already in a team -ALREADY_INVITED=§e{0} §cwas invited -INVITATION_SENT=§e{0} §7invited - NOT_IN_TEAM=§e{0} §cis not in your team KIT_UNAVAILABLE=§cThis kit does not exist @@ -41,8 +34,6 @@ GAMEMODE_NOT_ALLOWED=§cChanging gamemode is not permitted GAMEMODE_UNKNOWN=§cUnknown gamemode {0} GAMEMODE_HELP=§8/§7gm §8[§egamemode§8] -INVITE_HELP=§8/§einvite §8[§eplayer§8] - LEADER_FULL=§cAll teams already have a leader ALREADY_IN_TEAM=§cYou are already in a team @@ -58,12 +49,6 @@ WIN_HELP=§8/§7win §8[§eteam §8or §etie§8] # GUI -INVITATION_TITLE=Invitation from {0} -INVITATION_ACCEPT=§aAccept -INVITATION_DECLINE=§cDecline -INVITATION_CHAT_ACCEPT=§8/§aaccept§8, §7to §aaccept§7 the invitation -INVITATION_CHAT_DECLINE=§8/§cdecline§8, §7to §cdecline§7 the invitation - STATE_TITLE=Fight state STATE_PRE_LEADER_SETUP=§7Team leader waiting phase STATE_PRE_SCHEM_SETUP=§7Schematic selection phase @@ -73,8 +58,6 @@ STATE_RUNNING=§eFighting phase STATE_SPECTATE_WIN=§7Victory {0} STATE_SPECTATE_TIE=§7Draw -INVITE_TITLE=Invite player - REMOVE_TITLE=Kick player KIT_SELECTION_TITLE=Kit selection @@ -119,7 +102,6 @@ SKIP_NOT_READY=§c§mSkipping to next event TEAM_CHAT={0}{1}§8» {0}{2} CHOOSE_KIT=§eChoose kit RESPAWN=§eRespawn -INVITE_PLAYERS=§eInvite player REMOVE_PLAYERS=§cKick player CHOOSE_SCHEMATIC=§eChoose {0} SCHEMATIC_REQUIRED=§cChoose a schematic first @@ -250,14 +232,14 @@ AMONG_US_IMPOSTER_AMONG_MESSAGE = §4There is an Imposter among us§8! §7Kill h JOIN_REQUEST=§7Request join JOIN_REQUEST_TITLE=Request join JOIN_REQUEST_ALREADY=§cYou have already sent a join request -JOIN_REQUEST_TEAM=§eJoin {0} +JOIN_REQUEST_TEAM=§7Join {0} JOIN_REQUEST_CONFIRMATION=§7Join request submitted JOIN_REQUEST_NOTIFICATION=§e{0} §7requests joining team {1}§8. §7Accept or decline using §8/§erequests REQUESTS=§7Open join requests REQUESTS_TITLE=Open join requests REQUEST_DECLINED=§cJoin of {0} declined -YOUR_REQUEST_DECLINED=§cYour join request was declined +REQUEST_YOUR_DECLINED=§cYour join request was declined REQUESTS_LEFT_CLICK=§eLeft click §7to §eaccept§8! REQUESTS_RIGHT_CLICK=§eRight click §7to §edecline§8! diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties index 0bd4755..415652c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem_de.properties @@ -23,13 +23,6 @@ FIGHT_ALREADY_STARTED=§cDer Kampf hat bereits begonnen NOT_LEADER=§cDu bist kein Leader PLAYER_UNAVAILABLE=§cDer Spieler ist nicht in der Arena -NO_INVITATION=§cDu wurdest von keinem Team eingeladen -INVITATION_DECLINED=§cEinladung abgelehnt -INVITATION_DECLINED_TEAM=§e{0} §chat die Einladung abgelehnt -PLAYER_IN_TEAM=§e{0} §cist bereits in einem Team -ALREADY_INVITED=§e{0} §cwurde bereits eingeladen -INVITATION_SENT=§e{0} §7eingeladen - NOT_IN_TEAM=§e{0} §cist nicht in deinem Team KIT_UNAVAILABLE=§cDieses Kit gibt es nicht @@ -39,8 +32,6 @@ GAMEMODE_NOT_ALLOWED=§cSpielmodusänderung verboten GAMEMODE_UNKNOWN=§cUnbekannter Spielmodus {0} GAMEMODE_HELP=§8/§7gm §8[§eSpielmodus§8] -INVITE_HELP=§8/§einvite §8[§eSpieler§8] - LEADER_FULL=§cAlle Teams haben bereits einen Leader ALREADY_IN_TEAM=§cDu bist bereits in einem Team @@ -56,12 +47,6 @@ WIN_HELP=§8/§7win §8[§eTeam §8oder §etie§8] # GUI -INVITATION_TITLE=Einladung von {0} -INVITATION_ACCEPT=§aAnnehmen -INVITATION_DECLINE=§cAblehnen -INVITATION_CHAT_ACCEPT=§8/§aaccept§8, §7um die Einladung §aanzunehmen -INVITATION_CHAT_DECLINE=§8/§cdecline§8, §7um die Einladung §cabzulehnen - STATE_TITLE=Kampfstatus STATE_PRE_LEADER_SETUP=§7Teamleaderwartephase STATE_PRE_SCHEM_SETUP=§7Schemauswahlphase @@ -71,8 +56,6 @@ STATE_RUNNING=§eKampfphase STATE_SPECTATE_WIN=§7Sieg {0} STATE_SPECTATE_TIE=§7Unentschieden -INVITE_TITLE=Spieler einladen - REMOVE_TITLE=Spieler rauswerfen KIT_SELECTION_TITLE=Kitauswahl @@ -116,7 +99,6 @@ SKIP_READY=§aBeschleunigung zum nächsten Event SKIP_NOT_READY=§c§mBeschleunigung zum nächsten Event CHOOSE_KIT=§eKit wählen RESPAWN=§eRespawn -INVITE_PLAYERS=§eSpieler einladen REMOVE_PLAYERS=§cSpieler rauswerfen CHOOSE_SCHEMATIC=§e{0} wählen SCHEMATIC_REQUIRED=§cZuerst muss eine Schematic gewählt sein @@ -234,14 +216,14 @@ AMONG_US_IMPOSTER_AMONG_MESSAGE = §4Es ist ein Imposter unter uns§8! §7Tötet JOIN_REQUEST=§7Teambeitritt anfragen JOIN_REQUEST_TITLE=Teambeitritt anfragen JOIN_REQUEST_ALREADY=§cDu hast bereits ein Team um Beitritt angefragt -JOIN_REQUEST_TEAM={0} §ebeitreten +JOIN_REQUEST_TEAM={0} §7beitreten JOIN_REQUEST_CONFIRMATION=§7Teambeitritt angefragt JOIN_REQUEST_NOTIFICATION=§e{0} §7möchte Team {1} §7beitreten§8. §7Akzeptiere oder lehne ab mit §8/§erequests REQUESTS=§7Offene Beitrittsanfragen REQUESTS_TITLE=Offene Beitrittsanfragen REQUEST_DECLINED=§cBeitritt von {0} abgelehnt -YOUR_REQUEST_DECLINED=§cDeine Betrittsanfrage wurde abgelehnt +REQUEST_YOUR_DECLINED=§cDeine Betrittsanfrage wurde abgelehnt REQUESTS_LEFT_CLICK=§eLinksklick §7um §eanzunehmen§8! REQUESTS_RIGHT_CLICK=§eRechtsklick §7um §eabzulehnen§8! diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java index a160962..cb63550 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java @@ -61,10 +61,11 @@ public class GUI { } SWInventory inv = new SWInventory(p, 9, msg.parse("JOIN_REQUEST_TITLE", p)); - if(!Fight.getRedTeam().isPlayerInTeam(p)) - addTeamRequest(p, inv, 0, Fight.getBlueTeam()); - if(!Fight.getBlueTeam().isPlayerInTeam(p)) - addTeamRequest(p, inv, 8, Fight.getRedTeam()); + FightTeam team = Fight.getPlayerTeam(p); + if(team != Fight.getRedTeam()) + addTeamRequest(p, inv, team == null ? 0 : 4, Fight.getBlueTeam()); + if(team != Fight.getBlueTeam()) + addTeamRequest(p, inv, team == null ? 8 : 4, Fight.getRedTeam()); inv.open(); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index a877f9f..ecd5b8a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -307,7 +307,7 @@ public class FightTeam { if(player.isOnline()){ FightSystem.getTechHider().reloadChunks(player, chunksToReload, true); - HotbarKit.spectatorKit.loadToPlayer(player); + HotbarKit.SPECTATOR_KIT.loadToPlayer(player); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java index 044fea5..8310d2c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java @@ -48,10 +48,10 @@ import java.util.function.Consumer; public class HotbarKit extends Kit { - public static final HotbarKit spectatorKit = new HotbarKit(); + public static final HotbarKit SPECTATOR_KIT = new HotbarKit(); static { for(int i = 0; i < 9; i++) - spectatorKit.setItem(i, "JOIN_REQUEST", new ItemBuilder(Material.PAPER).removeAllAttributes().build(), GUI::joinRequest); + SPECTATOR_KIT.setItem(i, "JOIN_REQUEST", new ItemBuilder(Material.PAPER).removeAllAttributes().build(), GUI::joinRequest); } private static final int HOTBAR_SIZE = 9; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java index cf4acc6..13ab67a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/JoinRequest.java @@ -93,7 +93,7 @@ public class JoinRequest { } public void decline(FightTeam declinor) { - FightSystem.getMessage().sendPrefixless("YOUR_REQUEST_DECLINED", player, ChatMessageType.ACTION_BAR); + FightSystem.getMessage().sendPrefixless("REQUEST_YOUR_DECLINED", player, ChatMessageType.ACTION_BAR); waitOnApproval.forEach(t -> t.broadcast("REQUEST_DECLINED", player.getName())); silentDecline(); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java index 11ab3be..ad634a2 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java @@ -50,7 +50,7 @@ public class JoinRequestListener implements Listener { Player player = event.getPlayer(); if (!Config.ArenaLeaveable && !Fight.fighting(player)) { - HotbarKit.spectatorKit.loadToPlayer(player); + HotbarKit.SPECTATOR_KIT.loadToPlayer(player); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java index de63b33..cb17931 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java @@ -77,7 +77,7 @@ public class Permanent implements Listener { FightTeam team = Fight.getPlayerTeam(player); event.setRespawnLocation(team == null ? Config.SpecSpawn : team.getSpawn()); - HotbarKit.spectatorKit.loadToPlayer(player); + HotbarKit.SPECTATOR_KIT.loadToPlayer(player); } } @@ -103,7 +103,7 @@ public class Permanent implements Listener { player.teleport(Config.SpecSpawn); } else if(fp != null && !fp.isLiving()) { Fight.setPlayerGamemode(player, GameMode.SPECTATOR); - HotbarKit.spectatorKit.loadToPlayer(player); + HotbarKit.SPECTATOR_KIT.loadToPlayer(player); player.teleport(fp.getTeam().getSpawn()); } } -- 2.39.2 From 5e4190ea75ad09b53cafc11fa048ff22d66919f4 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 25 Jun 2023 20:07:41 +0200 Subject: [PATCH 8/8] Limit JoinAnytime to variable teams Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/fight/FightTeam.java | 4 +++- .../fightsystem/listener/JoinRequestListener.java | 13 ++++++++++++- .../de/steamwar/fightsystem/listener/Permanent.java | 3 --- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index ecd5b8a..ca19f3b 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -307,7 +307,9 @@ public class FightTeam { if(player.isOnline()){ FightSystem.getTechHider().reloadChunks(player, chunksToReload, true); - HotbarKit.SPECTATOR_KIT.loadToPlayer(player); + + if(ArenaMode.VariableTeams.contains(Config.mode)) + HotbarKit.SPECTATOR_KIT.loadToPlayer(player); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java index ad634a2..1ed3fe8 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/JoinRequestListener.java @@ -23,6 +23,7 @@ import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.HotbarKit; import de.steamwar.fightsystem.fight.JoinRequest; import de.steamwar.fightsystem.states.FightState; @@ -35,6 +36,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerRespawnEvent; public class JoinRequestListener implements Listener { @@ -48,12 +50,21 @@ public class JoinRequestListener implements Listener { @EventHandler(priority = EventPriority.HIGH) public void onJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); + FightPlayer fp = Fight.getFightPlayer(player); - if (!Config.ArenaLeaveable && !Fight.fighting(player)) { + if (!Config.ArenaLeaveable && (fp == null || !fp.isLiving())) { HotbarKit.SPECTATOR_KIT.loadToPlayer(player); } } + @EventHandler + public void handlePlayerRespawn(PlayerRespawnEvent event) { + Player player = event.getPlayer(); + if(Fight.fighting(player)) { + HotbarKit.SPECTATOR_KIT.loadToPlayer(player); + } + } + @EventHandler public void onLeave(PlayerQuitEvent event) { JoinRequest request = JoinRequest.get(event.getPlayer()); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java index cb17931..b5cb0e7 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java @@ -25,7 +25,6 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.fight.HotbarKit; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.utils.BountifulWrapper; @@ -77,7 +76,6 @@ public class Permanent implements Listener { FightTeam team = Fight.getPlayerTeam(player); event.setRespawnLocation(team == null ? Config.SpecSpawn : team.getSpawn()); - HotbarKit.SPECTATOR_KIT.loadToPlayer(player); } } @@ -103,7 +101,6 @@ public class Permanent implements Listener { player.teleport(Config.SpecSpawn); } else if(fp != null && !fp.isLiving()) { Fight.setPlayerGamemode(player, GameMode.SPECTATOR); - HotbarKit.SPECTATOR_KIT.loadToPlayer(player); player.teleport(fp.getTeam().getSpawn()); } } -- 2.39.2