Skip to content

Commit

Permalink
Merge master into Spigot rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Jun 21, 2020
2 parents cc3b4c3 + d0c95d3 commit 427f4ef
Show file tree
Hide file tree
Showing 40 changed files with 525 additions and 114 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img src="https://geysermc.org/img/geyserlogo.png" alt="Geyser" width="600"/>
<img src="https://geysermc.org/img/geyser-1760-860.png" alt="Geyser" width="600"/>

[![forthebadge made-with-java](http://ForTheBadge.com/images/badges/made-with-java.svg)](https://java.com/)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.file.Path;
import java.util.UUID;
import java.util.logging.Level;

Expand Down Expand Up @@ -134,4 +135,9 @@ public CommandManager getGeyserCommandManager() {
public IGeyserPingPassthrough getGeyserPingPassthrough() {
return geyserBungeePingPassthrough;
}

@Override
public Path getConfigFolder() {
return getDataFolder().toPath();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.UUID;
import java.util.logging.Level;

Expand Down Expand Up @@ -162,6 +163,11 @@ public WorldManager getWorldManager() {
return this.geyserWorldManager;
}

@Override
public Path getConfigFolder() {
return getDataFolder().toPath();
}

public boolean isCompatible(String version, String whichVersion) {
int[] currentVersion = parseVersion(version);
int[] otherVersion = parseVersion(whichVersion);
Expand Down Expand Up @@ -195,4 +201,5 @@ private int[] parseVersion(String versionParam) {
}
return temp;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ public boolean isAllowThirdPartyEars() {
return node.getNode("allow-third-party-ears").getBoolean(false);
}

@Override
public boolean isShowCooldown() {
return node.getNode("show-cooldown").getBoolean(true);
}

@Override
public String getDefaultLocale() {
return node.getNode("default-locale").getString("en_us");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.file.Path;
import java.util.UUID;

@Plugin(id = "geyser", name = GeyserConnector.NAME + "-Sponge", version = GeyserConnector.VERSION, url = "https://geysermc.org", authors = "GeyserMC")
Expand Down Expand Up @@ -147,6 +148,11 @@ public IGeyserPingPassthrough getGeyserPingPassthrough() {
return geyserSpongePingPassthrough;
}

@Override
public Path getConfigFolder() {
return configDir.toPath();
}

@Listener
public void onServerStart(GameStartedServerEvent event) {
onEnable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.UUID;

public class GeyserStandaloneBootstrap implements GeyserBootstrap {
Expand Down Expand Up @@ -100,4 +102,10 @@ public CommandManager getGeyserCommandManager() {
public IGeyserPingPassthrough getGeyserPingPassthrough() {
return geyserPingPassthrough;
}

@Override
public Path getConfigFolder() {
// Return the current working directory
return Paths.get(System.getProperty("user.dir"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void warning(String message) {

@Override
public void info(String message) {
log.info(printConsole(ChatColor.WHITE + message, colored));
log.info(printConsole(ChatColor.RESET + ChatColor.BOLD + message, colored));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.velocitypowered.api.plugin.Plugin;

import com.velocitypowered.api.proxy.ProxyServer;
import lombok.Getter;
import org.geysermc.common.PlatformType;
import org.geysermc.connector.configuration.GeyserConfiguration;
import org.geysermc.connector.GeyserConnector;
Expand All @@ -48,6 +49,8 @@
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.UUID;

@Plugin(id = "geyser", name = GeyserConnector.NAME + "-Velocity", version = GeyserConnector.VERSION, url = "https://geysermc.org", authors = "GeyserMC")
Expand All @@ -69,14 +72,16 @@ public class GeyserVelocityPlugin implements GeyserBootstrap {

private GeyserConnector connector;

@Getter
private final Path configFolder = Paths.get("plugins/" + GeyserConnector.NAME + "-Velocity/");

@Override
public void onEnable() {
File configDir = new File("plugins/" + GeyserConnector.NAME + "-Velocity/");

try {
if (!configDir.exists())
configDir.mkdir();
File configFile = FileUtils.fileOrCopiedFromResource(new File(configDir, "config.yml"), "config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()));
if (!configFolder.toFile().exists())
//noinspection ResultOfMethodCallIgnored
configFolder.toFile().mkdirs();
File configFile = FileUtils.fileOrCopiedFromResource(configFolder.resolve("config.yml").toFile(), "config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()));
this.geyserConfig = FileUtils.loadConfig(configFile, GeyserVelocityConfiguration.class);
} catch (IOException ex) {
logger.warn("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex);
Expand All @@ -101,7 +106,7 @@ public void onEnable() {
return;
}

geyserConfig.loadFloodgate(this, proxyServer, configDir);
geyserConfig.loadFloodgate(this, proxyServer, configFolder.toFile());

this.connector = GeyserConnector.start(PlatformType.VELOCITY, this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public class FormImage {

@Getter
@Setter
private FormImageType type;
private String type;

@Getter
@Setter
private String data;

public FormImage(FormImageType type, String data) {
this.type = type;
this.type = type.getName();
this.data = data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@

package org.geysermc.common.window.component;

import lombok.Getter;
import lombok.Setter;

public class ToggleComponent extends FormComponent {

@Getter
@Setter
private String text;

@Getter
@Setter
private boolean defaultValue;

public ToggleComponent(String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.nukkitx.protocol.bedrock.BedrockServer;
import com.nukkitx.protocol.bedrock.v390.Bedrock_v390;
import lombok.Getter;
import lombok.Setter;
import org.geysermc.common.AuthType;
import org.geysermc.common.PlatformType;
import org.geysermc.connector.bootstrap.GeyserBootstrap;
Expand Down Expand Up @@ -79,6 +80,7 @@ public class GeyserConnector {
private static GeyserConnector instance;

private RemoteServer remoteServer;
@Setter
private AuthType authType;

private boolean shuttingDown = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.geysermc.connector.network.translators.world.CachedChunkManager;
import org.geysermc.connector.network.translators.world.WorldManager;

import java.nio.file.Path;

public interface GeyserBootstrap {

CachedChunkManager DEFAULT_CHUNK_MANAGER = new CachedChunkManager();
Expand Down Expand Up @@ -83,4 +85,11 @@ public interface GeyserBootstrap {
default WorldManager getWorldManager() {
return DEFAULT_CHUNK_MANAGER;
}

/**
* Return the data folder where files get stored
*
* @return Path location of data folder
*/
Path getConfigFolder();
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void runCommand(CommandSender sender, String command) {
args = new String[0];
} else {
label = command.substring(0, command.indexOf(" ")).toLowerCase();
String argLine = command.substring(command.indexOf(" " + 1));
String argLine = command.substring(command.indexOf(" ") + 1);
args = argLine.contains(" ") ? argLine.split(" ") : new String[] { argLine };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public interface GeyserConfiguration {

boolean isAllowThirdPartyEars();

boolean isShowCooldown();

String getDefaultLocale();

Path getFloodgateKeyFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration
@JsonProperty("allow-third-party-capes")
private boolean allowThirdPartyCapes;

@JsonProperty("show-cooldown")
private boolean showCooldown = true;

@JsonProperty("allow-third-party-ears")
private boolean allowThirdPartyEars;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,28 @@ public class BoatEntity extends Entity {
private final float ROWING_SPEED = 0.05f;

public BoatEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
super(entityId, geyserId, entityType, position.add(0d, entityType.getOffset(), 0d), motion, rotation.add(0, 0, 90));
super(entityId, geyserId, entityType, position.add(0d, entityType.getOffset(), 0d), motion, rotation.add(90, 0, 90));
}

@Override
public void moveAbsolute(GeyserSession session, Vector3f position, Vector3f rotation, boolean isOnGround, boolean teleported) {
// Rotation is basically only called when entering/exiting a boat.
// We don't include the rotation (y) as it causes the boat to appear sideways
super.moveAbsolute(session, position.add(0d, this.entityType.getOffset(), 0d), Vector3f.from(0, 0, rotation.getZ() + 90), isOnGround, teleported);
super.moveAbsolute(session, position.add(0d, this.entityType.getOffset(), 0d), Vector3f.from(rotation.getX() + 90, 0, rotation.getX() + 90), isOnGround, teleported);
}

@Override
public void moveRelative(GeyserSession session, double relX, double relY, double relZ, Vector3f rotation, boolean isOnGround) {
super.moveRelative(session, relX, relY, relZ, Vector3f.from(0, 0, rotation.getZ()), isOnGround);
super.moveRelative(session, relX, relY, relZ, Vector3f.from(rotation.getX(), 0, rotation.getX()), isOnGround);
}

@Override
public void updatePositionAndRotation(GeyserSession session, double moveX, double moveY, double moveZ, float yaw, float pitch, boolean isOnGround) {
moveRelative(session, moveX, moveY, moveZ, yaw + 90, pitch, isOnGround);
}

@Override
public void updateRotation(GeyserSession session, float yaw, float pitch, boolean isOnGround) {
moveRelative(session, 0, 0, 0, Vector3f.from(yaw + 90, 0, 0), isOnGround);
}

@Override
Expand Down
57 changes: 55 additions & 2 deletions connector/src/main/java/org/geysermc/connector/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public class Entity {
*/
protected Vector3f rotation;

/**
* Saves if the entity should be on the ground. Otherwise entities like parrots are flapping when rotating
*/
protected boolean onGround;

protected float scale = 1;

protected EntityType entityType;
Expand Down Expand Up @@ -150,11 +155,12 @@ public boolean despawnEntity(GeyserSession session) {
}

public void moveRelative(GeyserSession session, double relX, double relY, double relZ, float yaw, float pitch, boolean isOnGround) {
moveRelative(session, relX, relY, relZ, Vector3f.from(yaw, pitch, yaw), isOnGround);
moveRelative(session, relX, relY, relZ, Vector3f.from(yaw, pitch, this.rotation.getZ()), isOnGround);
}

public void moveRelative(GeyserSession session, double relX, double relY, double relZ, Vector3f rotation, boolean isOnGround) {
setRotation(rotation);
setOnGround(isOnGround);
this.position = Vector3f.from(position.getX() + relX, position.getY() + relY, position.getZ() + relZ);

MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket();
Expand All @@ -168,12 +174,13 @@ public void moveRelative(GeyserSession session, double relX, double relY, double
}

public void moveAbsolute(GeyserSession session, Vector3f position, float yaw, float pitch, boolean isOnGround, boolean teleported) {
moveAbsolute(session, position, Vector3f.from(yaw, pitch, yaw), isOnGround, teleported);
moveAbsolute(session, position, Vector3f.from(yaw, pitch, this.rotation.getZ()), isOnGround, teleported);
}

public void moveAbsolute(GeyserSession session, Vector3f position, Vector3f rotation, boolean isOnGround, boolean teleported) {
setPosition(position);
setRotation(rotation);
setOnGround(isOnGround);

MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket();
moveEntityPacket.setRuntimeEntityId(geyserId);
Expand All @@ -185,6 +192,52 @@ public void moveAbsolute(GeyserSession session, Vector3f position, Vector3f rota
session.sendUpstreamPacket(moveEntityPacket);
}

/**
* Teleports an entity to a new location. Used in JavaEntityTeleportTranslator.
* @param session GeyserSession.
* @param position The new position of the entity.
* @param yaw The new yaw of the entity.
* @param pitch The new pitch of the entity.
* @param isOnGround Whether the entity is currently on the ground.
*/
public void teleport(GeyserSession session, Vector3f position, float yaw, float pitch, boolean isOnGround) {
moveAbsolute(session, position, yaw, pitch, isOnGround, false);
}

/**
* Updates an entity's head position. Used in JavaEntityHeadLookTranslator.
* @param session GeyserSession.
* @param headYaw The new head rotation of the entity.
*/
public void updateHeadLookRotation(GeyserSession session, float headYaw) {
moveRelative(session, 0, 0, 0, Vector3f.from(headYaw, rotation.getY(), rotation.getZ()), onGround);
}

/**
* Updates an entity's position and rotation. Used in JavaEntityPositionRotationTranslator.
* @param session GeyserSession
* @param moveX The new X offset of the current position.
* @param moveY The new Y offset of the current position.
* @param moveZ The new Z offset of the current position.
* @param yaw The new yaw of the entity.
* @param pitch The new pitch of the entity.
* @param isOnGround Whether the entity is currently on the ground.
*/
public void updatePositionAndRotation(GeyserSession session, double moveX, double moveY, double moveZ, float yaw, float pitch, boolean isOnGround) {
moveRelative(session, moveX, moveY, moveZ, Vector3f.from(rotation.getX(), pitch, yaw), isOnGround);
}

/**
* Updates an entity's rotation. Used in JavaEntityRotationTranslator.
* @param session GeyserSession.
* @param yaw The new yaw of the entity.
* @param pitch The new pitch of the entity.
* @param isOnGround Whether the entity is currently on the ground.
*/
public void updateRotation(GeyserSession session, float yaw, float pitch, boolean isOnGround) {
updatePositionAndRotation(session, 0, 0, 0, yaw, pitch, isOnGround);
}

public void updateBedrockAttributes(GeyserSession session) {
if (!valid) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public void spawnEntity(GeyserSession session) {
session.getConnector().getLogger().debug("Spawned painting on " + position);
}

@Override
public void updateHeadLookRotation(GeyserSession session, float headYaw) {
// Do nothing, as head look messes up paintings
}

public Vector3f fixOffset(boolean toBedrock) {
if (toBedrock) {
Vector3f position = super.position;
Expand Down
Loading

0 comments on commit 427f4ef

Please sign in to comment.