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> <version>1.0-SNAPSHOT</version>
<properties> <properties>
<maven.compiler.source>17</maven.compiler.source> <maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target> <maven.compiler.target>16</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
@ -21,7 +21,7 @@
</repository> </repository>
<repository> <repository>
<id>vault-repo</id> <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>
<repository> <repository>
<id>engine-hub-repo</id> <id>engine-hub-repo</id>
@ -33,7 +33,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.19-R0.1-SNAPSHOT</version> <version>1.19.2-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -52,7 +52,7 @@
<groupId>org.jetbrains</groupId> <groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId> <artifactId>annotations</artifactId>
<version>23.0.0</version> <version>23.0.0</version>
<scope>compile</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -6,6 +6,81 @@ import org.bukkit.World;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public record Arena(int arenaId, World world, List<ArenaPlayer> arenaPlayers, ArenaState arenaState, boolean canJoin, public class Arena {
boolean open, int countdownTimer, int maxPlayers, int gracePeriod, Map<Integer, Location> locations) {
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; 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

@ -1,9 +1,9 @@
package net.knarcraft.hungerarena; package net.knarcraft.hungerarena;
public enum ArenaState { public enum ArenaState {
IDLE, IDLE,
RUNNING, RUNNING,
WARPED WARPED
} }

View File

@ -46,9 +46,9 @@ public class Chests implements Listener {
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
Player p = event.getPlayer(); Player p = event.getPlayer();
if (plugin.getArena(p) != null) { 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.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 != null) {
if (block.getState() instanceof InventoryHolder) { if (block.getState() instanceof InventoryHolder) {
ItemStack[] itemsinchest = ((InventoryHolder) block.getState()).getInventory().getContents().clone(); 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.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -60,34 +59,36 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
public class HungerArena extends JavaPlugin { public class HungerArena extends JavaPlugin {
static Logger log; static Logger log;
public final HashMap<Integer, List<String>> Playing = new HashMap<>(); public final HashMap<Integer, List<UUID>> Playing = new HashMap<>();
public final HashMap<Integer, List<String>> Ready = new HashMap<>(); public final HashMap<Integer, List<UUID>> Ready = new HashMap<>();
public final HashMap<Integer, List<String>> Dead = new HashMap<>(); public final HashMap<Integer, List<UUID>> Dead = new HashMap<>();
public final HashMap<Integer, String> MatchRunning = new HashMap<>(); public final HashMap<Integer, String> MatchRunning = new HashMap<>();
public final HashMap<Integer, Boolean> canJoin = new HashMap<>(); public final HashMap<Integer, Boolean> canJoin = new HashMap<>();
public final HashMap<Integer, Boolean> open = new HashMap<>(); public final HashMap<Integer, Boolean> open = new HashMap<>();
private final HashMap<Integer, Integer> CountT = new HashMap<>(); private final HashMap<Integer, Integer> countDownTimer = new HashMap<>();
public final HashMap<Integer, List<String>> Quit = new HashMap<>(); public final HashMap<Integer, List<UUID>> Quit = new HashMap<>();
public final HashMap<Integer, List<String>> Out = new HashMap<>(); public final HashMap<Integer, List<UUID>> Out = new HashMap<>();
public final HashMap<Integer, List<String>> Watching = new HashMap<>(); public final HashMap<Integer, List<UUID>> Watching = new HashMap<>();
public final HashMap<String, Integer> Kills = 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, HashMap<Integer, Location>> location = new HashMap<>();
public final HashMap<Integer, List<String>> inArena = new HashMap<>(); public final HashMap<Integer, List<UUID>> inArena = new HashMap<>();
public final HashMap<Integer, List<String>> Frozen = new HashMap<>(); //public final HashMap<Integer, List<String>> Frozen = new HashMap<>();
public final HashMap<Integer, Integer> maxPlayers = new HashMap<>(); public final HashMap<Integer, Integer> maxPlayers = new HashMap<>();
public final HashMap<String, String> setting = new HashMap<>(); public final HashMap<String, String> setting = new HashMap<>();
public final HashMap<Integer, Integer> gp = new HashMap<>(); public final HashMap<Integer, Integer> gp = new HashMap<>();
public final ArrayList<Player> Tele = new ArrayList<>(); public final ArrayList<Player> Tele = new ArrayList<>();
public final ArrayList<String> needInv = 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<Integer, Arena> arenas = new HashMap<>();
public final Map<UUID, ArenaPlayer> arenaPlayers = new HashMap<>();
public final HashMap<String, Scoreboard> scoreboards = new HashMap<>(); public final HashMap<String, Scoreboard> scoreboards = new HashMap<>();
@ -137,7 +138,7 @@ public class HungerArena extends JavaPlugin {
int i = 0; int i = 0;
int v = 0; int v = 0;
int a = 0; int arenaId = 0;
final File PFilePath = new File(getDataFolder(), "/inventories"); final File PFilePath = new File(getDataFolder(), "/inventories");
@ -352,7 +353,7 @@ public class HungerArena extends JavaPlugin {
for (Entry<String, Object> entry : temp.entrySet()) { for (Entry<String, Object> entry : temp.entrySet()) {
if (spawns.getConfigurationSection("Spawns." + entry.getKey()) != null) { if (spawns.getConfigurationSection("Spawns." + entry.getKey()) != null) {
Integer a = Integer.parseInt(entry.getKey()); 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<>()); location.computeIfAbsent(a, k -> new HashMap<>());
Map<String, Object> temp2 = spawns.getConfigurationSection("Spawns." + entry.getKey()).getValues(false); Map<String, Object> temp2 = spawns.getConfigurationSection("Spawns." + entry.getKey()).getValues(false);
for (Map.Entry<String, Object> e : temp2.entrySet()) { 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(","); String[] coords = ((String) spawns.get("Spawns." + entry.getKey() + "" + e.getKey())).split(",");
Integer s = Integer.parseInt(e.getKey()); 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]))); 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()) { for (int arenaId : location.keySet()) {
if (location.get(i).size() != 0) { if (location.get(arenaId).size() != 0) {
if (verbose) { 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<>()); Playing.put(arenaId, new ArrayList<>());
Ready.put(i, new ArrayList<>()); Ready.put(arenaId, new ArrayList<>());
Dead.put(i, new ArrayList<>()); Dead.put(arenaId, new ArrayList<>());
MatchRunning.put(i, null); MatchRunning.put(arenaId, null);
Quit.put(i, new ArrayList<>()); Quit.put(arenaId, new ArrayList<>());
Out.put(i, new ArrayList<>()); Out.put(arenaId, new ArrayList<>());
Watching.put(i, new ArrayList<>()); Watching.put(arenaId, new ArrayList<>());
NeedConfirm.put(i, new ArrayList<>()); NeedConfirm.put(arenaId, new ArrayList<>());
inArena.put(i, new ArrayList<>()); inArena.put(arenaId, new ArrayList<>());
Frozen.put(i, new ArrayList<>());
canJoin.put(i, false); Arena arena = arenas.get(arenaId);
maxPlayers.put(i, location.get(i).size()); for (ArenaPlayer arenaPlayer : arenaPlayers.values()) {
open.put(i, true); 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") @SuppressWarnings("unchecked")
public void RestoreInv(Player p, String pname) { public void restoreInventory(Player p, String pname) {
for (int u : Playing.keySet()) { for (int u : Playing.keySet()) {
if (Playing.get(u) != null) { if (Playing.get(u) != null) {
if (Playing.get(u).contains(pname)) { if (Playing.get(u).contains(pname)) {
@ -649,7 +656,7 @@ public class HungerArena extends JavaPlugin {
if (config.getBoolean("broadcastAll")) { if (config.getBoolean("broadcastAll")) {
p.getServer().broadcastMessage(ChatColor.RED + pname + " Left Arena " + u + "!"); p.getServer().broadcastMessage(ChatColor.RED + pname + " Left Arena " + u + "!");
} else { } else {
for (String gn : Playing.get(u)) { for (UUID gn : Playing.get(u)) {
Player g = getServer().getPlayer(gn); Player g = getServer().getPlayer(gn);
g.sendMessage(ChatColor.RED + pname + " Quit!"); g.sendMessage(ChatColor.RED + pname + " Quit!");
} }
@ -724,11 +731,15 @@ public class HungerArena extends JavaPlugin {
Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); Location Spawn = new Location(spawnw, spawnx, spawny, spawnz);
for (i = 0; i < Playing.get(a).size(); i++) { for (i = 0; i < Playing.get(a).size(); i++) {
String winnername = Playing.get(a).get(i); UUID winnerId = Playing.get(a).get(i);
final Player winner = getServer().getPlayerExact(winnername); final Player winner = getServer().getPlayer(winnerId);
String winnername2 = winner.getName(); //TODO: Figure out exactly what needs to be done in this case
if (winner == null) {
continue;
}
String winnerName = winner.getName();
if (canJoin.get(a)) { 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().clear();
winner.getInventory().setBoots(null); winner.getInventory().setBoots(null);
@ -741,11 +752,11 @@ public class HungerArena extends JavaPlugin {
winner.removePotionEffect(potion); winner.removePotionEffect(potion);
} }
Tele.add(winner); Tele.add(winner);
needInv.add(winnername2); needInv.add(winnerName);
winner.teleport(Spawn); winner.teleport(Spawn);
this.RestoreInv(winner, winnername2); this.restoreInventory(winner, winnerName);
if (canJoin.get(a)) { if (canJoin.get(a)) {
winner.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); winner.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
@ -827,9 +838,9 @@ public class HungerArena extends JavaPlugin {
getServer().getScheduler().cancelTask(deathtime.get(a)); getServer().getScheduler().cancelTask(deathtime.get(a));
deathtime.put(a, null); deathtime.put(a, null);
} }
if (grace.get(a) != null) { if (graceSchedulerIds.get(a) != null) {
getServer().getScheduler().cancelTask(grace.get(a)); getServer().getScheduler().cancelTask(graceSchedulerIds.get(a));
grace.put(a, null); graceSchedulerIds.put(a, null);
} }
if (start.get(a) != null) { if (start.get(a) != null) {
getServer().getScheduler().cancelTask(start.get(a)); getServer().getScheduler().cancelTask(start.get(a));
@ -841,8 +852,8 @@ public class HungerArena extends JavaPlugin {
Dead.get(a).clear(); Dead.get(a).clear();
//Show spectators //Show spectators
for (String s1 : Watching.get(a)) { for (UUID s1 : Watching.get(a)) {
Player spectator = getServer().getPlayerExact(s1); Player spectator = getServer().getPlayer(s1);
spectator.setAllowFlight(false); spectator.setAllowFlight(false);
spectator.teleport(Spawn); spectator.teleport(Spawn);
for (Player online : getServer().getOnlinePlayers()) { for (Player online : getServer().getOnlinePlayers()) {
@ -906,9 +917,9 @@ public class HungerArena extends JavaPlugin {
public void updateScoreboard(Player p) { public void updateScoreboard(Player p) {
if (getArena(p) != null || isSpectating(p)) { if (getArena(p) != null || isSpectating(p)) {
if (getArena(p) != null) { if (getArena(p) != null) {
a = getArena(p); arenaId = getArena(p).getArenaId();
} else if (getSpectating(p) != null) { } 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) { if (scoreboards.get(p.getName()) != null && scoreboards.get(p.getName()).getObjective("HA") != null) {
Scoreboard sb = scoreboards.get(p.getName()); Scoreboard sb = scoreboards.get(p.getName());
@ -918,7 +929,7 @@ public class HungerArena extends JavaPlugin {
Score players = obj.getScore(ChatColor.RED + "Players"); Score players = obj.getScore(ChatColor.RED + "Players");
Score spectators = obj.getScore(ChatColor.RED + "Spectators"); Score spectators = obj.getScore(ChatColor.RED + "Spectators");
Score allkills = obj.getScore(ChatColor.RED + "Deaths"); Score allkills = obj.getScore(ChatColor.RED + "Deaths");
players.setScore(Playing.get(a).size()); players.setScore(Playing.get(arenaId).size());
if (Kills.containsKey(p.getName())) { if (Kills.containsKey(p.getName())) {
kills.setScore(Kills.get(p.getName())); kills.setScore(Kills.get(p.getName()));
} }
@ -926,15 +937,15 @@ public class HungerArena extends JavaPlugin {
allkills.setScore(Kills.get("__SuM__")); allkills.setScore(Kills.get("__SuM__"));
} }
if (Watching.get(a) != null) { if (Watching.get(arenaId) != null) {
spectators.setScore(Watching.get(a).size()); spectators.setScore(Watching.get(arenaId).size());
} }
if (config.getInt("DeathMatch") != 0) { if (config.getInt("DeathMatch") != 0) {
if (timetodeath.get(a) != null) { if (timetodeath.get(arenaId) != null) {
if (timetodeath.get(a) > 0) { if (timetodeath.get(arenaId) > 0) {
int ttd = timetodeath.get(a) - timetodeath.get(a) / 60 * 60; int ttd = timetodeath.get(arenaId) - timetodeath.get(arenaId) / 60 * 60;
String secs = String.valueOf((ttd < 10) ? "0" + ttd : ttd); 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 { } else {
obj.setDisplayName(ChatColor.GREEN + "HA - " + ChatColor.RED + "DEATHMATCH"); 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> start = new HashMap<>();
public final HashMap<Integer, Integer> deathtime = new HashMap<>(); public final HashMap<Integer, Integer> deathtime = new HashMap<>();
public final HashMap<Integer, Integer> timetodeath = new HashMap<>(); public final HashMap<Integer, Integer> timetodeath = new HashMap<>();
public void startGames(final int a) { public void startGames(final int arenaId) {
if ((MatchRunning.get(a) != null) && (MatchRunning.get(a).equals("true"))) { if ((MatchRunning.get(arenaId) != null) && (MatchRunning.get(arenaId).equals("true"))) {
return; return;
} }
final String msg = ChatColor.translateAlternateColorCodes('&', config.getString("Start_Message")); 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(); Scoreboard scoreboard = getServer().getScoreboardManager().getNewScoreboard();
Objective sobj; Objective sobj;
try { try {
@ -980,244 +991,257 @@ public class HungerArena extends JavaPlugin {
Bukkit.getPlayer(gn).setScoreboard(scoreboard); Bukkit.getPlayer(gn).setScoreboard(scoreboard);
scoreboards.put(Bukkit.getPlayer(gn).getName(), Bukkit.getPlayer(gn).getScoreboard()); scoreboards.put(Bukkit.getPlayer(gn).getName(), Bukkit.getPlayer(gn).getScoreboard());
} }
getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha Refill " + a); getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha Refill " + arenaId);
MatchRunning.put(a, "true"); MatchRunning.put(arenaId, "true");
if (start.get(a) != null) { if (start.get(arenaId) != null) {
getServer().getScheduler().cancelTask(start.get(a)); getServer().getScheduler().cancelTask(start.get(arenaId));
} }
if (config.getString("Countdown").equalsIgnoreCase("true")) { if (config.getString("Countdown").equalsIgnoreCase("true")) {
CountT.put(a, (config.getInt("Countdown_Timer") != 0 ? config.getInt("Countdown_Timer") : 10)); displayCountDown(arenaId, msg);
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));
} else {
for (String gn : Playing.get(a)) {
Player g = getServer().getPlayer(gn);
g.sendMessage(ChatColor.AQUA + "Game starting in: " + CountT.get(a));
}
}
} 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)) {
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));
}
}
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) {
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!");
}
}
} else {
for (String gn : Playing.get(a)) {
Player g = getServer().getPlayer(gn);
g.sendMessage(ChatColor.YELLOW + String.valueOf(timetodeath.get(a)) + ChatColor.RED + " mins till the death match!");
}
}
}
if (timetodeath.get(a) <= 0) {
int i = 1;
for (String playing : Playing.get(a)) {
Player tribute = getServer().getPlayerExact(playing);
Location pLoc = null;
if (tribute.hasMetadata("HA-Location")) {
List<MetadataValue> l = tribute.getMetadata("HA-Location");
if (l != null && l.size() != 0) {
try {
pLoc = (Location) l.get(0).value();
} catch (Exception e) {
}
}
if (pLoc != null) {
tribute.teleport(pLoc); //random
} else {
tribute.teleport(location.get(a).get(i)); //row
}
}
i += 1;
for (PotionEffect pe : tribute.getActivePotionEffects()) {
PotionEffectType potion = pe.getType();
tribute.removePotionEffect(potion);
}
if (tribute.getAllowFlight()) {
tribute.setAllowFlight(false);
}
}
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!");
}
} else {
for (String gn : Playing.get(a)) {
Player g = getServer().getPlayer(gn);
g.sendMessage(ChatColor.RED + "The final battle has begun! " + Playing.get(a).size() + " tributes will be facing off!");
}
}
StopTasksDelayed(deathtime.get(a));
deathtime.put(a, null);
}
}, 20L, 20L));
}
}
setTorch(a, true);
StopTasksDelayed(start.get(a));
}
}, 20L, 20L));
} else { } else {
setTorch(a, true); Arena arena = arenas.get(arenaId);
Frozen.get(a).clear(); setTorch(arenaId, true);
for (ArenaPlayer arenaPlayer : arenaPlayers.values()) {
if (arenaPlayer.getArena() == arena) {
arenaPlayer.setFrozen(false);
}
}
if (config.getBoolean("broadcastAll")) { if (config.getBoolean("broadcastAll")) {
getServer().broadcastMessage(msg); getServer().broadcastMessage(msg);
} else { } else {
for (String gn : Playing.get(a)) { for (UUID gn : Playing.get(arenaId)) {
Player g = getServer().getPlayer(gn); Player g = getServer().getPlayer(gn);
g.sendMessage(msg); g.sendMessage(msg);
} }
} }
} }
canJoin.put(a, true); canJoin.put(arenaId, true);
} }
private void StopTasksDelayed(final int task) { 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) {
announceGracePeriod(arenaId);
}
if (config.getInt("DeathMatch") != 0) {
int death = config.getInt("DeathMatch");
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(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 (UUID gn : Playing.get(arenaId)) {
Player g = getServer().getPlayer(gn);
g.sendMessage(ChatColor.YELLOW + String.valueOf(timetodeath.get(arenaId)) + ChatColor.RED + " mins till the death match!");
}
}
}
if (timetodeath.get(arenaId) <= 0) {
int i = 1;
for (UUID playing : Playing.get(arenaId)) {
Player tribute = getServer().getPlayer(playing);
Location pLoc = null;
if (tribute.hasMetadata("HA-Location")) {
List<MetadataValue> l = tribute.getMetadata("HA-Location");
if (l != null && l.size() != 0) {
try {
pLoc = (Location) l.get(0).value();
} catch (Exception e) {
}
}
if (pLoc != null) {
tribute.teleport(pLoc); //random
} else {
tribute.teleport(location.get(arenaId).get(i)); //row
}
}
i += 1;
for (PotionEffect pe : tribute.getActivePotionEffects()) {
PotionEffectType potion = pe.getType();
tribute.removePotionEffect(potion);
}
if (tribute.getAllowFlight()) {
tribute.setAllowFlight(false);
}
}
if (config.getBoolean("broadcastAll")) {
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 (UUID gn : Playing.get(arenaId)) {
Player g = getServer().getPlayer(gn);
g.sendMessage(ChatColor.RED + "The final battle has begun! " + Playing.get(arenaId).size() + " tributes will be facing off!");
}
}
stopTaskDelayed(deathtime.get(arenaId));
deathtime.put(arenaId, null);
}
}, 20L, 20L));
}
}
setTorch(arenaId, true);
stopTaskDelayed(start.get(arenaId));
}
}, 20L, 20L));
}
private void stopTaskDelayed(final int task) {
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> Bukkit.getScheduler().cancelTask(task), 10L); Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> Bukkit.getScheduler().cancelTask(task), 10L);
} }
public Integer getArena(Player p) { public Arena getArena(Player player) {
for (int x : Playing.keySet()) { ArenaPlayer arenaPlayer = arenaPlayers.get(player.getUniqueId());
if (Playing.get(x).contains(p.getName())) { if (arenaPlayer != null) {
return x; return arenaPlayer.getArena();
}
} }
return null; return null;
} }
public Integer getSpectating(Player p) { public Arena getSpectating(Player player) {
for (int x : Watching.keySet()) { ArenaPlayer arenaPlayer = arenaPlayers.get(player.getUniqueId());
if (Watching.get(x).contains(p.getName())) { if (arenaPlayer != null && arenaPlayer.isWatching()) {
return x; return arenaPlayer.getArena();
}
} }
return null; return null;
} }
public boolean isSpectating(Player p) { public boolean isSpectating(Player p) {
for (int x : Watching.keySet()) { return getSpectating(p) != null;
if (Watching.get(x).contains(p.getName())) {
return true;
}
}
return false;
} }
public void setTorch(int a, boolean set) { public void setTorch(int arenaId, boolean set) {
String arena = String.valueOf(a); if (spawns.getString("Start_torch." + arenaId) != null) {
if (spawns.getString("Start_torch." + arena) != null) { String[] torchCoordinates = spawns.getString("Start_torch." + arenaId).split(",");
String[] Torchcoords = spawns.getString("Start_torch." + arena).split(","); double torchX = Double.parseDouble(torchCoordinates[0]);
double torchx = Double.parseDouble(Torchcoords[0]); double torchY = Double.parseDouble(torchCoordinates[1]);
double torchy = Double.parseDouble(Torchcoords[1]); double torchZ = Double.parseDouble(torchCoordinates[2]);
double torchz = Double.parseDouble(Torchcoords[2]); String torchWorldName = torchCoordinates[3];
String torchworld = Torchcoords[3]; World torchWorld = getServer().getWorld(torchWorldName);
World torchw = getServer().getWorld(torchworld); Location torchLocation = new Location(torchWorld, torchX, torchY, torchZ);
Location TorchLoc = new Location(torchw, torchx, torchy, torchz);
if (set) { if (set) {
SetTorch(TorchLoc); torchLocation.getBlock().setType(Material.REDSTONE_TORCH);
} else { } 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; int a = 1;
if (alwaysProtect) { if (alwaysProtect) {
String ThisWorld = p.getWorld().getName(); String ThisWorld = p.getWorld().getName();
for (int z : plugin.worldsNames.keySet()) { for (int z : plugin.worldNames.keySet()) {
if (plugin.worldsNames.get(z) != null) { if (plugin.worldNames.get(z) != null) {
if (plugin.worldsNames.get(z).equals(ThisWorld)) { if (plugin.worldNames.get(z).equals(ThisWorld)) {
a = z; a = z;
} }
} }
} }
} }
if (plugin.getArena(p) != null) { 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 ((!event.isCancelled()) && (((plugin.Playing.get(a)).contains(pname)) || (alwaysProtect))) {
if (plugin.config.getBoolean("Protected_Arena")) { if (plugin.config.getBoolean("Protected_Arena")) {
event.setCancelled(true); event.setCancelled(true);
p.sendMessage(ChatColor.RED + "You can't break blocks while playing!"); 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"))) { 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); event.setCancelled(true);
p.sendMessage(ChatColor.RED + "That is an illegal block!"); p.sendMessage(ChatColor.RED + "That is an illegal block!");
@ -78,7 +78,7 @@ public class BlockStorage implements Listener {
for (int i : plugin.canJoin.keySet()) { for (int i : plugin.canJoin.keySet()) {
if (plugin.canJoin.get(i) || alwaysProtect()) { if (plugin.canJoin.get(i) || alwaysProtect()) {
String ThisWorld = e.getWorld().getName(); 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) { if (e.getType() == EntityType.PRIMED_TNT) {
e.getLocation().getBlock().setType(Material.TNT); e.getLocation().getBlock().setType(Material.TNT);
Block TNT = e.getLocation().getBlock(); Block TNT = e.getLocation().getBlock();
@ -102,7 +102,7 @@ public class BlockStorage implements Listener {
if (!event.isCancelled()) { if (!event.isCancelled()) {
for (int i : plugin.canJoin.keySet()) { for (int i : plugin.canJoin.keySet()) {
if (plugin.canJoin.get(i) || alwaysProtect()) { 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(); String w = b.getWorld().getName();
addDestroyedBlockToList(b, w, i); addDestroyedBlockToList(b, w, i);
} }
@ -123,21 +123,21 @@ public class BlockStorage implements Listener {
int a = 1; int a = 1;
if (protall) { if (protall) {
String ThisWorld = p.getWorld().getName(); String ThisWorld = p.getWorld().getName();
for (int z : plugin.worldsNames.keySet()) { for (int z : plugin.worldNames.keySet()) {
if (plugin.worldsNames.get(z) != null) { if (plugin.worldNames.get(z) != null) {
if (plugin.worldsNames.get(z).equals(ThisWorld)) { if (plugin.worldNames.get(z).equals(ThisWorld)) {
a = z; a = z;
} }
} }
} }
} }
if (plugin.getArena(p) != null) { if (plugin.getArena(p) != null) {
a = plugin.getArena(p); a = plugin.getArena(p).getArenaId();
} }
if (!event.isCancelled()) { if (!event.isCancelled()) {
if (((plugin.Playing.get(a)).contains(p.getName())) || (protall)) { if (((plugin.Playing.get(a)).contains(p.getName())) || (protall)) {
if ((plugin.canJoin.get(a)) || (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)) { 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; 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) { 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) @EventHandler(priority = EventPriority.MONITOR)
public void bucketEmpty(PlayerBucketEmptyEvent event) { public void bucketEmpty(PlayerBucketEmptyEvent event) {
if (plugin.getArena(event.getPlayer()) != null) { if (plugin.getArena(event.getPlayer()) != null) {
int a = plugin.getArena(event.getPlayer()); int a = plugin.getArena(event.getPlayer()).getArenaId();
if (!event.isCancelled()) { if (!event.isCancelled()) {
if (plugin.canJoin.get(a)) { if (plugin.canJoin.get(a)) {
if (plugin.Playing.get(a).contains(event.getPlayer().getName())) { 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()); Block b = event.getBlockClicked().getRelative(event.getBlockFace());
String w = b.getWorld().getName(); String w = b.getWorld().getName();
addPlacedBlockToList(b, w, a); addPlacedBlockToList(b, w, a);
@ -186,13 +186,13 @@ public class BlockStorage implements Listener {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void bucketFill(PlayerBucketFillEvent event) { public void bucketFill(PlayerBucketFillEvent event) {
if (plugin.getArena(event.getPlayer()) != null) { if (plugin.getArena(event.getPlayer()) != null) {
int arena = plugin.getArena(event.getPlayer()); int arena = plugin.getArena(event.getPlayer()).getArenaId();
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
} }
boolean isPlaying = plugin.Playing.get(arena).contains(event.getPlayer().getName()); 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))) { if (joinAble(arena) && (isPlaying && (!plugin.restrictedWorlds || enabledInWorld))) {
Block block = event.getBlockClicked().getRelative(event.getBlockFace()); Block block = event.getBlockClicked().getRelative(event.getBlockFace());
String worldName = block.getWorld().getName(); String worldName = block.getWorld().getName();
@ -208,9 +208,9 @@ public class BlockStorage implements Listener {
} }
for (int arena : plugin.canJoin.keySet()) { 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() && if (joinAble(arena) || alwaysProtect() &&
(!plugin.restrictedWorlds || plugin.worldsNames.get(arena) != null && isInWorld)) { (!plugin.restrictedWorlds || plugin.worldNames.get(arena) != null && isInWorld)) {
Block block = event.getBlock(); Block block = event.getBlock();
String worldName = block.getWorld().getName(); String worldName = block.getWorld().getName();
Material material = block.getType(); Material material = block.getType();
@ -263,7 +263,7 @@ public class BlockStorage implements Listener {
/** /**
* Gets whether the given arena can be joined * Gets whether the given arena can be joined
* *
* @param arena <p>The arena to check</p> * @param arena <p>The arena to check</p>
* @return <p>True if the arena can be joined</p> * @return <p>True if the arena can be joined</p>
*/ */

View File

@ -15,6 +15,8 @@ import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.DisplaySlot;
import java.util.UUID;
public class DeathListener implements Listener { public class DeathListener implements Listener {
public final HungerArena plugin; 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...) //get the arena the player has died in... (may be not the one he joined...)
String ThisWorld = p.getWorld().getName(); String ThisWorld = p.getWorld().getName();
for (int z : plugin.worldsNames.keySet()) { for (int z : plugin.worldNames.keySet()) {
if (plugin.worldsNames.get(z) != null) { if (plugin.worldNames.get(z) != null) {
if (plugin.worldsNames.get(z).equals(ThisWorld)) { if (plugin.worldNames.get(z).equals(ThisWorld)) {
a = z; a = z;
} }
} }
@ -63,7 +65,7 @@ public class DeathListener implements Listener {
final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz); final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz);
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> { Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
player.teleport(Spawn); player.teleport(Spawn);
plugin.RestoreInv(player, player.getName()); plugin.restoreInventory(player, player.getName());
}, 10L); }, 10L);
} }
@ -72,136 +74,141 @@ public class DeathListener implements Listener {
Player p = event.getEntity(); Player p = event.getEntity();
Server s = p.getServer(); Server s = p.getServer();
String pname = p.getName(); String pname = p.getName();
UUID playerId = p.getUniqueId();
if (plugin.getArena(p) != null) { if (plugin.getArena(p) != null) {
a = plugin.getArena(p); a = plugin.getArena(p).getArenaId();
int players = plugin.Playing.get(a).size() - 1;
String leftmsg = null; String leftmsg = null;
clearInv(p); clearInv(p);
event.getDrops().clear(); event.getDrops().clear();
p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
plugin.scoreboards.remove(p.getName()); plugin.scoreboards.remove(p.getName());
if (!plugin.Frozen.get(a).isEmpty()) { int players = plugin.Playing.get(a).size() - 1;
if (plugin.Frozen.get(a).contains(pname)) { if (plugin.arenaPlayers.get(playerId).isFrozen()) {
if (!(p.getKiller() instanceof Player)) { doFrozenPlayerStuff(p, players, leftmsg, pname, playerId, event, s);
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);
}
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)) {
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);
if (plugin.config.getBoolean("broadcastAll")) {
p.getServer().broadcastMessage(leftmsg);
} else {
for (String gn : plugin.Playing.get(a)) {
Player g = plugin.getServer().getPlayer(gn);
g.sendMessage(leftmsg);
}
}
plugin.winner(a);
}
}
} else { } else {
players = plugin.Playing.get(a).size() - 1; doNonFrozenPlayerStuff(p, players, leftmsg, pname, playerId, event, 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(); private void doFrozenPlayerStuff(Player p, int players, String leftmsg, String pname, UUID playerId, PlayerDeathEvent event, Server s) {
double z = p.getLocation().getZ(); //Basically, if a frozen player is killed by something which isn't another player, assume the reason the player
Location strike = new Location(p.getWorld(), x, newY, z); // was killed was because they left their pedestal too early
p.getWorld().strikeLightning(strike); if (!(p.getKiller() instanceof Player)) {
} leftmsg = ChatColor.BLUE + "There are now " + players + " tributes left!";
plugin.Dead.get(a).add(pname); fireCannon(p);
plugin.Playing.get(a).remove(pname); event.setDeathMessage("");
if (p.getKiller() instanceof Player) { if (plugin.config.getBoolean("broadcastAll")) {
if (p.getKiller().getInventory().getItemInMainHand().getType() == Material.AIR) { p.getServer().broadcastMessage(pname + ChatColor.LIGHT_PURPLE + " Stepped off their pedestal too early!");
Player killer = p.getKiller(); } else {
String killername = killer.getName(); for (UUID gn : plugin.Playing.get(a)) {
event.setDeathMessage(""); Player g = plugin.getServer().getPlayer(gn);
if (plugin.config.getBoolean("broadcastAll")) { g.sendMessage(pname + ChatColor.LIGHT_PURPLE + " Stepped off their pedestal too early!");
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)) {
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);
}
}
if (plugin.Kills.containsKey(killername)) {
plugin.Kills.put(killername, plugin.Kills.get(killername) + 1);
} else {
plugin.Kills.put(killername, 1);
}
if (plugin.Kills.containsKey("__SuM__")) {
plugin.Kills.put("__SuM__", plugin.Kills.get("__SuM__") + 1);
} else {
plugin.Kills.put("__SuM__", 1);
}
plugin.winner(a);
} else {
Player killer = p.getKiller();
String killername = killer.getName();
String weapon = "a(n) " + killer.getInventory().getItemInMainHand().getType().name().replace('_', ' ');
if (killer.getInventory().getItemInMainHand().hasItemMeta()) {
if (killer.getInventory().getItemInMainHand().getItemMeta().hasDisplayName()) {
weapon = killer.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
}
}
String msg = ChatColor.LIGHT_PURPLE + "**BOOM** Tribute " + pname + " was killed by tribute " + killername + " with " + weapon;
event.setDeathMessage("");
if (plugin.config.getBoolean("broadcastAll")) {
s.broadcastMessage(msg);
s.broadcastMessage(leftmsg);
} else {
for (String gn : plugin.Playing.get(a)) {
Player g = plugin.getServer().getPlayer(gn);
g.sendMessage(msg);
g.sendMessage(leftmsg);
}
}
if (plugin.Kills.containsKey(killername)) {
plugin.Kills.put(killername, plugin.Kills.get(killername) + 1);
} else {
plugin.Kills.put(killername, 1);
}
if (plugin.Kills.containsKey("__SuM__")) {
plugin.Kills.put("__SuM__", plugin.Kills.get("__SuM__") + 1);
} else {
plugin.Kills.put("__SuM__", 1);
}
plugin.winner(a);
}
} else {
event.setDeathMessage("");
if (plugin.config.getBoolean("broadcastAll")) {
s.broadcastMessage(ChatColor.LIGHT_PURPLE + pname + " died of natural causes!");
s.broadcastMessage(leftmsg);
} else {
for (String 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);
}
}
plugin.winner(a);
} }
} }
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 (UUID gn : plugin.Playing.get(a)) {
Player g = plugin.getServer().getPlayer(gn);
g.sendMessage(leftmsg);
}
}
plugin.winner(a);
}
}
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!";
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 (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);
}
}
if (plugin.Kills.containsKey(killername)) {
plugin.Kills.put(killername, plugin.Kills.get(killername) + 1);
} else {
plugin.Kills.put(killername, 1);
}
if (plugin.Kills.containsKey("__SuM__")) {
plugin.Kills.put("__SuM__", plugin.Kills.get("__SuM__") + 1);
} else {
plugin.Kills.put("__SuM__", 1);
}
plugin.winner(a);
} else {
Player killer = player.getKiller();
String killername = killer.getName();
String weapon = "a(n) " + killer.getInventory().getItemInMainHand().getType().name().replace('_', ' ');
if (killer.getInventory().getItemInMainHand().hasItemMeta()) {
if (killer.getInventory().getItemInMainHand().getItemMeta().hasDisplayName()) {
weapon = killer.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
}
}
String msg = ChatColor.LIGHT_PURPLE + "**BOOM** Tribute " + pname + " was killed by tribute " + killername + " with " + weapon;
event.setDeathMessage("");
if (plugin.config.getBoolean("broadcastAll")) {
s.broadcastMessage(msg);
s.broadcastMessage(leftmsg);
} else {
for (UUID gn : plugin.Playing.get(a)) {
Player g = plugin.getServer().getPlayer(gn);
g.sendMessage(msg);
g.sendMessage(leftmsg);
}
}
if (plugin.Kills.containsKey(killername)) {
plugin.Kills.put(killername, plugin.Kills.get(killername) + 1);
} else {
plugin.Kills.put(killername, 1);
}
if (plugin.Kills.containsKey("__SuM__")) {
plugin.Kills.put("__SuM__", plugin.Kills.get("__SuM__") + 1);
} else {
plugin.Kills.put("__SuM__", 1);
}
plugin.winner(a);
}
} else {
event.setDeathMessage("");
if (plugin.config.getBoolean("broadcastAll")) {
s.broadcastMessage(ChatColor.LIGHT_PURPLE + pname + " died of natural causes!");
s.broadcastMessage(leftmsg);
} else {
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);
}
}
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; package net.knarcraft.hungerarena.Listeners;
import net.knarcraft.hungerarena.ArenaPlayer;
import net.knarcraft.hungerarena.HungerArena; import net.knarcraft.hungerarena.HungerArena;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -13,6 +14,7 @@ import org.bukkit.metadata.MetadataValue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.UUID;
public class FreezeListener implements Listener { public class FreezeListener implements Listener {
public final HungerArena plugin; public final HungerArena plugin;
@ -31,12 +33,12 @@ public class FreezeListener implements Listener {
Player p = event.getPlayer(); Player p = event.getPlayer();
String pname = p.getName(); String pname = p.getName();
if (plugin.getArena(p) != null) { if (plugin.getArena(p) != null) {
a = plugin.getArena(p); a = plugin.getArena(p).getArenaId();
if (plugin.Frozen.get(a).contains(pname) && plugin.config.getBoolean("Frozen_Teleport")) { if (plugin.arenaPlayers.get(p.getUniqueId()).isFrozen() && plugin.config.getBoolean("Frozen_Teleport")) {
if (plugin.config.getBoolean("Explode_on_Move")) { if (plugin.config.getBoolean("Explode_on_Move")) {
timeUp.put(a, false); timeUp.put(a, false);
for (String players : plugin.Playing.get(a)) { for (UUID players : plugin.Playing.get(a)) {
Player playing = plugin.getServer().getPlayerExact(players); Player playing = plugin.getServer().getPlayer(players);
i = plugin.Playing.get(a).indexOf(players) + 1; i = plugin.Playing.get(a).indexOf(players) + 1;
if (!timeUp.get(a) && !timing.contains(a)) { if (!timeUp.get(a) && !timing.contains(a)) {
timing.add(a); timing.add(a);
@ -52,7 +54,7 @@ public class FreezeListener implements Listener {
} else { } else {
if (!playing.getLocation().getBlock().getLocation().equals(plugin.location.get(a).get(i).getBlock().getLocation())) { if (!playing.getLocation().getBlock().getLocation().equals(plugin.location.get(a).get(i).getBlock().getLocation())) {
if (!plugin.Dead.get(a).contains(playing.getName())) { 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 world = playing.getLocation().getWorld();
world.createExplosion(playing.getLocation(), 0.0F, false); world.createExplosion(playing.getLocation(), 0.0F, false);
playing.setHealth(0.0D); playing.setHealth(0.0D);
@ -74,17 +76,19 @@ public class FreezeListener implements Listener {
if (plugin.config.getBoolean("broadcastAll")) { if (plugin.config.getBoolean("broadcastAll")) {
p.getServer().broadcastMessage(pname + ChatColor.LIGHT_PURPLE + " Stepped off their pedestal too early!"); p.getServer().broadcastMessage(pname + ChatColor.LIGHT_PURPLE + " Stepped off their pedestal too early!");
} else { } else {
for (String gn : plugin.Playing.get(a)) { for (UUID gn : plugin.Playing.get(a)) {
Player g = plugin.getServer().getPlayer(gn); Player g = plugin.getServer().getPlayer(gn);
g.sendMessage(pname + ChatColor.LIGHT_PURPLE + " Stepped off their pedestal too early!"); g.sendMessage(pname + ChatColor.LIGHT_PURPLE + " Stepped off their pedestal too early!");
} }
} }
plugin.Frozen.get(a).remove(pname); ArenaPlayer arenaPlayer = plugin.arenaPlayers.get(p.getUniqueId());
plugin.Playing.get(a).remove(pname); arenaPlayer.setFrozen(false);
arenaPlayer.setInArena(false);
arenaPlayer.setArena(null);
if (plugin.config.getBoolean("broadcastAll")) { if (plugin.config.getBoolean("broadcastAll")) {
p.getServer().broadcastMessage(leftmsg); p.getServer().broadcastMessage(leftmsg);
} else { } else {
for (String gn : plugin.Playing.get(a)) { for (UUID gn : plugin.Playing.get(a)) {
Player g = plugin.getServer().getPlayer(gn); Player g = plugin.getServer().getPlayer(gn);
g.sendMessage(leftmsg); g.sendMessage(leftmsg);
} }

View File

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

View File

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

View File

@ -19,7 +19,7 @@ public class TeleportListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onTP(PlayerTeleportEvent event) { public void onTP(PlayerTeleportEvent event) {
Player p = event.getPlayer(); 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); event.setCancelled(true);
p.sendMessage(ChatColor.RED + "You are a dead tribute... How are you supposed to get back into the arena...."); p.sendMessage(ChatColor.RED + "You are a dead tribute... How are you supposed to get back into the arena....");
plugin.Tele.remove(p); plugin.Tele.remove(p);

View File

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

View File

@ -3,6 +3,7 @@ package net.knarcraft.hungerarena;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -13,166 +14,157 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
public class SpawnsCommand implements CommandExecutor { public class SpawnsCommand implements CommandExecutor {
public final HungerArena plugin;
int i = 0;
int arenaId = 0;
boolean NoPlayerSpawns;
public SpawnsCommand(HungerArena m) { public final HungerArena plugin;
this.plugin = m; int tributeId = 0;
int arenaId = 0;
boolean noPlayerSpawns;
public SpawnsCommand(HungerArena plugin) {
this.plugin = plugin;
} }
@Override @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String commandLabel, String[] args) { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String commandLabel,
Player p = (Player) sender; String[] args) {
String ThisWorld = p.getWorld().getName(); Player player = (Player) sender;
NoPlayerSpawns = true; String playerWorld = player.getWorld().getName();
for (int i : plugin.worldsNames.keySet()) { this.noPlayerSpawns = true;
if (plugin.worldsNames.get(i) != null) { for (int arenaId : plugin.arenas.keySet()) {
if (plugin.worldsNames.get(i).equals(ThisWorld)) { String arenaWorld = plugin.worldNames.get(arenaId);
arenaId = i; if (arenaWorld != null) {
NoPlayerSpawns = false; if (arenaWorld.equals(playerWorld)) {
this.arenaId = arenaId;
this.noPlayerSpawns = false;
break; 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;
}
String world = args[2]; if (!command.getName().equalsIgnoreCase("StartPoint")) {
x = Double.parseDouble(args[3]); return false;
y = Double.parseDouble(args[4]); }
z = Double.parseDouble(args[5]);
location = new Location(Bukkit.getWorld(world), x, y, z); if (!player.hasPermission("HungerArena.StartPoint")) {
if (plugin.location.get(arenaId) != null) { player.sendMessage(ChatColor.RED + "You don't have permission!");
plugin.location.get(arenaId).put(i, location); return false;
} else { }
/*plugin.arenas.put(arenaId, new Arena(arenaId, location.getWorld(), new ArrayList<>(),
ArenaState.IDLE, false, true, 0, 0, 0, if (args.length >= 2) {
new HashMap<>()));*/ try {
plugin.arenas.get(arenaId).locations().put(i, location); this.tributeId = Integer.parseInt(args[1]);
plugin.location.put(arenaId, new HashMap<>()); this.arenaId = Integer.parseInt(args[0]);
plugin.location.get(arenaId).put(i, location); } catch (Exception e) {
plugin.Playing.put(arenaId, new ArrayList<>()); player.sendMessage(ChatColor.RED + "Argument not an integer!");
plugin.Ready.put(arenaId, new ArrayList<>()); return true;
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 (args.length >= 2) {
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 (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!");
}
} else if (args.length == 1) {
if (NoPlayerSpawns) {
try {
arenaId = Integer.parseInt(args[0]);
} catch (Exception e) {
p.sendMessage(ChatColor.RED + "Argument not an integer!");
return true;
}
}
if (plugin.spawns.get("Spawns." + arenaId) != null) {
int start = 1;
while (start < plugin.config.getInt("maxPlayers") + 2) {
if (plugin.spawns.get("Spawns." + arenaId + "" + start) != null) {
start = start + 1;
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;
}
} 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;
}
}
}
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;
}
} else {
p.sendMessage(ChatColor.RED + "You don't have permission!");
} }
} }
return false;
if (args.length == 6) {
saveGivenLocationSpawnPoint(args, player);
return true;
} else if (args.length >= 2) {
savePlayerLocationSpawnPoint(player);
return true;
} else if (args.length == 1) {
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;
}
}
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++;
//All spawn points already set
if (start == plugin.config.getInt("maxPlayers") + 1) {
player.sendMessage(ChatColor.DARK_AQUA + "[HungerArena] " + ChatColor.GREEN +
"All spawns set, type /startpoint [Arena #] [Spawn #] to over-ride previous points!");
return;
}
} else {
//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;
}
}
}
//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);
}
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 ...");
}
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);
} }
} }