mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-19 14:50:30 +00:00
Slight change to how world edit is loaded + make locate commands like vanilla (#38)
* make getWorldEdit() never null. Signed-off-by: solonovamax <solonovamax@12oclockpoint.com> * Locate commands work like vanilla Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import java.nio.file.StandardCopyOption
|
||||
plugins {
|
||||
java
|
||||
maven
|
||||
idea
|
||||
id("com.github.johnrengelman.shadow").version("6.1.0")
|
||||
}
|
||||
|
||||
|
||||
@@ -5,12 +5,19 @@ import com.dfsek.terra.api.gaea.command.WorldCommand;
|
||||
import com.dfsek.terra.async.AsyncBiomeFinder;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
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.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -25,6 +32,7 @@ public class BiomeLocateCommand extends WorldCommand {
|
||||
this.tp = teleport;
|
||||
}
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
||||
String id = args[0];
|
||||
@@ -44,11 +52,14 @@ public class BiomeLocateCommand extends WorldCommand {
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(getMain(), new AsyncBiomeFinder(((Terra) getMain()).getWorld(world).getGrid(), b, sender.getLocation().clone().multiply((1D / ((Terra) getMain()).getTerraConfig().getBiomeSearchResolution())), 0, maxRadius, location -> {
|
||||
if(location != null) {
|
||||
LangUtil.send("command.biome.biome-found", sender, String.valueOf(location.getBlockX()), String.valueOf(location.getBlockZ()));
|
||||
if(tp) {
|
||||
Location l = new Location(sender.getWorld(), location.getX(), sender.getLocation().getY(), location.getZ());
|
||||
Bukkit.getScheduler().runTask(getMain(), () -> sender.teleport(l));
|
||||
}
|
||||
ComponentBuilder cm = new ComponentBuilder(String.format("The nearest %s is at ", id.toLowerCase()))
|
||||
.append(String.format("[%d, ~, %d]", location.getBlockX(), location.getBlockZ()), ComponentBuilder.FormatRetention.NONE)
|
||||
.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/minecraft:tp %s %d.0 %.2f %d.0", sender.getName(), location.getBlockX(), sender.getLocation().getY(), location.getBlockZ())))
|
||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new BaseComponent[] {new TextComponent("Click to teleport")}))
|
||||
.color(ChatColor.GREEN)
|
||||
.append(String.format(" (%.1f blocks away)", location.add(new Vector(0, sender.getLocation().getY(), 0)).distance(sender.getLocation().toVector())), ComponentBuilder.FormatRetention.NONE);
|
||||
sender.spigot().sendMessage(cm.create());
|
||||
// LangUtil.send("command.biome.biome-found", sender, String.valueOf(location.getBlockX()), String.valueOf(location.getBlockZ()));
|
||||
} else LangUtil.send("command.biome.unable-to-locate", sender);
|
||||
}, (Terra) getMain()));
|
||||
return true;
|
||||
|
||||
@@ -5,12 +5,18 @@ import com.dfsek.terra.api.gaea.command.WorldCommand;
|
||||
import com.dfsek.terra.async.AsyncStructureFinder;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
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.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -26,10 +32,12 @@ public class LocateCommand extends WorldCommand {
|
||||
this.tp = tp;
|
||||
}
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
|
||||
String id = args[0];
|
||||
int maxRadius;
|
||||
|
||||
try {
|
||||
maxRadius = Integer.parseInt(args[1]);
|
||||
} catch(NumberFormatException e) {
|
||||
@@ -46,13 +54,15 @@ public class LocateCommand extends WorldCommand {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(getMain(), new AsyncStructureFinder(((Terra) getMain()).getWorld(world).getGrid(), s, sender.getLocation(), 0, maxRadius, (location) -> {
|
||||
if(sender.isOnline()) {
|
||||
if(location != null) {
|
||||
sender.sendMessage("Located structure at (" + location.getBlockX() + ", " + location.getBlockZ() + ").");
|
||||
if(tp) {
|
||||
int finalX = location.getBlockX();
|
||||
int finalZ = location.getBlockZ();
|
||||
Bukkit.getScheduler().runTask(getMain(), () -> sender.teleport(new Location(sender.getWorld(), finalX, sender.getLocation().getY(), finalZ)));
|
||||
}
|
||||
} else sender.sendMessage("Unable to locate structure. ");
|
||||
ComponentBuilder cm = new ComponentBuilder(String.format("The nearest %s is at ", id.toLowerCase()))
|
||||
.append(String.format("[%d, ~, %d]", location.getBlockX(), location.getBlockZ()), ComponentBuilder.FormatRetention.NONE)
|
||||
.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/minecraft:tp %s %d.0 %.2f %d.0", sender.getName(), location.getBlockX(), sender.getLocation().getY(), location.getBlockZ())))
|
||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new BaseComponent[] {new TextComponent("Click to teleport")}))
|
||||
.color(ChatColor.GREEN)
|
||||
.append(String.format(" (%.1f blocks away)", location.add(new Vector(0, sender.getLocation().getY(), 0)).distance(sender.getLocation().toVector())), ComponentBuilder.FormatRetention.NONE);
|
||||
sender.spigot().sendMessage(cm.create());
|
||||
} else
|
||||
sender.sendMessage("Unable to locate structure. ");
|
||||
}
|
||||
}, (Terra) getMain()));
|
||||
return true;
|
||||
|
||||
@@ -48,7 +48,8 @@ public class StructurePopulator extends BlockPopulator {
|
||||
structure:
|
||||
for(TerraStructure conf : config.getStructures()) {
|
||||
Location spawn = conf.getSpawn().getNearestSpawn(cx + 8, cz + 8, world.getSeed()).toLocation(world);
|
||||
if(!((UserDefinedBiome) grid.getBiome(spawn)).getConfig().getStructures().contains(conf)) continue;
|
||||
if(!((UserDefinedBiome) grid.getBiome(spawn)).getConfig().getStructures().contains(conf))
|
||||
continue;
|
||||
Random r2 = new FastRandom(spawn.hashCode());
|
||||
Structure struc = conf.getStructures().get(r2);
|
||||
Rotation rotation = Rotation.fromDegrees(r2.nextInt(4) * 90);
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.dfsek.terra.util.structure;
|
||||
|
||||
public class WorldEditNotFoundException extends RuntimeException {
|
||||
public WorldEditNotFoundException() {
|
||||
}
|
||||
|
||||
public WorldEditNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public WorldEditNotFoundException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public WorldEditNotFoundException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public WorldEditNotFoundException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
||||
@@ -10,13 +10,16 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class WorldEditUtil {
|
||||
public static Location[] getSelectionLocations(Player sender) {
|
||||
WorldEditPlugin we = WorldEditUtil.getWorldEdit();
|
||||
if(we == null) {
|
||||
WorldEditPlugin we;
|
||||
try {
|
||||
we = WorldEditUtil.getWorldEdit();
|
||||
} catch(WorldEditNotFoundException e) {
|
||||
sender.sendMessage("WorldEdit is not installed! Please install WorldEdit before attempting to export structures.");
|
||||
return null;
|
||||
throw e;
|
||||
}
|
||||
Region selection;
|
||||
try {
|
||||
@@ -36,18 +39,27 @@ public final class WorldEditUtil {
|
||||
return new Location[] {l1, l2};
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an instance of the WorldEditPlugin class.
|
||||
*
|
||||
* @return The world edit plugin instance.
|
||||
* @throws WorldEditNotFoundException Thrown when worldedit cannot be found.
|
||||
*/
|
||||
@NotNull
|
||||
public static WorldEditPlugin getWorldEdit() {
|
||||
Plugin p = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
if(p instanceof WorldEditPlugin) return (WorldEditPlugin) p;
|
||||
Bukkit.getLogger().severe("[Terra] a command requiring WorldEdit was executed, but WorldEdit was not detected!");
|
||||
return null;
|
||||
throw new WorldEditNotFoundException("Could not find World Edit!");
|
||||
}
|
||||
|
||||
public static Location[] getSelectionPositions(Player sender) {
|
||||
WorldEditPlugin we = WorldEditUtil.getWorldEdit();
|
||||
if(we == null) {
|
||||
WorldEditPlugin we;
|
||||
try {
|
||||
we = WorldEditUtil.getWorldEdit();
|
||||
} catch(WorldEditNotFoundException e) {
|
||||
sender.sendMessage("WorldEdit is not installed! Please install WorldEdit before attempting to export structures.");
|
||||
return null;
|
||||
throw e;
|
||||
}
|
||||
CuboidRegion selection;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user