This commit is contained in:
2025-07-29 18:30:50 +02:00
parent 75821ad369
commit 79620b6787
14 changed files with 252 additions and 28 deletions

View File

@@ -2,7 +2,8 @@ package lnmpro.Commands;
import lnmpro.Main;
import lnmpro.Utils.Kits;
import lnmpro.Utils.SchematicPlacer;
import lnmpro.Utils.SchematicManager;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
@@ -12,14 +13,19 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import static java.util.Collections.emptyList;
import static java.util.Collections.min;
public class AcceptDuelCommand implements CommandExecutor, TabCompleter {
private final Main plugin;
@@ -32,29 +38,80 @@ public class AcceptDuelCommand implements CommandExecutor, TabCompleter {
if (sender instanceof Player player) {
if (player.hasMetadata("DueledBy")) {
Kits kitManager = new Kits(plugin);
SchematicPlacer schematic = new SchematicPlacer(plugin);
SchematicManager schematic = new SchematicManager(plugin);
UUID targetUUID = UUID.fromString(player.getMetadata("DueledBy").get(0).asString());
Player enemy = Bukkit.getPlayer(targetUUID);
String gamemode = player.getMetadata("DueledWithGamemode").get(0).asString();
enemy.sendMessage("cica " + gamemode);
player.sendMessage("cica " + gamemode);
player.removeMetadata("DueledBy", plugin);
player.removeMetadata("DueledWithGamemode", plugin);
player.getInventory().clear();
enemy.getInventory().clear();
player.getInventory().setContents(kitManager.getAxeKit(player).getContents());
enemy.getInventory().setContents(kitManager.getAxeKit(player).getContents());
int x = 0;
String arena = "";
if (gamemode.equals("uhc")) {
x = 1000;
arena = "football";
player.getInventory().setContents(kitManager.getUhcKit(player).getContents());
enemy.getInventory().setContents(kitManager.getUhcKit(player).getContents());
} else if (gamemode.equals("pot")) {
x = 0;
arena = "";
} else if (gamemode.equals("nethpot")) {
x = 0;
arena = "";
} else if (gamemode.equals("smp")) {
x = 0;
arena = "";
} else if (gamemode.equals("sword")) {
x = 1400;
arena = "football";
player.getInventory().setContents(kitManager.getSwordKit(player).getContents());
enemy.getInventory().setContents(kitManager.getSwordKit(player).getContents());
} else if (gamemode.equals("axe")) {
x = 1500;
arena = "football";
player.getInventory().setContents(kitManager.getAxeKit(player).getContents());
enemy.getInventory().setContents(kitManager.getAxeKit(player).getContents());
} else if (gamemode.equals("mace")) {
x = 0;
arena = "";
player.getInventory().setContents(kitManager.getMaceKit(player).getContents());
enemy.getInventory().setContents(kitManager.getMaceKit(player).getContents());
} else if (gamemode.equals("cart")) {
x = 0;
arena = "";
} else if (gamemode.equals("diasmp")) {
x = 1800;
arena = "football";
player.getInventory().setContents(kitManager.getDiaSMPKit(player).getContents());
enemy.getInventory().setContents(kitManager.getDiaSMPKit(player).getContents());
} else if (gamemode.equals("shieldlessuhc")) {
x = 0;
arena = "";
}
World world = Bukkit.getWorld("world");
int x = 1000;
int y = 0;
int z = -2000;
int z;
schematic.placeSchematic(world, x, y, z, "football");
Location playerLoc = new Location(world, x + 19.5, y + 0.5, z + 0.5, 90, 0);
Location enemyLoc = new Location(world, x - 17.5, y + 0.5, z + 0.5, -90, 0);
if (plugin.usedArenas.isEmpty()) {
z = -2000;
} else {
z = min(plugin.usedArenas) - 1;
}
plugin.usedArenas.add(z);
schematic.placeSchematic(world, x, y, z, arena, true);
Location playerLoc = new Location(world, x + 19.5, y, z + 0.5, 90, 0);
Location enemyLoc = new Location(world, x - 17.5, y, z + 0.5, -90, 0);
for (PotionEffect potionEffect : player.getActivePotionEffects()) {
player.removePotionEffect(potionEffect.getType());
@@ -75,6 +132,45 @@ public class AcceptDuelCommand implements CommandExecutor, TabCompleter {
player.setGameMode(GameMode.ADVENTURE);
enemy.setGameMode(GameMode.ADVENTURE);
player.setMetadata("DuelingWith", new FixedMetadataValue(plugin, enemy.getUniqueId()));
enemy.setMetadata("DuelingWith", new FixedMetadataValue(plugin, player.getUniqueId()));
player.setMetadata("ArenaLoc", new FixedMetadataValue(plugin, new Location(world, x, y, z)));
enemy.setMetadata("ArenaLoc", new FixedMetadataValue(plugin, new Location(world, x, y, z)));
player.setMetadata("Frozen", new FixedMetadataValue(plugin, true));
enemy.setMetadata("Frozen", new FixedMetadataValue(plugin, true));
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);
player.removeMetadata("Frozen", plugin);
enemy.removeMetadata("Frozen", plugin);
cancel();
}
}
}.runTaskTimer(plugin, 0L, 20L);
}
} else {
sender.sendMessage("nem vagy player nem fog sikerulni");
@@ -82,6 +178,7 @@ public class AcceptDuelCommand implements CommandExecutor, TabCompleter {
return true;
}
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
return List.of();

View File

@@ -39,7 +39,7 @@ public class DuelCommand implements CommandExecutor, TabCompleter {
if (args.length != 1) {
player.sendMessage("§a Használat");
player.sendMessage("§a----------------------------------------");
player.sendMessage("§a/duel [játékos] » Meghívás egy párbajra"); //valew ez rohadtul ainak hangzik ird mar at
player.sendMessage("§a/duel [játékos] » Meghívás egy párbajra");
return true;
}
@@ -49,7 +49,7 @@ public class DuelCommand implements CommandExecutor, TabCompleter {
return true;
}
if (target.hasMetadata("DueledBy") && target.getMetadata("DueledBy").get(0).asString().equals(player.getUniqueId().toString())) {
player.sendMessage("§7[§9§lInsane§e§lDuels§7] §7» §e" + target.getName() + "§9-nek már küldtél párbaj kérelmet.");
player.sendMessage("§7[§9§lInsane§e§lDuels§7] §7» §e" + target.getName() + "§9 játékosnak már küldtél párbaj kérelmet.");
return true;
}

View File

@@ -0,0 +1,94 @@
package lnmpro.Listeners;
import lnmpro.Main;
import lnmpro.Utils.SchematicManager;
import org.bukkit.*;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import java.time.Duration;
import java.util.List;
import java.util.UUID;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.title.Title;
import org.bukkit.inventory.meta.FireworkMeta;
public class DuelEndListener implements Listener {
private final Main plugin;
public DuelEndListener(Main plugin) {
this.plugin = plugin;
}
@EventHandler
public void onDuelEnd(PlayerDeathEvent e) {
Player player = e.getPlayer();
if (player.hasMetadata("DuelingWith")) {
SchematicManager schematic = new SchematicManager(plugin);
UUID targetUUID = UUID.fromString(player.getMetadata("DuelingWith").get(0).asString());
Player enemy = Bukkit.getPlayer(targetUUID);
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 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(1);
firework.setFireworkMeta(meta);
}, delay);
}
player.showTitle(loserTitle);
enemy.showTitle(winnerTitle);
Bukkit.getScheduler().runTaskLater(plugin, () -> {
try {
Location arenaLoc = (Location) player.getMetadata("ArenaLoc").get(0).value();
Location loc1 = new Location(arenaLoc.getWorld(), arenaLoc.getX() - 36, arenaLoc.getY() - 4, arenaLoc.getZ() - 30);
Location loc2 = new Location(arenaLoc.getWorld(), arenaLoc.getX() + 36, arenaLoc.getY() + 11, arenaLoc.getZ() + 30);
schematic.removeSchematic(arenaLoc.getWorld(), loc1, loc2);
Location spawn = new Location(Bukkit.getWorld("world"), 0, 3, 0, 0, 0);
player.setGameMode(GameMode.ADVENTURE);
enemy.setGameMode(GameMode.ADVENTURE);
player.teleport(spawn);
enemy.teleport(spawn);
} catch (Exception exception) {
exception.printStackTrace();
}
}, 60L);
}
}
}

