Skip to content

Commit

Permalink
Correct version dection for SpongeAPI 8
Browse files Browse the repository at this point in the history
  • Loading branch information
ME1312 committed Jul 30, 2018
1 parent d4f4a1c commit cc88e6b
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 4 deletions.
Expand Up @@ -43,9 +43,11 @@ public SubAddHostEvent(UUID player, String host) {
/**
* 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();
}
Expand Down
Expand Up @@ -54,9 +54,11 @@ public String getHost() {
/**
* 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();
}
Expand Down
Expand Up @@ -112,9 +112,11 @@ public int getPort() {
/**
* 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();
}
Expand Down
Expand Up @@ -72,9 +72,11 @@ public boolean isPermanent() {
/**
* 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();
}
Expand Down
Expand Up @@ -21,9 +21,11 @@ public SubNetworkConnectEvent(SubDataClient network) {
/**
* 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();
}
Expand Down
Expand Up @@ -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();
}
Expand Down
Expand Up @@ -43,9 +43,11 @@ public SubRemoveHostEvent(UUID player, String host) {
/**
* 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();
}
Expand Down
Expand Up @@ -54,9 +54,11 @@ public String getHost() {
/**
* 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();
}
Expand Down
Expand Up @@ -63,9 +63,11 @@ public void setCommand(String value) {
/**
* 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();
}
Expand Down
Expand Up @@ -44,9 +44,11 @@ public SubStartEvent(UUID player, String server) {
/**
* 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();
}
Expand Down
Expand Up @@ -56,9 +56,11 @@ public boolean isForced() {
/**
* 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();
}
Expand Down
Expand Up @@ -31,9 +31,11 @@ public SubStoppedEvent(String server) {
/**
* 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();
}
Expand Down
Expand Up @@ -197,7 +197,7 @@ private JsonObject getServerData() {
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");
Expand Down
Expand Up @@ -13,6 +13,9 @@
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.*;
Expand Down Expand Up @@ -367,7 +370,10 @@ public Version getPluginBuild() {
* @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());
}

/**
Expand Down
Expand Up @@ -156,10 +156,14 @@ public final class VERSION 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(() -> {
Expand All @@ -183,7 +187,7 @@ public CommandResult execute(CommandSource sender, CommandContext args) throws C
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")));
Expand Down

0 comments on commit cc88e6b

Please sign in to comment.