mirror of
https://github.com/refactorinqq/SLC-1.8.9.git
synced 2024-11-10 07:21:32 +01:00
(feature) save featured servers
This commit is contained in:
parent
e87fd6d221
commit
bee0757820
@ -6,6 +6,7 @@ import net.minecraft.client.Minecraft;
|
|||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
import net.minecraft.client.gui.ScaledResolution;
|
import net.minecraft.client.gui.ScaledResolution;
|
||||||
import net.minecraft.client.multiplayer.ServerData;
|
import net.minecraft.client.multiplayer.ServerData;
|
||||||
|
import net.minecraft.client.multiplayer.ServerList;
|
||||||
import net.minecraft.client.resources.data.IMetadataSerializer;
|
import net.minecraft.client.resources.data.IMetadataSerializer;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.Session;
|
import net.minecraft.util.Session;
|
||||||
@ -223,17 +224,18 @@ public class Client {
|
|||||||
content.append(inputLine);
|
content.append(inputLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
globalSettings.setConfig(new JSONObject(content.toString()).getString("config"));
|
globalSettings = gson.fromJson(content.toString(), GlobalSettings.class);
|
||||||
globalSettings.setLite(new JSONObject(content.toString()).getBoolean("lite"));
|
|
||||||
globalSettings.setDisplayedTutorial(new JSONObject(content.toString()).getBoolean("displayedTutorial"));
|
|
||||||
globalSettings.setConfigsMigrated(new JSONObject(content.toString()).getBoolean("configsMigrated"));
|
|
||||||
globalSettings.setPacksPanoramaEnabled(new JSONObject(content.toString()).getBoolean("packsPanoramaEnabled"));
|
|
||||||
Client.getInstance().updateWindowTitle();
|
Client.getInstance().updateWindowTitle();
|
||||||
in.close();
|
in.close();
|
||||||
} catch (Exception err) {
|
} catch (Exception err) {
|
||||||
Client.logger.catching(err);
|
Client.logger.catching(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(globalSettings == null) {
|
||||||
|
globalSettings = new GlobalSettings();
|
||||||
|
}
|
||||||
|
|
||||||
globalSettings.save();
|
globalSettings.save();
|
||||||
Client.getInstance().updateWindowTitle();
|
Client.getInstance().updateWindowTitle();
|
||||||
if(!globalSettings.configsMigrated && new File(Minecraft.getMinecraft().mcDataDir, "SilentClient").exists() && new File(Minecraft.getMinecraft().mcDataDir, "SilentClient").isDirectory()) {
|
if(!globalSettings.configsMigrated && new File(Minecraft.getMinecraft().mcDataDir, "SilentClient").exists() && new File(Minecraft.getMinecraft().mcDataDir, "SilentClient").isDirectory()) {
|
||||||
@ -295,6 +297,20 @@ public class Client {
|
|||||||
featuredServers.add(new ServerDataFeature(server.getName(), server.getIp()));
|
featuredServers.add(new ServerDataFeature(server.getName(), server.getIp()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
ServerList savedServerList = new ServerList(Minecraft.getMinecraft());
|
||||||
|
savedServerList.loadServerList();
|
||||||
|
ArrayList<FeaturedServers.FeaturedServerInfo> newSavedFeaturedServers = new ArrayList<>(globalSettings.getSavedFeaturedServers());
|
||||||
|
globalSettings.getSavedFeaturedServers().forEach((savedServer) -> {
|
||||||
|
if(FeaturedServers.findByIPServerDataFeature(savedServer.getIp(), featuredServers) == null) {
|
||||||
|
Client.logger.info("adding saved featured server to server list: " + savedServer.getIp());
|
||||||
|
savedServerList.addServerData(new ServerData(savedServer.getName(), savedServer.getIp(), false));
|
||||||
|
newSavedFeaturedServers.remove(savedServer);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
globalSettings.setSavedFeaturedServers(newSavedFeaturedServers);
|
||||||
|
globalSettings.save();
|
||||||
|
|
||||||
|
savedServerList.saveServerList();
|
||||||
|
|
||||||
logger.info("STARTING > friends");
|
logger.info("STARTING > friends");
|
||||||
this.updateFriendsList();
|
this.updateFriendsList();
|
||||||
@ -356,7 +372,7 @@ public class Client {
|
|||||||
Client.logger.info("STARTING > config-manager-post-init");
|
Client.logger.info("STARTING > config-manager-post-init");
|
||||||
configManager.postInit();
|
configManager.postInit();
|
||||||
|
|
||||||
if(!globalSettings.displayedTutorial) {
|
if(!globalSettings.isDisplayedTutorial()) {
|
||||||
Minecraft.getMinecraft().displayGuiScreen(new UserTutorial());
|
Minecraft.getMinecraft().displayGuiScreen(new UserTutorial());
|
||||||
}
|
}
|
||||||
} catch(Exception err) {
|
} catch(Exception err) {
|
||||||
|
@ -22,6 +22,7 @@ import net.silentclient.client.gui.lite.clickgui.utils.MouseUtils;
|
|||||||
import net.silentclient.client.gui.multiplayer.SilentMultiplayerGui;
|
import net.silentclient.client.gui.multiplayer.SilentMultiplayerGui;
|
||||||
import net.silentclient.client.gui.theme.Theme;
|
import net.silentclient.client.gui.theme.Theme;
|
||||||
import net.silentclient.client.gui.util.RenderUtil;
|
import net.silentclient.client.gui.util.RenderUtil;
|
||||||
|
import net.silentclient.client.utils.FeaturedServers;
|
||||||
import net.silentclient.client.utils.MouseCursorHandler;
|
import net.silentclient.client.utils.MouseCursorHandler;
|
||||||
import org.apache.commons.lang3.Validate;
|
import org.apache.commons.lang3.Validate;
|
||||||
|
|
||||||
@ -56,6 +57,7 @@ public class ServerComponent {
|
|||||||
public MouseCursorHandler.CursorType draw(int serverIndex, int mouseX, int mouseY, float x, float y, boolean isSelected) {
|
public MouseCursorHandler.CursorType draw(int serverIndex, int mouseX, int mouseY, float x, float y, boolean isSelected) {
|
||||||
MouseCursorHandler.CursorType cursorType = null;
|
MouseCursorHandler.CursorType cursorType = null;
|
||||||
boolean featured = this.server instanceof ServerDataFeature;
|
boolean featured = this.server instanceof ServerDataFeature;
|
||||||
|
boolean unsaved = featured && FeaturedServers.findByIPFeaturedServerInfo(this.server.serverIP, Client.getInstance().getGlobalSettings().getSavedFeaturedServers()) == null;
|
||||||
if (!this.server.field_78841_f)
|
if (!this.server.field_78841_f)
|
||||||
{
|
{
|
||||||
this.server.field_78841_f = true;
|
this.server.field_78841_f = true;
|
||||||
@ -122,7 +124,7 @@ public class ServerComponent {
|
|||||||
boolean flag2 = flag || flag1;
|
boolean flag2 = flag || flag1;
|
||||||
String s2 = flag2 ? EnumChatFormatting.DARK_RED + this.server.gameVersion : this.server.populationInfo;
|
String s2 = flag2 ? EnumChatFormatting.DARK_RED + this.server.gameVersion : this.server.populationInfo;
|
||||||
int j = this.mc.fontRendererObj.getStringWidth(s2);
|
int j = this.mc.fontRendererObj.getStringWidth(s2);
|
||||||
this.mc.fontRendererObj.drawString(s2, (int) x + 240 - j - 15 - 2 - (featured ? 10 : 0), (int) y + 3, -1);
|
this.mc.fontRendererObj.drawString(s2, (int) x + 240 - j - 15 - 2 - (featured ? 10 : 0) - (unsaved ? 10 : 0), (int) y + 3, -1);
|
||||||
int k = 0;
|
int k = 0;
|
||||||
String s = null;
|
String s = null;
|
||||||
int l;
|
int l;
|
||||||
@ -186,12 +188,17 @@ public class ServerComponent {
|
|||||||
|
|
||||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
this.mc.getTextureManager().bindTexture(Gui.icons);
|
this.mc.getTextureManager().bindTexture(Gui.icons);
|
||||||
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);
|
Gui.drawModalRectWithCustomSizedTexture((int) x + 240 - 15 - (featured ? 10 : 0) - (unsaved ? 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);
|
Tooltip.render(mouseX, mouseY, x + 240 - 15 - (featured ? 10 : 0) - (unsaved ? 10 : 0), y + 2, 10, 8, s1);
|
||||||
|
|
||||||
if(this.server instanceof ServerDataFeature) {
|
if(featured) {
|
||||||
RenderUtil.drawImage(new ResourceLocation("silentclient/icons/star.png"), x + 240 - 13, y + 2, 8, 8);
|
RenderUtil.drawImage(new ResourceLocation("silentclient/icons/star.png"), x + 240 - 13 - (unsaved ? 10 : 0), y + 2, 8, 8);
|
||||||
Tooltip.render(mouseX, mouseY, x + 240 - 13, y + 2, 8, 8, "Featured Server");
|
Tooltip.render(mouseX, mouseY, x + 240 - 13 - (unsaved ? 10 : 0), y + 2, 8, 8, "Featured Server");
|
||||||
|
|
||||||
|
if(unsaved) {
|
||||||
|
RenderUtil.drawImage(new ResourceLocation("silentclient/icons/save-icon.png"), x + 240 - 13, y + 2, 8, 8);
|
||||||
|
Tooltip.render(mouseX, mouseY, x + 240 - 13, y + 2, 8, 8, "Save Server");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cursorType;
|
return cursorType;
|
||||||
@ -213,6 +220,13 @@ public class ServerComponent {
|
|||||||
return isHovered;
|
return isHovered;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(this.server instanceof ServerDataFeature) {
|
||||||
|
if(FeaturedServers.findByIPFeaturedServerInfo(this.server.serverIP, Client.getInstance().getGlobalSettings().getSavedFeaturedServers()) == null && MouseUtils.isInside(mouseX, mouseY, x + 240 - 13, y + 2, 8, 8)) {
|
||||||
|
Client.getInstance().getGlobalSettings().getSavedFeaturedServers().add(new FeaturedServers.FeaturedServerInfo(this.server.serverName, this.server.serverIP));
|
||||||
|
Client.getInstance().getGlobalSettings().save();
|
||||||
|
return isHovered;
|
||||||
|
}
|
||||||
|
}
|
||||||
if(!isSelected) {
|
if(!isSelected) {
|
||||||
this.owner.selectServer(serverIndex);
|
this.owner.selectServer(serverIndex);
|
||||||
} else {
|
} else {
|
||||||
|
@ -3,6 +3,7 @@ package net.silentclient.client.utils;
|
|||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
import net.silentclient.client.ServerDataFeature;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -22,10 +23,15 @@ public class FeaturedServers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FeaturedServerInfo {
|
public static class FeaturedServerInfo {
|
||||||
public String name;
|
public String name;
|
||||||
public String ip;
|
public String ip;
|
||||||
|
|
||||||
|
public FeaturedServerInfo(String name, String ip) {
|
||||||
|
this.name = name;
|
||||||
|
this.ip = ip;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@ -34,4 +40,22 @@ public class FeaturedServers {
|
|||||||
return ip;
|
return ip;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ServerDataFeature findByIPServerDataFeature(String ip, ArrayList<ServerDataFeature> servers) {
|
||||||
|
for (ServerDataFeature server : servers) {
|
||||||
|
if (server.serverIP.equals(ip)) {
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FeaturedServerInfo findByIPFeaturedServerInfo(String ip, ArrayList<FeaturedServerInfo> servers) {
|
||||||
|
for (FeaturedServerInfo server : servers) {
|
||||||
|
if (server.getIp().equals(ip)) {
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,8 +1,10 @@
|
|||||||
package net.silentclient.client.utils.types;
|
package net.silentclient.client.utils.types;
|
||||||
|
|
||||||
import net.silentclient.client.Client;
|
import net.silentclient.client.Client;
|
||||||
|
import net.silentclient.client.utils.FeaturedServers;
|
||||||
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class GlobalSettings {
|
public class GlobalSettings {
|
||||||
public String config;
|
public String config;
|
||||||
@ -10,15 +12,20 @@ public class GlobalSettings {
|
|||||||
public boolean displayedTutorial;
|
public boolean displayedTutorial;
|
||||||
public boolean configsMigrated;
|
public boolean configsMigrated;
|
||||||
public boolean packsPanoramaEnabled;
|
public boolean packsPanoramaEnabled;
|
||||||
|
public ArrayList<FeaturedServers.FeaturedServerInfo> savedFeaturedServers;
|
||||||
|
|
||||||
public GlobalSettings() {
|
public GlobalSettings() {
|
||||||
this.config = "Default.txt";
|
this.config = "Default.txt";
|
||||||
this.lite = false;
|
this.lite = false;
|
||||||
this.displayedTutorial = false;
|
this.displayedTutorial = false;
|
||||||
this.packsPanoramaEnabled = true;
|
this.packsPanoramaEnabled = true;
|
||||||
|
this.savedFeaturedServers = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getConfig() {
|
public String getConfig() {
|
||||||
|
if(config == null) {
|
||||||
|
config = "Default.txt";
|
||||||
|
}
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,6 +62,17 @@ public class GlobalSettings {
|
|||||||
this.packsPanoramaEnabled = packsPanoramaEnabled;
|
this.packsPanoramaEnabled = packsPanoramaEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<FeaturedServers.FeaturedServerInfo> getSavedFeaturedServers() {
|
||||||
|
if(savedFeaturedServers == null) {
|
||||||
|
this.savedFeaturedServers = new ArrayList<>();
|
||||||
|
}
|
||||||
|
return savedFeaturedServers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSavedFeaturedServers(ArrayList<FeaturedServers.FeaturedServerInfo> savedFeaturedServers) {
|
||||||
|
this.savedFeaturedServers = savedFeaturedServers;
|
||||||
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
try {
|
try {
|
||||||
FileOutputStream outputStream = new FileOutputStream(Client.getInstance().getGlobalSettingsFile());
|
FileOutputStream outputStream = new FileOutputStream(Client.getInstance().getGlobalSettingsFile());
|
||||||
|
BIN
src/main/resources/assets/minecraft/silentclient/icons/save-icon.png
Executable file
BIN
src/main/resources/assets/minecraft/silentclient/icons/save-icon.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 223 B |
Loading…
Reference in New Issue
Block a user