Skip to content

Commit

Permalink
v7.3.51 - update for 1.20.4, also make updating minecraft-version-dep…
Browse files Browse the repository at this point in the history
…endent to not break servers by introducing unknown blocks or tree definitions
  • Loading branch information
slipcor committed Jan 13, 2024
1 parent e0fde3b commit 0448839
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 333 deletions.
1 change: 1 addition & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## v7.3 - API Expansion

- v7.3.51 - update for 1.20.4, also make updating minecraft-version-dependent to not break servers by introducing unknown blocks or tree definitions
- v7.3.50 - print correct permission message for "treeconfig" command
- v7.3.49 - implement pull #97 manually
- v7.3.48 - allow natural blocks to be the roof of a tree - nether hotfix
Expand Down
2 changes: 1 addition & 1 deletion doc/treeconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ This is the default tree configuration file.
- 'minecraft:azure_bluet'
- 'minecraft:oxeye_daisy'
- 'minecraft:lilac'
- 'minecraft:grass'
- 'minecraft:short_grass'
- 'minecraft:tall_grass'
- 'minecraft:fern'
- 'minecraft:dead_bush'
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ It also will take down an entire tree when it is enabled in the config.

## Changelog

- v7.3.50 - print correct permission message for "treeconfig" command
- v7.3.51 - update for 1.20.4, also make updating minecraft-version-dependent to not break servers by introducing unknown blocks or tree definitions
- [read more](doc/changelog.md)

***
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/net/slipcor/treeassist/utils/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,51 @@ public static String[] compress(String[] args) {
}
return arguments.toArray(new String[0]);
}

/**
* Check whether a version is greater or equal to our server version
* @param serverVersion the running server minecraft version as integer array
* @param testVersion the required server minecraft version as integer array
* @return whether a particular check version is greater or equal to a required one
*/
public static boolean isSupportedVersion(int[] serverVersion, int[] testVersion) {
for (int i=0; i<3; i++) {
if (serverVersion[i] < testVersion[i]) {
return false;
}
if (serverVersion[i] > testVersion[i]) {
return true;
}
}
return true;
}

/**
* Create an integer array of the Bukkit version string
* @param version the bukkit version string, i.e. "1.20.4-R0.1....."
* @return an integer array, i.e. {1, 20, 4}
*/
public static int[] splitToVersionArray(String version) {
String[] chunks = new String[]{"1", "9"};
try {
chunks = version.split("-")[0].split("\\.");
} catch (Exception e) {
}
int major = 1;
int minor = 9;
int patch = 0;
try {
major = Integer.parseInt(chunks[0]);
} catch (Exception e) {
}
try {
minor = Integer.parseInt(chunks[1]);
} catch (Exception e) {
}
try {
patch = Integer.parseInt(chunks[2]);
} catch (Exception e) {
}
return new int[] {major,minor,patch};
}
}
228 changes: 0 additions & 228 deletions src/main/java/net/slipcor/treeassist/yml/ConfigV7Updater.java

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/java/net/slipcor/treeassist/yml/MainConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,6 @@ public CFG getByNode(final String node) {
public boolean load() {
try {
cfg.load(configFile);
if (cfg.contains("Main.Use Permissions")) {
ConfigV7Updater.commit(); //TODO: remove class next major bump or reuse next rewrite
cfg.load(configFile); // reload again!
}
reloadMaps();
return true;
} catch (final Exception e) {
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/net/slipcor/treeassist/yml/MainConfigUpdater.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package net.slipcor.treeassist.yml;

import net.slipcor.treeassist.TreeAssist;
import net.slipcor.treeassist.utils.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;

import java.io.File;
Expand Down Expand Up @@ -31,18 +33,20 @@ enum Moving {
}

enum TreeAddition {
AZALEA(7.2012f, "overworld", "azalea.yml"),
MANGROVE(7.330f, "overworld", "mangrove.yml"),
CHERRY(7.341f, "overworld", "cherry.yml");
AZALEA(7.2012f, "overworld", "azalea.yml", new int[] {1, 17, 0}),
MANGROVE(7.330f, "overworld", "mangrove.yml", new int[] {1, 19, 0}),
CHERRY(7.341f, "overworld", "cherry.yml", new int[] {1, 20, 0});

private final float version;
private final String path;
private final String file;
private final int[] mcversion;

TreeAddition(float v, String p, String f) {
TreeAddition(float v, String p, String f, int[] mcv) {
version = v;
path = p;
file = f;
mcversion = mcv;
}
}

Expand Down Expand Up @@ -110,6 +114,9 @@ enum Adding {
*/
public static boolean check(MainConfig instance, FileConfiguration config) {
instance.preLoad();

int[] serverVersion = StringUtils.splitToVersionArray(Bukkit.getBukkitVersion());

double version = config.getDouble("Version", 7.0);
double newVersion = version;
boolean changed = false;
Expand Down Expand Up @@ -149,7 +156,7 @@ public static boolean check(MainConfig instance, FileConfiguration config) {
}
}
for (TreeAddition m : TreeAddition.values()) {
if (m.version > version) {
if (m.version > version && StringUtils.isSupportedVersion(serverVersion, m.mcversion)) {
newVersion = Math.max(newVersion, m.version);

File trees = new File(TreeAssist.instance.getDataFolder(), "trees");
Expand Down
Loading

0 comments on commit 0448839

Please sign in to comment.