Merge branch 'MV5' into MV5-version-command

This commit is contained in:
Ben Woo 2023-09-01 23:42:55 +08:00 committed by GitHub
commit 381f440a6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 242 additions and 25 deletions

View File

@ -0,0 +1,52 @@
package com.onarandombox.MultiverseCore.commands;
import co.aikar.commands.BukkitCommandIssuer;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.Flags;
import co.aikar.commands.annotation.Subcommand;
import com.onarandombox.MultiverseCore.api.LocationManipulation;
import com.onarandombox.MultiverseCore.api.MVWorld;
import com.onarandombox.MultiverseCore.commandtools.MVCommandManager;
import com.onarandombox.MultiverseCore.commandtools.MultiverseCommand;
import com.onarandombox.MultiverseCore.utils.MVCorei18n;
import jakarta.inject.Inject;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jvnet.hk2.annotations.Service;
@Service
@CommandAlias("mv")
public class CoordinatesCommand extends MultiverseCommand {
private final LocationManipulation locationManipulation;
@Inject
public CoordinatesCommand(
@NotNull MVCommandManager commandManager,
@NotNull LocationManipulation locationManipulation
) {
super(commandManager);
this.locationManipulation = locationManipulation;
}
@Subcommand("coordinates|coords|coord|co")
@CommandPermission("multiverse.core.coord")
@Description("{@@mv-core.coordinates.description}")
public void onCoordinatesCommand(BukkitCommandIssuer issuer,
@Flags("resolve=issuerOnly")
Player player,
@Flags("resolve=issuerOnly")
MVWorld world
) {
issuer.sendInfo(MVCorei18n.COORDINATES_INFO_TITLE);
issuer.sendInfo(MVCorei18n.COORDINATES_INFO_WORLD, "{world}", world.getName());
issuer.sendInfo(MVCorei18n.COORDINATES_INFO_ALIAS, "{alias}", world.getColoredWorldString());
issuer.sendInfo(MVCorei18n.COORDINATES_INFO_WORLDSCALE, "{scale}", String.valueOf(world.getScaling()));
issuer.sendInfo(MVCorei18n.COORDINATES_INFO_COORDINATES, "{coordinates}", locationManipulation.strCoords(player.getLocation()));
issuer.sendInfo(MVCorei18n.COORDINATES_INFO_DIRECTION, "{direction}", locationManipulation.getDirection(player.getLocation()));
}
}

View File

