From b51df4cc6b09a3bd234165f326484a2ce3b4ad37 Mon Sep 17 00:00:00 2001 From: Super_ Date: Sat, 31 Oct 2020 00:51:22 -0400 Subject: [PATCH] Wow --- src/main/java/me/totalfreedom/plex/Plex.java | 15 ++- .../plex/command/PlexCommand.java | 16 --- .../plex/command/impl/CommandParameters.java | 12 ++ .../plex/command/impl/CommandPermissions.java | 13 +++ .../plex/command/impl/CommandSource.java | 25 +++++ .../plex/command/impl/PlexCommand.java | 106 ++++++++++++++++++ .../command/impl/RequiredCommandSource.java | 8 ++ .../me/totalfreedom/plex/rank/enums/Rank.java | 2 +- .../me/totalfreedom/plex/world/Flatlands.java | 58 ++++++++++ .../plex/world/impl/CustomChunkGenerator.java | 27 +++++ .../plex/world/impl/CustomWorld.java | 28 +++++ .../plex/world/impl/FlatChunkGenerator.java | 29 +++++ .../plex/world/impl/NoiseChunkGenerator.java | 36 ++++++ .../plex/world/impl/NoiseOptions.java | 26 +++++ .../plex/world/impl/OctaveChunkGenerator.java | 36 ++++++ .../plex/world/impl/OctaveOptions.java | 15 +++ src/main/resources/config.yml | 8 ++ 17 files changed, 440 insertions(+), 20 deletions(-) delete mode 100644 src/main/java/me/totalfreedom/plex/command/PlexCommand.java create mode 100644 src/main/java/me/totalfreedom/plex/command/impl/CommandParameters.java create mode 100644 src/main/java/me/totalfreedom/plex/command/impl/CommandPermissions.java create mode 100644 src/main/java/me/totalfreedom/plex/command/impl/CommandSource.java create mode 100644 src/main/java/me/totalfreedom/plex/command/impl/PlexCommand.java create mode 100644 src/main/java/me/totalfreedom/plex/command/impl/RequiredCommandSource.java create mode 100644 src/main/java/me/totalfreedom/plex/world/Flatlands.java create mode 100644 src/main/java/me/totalfreedom/plex/world/impl/CustomChunkGenerator.java create mode 100644 src/main/java/me/totalfreedom/plex/world/impl/CustomWorld.java create mode 100644 src/main/java/me/totalfreedom/plex/world/impl/FlatChunkGenerator.java create mode 100644 src/main/java/me/totalfreedom/plex/world/impl/NoiseChunkGenerator.java create mode 100644 src/main/java/me/totalfreedom/plex/world/impl/NoiseOptions.java create mode 100644 src/main/java/me/totalfreedom/plex/world/impl/OctaveChunkGenerator.java create mode 100644 src/main/java/me/totalfreedom/plex/world/impl/OctaveOptions.java diff --git a/src/main/java/me/totalfreedom/plex/Plex.java b/src/main/java/me/totalfreedom/plex/Plex.java index d10cfd3..eb18dad 100644 --- a/src/main/java/me/totalfreedom/plex/Plex.java +++ b/src/main/java/me/totalfreedom/plex/Plex.java @@ -4,7 +4,6 @@ import lombok.Getter; import lombok.Setter; import me.totalfreedom.plex.cache.MongoPlayerData; import me.totalfreedom.plex.cache.SQLPlayerData; -import me.totalfreedom.plex.command.PlexCommand; import me.totalfreedom.plex.config.MainConfig; import me.totalfreedom.plex.listener.ChatListener; import me.totalfreedom.plex.listener.PlayerListener; @@ -15,6 +14,8 @@ import me.totalfreedom.plex.storage.SQLConnection; import me.totalfreedom.plex.storage.StorageType; import me.totalfreedom.plex.util.PlexLog; import me.totalfreedom.plex.util.PlexUtils; +import me.totalfreedom.plex.world.Flatlands; +import org.bukkit.World; import org.bukkit.plugin.java.JavaPlugin; @Getter @@ -34,6 +35,8 @@ public class Plex extends JavaPlugin private RankManager rankManager; + public World flatlands; + public static Plex get() { return plugin; @@ -91,8 +94,7 @@ public class Plex extends JavaPlugin rankManager.importDefaultRanks(); PlexLog.log("Rank Manager initialized"); - getCommand("plex").setExecutor(new PlexCommand()); - + generateWorlds(); } @Override @@ -104,4 +106,11 @@ public class Plex extends JavaPlugin redisConnection.getJedis().close(); }*/ } + + private void generateWorlds() + { + PlexLog.log("Generating any worlds if needed..."); + flatlands = new Flatlands().generate(); + PlexLog.log("Finished with world generation!"); + } } \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/command/PlexCommand.java b/src/main/java/me/totalfreedom/plex/command/PlexCommand.java deleted file mode 100644 index 7e5bf95..0000000 --- a/src/main/java/me/totalfreedom/plex/command/PlexCommand.java +++ /dev/null @@ -1,16 +0,0 @@ -package me.totalfreedom.plex.command; - -import me.totalfreedom.plex.PlexBase; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; - -public class PlexCommand extends PlexBase implements CommandExecutor -{ - @Override - public boolean onCommand(CommandSender sender, Command message, String s, String[] args) - { - sender.sendMessage(plugin.config.getString("server.test")); - return true; - } -} diff --git a/src/main/java/me/totalfreedom/plex/command/impl/CommandParameters.java b/src/main/java/me/totalfreedom/plex/command/impl/CommandParameters.java new file mode 100644 index 0000000..c26c258 --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/command/impl/CommandParameters.java @@ -0,0 +1,12 @@ +package me.totalfreedom.plex.command.impl; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface CommandParameters +{ + String description() default ""; + String usage() default "/"; + String aliases() default ""; +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/command/impl/CommandPermissions.java b/src/main/java/me/totalfreedom/plex/command/impl/CommandPermissions.java new file mode 100644 index 0000000..7f851ef --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/command/impl/CommandPermissions.java @@ -0,0 +1,13 @@ +package me.totalfreedom.plex.command.impl; + +import me.totalfreedom.plex.rank.enums.Rank; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface CommandPermissions +{ + Rank level() default Rank.IMPOSTOR; + RequiredCommandSource source(); +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/command/impl/CommandSource.java b/src/main/java/me/totalfreedom/plex/command/impl/CommandSource.java new file mode 100644 index 0000000..d03b6da --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/command/impl/CommandSource.java @@ -0,0 +1,25 @@ +package me.totalfreedom.plex.command.impl; + +import lombok.Getter; +import me.totalfreedom.plex.player.PlexPlayer; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class CommandSource +{ + @Getter + private CommandSender sender; + @Getter + private Player player; + private PlexPlayer plexPlayer; + + public CommandSource(CommandSender sender) + { + this.sender = sender; + this.player = Bukkit.getPlayer(sender.getName()); + this.plexPlayer = null; + } + + +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/command/impl/PlexCommand.java b/src/main/java/me/totalfreedom/plex/command/impl/PlexCommand.java new file mode 100644 index 0000000..756410d --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/command/impl/PlexCommand.java @@ -0,0 +1,106 @@ +package me.totalfreedom.plex.command.impl; + +import me.totalfreedom.plex.PlexBase; +import me.totalfreedom.plex.rank.enums.Rank; +import org.bukkit.Bukkit; +import org.bukkit.command.*; + +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +public abstract class PlexCommand extends PlexBase implements CommandExecutor, TabCompleter +{ + private static final String COMMAND_PREFIX = "Command_"; + private static CommandMap COMMAND_MAP; + + private final CommandParameters params; + private final CommandPermissions perms; + private final String name; + private final String description; + private final String usage; + private final List aliases; + private final Rank level; + private final RequiredCommandSource source; + + protected PlexCommand() + { + this.params = this.getClass().getAnnotation(CommandParameters.class); + this.perms = this.getClass().getAnnotation(CommandPermissions.class); + this.name = this.getClass().getSimpleName().toLowerCase().replace(COMMAND_PREFIX.toLowerCase(), ""); + this.description = this.params.description(); + this.usage = this.params.usage(); + this.aliases = Arrays.asList(this.params.aliases().split(",")); + this.level = this.perms.level(); + this.source = this.perms.source(); + } + + public void register() + { + PCommand command = new PCommand(this.name); + command.setDescription(this.description); + command.setUsage(this.usage); + command.setAliases(this.aliases); + this.getCommandMap().register("", command); + command.setExecutor(this); + } + + protected CommandMap getCommandMap() + { + if (COMMAND_MAP == null) + { + try + { + final Field f = Bukkit.getServer().getClass().getDeclaredField("commandMap"); + f.setAccessible(true); + COMMAND_MAP = (CommandMap) f.get(Bukkit.getServer()); + return getCommandMap(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + else + return COMMAND_MAP; + return getCommandMap(); + } + + private static class PCommand extends Command + { + private PlexCommand command = null; + + private PCommand(String name) + { + super(name); + } + + public void setExecutor(PlexCommand command) + { + this.command = command; + } + + @Override + public boolean execute(CommandSender sender, String c, String[] args) + { + if (command == null) + return false; + return command.onCommand(sender, this, c, args); + } + + @Override + public List tabComplete(CommandSender sender, String alias, String[] args) + { + if (command == null) + return null; + return Objects.requireNonNull(command.onTabComplete(sender, this, alias, args)); + } + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String c, String[] args) + { + return false; + } +} diff --git a/src/main/java/me/totalfreedom/plex/command/impl/RequiredCommandSource.java b/src/main/java/me/totalfreedom/plex/command/impl/RequiredCommandSource.java new file mode 100644 index 0000000..aea919c --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/command/impl/RequiredCommandSource.java @@ -0,0 +1,8 @@ +package me.totalfreedom.plex.command.impl; + +public enum RequiredCommandSource +{ + IN_GAME, + CONSOLE, + ANY +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/rank/enums/Rank.java b/src/main/java/me/totalfreedom/plex/rank/enums/Rank.java index e726836..30cefe3 100644 --- a/src/main/java/me/totalfreedom/plex/rank/enums/Rank.java +++ b/src/main/java/me/totalfreedom/plex/rank/enums/Rank.java @@ -7,7 +7,7 @@ import java.util.List; public enum Rank { - IMPOSTER(-1, ChatColor.AQUA + "an " + ChatColor.YELLOW + "Imposter", ChatColor.YELLOW + "[Imp]"), + IMPOSTOR(-1, ChatColor.AQUA + "an " + ChatColor.YELLOW + "Impostor", ChatColor.YELLOW + "[Imp]"), NONOP(0, ChatColor.WHITE + "a " + ChatColor.WHITE + "Non-Op", ChatColor.WHITE + ""), OP(1, ChatColor.GREEN + "an " + ChatColor.GREEN + "Operator", ChatColor.GREEN + "[OP]"), ADMIN(2, ChatColor.DARK_GREEN + "an " + ChatColor.DARK_GREEN + "Admin", ChatColor.DARK_GREEN + "[Admin]"), diff --git a/src/main/java/me/totalfreedom/plex/world/Flatlands.java b/src/main/java/me/totalfreedom/plex/world/Flatlands.java new file mode 100644 index 0000000..f5b5621 --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/world/Flatlands.java @@ -0,0 +1,58 @@ +package me.totalfreedom.plex.world; + +import me.totalfreedom.plex.Plex; +import me.totalfreedom.plex.world.impl.CustomWorld; +import me.totalfreedom.plex.world.impl.FlatChunkGenerator; +import org.bukkit.ChatColor; +import org.bukkit.Chunk; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.generator.BlockPopulator; + +import java.util.Random; + +public class Flatlands extends CustomWorld +{ + private static Plex plugin = Plex.get(); + + public Flatlands() + { + super("flatlands", new FlatlandsChunkGenerator()); + } + + @Override + public World generate() + { + return super.generate(); + } + + private static class FlatlandsChunkGenerator extends FlatChunkGenerator + { + public FlatlandsChunkGenerator() + { + super(50, new FlatlandsBlockPopulator()); + } + + @Override + public void createLoopChunkData(int x, int y, int z, ChunkData chunk) + { + int height = this.height; + for (String key : plugin.config.getConfigurationSection("server.flatlands.parameters").getKeys(false)) + { + Material material = Material.getMaterial(key.toUpperCase()); + if (material == null) continue; + int count = plugin.config.getInt("server.flatlands.parameters." + key); + for (int i = 0; i < count; i++, height--) + chunk.setBlock(x, height, z, material); + } + } + + private static class FlatlandsBlockPopulator extends BlockPopulator + { + @Override + public void populate(World world, Random random, Chunk chunk) + { + } + } + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/world/impl/CustomChunkGenerator.java b/src/main/java/me/totalfreedom/plex/world/impl/CustomChunkGenerator.java new file mode 100644 index 0000000..7805e7f --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/world/impl/CustomChunkGenerator.java @@ -0,0 +1,27 @@ +package me.totalfreedom.plex.world.impl; + +import org.bukkit.World; +import org.bukkit.generator.BlockPopulator; +import org.bukkit.generator.ChunkGenerator; + +import java.util.Arrays; +import java.util.List; + +public abstract class CustomChunkGenerator extends ChunkGenerator +{ + protected int height; + private final List populators; + + protected CustomChunkGenerator(int height, BlockPopulator... populators) + { + this.height = height; + this.populators = Arrays.asList(populators); + } + + public List getDefaultPopulators(World world) + { + return populators; + } + + public abstract void createLoopChunkData(int x, int y, int z, ChunkData chunk); +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/world/impl/CustomWorld.java b/src/main/java/me/totalfreedom/plex/world/impl/CustomWorld.java new file mode 100644 index 0000000..b2d64ba --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/world/impl/CustomWorld.java @@ -0,0 +1,28 @@ +package me.totalfreedom.plex.world.impl; + +import org.bukkit.World; +import org.bukkit.WorldCreator; +import org.bukkit.generator.ChunkGenerator; + +public class CustomWorld extends WorldCreator +{ + private final CustomChunkGenerator chunks; + + public CustomWorld(String name, CustomChunkGenerator generator) + { + super(name); + this.chunks = generator; + this.generator(this.chunks); + } + + @Override + public ChunkGenerator generator() + { + return chunks; + } + + public World generate() + { + return this.createWorld(); + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/world/impl/FlatChunkGenerator.java b/src/main/java/me/totalfreedom/plex/world/impl/FlatChunkGenerator.java new file mode 100644 index 0000000..2552c3d --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/world/impl/FlatChunkGenerator.java @@ -0,0 +1,29 @@ +package me.totalfreedom.plex.world.impl; + +import org.bukkit.World; +import org.bukkit.generator.BlockPopulator; +import java.util.Random; + +public abstract class FlatChunkGenerator extends CustomChunkGenerator +{ + public FlatChunkGenerator(int height, BlockPopulator... populators) + { + super(height, populators); + } + + @Override + public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) + { + ChunkData chunk = this.createChunkData(world); + for (int xx = 0; xx < 16; xx++) + { + for (int zz = 0; zz < 16; zz++) + { + createLoopChunkData(xx, height, zz, chunk); + } + } + return chunk; + } + + public abstract void createLoopChunkData(int x, int y, int z, ChunkData chunk); +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/world/impl/NoiseChunkGenerator.java b/src/main/java/me/totalfreedom/plex/world/impl/NoiseChunkGenerator.java new file mode 100644 index 0000000..33f3f85 --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/world/impl/NoiseChunkGenerator.java @@ -0,0 +1,36 @@ +package me.totalfreedom.plex.world.impl; + +import org.bukkit.World; +import org.bukkit.generator.BlockPopulator; +import org.bukkit.util.noise.PerlinNoiseGenerator; + +import java.util.Random; + +public abstract class NoiseChunkGenerator extends CustomChunkGenerator +{ + private final NoiseOptions options; + + public NoiseChunkGenerator(int height, NoiseOptions options, BlockPopulator... populators) + { + super(height, populators); + this.options = options; + } + + @Override + public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) + { + ChunkData chunk = this.createChunkData(world); + PerlinNoiseGenerator generator = new PerlinNoiseGenerator(new Random(world.getSeed())); + for (int xx = 0; xx < 16; xx++) + { + for (int zz = 0; zz < 16; zz++) + { + height = (int) generator.noise(options.getX(), options.getY(), options.getFrequency(), options.getAmplitude(), options.isNormalized()); + createLoopChunkData(xx, height, zz, chunk); + } + } + return chunk; + } + + public abstract void createLoopChunkData(int x, int y, int z, ChunkData chunk); +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/world/impl/NoiseOptions.java b/src/main/java/me/totalfreedom/plex/world/impl/NoiseOptions.java new file mode 100644 index 0000000..a70fd0c --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/world/impl/NoiseOptions.java @@ -0,0 +1,26 @@ +package me.totalfreedom.plex.world.impl; + +import lombok.Getter; + +public class NoiseOptions +{ + @Getter + private final int x; + @Getter + private final int y; + @Getter + private final double frequency; + @Getter + private final double amplitude; + @Getter + private final boolean normalized; + + public NoiseOptions(int x, int y, double frequency, double amplitude, boolean normalized) + { + this.x = x; + this.y = y; + this.frequency = frequency; + this.amplitude = amplitude; + this.normalized = normalized; + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/world/impl/OctaveChunkGenerator.java b/src/main/java/me/totalfreedom/plex/world/impl/OctaveChunkGenerator.java new file mode 100644 index 0000000..1f44043 --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/world/impl/OctaveChunkGenerator.java @@ -0,0 +1,36 @@ +package me.totalfreedom.plex.world.impl; + +import org.bukkit.World; +import org.bukkit.generator.BlockPopulator; +import org.bukkit.util.noise.PerlinOctaveGenerator; + +import java.util.Random; + +public abstract class OctaveChunkGenerator extends CustomChunkGenerator +{ + private OctaveOptions options; + + public OctaveChunkGenerator(int height, OctaveOptions options, BlockPopulator... populators) + { + super(height, populators); + this.options = options; + } + + @Override + public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) + { + ChunkData chunk = this.createChunkData(world); + PerlinOctaveGenerator generator = new PerlinOctaveGenerator(new Random(world.getSeed()), options.getOctaves()); + for (int xx = 0; xx < 16; xx++) + { + for (int zz = 0; zz < 16; zz++) + { + height = (int) generator.noise(options.getX(), options.getY(), options.getFrequency(), options.getAmplitude(), options.isNormalized()); + createLoopChunkData(xx, height, zz, chunk); + } + } + return chunk; + } + + public abstract void createLoopChunkData(int x, int y, int z, ChunkData chunk); +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/plex/world/impl/OctaveOptions.java b/src/main/java/me/totalfreedom/plex/world/impl/OctaveOptions.java new file mode 100644 index 0000000..02e6819 --- /dev/null +++ b/src/main/java/me/totalfreedom/plex/world/impl/OctaveOptions.java @@ -0,0 +1,15 @@ +package me.totalfreedom.plex.world.impl; + +import lombok.Getter; + +public class OctaveOptions extends NoiseOptions +{ + @Getter + private final int octaves; + + public OctaveOptions(int x, int y, double frequency, double amplitude, boolean normalized, int octaves) + { + super(x, y, frequency, amplitude, normalized); + this.octaves = octaves; + } +} \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 6e27a2f..d15da49 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -3,6 +3,14 @@ server: test: "test string" + flatlands: + generate: true + parameters: + grass_block: 1 + dirt: 32 + stone: 16 + bedrock: 1 + data: central: storage: sqlite # use mariadb, mongodb, or sqlite here