Add block break sounds for blocks with 0 hardness, and refactor some things

The refactors in this commit go a bit beyond the scope of what the sound/effects branch was meant to accomplish, however most of these changes are necessary so chunk caching could be reintroduced for the standalone version. The chunk caching here allows for us to get the block ID before the block was broken, and in the future allow us to implement newer features. Chunk caching is optional (and disabled by default) as on non-Bukkit versions, it can eat up a lot of RAM with many players online.
This commit is contained in:
RednedEpic 2020-04-29 15:01:53 -05:00
parent efcf739973
commit 31be608038
74 changed files with 873 additions and 598 deletions

View file

@ -26,7 +26,7 @@
package org.geysermc.platform.bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.geysermc.common.IGeyserConfiguration;
import org.geysermc.connector.GeyserConfiguration;
import java.io.File;
import java.nio.file.Path;
@ -34,7 +34,7 @@ import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
public class GeyserBukkitConfiguration implements IGeyserConfiguration {
public class GeyserBukkitConfiguration implements GeyserConfiguration {
private FileConfiguration config;
private File dataFolder;
@ -111,6 +111,11 @@ public class GeyserBukkitConfiguration implements IGeyserConfiguration {
return Paths.get(dataFolder.toString(), config.getString("floodgate-key-file", "public-key.pem"));
}
@Override
public boolean isCacheChunks() {
return true; // We override this as with Bukkit, we have direct access to the server implementation
}
@Override
public IMetricsInfo getMetrics() {
return metricsInfo;

View file

@ -27,13 +27,13 @@ package org.geysermc.platform.bukkit;
import lombok.AllArgsConstructor;
import org.geysermc.common.logger.IGeyserLogger;
import org.geysermc.connector.GeyserLogger;
import java.util.logging.Level;
import java.util.logging.Logger;
@AllArgsConstructor
public class GeyserBukkitLogger implements IGeyserLogger {
public class GeyserBukkitLogger implements GeyserLogger {
private Logger logger;
private boolean debugMode;

View file

@ -27,20 +27,22 @@ package org.geysermc.platform.bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.geysermc.common.PlatformType;
import org.geysermc.common.command.ICommandManager;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.common.bootstrap.IGeyserBootstrap;
import org.geysermc.connector.bootstrap.GeyserBootstrap;
import org.geysermc.connector.command.CommandManager;
import org.geysermc.connector.network.translators.world.WorldManager;
import org.geysermc.platform.bukkit.command.GeyserBukkitCommandExecutor;
import org.geysermc.platform.bukkit.command.GeyserBukkitCommandManager;
import org.geysermc.platform.bukkit.world.GeyserBukkitWorldManager;
import java.util.UUID;
public class GeyserBukkitPlugin extends JavaPlugin implements IGeyserBootstrap {
public class GeyserBukkitPlugin extends JavaPlugin implements GeyserBootstrap {
private GeyserBukkitCommandManager geyserCommandManager;
private GeyserBukkitConfiguration geyserConfig;
private GeyserBukkitLogger geyserLogger;
private GeyserBukkitWorldManager geyserWorldManager;
private GeyserConnector connector;
@ -58,6 +60,7 @@ public class GeyserBukkitPlugin extends JavaPlugin implements IGeyserBootstrap {
this.connector = GeyserConnector.start(PlatformType.BUKKIT, this);
this.geyserCommandManager = new GeyserBukkitCommandManager(this, connector);
this.geyserWorldManager = new GeyserBukkitWorldManager();
this.getCommand("geyser").setExecutor(new GeyserBukkitCommandExecutor(connector));
}
@ -81,4 +84,9 @@ public class GeyserBukkitPlugin extends JavaPlugin implements IGeyserBootstrap {
public CommandManager getGeyserCommandManager() {
return this.geyserCommandManager;
}
@Override
public WorldManager getWorldManager() {
return this.geyserWorldManager;
}
}

View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*
*/
package org.geysermc.platform.bukkit.world;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
import org.bukkit.Bukkit;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.world.WorldManager;
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
public class GeyserBukkitWorldManager extends WorldManager {
@Override
public BlockState getBlockAt(GeyserSession session, int x, int y, int z) {
return BlockTranslator.getJavaIdBlockMap().get(Bukkit.getPlayer(session.getName()).getWorld().getBlockAt(x, y, z).getBlockData().getAsString());
}
}

View file

@ -27,7 +27,7 @@ package org.geysermc.platform.bungeecord;
import net.md_5.bungee.config.Configuration;
import org.geysermc.common.IGeyserConfiguration;
import org.geysermc.connector.GeyserConfiguration;
import java.io.File;
import java.nio.file.Path;
@ -35,7 +35,7 @@ import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
public class GeyserBungeeConfiguration implements IGeyserConfiguration {
public class GeyserBungeeConfiguration implements GeyserConfiguration {
private File dataFolder;
private Configuration config;
@ -112,6 +112,11 @@ public class GeyserBungeeConfiguration implements IGeyserConfiguration {
return Paths.get(dataFolder.toString(), config.getString("floodgate-key-file", "public-key.pem"));
}
@Override
public boolean isCacheChunks() {
return config.getBoolean("cache-chunks", false);
}
@Override
public BungeeMetricsInfo getMetrics() {
return metricsInfo;

View file

@ -25,12 +25,12 @@
package org.geysermc.platform.bungeecord;
import org.geysermc.common.logger.IGeyserLogger;
import org.geysermc.connector.GeyserLogger;
import java.util.logging.Level;
import java.util.logging.Logger;
public class GeyserBungeeLogger implements IGeyserLogger {
public class GeyserBungeeLogger implements GeyserLogger {
private Logger logger;
private boolean debugMode;

View file

@ -32,7 +32,7 @@ import net.md_5.bungee.config.YamlConfiguration;
import org.geysermc.common.PlatformType;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.common.bootstrap.IGeyserBootstrap;
import org.geysermc.connector.bootstrap.GeyserBootstrap;
import org.geysermc.connector.command.CommandManager;
import org.geysermc.platform.bungeecord.command.GeyserBungeeCommandExecutor;
import org.geysermc.platform.bungeecord.command.GeyserBungeeCommandManager;
@ -44,7 +44,7 @@ import java.nio.file.Files;
import java.util.UUID;
import java.util.logging.Level;
public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap {
public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
private GeyserBungeeCommandManager geyserCommandManager;
private GeyserBungeeConfiguration geyserConfig;

View file

@ -29,7 +29,7 @@ import lombok.AllArgsConstructor;
import ninja.leaping.configurate.ConfigurationNode;
import org.geysermc.common.IGeyserConfiguration;
import org.geysermc.connector.GeyserConfiguration;
import java.io.File;
import java.nio.file.Path;
@ -38,7 +38,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class GeyserSpongeConfiguration implements IGeyserConfiguration {
public class GeyserSpongeConfiguration implements GeyserConfiguration {
private File dataFolder;
private ConfigurationNode node;
@ -115,6 +115,11 @@ public class GeyserSpongeConfiguration implements IGeyserConfiguration {
return Paths.get(dataFolder.toString(), node.getNode("floodgate-key-file").getString("public-key.pem"));
}
@Override
public boolean isCacheChunks() {
return node.getNode("cache-chunks").getBoolean(false);
}
@Override
public SpongeMetricsInfo getMetrics() {
return metricsInfo;

View file

@ -27,11 +27,11 @@ package org.geysermc.platform.sponge;
import lombok.AllArgsConstructor;
import org.geysermc.common.logger.IGeyserLogger;
import org.geysermc.connector.GeyserLogger;
import org.slf4j.Logger;
@AllArgsConstructor
public class GeyserSpongeLogger implements IGeyserLogger {
public class GeyserSpongeLogger implements GeyserLogger {
private Logger logger;
private boolean debugMode;

View file

@ -31,8 +31,7 @@ import ninja.leaping.configurate.loader.ConfigurationLoader;
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
import org.geysermc.common.PlatformType;
import org.geysermc.common.bootstrap.IGeyserBootstrap;
import org.geysermc.common.command.ICommandManager;
import org.geysermc.connector.bootstrap.GeyserBootstrap;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandManager;
import org.geysermc.connector.utils.FileUtils;
@ -51,7 +50,7 @@ import java.io.IOException;
import java.util.UUID;
@Plugin(id = "geyser", name = GeyserConnector.NAME + "-Sponge", version = GeyserConnector.VERSION, url = "https://geysermc.org", authors = "GeyserMC")
public class GeyserSpongePlugin implements IGeyserBootstrap {
public class GeyserSpongePlugin implements GeyserBootstrap {
@Inject
private Logger logger;

View file

@ -81,7 +81,7 @@
<configuration>
<archive>
<manifestEntries>
<Main-Class>org.geysermc.platform.standalone.GeyserBootstrap</Main-Class>
<Main-Class>org.geysermc.platform.standalone.GeyserStandaloneBootstrap</Main-Class>
</manifestEntries>
</archive>
</configuration>
@ -119,7 +119,7 @@
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.geysermc.platform.standalone.GeyserBootstrap</mainClass>
<mainClass>org.geysermc.platform.standalone.GeyserStandaloneBootstrap</mainClass>
<manifestEntries>
<Multi-Release>true</Multi-Release>
</manifestEntries>

View file

@ -26,38 +26,38 @@
package org.geysermc.platform.standalone;
import org.geysermc.common.PlatformType;
import org.geysermc.common.bootstrap.IGeyserBootstrap;
import org.geysermc.connector.GeyserConfiguration;
import org.geysermc.connector.bootstrap.GeyserBootstrap;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandManager;
import org.geysermc.connector.utils.FileUtils;
import org.geysermc.platform.standalone.command.GeyserCommandManager;
import org.geysermc.platform.standalone.console.GeyserLogger;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
public class GeyserBootstrap implements IGeyserBootstrap {
public class GeyserStandaloneBootstrap implements GeyserBootstrap {
private GeyserCommandManager geyserCommandManager;
private GeyserConfiguration geyserConfig;
private GeyserLogger geyserLogger;
private GeyserStandaloneLogger geyserLogger;
private GeyserConnector connector;
public static void main(String[] args) {
new GeyserBootstrap().onEnable();
new GeyserStandaloneBootstrap().onEnable();
}
@Override
public void onEnable() {
geyserLogger = new GeyserLogger();
geyserLogger = new GeyserStandaloneLogger();
LoopbackUtil.checkLoopback(geyserLogger);
try {
File configFile = FileUtils.fileOrCopiedFromResource("config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()));
geyserConfig = FileUtils.loadConfig(configFile, GeyserConfiguration.class);
geyserConfig = FileUtils.loadConfig(configFile, GeyserStandaloneConfiguration.class);
} catch (IOException ex) {
geyserLogger.severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex);
System.exit(0);
@ -80,7 +80,7 @@ public class GeyserBootstrap implements IGeyserBootstrap {
}
@Override
public GeyserLogger getGeyserLogger() {
public GeyserStandaloneLogger getGeyserLogger() {
return geyserLogger;
}

View file

@ -29,8 +29,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import org.geysermc.common.IGeyserConfiguration;
import org.geysermc.connector.GeyserConfiguration;
import java.nio.file.Path;
import java.nio.file.Paths;
@ -38,7 +37,7 @@ import java.util.Map;
@JsonIgnoreProperties(ignoreUnknown = true)
@Getter
public class GeyserConfiguration implements IGeyserConfiguration {
public class GeyserStandaloneConfiguration implements GeyserConfiguration {
private BedrockConfiguration bedrock;
private RemoteConfiguration remote;
@ -66,6 +65,9 @@ public class GeyserConfiguration implements IGeyserConfiguration {
@JsonProperty("default-locale")
private String defaultLocale;
@JsonProperty("cache-chunks")
private boolean cacheChunks;
private MetricsInfo metrics;
@Override

View file

@ -1,29 +1,30 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.platform.standalone.console;
package org.geysermc.platform.standalone;
import lombok.extern.log4j.Log4j2;
@ -31,12 +32,11 @@ import net.minecrell.terminalconsole.SimpleTerminalConsole;
import org.apache.logging.log4j.core.config.Configurator;
import org.geysermc.common.ChatColor;
import org.geysermc.common.logger.IGeyserLogger;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandSender;
@Log4j2
public class GeyserLogger extends SimpleTerminalConsole implements IGeyserLogger, CommandSender {
public class GeyserStandaloneLogger extends SimpleTerminalConsole implements org.geysermc.connector.GeyserLogger, CommandSender {
private boolean colored = true;

View file

@ -6,14 +6,13 @@ import java.nio.file.OpenOption;
import java.nio.file.Paths;
import org.geysermc.common.ChatColor;
import org.geysermc.platform.standalone.console.GeyserLogger;
public class LoopbackUtil {
private static final String checkExemption = "powershell -Command \"CheckNetIsolation LoopbackExempt -s\""; // Java's Exec feature runs as CMD, NetIsolation is only accessible from PowerShell.
private static final String loopbackCommand = "powershell -Command \"CheckNetIsolation LoopbackExempt -a -n='Microsoft.MinecraftUWP_8wekyb3d8bbwe'\"";
private static final String startScript = "powershell -Command \"Start-Process 'cmd' -ArgumentList /c,%temp%/loopback_minecraft.bat -Verb runAs\"";
public static void checkLoopback(GeyserLogger geyserLogger) {
public static void checkLoopback(GeyserStandaloneLogger geyserLogger) {
if (System.getProperty("os.name").equalsIgnoreCase("Windows 10")) {
try {
Process process = Runtime.getRuntime().exec(checkExemption);

View file

@ -30,7 +30,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import org.geysermc.common.IGeyserConfiguration;
import org.geysermc.connector.GeyserConfiguration;
import java.nio.file.Path;
import java.nio.file.Paths;
@ -38,7 +38,7 @@ import java.util.Map;
@JsonIgnoreProperties(ignoreUnknown = true)
@Getter
public class GeyserVelocityConfiguration implements IGeyserConfiguration {
public class GeyserVelocityConfiguration implements GeyserConfiguration {
private BedrockConfiguration bedrock;
private RemoteConfiguration remote;
@ -66,6 +66,9 @@ public class GeyserVelocityConfiguration implements IGeyserConfiguration {
@JsonProperty("default-locale")
private String defaultLocale;
@JsonProperty("cache-chunks")
private boolean cacheChunks;
private MetricsInfo metrics;
@Override

View file

@ -27,11 +27,11 @@ package org.geysermc.platform.velocity;
import lombok.AllArgsConstructor;
import org.geysermc.common.logger.IGeyserLogger;
import org.geysermc.connector.GeyserLogger;
import org.slf4j.Logger;
@AllArgsConstructor
public class GeyserVelocityLogger implements IGeyserLogger {
public class GeyserVelocityLogger implements GeyserLogger {
private Logger logger;
private boolean debugMode;

View file

@ -34,8 +34,8 @@ import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
import com.velocitypowered.api.plugin.Plugin;
import org.geysermc.common.PlatformType;
import org.geysermc.common.bootstrap.IGeyserBootstrap;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.bootstrap.GeyserBootstrap;
import org.geysermc.connector.utils.FileUtils;
import org.geysermc.platform.velocity.command.GeyserVelocityCommandExecutor;
import org.geysermc.platform.velocity.command.GeyserVelocityCommandManager;
@ -46,7 +46,7 @@ import java.io.IOException;
import java.util.UUID;
@Plugin(id = "geyser", name = GeyserConnector.NAME + "-Velocity", version = GeyserConnector.VERSION, url = "https://geysermc.org", authors = "GeyserMC")
public class GeyserVelocityPlugin implements IGeyserBootstrap {
public class GeyserVelocityPlugin implements GeyserBootstrap {
@Inject
private Logger logger;