@ -34,15 +34,21 @@ abstract class FileConfigHandle<C extends FileConfiguration> extends GenericConf
*/
@Override
public boolean load() {
if (!createConfigFile()) {
boolean newFileCreated;
try {
newFileCreated = createConfigFile();
} catch (IOException e) {
Logging.severe("Failed to create config file: %s", configFile.getName());
Logging.severe(e.getMessage());
return false;
}
if (!loadConfigObject()) {
Logging.severe("Failed to load config file: %s", configFile.getName());
return false;
}
migrateConfig();
if (!newFileCreated) {
migrateConfig();
}
setUpNodes();
return true;
}
@ -52,19 +58,11 @@ abstract class FileConfigHandle<C extends FileConfiguration> extends GenericConf
*
* @return True if file exist or created successfully, otherwise false.
*/
protected boolean createConfigFile() {
protected boolean createConfigFile() throws IOException {
if (configFile.exists()) {
return true;
}
try {
if (!configFile.createNewFile()) {
return false;
}
Logging.info("Created new config file: %s", configFile.getName());
} catch (IOException e) {
return false;
}
return true;
return configFile.createNewFile();
}
/**

View File

@ -19,6 +19,14 @@ public enum MVCorei18n implements MessageKeyProvider {
CLONE_FAILED,
CLONE_SUCCESS,
// Coordinates command
COORDINATES_INFO_TITLE,
COORDINATES_INFO_WORLD,
COORDINATES_INFO_ALIAS,
COORDINATES_INFO_WORLDSCALE,
COORDINATES_INFO_COORDINATES,
COORDINATES_INFO_DIRECTION,
// create command
CREATE_PROPERTIES,
CREATE_PROPERTIES_ENVIRONMENT,
@ -86,6 +94,10 @@ public enum MVCorei18n implements MessageKeyProvider {
DEBUG_INFO_OFF,
DEBUG_INFO_ON,
// commands error
COMMANDS_ERROR_PLAYERSONLY,
COMMANDS_ERROR_MULTIVERSEWORLDONLY,
// entry check
ENTRYCHECK_BLACKLISTED,
ENTRYCHECK_NOTENOUGHMONEY,

View File

@ -29,15 +29,13 @@ public class WorldManager {
}
public void addWorld(String worldName) {
ConfigurationSection worldConfigSection = worldsConfigFile.getWorldConfigSection(worldName);
WorldConfig worldConfig = new WorldConfig(worldConfigSection);
WorldConfig worldConfig = worldsConfigFile.getWorldConfig(worldName);
//todo
saveWorldsConfig();
}
public void loadWorld(String worldName) {
ConfigurationSection worldConfigSection = worldsConfigFile.getWorldConfigSection(worldName);
WorldConfig worldConfig = new WorldConfig(worldConfigSection);
WorldConfig worldConfig = worldsConfigFile.getWorldConfig(worldName);
//todo
}

View File

@ -2,7 +2,11 @@ package com.onarandombox.MultiverseCore.worldnew.config;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.configuration.handle.ConfigurationSectionHandle;
import com.onarandombox.MultiverseCore.world.configuration.AllowedPortalType;
import io.vavr.control.Try;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -31,22 +35,158 @@ public class WorldConfig {
return configHandle.set(name, value);
}
public void setAlias(String alias) {
configHandle.set(configNodes.ALIAS, alias);
public boolean getAdjustSpawn() {
return configHandle.get(configNodes.ADJUST_SPAWN);
}
public Try<Void> setAdjustSpawn(boolean adjustSpawn) {
return configHandle.set(configNodes.ADJUST_SPAWN, adjustSpawn);
}
public @Nullable String getAlias() {
return configHandle.get(configNodes.ALIAS);
}
public void setHidden(boolean hidden) {
configHandle.set(configNodes.HIDDEN, hidden);
public Try<Void> setAlias(String alias) {
return configHandle.set(configNodes.ALIAS, alias);
}
public boolean getAllowFlight() {
return configHandle.get(configNodes.ALLOW_FLIGHT);
}
public Try<Void> setAllowFlight(boolean allowFlight) {
return configHandle.set(configNodes.ALLOW_FLIGHT, allowFlight);
}
public boolean getAllowWeather() {
return configHandle.get(configNodes.ALLOW_WEATHER);
}
public Try<Void> setAllowWeather(boolean allowWeather) {
return configHandle.set(configNodes.ALLOW_WEATHER, allowWeather);
}
public boolean getAutoHeal() {
return configHandle.get(configNodes.AUTO_HEAL);
}
public Try<Void> setAutoHeal(boolean autoHeal) {
return configHandle.set(configNodes.AUTO_HEAL, autoHeal);
}
public boolean getAutoLoad() {
return configHandle.get(configNodes.AUTO_LOAD);
}
public Try<Void> setAutoLoad(boolean autoLoad) {
return configHandle.set(configNodes.AUTO_LOAD, autoLoad);
}
public Difficulty getDifficulty() {
return configHandle.get(configNodes.DIFFICULTY);
}
public Try<Void> setDifficulty(Difficulty difficulty) {
return configHandle.set(configNodes.DIFFICULTY, difficulty);
}
public World.Environment getEnvironment() {
return configHandle.get(configNodes.ENVIRONMENT);
}
public Try<Void> setEnvironment(World.Environment environment) {
return configHandle.set(configNodes.ENVIRONMENT, environment);
}
public GameMode getGamemode() {
return configHandle.get(configNodes.GAMEMODE);
}
public Try<Void> setGamemode(GameMode gamemode) {
return configHandle.set(configNodes.GAMEMODE, gamemode);
}
public @Nullable String getGenerator() {
return configHandle.get(configNodes.GENERATOR);
}
public Try<Void> setGenerator(String generator) {
return configHandle.set(configNodes.GENERATOR, generator);
}
public boolean isHidden() {
return configHandle.get(configNodes.HIDDEN);
}
public Try<Void> setHidden(boolean hidden) {
return configHandle.set(configNodes.HIDDEN, hidden);
}
public boolean getHunger() {
return configHandle.get(configNodes.HUNGER);
}
public Try<Void> setHunger(boolean hunger) {
return configHandle.set(configNodes.HUNGER, hunger);
}
public boolean getKeepSpawnInMemory() {
return configHandle.get(configNodes.KEEP_SPAWN_IN_MEMORY);
}
public Try<Void> setKeepSpawnInMemory(boolean keepSpawnInMemory) {
return configHandle.set(configNodes.KEEP_SPAWN_IN_MEMORY, keepSpawnInMemory);
}
public int getPlayerLimit() {
return configHandle.get(configNodes.PLAYER_LIMIT);
}
public Try<Void> setPlayerLimit(int playerLimit) {
return configHandle.set(configNodes.PLAYER_LIMIT, playerLimit);
}
public AllowedPortalType getPortalForm() {
return configHandle.get(configNodes.PORTAL_FORM);
}
public Try<Void> setPortalForm(AllowedPortalType portalForm) {
return configHandle.set(configNodes.PORTAL_FORM, portalForm);
}
public boolean getPvp() {
return configHandle.get(configNodes.PVP);
}
public Try<Void> setPvp(boolean pvp) {
return configHandle.set(configNodes.PVP, pvp);
}
public String getRespawnWorld() {
return configHandle.get(configNodes.RESPAWN_WORLD);
}
public Try<Void> setRespawnWorld(String respawnWorld) {
return configHandle.set(configNodes.RESPAWN_WORLD, respawnWorld);
}
public double getScale() {
return configHandle.get(configNodes.SCALE);
}
public Try<Void> setScale(double scale) {
return configHandle.set(configNodes.SCALE, scale);
}
public @Nullable String getSeed() {
return configHandle.get(configNodes.SEED);
}
public Try<Void> setSeed(String seed) {
return configHandle.set(configNodes.SEED, seed);
}
public List<String> getWorldBlacklist() {
return (List<String>) configHandle.get(configNodes.WORLD_BLACKLIST);
}

View File

@ -126,7 +126,7 @@ public class WorldConfigNodes {
.name("world-blacklist")
.build());
//todo: color and style
//todo: Migrate color and style into alias
//todo: spawning
//todo: entryfee
//todo: spawnLocation

View File

@ -49,6 +49,10 @@ public class WorldsConfigFile {
? worldConfig.getConfigurationSection(worldName) : worldConfig.createSection(worldName);
}
public WorldConfig getWorldConfig(String worldName) {
return new WorldConfig(getWorldConfigSection(worldName));
}
public void deleteWorldConfigSection(String worldName) {
worldConfig.set(worldName, null);
}

View File

@ -19,6 +19,15 @@ mv-core.clone.success=Cloned world '{world}'!
# /mv confirm
mv-core.confirm.description=Confirms dangerous commands before executing them.
# /mv coordinates
mv-core.coordinates.description=Simply sends your coordinates
mv-core.coordinates.info.title=&b--- Location Information ---
mv-core.coordinates.info.world=&bWorld: &f{world}
mv-core.coordinates.info.alias=&bAlias: &f{alias}
mv-core.coordinates.info.worldScale=&bWorld Scale: &f{scale}
mv-core.coordinates.info.coordinates=&bCoordinates: &f{coordinates}
mv-core.coordinates.info.direction=&bDirection: &f{direction}
# /mv create
mv-core.create.description=Creates a new world and loads it.
mv-core.create.name.description=New world name.
@ -119,6 +128,10 @@ mv-core.unload.success=&aUnloaded world '{world}'!
# /mv usage
mv-core.usage.description=Show Multiverse-Core command usage.
# commands error
mv-core.commands.error.playersonly=&cThis command can only be used by players
mv-core.commands.error.multiverseworldonly=&cThis can only be used in multiverse worlds
# entry check
mv-core.entrycheck.blacklisted='{world}' is blacklisted.
mv-core.entrycheck.notenoughmoney=you do not have enough money to pay entry fee. You are required to pay {amount}.

View File

@ -38,14 +38,14 @@ class WorldConfigFileTest : TestWithMockBukkit() {
@Test
fun `Add a new world to config`() {
val worldConfig = WorldConfig(worldConfigFile.getWorldConfigSection("newworld"))
val worldConfig = worldConfigFile.getWorldConfig("newworld")
worldConfigFile.save()
compareConfigFile("worlds2.yml", "/newworld_worlds.yml")
}
@Test
fun `Updating existing world properties`() {
val worldConfig = WorldConfig(worldConfigFile.getWorldConfigSection("world"))
val worldConfig = worldConfigFile.getWorldConfig("world")
worldConfig.setProperty("adjust-spawn", true)
worldConfig.setProperty("alias", "newalias")
worldConfigFile.save()
@ -66,4 +66,4 @@ class WorldConfigFileTest : TestWithMockBukkit() {
assertNotNull(configCompare)
assertEquals(configCompare, config)
}
}
}

View File

@ -25,7 +25,7 @@ class WorldConfigTest : TestWithMockBukkit() {
worldConfigFile = WorldsConfigFile(multiverseCore)
worldConfigFile.load()
worldConfig = WorldConfig(worldConfigFile.getWorldConfigSection("world"))
worldConfig = worldConfigFile.getWorldConfig("world")
}
@Test