Skip to content

Commit

Permalink
Update to v3.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Efnilite committed Feb 22, 2022
1 parent bb4311f commit 019567e
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 61 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>dev.efnilite</groupId>
<artifactId>WITP</artifactId>
<packaging>pom</packaging>
<version>3.0.2</version>
<version>3.0.3</version>
<modules>
<module>witp</module>
<module>ipex</module>
Expand Down
4 changes: 2 additions & 2 deletions todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Walk in the Park

v3.0.3
- Add spectator join/leave messages
- Add custom language support
- Fix Multiverse reporting a missing world
- Add Sessions (internal)
- Fix several world issues

High priority:
- Optimize ram with schematics (async?)
Expand Down
2 changes: 1 addition & 1 deletion witp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>WITP</artifactId>
<groupId>dev.efnilite</groupId>
<version>3.0.2</version>
<version>3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
1 change: 1 addition & 0 deletions witp/src/main/java/dev/efnilite/witp/WITP.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public void disable() {
}
}
}

worldHandler.deleteWorld();
}

Expand Down
16 changes: 15 additions & 1 deletion witp/src/main/java/dev/efnilite/witp/generator/WorldHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,26 @@ public class WorldHandler {
*/
public void createWorld() {
String name = Option.WORLD_NAME.get();
World world = Bukkit.getWorld(name);

if (!Option.DELETE_ON_RELOAD.get()) {
world = Bukkit.getWorld(name);
if (world == null) {
create();
}
return;
}

if (world == null) { // on crash prevent loading twice
deleteWorld();
create();
} else {
Logging.warn("Crash detected! If there are any blocks left in the Parkour world, reload your server.");
}
}

private void create() {
String name = Option.WORLD_NAME.get();

if (WITP.getMultiverseHook() != null) { // if multiverse isn't detected
world = WITP.getMultiverseHook().createWorld(name);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public World createWorld(String worldName) {
world.setAllowAnimalSpawn(false);
world.setAllowMonsterSpawn(false);

world.setAutoLoad(false);
world.setKeepSpawnInMemory(true);

return world.getCBWorld();
Expand Down
3 changes: 1 addition & 2 deletions witp/src/main/java/dev/efnilite/witp/player/ParkourUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ protected static void unregister0(@NotNull ParkourUser user, boolean sendBack, b
}
if (user.getPreviousData() == null) {
Logging.warn("No previous data found for " + user.getPlayer().getName());
return;
} else {
user.getPreviousData().apply(sendBack);
}
Expand Down Expand Up @@ -462,7 +461,7 @@ public void sendTranslated(String path, String... replaceable) {
*/
public String getTranslated(String path, String... replaceable) {
path = "messages." + getLocale() + "." + path;
String message = WITP.getConfiguration().getString("lang", path);
String message = WITP.getConfiguration().getLang("lang", path);

for (String s : replaceable) {
message = message.replaceFirst("%[a-z]", s);
Expand Down
9 changes: 3 additions & 6 deletions witp/src/main/java/dev/efnilite/witp/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,10 @@ public static void depositPlayer(Player player, double amount) {
* @return a vector that indicates the direction
*/
public static Direction getDirection(@Nullable String face) {
if (face == null) {
return null;
}
try {
return Direction.valueOf(face.toUpperCase());
} catch (IllegalArgumentException ex) {
Logging.error(face + " is not a direction! Defaulting to east.");
return Direction.valueOf(face == null ? "-" : face.toUpperCase());
} catch (Throwable throwable) {
Logging.stack(face + " is not a direction!", "Please check generation.yml", throwable);
return Direction.EAST;
}
}
Expand Down
21 changes: 0 additions & 21 deletions witp/src/main/java/dev/efnilite/witp/util/VoidGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.generator.WorldInfo;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
Expand All @@ -17,26 +16,6 @@
@SuppressWarnings("deprecation") // generateChunkData is used for <1.18 versions
public class VoidGenerator extends ChunkGenerator {

@Override
public void generateBedrock(@NotNull WorldInfo worldInfo, @NotNull Random random, int x, int z, @NotNull ChunkGenerator.ChunkData chunkData) {

}

@Override
public void generateCaves(@NotNull WorldInfo worldInfo, @NotNull Random random, int x, int z, @NotNull ChunkGenerator.ChunkData chunkData) {

}

@Override
public void generateNoise(@NotNull WorldInfo worldInfo, @NotNull Random random, int x, int z, @NotNull ChunkGenerator.ChunkData chunkData) {

}

@Override
public void generateSurface(@NotNull WorldInfo worldInfo, @NotNull Random random, int x, int z, @NotNull ChunkGenerator.ChunkData chunkData) {

}

@Override
public boolean shouldGenerateNoise() {
return false;
Expand Down
79 changes: 54 additions & 25 deletions witp/src/main/java/dev/efnilite/witp/util/config/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.net.URL;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Collectors;

/**
* An utilities class for the Configuration
Expand All @@ -39,17 +36,14 @@ public Configuration(Plugin plugin) {
this.plugin = plugin;

List<String> defaultFiles = Arrays.asList("config.yml", "generation.yml", "schematics.yml", "lang/messages-v3.yml", "lang/items-v3.yml", "lang/scoreboard-v3.yml");
List<File> asFiles = defaultFiles // convert file names to file instances
.stream()
.map(name -> new File(plugin.getDataFolder(), name))
.collect(Collectors.toList());
for (String name : defaultFiles) {
File file = new File(plugin.getDataFolder(), name);

for (File file : asFiles) {
if (!file.exists()) {
plugin.getDataFolder().mkdirs();

plugin.saveResource(file.getName(), false);
Logging.info("Created config file " + file.getName());
plugin.saveResource(name, false);
Logging.info("Created config file " + name);
}
}

Expand All @@ -63,26 +57,44 @@ public Configuration(Plugin plugin) {
}
}

// Lang files
for (String file : Arrays.asList("lang/messages-v3.yml", "lang/items-v3.yml")) {
// Load included and user file and if there are any differences, exempt them from updating
FileConfiguration included = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder() + "/" + file));
FileConfiguration user = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder() + "/" + file));
// List<String> langs = Util.getNode(c, "messages");

try {
ConfigUpdater.update(plugin, file, new File(plugin.getDataFolder(), file), Collections.emptyList());
} catch (IOException ex) {
Logging.stack("Error while trying to update language file " + file,
"Delete this file. If the problem persists, please report this error to the developer!", ex);
}
}
checkUserLanguages("lang/messages-v3.yml", "messages");
checkUserLanguages("lang/items-v3.yml", "locale");

reload();
schematics();
Logging.info("Loaded all config files");
}

private void checkUserLanguages(String file, String beginPath) {
// Load included and user file and if there are any differences, exempt them from updating
InputStream stream = plugin.getResource(file);
if (stream == null) {
throw new IllegalArgumentException("Invalid plugin resource " + file);
}

FileConfiguration included = YamlConfiguration.loadConfiguration(new InputStreamReader(stream));
FileConfiguration user = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), file));
List<String> includedLangs = Util.getNode(included, beginPath);
List<String> userLangs = Util.getNode(user, beginPath);

// Add all differences to list
List<String> toNotUpdate = new ArrayList<>();
if (includedLangs != null && userLangs != null) {
for (String userLang : userLangs) {
if (!includedLangs.contains(userLang)) {
toNotUpdate.add(beginPath + "." + userLang);
}
}
}

try {
ConfigUpdater.update(plugin, file, new File(plugin.getDataFolder(), file), toNotUpdate);
} catch (IOException ex) {
Logging.stack("Error while trying to update language file " + file,
"Delete this file. If the problem persists, please report this error to the developer!", ex);
}
}

/**
* Maps all files to aliases.
*/
Expand Down Expand Up @@ -196,6 +208,23 @@ public FileConfiguration getFile(String file) {
return Util.color(string);
}

public @NotNull String getLang(@NotNull String file, @NotNull String path) {
String string = getFile(file).getString(path);

if (string == null) {
repairPaths();
Logging.stack("Option at path " + path + " with file " + file + " is null", "Please check your config values");
return "";
}

return Util.color(string);
}

// todo implement
private void repairPaths() {

}

/**
* Gets a coloured string that may be null
*
Expand Down
1 change: 1 addition & 0 deletions witp/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ sql:

# Options for the world
world:

# The world in which the personal parkours will take place
name: 'witp'

Expand Down
2 changes: 1 addition & 1 deletion witp/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: 'WITP'
description: 'Infinitely automatically generating parkour plugin.'
author: Efnilite, Ice_Pancake
version: 3.0.2
version: 3.0.3
api-version: 1.16
main: dev.efnilite.witp.WITP
softdepend: [Vault, PlaceholderAPI, ProtocolAPI, Multiverse-Core, HolographicDisplays, NoteBlockAPI, WVoidGen, VoidGen]
Expand Down

0 comments on commit 019567e

Please sign in to comment.