This commit is contained in:
Super_ 2020-10-31 00:51:22 -04:00
parent a770fc36e9
commit b51df4cc6b
17 changed files with 440 additions and 20 deletions

View File

@ -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!");
}
}

View File

@ -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;
}
}

View File

@ -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 "/<command>";
String aliases() default "";
}

View File

@ -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();
}

View File

@ -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;
}
}

View File

@ -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<String> 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<String> 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;
}
}

View File

@ -0,0 +1,8 @@
package me.totalfreedom.plex.command.impl;
public enum RequiredCommandSource
{
IN_GAME,
CONSOLE,
ANY
}

View File

@ -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]"),

View File

@ -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)
{
}
}
}
}

View File

@ -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<BlockPopulator> populators;
protected CustomChunkGenerator(int height, BlockPopulator... populators)
{
this.height = height;
this.populators = Arrays.asList(populators);
}
public List<BlockPopulator> getDefaultPopulators(World world)
{
return populators;
}
public abstract void createLoopChunkData(int x, int y, int z, ChunkData chunk);
}

View File

@ -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();
}
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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