flewkey
/
mc.2a03.party
Archived
1
0
Fork 0

Allow cross-dimension teleportation

This commit is contained in:
flewkey 2019-06-01 19:53:35 -07:00
parent 92ad68af24
commit 89f42f6d2c
Signed by: flewkey
GPG Key ID: 94F56ADFD848851E
6 changed files with 95 additions and 50 deletions

View File

@ -8,6 +8,15 @@
public abstract class MinecraftServer extends RecursiveEventLoop<TickDelayedTask> implements ISnooperInfo, ICommandSource, AutoCloseable, Runnable { public abstract class MinecraftServer extends RecursiveEventLoop<TickDelayedTask> implements ISnooperInfo, ICommandSource, AutoCloseable, Runnable {
private static final Logger field_147145_h = LogManager.getLogger(); 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 @@ @@ -810,6 +811,7 @@
} }
@ -16,17 +25,18 @@
OptionParser optionparser = new OptionParser(); OptionParser optionparser = new OptionParser();
OptionSpec<Void> optionspec = optionparser.accepts("nogui"); OptionSpec<Void> optionspec = optionparser.accepts("nogui");
OptionSpec<Void> optionspec1 = optionparser.accepts("initSettings", "Initializes 'server.properties' and 'eula.txt', then quits"); 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_213197_c(optionset.has(optionspec5));
dedicatedserver.func_213208_c(optionset.valueOf(optionspec11)); dedicatedserver.func_213208_c(optionset.valueOf(optionspec11));
boolean flag = !optionset.has(optionspec) && !optionset.valuesOf(optionspec12).contains("nogui"); boolean flag = !optionset.has(optionspec) && !optionset.valuesOf(optionspec12).contains("nogui");
- if (flag && !GraphicsEnvironment.isHeadless()) { - if (flag && !GraphicsEnvironment.isHeadless()) {
+ Config.initConfig(field_71305_c); //Patched
+ Config.loadConfig(); //Patched + Config.loadConfig(); //Patched
+ if (flag && !GraphicsEnvironment.isHeadless() && false) { //Patched + if (flag && !GraphicsEnvironment.isHeadless() && false) { //Patched
dedicatedserver.func_120011_ar(); dedicatedserver.func_120011_ar();
} }
@@ -950,7 +953,7 @@ @@ -950,7 +954,7 @@
} }
public String getServerModName() { public String getServerModName() {

View File

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

View File

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

View File

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

View File

@ -5,33 +5,30 @@ import org.json.JSONObject;
import party._2a03.server.PlayerPosition; import party._2a03.server.PlayerPosition;
public class PlayerData { public class PlayerData {
public JSONObject json; private String uuid;
private PlayerPosition home;
public PlayerData(JSONObject p_json) { public PlayerData(String p_uuid, PlayerPosition p_home) {
this.json = p_json; this.uuid = p_uuid;
this.home = p_home;
} }
public PlayerPosition getHome() { public PlayerPosition getHome() {
JSONArray data = json.getJSONArray("home"); return this.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);
} }
public String getUUID() { public String getUUID() {
return json.getString("uuid"); return this.uuid;
} }
public void setHome(PlayerPosition location) { public void setHome(PlayerPosition location) {
JSONArray locationArray = new JSONArray(); this.home = location;
locationArray.put(location.x); }
locationArray.put(location.y);
locationArray.put(location.z); public JSONObject getJSON() {
locationArray.put(location.yaw); JSONObject json = new JSONObject();
locationArray.put(location.pitch); json.put("uuid", uuid);
json.put("home", locationArray); json.put("home", home.getJSON());
return json;
} }
} }

View File

@ -1,17 +1,45 @@
package party._2a03.server; package party._2a03.server;
import org.json.JSONArray;
import net.minecraft.world.ServerWorld;
public class PlayerPosition { public class PlayerPosition {
public double x; public double x;
public double y; public double y;
public double z; public double z;
public float yaw; public float yaw;
public float pitch; public float pitch;
public ServerWorld world;
public PlayerPosition(double p_x, double p_y, double p_z, float p_yaw, float p_pitch, int world) { public PlayerPosition() {
}
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.x = p_x;
this.y = p_y; this.y = p_y;
this.z = p_z; this.z = p_z;
this.yaw = p_yaw; this.yaw = p_yaw;
this.pitch = p_pitch; 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;
} }
} }