mirror of
https://github.com/refactorinqq/SLC-1.8.9.git
synced 2024-11-10 06:51:32 +01:00
Featured Servers
This commit is contained in:
parent
318a7a5590
commit
3e796da7d9
@ -266,10 +266,10 @@ public class Client {
|
||||
}
|
||||
});
|
||||
logger.info("STARTING > servers");
|
||||
FeaturedServersResponse servers = FeaturedServers.get();
|
||||
ArrayList<FeaturedServers.FeaturedServerInfo> servers = FeaturedServers.get();
|
||||
featuredServers.clear();
|
||||
if(servers != null && servers.getServers() != null) {
|
||||
servers.getServers().forEach(server -> {
|
||||
if(servers != null && servers != null) {
|
||||
servers.forEach(server -> {
|
||||
featuredServers.add(new ServerDataFeature(server.getName(), server.getIp()));
|
||||
});
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import net.minecraft.client.multiplayer.ServerList;
|
||||
import net.minecraft.client.network.OldServerPinger;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.silentclient.client.Client;
|
||||
import net.silentclient.client.ServerDataFeature;
|
||||
import net.silentclient.client.gui.SilentScreen;
|
||||
import net.silentclient.client.gui.animation.SimpleAnimation;
|
||||
import net.silentclient.client.gui.elements.Button;
|
||||
@ -64,13 +65,7 @@ public class SilentMultiplayerGui extends SilentScreen {
|
||||
this.savedServerList = new ServerList(this.mc);
|
||||
this.savedServerList.loadServerList();
|
||||
|
||||
servers.clear();
|
||||
for (int i = 0; i < savedServerList.countServers(); ++i)
|
||||
{
|
||||
ServerData serverData = savedServerList.getServerData(i);
|
||||
|
||||
servers.add(new ServerComponent(this, serverData));
|
||||
}
|
||||
this.getServers();
|
||||
}
|
||||
|
||||
this.silentInputs.clear();
|
||||
@ -93,6 +88,19 @@ public class SilentMultiplayerGui extends SilentScreen {
|
||||
this.selectServer(-1);
|
||||
}
|
||||
|
||||
public void getServers() {
|
||||
servers.clear();
|
||||
for(ServerDataFeature serverDataFeature : Client.getInstance().getFeaturedServers()) {
|
||||
servers.add(new ServerComponent(this, serverDataFeature));
|
||||
}
|
||||
for (int i = 0; i < savedServerList.countServers(); ++i)
|
||||
{
|
||||
ServerData serverData = savedServerList.getServerData(i);
|
||||
|
||||
servers.add(new ServerComponent(this, serverData));
|
||||
}
|
||||
}
|
||||
|
||||
public void selectServer(int index)
|
||||
{
|
||||
this.selectedServer = index;
|
||||
@ -105,8 +113,10 @@ public class SilentMultiplayerGui extends SilentScreen {
|
||||
|
||||
if(serverComponent != null) {
|
||||
this.btnSelectServer.enabled = true;
|
||||
this.btnEditServer.enabled = true;
|
||||
this.btnDeleteServer.enabled = true;
|
||||
if(!(serverComponent.getServer() instanceof ServerDataFeature)) {
|
||||
this.btnEditServer.enabled = true;
|
||||
this.btnDeleteServer.enabled = true;
|
||||
}
|
||||
} else {
|
||||
Client.logger.info("Server " + index + " not found!");
|
||||
}
|
||||
@ -174,16 +184,17 @@ public class SilentMultiplayerGui extends SilentScreen {
|
||||
|
||||
public boolean canUpSwap(int index)
|
||||
{
|
||||
return index > 0;
|
||||
return index > Client.getInstance().getFeaturedServers().size();
|
||||
}
|
||||
|
||||
public boolean canDownSwap(int index)
|
||||
{
|
||||
return index < this.savedServerList.countServers() - 1;
|
||||
return (index - Client.getInstance().getFeaturedServers().size()) < this.savedServerList.countServers() - 1;
|
||||
}
|
||||
|
||||
public void swapUp(int index, boolean fullSwap)
|
||||
{
|
||||
index = index - (Client.getInstance().getFeaturedServers().size());
|
||||
int i = fullSwap ? 0 : index - 1;
|
||||
this.savedServerList.swapServers(index, i);
|
||||
|
||||
@ -192,17 +203,12 @@ public class SilentMultiplayerGui extends SilentScreen {
|
||||
this.selectServer(i);
|
||||
}
|
||||
|
||||
servers.clear();
|
||||
for (int i1 = 0; i1 < savedServerList.countServers(); ++i1)
|
||||
{
|
||||
ServerData serverData = savedServerList.getServerData(i1);
|
||||
|
||||
servers.add(new ServerComponent(this, serverData));
|
||||
}
|
||||
getServers();
|
||||
}
|
||||
|
||||
public void swapDown(int index, boolean fullSwap)
|
||||
{
|
||||
index = index - (Client.getInstance().getFeaturedServers().size());
|
||||
int i = fullSwap ? this.savedServerList.countServers() - 1 : index + 1;
|
||||
this.savedServerList.swapServers(index, i);
|
||||
|
||||
@ -211,13 +217,7 @@ public class SilentMultiplayerGui extends SilentScreen {
|
||||
this.selectServer(i);
|
||||
}
|
||||
|
||||
servers.clear();
|
||||
for (int i1 = 0; i1 < savedServerList.countServers(); ++i1)
|
||||
{
|
||||
ServerData serverData = savedServerList.getServerData(i1);
|
||||
|
||||
servers.add(new ServerComponent(this, serverData));
|
||||
}
|
||||
getServers();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -273,6 +273,7 @@ public class SilentMultiplayerGui extends SilentScreen {
|
||||
|
||||
Client.logger.info("Saving server list...");
|
||||
newServerList.saveServerList();
|
||||
getServers();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,6 +16,7 @@ import net.minecraft.client.renderer.texture.TextureUtil;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.silentclient.client.Client;
|
||||
import net.silentclient.client.ServerDataFeature;
|
||||
import net.silentclient.client.gui.elements.Tooltip;
|
||||
import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils;
|
||||
import net.silentclient.client.gui.multiplayer.SilentMultiplayerGui;
|
||||
@ -54,6 +55,7 @@ public class ServerComponent {
|
||||
|
||||
public MouseCursorHandler.CursorType draw(int serverIndex, int mouseX, int mouseY, float x, float y, boolean isSelected) {
|
||||
MouseCursorHandler.CursorType cursorType = null;
|
||||
boolean featured = this.server instanceof ServerDataFeature;
|
||||
if (!this.server.field_78841_f)
|
||||
{
|
||||
this.server.field_78841_f = true;
|
||||
@ -97,7 +99,7 @@ public class ServerComponent {
|
||||
|
||||
RenderUtil.drawImage(this.field_148305_h != null ? serverIcon : UNKNOWN_SERVER, x + 2, y + 2, 31, 31, false);
|
||||
|
||||
if(MouseUtils.isInside(mouseX, mouseY, x + 2, y + 2, 31, 31)) {
|
||||
if(MouseUtils.isInside(mouseX, mouseY, x + 2, y + 2, 31, 31) && !featured) {
|
||||
if(this.owner.canUpSwap(serverIndex)) {
|
||||
RenderUtil.drawImage(new ResourceLocation("silentclient/icons/page-up.png"), x + 2 + (31 / 2) - (15 / 2), y + 2, 15, 15, true, MouseUtils.isInside(mouseX, mouseY, x + 2 + (31 / 2) - (15 / 2), y + 2, 15, 15) ? new Color(255, 255, 255).getRGB() : Theme.borderColor().getRGB());
|
||||
}
|
||||
@ -120,7 +122,7 @@ public class ServerComponent {
|
||||
boolean flag2 = flag || flag1;
|
||||
String s2 = flag2 ? EnumChatFormatting.DARK_RED + this.server.gameVersion : this.server.populationInfo;
|
||||
int j = this.mc.fontRendererObj.getStringWidth(s2);
|
||||
this.mc.fontRendererObj.drawString(s2, (int) x + 240 - j - 15 - 2, (int) y + 3, -1);
|
||||
this.mc.fontRendererObj.drawString(s2, (int) x + 240 - j - 15 - 2 - (featured ? 10 : 0), (int) y + 3, -1);
|
||||
int k = 0;
|
||||
String s = null;
|
||||
int l;
|
||||
@ -184,8 +186,13 @@ public class ServerComponent {
|
||||
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.mc.getTextureManager().bindTexture(Gui.icons);
|
||||
Gui.drawModalRectWithCustomSizedTexture((int) x + 240 - 15, (int) y + 2, (float)(k * 10), (float)(176 + l * 8), 10, 8, 256.0F, 256.0F);
|
||||
Tooltip.render(mouseX, mouseY, x + 240 - 15, y + 2, 10, 8, s1);
|
||||
Gui.drawModalRectWithCustomSizedTexture((int) x + 240 - 15 - (featured ? 10 : 0), (int) y + 2, (float)(k * 10), (float)(176 + l * 8), 10, 8, 256.0F, 256.0F);
|
||||
Tooltip.render(mouseX, mouseY, x + 240 - 15 - (featured ? 10 : 0), y + 2, 10, 8, s1);
|
||||
|
||||
if(this.server instanceof ServerDataFeature) {
|
||||
RenderUtil.drawImage(new ResourceLocation("silentclient/icons/star.png"), x + 240 - 13, y + 2, 8, 8);
|
||||
Tooltip.render(mouseX, mouseY, x + 240 - 13, y + 2, 8, 8, "Featured Server");
|
||||
}
|
||||
|
||||
return cursorType;
|
||||
}
|
||||
@ -193,7 +200,7 @@ public class ServerComponent {
|
||||
public boolean mouseClicked(int serverIndex, int mouseX, int mouseY, float x, float y, boolean isSelected) {
|
||||
boolean isHovered = MouseUtils.isInside(mouseX, mouseY, x, y, 240, 35);
|
||||
if(isHovered) {
|
||||
if(MouseUtils.isInside(mouseX, mouseY, x + 2, y + 2, 31, 31)) {
|
||||
if(MouseUtils.isInside(mouseX, mouseY, x + 2, y + 2, 31, 31) && !(this.server instanceof ServerDataFeature)) {
|
||||
if(this.owner.canUpSwap(serverIndex) && MouseUtils.isInside(mouseX, mouseY, x + 2 + (31 / 2) - (15 / 2), y + 2, 15, 15)) {
|
||||
Client.logger.info("Swapping server " + serverIndex + " to up");
|
||||
this.owner.swapUp(serverIndex, GuiScreen.isShiftKeyDown());
|
||||
|
@ -1,20 +1,37 @@
|
||||
package net.silentclient.client.utils;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import net.silentclient.client.utils.types.FeaturedServersResponse;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class FeaturedServers {
|
||||
public static FeaturedServersResponse get() {
|
||||
public static ArrayList<FeaturedServerInfo> get() {
|
||||
try {
|
||||
String content = Requests.get("https://api.silentclient.net/_next/servers.json");
|
||||
String content = Requests.get("https://assets.silentclient.net/client/servers.json");
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
Gson gson = builder.create();
|
||||
|
||||
FeaturedServersResponse response = gson.fromJson(content.toString(), FeaturedServersResponse.class);
|
||||
Type listType = new TypeToken<ArrayList<FeaturedServerInfo>>(){}.getType();
|
||||
ArrayList<FeaturedServerInfo> response = gson.fromJson(content.toString(), listType);
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class FeaturedServerInfo {
|
||||
public String name;
|
||||
public String ip;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package net.silentclient.client.utils.types;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.silentclient.client.utils.reply.AbstractReply;
|
||||
|
||||
public class FeaturedServersResponse extends AbstractReply {
|
||||
public ArrayList<FeaturedServerInfo> servers = new ArrayList<FeaturedServerInfo>();
|
||||
|
||||
public ArrayList<FeaturedServerInfo> getServers() {
|
||||
return servers;
|
||||
}
|
||||
|
||||
public class FeaturedServerInfo {
|
||||
public String name;
|
||||
public String ip;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user