use of org.bukkit.Location in project Minigames by AddstarMC.
the class PlayerData method startMPMinigame.
public void startMPMinigame(Minigame minigame, boolean teleport) {
List<MinigamePlayer> players = new ArrayList<MinigamePlayer>();
players.addAll(minigame.getPlayers());
Collections.shuffle(players);
if (minigame.isTeamGame() && GameMechanics.getGameMechanic(minigame.getMechanicName()) != null) {
GameMechanics.getGameMechanic(minigame.getMechanicName()).balanceTeam(players, minigame);
}
Location start = null;
int pos = 0;
Map<Team, Integer> tpos = new HashMap<Team, Integer>();
for (Team t : TeamsModule.getMinigameModule(minigame).getTeams()) {
tpos.put(t, 0);
}
for (MinigamePlayer ply : players) {
if (!minigame.isTeamGame()) {
if (pos < minigame.getStartLocations().size()) {
ply.setStartTime(Calendar.getInstance().getTimeInMillis());
if (teleport) {
start = minigame.getStartLocations().get(pos);
}
} else {
pos = 0;
if (!minigame.getStartLocations().isEmpty()) {
if (teleport) {
start = minigame.getStartLocations().get(0);
}
} else {
ply.sendMessage(MinigameUtils.getLang("minigame.error.incorrectStart"), "error");
quitMinigame(ply, false);
}
}
ply.setCheckpoint(start);
} else {
Team team = ply.getTeam();
if (TeamsModule.getMinigameModule(minigame).hasTeamStartLocations()) {
if (tpos.get(team) >= team.getStartLocations().size()) {
tpos.put(team, 0);
}
start = team.getStartLocations().get(tpos.get(team));
tpos.put(team, tpos.get(team) + 1);
} else {
if (pos < minigame.getStartLocations().size()) {
if (teleport) {
start = minigame.getStartLocations().get(pos);
}
} else {
pos = 0;
if (!minigame.getStartLocations().isEmpty()) {
if (teleport) {
start = minigame.getStartLocations().get(0);
}
} else {
ply.sendMessage(MinigameUtils.getLang("minigame.error.incorrectStart"), "error");
quitMinigame(ply, false);
}
}
}
if (minigame.getLives() > 0) {
ply.sendMessage(MinigameUtils.formStr("minigame.livesLeft", minigame.getLives()), null);
}
}
if (start != null) {
if (teleport) {
ply.teleport(start);
ply.setCheckpoint(start);
}
if (minigame.getMaxScore() != 0) {
ply.sendMessage(MinigameUtils.formStr("minigame.scoreToWin", minigame.getMaxScorePerPlayer()), null);
}
}
pos++;
ply.getLoadout().equiptLoadout(ply);
if (minigame.isAllowedFlight()) {
ply.setCanFly(true);
if (minigame.isFlightEnabled())
ply.getPlayer().setFlying(true);
}
PlayMGSound.playSound(ply, MGSounds.getSound("gameStart"));
}
Bukkit.getServer().getPluginManager().callEvent(new StartMinigameEvent(players, minigame, teleport));
minigame.setState(MinigameState.STARTED);
}
use of org.bukkit.Location in project Minigames by AddstarMC.
the class PlayerData method joinMinigame.
public void joinMinigame(MinigamePlayer player, Minigame minigame, boolean isBetting, Double betAmount) {
MinigameType type = minigame.getType();
JoinMinigameEvent event = new JoinMinigameEvent(player, minigame);
Bukkit.getServer().getPluginManager().callEvent(event);
boolean canStart = minigame.getMechanic().checkCanStart(minigame, player);
if (!event.isCancelled()) {
if ((minigame.isEnabled() || player.getPlayer().hasPermission("minigame.join.disabled")) && (minigame.getState() == MinigameState.IDLE || minigame.getState() == MinigameState.OCCUPIED || minigame.getState() == MinigameState.WAITING || (minigame.getState() == MinigameState.STARTED && minigame.canLateJoin())) && /*!minigame.isRegenerating() &&
(!minigame.isNotWaitingForPlayers() || (minigame.canLateJoin() && minigame.getMpTimer().getPlayerWaitTimeLeft() == 0)) &&*/
(minigame.getStartLocations().size() > 0 || (minigame.isTeamGame() && TeamsModule.getMinigameModule(minigame).hasTeamStartLocations())) && minigame.getEndPosition() != null && minigame.getQuitPosition() != null && (minigame.getType() == MinigameType.SINGLEPLAYER || minigame.getLobbyPosition() != null) && ((type == MinigameType.SINGLEPLAYER && !minigame.isSpMaxPlayers()) || minigame.getPlayers().size() < minigame.getMaxPlayers()) && minigame.getMechanic().validTypes().contains(minigame.getType()) && canStart) {
//Do betting stuff
if (isBetting) {
if (minigame.getMpBets() == null && (player.getPlayer().getInventory().getItemInMainHand().getType() != Material.AIR || betAmount != 0)) {
minigame.setMpBets(new MultiplayerBets());
}
MultiplayerBets pbet = minigame.getMpBets();
ItemStack item = player.getPlayer().getInventory().getItemInMainHand().clone();
if (pbet != null && ((betAmount != 0 && pbet.canBet(player, betAmount) && plugin.getEconomy().getBalance(player.getPlayer().getPlayer()) >= betAmount) || (pbet.canBet(player, item) && item.getType() != Material.AIR && pbet.betValue(item.getType()) > 0))) {
player.sendMessage(MinigameUtils.getLang("player.bet.plyMsg"), null);
if (betAmount == 0) {
pbet.addBet(player, item);
} else {
pbet.addBet(player, betAmount);
plugin.getEconomy().withdrawPlayer(player.getPlayer().getPlayer(), betAmount);
}
player.getPlayer().getInventory().removeItem(new ItemStack(item.getType(), 1));
} else if (item.getType() == Material.AIR && betAmount == 0) {
player.sendMessage(MinigameUtils.getLang("player.bet.plyNoBet"), "error");
return;
} else if (betAmount != 0 && !pbet.canBet(player, betAmount)) {
player.sendMessage(MinigameUtils.getLang("player.bet.incorrectAmount"), "error");
player.sendMessage(MinigameUtils.formStr("player.bet.incorrectAmountInfo", Minigames.plugin.getEconomy().format(minigame.getMpBets().getHighestMoneyBet())), "error");
return;
} else if (betAmount != 0 && plugin.getEconomy().getBalance(player.getPlayer().getPlayer()) < betAmount) {
player.sendMessage(MinigameUtils.getLang("player.bet.notEnoughMoney"), "error");
player.sendMessage(MinigameUtils.formStr("player.bet.notEnoughMoneyInfo", Minigames.plugin.getEconomy().format(minigame.getMpBets().getHighestMoneyBet())), "error");
return;
} else {
player.sendMessage(MinigameUtils.getLang("player.bet.incorrectItem"), "error");
player.sendMessage(MinigameUtils.formStr("player.bet.incorrectItemInfo", 1, minigame.getMpBets().highestBetName()), "error");
return;
}
}
//Try teleport the player to their designated area.
boolean tpd = false;
if (type == MinigameType.SINGLEPLAYER) {
List<Location> locs = new ArrayList<Location>(minigame.getStartLocations());
Collections.shuffle(locs);
tpd = player.teleport(locs.get(0));
if (plugin.getConfig().getBoolean("warnings") && player.getPlayer().getWorld() != locs.get(0).getWorld() && player.getPlayer().hasPermission("minigame.set.start")) {
player.sendMessage(ChatColor.RED + "WARNING: " + ChatColor.WHITE + "Join location is across worlds! This may cause some server performance issues!", "error");
}
} else {
tpd = player.teleport(minigame.getLobbyPosition());
if (plugin.getConfig().getBoolean("warnings") && player.getPlayer().getWorld() != minigame.getLobbyPosition().getWorld() && player.getPlayer().hasPermission("minigame.set.lobby")) {
player.sendMessage(ChatColor.RED + "WARNING: " + ChatColor.WHITE + "Lobby location is across worlds! This may cause some server performance issues!", "error");
}
}
if (!tpd) {
player.sendMessage(MinigameUtils.getLang("minigame.error.noTeleport"), "error");
return;
}
//Give them the game type name
if (minigame.getGametypeName() == null)
player.sendMessage(MinigameUtils.formStr("player.join.plyInfo", minigame.getType().getName()), "win");
else
player.sendMessage(MinigameUtils.formStr("player.join.plyInfo", minigame.getGametypeName()), "win");
//Give them the objective
if (minigame.getObjective() != null) {
player.sendMessage(ChatColor.GREEN + "----------------------------------------------------");
player.sendMessage(ChatColor.AQUA.toString() + ChatColor.BOLD + MinigameUtils.formStr("player.join.objective", ChatColor.RESET.toString() + ChatColor.WHITE + minigame.getObjective()));
player.sendMessage(ChatColor.GREEN + "----------------------------------------------------");
}
//Prepare regeneration region for rollback.
if (minigame.getBlockRecorder().hasRegenArea() && !minigame.getBlockRecorder().hasCreatedRegenBlocks()) {
RecorderData d = minigame.getBlockRecorder();
d.setCreatedRegenBlocks(true);
Location cur = new Location(minigame.getRegenArea1().getWorld(), 0, 0, 0);
for (double y = d.getRegenMinY(); y <= d.getRegenMaxY(); y++) {
cur.setY(y);
for (double x = d.getRegenMinX(); x <= d.getRegenMaxX(); x++) {
cur.setX(x);
for (double z = d.getRegenMinZ(); z <= d.getRegenMaxZ(); z++) {
cur.setZ(z);
d.addBlock(cur.getBlock(), null);
}
}
}
}
//Standardize player
player.storePlayerData();
player.setMinigame(minigame);
minigame.addPlayer(player);
WeatherTimeModule.getMinigameModule(minigame).applyCustomTime(player);
WeatherTimeModule.getMinigameModule(minigame).applyCustomWeather(player);
player.setCheckpoint(player.getPlayer().getLocation());
player.getPlayer().setFallDistance(0);
player.getPlayer().setWalkSpeed(0.2f);
player.setStartTime(Calendar.getInstance().getTimeInMillis());
player.setGamemode(minigame.getDefaultGamemode());
if (minigame.getType() == MinigameType.SINGLEPLAYER) {
if (!minigame.isAllowedFlight()) {
player.setCanFly(false);
} else {
player.setCanFly(true);
if (minigame.isFlightEnabled())
player.getPlayer().setFlying(true);
}
} else {
player.getPlayer().setAllowFlight(false);
}
for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) {
player.getPlayer().removePotionEffect(potion.getType());
}
//Hide Spectators
for (MinigamePlayer pl : minigame.getSpectators()) {
player.getPlayer().hidePlayer(pl.getPlayer());
}
if (minigame.getPlayers().size() == 1) {
//Register regen recorder events
if (minigame.getBlockRecorder().hasRegenArea())
Bukkit.getServer().getPluginManager().registerEvents(minigame.getBlockRecorder(), plugin);
WeatherTimeModule.getMinigameModule(minigame).startTimeLoop();
}
//Call Type specific join
mdata.minigameType(type).joinMinigame(player, minigame);
//Call Mechanic specific join
minigame.getMechanic().joinMinigame(minigame, player);
//Send other players the join message.
mdata.sendMinigameMessage(minigame, MinigameUtils.formStr("player.join.plyMsg", player.getName(), minigame.getName(true)), null, player);
player.updateInventory();
if (minigame.canDisplayScoreboard()) {
player.getPlayer().setScoreboard(minigame.getScoreboardManager());
minigame.setScore(player, 1);
minigame.setScore(player, 0);
}
} else if (!minigame.isEnabled()) {
player.sendMessage(MinigameUtils.getLang("minigame.error.notEnabled"), "error");
} else if (minigame.getState() == MinigameState.REGENERATING) {
player.sendMessage(MinigameUtils.getLang("minigame.error.regenerating"), "error");
} else if (minigame.getState() == MinigameState.STARTED && !minigame.canLateJoin()) {
player.sendMessage(MinigameUtils.getLang("minigame.started"), "error");
} else if (minigame.getState() == MinigameState.STARTING && minigame.canLateJoin() && minigame.getPlayers().size() != minigame.getMaxPlayers()) {
player.sendMessage(MinigameUtils.formStr("minigame.lateJoinWait", minigame.getMpTimer().getStartWaitTimeLeft()), null);
} else if (minigame.getStartLocations().size() == 0 || (minigame.isTeamGame() && !TeamsModule.getMinigameModule(minigame).hasTeamStartLocations())) {
player.sendMessage(MinigameUtils.getLang("minigame.error.noStart"), "error");
} else if (minigame.getEndPosition() == null) {
player.sendMessage(MinigameUtils.getLang("minigame.error.noEnd"), "error");
} else if (minigame.getQuitPosition() == null) {
player.sendMessage(MinigameUtils.getLang("minigame.error.noQuit"), "error");
} else if (minigame.getLobbyPosition() == null) {
player.sendMessage(MinigameUtils.getLang("minigame.error.noLobby"), "error");
} else if (minigame.getPlayers().size() >= minigame.getMaxPlayers()) {
player.sendMessage(MinigameUtils.getLang("minigame.full"), "error");
} else if (!minigame.getMechanic().validTypes().contains(minigame.getType())) {
player.sendMessage(MinigameUtils.getLang("minigame.error.invalidMechanic"), "error");
} else if (!canStart) {
player.sendMessage(MinigameUtils.getLang("minigame.error.mechanicStartFail"), "error");
}
}
}
use of org.bukkit.Location in project Minigames by AddstarMC.
the class SetRegenAreaCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
if (args != null) {
Player ply = (Player) sender;
if (args[0].equals("1")) {
Location loc = ply.getLocation();
loc.setY(loc.getY() - 1);
loc = loc.getBlock().getLocation();
if (minigame.getRegenArea2() == null || minigame.getRegenArea2().getWorld() == loc.getWorld()) {
minigame.setRegenArea1(loc);
ply.sendMessage(ChatColor.GRAY + "The first point of the regeneration area in " + minigame + " has been set to the block below your position.");
} else {
ply.sendMessage(ChatColor.RED + "The first point of the regeneration area must be within the same world as the second point!");
}
return true;
} else if (args[0].equals("2")) {
Location loc = ply.getLocation();
loc.setY(loc.getY() - 1);
loc = loc.getBlock().getLocation();
if (minigame.getRegenArea1() == null || minigame.getRegenArea1().getWorld() == loc.getWorld()) {
minigame.setRegenArea2(loc);
ply.sendMessage(ChatColor.GRAY + "The second point of the regeneration area in " + minigame + " has been set to the block below your position.");
} else {
ply.sendMessage(ChatColor.RED + "The second point of the regeneration area must be within the same world as the first point!");
}
return true;
} else if (args[0].equalsIgnoreCase("clear")) {
minigame.setRegenArea1(null);
minigame.setRegenArea2(null);
ply.sendMessage(ChatColor.GRAY + "The regeneration area has been cleared for " + minigame);
return true;
}
}
return false;
}
use of org.bukkit.Location in project Minigames by AddstarMC.
the class MultiplayerType method joinMinigame.
@Override
public boolean joinMinigame(MinigamePlayer player, Minigame mgm) {
if (!LobbySettingsModule.getMinigameModule(mgm).canInteractPlayerWait())
player.setCanInteract(false);
if (!LobbySettingsModule.getMinigameModule(mgm).canMovePlayerWait())
player.setFrozen(true);
if (!mgm.isWaitingForPlayers() && !mgm.hasStarted()) {
if (mgm.getMpTimer() == null && mgm.getPlayers().size() == mgm.getMinPlayers()) {
mgm.setMpTimer(new MultiplayerTimer(mgm));
mgm.getMpTimer().startTimer();
if (mgm.getPlayers().size() == mgm.getMaxPlayers()) {
mgm.getMpTimer().setPlayerWaitTime(0);
mdata.sendMinigameMessage(mgm, MinigameUtils.getLang("minigame.skipWaitTime"), "info", null);
}
} else if (mgm.getMpTimer() != null && mgm.getPlayers().size() == mgm.getMaxPlayers()) {
mgm.getMpTimer().setPlayerWaitTime(0);
mdata.sendMinigameMessage(mgm, MinigameUtils.getLang("minigame.skipWaitTime"), "info", null);
} else if (mgm.getMpTimer() == null) {
int neededPlayers = mgm.getMinPlayers() - mgm.getPlayers().size();
mdata.sendMinigameMessage(mgm, MinigameUtils.formStr("minigame.waitingForPlayers", neededPlayers), null, null);
}
} else if (mgm.hasStarted()) {
player.setLatejoining(true);
//TODO: Late join delay variable
player.sendMessage(MinigameUtils.formStr("minigame.lateJoin", 5));
final MinigamePlayer fply = player;
final Minigame fmgm = mgm;
if (mgm.isTeamGame()) {
Team smTeam = null;
for (Team team : TeamsModule.getMinigameModule(mgm).getTeams()) {
if (smTeam == null || team.getPlayers().size() < smTeam.getPlayers().size()) {
smTeam = team;
}
}
smTeam.addPlayer(player);
player.sendMessage(String.format(smTeam.getAssignMessage(), smTeam.getChatColor() + smTeam.getDisplayName()), null);
final Team fteam = smTeam;
player.setLateJoinTimer(Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
if (fply.isInMinigame()) {
List<Location> locs = new ArrayList<Location>();
if (TeamsModule.getMinigameModule(fmgm).hasTeamStartLocations()) {
locs.addAll(fteam.getStartLocations());
} else {
locs.addAll(fmgm.getStartLocations());
}
Collections.shuffle(locs);
fply.teleport(locs.get(0));
fply.getLoadout().equiptLoadout(fply);
fply.setLatejoining(false);
fply.setFrozen(false);
fply.setCanInteract(true);
fply.setLateJoinTimer(-1);
}
}
}, //TODO: Latejoin variable
5 * 20));
} else {
player.setLateJoinTimer(Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
if (fply.isInMinigame()) {
List<Location> locs = new ArrayList<Location>(fmgm.getStartLocations());
Collections.shuffle(locs);
fply.teleport(locs.get(0));
fply.getLoadout().equiptLoadout(fply);
fply.setLatejoining(false);
fply.setFrozen(false);
fply.setCanInteract(true);
fply.setLateJoinTimer(-1);
}
}
}, //TODO: Latejoin variable
5 * 20));
}
player.getPlayer().setScoreboard(mgm.getScoreboardManager());
mgm.setScore(player, 1);
mgm.setScore(player, 0);
}
return true;
}
use of org.bukkit.Location 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.pdata.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.pdata.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;
}
Aggregations