Browse Source

Allow cross-dimension teleportation

master
flewkey 3 years ago
parent
commit
89f42f6d2c
Signed by: flewkey GPG Key ID: 94F56ADFD848851E
  1. 14
      patches/net/minecraft/server/MinecraftServer.patch
  2. 18
      src/party/_2a03/command/HomeCommand.java
  3. 12
      src/party/_2a03/command/SpawnCommand.java
  4. 38
      src/party/_2a03/server/Config.java
  5. 33
      src/party/_2a03/server/PlayerData.java
  6. 30
      src/party/_2a03/server/PlayerPosition.java

14
patches/net/minecraft/server/MinecraftServer.patch

@ -8,6 +8,15 @@
public abstract class MinecraftServer extends RecursiveEventLoop<TickDelayedTask> implements ISnooperInfo, ICommandSource, AutoCloseable, Runnable {
private static final Logger field_147145_h = LogManager.getLogger();
@@ -138,7 +139,7 @@
private final DataFixer field_184112_s;
private String field_71320_r;
private int field_71319_s = -1;
- private final Map<DimensionType, ServerWorld> field_71305_c = Maps.newIdentityHashMap();
+ private static final Map<DimensionType, ServerWorld> field_71305_c = Maps.newIdentityHashMap(); //Patched
private PlayerList field_71318_t;
private volatile boolean field_71317_u = true;
private boolean field_71316_v;
@@ -810,6 +811,7 @@
}
@ -16,17 +25,18 @@
OptionParser optionparser = new OptionParser();
OptionSpec<Void> optionspec = optionparser.accepts("nogui");
OptionSpec<Void> optionspec1 = optionparser.accepts("initSettings", "Initializes 'server.properties' and 'eula.txt', then quits");
@@ -864,7 +866,8 @@
@@ -864,7 +866,9 @@
dedicatedserver.func_213197_c(optionset.has(optionspec5));
dedicatedserver.func_213208_c(optionset.valueOf(optionspec11));
boolean flag = !optionset.has(optionspec) && !optionset.valuesOf(optionspec12).contains("nogui");
- if (flag && !GraphicsEnvironment.isHeadless()) {
+ Config.initConfig(field_71305_c); //Patched
+ Config.loadConfig(); //Patched
+ if (flag && !GraphicsEnvironment.isHeadless() && false) { //Patched
dedicatedserver.func_120011_ar();
}
@@ -950,7 +953,7 @@
@@ -950,7 +954,7 @@
}
public String getServerModName() {

18
src/party/_2a03/command/HomeCommand.java

@ -7,9 +7,7 @@ import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.network.play.server.SPlayerPositionLookPacket;
import java.util.Set;
import java.util.EnumSet;
import net.minecraft.world.ServerWorld;
import party._2a03.server.Config;
import party._2a03.server.PlayerData;
import party._2a03.server.PlayerPosition;
@ -19,15 +17,11 @@ public class HomeCommand {
LiteralArgumentBuilder<CommandSource> literalargumentbuilder = Commands.func_197057_a("home").executes((source) -> {
PlayerData player = Config.getPlayer(source.getSource().func_197035_h().func_110124_au().toString());
PlayerPosition position = player.getHome();
if (position.y == -1) {
if (position.world == null) {
source.getSource().func_197030_a(new TranslationTextComponent("Home not found, do /home set"), false);
return 1;
}
Set<SPlayerPositionLookPacket.Flags> set = EnumSet.noneOf(SPlayerPositionLookPacket.Flags.class);
set.add(SPlayerPositionLookPacket.Flags.X);
set.add(SPlayerPositionLookPacket.Flags.Y);
set.add(SPlayerPositionLookPacket.Flags.Z);
((ServerPlayerEntity)source.getSource().func_197035_h()).field_71135_a.func_175089_a((double)position.x, (double)position.y, (double)position.z, (float)position.yaw, (float)position.pitch, set);
((ServerPlayerEntity)source.getSource().func_197035_h()).func_200619_a(position.world, position.x, position.y, position.z, position.yaw, position.pitch);
source.getSource().func_197030_a(new TranslationTextComponent("Teleported to home"), true);
return 1;
});
@ -39,7 +33,8 @@ public class HomeCommand {
double z = playerEntity.field_70161_v;
float yaw = playerEntity.field_70177_z;
float pitch = playerEntity.field_70125_A;
PlayerPosition location = new PlayerPosition(x, y, z, yaw, pitch);
ServerWorld world = (ServerWorld)playerEntity.field_70170_p;
PlayerPosition location = new PlayerPosition(x, y, z, yaw, pitch, world);
player.setHome(location);
Config.setPlayer(player);
source.getSource().func_197030_a(new TranslationTextComponent("Your home has been updated"), true);
@ -55,7 +50,8 @@ public class HomeCommand {
double z = playerEntity.field_70161_v;
float yaw = playerEntity.field_70177_z;
float pitch = playerEntity.field_70125_A;
PlayerPosition location = new PlayerPosition(x, y, z, yaw, pitch);
ServerWorld world = (ServerWorld)playerEntity.field_70170_p;
PlayerPosition location = new PlayerPosition(x, y, z, yaw, pitch, world);
player.setHome(location);
Config.setPlayer(player);
source.getSource().func_197030_a(new TranslationTextComponent("User's home has been updated ("+player.getUUID()+")"), true);

12
src/party/_2a03/command/SpawnCommand.java

@ -5,21 +5,15 @@ import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.network.play.server.SPlayerPositionLookPacket;
import java.util.Set;
import java.util.EnumSet;
import net.minecraft.world.ServerWorld;
import party._2a03.server.Config;
import party._2a03.server.PlayerPosition;
public class SpawnCommand {
public static void register(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(Commands.func_197057_a("spawn").executes((source) -> {
Set<SPlayerPositionLookPacket.Flags> set = EnumSet.noneOf(SPlayerPositionLookPacket.Flags.class);
set.add(SPlayerPositionLookPacket.Flags.X);
set.add(SPlayerPositionLookPacket.Flags.Y);
set.add(SPlayerPositionLookPacket.Flags.Z);
PlayerPosition position = Config.getPosition("spawn");
((ServerPlayerEntity)source.getSource().func_197035_h()).field_71135_a.func_175089_a((double)position.x, (double)position.y, (double)position.z, (float)position.yaw, (float)position.pitch, set);
PlayerPosition position = Config.parsePosition(Config.getData("spawn"));
((ServerPlayerEntity)source.getSource().func_197035_h()).func_200619_a(position.world, position.x, position.y, position.z, position.yaw, position.pitch);
source.getSource().func_197030_a(new TranslationTextComponent("Teleported to the spawn point"), true);
return 1;
}));

38
src/party/_2a03/server/Config.java

@ -1,9 +1,14 @@
package party._2a03.server;
import com.google.common.collect.Maps;
import java.io.File;
import java.io.FileWriter;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Map;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.ServerWorld;
import org.json.JSONObject;
import org.json.JSONArray;
import org.apache.commons.io.IOUtils;
@ -15,6 +20,12 @@ import party._2a03.server.PlayerPosition;
public class Config {
private static JSONObject json;
private static final Logger logger = LogManager.getLogger();
private static Map<DimensionType, ServerWorld> worlds = Maps.newIdentityHashMap();
public static MinecraftServer server;
public static void initConfig(Map<DimensionType, ServerWorld> p_worlds) {
worlds = p_worlds;
}
public static void loadConfig() throws Exception {
logger.info("Loading 2a03.party configuration");
@ -31,18 +42,18 @@ public class Config {
public static PlayerData getPlayer(String uuid) {
JSONArray members = json.getJSONArray("members");
JSONObject data = null;
PlayerPosition home = null;
for (int i = 0; i < members.length(); ++i) {
JSONObject item = members.getJSONObject(i);
String item_uuid = item.getString("uuid");
if (item_uuid.equals(uuid)) {
data = item;
home = parsePosition(item.getJSONArray("home"));
}
}
if (data == null) {
data = new JSONObject("{\"uuid\":\""+uuid+"\",\"home\":[-1,-1,-1,-1,-1]}");
if (home == null) {
home = new PlayerPosition();
}
return new PlayerData(data);
return new PlayerData(uuid, home);
}
public static void setPlayer(PlayerData player) {
@ -58,19 +69,28 @@ public class Config {
if (playerIndex >= 0) {
members.remove(playerIndex);
}
members.put(player.json);
members.put(player.getJSON());
json.put("members", members);
saveConfig();
}
public static PlayerPosition getPosition(String key) {
JSONArray data = json.getJSONArray(key);
public static JSONArray getData(String key) {
return json.getJSONArray(key);
}
public static PlayerPosition parsePosition(JSONArray data) {
double x = data.getDouble(0);
double y = data.getDouble(1);
double z = data.getDouble(2);
float yaw = data.getFloat(3);
float pitch = data.getFloat(4);
return new PlayerPosition((double)x, (double)y, (double)z, (float)yaw, (float)pitch);
int dimension_id = data.getInt(5);
if (dimension_id != -2) {
ServerWorld world = worlds.get(DimensionType.func_186069_a(dimension_id));
return new PlayerPosition(x, y, z, yaw, pitch, world);
} else {
return new PlayerPosition();
}
}
private static void saveConfig() {

33
src/party/_2a03/server/PlayerData.java

@ -5,33 +5,30 @@ import org.json.JSONObject;
import party._2a03.server.PlayerPosition;
public class PlayerData {
public JSONObject json;
private String uuid;
private PlayerPosition home;
public PlayerData(JSONObject p_json) {
this.json = p_json;
public PlayerData(String p_uuid, PlayerPosition p_home) {
this.uuid = p_uuid;
this.home = p_home;
}
public PlayerPosition getHome() {
JSONArray data = json.getJSONArray("home");
double x = data.getDouble(0);
double y = data.getDouble(1);
double z = data.getDouble(2);
float yaw = data.getFloat(3);
float pitch = data.getFloat(4);
return new PlayerPosition(x, y, z, yaw, pitch);
return this.home;
}
public String getUUID() {
return json.getString("uuid");
return this.uuid;
}
public void setHome(PlayerPosition location) {
JSONArray locationArray = new JSONArray();
locationArray.put(location.x);
locationArray.put(location.y);
locationArray.put(location.z);
locationArray.put(location.yaw);
locationArray.put(location.pitch);
json.put("home", locationArray);
this.home = location;
}
public JSONObject getJSON() {
JSONObject json = new JSONObject();
json.put("uuid", uuid);
json.put("home", home.getJSON());
return json;
}
}

30
src/party/_2a03/server/PlayerPosition.java

@ -1,17 +1,45 @@
package party._2a03.server;
import org.json.JSONArray;
import net.minecraft.world.ServerWorld;
public class PlayerPosition {
public double x;
public double y;
public double z;
public float yaw;
public float pitch;
public ServerWorld world;
public PlayerPosition() {
}
public PlayerPosition(double p_x, double p_y, double p_z, float p_yaw, float p_pitch, int world) {
public PlayerPosition(double p_x, double p_y, double p_z, float p_yaw, float p_pitch, ServerWorld p_world) {
this.x = p_x;
this.y = p_y;
this.z = p_z;
this.yaw = p_yaw;
this.pitch = p_pitch;
this.world = p_world;
}
public JSONArray getJSON() {
JSONArray json = new JSONArray();
if (this.world != null) {
json.put(this.x);
json.put(this.y);
json.put(this.z);
json.put(this.yaw);
json.put(this.pitch);
json.put(this.world.field_73011_w.func_186058_p().func_186068_a());
} else {
json.put(-2);
json.put(-2);
json.put(-2);
json.put(-2);
json.put(-2);
json.put(-2);
}
return json;
}
}