Skip to content

Commit

Permalink
1.1.0-r3
Browse files Browse the repository at this point in the history
- fixed default config.yml file loading
- fixed updating config.yml with new properties on plugin update
- implemented whitelist for "not ignored" servers
  • Loading branch information
LoneDev6 committed Jan 17, 2023
1 parent 76fddb4 commit 7b35d0a
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>BungeePackFix</groupId>
<artifactId>BungeePackFix</artifactId>
<version>1.1.0-r2</version>
<version>1.1.0-r3</version>
<packaging>jar</packaging>

<name>BungeePackFix</name>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/lone/bungeepackfix/bungee/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void onEnable()
adventure = BungeeAudiences.create(this);
try
{
settings = new Settings(this.getDataFolder().toPath());
settings = new Settings(this.getDataFolder().toPath(), getResourceAsStream("config.yml"));
}
catch (Throwable ex)
{
Expand Down Expand Up @@ -144,7 +144,7 @@ else if(packet.status == ServerboundResourcePackPacket.Status.FAILED_DOWNLOAD.or

private boolean isIgnoredServer(UserConnection conn)
{
return (settings.ignored_servers.contains(conn.getServer().getInfo().getName()));
return settings.isIgnoredServer(conn.getServer().getInfo().getName());
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/dev/lone/bungeepackfix/bungee/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import net.md_5.bungee.api.chat.BaseComponent;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;

public class Settings extends AbstractSettings<BaseComponent[]>
{
public Settings(Path dataDirectory) throws IOException
public Settings(Path dataDirectory, InputStream defaultConfigStream) throws IOException
{
super(dataDirectory);
super(dataDirectory, defaultConfigStream);
}

@Override
Expand Down
22 changes: 19 additions & 3 deletions src/main/java/dev/lone/bungeepackfix/generic/AbstractSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.List;

Expand All @@ -20,6 +21,9 @@ public abstract class AbstractSettings<T>

public boolean ignore_hash_in_url;
public String main_server_name;

public boolean ignored_servers_enabled;
public boolean ignored_servers_invert_check;
public List<String> ignored_servers;

public boolean log_debug;
Expand All @@ -33,18 +37,21 @@ public abstract class AbstractSettings<T>

protected YamlConfig config;

public AbstractSettings(Path dataDirectory) throws IOException
public AbstractSettings(Path dataDirectory, InputStream defaultConfigStream) throws IOException
{
config = new YamlConfig(new File(dataDirectory.toFile(), "config.yml").toPath());
config.load();
config.loadConfig(defaultConfigStream);

equal_pack_attributes_hash = config.getBoolean("equal_pack_attributes.hash", true);
equal_pack_attributes_forced = config.getBoolean("equal_pack_attributes.forced", true);
equal_pack_attributes_prompt_message = config.getBoolean("equal_pack_attributes.prompt_message", true);

ignore_hash_in_url = config.getBoolean("ignore_hash_in_url", true);
main_server_name = config.getString("main_server_name", "server_1");
ignored_servers = config.getStringList("ignored_servers");

ignored_servers_enabled = config.getBoolean("ignored_servers.enabled");
ignored_servers_invert_check = config.getBoolean("ignored_servers.invert_check");
ignored_servers = config.getStringList("ignored_servers.list");

log_debug = config.getBoolean("log.debug", false);
log_ignored_respack = config.getBoolean("log.ignored_respack", false);
Expand All @@ -62,4 +69,13 @@ public AbstractSettings(Path dataDirectory) throws IOException
}

protected abstract void runPlatformDependentCode();

public boolean isIgnoredServer(String name)
{
if(!ignored_servers_enabled)
return false;
if(ignored_servers_invert_check)
return !(ignored_servers.contains(name));
return (ignored_servers.contains(name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@Plugin(
id = "bungeepackfix",
name = "BungeePackFix (Velocity)",
version = "1.1.0-r2",
version = "1.1.0-r3",
description = "Avoid sending resourcepacks again if it's the same resourcepack. Useful when you switch servers.", authors = {"LoneDev", "YoSoyVillaa"}
)
public class BungeePackFixVelocity
Expand Down Expand Up @@ -57,15 +57,17 @@ public void onProxyInitialization(ProxyInitializeEvent e)
{
try
{
//TODO add metrics
this.settings = new Settings(dataDirectory);
this.settings = new Settings(dataDirectory, getClass().getClassLoader().getResourceAsStream("config.yml"));
proxy.getEventManager().register(this, new ServerResourcePackSendListener(this));
}
catch (Throwable ex)
{
ex.printStackTrace();
logger.error("Disabling plugin.");
return;
}

//TODO add metrics
}

@Subscribe(order = PostOrder.NORMAL)
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/dev/lone/bungeepackfix/velocity/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import net.kyori.adventure.text.Component;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;

public class Settings extends AbstractSettings<Component>
{
public Settings(Path dataDirectory) throws IOException
public Settings(Path dataDirectory, InputStream defaultConfigStream) throws IOException
{
super(dataDirectory);
super(dataDirectory, defaultConfigStream);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void onServerResourcePackSend(ServerResourcePackSendEvent e)
if (settings.log_debug)
plugin.getLogger().warn("ServerResourcePackSendEvent: " + player.getUsername() + " " + readablePacket(serverPack));

if (settings.ignored_servers.contains(e.getServerConnection().getServerInfo().getName()))
if (settings.isIgnoredServer(e.getServerConnection().getServerInfo().getName()))
{
plugin.getLogger().warn("Skipping ignored server: " + player.getUsername() + " " + readablePacket(serverPack));
return;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/bungee.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: BungeePackFix
version: '1.1.0-r2'
version: '1.1.0-r3'
main: dev.lone.bungeepackfix.bungee.Main
author: LoneDev
description: Avoid sending resourcepacks again if it's the same resourcepack. Useful when you switch servers.
7 changes: 5 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ equal_pack_attributes:
ignore_hash_in_url: true
main_spigot_server_name: server_1
ignored_servers:
- ignored_1
- ignored_2
enabled: true
invert_check: false
list:
- ignored_1
- ignored_2
log:
ignored_respack: false
sent_respack: false
Expand Down

0 comments on commit 7b35d0a

Please sign in to comment.