Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
279 changes: 151 additions & 128 deletions src/main/java/de/btegermany/terraplusminus/Terraplusminus.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

Expand All @@ -30,20 +31,19 @@ public void execute(@NotNull CommandSourceStack stack, @NotNull String[] args) {
int xOffset = Terraplusminus.config.getInt("terrain_offset.x");
int zOffset = Terraplusminus.config.getInt("terrain_offset.z");

double[] mcCoordinates = new double[2];
mcCoordinates[0] = player.getLocation().getX() - xOffset;
mcCoordinates[1] = player.getLocation().getZ() - zOffset;
System.out.println(mcCoordinates[0] + ", " + mcCoordinates[1]);
double[] coordinates = new double[0];
TextComponent message = new TextComponent(Terraplusminus.config.getString("prefix"));

double playerX = player.getLocation().getX() - xOffset;
double playerZ = player.getLocation().getZ() - zOffset;
try {
coordinates = bteGeneratorSettings.projection().toGeo(mcCoordinates[0], mcCoordinates[1]);
double[] coordinates = this.bteGeneratorSettings.projection().toGeo(playerX, playerZ);
message.addExtra("§7Your coordinates are:");
Comment thread
SmylerMC marked this conversation as resolved.
message.addExtra("\n§8" + coordinates[1] + ", " + coordinates[0] + "§7.");
message.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://maps.google.com/maps?t=k&q=loc:" + coordinates[1] + "+" + coordinates[0]));
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§7Click here to view in Google Maps.").create()));
} catch (OutOfProjectionBoundsException e) {
e.printStackTrace();
message.addExtra(ChatColor.RED + "You are currently outside of the world's projection and your location in the Minecraft world has no equivalent on Earth.");
}
TextComponent message = new TextComponent(Terraplusminus.config.getString("prefix") + "§7Your coordinates are:");
message.addExtra("\n§8" + coordinates[1] + ", " + coordinates[0] + "§7.");
message.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://maps.google.com/maps?t=k&q=loc:" + coordinates[1] + "+" + coordinates[0]));
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§7Click here to view in Google Maps.").create()));
player.spigot().sendMessage(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;

import static java.lang.String.valueOf;
import static org.bukkit.ChatColor.BOLD;
Expand Down Expand Up @@ -54,7 +53,7 @@ public PlayerMoveEvent(Plugin plugin) {
for (LinkedWorld world : worlds) {
this.worldHashMap.put(world.getWorldName(), world.getOffset());
}
Bukkit.getLogger().log(Level.INFO, "[T+-] Linked worlds enabled, using Multiverse method.");
Terraplusminus.instance.getComponentLogger().info("Linked worlds enabled, using Multiverse method.");
} /*
else {
for (World world : Bukkit.getServer().getWorlds()) { // plugin loaded before worlds initialized, so that does not work
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.btegermany.terraplusminus.events;

import de.btegermany.terraplusminus.Terraplusminus;
import de.btegermany.terraplusminus.utils.PlayerHashMapManagement;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
Expand All @@ -11,6 +12,7 @@
import java.io.IOException;
import java.util.UUID;


public class PluginMessageEvent implements PluginMessageListener {

PlayerHashMapManagement playerHashMapManagement;
Expand All @@ -35,7 +37,7 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player pla
targetPlayer.chat("/tpll " + coordinates);
}
} catch (IOException e) {
e.printStackTrace();
Terraplusminus.instance.getComponentLogger().warn("Failed to read plugin message", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.List;
import java.util.concurrent.ExecutionException;


public class CustomBiomeProvider extends BiomeProvider {

private final KoppenClimateData climateData = new KoppenClimateData();
Expand Down Expand Up @@ -45,9 +46,16 @@ public Biome getBiome(@NotNull WorldInfo worldInfo, int x, int y, int z) {
try {
biomeData = this.climateData.getAsync(coords[0], coords[1]).get();
return koppenDataToBukkitBiome(biomeData);
} catch (InterruptedException | ExecutionException | OutOfProjectionBoundsException e) {
e.printStackTrace();

} catch (OutOfProjectionBoundsException silenced) {
// This is not an issue,
// we can't be expected to supply a realistic biome for a place that does not exist on Earth
} catch (InterruptedException | ExecutionException e) {
Terraplusminus.instance.getComponentLogger().warn(
"Exception when generating biome at position {}/{}/{} in world {}",
x, y, z,
worldInfo.getName(),
e
);
}
} else biomeData = 8; // Default is plains for tree generation
return parseDefaultBiome();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;


public class TreePopulator extends BlockPopulator {

Expand Down Expand Up @@ -69,35 +69,43 @@ public TreePopulator(CustomBiomeProvider customBiomeProvider, int yOffset) {

// Load Trees from customTrees.json
JsonObject treeTypes = getJSONObject();
final int[] treeCount = {0};
treeTypes.entrySet().forEach(treeSizes -> {

trees.put(treeSizes.getKey(), new ArrayList<>());

Bukkit.getLogger().log(Level.INFO, "[T+-] Loading Tree Type " + treeSizes.getKey());

treeSizes.getValue().getAsJsonObject().entrySet().forEach(treeNames -> {

treeNames.getValue().getAsJsonObject().entrySet().forEach(tree -> {

treeCount[0]++;
final TreeLoadingStatistics stats = new TreeLoadingStatistics();
treeTypes.entrySet().forEach(treeTypeEntry -> {
final String treeType = treeTypeEntry.getKey();
final JsonObject treeSizeVariants = treeTypeEntry.getValue().getAsJsonObject();
stats.familyCount++;
Terraplusminus.instance.getComponentLogger().debug("Loading tree family {} with {} size variants", treeType, treeSizeVariants.size());

this.trees.put(treeType, new ArrayList<>());

treeSizeVariants.entrySet().forEach(variantEntry -> {
final String sizeName = variantEntry.getKey(); // s, m, l, ...
final JsonObject treeVariants = variantEntry.getValue().getAsJsonObject();
Terraplusminus.instance.getComponentLogger().trace("Loading trees of family {} and size {} with {} variants", treeType, sizeName, treeVariants.size());

treeVariants.entrySet().forEach(treeEntry -> {
final String treeName = treeEntry.getKey();
final JsonObject treeConfig = treeEntry.getValue().getAsJsonObject();
Terraplusminus.instance.getComponentLogger().trace("Loading tree variant {} of size {} and family {}", treeName, sizeName, treeType);

stats.totalVariantCount++;
ArrayList<TreeBlock> treeBlocks = new ArrayList<>();

tree.getValue().getAsJsonObject().get("blocks").getAsJsonArray().forEach(treeBlockElement -> {
treeConfig.get("blocks").getAsJsonArray().forEach(treeBlockElement -> {

JsonObject treeBlock = treeBlockElement.getAsJsonObject();
treeBlocks.add(new TreeBlock(treeBlock.get("x").getAsInt(), treeBlock.get("y").getAsInt(), treeBlock.get("z").getAsInt(), Material.getMaterial(treeBlock.get("material").getAsString())));

});

trees.get(treeSizes.getKey()).add(treeBlocks);
trees.get(treeTypeEntry.getKey()).add(treeBlocks);

});

});

});
Bukkit.getLogger().log(Level.INFO, "[T+-] Finished loading " + treeCount[0] + " custom trees");
Terraplusminus.instance.getComponentLogger().info("Loaded {} custom trees from {} families", stats.totalVariantCount, stats.familyCount);

}

Expand Down Expand Up @@ -126,7 +134,10 @@ public void populate(@NotNull WorldInfo worldInfo, @NotNull Random random, int x
waterY = data.waterHeight(valueX, valueZ);
state = data.surfaceBlock(valueX, valueZ);
} catch (IndexOutOfBoundsException e) {
e.printStackTrace();
Terraplusminus.instance.getComponentLogger().warn(
"Chunk boundary overflow when attempting to generate a tree at chunk {}/{}",
x, z
);
}

if (groundY < waterY) {
Expand Down Expand Up @@ -159,7 +170,12 @@ public void populate(@NotNull WorldInfo worldInfo, @NotNull Random random, int x


} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
Terraplusminus.instance.getComponentLogger().warn(
"Exception when generating trees in chunk {}/{} in world {}",
x, z,
worldInfo.getName(),
e
);
}
}
}
Expand Down Expand Up @@ -221,4 +237,9 @@ public JsonObject getJSONObject() {
return jsonObject.get("trees").getAsJsonObject();
}

private static class TreeLoadingStatistics {
int familyCount = 0;
int totalVariantCount = 0;
}

}
Loading