|
|
|
|
@@ -1,10 +1,12 @@
|
|
|
|
|
package ciomek.quetzal.commands;
|
|
|
|
|
|
|
|
|
|
import ciomek.quetzal.IWorldUtils;
|
|
|
|
|
import ciomek.quetzal.Utils;
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
import com.google.gson.reflect.TypeToken;
|
|
|
|
|
import com.mojang.brigadier.CommandDispatcher;
|
|
|
|
|
import com.mojang.brigadier.builder.ArgumentBuilderLiteral;
|
|
|
|
|
import net.fabricmc.loader.api.FabricLoader;
|
|
|
|
|
import net.minecraft.core.entity.player.Player;
|
|
|
|
|
import net.minecraft.core.net.command.CommandManager;
|
|
|
|
|
import net.minecraft.core.net.command.CommandSource;
|
|
|
|
|
@@ -22,7 +24,8 @@ import java.util.Map;
|
|
|
|
|
public class HomeCommand implements CommandManager.CommandRegistry, ModInitializer {
|
|
|
|
|
private static final Map<String, double[]> homes = new HashMap<>();
|
|
|
|
|
private static final Gson gson = new Gson();
|
|
|
|
|
private static final File homesFile = new File("homes.json");
|
|
|
|
|
private static final File homesFile =
|
|
|
|
|
new File(FabricLoader.getInstance().getConfigDir().toFile(), "homes.json");
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onInitialize() {
|
|
|
|
|
@@ -90,14 +93,14 @@ public class HomeCommand implements CommandManager.CommandRegistry, ModInitializ
|
|
|
|
|
|
|
|
|
|
double[] home = homes.get(player.username);
|
|
|
|
|
|
|
|
|
|
double startX = round1(player.x);
|
|
|
|
|
double startY = round1(player.y);
|
|
|
|
|
double startZ = round1(player.z);
|
|
|
|
|
double startX = Utils.round1(player.x);
|
|
|
|
|
double startY = Utils.round1(player.y);
|
|
|
|
|
double startZ = Utils.round1(player.z);
|
|
|
|
|
|
|
|
|
|
player.sendMessage("Teleporting home. Don't move for 5 seconds...");
|
|
|
|
|
|
|
|
|
|
worldUtils.addTickCallback(100, (w) -> {
|
|
|
|
|
if (round1(player.x) != startX || round1(player.y) != startY || round1(player.z) != startZ) {
|
|
|
|
|
if (Utils.round1(player.x) != startX || Utils.round1(player.y) != startY || Utils.round1(player.z) != startZ) {
|
|
|
|
|
player.sendMessage("Teleport cancelled because you moved.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
@@ -110,8 +113,4 @@ public class HomeCommand implements CommandManager.CommandRegistry, ModInitializ
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private double round1(double value) {
|
|
|
|
|
return Math.round(value * 10.0) / 10.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|