forked from SteamWar/SteamWar
Improved tracer Lib
This commit is contained in:
+17
-29
@@ -6,15 +6,8 @@ import de.steamwar.bausystem.features.tracer.TraceManager;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.luaj.vm2.LuaError;
|
|
||||||
import org.luaj.vm2.LuaInteger;
|
|
||||||
import org.luaj.vm2.LuaTable;
|
import org.luaj.vm2.LuaTable;
|
||||||
import org.luaj.vm2.LuaValue;
|
import org.luaj.vm2.LuaValue;
|
||||||
import org.luaj.vm2.lib.OneArgFunction;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class TracerLib implements LuaLib{
|
public class TracerLib implements LuaLib{
|
||||||
@Override
|
@Override
|
||||||
@@ -23,12 +16,19 @@ public class TracerLib implements LuaLib{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private LuaTable convertTrace(Trace trace) {
|
private LuaTable convertTrace(Trace trace) {
|
||||||
return LuaValue.listOf(
|
LuaTable luaTrace = new LuaTable();
|
||||||
|
|
||||||
|
luaTrace.set("getRecords", getter(() -> LuaValue.listOf(
|
||||||
trace.getHistories()
|
trace.getHistories()
|
||||||
.stream()
|
.stream()
|
||||||
.map((history) -> LuaValue.listOf(history.stream().map(this::convertTntPoint).toArray(LuaValue[]::new)))
|
.map((history) -> LuaValue.listOf(history.stream().map(this::convertTntPoint).toArray(LuaValue[]::new)))
|
||||||
.toArray(LuaValue[]::new)
|
.toArray(LuaValue[]::new)
|
||||||
);
|
)));
|
||||||
|
|
||||||
|
luaTrace.set("getId", getter(() -> TraceManager.instance.getId(trace)));
|
||||||
|
|
||||||
|
|
||||||
|
return luaTrace;
|
||||||
}
|
}
|
||||||
|
|
||||||
private LuaTable convertTntPoint(TNTPoint tntPoint) {
|
private LuaTable convertTntPoint(TNTPoint tntPoint) {
|
||||||
@@ -62,23 +62,11 @@ public class TracerLib implements LuaLib{
|
|||||||
public LuaTable get(Player player) {
|
public LuaTable get(Player player) {
|
||||||
LuaTable rootTable = new LuaTable();
|
LuaTable rootTable = new LuaTable();
|
||||||
|
|
||||||
rootTable.set("getTrace", new OneArgFunction() {
|
rootTable.set("getTraces", getter(() ->
|
||||||
@Override
|
LuaValue.listOf(TraceManager.instance.getAll()
|
||||||
public LuaValue call(LuaValue arg) {
|
.stream()
|
||||||
int id = arg.checkint();
|
.map((trace) -> convertTrace(trace))
|
||||||
|
.toArray(LuaValue[]::new))
|
||||||
Optional<Trace> traceResult = TraceManager.instance.get(id);
|
|
||||||
if(traceResult.isEmpty()) {
|
|
||||||
throw new LuaError("No trace found with id " + id);
|
|
||||||
} else {
|
|
||||||
return convertTrace(traceResult.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
rootTable.set("getAllTraceIds", getter(() -> LuaValue.listOf(TraceManager.instance.getAllIds()
|
|
||||||
.stream()
|
|
||||||
.map((id) -> LuaValue.valueOf(id)).toArray(LuaValue[]::new))
|
|
||||||
));
|
));
|
||||||
|
|
||||||
return rootTable;
|
return rootTable;
|
||||||
|
|||||||
Reference in New Issue
Block a user