message
This commit is contained in:
43
src/main/java/hu/jgj52/pvpcore/Commands/FfaCommand.java
Normal file
43
src/main/java/hu/jgj52/pvpcore/Commands/FfaCommand.java
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package hu.jgj52.pvpcore.Commands;
|
||||||
|
|
||||||
|
import hu.jgj52.pvpcore.Main;
|
||||||
|
import hu.jgj52.pvpcore.Utils.Kits;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
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 {
|
||||||
|
public 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 kitManager = new Kits(plugin);
|
||||||
|
try {
|
||||||
|
player.getInventory().setContents(kitManager.getKit("ffa", player, false));
|
||||||
|
player.teleport(Bukkit.getWorld("ffa").getSpawnLocation());
|
||||||
|
plugin.playersInFfa.add(player);
|
||||||
|
} catch (ExecutionException | InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String @NotNull [] strings) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,23 +12,36 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ResetArenasCommand implements CommandExecutor, TabCompleter {
|
public class ResetCommand implements CommandExecutor, TabCompleter {
|
||||||
private final Main plugin;
|
private final Main plugin;
|
||||||
|
|
||||||
public ResetArenasCommand(Main plugin) {
|
public ResetCommand(Main plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
|
||||||
|
if (args.length == 1) {
|
||||||
WorldReset worldReset = new WorldReset(plugin);
|
WorldReset worldReset = new WorldReset(plugin);
|
||||||
|
switch (args[0]) {
|
||||||
|
case "arenas":
|
||||||
worldReset.recreateArenaWorld();
|
worldReset.recreateArenaWorld();
|
||||||
plugin.usedArenas = new ArrayList<>();
|
plugin.usedArenas = new ArrayList<>();
|
||||||
|
break;
|
||||||
|
case "ffa":
|
||||||
|
worldReset.recreateFfaWorld();
|
||||||
|
plugin.playersInFfa = new ArrayList<>();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
|
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
|
||||||
|
if (args.length == 1) {
|
||||||
|
List.of("arenas", "ffa");
|
||||||
|
}
|
||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,29 +15,27 @@ import org.bukkit.event.entity.PlayerDeathEvent;
|
|||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.title.Title;
|
import net.kyori.adventure.title.Title;
|
||||||
import org.bukkit.inventory.meta.FireworkMeta;
|
import org.bukkit.inventory.meta.FireworkMeta;
|
||||||
import org.bukkit.metadata.FixedMetadataValue;
|
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import static java.util.Collections.min;
|
import static java.util.Collections.min;
|
||||||
|
|
||||||
public class DuelEndListener implements Listener {
|
public class PlayerDeathListener implements Listener {
|
||||||
private final Main plugin;
|
private final Main plugin;
|
||||||
|
|
||||||
public DuelEndListener(Main plugin) {
|
public PlayerDeathListener(Main plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onDuelEnd(PlayerDeathEvent e) throws ExecutionException, InterruptedException {
|
public void onDeath(PlayerDeathEvent e) throws ExecutionException, InterruptedException {
|
||||||
Player player = e.getPlayer();
|
Player player = e.getPlayer();
|
||||||
boolean isEnemy = false;
|
boolean isEnemy = false;
|
||||||
Database.QueryResult result = plugin.db.from("pvpcore_duels").eq("player", player.getUniqueId()).execute().get();
|
Database.QueryResult result = plugin.db.from("pvpcore_duels").eq("player", player.getUniqueId()).execute().get();
|
||||||
@@ -217,6 +215,10 @@ public class DuelEndListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.runTaskTimer(plugin, 0L, 20L);
|
}.runTaskTimer(plugin, 0L, 20L);
|
||||||
|
} else if (plugin.playersInFfa.contains(player)) {
|
||||||
|
plugin.tpToSpawn(player);
|
||||||
|
plugin.playersInFfa.remove(player);
|
||||||
|
e.setDeathMessage("§c" + player.getName() + " §7meghalt §c" + player.getKiller() + " §7által");
|
||||||
} else {
|
} else {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
plugin.tpToSpawn(player);
|
plugin.tpToSpawn(player);
|
||||||
@@ -7,7 +7,6 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.metadata.MetadataValue;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
@@ -48,15 +47,16 @@ public final class Main extends JavaPlugin {
|
|||||||
getCommand("acceptduel").setExecutor(new AcceptDuelCommand(this));
|
getCommand("acceptduel").setExecutor(new AcceptDuelCommand(this));
|
||||||
getCommand("denyduel").setExecutor(new DenyDuelCommand(this));
|
getCommand("denyduel").setExecutor(new DenyDuelCommand(this));
|
||||||
getCommand("editkit").setExecutor(new EditKitCommand(this));
|
getCommand("editkit").setExecutor(new EditKitCommand(this));
|
||||||
getCommand("resetarenas").setExecutor(new ResetArenasCommand(this));
|
getCommand("reset").setExecutor(new ResetCommand(this));
|
||||||
getCommand("spectate").setExecutor(new SpectateCommand(this));
|
getCommand("spectate").setExecutor(new SpectateCommand(this));
|
||||||
getCommand("leave").setExecutor(new LeaveCommand(this));
|
getCommand("leave").setExecutor(new LeaveCommand(this));
|
||||||
getCommand("createkit").setExecutor(new CreateKitCommand(this));
|
getCommand("createkit").setExecutor(new CreateKitCommand(this));
|
||||||
getCommand("connect").setExecutor(new ConnectCommand(this));
|
getCommand("connect").setExecutor(new ConnectCommand(this));
|
||||||
|
getCommand("ffa").setExecutor(new FfaCommand(this));
|
||||||
|
|
||||||
getServer().getPluginManager().registerEvents(new DuelRequestListener(this), this);
|
getServer().getPluginManager().registerEvents(new DuelRequestListener(this), this);
|
||||||
getServer().getPluginManager().registerEvents(new KitListener(this), this);
|
getServer().getPluginManager().registerEvents(new KitListener(this), this);
|
||||||
getServer().getPluginManager().registerEvents(new DuelEndListener(this), this);
|
getServer().getPluginManager().registerEvents(new PlayerDeathListener(this), this);
|
||||||
getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
|
getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
|
||||||
getServer().getPluginManager().registerEvents(new SpectatorListener(this), this);
|
getServer().getPluginManager().registerEvents(new SpectatorListener(this), this);
|
||||||
|
|
||||||
@@ -108,4 +108,5 @@ public final class Main extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> usedArenas = new ArrayList<>();
|
public List<Integer> usedArenas = new ArrayList<>();
|
||||||
|
public List<Player> playersInFfa = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.util.io.BukkitObjectInputStream;
|
import org.bukkit.util.io.BukkitObjectInputStream;
|
||||||
import org.bukkit.util.io.BukkitObjectOutputStream;
|
import org.bukkit.util.io.BukkitObjectOutputStream;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.postgresql.util.PGobject;
|
import org.postgresql.util.PGobject;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
|||||||
@@ -69,31 +69,4 @@ public class SchematicManager {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeSchematic(World world, Location loc1, Location loc2) {
|
|
||||||
try {
|
|
||||||
com.sk89q.worldedit.world.World weWorld = BukkitAdapter.adapt(world);
|
|
||||||
|
|
||||||
int minX = Math.min(loc1.getBlockX(), loc2.getBlockX());
|
|
||||||
int maxX = Math.max(loc1.getBlockX(), loc2.getBlockX());
|
|
||||||
int minY = Math.min(loc1.getBlockY(), loc2.getBlockY());
|
|
||||||
int maxY = Math.max(loc1.getBlockY(), loc2.getBlockY());
|
|
||||||
int minZ = Math.min(loc1.getBlockZ(), loc2.getBlockZ());
|
|
||||||
int maxZ = Math.max(loc1.getBlockZ(), loc2.getBlockZ());
|
|
||||||
|
|
||||||
BlockVector3 min = BlockVector3.at(minX, minY, minZ);
|
|
||||||
BlockVector3 max = BlockVector3.at(maxX, maxY, maxZ);
|
|
||||||
CuboidRegion region = new CuboidRegion(weWorld, min, max);
|
|
||||||
|
|
||||||
try (EditSession editSession = WorldEdit.getInstance().newEditSession(weWorld)) {
|
|
||||||
editSession.setBlocks(region, BlockTypes.AIR.getDefaultState());
|
|
||||||
editSession.flushSession();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
plugin.getLogger().severe("Error removing schematic: " + e.getMessage());
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,22 +1,17 @@
|
|||||||
package hu.jgj52.pvpcore.Utils;
|
package hu.jgj52.pvpcore.Utils;
|
||||||
|
|
||||||
|
import hu.jgj52.pvpcore.Main;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.metadata.MetadataValue;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.potion.PotionEffect;
|
|
||||||
import org.bukkit.potion.PotionEffectType;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public class WorldReset {
|
public class WorldReset {
|
||||||
private Plugin plugin;
|
private Main plugin;
|
||||||
|
|
||||||
public WorldReset(Plugin plugin) {
|
public WorldReset(Main plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String[] metadatas = {"DuelingWith", "ArenaLoc", "Frozen", "DuelRequest", "DueledBy", "DueledWithGamemode", "IsSpectating"};
|
|
||||||
|
|
||||||
public boolean recreateArenaWorld() {
|
public boolean recreateArenaWorld() {
|
||||||
String worldName = "arenas";
|
String worldName = "arenas";
|
||||||
|
|
||||||
@@ -43,24 +38,7 @@ public class WorldReset {
|
|||||||
if (world != null) {
|
if (world != null) {
|
||||||
|
|
||||||
world.getPlayers().forEach(player -> {
|
world.getPlayers().forEach(player -> {
|
||||||
Location spawn = new Location(Bukkit.getWorld("world"), 0, 3, 0, 0, 0);
|
plugin.tpToSpawn(player);
|
||||||
for (PotionEffect potionEffect : player.getActivePotionEffects()) {
|
|
||||||
player.removePotionEffect(potionEffect.getType());
|
|
||||||
}
|
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 20, 1), true);
|
|
||||||
player.setHealth(20D);
|
|
||||||
player.setFoodLevel(20);
|
|
||||||
player.setSaturation(5);
|
|
||||||
player.setGameMode(GameMode.ADVENTURE);
|
|
||||||
player.teleport(spawn);
|
|
||||||
for (String key : metadatas) {
|
|
||||||
for (MetadataValue value : player.getMetadata(key)) {
|
|
||||||
if (value.getOwningPlugin() == plugin) {
|
|
||||||
player.removeMetadata(key, plugin);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
player.sendMessage("§cszia resetel a map szoval tunes");
|
player.sendMessage("§cszia resetel a map szoval tunes");
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -98,11 +76,89 @@ public class WorldReset {
|
|||||||
|
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
world.setSpawnFlags(false, false);
|
world.setSpawnFlags(false, false);
|
||||||
world.setTime(6000);
|
|
||||||
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
|
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
|
||||||
world.setStorm(false);
|
world.setStorm(false);
|
||||||
world.setThundering(false);
|
world.setThundering(false);
|
||||||
world.setGameRule(GameRule.DO_WEATHER_CYCLE, false);
|
world.setGameRule(GameRule.DO_WEATHER_CYCLE, false);
|
||||||
|
world.setTime(6000);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
plugin.getLogger().severe("Failed to create arena world!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().severe("Error creating arena world: " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean recreateFfaWorld() {
|
||||||
|
String worldName = "ffa";
|
||||||
|
|
||||||
|
try {
|
||||||
|
removeFfaWorld(worldName);
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
||||||
|
createFfaWorld(worldName);
|
||||||
|
}, 20L);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().severe("Error recreating arena world: " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean removeFfaWorld(String worldName) {
|
||||||
|
try {
|
||||||
|
World world = Bukkit.getWorld(worldName);
|
||||||
|
|
||||||
|
if (world != null) {
|
||||||
|
|
||||||
|
world.getPlayers().forEach(player -> {
|
||||||
|
plugin.tpToSpawn(player);
|
||||||
|
player.sendMessage("§cszia resetel a map szoval tunes");
|
||||||
|
});
|
||||||
|
|
||||||
|
boolean unloaded = Bukkit.unloadWorld(world, false);
|
||||||
|
|
||||||
|
if (unloaded) {
|
||||||
|
File worldFolder = new File(Bukkit.getWorldContainer(), worldName);
|
||||||
|
if (worldFolder.exists()) {
|
||||||
|
deleteDirectory(worldFolder);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
plugin.getLogger().warning("Failed to unload arena world.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().severe("Error removing arena world: " + e.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean createFfaWorld(String worldName) {
|
||||||
|
try {
|
||||||
|
WorldCreator creator = new WorldCreator(worldName)
|
||||||
|
.environment(World.Environment.NORMAL);
|
||||||
|
|
||||||
|
World world = creator.createWorld();
|
||||||
|
|
||||||
|
if (world != null) {
|
||||||
|
world.setSpawnFlags(false, false);
|
||||||
|
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
|
||||||
|
world.setStorm(false);
|
||||||
|
world.setThundering(false);
|
||||||
|
world.setTime(6000);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
plugin.getLogger().severe("Failed to create arena world!");
|
plugin.getLogger().severe("Failed to create arena world!");
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ commands:
|
|||||||
acceptduel:
|
acceptduel:
|
||||||
denyduel:
|
denyduel:
|
||||||
editkit:
|
editkit:
|
||||||
resetarenas:
|
reset:
|
||||||
permission: pvpcore.resetarenas
|
permission: pvpcore.command.reset
|
||||||
spectate:
|
spectate:
|
||||||
leave:
|
leave:
|
||||||
createkit:
|
createkit:
|
||||||
permission: pvpcore.createkit
|
permission: pvpcore.command.createkit
|
||||||
connect:
|
connect:
|
||||||
Reference in New Issue
Block a user