aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2020-04-13 19:16:10 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2020-04-13 19:16:10 +0200
commitc532050d4d29cc55559fadd591f3ffad47246572 (patch)
treea1d29829949456485a46aefca452fff59646a5bd /src/main
parent792549e981f5370f07502cab8ca4063e3c76feb9 (diff)
downloadparquet-c532050d4d29cc55559fadd591f3ffad47246572.tar.gz
added camermode command with location reset
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/re/jag/parquet/Parquet.java13
-rw-r--r--src/main/java/re/jag/parquet/commands/CameraMode.java61
-rw-r--r--src/main/java/re/jag/parquet/commands/CameraModeData.java7
-rw-r--r--src/main/java/re/jag/parquet/commands/ListAllPlayerSaves.java38
-rw-r--r--src/main/java/re/jag/parquet/mixin/CommandManagerMixin.java26
-rw-r--r--src/main/java/re/jag/parquet/mixin/ServerPlayerEntityMixin.java89
-rw-r--r--src/main/resources/parquet.mixins.json6
7 files changed, 237 insertions, 3 deletions
diff --git a/src/main/java/re/jag/parquet/Parquet.java b/src/main/java/re/jag/parquet/Parquet.java
index 01735c6..17c3021 100644
--- a/src/main/java/re/jag/parquet/Parquet.java
+++ b/src/main/java/re/jag/parquet/Parquet.java
@@ -1,13 +1,22 @@
package re.jag.parquet;
+import com.mojang.brigadier.CommandDispatcher;
+
import net.fabricmc.api.ModInitializer;
+import net.minecraft.server.command.ServerCommandSource;
+import re.jag.parquet.commands.CameraMode;
+import re.jag.parquet.commands.ListAllPlayerSaves;
public class Parquet implements ModInitializer {
@Override
public void onInitialize() {
- // TODO Auto-generated method stub
-
+
+ }
+
+ public static void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher) {
+ ListAllPlayerSaves.register(dispatcher);
+ CameraMode.register(dispatcher);
}
}
diff --git a/src/main/java/re/jag/parquet/commands/CameraMode.java b/src/main/java/re/jag/parquet/commands/CameraMode.java
new file mode 100644
index 0000000..f65e1e7
--- /dev/null
+++ b/src/main/java/re/jag/parquet/commands/CameraMode.java
@@ -0,0 +1,61 @@
+package re.jag.parquet.commands;
+
+import static net.minecraft.server.command.CommandManager.argument;
+import static net.minecraft.server.command.CommandManager.literal;
+
+import com.mojang.brigadier.CommandDispatcher;
+import com.mojang.brigadier.builder.LiteralArgumentBuilder;
+
+import net.minecraft.command.arguments.EntityArgumentType;
+import net.minecraft.entity.effect.StatusEffectInstance;
+import net.minecraft.entity.effect.StatusEffects;
+import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket;
+import net.minecraft.network.packet.s2c.play.RemoveEntityStatusEffectS2CPacket;
+import net.minecraft.server.command.ServerCommandSource;
+import net.minecraft.server.network.ServerPlayerEntity;
+import net.minecraft.text.LiteralText;
+import net.minecraft.world.GameMode;
+
+public class CameraMode {
+ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
+ LiteralArgumentBuilder<ServerCommandSource> camermode = literal("c").
+ executes((c) -> camera( c.getSource(), c.getSource().getPlayer())).
+ then(argument("player", EntityArgumentType.player()).
+ executes( (c) -> camera(c.getSource(), EntityArgumentType.getPlayer(c, "player"))));
+ LiteralArgumentBuilder<ServerCommandSource> survivalmode = literal("s").
+ executes((c) -> survival( c.getSource(), c.getSource().getPlayer())).
+ then(argument("player", EntityArgumentType.player()).
+ executes( (c) -> survival(c.getSource(), EntityArgumentType.getPlayer(c, "player"))));
+
+ dispatcher.register(camermode);
+ dispatcher.register(survivalmode);
+ }
+
+ private static int camera(ServerCommandSource source, ServerPlayerEntity player) {
+ if (! ((CameraModeData)player).saveCameraPosition() ) {
+ source.sendFeedback(new LiteralText("Gamemode is already camera"), false);
+ return 0;
+ }
+
+ player.setGameMode(GameMode.SPECTATOR);
+ player.addVelocity(0,0.1,0);
+ player.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(player));
+ player.addStatusEffect(new StatusEffectInstance(StatusEffects.NIGHT_VISION, 999999, 0, false, false));
+ player.addStatusEffect(new StatusEffectInstance(StatusEffects.CONDUIT_POWER, 999999, 0, false, false));
+ return 1;
+ }
+
+ private static int survival(ServerCommandSource source, ServerPlayerEntity player) {
+ if (! ((CameraModeData)player).restoreCameraPosition() ) {
+ source.sendFeedback(new LiteralText("Gamemode is already survival"), false);
+ return 0;
+ }
+
+ player.setGameMode(GameMode.SURVIVAL);
+ player.networkHandler.sendPacket(new RemoveEntityStatusEffectS2CPacket(player.getEntityId(), StatusEffects.NIGHT_VISION));
+ player.removeStatusEffect(StatusEffects.NIGHT_VISION);
+ player.networkHandler.sendPacket(new RemoveEntityStatusEffectS2CPacket(player.getEntityId(), StatusEffects.CONDUIT_POWER));
+ player.removeStatusEffect(StatusEffects.CONDUIT_POWER);
+ return 1;
+ }
+}
diff --git a/src/main/java/re/jag/parquet/commands/CameraModeData.java b/src/main/java/re/jag/parquet/commands/CameraModeData.java
new file mode 100644
index 0000000..c1319f9
--- /dev/null
+++ b/src/main/java/re/jag/parquet/commands/CameraModeData.java
@@ -0,0 +1,7 @@
+package re.jag.parquet.commands;
+
+public interface CameraModeData {
+ boolean saveCameraPosition();
+
+ boolean restoreCameraPosition();
+}
diff --git a/src/main/java/re/jag/parquet/commands/ListAllPlayerSaves.java b/src/main/java/re/jag/parquet/commands/ListAllPlayerSaves.java
new file mode 100644
index 0000000..53e8a7e
--- /dev/null
+++ b/src/main/java/re/jag/parquet/commands/ListAllPlayerSaves.java
@@ -0,0 +1,38 @@
+package re.jag.parquet.commands;
+
+import static net.minecraft.server.command.CommandManager.literal;
+
+import com.mojang.brigadier.CommandDispatcher;
+import com.mojang.brigadier.builder.LiteralArgumentBuilder;
+import java.util.UUID;
+import com.mojang.authlib.GameProfile;
+import net.minecraft.server.command.ServerCommandSource;
+import net.minecraft.text.LiteralText;
+import net.minecraft.world.dimension.DimensionType;
+
+public class ListAllPlayerSaves {
+ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
+ LiteralArgumentBuilder<ServerCommandSource> listplayersaves = literal("listplayersaves").
+ requires(source -> source.hasPermissionLevel(4)).
+ executes((c) -> execute(c.getSource()));
+
+ dispatcher.register(listplayersaves);
+ }
+
+ private static int execute(ServerCommandSource source) {
+ String uuid_list[] = source.getMinecraftServer().getWorld(DimensionType.OVERWORLD).getSaveHandler().getSavedPlayerIds();
+
+ for (int i = 0; i < uuid_list.length; i++) {
+ GameProfile profile = source.getMinecraftServer().getUserCache().getByUuid(UUID.fromString(uuid_list[i]));
+ String name = "N.A.";
+
+ if(profile != null)
+ name = profile.getName();
+
+ source.sendFeedback(new LiteralText(name + " (" + uuid_list[i] + ")"), false);
+ }
+
+ return 1;
+ }
+
+}
diff --git a/src/main/java/re/jag/parquet/mixin/CommandManagerMixin.java b/src/main/java/re/jag/parquet/mixin/CommandManagerMixin.java
new file mode 100644
index 0000000..0c627e5
--- /dev/null
+++ b/src/main/java/re/jag/parquet/mixin/CommandManagerMixin.java
@@ -0,0 +1,26 @@
+package re.jag.parquet.mixin;
+
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import com.mojang.brigadier.CommandDispatcher;
+
+import re.jag.parquet.Parquet;
+import net.minecraft.server.command.CommandManager;
+import net.minecraft.server.command.ServerCommandSource;
+
+@Mixin(CommandManager.class)
+public class CommandManagerMixin {
+ @Shadow
+ @Final
+ private CommandDispatcher<ServerCommandSource> dispatcher;
+
+ @Inject(method = "<init>", at = @At("RETURN"))
+ private void onRegister(boolean boolean_1, CallbackInfo ci) {
+ Parquet.registerCommands(this.dispatcher);
+ }
+}
diff --git a/src/main/java/re/jag/parquet/mixin/ServerPlayerEntityMixin.java b/src/main/java/re/jag/parquet/mixin/ServerPlayerEntityMixin.java
new file mode 100644
index 0000000..259d65a
--- /dev/null
+++ b/src/main/java/re/jag/parquet/mixin/ServerPlayerEntityMixin.java
@@ -0,0 +1,89 @@
+package re.jag.parquet.mixin;
+
+import re.jag.parquet.commands.CameraModeData;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import com.mojang.authlib.GameProfile;
+
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.network.ServerPlayerEntity;
+import net.minecraft.server.world.ServerWorld;
+import net.minecraft.world.World;
+import net.minecraft.world.dimension.DimensionType;
+import net.minecraft.entity.player.PlayerEntity;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.ListTag;
+import net.minecraft.nbt.Tag;
+
+@Mixin(ServerPlayerEntity.class)
+public abstract class ServerPlayerEntityMixin extends PlayerEntity implements CameraModeData{
+
+ public ServerPlayerEntityMixin(World world, GameProfile profile) {
+ super(world, profile);
+ }
+
+ private double saved_x, saved_y, saved_z;
+ private DimensionType saved_dimension;
+ private boolean save_active = false;
+
+ @Shadow
+ public MinecraftServer server;
+
+ @Shadow
+ public void teleport(ServerWorld arg, double d, double e, double f, float g, float h) {}
+
+ @Inject(method="writeCustomDataToTag", at = @At("RETURN"))
+ private void onWriteCustomDataToTag(CompoundTag arg, CallbackInfo ci) {
+ arg.put("ParquetSavedPos", (Tag)toListTag(new double[] { saved_x, saved_y, saved_z }));
+ arg.putInt("ParquetSavedDimension", this.dimension.getRawId());
+ arg.putBoolean("ParquetSaveActive", save_active);
+ }
+
+ @Inject(method="readCustomDataFromTag", at = @At("RETURN"))
+ private void onReadCustomDataFromTag(CompoundTag arg, CallbackInfo ci) {
+ ListTag lv = arg.getList("ParquetSavedPos", 6);
+
+ int dim_raw_id = arg.getInt("ParquetSavedDimension");
+
+ this.save_active = arg.getBoolean("ParquetSaveActive");
+
+ if(lv != null) {
+ this.saved_x = lv.getDouble(0);
+ this.saved_y = lv.getDouble(1);
+ this.saved_z = lv.getDouble(2);
+ }
+
+ this.saved_dimension = DimensionType.byRawId(dim_raw_id);
+ }
+
+ public boolean saveCameraPosition() {
+ if (!this.save_active) {
+ this.saved_x = getX();
+ this.saved_y = getY();
+ this.saved_z = getZ();
+
+ this.saved_dimension = this.dimension;
+
+ this.save_active = true;
+
+ return true;
+ }
+ return false;
+ }
+
+ public boolean restoreCameraPosition() {
+ if (this.save_active) {
+ this.teleport(server.getWorld(saved_dimension), saved_x, saved_y, saved_z, 0,0);
+
+ this.save_active = false;
+
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/src/main/resources/parquet.mixins.json b/src/main/resources/parquet.mixins.json
index 940a19e..44f7df5 100644
--- a/src/main/resources/parquet.mixins.json
+++ b/src/main/resources/parquet.mixins.json
@@ -6,7 +6,11 @@
"mixins": [
],
"server": [
- "VanillaMixin"
+ "VanillaMixin",
+ "CommandManagerMixin",
+ "ServerPlayerEntityMixin"
+ ],
+ "client": [
],
"injectors": {
"defaultRequire": 1