Correct version dection for SpongeAPI 8

This commit is contained in:
ME1312 2018-07-30 12:29:36 -04:00
parent d4f4a1cf01
commit cc88e6b6ea
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
15 changed files with 38 additions and 4 deletions

View File

@ -43,9 +43,11 @@ public class SubAddHostEvent extends AbstractEvent implements SubEvent {
/**
* Gets the cause of this Event
*
* @deprecated Use simplified methods where available
* @return The player who triggered this event under the key: player
*/
@Override
@Deprecated
public Cause getCause() {
return Cause.builder().named("player", player).build();
}

View File

@ -54,9 +54,11 @@ public class SubAddServerEvent extends AbstractEvent implements SubEvent {
/**
* Gets the cause of this Event
*
* @deprecated Use simplified methods where available
* @return The player who triggered this event under the key: player
*/
@Override
@Deprecated
public Cause getCause() {
return Cause.builder().named("player", player).build();
}

View File

@ -112,9 +112,11 @@ public class SubCreateEvent extends AbstractEvent implements SubEvent {
/**
* Gets the cause of this Event
*
* @deprecated Use simplified methods where available
* @return The player who triggered this event under the key: player
*/
@Override
@Deprecated
public Cause getCause() {
return Cause.builder().named("player", player).build();
}

View File

@ -72,9 +72,11 @@ public class SubEditServerEvent extends AbstractEvent implements SubEvent {
/**
* Gets the cause of this Event
*
* @deprecated Use simplified methods where available
* @return The player who triggered this event under the key: player
*/
@Override
@Deprecated
public Cause getCause() {
return Cause.builder().named("player", player).build();
}

View File

@ -21,9 +21,11 @@ public class SubNetworkConnectEvent extends AbstractEvent implements SubEvent {
/**
* Gets the cause of this Event
*
* @deprecated Use simplified methods where available
* @return An empty cause list
*/
@Override
@Deprecated
public Cause getCause() {
return Cause.builder().build();
}

View File

@ -12,9 +12,11 @@ public class SubNetworkDisconnectEvent extends AbstractEvent implements SubEvent
/**
* Gets the cause of this Event
*
* @deprecated Use simplified methods where available
* @return An empty cause list
*/
@Override
@Deprecated
public Cause getCause() {
return Cause.builder().build();
}

View File

@ -43,9 +43,11 @@ public class SubRemoveHostEvent extends AbstractEvent implements SubEvent {
/**
* Gets the cause of this Event
*
* @deprecated Use simplified methods where available
* @return The player who triggered this event under the key: player
*/
@Override
@Deprecated
public Cause getCause() {
return Cause.builder().named("player", player).build();
}

View File

@ -54,9 +54,11 @@ public class SubRemoveServerEvent extends AbstractEvent implements SubEvent {
/**
* Gets the cause of this Event
*
* @deprecated Use simplified methods where available
* @return The player who triggered this event under the key: player
*/
@Override
@Deprecated
public Cause getCause() {
return Cause.builder().named("player", player).build();
}

View File

@ -63,9 +63,11 @@ public class SubSendCommandEvent extends AbstractEvent implements SubEvent {
/**
* Gets the cause of this Event
*
* @deprecated Use simplified methods where available
* @return The player who triggered this event under the key: player
*/
@Override
@Deprecated
public Cause getCause() {
return Cause.builder().named("player", player).build();
}

View File

@ -44,9 +44,11 @@ public class SubStartEvent extends AbstractEvent implements SubEvent {
/**
* Gets the cause of this Event
*
* @deprecated Use simplified methods where available
* @return The player who triggered this event under the key: player
*/
@Override
@Deprecated
public Cause getCause() {
return Cause.builder().named("player", player).build();
}

View File

@ -56,9 +56,11 @@ public class SubStopEvent extends AbstractEvent implements SubEvent {
/**
* Gets the cause of this Event
*
* @deprecated Use simplified methods where available
* @return The player who triggered this event under the key: player
*/
@Override
@Deprecated
public Cause getCause() {
return Cause.builder().named("player", player).build();
}

View File

@ -31,9 +31,11 @@ public class SubStoppedEvent extends AbstractEvent implements SubEvent {
/**
* Gets the cause of this Event
*
* @deprecated Use simplified methods where available
* @return An empty cause list
*/
@Override
@Deprecated
public Cause getCause() {
return Cause.builder().build();
}

View File

@ -197,7 +197,7 @@ public class Metrics {
playerAmount = playerAmount > 200 ? 200 : playerAmount;
int onlineMode = Sponge.getServer().getOnlineMode() ? 1 : 0;
String minecraftVersion = Sponge.getGame().getPlatform().getMinecraftVersion().getName();
String spongeImplementation = Sponge.getPlatform().getImplementation().getName();
String spongeImplementation = plugin.api.getServerVersion() + "";
// OS/Java specific data
String javaVersion = System.getProperty("java.version");

View File

@ -13,6 +13,9 @@ import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadNetworkL
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadPlayerList;
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadServerList;
import net.ME1312.SubServers.Client.Sponge.Network.SubDataClient;
import org.spongepowered.api.Platform;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.plugin.PluginContainer;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
@ -367,7 +370,10 @@ public final class SubAPI {
* @return Server Version
*/
public Version getServerVersion() {
return new Version(plugin.game.getPlatform().getImplementation().getVersion().get());
PluginContainer container = null;
if (container == null) container = Util.getDespiteException(() -> (PluginContainer) Platform.class.getMethod("getContainer", Class.forName("org.spongepowered.api.Platform$Component")).invoke(Sponge.getPlatform(), Enum.valueOf((Class<Enum>) Class.forName("org.spongepowered.api.Platform$Component"), "IMPLEMENTATION")), null);
if (container == null) container = Util.getDespiteException(() -> (PluginContainer) Platform.class.getMethod("getImplementation").invoke(Sponge.getPlatform()), null);
return (container == null || !container.getVersion().isPresent())?null:new Version(container.getVersion().get());
}
/**

View File

@ -156,10 +156,14 @@ public final class SubCommand implements CommandExecutor {
@SuppressWarnings("unchecked")
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
if (canRun(sender)) {
PluginContainer container = null;
if (container == null) container = Util.getDespiteException(() -> (PluginContainer) Platform.class.getMethod("getContainer", Class.forName("org.spongepowered.api.Platform$Component")).invoke(Sponge.getPlatform(), Enum.valueOf((Class<Enum>) Class.forName("org.spongepowered.api.Platform$Component"), "IMPLEMENTATION")), null);
if (container == null) container = Util.getDespiteException(() -> (PluginContainer) Platform.class.getMethod("getImplementation").invoke(Sponge.getPlatform()), null);
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Version").replace("$str$", "SubServers.Client.Sponge")));
sender.sendMessage(Text.builder(" " + System.getProperty("os.name") + ' ' + System.getProperty("os.version")).color(TextColors.WHITE).append(Text.of(",")).build());
sender.sendMessage(Text.builder(" Java " + System.getProperty("java.version")).color(TextColors.WHITE).append(Text.of(",")).build());
sender.sendMessage(Text.builder(" " + Sponge.getPlatform().getImplementation().getName() + ' ' + Sponge.getPlatform().getImplementation().getVersion().get()).color(TextColors.WHITE).append(Text.of(",")).build());
sender.sendMessage(Text.builder(" " + container.getName() + ' ' + container.getVersion().get()).color(TextColors.WHITE).append(Text.of(",")).build());
sender.sendMessage(Text.builder(" SubServers.Client.Sponge v" + plugin.version.toExtendedString() + ((plugin.api.getPluginBuild() != null)?" (" + plugin.api.getPluginBuild() + ')':"")).color(TextColors.WHITE).build());
sender.sendMessage(Text.EMPTY);
plugin.game.getScheduler().createTaskBuilder().async().execute(() -> {
@ -183,7 +187,7 @@ public final class SubCommand implements CommandExecutor {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Version.Outdated").replace("$name$", "SubServers.Client.Sponge").replace("$str$", updversion.toString()).replace("$int$", Integer.toString(updcount))));
}
} catch (Exception e) {}
});
}).submit(plugin);
return CommandResult.builder().successCount(1).build();
} else {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));