Allow /team to be used in Cake Wars Duos and improve TeamModule
This commit is contained in:
parent
1350cf63c8
commit
442907341b
@ -245,7 +245,7 @@ public class GameTeam
|
||||
|
||||
public ArrayList<Player> GetPlayers(boolean playerIn)
|
||||
{
|
||||
ArrayList<Player> alive = new ArrayList<Player>();
|
||||
ArrayList<Player> alive = new ArrayList<>();
|
||||
|
||||
for (Player player : _players.keySet())
|
||||
if (!playerIn || (_players.get(player) == PlayerState.IN && player.isOnline()))
|
||||
|
@ -3,6 +3,7 @@ package nautilus.game.arcade.game.games.cakewars.modes;
|
||||
import nautilus.game.arcade.ArcadeManager;
|
||||
import nautilus.game.arcade.GameType;
|
||||
import nautilus.game.arcade.game.games.cakewars.CakeWars;
|
||||
import nautilus.game.arcade.game.modules.TeamModule;
|
||||
|
||||
public class CakeWarsDuos extends CakeWars
|
||||
{
|
||||
@ -10,5 +11,10 @@ public class CakeWarsDuos extends CakeWars
|
||||
public CakeWarsDuos(ArcadeManager manager)
|
||||
{
|
||||
super(manager, GameType.CakeWarsDuos);
|
||||
|
||||
HideTeamSheep = true;
|
||||
|
||||
new TeamModule()
|
||||
.register(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
package nautilus.game.arcade.game.modules;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import nautilus.game.arcade.game.Game;
|
||||
import nautilus.game.arcade.game.GameTeam;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -12,26 +11,34 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import mineplex.core.common.jsonchat.ClickEvent;
|
||||
import mineplex.core.common.jsonchat.HoverEvent;
|
||||
import mineplex.core.common.jsonchat.JsonMessage;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
|
||||
import nautilus.game.arcade.game.Game.GameState;
|
||||
import nautilus.game.arcade.game.GameTeam;
|
||||
|
||||
public class TeamModule extends Module
|
||||
{
|
||||
private Map<UUID, UUID> _teamReqs = new HashMap<>();
|
||||
|
||||
private final Map<UUID, UUID> _teamRequests;
|
||||
|
||||
public TeamModule()
|
||||
{
|
||||
_teamRequests = new HashMap<>();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void teamSelectInteract(PlayerInteractEntityEvent event)
|
||||
{
|
||||
if (getGame().GetState() != Game.GameState.Recruit)
|
||||
return;
|
||||
|
||||
if (event.getRightClicked() == null)
|
||||
return;
|
||||
|
||||
if (!(event.getRightClicked() instanceof Player))
|
||||
if (getGame().GetState() != GameState.Recruit || !(event.getRightClicked() instanceof Player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
@ -49,13 +56,15 @@ public class TeamModule extends Module
|
||||
public void teamSelectCommand(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
if (!event.getMessage().toLowerCase().startsWith("/team "))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
if (getGame().GetState() != Game.GameState.Recruit)
|
||||
if (getGame().GetState() != GameState.Recruit)
|
||||
{
|
||||
UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot send team requests while the game is live"));
|
||||
UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot send team requests at this time!"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -70,7 +79,6 @@ public class TeamModule extends Module
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
UtilPlayer.message(event.getPlayer(), F.main("Game", "That player is not online"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -85,28 +93,38 @@ public class TeamModule extends Module
|
||||
|
||||
private void selectTeamMate(Player player, Player ally)
|
||||
{
|
||||
GameTeam playerTeam = getGame().GetTeam(player);
|
||||
GameTeam allyTeam = getGame().GetTeam(ally);
|
||||
|
||||
//Accept Invite
|
||||
if (_teamReqs.containsKey(ally.getUniqueId()) && _teamReqs.get(ally.getUniqueId()).equals(player.getUniqueId()))
|
||||
if (_teamRequests.containsKey(ally.getUniqueId()) && _teamRequests.get(ally.getUniqueId()).equals(player.getUniqueId()))
|
||||
{
|
||||
//Remove Prefs
|
||||
_teamReqs.remove(player.getUniqueId());
|
||||
_teamReqs.remove(ally.getUniqueId());
|
||||
_teamRequests.remove(player.getUniqueId());
|
||||
_teamRequests.remove(ally.getUniqueId());
|
||||
|
||||
//Inform
|
||||
UtilPlayer.message(player, F.main("Game", "You accepted " + ally.getName() + "'s Team Request!"));
|
||||
UtilPlayer.message(ally, F.main("Game", player.getName() + " accepted your Team Request!"));
|
||||
|
||||
//Leave Old Teams
|
||||
if (getGame().GetTeam(player) != null)
|
||||
getGame().GetTeam(player).DisbandTeam();
|
||||
if (playerTeam != null)
|
||||
{
|
||||
playerTeam.DisbandTeam();
|
||||
}
|
||||
|
||||
if (getGame().GetTeam(ally) != null)
|
||||
getGame().GetTeam(ally).DisbandTeam();
|
||||
if (allyTeam != null)
|
||||
{
|
||||
allyTeam.DisbandTeam();
|
||||
}
|
||||
|
||||
//Get Team
|
||||
GameTeam team = getEmptyTeam();
|
||||
|
||||
if (team == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
team.setDisplayName(player.getName() + " & " + ally.getName());
|
||||
|
||||
@ -118,55 +136,53 @@ public class TeamModule extends Module
|
||||
else
|
||||
{
|
||||
//Already on Team with Target
|
||||
if (getGame().GetTeam(player) != null)
|
||||
if (getGame().GetTeam(player).HasPlayer(ally))
|
||||
return;
|
||||
if (playerTeam != null && playerTeam.HasPlayer(ally))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Inform Player
|
||||
UtilPlayer.message(player, F.main("Game", "You sent a Team Request to " + ally.getName() + "!"));
|
||||
UtilPlayer.message(player, F.main("Game", "You sent a " + F.elem("Team Request") + " to " + F.name(ally.getName()) + "!"));
|
||||
|
||||
//Inform Target
|
||||
if (Recharge.Instance.use(player, "Team Req " + ally.getName(), 2000, false, false))
|
||||
{
|
||||
UtilPlayer.message(ally, F.main("Game", player.getName() + " sent you a Team Request!"));
|
||||
UtilPlayer.message(ally, F.main("Game", "Type " + F.elem("/team " + player.getName()) + " to accept!"));
|
||||
UtilPlayer.message(ally, F.main("Game", F.name(player.getName()) + " sent you a " + F.elem("Team Request") + "!"));
|
||||
new JsonMessage(F.main("Game", F.elem(C.Bold + "CLICK HERE") + " to join their team!"))
|
||||
.hover(HoverEvent.SHOW_TEXT, C.cYellow + "Click to join " + player.getName() + "'s team")
|
||||
.click(ClickEvent.RUN_COMMAND, "/team " + player.getName())
|
||||
.sendToPlayer(ally);
|
||||
}
|
||||
|
||||
//Add Pref
|
||||
_teamReqs.put(player.getUniqueId(), ally.getUniqueId());
|
||||
_teamRequests.put(player.getUniqueId(), ally.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler (priority = EventPriority.LOWEST)
|
||||
public void teamQuit(PlayerQuitEvent event)
|
||||
{
|
||||
if (getGame().GetState() != Game.GameState.Recruit)
|
||||
if (getGame().GetState() != GameState.Recruit)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
GameTeam team = getGame().GetTeam(player);
|
||||
|
||||
if (getGame().GetTeam(player) != null)
|
||||
getGame().GetTeam(player).DisbandTeam();
|
||||
|
||||
Iterator<Map.Entry<UUID, UUID>> iterator = _teamReqs.entrySet().iterator();
|
||||
while (iterator.hasNext())
|
||||
if (team != null)
|
||||
{
|
||||
Map.Entry<UUID, UUID> entry = iterator.next();
|
||||
if (entry.getKey().equals(player.getUniqueId()) || entry.getValue().equals(player.getUniqueId()))
|
||||
{
|
||||
iterator.remove();
|
||||
}
|
||||
team.DisbandTeam();
|
||||
}
|
||||
|
||||
_teamRequests.entrySet().removeIf(entry -> entry.getKey().equals(player.getUniqueId()) || entry.getValue().equals(player.getUniqueId()));
|
||||
}
|
||||
|
||||
private GameTeam getEmptyTeam()
|
||||
{
|
||||
for (GameTeam team : getGame().GetTeamList())
|
||||
{
|
||||
if (team.GetPlayers(false).isEmpty())
|
||||
return team;
|
||||
}
|
||||
|
||||
return null;
|
||||
return getGame().GetTeamList().stream()
|
||||
.filter(team -> team.GetSize() == 0)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user