forked from Upstream/mmocore
.
This commit is contained in:
parent
3786ca1c15
commit
bd293f76b6
@ -0,0 +1,58 @@
|
|||||||
|
package net.Indyuce.mmocore.manager;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PluginMessageManager implements MMOCoreManager, PluginMessageListener {
|
||||||
|
private String serverName;
|
||||||
|
private List<String> allServerNames;
|
||||||
|
public final String BUNGEECORD_CHANNEL = "BungeeCord";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(boolean clearBefore) {
|
||||||
|
if (!clearBefore) {
|
||||||
|
//Setup the channels.
|
||||||
|
MMOCore.plugin.getServer().getMessenger().registerOutgoingPluginChannel(MMOCore.plugin, BUNGEECORD_CHANNEL);
|
||||||
|
MMOCore.plugin.getServer().getMessenger().registerIncomingPluginChannel(MMOCore.plugin, BUNGEECORD_CHANNEL, this);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void teleportToOtherServer(PlayerData playerData, String server) {
|
||||||
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
out.writeUTF("Connect");
|
||||||
|
out.writeUTF(server);
|
||||||
|
playerData.getPlayer().sendPluginMessage(MMOCore.plugin, BUNGEECORD_CHANNEL, out.toByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] bytes) {
|
||||||
|
if (!channel.equals(BUNGEECORD_CHANNEL)) return;
|
||||||
|
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
|
||||||
|
String subchannel = in.readUTF();
|
||||||
|
if (subchannel.equals("GetServer")) {
|
||||||
|
serverName = in.readUTF();
|
||||||
|
} else if (subchannel.equals("GetServers")) {
|
||||||
|
allServerNames = Arrays.asList(in.readUTF().split(", "));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServerName() {
|
||||||
|
return serverName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getAllServerNames() {
|
||||||
|
return new ArrayList(allServerNames);
|
||||||
|
}
|
||||||
|
}
|
@ -40,7 +40,6 @@ public class YAMLPlayerDataHandler extends YAMLSynchronizedDataHandler<PlayerDat
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadFromSection(PlayerData data, ConfigurationSection config) {
|
public void loadFromSection(PlayerData data, ConfigurationSection config) {
|
||||||
MMOCore.log("LOAD");
|
|
||||||
|
|
||||||
// Reset stats linked to triggers.
|
// Reset stats linked to triggers.
|
||||||
data.resetTriggerStats();
|
data.resetTriggerStats();
|
||||||
@ -136,8 +135,10 @@ public class YAMLPlayerDataHandler extends YAMLSynchronizedDataHandler<PlayerDat
|
|||||||
data.setMana(config.contains("mana") ? config.getDouble("mana") : data.getStats().getStat("MAX_MANA"));
|
data.setMana(config.contains("mana") ? config.getDouble("mana") : data.getStats().getStat("MAX_MANA"));
|
||||||
data.setStamina(config.contains("stamina") ? config.getDouble("stamina") : data.getStats().getStat("MAX_STAMINA"));
|
data.setStamina(config.contains("stamina") ? config.getDouble("stamina") : data.getStats().getStat("MAX_STAMINA"));
|
||||||
data.setStellium(config.contains("stellium") ? config.getDouble("stellium") : data.getStats().getStat("MAX_STELLIUM"));
|
data.setStellium(config.contains("stellium") ? config.getDouble("stellium") : data.getStats().getStat("MAX_STELLIUM"));
|
||||||
data.setLastSpawnPointContext(new SpawnPointContext(config.getString("last-spawn-point.id"),
|
if (config.contains("last-spawn-point")) {
|
||||||
Optional.ofNullable(config.getString("last-spawn-point.server"))));
|
data.setLastSpawnPointContext(new SpawnPointContext(config.getString("last-spawn-point.id"),
|
||||||
|
Optional.ofNullable(config.getString("last-spawn-point.server"))));
|
||||||
|
}
|
||||||
data.setShouldTeleportWhenJoin(config.getBoolean("should-teleport-when-join", false));
|
data.setShouldTeleportWhenJoin(config.getBoolean("should-teleport-when-join", false));
|
||||||
data.setupSpawnPoint();
|
data.setupSpawnPoint();
|
||||||
if (data.isOnline() && !data.getPlayer().isDead())
|
if (data.isOnline() && !data.getPlayer().isDead())
|
||||||
@ -146,7 +147,6 @@ public class YAMLPlayerDataHandler extends YAMLSynchronizedDataHandler<PlayerDat
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveInSection(PlayerData data, ConfigurationSection config) {
|
public void saveInSection(PlayerData data, ConfigurationSection config) {
|
||||||
MMOCore.log("SAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVE");
|
|
||||||
config.set("class-points", data.getClassPoints());
|
config.set("class-points", data.getClassPoints());
|
||||||
config.set("skill-points", data.getSkillPoints());
|
config.set("skill-points", data.getSkillPoints());
|
||||||
config.set("skill-reallocation-points", data.getSkillReallocationPoints());
|
config.set("skill-reallocation-points", data.getSkillReallocationPoints());
|
||||||
@ -174,7 +174,6 @@ public class YAMLPlayerDataHandler extends YAMLSynchronizedDataHandler<PlayerDat
|
|||||||
|
|
||||||
config.set("bound-skills", null);
|
config.set("bound-skills", null);
|
||||||
data.mapBoundSkills().forEach((slot, skill) -> config.set("bound-skills." + slot, skill));
|
data.mapBoundSkills().forEach((slot, skill) -> config.set("bound-skills." + slot, skill));
|
||||||
MMOCore.log(data.getUnlockedItems().size()+" unlocked.");
|
|
||||||
config.set("unlocked-items", data.getUnlockedItems().stream().collect(Collectors.toList()));
|
config.set("unlocked-items", data.getUnlockedItems().stream().collect(Collectors.toList()));
|
||||||
config.set("attribute", null);
|
config.set("attribute", null);
|
||||||
config.createSection("attribute");
|
config.createSection("attribute");
|
||||||
@ -209,6 +208,7 @@ public class YAMLPlayerDataHandler extends YAMLSynchronizedDataHandler<PlayerDat
|
|||||||
info.mapBoundSkills().forEach((slot, skill) -> config.set("class-info." + key + ".bound-skills." + slot, skill));
|
info.mapBoundSkills().forEach((slot, skill) -> config.set("class-info." + key + ".bound-skills." + slot, skill));
|
||||||
config.set("class-info." + key + ".unlocked-items", new ArrayList<>(info.getUnlockedItems()));
|
config.set("class-info." + key + ".unlocked-items", new ArrayList<>(info.getUnlockedItems()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
package net.Indyuce.mmocore.spawnpoint;
|
||||||
|
|
||||||
|
import io.lumine.mythic.lib.gson.JsonObject;
|
||||||
|
import io.lumine.mythic.lib.util.Jsonable;
|
||||||
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class SpawnPointContext implements Jsonable {
|
||||||
|
private final String id;
|
||||||
|
|
||||||
|
private final Optional<String> server;
|
||||||
|
|
||||||
|
public SpawnPointContext(String id) {
|
||||||
|
this.id = id;
|
||||||
|
this.server = Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SpawnPointContext(String id, Optional<String> server) {
|
||||||
|
this.id = id;
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SpawnPointContext(JsonObject jsonObject) {
|
||||||
|
this.id = jsonObject.get("id").getAsString();
|
||||||
|
this.server = Optional.ofNullable(jsonObject.get("server")).map((jsonElement) -> jsonElement.getAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<String> getServer() {
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return MMOCore.plugin.spawnPointManager.getSpawnPoint(id).getLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOtherServer() {
|
||||||
|
return !server.isEmpty() && server.get() != MMOCore.plugin.pluginMessageManager.getServerName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void whenRespawn(PlayerData playerData) {
|
||||||
|
if (isOtherServer()) {
|
||||||
|
MMOCore.plugin.pluginMessageManager.teleportToOtherServer(playerData, server.get());
|
||||||
|
} else {
|
||||||
|
MMOCore.plugin.spawnPointManager.getSpawnPoint(id).whenRespawn(playerData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull JsonObject toJson() {
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
jsonObject.addProperty("id", id);
|
||||||
|
server.ifPresent((server) -> jsonObject.addProperty("server", server));
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package net.Indyuce.mmocore.spawnpoint.def;
|
||||||
|
|
||||||
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
|
import net.Indyuce.mmocore.spawnpoint.SpawnPointContext;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class SpawnPointOption extends DefaultSpawnOption {
|
||||||
|
private final SpawnPointContext spawnPointContext;
|
||||||
|
|
||||||
|
public SpawnPointOption(MMOLineConfig config) {
|
||||||
|
super(config);
|
||||||
|
spawnPointContext = new SpawnPointContext(config.getString("id"), config.contains("server") ?
|
||||||
|
Optional.of(config.getString("server")) : Optional.empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SpawnPointContext getSpawnPointContext(PlayerData playerData) {
|
||||||
|
return spawnPointContext;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user