mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-22 10:15:52 +01:00
Correct version dection for SpongeAPI 8
This commit is contained in:
parent
d4f4a1cf01
commit
cc88e6b6ea
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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");
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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")));
|
||||
|
Loading…
Reference in New Issue
Block a user