mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-12-28 11:59:21 +01:00
Update Sponge8 implementation with some small improvements
This commit is contained in:
parent
34d1144717
commit
445b18cd65
@ -24,21 +24,16 @@
|
||||
*/
|
||||
package de.bluecolored.bluemap.sponge;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.ServerEventListener;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.ServerInterface;
|
||||
import de.bluecolored.bluemap.core.MinecraftVersion;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
import de.bluecolored.bluemap.core.resourcepack.ParseResourceException;
|
||||
import de.bluecolored.bluemap.sponge.SpongeCommands.SpongeCommandProxy;
|
||||
import net.querz.nbt.CompoundTag;
|
||||
import net.querz.nbt.NBTUtil;
|
||||
import org.bstats.sponge.MetricsLite2;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.config.ConfigDir;
|
||||
@ -54,16 +49,13 @@
|
||||
import org.spongepowered.api.world.World;
|
||||
import org.spongepowered.api.world.storage.WorldProperties;
|
||||
|
||||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.ServerEventListener;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.ServerInterface;
|
||||
import de.bluecolored.bluemap.core.MinecraftVersion;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
import de.bluecolored.bluemap.core.resourcepack.ParseResourceException;
|
||||
import de.bluecolored.bluemap.sponge.SpongeCommands.SpongeCommandProxy;
|
||||
import net.querz.nbt.CompoundTag;
|
||||
import net.querz.nbt.NBTUtil;
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@org.spongepowered.api.plugin.Plugin (
|
||||
id = Plugin.PLUGIN_ID,
|
||||
@ -81,15 +73,15 @@ public class SpongePlugin implements ServerInterface {
|
||||
@SuppressWarnings("unused")
|
||||
private MetricsLite2 metrics;
|
||||
|
||||
private Plugin pluginInstance;
|
||||
private SpongeCommands commands;
|
||||
private final Plugin pluginInstance;
|
||||
private final SpongeCommands commands;
|
||||
|
||||
private SpongeExecutorService asyncExecutor;
|
||||
private SpongeExecutorService syncExecutor;
|
||||
|
||||
private int playerUpdateIndex = 0;
|
||||
private Map<UUID, Player> onlinePlayerMap;
|
||||
private List<SpongePlayer> onlinePlayerList;
|
||||
private final Map<UUID, Player> onlinePlayerMap;
|
||||
private final List<SpongePlayer> onlinePlayerList;
|
||||
|
||||
@Inject
|
||||
public SpongePlugin(org.slf4j.Logger logger) {
|
||||
@ -145,7 +137,7 @@ public void onServerStart(GameStartingServerEvent evt) {
|
||||
@Listener
|
||||
public void onServerStop(GameStoppingEvent evt) {
|
||||
Logger.global.logInfo("Stopping...");
|
||||
Sponge.getScheduler().getScheduledTasks(this).forEach(t -> t.cancel());
|
||||
Sponge.getScheduler().getScheduledTasks(this).forEach(Task::cancel);
|
||||
pluginInstance.unload();
|
||||
Logger.global.logInfo("Saved and stopped!");
|
||||
}
|
||||
@ -207,9 +199,7 @@ public UUID getUUIDForWorld(File worldFolder) throws IOException {
|
||||
@Override
|
||||
public String getWorldName(UUID worldUUID) {
|
||||
Optional<World> world = Sponge.getServer().getWorld(worldUUID);
|
||||
if (world.isPresent()) return world.get().getName();
|
||||
|
||||
return null;
|
||||
return world.map(World::getName).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -233,7 +223,7 @@ public boolean isMetricsEnabled(boolean configValue) {
|
||||
if (pluginContainer != null) {
|
||||
Tristate metricsEnabled = Sponge.getMetricsConfigManager().getCollectionState(pluginContainer);
|
||||
if (metricsEnabled != Tristate.UNDEFINED) {
|
||||
return metricsEnabled == Tristate.TRUE ? true : false;
|
||||
return metricsEnabled == Tristate.TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
dependencies {
|
||||
shadow "org.spongepowered:spongeapi:8.0.0-SNAPSHOT"
|
||||
|
||||
compile group: 'org.bstats', name: 'bstats-sponge-lite', version: '1.5'
|
||||
|
||||
compile (project(':BlueMapCommon')) {
|
||||
implementation group: 'org.bstats', name: 'bstats-sponge-lite', version: '1.5'
|
||||
|
||||
implementation (project(':BlueMapCommon')) {
|
||||
//exclude dependencies provided by sponge
|
||||
exclude group: 'com.google.guava', module: 'guava'
|
||||
exclude group: 'com.google.code.gson', module: 'gson'
|
||||
@ -13,9 +13,10 @@ dependencies {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
build.dependsOn shadowJar {
|
||||
destinationDirectory = file '../../build/release'
|
||||
archiveFileName = "BlueMap-${version}-sponge-8.0.0.jar"
|
||||
archiveFileName.set("BlueMap-${archiveVersion.get()}-sponge-8.0.0.jar")
|
||||
|
||||
relocate 'net.querz.nbt', 'de.bluecolored.shadow.querz.nbt'
|
||||
relocate 'org.apache.commons.io', 'de.bluecolored.shadow.apache.commons.io'
|
||||
@ -27,11 +28,13 @@ build.dependsOn shadowJar {
|
||||
relocate 'com.typesafe.config', 'de.bluecolored.shadow.typesafe.config'
|
||||
relocate 'org.checkerframework', 'de.bluecolored.shadow.checkerframework'
|
||||
relocate 'org.codehaus', 'de.bluecolored.shadow.codehaus'
|
||||
relocate 'io.leangen.geantyref', 'de.bluecolored.shadow.geantyref'
|
||||
}
|
||||
|
||||
processResources {
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include 'META-INF/plugins.json'
|
||||
duplicatesStrategy = DuplicatesStrategy.WARN
|
||||
|
||||
expand (
|
||||
version: project.version
|
||||
|
@ -50,41 +50,6 @@ public EventForwarder(ServerEventListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
/* Use ChunkSaveToDisk as it is the preferred event to use and more reliable on the chunk actually saved to disk
|
||||
@Listener(order = Order.POST)
|
||||
public void onWorldSaveToDisk(SaveWorldEvent evt) {
|
||||
listener.onWorldSaveToDisk(evt.getTargetWorld().getUniqueId());
|
||||
}
|
||||
*/
|
||||
|
||||
@Listener(order = Order.POST)
|
||||
public void onChunkSaveToDisk(ChunkEvent.Save.Pre evt) {
|
||||
ResourceKey worldKey = evt.chunkWorld();
|
||||
Optional<ServerWorld> world = Sponge.server().worldManager().world(worldKey);
|
||||
if (world.isPresent()) {
|
||||
listener.onChunkSaveToDisk(world.get().uniqueId(), SpongePlugin.fromSpongePoweredVector(evt.targetChunk().chunkPosition().toVector2(true)));
|
||||
}
|
||||
}
|
||||
|
||||
@Listener(order = Order.POST)
|
||||
public void onBlockChange(ChangeBlockEvent.All evt) {
|
||||
for (Transaction<BlockSnapshot> tr : evt.transactions()) {
|
||||
if(!tr.isValid()) continue;
|
||||
|
||||
Optional<ServerLocation> ow = tr.finalReplacement().location();
|
||||
if (ow.isPresent()) {
|
||||
listener.onBlockChange(ow.get().world().uniqueId(), SpongePlugin.fromSpongePoweredVector(ow.get().position().toInt()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO event missing in Sponge
|
||||
// @Listener(order = Order.POST)
|
||||
// public void onChunkFinishedGeneration(PopulateChunkEvent.Post evt) {
|
||||
// Vector3i chunkPos = evt.getTargetChunk().getPosition();
|
||||
// listener.onChunkFinishedGeneration(evt.getTargetChunk().getWorld().getUniqueId(), new Vector2i(chunkPos.getX(), chunkPos.getZ()));
|
||||
// }
|
||||
|
||||
@Listener(order = Order.POST)
|
||||
public void onPlayerJoin(ServerSideConnectionEvent.Join evt) {
|
||||
listener.onPlayerJoin(evt.player().uniqueId());
|
||||
|
@ -23,25 +23,23 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package de.bluecolored.bluemap.sponge8;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.flowpowered.math.vector.Vector3d;
|
||||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.spongepowered.api.adventure.SpongeComponents;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
import org.spongepowered.api.world.Locatable;
|
||||
|
||||
import com.flowpowered.math.vector.Vector3d;
|
||||
|
||||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.CommandSource;
|
||||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import de.bluecolored.bluemap.core.world.World;
|
||||
import java.util.Optional;
|
||||
|
||||
public class SpongeCommandSource implements CommandSource {
|
||||
|
||||
private Plugin plugin;
|
||||
private Audience audience;
|
||||
private Subject subject;
|
||||
private final Plugin plugin;
|
||||
private final Audience audience;
|
||||
private final Subject subject;
|
||||
|
||||
public SpongeCommandSource(Plugin plugin, Audience audience, Subject subject) {
|
||||
this.plugin = plugin;
|
||||
|
@ -24,48 +24,42 @@
|
||||
*/
|
||||
package de.bluecolored.bluemap.sponge8;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.spongepowered.api.command.Command;
|
||||
import org.spongepowered.api.command.CommandCause;
|
||||
import org.spongepowered.api.command.CommandResult;
|
||||
import org.spongepowered.api.command.parameter.ArgumentReader;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.Message;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.Suggestion;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
|
||||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.plugin.commands.Commands;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.spongepowered.api.command.Command;
|
||||
import org.spongepowered.api.command.CommandCause;
|
||||
import org.spongepowered.api.command.CommandCompletion;
|
||||
import org.spongepowered.api.command.CommandResult;
|
||||
import org.spongepowered.api.command.parameter.ArgumentReader;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public class SpongeCommands {
|
||||
|
||||
private CommandDispatcher<Subject> dispatcher;
|
||||
private final CommandDispatcher<CommandCause> dispatcher;
|
||||
|
||||
public SpongeCommands(final Plugin plugin) {
|
||||
this.dispatcher = new CommandDispatcher<>();
|
||||
|
||||
// register commands
|
||||
// this assumes that every Subject will also be an Audience
|
||||
new Commands<>(plugin, dispatcher, subject -> new SpongeCommandSource(plugin, (Audience) subject, subject));
|
||||
new Commands<>(plugin, dispatcher, cause -> new SpongeCommandSource(plugin, cause.audience(), cause.subject()));
|
||||
}
|
||||
|
||||
public Collection<SpongeCommandProxy> getRootCommands(){
|
||||
Collection<SpongeCommandProxy> rootCommands = new ArrayList<>();
|
||||
|
||||
for (CommandNode<Subject> node : this.dispatcher.getRoot().getChildren()) {
|
||||
for (CommandNode<CommandCause> node : this.dispatcher.getRoot().getChildren()) {
|
||||
rootCommands.add(new SpongeCommandProxy(node.getName()));
|
||||
}
|
||||
|
||||
@ -92,7 +86,7 @@ public CommandResult process(CommandCause cause, ArgumentReader.Mutable argument
|
||||
}
|
||||
|
||||
try {
|
||||
return CommandResult.builder().result(dispatcher.execute(command, cause.subject())).build();
|
||||
return CommandResult.builder().result(dispatcher.execute(command, cause)).build();
|
||||
} catch (CommandSyntaxException ex) {
|
||||
cause.audience().sendMessage(Component.text(ex.getRawMessage().getString(), NamedTextColor.RED));
|
||||
|
||||
@ -104,28 +98,34 @@ public CommandResult process(CommandCause cause, ArgumentReader.Mutable argument
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggestions(CommandCause cause, ArgumentReader.Mutable arguments) {
|
||||
public List<CommandCompletion> complete(CommandCause cause, ArgumentReader.Mutable arguments) {
|
||||
String command = label;
|
||||
if (!arguments.input().isEmpty()) {
|
||||
command += " " + arguments.input();
|
||||
}
|
||||
|
||||
List<String> completions = new ArrayList<>();
|
||||
List<CommandCompletion> completions = new ArrayList<>();
|
||||
|
||||
try {
|
||||
Suggestions suggestions = dispatcher.getCompletionSuggestions(dispatcher.parse(command, cause.subject())).get(100, TimeUnit.MILLISECONDS);
|
||||
Suggestions suggestions = dispatcher.getCompletionSuggestions(dispatcher.parse(command, cause)).get(100, TimeUnit.MILLISECONDS);
|
||||
for (Suggestion suggestion : suggestions.getList()) {
|
||||
String text = suggestion.getText();
|
||||
|
||||
if (text.indexOf(' ') == -1) {
|
||||
completions.add(text);
|
||||
Message tooltip = suggestion.getTooltip();
|
||||
if (tooltip == null) {
|
||||
completions.add(CommandCompletion.of(text));
|
||||
} else {
|
||||
completions.add(CommandCompletion.of(text, Component.text(tooltip.getString())));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException ignore) {
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (ExecutionException | TimeoutException ignore) {}
|
||||
|
||||
completions.sort(String::compareToIgnoreCase);
|
||||
completions.sort(Comparator.comparing(CommandCompletion::completion));
|
||||
|
||||
return completions;
|
||||
}
|
||||
|
||||
@ -146,11 +146,11 @@ public Optional<Component> extendedDescription(CommandCause cause) {
|
||||
|
||||
@Override
|
||||
public Component usage(CommandCause cause) {
|
||||
CommandNode<Subject> node = dispatcher.getRoot().getChild(label);
|
||||
CommandNode<CommandCause> node = dispatcher.getRoot().getChild(label);
|
||||
if (node == null) return Component.text("/" + label);
|
||||
|
||||
List<Component> lines = new ArrayList<>();
|
||||
for (String usageString : dispatcher.getSmartUsage(node, cause.subject()).values()) {
|
||||
for (String usageString : dispatcher.getSmartUsage(node, cause).values()) {
|
||||
lines.add(Component.text("/" + label + " ", NamedTextColor.WHITE).append(Component.text(usageString, NamedTextColor.GRAY)));
|
||||
}
|
||||
|
||||
|
@ -24,25 +24,20 @@
|
||||
*/
|
||||
package de.bluecolored.bluemap.sponge8;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.flowpowered.math.vector.Vector3d;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.Gamemode;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.data.Keys;
|
||||
import org.spongepowered.api.effect.potion.PotionEffect;
|
||||
import org.spongepowered.api.effect.potion.PotionEffectTypes;
|
||||
import org.spongepowered.api.entity.living.player.gamemode.GameMode;
|
||||
import org.spongepowered.api.entity.living.player.gamemode.GameModes;
|
||||
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.Gamemode;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.plugin.text.Text;
|
||||
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class SpongePlayer implements Player {
|
||||
|
||||
private static final Map<GameMode, Gamemode> GAMEMODE_MAP = new HashMap<>(5);
|
||||
@ -54,7 +49,7 @@ public class SpongePlayer implements Player {
|
||||
GAMEMODE_MAP.put(GameModes.NOT_SET.get(), Gamemode.SURVIVAL);
|
||||
}
|
||||
|
||||
private UUID uuid;
|
||||
private final UUID uuid;
|
||||
private Text name;
|
||||
private UUID world;
|
||||
private Vector3d position;
|
||||
|
@ -24,29 +24,21 @@
|
||||
*/
|
||||
package de.bluecolored.bluemap.sponge8;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
import com.flowpowered.math.vector.Vector2i;
|
||||
import com.flowpowered.math.vector.Vector3d;
|
||||
import com.flowpowered.math.vector.Vector3i;
|
||||
import com.google.inject.Inject;
|
||||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.ServerEventListener;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.ServerInterface;
|
||||
import de.bluecolored.bluemap.core.MinecraftVersion;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
import de.bluecolored.bluemap.core.resourcepack.ParseResourceException;
|
||||
import de.bluecolored.bluemap.sponge8.SpongeCommands.SpongeCommandProxy;
|
||||
import net.querz.nbt.CompoundTag;
|
||||
import net.querz.nbt.NBTUtil;
|
||||
import org.spongepowered.api.Platform;
|
||||
import org.spongepowered.api.ResourceKey;
|
||||
import org.spongepowered.api.Server;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.adventure.SpongeComponents;
|
||||
@ -63,21 +55,21 @@
|
||||
import org.spongepowered.api.util.Ticks;
|
||||
import org.spongepowered.api.util.Tristate;
|
||||
import org.spongepowered.api.world.server.ServerWorld;
|
||||
|
||||
import de.bluecolored.bluemap.common.plugin.Plugin;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.Player;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.ServerEventListener;
|
||||
import de.bluecolored.bluemap.common.plugin.serverinterface.ServerInterface;
|
||||
import de.bluecolored.bluemap.core.MinecraftVersion;
|
||||
import de.bluecolored.bluemap.core.logger.Logger;
|
||||
import de.bluecolored.bluemap.core.resourcepack.ParseResourceException;
|
||||
import de.bluecolored.bluemap.sponge8.SpongeCommands.SpongeCommandProxy;
|
||||
import org.spongepowered.plugin.PluginContainer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
@org.spongepowered.plugin.jvm.Plugin(Plugin.PLUGIN_ID)
|
||||
public class SpongePlugin implements ServerInterface {
|
||||
|
||||
private final PluginContainer pluginContainer;
|
||||
|
||||
@Inject
|
||||
@ConfigDir(sharedRoot = false)
|
||||
private Path configurationDir;
|
||||
@ -87,17 +79,15 @@ public class SpongePlugin implements ServerInterface {
|
||||
// @SuppressWarnings("unused")
|
||||
// private MetricsLite2 metrics;
|
||||
|
||||
private Plugin pluginInstance;
|
||||
private SpongeCommands commands;
|
||||
|
||||
private Map<File, UUID> worldUUIDs = new ConcurrentHashMap<>();
|
||||
private final Plugin pluginInstance;
|
||||
private final SpongeCommands commands;
|
||||
|
||||
private ExecutorService asyncExecutor;
|
||||
private ExecutorService syncExecutor;
|
||||
|
||||
private int playerUpdateIndex = 0;
|
||||
private Map<UUID, Player> onlinePlayerMap;
|
||||
private List<SpongePlayer> onlinePlayerList;
|
||||
private final Map<UUID, Player> onlinePlayerMap;
|
||||
private final List<SpongePlayer> onlinePlayerList;
|
||||
|
||||
@Inject
|
||||
public SpongePlugin(org.apache.logging.log4j.Logger logger, PluginContainer pluginContainer) {
|
||||
@ -107,7 +97,7 @@ public SpongePlugin(org.apache.logging.log4j.Logger logger, PluginContainer plug
|
||||
this.onlinePlayerMap = new ConcurrentHashMap<>();
|
||||
this.onlinePlayerList = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
final String versionFromSponge = Sponge.platform().container(Platform.Component.GAME).getMetadata().getVersion();
|
||||
final String versionFromSponge = Sponge.platform().container(Platform.Component.GAME).metadata().version();
|
||||
MinecraftVersion version = MinecraftVersion.MC_1_16;
|
||||
try {
|
||||
version = MinecraftVersion.fromVersionString(versionFromSponge);
|
||||
@ -156,7 +146,7 @@ public void onServerStart(StartedEngineEvent<Server> evt) {
|
||||
@Listener
|
||||
public void onServerStop(StoppingEngineEvent<Server> evt) {
|
||||
Logger.global.logInfo("Stopping...");
|
||||
evt.engine().scheduler().tasksByPlugin(pluginContainer).forEach(ScheduledTask::cancel);
|
||||
evt.engine().scheduler().tasks(pluginContainer).forEach(ScheduledTask::cancel);
|
||||
pluginInstance.unload();
|
||||
Logger.global.logInfo("Saved and stopped!");
|
||||
}
|
||||
@ -204,39 +194,35 @@ public void unregisterAllListeners() {
|
||||
|
||||
@Override
|
||||
public UUID getUUIDForWorld(File worldFolder) throws IOException {
|
||||
// this logic derives the the world key from the folder structure
|
||||
final Pattern customDimension = Pattern.compile(".+/dimensions/([a-z0-9_.-]+)/([a-z0-9._-]+)$".replace("/", File.separator));
|
||||
final Matcher matcher = customDimension.matcher(worldFolder.toString());
|
||||
final ResourceKey key;
|
||||
if (matcher.matches()) {
|
||||
key = ResourceKey.of(matcher.group(1), matcher.group(2));
|
||||
} else if ("DIM-1".equals(worldFolder.getName())) {
|
||||
key = ResourceKey.minecraft("the_nether");
|
||||
} else if ("DIM1".equals(worldFolder.getName())) {
|
||||
key = ResourceKey.minecraft("the_end");
|
||||
} else {
|
||||
// assume it's the main world
|
||||
key = Sponge.server().worldManager().defaultWorld().key();
|
||||
try {
|
||||
CompoundTag levelSponge = (CompoundTag) NBTUtil.readTag(new File(worldFolder, "level.dat"));
|
||||
CompoundTag spongeData = levelSponge.getCompoundTag("SpongeData");
|
||||
int[] uuidIntArray = spongeData.getIntArray("UUID");
|
||||
if (uuidIntArray.length != 4) throw new IOException("World-UUID is stored in a wrong format! Is the worlds level.dat corrupted?");
|
||||
return intArrayToUuid(uuidIntArray);
|
||||
} catch (IOException | RuntimeException e) {
|
||||
throw new IOException("Failed to read the worlds level.dat!", e);
|
||||
}
|
||||
|
||||
return Sponge.server().worldManager().world(key)
|
||||
.map(ServerWorld::uniqueId)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getWorldName(UUID worldUUID) {
|
||||
return getServerWorld(worldUUID)
|
||||
.map(serverWorld -> serverWorld
|
||||
.properties()
|
||||
.displayName()
|
||||
.map(SpongeComponents.plainSerializer()::serialize)
|
||||
.orElse(serverWorld.key().asString()))
|
||||
.flatMap(
|
||||
serverWorld -> serverWorld
|
||||
.properties()
|
||||
.displayName()
|
||||
.map(SpongeComponents.plainSerializer()::serialize)
|
||||
)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private Optional<ServerWorld> getServerWorld(UUID worldUUID) {
|
||||
return Sponge.server().worldManager().worldKey(worldUUID).flatMap(k -> Sponge.server().worldManager().world(k));
|
||||
for (ServerWorld world : Sponge.server().worldManager().worlds()) {
|
||||
if (world.uniqueId().equals(worldUUID)) return Optional.of(world);
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -259,7 +245,7 @@ public boolean isMetricsEnabled(boolean configValue) {
|
||||
if (pluginContainer != null) {
|
||||
Tristate metricsEnabled = Sponge.metricsConfigManager().collectionState(pluginContainer);
|
||||
if (metricsEnabled != Tristate.UNDEFINED) {
|
||||
return metricsEnabled == Tristate.TRUE ? true : false;
|
||||
return metricsEnabled == Tristate.TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -309,15 +295,23 @@ private void updateSomePlayers() {
|
||||
}
|
||||
|
||||
public static Vector3d fromSpongePoweredVector(org.spongepowered.math.vector.Vector3d vec) {
|
||||
return new Vector3d(vec.getX(), vec.getY(), vec.getZ());
|
||||
return new Vector3d(vec.x(), vec.y(), vec.z());
|
||||
}
|
||||
|
||||
public static Vector3i fromSpongePoweredVector(org.spongepowered.math.vector.Vector3i vec) {
|
||||
return new Vector3i(vec.getX(), vec.getY(), vec.getZ());
|
||||
return new Vector3i(vec.x(), vec.y(), vec.z());
|
||||
}
|
||||
|
||||
public static Vector2i fromSpongePoweredVector(org.spongepowered.math.vector.Vector2i vec) {
|
||||
return new Vector2i(vec.getX(), vec.getY());
|
||||
return new Vector2i(vec.x(), vec.y());
|
||||
}
|
||||
|
||||
private static UUID intArrayToUuid(int[] array) {
|
||||
if (array.length != 4) throw new IllegalArgumentException("Int array has to contain exactly 4 ints!");
|
||||
return new UUID(
|
||||
(long) array[0] << 32 | (long) array[1] & 0x00000000FFFFFFFFL,
|
||||
(long) array[2] << 32 | (long) array[3] & 0x00000000FFFFFFFFL
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user