mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-06-17 14:21:33 +00:00
Merge pull request #7 from CrazyDev05/Pixeldev
implement showing location instead of teleporting
This commit is contained in:
@@ -34,7 +34,9 @@ public class CommandFind implements DecreeExecutor {
|
|||||||
@Decree(description = "Find a biome")
|
@Decree(description = "Find a biome")
|
||||||
public void biome(
|
public void biome(
|
||||||
@Param(description = "The biome to look for")
|
@Param(description = "The biome to look for")
|
||||||
IrisBiome biome
|
IrisBiome biome,
|
||||||
|
@Param(description = "Should you be teleported", defaultValue = "true")
|
||||||
|
boolean teleport
|
||||||
) {
|
) {
|
||||||
Engine e = engine();
|
Engine e = engine();
|
||||||
|
|
||||||
@@ -43,13 +45,15 @@ public class CommandFind implements DecreeExecutor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.gotoBiome(biome, player());
|
e.gotoBiome(biome, player(), teleport);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Decree(description = "Find a region")
|
@Decree(description = "Find a region")
|
||||||
public void region(
|
public void region(
|
||||||
@Param(description = "The region to look for")
|
@Param(description = "The region to look for")
|
||||||
IrisRegion region
|
IrisRegion region,
|
||||||
|
@Param(description = "Should you be teleported", defaultValue = "true")
|
||||||
|
boolean teleport
|
||||||
) {
|
) {
|
||||||
Engine e = engine();
|
Engine e = engine();
|
||||||
|
|
||||||
@@ -58,13 +62,15 @@ public class CommandFind implements DecreeExecutor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.gotoRegion(region, player());
|
e.gotoRegion(region, player(), teleport);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Decree(description = "Find a structure")
|
@Decree(description = "Find a structure")
|
||||||
public void structure(
|
public void structure(
|
||||||
@Param(description = "The structure to look for")
|
@Param(description = "The structure to look for")
|
||||||
IrisJigsawStructure structure
|
IrisJigsawStructure structure,
|
||||||
|
@Param(description = "Should you be teleported", defaultValue = "true")
|
||||||
|
boolean teleport
|
||||||
) {
|
) {
|
||||||
Engine e = engine();
|
Engine e = engine();
|
||||||
|
|
||||||
@@ -73,13 +79,15 @@ public class CommandFind implements DecreeExecutor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.gotoJigsaw(structure, player());
|
e.gotoJigsaw(structure, player(), teleport);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Decree(description = "Find a point of interest.")
|
@Decree(description = "Find a point of interest.")
|
||||||
public void poi(
|
public void poi(
|
||||||
@Param(description = "The type of PoI to look for.")
|
@Param(description = "The type of PoI to look for.")
|
||||||
String type
|
String type,
|
||||||
|
@Param(description = "Should you be teleported", defaultValue = "true")
|
||||||
|
boolean teleport
|
||||||
) {
|
) {
|
||||||
Engine e = engine();
|
Engine e = engine();
|
||||||
if (e == null) {
|
if (e == null) {
|
||||||
@@ -87,13 +95,15 @@ public class CommandFind implements DecreeExecutor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.gotoPOI(type, player());
|
e.gotoPOI(type, player(), teleport);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Decree(description = "Find an object")
|
@Decree(description = "Find an object")
|
||||||
public void object(
|
public void object(
|
||||||
@Param(description = "The object to look for", customHandler = ObjectHandler.class)
|
@Param(description = "The object to look for", customHandler = ObjectHandler.class)
|
||||||
String object
|
String object,
|
||||||
|
@Param(description = "Should you be teleported", defaultValue = "true")
|
||||||
|
boolean teleport
|
||||||
) {
|
) {
|
||||||
Engine e = engine();
|
Engine e = engine();
|
||||||
|
|
||||||
@@ -102,6 +112,6 @@ public class CommandFind implements DecreeExecutor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.gotoObject(object, player());
|
e.gotoObject(object, player(), teleport);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -804,7 +804,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
|||||||
return getBiomeOrMantle(l.getBlockX(), l.getBlockY(), l.getBlockZ());
|
return getBiomeOrMantle(l.getBlockX(), l.getBlockY(), l.getBlockZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
default void gotoBiome(IrisBiome biome, Player player) {
|
default void gotoBiome(IrisBiome biome, Player player, boolean teleport) {
|
||||||
Set<String> regionKeys = getDimension()
|
Set<String> regionKeys = getDimension()
|
||||||
.getAllRegions(this).stream()
|
.getAllRegions(this).stream()
|
||||||
.filter((i) -> i.getAllBiomes(this).contains(biome))
|
.filter((i) -> i.getAllBiomes(this).contains(biome))
|
||||||
@@ -816,13 +816,13 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
|||||||
&& lb.matches(engine, chunk);
|
&& lb.matches(engine, chunk);
|
||||||
|
|
||||||
if (!regionKeys.isEmpty()) {
|
if (!regionKeys.isEmpty()) {
|
||||||
locator.find(player);
|
locator.find(player, teleport, "Biome " + biome.getName());
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(C.RED + biome.getName() + " is not in any defined regions!");
|
player.sendMessage(C.RED + biome.getName() + " is not in any defined regions!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
default void gotoJigsaw(IrisJigsawStructure s, Player player) {
|
default void gotoJigsaw(IrisJigsawStructure s, Player player, boolean teleport) {
|
||||||
if (s.getLoadKey().equals(getDimension().getStronghold())) {
|
if (s.getLoadKey().equals(getDimension().getStronghold())) {
|
||||||
KList<Position2> p = getDimension().getStrongholds(getSeedManager().getSpawn());
|
KList<Position2> p = getDimension().getStrongholds(getSeedManager().getSpawn());
|
||||||
|
|
||||||
@@ -859,7 +859,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
|||||||
if (getDimension().getJigsawStructures().stream()
|
if (getDimension().getJigsawStructures().stream()
|
||||||
.map(IrisJigsawStructurePlacement::getStructure)
|
.map(IrisJigsawStructurePlacement::getStructure)
|
||||||
.collect(Collectors.toSet()).contains(s.getLoadKey())) {
|
.collect(Collectors.toSet()).contains(s.getLoadKey())) {
|
||||||
Locator.jigsawStructure(s.getLoadKey()).find(player);
|
Locator.jigsawStructure(s.getLoadKey()).find(player, teleport, "Structure " + s.getLoadKey());
|
||||||
} else {
|
} else {
|
||||||
Set<String> biomeKeys = getDimension().getAllBiomes(this).stream()
|
Set<String> biomeKeys = getDimension().getAllBiomes(this).stream()
|
||||||
.filter((i) -> i.getJigsawStructures()
|
.filter((i) -> i.getJigsawStructures()
|
||||||
@@ -886,7 +886,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (!regionKeys.isEmpty()) {
|
if (!regionKeys.isEmpty()) {
|
||||||
locator.find(player);
|
locator.find(player, teleport, "Structure " + s.getLoadKey());
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(C.RED + s.getLoadKey() + " is not in any defined regions, biomes or dimensions!");
|
player.sendMessage(C.RED + s.getLoadKey() + " is not in any defined regions, biomes or dimensions!");
|
||||||
}
|
}
|
||||||
@@ -894,7 +894,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default void gotoObject(String s, Player player) {
|
default void gotoObject(String s, Player player, boolean teleport) {
|
||||||
Set<String> biomeKeys = getDimension().getAllBiomes(this).stream()
|
Set<String> biomeKeys = getDimension().getAllBiomes(this).stream()
|
||||||
.filter((i) -> i.getObjects().stream().anyMatch((f) -> f.getPlace().contains(s)))
|
.filter((i) -> i.getObjects().stream().anyMatch((f) -> f.getPlace().contains(s)))
|
||||||
.map(IrisRegistrant::getLoadKey)
|
.map(IrisRegistrant::getLoadKey)
|
||||||
@@ -917,23 +917,23 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (!regionKeys.isEmpty()) {
|
if (!regionKeys.isEmpty()) {
|
||||||
locator.find(player);
|
locator.find(player, teleport, "Object " + s);
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(C.RED + s + " is not in any defined regions or biomes!");
|
player.sendMessage(C.RED + s + " is not in any defined regions or biomes!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
default void gotoRegion(IrisRegion r, Player player) {
|
default void gotoRegion(IrisRegion r, Player player, boolean teleport) {
|
||||||
if (!getDimension().getAllRegions(this).contains(r)) {
|
if (!getDimension().getAllRegions(this).contains(r)) {
|
||||||
player.sendMessage(C.RED + r.getName() + " is not defined in the dimension!");
|
player.sendMessage(C.RED + r.getName() + " is not defined in the dimension!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Locator.region(r.getLoadKey()).find(player);
|
Locator.region(r.getLoadKey()).find(player, teleport, "Region " + r.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
default void gotoPOI(String type, Player p) {
|
default void gotoPOI(String type, Player p, boolean teleport) {
|
||||||
Locator.poi(type).find(p);
|
Locator.poi(type).find(p, teleport, "POI " + type);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void cleanupMantleChunk(int x, int z) {
|
default void cleanupMantleChunk(int x, int z) {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import com.volmit.iris.engine.object.IrisJigsawStructure;
|
|||||||
import com.volmit.iris.engine.object.IrisObject;
|
import com.volmit.iris.engine.object.IrisObject;
|
||||||
import com.volmit.iris.engine.object.IrisRegion;
|
import com.volmit.iris.engine.object.IrisRegion;
|
||||||
import com.volmit.iris.util.context.ChunkContext;
|
import com.volmit.iris.util.context.ChunkContext;
|
||||||
|
import com.volmit.iris.util.format.C;
|
||||||
import com.volmit.iris.util.format.Form;
|
import com.volmit.iris.util.format.Form;
|
||||||
import com.volmit.iris.util.math.M;
|
import com.volmit.iris.util.math.M;
|
||||||
import com.volmit.iris.util.math.Position2;
|
import com.volmit.iris.util.math.Position2;
|
||||||
@@ -39,6 +40,7 @@ import com.volmit.iris.util.scheduling.J;
|
|||||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||||
import com.volmit.iris.util.scheduling.jobs.SingleJob;
|
import com.volmit.iris.util.scheduling.jobs.SingleJob;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -109,23 +111,35 @@ public interface Locator<T> {
|
|||||||
|
|
||||||
boolean matches(Engine engine, Position2 chunk);
|
boolean matches(Engine engine, Position2 chunk);
|
||||||
|
|
||||||
default void find(Player player) {
|
default void find(Player player, boolean teleport, String message) {
|
||||||
find(player, 30_000);
|
find(player, location -> {
|
||||||
|
if (teleport) {
|
||||||
|
J.s(() -> player.teleport(location));
|
||||||
|
} else {
|
||||||
|
player.sendMessage(C.GREEN + message + " at: " + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
default void find(Player player, long timeout) {
|
default void find(Player player, Consumer<Location> consumer) {
|
||||||
|
find(player, 30_000, consumer);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void find(Player player, long timeout, Consumer<Location> consumer) {
|
||||||
AtomicLong checks = new AtomicLong();
|
AtomicLong checks = new AtomicLong();
|
||||||
long ms = M.ms();
|
long ms = M.ms();
|
||||||
new SingleJob("Searching", () -> {
|
new SingleJob("Searching", () -> {
|
||||||
try {
|
try {
|
||||||
Position2 at = find(IrisToolbelt.access(player.getWorld()).getEngine(), new Position2(player.getLocation().getBlockX() >> 4, player.getLocation().getBlockZ() >> 4), timeout, checks::set).get();
|
World world = player.getWorld();
|
||||||
|
Engine engine = IrisToolbelt.access(world).getEngine();
|
||||||
|
Position2 at = find(engine, new Position2(player.getLocation().getBlockX() >> 4, player.getLocation().getBlockZ() >> 4), timeout, checks::set).get();
|
||||||
|
|
||||||
if (at != null) {
|
if (at != null) {
|
||||||
J.s(() -> player.teleport(new Location(player.getWorld(), (at.getX() << 4) + 8,
|
consumer.accept(new Location(world, (at.getX() << 4) + 8,
|
||||||
IrisToolbelt.access(player.getWorld()).getEngine().getHeight(
|
engine.getHeight(
|
||||||
(at.getX() << 4) + 8,
|
(at.getX() << 4) + 8,
|
||||||
(at.getZ() << 4) + 8, false),
|
(at.getZ() << 4) + 8, false),
|
||||||
(at.getZ() << 4) + 8)));
|
(at.getZ() << 4) + 8));
|
||||||
}
|
}
|
||||||
} catch (WrongEngineBroException | InterruptedException | ExecutionException e) {
|
} catch (WrongEngineBroException | InterruptedException | ExecutionException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
Reference in New Issue
Block a user