NEWS: Welcome to my new homepage! <3

feat: Formatted code & added world constants - poppy - A feature-rich Minecraft plugin which enhances gaming experience

poppy

A feature-rich Minecraft plugin which enhances gaming experience
git clone git://192.168.2.2/poppy
Log | Files | Refs | README

commit 0df3308fe33ca07928b1237660aaf10d453836f6
parent 6fecb992f53fd9c94fc2f3e7f2f7271088cb079e
Author: typable <contact@typable.dev>
Date:   Thu, 16 Nov 2023 14:19:31 +0100

feat: Formatted code & added world constants

Diffstat:
Msrc/poppy/Constants.java | 9+++++++++
Msrc/poppy/Main.java | 105+++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
2 files changed, 80 insertions(+), 34 deletions(-)

diff --git a/src/poppy/Constants.java b/src/poppy/Constants.java @@ -11,6 +11,15 @@ public class Constants public static final int MIN_FEE = 1; public static final int MAX_FEE = 64; + public static final class Worlds + { + public static final String DEFAULT = "world"; + public static final String SURVIVAL = "survival"; + public static final String SURVIVAL_NETHER = "survival_nether"; + public static final String SURVIVAL_THE_END = "survival_the_end"; + public static final String BACKROOMS = "creative"; + } + public static final class Messages { public static final String NOT_ENOUGH_PERMISSION = ChatColor.RED + "You don't have enough Permission to perform this command!"; diff --git a/src/poppy/Main.java b/src/poppy/Main.java @@ -110,22 +110,22 @@ public class Main extends JavaPlugin implements Listener FurnaceRecipe recipe = new FurnaceRecipe(key, new ItemStack(Material.LEATHER), Material.ROTTEN_FLESH, 1, 200); Bukkit.addRecipe(recipe); - new WorldCreator("creative") + new WorldCreator(Constants.Worlds.BACKROOMS) .type(WorldType.FLAT) .generateStructures(false) .createWorld(); - new WorldCreator("survival") + new WorldCreator(Constants.Worlds.SURVIVAL) .type(WorldType.NORMAL) .generateStructures(true) .createWorld(); - new WorldCreator("survival_nether") + new WorldCreator(Constants.Worlds.SURVIVAL_NETHER) .environment(Environment.NETHER) .generateStructures(true) .createWorld(); - new WorldCreator("survival_the_end") + new WorldCreator(Constants.Worlds.SURVIVAL_THE_END) .environment(Environment.THE_END) .generateStructures(true) .createWorld(); @@ -190,45 +190,73 @@ public class Main extends JavaPlugin implements Listener public void onPlayerPortal(final PlayerPortalEvent event) { final Player player = event.getPlayer(); + final String worldName = player.getWorld().getName(); - if (event.getCause() == TeleportCause.NETHER_PORTAL); + if (event.getCause() == TeleportCause.NETHER_PORTAL) { - if (player.getWorld().getName().equals("survival")) + if (worldName.equals(Constants.Worlds.SURVIVAL)) { - event.setTo(new Location(Bukkit.getWorld("survival_nether"), event.getFrom().getBlockX() / 8, event.getFrom().getBlockY(), event.getFrom().getBlockZ() / 8)); + final Location location = new Location( + Bukkit.getWorld(Constants.Worlds.SURVIVAL_NETHER), + event.getFrom().getBlockX() / 8, + event.getFrom().getBlockY(), + event.getFrom().getBlockZ() / 8 + ); + event.setTo(location); } - - else if (player.getWorld().getName().equals("survival_nether")) + else if (worldName.equals(Constants.Worlds.SURVIVAL_NETHER)) { - event.setTo(new Location(Bukkit.getWorld("survival"), event.getFrom().getBlockX() * 8, event.getFrom().getBlockY(), event.getFrom().getBlockZ() * 8)); + final Location location = new Location( + Bukkit.getWorld(Constants.Worlds.SURVIVAL), + event.getFrom().getBlockX() * 8, + event.getFrom().getBlockY(), + event.getFrom().getBlockZ() * 8 + ); + event.setTo(location); } } - // TODO ugly code quick fix only!!! - if (event.getCause() == TeleportCause.END_PORTAL) { - if (player.getWorld().getName().equals("survival")) { - Location loc = new Location(Bukkit.getWorld("survival_the_end"), 100, 50, 0); - event.setTo(loc); - Block block = loc.getBlock(); - for (int x = block.getX() - 2; x <= block.getX() + 2; x++) { - for (int z = block.getZ() - 2; z <= block.getZ() + 2; z++) { - Block platformBlock = loc.getWorld().getBlockAt(x, block.getY() - 1, z); - if (platformBlock.getType() != Material.OBSIDIAN) { - platformBlock.setType(Material.OBSIDIAN); - } - for (int yMod = 1; yMod <= 3; yMod++) { - Block b = platformBlock.getRelative(BlockFace.UP, yMod); - if (b.getType() != Material.AIR) { - b.setType(Material.AIR); - } - } - } - } - } else if (player.getWorld().getName().equals("survival_the_end")) { - event.setTo(Bukkit.getWorld("survival").getSpawnLocation()); + if (worldName.equals(Constants.Worlds.SURVIVAL)) + { + final Location location = new Location( + Bukkit.getWorld(Constants.Worlds.SURVIVAL_THE_END), + 100, + 50, + 0 + ); + event.setTo(location); + + final Block block = location.getBlock(); + + for (int x = block.getX() - 2; x <= block.getX() + 2; x++) + { + for (int z = block.getZ() - 2; z <= block.getZ() + 2; z++) + { + final Block platformBlock = location.getWorld().getBlockAt(x, block.getY() - 1, z); + + if (platformBlock.getType() != Material.OBSIDIAN) + { + platformBlock.setType(Material.OBSIDIAN); + } + + for (int yMod = 1; yMod <= 3; yMod++) + { + final Block b = platformBlock.getRelative(BlockFace.UP, yMod); + + if (b.getType() != Material.AIR) + { + b.setType(Material.AIR); + } } + } + } + } + else if (worldName.equals(Constants.Worlds.SURVIVAL_THE_END)) + { + event.setTo(Bukkit.getWorld(Constants.Worlds.SURVIVAL).getSpawnLocation()); + } } } @@ -512,7 +540,16 @@ public class Main extends JavaPlugin implements Listener } player.teleport(world.getSpawnLocation()); - player.setGameMode(GameMode.SURVIVAL); + + if (world.getName().equals(Constants.Worlds.BACKROOMS)) + { + player.setGameMode(GameMode.ADVENTURE); + } + else + { + player.setGameMode(GameMode.SURVIVAL); + } + player.sendMessage(ChatColor.GRAY + "You've been teleported to world " + name + "."); return true; @@ -520,7 +557,7 @@ public class Main extends JavaPlugin implements Listener private boolean changeGameMode(final Player player) { - if (!"world".equals(player.getWorld().getName())) { + if (!Constants.Worlds.DEFAULT.equals(player.getWorld().getName())) { player.sendMessage(ChatColor.RED + "This is not a creative world!"); return true; }