Start working on actual island generation and saving the data
This commit is contained in:
parent
b038477cec
commit
a363382a0f
|
|
@ -5,6 +5,8 @@ import com.alttd.cometskyblock.commands.island.IslandCommand;
|
|||
import com.alttd.cometskyblock.configuration.*;
|
||||
import com.alttd.cometskyblock.listeners.PlayerJoinListener;
|
||||
import com.alttd.cometskyblock.managers.IslandManager;
|
||||
import com.alttd.cometskyblock.managers.PlayerManager;
|
||||
import com.alttd.cometskyblock.worldgenerator.MasterWorldGenerator;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
|
@ -22,6 +24,8 @@ public class CometSkyBlockPlugin extends JavaPlugin implements CometSkyBlockAPI
|
|||
@Getter private ConfigurationContainer<ChallengesConfiguration> challengesConfiguration;
|
||||
|
||||
@Getter private IslandManager islandManager;
|
||||
@Getter private PlayerManager playerManager;
|
||||
@Getter private MasterWorldGenerator worldGenerator;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
|
|
@ -47,6 +51,8 @@ public class CometSkyBlockPlugin extends JavaPlugin implements CometSkyBlockAPI
|
|||
|
||||
// load worlds & manager
|
||||
islandManager = new IslandManager(this);
|
||||
playerManager = new PlayerManager(this);
|
||||
worldGenerator = new MasterWorldGenerator(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.alttd.cometskyblock.commands.island;
|
|||
|
||||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||
import com.alttd.cometskyblock.commands.PlayerSubCommand;
|
||||
import com.alttd.cometskyblock.configuration.MessageConfiguration;
|
||||
import com.alttd.cometskyblock.island.IslandPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
|
@ -13,7 +14,7 @@ public class IslandCommand extends PlayerSubCommand {
|
|||
super(plugin, "island");
|
||||
this.plugin = plugin;
|
||||
|
||||
registerSubCommand(new IslandHelp(plugin));
|
||||
registerSubCommand(new IslandGo(plugin));
|
||||
registerSubCommand(new IslandSethome(plugin));
|
||||
registerSubCommand(new IslandRestart(plugin));
|
||||
registerSubCommand(new IslandAccept(plugin));
|
||||
|
|
@ -31,6 +32,26 @@ public class IslandCommand extends PlayerSubCommand {
|
|||
|
||||
@Override
|
||||
public boolean execute(Player player, IslandPlayer islandPlayer, String[] args) {
|
||||
return false;
|
||||
MessageConfiguration.Commands.Island.Help help = plugin.messagesConfiguration().get().commands().island().help();
|
||||
// Todo - builder to check for perm and only add messages with permission
|
||||
player.sendRichMessage(
|
||||
help.intro() + "<newline>" +
|
||||
"<gold>/island go: </gold>" + help.go() + "<newline>" +
|
||||
"<gold>/island sethome: </gold>" + help.setHome() + "<newline>" +
|
||||
"<gold>/island restart: </gold>" + help.restart() + "<newline>" +
|
||||
"<gold>/island invite: </gold>" + help.invite() + "<newline>" +
|
||||
"<gold>/island accept: </gold>" + help.accept() + "<newline>" +
|
||||
"<gold>/island kick: </gold>" + help.kick() + "<newline>" +
|
||||
"<gold>/island setowner: </gold>" + help.setOwner() + "<newline>" +
|
||||
"<gold>/island leave: </gold>" + help.leave() + "<newline>" +
|
||||
"<gold>/island level: </gold>" + help.level() + "<newline>" +
|
||||
"<gold>/island members: </gold>" + help.members() + "<newline>" +
|
||||
"<gold>/island options: </gold>" + help.options() + "<newline>" +
|
||||
"<gold>/island top: </gold>" + help.top() + "<newline>" +
|
||||
"<gold>/island visit: </gold>" + help.visit() + "<newline>" +
|
||||
"<gold>/island confirm: </gold>" + help.confirm() + "<newline>" +
|
||||
"<gold>/island challenges: </gold>" + help.challenges()
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
package com.alttd.cometskyblock.commands.island;
|
||||
|
||||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||
import com.alttd.cometskyblock.commands.PlayerSubCommand;
|
||||
import com.alttd.cometskyblock.island.Island;
|
||||
import com.alttd.cometskyblock.island.IslandPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Teleport to your island & create an island if you do not have one yet
|
||||
*/
|
||||
public class IslandGo extends PlayerSubCommand {
|
||||
|
||||
public IslandGo(CometSkyBlockPlugin plugin) {
|
||||
super(plugin, "go");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, IslandPlayer islandPlayer, String[] args) {
|
||||
plugin.worldGenerator().createNewIslandWorld(result -> {
|
||||
World world = Bukkit.getWorld(result);
|
||||
if (world == null) {
|
||||
plugin.getLogger().warning("Failed to create world " + result);
|
||||
return;
|
||||
}
|
||||
|
||||
Island.IslandBuilder islandBuilder = new Island.IslandBuilder(world.getUID(), world.getName());
|
||||
plugin.islandManager().addIsland(player.getWorld().getUID(), islandBuilder.build());
|
||||
|
||||
player.teleportAsync(world.getSpawnLocation());
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
package com.alttd.cometskyblock.commands.island;
|
||||
|
||||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||
import com.alttd.cometskyblock.commands.PlayerSubCommand;
|
||||
import com.alttd.cometskyblock.configuration.MessageConfiguration;
|
||||
import com.alttd.cometskyblock.island.IslandPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class IslandHelp extends PlayerSubCommand {
|
||||
|
||||
public IslandHelp(CometSkyBlockPlugin plugin) {
|
||||
super(plugin, "help");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, IslandPlayer islandPlayer, String[] args) {
|
||||
MessageConfiguration.Commands.Island.Help help = plugin.messagesConfiguration().get().commands().island().help();
|
||||
// Todo - builder to check for perm and only add messages with permission
|
||||
player.sendRichMessage(
|
||||
help.intro() + "<newline>" +
|
||||
help.island() + "<newline>" +
|
||||
help.setHome() + "<newline>" +
|
||||
help.restart() + "<newline>" +
|
||||
help.invite() + "<newline>" +
|
||||
help.accept() + "<newline>" +
|
||||
help.confirm() + "<newline>" +
|
||||
help.kick() + "<newline>" +
|
||||
help.setOwner() + "<newline>" +
|
||||
help.leave() + "<newline>" +
|
||||
help.level() + "<newline>" +
|
||||
help.members() + "<newline>" +
|
||||
help.options() + "<newline>" +
|
||||
help.top() + "<newline>" +
|
||||
help.visit() + "<newline>" +
|
||||
help.challenges() + "<newline>"
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,21 @@
|
|||
package com.alttd.cometskyblock.configuration;
|
||||
|
||||
import com.alttd.cometskyblock.island.Island;
|
||||
import lombok.Getter;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@ConfigSerializable
|
||||
@Getter
|
||||
@SuppressWarnings({"CanBeFinal", "FieldMayBeFinal"})
|
||||
public class IslandConfiguration implements Configuration {
|
||||
|
||||
private int id;
|
||||
@Getter private Map<UUID, Island> islands;
|
||||
|
||||
public int getAndIncrementId() {
|
||||
return id = id + 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,22 +22,22 @@ public class MessageConfiguration implements Configuration {
|
|||
private Help help = new Help();
|
||||
@ConfigSerializable @Getter
|
||||
public static class Help {
|
||||
String intro = "test";
|
||||
String island = "";
|
||||
String setHome = "";
|
||||
String restart = "";
|
||||
String invite = "";
|
||||
String accept = "";
|
||||
String confirm = "";
|
||||
String kick = "";
|
||||
String setOwner = "";
|
||||
String leave = "";
|
||||
String level = "";
|
||||
String members = "";
|
||||
String options = "";
|
||||
String top = "";
|
||||
String visit = "";
|
||||
String challenges = "";
|
||||
String intro = "List of all Skyblock Commands:";
|
||||
String go = "Teleports you to your island. Creates a new island if it is not existing.";
|
||||
String setHome = "Sets the islands spawnpoint to the players location.";
|
||||
String restart = "Restarts your island.";
|
||||
String invite = "Invites another player to your island.";
|
||||
String accept = "Accepts the invite from another player.";
|
||||
String kick = "Kicks a player from your island.";
|
||||
String setOwner = "Gives island ownership to another player";
|
||||
String leave = "Leave your current island with this command.";
|
||||
String level = "Calculates and shows the current level of your island.";
|
||||
String members = "Gives a list of all members on the island.";
|
||||
String options = "Opens the options menu for your island.";
|
||||
String top = "Shows the top 5 islands per level.";
|
||||
String visit = "Lets you visit another island without losing your own.";
|
||||
String confirm = "Accepts the request of another player to visit your island.";
|
||||
String challenges = "Opens the challenges menu.";
|
||||
}
|
||||
|
||||
SetHome setHome = new SetHome();
|
||||
|
|
@ -118,6 +118,11 @@ public class MessageConfiguration implements Configuration {
|
|||
|
||||
}
|
||||
|
||||
Go go = new Go();
|
||||
@ConfigSerializable @Getter
|
||||
public static class Go {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private Challenges challenges = new Challenges();
|
||||
|
|
|
|||
|
|
@ -1,21 +1,23 @@
|
|||
package com.alttd.cometskyblock.island;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@ConfigSerializable
|
||||
@Getter
|
||||
public class Island {
|
||||
|
||||
private String worldName;
|
||||
private String islandName;
|
||||
private int level;
|
||||
private UUID owner;
|
||||
private final List<UUID> members = new ArrayList<>();
|
||||
protected UUID worldId;
|
||||
protected String worldName;
|
||||
protected String islandName;
|
||||
@Setter protected int level;
|
||||
@Setter protected UUID owner;
|
||||
protected final List<UUID> members = new ArrayList<>();
|
||||
|
||||
public boolean canBuild(UUID uuid) {
|
||||
return owner.equals(uuid) || members.contains(uuid);
|
||||
|
|
@ -29,4 +31,47 @@ public class Island {
|
|||
return this.members.remove(uuid);
|
||||
}
|
||||
|
||||
public static class IslandBuilder extends Island {
|
||||
private final UUID worldUUID;
|
||||
private final String worldName;
|
||||
private String islandName;
|
||||
private int level;
|
||||
private UUID owner;
|
||||
private final List<UUID> members = new ArrayList<>();
|
||||
|
||||
public IslandBuilder(UUID worldUUID, String worldName) {
|
||||
this.worldUUID = worldUUID;
|
||||
this.worldName = worldName;
|
||||
}
|
||||
|
||||
public IslandBuilder islandName(String islandName) {
|
||||
this.islandName = islandName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IslandBuilder level(int level) {
|
||||
this.level = level;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IslandBuilder owner(UUID owner) {
|
||||
this.owner = owner;
|
||||
return this;
|
||||
}
|
||||
public IslandBuilder members(List<UUID> members) {
|
||||
this.members.addAll(members);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Island build() {
|
||||
Island island = new Island();
|
||||
island.worldId = this.worldUUID;
|
||||
island.worldName = this.worldName;
|
||||
island.islandName = this.islandName;
|
||||
island.level = this.level;
|
||||
island.owner = this.owner;
|
||||
island.members.addAll(this.members);
|
||||
return island;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,14 @@
|
|||
package com.alttd.cometskyblock.managers;
|
||||
|
||||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||
import com.alttd.cometskyblock.configuration.ConfigurationContainer;
|
||||
import com.alttd.cometskyblock.configuration.IslandConfiguration;
|
||||
import com.alttd.cometskyblock.island.Island;
|
||||
import org.bukkit.World;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
@ -11,16 +16,13 @@ public class IslandManager {
|
|||
|
||||
private final CometSkyBlockPlugin plugin;
|
||||
|
||||
private HashMap<UUID, Island> islands;
|
||||
ConfigurationContainer<IslandConfiguration> islands;
|
||||
|
||||
public IslandManager(CometSkyBlockPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
loadIslands();
|
||||
}
|
||||
|
||||
void loadIslands() {
|
||||
this.islands = new HashMap<>();
|
||||
Path path = new File(plugin.getDataFolder(), "IslandData").toPath();
|
||||
islands = ConfigurationContainer.load(plugin.getSLF4JLogger(), path, IslandConfiguration.class, "islands");
|
||||
}
|
||||
|
||||
public Island getIsland(World world) {
|
||||
|
|
@ -28,9 +30,18 @@ public class IslandManager {
|
|||
}
|
||||
|
||||
public Island getIsland(UUID uuid) {
|
||||
return islands.get(uuid);
|
||||
return islands.get().islands().get(uuid);
|
||||
}
|
||||
|
||||
public void addIsland(UUID uuid, Island island) {
|
||||
islands.get().islands().put(uuid, island);
|
||||
islands.save();
|
||||
}
|
||||
|
||||
public int getNextId() {
|
||||
int id = islands.get().getAndIncrementId();
|
||||
islands.save();
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
package com.alttd.cometskyblock.managers;
|
||||
|
||||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||
import com.alttd.cometskyblock.island.IslandPlayer;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
public class PlayerManager {
|
||||
|
||||
private final CometSkyBlockPlugin plugin;
|
||||
protected final Map<UUID, IslandPlayer> islandPlayers = new LinkedHashMap<>();
|
||||
|
||||
public PlayerManager(CometSkyBlockPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void addIslandPlayer(UUID uuid, IslandPlayer islandPlayer) {
|
||||
islandPlayers.putIfAbsent(uuid, islandPlayer);
|
||||
}
|
||||
|
||||
|
||||
public void removeIslandPlayer(UUID uuid) {
|
||||
islandPlayers.remove(uuid);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ public class IslandGenerator extends BlockPopulator {
|
|||
// Always generate an island at 0 0 and add spread some random in the world
|
||||
if ((x == 0 && z == 0) || random.nextInt(10000) < 1) {
|
||||
// set starting values
|
||||
int startY = 95;
|
||||
int startY = 63;
|
||||
int startX = x * 16;
|
||||
int startZ = z * 16;
|
||||
int treeX = Mth.randomBetweenInclusive(random, -3, 3);
|
||||
|
|
|
|||
|
|
@ -12,23 +12,26 @@ import org.bukkit.WorldCreator;
|
|||
public class MasterWorldGenerator {
|
||||
|
||||
CometSkyBlockPlugin plugin;
|
||||
public static final String WORLD_NAME = "CometSkyBlockMasterWorld";
|
||||
public static final String WORLD_NAME = "CometSkyBlockWorld-<id>";
|
||||
|
||||
public MasterWorldGenerator(CometSkyBlockPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void checkMasterIslandWorld() {
|
||||
public void checkIslandWorld() {
|
||||
if (plugin.getServer().getWorld(WORLD_NAME) == null) {
|
||||
createMasterIslandWorld(result -> {
|
||||
createNewIslandWorld(result -> {
|
||||
plugin.getLogger().info(WORLD_NAME + " has been created");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void createMasterIslandWorld(Callback callback) {
|
||||
public void createNewIslandWorld(Callback callback) {
|
||||
final int id = plugin.islandManager().getNextId();
|
||||
plugin.getServer().getScheduler().runTask(plugin, () -> {
|
||||
WorldCreator worldCreator = new WorldCreator(WORLD_NAME);
|
||||
WorldCreator worldCreator = new WorldCreator(WORLD_NAME.replace("<id>",
|
||||
id + ""
|
||||
));
|
||||
worldCreator.generator(new CometIslandGenerator());
|
||||
worldCreator.environment(World.Environment.NORMAL);
|
||||
worldCreator.generateStructures(true);
|
||||
|
|
@ -46,7 +49,7 @@ public class MasterWorldGenerator {
|
|||
|
||||
// TODO Load a schematic into this world?
|
||||
|
||||
Bukkit.getScheduler().runTask(plugin, () -> callback.onQueryDone(WORLD_NAME));
|
||||
Bukkit.getScheduler().runTask(plugin, () -> callback.onQueryDone(WORLD_NAME.replace("<id>", id + "")));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user