Changes some code necessary for the new arena format

This commit is contained in:
Kristian Knarvik 2022-11-14 13:00:54 +01:00
parent 392a8448e4
commit c51b0e9557
15 changed files with 1233 additions and 936 deletions

10
pom.xml
View File

@ -9,8 +9,8 @@
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
@ -21,7 +21,7 @@
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
<url>https://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
<repository>
<id>engine-hub-repo</id>
@ -33,7 +33,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19-R0.1-SNAPSHOT</version>
<version>1.19.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -52,7 +52,7 @@
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
<scope>compile</scope>
<scope>provided</scope>
</dependency>
</dependencies>

View File

@ -6,6 +6,81 @@ import org.bukkit.World;
import java.util.List;
import java.util.Map;
public record Arena(int arenaId, World world, List<ArenaPlayer> arenaPlayers, ArenaState arenaState, boolean canJoin,
boolean open, int countdownTimer, int maxPlayers, int gracePeriod, Map<Integer, Location> locations) {
public class Arena {
private final int arenaId;
private final World world;
private final List<ArenaPlayer> arenaPlayers;
private final ArenaState arenaState;
private final boolean canJoin;
private final boolean open;
private final int countdownTimer;
private int maxPlayers;
private int gracePeriod;
private final Map<Integer, Location> locations;
public Arena(int arenaId, World world, List<ArenaPlayer> arenaPlayers, ArenaState arenaState, boolean canJoin,
boolean open, int countdownTimer, int maxPlayers, int gracePeriod,
Map<Integer, Location> locations) {
this.arenaId = arenaId;
this.world = world;
this.arenaPlayers = arenaPlayers;
this.arenaState = arenaState;
this.canJoin = canJoin;
this.open = open;
this.countdownTimer = countdownTimer;
this.maxPlayers = maxPlayers;
this.gracePeriod = gracePeriod;
this.locations = locations;
}
//TODO: Add arena name to make them easier to keep track of
public void setMaxPlayers(int maxPlayers) {
this.maxPlayers = maxPlayers;
}
public List<ArenaPlayer> getArenaPlayers() {
return arenaPlayers;
}
public World getWorld() {
return world;
}
public int getArenaId() {
return arenaId;
}
public ArenaState getArenaState() {
return arenaState;
}
public boolean isCanJoin() {
return canJoin;
}
public boolean isOpen() {
return open;
}
public int getCountdownTimer() {
return countdownTimer;
}
public int getMaxPlayers() {
return maxPlayers;
}
public int getGracePeriod() {
return gracePeriod;
}
public Map<Integer, Location> getLocations() {
return locations;
}
public void setGracePeriod(int gracePeriod) {
this.gracePeriod = gracePeriod;
}
}

View File

@ -2,6 +2,191 @@ package net.knarcraft.hungerarena;
import org.bukkit.entity.Player;
public record ArenaPlayer(Player player, boolean ready, boolean quit, boolean dead, boolean isOut, boolean isWatching,
boolean needConfirmation, boolean inArena, boolean frozen) {
/**
* A container for all properties stored for a player in an arena
*/
public class ArenaPlayer {
private Player player;
private Arena arena;
private boolean ready;
private boolean quit;
private boolean dead;
private boolean isOut;
private boolean isWatching;
private boolean needConfirmation;
private boolean inArena;
private boolean frozen;
/**
* Instantiates a new arena player
*
* @param player <p>The player this arena player represents</p>
* @param arena <p>The arena the player is currently in</p>
* @param ready <p>Whether the player is currently ready to start the game</p>
* @param quit <p>Whether the player has quit the game</p>
* @param dead <p>Whether the player has died</p>
* @param isOut <p>Whether the player has left the game</p>
* @param isWatching <p>Whether the player is watching the arena</p>
* @param needConfirmation <p>Whether a conformation is necessary for the player to join the game</p>
* @param inArena <p>Whether the player is currently in an arena</p>
* @param frozen <p>Whether the player is currently frozen, not allowed to move</p>
*/
public ArenaPlayer(Player player, Arena arena, boolean ready, boolean quit, boolean dead, boolean isOut,
boolean isWatching, boolean needConfirmation, boolean inArena, boolean frozen) {
this.player = player;
this.arena = arena;
this.ready = ready;
this.quit = quit;
this.dead = dead;
this.isOut = isOut;
this.isWatching = isWatching;
this.needConfirmation = needConfirmation;
this.inArena = inArena;
this.frozen = frozen;
}
/**
* Gets the player this arena player corresponds to
*
* @return <p>The actual player</p>
*/
public Player getPlayer() {
return player;
}
public void setPlayer(Player player) {
this.player = player;
}
/**
* Gets the arena this arena player is currently in
*
* @return <p>The arena this player is in, or null if not in an arena</p>
*/
public Arena getArena() {
return arena;
}
public void setArena(Arena arena) {
this.arena = arena;
}
/**
* Gets whether this arena player is ready to start the game
*
* @return <p>True if this player is ready</p>
*/
public boolean isReady() {
return ready;
}
public void setReady(boolean ready) {
this.ready = ready;
}
/**
* Gets whether this arena player has quit
*
* <p>If the player has been kicked, has died or has quit the game, this returns true.</p>
*
* @return <p>True if this arena player has quit</p>
*/
public boolean hasQuit() {
return quit;
}
public void setQuit(boolean quit) {
this.quit = quit;
}
/**
* Gets whether this arena player has died
*
* @return <p>True if this arena player has died</p>
*/
public boolean isDead() {
return dead;
}
public void setDead(boolean dead) {
this.dead = dead;
}
/**
* Gets whether this arena player has left the game, and is "out"
*
* @return <p>True if this arena player is currently out</p>
*/
public boolean isOut() {
return isOut;
}
public void setOut(boolean out) {
isOut = out;
}
/**
* Gets whether this arena player is currently watching the arena
*
* @return <p>True if currently watching the arena</p>
*/
public boolean isWatching() {
return isWatching;
}
public void setWatching(boolean watching) {
isWatching = watching;
}
/**
* Gets whether ths arena player needs to confirm that they want to join the game
*
* <p>As some arenas have entry fees, they might require that a player confirms that they really want to join the
* arena. If a player hasn't confirmed that they want to join, this will be true.</p>
*
* @return <p>True if this arena player needs to confirm that they are joining</p>
*/
public boolean needConfirmation() {
return needConfirmation;
}
public void setNeedConfirmation(boolean needConfirmation) {
this.needConfirmation = needConfirmation;
}
/**
* Gets whether this arena player is currently in an arena
*
* @return <p>True if in an arena</p>
*/
public boolean isInArena() {
return inArena;
}
/**
* Sets whether this arena player is currently in an arena
*
* @param inArena <p>True if this arena player is currently in an arena</p>
*/
public void setInArena(boolean inArena) {
this.inArena = inArena;
}
/**
* Gets whether this arena player is frozen
*
* <p>A frozen player is a player that is currently prevented from moving, such as when players are forced to stay
* on their pedestals until the countdown expires.</p>
*
* @return <p>True if this arena player is frozen</p>
*/
public boolean isFrozen() {
return frozen;
}
public void setFrozen(boolean frozen) {
this.frozen = frozen;
}
}

View File

@ -46,9 +46,9 @@ public class Chests implements Listener {
Block block = event.getClickedBlock();
Player p = event.getPlayer();
if (plugin.getArena(p) != null) {
int a = plugin.getArena(p);
int a = plugin.getArena(p).getArenaId();
if (plugin.Playing.get(a).contains(p.getName()) && plugin.canJoin.get(a)) {
if (!plugin.restrictedWorlds || (plugin.restrictedWorlds && plugin.worldsNames.containsValue(p.getWorld().getName()))) {
if (!plugin.restrictedWorlds || (plugin.restrictedWorlds && plugin.worldNames.containsValue(p.getWorld().getName()))) {
if (block != null) {
if (block.getState() instanceof InventoryHolder) {
ItemStack[] itemsinchest = ((InventoryHolder) block.getState()).getInventory().getContents().clone();

File diff suppressed because it is too large Load Diff

View File

@ -24,7 +24,6 @@ import org.bukkit.FireworkEffect.Type;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.CommandExecutor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@ -60,34 +59,36 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
public class HungerArena extends JavaPlugin {
static Logger log;
public final HashMap<Integer, List<String>> Playing = new HashMap<>();
public final HashMap<Integer, List<String>> Ready = new HashMap<>();
public final HashMap<Integer, List<String>> Dead = new HashMap<>();
public final HashMap<Integer, List<UUID>> Playing = new HashMap<>();
public final HashMap<Integer, List<UUID>> Ready = new HashMap<>();
public final HashMap<Integer, List<UUID>> Dead = new HashMap<>();
public final HashMap<Integer, String> MatchRunning = new HashMap<>();
public final HashMap<Integer, Boolean> canJoin = new HashMap<>();
public final HashMap<Integer, Boolean> open = new HashMap<>();
private final HashMap<Integer, Integer> CountT = new HashMap<>();
public final HashMap<Integer, List<String>> Quit = new HashMap<>();
public final HashMap<Integer, List<String>> Out = new HashMap<>();
public final HashMap<Integer, List<String>> Watching = new HashMap<>();
private final HashMap<Integer, Integer> countDownTimer = new HashMap<>();
public final HashMap<Integer, List<UUID>> Quit = new HashMap<>();
public final HashMap<Integer, List<UUID>> Out = new HashMap<>();
public final HashMap<Integer, List<UUID>> Watching = new HashMap<>();
public final HashMap<String, Integer> Kills = new HashMap<>();
public final HashMap<Integer, List<String>> NeedConfirm = new HashMap<>();
public final HashMap<Integer, List<UUID>> NeedConfirm = new HashMap<>();
public final HashMap<Integer, HashMap<Integer, Location>> location = new HashMap<>();
public final HashMap<Integer, List<String>> inArena = new HashMap<>();
public final HashMap<Integer, List<String>> Frozen = new HashMap<>();
public final HashMap<Integer, List<UUID>> inArena = new HashMap<>();
//public final HashMap<Integer, List<String>> Frozen = new HashMap<>();
public final HashMap<Integer, Integer> maxPlayers = new HashMap<>();
public final HashMap<String, String> setting = new HashMap<>();
public final HashMap<Integer, Integer> gp = new HashMap<>();
public final ArrayList<Player> Tele = new ArrayList<>();
public final ArrayList<String> needInv = new ArrayList<>();
public final HashMap<Integer, String> worldsNames = new HashMap<>();
public final HashMap<Integer, String> worldNames = new HashMap<>();
public final Map<Integer, Arena> arenas = new HashMap<>();
public final Map<UUID, ArenaPlayer> arenaPlayers = new HashMap<>();
public final HashMap<String, Scoreboard> scoreboards = new HashMap<>();
@ -137,7 +138,7 @@ public class HungerArena extends JavaPlugin {
int i = 0;
int v = 0;
int a = 0;
int arenaId = 0;
final File PFilePath = new File(getDataFolder(), "/inventories");
@ -352,7 +353,7 @@ public class HungerArena extends JavaPlugin {
for (Entry<String, Object> entry : temp.entrySet()) {
if (spawns.getConfigurationSection("Spawns." + entry.getKey()) != null) {
Integer a = Integer.parseInt(entry.getKey());
worldsNames.put(a, "none_meaning_this_is_not_a_map");
worldNames.put(a, "none_meaning_this_is_not_a_map");
location.computeIfAbsent(a, k -> new HashMap<>());
Map<String, Object> temp2 = spawns.getConfigurationSection("Spawns." + entry.getKey()).getValues(false);
for (Map.Entry<String, Object> e : temp2.entrySet()) {
@ -360,31 +361,37 @@ public class HungerArena extends JavaPlugin {
String[] coords = ((String) spawns.get("Spawns." + entry.getKey() + "" + e.getKey())).split(",");
Integer s = Integer.parseInt(e.getKey());
location.get(a).put(s, new Location(getServer().getWorld(coords[0]), Double.parseDouble(coords[1]), Double.parseDouble(coords[2]), Double.parseDouble(coords[3])));
worldsNames.put(a, coords[0]);
worldNames.put(a, coords[0]);
}
}
}
}
}
for (int i : location.keySet()) {
if (location.get(i).size() != 0) {
for (int arenaId : location.keySet()) {
if (location.get(arenaId).size() != 0) {
if (verbose) {
log.info("Loaded " + location.get(i).size() + " tribute spawns for arena " + i + "!");
log.info("Loaded " + location.get(arenaId).size() + " tribute spawns for arena " + arenaId + "!");
}
Playing.put(i, new ArrayList<>());
Ready.put(i, new ArrayList<>());
Dead.put(i, new ArrayList<>());
MatchRunning.put(i, null);
Quit.put(i, new ArrayList<>());
Out.put(i, new ArrayList<>());
Watching.put(i, new ArrayList<>());
NeedConfirm.put(i, new ArrayList<>());
inArena.put(i, new ArrayList<>());
Frozen.put(i, new ArrayList<>());
canJoin.put(i, false);
maxPlayers.put(i, location.get(i).size());
open.put(i, true);
Playing.put(arenaId, new ArrayList<>());
Ready.put(arenaId, new ArrayList<>());
Dead.put(arenaId, new ArrayList<>());
MatchRunning.put(arenaId, null);
Quit.put(arenaId, new ArrayList<>());
Out.put(arenaId, new ArrayList<>());
Watching.put(arenaId, new ArrayList<>());
NeedConfirm.put(arenaId, new ArrayList<>());
inArena.put(arenaId, new ArrayList<>());
Arena arena = arenas.get(arenaId);
for (ArenaPlayer arenaPlayer : arenaPlayers.values()) {
if (arenaPlayer.getArena() == arena) {
arenaPlayer.setFrozen(false);
}
}
canJoin.put(arenaId, false);
maxPlayers.put(arenaId, location.get(arenaId).size());
open.put(arenaId, true);
}
}
}
@ -640,7 +647,7 @@ public class HungerArena extends JavaPlugin {
}
@SuppressWarnings("unchecked")
public void RestoreInv(Player p, String pname) {
public void restoreInventory(Player p, String pname) {
for (int u : Playing.keySet()) {
if (Playing.get(u) != null) {
if (Playing.get(u).contains(pname)) {
@ -649,7 +656,7 @@ public class HungerArena extends JavaPlugin {
if (config.getBoolean("broadcastAll")) {
p.getServer().broadcastMessage(ChatColor.RED + pname + " Left Arena " + u + "!");
} else {
for (String gn : Playing.get(u)) {
for (UUID gn : Playing.get(u)) {
Player g = getServer().getPlayer(gn);
g.sendMessage(ChatColor.RED + pname + " Quit!");
}
@ -724,11 +731,15 @@ public class HungerArena extends JavaPlugin {
Location Spawn = new Location(spawnw, spawnx, spawny, spawnz);
for (i = 0; i < Playing.get(a).size(); i++) {
String winnername = Playing.get(a).get(i);
final Player winner = getServer().getPlayerExact(winnername);
String winnername2 = winner.getName();
UUID winnerId = Playing.get(a).get(i);
final Player winner = getServer().getPlayer(winnerId);
//TODO: Figure out exactly what needs to be done in this case
if (winner == null) {
continue;
}
String winnerName = winner.getName();
if (canJoin.get(a)) {
getServer().broadcastMessage(ChatColor.GREEN + winnername2 + " is the victor of this Hunger Games!");
getServer().broadcastMessage(ChatColor.GREEN + winnerName + " is the victor of this Hunger Games!");
}
winner.getInventory().clear();
winner.getInventory().setBoots(null);
@ -741,11 +752,11 @@ public class HungerArena extends JavaPlugin {
winner.removePotionEffect(potion);
}
Tele.add(winner);
needInv.add(winnername2);
needInv.add(winnerName);
winner.teleport(Spawn);
this.RestoreInv(winner, winnername2);
this.restoreInventory(winner, winnerName);
if (canJoin.get(a)) {
winner.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
@ -827,9 +838,9 @@ public class HungerArena extends JavaPlugin {
getServer().getScheduler().cancelTask(deathtime.get(a));
deathtime.put(a, null);
}
if (grace.get(a) != null) {
getServer().getScheduler().cancelTask(grace.get(a));
grace.put(a, null);
if (graceSchedulerIds.get(a) != null) {
getServer().getScheduler().cancelTask(graceSchedulerIds.get(a));
graceSchedulerIds.put(a, null);
}
if (start.get(a) != null) {
getServer().getScheduler().cancelTask(start.get(a));
@ -841,8 +852,8 @@ public class HungerArena extends JavaPlugin {
Dead.get(a).clear();
//Show spectators
for (String s1 : Watching.get(a)) {
Player spectator = getServer().getPlayerExact(s1);
for (UUID s1 : Watching.get(a)) {
Player spectator = getServer().getPlayer(s1);
spectator.setAllowFlight(false);
spectator.teleport(Spawn);
for (Player online : getServer().getOnlinePlayers()) {
@ -906,9 +917,9 @@ public class HungerArena extends JavaPlugin {
public void updateScoreboard(Player p) {
if (getArena(p) != null || isSpectating(p)) {
if (getArena(p) != null) {
a = getArena(p);
arenaId = getArena(p).getArenaId();
} else if (getSpectating(p) != null) {
a = getSpectating(p);
arenaId = getSpectating(p).getArenaId();
}
if (scoreboards.get(p.getName()) != null && scoreboards.get(p.getName()).getObjective("HA") != null) {
Scoreboard sb = scoreboards.get(p.getName());
@ -918,7 +929,7 @@ public class HungerArena extends JavaPlugin {
Score players = obj.getScore(ChatColor.RED + "Players");
Score spectators = obj.getScore(ChatColor.RED + "Spectators");
Score allkills = obj.getScore(ChatColor.RED + "Deaths");
players.setScore(Playing.get(a).size());
players.setScore(Playing.get(arenaId).size());
if (Kills.containsKey(p.getName())) {
kills.setScore(Kills.get(p.getName()));
}
@ -926,15 +937,15 @@ public class HungerArena extends JavaPlugin {
allkills.setScore(Kills.get("__SuM__"));
}
if (Watching.get(a) != null) {
spectators.setScore(Watching.get(a).size());
if (Watching.get(arenaId) != null) {
spectators.setScore(Watching.get(arenaId).size());
}
if (config.getInt("DeathMatch") != 0) {
if (timetodeath.get(a) != null) {
if (timetodeath.get(a) > 0) {
int ttd = timetodeath.get(a) - timetodeath.get(a) / 60 * 60;
if (timetodeath.get(arenaId) != null) {
if (timetodeath.get(arenaId) > 0) {
int ttd = timetodeath.get(arenaId) - timetodeath.get(arenaId) / 60 * 60;
String secs = String.valueOf((ttd < 10) ? "0" + ttd : ttd);
obj.setDisplayName(ChatColor.GREEN + "HA - DMTime: " + ChatColor.AQUA + timetodeath.get(a) / 60 + ":" + secs);
obj.setDisplayName(ChatColor.GREEN + "HA - DMTime: " + ChatColor.AQUA + timetodeath.get(arenaId) / 60 + ":" + secs);
} else {
obj.setDisplayName(ChatColor.GREEN + "HA - " + ChatColor.RED + "DEATHMATCH");
}
@ -948,18 +959,18 @@ public class HungerArena extends JavaPlugin {
}
}
public final HashMap<Integer, Integer> grace = new HashMap<>();
public final HashMap<Integer, Integer> graceSchedulerIds = new HashMap<>();
public final HashMap<Integer, Integer> start = new HashMap<>();
public final HashMap<Integer, Integer> deathtime = new HashMap<>();
public final HashMap<Integer, Integer> timetodeath = new HashMap<>();
public void startGames(final int a) {
if ((MatchRunning.get(a) != null) && (MatchRunning.get(a).equals("true"))) {
public void startGames(final int arenaId) {
if ((MatchRunning.get(arenaId) != null) && (MatchRunning.get(arenaId).equals("true"))) {
return;
}
final String msg = ChatColor.translateAlternateColorCodes('&', config.getString("Start_Message"));
for (String gn : Playing.get(a)) {
for (UUID gn : Playing.get(arenaId)) {
Scoreboard scoreboard = getServer().getScoreboardManager().getNewScoreboard();
Objective sobj;
try {
@ -980,126 +991,171 @@ public class HungerArena extends JavaPlugin {
Bukkit.getPlayer(gn).setScoreboard(scoreboard);
scoreboards.put(Bukkit.getPlayer(gn).getName(), Bukkit.getPlayer(gn).getScoreboard());
}
getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha Refill " + a);
MatchRunning.put(a, "true");
if (start.get(a) != null) {
getServer().getScheduler().cancelTask(start.get(a));
getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha Refill " + arenaId);
MatchRunning.put(arenaId, "true");
if (start.get(arenaId) != null) {
getServer().getScheduler().cancelTask(start.get(arenaId));
}
if (config.getString("Countdown").equalsIgnoreCase("true")) {
CountT.put(a, (config.getInt("Countdown_Timer") != 0 ? config.getInt("Countdown_Timer") : 10));
start.put(a, getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
if (CountT.get(a) > 0) {
if (!restrictedWorlds) {
if (config.getBoolean("broadcastAll")) {
getServer().broadcastMessage(ChatColor.AQUA + "Game " + a + " starting in: " + CountT.get(a));
displayCountDown(arenaId, msg);
} else {
for (String gn : Playing.get(a)) {
Player g = getServer().getPlayer(gn);
g.sendMessage(ChatColor.AQUA + "Game starting in: " + CountT.get(a));
Arena arena = arenas.get(arenaId);
setTorch(arenaId, true);
for (ArenaPlayer arenaPlayer : arenaPlayers.values()) {
if (arenaPlayer.getArena() == arena) {
arenaPlayer.setFrozen(false);
}
}
} else {
if (config.getBoolean("broadcastAll")) {
for (String world : worldsNames.values()) {
World w = getServer().getWorld(world);
for (Player wp : w.getPlayers()) {
wp.sendMessage(String.valueOf(CountT.get(a)));
}
}
} else {
for (String gn : Playing.get(a)) {
Player g = getServer().getPlayer(gn);
g.sendMessage(String.valueOf(CountT.get(a)));
}
}
}
}
CountT.put(a, CountT.get(a) - 1);
if (CountT.get(a) == -1) {
for (String gn : Playing.get(a)) {
Scoreboard scoreboard = getServer().getScoreboardManager().getNewScoreboard();
Objective sobj;
try {
sobj = scoreboard.registerNewObjective("HA", "HAData", ChatColor.GREEN + "HA - Starting");
} catch (NoSuchMethodError e) {
sobj = scoreboard.registerNewObjective("HA", "HAData");
sobj.setDisplayName(ChatColor.GREEN + "HA - Starting");
}
Score skills = sobj.getScore(ChatColor.RED + "Kills");
skills.setScore(0);
Score sdeaths = sobj.getScore(ChatColor.RED + "Spectators");
sdeaths.setScore(0);
Score splayers = sobj.getScore(ChatColor.RED + "Players");
splayers.setScore(0);
Score allkills = sobj.getScore(ChatColor.RED + "Deaths");
allkills.setScore(0);
sobj.setDisplaySlot(DisplaySlot.SIDEBAR);
Bukkit.getPlayer(gn).setScoreboard(scoreboard);
scoreboards.put(Bukkit.getPlayer(gn).getName(), Bukkit.getPlayer(gn).getScoreboard());
}
if (Frozen.get(a) != null) {
Frozen.get(a).clear();
}
if (config.getBoolean("broadcastAll")) {
getServer().broadcastMessage(msg);
} else {
for (String gn : Playing.get(a)) {
for (UUID gn : Playing.get(arenaId)) {
Player g = getServer().getPlayer(gn);
g.sendMessage(msg);
}
}
}
canJoin.put(arenaId, true);
}
private void broadCastArenaStartingSoon(int arenaId) {
if (!config.getBoolean("broadcastAll")) {
//Broadcast that a game is starting soon to all players in the arena
for (ArenaPlayer player : arenas.get(arenaId).getArenaPlayers()) {
player.getPlayer().sendMessage(ChatColor.AQUA + "Game starting in: " + countDownTimer.get(arenaId));
}
} else if (!restrictedWorlds) {
//Broadcast that a game is starting soon to all players
getServer().broadcastMessage(ChatColor.AQUA + "Game " + arenaId + " starting in: " +
countDownTimer.get(arenaId));
} else {
//Broadcast to all players in the arena world that a game is starting soon
for (String worldName : worldNames.values()) {
World world = getServer().getWorld(worldName);
//If the world doesn't exist, skip it
if (world == null) {
continue;
}
for (Player worldPlayer : world.getPlayers()) {
worldPlayer.sendMessage(String.valueOf(countDownTimer.get(arenaId)));
}
}
}
}
private void announceGracePeriod(int arenaId) {
Arena arena = arenas.get(arenaId);
arena.setGracePeriod(config.getInt("Grace_Period"));
if (this.graceSchedulerIds.get(arenaId) == null) {
return;
}
int taskId = getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
//Reduce grace period by one
arena.setGracePeriod(arena.getGracePeriod() - 1);
int gracePeriod = arena.getGracePeriod();
boolean broadcastAll = config.getBoolean("broadcastAll");
String gracePeriodMessage = null;
if (gracePeriod == 30 || gracePeriod == 15 || (gracePeriod < 11 && gracePeriod > 0)) {
//Print when 30 seconds left, 15 seconds left, and count down from 10
gracePeriodMessage = ChatColor.GREEN + "Grace period ends in " + gracePeriod + " seconds!";
} else if (gracePeriod <= 0) {
//Print when the grace period expires
gracePeriodMessage = ChatColor.GREEN + "Grace period is over, FIGHT!";
}
if (gracePeriodMessage != null) {
if (broadcastAll) {
//Broadcast to all players
getServer().broadcastMessage(gracePeriodMessage);
} else {
//Broadcast to all players in the arena's world
for (Player player : arena.getWorld().getPlayers()) {
player.sendMessage(gracePeriodMessage);
}
}
}
//Cancel the scheduler if the grace period is over
if (gracePeriod <= 0) {
getServer().getScheduler().cancelTask(graceSchedulerIds.get(arenaId));
graceSchedulerIds.put(arenaId, null);
}
}, 20L, 20L);
graceSchedulerIds.put(arenaId, taskId);
}
private void displayCountDown(int arenaId, String msg) {
countDownTimer.put(arenaId, (config.getInt("Countdown_Timer") != 0 ? config.getInt("Countdown_Timer") : 10));
start.put(arenaId, getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
if (countDownTimer.get(arenaId) > 0) {
broadCastArenaStartingSoon(arenaId);
}
countDownTimer.put(arenaId, countDownTimer.get(arenaId) - 1);
if (countDownTimer.get(arenaId) == -1) {
for (UUID gn : Playing.get(arenaId)) {
Scoreboard scoreboard = getServer().getScoreboardManager().getNewScoreboard();
Objective sobj;
try {
sobj = scoreboard.registerNewObjective("HA", "HAData", ChatColor.GREEN + "HA - Starting");
} catch (NoSuchMethodError e) {
sobj = scoreboard.registerNewObjective("HA", "HAData");
sobj.setDisplayName(ChatColor.GREEN + "HA - Starting");
}
Score sKills = sobj.getScore(ChatColor.RED + "Kills");
sKills.setScore(0);
Score sDeaths = sobj.getScore(ChatColor.RED + "Spectators");
sDeaths.setScore(0);
Score sPlayers = sobj.getScore(ChatColor.RED + "Players");
sPlayers.setScore(0);
Score allKills = sobj.getScore(ChatColor.RED + "Deaths");
allKills.setScore(0);
sobj.setDisplaySlot(DisplaySlot.SIDEBAR);
Bukkit.getPlayer(gn).setScoreboard(scoreboard);
scoreboards.put(Bukkit.getPlayer(gn).getName(), Bukkit.getPlayer(gn).getScoreboard());
}
Arena arena = arenas.get(arenaId);
for (ArenaPlayer arenaPlayer : arenaPlayers.values()) {
if (arenaPlayer.getArena() == arena) {
arenaPlayer.setFrozen(false);
}
}
if (config.getBoolean("broadcastAll")) {
getServer().broadcastMessage(msg);
} else {
for (UUID gn : Playing.get(arenaId)) {
Player g = getServer().getPlayer(gn);
g.sendMessage(msg);
}
}
if (config.getInt("Grace_Period") != 0) {
gp.put(a, config.getInt("Grace_Period"));
if (grace.get(a) == null) {
grace.put(a, getServer().getScheduler().scheduleSyncRepeatingTask(Bukkit.getPluginManager().getPlugin("HungerArena"), () -> {
gp.put(a, gp.get(a) - 1);
if (gp.get(a) == 30 || gp.get(a) == 15 || (gp.get(a) < 11 && gp.get(a) != 0)) {
if (config.getBoolean("broadcastAll")) {
for (Player wp : location.get(a).get(1).getWorld().getPlayers()) {
wp.sendMessage(ChatColor.GREEN + "Grace period ends in " + gp.get(a) + " seconds!");
}
} else {
getServer().broadcastMessage(ChatColor.GREEN + "Grace period ends in " + gp.get(a) + " seconds!");
}
}
if (gp.get(a) <= 0) {
if (config.getBoolean("broadcastAll")) {
for (Player wp : location.get(a).get(1).getWorld().getPlayers()) {
wp.sendMessage(ChatColor.GREEN + "Grace period is over, FIGHT!");
}
} else {
getServer().broadcastMessage(ChatColor.GREEN + "Grace period is over, FIGHT!");
}
getServer().getScheduler().cancelTask(grace.get(a));
grace.put(a, null);
}
}, 20L, 20L));
}
announceGracePeriod(arenaId);
}
if (config.getInt("DeathMatch") != 0) {
int death = config.getInt("DeathMatch");
timetodeath.put(a, death * 60);
if (deathtime.get(a) == null) {
deathtime.put(a, getServer().getScheduler().scheduleSyncRepeatingTask(Bukkit.getPluginManager().getPlugin("HungerArena"), () -> {
timetodeath.put(a, timetodeath.get(a) - 1);
if (timetodeath.get(a) % 300 == 0) {
timetodeath.put(arenaId, death * 60);
if (deathtime.get(arenaId) == null) {
deathtime.put(arenaId, getServer().getScheduler().scheduleSyncRepeatingTask(Bukkit.getPluginManager().getPlugin("HungerArena"), () -> {
timetodeath.put(arenaId, timetodeath.get(arenaId) - 1);
if (timetodeath.get(arenaId) % 300 == 0) {
if (config.getBoolean("broadcastAll")) {
for (Player wp : location.get(a).get(1).getWorld().getPlayers()) {
if (timetodeath.get(a) != 0) {
wp.sendMessage(ChatColor.YELLOW + String.valueOf(timetodeath.get(a) / 60) + ChatColor.RED + " mins till the death match!");
for (Player wp : location.get(arenaId).get(1).getWorld().getPlayers()) {
if (timetodeath.get(arenaId) != 0) {
wp.sendMessage(ChatColor.YELLOW + String.valueOf(timetodeath.get(arenaId) / 60) + ChatColor.RED + " mins till the death match!");
}
}
} else {
for (String gn : Playing.get(a)) {
for (UUID gn : Playing.get(arenaId)) {
Player g = getServer().getPlayer(gn);
g.sendMessage(ChatColor.YELLOW + String.valueOf(timetodeath.get(a)) + ChatColor.RED + " mins till the death match!");
g.sendMessage(ChatColor.YELLOW + String.valueOf(timetodeath.get(arenaId)) + ChatColor.RED + " mins till the death match!");
}
}
}
if (timetodeath.get(a) <= 0) {
if (timetodeath.get(arenaId) <= 0) {
int i = 1;
for (String playing : Playing.get(a)) {
Player tribute = getServer().getPlayerExact(playing);
for (UUID playing : Playing.get(arenaId)) {
Player tribute = getServer().getPlayer(playing);
Location pLoc = null;
if (tribute.hasMetadata("HA-Location")) {
@ -1113,7 +1169,7 @@ public class HungerArena extends JavaPlugin {
if (pLoc != null) {
tribute.teleport(pLoc); //random
} else {
tribute.teleport(location.get(a).get(i)); //row
tribute.teleport(location.get(arenaId).get(i)); //row
}
}
i += 1;
@ -1126,98 +1182,66 @@ public class HungerArena extends JavaPlugin {
}
}
if (config.getBoolean("broadcastAll")) {
for (Player wp : location.get(a).get(1).getWorld().getPlayers()) {
wp.sendMessage(ChatColor.RED + "The final battle has begun! " + Playing.get(a).size() + " tributes will be facing off!");
for (Player wp : location.get(arenaId).get(1).getWorld().getPlayers()) {
wp.sendMessage(ChatColor.RED + "The final battle has begun! " + Playing.get(arenaId).size() + " tributes will be facing off!");
}
} else {
for (String gn : Playing.get(a)) {
for (UUID gn : Playing.get(arenaId)) {
Player g = getServer().getPlayer(gn);
g.sendMessage(ChatColor.RED + "The final battle has begun! " + Playing.get(a).size() + " tributes will be facing off!");
g.sendMessage(ChatColor.RED + "The final battle has begun! " + Playing.get(arenaId).size() + " tributes will be facing off!");
}
}
StopTasksDelayed(deathtime.get(a));
deathtime.put(a, null);
stopTaskDelayed(deathtime.get(arenaId));
deathtime.put(arenaId, null);
}
}, 20L, 20L));
}
}
setTorch(a, true);
StopTasksDelayed(start.get(a));
setTorch(arenaId, true);
stopTaskDelayed(start.get(arenaId));
}
}, 20L, 20L));
} else {
setTorch(a, true);
Frozen.get(a).clear();
if (config.getBoolean("broadcastAll")) {
getServer().broadcastMessage(msg);
} else {
for (String gn : Playing.get(a)) {
Player g = getServer().getPlayer(gn);
g.sendMessage(msg);
}
}
}
canJoin.put(a, true);
}
private void StopTasksDelayed(final int task) {
private void stopTaskDelayed(final int task) {
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> Bukkit.getScheduler().cancelTask(task), 10L);
}
public Integer getArena(Player p) {
for (int x : Playing.keySet()) {
if (Playing.get(x).contains(p.getName())) {
return x;
}
public Arena getArena(Player player) {
ArenaPlayer arenaPlayer = arenaPlayers.get(player.getUniqueId());
if (arenaPlayer != null) {
return arenaPlayer.getArena();
}
return null;
}
public Integer getSpectating(Player p) {
for (int x : Watching.keySet()) {
if (Watching.get(x).contains(p.getName())) {
return x;
}
public Arena getSpectating(Player player) {
ArenaPlayer arenaPlayer = arenaPlayers.get(player.getUniqueId());
if (arenaPlayer != null && arenaPlayer.isWatching()) {
return arenaPlayer.getArena();
}
return null;
}
public boolean isSpectating(Player p) {
for (int x : Watching.keySet()) {
if (Watching.get(x).contains(p.getName())) {
return true;
}
}
return false;
return getSpectating(p) != null;
}
public void setTorch(int a, boolean set) {
String arena = String.valueOf(a);
if (spawns.getString("Start_torch." + arena) != null) {
String[] Torchcoords = spawns.getString("Start_torch." + arena).split(",");
double torchx = Double.parseDouble(Torchcoords[0]);
double torchy = Double.parseDouble(Torchcoords[1]);
double torchz = Double.parseDouble(Torchcoords[2]);
String torchworld = Torchcoords[3];
World torchw = getServer().getWorld(torchworld);
Location TorchLoc = new Location(torchw, torchx, torchy, torchz);
public void setTorch(int arenaId, boolean set) {
if (spawns.getString("Start_torch." + arenaId) != null) {
String[] torchCoordinates = spawns.getString("Start_torch." + arenaId).split(",");
double torchX = Double.parseDouble(torchCoordinates[0]);
double torchY = Double.parseDouble(torchCoordinates[1]);
double torchZ = Double.parseDouble(torchCoordinates[2]);
String torchWorldName = torchCoordinates[3];
World torchWorld = getServer().getWorld(torchWorldName);
Location torchLocation = new Location(torchWorld, torchX, torchY, torchZ);
if (set) {
SetTorch(TorchLoc);
torchLocation.getBlock().setType(Material.REDSTONE_TORCH);
} else {
TorchLoc.getBlock().setType(Material.AIR);
torchLocation.getBlock().setType(Material.AIR);
}
}
}
private void SetTorch(Location Baseblock) {
Block TorchBlock = Baseblock.getBlock();
try {
Material Torch = (org.bukkit.Material.valueOf("REDSTONE_TORCH"));
if (Torch != null) {
TorchBlock.setType(Torch);
}
} catch (Exception ex) {
TorchBlock.setType(Material.REDSTONE_TORCH);
}
}
}

View File

@ -42,22 +42,22 @@ public class BlockStorage implements Listener {
int a = 1;
if (alwaysProtect) {
String ThisWorld = p.getWorld().getName();
for (int z : plugin.worldsNames.keySet()) {
if (plugin.worldsNames.get(z) != null) {
if (plugin.worldsNames.get(z).equals(ThisWorld)) {
for (int z : plugin.worldNames.keySet()) {
if (plugin.worldNames.get(z) != null) {
if (plugin.worldNames.get(z).equals(ThisWorld)) {
a = z;
}
}
}
}
if (plugin.getArena(p) != null) {
a = plugin.getArena(p);
a = plugin.getArena(p).getArenaId();
}
if ((!event.isCancelled()) && (((plugin.Playing.get(a)).contains(pname)) || (alwaysProtect))) {
if (plugin.config.getBoolean("Protected_Arena")) {
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "You can't break blocks while playing!");
} else if ((plugin.canJoin.get(a) || alwaysProtect) && ((!plugin.restrictedWorlds) || ((plugin.restrictedWorlds) && (plugin.worldsNames.containsValue(p.getWorld().getName()))))) {
} else if ((plugin.canJoin.get(a) || alwaysProtect) && ((!plugin.restrictedWorlds) || ((plugin.restrictedWorlds) && (plugin.worldNames.containsValue(p.getWorld().getName()))))) {
if (((plugin.management.getStringList("blocks.whitelist").isEmpty()) || ((!plugin.management.getStringList("blocks.whitelist").isEmpty()) && (!plugin.management.getStringList("blocks.whitelist").contains(b.getType().name())))) ^ (plugin.management.getBoolean("blocks.useWhitelistAsBlacklist"))) {
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "That is an illegal block!");
@ -78,7 +78,7 @@ public class BlockStorage implements Listener {
for (int i : plugin.canJoin.keySet()) {
if (plugin.canJoin.get(i) || alwaysProtect()) {
String ThisWorld = e.getWorld().getName();
if ((!plugin.restrictedWorlds) || ((plugin.restrictedWorlds) && plugin.worldsNames.get(i) != null && plugin.worldsNames.get(i).equalsIgnoreCase(ThisWorld))) {
if ((!plugin.restrictedWorlds) || ((plugin.restrictedWorlds) && plugin.worldNames.get(i) != null && plugin.worldNames.get(i).equalsIgnoreCase(ThisWorld))) {
if (e.getType() == EntityType.PRIMED_TNT) {
e.getLocation().getBlock().setType(Material.TNT);
Block TNT = e.getLocation().getBlock();
@ -102,7 +102,7 @@ public class BlockStorage implements Listener {
if (!event.isCancelled()) {
for (int i : plugin.canJoin.keySet()) {
if (plugin.canJoin.get(i) || alwaysProtect()) {
if ((!plugin.restrictedWorlds) || ((plugin.restrictedWorlds) && (plugin.worldsNames.get(i) != null && plugin.worldsNames.get(i).equalsIgnoreCase(b.getWorld().getName())))) {
if ((!plugin.restrictedWorlds) || ((plugin.restrictedWorlds) && (plugin.worldNames.get(i) != null && plugin.worldNames.get(i).equalsIgnoreCase(b.getWorld().getName())))) {
String w = b.getWorld().getName();
addDestroyedBlockToList(b, w, i);
}
@ -123,21 +123,21 @@ public class BlockStorage implements Listener {
int a = 1;
if (protall) {
String ThisWorld = p.getWorld().getName();
for (int z : plugin.worldsNames.keySet()) {
if (plugin.worldsNames.get(z) != null) {
if (plugin.worldsNames.get(z).equals(ThisWorld)) {
for (int z : plugin.worldNames.keySet()) {
if (plugin.worldNames.get(z) != null) {
if (plugin.worldNames.get(z).equals(ThisWorld)) {
a = z;
}
}
}
}
if (plugin.getArena(p) != null) {
a = plugin.getArena(p);
a = plugin.getArena(p).getArenaId();
}
if (!event.isCancelled()) {
if (((plugin.Playing.get(a)).contains(p.getName())) || (protall)) {
if ((plugin.canJoin.get(a)) || (protall)) {
if ((!plugin.restrictedWorlds) || ((plugin.restrictedWorlds) && (plugin.worldsNames.containsValue(b.getWorld().getName())))) {
if ((!plugin.restrictedWorlds) || ((plugin.restrictedWorlds) && (plugin.worldNames.containsValue(b.getWorld().getName())))) {
if ((b.getType() == Material.SAND || b.getType() == Material.GRAVEL) && (b.getRelative(BlockFace.DOWN).getType() == Material.AIR || b.getRelative(BlockFace.DOWN).getType() == Material.WATER || b.getRelative(BlockFace.DOWN).getType() == Material.LAVA)) {
int n = b.getY() - 1;
while (b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType() == Material.AIR || b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType() == Material.WATER || b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType() == Material.LAVA) {
@ -168,11 +168,11 @@ public class BlockStorage implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void bucketEmpty(PlayerBucketEmptyEvent event) {
if (plugin.getArena(event.getPlayer()) != null) {
int a = plugin.getArena(event.getPlayer());
int a = plugin.getArena(event.getPlayer()).getArenaId();
if (!event.isCancelled()) {
if (plugin.canJoin.get(a)) {
if (plugin.Playing.get(a).contains(event.getPlayer().getName())) {
if ((!plugin.restrictedWorlds) || ((plugin.restrictedWorlds) && (plugin.worldsNames.containsValue(event.getPlayer().getWorld().getName())))) {
if ((!plugin.restrictedWorlds) || ((plugin.restrictedWorlds) && (plugin.worldNames.containsValue(event.getPlayer().getWorld().getName())))) {
Block b = event.getBlockClicked().getRelative(event.getBlockFace());
String w = b.getWorld().getName();
addPlacedBlockToList(b, w, a);
@ -186,12 +186,12 @@ public class BlockStorage implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void bucketFill(PlayerBucketFillEvent event) {
if (plugin.getArena(event.getPlayer()) != null) {
int arena = plugin.getArena(event.getPlayer());
int arena = plugin.getArena(event.getPlayer()).getArenaId();
if (event.isCancelled()) {
return;
}
boolean isPlaying = plugin.Playing.get(arena).contains(event.getPlayer().getName());
boolean enabledInWorld = plugin.worldsNames.containsValue(event.getPlayer().getWorld().getName());
boolean enabledInWorld = plugin.worldNames.containsValue(event.getPlayer().getWorld().getName());
if (joinAble(arena) && (isPlaying && (!plugin.restrictedWorlds || enabledInWorld))) {
Block block = event.getBlockClicked().getRelative(event.getBlockFace());
@ -208,9 +208,9 @@ public class BlockStorage implements Listener {
}
for (int arena : plugin.canJoin.keySet()) {
boolean isInWorld = plugin.worldsNames.get(arena).equalsIgnoreCase(event.getBlock().getWorld().getName());
boolean isInWorld = plugin.worldNames.get(arena).equalsIgnoreCase(event.getBlock().getWorld().getName());
if (joinAble(arena) || alwaysProtect() &&
(!plugin.restrictedWorlds || plugin.worldsNames.get(arena) != null && isInWorld)) {
(!plugin.restrictedWorlds || plugin.worldNames.get(arena) != null && isInWorld)) {
Block block = event.getBlock();
String worldName = block.getWorld().getName();
Material material = block.getType();

View File

@ -15,6 +15,8 @@ import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.scoreboard.DisplaySlot;
import java.util.UUID;
public class DeathListener implements Listener {
public final HungerArena plugin;
@ -31,9 +33,9 @@ public class DeathListener implements Listener {
//get the arena the player has died in... (may be not the one he joined...)
String ThisWorld = p.getWorld().getName();
for (int z : plugin.worldsNames.keySet()) {
if (plugin.worldsNames.get(z) != null) {
if (plugin.worldsNames.get(z).equals(ThisWorld)) {
for (int z : plugin.worldNames.keySet()) {
if (plugin.worldNames.get(z) != null) {
if (plugin.worldNames.get(z).equals(ThisWorld)) {
a = z;
}
}
@ -63,7 +65,7 @@ public class DeathListener implements Listener {
final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz);
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
player.teleport(Spawn);
plugin.RestoreInv(player, player.getName());
plugin.restoreInventory(player, player.getName());
}, 10L);
}
@ -72,42 +74,45 @@ public class DeathListener implements Listener {
Player p = event.getEntity();
Server s = p.getServer();
String pname = p.getName();
UUID playerId = p.getUniqueId();
if (plugin.getArena(p) != null) {
a = plugin.getArena(p);
int players = plugin.Playing.get(a).size() - 1;
a = plugin.getArena(p).getArenaId();
String leftmsg = null;
clearInv(p);
event.getDrops().clear();
p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
plugin.scoreboards.remove(p.getName());
if (!plugin.Frozen.get(a).isEmpty()) {
if (plugin.Frozen.get(a).contains(pname)) {
if (!(p.getKiller() instanceof Player)) {
players = plugin.Playing.get(a).size() - 1;
leftmsg = ChatColor.BLUE + "There are now " + players + " tributes left!";
if (plugin.config.getBoolean("Cannon_Death")) {
double y = p.getLocation().getY();
double newy = y + 200;
double x = p.getLocation().getX();
double z = p.getLocation().getZ();
Location strike = new Location(p.getWorld(), x, newy, z);
p.getWorld().strikeLightning(strike);
int players = plugin.Playing.get(a).size() - 1;
if (plugin.arenaPlayers.get(playerId).isFrozen()) {
doFrozenPlayerStuff(p, players, leftmsg, pname, playerId, event, s);
} else {
doNonFrozenPlayerStuff(p, players, leftmsg, pname, playerId, event, s);
}
}
}
private void doFrozenPlayerStuff(Player p, int players, String leftmsg, String pname, UUID playerId, PlayerDeathEvent event, Server s) {
//Basically, if a frozen player is killed by something which isn't another player, assume the reason the player
// was killed was because they left their pedestal too early
if (!(p.getKiller() instanceof Player)) {
leftmsg = ChatColor.BLUE + "There are now " + players + " tributes left!";
fireCannon(p);
event.setDeathMessage("");
if (plugin.config.getBoolean("broadcastAll")) {
p.getServer().broadcastMessage(pname + ChatColor.LIGHT_PURPLE + " Stepped off their pedestal too early!");
} else {
for (String gn : plugin.Playing.get(a)) {
for (UUID gn : plugin.Playing.get(a)) {
Player g = plugin.getServer().getPlayer(gn);
g.sendMessage(pname + ChatColor.LIGHT_PURPLE + " Stepped off their pedestal too early!");
}
}
plugin.Frozen.get(a).remove(pname);
plugin.Playing.get(a).remove(pname);
plugin.arenaPlayers.get(playerId).setFrozen(false);
plugin.arenaPlayers.get(playerId).setInArena(false);
plugin.arenaPlayers.get(playerId).setArena(null);
if (plugin.config.getBoolean("broadcastAll")) {
p.getServer().broadcastMessage(leftmsg);
} else {
for (String gn : plugin.Playing.get(a)) {
for (UUID gn : plugin.Playing.get(a)) {
Player g = plugin.getServer().getPlayer(gn);
g.sendMessage(leftmsg);
}
@ -115,29 +120,22 @@ public class DeathListener implements Listener {
plugin.winner(a);
}
}
} else {
players = plugin.Playing.get(a).size() - 1;
private void doNonFrozenPlayerStuff(Player player, int players, String leftmsg, String pname, UUID playerId, PlayerDeathEvent event, Server s) {
leftmsg = ChatColor.BLUE + "There are now " + players + " tributes left!";
if (plugin.config.getBoolean("Cannon_Death")) {
double y = p.getLocation().getY();
double newY = y + 200;
double x = p.getLocation().getX();
double z = p.getLocation().getZ();
Location strike = new Location(p.getWorld(), x, newY, z);
p.getWorld().strikeLightning(strike);
}
plugin.Dead.get(a).add(pname);
plugin.Playing.get(a).remove(pname);
if (p.getKiller() instanceof Player) {
if (p.getKiller().getInventory().getItemInMainHand().getType() == Material.AIR) {
Player killer = p.getKiller();
fireCannon(player);
plugin.Dead.get(a).add(playerId);
plugin.Playing.get(a).remove(playerId);
if (player.getKiller() instanceof Player) {
if (player.getKiller().getInventory().getItemInMainHand().getType() == Material.AIR) {
Player killer = player.getKiller();
String killername = killer.getName();
event.setDeathMessage("");
if (plugin.config.getBoolean("broadcastAll")) {
s.broadcastMessage(ChatColor.LIGHT_PURPLE + "**BOOM** Tribute " + pname + " was killed by tribute " + killername + " with their FIST!");
s.broadcastMessage(leftmsg);
} else {
for (String gn : plugin.Playing.get(a)) {
for (UUID gn : plugin.Playing.get(a)) {
Player g = plugin.getServer().getPlayer(gn);
g.sendMessage(ChatColor.LIGHT_PURPLE + "**BOOM** Tribute " + pname + " was killed by tribute " + killername + " with their FIST!");
g.sendMessage(leftmsg);
@ -155,7 +153,7 @@ public class DeathListener implements Listener {
}
plugin.winner(a);
} else {
Player killer = p.getKiller();
Player killer = player.getKiller();
String killername = killer.getName();
String weapon = "a(n) " + killer.getInventory().getItemInMainHand().getType().name().replace('_', ' ');
if (killer.getInventory().getItemInMainHand().hasItemMeta()) {
@ -169,7 +167,7 @@ public class DeathListener implements Listener {
s.broadcastMessage(msg);
s.broadcastMessage(leftmsg);
} else {
for (String gn : plugin.Playing.get(a)) {
for (UUID gn : plugin.Playing.get(a)) {
Player g = plugin.getServer().getPlayer(gn);
g.sendMessage(msg);
g.sendMessage(leftmsg);
@ -193,7 +191,7 @@ public class DeathListener implements Listener {
s.broadcastMessage(ChatColor.LIGHT_PURPLE + pname + " died of natural causes!");
s.broadcastMessage(leftmsg);
} else {
for (String gn : plugin.Playing.get(a)) {
for (UUID gn : plugin.Playing.get(a)) {
Player g = plugin.getServer().getPlayer(gn);
g.sendMessage(ChatColor.LIGHT_PURPLE + pname + " died of " + ChatColor.ITALIC + " probably " + ChatColor.LIGHT_PURPLE + "natural causes!");
g.sendMessage(leftmsg);
@ -202,6 +200,15 @@ public class DeathListener implements Listener {
plugin.winner(a);
}
}
private void fireCannon(Player player) {
if (plugin.config.getBoolean("Cannon_Death")) {
double y = player.getLocation().getY();
double newY = y + 200;
double x = player.getLocation().getX();
double z = player.getLocation().getZ();
Location strike = new Location(player.getWorld(), x, newY, z);
player.getWorld().strikeLightning(strike);
}
}

View File

@ -1,5 +1,6 @@
package net.knarcraft.hungerarena.Listeners;
import net.knarcraft.hungerarena.ArenaPlayer;
import net.knarcraft.hungerarena.HungerArena;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@ -13,6 +14,7 @@ import org.bukkit.metadata.MetadataValue;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
public class FreezeListener implements Listener {
public final HungerArena plugin;
@ -31,12 +33,12 @@ public class FreezeListener implements Listener {
Player p = event.getPlayer();
String pname = p.getName();
if (plugin.getArena(p) != null) {
a = plugin.getArena(p);
if (plugin.Frozen.get(a).contains(pname) && plugin.config.getBoolean("Frozen_Teleport")) {
a = plugin.getArena(p).getArenaId();
if (plugin.arenaPlayers.get(p.getUniqueId()).isFrozen() && plugin.config.getBoolean("Frozen_Teleport")) {
if (plugin.config.getBoolean("Explode_on_Move")) {
timeUp.put(a, false);
for (String players : plugin.Playing.get(a)) {
Player playing = plugin.getServer().getPlayerExact(players);
for (UUID players : plugin.Playing.get(a)) {
Player playing = plugin.getServer().getPlayer(players);
i = plugin.Playing.get(a).indexOf(players) + 1;
if (!timeUp.get(a) && !timing.contains(a)) {
timing.add(a);
@ -52,7 +54,7 @@ public class FreezeListener implements Listener {
} else {
if (!playing.getLocation().getBlock().getLocation().equals(plugin.location.get(a).get(i).getBlock().getLocation())) {
if (!plugin.Dead.get(a).contains(playing.getName())) {
plugin.Dead.get(a).add(playing.getName());
plugin.Dead.get(a).add(playing.getUniqueId());
World world = playing.getLocation().getWorld();
world.createExplosion(playing.getLocation(), 0.0F, false);
playing.setHealth(0.0D);
@ -74,17 +76,19 @@ public class FreezeListener implements Listener {
if (plugin.config.getBoolean("broadcastAll")) {
p.getServer().broadcastMessage(pname + ChatColor.LIGHT_PURPLE + " Stepped off their pedestal too early!");
} else {
for (String gn : plugin.Playing.get(a)) {
for (UUID gn : plugin.Playing.get(a)) {
Player g = plugin.getServer().getPlayer(gn);
g.sendMessage(pname + ChatColor.LIGHT_PURPLE + " Stepped off their pedestal too early!");
}
}
plugin.Frozen.get(a).remove(pname);
plugin.Playing.get(a).remove(pname);
ArenaPlayer arenaPlayer = plugin.arenaPlayers.get(p.getUniqueId());
arenaPlayer.setFrozen(false);
arenaPlayer.setInArena(false);
arenaPlayer.setArena(null);
if (plugin.config.getBoolean("broadcastAll")) {
p.getServer().broadcastMessage(leftmsg);
} else {
for (String gn : plugin.Playing.get(a)) {
for (UUID gn : plugin.Playing.get(a)) {
Player g = plugin.getServer().getPlayer(gn);
g.sendMessage(leftmsg);
}

View File

@ -1,5 +1,6 @@
package net.knarcraft.hungerarena.Listeners;
import net.knarcraft.hungerarena.ArenaPlayer;
import net.knarcraft.hungerarena.HaCommands;
import net.knarcraft.hungerarena.HungerArena;
import org.bukkit.ChatColor;
@ -12,6 +13,8 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scoreboard.DisplaySlot;
import java.util.UUID;
public class JoinAndQuitListener implements Listener {
public HungerArena plugin;
@ -30,25 +33,26 @@ public class JoinAndQuitListener implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
final Player player = event.getPlayer();
final UUID playerId = player.getUniqueId();
final String pname = player.getName();
boolean pfound = false;
for (int i : plugin.Watching.keySet()) {
for (String s : plugin.Watching.get(i)) {
Player spectator = plugin.getServer().getPlayerExact(s);
for (UUID s : plugin.Watching.get(i)) {
Player spectator = plugin.getServer().getPlayer(s);
player.hidePlayer(plugin, spectator);
}
}
for (int i : plugin.Out.keySet()) {
if (plugin.Out.get(i).contains(pname)) {
plugin.Playing.get(i).add(pname);
if (plugin.Out.get(i).contains(playerId)) {
plugin.Playing.get(i).add(playerId);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> player.sendMessage(ChatColor.AQUA + "You have saved yourself from being ejected from the arena!"), 40L);
plugin.Out.get(i).remove(pname);
plugin.Out.get(i).remove(playerId);
pfound = true;
}
}
for (final int i : plugin.Quit.keySet()) {
if (plugin.Quit.get(i).contains(pname)) {
if (plugin.Quit.get(i).contains(playerId)) {
String[] Spawncoords = plugin.spawns.getString("Spawn_coordinates." + i).split(",");
String w = Spawncoords[3];
World spawnw = plugin.getServer().getWorld(w);
@ -59,9 +63,9 @@ public class JoinAndQuitListener implements Listener {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
player.teleport(Spawn);
player.sendMessage(ChatColor.RED + "You have been teleported to last spawn because you quit/forfeited!");
plugin.RestoreInv(player, player.getName());
plugin.restoreInventory(player, player.getName());
if (plugin.Quit.get(i) != null) {
plugin.Quit.get(i).remove(player.getName());
plugin.Quit.get(i).remove(player.getUniqueId());
}
}, 40L);
pfound = true;
@ -79,7 +83,7 @@ public class JoinAndQuitListener implements Listener {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
player.teleport(Spawn);
player.sendMessage(ChatColor.RED + "You have been teleported to spawn because you quit/died/forfeited!!");
plugin.RestoreInv(player, player.getName());
plugin.restoreInventory(player, player.getName());
if (plugin.Dead.get(i) != null) {
plugin.Dead.get(i).remove(player.getName());
}
@ -106,7 +110,7 @@ public class JoinAndQuitListener implements Listener {
player.getInventory().setHelmet(null);
plugin.inArena.remove(pname);
player.sendMessage(ChatColor.RED + "You were still in the arena when you left and now the games are over.");
plugin.RestoreInv(player, player.getName());
plugin.restoreInventory(player, player.getName());
if (plugin.inArena.get(i) != null) {
plugin.inArena.get(i).remove(player.getName());
}
@ -115,7 +119,7 @@ public class JoinAndQuitListener implements Listener {
}
}
}
if (!plugin.restrictedWorlds || plugin.worldsNames.containsValue(player.getWorld().getName())) {
if (!plugin.restrictedWorlds || plugin.worldNames.containsValue(player.getWorld().getName())) {
if (!pfound && plugin.config.getBoolean("Force_Players_toSpawn") && (plugin.spawns.getString("Spawn_coordinates.0") != null)) {
String[] spawnCoordinates = plugin.spawns.getString("Spawn_coordinates.0").split(",");
String w = spawnCoordinates[3];
@ -124,7 +128,7 @@ public class JoinAndQuitListener implements Listener {
double spawnY = Double.parseDouble(spawnCoordinates[1]);
double spawnZ = Double.parseDouble(spawnCoordinates[2]);
final Location Spawn = new Location(spawnWorld, spawnX, spawnY, spawnZ);
plugin.RestoreInv(player, player.getName());
plugin.restoreInventory(player, player.getName());
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
player.teleport(Spawn);
player.sendMessage(ChatColor.RED + "You have been teleported to spawn!!");
@ -134,46 +138,44 @@ public class JoinAndQuitListener implements Listener {
}
@EventHandler
public void onQuit(PlayerQuitEvent evt) {
Player p = evt.getPlayer();
String playerName = p.getName();
for (int i : plugin.Frozen.keySet()) {
if (plugin.Frozen.get(i).contains(playerName)) {
plugin.Frozen.remove(playerName);
String[] Spawncoords = plugin.spawns.getString("Spawn_coordinates.0").split(",");
String w = Spawncoords[3];
World spawnw = plugin.getServer().getWorld(w);
double spawnx = Double.parseDouble(Spawncoords[0]);
double spawny = Double.parseDouble(Spawncoords[1]);
double spawnz = Double.parseDouble(Spawncoords[2]);
Location Spawn = new Location(spawnw, spawnx, spawny, spawnz);
p.teleport(Spawn);
p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
plugin.scoreboards.remove(p.getName());
plugin.Kills.remove(p.getName());
}
public void onQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
ArenaPlayer arenaPlayer = plugin.arenaPlayers.get(player.getUniqueId());
if (arenaPlayer != null && arenaPlayer.isFrozen()) {
arenaPlayer.setFrozen(false);
String[] spawnCoordinates = plugin.spawns.getString("Spawn_coordinates.0").split(",");
String w = spawnCoordinates[3];
World spawnWorld = plugin.getServer().getWorld(w);
double spawnX = Double.parseDouble(spawnCoordinates[0]);
double spawnY = Double.parseDouble(spawnCoordinates[1]);
double spawnZ = Double.parseDouble(spawnCoordinates[2]);
Location Spawn = new Location(spawnWorld, spawnX, spawnY, spawnZ);
player.teleport(Spawn);
player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
plugin.scoreboards.remove(player.getName());
plugin.Kills.remove(player.getName());
}
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
final Player p = event.getPlayer();
final String playerName = p.getName();
if (plugin.getArena(p) != null) {
arena = plugin.getArena(p);
plugin.Out.get(arena).add(playerName);
plugin.Playing.get(arena).remove(playerName);
final Player player = event.getPlayer();
final UUID playerId = player.getUniqueId();
if (plugin.getArena(player) != null) {
arena = plugin.getArena(player).getArenaId();
plugin.Out.get(arena).add(playerId);
plugin.Playing.get(arena).remove(playerId);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
if (plugin.Out.get(arena).contains(playerName)) {
plugin.Quit.get(arena).add(playerName);
plugin.Out.get(arena).remove(playerName);
p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
plugin.scoreboards.remove(p.getName());
plugin.Kills.remove(p.getName());
if (plugin.Out.get(arena).contains(playerId)) {
plugin.Quit.get(arena).add(playerId);
plugin.Out.get(arena).remove(playerId);
player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
plugin.scoreboards.remove(player.getName());
plugin.Kills.remove(player.getName());
plugin.winner(arena);
plugin.inArena.get(arena).add(playerName);
} else if (plugin.getArena(p) == null) {
plugin.Quit.get(arena).add(playerName);
plugin.inArena.get(arena).add(playerId);
} else if (plugin.getArena(player) == null) {
plugin.Quit.get(arena).add(playerId);
}
}, 1200L);
}

View File

@ -18,7 +18,7 @@ public class PvP implements Listener {
this.plugin = m;
}
int a = 0;
int arenaId = 0;
@EventHandler(priority = EventPriority.MONITOR)
public void PlayerPvP(EntityDamageByEntityEvent event) {
@ -26,8 +26,8 @@ public class PvP implements Listener {
Entity dl = event.getDamager();
if (pl instanceof Player p && dl instanceof Player d) {
if (plugin.getArena(p) != null && plugin.getArena(d) != null) {
a = plugin.getArena(p);
if (plugin.canJoin.get(a)) {
arenaId = plugin.getArena(p).getArenaId();
if (plugin.canJoin.get(arenaId)) {
if (event.isCancelled()) {
event.setCancelled(false);
}
@ -39,8 +39,8 @@ public class PvP implements Listener {
}
}
if (plugin.getArena(p) != null) {
a = plugin.getArena(p);
if (!plugin.canJoin.get(a)) {
arenaId = plugin.getArena(p).getArenaId();
if (!plugin.canJoin.get(arenaId)) {
if (!event.isCancelled()) {
event.setCancelled(true);
}
@ -76,13 +76,13 @@ public class PvP implements Listener {
@EventHandler
public void PlayerDamage(EntityDamageEvent event) {
Entity e = event.getEntity();
if (e instanceof Player p) {
if (plugin.getArena(p) != null) {
a = plugin.getArena(p);
if (plugin.gp.get(a) != null && plugin.gp.get(a) != 0) {
if (e instanceof Player player) {
if (plugin.getArena(player) != null) {
arenaId = plugin.getArena(player).getArenaId();
if (plugin.gp.get(arenaId) != null && plugin.gp.get(arenaId) != 0) {
event.setCancelled(true);
}
if (plugin.Frozen.get(a) != null && plugin.Frozen.get(a).contains(p.getName())) {
if (plugin.arenaPlayers.get(player.getUniqueId()).isFrozen()) {
event.setCancelled(true);
}
}

View File

@ -19,7 +19,7 @@ public class TeleportListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onTP(PlayerTeleportEvent event) {
Player p = event.getPlayer();
if (plugin.worldsNames.containsValue(event.getTo().getWorld().getName()) && plugin.Tele.contains(p)) {
if (plugin.worldNames.containsValue(event.getTo().getWorld().getName()) && plugin.Tele.contains(p)) {
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "You are a dead tribute... How are you supposed to get back into the arena....");
plugin.Tele.remove(p);

View File

@ -21,8 +21,8 @@ public class WorldChange implements Listener {
String pname = p.getName();
String ThisWorld = p.getWorld().getName();
String FromWorld = event.getFrom().getName();
if (!plugin.worldsNames.containsValue(ThisWorld) && plugin.worldsNames.containsValue(FromWorld)) {
plugin.RestoreInv(p, pname);
if (!plugin.worldNames.containsValue(ThisWorld) && plugin.worldNames.containsValue(FromWorld)) {
plugin.restoreInventory(p, pname);
}
}
@ -32,16 +32,16 @@ public class WorldChange implements Listener {
String pname = p.getName();
String ThisWorld = p.getWorld().getName();
int a = 0;
for (int i : plugin.worldsNames.keySet()) {
if (plugin.worldsNames.get(i) == null) {
for (int i : plugin.worldNames.keySet()) {
if (plugin.worldNames.get(i) == null) {
continue;
}
if (plugin.worldsNames.get(i).equals(ThisWorld)) {
if (plugin.worldNames.get(i).equals(ThisWorld)) {
a = i;
if (plugin.Frozen.get(a) != null && plugin.Frozen.get(a).contains(pname)) {
if (plugin.arenaPlayers.get(p.getUniqueId()).isFrozen()) {
return;
} else {
plugin.RestoreInv(p, pname);
plugin.restoreInventory(p, pname);
if (plugin.config.getBoolean("joinTeleport")) {
String[] spawnCoordinates = plugin.spawns.getString("Spawn_coordinates." + a).split(",");
double spawnX = Double.parseDouble(spawnCoordinates[0]);

View File

@ -3,6 +3,7 @@ package net.knarcraft.hungerarena;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@ -13,166 +14,157 @@ import java.util.ArrayList;
import java.util.HashMap;
public class SpawnsCommand implements CommandExecutor {
public final HungerArena plugin;
int i = 0;
int arenaId = 0;
boolean NoPlayerSpawns;
public SpawnsCommand(HungerArena m) {
this.plugin = m;
public final HungerArena plugin;
int tributeId = 0;
int arenaId = 0;
boolean noPlayerSpawns;
public SpawnsCommand(HungerArena plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String commandLabel, String[] args) {
Player p = (Player) sender;
String ThisWorld = p.getWorld().getName();
NoPlayerSpawns = true;
for (int i : plugin.worldsNames.keySet()) {
if (plugin.worldsNames.get(i) != null) {
if (plugin.worldsNames.get(i).equals(ThisWorld)) {
arenaId = i;
NoPlayerSpawns = false;
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String commandLabel,
String[] args) {
Player player = (Player) sender;
String playerWorld = player.getWorld().getName();
this.noPlayerSpawns = true;
for (int arenaId : plugin.arenas.keySet()) {
String arenaWorld = plugin.worldNames.get(arenaId);
if (arenaWorld != null) {
if (arenaWorld.equals(playerWorld)) {
this.arenaId = arenaId;
this.noPlayerSpawns = false;
break;
}
}
}
if (cmd.getName().equalsIgnoreCase("StartPoint")) {
if (p.hasPermission("HungerArena.StartPoint")) {
Location location;
double x;
double y;
double z;
if (args.length == 6) {
try {
i = Integer.parseInt(args[1]);
arenaId = Integer.parseInt(args[0]);
} catch (Exception e) {
p.sendMessage(ChatColor.RED + "Argument not an integer!");
return true;
if (!command.getName().equalsIgnoreCase("StartPoint")) {
return false;
}
String world = args[2];
x = Double.parseDouble(args[3]);
y = Double.parseDouble(args[4]);
z = Double.parseDouble(args[5]);
location = new Location(Bukkit.getWorld(world), x, y, z);
if (plugin.location.get(arenaId) != null) {
plugin.location.get(arenaId).put(i, location);
} else {
/*plugin.arenas.put(arenaId, new Arena(arenaId, location.getWorld(), new ArrayList<>(),
ArenaState.IDLE, false, true, 0, 0, 0,
new HashMap<>()));*/
plugin.arenas.get(arenaId).locations().put(i, location);
plugin.location.put(arenaId, new HashMap<>());
plugin.location.get(arenaId).put(i, location);
plugin.Playing.put(arenaId, new ArrayList<>());
plugin.Ready.put(arenaId, new ArrayList<>());
plugin.Dead.put(arenaId, new ArrayList<>());
plugin.Quit.put(arenaId, new ArrayList<>());
plugin.Out.put(arenaId, new ArrayList<>());
plugin.Watching.put(arenaId, new ArrayList<>());
plugin.NeedConfirm.put(arenaId, new ArrayList<>());
plugin.inArena.put(arenaId, new ArrayList<>());
plugin.Frozen.put(arenaId, new ArrayList<>());
plugin.canJoin.put(arenaId, false);
plugin.MatchRunning.put(arenaId, null);
plugin.open.put(arenaId, true);
}
String coords = location.getWorld().getName() + "," + (location.getX()) + "," + location.getY() + "," + (location.getZ());
p.sendMessage(coords);
plugin.spawns.set("Spawns." + arenaId + "" + i, coords);
plugin.worldsNames.put(arenaId, location.getWorld().getName());
plugin.saveSpawns();
plugin.maxPlayers.put(arenaId, plugin.location.get(arenaId).size());
p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute " + i + " in arena " + arenaId + "!");
this.plugin.reloadSpawnPoints(false);
return true;
if (!player.hasPermission("HungerArena.StartPoint")) {
player.sendMessage(ChatColor.RED + "You don't have permission!");
return false;
}
if (args.length >= 2) {
try {
i = Integer.parseInt(args[1]);
arenaId = Integer.parseInt(args[0]);
this.tributeId = Integer.parseInt(args[1]);
this.arenaId = Integer.parseInt(args[0]);
} catch (Exception e) {
p.sendMessage(ChatColor.RED + "Argument not an integer!");
player.sendMessage(ChatColor.RED + "Argument not an integer!");
return true;
}
if (i >= 1 && i <= plugin.config.getInt("maxPlayers")) {
if (!plugin.worldsNames.containsValue(p.getWorld().getName())) {
p.sendMessage(ChatColor.GOLD + "You've added this world to the config ...");
}
location = p.getLocation().getBlock().getLocation();
x = location.getX() + .5;
y = location.getY();
z = location.getZ() + .5;
location = new Location(location.getWorld(), x, y, z);
if (plugin.location.get(arenaId) != null) {
plugin.location.get(arenaId).put(i, location);
} else {
plugin.location.put(arenaId, new HashMap<>());
plugin.location.get(arenaId).put(i, location);
plugin.Playing.put(arenaId, new ArrayList<>());
plugin.Ready.put(arenaId, new ArrayList<>());
plugin.Dead.put(arenaId, new ArrayList<>());
plugin.Quit.put(arenaId, new ArrayList<>());
plugin.Out.put(arenaId, new ArrayList<>());
plugin.Watching.put(arenaId, new ArrayList<>());
plugin.NeedConfirm.put(arenaId, new ArrayList<>());
plugin.inArena.put(arenaId, new ArrayList<>());
plugin.Frozen.put(arenaId, new ArrayList<>());
plugin.canJoin.put(arenaId, false);
plugin.MatchRunning.put(arenaId, null);
plugin.open.put(arenaId, true);
}
String coords = location.getWorld().getName() + "," + (location.getX()) + "," + location.getY() + "," + (location.getZ());
p.sendMessage(coords);
plugin.spawns.set("Spawns." + arenaId + "" + i, coords);
plugin.worldsNames.put(arenaId, location.getWorld().getName());
plugin.saveSpawns();
plugin.maxPlayers.put(arenaId, plugin.location.get(arenaId).size());
p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute " + i + " in arena " + arenaId + "!");
this.plugin.reloadSpawnPoints(false);
} else {
p.sendMessage(ChatColor.RED + "You can't go past " + plugin.config.getInt("maxPlayers") + " players!");
}
if (args.length == 6) {
saveGivenLocationSpawnPoint(args, player);
return true;
} else if (args.length >= 2) {
savePlayerLocationSpawnPoint(player);
return true;
} else if (args.length == 1) {
if (NoPlayerSpawns) {
try {
arenaId = Integer.parseInt(args[0]);
} catch (Exception e) {
p.sendMessage(ChatColor.RED + "Argument not an integer!");
enableSpawnSetting(args, player);
return true;
} else {
player.sendMessage(ChatColor.RED + "No argument given! \nUse command like this:\n/startpoint [Arena #] " +
"[Startpoint #] for setting your position as a startpoint.\n/startpoint [Arena #] [Startpoint #] " +
"[Mapname] [x] [y] [z] \nOr you can use /startpoint [Arena #] to use the 'spawntool': ID" +
plugin.config.getInt("spawnsTool") + " for setting the startpoints!");
return false;
}
}
if (plugin.spawns.get("Spawns." + arenaId) != null) {
private void enableSpawnSetting(String[] args, Player player) {
//If any player spawn has been set, the arena id was set during the constructor call
if (noPlayerSpawns) {
try {
this.arenaId = Integer.parseInt(args[0]);
} catch (Exception e) {
player.sendMessage(ChatColor.RED + "Argument not an integer!");
return;
}
}
//If spawns already exist, calculate the next missing spawn
int start = 1;
if (plugin.spawns.get("Spawns." + arenaId) != null) {
while (start < plugin.config.getInt("maxPlayers") + 2) {
if (plugin.spawns.get("Spawns." + arenaId + "" + start) != null) {
start = start + 1;
start++;
//All spawn points already set
if (start == plugin.config.getInt("maxPlayers") + 1) {
p.sendMessage(ChatColor.DARK_AQUA + "[HungerArena] " + ChatColor.GREEN + "All spawns set, type /startpoint [Arena #] [Spawn #] to over-ride previous points!");
return true;
player.sendMessage(ChatColor.DARK_AQUA + "[HungerArena] " + ChatColor.GREEN +
"All spawns set, type /startpoint [Arena #] [Spawn #] to over-ride previous points!");
return;
}
} else {
int sloc = start;
start = plugin.config.getInt("maxPlayers") + 1;
p.sendMessage(ChatColor.DARK_AQUA + "[HungerArena] " + ChatColor.RED + "Begin Setting For Arena " + arenaId + " Starting From Point " + sloc);
plugin.setting.put(p.getName(), arenaId + "-" + sloc);
return true;
//Enable spawn setting, starting from the next available spawn
player.sendMessage(ChatColor.DARK_AQUA + "[HungerArena] " + ChatColor.RED +
"Begin Setting For Arena " + arenaId + " Starting From Point " + start);
plugin.setting.put(player.getName(), arenaId + "-" + start);
return;
}
}
}
p.sendMessage(ChatColor.DARK_AQUA + "[HungerArena] " + ChatColor.RED + "Begin Setting For Arena " + arenaId + " Starting From Point " + 1);
plugin.setting.put(p.getName(), arenaId + "-" + 1);
return true;
} else {
p.sendMessage(ChatColor.RED + "No argument given! \nUse command like this:\n/startpoint [Arena #] [Startpoint #] for setting your position as a startpoint.\n/startpoint [Arena #] [Startpoint #] [Mapname] [x] [y] [z] \nOr you can use /startpoint [Arena #] to use the 'spawntool': ID" + plugin.config.getInt("spawnsTool") + " for setting the startpoints!");
return false;
//Enable spawn setting, starting from the next available spawn
player.sendMessage(ChatColor.DARK_AQUA + "[HungerArena] " + ChatColor.RED + "Begin Setting For Arena " +
arenaId + " Starting From Point " + start);
plugin.setting.put(player.getName(), arenaId + "-" + start);
}
} else {
p.sendMessage(ChatColor.RED + "You don't have permission!");
private void savePlayerLocationSpawnPoint(Player player) {
if (tributeId >= 1 && tributeId <= plugin.config.getInt("maxPlayers")) {
player.sendMessage(ChatColor.RED + "You can't go past " + plugin.config.getInt("maxPlayers") + " players!");
return;
}
if (!plugin.worldNames.containsValue(player.getWorld().getName())) {
player.sendMessage(ChatColor.GOLD + "You've added this world to the config ...");
}
return false;
Location location = player.getLocation().getBlock().getLocation();
double x = location.getX() + .5;
double y = location.getY();
double z = location.getZ() + .5;
location = new Location(location.getWorld(), x, y, z);
saveSpawnPoint(player, location);
}
private void saveGivenLocationSpawnPoint(String[] args, Player player) {
String worldName = args[2];
double x = Double.parseDouble(args[3]);
double y = Double.parseDouble(args[4]);
double z = Double.parseDouble(args[5]);
Location location = new Location(Bukkit.getWorld(worldName), x, y, z);
saveSpawnPoint(player, location);
}
private void saveSpawnPoint(Player player, Location location) {
//Add a new arena if it does not yet exist
if (plugin.arenas.get(arenaId) == null) {
plugin.arenas.put(arenaId, new Arena(arenaId, location.getWorld(), new ArrayList<>(),
ArenaState.IDLE, false, true, 0, 0, 0,
new HashMap<>()));
}
Arena arena = plugin.arenas.get(arenaId);
arena.getLocations().put(tributeId, location);
World world = location.getWorld();
String coordinates = world == null ? "" : world.getName() + "," + location.getX() + "," +
location.getY() + "," + location.getZ();
player.sendMessage(coordinates);
plugin.spawns.set(String.format("Spawns.%s.%s", arenaId, tributeId), coordinates);
plugin.worldNames.put(arenaId, location.getWorld().getName());
plugin.saveSpawns();
arena.setMaxPlayers(plugin.location.get(arenaId).size());
player.sendMessage(ChatColor.AQUA + String.format("You have set the spawn location of Tribute %d in arena %d!", tributeId, arenaId));
this.plugin.reloadSpawnPoints(false);
}
}