QUOTE: Love yourself first, then others.

feat: Added gm & world command - 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 cfd176766471d98f87650ea9e3b8c47547c0ab53
parent 3e03b64e498b4170940752d9a9720bef905cabef
Author: typable <contact@typable.dev>
Date:   Fri,  3 Nov 2023 22:26:31 +0100

feat: Added gm & world command

Diffstat:
Msrc/poppy/Main.java | 55++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 54 insertions(+), 1 deletion(-)

diff --git a/src/poppy/Main.java b/src/poppy/Main.java @@ -6,6 +6,7 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.NamespacedKey; +import org.bukkit.World; import org.bukkit.WorldCreator; import org.bukkit.WorldType; import org.bukkit.block.Block; @@ -14,7 +15,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.FurnaceRecipe; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.RecipeChoice; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.BookMeta; import org.bukkit.plugin.Plugin; @@ -106,6 +106,11 @@ public class Main extends JavaPlugin .type(WorldType.FLAT) .generateStructures(false) .createWorld(); + + new WorldCreator("survival") + .type(WorldType.NORMAL) + .generateStructures(true) + .createWorld(); } @Override @@ -151,6 +156,10 @@ public class Main extends JavaPlugin return openEnderChest(player, args); case "enderchest": return openEnderChest(player, args); + case "world": + return teleportToWorld(player, args); + case "gm": + return changeGameMode(player); default: return false; } @@ -421,4 +430,48 @@ public class Main extends JavaPlugin return true; } + + private boolean teleportToWorld(final Player player, final String[] args) + { + if (args.length != 1) + { + return false; + } + + final String name = args[0].toLowerCase(); + final World world = Bukkit.getServer().getWorld(name); + + if (world == null) + { + player.sendMessage(ChatColor.RED + "World " + name + " doesn't exist!"); + return true; + } + + player.teleport(world.getSpawnLocation()); + player.setGameMode(GameMode.SURVIVAL); + player.sendMessage(ChatColor.GRAY + "You've been teleported to world " + name + "."); + + return true; + } + + private boolean changeGameMode(final Player player) + { + if (!"overworld".equals(player.getWorld().getName())) { + player.sendMessage(ChatColor.RED + "This is not a creative world!"); + return true; + } + + if (GameMode.SURVIVAL.equals(player.getGameMode())) + { + player.setGameMode(GameMode.CREATIVE); + player.sendMessage(ChatColor.GRAY + "Changed gamemode to creative."); + } + else + { + player.setGameMode(GameMode.SURVIVAL); + player.sendMessage(ChatColor.GRAY + "Changed gamemode to survival."); + } + + return true; + } }