View File

@@ -4,6 +4,9 @@ import org.bukkit.plugin.java.JavaPlugin;
import lnmpro.Commands.*;
import lnmpro.Listeners.*;
import java.util.ArrayList;
import java.util.List;
public final class Main extends JavaPlugin {
private static Main instance;
@@ -20,6 +23,8 @@ public final class Main extends JavaPlugin {
getServer().getPluginManager().registerEvents(new DuelRequestListener(this), this);
getServer().getPluginManager().registerEvents(new KitListener(this), this);
getServer().getPluginManager().registerEvents(new DuelEndListener(this), this);
getServer().getPluginManager().registerEvents(new FreezeListener(), this);
instance = this;
}
@@ -27,4 +32,6 @@ public final class Main extends JavaPlugin {
public static Main getInstance() {
return instance;
}
public List<Integer> usedArenas = new ArrayList<>();
}

View File

@@ -9,8 +9,11 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.history.change.BlockChange;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import lnmpro.Main;
import org.bukkit.Location;
import org.bukkit.World;
@@ -19,13 +22,14 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class SchematicPlacer {
public class SchematicManager {
private final Main plugin;
public SchematicPlacer(Main plugin) {
public SchematicManager(Main plugin) {
this.plugin = plugin;
}
public boolean placeSchematic(World world, int x, int y, int z, String schematicName) {
public boolean placeSchematic(World world, int x, int y, int z, String schematicName, boolean air) {
File schematicFile = new File(plugin.getDataFolder() + File.separator + "schematics", schematicName + ".schem");
if (!schematicFile.exists()) {
@@ -49,7 +53,7 @@ public class SchematicPlacer {
Operation operation = new ClipboardHolder(clipboard)
.createPaste(editSession)
.to(BlockVector3.at(x, y, z))
.ignoreAirBlocks(false)
.ignoreAirBlocks(air)
.build();
Operations.complete(operation);
@@ -67,13 +71,30 @@ public class SchematicPlacer {
return false;
}
public boolean placeSchematic(Location location, String schematicName) {
return placeSchematic(
location.getWorld(),
location.getBlockX(),
location.getBlockY(),
location.getBlockZ(),
schematicName
);
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;
}
}
}