Skip to content

Commit

Permalink
performance fix of height in actionbar, fix link-worlds feature, code…
Browse files Browse the repository at this point in the history
… cleanup
  • Loading branch information
Le4nderS committed Nov 21, 2023
1 parent 4d19270 commit 111e495
Show file tree
Hide file tree
Showing 9 changed files with 390 additions and 357 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,12 @@ linked_worlds:
method: 'SERVER' # 'SERVER' or 'MULTIVERSE'
# if method = MULTIVERSE -> world_name, y-offset
worlds:
- another_world/server # e.g. this world/server has a datapack to extend height to 2032. it covers the height section (-2032) - (-1) m a.s.l. it has a y-offset of -2032.
- current_world/server # do not change! e.g. this world/server has a datapack to extend height to 2032. it covers the height section 0 - 2032 m a.s.l.
- another_world/server # e.g. this world/server has a datapack to extend height to 2032. it covers the height section 2033 - 4064 m a.s.l. it has a y-offset of 2032
- name: another_world/server # e.g. this world/server has a datapack to extend height to 2032. it covers the height section (-2032) - (-1) m a.s.l. it has a y-offset of -2032.
offset: 2032
- name: current_world/server # do not change! e.g. this world/server has a datapack to extend height to 2032. it covers the height section 0 - 2032 m a.s.l.
offset: 0
- name: another_world/server # e.g. this world/server has a datapack to extend height to 2032. it covers the height section 2033 - 4064 m a.s.l. it has a y-offset of 2032
offset: -2032
# If disabled, tree generation is turned off.
Expand All @@ -175,7 +178,7 @@ path_material: MOSS_BLOCK
# -----------------------------------------------------
# NOTE: Do not change
config_version: 1.3
config_version: 1.4
```

# Dependencies
Expand Down
37 changes: 19 additions & 18 deletions src/main/java/de/btegermany/terraplusminus/Terraplusminus.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import de.btegermany.terraplusminus.gen.RealWorldGenerator;
import de.btegermany.terraplusminus.utils.ConfigurationHelper;
import de.btegermany.terraplusminus.utils.FileBuilder;
import de.btegermany.terraplusminus.utils.LinkedWorld;
import de.btegermany.terraplusminus.utils.PlayerHashMapManagement;
import net.buildtheearth.terraminusminus.TerraConfig;
import org.bukkit.Bukkit;
Expand All @@ -20,6 +21,7 @@
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

import java.io.*;
import java.util.logging.Level;
Expand All @@ -44,7 +46,7 @@ public void onEnable() {

// Config ------------------
this.saveDefaultConfig();
this.config = getConfig();
config = getConfig();
this.updateConfig();
// --------------------------

Expand Down Expand Up @@ -77,11 +79,7 @@ public void onEnable() {
}
// --------------------------

if (Terraplusminus.config.getBoolean("reduced_console_messages")) {
TerraConfig.reducedConsoleMessages = true; // Disables console log of fetching data
} else {
TerraConfig.reducedConsoleMessages = false;
}
TerraConfig.reducedConsoleMessages = Terraplusminus.config.getBoolean("reduced_console_messages"); // Disables console log of fetching data

// Registering commands
getCommand("tpll").setExecutor(new TpllCommand());
Expand Down Expand Up @@ -117,22 +115,17 @@ public void onWorldInit(WorldInitEvent event) {


@Override
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
public ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, String id) {
// Multiverse different y-offset support
int yOffset = 0;
if (Terraplusminus.config.getBoolean("linked_worlds.enabled") && Terraplusminus.config.getString("linked_worlds.method").equalsIgnoreCase("MULTIVERSE")) {

String lastServerName = ConfigurationHelper.getLastServerName("world");
String nextServerName = ConfigurationHelper.getNextServerName("world");
try {
if (lastServerName != null && worldName.equalsIgnoreCase(lastServerName.split(",")[0])) {
yOffset = Integer.parseInt(lastServerName.split(",")[1].replace(" ", ""));
} else if (nextServerName != null && worldName.equalsIgnoreCase(nextServerName.split(",")[0])) {
yOffset = Integer.parseInt(nextServerName.split(",")[1].replace(" ", ""));
for (LinkedWorld world : ConfigurationHelper.getWorlds()) {
if (world.getWorldName().equalsIgnoreCase(worldName)) {
yOffset = world.getOffset();
}
} catch (Exception e) {
Bukkit.getLogger().log(Level.SEVERE, "[T+-] Could not parse y-offset from config");
}
} else {
yOffset = Terraplusminus.config.getInt("y_offset");
}
return new RealWorldGenerator(yOffset);
}
Expand Down Expand Up @@ -240,7 +233,15 @@ private void updateConfig() {
FileBuilder.addLineAfter("prefix:",
"\n# If disabled, the plugin will log every fetched data to the console\n" +
"reduced_console_messages: true");

FileBuilder.deleteLine("- another_world/server");
FileBuilder.deleteLine("- current_world/server");
FileBuilder.addLineAbove("# If disabled, tree generation is turned off.",
" - name: another_world/server # e.g. this world/server has a datapack to extend height to 2032. it covers the height section (-2032) - (-1) m a.s.l. it has a y-offset of -2032.\n" +
" offset: 2032\n" +
" - name: current_world/server # e.g. this world/server has a datapack to extend height to 2032. it covers the height section 0 - 2032 m a.s.l.\n" +
" offset: 0\n" +
" - name: another_world/server # e.g. this world/server has a datapack to extend height to 2032. it covers the height section 2033 - 4064 m a.s.l. it has a y-offset of 2032\n" +
" offset: -2032\n\n");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,27 @@
public class OffsetCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
if (command.getName().equalsIgnoreCase("offset")) {
Player player = (Player) commandSender;
String worldName = player.getWorld().getName();
if (player.hasPermission("t+-.offset")) {
player.sendMessage(Terraplusminus.config.getString("prefix") + "§7Offsets:");
player.sendMessage(Terraplusminus.config.getString("prefix") + "§7 | X: §8" + Terraplusminus.config.getInt("terrain_offset.x"));

if (!Terraplusminus.config.getString("linked_worlds.method").equalsIgnoreCase("MULTIVERSE") || !Terraplusminus.config.getBoolean("linked_worlds.enabled")) {
player.sendMessage(Terraplusminus.config.getString("prefix") + "§7 | Y: §8" + Terraplusminus.config.getInt("terrain_offset.y"));
} else {
if (Terraplusminus.config.getBoolean("linked_worlds.enabled") && Terraplusminus.config.getString("linked_worlds.method").equalsIgnoreCase("MULTIVERSE")) {
player.sendMessage(Terraplusminus.config.getString("prefix") + "§9 World§7 | Y: §8" + Terraplusminus.config.getInt("terrain_offset.y"));
String lastServerName = ConfigurationHelper.getLastServerName("world");
String nextServerName = ConfigurationHelper.getNextServerName("world");
if (lastServerName != null) {
player.sendMessage(Terraplusminus.config.getString("prefix") + "§9 " + lastServerName.split(",")[0] + "§7 | Y: §8" + Integer.parseInt(lastServerName.split(",")[1].replace(" ", "")));
} else if (nextServerName != null) {
player.sendMessage(Terraplusminus.config.getString("prefix") + "§9 " + nextServerName.split(",")[0] + "§7 | Y: §8" + Integer.parseInt(nextServerName.split(",")[1].replace(" ", "")));
}
}
}
if (!command.getName().equalsIgnoreCase("offset")) {
return true;
}
Player player = (Player) commandSender;
if (player.hasPermission("t+-.offset")) {
player.sendMessage(Terraplusminus.config.getString("prefix") + "§7No permission for /offset");
return true;
}
player.sendMessage(Terraplusminus.config.getString("prefix") + "§7Offsets:");
player.sendMessage(Terraplusminus.config.getString("prefix") + "§7 | X: §8" + Terraplusminus.config.getInt("terrain_offset.x"));

player.sendMessage(Terraplusminus.config.getString("prefix") + "§7 | Z: §8" + Terraplusminus.config.getInt("terrain_offset.z"));
} else {
player.sendMessage(Terraplusminus.config.getString("prefix") + "§7No permission for /offset");
return true;
if (!Terraplusminus.config.getString("linked_worlds.method").equalsIgnoreCase("MULTIVERSE") || !Terraplusminus.config.getBoolean("linked_worlds.enabled")) {
player.sendMessage(Terraplusminus.config.getString("prefix") + "§7 | Y: §8" + Terraplusminus.config.getInt("terrain_offset.y"));
} else {
if (Terraplusminus.config.getBoolean("linked_worlds.enabled") && Terraplusminus.config.getString("linked_worlds.method").equalsIgnoreCase("MULTIVERSE")) {
ConfigurationHelper.getWorlds().forEach(world -> player.sendMessage(Terraplusminus.config.getString("prefix") + "§9 " + world.getWorldName() + "§7 | Y: §8" + world.getOffset()));
}
}

player.sendMessage(Terraplusminus.config.getString("prefix") + "§7 | Z: §8" + Terraplusminus.config.getInt("terrain_offset.z"));

return true;
}
}
Loading

0 comments on commit 111e495

Please sign in to comment.