Skip to content
This repository was archived by the owner on Apr 9, 2024. It is now read-only.

Commit 0745a21

Browse files
committed
Version 1.0.3
- Fix HEX color issues on SpigotMC servers - Fix rare edge case where exception is thrown during config creation - Add safety check for PaperMC version being used on SpigotMC
1 parent 6c4a57d commit 0745a21

File tree

16 files changed

+124
-31
lines changed

16 files changed

+124
-31
lines changed

bungeecord/src/main/java/ch/andre601/advancedserverlist/bungeecord/logging/BungeeLogger.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public BungeeLogger(Logger logger){
3939
}
4040

4141
@Override
42-
public void info(String msg){
43-
logger.info(msg);
42+
public void info(String msg, Object... args){
43+
logger.info(String.format(msg, args));
4444
}
4545

4646
@Override

core/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@
6868

6969
<build>
7070
<finalName>AdvancedServerList-Core-${plugin.version}</finalName>
71+
<resources>
72+
<resource>
73+
<filtering>true</filtering>
74+
<directory>${project.basedir}/src/main/resources</directory>
75+
</resource>
76+
</resources>
7177
<plugins>
7278
<plugin>
7379
<groupId>org.apache.maven.plugins</groupId>

core/src/main/java/ch/andre601/advancedserverlist/core/AdvancedServerList.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import ch.andre601.advancedserverlist.core.profiles.players.PlayerHandler;
3434
import ch.andre601.advancedserverlist.core.profiles.replacer.Placeholders;
3535

36+
import java.io.IOException;
37+
import java.io.InputStream;
3638
import java.lang.reflect.Constructor;
3739
import java.lang.reflect.InvocationTargetException;
3840
import java.net.InetSocketAddress;
@@ -46,6 +48,8 @@ public class AdvancedServerList{
4648
private final CommandHandler commandHandler;
4749
private final PlayerHandler playerHandler;
4850

51+
private String version;
52+
4953
public AdvancedServerList(PluginCore plugin){
5054
this.plugin = plugin;
5155
this.fileHandler = new FileHandler(this);
@@ -113,9 +117,15 @@ public PlayerHandler getPlayerHandler(){
113117
return playerHandler;
114118
}
115119

120+
public String getVersion(){
121+
return version;
122+
}
123+
116124
private void load(){
117125
printBanner();
118-
getPluginLogger().info("Starting AdvancedServerList...");
126+
resolveVersion();
127+
128+
getPluginLogger().info("Starting AdvancedServerList v%s...", version);
119129

120130
getPluginLogger().info("Proxy: " + plugin.getPlatformName() + " " + plugin.getPlatformVersion());
121131

@@ -165,4 +175,16 @@ private void printBanner(){
165175
getPluginLogger().info("/_/ \\_\\_____/|______|");
166176
getPluginLogger().info("");
167177
}
178+
179+
private void resolveVersion(){
180+
try(InputStream is = getClass().getResourceAsStream("/version.properties")){
181+
Properties properties = new Properties();
182+
183+
properties.load(is);
184+
185+
version = properties.getProperty("version");
186+
}catch(IOException ex){
187+
version = "UNKNOWN";
188+
}
189+
}
168190
}

core/src/main/java/ch/andre601/advancedserverlist/core/file/FileHandler.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,16 @@ public List<ServerListProfile> getProfiles(){
6969

7070
public boolean loadConfig(){
7171
logger.info("Loading config.yml...");
72+
File folder = config.toFile().getParentFile();
73+
if(!folder.exists() && !folder.mkdirs()){
74+
logger.warn("Couldn't create folder for plugin. Is it missing Write permissions?");
75+
return false;
76+
}
77+
7278
if(!config.toFile().exists()){
7379
try(InputStream stream = plugin.getClass().getResourceAsStream("/config.yml")){
7480
if(stream == null){
75-
logger.warn("Cannot retrieve config.yml from Plugin.");
81+
logger.warn("Cannot retrieve config.yml from plugin.");
7682
return false;
7783
}
7884

core/src/main/java/ch/andre601/advancedserverlist/core/interfaces/PluginLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
public interface PluginLogger{
2929

30-
void info(String msg);
30+
void info(String msg, Object... args);
3131

3232
void warn(String msg);
3333

core/src/main/java/ch/andre601/advancedserverlist/core/profiles/players/PlayerHandler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ public void load(){
7474
if(parts.length < 2 || parts[0].isEmpty() || parts[1].isEmpty())
7575
continue;
7676

77+
if(players.containsKey(parts[0]))
78+
continue;
79+
7780
players.add(parts[0], parts[1]);
7881
}
7982

@@ -100,6 +103,9 @@ public void save(){
100103
}
101104

102105
public void addPlayer(String name, String ip){
106+
if(players.containsKey(name))
107+
return;
108+
103109
players.add(name, ip);
104110
}
105111

core/src/main/java/ch/andre601/advancedserverlist/core/profiles/replacer/EntryList.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,12 @@ public class EntryList<K, V> extends ArrayList<Map.Entry<K, V>>{
3838
public void add(K key, V value){
3939
add(new AbstractMap.SimpleEntry<>(key, value));
4040
}
41+
42+
public boolean containsKey(K key){
43+
for(Map.Entry<K, V> entry : this){
44+
if(entry.getKey() == key)
45+
return true;
46+
}
47+
return false;
48+
}
4149
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# MIT License
3+
#
4+
# Copyright (c) 2022 Andre_601
5+
#
6+
# Permission is hereby granted, free of charge, to any person obtaining a copy
7+
# of this software and associated documentation files (the "Software"), to deal
8+
# in the Software without restriction, including without limitation the rights
9+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
# copies of the Software, and to permit persons to whom the Software is
11+
# furnished to do so, subject to the following conditions:
12+
#
13+
# The above copyright notice and this permission notice shall be included in all
14+
# copies or substantial portions of the Software.
15+
#
16+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
# SOFTWARE.
23+
#
24+
#
25+
26+
version=${plugin.version}

paper/src/main/java/ch/andre601/advancedserverlist/paper/PaperCore.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,36 @@ public class PaperCore extends JavaPlugin implements PluginCore{
4646

4747
@Override
4848
public void onEnable(){
49-
this.core = new AdvancedServerList(this);
49+
try{
50+
Class.forName("io.papermc.paper.configuration.ConfigurationLoaders");
51+
this.core = new AdvancedServerList(this);
52+
}catch(ClassNotFoundException ex){
53+
try{
54+
Class.forName("com.destroystokyo.paper.PaperConfig");
55+
this.core = new AdvancedServerList(this);
56+
}catch(ClassNotFoundException ex1){
57+
getPluginLogger().warn("======================================== WARNING ========================================");
58+
getPluginLogger().warn("");
59+
getPluginLogger().warn("You are using the PaperMC version of AdvancedServerList on a SpigotMC server.");
60+
getPluginLogger().warn("The PaperMC version is ONLY compatible with PaperMC itself due to it using exclusive");
61+
getPluginLogger().warn("methods and events not available within SpigotMC.");
62+
getPluginLogger().warn("");
63+
getPluginLogger().warn("To avoid any exceptions and errors will AdvancedServerList disable itself now.");
64+
getPluginLogger().warn("Please stop your server and either switch to PaperMC or use the Spigot version");
65+
getPluginLogger().warn("of AdvancedServerList.");
66+
getPluginLogger().warn("");
67+
getPluginLogger().warn("======================================== WARNING ========================================");
68+
69+
getServer().getPluginManager().disablePlugin(this);
70+
}
71+
}
5072
}
5173

5274
@Override
5375
public void onDisable(){
76+
if(getCore() == null)
77+
return; // This is always the case when the plugin is used on a Spigot server (See above try-catch blocks).
78+
5479
getCore().disable();
5580
}
5681

paper/src/main/java/ch/andre601/advancedserverlist/paper/events/PingEvent.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,8 @@ private List<PlayerProfile> getPlayers(List<String> lines, Map<String, Object> r
105105
lines.forEach(line -> players.add(Bukkit.createProfile(UUID.randomUUID(), ComponentParser.text(line)
106106
.replacements(replacements)
107107
.function(text -> {
108-
plugin.getPluginLogger().info("Before: " + text);
109-
if(plugin.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")){
110-
String after = PlaceholderAPI.setPlaceholders(player, text);
111-
112-
plugin.getPluginLogger().info("After: " + after);
113-
return after;
114-
}
108+
if(plugin.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI"))
109+
return PlaceholderAPI.setPlaceholders(player, text);
115110

116111
return text;
117112
})

0 commit comments

Comments
 (0)