Safety commit before changing how arenas are stored

This commit is contained in:
Kristian Knarvik 2022-07-21 20:36:27 +02:00
parent df467cd956
commit 392a8448e4
28 changed files with 717 additions and 684 deletions

View File

@ -48,6 +48,12 @@
<version>7.2.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,58 +0,0 @@
package me.Travja.HungerArena.Listeners;
import me.Travja.HungerArena.Main;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
public class WorldChange implements Listener {
public final Main plugin;
public WorldChange(Main m) {
plugin = m;
}
@EventHandler(priority = EventPriority.LOWEST)
public void worldChangeLow(PlayerChangedWorldEvent event) {
Player p = event.getPlayer();
String pname = p.getName();
String ThisWorld = p.getWorld().getName();
String FromWorld = event.getFrom().getName();
if (!plugin.worldsNames.containsValue(ThisWorld) && plugin.worldsNames.containsValue(FromWorld)) {
plugin.RestoreInv(p, pname);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void worldChangeHigh(PlayerChangedWorldEvent event) {
Player p = event.getPlayer();
String pname = p.getName();
String ThisWorld = p.getWorld().getName();
int a = 0;
for (int i : plugin.worldsNames.keySet()) {
if (plugin.worldsNames.get(i) != null) {
if (plugin.worldsNames.get(i).equals(ThisWorld)) {
a = i;
if (plugin.Frozen.get(a) != null && plugin.Frozen.get(a).contains(pname)) {
return;
} else {
plugin.RestoreInv(p, pname);
if (plugin.config.getString("joinTeleport").equalsIgnoreCase("true")) {
String[] Spawncoords = plugin.spawns.getString("Spawn_coords." + a).split(",");
double spawnx = Double.parseDouble(Spawncoords[0]);
double spawny = Double.parseDouble(Spawncoords[1]);
double spawnz = Double.parseDouble(Spawncoords[2]);
Location Spawn = new Location(p.getWorld(), spawnx, spawny, spawnz);
if (!p.getLocation().getBlock().equals(Spawn.getBlock())) {
p.teleport(Spawn);
}
}
}
}
}
}
}
}

View File

@ -1,180 +0,0 @@
package me.Travja.HungerArena;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.HashMap;
public class SpawnsCommand implements CommandExecutor {
public final Main plugin;
int i = 0;
int a = 0;
boolean NoPlayerSpawns;
public SpawnsCommand(Main m) {
this.plugin = m;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
Player p = (Player) sender;
String ThisWorld = p.getWorld().getName();
NoPlayerSpawns = true;
for (int i : plugin.worldsNames.keySet()) {
if (plugin.worldsNames.get(i) != null) {
if (plugin.worldsNames.get(i).equals(ThisWorld)) {
a = i;
NoPlayerSpawns = false;
break;
}
}
}
if (cmd.getName().equalsIgnoreCase("StartPoint")) {
if (p.hasPermission("HungerArena.StartPoint")) {
Location loc = null;
double x;
double y;
double z;
if (args.length == 6) {
try {
i = Integer.parseInt(args[1]);
a = Integer.parseInt(args[0]);
} catch (Exception e) {
p.sendMessage(ChatColor.RED + "Argument not an integer!");
return true;
}
String world = args[2];
x = Double.parseDouble(args[3]);
y = Double.parseDouble(args[4]);
z = Double.parseDouble(args[5]);
loc = new Location(Bukkit.getWorld(world), x, y, z);
if (plugin.location.get(a) != null) {
plugin.location.get(a).put(i, loc);
} else {
plugin.location.put(a, new HashMap<>());
plugin.location.get(a).put(i, loc);
plugin.Playing.put(a, new ArrayList<>());
plugin.Ready.put(a, new ArrayList<>());
plugin.Dead.put(a, new ArrayList<>());
plugin.Quit.put(a, new ArrayList<>());
plugin.Out.put(a, new ArrayList<>());
plugin.Watching.put(a, new ArrayList<>());
plugin.NeedConfirm.put(a, new ArrayList<>());
plugin.inArena.put(a, new ArrayList<>());
plugin.Frozen.put(a, new ArrayList<>());
plugin.arena.put(a, new ArrayList<>());
plugin.canjoin.put(a, false);
plugin.MatchRunning.put(a, null);
plugin.open.put(a, true);
}
String coords = loc.getWorld().getName() + "," + (loc.getX()) + "," + loc.getY() + "," + (loc.getZ());
p.sendMessage(coords);
plugin.spawns.set("Spawns." + a + "" + i, coords);
plugin.worldsNames.put(a, loc.getWorld().getName());
plugin.saveSpawns();
plugin.maxPlayers.put(a, plugin.location.get(a).size());
p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute " + i + " in arena " + a + "!");
this.plugin.reloadSpawnpoints(false);
return true;
}
if (args.length >= 2) {
try {
i = Integer.parseInt(args[1]);
a = 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 ...");
}
loc = p.getLocation().getBlock().getLocation();
x = loc.getX() + .5;
y = loc.getY();
z = loc.getZ() + .5;
loc = new Location(loc.getWorld(), x, y, z);
if (plugin.location.get(a) != null) {
plugin.location.get(a).put(i, loc);
} else {
plugin.location.put(a, new HashMap<>());
plugin.location.get(a).put(i, loc);
plugin.Playing.put(a, new ArrayList<>());
plugin.Ready.put(a, new ArrayList<>());
plugin.Dead.put(a, new ArrayList<>());
plugin.Quit.put(a, new ArrayList<>());
plugin.Out.put(a, new ArrayList<>());
plugin.Watching.put(a, new ArrayList<>());
plugin.NeedConfirm.put(a, new ArrayList<>());
plugin.inArena.put(a, new ArrayList<>());
plugin.Frozen.put(a, new ArrayList<>());
plugin.arena.put(a, new ArrayList<>());
plugin.canjoin.put(a, false);
plugin.MatchRunning.put(a, null);
plugin.open.put(a, true);
}
String coords = loc.getWorld().getName() + "," + (loc.getX()) + "," + loc.getY() + "," + (loc.getZ());
p.sendMessage(coords);
plugin.spawns.set("Spawns." + a + "" + i, coords);
plugin.worldsNames.put(a, loc.getWorld().getName());
plugin.saveSpawns();
plugin.maxPlayers.put(a, plugin.location.get(a).size());
p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute " + i + " in arena " + a + "!");
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 (sender instanceof Player) {
p = (Player) sender;
if (NoPlayerSpawns) {
try {
a = Integer.parseInt(args[0]);
} catch (Exception e) {
p.sendMessage(ChatColor.RED + "Argument not an integer!");
return true;
}
}
if (plugin.spawns.get("Spawns." + a) != null) {
int start = 1;
while (start < plugin.config.getInt("maxPlayers") + 2) {
if (plugin.spawns.get("Spawns." + a + "" + 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 " + a + " Starting From Point " + sloc);
plugin.setting.put(p.getName(), a + "-" + sloc);
return true;
}
}
}
p.sendMessage(ChatColor.DARK_AQUA + "[HungerArena] " + ChatColor.RED + "Begin Setting For Arena " + a + " Starting From Point " + 1);
plugin.setting.put(p.getName(), a + "-" + 1);
return true;
} else {
sender.sendMessage(ChatColor.BLUE + "This Can Only Be Sent As A Player");
}
} 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;
}
}

View File

@ -0,0 +1,11 @@
package net.knarcraft.hungerarena;
import org.bukkit.Location;
import org.bukkit.World;
import java.util.List;
import java.util.Map;
public record Arena(int arenaId, World world, List<ArenaPlayer> arenaPlayers, ArenaState arenaState, boolean canJoin,
boolean open, int countdownTimer, int maxPlayers, int gracePeriod, Map<Integer, Location> locations) {
}

View File

@ -0,0 +1,7 @@
package net.knarcraft.hungerarena;
import org.bukkit.entity.Player;
public record ArenaPlayer(Player player, boolean ready, boolean quit, boolean dead, boolean isOut, boolean isWatching,
boolean needConfirmation, boolean inArena, boolean frozen) {
}

View File

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

View File

@ -1,4 +1,4 @@
package me.Travja.HungerArena;
package net.knarcraft.hungerarena;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@ -13,9 +13,9 @@ import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
public class Chests implements Listener {
public final Main plugin;
public final HungerArena plugin;
public Chests(Main m) {
public Chests(HungerArena m) {
this.plugin = m;
}
@ -47,8 +47,8 @@ public class Chests implements Listener {
Player p = event.getPlayer();
if (plugin.getArena(p) != null) {
int a = plugin.getArena(p);
if (plugin.Playing.get(a).contains(p.getName()) && plugin.canjoin.get(a)) {
if (!plugin.restricted || (plugin.restricted && plugin.worldsNames.containsValue(p.getWorld().getName()))) {
if (plugin.Playing.get(a).contains(p.getName()) && plugin.canJoin.get(a)) {
if (!plugin.restrictedWorlds || (plugin.restrictedWorlds && plugin.worldsNames.containsValue(p.getWorld().getName()))) {
if (block != null) {
if (block.getState() instanceof InventoryHolder) {
ItemStack[] itemsinchest = ((InventoryHolder) block.getState()).getInventory().getContents().clone();

View File

@ -1,4 +1,4 @@
package me.Travja.HungerArena;
package net.knarcraft.hungerarena;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -9,9 +9,9 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class CommandBlock implements Listener {
public final Main plugin;
public final HungerArena plugin;
public CommandBlock(Main m) {
public CommandBlock(HungerArena m) {
this.plugin = m;
}
@ -33,7 +33,7 @@ public class CommandBlock implements Listener {
}
} else if (cmd.toLowerCase().trim().equals("/back")) {
for (int u : plugin.Dead.keySet()) {
if (plugin.Dead.get(u).contains(pname) && plugin.canjoin.get(u)) {
if (plugin.Dead.get(u).contains(pname) && plugin.canJoin.get(u)) {
plugin.Tele.add(p);
}
}

View File

@ -1,4 +1,4 @@
package me.Travja.HungerArena;
package net.knarcraft.hungerarena;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
@ -42,14 +42,14 @@ import java.util.List;
import java.util.Set;
public class HaCommands implements CommandExecutor {
public final Main plugin;
public final HungerArena plugin;
public HaCommands(Main m) {
public HaCommands(HungerArena m) {
this.plugin = m;
}
int i = 0;
int a = 1;
int arena = 1;
boolean NoPlayerSpawns = true;
private void clearInv(Player p) {
@ -63,10 +63,10 @@ public class HaCommands implements CommandExecutor {
private Location getArenaSpawn() {
String[] Spawncoords;
if (plugin.spawns.getString("Spawn_coords." + a) != null) {
Spawncoords = plugin.spawns.getString("Spawn_coords." + a).split(",");
if (plugin.spawns.getString("Spawn_coordinates." + arena) != null) {
Spawncoords = plugin.spawns.getString("Spawn_coordinates." + arena).split(",");
} else {
Spawncoords = plugin.spawns.getString("Spawn_coords.0").split(",");
Spawncoords = plugin.spawns.getString("Spawn_coordinates.0").split(",");
}
double spawnx = Double.parseDouble(Spawncoords[0]);
double spawny = Double.parseDouble(Spawncoords[1]);
@ -94,14 +94,14 @@ public class HaCommands implements CommandExecutor {
for (int i : plugin.worldsNames.keySet()) {
if (plugin.worldsNames.get(i) != null) {
if (plugin.worldsNames.get(i).equals(ThisWorld)) {
a = i;
arena = i;
NoPlayerSpawns = false;
}
}
}
if (plugin.getArena(p) != null) {
a = plugin.getArena(p);
arena = plugin.getArena(p);
NoPlayerSpawns = false;
}
if (cmd.getName().equalsIgnoreCase("Ha")) {
@ -115,7 +115,7 @@ public class HaCommands implements CommandExecutor {
p.sendMessage(ChatColor.AQUA + "You have to enter the arena number as 2nd argument");
} else {
try {
a = Integer.parseInt(args[1]);
arena = Integer.parseInt(args[1]);
} catch (Exception e) {
p.sendMessage(ChatColor.RED + "Argument not an integer!");
return false;
@ -124,7 +124,7 @@ public class HaCommands implements CommandExecutor {
p.sendMessage(ChatColor.RED + "This world already has an areana! \n (only one arena per world possible, yet!)");
return false;
}
((Player) sender).performCommand("startpoint " + a);
((Player) sender).performCommand("startpoint " + arena);
}
} else {
p.sendMessage(ChatColor.RED + "You don't have permission!");
@ -137,20 +137,20 @@ public class HaCommands implements CommandExecutor {
double x = p.getLocation().getX();
double y = p.getLocation().getY();
double z = p.getLocation().getZ();
if (plugin.spawns.getString("Spawn_coords.0") == null) {
plugin.spawns.set("Spawn_coords.0", x + "," + y + "," + z + "," + ThisWorld);
if (plugin.spawns.getString("Spawn_coordinates.0") == null) {
plugin.spawns.set("Spawn_coordinates.0", x + "," + y + "," + z + "," + ThisWorld);
plugin.spawns.set("Spawns_set.0", "true");
}
if (args.length >= 2) {
try {
a = Integer.parseInt(args[1]);
arena = Integer.parseInt(args[1]);
} catch (Exception e) {
p.sendMessage(ChatColor.RED + "Argument not an integer!");
return false;
}
}
plugin.spawns.set("Spawn_coords." + a, x + "," + y + "," + z + "," + ThisWorld);
plugin.spawns.set("Spawns_set." + a, "true");
plugin.spawns.set("Spawn_coordinates." + arena, x + "," + y + "," + z + "," + ThisWorld);
plugin.spawns.set("Spawns_set." + arena, "true");
plugin.saveSpawns();
p.sendMessage(ChatColor.AQUA + "You have set the spawn for dead tributes!");
}
@ -167,15 +167,15 @@ public class HaCommands implements CommandExecutor {
double z = p.getLocation().getZ();
if (args.length >= 2) {
try {
a = Integer.parseInt(args[1]);
arena = Integer.parseInt(args[1]);
} catch (Exception e) {
p.sendMessage(ChatColor.RED + "Argument not an integer!");
return true;
}
}
plugin.spawns.set("Start_torch." + a, x + "," + y + "," + z + "," + ThisWorld);
plugin.spawns.set("Start_torch." + arena, x + "," + y + "," + z + "," + ThisWorld);
plugin.saveSpawns();
p.sendMessage(ChatColor.AQUA + "You have set the start redstone torch for arena " + a + "!");
p.sendMessage(ChatColor.AQUA + "You have set the start redstone torch for arena " + arena + "!");
}
} else {
p.sendMessage(ChatColor.RED + "You don't have permission!");
@ -184,12 +184,12 @@ public class HaCommands implements CommandExecutor {
} else if (args[0].equalsIgnoreCase("Help")) {
help_sub(sender, playr, console);
} else if (plugin.restricted && !plugin.worldsNames.containsValue(ThisWorld)) {
} else if (plugin.restrictedWorlds && !plugin.worldsNames.containsValue(ThisWorld)) {
p.sendMessage(ChatColor.RED + "That can't be run in this world!");
} else if (!plugin.restricted || plugin.restricted && plugin.worldsNames.containsValue(ThisWorld)) {
} else if (!plugin.restrictedWorlds || plugin.restrictedWorlds && plugin.worldsNames.containsValue(ThisWorld)) {
//////////////////////////////////////// LISTING ///////////////////////////////////////////////
if (args[0].equalsIgnoreCase("List")) {
if (p.hasPermission("HungerArena.GameMaker") || plugin.Watching.get(a).contains(pname) || p.hasPermission("HungerArena.List")) {
if (p.hasPermission("HungerArena.GameMaker") || plugin.Watching.get(arena).contains(pname) || p.hasPermission("HungerArena.List")) {
list_sub(p, sender, playr, console, args);
} else {
@ -215,13 +215,13 @@ public class HaCommands implements CommandExecutor {
}
if (!needconfirm) {
if ((args.length >= 2) && checkarena(args[1], sender)) {
a = Integer.parseInt(args[1]);
arena = Integer.parseInt(args[1]);
} else {
if (NoPlayerSpawns) {
for (int i : plugin.Playing.keySet()) {
if (plugin.Playing.get(i).size() < plugin.maxPlayers.get(i)) {
a = i;
p.sendMessage(ChatColor.RED + "Found free slots in Arena " + a + " !");
arena = i;
p.sendMessage(ChatColor.RED + "Found free slots in Arena " + arena + " !");
} else if (i == plugin.Playing.size()) {
p.sendMessage(ChatColor.RED + "No free slots found / All games are full!");
}
@ -229,22 +229,22 @@ public class HaCommands implements CommandExecutor {
}
}
if ((plugin.Playing.get(a) != null) && (plugin.location.get(a).size() != 0)) {
if (plugin.Playing.get(a).contains(pname)) {
if ((plugin.Playing.get(arena) != null) && (plugin.location.get(arena).size() != 0)) {
if (plugin.Playing.get(arena).contains(pname)) {
p.sendMessage(ChatColor.RED + "You are already playing!");
} else if (plugin.Dead.get(a).contains(pname) || plugin.Quit.get(a).contains(pname)) {
} else if (plugin.Dead.get(arena).contains(pname) || plugin.Quit.get(arena).contains(pname)) {
p.sendMessage(ChatColor.RED + "You DIED/QUIT! You can't join again!");
} else if (plugin.Playing.get(a).size() == plugin.maxPlayers.get(a)) {
p.sendMessage(ChatColor.RED + "There are already " + plugin.maxPlayers.get(a) + " Tributes in that Arena!");
} else if (plugin.canjoin.get(a)) {
} else if (plugin.Playing.get(arena).size() == plugin.maxPlayers.get(arena)) {
p.sendMessage(ChatColor.RED + "There are already " + plugin.maxPlayers.get(arena) + " Tributes in that Arena!");
} else if (plugin.canJoin.get(arena)) {
p.sendMessage(ChatColor.RED + "That game is in progress!");
} else if (!plugin.open.get(a)) {
} else if (!plugin.open.get(arena)) {
p.sendMessage(ChatColor.RED + "That game is closed!");
} else if ((plugin.spawns.getString("Spawns_set." + a) == null) || (plugin.spawns.getString("Spawns_set." + a).equalsIgnoreCase("false"))) {
p.sendMessage(ChatColor.RED + "/ha setspawn for Arena " + a + " hasn't been run!");
} else if ((plugin.spawns.getString("Spawns_set." + arena) == null) || (plugin.spawns.getString("Spawns_set." + arena).equalsIgnoreCase("false"))) {
p.sendMessage(ChatColor.RED + "/ha setspawn for Arena " + arena + " hasn't been run!");
} else if (plugin.getArena(p) != null) {
p.sendMessage(ChatColor.RED + "You are already in an arena!");
} else if (plugin.config.getString("Need_Confirm").equalsIgnoreCase("true")) {
} else if (plugin.config.getBoolean("Need_Confirm")) {
if (plugin.config.getBoolean("EntryFee.enabled") && plugin.config.getBoolean("EntryFee.eco")) {
if (!(plugin.econ.getBalance(p) < plugin.config.getDouble("EntryFee.cost"))) {
i = 0;
@ -253,7 +253,7 @@ public class HaCommands implements CommandExecutor {
if (p.getInventory().containsAtLeast(fee, fee.getAmount())) {
i = i + 1;
if (total == i) {
plugin.NeedConfirm.get(a).add(pname);
plugin.NeedConfirm.get(arena).add(pname);
p.sendMessage(ChatColor.GOLD + "Your inventory will be cleared! Type /ha confirm to procede");
}
}
@ -271,7 +271,7 @@ public class HaCommands implements CommandExecutor {
if (p.getInventory().containsAtLeast(fee, fee.getAmount())) {
i = i + 1;
if (total == i) {
plugin.NeedConfirm.get(a).add(pname);
plugin.NeedConfirm.get(arena).add(pname);
p.sendMessage(ChatColor.GOLD + "Your inventory will be cleared! Type /ha confirm to procede");
}
}
@ -281,13 +281,13 @@ public class HaCommands implements CommandExecutor {
}
} else if (!plugin.config.getBoolean("EntryFee.enabled") && plugin.config.getBoolean("EntryFee.eco")) {
if (!(plugin.econ.getBalance(p) < plugin.config.getDouble("EntryFee.cost"))) {
plugin.NeedConfirm.get(a).add(pname);
plugin.NeedConfirm.get(arena).add(pname);
p.sendMessage(ChatColor.GOLD + "Your inventory will be cleared! Type /ha confirm to procede");
} else {
p.sendMessage(ChatColor.RED + "You don't have enough money to join!");
}
} else {
plugin.NeedConfirm.get(a).add(pname);
plugin.NeedConfirm.get(arena).add(pname);
p.sendMessage(ChatColor.GOLD + "Your inventory will be cleared! Type /ha confirm to procede");
}
} else if (plugin.config.getString("Need_Confirm").equalsIgnoreCase("false")) {
@ -306,34 +306,34 @@ public class HaCommands implements CommandExecutor {
} else if (args[0].equalsIgnoreCase("Confirm")) {
for (int v : plugin.NeedConfirm.keySet()) {
if (plugin.NeedConfirm.get(v).contains(pname)) {
a = v;
arena = v;
confirmSub(p, pname, ThisWorld);
} else if ((v == plugin.NeedConfirm.size()) && (plugin.config.getString("Need_Confirm").equalsIgnoreCase("true"))) {
} else if ((v == plugin.NeedConfirm.size()) && (plugin.config.getBoolean("Need_Confirm"))) {
p.sendMessage(ChatColor.RED + "You haven't joined any games!");
}
}
} else if (args[0].equalsIgnoreCase("Ready")) {
if (plugin.getArena(p) != null) {
a = plugin.getArena(p);
if (plugin.Playing.get(a).contains(pname)) {
if (plugin.Ready.get(a).contains(pname)) {
arena = plugin.getArena(p);
if (plugin.Playing.get(arena).contains(pname)) {
if (plugin.Ready.get(arena).contains(pname)) {
p.sendMessage(ChatColor.RED + "You're already ready!");
} else if (plugin.Playing.get(a).size() == 1) {
} else if (plugin.Playing.get(arena).size() == 1) {
p.sendMessage(ChatColor.RED + "You can't be ready when no one else is playing!");
} else {
plugin.Ready.get(a).add(pname);
plugin.Ready.get(arena).add(pname);
if (plugin.config.getBoolean("broadcastAll")) {
plugin.getServer().broadcastMessage(ChatColor.AQUA + "[HungerArena] Game " + a + ": " + ChatColor.GRAY + plugin.Ready.get(a).size() + "/" + plugin.maxPlayers.get(a) + " Players ready!");
plugin.getServer().broadcastMessage(ChatColor.AQUA + "[HungerArena] Game " + arena + ": " + ChatColor.GRAY + plugin.Ready.get(arena).size() + "/" + plugin.maxPlayers.get(arena) + " Players ready!");
} else {
for (String gn : plugin.Playing.get(a)) {
for (String gn : plugin.Playing.get(arena)) {
Player g = plugin.getServer().getPlayer(gn);
g.sendMessage(ChatColor.GRAY + String.valueOf(plugin.Ready.get(a).size()) + "/" + plugin.maxPlayers.get(a) + " Players ready!");
g.sendMessage(ChatColor.GRAY + String.valueOf(plugin.Ready.get(arena).size()) + "/" + plugin.maxPlayers.get(arena) + " Players ready!");
}
}
p.sendMessage(ChatColor.AQUA + "You have marked yourself as READY!");
if (plugin.config.getBoolean("Auto_Warp")) {
if (((double) plugin.Playing.get(a).size()) % 60 <= plugin.Ready.get(a).size() || plugin.Playing.get(a).size() == plugin.Ready.get(a).size()) {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha warpall " + a);
if (((double) plugin.Playing.get(arena).size()) % 60 <= plugin.Ready.get(arena).size() || plugin.Playing.get(arena).size() == plugin.Ready.get(arena).size()) {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha warpall " + arena);
}
}
}
@ -343,17 +343,17 @@ public class HaCommands implements CommandExecutor {
}
} else if (args[0].equalsIgnoreCase("Leave")) {
if (plugin.getArena(p) != null) {
a = plugin.getArena(p);
if (plugin.canjoin.get(a)) {
arena = plugin.getArena(p);
if (plugin.canJoin.get(arena)) {
clearInv(p);
p.teleport(getArenaSpawn());
plugin.Frozen.get(a).remove(pname);
plugin.Frozen.get(arena).remove(pname);
if (plugin.Playing.get(a).size() != 1) {
if (plugin.Playing.get(arena).size() != 1) {
plugin.RestoreInv(p, pname);
}
plugin.winner(a);
plugin.winner(arena);
} else {
clearInv(p);
p.teleport(getArenaSpawn());
@ -386,10 +386,10 @@ public class HaCommands implements CommandExecutor {
if (sender.hasPermission("HungerArena.Watch")) {
if (args.length >= 2) {
if (checkarena(args[1], sender)) {
a = Integer.parseInt(args[1]);
if (!plugin.Watching.get(a).contains(pname) && plugin.getArena(p) == null && plugin.canjoin.get(a)) {
plugin.Watching.get(a).add(pname);
p.teleport(Bukkit.getPlayer(plugin.Playing.get(a).get(0)));
arena = Integer.parseInt(args[1]);
if (!plugin.Watching.get(arena).contains(pname) && plugin.getArena(p) == null && plugin.canJoin.get(arena)) {
plugin.Watching.get(arena).add(pname);
p.teleport(Bukkit.getPlayer(plugin.Playing.get(arena).get(0)));
for (Player online : plugin.getServer().getOnlinePlayers()) {
online.hidePlayer(plugin, p);
}
@ -410,12 +410,12 @@ public class HaCommands implements CommandExecutor {
sobj.setDisplaySlot(DisplaySlot.SIDEBAR);
p.setScoreboard(scoreboard);
plugin.scoreboards.put(p.getName(), p.getScoreboard());
} else if (!plugin.canjoin.get(a)) {
} else if (!plugin.canJoin.get(arena)) {
p.sendMessage(ChatColor.RED + "That game isn't in progress!");
} else if (plugin.Playing.get(a).contains(pname)) {
} else if (plugin.Playing.get(arena).contains(pname)) {
p.sendMessage(ChatColor.RED + "You can't watch while you're playing!");
} else if (plugin.Watching.get(a).contains(pname)) {
plugin.Watching.get(a).remove(pname);
} else if (plugin.Watching.get(arena).contains(pname)) {
plugin.Watching.get(arena).remove(pname);
for (Player online : plugin.getServer().getOnlinePlayers()) {
online.showPlayer(plugin, p);
}
@ -635,24 +635,24 @@ public class HaCommands implements CommandExecutor {
private void list_sub(Player p, CommandSender sender, boolean playr, boolean console, String[] args) {
if (args.length >= 2) {
if (checkarena(args[1], sender)) {
a = Integer.parseInt(args[1]);
arena = Integer.parseInt(args[1]);
list_subsub(p, sender, console);
}
} else {
if (console || (p != null && plugin.getArena(p) == null)) {
a = 1;
arena = 1;
list_subsub(p, sender, console);
} else {
a = plugin.getArena(p);
arena = plugin.getArena(p);
list_subsub(p, sender, console);
}
}
}
private void list_subsub(Player p, CommandSender sender, boolean console) {
sender.sendMessage(ChatColor.AQUA + "----- Arena " + a + " -----");
if (!plugin.Playing.get(a).isEmpty() && plugin.Playing.containsKey(a)) {
for (String playernames : plugin.Playing.get(a)) {
sender.sendMessage(ChatColor.AQUA + "----- Arena " + arena + " -----");
if (!plugin.Playing.get(arena).isEmpty() && plugin.Playing.containsKey(arena)) {
for (String playernames : plugin.Playing.get(arena)) {
Player players = plugin.getServer().getPlayerExact(playernames);
if (console || (p != null && p.hasPermission("HungerArena.GameMaker"))) {
double maxh;
@ -675,10 +675,10 @@ public class HaCommands implements CommandExecutor {
private void rList_sub(CommandSender sender, String[] args) {
if (args.length >= 2) {
if (checkarena(args[1], sender)) {
a = Integer.parseInt(args[1]);
sender.sendMessage(ChatColor.AQUA + "----- Arena " + a + " -----");
if (!plugin.Ready.get(a).isEmpty() && plugin.Ready.containsKey(a)) {
for (String playernames : plugin.Ready.get(a)) {
arena = Integer.parseInt(args[1]);
sender.sendMessage(ChatColor.AQUA + "----- Arena " + arena + " -----");
if (!plugin.Ready.get(arena).isEmpty() && plugin.Ready.containsKey(arena)) {
for (String playernames : plugin.Ready.get(arena)) {
sender.sendMessage(ChatColor.GREEN + playernames);
}
} else {
@ -711,21 +711,21 @@ public class HaCommands implements CommandExecutor {
}
if (console || (playr && sender.hasPermission("HungerArena.Kick"))) {
if (plugin.getArena(target) != null) {
a = plugin.getArena(target);
plugin.Playing.get(a).remove(target.getName());
arena = plugin.getArena(target);
plugin.Playing.get(arena).remove(target.getName());
if (!plugin.config.getBoolean("broadcastAll")) {
plugin.getServer().broadcastMessage(ChatColor.RED + target.getName() + " was kicked from arena " + a + "!");
plugin.getServer().broadcastMessage(ChatColor.RED + target.getName() + " was kicked from arena " + arena + "!");
} else {
for (String gn : plugin.Playing.get(a)) {
for (String gn : plugin.Playing.get(arena)) {
Player g = plugin.getServer().getPlayer(gn);
g.sendMessage(ChatColor.RED + target.getName() + " was kicked from the game!");
}
}
clearInv(target);
target.teleport(Spawn);
plugin.Quit.get(a).add(target.getName());
plugin.Quit.get(arena).add(target.getName());
plugin.RestoreInv(target, target.getName());
plugin.winner(a);
plugin.winner(arena);
return true;
} else {
sender.sendMessage(ChatColor.RED + "That player isn't in the game!");
@ -860,7 +860,7 @@ public class HaCommands implements CommandExecutor {
if (closeit) {
plugin.open.put(a, false);
} else {
plugin.canjoin.put(a, false);
plugin.canJoin.put(a, false);
plugin.open.put(a, true);
}
@ -1001,7 +1001,7 @@ public class HaCommands implements CommandExecutor {
private void reload_sub(CommandSender sender) {
for (Player online : plugin.getServer().getOnlinePlayers()) {
if (plugin.getArena(online) != null) {
a = plugin.getArena(online);
arena = plugin.getArena(online);
plugin.RestoreInv(online, online.getName());
online.teleport(getArenaSpawn());
}
@ -1030,31 +1030,31 @@ public class HaCommands implements CommandExecutor {
} else {
if (args.length >= 2) {
if (checkarena(args[1], sender)) {
a = Integer.parseInt(args[1]);
if ((plugin.spawns.getString("Spawns_set." + a) == null) || (plugin.spawns.getString("Spawns_set." + a).equalsIgnoreCase("false"))) {
sender.sendMessage(ChatColor.RED + "/ha setspawn for Arena " + a + " hasn't been run!");
arena = Integer.parseInt(args[1]);
if ((plugin.spawns.getString("Spawns_set." + arena) == null) || (plugin.spawns.getString("Spawns_set." + arena).equalsIgnoreCase("false"))) {
sender.sendMessage(ChatColor.RED + "/ha setspawn for Arena " + arena + " hasn't been run!");
} else {
if (plugin.Playing.get(a).size() <= 1) {
if (plugin.Playing.get(arena).size() <= 1) {
sender.sendMessage(ChatColor.RED + "There are not enough players!");
} else if (plugin.canjoin.get(a)) {
} else if (plugin.canJoin.get(arena)) {
sender.sendMessage(ChatColor.RED + "Game already in progress!");
} else {
plugin.setTorch(a, false);
plugin.setTorch(arena, false);
if (plugin.config.getString("Auto_Start").equalsIgnoreCase("true")) {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha start " + a), 20L);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha start " + arena), 20L);
}
List<Integer> shuffle = new ArrayList<>();
for (i = 1; i <= plugin.location.get(a).size(); shuffle.add(i++)) {
for (i = 1; i <= plugin.location.get(arena).size(); shuffle.add(i++)) {
}
Collections.shuffle(shuffle);
i = 1;
for (String playing : plugin.Playing.get(a)) {
for (String playing : plugin.Playing.get(arena)) {
Player tribute = plugin.getServer().getPlayerExact(playing);
plugin.Frozen.get(a).add(tribute.getName());
Location toLoc = plugin.location.get(a).get(shuffle.get(i));
plugin.Frozen.get(arena).add(tribute.getName());
Location toLoc = plugin.location.get(arena).get(shuffle.get(i));
tribute.setHealth(20);
tribute.setFoodLevel(20);
tribute.setSaturation(20);
@ -1070,7 +1070,7 @@ public class HaCommands implements CommandExecutor {
Location opposite = toLoc.clone();
double dist = 0;
double dist2;
for (Location loc : plugin.location.get(a).values()) {
for (Location loc : plugin.location.get(arena).values()) {
dist2 = loc.distance(toLoc);
if (dist2 > dist) {
dist = dist2;
@ -1085,7 +1085,7 @@ public class HaCommands implements CommandExecutor {
}
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
sender.sendMessage(ChatColor.AQUA + "All Tributes warped!");
plugin.MatchRunning.put(a, "warped");
plugin.MatchRunning.put(arena, "warped");
}, 10L);
}
}
@ -1101,15 +1101,15 @@ public class HaCommands implements CommandExecutor {
sender.sendMessage(ChatColor.RED + "You need to specify the arena to start!");
} else {
if (checkarena(args[1], sender)) {
a = Integer.parseInt(args[1]);
if (plugin.canjoin.get(a)) {
arena = Integer.parseInt(args[1]);
if (plugin.canJoin.get(arena)) {
sender.sendMessage(ChatColor.RED + "Game already in progress!");
} else if (plugin.Playing.get(a).size() == 1) {
} else if (plugin.Playing.get(arena).size() == 1) {
sender.sendMessage(ChatColor.RED + "There are not enough players!");
} else if (plugin.Playing.get(a).isEmpty()) {
} else if (plugin.Playing.get(arena).isEmpty()) {
sender.sendMessage(ChatColor.RED + "No one is in that game!");
} else if ((plugin.MatchRunning.get(a) != null) && (plugin.MatchRunning.get(a).equals("warped"))) {
plugin.startGames(a);
} else if ((plugin.MatchRunning.get(arena) != null) && (plugin.MatchRunning.get(arena).equals("warped"))) {
plugin.startGames(arena);
} else {
sender.sendMessage(ChatColor.RED + "First all players must be warped!");
}
@ -1118,15 +1118,15 @@ public class HaCommands implements CommandExecutor {
}
private boolean checkarena(String Int, CommandSender sender) {
a = 0;
arena = 0;
try {
a = Integer.parseInt(Int);
arena = Integer.parseInt(Int);
} catch (NumberFormatException e) {
sender.sendMessage(ChatColor.RED + "You have to enter the Arena number!");
return false;
}
if (a > 0) {
if (plugin.canjoin.containsKey(a)) {
if (arena > 0) {
if (plugin.canJoin.containsKey(arena)) {
return true;
}
}
@ -1182,8 +1182,8 @@ public class HaCommands implements CommandExecutor {
}
private void preparePlayer(Player p, String pname, String ThisWorld) {
plugin.Playing.get(a).add(pname);
plugin.NeedConfirm.get(a).remove(pname);
plugin.Playing.get(arena).add(pname);
plugin.NeedConfirm.get(arena).remove(pname);
p.sendMessage(ChatColor.GREEN + "Do /ha ready to vote to start the games!");
FileConfiguration pinfo = plugin.getPConfig(pname);
pinfo.set("inv", p.getInventory().getContents());
@ -1194,15 +1194,15 @@ public class HaCommands implements CommandExecutor {
clearInv(p);
plugin.needInv.add(pname);
if (plugin.config.getBoolean("broadcastAll")) {
plugin.getServer().broadcastMessage(ChatColor.AQUA + pname + " has Joined Arena " + a + "! " + ChatColor.GRAY + plugin.Playing.get(a).size() + "/" + plugin.maxPlayers.get(a));
plugin.getServer().broadcastMessage(ChatColor.AQUA + pname + " has Joined Arena " + arena + "! " + ChatColor.GRAY + plugin.Playing.get(arena).size() + "/" + plugin.maxPlayers.get(arena));
} else {
for (String gn : plugin.Playing.get(a)) {
for (String gn : plugin.Playing.get(arena)) {
Player g = plugin.getServer().getPlayer(gn);
g.sendMessage(ChatColor.AQUA + pname + " has Joined the Game! " + ChatColor.GRAY + plugin.Playing.get(a).size() + "/" + plugin.maxPlayers.get(a));
g.sendMessage(ChatColor.AQUA + pname + " has Joined the Game! " + ChatColor.GRAY + plugin.Playing.get(arena).size() + "/" + plugin.maxPlayers.get(arena));
}
}
if (plugin.Playing.get(a).size() == plugin.maxPlayers.get(a)) {
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "ha warpall " + a);
if (plugin.Playing.get(arena).size() == plugin.maxPlayers.get(arena)) {
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "ha warpall " + arena);
}
}
}

View File

@ -1,20 +1,20 @@
package me.Travja.HungerArena;
package net.knarcraft.hungerarena;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import me.Travja.HungerArena.Listeners.BlockStorage;
import me.Travja.HungerArena.Listeners.Boundaries;
import me.Travja.HungerArena.Listeners.ChatListener;
import me.Travja.HungerArena.Listeners.DeathListener;
import me.Travja.HungerArena.Listeners.FreezeListener;
import me.Travja.HungerArena.Listeners.JoinAndQuitListener;
import me.Travja.HungerArena.Listeners.PvP;
import me.Travja.HungerArena.Listeners.SignsAndBeds;
import me.Travja.HungerArena.Listeners.SignsAndBedsOld;
import me.Travja.HungerArena.Listeners.SpectatorListener;
import me.Travja.HungerArena.Listeners.SpectatorListenerOld;
import me.Travja.HungerArena.Listeners.TeleportListener;
import me.Travja.HungerArena.Listeners.WorldChange;
import me.Travja.HungerArena.Listeners.spawnsListener;
import net.knarcraft.hungerarena.Listeners.BlockStorage;
import net.knarcraft.hungerarena.Listeners.Boundaries;
import net.knarcraft.hungerarena.Listeners.ChatListener;
import net.knarcraft.hungerarena.Listeners.DeathListener;
import net.knarcraft.hungerarena.Listeners.FreezeListener;
import net.knarcraft.hungerarena.Listeners.JoinAndQuitListener;
import net.knarcraft.hungerarena.Listeners.PvP;
import net.knarcraft.hungerarena.Listeners.SignsAndBeds;
import net.knarcraft.hungerarena.Listeners.SignsAndBedsOld;
import net.knarcraft.hungerarena.Listeners.SpectatorListener;
import net.knarcraft.hungerarena.Listeners.SpectatorListenerOld;
import net.knarcraft.hungerarena.Listeners.TeleportListener;
import net.knarcraft.hungerarena.Listeners.WorldChange;
import net.knarcraft.hungerarena.Listeners.spawnsListener;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -63,13 +63,14 @@ import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Main extends JavaPlugin {
public class HungerArena extends JavaPlugin {
static Logger log;
public final HashMap<Integer, List<String>> Playing = new HashMap<>();
public final HashMap<Integer, List<String>> Ready = new HashMap<>();
public final HashMap<Integer, List<String>> Dead = new HashMap<>();
public final HashMap<Integer, 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<>();
private final HashMap<Integer, Integer> CountT = new HashMap<>();
public final HashMap<Integer, List<String>> Quit = new HashMap<>();
@ -80,13 +81,13 @@ public class Main extends JavaPlugin {
public final HashMap<Integer, HashMap<Integer, Location>> location = new HashMap<>();
public final HashMap<Integer, List<String>> inArena = new HashMap<>();
public final HashMap<Integer, List<String>> Frozen = new HashMap<>();
public final HashMap<Integer, List<String>> arena = new HashMap<>();
public final HashMap<Integer, Integer> maxPlayers = new HashMap<>();
public final HashMap<String, String> setting = new HashMap<>();
public final HashMap<Integer, Integer> gp = new HashMap<>();
public final ArrayList<Player> Tele = new ArrayList<>();
public final ArrayList<String> needInv = new ArrayList<>();
public final HashMap<Integer, String> worldsNames = new HashMap<>();
public final Map<Integer, Arena> arenas = new HashMap<>();
public final HashMap<String, Scoreboard> scoreboards = new HashMap<>();
@ -112,7 +113,7 @@ public class Main extends JavaPlugin {
final CommandExecutor SpawnsCommand = new SpawnsCommand(this);
public boolean exists;
public boolean restricted;
public boolean restrictedWorlds;
public FileConfiguration config;
public FileConfiguration spawns = null;
@ -208,7 +209,7 @@ public class Main extends JavaPlugin {
i = 1;
this.reloadSpawnpoints(true);
this.reloadSpawnPoints(true);
if (setupEconomy()) {
log.info("Found Vault! Hooking in for economy!");
@ -301,7 +302,7 @@ public class Main extends JavaPlugin {
}
} catch (Exception e) {
}
restricted = config.getBoolean("Restricted");
restrictedWorlds = config.getBoolean("Restricted");
saveConfig();
scoreboardInit();
log.info("Enabled v" + getDescription().getVersion());
@ -345,23 +346,21 @@ public class Main extends JavaPlugin {
log.info("Disabled v" + getDescription().getVersion());
}
public void reloadSpawnpoints(boolean verbose) {
public void reloadSpawnPoints(boolean verbose) {
if (spawns.getConfigurationSection("Spawns") != null) {
Map<String, Object> temp = spawns.getConfigurationSection("Spawns").getValues(false);
for (Entry<String, Object> entry : temp.entrySet()) {
if (spawns.getConfigurationSection("Spawns." + entry.getKey()) != null) {
Integer a = Integer.parseInt(entry.getKey());
worldsNames.put(a, "none_meening_this_is_not_a_map");
worldsNames.put(a, "none_meaning_this_is_not_a_map");
location.computeIfAbsent(a, k -> new HashMap<>());
Map<String, Object> temp2 = spawns.getConfigurationSection("Spawns." + entry.getKey()).getValues(false);
for (Map.Entry<String, Object> e : temp2.entrySet()) {
if (spawns.get("Spawns." + entry.getKey() + "" + e.getKey()) != null) {
if (!e.getKey().equals("Max") || !e.getKey().equals("Min")) {
String[] coords = ((String) spawns.get("Spawns." + entry.getKey() + "" + e.getKey())).split(",");
Integer s = Integer.parseInt(e.getKey());
location.get(a).put(s, new Location(getServer().getWorld(coords[0]), Double.parseDouble(coords[1]), Double.parseDouble(coords[2]), Double.parseDouble(coords[3])));
worldsNames.put(a, coords[0]);
}
String[] coords = ((String) spawns.get("Spawns." + entry.getKey() + "" + e.getKey())).split(",");
Integer s = Integer.parseInt(e.getKey());
location.get(a).put(s, new Location(getServer().getWorld(coords[0]), Double.parseDouble(coords[1]), Double.parseDouble(coords[2]), Double.parseDouble(coords[3])));
worldsNames.put(a, coords[0]);
}
}
}
@ -383,8 +382,7 @@ public class Main extends JavaPlugin {
NeedConfirm.put(i, new ArrayList<>());
inArena.put(i, new ArrayList<>());
Frozen.put(i, new ArrayList<>());
arena.put(i, new ArrayList<>());
canjoin.put(i, false);
canJoin.put(i, false);
maxPlayers.put(i, location.get(i).size());
open.put(i, true);
}
@ -411,7 +409,7 @@ public class Main extends JavaPlugin {
}
econ = rsp.getProvider();
vault = true;
return econ != null;
return true;
}
public void reloadSpawns() {
@ -424,33 +422,37 @@ public class Main extends JavaPlugin {
spawns = YamlConfiguration.loadConfiguration(spawnsFile);
InputStream defConfigStream = this.getResource("spawns.yml");
if (defConfigStream != null) {
YamlConfiguration defConfig = loadConfigStream(defConfigStream);
if (defConfig != null) {
spawns.addDefaults(defConfig);
spawns.options().copyHeader(true);
InputStream defaultSpawnsConfigStream = this.getResource("spawns.yml");
if (defaultSpawnsConfigStream != null) {
YamlConfiguration defaultSpawnsConfig = loadConfigStream(defaultSpawnsConfigStream);
if (defaultSpawnsConfig != null) {
spawns.addDefaults(defaultSpawnsConfig);
spawns.options().copyDefaults(true);
saveSpawns();
}
}
if (spawns.getString("Spawns_set") != null && (spawns.getString("Spawns_set").equalsIgnoreCase("false") || spawns.getString("Spawns_set").equalsIgnoreCase("true"))) {
String temp = spawns.getString("Spawns_set");
String spawnsSet = spawns.getString("Spawns_set");
if (spawnsSet != null && (spawnsSet.equalsIgnoreCase("false") ||
spawnsSet.equalsIgnoreCase("true"))) {
//Move the spawns_set value to spawns_set.0, and unset Spawns_set
spawns.set("Spawns_set", null);
spawns.set("Spawns_set.0", temp);
temp = spawns.getString("Spawn_coords");
spawns.set("Spawn_coords", null);
spawns.set("Spawn_coords.0", temp);
spawns.set("Spawns_set.0", spawnsSet);
String spawnCoordinatesValue = spawns.getString("Spawn_coordinates");
spawns.set("Spawn_coordinates", null);
spawns.set("Spawn_coordinates.0", spawnCoordinatesValue);
if (spawns.getConfigurationSection("Spawns") != null) {
Set<String> temp2 = spawns.getConfigurationSection("Spawns").getValues(false).keySet();
for (String entry : temp2) {
Set<String> spawnConfigKeys = spawns.getConfigurationSection("Spawns").getValues(false).keySet();
for (String entry : spawnConfigKeys) {
if (spawns.getString("Spawns_set_" + entry) != null) {
spawns.set("Spawns_set." + entry, spawns.getString("Spawns_set_" + entry));
spawns.set("Spawns_set_" + entry, null);
}
if (spawns.getString("Spawn_coords_" + entry) != null) {
spawns.set("Spawn_coords." + entry, spawns.getString("Spawn_coords_" + entry));
spawns.set("Spawn_coords_" + entry, null);
if (spawns.getString("Spawn_coordinates_" + entry) != null) {
spawns.set("Spawn_coordinates." + entry, spawns.getString("Spawn_coordinates_" + entry));
spawns.set("Spawn_coordinates_" + entry, null);
}
}
}
@ -486,12 +488,11 @@ public class Main extends JavaPlugin {
data = YamlConfiguration.loadConfiguration(dataFile);
InputStream defConfigStream = this.getResource("Data.yml");
if (defConfigStream != null) {
YamlConfiguration defConfig = loadConfigStream(defConfigStream);
if (defConfig != null) {
data.addDefaults(defConfig);
data.options().copyHeader(true);
InputStream defaultConfigStream = this.getResource("Data.yml");
if (defaultConfigStream != null) {
YamlConfiguration defaultConfig = loadConfigStream(defaultConfigStream);
if (defaultConfig != null) {
data.addDefaults(defaultConfig);
data.options().copyDefaults(true);
saveData();
}
@ -526,11 +527,11 @@ public class Main extends JavaPlugin {
management = YamlConfiguration.loadConfiguration(managementFile);
InputStream defConfigStream = this.getResource("commandAndBlockManagement.yml");
if (defConfigStream != null) {
YamlConfiguration defConfig = loadConfigStream(defConfigStream);
if (defConfig != null) {
management.addDefaults(defConfig);
InputStream defaultConfigStream = this.getResource("commandAndBlockManagement.yml");
if (defaultConfigStream != null) {
YamlConfiguration defaultConfig = loadConfigStream(defaultConfigStream);
if (defaultConfig != null) {
management.addDefaults(defaultConfig);
management.options().copyHeader(true);
management.options().copyDefaults(true);
saveManagement();
@ -589,24 +590,24 @@ public class Main extends JavaPlugin {
PFile = new File(PFilePath, pname + ".yml");
}
PConfig = YamlConfiguration.loadConfiguration(PFile);
InputStream defConfigStream = this.getResource("Player.yml");
if (defConfigStream != null) {
YamlConfiguration defConfig = loadConfigStream(defConfigStream);
if (defConfig != null) {
this.PConfig.setDefaults(defConfig);
InputStream defaultConfigStream = this.getResource("Player.yml");
if (defaultConfigStream != null) {
YamlConfiguration defaultConfig = loadConfigStream(defaultConfigStream);
if (defaultConfig != null) {
this.PConfig.setDefaults(defaultConfig);
}
}
}
private YamlConfiguration loadConfigStream(InputStream defConfigStream) {
private YamlConfiguration loadConfigStream(InputStream defaultConfigStream) {
Reader defaultConfigReader = null;
YamlConfiguration defConfig = null;
if (defConfigStream != null) {
defaultConfigReader = new java.io.InputStreamReader(defConfigStream, StandardCharsets.UTF_8);
YamlConfiguration defaultConfig = null;
if (defaultConfigStream != null) {
defaultConfigReader = new java.io.InputStreamReader(defaultConfigStream, StandardCharsets.UTF_8);
}
if (defaultConfigReader != null) {
defConfig = YamlConfiguration.loadConfiguration(defaultConfigReader);
defaultConfig = YamlConfiguration.loadConfiguration(defaultConfigReader);
} else {
log.warning("A default resource in the plugin jar could not be read.");
}
@ -617,7 +618,7 @@ public class Main extends JavaPlugin {
} catch (IOException e) {
log.warning("An error occured while trying to close the resource file.");
}
return defConfig;
return defaultConfig;
}
public FileConfiguration getPConfig(String pname) {
@ -653,7 +654,7 @@ public class Main extends JavaPlugin {
g.sendMessage(ChatColor.RED + pname + " Quit!");
}
}
if (canjoin.get(u)) {
if (canJoin.get(u)) {
p.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
scoreboards.remove(p.getName());
Kills.remove(p.getName());
@ -711,10 +712,10 @@ public class Main extends JavaPlugin {
public void winner(final Integer a) {
if (Playing.get(a).size() == 1) {
String[] Spawncoords;
if (spawns.getString("Spawn_coords." + a) != null) {
Spawncoords = spawns.getString("Spawn_coords." + a).split(",");
if (spawns.getString("Spawn_coordinates." + a) != null) {
Spawncoords = spawns.getString("Spawn_coordinates." + a).split(",");
} else {
Spawncoords = spawns.getString("Spawn_coords.0").split(",");
Spawncoords = spawns.getString("Spawn_coordinates.0").split(",");
}
World spawnw = getServer().getWorld(Spawncoords[3]);
double spawnx = Double.parseDouble(Spawncoords[0]);
@ -726,7 +727,7 @@ public class Main extends JavaPlugin {
String winnername = Playing.get(a).get(i);
final Player winner = getServer().getPlayerExact(winnername);
String winnername2 = winner.getName();
if (canjoin.get(a)) {
if (canJoin.get(a)) {
getServer().broadcastMessage(ChatColor.GREEN + winnername2 + " is the victor of this Hunger Games!");
}
winner.getInventory().clear();
@ -746,7 +747,7 @@ public class Main extends JavaPlugin {
this.RestoreInv(winner, winnername2);
if (canjoin.get(a)) {
if (canJoin.get(a)) {
winner.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
scoreboards.remove(winner.getName());
Kills.remove(winner.getName());
@ -848,7 +849,7 @@ public class Main extends JavaPlugin {
online.showPlayer(this, spectator);
}
}
if (config.getString("Auto_Restart").equalsIgnoreCase("True")) {
if (config.getBoolean("Auto_Restart")) {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, () -> Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "ha restart " + a), 220L);
}
MatchRunning.put(a, null);
@ -988,7 +989,7 @@ public class Main extends JavaPlugin {
CountT.put(a, (config.getInt("Countdown_Timer") != 0 ? config.getInt("Countdown_Timer") : 10));
start.put(a, getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
if (CountT.get(a) > 0) {
if (!restricted) {
if (!restrictedWorlds) {
if (config.getBoolean("broadcastAll")) {
getServer().broadcastMessage(ChatColor.AQUA + "Game " + a + " starting in: " + CountT.get(a));
} else {
@ -1156,7 +1157,7 @@ public class Main extends JavaPlugin {
}
}
}
canjoin.put(a, true);
canJoin.put(a, true);
}
private void StopTasksDelayed(final int task) {

View File

@ -1,11 +1,10 @@
package me.Travja.HungerArena.Listeners;
package net.knarcraft.hungerarena.Listeners;
import me.Travja.HungerArena.Main;
import net.knarcraft.hungerarena.HungerArena;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
@ -19,14 +18,13 @@ import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.material.MaterialData;
import java.util.List;
public class BlockStorage implements Listener {
public final Main plugin;
public final HungerArena plugin;
public BlockStorage(Main m) {
public BlockStorage(HungerArena m) {
this.plugin = m;
}
@ -35,14 +33,14 @@ public class BlockStorage implements Listener {
Block b = event.getBlock();
Player p = event.getPlayer();
String pname = p.getName();
boolean protall = false;
boolean alwaysProtect = false;
if (!p.hasPermission("HungerArena.arena")) {
protall = protall(); //true = protect allways!!
alwaysProtect = alwaysProtect();
}
if ((plugin.getArena(p) != null) || (protall)) {
//Jeppa: get a default arena if protall is true... (but use getArena if set...)
if ((plugin.getArena(p) != null) || (alwaysProtect)) {
//Jeppa: get a default arena if always protect is true... (but use getArena if set...)
int a = 1;
if (protall) {
if (alwaysProtect) {
String ThisWorld = p.getWorld().getName();
for (int z : plugin.worldsNames.keySet()) {
if (plugin.worldsNames.get(z) != null) {
@ -55,11 +53,11 @@ public class BlockStorage implements Listener {
if (plugin.getArena(p) != null) {
a = plugin.getArena(p);
}
if ((!event.isCancelled()) && (((plugin.Playing.get(a)).contains(pname)) || (protall))) {
if (plugin.config.getString("Protected_Arena").equalsIgnoreCase("True")) {
if ((!event.isCancelled()) && (((plugin.Playing.get(a)).contains(pname)) || (alwaysProtect))) {
if (plugin.config.getBoolean("Protected_Arena")) {
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "You can't break blocks while playing!");
} else if ((plugin.canjoin.get(a) || protall) && ((!plugin.restricted) || ((plugin.restricted) && (plugin.worldsNames.containsValue(p.getWorld().getName()))))) {
} else if ((plugin.canJoin.get(a) || alwaysProtect) && ((!plugin.restrictedWorlds) || ((plugin.restrictedWorlds) && (plugin.worldsNames.containsValue(p.getWorld().getName()))))) {
if (((plugin.management.getStringList("blocks.whitelist").isEmpty()) || ((!plugin.management.getStringList("blocks.whitelist").isEmpty()) && (!plugin.management.getStringList("blocks.whitelist").contains(b.getType().name())))) ^ (plugin.management.getBoolean("blocks.useWhitelistAsBlacklist"))) {
event.setCancelled(true);
p.sendMessage(ChatColor.RED + "That is an illegal block!");
@ -77,10 +75,10 @@ public class BlockStorage implements Listener {
List<Block> blocksd = event.blockList();
Entity e = event.getEntity();
if (!event.isCancelled()) {
for (int i : plugin.canjoin.keySet()) {
if (plugin.canjoin.get(i) || protall()) {
for (int i : plugin.canJoin.keySet()) {
if (plugin.canJoin.get(i) || alwaysProtect()) {
String ThisWorld = e.getWorld().getName();
if ((!plugin.restricted) || ((plugin.restricted) && plugin.worldsNames.get(i) != null && plugin.worldsNames.get(i).equalsIgnoreCase(ThisWorld))) {
if ((!plugin.restrictedWorlds) || ((plugin.restrictedWorlds) && plugin.worldsNames.get(i) != null && plugin.worldsNames.get(i).equalsIgnoreCase(ThisWorld))) {
if (e.getType() == EntityType.PRIMED_TNT) {
e.getLocation().getBlock().setType(Material.TNT);
Block TNT = e.getLocation().getBlock();
@ -102,9 +100,9 @@ public class BlockStorage implements Listener {
public void burningBlocks(BlockBurnEvent event) {
Block b = event.getBlock();
if (!event.isCancelled()) {
for (int i : plugin.canjoin.keySet()) {
if (plugin.canjoin.get(i) || protall()) {
if ((!plugin.restricted) || ((plugin.restricted) && (plugin.worldsNames.get(i) != null && plugin.worldsNames.get(i).equalsIgnoreCase(b.getWorld().getName())))) {
for (int i : plugin.canJoin.keySet()) {
if (plugin.canJoin.get(i) || alwaysProtect()) {
if ((!plugin.restrictedWorlds) || ((plugin.restrictedWorlds) && (plugin.worldsNames.get(i) != null && plugin.worldsNames.get(i).equalsIgnoreCase(b.getWorld().getName())))) {
String w = b.getWorld().getName();
addDestroyedBlockToList(b, w, i);
}
@ -119,7 +117,7 @@ public class BlockStorage implements Listener {
Player p = event.getPlayer();
boolean protall = false;
if (!p.hasPermission("HungerArena.arena")) {
protall = protall();
protall = alwaysProtect();
}
if ((plugin.getArena(p) != null) || (protall)) {
int a = 1;
@ -138,8 +136,8 @@ public class BlockStorage implements Listener {
}
if (!event.isCancelled()) {
if (((plugin.Playing.get(a)).contains(p.getName())) || (protall)) {
if ((plugin.canjoin.get(a)) || (protall)) {
if ((!plugin.restricted) || ((plugin.restricted) && (plugin.worldsNames.containsValue(b.getWorld().getName())))) {
if ((plugin.canJoin.get(a)) || (protall)) {
if ((!plugin.restrictedWorlds) || ((plugin.restrictedWorlds) && (plugin.worldsNames.containsValue(b.getWorld().getName())))) {
if ((b.getType() == Material.SAND || b.getType() == Material.GRAVEL) && (b.getRelative(BlockFace.DOWN).getType() == Material.AIR || b.getRelative(BlockFace.DOWN).getType() == Material.WATER || b.getRelative(BlockFace.DOWN).getType() == Material.LAVA)) {
int n = b.getY() - 1;
while (b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType() == Material.AIR || b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType() == Material.WATER || b.getWorld().getBlockAt(b.getX(), n, b.getZ()).getType() == Material.LAVA) {
@ -172,9 +170,9 @@ public class BlockStorage implements Listener {
if (plugin.getArena(event.getPlayer()) != null) {
int a = plugin.getArena(event.getPlayer());
if (!event.isCancelled()) {
if (plugin.canjoin.get(a)) {
if (plugin.canJoin.get(a)) {
if (plugin.Playing.get(a).contains(event.getPlayer().getName())) {
if ((!plugin.restricted) || ((plugin.restricted) && (plugin.worldsNames.containsValue(event.getPlayer().getWorld().getName())))) {
if ((!plugin.restrictedWorlds) || ((plugin.restrictedWorlds) && (plugin.worldsNames.containsValue(event.getPlayer().getWorld().getName())))) {
Block b = event.getBlockClicked().getRelative(event.getBlockFace());
String w = b.getWorld().getName();
addPlacedBlockToList(b, w, a);
@ -188,92 +186,89 @@ public class BlockStorage implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void bucketFill(PlayerBucketFillEvent event) {
if (plugin.getArena(event.getPlayer()) != null) {
int a = plugin.getArena(event.getPlayer());
if (!event.isCancelled()) {
if (plugin.canjoin.get(a)) {
if (plugin.Playing.get(a).contains(event.getPlayer().getName())) {
if ((!plugin.restricted) || ((plugin.restricted) && (plugin.worldsNames.containsValue(event.getPlayer().getWorld().getName())))) {
Block b = event.getBlockClicked().getRelative(event.getBlockFace());
String w = b.getWorld().getName();
addDestroyedBlockToList(b, w, a);
}
}
}
int arena = plugin.getArena(event.getPlayer());
if (event.isCancelled()) {
return;
}
boolean isPlaying = plugin.Playing.get(arena).contains(event.getPlayer().getName());
boolean enabledInWorld = plugin.worldsNames.containsValue(event.getPlayer().getWorld().getName());
if (joinAble(arena) && (isPlaying && (!plugin.restrictedWorlds || enabledInWorld))) {
Block block = event.getBlockClicked().getRelative(event.getBlockFace());
String worldName = block.getWorld().getName();
addDestroyedBlockToList(block, worldName, arena);
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void blockMelt(BlockFadeEvent event) {
if (!event.isCancelled()) {
for (int i : plugin.canjoin.keySet()) {
if (plugin.canjoin.get(i) || protall()) {
if ((!plugin.restricted) || ((plugin.restricted) && (plugin.worldsNames.get(i) != null && plugin.worldsNames.get(i).equalsIgnoreCase(event.getBlock().getWorld().getName())))) {
Block b = event.getBlock();
String w = b.getWorld().getName();
String d = b.getType().name();
if (d.equalsIgnoreCase("FIRE") || d.equalsIgnoreCase("AIR")) {
continue;
}
addDestroyedBlockToList(b, w, i);
}
if (event.isCancelled()) {
return;
}
for (int arena : plugin.canJoin.keySet()) {
boolean isInWorld = plugin.worldsNames.get(arena).equalsIgnoreCase(event.getBlock().getWorld().getName());
if (joinAble(arena) || alwaysProtect() &&
(!plugin.restrictedWorlds || plugin.worldsNames.get(arena) != null && isInWorld)) {
Block block = event.getBlock();
String worldName = block.getWorld().getName();
Material material = block.getType();
if (material == Material.FIRE || material.isAir()) {
continue;
}
addDestroyedBlockToList(block, worldName, arena);
}
}
}
//SubRoutines:
private boolean protall() {
return plugin.config.getString("Protected_Arena_Always").equalsIgnoreCase("True");
private boolean alwaysProtect() {
return plugin.config.getBoolean("Protected_Arena_Always");
}
private void addDestroyedBlockToList(Block block, String worldName, int arena) {
int x = block.getX();
int y = block.getY();
int z = block.getZ();
String d = block.getType().name();
String blockDataString;
String splitter = ";";
private void addDestroyedBlockToList(Block b, String w, int a) {
int x = b.getX();
int y = b.getY();
int z = b.getZ();
String d = b.getType().name();
byte m = 0;
String BlDataString = null;
String sp = ";";
String dir = "";
try {
if (b.getState().getBlockData() instanceof BlockData) {
BlDataString = b.getBlockData().getAsString();
}
} catch (Exception | NoSuchMethodError ex) {
m = b.getData();
sp = ",";
MaterialData mData = b.getState().getData();
if (mData instanceof org.bukkit.material.Directional) {
BlockFace Dir = ((org.bukkit.material.Directional) mData).getFacing();
if (Dir != null) {
dir = sp + (Dir.name());
}
}
}
String data = BlDataString != null ? BlDataString : String.valueOf(m);
String coords = w + sp + x + sp + y + sp + z + sp + d + sp + data + sp + a + dir;
String direction = "";
block.getState().getBlockData();
blockDataString = block.getBlockData().getAsString();
String coordinates = worldName + splitter + x + splitter + y + splitter + z + splitter + d + splitter +
blockDataString + splitter + arena + direction;
List<String> blocks = plugin.data.getStringList("Blocks_Destroyed");
if (!plugin.data.getStringList("Blocks_Placed").contains(w + "," + x + "," + y + "," + z + "," + a)) {
blocks.add(coords);
if (!plugin.data.getStringList("Blocks_Placed").contains(String.format("%s,%d,%d,%d,%s", worldName, x, y, z, arena))) {
blocks.add(coordinates);
plugin.data.set("Blocks_Destroyed", blocks);
plugin.saveData();
}
}
private void addPlacedBlockToList(Block br, String w, int a) {
int x = br.getX();
int y = br.getY();
int z = br.getZ();
String coords = w + "," + x + "," + y + "," + z + "," + a;
private void addPlacedBlockToList(Block block, String worldName, int arena) {
int x = block.getX();
int y = block.getY();
int z = block.getZ();
String coordinates = String.format("%s,%d,%d,%d,%d", worldName, x, y, z, arena);
List<String> blocks = plugin.data.getStringList("Blocks_Placed");
if (!blocks.contains(coords)) {
blocks.add(coords);
if (!blocks.contains(coordinates)) {
blocks.add(coordinates);
plugin.data.set("Blocks_Placed", blocks);
plugin.saveData();
}
}
/**
* Gets whether the given arena can be joined
*
* @param arena <p>The arena to check</p>
* @return <p>True if the arena can be joined</p>
*/
private boolean joinAble(int arena) {
return plugin.canJoin.get(arena);
}
}

View File

@ -1,6 +1,6 @@
package me.Travja.HungerArena.Listeners;
package net.knarcraft.hungerarena.Listeners;
import me.Travja.HungerArena.Main;
import net.knarcraft.hungerarena.HungerArena;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@ -15,9 +15,9 @@ import java.util.Map;
import java.util.Map.Entry;
public class Boundaries implements Listener {
public final Main plugin;
public final HungerArena plugin;
public Boundaries(Main m) {
public Boundaries(HungerArena m) {
this.plugin = m;
}

View File

@ -1,6 +1,6 @@
package me.Travja.HungerArena.Listeners;
package net.knarcraft.hungerarena.Listeners;
import me.Travja.HungerArena.Main;
import net.knarcraft.hungerarena.HungerArena;
import org.bukkit.ChatColor;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@ -11,9 +11,9 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
import java.util.List;
public class ChatListener implements Listener {
public final Main plugin;
public final HungerArena plugin;
public ChatListener(Main m) {
public ChatListener(HungerArena m) {
this.plugin = m;
}
@ -23,7 +23,7 @@ public class ChatListener implements Listener {
String pname = p.getName();
if (plugin.getArena(p) != null) {
String msg = "<" + ChatColor.RED + "[Tribute] " + ChatColor.WHITE + pname + ">" + " " + event.getMessage();
if (plugin.config.getString("ChatClose").equalsIgnoreCase("True")) {
if (plugin.config.getBoolean("ChatClose")) {
double radius = plugin.config.getDouble("ChatClose_Radius");
List<Entity> near = p.getNearbyEntities(radius, radius, radius);
event.setCancelled(true);

View File

@ -1,6 +1,6 @@
package me.Travja.HungerArena.Listeners;
package net.knarcraft.hungerarena.Listeners;
import me.Travja.HungerArena.Main;
import net.knarcraft.hungerarena.HungerArena;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@ -16,9 +16,9 @@ import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.scoreboard.DisplaySlot;
public class DeathListener implements Listener {
public final Main plugin;
public final HungerArena plugin;
public DeathListener(Main m) {
public DeathListener(HungerArena m) {
this.plugin = m;
}
@ -55,7 +55,7 @@ public class DeathListener implements Listener {
private void RespawnDeadPlayer(Player p, int a) {
final Player player = p;
String[] Spawncoords = plugin.spawns.getString("Spawn_coords." + a).split(",");
String[] Spawncoords = plugin.spawns.getString("Spawn_coordinates." + a).split(",");
World spawnw = plugin.getServer().getWorld(Spawncoords[3]);
double spawnx = Double.parseDouble(Spawncoords[0]);
double spawny = Double.parseDouble(Spawncoords[1]);
@ -85,7 +85,7 @@ public class DeathListener implements Listener {
if (!(p.getKiller() instanceof Player)) {
players = plugin.Playing.get(a).size() - 1;
leftmsg = ChatColor.BLUE + "There are now " + players + " tributes left!";
if (plugin.config.getString("Cannon_Death").equalsIgnoreCase("True")) {
if (plugin.config.getBoolean("Cannon_Death")) {
double y = p.getLocation().getY();
double newy = y + 200;
double x = p.getLocation().getX();
@ -118,12 +118,12 @@ public class DeathListener implements Listener {
} else {
players = plugin.Playing.get(a).size() - 1;
leftmsg = ChatColor.BLUE + "There are now " + players + " tributes left!";
if (plugin.config.getString("Cannon_Death").equalsIgnoreCase("True")) {
if (plugin.config.getBoolean("Cannon_Death")) {
double y = p.getLocation().getY();
double newy = y + 200;
double newY = y + 200;
double x = p.getLocation().getX();
double z = p.getLocation().getZ();
Location strike = new Location(p.getWorld(), x, newy, z);
Location strike = new Location(p.getWorld(), x, newY, z);
p.getWorld().strikeLightning(strike);
}
plugin.Dead.get(a).add(pname);

View File

@ -1,6 +1,6 @@
package me.Travja.HungerArena.Listeners;
package net.knarcraft.hungerarena.Listeners;
import me.Travja.HungerArena.Main;
import net.knarcraft.hungerarena.HungerArena;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
@ -15,9 +15,9 @@ import java.util.HashMap;
import java.util.List;
public class FreezeListener implements Listener {
public final Main plugin;
public final HungerArena plugin;
public FreezeListener(Main m) {
public FreezeListener(HungerArena m) {
this.plugin = m;
}
@ -32,8 +32,8 @@ public class FreezeListener implements Listener {
String pname = p.getName();
if (plugin.getArena(p) != null) {
a = plugin.getArena(p);
if (plugin.Frozen.get(a).contains(pname) && plugin.config.getString("Frozen_Teleport").equalsIgnoreCase("True")) {
if (plugin.config.getString("Explode_on_Move").equalsIgnoreCase("true")) {
if (plugin.Frozen.get(a).contains(pname) && plugin.config.getBoolean("Frozen_Teleport")) {
if (plugin.config.getBoolean("Explode_on_Move")) {
timeUp.put(a, false);
for (String players : plugin.Playing.get(a)) {
Player playing = plugin.getServer().getPlayerExact(players);
@ -63,7 +63,7 @@ public class FreezeListener implements Listener {
if (plugin.Dead.get(a).contains(pname) && plugin.Playing.get(a).contains(pname)) {
int players = plugin.Playing.get(a).size() - 1;
String leftmsg = ChatColor.BLUE + "There are now " + players + " tributes left!";
if (plugin.config.getString("Cannon_Death").equalsIgnoreCase("True")) {
if (plugin.config.getBoolean("Cannon_Death")) {
double y = p.getLocation().getY();
double newy = y + 200;
double x = p.getLocation().getX();

View File

@ -1,7 +1,7 @@
package me.Travja.HungerArena.Listeners;
package net.knarcraft.hungerarena.Listeners;
import me.Travja.HungerArena.HaCommands;
import me.Travja.HungerArena.Main;
import net.knarcraft.hungerarena.HaCommands;
import net.knarcraft.hungerarena.HungerArena;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
@ -13,9 +13,9 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scoreboard.DisplaySlot;
public class JoinAndQuitListener implements Listener {
public Main plugin;
public HungerArena plugin;
public JoinAndQuitListener(Main m) {
public JoinAndQuitListener(HungerArena m) {
this.plugin = m;
}
@ -29,19 +29,19 @@ public class JoinAndQuitListener implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
final Player p = event.getPlayer();
final String pname = p.getName();
final Player player = event.getPlayer();
final String pname = player.getName();
boolean pfound = false;
for (int i : plugin.Watching.keySet()) {
for (String s : plugin.Watching.get(i)) {
Player spectator = plugin.getServer().getPlayerExact(s);
p.hidePlayer(plugin, spectator);
player.hidePlayer(plugin, spectator);
}
}
for (int i : plugin.Out.keySet()) {
if (plugin.Out.get(i).contains(pname)) {
plugin.Playing.get(i).add(pname);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> p.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);
pfound = true;
}
@ -49,7 +49,7 @@ public class JoinAndQuitListener implements Listener {
for (final int i : plugin.Quit.keySet()) {
if (plugin.Quit.get(i).contains(pname)) {
String[] Spawncoords = plugin.spawns.getString("Spawn_coords." + i).split(",");
String[] Spawncoords = plugin.spawns.getString("Spawn_coordinates." + i).split(",");
String w = Spawncoords[3];
World spawnw = plugin.getServer().getWorld(w);
double spawnx = Double.parseDouble(Spawncoords[0]);
@ -57,11 +57,11 @@ public class JoinAndQuitListener implements Listener {
double spawnz = Double.parseDouble(Spawncoords[2]);
final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
p.teleport(Spawn);
p.sendMessage(ChatColor.RED + "You have been teleported to last spawn because you quit/forfeited!");
plugin.RestoreInv(p, p.getName());
player.teleport(Spawn);
player.sendMessage(ChatColor.RED + "You have been teleported to last spawn because you quit/forfeited!");
plugin.RestoreInv(player, player.getName());
if (plugin.Quit.get(i) != null) {
plugin.Quit.get(i).remove(p.getName());
plugin.Quit.get(i).remove(player.getName());
}
}, 40L);
pfound = true;
@ -69,7 +69,7 @@ public class JoinAndQuitListener implements Listener {
}
for (final int i : plugin.Dead.keySet()) {
if (plugin.Dead.get(i).contains(pname)) {
String[] Spawncoords = plugin.spawns.getString("Spawn_coords." + i).split(",");
String[] Spawncoords = plugin.spawns.getString("Spawn_coordinates." + i).split(",");
String w = Spawncoords[3];
World spawnw = plugin.getServer().getWorld(w);
double spawnx = Double.parseDouble(Spawncoords[0]);
@ -77,11 +77,11 @@ public class JoinAndQuitListener implements Listener {
double spawnz = Double.parseDouble(Spawncoords[2]);
final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
p.teleport(Spawn);
p.sendMessage(ChatColor.RED + "You have been teleported to spawn because you quit/died/forfeited!!");
plugin.RestoreInv(p, p.getName());
player.teleport(Spawn);
player.sendMessage(ChatColor.RED + "You have been teleported to spawn because you quit/died/forfeited!!");
plugin.RestoreInv(player, player.getName());
if (plugin.Dead.get(i) != null) {
plugin.Dead.get(i).remove(p.getName());
plugin.Dead.get(i).remove(player.getName());
}
}, 40L);
pfound = true;
@ -90,7 +90,7 @@ public class JoinAndQuitListener implements Listener {
for (final int i : plugin.inArena.keySet()) {
if (plugin.inArena.get(i) != null) {
if (plugin.inArena.get(i).contains(pname)) {
String[] Spawncoords = plugin.spawns.getString("Spawn_coords." + i).split(",");
String[] Spawncoords = plugin.spawns.getString("Spawn_coordinates." + i).split(",");
String w = Spawncoords[3];
World spawnw = plugin.getServer().getWorld(w);
double spawnx = Double.parseDouble(Spawncoords[0]);
@ -98,36 +98,36 @@ public class JoinAndQuitListener implements Listener {
double spawnz = Double.parseDouble(Spawncoords[2]);
final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
p.teleport(Spawn);
p.getInventory().clear();
p.getInventory().setBoots(null);
p.getInventory().setLeggings(null);
p.getInventory().setChestplate(null);
p.getInventory().setHelmet(null);
player.teleport(Spawn);
player.getInventory().clear();
player.getInventory().setBoots(null);
player.getInventory().setLeggings(null);
player.getInventory().setChestplate(null);
player.getInventory().setHelmet(null);
plugin.inArena.remove(pname);
p.sendMessage(ChatColor.RED + "You were still in the arena when you left and now the games are over.");
plugin.RestoreInv(p, p.getName());
player.sendMessage(ChatColor.RED + "You were still in the arena when you left and now the games are over.");
plugin.RestoreInv(player, player.getName());
if (plugin.inArena.get(i) != null) {
plugin.inArena.get(i).remove(p.getName());
plugin.inArena.get(i).remove(player.getName());
}
}, 40L);
pfound = true;
}
}
}
if (!plugin.restricted || plugin.worldsNames.containsValue(p.getWorld().getName())) {
if (!pfound && plugin.config.getString("Force_Players_toSpawn").equalsIgnoreCase("True") && (plugin.spawns.getString("Spawn_coords.0") != null)) {
String[] Spawncoords = plugin.spawns.getString("Spawn_coords.0").split(",");
String w = Spawncoords[3];
World spawnw = plugin.getServer().getWorld(w);
double spawnx = Double.parseDouble(Spawncoords[0]);
double spawny = Double.parseDouble(Spawncoords[1]);
double spawnz = Double.parseDouble(Spawncoords[2]);
final Location Spawn = new Location(spawnw, spawnx, spawny, spawnz);
plugin.RestoreInv(p, p.getName());
if (!plugin.restrictedWorlds || plugin.worldsNames.containsValue(player.getWorld().getName())) {
if (!pfound && plugin.config.getBoolean("Force_Players_toSpawn") && (plugin.spawns.getString("Spawn_coordinates.0") != null)) {
String[] spawnCoordinates = plugin.spawns.getString("Spawn_coordinates.0").split(",");
String w = spawnCoordinates[3];
World spawnWorld = plugin.getServer().getWorld(w);
double spawnX = Double.parseDouble(spawnCoordinates[0]);
double spawnY = Double.parseDouble(spawnCoordinates[1]);
double spawnZ = Double.parseDouble(spawnCoordinates[2]);
final Location Spawn = new Location(spawnWorld, spawnX, spawnY, spawnZ);
plugin.RestoreInv(player, player.getName());
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
p.teleport(Spawn);
p.sendMessage(ChatColor.RED + "You have been teleported to spawn!!");
player.teleport(Spawn);
player.sendMessage(ChatColor.RED + "You have been teleported to spawn!!");
}, 40L);
}
}
@ -140,7 +140,7 @@ public class JoinAndQuitListener implements Listener {
for (int i : plugin.Frozen.keySet()) {
if (plugin.Frozen.get(i).contains(playerName)) {
plugin.Frozen.remove(playerName);
String[] Spawncoords = plugin.spawns.getString("Spawn_coords.0").split(",");
String[] Spawncoords = plugin.spawns.getString("Spawn_coordinates.0").split(",");
String w = Spawncoords[3];
World spawnw = plugin.getServer().getWorld(w);
double spawnx = Double.parseDouble(Spawncoords[0]);

View File

@ -1,6 +1,6 @@
package me.Travja.HungerArena.Listeners;
package net.knarcraft.hungerarena.Listeners;
import me.Travja.HungerArena.Main;
import net.knarcraft.hungerarena.HungerArena;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
@ -12,9 +12,9 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
public class PvP implements Listener {
public final Main plugin;
public final HungerArena plugin;
public PvP(Main m) {
public PvP(HungerArena m) {
this.plugin = m;
}
@ -27,7 +27,7 @@ public class PvP implements Listener {
if (pl instanceof Player p && dl instanceof Player d) {
if (plugin.getArena(p) != null && plugin.getArena(d) != null) {
a = plugin.getArena(p);
if (plugin.canjoin.get(a)) {
if (plugin.canJoin.get(a)) {
if (event.isCancelled()) {
event.setCancelled(false);
}
@ -40,7 +40,7 @@ public class PvP implements Listener {
}
if (plugin.getArena(p) != null) {
a = plugin.getArena(p);
if (!plugin.canjoin.get(a)) {
if (!plugin.canJoin.get(a)) {
if (!event.isCancelled()) {
event.setCancelled(true);
}

View File

@ -1,6 +1,6 @@
package me.Travja.HungerArena.Listeners;
package net.knarcraft.hungerarena.Listeners;
import me.Travja.HungerArena.Main;
import net.knarcraft.hungerarena.HungerArena;
import org.bukkit.ChatColor;
import org.bukkit.Tag;
import org.bukkit.block.Block;
@ -12,9 +12,9 @@ import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
public class SignsAndBeds implements Listener {
public final Main plugin;
public final HungerArena plugin;
public SignsAndBeds(Main m) {
public SignsAndBeds(HungerArena m) {
this.plugin = m;
}
@ -65,7 +65,7 @@ public class SignsAndBeds implements Listener {
}
}
if (plugin.config.getString("DenyBedUsage").equalsIgnoreCase("True")) {
if (plugin.config.getBoolean("DenyBedUsage")) {
boolean foundBed = false;
try {
if (b.getState() instanceof org.bukkit.block.Bed) {

View File

@ -1,6 +1,6 @@
package me.Travja.HungerArena.Listeners;
package net.knarcraft.hungerarena.Listeners;
import me.Travja.HungerArena.Main;
import net.knarcraft.hungerarena.HungerArena;
import org.bukkit.ChatColor;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
@ -11,9 +11,9 @@ import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
public class SignsAndBedsOld implements Listener {
public final Main plugin;
public final HungerArena plugin;
public SignsAndBedsOld(Main m) {
public SignsAndBedsOld(HungerArena m) {
this.plugin = m;
}
@ -53,7 +53,7 @@ public class SignsAndBedsOld implements Listener {
}
}
if (plugin.config.getString("DenyBedUsage").trim().equalsIgnoreCase("true")) {
if (plugin.config.getBoolean("DenyBedUsage")) {
if (b.getState().getData() instanceof org.bukkit.material.Bed) {
event.setCancelled(true);
}

View File

@ -1,6 +1,6 @@
package me.Travja.HungerArena.Listeners;
package net.knarcraft.hungerarena.Listeners;
import me.Travja.HungerArena.Main;
import net.knarcraft.hungerarena.HungerArena;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
@ -22,14 +22,12 @@ import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.scoreboard.DisplaySlot;
public class SpectatorListener implements Listener {
public final Main plugin;
public final HungerArena plugin;
public SpectatorListener(Main m) {
public SpectatorListener(HungerArena m) {
this.plugin = m;
}
int i = 0;
@EventHandler
public void SpectatorDrops(PlayerDropItemEvent event) {
Player p = event.getPlayer();
@ -140,7 +138,7 @@ public class SpectatorListener implements Listener {
if (plugin.Watching.get(i) != null) {
if (plugin.Watching.get(i).contains(pname)) {
plugin.Watching.get(i).remove(pname);
String[] Spawncoords = plugin.spawns.getString("Spawn_coords.0").split(",");
String[] Spawncoords = plugin.spawns.getString("Spawn_coordinates.0").split(",");
String w = Spawncoords[3];
World spawnw = plugin.getServer().getWorld(w);
double spawnx = Double.parseDouble(Spawncoords[0]);

View File

@ -1,6 +1,6 @@
package me.Travja.HungerArena.Listeners;
package net.knarcraft.hungerarena.Listeners;
import me.Travja.HungerArena.Main;
import net.knarcraft.hungerarena.HungerArena;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
@ -22,14 +22,12 @@ import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.scoreboard.DisplaySlot;
public class SpectatorListenerOld implements Listener {
public final Main plugin;
public final HungerArena plugin;
public SpectatorListenerOld(Main m) {
public SpectatorListenerOld(HungerArena m) {
this.plugin = m;
}
int i = 0;
@EventHandler
public void SpectatorDrops(PlayerDropItemEvent event) {
Player p = event.getPlayer();
@ -154,7 +152,7 @@ public class SpectatorListenerOld implements Listener {
if (plugin.Watching.get(i) != null) {
if (plugin.Watching.get(i).contains(pname)) {
plugin.Watching.get(i).remove(pname);
String[] Spawncoords = plugin.spawns.getString("Spawn_coords.0").split(",");
String[] Spawncoords = plugin.spawns.getString("Spawn_coordinates.0").split(",");
String w = Spawncoords[3];
World spawnw = plugin.getServer().getWorld(w);
double spawnx = Double.parseDouble(Spawncoords[0]);

View File

@ -1,6 +1,6 @@
package me.Travja.HungerArena.Listeners;
package net.knarcraft.hungerarena.Listeners;
import me.Travja.HungerArena.Main;
import net.knarcraft.hungerarena.HungerArena;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -10,9 +10,9 @@ import org.bukkit.event.player.PlayerTeleportEvent;
public class TeleportListener implements Listener {
public final Main plugin;
public final HungerArena plugin;
public TeleportListener(Main m) {
public TeleportListener(HungerArena m) {
this.plugin = m;
}

View File

@ -0,0 +1,59 @@
package net.knarcraft.hungerarena.Listeners;
import net.knarcraft.hungerarena.HungerArena;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
public class WorldChange implements Listener {
public final HungerArena plugin;
public WorldChange(HungerArena m) {
plugin = m;
}
@EventHandler(priority = EventPriority.LOWEST)
public void worldChangeLow(PlayerChangedWorldEvent event) {
Player p = event.getPlayer();
String pname = p.getName();
String ThisWorld = p.getWorld().getName();
String FromWorld = event.getFrom().getName();
if (!plugin.worldsNames.containsValue(ThisWorld) && plugin.worldsNames.containsValue(FromWorld)) {
plugin.RestoreInv(p, pname);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void worldChangeHigh(PlayerChangedWorldEvent event) {
Player p = event.getPlayer();
String pname = p.getName();
String ThisWorld = p.getWorld().getName();
int a = 0;
for (int i : plugin.worldsNames.keySet()) {
if (plugin.worldsNames.get(i) == null) {
continue;
}
if (plugin.worldsNames.get(i).equals(ThisWorld)) {
a = i;
if (plugin.Frozen.get(a) != null && plugin.Frozen.get(a).contains(pname)) {
return;
} else {
plugin.RestoreInv(p, pname);
if (plugin.config.getBoolean("joinTeleport")) {
String[] spawnCoordinates = plugin.spawns.getString("Spawn_coordinates." + a).split(",");
double spawnX = Double.parseDouble(spawnCoordinates[0]);
double spawnY = Double.parseDouble(spawnCoordinates[1]);
double spawnZ = Double.parseDouble(spawnCoordinates[2]);
Location Spawn = new Location(p.getWorld(), spawnX, spawnY, spawnZ);
if (!p.getLocation().getBlock().equals(Spawn.getBlock())) {
p.teleport(Spawn);
}
}
}
}
}
}
}

View File

@ -1,6 +1,6 @@
package me.Travja.HungerArena.Listeners;
package net.knarcraft.hungerarena.Listeners;
import me.Travja.HungerArena.Main;
import net.knarcraft.hungerarena.HungerArena;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -12,9 +12,9 @@ import org.bukkit.event.player.PlayerInteractEvent;
import java.util.Collection;
public class spawnsListener implements Listener {
public final Main plugin;
public final HungerArena plugin;
public spawnsListener(Main m) {
public spawnsListener(HungerArena m) {
this.plugin = m;
}

View File

@ -0,0 +1,178 @@
package net.knarcraft.hungerarena;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
public class SpawnsCommand implements CommandExecutor {
public final HungerArena plugin;
int i = 0;
int arenaId = 0;
boolean NoPlayerSpawns;
public SpawnsCommand(HungerArena m) {
this.plugin = m;
}
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String commandLabel, String[] args) {
Player p = (Player) sender;
String ThisWorld = p.getWorld().getName();
NoPlayerSpawns = true;
for (int i : plugin.worldsNames.keySet()) {
if (plugin.worldsNames.get(i) != null) {
if (plugin.worldsNames.get(i).equals(ThisWorld)) {
arenaId = i;
NoPlayerSpawns = false;
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];
x = Double.parseDouble(args[3]);
y = Double.parseDouble(args[4]);
z = Double.parseDouble(args[5]);
location = new Location(Bukkit.getWorld(world), x, y, z);
if (plugin.location.get(arenaId) != null) {
plugin.location.get(arenaId).put(i, location);
} else {
/*plugin.arenas.put(arenaId, new Arena(arenaId, location.getWorld(), new ArrayList<>(),
ArenaState.IDLE, false, true, 0, 0, 0,
new HashMap<>()));*/
plugin.arenas.get(arenaId).locations().put(i, location);
plugin.location.put(arenaId, new HashMap<>());
plugin.location.get(arenaId).put(i, location);
plugin.Playing.put(arenaId, new ArrayList<>());
plugin.Ready.put(arenaId, new ArrayList<>());
plugin.Dead.put(arenaId, new ArrayList<>());
plugin.Quit.put(arenaId, new ArrayList<>());
plugin.Out.put(arenaId, new ArrayList<>());
plugin.Watching.put(arenaId, new ArrayList<>());
plugin.NeedConfirm.put(arenaId, new ArrayList<>());
plugin.inArena.put(arenaId, new ArrayList<>());
plugin.Frozen.put(arenaId, new ArrayList<>());
plugin.canJoin.put(arenaId, false);
plugin.MatchRunning.put(arenaId, null);
plugin.open.put(arenaId, true);
}
String coords = location.getWorld().getName() + "," + (location.getX()) + "," + location.getY() + "," + (location.getZ());
p.sendMessage(coords);
plugin.spawns.set("Spawns." + arenaId + "" + i, coords);
plugin.worldsNames.put(arenaId, location.getWorld().getName());
plugin.saveSpawns();
plugin.maxPlayers.put(arenaId, plugin.location.get(arenaId).size());
p.sendMessage(ChatColor.AQUA + "You have set the spawn location of Tribute " + i + " in arena " + arenaId + "!");
this.plugin.reloadSpawnPoints(false);
return true;
}
if (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;
}
}

View File

@ -1,4 +1,4 @@
package me.Travja.HungerArena;
package net.knarcraft.hungerarena;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -9,16 +9,17 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class SponsorCommands implements CommandExecutor {
public final Main plugin;
public final HungerArena plugin;
public SponsorCommands(Main m) {
public SponsorCommands(HungerArena m) {
this.plugin = m;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, Command cmd, @NotNull String commandLabel, String[] args) {
if (cmd.getName().equalsIgnoreCase("Sponsor")) {
if (sender instanceof Player p) {
if (p.hasPermission("HungerArena.Sponsor")) {
@ -35,7 +36,7 @@ public class SponsorCommands implements CommandExecutor {
}
if (args.length >= 3) {
Player target = Bukkit.getServer().getPlayer(args[0]);
if (target == null || (target != null && plugin.getArena(target) == null)) {
if (target == null || plugin.getArena(target) == null) {
p.sendMessage(ChatColor.RED + "That person isn't playing!");
} else {
try {
@ -74,17 +75,24 @@ public class SponsorCommands implements CommandExecutor {
}
if (args.length >= 3) {
Player target = Bukkit.getPlayer(args[0]);
String ID = args[1].toUpperCase().trim();
int Amount = Integer.parseInt(args[2]);
if (target == null) {
throw new NullPointerException("getPlayer returned null");
}
String materialId = args[1].toUpperCase().trim();
int materialAmount = Integer.parseInt(args[2]);
try {
if ((!plugin.management.getStringList("sponsors.blacklist").isEmpty() && !plugin.management.getStringList("sponsors.blacklist").contains(ID)) || plugin.management.getStringList("sponsors.blacklist").isEmpty()) {
ItemStack sponsoritem = new ItemStack(org.bukkit.Material.getMaterial(ID), Amount);
if ((!plugin.management.getStringList("sponsors.blacklist").isEmpty() && !plugin.management.getStringList("sponsors.blacklist").contains(materialId)) || plugin.management.getStringList("sponsors.blacklist").isEmpty()) {
Material material = Material.getMaterial(materialId);
if (material == null) {
throw new NullPointerException("getMaterial returned null");
}
ItemStack sponsorItem = new ItemStack(material, materialAmount);
if (plugin.getArena(target) == null) {
sender.sendMessage(ChatColor.RED + "That person isn't playing!");
} else {
sender.sendMessage(ChatColor.RED + "You can't sponsor yourself!");
target.sendMessage(ChatColor.AQUA + "You have been Sponsored!");
target.getInventory().addItem(sponsoritem);
target.getInventory().addItem(sponsorItem);
sender.sendMessage("You have sponsored " + target.getName() + "!");
}
} else {
@ -95,7 +103,7 @@ public class SponsorCommands implements CommandExecutor {
}
}
} catch (Exception e) {
sender.sendMessage(ChatColor.RED + "Something went wrong there... Make sure that you do like this /sponsor [name] [number] [number]");
sender.sendMessage(ChatColor.RED + "Something went wrong there... Make sure that you do like this /sponsor [name] [material] [number]");
}
}
}
@ -103,49 +111,50 @@ public class SponsorCommands implements CommandExecutor {
return false;
}
private void handleItemsAndEco(Player p, String[] args, String ID, int amount, Player target) {
Material sponsMat = plugin.getNewMaterial(ID, 0);
ItemStack sponsoritem;
private void handleItemsAndEco(Player player, String[] args, String materialId, int amount, Player target) {
Material sponsorMaterial = plugin.getNewMaterial(materialId, 0);
ItemStack sponsorItem;
boolean done = false;
if (sponsMat != null) {
sponsoritem = new ItemStack(sponsMat, amount);
if (sponsorMaterial != null) {
sponsorItem = new ItemStack(sponsorMaterial, amount);
} else {
p.sendMessage(ChatColor.RED + "That item does not exist !!");
player.sendMessage(ChatColor.RED + "That item does not exist !!");
return;
}
for (ItemStack Costs : plugin.Cost) {
if (!p.getInventory().containsAtLeast(Costs, Costs.getAmount() * amount)) {
p.sendMessage(ChatColor.RED + "You don't have the necessary items to sponsor!");
if (!player.getInventory().containsAtLeast(Costs, Costs.getAmount() * amount)) {
player.sendMessage(ChatColor.RED + "You don't have the necessary items to sponsor!");
return;
}
}
if (args[0].equalsIgnoreCase(p.getName())) {
p.sendMessage(ChatColor.RED + "You can't sponsor yourself!");
if (args[0].equalsIgnoreCase(player.getName())) {
player.sendMessage(ChatColor.RED + "You can't sponsor yourself!");
} else {
if (plugin.config.getBoolean("sponsorEco.enabled")) {
if (!(plugin.econ.getBalance(p) < (plugin.config.getDouble("sponsorEco.cost") * amount))) {
plugin.econ.withdrawPlayer(p, plugin.config.getDouble("sponsorEco.cost") * amount);
if (!(plugin.econ.getBalance(player) < (plugin.config.getDouble("sponsorEco.cost") * amount))) {
plugin.econ.withdrawPlayer(player, plugin.config.getDouble("sponsorEco.cost") * amount);
done = true;
} else {
p.sendMessage(ChatColor.RED + "You don't have enough money to do that!");
player.sendMessage(ChatColor.RED + "You don't have enough money to do that!");
return;
}
}
if (!plugin.Cost.isEmpty()) {
for (ItemStack aCosts : plugin.Cost) {
for (int x = 1; x <= amount; x++) {
p.getInventory().removeItem(aCosts);
player.getInventory().removeItem(aCosts);
done = true;
}
}
}
if (done) {
target.getInventory().addItem(sponsoritem);
target.getInventory().addItem(sponsorItem);
target.sendMessage(ChatColor.AQUA + "You have been Sponsored!");
p.sendMessage("You have sponsored " + target.getName() + "!");
player.sendMessage("You have sponsored " + target.getName() + "!");
} else {
p.sendMessage(ChatColor.RED + "Sponsoring is disabled!");
player.sendMessage(ChatColor.RED + "Sponsoring is disabled!");
}
}
}
}

View File

@ -9,38 +9,38 @@ config:
######################################
# If all HA features are restricted to the HA-world(s) only .
# If set to 'false' all worlds will be allowed.
# If set to false all worlds will be allowed.
Restricted: true
# If left at 0 there will be no death match, fill in a time in minutes
DeathMatch: 0
#Whether or not to broadcast game messages to all players
#Whether to broadcast game messages to all players
broadcastAll: true
# The max amount of players that can be in a game, This is also dependent on the amount of startpoints you have set.
maxPlayers: 24
# If the worlds spawn is not the same as your Arena spawn you can set this to true for players spawn at arena
joinTeleport: 'false'
joinTeleport: false
# Message to display when the games start
Start_Message: '&bLet The Games Begin!'
# If the games should automatically restart at the end
Auto_Restart: 'false'
Auto_Restart: false
# If it should automatically start the countdown on warping
Auto_Start: 'false'
Auto_Start: false
# If it should automatically warp players if there are enough (else wait for the command 'warpall')
Auto_Warp: 'true'
Auto_Warp: true
# If tributes need to type /ha confirm to join
Need_Confirm: 'true'
Need_Confirm: true
# Whether or not the countdown will start upon warping.
Countdown: 'true'
# Whether the countdown will start upon warping.
Countdown: true
# Duration of the countdown .
Countdown_Timer: 15
@ -48,28 +48,28 @@ Countdown_Timer: 15
# How long the grace period should last (seconds)
Grace_Period: 60
# Whether or not players can break ANY blocks while playing
Protected_Arena: 'true'
# Whether players can break ANY blocks while playing
Protected_Arena: true
# Whether or not players (not playing) can break blocks while waiting
Protected_Arena_Always: 'true'
# Whether players (not playing) can break blocks while waiting
Protected_Arena_Always: true
# Whether new or unknown players on HA-maps should be forced to the spawn or not.
Force_Players_toSpawn: 'true'
Force_Players_toSpawn: true
# Whether or not players will be frozen when they are teleported to their positions
Frozen_Teleport: 'true'
# Whether players will be frozen when they are teleported to their positions
Frozen_Teleport: true
# If the Tributes will get blown to bits when stepping off the pedestal
Explode_on_Move: 'false'
Explode_on_Move: false
# Whether or not thunder will sound upon a players death
Cannon_Death: 'true'
# Whether thunder will sound upon a players death
Cannon_Death: true
# Whether players are allowed to use beds, or not!
DenyBedUsage: 'true'
DenyBedUsage: true
# Whether or not to have the arena be the world or the WorldEdit selection
# Whether to have the arena be the world or the WorldEdit selection
WorldEdit: false
# What item should be used to set spawns after /startpoint [arena#]
@ -117,7 +117,7 @@ ChestPay:
#############################
# If players will only talk to close players of the whole server
ChatClose: 'true'
ChatClose: true
# How close the players have to be to talk to them
ChatClose_Radius: 10

View File

@ -1,8 +1,8 @@
# This file stores all of the spawns!
Spawn_coords: [ ]
# If /ha setspawn has been run
# This file stores all the spawns!
Spawn_coordinates: [ ]
# If /ha setSpawn has been run
Spawns_set:
0: 'false'
0: false
Spawns:
1:
1: