runelite-client: Make RuneLiteProperties fully static

This commit is contained in:
Max Weber
2019-08-07 02:58:57 -06:00
parent 3757c3bae6
commit 944064b1b5
9 changed files with 30 additions and 55 deletions

View File

@@ -73,8 +73,9 @@ public class Notifier
private static final int MINIMUM_FLASH_DURATION_MILLIS = 2000; private static final int MINIMUM_FLASH_DURATION_MILLIS = 2000;
private static final int MINIMUM_FLASH_DURATION_TICKS = MINIMUM_FLASH_DURATION_MILLIS / Constants.CLIENT_TICK_LENGTH; private static final int MINIMUM_FLASH_DURATION_TICKS = MINIMUM_FLASH_DURATION_MILLIS / Constants.CLIENT_TICK_LENGTH;
private static final String appName = RuneLiteProperties.getTitle();
private final Client client; private final Client client;
private final String appName;
private final RuneLiteConfig runeLiteConfig; private final RuneLiteConfig runeLiteConfig;
private final ClientUI clientUI; private final ClientUI clientUI;
private final ScheduledExecutorService executorService; private final ScheduledExecutorService executorService;
@@ -89,12 +90,10 @@ public class Notifier
final ClientUI clientUI, final ClientUI clientUI,
final Client client, final Client client,
final RuneLiteConfig runeliteConfig, final RuneLiteConfig runeliteConfig,
final RuneLiteProperties runeLiteProperties,
final ScheduledExecutorService executorService, final ScheduledExecutorService executorService,
final ChatMessageManager chatMessageManager) final ChatMessageManager chatMessageManager)
{ {
this.client = client; this.client = client;
this.appName = runeLiteProperties.getTitle();
this.clientUI = clientUI; this.clientUI = clientUI;
this.runeLiteConfig = runeliteConfig; this.runeLiteConfig = runeliteConfig;
this.executorService = executorService; this.executorService = executorService;

View File

@@ -75,7 +75,6 @@ public class RuneLiteModule extends AbstractModule
bind(ItemManager.class); bind(ItemManager.class);
bind(Scheduler.class); bind(Scheduler.class);
bind(PluginManager.class); bind(PluginManager.class);
bind(RuneLiteProperties.class);
bind(SessionManager.class); bind(SessionManager.class);
bind(Callbacks.class).to(Hooks.class); bind(Callbacks.class).to(Hooks.class);

View File

@@ -28,12 +28,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Properties; import java.util.Properties;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
@Singleton
@Slf4j
public class RuneLiteProperties public class RuneLiteProperties
{ {
private static final String RUNELITE_TITLE = "runelite.title"; private static final String RUNELITE_TITLE = "runelite.title";
@@ -46,57 +41,56 @@ public class RuneLiteProperties
private static final String PATREON_LINK = "runelite.patreon.link"; private static final String PATREON_LINK = "runelite.patreon.link";
private static final String LAUNCHER_VERSION_PROPERTY = "runelite.launcher.version"; private static final String LAUNCHER_VERSION_PROPERTY = "runelite.launcher.version";
private final Properties properties = new Properties(); private static final Properties properties = new Properties();
@Inject static
public RuneLiteProperties()
{ {
try (InputStream in = getClass().getResourceAsStream("runelite.properties")) try (InputStream in = RuneLiteProperties.class.getResourceAsStream("runelite.properties"))
{ {
properties.load(in); properties.load(in);
} }
catch (IOException ex) catch (IOException ex)
{ {
log.warn("unable to load propertries", ex); throw new RuntimeException(ex);
} }
} }
public String getTitle() public static String getTitle()
{ {
return properties.getProperty(RUNELITE_TITLE); return properties.getProperty(RUNELITE_TITLE);
} }
public String getVersion() public static String getVersion()
{ {
return properties.getProperty(RUNELITE_VERSION); return properties.getProperty(RUNELITE_VERSION);
} }
public String getRunescapeVersion() public static String getRunescapeVersion()
{ {
return properties.getProperty(RUNESCAPE_VERSION); return properties.getProperty(RUNESCAPE_VERSION);
} }
public String getDiscordAppId() public static String getDiscordAppId()
{ {
return properties.getProperty(DISCORD_APP_ID); return properties.getProperty(DISCORD_APP_ID);
} }
public String getDiscordInvite() public static String getDiscordInvite()
{ {
return properties.getProperty(DISCORD_INVITE); return properties.getProperty(DISCORD_INVITE);
} }
public String getGithubLink() public static String getGithubLink()
{ {
return properties.getProperty(GITHUB_LINK); return properties.getProperty(GITHUB_LINK);
} }
public String getWikiLink() public static String getWikiLink()
{ {
return properties.getProperty(WIKI_LINK); return properties.getProperty(WIKI_LINK);
} }
public String getPatreonLink() public static String getPatreonLink()
{ {
return properties.getProperty(PATREON_LINK); return properties.getProperty(PATREON_LINK);
} }

View File

@@ -49,7 +49,6 @@ import net.runelite.discord.DiscordUser;
public class DiscordService implements AutoCloseable public class DiscordService implements AutoCloseable
{ {
private final EventBus eventBus; private final EventBus eventBus;
private final RuneLiteProperties runeLiteProperties;
private final ScheduledExecutorService executorService; private final ScheduledExecutorService executorService;
private final DiscordRPC discordRPC; private final DiscordRPC discordRPC;
@@ -62,12 +61,10 @@ public class DiscordService implements AutoCloseable
@Inject @Inject
private DiscordService( private DiscordService(
final EventBus eventBus, final EventBus eventBus,
final RuneLiteProperties runeLiteProperties,
final ScheduledExecutorService executorService) final ScheduledExecutorService executorService)
{ {
this.eventBus = eventBus; this.eventBus = eventBus;
this.runeLiteProperties = runeLiteProperties;
this.executorService = executorService; this.executorService = executorService;
DiscordRPC discordRPC = null; DiscordRPC discordRPC = null;
@@ -106,7 +103,7 @@ public class DiscordService implements AutoCloseable
discordEventHandlers.joinGame = this::joinGame; discordEventHandlers.joinGame = this::joinGame;
discordEventHandlers.spectateGame = this::spectateGame; discordEventHandlers.spectateGame = this::spectateGame;
discordEventHandlers.joinRequest = this::joinRequest; discordEventHandlers.joinRequest = this::joinRequest;
discordRPC.Discord_Initialize(runeLiteProperties.getDiscordAppId(), discordEventHandlers, true, null); discordRPC.Discord_Initialize(RuneLiteProperties.getDiscordAppId(), discordEventHandlers, true, null);
executorService.scheduleAtFixedRate(discordRPC::Discord_RunCallbacks, 0, 2, TimeUnit.SECONDS); executorService.scheduleAtFixedRate(discordRPC::Discord_RunCallbacks, 0, 2, TimeUnit.SECONDS);
} }

View File

@@ -68,9 +68,6 @@ public class ChatNotificationsPlugin extends Plugin
@Inject @Inject
private Notifier notifier; private Notifier notifier;
@Inject
private RuneLiteProperties runeLiteProperties;
//Custom Highlights //Custom Highlights
private Pattern usernameMatcher = null; private Pattern usernameMatcher = null;
private String usernameReplacer = ""; private String usernameReplacer = "";
@@ -148,7 +145,7 @@ public class ChatNotificationsPlugin extends Plugin
break; break;
case CONSOLE: case CONSOLE:
// Don't notify for notification messages // Don't notify for notification messages
if (chatMessage.getName().equals(runeLiteProperties.getTitle())) if (chatMessage.getName().equals(RuneLiteProperties.getTitle()))
{ {
return; return;
} }

View File

@@ -91,9 +91,6 @@ public class DiscordPlugin extends Plugin
@Inject @Inject
private ClientToolbar clientToolbar; private ClientToolbar clientToolbar;
@Inject
private RuneLiteProperties properties;
@Inject @Inject
private DiscordState discordState; private DiscordState discordState;
@@ -125,7 +122,7 @@ public class DiscordPlugin extends Plugin
.tab(false) .tab(false)
.tooltip("Join Discord") .tooltip("Join Discord")
.icon(icon) .icon(icon)
.onClick(() -> LinkBrowser.browse(properties.getDiscordInvite())) .onClick(() -> LinkBrowser.browse(RuneLiteProperties.getDiscordInvite()))
.build(); .build();
clientToolbar.addNavigation(discordButton); clientToolbar.addNavigation(discordButton);

View File

@@ -58,16 +58,14 @@ class DiscordState
private final DiscordService discordService; private final DiscordService discordService;
private final DiscordConfig config; private final DiscordConfig config;
private PartyService party; private PartyService party;
private final RuneLiteProperties properties;
private DiscordPresence lastPresence; private DiscordPresence lastPresence;
@Inject @Inject
private DiscordState(final DiscordService discordService, final DiscordConfig config, final PartyService party, final RuneLiteProperties properties) private DiscordState(final DiscordService discordService, final DiscordConfig config, final PartyService party)
{ {
this.discordService = discordService; this.discordService = discordService;
this.config = config; this.config = config;
this.party = party; this.party = party;
this.properties = properties;
} }
/** /**
@@ -173,12 +171,12 @@ class DiscordState
} }
// Replace snapshot with + to make tooltip shorter (so it will span only 1 line) // Replace snapshot with + to make tooltip shorter (so it will span only 1 line)
final String versionShortHand = properties.getVersion().replace("-SNAPSHOT", "+"); final String versionShortHand = RuneLiteProperties.getVersion().replace("-SNAPSHOT", "+");
final DiscordPresence.DiscordPresenceBuilder presenceBuilder = DiscordPresence.builder() final DiscordPresence.DiscordPresenceBuilder presenceBuilder = DiscordPresence.builder()
.state(MoreObjects.firstNonNull(state, "")) .state(MoreObjects.firstNonNull(state, ""))
.details(MoreObjects.firstNonNull(details, "")) .details(MoreObjects.firstNonNull(details, ""))
.largeImageText(properties.getTitle() + " v" + versionShortHand) .largeImageText(RuneLiteProperties.getTitle() + " v" + versionShortHand)
.startTimestamp(event.getStart()) .startTimestamp(event.getStart())
.smallImageKey(imageKey) .smallImageKey(imageKey)
.partyMax(PARTY_MAX) .partyMax(PARTY_MAX)

View File

@@ -79,9 +79,6 @@ public class InfoPanel extends PluginPanel
@Nullable @Nullable
private Client client; private Client client;
@Inject
private RuneLiteProperties runeLiteProperties;
@Inject @Inject
private EventBus eventBus; private EventBus eventBus;
@@ -117,7 +114,7 @@ public class InfoPanel extends PluginPanel
final Font smallFont = FontManager.getRunescapeSmallFont(); final Font smallFont = FontManager.getRunescapeSmallFont();
JLabel version = new JLabel(htmlLabel("RuneLite version: ", runeLiteProperties.getVersion())); JLabel version = new JLabel(htmlLabel("RuneLite version: ", RuneLiteProperties.getVersion()));
version.setFont(smallFont); version.setFont(smallFont);
JLabel revision = new JLabel(); JLabel revision = new JLabel();
@@ -176,10 +173,10 @@ public class InfoPanel extends PluginPanel
} }
}); });
actionsContainer.add(buildLinkPanel(GITHUB_ICON, "Report an issue or", "make a suggestion", runeLiteProperties.getGithubLink())); actionsContainer.add(buildLinkPanel(GITHUB_ICON, "Report an issue or", "make a suggestion", RuneLiteProperties.getGithubLink()));
actionsContainer.add(buildLinkPanel(DISCORD_ICON, "Talk to us on our", "discord server", runeLiteProperties.getDiscordInvite())); actionsContainer.add(buildLinkPanel(DISCORD_ICON, "Talk to us on our", "discord server", RuneLiteProperties.getDiscordInvite()));
actionsContainer.add(buildLinkPanel(PATREON_ICON, "Become a patron to", "help support RuneLite", runeLiteProperties.getPatreonLink())); actionsContainer.add(buildLinkPanel(PATREON_ICON, "Become a patron to", "help support RuneLite", RuneLiteProperties.getPatreonLink()));
actionsContainer.add(buildLinkPanel(WIKI_ICON, "Information about", "RuneLite and plugins", runeLiteProperties.getWikiLink())); actionsContainer.add(buildLinkPanel(WIKI_ICON, "Information about", "RuneLite and plugins", RuneLiteProperties.getWikiLink()));
add(versionPanel, BorderLayout.NORTH); add(versionPanel, BorderLayout.NORTH);
add(actionsContainer, BorderLayout.CENTER); add(actionsContainer, BorderLayout.CENTER);

View File

@@ -111,7 +111,6 @@ public class ClientUI
@Getter @Getter
private TrayIcon trayIcon; private TrayIcon trayIcon;
private final RuneLiteProperties properties;
private final RuneLiteConfig config; private final RuneLiteConfig config;
private final KeyManager keyManager; private final KeyManager keyManager;
private final MouseManager mouseManager; private final MouseManager mouseManager;
@@ -138,7 +137,6 @@ public class ClientUI
@Inject @Inject
private ClientUI( private ClientUI(
RuneLiteProperties properties,
RuneLiteConfig config, RuneLiteConfig config,
KeyManager keyManager, KeyManager keyManager,
MouseManager mouseManager, MouseManager mouseManager,
@@ -146,7 +144,6 @@ public class ClientUI
ConfigManager configManager, ConfigManager configManager,
Provider<ClientThread> clientThreadProvider) Provider<ClientThread> clientThreadProvider)
{ {
this.properties = properties;
this.config = config; this.config = config;
this.keyManager = keyManager; this.keyManager = keyManager;
this.mouseManager = mouseManager; this.mouseManager = mouseManager;
@@ -286,7 +283,7 @@ public class ClientUI
return false; return false;
} }
frame.setTitle(properties.getTitle() + " - " + name); frame.setTitle(RuneLiteProperties.getTitle() + " - " + name);
return true; return true;
}); });
} }
@@ -315,7 +312,7 @@ public class ClientUI
// Try to enable fullscreen on OSX // Try to enable fullscreen on OSX
OSXUtil.tryEnableFullscreen(frame); OSXUtil.tryEnableFullscreen(frame);
frame.setTitle(properties.getTitle()); frame.setTitle(RuneLiteProperties.getTitle());
frame.setIconImage(ICON); frame.setIconImage(ICON);
frame.getLayeredPane().setCursor(Cursor.getDefaultCursor()); // Prevent substance from using a resize cursor for pointing frame.getLayeredPane().setCursor(Cursor.getDefaultCursor()); // Prevent substance from using a resize cursor for pointing
frame.setLocationRelativeTo(frame.getOwner()); frame.setLocationRelativeTo(frame.getOwner());
@@ -464,7 +461,7 @@ public class ClientUI
frame.revalidateMinimumSize(); frame.revalidateMinimumSize();
// Create tray icon (needs to be created after frame is packed) // Create tray icon (needs to be created after frame is packed)
trayIcon = SwingUtil.createTrayIcon(ICON, properties.getTitle(), frame); trayIcon = SwingUtil.createTrayIcon(ICON, RuneLiteProperties.getTitle(), frame);
// Move frame around (needs to be done after frame is packed) // Move frame around (needs to be done after frame is packed)
if (config.rememberScreenBounds()) if (config.rememberScreenBounds())
@@ -844,12 +841,12 @@ public class ClientUI
if (player != null && player.getName() != null) if (player != null && player.getName() != null)
{ {
frame.setTitle(properties.getTitle() + " - " + player.getName()); frame.setTitle(RuneLiteProperties.getTitle() + " - " + player.getName());
} }
} }
else else
{ {
frame.setTitle(properties.getTitle()); frame.setTitle(RuneLiteProperties.getTitle());
} }
if (frame.isAlwaysOnTopSupported()) if (frame.isAlwaysOnTopSupported())