diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml
index b3b0e3d..cf0183e 100644
--- a/dependency-reduced-pom.xml
+++ b/dependency-reduced-pom.xml
@@ -64,7 +64,13 @@
com.sk89q.worldedit
worldedit-bukkit
- 7.3.9
+ 7.4.0-SNAPSHOT
+ provided
+
+
+ com.sk89q.worldguard
+ worldguard-bukkit
+ 7.1.0-SNAPSHOT
provided
diff --git a/pom.xml b/pom.xml
index d52248a..2035fc4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,10 +63,6 @@
enginehub
https://maven.enginehub.org/repo/
-
- multiverse-multiverse-releases
- https://repo.onarandombox.com/multiverse-releases
-
@@ -80,7 +76,14 @@
com.sk89q.worldedit
worldedit-bukkit
- 7.3.9
+ 7.4.0-SNAPSHOT
+ provided
+
+
+
+ com.sk89q.worldguard
+ worldguard-bukkit
+ 7.1.0-SNAPSHOT
provided
diff --git a/src/main/java/hu/jgj52/pvpcore/Commands/AcceptDuelCommand.java b/src/main/java/hu/jgj52/pvpcore/Commands/AcceptDuelCommand.java
index 2fffd41..4f096d3 100644
--- a/src/main/java/hu/jgj52/pvpcore/Commands/AcceptDuelCommand.java
+++ b/src/main/java/hu/jgj52/pvpcore/Commands/AcceptDuelCommand.java
@@ -1,5 +1,6 @@
package hu.jgj52.pvpcore.Commands;
+import com.google.common.reflect.TypeToken;
import hu.jgj52.pvpcore.Main;
import hu.jgj52.pvpcore.Utils.Database;
import hu.jgj52.pvpcore.Utils.Kits;
@@ -22,6 +23,8 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.title.Title;
+
+import java.lang.reflect.Type;
import java.time.Duration;
import java.util.*;
@@ -45,127 +48,155 @@ public class AcceptDuelCommand implements CommandExecutor, TabCompleter {
}
- Database.QueryResult reqResult = null;
+ Database.QueryResult reqResult;
try {
reqResult = plugin.db.from("pvpcore_duel_requests").eq("player", Objects.requireNonNull(Bukkit.getPlayer(args[0])).getUniqueId()).eq("enemy", player.getUniqueId()).execute().get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
- Map row = reqResult.data.get(0);
+ if (!reqResult.isEmpty()) {
+ Map row = reqResult.data.get(0);
- Player enemy = Bukkit.getPlayer(args[0]);
- if (enemy == null) {
- player.sendMessage("§cA megadott játékos nem található.");
- return true;
- }
-
- if (reqResult.isEmpty()) {
- player.sendMessage("§cNincs párbajkérelmed ettől a játékostól.");
- return true;
- }
-
- Kits kitManager = new Kits(plugin);
- SchematicManager schematic = new SchematicManager(plugin);
-
- String gamemode = row.get("kit").toString();
-
- Database.QueryResult result = null;
- try {
- result = plugin.db.from("pvpcore_kits")
- .eq("name", gamemode)
- .execute()
- .get();
- } catch (InterruptedException | ExecutionException e) {
- throw new RuntimeException(e);
- }
-
- Map kitRow = result.data.get(0);
-
- player.getInventory().clear();
- enemy.getInventory().clear();
- World world = Bukkit.getWorld("arenas");
- boolean survival = Boolean.parseBoolean(kitRow.get("survival").toString());
- String arena = kitRow.get("arena").toString();
- int x = Integer.parseInt(kitRow.get("id").toString()) * 1000;
- int y = 0;
- int z;
-
- if (plugin.usedArenas.isEmpty()) {
- z = 0;
- } else {
- z = min(plugin.usedArenas) - 1000;
- }
-
- plugin.usedArenas.add(z);
-
- schematic.placeSchematic(world, x, y, z, arena, true);
- Location playerLoc = new Location(world, x + 20.5, y, z + 0.5, 90, 0);
- Location enemyLoc = new Location(world, x - 20.5, y, z + 0.5, -90, 0);
-
- for (PotionEffect potionEffect : player.getActivePotionEffects()) {
- player.removePotionEffect(potionEffect.getType());
- }
- for (PotionEffect potionEffect : enemy.getActivePotionEffects()) {
- enemy.removePotionEffect(potionEffect.getType());
- }
- player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 20, 1), true);
- enemy.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 20, 1), true);
- player.teleport(playerLoc);
- enemy.teleport(enemyLoc);
- try {
- player.getInventory().setContents(kitManager.getKit(gamemode, player, false));
- enemy.getInventory().setContents(kitManager.getKit(gamemode, enemy, false));
- } catch (ExecutionException | InterruptedException e) {
- throw new RuntimeException(e);
- }
- player.setHealth(20D);
- enemy.setHealth(20D);
- player.setFoodLevel(20);
- enemy.setFoodLevel(20);
- player.setSaturation(5);
- enemy.setSaturation(5);
- player.setGameMode(survival ? GameMode.SURVIVAL : GameMode.ADVENTURE);
- enemy.setGameMode(survival ? GameMode.SURVIVAL : GameMode.ADVENTURE);
-
- Map duelData = new HashMap<>();
- duelData.put("player", enemy.getUniqueId());
- duelData.put("enemy", player.getUniqueId());
- duelData.put("ft", row.get("ft"));
- duelData.put("kit", gamemode);
- duelData.put("started", System.currentTimeMillis());
-
- plugin.db.from("pvpcore_duels").insert(duelData);
- plugin.db.from("pvpcore_duel_requests").eq("player", Objects.requireNonNull(Bukkit.getPlayer(args[0])).getUniqueId()).eq("enemy", player.getUniqueId()).delete();
-
- new BukkitRunnable() {
- int countdown = 3;
-
- @Override
- public void run() {
- if (countdown > 0) {
- Component titleText = Component.text(String.valueOf(countdown), NamedTextColor.AQUA);
- Title title = Title.title(
- titleText,
- Component.empty(),
- Title.Times.times(Duration.ZERO, Duration.ofSeconds(1), Duration.ZERO)
- );
- player.showTitle(title);
- enemy.showTitle(title);
- countdown--;
- } else {
- Title startTitle = Title.title(
- Component.text("§eA párbaj megkezdődött!"),
- Component.empty(),
- Title.Times.times(Duration.ZERO, Duration.ofSeconds(2), Duration.ofSeconds(1))
- );
- player.showTitle(startTitle);
- enemy.showTitle(startTitle);
- cancel();
- }
+ Player enemy = Bukkit.getPlayer(args[0]);
+ if (enemy == null) {
+ player.sendMessage("§cA megadott játékos nem található.");
+ return true;
}
- }.runTaskTimer(plugin, 0L, 20L);
+ if (reqResult.isEmpty()) {
+ player.sendMessage("§cNincs párbajkérelmed ettől a játékostól.");
+ return true;
+ }
+
+ Kits kitManager = new Kits(plugin);
+ SchematicManager schematic = new SchematicManager(plugin);
+
+ String gamemode = row.get("kit").toString();
+
+ Database.QueryResult result;
+ try {
+ result = plugin.db.from("pvpcore_kits")
+ .eq("name", gamemode)
+ .execute()
+ .get();
+ } catch (InterruptedException | ExecutionException e) {
+ throw new RuntimeException(e);
+ }
+
+ Map kitRow = result.data.get(0);
+ Database.QueryResult arenaResult;
+ try {
+ arenaResult = plugin.db.from("pvpcore_arenas").eq("id", Integer.parseInt(kitRow.get("arena").toString())).execute().get();
+ } catch (InterruptedException | ExecutionException e) {
+ throw new RuntimeException(e);
+ }
+
+ Map arenaRow = arenaResult.data.get(0);
+
+ player.getInventory().clear();
+ enemy.getInventory().clear();
+ World world = Bukkit.getWorld("arenas");
+ boolean survival = Boolean.parseBoolean(kitRow.get("survival").toString());
+ String arena = arenaRow.get("name").toString();
+ int x = Integer.parseInt(kitRow.get("id").toString()) * 1000;
+ int y = 0;
+ int z;
+
+ if (plugin.usedArenas.isEmpty()) {
+ z = 0;
+ } else {
+ z = min(plugin.usedArenas) - 1000;
+ }
+
+ plugin.usedArenas.add(z);
+
+ schematic.placeSchematic(world, x, y, z, arena, true);
+
+ com.google.gson.Gson gson = new com.google.gson.Gson();
+ Type type = new TypeToken>>>() {
+ }.getType();
+ List>> regions = gson.fromJson(arenaRow.get("regions").toString(), type);
+
+ for (List> region : regions) {
+ List pos1 = region.get(0);
+ List pos2 = region.get(1);
+
+ int x1 = pos1.get(0), y1 = pos1.get(1), z1 = pos1.get(2);
+ int x2 = pos2.get(0), y2 = pos2.get(1), z2 = pos2.get(2);
+ Location loc1 = new Location(world, x + x1, y + y1, z + z1);
+ Location loc2 = new Location(world, x + x2, y + y2, z + z2);
+
+ schematic.createRegion(world, UUID.randomUUID().toString(), loc1, loc2);
+ }
+
+ Location playerLoc = new Location(world, x + 20.5, y, z + 0.5, 90, 0);
+ Location enemyLoc = new Location(world, x - 20.5, y, z + 0.5, -90, 0);
+
+ for (PotionEffect potionEffect : player.getActivePotionEffects()) {
+ player.removePotionEffect(potionEffect.getType());
+ }
+ for (PotionEffect potionEffect : enemy.getActivePotionEffects()) {
+ enemy.removePotionEffect(potionEffect.getType());
+ }
+ player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 20, 1), true);
+ enemy.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 20, 1), true);
+ player.teleport(playerLoc);
+ enemy.teleport(enemyLoc);
+ try {
+ player.getInventory().setContents(kitManager.getKit(gamemode, player, false));
+ enemy.getInventory().setContents(kitManager.getKit(gamemode, enemy, false));
+ } catch (ExecutionException | InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ player.setHealth(20D);
+ enemy.setHealth(20D);
+ player.setFoodLevel(20);
+ enemy.setFoodLevel(20);
+ player.setSaturation(5);
+ enemy.setSaturation(5);
+ player.setGameMode(survival ? GameMode.SURVIVAL : GameMode.ADVENTURE);
+ enemy.setGameMode(survival ? GameMode.SURVIVAL : GameMode.ADVENTURE);
+
+ Map duelData = new HashMap<>();
+ duelData.put("player", enemy.getUniqueId());
+ duelData.put("enemy", player.getUniqueId());
+ duelData.put("ft", row.get("ft"));
+ duelData.put("kit", gamemode);
+ duelData.put("started", System.currentTimeMillis());
+
+ plugin.db.from("pvpcore_duels").insert(duelData);
+ plugin.db.from("pvpcore_duel_requests").eq("player", Objects.requireNonNull(Bukkit.getPlayer(args[0])).getUniqueId()).eq("enemy", player.getUniqueId()).delete();
+
+ new BukkitRunnable() {
+ int countdown = 3;
+
+ @Override
+ public void run() {
+ if (countdown > 0) {
+ Component titleText = Component.text(String.valueOf(countdown), NamedTextColor.AQUA);
+ Title title = Title.title(
+ titleText,
+ Component.empty(),
+ Title.Times.times(Duration.ZERO, Duration.ofSeconds(1), Duration.ZERO)
+ );
+ player.showTitle(title);
+ enemy.showTitle(title);
+ countdown--;
+ } else {
+ Title startTitle = Title.title(
+ Component.text("§eA párbaj megkezdődött!"),
+ Component.empty(),
+ Title.Times.times(Duration.ZERO, Duration.ofSeconds(2), Duration.ofSeconds(1))
+ );
+ player.showTitle(startTitle);
+ enemy.showTitle(startTitle);
+ cancel();
+ }
+ }
+ }.runTaskTimer(plugin, 0L, 20L);
+
+ }
}
return true;
diff --git a/src/main/java/hu/jgj52/pvpcore/Commands/DuelCommand.java b/src/main/java/hu/jgj52/pvpcore/Commands/DuelCommand.java
index 910d241..1c2f1bf 100644
--- a/src/main/java/hu/jgj52/pvpcore/Commands/DuelCommand.java
+++ b/src/main/java/hu/jgj52/pvpcore/Commands/DuelCommand.java
@@ -122,26 +122,6 @@ public class DuelCommand implements CommandExecutor, TabCompleter {
diasmpMeta.setDisplayName("§dDiaSMP");
diasmp.setItemMeta(diasmpMeta);
- ItemStack shieldlessuhc = new ItemStack(Material.PLAYER_HEAD);
- SkullMeta skullMeta = (SkullMeta) shieldlessuhc.getItemMeta();
-
- PlayerProfile profile = Bukkit.createProfile(UUID.randomUUID(), "Schicsial");
-
- try {
- PlayerTextures textures = profile.getTextures();
-
- textures.setSkin(new URL("https://textures.minecraft.net/texture/566a87460173adf067cb356ae200d030504378c552e3428b4774c4c11a599c24"));
-
- profile.setTextures(textures);
-
- skullMeta.setPlayerProfile((com.destroystokyo.paper.profile.PlayerProfile) profile);
-
- skullMeta.setDisplayName("§eShieldlessUHC");
- shieldlessuhc.setItemMeta(skullMeta);
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
-
ItemStack pirosuveg = new ItemStack(Material.RED_STAINED_GLASS_PANE);
ItemMeta pirosuvegMeta = pirosuveg.getItemMeta();
pirosuvegMeta.setDisplayName("§cItt még nincs játékmód!");
@@ -168,18 +148,19 @@ public class DuelCommand implements CommandExecutor, TabCompleter {
gui.setItem(8, kekuveg);
gui.setItem(9, kekuveg);
gui.setItem(10, vanilla);
- gui.setItem(11, uhc);
- gui.setItem(12, pot);
- gui.setItem(13, nethpot);
- gui.setItem(14, smp);
- gui.setItem(15, sword);
- gui.setItem(16, axe);
+ gui.setItem(10, uhc);
+ gui.setItem(11, pot);
+ gui.setItem(12, nethpot);
+ gui.setItem(13, smp);
+ gui.setItem(14, sword);
+ gui.setItem(15, axe);
+ gui.setItem(16, mace);
gui.setItem(17, kekuveg);
gui.setItem(18, kekuveg);
- gui.setItem(19, mace);
- gui.setItem(20, cart);
- gui.setItem(21, diasmp);
- gui.setItem(22, shieldlessuhc);
+ gui.setItem(19, diasmp);
+ gui.setItem(20, pirosuveg);
+ gui.setItem(21, pirosuveg);
+ gui.setItem(22, pirosuveg);
gui.setItem(23, pirosuveg);
gui.setItem(24, pirosuveg);
gui.setItem(25, pirosuveg);
diff --git a/src/main/java/hu/jgj52/pvpcore/Commands/EditKitCommand.java b/src/main/java/hu/jgj52/pvpcore/Commands/EditKitCommand.java
index f35ef9a..7e3312a 100644
--- a/src/main/java/hu/jgj52/pvpcore/Commands/EditKitCommand.java
+++ b/src/main/java/hu/jgj52/pvpcore/Commands/EditKitCommand.java
@@ -33,61 +33,66 @@ public class EditKitCommand implements CommandExecutor, TabCompleter {
if (sender instanceof Player player) {
if (args.length > 0) {
try {
- Database.QueryResult result = plugin.db.from("pvpcore_kits").eq("name", args[0]).execute().get();
- if (!result.isEmpty()) {
- Kits kitManager = new Kits(plugin);
- Inventory gui = Bukkit.createInventory(null, 27, "Kit Editor");
-
- ItemStack saveKit = new ItemStack(Material.GREEN_STAINED_GLASS_PANE);
- ItemMeta saveMeta = saveKit.getItemMeta();
-
- ItemStack infoItem = new ItemStack(Material.WHITE_STAINED_GLASS_PANE);
- ItemMeta infoMeta = infoItem.getItemMeta();
- infoMeta.setDisplayName("§fEdit Kit: " + args[0]);
- infoItem.setItemMeta(infoMeta);
-
- ItemStack undoKit = new ItemStack(Material.RED_STAINED_GLASS_PANE);
- ItemMeta undoMeta = undoKit.getItemMeta();
- saveMeta.setDisplayName("§aSave Kit");
- saveKit.setItemMeta(saveMeta);
- undoMeta.setDisplayName("§cUndo Changes");
- undoKit.setItemMeta(undoMeta);
-
- gui.setItem(0, saveKit);
- gui.setItem(1, saveKit);
- gui.setItem(2, saveKit);
- gui.setItem(6, undoKit);
- gui.setItem(7, undoKit);
- gui.setItem(8, undoKit);
- gui.setItem(9, saveKit);
- gui.setItem(10, saveKit);
- gui.setItem(11, saveKit);
- gui.setItem(15, undoKit);
- gui.setItem(16, undoKit);
- gui.setItem(17, undoKit);
- gui.setItem(18, saveKit);
- gui.setItem(19, saveKit);
- gui.setItem(20, saveKit);
- gui.setItem(24, undoKit);
- gui.setItem(25, undoKit);
- gui.setItem(26, undoKit);
- gui.setItem(3, infoItem);
- gui.setItem(4, infoItem);
- gui.setItem(5, infoItem);
- gui.setItem(12, infoItem);
- gui.setItem(13, infoItem);
- gui.setItem(14, infoItem);
- gui.setItem(21, infoItem);
- gui.setItem(22, infoItem);
- gui.setItem(23, infoItem);
- Inventory inv = player.getInventory();
- inv.clear();
-
- inv.setContents(kitManager.getKit(args[0], player, false));
-
- player.openInventory(gui);
+ Database.QueryResult isDueling = plugin.db.from("pvpcore_duels").eq("player", player.getUniqueId()).execute().get();
+ if (isDueling.isEmpty()) {
+ isDueling = plugin.db.from("pvpcore_duels").eq("enemy", player.getUniqueId()).execute().get();
}
+ if (isDueling.isEmpty()) {
+ Database.QueryResult result = plugin.db.from("pvpcore_kits").eq("name", args[0]).execute().get();
+ if (!result.isEmpty()) {
+ Kits kitManager = new Kits(plugin);
+ Inventory gui = Bukkit.createInventory(null, 27, "Kit Editor");
+ ItemStack saveKit = new ItemStack(Material.GREEN_STAINED_GLASS_PANE);
+ ItemMeta saveMeta = saveKit.getItemMeta();
+
+ ItemStack infoItem = new ItemStack(Material.WHITE_STAINED_GLASS_PANE);
+ ItemMeta infoMeta = infoItem.getItemMeta();
+ infoMeta.setDisplayName("§fEdit Kit: " + args[0]);
+ infoItem.setItemMeta(infoMeta);
+
+ ItemStack undoKit = new ItemStack(Material.RED_STAINED_GLASS_PANE);
+ ItemMeta undoMeta = undoKit.getItemMeta();
+ saveMeta.setDisplayName("§aSave Kit");
+ saveKit.setItemMeta(saveMeta);
+ undoMeta.setDisplayName("§cUndo Changes");
+ undoKit.setItemMeta(undoMeta);
+
+ gui.setItem(0, saveKit);
+ gui.setItem(1, saveKit);
+ gui.setItem(2, saveKit);
+ gui.setItem(6, undoKit);
+ gui.setItem(7, undoKit);
+ gui.setItem(8, undoKit);
+ gui.setItem(9, saveKit);
+ gui.setItem(10, saveKit);
+ gui.setItem(11, saveKit);
+ gui.setItem(15, undoKit);
+ gui.setItem(16, undoKit);
+ gui.setItem(17, undoKit);
+ gui.setItem(18, saveKit);
+ gui.setItem(19, saveKit);
+ gui.setItem(20, saveKit);
+ gui.setItem(24, undoKit);
+ gui.setItem(25, undoKit);
+ gui.setItem(26, undoKit);
+ gui.setItem(3, infoItem);
+ gui.setItem(4, infoItem);
+ gui.setItem(5, infoItem);
+ gui.setItem(12, infoItem);
+ gui.setItem(13, infoItem);
+ gui.setItem(14, infoItem);
+ gui.setItem(21, infoItem);
+ gui.setItem(22, infoItem);
+ gui.setItem(23, infoItem);
+ Inventory inv = player.getInventory();
+ inv.clear();
+
+ inv.setContents(kitManager.getKit(args[0], player, false));
+
+ player.openInventory(gui);
+ }
+ }
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
diff --git a/src/main/java/hu/jgj52/pvpcore/Commands/FfaCommand.java b/src/main/java/hu/jgj52/pvpcore/Commands/FfaCommand.java
new file mode 100644
index 0000000..7289c2c
--- /dev/null
+++ b/src/main/java/hu/jgj52/pvpcore/Commands/FfaCommand.java
@@ -0,0 +1,47 @@
+package hu.jgj52.pvpcore.Commands;
+
+import hu.jgj52.pvpcore.Main;
+import hu.jgj52.pvpcore.Utils.Kits;
+import org.bukkit.Bukkit;
+import org.bukkit.GameMode;
+import org.bukkit.Location;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.TabCompleter;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+
+public class FfaCommand implements CommandExecutor, TabCompleter {
+ private final Main plugin;
+
+ public FfaCommand(Main plugin) {
+ this.plugin = plugin;
+ }
+
+
+ @Override
+ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String @NotNull [] args) {
+ if (sender instanceof Player player) {
+ Kits kits = new Kits(plugin);
+ plugin.playersInFfa.add(player);
+ player.teleport(new Location(Bukkit.getWorld("arenas"), 0.5, 0.5, plugin.ffaCoords + 0.5));
+ player.setGameMode(GameMode.SURVIVAL);
+ try {
+ player.getInventory().setContents(kits.getKit("ffa", player, false));
+ } catch (ExecutionException | InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public @Nullable List onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String @NotNull [] strings) {
+ return List.of();
+ }
+}
diff --git a/src/main/java/hu/jgj52/pvpcore/Commands/ResetArenasCommand.java b/src/main/java/hu/jgj52/pvpcore/Commands/ResetArenasCommand.java
index 388979e..b584051 100644
--- a/src/main/java/hu/jgj52/pvpcore/Commands/ResetArenasCommand.java
+++ b/src/main/java/hu/jgj52/pvpcore/Commands/ResetArenasCommand.java
@@ -2,6 +2,7 @@ package hu.jgj52.pvpcore.Commands;
import hu.jgj52.pvpcore.Main;
import hu.jgj52.pvpcore.Utils.WorldReset;
+import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@@ -23,6 +24,7 @@ public class ResetArenasCommand implements CommandExecutor, TabCompleter {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
WorldReset worldReset = new WorldReset(plugin);
worldReset.recreateArenaWorld();
+ Bukkit.getScheduler().runTaskLater(plugin, worldReset::resetFfa, 40L);
plugin.usedArenas = new ArrayList<>();
return true;
}
diff --git a/src/main/java/hu/jgj52/pvpcore/Listeners/DuelEndListener.java b/src/main/java/hu/jgj52/pvpcore/Listeners/DuelEndListener.java
index 1400f2b..1030298 100644
--- a/src/main/java/hu/jgj52/pvpcore/Listeners/DuelEndListener.java
+++ b/src/main/java/hu/jgj52/pvpcore/Listeners/DuelEndListener.java
@@ -1,5 +1,6 @@
package hu.jgj52.pvpcore.Listeners;
+import com.google.common.reflect.TypeToken;
import hu.jgj52.pvpcore.Main;
import hu.jgj52.pvpcore.Utils.Database;
import hu.jgj52.pvpcore.Utils.Kits;
@@ -12,11 +13,9 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
+import java.lang.reflect.Type;
import java.time.Duration;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.UUID;
+import java.util.*;
import java.util.concurrent.ExecutionException;
import net.kyori.adventure.text.Component;
@@ -46,177 +45,211 @@ public class DuelEndListener implements Listener {
isEnemy = true;
}
- Map row = result.data.get(0);
- if (!result.isEmpty() && (Integer.parseInt(row.get("ft").toString()) - 1 == Integer.parseInt(row.get("player_points").toString()) || Integer.parseInt(row.get("ft").toString()) - 1 == Integer.parseInt(row.get("enemy_points").toString()))) {
- Player enemy = Bukkit.getPlayer(UUID.fromString(isEnemy ? row.get("player").toString() : row.get("enemy").toString()));
- player.getInventory().clear();
- enemy.getInventory().clear();
- e.setCancelled(true);
- player.setGameMode(GameMode.SPECTATOR);
- Location playerLoc = player.getLocation();
+ if (!result.isEmpty()) {
+ Map row = result.data.get(0);
+ if (Integer.parseInt(row.get("ft").toString()) - 1 == Integer.parseInt(row.get("player_points").toString()) || Integer.parseInt(row.get("ft").toString()) - 1 == Integer.parseInt(row.get("enemy_points").toString())) {
+ Player enemy = Bukkit.getPlayer(UUID.fromString(isEnemy ? row.get("player").toString() : row.get("enemy").toString()));
+ player.getInventory().clear();
+ enemy.getInventory().clear();
+ e.setCancelled(true);
+ player.setGameMode(GameMode.SPECTATOR);
+ Location playerLoc = player.getLocation();
- Title winnerTitle = Title.title(
- Component.text("§6🗡 §eMegnyerted a párbajt!"),
- Component.empty(),
- Title.Times.times(Duration.ofMillis(500), Duration.ofSeconds(3), Duration.ofMillis(1000))
- );
+ Title winnerTitle = Title.title(
+ Component.text("§6🗡 §eMegnyerted a párbajt!"),
+ Component.empty(),
+ Title.Times.times(Duration.ofMillis(500), Duration.ofSeconds(3), Duration.ofMillis(1000))
+ );
- Title loserTitle = Title.title(
- Component.text("§4🗡 §cElvesztetted a párbajt!"),
- Component.empty(),
- Title.Times.times(Duration.ofMillis(500), Duration.ofSeconds(3), Duration.ofMillis(1000))
- );
+ Title loserTitle = Title.title(
+ Component.text("§4🗡 §cElvesztetted a párbajt!"),
+ Component.empty(),
+ Title.Times.times(Duration.ofMillis(500), Duration.ofSeconds(3), Duration.ofMillis(1000))
+ );
+
+ for (int i = 0; i < 3; i++) {
+ int delay = i * 10;
+ Bukkit.getScheduler().runTaskLater(plugin, () -> {
+ Firework firework = playerLoc.getWorld().spawn(playerLoc, Firework.class);
+ FireworkMeta meta = firework.getFireworkMeta();
+
+ FireworkEffect effect = FireworkEffect.builder()
+ .with(FireworkEffect.Type.BURST)
+ .withColor(
+ Color.fromRGB(2437522),
+ Color.fromRGB(14602026),
+ Color.fromRGB(6719955)
+ )
+ .build();
+
+ meta.addEffect(effect);
+ meta.setPower((int) 0.5);
+ firework.setFireworkMeta(meta);
+ }, delay);
+ }
+
+ player.showTitle(loserTitle);
+ enemy.showTitle(winnerTitle);
- for (int i = 0; i < 3; i++) {
- int delay = i * 10;
Bukkit.getScheduler().runTaskLater(plugin, () -> {
- Firework firework = playerLoc.getWorld().spawn(playerLoc, Firework.class);
- FireworkMeta meta = firework.getFireworkMeta();
-
- FireworkEffect effect = FireworkEffect.builder()
- .with(FireworkEffect.Type.BURST)
- .withColor(
- Color.fromRGB(2437522),
- Color.fromRGB(14602026),
- Color.fromRGB(6719955)
- )
- .build();
-
- meta.addEffect(effect);
- meta.setPower((int) 0.5);
- firework.setFireworkMeta(meta);
- }, delay);
- }
-
- player.showTitle(loserTitle);
- enemy.showTitle(winnerTitle);
-
- Bukkit.getScheduler().runTaskLater(plugin, () -> {
- try {
- plugin.tpToSpawn(player);
- plugin.tpToSpawn(enemy);
- } catch (Exception exception) {
- exception.printStackTrace();
- }
- }, 60L);
-
- Map data = new HashMap<>();
- data.put("player", row.get("player"));
- data.put("enemy", row.get("enemy"));
- data.put("ft", row.get("ft"));
- data.put("kit", row.get("kit"));
- data.put("winner", enemy.getUniqueId());
- data.put("loser", player.getUniqueId());
- data.put("player_points", row.get("player_points"));
- data.put("enemy_points", row.get("enemy_points"));
- data.put("started", row.get("started"));
- data.put("ended", System.currentTimeMillis());
- plugin.db.from("pvpcore_duel_logs").insert(data);
- plugin.db.from("pvpcore_duels").eq(isEnemy ? "enemy" : "player", player.getUniqueId()).eq(isEnemy ? "player" : "enemy", enemy.getUniqueId()).delete();
- } else if (!result.isEmpty() && Integer.parseInt(row.get("ft").toString()) - 1 != Integer.parseInt(row.get("player_points").toString()) && Integer.parseInt(row.get("ft").toString()) - 1 != Integer.parseInt(row.get("enemy_points").toString())) {
- Player enemy = Bukkit.getPlayer(UUID.fromString(isEnemy ? row.get("player").toString() : row.get("enemy").toString()));
- Kits kitManager = new Kits(plugin);
- SchematicManager schematic = new SchematicManager(plugin);
-
- String gamemode = row.get("kit").toString();
-
- Database.QueryResult kitResult = null;
- try {
- kitResult = plugin.db.from("pvpcore_kits")
- .eq("name", gamemode)
- .execute()
- .get();
- } catch (InterruptedException | ExecutionException ex) {
- throw new RuntimeException(ex);
- }
-
- Map kitRow = kitResult.data.get(0);
-
- player.getInventory().clear();
- enemy.getInventory().clear();
- e.setCancelled(true);
- World world = Bukkit.getWorld("arenas");
- boolean survival = Boolean.parseBoolean(kitRow.get("survival").toString());
- String arena = kitRow.get("arena").toString();
- int x = Integer.parseInt(kitRow.get("id").toString()) * 1000;
- int y = 0;
- int z;
-
- if (plugin.usedArenas.isEmpty()) {
- z = 0;
- } else {
- z = min(plugin.usedArenas) - 1000;
- }
-
- plugin.usedArenas.add(z);
-
- schematic.placeSchematic(world, x, y, z, arena, true);
- Location playerLoc = new Location(world, x + 20.5, y, z + 0.5, 90, 0);
- Location enemyLoc = new Location(world, x - 20.5, y, z + 0.5, -90, 0);
-
- for (PotionEffect potionEffect : player.getActivePotionEffects()) {
- player.removePotionEffect(potionEffect.getType());
- }
- for (PotionEffect potionEffect : enemy.getActivePotionEffects()) {
- enemy.removePotionEffect(potionEffect.getType());
- }
- player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 20, 1), true);
- enemy.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 20, 1), true);
-
- Bukkit.getScheduler().runTaskLater(plugin, () -> {player.teleport(playerLoc);enemy.teleport(enemyLoc);}, 2L);
-
- try {
- player.getInventory().setContents(kitManager.getKit(gamemode, player, false));
- enemy.getInventory().setContents(kitManager.getKit(gamemode, enemy, false));
- } catch (ExecutionException | InterruptedException ex) {
- throw new RuntimeException(ex);
- }
- player.setHealth(20D);
- enemy.setHealth(20D);
- player.setFoodLevel(20);
- enemy.setFoodLevel(20);
- player.setSaturation(5);
- enemy.setSaturation(5);
- player.setGameMode(survival ? GameMode.SURVIVAL : GameMode.ADVENTURE);
- enemy.setGameMode(survival ? GameMode.SURVIVAL : GameMode.ADVENTURE);
-
- Map duelData = new HashMap<>();
- duelData.put("player", row.get("player"));
- duelData.put("enemy", row.get("enemy"));
- duelData.put("ft", row.get("ft"));
- duelData.put("kit", row.get("kit"));
- duelData.put(isEnemy ? "player_points" : "enemy_points", Integer.parseInt(row.get(isEnemy ? "player_points" : "enemy_points").toString()) + 1);
- duelData.put("started", row.get("started"));
-
- plugin.db.from("pvpcore_duels").update(duelData);
-
- new BukkitRunnable() {
- int countdown = 3;
-
- @Override
- public void run() {
- if (countdown > 0) {
- Component titleText = Component.text(String.valueOf(countdown), NamedTextColor.AQUA);
- Title title = Title.title(
- titleText,
- Component.empty(),
- Title.Times.times(Duration.ZERO, Duration.ofSeconds(1), Duration.ZERO)
- );
- player.showTitle(title);
- enemy.showTitle(title);
- countdown--;
- } else {
- Title startTitle = Title.title(
- Component.text("§eA párbaj megkezdődött!"),
- Component.empty(),
- Title.Times.times(Duration.ZERO, Duration.ofSeconds(2), Duration.ofSeconds(1))
- );
- player.showTitle(startTitle);
- enemy.showTitle(startTitle);
- cancel();
+ try {
+ plugin.tpToSpawn(player);
+ plugin.tpToSpawn(enemy);
+ } catch (Exception exception) {
+ exception.printStackTrace();
}
+ }, 60L);
+
+ Map data = new HashMap<>();
+ data.put("player", row.get("player"));
+ data.put("enemy", row.get("enemy"));
+ data.put("ft", row.get("ft"));
+ data.put("kit", row.get("kit"));
+ data.put("winner", enemy.getUniqueId());
+ data.put("loser", player.getUniqueId());
+ data.put("player_points", row.get("player_points"));
+ data.put("enemy_points", row.get("enemy_points"));
+ data.put(isEnemy ? "player_points" : "enemy_points", Integer.parseInt(row.get(isEnemy ? "player_points" : "enemy_points").toString()) + 1);
+ data.put("started", row.get("started"));
+ data.put("ended", System.currentTimeMillis());
+ plugin.db.from("pvpcore_duel_logs").insert(data);
+ plugin.db.from("pvpcore_duels").eq(isEnemy ? "enemy" : "player", player.getUniqueId()).eq(isEnemy ? "player" : "enemy", enemy.getUniqueId()).delete();
+ } else if (Integer.parseInt(row.get("ft").toString()) - 1 != Integer.parseInt(row.get("player_points").toString()) && Integer.parseInt(row.get("ft").toString()) - 1 != Integer.parseInt(row.get("enemy_points").toString())) {
+ Player enemy = Bukkit.getPlayer(UUID.fromString(isEnemy ? row.get("player").toString() : row.get("enemy").toString()));
+ Kits kitManager = new Kits(plugin);
+ SchematicManager schematic = new SchematicManager(plugin);
+
+ String gamemode = row.get("kit").toString();
+
+ Database.QueryResult kitResult;
+ try {
+ kitResult = plugin.db.from("pvpcore_kits")
+ .eq("name", gamemode)
+ .execute()
+ .get();
+ } catch (InterruptedException | ExecutionException ex) {
+ throw new RuntimeException(ex);
}
- }.runTaskTimer(plugin, 0L, 20L);
+
+ Map kitRow = kitResult.data.get(0);
+ Database.QueryResult arenaResult;
+ try {
+ arenaResult = plugin.db.from("pvpcore_arenas").eq("id", Integer.parseInt(kitRow.get("arena").toString())).execute().get();
+ } catch (InterruptedException | ExecutionException err) {
+ throw new RuntimeException(err);
+ }
+
+ Map arenaRow = arenaResult.data.get(0);
+
+ player.getInventory().clear();
+ enemy.getInventory().clear();
+ e.setCancelled(true);
+ World world = Bukkit.getWorld("arenas");
+ boolean survival = Boolean.parseBoolean(kitRow.get("survival").toString());
+ String arena = arenaRow.get("name").toString();
+ int x = Integer.parseInt(kitRow.get("id").toString()) * 1000;
+ int y = 0;
+ int z;
+
+ if (plugin.usedArenas.isEmpty()) {
+ z = 0;
+ } else {
+ z = min(plugin.usedArenas) - 1000;
+ }
+
+ plugin.usedArenas.add(z);
+
+ schematic.placeSchematic(world, x, y, z, arena, true);
+
+ com.google.gson.Gson gson = new com.google.gson.Gson();
+ Type type = new TypeToken>>>() {
+ }.getType();
+ List>> regions = gson.fromJson(arenaRow.get("regions").toString(), type);
+
+ for (List> region : regions) {
+ List pos1 = region.get(0);
+ List pos2 = region.get(1);
+
+ int x1 = pos1.get(0), y1 = pos1.get(1), z1 = pos1.get(2);
+ int x2 = pos2.get(0), y2 = pos2.get(1), z2 = pos2.get(2);
+ Location loc1 = new Location(world, x + x1, y + y1, z + z1);
+ Location loc2 = new Location(world, x + x2, y + y2, z + z2);
+
+ schematic.createRegion(world, UUID.randomUUID().toString(), loc1, loc2);
+ }
+
+ Location playerLoc = new Location(world, x + 20.5, y, z + 0.5, 90, 0);
+ Location enemyLoc = new Location(world, x - 20.5, y, z + 0.5, -90, 0);
+
+ for (PotionEffect potionEffect : player.getActivePotionEffects()) {
+ player.removePotionEffect(potionEffect.getType());
+ }
+ for (PotionEffect potionEffect : enemy.getActivePotionEffects()) {
+ enemy.removePotionEffect(potionEffect.getType());
+ }
+ player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 20, 1), true);
+ enemy.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 20, 1), true);
+
+ Bukkit.getScheduler().runTaskLater(plugin, () -> {
+ player.teleport(playerLoc);
+ enemy.teleport(enemyLoc);
+ }, 2L);
+
+ try {
+ player.getInventory().setContents(kitManager.getKit(gamemode, player, false));
+ enemy.getInventory().setContents(kitManager.getKit(gamemode, enemy, false));
+ } catch (ExecutionException | InterruptedException ex) {
+ throw new RuntimeException(ex);
+ }
+ player.setHealth(20D);
+ enemy.setHealth(20D);
+ player.setFoodLevel(20);
+ enemy.setFoodLevel(20);
+ player.setSaturation(5);
+ enemy.setSaturation(5);
+ player.setGameMode(survival ? GameMode.SURVIVAL : GameMode.ADVENTURE);
+ enemy.setGameMode(survival ? GameMode.SURVIVAL : GameMode.ADVENTURE);
+
+ Map duelData = new HashMap<>();
+ duelData.put("player", row.get("player"));
+ duelData.put("enemy", row.get("enemy"));
+ duelData.put("ft", row.get("ft"));
+ duelData.put("kit", row.get("kit"));
+ duelData.put(isEnemy ? "player_points" : "enemy_points", Integer.parseInt(row.get(isEnemy ? "player_points" : "enemy_points").toString()) + 1);
+ duelData.put("started", row.get("started"));
+
+ plugin.db.from("pvpcore_duels").update(duelData);
+
+ new BukkitRunnable() {
+ int countdown = 3;
+
+ @Override
+ public void run() {
+ if (countdown > 0) {
+ Component titleText = Component.text(String.valueOf(countdown), NamedTextColor.AQUA);
+ Title title = Title.title(
+ titleText,
+ Component.empty(),
+ Title.Times.times(Duration.ZERO, Duration.ofSeconds(1), Duration.ZERO)
+ );
+ player.showTitle(title);
+ enemy.showTitle(title);
+ countdown--;
+ } else {
+ Title startTitle = Title.title(
+ Component.text("§eA párbaj megkezdődött!"),
+ Component.empty(),
+ Title.Times.times(Duration.ZERO, Duration.ofSeconds(2), Duration.ofSeconds(1))
+ );
+ player.showTitle(startTitle);
+ enemy.showTitle(startTitle);
+ cancel();
+ }
+ }
+ }.runTaskTimer(plugin, 0L, 20L);
+ }
+ } else if (plugin.playersInFfa.contains(player)) {
+ plugin.playersInFfa.remove(player);
} else {
e.setCancelled(true);
plugin.tpToSpawn(player);
diff --git a/src/main/java/hu/jgj52/pvpcore/Listeners/KitListener.java b/src/main/java/hu/jgj52/pvpcore/Listeners/KitListener.java
index 69007cb..0c96964 100644
--- a/src/main/java/hu/jgj52/pvpcore/Listeners/KitListener.java
+++ b/src/main/java/hu/jgj52/pvpcore/Listeners/KitListener.java
@@ -47,55 +47,92 @@ public class KitListener implements Listener {
String gamemode = event.getClickedInventory().getItem(13).getItemMeta().getDisplayName().split(" ")[2];
ItemStack[] kit = kitsUtil.getKit(gamemode, player, true);
+ Map kitTotals = new HashMap<>();
+ for (ItemStack kitItem : kit) {
+ if (kitItem == null) continue;
+ String key = kitItem.getType().toString() + kitItem.getItemMeta().toString();
+ kitTotals.put(key, kitTotals.getOrDefault(key, 0) + kitItem.getAmount());
+ }
- String base64Inv = Kits.itemStackArrayToBase64(player.getInventory().getContents());
+ Map invTotals = new HashMap<>();
+ for (ItemStack invItem : player.getInventory().getContents()) {
+ if (invItem == null) continue;
+ String key = invItem.getType().toString() + invItem.getItemMeta().toString();
+ invTotals.put(key, invTotals.getOrDefault(key, 0) + invItem.getAmount());
+ }
- Database.QueryResult plResult = plugin.db.from("pvpcore_players")
- .eq("uuid", player.getUniqueId())
- .execute()
- .get();
+ boolean valid = true;
+ for (Map.Entry entry : invTotals.entrySet()) {
+ String key = entry.getKey();
+ int invAmount = entry.getValue();
+ int kitAmount = kitTotals.getOrDefault(key, 0);
+ if (invAmount != kitAmount) {
+ valid = false;
+ break;
+ }
+ }
- Map playerKits;
- if (!plResult.isEmpty()) {
- Map playerRow = plResult.data.get(0);
- Object kitsObj = playerRow.get("kits");
- if (kitsObj != null) {
- String playerKitsStr = kitsObj instanceof PGobject pg ? pg.getValue() : kitsObj.toString();
- java.lang.reflect.Type type = new com.google.gson.reflect.TypeToken