use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.
the class StartCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
if (args != null) {
Minigame mgm = plugin.getMinigameManager().getMinigame(args[0]);
if (mgm != null) {
if (!mgm.isEnabled() && mgm.getType() == MinigameType.GLOBAL) {
MinigamePlayer caller = null;
if (sender instanceof Player)
caller = plugin.getPlayerManager().getMinigamePlayer((Player) sender);
plugin.getMinigameManager().startGlobalMinigame(mgm, caller);
} else if (mgm.getType() != MinigameType.GLOBAL && mgm.getType() != MinigameType.SINGLEPLAYER && mgm.hasPlayers()) {
if (mgm.getMpTimer() == null || mgm.getMpTimer().getPlayerWaitTimeLeft() != 0) {
if (mgm.getMpTimer() == null) {
mgm.setMpTimer(new MultiplayerTimer(mgm));
}
mgm.getMpTimer().setCurrentLobbyWaitTime(0);
mgm.getMpTimer().startTimer();
} else
sender.sendMessage(ChatColor.RED + mgm.getName(false) + " has already started.");
} else if (mgm.isEnabled() && mgm.getType() == MinigameType.GLOBAL) {
sender.sendMessage(ChatColor.RED + mgm.getName(false) + " is already running!");
}
} else {
sender.sendMessage(ChatColor.RED + "No Global or Multiplayer Minigame found by the name " + args[0]);
}
return true;
}
return false;
}
use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.
the class TeleportCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
if (args != null) {
List<Player> plys = plugin.getServer().matchPlayer(args[0]);
MinigamePlayer ply = null;
if (!plys.isEmpty()) {
ply = plugin.getPlayerManager().getMinigamePlayer(plys.get(0));
} else {
sender.sendMessage(ChatColor.RED + "No player found by the name " + args[0] + "!");
return true;
}
if (args.length >= 4 && args[1].matches("~?(-?[0-9]+(.[0-9]+)?)|~") && args[2].matches("~?(-?[0-9]+(.[0-9]+)?)|~") && args[3].matches("~?(-?[0-9]+(.[0-9]+)?)|~")) {
double x = 0;
double y = 0;
double z = 0;
float yaw = ply.getLocation().getYaw();
float pitch = ply.getLocation().getPitch();
if (args[1].contains("~")) {
if (args[1].equals("~"))
x = ply.getPlayer().getLocation().getX();
else
x = ply.getPlayer().getLocation().getX() + Double.parseDouble(args[1].replace("~", ""));
} else {
x = Double.parseDouble(args[1]);
}
if (args[2].contains("~")) {
if (args[2].equals("~"))
y = ply.getPlayer().getLocation().getY();
else
y = ply.getPlayer().getLocation().getY() + Double.parseDouble(args[2].replace("~", ""));
} else {
y = Double.parseDouble(args[2]);
}
if (args[3].contains("~")) {
if (args[3].equals("~"))
z = ply.getPlayer().getLocation().getZ();
else
z = ply.getPlayer().getLocation().getZ() + Double.parseDouble(args[3].replace("~", ""));
} else {
z = Double.parseDouble(args[3]);
}
if (args.length == 6 && args[4].matches("~?(-?[0-9]+(.[0-9]+)?)|~") && args[5].matches("~?(-?[0-9]+(.[0-9]+)?)|~")) {
if (args[4].contains("~")) {
if (args[4].equals("~"))
yaw = ply.getPlayer().getLocation().getYaw();
else
yaw = ply.getPlayer().getLocation().getYaw() + Float.parseFloat(args[4].replace("~", ""));
} else {
yaw = Float.parseFloat(args[4]);
}
if (args[5].contains("~")) {
if (args[5].equals("~"))
pitch = ply.getPlayer().getLocation().getPitch();
else {
pitch = ply.getPlayer().getLocation().getPitch() + Float.parseFloat(args[5].replace("~", ""));
}
} else {
pitch = Float.parseFloat(args[5]);
}
if (pitch > 90) {
pitch = 90f;
} else if (pitch < -90) {
pitch = -90f;
}
}
sender.sendMessage(ChatColor.GRAY + "Teleported " + ply.getName() + " to assigned coordinates.");
ply.teleport(new Location(ply.getPlayer().getWorld(), x, y, z, yaw, pitch));
return true;
} else if (args.length >= 2 && args[1].equalsIgnoreCase("start")) {
if (ply.isInMinigame()) {
int pos = 0;
Team team = null;
if (args.length == 3)
team = TeamsModule.getMinigameModule(ply.getMinigame()).getTeam(TeamColor.matchColor(args[3]));
else if (ply.getTeam() != null)
team = ply.getTeam();
if (args.length >= 3 && args[2].matches("[0-9]+") && !args[2].equals("0"))
pos = Integer.parseInt(args[2]) - 1;
if (team == null && pos >= ply.getMinigame().getStartLocations().size())
pos = ply.getMinigame().getStartLocations().size() - 1;
else if (team != null && pos >= team.getStartLocations().size())
pos = team.getStartLocations().size() - 1;
if (team != null) {
ply.teleport(team.getStartLocations().get(pos));
sender.sendMessage(ChatColor.GRAY + "Teleported " + ply.getName() + " to " + team.getDisplayName() + " start position " + (pos + 1) + ".");
} else {
ply.teleport(ply.getMinigame().getStartLocations().get(pos));
sender.sendMessage(ChatColor.GRAY + "Teleported " + ply.getName() + " to start position " + (pos + 1) + ".");
}
} else {
sender.sendMessage(ChatColor.RED + ply.getName() + " is not in a Minigame!");
}
return true;
} else if (args.length == 2 && args[1].equalsIgnoreCase("checkpoint")) {
if (ply.isInMinigame()) {
ply.teleport(ply.getCheckpoint());
sender.sendMessage(ChatColor.GRAY + "Teleported " + ply.getName() + " to their checkpoint.");
} else {
sender.sendMessage(ChatColor.RED + ply.getName() + " is not in a Minigame!");
}
return true;
} else if (args.length == 2) {
plys = plugin.getServer().matchPlayer(args[1]);
MinigamePlayer ply2 = null;
if (!plys.isEmpty()) {
ply2 = plugin.getPlayerManager().getMinigamePlayer(plys.get(0));
} else {
sender.sendMessage(ChatColor.RED + "No player found by the name " + args[1] + "!");
return true;
}
ply.teleport(ply2.getPlayer().getLocation());
sender.sendMessage(ChatColor.GRAY + "Teleported " + ply.getName() + " to " + ply2.getName() + ".");
return true;
}
}
return false;
}
use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.
the class MenuItemToolTeam method onClick.
@Override
public ItemStack onClick() {
super.onClick();
MinigamePlayer ply = getContainer().getViewer();
if (MinigameUtils.hasMinigameTool(ply)) {
MinigameTool tool = MinigameUtils.getMinigameTool(ply);
tool.setTeam(TeamColor.matchColor(value.getValue().replace(" ", "_")));
}
return getItem();
}
use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.
the class LoadoutModule method displaySelectionMenu.
public void displaySelectionMenu(MinigamePlayer player, final boolean equip) {
Menu m = new Menu(6, "Select Loadout", player);
final MinigamePlayer fply = player;
for (PlayerLoadout loadout : extraLoadouts.values()) {
if (loadout.isDisplayedInMenu()) {
if (!loadout.getUsePermissions() || player.getPlayer().hasPermission("minigame.loadout." + loadout.getName(false).toLowerCase())) {
if (!player.getMinigame().isTeamGame() || loadout.getTeamColor() == null || player.getTeam().getColor() == loadout.getTeamColor()) {
MenuItemCustom c = new MenuItemCustom(loadout.getName(true), Material.GLASS);
if (!loadout.getItems().isEmpty()) {
ItemStack item = loadout.getItem(new ArrayList<>(loadout.getItems()).get(0));
c.setItem(item);
}
final PlayerLoadout floadout2 = loadout;
c.setClick(object -> {
fply.setLoadout(floadout2);
fply.getPlayer().closeInventory();
if (!equip)
fply.sendMessage(MinigameUtils.getLang("player.loadout.nextSpawn"), MinigameMessageType.INFO);
else {
fply.sendMessage(MinigameUtils.formStr("player.loadout.equipped", floadout2.getName(true)), MinigameMessageType.INFO);
floadout2.equiptLoadout(fply);
}
return null;
});
m.addItem(c);
}
}
}
}
m.displayMenu(player);
}
use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.
the class FinishSign method signUse.
@Override
public boolean signUse(Sign sign, MinigamePlayer player) {
if (player.isInMinigame() && player.getPlayer().getInventory().getItemInMainHand().getType() == Material.AIR) {
Minigame minigame = player.getMinigame();
if (minigame.isSpectator(player) || minigame.getState() == MinigameState.ENDED) {
return false;
}
if (!minigame.getFlags().isEmpty()) {
if (player.getPlayer().isOnGround()) {
if (plugin.getPlayerManager().checkRequiredFlags(player, minigame.getName(false)).isEmpty()) {
if (sign.getLine(2).isEmpty() || sign.getLine(2).equals(player.getMinigame().getName(false))) {
if (player.getMinigame().isTeamGame()) {
List<MinigamePlayer> w = new ArrayList<>(player.getTeam().getPlayers());
List<MinigamePlayer> l = new ArrayList<>(minigame.getPlayers().size() - player.getTeam().getPlayers().size());
for (Team t : TeamsModule.getMinigameModule(minigame).getTeams()) {
if (t != player.getTeam())
l.addAll(t.getPlayers());
}
plugin.getPlayerManager().endMinigame(minigame, w, l);
} else {
if (minigame.getType() == MinigameType.MULTIPLAYER) {
List<MinigamePlayer> w = new ArrayList<>(1);
w.add(player);
List<MinigamePlayer> l = new ArrayList<>(minigame.getPlayers().size());
l.addAll(minigame.getPlayers());
l.remove(player);
plugin.getPlayerManager().endMinigame(minigame, w, l);
} else
plugin.getPlayerManager().endMinigame(player);
}
plugin.getPlayerManager().partyMode(player, 3, 10L);
}
} else {
List<String> requiredFlags = plugin.getPlayerManager().checkRequiredFlags(player, minigame.getName(false));
String flags = "";
int num = requiredFlags.size();
for (int i = 0; i < num; i++) {
flags += requiredFlags.get(i);
if (i != num - 1) {
flags += ", ";
}
}
player.sendInfoMessage(MinigameUtils.getLang("sign.finish.requireFlags"));
player.sendInfoMessage(ChatColor.GRAY + flags);
}
}
return true;
} else {
if (player.getPlayer().isOnGround()) {
if (player.getMinigame().isTeamGame()) {
List<MinigamePlayer> w = new ArrayList<>(player.getTeam().getPlayers());
List<MinigamePlayer> l = new ArrayList<>(minigame.getPlayers().size() - player.getTeam().getPlayers().size());
for (Team t : TeamsModule.getMinigameModule(minigame).getTeams()) {
if (t != player.getTeam())
l.addAll(t.getPlayers());
}
plugin.getPlayerManager().endMinigame(minigame, w, l);
} else {
if (minigame.getType() == MinigameType.MULTIPLAYER) {
List<MinigamePlayer> w = new ArrayList<>(1);
w.add(player);
List<MinigamePlayer> l = new ArrayList<>(minigame.getPlayers().size());
l.addAll(minigame.getPlayers());
l.remove(player);
plugin.getPlayerManager().endMinigame(minigame, w, l);
} else
plugin.getPlayerManager().endMinigame(player);
}
plugin.getPlayerManager().partyMode(player);
return true;
}
}
} else if (player.getPlayer().getInventory().getItemInMainHand().getType() != Material.AIR) {
player.sendMessage(MinigameUtils.getLang("sign.emptyHand"), MinigameMessageType.ERROR);
}
return false;
}
Aggregations