diff --git a/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/ChaosChallenge.java b/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/ChaosChallenge.java new file mode 100644 index 0000000..3a7b216 --- /dev/null +++ b/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/ChaosChallenge.java @@ -0,0 +1,9 @@ +package de.fanta.challenge.challenges.chaoschallenge; + +import de.fanta.challenge.Challenge; + +public class ChaosChallenge { + private Challenge plugin; + + +} diff --git a/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/SimpleIRCClient.java b/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/SimpleIRCClient.java new file mode 100644 index 0000000..5872b07 --- /dev/null +++ b/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/SimpleIRCClient.java @@ -0,0 +1,42 @@ +package de.fanta.challenge.challenges.chaoschallenge; + +import javax.net.ssl.SSLSocket; +import javax.net.ssl.SSLSocketFactory; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.PrintWriter; + +public class SimpleIRCClient { + + private static final String SERVER = "libera.chat"; + private static final int PORT = 6697; + private static final String CHANNEL = "fantahund"; + + public static void main(String[] args) { + new SimpleIRCClient().connect(); + } + + public void connect() { + try { + SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault(); + SSLSocket socket = (SSLSocket) factory.createSocket(SERVER, PORT); + + PrintWriter out = new PrintWriter(socket.getOutputStream(), true); + BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); + + out.println("JoinChannel: " + CHANNEL); + + String line; + while ((line = in.readLine()) != null) { + System.out.println(line); + } + + in.close(); + out.close(); + socket.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} + diff --git a/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/Action.java b/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/Action.java new file mode 100644 index 0000000..e13db9e --- /dev/null +++ b/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/Action.java @@ -0,0 +1,9 @@ +package de.fanta.challenge.challenges.chaoschallenge.actions; + +public interface Action { + + + ActionType getActionType(); + + void execute(); +} diff --git a/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/ActionType.java b/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/ActionType.java new file mode 100644 index 0000000..949b43c --- /dev/null +++ b/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/ActionType.java @@ -0,0 +1,13 @@ +package de.fanta.challenge.challenges.chaoschallenge.actions; + +public enum ActionType { + SPAWN_MOB, + TELEPORT, + TELEPORT_OTHER_WORLD, + TELEPORT_STRUCTURE, + GIVE_ITEM, + CLEAR_RANDOM_INVENTORY_SLOT, + CLEAR_INVENTORY, + GIVE_EFFECT, + TROLL +} diff --git a/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/ClearInventoryAction.java b/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/ClearInventoryAction.java new file mode 100644 index 0000000..434993f --- /dev/null +++ b/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/ClearInventoryAction.java @@ -0,0 +1,22 @@ +package de.fanta.challenge.challenges.chaoschallenge.actions; + +import de.fanta.challenge.Challenge; + +public class ClearInventoryAction implements Action { + + private final Challenge plugin; + + public ClearInventoryAction(Challenge plugin) { + this.plugin = plugin; + } + + @Override + public ActionType getActionType() { + return ActionType.CLEAR_INVENTORY; + } + + @Override + public void execute() { + plugin.getVanish().getPlayerListWithoutVanishPlayers().forEach(player -> player.getInventory().clear()); + } +} diff --git a/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/GiveItemAction.java b/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/GiveItemAction.java new file mode 100644 index 0000000..e89793e --- /dev/null +++ b/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/GiveItemAction.java @@ -0,0 +1,35 @@ +package de.fanta.challenge.challenges.chaoschallenge.actions; + +import de.fanta.challenge.Challenge; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +import java.util.Collection; + +public class GiveItemAction implements Action { + + private final Challenge plugin; + private final Material item; + private final int amount; + + public GiveItemAction(Challenge plugin, Material item, int amount) { + this.plugin = plugin; + this.item = item; + this.amount = amount; + } + + @Override + public ActionType getActionType() { + return ActionType.GIVE_ITEM; + } + + @Override + public void execute() { + plugin.getVanish().getPlayerListWithoutVanishPlayers().forEach(player -> { + Collection dropItems = player.getInventory().addItem(new ItemStack(item, amount)).values(); + Location dropLocation = player.getLocation().clone().toCenterLocation(); + dropItems.forEach(stack -> dropLocation.getWorld().dropItem(dropLocation, stack)); + }); + } +} diff --git a/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/SpawnMobAction.java b/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/SpawnMobAction.java new file mode 100644 index 0000000..e938f70 --- /dev/null +++ b/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/SpawnMobAction.java @@ -0,0 +1,39 @@ +package de.fanta.challenge.challenges.chaoschallenge.actions; + + +import de.fanta.challenge.Challenge; +import de.fanta.challengeutils.LocationUtils; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.EntityType; + +public class SpawnMobAction implements Action { + + private final Challenge plugin; + private final EntityType entityType; + private final int amount; + private final int radius; + + public SpawnMobAction(Challenge plugin, EntityType entityType, int amount, int radius) { + this.plugin = plugin; + this.entityType = entityType; + this.amount = amount; + this.radius = radius; + } + + @Override + public ActionType getActionType() { + return ActionType.SPAWN_MOB; + } + + @Override + public void execute() { + for (int i = 0; i < amount; i++) { + plugin.getVanish().getPlayerListWithoutVanishPlayers().forEach(player -> { + World world = player.getWorld(); + Location randomLocation = LocationUtils.getRandomLocationAroundPlayer(player, radius, true); + world.spawnEntity(randomLocation, entityType); + }); + } + } +} diff --git a/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/TeleportAction.java b/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/TeleportAction.java new file mode 100644 index 0000000..b5af5cc --- /dev/null +++ b/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/TeleportAction.java @@ -0,0 +1,28 @@ +package de.fanta.challenge.challenges.chaoschallenge.actions; +import de.fanta.challenge.Challenge; +import de.fanta.challengeutils.LocationUtils; +import org.bukkit.Location; + +public class TeleportAction implements Action { + + private final Challenge plugin; + private final int radius; + + public TeleportAction(Challenge plugin, int radius) { + this.plugin = plugin; + this.radius = radius; + } + + @Override + public ActionType getActionType() { + return ActionType.TELEPORT; + } + + @Override + public void execute() { + plugin.getVanish().getPlayerListWithoutVanishPlayers().forEach(player -> { + Location teleportLocation = LocationUtils.getRandomLocationAroundPlayer(player, radius, true); + player.teleport(teleportLocation); + }); + } +} diff --git a/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/TeleportStructureAction.java b/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/TeleportStructureAction.java new file mode 100644 index 0000000..7aa3d80 --- /dev/null +++ b/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/TeleportStructureAction.java @@ -0,0 +1,40 @@ +package de.fanta.challenge.challenges.chaoschallenge.actions; + +import de.fanta.challenge.Challenge; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.generator.structure.Structure; +import org.bukkit.util.StructureSearchResult; + +public class TeleportStructureAction implements Action { + + private final Challenge plugin; + private final Structure structure; + + public TeleportStructureAction(Challenge plugin, Structure structure) { + this.plugin = plugin; + this.structure = structure; + } + + @Override + public ActionType getActionType() { + return ActionType.TELEPORT_STRUCTURE; + } + + @Override + public void execute() { + StructureSearchResult searchResult; + for (Player player : plugin.getVanish().getPlayerListWithoutVanishPlayers()) { + World world = player.getWorld(); + searchResult = world.locateNearestStructure(player.getLocation(), structure, 2500, false); + if (searchResult != null) { + for (Player tpPlayer : plugin.getVanish().getPlayerListWithoutVanishPlayers()) { + Location location = searchResult.getLocation(); + tpPlayer.teleport(location); + } + return; + } + } + } +} diff --git a/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/TeleportToOtherWorldAction.java b/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/TeleportToOtherWorldAction.java new file mode 100644 index 0000000..94f4904 --- /dev/null +++ b/Challenge/src/main/java/de/fanta/challenge/challenges/chaoschallenge/actions/TeleportToOtherWorldAction.java @@ -0,0 +1,43 @@ +package de.fanta.challenge.challenges.chaoschallenge.actions; + +import de.fanta.challenge.Challenge; +import de.fanta.challengeutils.LocationUtils; +import org.bukkit.Location; +import org.bukkit.World; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Random; + +public class TeleportToOtherWorldAction implements Action { + + private final Challenge plugin; + + public TeleportToOtherWorldAction(Challenge plugin) { + this.plugin = plugin; + } + + @Override + public ActionType getActionType() { + return ActionType.TELEPORT_OTHER_WORLD; + } + + @Override + public void execute() { + Random r = new Random(); + plugin.getVanish().getPlayerListWithoutVanishPlayers().forEach(player -> { + List worlds = new ArrayList<>(); + worlds.add("world"); + worlds.add("world_nether"); + worlds.add("world_the_end"); + worlds.remove(player.getWorld().getName()); + String worldName = worlds.get(r.nextInt((worlds.size() - 1) + 1)); + World world = plugin.getServer().getWorld(worldName); + Location spawnLocation = LocationUtils.getRandomLocationAroundLocation(world.getSpawnLocation(), 10000, true); + player.teleport(spawnLocation); + }); + + + } +} diff --git a/ChallengeUtils/src/main/java/de/fanta/challengeutils/LocationUtils.java b/ChallengeUtils/src/main/java/de/fanta/challengeutils/LocationUtils.java new file mode 100644 index 0000000..f7917a4 --- /dev/null +++ b/ChallengeUtils/src/main/java/de/fanta/challengeutils/LocationUtils.java @@ -0,0 +1,116 @@ +package de.fanta.challengeutils; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.util.BoundingBox; + +import java.util.List; +import java.util.Random; + +public class LocationUtils { + + private static final int MAX_ATTEMPTS = 10; // Maximale Versuche, um eine sichere Location zu finden + + public static Location getRandomLocationAroundPlayer(Player player, double radius) { + return getRandomLocationAroundLocation(player.getLocation(), radius, false); + } + + public static Location getRandomLocationAroundPlayer(Player player, double radius, boolean findSafeLocation) { + return getRandomLocationAroundLocation(player.getLocation(), radius, findSafeLocation); + } + + public static Location getRandomLocationAroundLocation(Location location, double radius) { + return getRandomLocationAroundLocation(location, radius, false); + } + + public static Location getRandomLocationAroundLocation(Location location, double radius, boolean findSafeLocation) { + Random random = new Random(); + World world = location.getWorld(); + int maxHeight = world.getMaxHeight(); + int minHeight = world.getMinHeight() + 5; //+5 Weil Bedrock + + if (world.getEnvironment() == World.Environment.NETHER) { + maxHeight = 122; //Max Logical height in Nether + } + + if (findSafeLocation) { + for (int attempt = 0; attempt < MAX_ATTEMPTS; attempt++) { + double angle = random.nextDouble() * 2 * Math.PI; + double distance = random.nextDouble() * radius; + double xOffset = Math.cos(angle) * distance; + double zOffset = Math.sin(angle) * distance; + + double newX = location.getX() + xOffset; + double newZ = location.getZ() + zOffset; + double newY = random.nextDouble() * (maxHeight - minHeight) + minHeight; + + Location newLocation = new Location(world, newX, newY, newZ); + + if (isSafeLocation(newLocation)) { + return newLocation; + } + } + } + + double finalAngle = random.nextDouble() * 2 * Math.PI; + double finalDistance = random.nextDouble() * radius; + double finalXOffset = Math.cos(finalAngle) * finalDistance; + double finalZOffset = Math.sin(finalAngle) * finalDistance; + + double finalX = location.getX() + finalXOffset; + double finalZ = location.getZ() + finalZOffset; + double finalY = random.nextDouble() * (maxHeight - minHeight) + minHeight; + + return new Location(location.getWorld(), finalX, finalY, finalZ); + } + + private static boolean isSafeLocation(Location location) { + World world = location.getWorld(); + int x = location.getBlockX(); + int y = location.getBlockY(); + int z = location.getBlockZ(); + + if (world.getBlockAt(x, y - 1, z).getType().isSolid()) { + return world.getBlockAt(x, y, z).getType() == Material.AIR && world.getBlockAt(x, y + 1, z).getType() == Material.AIR; + } + return false; + } + + public static BoundingBox calculateEnclosingBoundingBox(List boxes) { + if (boxes == null || boxes.isEmpty()) { + throw new IllegalArgumentException("Error while the bounding box list is null or Empty"); + } + + double minX = boxes.getFirst().getMinX(); + double minY = boxes.getFirst().getMinY(); + double minZ = boxes.getFirst().getMinZ(); + double maxX = boxes.getFirst().getMaxX(); + double maxY = boxes.getFirst().getMaxY(); + double maxZ = boxes.getFirst().getMaxZ(); + + for (BoundingBox box : boxes) { + if (box.getMinX() < minX) { + minX = box.getMinX(); + } + if (box.getMinY() < minY) { + minY = box.getMinY(); + } + if (box.getMinZ() < minZ) { + minZ = box.getMinZ(); + } + if (box.getMaxX() > maxX) { + maxX = box.getMaxX(); + } + if (box.getMaxY() > maxY) { + maxY = box.getMaxY(); + } + if (box.getMaxZ() > maxZ) { + maxZ = box.getMaxZ(); + } + } + + return new BoundingBox(minX, minY, minZ, maxX, maxY, maxZ); + } +}