Compare commits

...
26 Commits
Author SHA1 Message Date
Andre_601 d3673a79af Update README.md 2023-01-23 20:59:26 +01:00
Andre_601 29c6930ce1 Merge pull request #38 from Andre601/feature/add-api
Start with an API for custom placeholder support
2023-01-23 20:54:03 +01:00
Andre601 125e9c0918 Add missing files to git 2023-01-23 20:53:21 +01:00
Andre601 2ac6931f26 Remove unused files and add workflow 2023-01-23 20:52:37 +01:00
Andre601 e301ef38f0 Bump version + Docs 2023-01-23 20:36:28 +01:00
Andre_601 3f6ada4599 Create api_support.yml 2023-01-23 14:27:41 +01:00
Andre601 45d3f17faa Use a Constructor for PlaceholderProvider 2023-01-22 15:00:01 +01:00
Andre601 d8fca2ca03 Improve Javadocs and rename getUuid to getUUID 2023-01-21 00:14:06 +01:00
Andre601 730b2e3aa8 Get rid of <T> nonsense for GenericPlayer 2023-01-21 00:03:55 +01:00
Andre601 e4e3543b9b Check for null/empty before lowercasing identifier 2023-01-20 23:18:59 +01:00
Andre_601 a955109db5 Merge pull request #44 from Andre601/dependabot/maven/core/com.unascribed-flexver-java-1.1.0
Bump flexver-java from 1.0.2 to 1.1.0 in /core
2023-01-17 16:55:01 +01:00
dependabot[bot] d399c7df63 Bump flexver-java from 1.0.2 to 1.1.0 in /core
Bumps flexver-java from 1.0.2 to 1.1.0.

---
updated-dependencies:
- dependency-name: com.unascribed:flexver-java
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-17 15:11:31 +00:00
Andre601 973620925d fix wrong char position 2023-01-16 15:22:42 +01:00
Andre601 697e9e265d Update javadoc 2023-01-11 23:14:28 +01:00
Andre601 cabed6aa65 Update missing copyright headers 2023-01-11 23:10:00 +01:00
Andre601 b408658026 Apply fixes 2023-01-11 23:08:41 +01:00
Andre601 15f611445c Merge branch 'master' into feature/add-api
# Conflicts:
#	api/src/main/java/ch/andre601/advancedserverlist/api/exceptions/InvalidPlaceholderProviderException.java
#	bungeecord/src/main/java/ch/andre601/advancedserverlist/bungeecord/events/BungeeEventWrapper.java
#	core/src/main/java/ch/andre601/advancedserverlist/core/events/PingEventHandler.java
#	core/src/main/java/ch/andre601/advancedserverlist/core/interfaces/events/GenericEventWrapper.java
#	paper/src/main/java/ch/andre601/advancedserverlist/paper/events/PaperEventWrapper.java
#	paper/src/main/java/ch/andre601/advancedserverlist/paper/objects/PaperPlayer.java
#	paper/src/main/java/ch/andre601/advancedserverlist/paper/objects/PlayerPlaceholders.java
#	spigot/src/main/java/ch/andre601/advancedserverlist/spigot/events/ProtocolLibEventWrapper.java
#	spigot/src/main/java/ch/andre601/advancedserverlist/spigot/objects/SpigotPlayer.java
#	velocity/src/main/java/ch/andre601/advancedserverlist/velocity/events/VelocityEventWrapper.java
#	velocity/src/main/java/ch/andre601/advancedserverlist/velocity/objects/VelocityPlayer.java
2023-01-11 22:45:43 +01:00
Andre_601 a8d6fc48bf Merge branch 'master' into feature/add-api 2022-12-31 23:06:26 +01:00
Andre601 c964c942dc Implement latest changes from v1.10.0 2022-12-28 14:00:19 +01:00
Andre601 27c591d92c Merge branch 'master' into feature/add-api
# Conflicts:
#	core/src/main/java/ch/andre601/advancedserverlist/core/events/PingEventHandler.java
#	core/src/main/java/ch/andre601/advancedserverlist/core/profiles/ProfileManager.java
#	core/src/main/java/ch/andre601/advancedserverlist/core/profiles/ServerListProfile.java
2022-12-28 13:47:46 +01:00
Andre601 de2d43f01c fix methods and imports 2022-12-20 23:48:03 +01:00
Andre_601 3fde989eb5 Merge branch 'master' into feature/add-api 2022-12-20 23:44:28 +01:00
Andre601 c1fa8d0df1 Add maven-compiler-plugin + throws docs 2022-12-16 17:05:06 +01:00
Andre601 f0446fe8f4 Move API to own module 2022-12-16 16:55:21 +01:00
Andre601 5509fb4380 Add and improve javadoc comments 2022-12-11 23:46:26 +01:00
Andre601 d0f7bf9897 Start with an API for custom placeholder support 2022-12-11 23:26:54 +01:00
52 changed files with 2046 additions and 295 deletions

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
name: API support
description: Ask for help with the API.
body:
- type: markdown
attributes:
value: |-
## Before opening
Please make sure you've checked the following things first:
- You're using the latest release of AdvancedServerList [[Download from Modrinth](https://modrinth.com/plugin/advancedserverlist)] and the right API version.
- You're using a supported Proxy/Server version. As of right now is only 1.19.x supported.
- The Feature you suggest hasn't been suggested before.
- type: dropdown
attributes:
label: Platforms
description: On what platform(s) are you using the API?
multiple: true
options:
- Proxy (BungeeCord, Waterfall, ...)
- Proxy (Velocity)
- Server (Spigot, Paper, ...)
validations:
required: true
- type: textarea
attributes:
label: Description
description: |-
Give a detailed description of what exactly you try to do, what steps you did and what you need help with.
placeholder: I tried to...
validations:
required: true
- type: textarea
attributes:
label: Code
description: |-
Provide code-snippets to help us better understand what you tried.
The code is automatically parsed as Java Code.
render: java
validations:
required: true
+30
View File
@@ -0,0 +1,30 @@
name: Deploy Site
on:
push:
paths:
- 'docs/**'
- 'mkdocs.yml'
branches:
- master
tags-ignore:
- '**'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.7
uses: actions/setup-python@v4
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools
python -m pip install -r requirements.txt
- name: Deploy Files
run: |
git config user.name "github-actions[bot]"
git config user.email "actions@github.com"
mkdocs gh-deploy --force
+6 -6
View File
@@ -42,6 +42,8 @@ The format is `${<target> <identifier>}` which was adopted from BungeeTabListPlu
When using the SpigotMC/PaperMC version can you also use placeholders from [PlaceholderAPI][placeholderapi] using its `%<identifier>_<values>%` placeholder format. PlaceholderAPI needs to be installed for that.
If you're a plugin dev can you even add your own custom placeholders through AdvancedServerList's own API.
> [*Read More*][placeholders]
### Formatting
@@ -84,12 +86,10 @@ You can disable this in the global bStats config file located in `/plugins/bstat
</a>
<!-- Links -->
[profiles]: https://github.com/Andre601/AdvancedServerList/wiki/Profiles
[conditions]: https://github.com/Andre601/AdvancedServerList/wiki/Profiles#conditions
[placeholders]: https://github.com/Andre601/AdvancedServerList/wiki/Profiles#placeholders
[minimessage]: https://github.com/Andre601/AdvancedServerList/wiki/Profiles#minimessage
[placeholderapi]: https://www.spigotmc.org/resources/6245/
[profiles]: https://www.andre601.ch/AdvancedServerList/profiles/
[conditions]: https://www.andre601.ch/AdvancedServerList/profiles/#conditions
[placeholders]: https://www.andre601.ch/AdvancedServerList/profiles/placeholders/
[minimessage]: https://www.andre601.ch/AdvancedServerList/profiles/formatting/
[modrinth]: https://modrinth.com/plugin/advancedserverlist
+59
View File
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ MIT License
~
~ Copyright (c) 2022-2023 Andre_601
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is
~ furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
~ SOFTWARE.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>parent</artifactId>
<groupId>ch.andre601.advancedserverlist</groupId>
<version>parent</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>api</artifactId>
<packaging>jar</packaging>
<version>${plugin.version}</version>
<description>${plugin.description}</description>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<finalName>AdvancedServerList-API-${plugin.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,98 @@
/*
* MIT License
*
* Copyright (c) 2022-2023 Andre_601
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
package ch.andre601.advancedserverlist.api;
import ch.andre601.advancedserverlist.api.internal.CheckUtil;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
* Core class of the API for AdvancedServerList.
* <br>Use {@link #get() get()} to retrieve the instance currently used.
*/
public class AdvancedServerListAPI{
private static AdvancedServerListAPI instance;
private final Map<String, PlaceholderProvider> placeholderProviders = new HashMap<>();
private AdvancedServerListAPI(){}
/**
* Retrieves the instance used of this API.
* <br>If no instance has been made so far will a new one be created.
*
* @return Instance of this API.
*/
public static AdvancedServerListAPI get(){
if(instance != null)
return instance;
return (instance = new AdvancedServerListAPI());
}
/**
* Adds the provided {@link PlaceholderProvider PlaceholderProvider} to the list, if it passes the following checks:
* <ul>
* <li>The identifier is not null or empty.</li>
* <li>The identifier does not contain any spaces.</li>
* <li>A PlaceholderProvider with the same identifier doesn't exist already.</li>
* </ul>
* Not passing any of the above checks results in a
* {@link ch.andre601.advancedserverlist.api.exceptions.InvalidPlaceholderProviderException InvalidPlaceholderProviderException}
* being thrown.
*
* @param placeholderProvider
* The {@link PlaceholderProvider PlaceholderProvider} to add.
*
* @throws ch.andre601.advancedserverlist.api.exceptions.InvalidPlaceholderProviderException
* When the provided {@link PlaceholderProvider PlaceholderProvider instance} has a null or empty identifier,
* the identifier contains spaces or another provider with the same identifier is already loaded.
*/
public void addPlaceholderProvider(PlaceholderProvider placeholderProvider){
CheckUtil.notEmpty(placeholderProvider.getIdentifier(), "Identifier");
String identifier = placeholderProvider.getIdentifier().toLowerCase(Locale.ROOT);
CheckUtil.check(identifier.contains(" "), "Identifier may not contain spaces.");
CheckUtil.check(placeholderProviders.containsKey(identifier), "A PlaceholderProvider with name " + identifier + " already exists.");
placeholderProviders.put(identifier, placeholderProvider);
}
/**
* Retrieves the {@link PlaceholderProvider PlaceholderProvider} associated with the given identifier, or {@code null}
* should no such entry exist.
*
* @param identifier
* The identifier to find a matching {@link PlaceholderProvider PlaceholderProvider} for.
*
* @return Possibly-null {@link PlaceholderProvider PlaceholderProvider instance}.
*/
public PlaceholderProvider retrievePlaceholderProvider(String identifier){
return placeholderProviders.get(identifier.toLowerCase(Locale.ROOT));
}
}
@@ -0,0 +1,97 @@
/*
* MIT License
*
* Copyright (c) 2022-2023 Andre_601
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
package ch.andre601.advancedserverlist.api;
import ch.andre601.advancedserverlist.api.objects.GenericPlayer;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
/**
* Abstract class that is used to provide your own Placeholder patterns for AdvancedServerList to parse.
*
* <p>In order for your class to be considered a valid PlaceholderProvider will you need to set the
* {@link #identifier identifier} to a non-null, non-empty value without having any spaces in it.
* <br>Once set, use {@link ch.andre601.advancedserverlist.api.AdvancedServerListAPI#addPlaceholderProvider(PlaceholderProvider) AdvancedServerListAPI#addPlaceholderProvider(PlaceholderProvider)}
* to register your class for AdvancedServerList to use.
*/
public abstract class PlaceholderProvider{
private final String identifier;
/**
* Constructor used to set the identifier for the class extending the PlaceholderProvider class.
*
* <h2>Example</h2>
* <pre>{@code
* public class MyPlaceholders extends PlaceholderProvider {
*
* public MyPlaceholders() {
* super("myplaceholders");
* }
*
* @Override
* public String parsePlaceholder(String placeholder, GenericPlayer player, GenericServer server) {
* if(placeholder.equals("hello")
* return "Hi!";
*
* return null;
* }
* }
* }</pre>
*
* @param identifier
* The identifier to use for the placeholder. Shouldn't be null nor empty.
*/
public PlaceholderProvider(String identifier){
this.identifier = identifier;
}
/**
* Method called by AdvancedServerList's StringReplacer class to replace any appearances of
* {@code ${<identifier> <placeholder>}} with whatever value a PlaceholderProvider may return.
*
* <p>Returning {@code null} will be treated as an invalid placeholder, returning the full placeholder as-is without
* any changes made.
*
* @param placeholder
* The part of the placeholder after the identifier ({@code ${<identifier> <placeholder>}}
* @param player
* The {@link GenericPlayer GenericPlayer instance} used.
* @param server
* The {@link GenericServer GenericServer instance} used.
*
* @return Parsed String based on the PlaceholderProvider or {@code null} for invalid placeholders.
*/
public abstract String parsePlaceholder(String placeholder, GenericPlayer player, GenericServer server);
/**
* Returns the identifier used by this instance.
*
* @return String containing the identifier used by this instance.
*/
public String getIdentifier(){
return identifier;
}
}
@@ -23,11 +23,15 @@
*
*/
package ch.andre601.advancedserverlist.core.profiles.replacer.placeholders;
package ch.andre601.advancedserverlist.api.exceptions;
import java.util.Map;
public interface Placeholders{
/**
* RuntimeException thrown whenever an invalid {@link ch.andre601.advancedserverlist.api.PlaceholderProvider PlaceholderProvider}
* has been given.
*/
public class InvalidPlaceholderProviderException extends RuntimeException{
Map<String, Object> getReplacements();
public InvalidPlaceholderProviderException(String msg){
super(msg);
}
}
@@ -23,12 +23,18 @@
*
*/
package ch.andre601.advancedserverlist.core.interfaces.core;
package ch.andre601.advancedserverlist.api.internal;
import ch.andre601.advancedserverlist.core.profiles.replacer.placeholders.Placeholders;
import ch.andre601.advancedserverlist.api.exceptions.InvalidPlaceholderProviderException;
import java.util.List;
public interface ProxyCore<F, P> extends PluginCore<F>{
List<P> createPlayers(List<String> lines, Placeholders... placeholders);
public class CheckUtil{
public static void notEmpty(String text, String name){
check(text == null || text.isEmpty(), name + " may not be null or empty.");
}
public static void check(boolean condition, String msg){
if(condition)
throw new InvalidPlaceholderProviderException(msg);
}
}
@@ -23,25 +23,25 @@
*
*/
package ch.andre601.advancedserverlist.core.profiles.replacer.placeholders;
package ch.andre601.advancedserverlist.api.internal;
import java.util.HashMap;
import java.util.Map;
import ch.andre601.advancedserverlist.api.PlaceholderProvider;
import ch.andre601.advancedserverlist.api.objects.GenericPlayer;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
public class ServerPlaceholders implements Placeholders{
public class ServerPlaceholders extends PlaceholderProvider{
private final Map<String, Object> replacements = new HashMap<>();
public ServerPlaceholders(int online, int max, String host){
this.replacements.put("${server playersOnline}", online);
this.replacements.put("${server playersMax}", max);
if(host != null)
this.replacements.put("${server host}", host);
public ServerPlaceholders(){
super("server");
}
@Override
public Map<String, Object> getReplacements(){
return this.replacements;
public String parsePlaceholder(String placeholder, GenericPlayer player, GenericServer server){
return switch(placeholder){
case "playersOnline" -> String.valueOf(server.getPlayersOnline());
case "playersMax" -> String.valueOf(server.getPlayersMax());
case "host" -> server.getHost();
default -> null;
};
}
}
@@ -0,0 +1,136 @@
/*
* MIT License
*
* Copyright (c) 2022-2023 Andre_601
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
package ch.andre601.advancedserverlist.api.objects;
import java.util.UUID;
/**
* A basic abstract class used to store generic player data with to use in placeholder resolving.
* <br>The different variants of AdvancedServerList extend their own class with this one and may or may not use all values
* available here.
*
* <p>The following values will always be present, no matter the platform this class is used on:
* <ul>
* <li>{@link #getName() Name of Player}</li>
* <li>{@link #getProtocol() Protocol version of Player}</li>
* <li>{@link #getUUID() UUID of Player}</li>
* </ul>
* Any other value is not guaranteed to be accurate or even be set.
*/
public abstract class GenericPlayer{
protected String name = null;
protected int protocol = -1;
protected UUID uuid = null;
protected String version = null;
protected boolean playedBefore = false;
protected boolean banned = false;
protected boolean whitelisted = false;
/**
* Returns the name of the player.
* <br>Note that on Spigot, Paper and other forks can the name differ from the one cached by AdvancedServerList,
* if the plugin was able to retrieve an OfflinePlayer instance from the server. On BungeeCord and Velocity will
* the returned String always be the name from the cache.
*
* <p>Name may be whatever has been defined in AdvancedServerList's config.yml, should the player not be cached yet
* by AdvancedServerList.
*
* @return String representing the player's name.
*/
public String getName(){
return name;
}
/**
* Returns the protocol ID the player is using. The protocol ID is an integer used by Minecraft to determine what
* version a server or client is running.
*
* @return Integer representing the protocol version of this player.
*/
public int getProtocol(){
return protocol;
}
/**
* Returns the Unique ID associated with this player.
*
* <p>UUID may be whatever has been defined in AdvancedServerList's config.yml, should the player not be cached yet
* by AdvancedServerList.
*
* @return UUID of the player.
*/
public UUID getUUID(){
return uuid;
}
/**
* Returns the {@link #getProtocol() protocol version} in a readable MC version format (i.e. 1.19.3).
*
* <p>This only works on Velocity and will return {@code null} for any other platform.
*
* @return The readable MC version the player uses.
*/
public String getVersion(){
return version;
}
/**
* Returns whether this player has played on the Server before.
*
* <p>The returned boolean is <b>always</b> false on BungeeCord and Velocity due to a lack of any offline player data
* storage.
*
* @return Boolean indicating whether this player has played on this Server before.
*/
public boolean hasPlayedBefore() {
return playedBefore;
}
/**
* Returns whether this player is banned on the server.
*
* <p>The returned boolean is <b>always</b> false on BungeeCord and Velocity due to a lack of any offline player data
* storage.
*
* @return Boolean indicating whether this player was banned from the server.
*/
public boolean isBanned(){
return banned;
}
/**
* Returns whether this player is whitelisted on the server.
*
* <p>The returned boolean is <b>always</b> false on BungeeCord and Velocity due to a lack of any offline player data
* storage.
*
* @return Boolean indicating whether this player was banned from the server.
*/
public boolean isWhitelisted(){
return whitelisted;
}
}
@@ -0,0 +1,70 @@
/*
* MIT License
*
* Copyright (c) 2022-2023 Andre_601
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
package ch.andre601.advancedserverlist.api.objects;
/**
* Simple class used to wrap around some generic server data such as online player count, amount of total players that
* can join and the host (IP/Domain) that got pinged by the player.
*/
public class GenericServer{
private final int playersOnline;
private final int playersMax;
private final String host;
public GenericServer(int playersOnline, int playersMax, String host){
this.playersOnline = playersOnline;
this.playersMax = playersMax;
this.host = host;
}
/**
* Returns the number of players currently online on the server.
*
* @return Number of players online on the server.
*/
public int getPlayersOnline(){
return playersOnline;
}
/**
* Returns the number of total players that can join the server.
*
* @return Number of total players that can join the server.
*/
public int getPlayersMax(){
return playersMax;
}
/**
* Returns the IP/Domain that got pinged by the player.
*
* @return Possibly-null String containing the IP/Domain that got pinged by the player.
*/
public String getHost(){
return host;
}
}
@@ -25,16 +25,18 @@
package ch.andre601.advancedserverlist.bungeecord;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
import ch.andre601.advancedserverlist.bungeecord.commands.CmdAdvancedServerList;
import ch.andre601.advancedserverlist.bungeecord.events.JoinEvent;
import ch.andre601.advancedserverlist.bungeecord.events.PingEvent;
import ch.andre601.advancedserverlist.bungeecord.logging.BungeeLogger;
import ch.andre601.advancedserverlist.bungeecord.objects.BungeePlayer;
import ch.andre601.advancedserverlist.bungeecord.objects.PlayerPlaceholders;
import ch.andre601.advancedserverlist.core.AdvancedServerList;
import ch.andre601.advancedserverlist.core.interfaces.PluginLogger;
import ch.andre601.advancedserverlist.core.interfaces.core.ProxyCore;
import ch.andre601.advancedserverlist.core.interfaces.core.PluginCore;
import ch.andre601.advancedserverlist.core.parsing.ComponentParser;
import ch.andre601.advancedserverlist.core.profiles.favicon.FaviconHandler;
import ch.andre601.advancedserverlist.core.profiles.replacer.placeholders.Placeholders;
import net.md_5.bungee.api.Favicon;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.plugin.Plugin;
@@ -46,7 +48,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class BungeeCordCore extends Plugin implements ProxyCore<Favicon, ServerPing.PlayerInfo>{
public class BungeeCordCore extends Plugin implements PluginCore<Favicon, ServerPing.PlayerInfo, BungeePlayer>{
private AdvancedServerList core;
private FaviconHandler<Favicon> faviconHandler = null;
@@ -54,7 +56,7 @@ public class BungeeCordCore extends Plugin implements ProxyCore<Favicon, ServerP
@Override
public void onEnable(){
this.core = new AdvancedServerList(this);
this.core = new AdvancedServerList(this, new PlayerPlaceholders());
}
@Override
@@ -128,13 +130,12 @@ public class BungeeCordCore extends Plugin implements ProxyCore<Favicon, ServerP
}
@Override
public List<ServerPing.PlayerInfo> createPlayers(List<String> lines, Placeholders... placeholders){
public List<ServerPing.PlayerInfo> createPlayers(List<String> lines, BungeePlayer player, GenericServer server){
List<ServerPing.PlayerInfo> players = new ArrayList<>(lines.size());
for(String line : lines){
String parsed = ComponentParser.text(line)
.replacements(placeholders[0])
.replacements(placeholders[1])
.applyReplacements(player, server)
.toString();
players.add(new ServerPing.PlayerInfo(parsed, UUID.randomUUID()));
@@ -25,27 +25,24 @@
package ch.andre601.advancedserverlist.bungeecord.events;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
import ch.andre601.advancedserverlist.bungeecord.BungeeCordCore;
import ch.andre601.advancedserverlist.bungeecord.BungeePlayer;
import ch.andre601.advancedserverlist.core.interfaces.events.GenericEventWrapper;
import ch.andre601.advancedserverlist.bungeecord.objects.BungeePlayer;
import ch.andre601.advancedserverlist.core.interfaces.core.PluginCore;
import ch.andre601.advancedserverlist.core.interfaces.events.GenericEventWrapper;
import ch.andre601.advancedserverlist.core.objects.CachedPlayer;
import ch.andre601.advancedserverlist.core.profiles.players.GenericPlayer;
import ch.andre601.advancedserverlist.core.profiles.replacer.placeholders.PlayerPlaceholders;
import ch.andre601.advancedserverlist.core.profiles.replacer.placeholders.ServerPlaceholders;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
import net.md_5.bungee.api.Favicon;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ProxyPingEvent;
import java.awt.image.BufferedImage;
import java.net.InetSocketAddress;
import java.util.List;
public class BungeeEventWrapper implements GenericEventWrapper<ProxiedPlayer, Favicon>{
public class BungeeEventWrapper implements GenericEventWrapper<Favicon, ServerPing.PlayerInfo, BungeePlayer>{
private final BungeeCordCore plugin;
private final ProxyPingEvent event;
@@ -81,9 +78,8 @@ public class BungeeEventWrapper implements GenericEventWrapper<ProxiedPlayer, Fa
}
@Override
public void setPlayers(List<String> players, GenericPlayer<ProxiedPlayer> player, PlayerPlaceholders playerPlaceholders, ServerPlaceholders serverPlaceholders){
ServerPing.PlayerInfo[] playerInfos = plugin.createPlayers(players, playerPlaceholders, serverPlaceholders)
.toArray(new ServerPing.PlayerInfo[0]);
public void setPlayers(List<String> players, BungeePlayer player, GenericServer server){
ServerPing.PlayerInfo[] playerInfos = plugin.createPlayers(players, player, server).toArray(new ServerPing.PlayerInfo[0]);
if(playerInfos.length > 0)
ping.getPlayers().setSample(playerInfos);
@@ -131,7 +127,7 @@ public class BungeeEventWrapper implements GenericEventWrapper<ProxiedPlayer, Fa
}
@Override
public String parsePAPIPlaceholders(String text, GenericPlayer<ProxiedPlayer> player){
public String parsePAPIPlaceholders(String text, BungeePlayer player){
return text;
}
@@ -141,12 +137,12 @@ public class BungeeEventWrapper implements GenericEventWrapper<ProxiedPlayer, Fa
}
@Override
public PluginCore<Favicon> getPlugin(){
public PluginCore<Favicon, ServerPing.PlayerInfo, BungeePlayer> getPlugin(){
return plugin;
}
@Override
public GenericPlayer<ProxiedPlayer> createPlayer(CachedPlayer player, int protocol){
public BungeePlayer createPlayer(CachedPlayer player, int protocol){
return new BungeePlayer(player, protocol);
}
@@ -23,13 +23,12 @@
*
*/
package ch.andre601.advancedserverlist.bungeecord;
package ch.andre601.advancedserverlist.bungeecord.objects;
import ch.andre601.advancedserverlist.api.objects.GenericPlayer;
import ch.andre601.advancedserverlist.core.objects.CachedPlayer;
import ch.andre601.advancedserverlist.core.profiles.players.GenericPlayer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
public class BungeePlayer extends GenericPlayer<ProxiedPlayer>{
public class BungeePlayer extends GenericPlayer{
public BungeePlayer(CachedPlayer player, int protocol){
this.name = player.getName();
@@ -0,0 +1,49 @@
/*
* MIT License
*
* Copyright (c) 2022-2023 Andre_601
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
package ch.andre601.advancedserverlist.bungeecord.objects;
import ch.andre601.advancedserverlist.api.PlaceholderProvider;
import ch.andre601.advancedserverlist.api.objects.GenericPlayer;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
import java.util.Locale;
public class PlayerPlaceholders extends PlaceholderProvider{
public PlayerPlaceholders(){
super("player");
}
@Override
public String parsePlaceholder(String placeholder, GenericPlayer player, GenericServer server){
return switch(placeholder.toLowerCase(Locale.ROOT)){
case "name" -> player.getName();
case "protocol" -> String.valueOf(player.getProtocol());
case "uuid" -> String.valueOf(player.getUUID());
default -> null;
};
}
}
+6 -1
View File
@@ -51,6 +51,11 @@
</repositories>
<dependencies>
<dependency>
<groupId>ch.andre601.advancedserverlist</groupId>
<artifactId>api</artifactId>
<version>${plugin.version}</version>
</dependency>
<dependency>
<groupId>org.spongepowered</groupId>
<artifactId>configurate-yaml</artifactId>
@@ -90,7 +95,7 @@
<dependency>
<groupId>com.unascribed</groupId>
<artifactId>flexver-java</artifactId>
<version>1.0.2</version>
<version>1.1.0</version>
</dependency>
<!-- Test dependencies -->
@@ -25,6 +25,9 @@
package ch.andre601.advancedserverlist.core;
import ch.andre601.advancedserverlist.api.AdvancedServerListAPI;
import ch.andre601.advancedserverlist.api.PlaceholderProvider;
import ch.andre601.advancedserverlist.api.internal.ServerPlaceholders;
import ch.andre601.advancedserverlist.core.check.UpdateChecker;
import ch.andre601.advancedserverlist.core.commands.CommandHandler;
import ch.andre601.advancedserverlist.core.file.FileHandler;
@@ -38,25 +41,28 @@ import java.util.Properties;
public class AdvancedServerList{
private final PluginCore<?> plugin;
private final PluginCore<?, ?, ?> plugin;
private final FileHandler fileHandler;
private final CommandHandler commandHandler;
private final PlayerHandler playerHandler;
private final AdvancedServerListAPI api = AdvancedServerListAPI.get();
private UpdateChecker updateChecker;
private String version;
public AdvancedServerList(PluginCore<?> plugin){
public AdvancedServerList(PluginCore<?, ?, ?> plugin, PlaceholderProvider player){
this.plugin = plugin;
this.fileHandler = new FileHandler(this);
this.commandHandler = new CommandHandler(this);
this.playerHandler = new PlayerHandler(this);
this.api.addPlaceholderProvider(player);
this.api.addPlaceholderProvider(new ServerPlaceholders());
load();
}
public PluginCore<?> getPlugin(){
public PluginCore<?, ?, ?> getPlugin(){
return plugin;
}
@@ -76,6 +82,10 @@ public class AdvancedServerList{
return version;
}
public AdvancedServerListAPI getApi(){
return api;
}
public void disable(){
getPlugin().getPluginLogger().info("Saving playercache.json file...");
getPlayerHandler().save();
@@ -25,40 +25,36 @@
package ch.andre601.advancedserverlist.core.events;
import ch.andre601.advancedserverlist.api.objects.GenericPlayer;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
import ch.andre601.advancedserverlist.core.interfaces.core.PluginCore;
import ch.andre601.advancedserverlist.core.interfaces.events.GenericEventWrapper;
import ch.andre601.advancedserverlist.core.parsing.ComponentParser;
import ch.andre601.advancedserverlist.core.profiles.ServerListProfile;
import ch.andre601.advancedserverlist.core.profiles.profile.ProfileEntry;
import ch.andre601.advancedserverlist.core.profiles.profile.ProfileManager;
import ch.andre601.advancedserverlist.core.profiles.ServerListProfile;
import ch.andre601.advancedserverlist.core.profiles.players.GenericPlayer;
import ch.andre601.advancedserverlist.core.profiles.replacer.StringReplacer;
import ch.andre601.advancedserverlist.core.profiles.replacer.placeholders.PlayerPlaceholders;
import ch.andre601.advancedserverlist.core.profiles.replacer.placeholders.ServerPlaceholders;
public class PingEventHandler{
public static <P, F> void handleEvent(GenericEventWrapper<P, F> event){
public static <F, PL, P extends GenericPlayer> void handleEvent(GenericEventWrapper<F, PL, P> event){
if(event.isInvalidProtocol())
return;
PluginCore<F> plugin = event.getPlugin();
GenericPlayer<P> player = event.createPlayer(
plugin.getCore().getPlayerHandler().getCachedPlayer(event.getPlayerIP()),
event.getProtocolVersion()
);
PluginCore<F, PL, P> plugin = event.getPlugin();
String host = event.getVirtualHost();
int online = event.getOnlinePlayers();
int max = event.getMaxPlayers();
PlayerPlaceholders playerPlaceholders = new PlayerPlaceholders(player);
ServerPlaceholders serverPlaceholders = new ServerPlaceholders(online, max, host);
P player = event.createPlayer(
plugin.getCore().getPlayerHandler().getCachedPlayer(event.getPlayerIP()),
event.getProtocolVersion()
);
GenericServer server = new GenericServer(online, max, host);
ServerListProfile profile = ProfileManager.get(plugin.getCore())
.replacements(playerPlaceholders)
.replacements(serverPlaceholders)
.applyReplacements(player, server)
.getProfile();
if(profile == null)
@@ -71,13 +67,12 @@ public class PingEventHandler{
event.setMaxPlayers(max);
}
serverPlaceholders = new ServerPlaceholders(online, max, host);
server = new GenericServer(online, max, host);
if(!entry.getMOTD().isEmpty()){
event.setMotd(
ComponentParser.list(entry.getMOTD())
.replacements(playerPlaceholders)
.replacements(serverPlaceholders)
.applyReplacements(player, server)
.modifyText(text -> event.parsePAPIPlaceholders(text, player))
.toComponent()
);
@@ -92,19 +87,18 @@ public class PingEventHandler{
if(!entry.getPlayerCountText().isEmpty() && !hidePlayers){
event.setPlayerCount(
ComponentParser.text(entry.getPlayerCountText())
.replacements(playerPlaceholders)
.replacements(serverPlaceholders)
.applyReplacements(player, server)
.modifyText(text -> event.parsePAPIPlaceholders(text, player))
.toString()
);
}
if(!entry.getPlayers().isEmpty() && !hidePlayers){
event.setPlayers(entry.getPlayers(), player, playerPlaceholders, serverPlaceholders);
event.setPlayers(entry.getPlayers(), player, server);
}
if(!entry.getFavicon().isEmpty()){
String favicon = StringReplacer.replace(entry.getFavicon(), playerPlaceholders.getReplacements());
String favicon = StringReplacer.replace(entry.getFavicon(), player, server);
F fav = plugin.getFaviconHandler().getFavicon(favicon, image -> {
try{
@@ -27,8 +27,8 @@ package ch.andre601.advancedserverlist.core.file;
import ch.andre601.advancedserverlist.core.AdvancedServerList;
import ch.andre601.advancedserverlist.core.interfaces.PluginLogger;
import ch.andre601.advancedserverlist.core.profiles.profile.ProfileEntry;
import ch.andre601.advancedserverlist.core.profiles.ServerListProfile;
import ch.andre601.advancedserverlist.core.profiles.profile.ProfileEntry;
import ch.andre601.advancedserverlist.core.profiles.profile.ProfileSerializer;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
@@ -25,13 +25,16 @@
package ch.andre601.advancedserverlist.core.interfaces.core;
import ch.andre601.advancedserverlist.api.objects.GenericPlayer;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
import ch.andre601.advancedserverlist.core.AdvancedServerList;
import ch.andre601.advancedserverlist.core.interfaces.PluginLogger;
import ch.andre601.advancedserverlist.core.profiles.favicon.FaviconHandler;
import java.nio.file.Path;
import java.util.List;
public interface PluginCore<F>{
public interface PluginCore<F, PL, P extends GenericPlayer>{
void loadCommands();
@@ -54,4 +57,6 @@ public interface PluginCore<F>{
String getPlatformVersion();
String getLoader();
List<PL> createPlayers(List<String> lines, P player, GenericServer server);
}
@@ -25,18 +25,17 @@
package ch.andre601.advancedserverlist.core.interfaces.events;
import ch.andre601.advancedserverlist.api.objects.GenericPlayer;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
import ch.andre601.advancedserverlist.core.interfaces.core.PluginCore;
import ch.andre601.advancedserverlist.core.objects.CachedPlayer;
import ch.andre601.advancedserverlist.core.profiles.players.GenericPlayer;
import ch.andre601.advancedserverlist.core.profiles.replacer.placeholders.PlayerPlaceholders;
import ch.andre601.advancedserverlist.core.profiles.replacer.placeholders.ServerPlaceholders;
import net.kyori.adventure.text.Component;
import java.awt.image.BufferedImage;
import java.net.InetSocketAddress;
import java.util.List;
public interface GenericEventWrapper<P, F>{
public interface GenericEventWrapper<F, PL, P extends GenericPlayer>{
void setMaxPlayers(int maxPlayers);
@@ -46,7 +45,7 @@ public interface GenericEventWrapper<P, F>{
void setPlayerCount(String name);
void setPlayers(List<String> players, GenericPlayer<P> player, PlayerPlaceholders playerPlaceholders, ServerPlaceholders serverPlaceholders);
void setPlayers(List<String> players, P player, GenericServer server);
void setFavicon(F favicon);
@@ -64,13 +63,13 @@ public interface GenericEventWrapper<P, F>{
String getPlayerIP();
String parsePAPIPlaceholders(String text, GenericPlayer<P> player);
String parsePAPIPlaceholders(String text, P player);
String getVirtualHost();
PluginCore<F> getPlugin();
PluginCore<F, PL, P> getPlugin();
GenericPlayer<P> createPlayer(CachedPlayer player, int protocol);
P createPlayer(CachedPlayer player, int protocol);
F createFavicon(BufferedImage image) throws Exception;
@@ -25,8 +25,9 @@
package ch.andre601.advancedserverlist.core.parsing;
import ch.andre601.advancedserverlist.api.objects.GenericPlayer;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
import ch.andre601.advancedserverlist.core.profiles.replacer.StringReplacer;
import ch.andre601.advancedserverlist.core.profiles.replacer.placeholders.Placeholders;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
@@ -58,8 +59,8 @@ public class ComponentParser{
return new ComponentParser(String.join("\n", lines));
}
public ComponentParser replacements(Placeholders placeholders){
text = StringReplacer.replace(text, placeholders.getReplacements());
public ComponentParser applyReplacements(GenericPlayer player, GenericServer server){
text = StringReplacer.replace(text, player, server);
return this;
}
@@ -25,6 +25,8 @@
package ch.andre601.advancedserverlist.core.profiles;
import ch.andre601.advancedserverlist.api.objects.GenericPlayer;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
import ch.andre601.advancedserverlist.core.interfaces.PluginLogger;
import ch.andre601.advancedserverlist.core.profiles.conditions.Expression;
import ch.andre601.advancedserverlist.core.profiles.profile.ProfileEntry;
@@ -33,7 +35,6 @@ import org.spongepowered.configurate.serialize.SerializationException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
public class ServerListProfile{
@@ -57,12 +58,12 @@ public class ServerListProfile{
return priority;
}
public boolean evaluateConditions(Map<String, Object> replacements){
public boolean evalConditions(GenericPlayer player, GenericServer server){
if(expressions.isEmpty())
return true;
for(Expression expression : expressions){
if(!expression.evaluate(replacements))
if(!expression.evaluate(player, server))
return false;
}
@@ -25,10 +25,10 @@
package ch.andre601.advancedserverlist.core.profiles.conditions;
import ch.andre601.advancedserverlist.api.objects.GenericPlayer;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
import ch.andre601.advancedserverlist.core.profiles.replacer.StringReplacer;
import java.util.Map;
public class Expression{
private ExpressionResult result = ExpressionResult.VALID;
@@ -41,9 +41,9 @@ public class Expression{
resolveExpression(expression);
}
public boolean evaluate(Map<String, Object> replacements){
String newLeft = StringReplacer.replace(left, replacements).trim();
String newRight = StringReplacer.replace(right, replacements).trim();
public boolean evaluate(GenericPlayer player, GenericServer server){
String newLeft = StringReplacer.replace(left, player, server);
String newRight = StringReplacer.replace(right, player, server);
return operator.evaluate(newLeft, newRight);
}
@@ -1,72 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2022-2023 Andre_601
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
package ch.andre601.advancedserverlist.core.profiles.players;
import java.util.UUID;
public abstract class GenericPlayer<T>{
protected T player = null;
protected String name = null;
protected String version = null;
protected int protocol = -1;
protected boolean playedBefore = false;
protected boolean banned = false;
protected boolean whitelisted = false;
protected UUID uuid = null;
public T getPlayer(){
return player;
}
public String getName(){
return name;
}
public int getProtocol(){
return protocol;
}
public String getVersion(){
return version;
}
public boolean hasPlayedBefore(){
return playedBefore;
}
public boolean isBanned(){
return banned;
}
public boolean isWhitelisted(){
return whitelisted;
}
public UUID getUniqueId(){
return uuid;
}
}
@@ -38,7 +38,9 @@ import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class PlayerHandler{
@@ -25,20 +25,20 @@
package ch.andre601.advancedserverlist.core.profiles.profile;
import ch.andre601.advancedserverlist.api.objects.GenericPlayer;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
import ch.andre601.advancedserverlist.core.AdvancedServerList;
import ch.andre601.advancedserverlist.core.objects.NullBool;
import ch.andre601.advancedserverlist.core.profiles.ServerListProfile;
import ch.andre601.advancedserverlist.core.profiles.replacer.placeholders.Placeholders;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ProfileManager{
private final AdvancedServerList core;
private final Map<String, Object> replacements = new HashMap<>();
private GenericPlayer player;
private GenericServer server;
private ProfileManager(AdvancedServerList core){
this.core = core;
@@ -48,8 +48,10 @@ public class ProfileManager{
return new ProfileManager(core);
}
public ProfileManager replacements(Placeholders placeholders){
this.replacements.putAll(placeholders.getReplacements());
public ProfileManager applyReplacements(GenericPlayer player, GenericServer server){
this.player = player;
this.server = server;
return this;
}
@@ -58,7 +60,7 @@ public class ProfileManager{
if(profile.isInvalidProfile())
continue;
if(profile.evaluateConditions(replacements))
if(profile.evalConditions(player, server))
return profile;
}
@@ -25,20 +25,107 @@
package ch.andre601.advancedserverlist.core.profiles.replacer;
import java.util.Map;
import ch.andre601.advancedserverlist.api.AdvancedServerListAPI;
import ch.andre601.advancedserverlist.api.PlaceholderProvider;
import ch.andre601.advancedserverlist.api.objects.GenericPlayer;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
public class StringReplacer{
public static String replace(String input, Map<String, Object> replacements){
StringBuilder output = new StringBuilder(input);
int index;
for(Map.Entry<String, Object> entry : replacements.entrySet()){
index = 0;
while((index = output.indexOf(entry.getKey(), index)) != -1){
output.replace(index, index + entry.getKey().length(), String.valueOf(entry.getValue()));
index += String.valueOf(entry.getValue()).length();
public static String replace(String input, GenericPlayer player, GenericServer server){
char[] chars = input.toCharArray();
StringBuilder builder = new StringBuilder(input.length());
StringBuilder identifier = new StringBuilder();
StringBuilder placeholder = new StringBuilder();
AdvancedServerListAPI api = AdvancedServerListAPI.get();
for(int i = 0; i < chars.length; i++){
char c = chars[i];
char next = (i == (chars.length - 1)) ? '\0' : chars[i + 1];
if(c != '$' || i + 2 >= chars.length){
builder.append(c);
continue;
}
if(next != '{'){
if(next == '\0')
continue;
builder.append(next);
i++;
continue;
}
i++;
boolean identified = false;
boolean invalid = true;
while(++i < chars.length){
final char id = chars[i];
if(id == '}'){
invalid = false;
break;
}
if(id == ' ' && !identified){
identified = true;
continue;
}
if(identified){
placeholder.append(id);
}else{
identifier.append(id);
}
}
String identifierString = identifier.toString();
String placeholderString = placeholder.toString();
identifier.setLength(0);
placeholder.setLength(0);
if(invalid){
builder.append("${").append(identifierString);
if(identified){
builder.append(' ').append(placeholderString);
}
continue;
}
PlaceholderProvider provider = api.retrievePlaceholderProvider(identifierString);
if(provider == null){
builder.append("${").append(identifierString);
if(identified){
builder.append(' ').append(placeholderString);
}
builder.append('}');
continue;
}
String replacement = provider.parsePlaceholder(placeholderString, player, server);
if(replacement == null){
builder.append("${").append(identifierString);
if(identified){
builder.append(' ').append(placeholderString);
}
builder.append('}');
continue;
}
builder.append(replacement);
}
return output.toString();
return builder.toString();
}
}
+142
View File
@@ -0,0 +1,142 @@
# API
AdvancedServerList v2 introduced a new API that plugins can hook into to use.
As of right now is it only providing a way to add your own placeholders for it to use.
## Add dependency
Add the following to your `build.gradle` or `pom.xml` file to use the API:
=== ":simple-gradle: Gradle"
Make sure to replace `{version}` with the latest version available in the [GitHub Repository][api-repo].
```groovy
repositorories {
maven { url = 'https://jitpack.io/" }
}
dependencies {
implementation 'ch.andre601.asl-api:api:{version}'
// Optional platform dependencies
implementation 'ch.andre601.asl-api:platform-bungeecord:{version}'
implementation 'ch.andre601.asl-api:platform-paper:{version}'
implementation 'ch.andre601.asl-api:platform-spigot:{version}'
implementation 'ch.andre601.asl-api:platform-velocity:{version}'
}
```
=== ":simple-apachemaven: Maven"
Make sure to replace `{version}` with the latest version available in the [GitHub Repository][api-repo].
```xml
<repositories>
<repository>
<id>jitpack</id>
<url>https://jitpack.io/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>ch.andre601.asl-api</groupId>
<artifactId>api</artifactId>
<version>{version}</version>
</dependency>
<!-- Optional platform dependencies -->
<dependency>
<groupId>ch.andre601.asl-api</groupId>
<artifactId>platform-bungeecord</artifactId>
<version>{version}</version>
</dependency>
<dependency>
<groupId>ch.andre601.asl-api</groupId>
<artifactId>platform-paper</artifactId>
<version>{version}</version>
</dependency>
<dependency>
<groupId>ch.andre601.asl-api</groupId>
<artifactId>platform-spigot</artifactId>
<version>{version}</version>
</dependency>
<dependency>
<groupId>ch.andre601.asl-api</groupId>
<artifactId>platform-velocity</artifactId>
<version>{version}</version>
</dependency>
</dependencies>
```
[api-repo]: https://github.com/Andre601/asl-api
## Add own placeholders
To add your own placeholders will you need to do a few steps.
### 1) Get API instance
Use `AdvancedServerListAPI.get()` to retrieve an instance of the currently used AdvancedServerList API.
It will be needed at a later point.
### 2) Create a Placeholder class
Make a new class that you want to use for the placeholders and let it extend the `PlaceholderProvider` class of AdvancedServerList.
Your IDE should now tell you to implement/override some methods. Confirm this action and your class should look something alongside this:
```java
public class MyPlaceholders extends PlaceholderProvider {
public MyPlaceholders(String identifier) {
super(identifier);
}
@Override
public String parsePlaceholder(String placeholder, GenericPlayer player, GenericServer server) {
return null;
}
}
```
It's recommended to replace your generated constructor with a no-args one and set the identifier directly in the `super()`.
For example:
```java
public MyPlaceholders() {
super("myplaceholders");
}
```
The next step now would be to handle the different placeholders. These are handled in the `parsePlaceholder` method you had to override.
The `placeholder` String is whatever value was provided after the identifier in `${<identifier> <placeholder>}`. It can contain spaces.
Something to note is, that when returning `null` will AdvancedServerList understand it as an invalid placeholder and return it unchanged.
Here is a small example of the final class:
```java
public class MyPlaceholders extends PlaceholderProvider {
public MyPlaceholders() {
super("myplaceholders");
}
@Override
public String parsePlaceholder(String placeholder, GenericPlayer player, GenericServer server) {
if(placeholder.equals("hello"))
return "Hi!";
return null;
}
}
```
### 3) Register the placeholder class
All that is left to do now is to register your class as a new PlaceholderProvider instance. To do this, get the API instance you retrieved earlier and use `addPlaceholderProvider` with a new instance of your class.
Example:
```java
AdvancedServerListAPI api = AdvancedServerListAPI.get();
api.addPlaceholderProvider(new MyPlaceholders());
```
Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

+8
View File
@@ -0,0 +1,8 @@
.md-header__button.md-logo img {
height: 2.5rem;
}
.md-header__button.md-logo {
padding-right: unset;
padding-left: unset;
}
+149
View File
@@ -0,0 +1,149 @@
## About
!!! warning "The below examples may only work in v1.10.0 or newer!"
This page lists some examples you may want to use for your proxy or server.
Feel free to suggest additional examples on my [Discord Server](https://discord.gg/6dazXp6) in the `#advancedserverlist` channel.
## Table of Contents
- [Versions](#versions)
- [Different List for outdated Clients](#different-list-for-outdated-clients)
- [Different MOTD for < 1.16](#different-motd-for-116)
- [Spigot/PaperMC](#spigotpapermc)
- [Different profile for banned Player](#different-profile-for-banned-player)
- [Other](#other)
- [Different profile for different host](#different-profile-for-different-host)
- [Different profile for known player](#different-profile-for-known-player)
- [Random MOTD but same hover](#random-motd-but-same-hover)
----
## Versions
Some examples about version-related things.
### Different List for outdated Clients
You may want to display a separate MOTD or text for incompatible client versions.
This example here shows a separate MOTD and player count message for when the player's client version is older than what the server supports.
```yaml
priority: 1
# Display this profile, if the version of the player is below 760 (1.19.1)
conditions:
- '${player protocol} < 760'
motd:
- <red>You are using an outdated client!
- <red>Please update to 1.19.1 to join.
playerCount:
text: '<red>Outdated Client!'
```
### Different MOTD for < 1.16
This profile would display a MOTD without HEX colours if the player's version is below 735 (1.16).
```yaml
priority: 1
# Display this profile, if the version of the player is below 735 (1.16)
conditions:
- '${player protocol} < 735'
motd:
- <grey>Welcome to <aqua>YourServer.com</aqua>!
- <grey>Enjoy your stay.
```
----
## Spigot/PaperMC
Examples that can be used with the Spigot or PaperMC version.
### Different profile for banned Player
!!! warning "Requires a cached player to work reliably."
Displays a separate profile for when the player has been banned from the server.
```yaml
priority: 1
conditions:
- '${player isBanned} = true'
motd:
- <red>You have been <bold>BANNED</bold>!
- <red>Go away.
# Don't show the player count to the banned player.
playerCount:
hidePlayers: true
```
----
## Other
Some misc examples.
### Different profile for different host
Display a different profile when the playing pings a specific domain/IP.
```yaml
priority: 1
conditions:
- '${server host} = other.example.com'
motd:
- <grey>Please use <aqua>mc.example.com
- <grey>to join our server.
```
### Different profile for known player
Display a different profile, if the player pinging the server is "known" by AdvancedServerList (Has joined before with the same IP).
```yaml
priority: 1
conditions:
- `${player name} != Anonymous` # "Anonymous" should be replaced with whatever you use in 'unknown_player'
motd:
- <grey>Hello there <aqua>${player name}</aqua>!
- <grey>It's nice to see you again.
playerCount:
hover:
- '<grey>Welcome back <aqua>${player name}</aqua>!'
- '<grey>'
- '<grey>Come and join <aqua>${server playersOnline}'
- '<aqua>other players</aqua> <grey>on the Server!'
```
### Random MOTD but same hover
v1.10.0 of AdvancedServerList introduced an option called `profiles`. It allows you to create multiple variants of an MOTD, playercount, etc. while also supporting the normal (global) options as a fallback.
The following example will create a profile that has a randomized MOTD, but the same hover for both:
```yaml
priority: 1
profiles:
- motd:
- 'A randomized MOTD.'
- 'Lines change, but hover is the same.'
- motd: ['Different Syntax.', 'May be more readable.']
playerCount:
hover:
- 'This player count hover always'
- 'stays the same, no matter what'
- 'MOTD is being used here.'
```
+34
View File
@@ -0,0 +1,34 @@
# AdvancedServerList Wiki
Welcome to the Wiki of AdvancedServerList!
On this site can you find the latest documentation for the plugin, including some useful examples.
If you're new to the plugin is it recommended to check out the [Profiles page](./profiles) for a quick start on how to use this plugin.
## Platforms
AdvancedServerList supports the following platforms:
<a href="https://www.spigotmc.org" target="_blank">
<img src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@2/assets/minimal/supported/spigot_vector.svg" width="64" alt="platform-spigot" title="Tested on Spigot">
</a>
<a href="https://papermc.io" target="_blank">
<img src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@2/assets/minimal/supported/paper_vector.svg" width="64" alt="platform-paper" title="Tested on Paper">
</a>
<a href="https://www.spigotmc.org" target="_blank">
<img src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@2/assets/minimal/supported/bungeecord_vector.svg" width="64" alt="platform-bungeecord" title="Tested on BungeeCord">
</a>
<a href="https://www.papermc.io" target="_blank">
<img src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@2/assets/minimal/supported/waterfall_vector.svg" width="64" alt="platform-waterfall" title="Tested on Waterfall">
</a>
<a href="https://velocitypowered.com" target="_blank">
<img src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@2/assets/minimal/supported/velocity_vector.svg" width="64" alt="platform-velocity" title="Tested on Velocity">
</a>
## Pages
- [Profiles](./profiles)
- [Formatting](./profiles/formatting)
- [Placeholders](./profiles/placeholders)
- [API](./api)
- [Examples](./examples)
+21
View File
@@ -0,0 +1,21 @@
# Formatting
All text options with exception of [`Conditions`](../#conditions) allow the usage of formatting options using [MiniMessage].
## Unsupported options
The following options are **not** supported, no matter what option they are used in:
- Hover Actions (Show text, Show Advancement, etc)
- Click Actions (Run command, Suggest command, etc.)
- Custom Fonts (May work if player already has the resource pack loaded)
## Colors
Normal text colours such as `<aqua>` or `<red>` can be used in all text options.
## HEX Colours
24-Bit HEX colours such as `<#ffffff>` can be used in the [`Motd`](../#motd) option on 1.16+ servers/proxies.
[MiniMessage]: https://docs.adventure.kyori.net/minimessage/index.html
+157
View File
@@ -0,0 +1,157 @@
# Profiles
AdvancedServerList allows the creation of multiple profiles.
A profile is a single YAML file located in the plugin's `profiles` directory containing multiple settings including [Conditions](#conditions) and [Priority](#priority).
!!! info "Important"
In order for a profile to be considered "valid" by AdvancedServerList will it need to meet the following conditions:
- Have a [`Priority`](#priority) set to a valid, whole number (i.e. `1`)
- Have **at least one** of the following options set:
- [`Profiles`](#profiles) with at least one entry containing one of the below option
- [`Motd`](#motd) set with at least one line of text
- [`Favicon`](#favicon) set with a non-empty String
- [`HidePlayers`](#hideplayers) set to `true`
- [`Hover`](#hover) set with at least one line of text
- [`Text`](#text) set with a non-empty String
## Priority
The priority option determines the order in which the profiles are checked by AdvancedServerList, starting with the highest number.
It will go through each file until it finds one with [`conditions`](#conditions) returning true (Default if no conditions are set).
This means that a profile with no conditions and a priority of `1` will be used before a profile with a condition and priority `0` even if the player is meeting the condition.
## Conditions
A list of conditions can be set that need to be met in order to have this profile shown to the player.
[Placeholders](./formatting#placeholders) can be used to further customize the conditions (PlaceholderAPI placeholders are **not** supported).
Only when **all** conditions defined return true will the profile be displayed.
You can remove this option, or set it to an empty list (`conditions: []`) to always return true.
### Operants
The following operants are available and can be used in the conditions.
!!! warning "Only one operant can be used per condition!"
| Operant | Description |
| ------- | ------------------------------------------------------------------ |
| `<` | Checks if the left value is less than the right one.\* |
| `<=` | Checks if the left value is less than or equal to the right one.\* |
| `>` | Checks if the left value is more than the right one.\* |
| `>=` | Checks if the left value is more than or equal to the right one.\* |
| `=` | Checks if the left value is equal to the right one. |
| `!=` | Checks if the left value is not equal to the right one. |
\* In the case of the provided value not being a number will the plugin instead use the text length to compare with.
## Profiles
!!! info "Available since v1.10.0"
The profiles option allows you to add multiple combinations of all the other options (With the exception of [`Priority`](#priority) and [`Conditions`](#conditions)) to have randomized MOTDs, player counts, etc.
If an option is not present in an entry will AdvancedServerList try to use one defined in the file or use whatever default value would be for that option.
As an example:
```yaml
priority: 1
profiles:
- motd:
- Line 1
- Line 2
playerCount:
text: 'Awesome!'
- playerCount:
text: 'Also Awesome'
motd:
- Line A
- Line B
```
...the above file would randomly select between a MOTD saying `Line 1\nLine 2` and a player count saying `Awesome!` or a MOTD saying `Line A\nLine B` while the player count says `Also Awesome`
## Motds
!!! warning "Only available in v1.9.0"
This option allows to create multiple MOTDs that AdvancedServerList should randomly select from.
Due to the structure of this option will you need to use `|-` to have multi-line MOTDs.
Example:
```yaml
motds:
- |-
Line 1
Line 2
- |-
Line A
Line B
```
## Motd
The motd option allows to set up to two lines to be displayed in an MOTD.
Normal colour and formatting codes such as `<aqua>` or `<bold>` are supported. On 1.16 and newer can you also use HEX colours using either `<#rrggbb>` or `<color:#rrggbb>`.
If you want to display multiple MOTDs will you need to use the [`Profiles` option](#profiles)
## Favicon
The favicon option allows you to customize the favicon and display one or multiple different images.
This option currently supports the following values:
- A URL pointing to a `64x64` PNG image.
- A name with `.png` extension that matches a PNG file in the `favicons` folder.
- `${player uuid}` (or alternatively `${player name}`) to display the head of the player. The UUID/Name resolving is handled by https://mc-heads.net
Please note that AdvancedServerList will rescale the image to be 64x64 pixels, so be sure to provide images at that particular scale.
## PlayerCount
The `playerCount` option contains multiple different options all about the Player count itself.
### HidePlayers
Boolean option to set whether AdvancedServerList should hide the player count or not. When set to `true` will the player count be replaced with `???`.
Additionally will the [`Text`](#text) and [`Hover`](#hover) option be ignored.
### Hover
This option allows to override the hover text usually displaying the players on the server when hovering over the player count.
You can either remove this option or set to an empty list (`hover: []`) to not override the hover.
### Text
This option allows to override the text usually displaying the online players and total players that can join.
Note that AdvancedServerList will not add the `<online>/<max>` text to the player count. Instead will you need to use [`${server playersOnline}`](./placeholders#server) and [`${server playersMax}`](./placeholders#server) respectively.
!!! info "Note"
This feature works by changing the "outdated server" message followed by altering the protocol version of the server.
Due to this will your server appear as "outdated" to the client (Have the ping icon crossed out). This is nothing that can be changed unfortunately.
To not override the player count, remove this option or set it to an empty String (`text: ''`).
### ExtraPlayers
Contains options to modify how the `<max>` number in the player count should look like.
!!! warning "Using this option will modify the `${server playersMax}` placeholder (Except in conditions)"
#### Enabled
Boolean option to set whether the extra players feature should be used or not.
When set to `true` will the max amount of players be modified by taking the current amount of online players, add [`Amount`](#amount) more to it and use it.
#### Amount
Sets the number to add to the current online players to then use as the new max players count.
As an example, setting this to `1` while `10` players are online will display `11`, while `-1` would display `9`.
+52
View File
@@ -0,0 +1,52 @@
# Placeholders
AdvancedServerList provides a set of pre-made placeholders using the `${<identifier> <placeholder>}` format adobted from BungeeTabListPlus.
It also has built-in [PlaceholderAPI support](#placeholderapi) for Spigot and Paper Servers and since v2 can even allow you to [add your own placeholders](#custom-placeholders) by using its [API](../../api).
## Built-in Placeholders
The following placeholders are available in AdvancedServerList itself. Please note that not all placeholders are available on all platforms.
### Player Placeholders
These placeholders use the player who pinged the server, to return values. They may require the player to be cached in order to work.
| Placeholder | Description | Platforms | Cached Player required?\* |
| --------------------------- | --------------------------------------------------------------- | ------------ | ------------------------ |
| `${player name}` | The name of the player. | All | Yes\*\* |
| `${player protocol}` | The protocol version of the player. | All | No |
| `${player uuid}` | The UUID of the player. | All | Yes\*\*\* |
| `${player version}` | The protocol version of the player as readable MC version. | Velocity | No |
| `${player hasPlayedBefore}` | Boolean for whether the player has played on the server before. | Spigot/Paper | Yes |
| `${player isBanned}` | Boolean for whether the player has been banned from the server. | Spigot/Paper | Yes |
| `${player isWhitelisted}` | Boolean for whether the player is whitelisted on the server. | Spigot/Paper | Yes |
\*Whether this placeholder requires the player to have joined before while AdvancedServerList was running. When `disable_cache` is enabled will these placeholders not work.
\*\*Will default to whatever name has been provided in the config.yml's `unknown_player` option, when the player isn't cached yet.
\*\*\*Will default to whatever name has been provided in the config.yml's `unknown_player_uuid` option, when the player isn't cached yet.
### Server
These placeholders use values given by the server/proxy AdvancedServerList runs on.
| Placeholder | Description |
| ------------------------- | -------------------------------------------------------- |
| `${server playersOnline}` | The number of players online on this server. |
| `${server playersMax}` | The total number of players that can join this server.\* |
| `${server host}` | The domain/IP the player pinged. |
\*This placeholder is affected by the [`Amount` option](../#amount) in a server list profile, with the exception being when used in [`Conditions`](../#conditions).
## PlaceholderAPI
The Spigot and Paper version of AdvancedServerList allow the usage of *any* placeholders provided by PlaceholderAPI by using the `%<identifier>_<values>%` placeholder format.
Depending on the placeholder used is a cached player required (i.e. `%player_name%`). AdvancedServerList will try to get a OfflinePlayer instance based on the cached UUID from the server to manage this.
!!! warning "PlaceholderAPI placeholders can NOT be used in Conditions!"
## Custom Placeholders
Since version 2 of AdvancedServerList are developers able to provide their own placeholders to be used in a server list profile.
The format follows the same one as the [built-in placeholders](#built-in-placeholders), meaning it is `${<identifier> <placeholder>}`.
If you're a developer and want to integrate your own placeholders into AdvancedServerList, read about it [here](../../api).
+492
View File
@@ -0,0 +1,492 @@
# +--------------------------------------------------------------------------------------------------------+
# | |
# | This is the main file used by MkDocs to build the pages. |
# | It contains a lot of information and settings for you to read and use. |
# | Comments may contain "Read More" URLs to more in-depth documentation about the option for you to read. |
# | |
# | You can check out https://www.mkdocs.org/user-guide/configuration/ for a more detailed explanation of |
# | all the options MkDocs offers by default. |
# | |
# +------------------------------------------------- NOTE -------------------------------------------------+
# | |
# | Some of the options listed here are only available through the usage of Material for MkDocs. |
# | Those options will usually have a link to the docs of this Theme and also mention "Material" as name. |
# | The actual name of the theme is "Material for MkDocs" and "Material" is used for simplicity reasons. |
# | |
# +--------------------------------------------------------------------------------------------------------+
# +--------------------------------------------------------------------------------------------------------+
# | |
# | Main Page Settings for MkDocs. |
# | Those settings are site name, site description, Site author and also Site URL (Canonical URL) |
# | |
# | Read More: |
# | - https://www.mkdocs.org/user-guide/configuration/#site_name |
# | - https://www.mkdocs.org/user-guide/configuration/#site_description |
# | - https://www.mkdocs.org/user-guide/configuration/#site_author |
# | - https://www.mkdocs.org/user-guide/configuration/#site_url |
# | |
# +--------------------------------------------------------------------------------------------------------+
site_name: AdvancedServerList Wiki
site_description: 'Wiki for the AdvancedServerList plugin'
site_author: 'Andre_601'
site_url: 'https://www.andre601.ch/AdvancedServerList' # Uncomment to set a canonical URL
# +--------------------------------------------------------------------------------------------------------+
# | |
# | This setting allows you to define your own Copyright notice. |
# | The text is treated as HTML code so you can use things like <a> tags or &copy; to display the |
# | Copyright icon. |
# | |
# | Where or IF the Copyright is displayed depends on the theme you use. |
# | |
# | Read More: |
# | - https://www.mkdocs.org/user-guide/configuration/#copyright |
# | |
# +--------------------------------------------------------------------------------------------------------+
copyright: |
&copy; Andre_601
# +--------------------------------------------------------------------------------------------------------+
# | |
# | The base folder to use. |
# | Any Markdown files you put into this folder will be turned into a static HTML page once you build or |
# | publish your page. |
# | |
# | It is also used as the base directory for other settings like the "extra_css" or "extra_javascript" |
# | option. |
# | |
# +--------------------------------------------------------------------------------------------------------+
docs_dir: docs/
# +--------------------------------------------------------------------------------------------------------+
# | |
# | These options allow to define a Repository to link to. |
# | The result will, depending on the theme, be a link somewhere shown on the page that links to the |
# | Repository with the specified repo_name. |
# | |
# | This will also enable a "edit" button on the page itself that allows the direct editing of the page. |
# | You can disable this by setting "edit_uri" to an empty String. |
# | |
# | Read More: |
# | - https://www.mkdocs.org/user-guide/configuration/#repo_name |
# | - https://www.mkdocs.org/user-guide/configuration/#repo_url |
# | - https://www.mkdocs.org/user-guide/configuration/#edit_uri |
# | |
# +--------------------------------------------------------------------------------------------------------+
repo_name: Andre601/AdvancedServerList
repo_url: https://github.com/Andre601/AdvancedServerList
#edit_uri: tree/master/docs # Uncomment to define a different URI/URL for the "edit" option
# +--------------------------------------------------------------------------------------------------------+
# | |
# | The "nav" option is where you define the navigation to show in MkDocs. |
# | |
# | Depending on the theme you use will the resulting Navigation look different. |
# | |
# | You can set different types of navigations. Either just the path, the path with a separate title or |
# | an external URL. |
# | |
# | Read More: |
# | - https://www.mkdocs.org/user-guide/configuration/#documentation-layout |
# | |
# +--------------------------------------------------------------------------------------------------------+
nav:
- Home: index.md
- Profiles:
- profiles/index.md
- Formatting: profiles/formatting.md
- Placeholders: profiles/placeholders.md
- API: api.md
- Examples: examples.md
# +--------------------------------------------------------------------------------------------------------+
# | |
# | The "theme" section allows you to define what theme to use. |
# | It is also used for theme-specific options, but also for advanced stuff such as theme-extensions, if |
# | the theme actually supports it. |
# | |
# | Read More: |
# | - https://www.mkdocs.org/user-guide/configuration/#theme |
# | |
# +--------------------------------------------------------------------------------------------------------+
theme:
# +------------------------------------------------------------------------------------------------------+
# | |
# | The "name" option is where you define the theme to use. |
# | |
# | Note that not all themes are included by default and will require you to install them first. |
# | The Material theme is one of them. See the "Read More" link for instructions on how to install it. |
# | |
# | Read More: |
# | - https://squidfunk.github.io/mkdocs-material/getting-started/ |
# | |
# +------------------------------------------------------------------------------------------------------+
name: 'material'
# +------------------------------------------------------------------------------------------------------+
# | |
# | The Material theme allows "theme-extsnions", meaning that you can override parts of it by either |
# | overriding a particular file, or only parts (blocks) of it. |
# | |
# | If you want to override parts of Material, uncomment the "custom_dir" option below and set the |
# | folder (relative to the mkdocs.yml file) where your theme extensions will be located at. |
# | |
# | Read More: |
# | - https://www.mkdocs.org/user-guide/configuration/#custom_dir |
# | - https://squidfunk.github.io/mkdocs-material/customization/#extending-the-theme |
# | |
# +------------------------------------------------------------------------------------------------------+
#custom_dir: 'theme'
# +------------------------------------------------------------------------------------------------------+
# | |
# | The "favicon" option allows you to set your own image/icon to use in the browser-tab. |
# | |
# | Pretty much all image types are supported, but it's recommended to use a PNG, SVG or ICO image for |
# | the favicon. |
# | |
# | The directory is relative to the "docs_dir". |
# | |
# | Example: Having a favicon.png in docs/assets/images will result in the "favicon" setting showing |
# | 'assets/images/favicon.png' |
# | |
# | Read More: |
# | - https://squidfunk.github.io/mkdocs-material/setup/changing-the-logo-and-icons/#favicon |
# | |
# +------------------------------------------------------------------------------------------------------+
favicon: 'assets/images/favicon.png'
logo: 'assets/images/favicon.png'
# +------------------------------------------------------------------------------------------------------+
# | |
# | The "palette" section is a Material option and allows you to define specific style options such as |
# | Color-Scheme, and primary and secondary Color. |
# | |
# | You can also define multiple palettes that can have different Color Schemses and primary and/or |
# | secondary Colors. |
# | |
# | Read More: |
# | - https://squidfunk.github.io/mkdocs-material/setup/changing-the-colors/ |
# | - https://squidfunk.github.io/mkdocs-material/setup/changing-the-colors/#color-palette-toggle |
# | |
# +------------------------------------------------------------------------------------------------------+
palette:
# +----------------------------------------------------------------------------------------------------+
# | |
# | The "scheme" option is used to define the Color Scheme used by Material. |
# | |
# | Material offers a "default" and a "slate" scheme. "default" is obviously the default (bright) |
# | Color scheme while "slate" is the native dark theme from Material. |
# | |
# | Read More: |
# | - https://squidfunk.github.io/mkdocs-material/setup/changing-the-colors/#color-scheme |
# | |
# +----------------------------------------------------------------------------------------------------+
scheme: 'slate'
# +----------------------------------------------------------------------------------------------------+
# | |
# | "primary" is used to set the main color of the Material Theme. |
# | |
# | The primary color is used on the top banner of the page but also for things like the link color. |
# | |
# | Read More: |
# | - https://squidfunk.github.io/mkdocs-material/setup/changing-the-colors/#primary-color |
# | |
# +----------------------------------------------------------------------------------------------------+
primary: 'indigo'
# +----------------------------------------------------------------------------------------------------+
# | |
# | The "accent" is used for moments such as hovering over links. |
# | |
# | Read More: |
# | - https://squidfunk.github.io/mkdocs-material/setup/changing-the-colors/#accent-color |
# | |
# +----------------------------------------------------------------------------------------------------+
accent: 'indigo'
# +------------------------------------------------------------------------------------------------------+
# | |
# | With the "font" option can you set a different font to use. |
# | |
# | Material supports all Google fonts, but you can also define your own ones if you choose so. |
# | |
# | The "text" option is used for the regular font while "code" is used for code blocks, inline code and |
# | similar. |
# | |
# | Read More: |
# | - https://squidfunk.github.io/mkdocs-material/setup/changing-the-fonts/ |
# | |
# +------------------------------------------------------------------------------------------------------+
#font:
# text: 'Roboto'
# code: 'Roboto Mono'
# +------------------------------------------------------------------------------------------------------+
# | |
# | Material suppors more than 40 different languages which you can set using the "language" option |
# | below. |
# | |
# | The default language is "en" (English). |
# | |
# | You can also enable/set a "selector" to allow switching between languages. |
# | See the "alternate" option in the "extra" section below for more information on this topic. |
# | |
# | Read More: |
# | - https://squidfunk.github.io/mkdocs-material/setup/changing-the-language/ |
# | |
# +------------------------------------------------------------------------------------------------------+
#language: 'en'
# +------------------------------------------------------------------------------------------------------+
# | |
# | The "direction" option is commonly used together with the "language" option. |
# | |
# | It allows you to change the text direction from the default left-to-right (ltr) to right-to-left |
# | (rtl) which is used in certain languages. |
# | |
# | Read More: |
# | - https://squidfunk.github.io/mkdocs-material/setup/changing-the-language/#directionality |
# | |
# +------------------------------------------------------------------------------------------------------+
#direction: 'ltr'
# +------------------------------------------------------------------------------------------------------+
# | |
# | The "features" option allows you to enable specific features of Material, by adding them to the |
# | list. |
# | |
# | Features are in the format <category>.<name>. As an example, the feature to enable tabs is called |
# | navigation.tabs. |
# | |
# | The list below contains all known features of Material. |
# | |
# | Features marked with a * are currently Insiders-only. (Last update: 11th December 2021) |
# | https://squidfunk.github.io/mkdocs-material/insiders/ |
# | |
# | Read More: |
# | - https://squidfunk.github.io/mkdocs-material/setup/setting-up-navigation/ |
# | |
# +------------------------------------------------------------------------------------------------------+
features:
# Announce
#
#- announce.dismiss # Adds a "X" button to dismiss a news banner/mark it as read.*
# Header
#
#- header.autohide # Hide header when user scrolls past a specific point.
# Navigation:
#
#- navigation.expand # Expand all collapsable sections.
#- navigation.instant # Instant loading pages.
- navigation.indexes # Attach pages directly to Sections. Incompatible with "toc.integrate"
#- navigation.sections # Render top sections as groups.
- navigation.tabs # Render top sections as tabs at the top.
- navigation.tabs.sticky # Tabs won't disappear when scrolling down. Requires "navigation.tabs".
#- navigation.top # Adds a "Back to top" that is shown when scrolling up.
#- navigation.tracking # Updates the url with highlighted section anchor.
# Search
#
#- search.highlight # Search will highlight the searched word(s) on the page.*
#- search.share # Adds an option to share a search query link.*
#- search.suggest # Search will suggest the likeliest completion for a word.*
# Table of Contents
#
#- toc.integrate # Include the TOC sections in the left navugation.
# +------------------------------------------------------------------------------------------------------+
# | |
# | The "icon" section allows you to define a icon to use for the logo and/or repository. |
# | |
# | To use already available icons will you need to set the right path for it, depending on which you |
# | want to use. |
# | |
# | Available icons: |
# | - FontAwesome |
# | - Brands: fontawesome/brands/... (https://fontawesome.com/icons?d=gallery&p=2&s=brands&m=free) |
# | - Regular: fontawesome/regular/... (https://fontawesome.com/icons?d=gallery&p=2&s=regular&m=free) |
# | - Solid: fontawesome/solid/... (https://fontawesome.com/icons?d=gallery&p=2&s=solid&m=free) |
# | |
# | - Material Design Icons: material/... (https://materialdesignicons.com/) |
# | |
# | - Octicons: octicons/... (https://primer.style/octicons/) |
# | |
# | You can also define your own Image for the logo. To do that, remove the "logo" option from "icon" |
# | instead add a "logo" option on the same level as the "icon" one, where you then set the path |
# | (relative to the "docs_dir") to the icon to use. Supported are all images types, including SVG. |
# | |
# | Read More: |
# | - https://squidfunk.github.io/mkdocs-material/setup/changing-the-logo-and-icons/#logo |
# | |
# +------------------------------------------------------------------------------------------------------+
icon:
repo: 'octicons/mark-github-16'
# +------------------------------------------------------------------------------------------------------+
# | |
# | The "admonition" option allows you to set a different icon for each admonition type. |
# | |
# | This is currently a Insiders-only feature. (Last update: 7th October 2021) |
# | https://squidfunk.github.io/mkdocs-material/insiders/ |
# | |
# | Supported are all bundled icons: |
# | - FontAwesome |
# | - Brands: fontawesome/brands/... (https://fontawesome.com/icons?d=gallery&p=2&s=brands&m=free) |
# | - Regular: fontawesome/regular/... (https://fontawesome.com/icons?d=gallery&p=2&s=regular&m=free) |
# | - Solid: fontawesome/solid/... (https://fontawesome.com/icons?d=gallery&p=2&s=solid&m=free) |
# | |
# | - Material Design Icons: material/... (https://materialdesignicons.com/) |
# | |
# | - Octicons: octicons/... (https://primer.style/octicons/) |
# | |
# | You can also create and use your own icons. See the documentation for more information. |
# | |
# | Read More: |
# | - https://squidfunk.github.io/mkdocs-material/reference/admonitions/#changing-the-icons |
# | |
# +------------------------------------------------------------------------------------------------------+
admonition:
note: 'octicons/tag-16'
abstract: 'octicons/checklist-16'
info: 'octicons/info-16'
tip: 'octicons/squirrel-16'
success: 'octicons/check-16'
question: 'octicons/question-16'
warning: 'octicons/alert-16'
failure: 'octicons/x-circle-16'
danger: 'octicons/zap-16'
bug: 'octicons/bug-16'
example: 'octicons/beaker-16'
quote: 'octicons/quote-16'
# +--------------------------------------------------------------------------------------------------------+
# | |
# | With the "extra_css" option can you add your own (S)CSS files to enhance the documentation. |
# | |
# | The path to the file is relative to the "docs_dir". |
# | |
# | Read More: |
# | - https://www.mkdocs.org/user-guide/configuration/#extra_css |
# | |
# +--------------------------------------------------------------------------------------------------------+
extra_css:
- assets/stylesheets/custom.css
# +--------------------------------------------------------------------------------------------------------+
# | |
# | Similar to the "extra_css" option does the "extra_javascript" option allow you to set custom JS files |
# | to add extra featurues. |
# | |
# | The path to the file is relative to the "docs_dir". |
# | |
# | Read More: |
# | - https://www.mkdocs.org/user-guide/configuration/#extra_javascript |
# | |
# +--------------------------------------------------------------------------------------------------------+
#extra_javascript:
# +--------------------------------------------------------------------------------------------------------+
# | |
# | The "extra" section contains pretty much anything you want, as long as it is a valid key-value pair. |
# | |
# | Material uses this section for different custom settings that wouldn't fit in the theme section. |
# | |
# | Read More: |
# | - https://www.mkdocs.org/user-guide/configuration/#extra |
# | |
# +--------------------------------------------------------------------------------------------------------+
extra:
# +------------------------------------------------------------------------------------------------------+
# | |
# | The social section allows you to set a list of entries which would be displayed in the footer of the |
# | page. |
# | |
# | Each entry has the exact same options: |
# | - icon: Path to the SVG icon to use. See "icon" section for available icon sets. |
# | - link: URL to which the icon should link. |
# | - name: Optional Name that would be displayed as title on hover. |
# | |
# | Read More: |
# | - https://squidfunk.github.io/mkdocs-material/setup/setting-up-the-footer/#social-links |
# | |
# +------------------------------------------------------------------------------------------------------+
social:
- icon: 'fontawesome/brands/github'
link: 'https://github.com/Andre601/asl-wiki'
# +------------------------------------------------------------------------------------------------------+
# | |
# | Allows you to hide the "Made with Material for MkDocs" text in the footer of the pages by setting |
# | this to "true". |
# | |
# | Read More: |
# | - https://squidfunk.github.io/mkdocs-material/setup/setting-up-the-footer/#generator-notice |
# | |
# +------------------------------------------------------------------------------------------------------+
#generator: true
# +------------------------------------------------------------------------------------------------------+
# | |
# | The "manifest" option allows you to define a .manifest file to use. |
# | |
# | A .manifest file makes the doc act like a web-application and tells it how to behave when installed. |
# | |
# | Read More: |
# | - https://squidfunk.github.io/mkdocs-material/reference/meta-tags/#adding-a-web-app-manifest |
# | |
# +------------------------------------------------------------------------------------------------------+
#manifest: manifest.webmanifest
# +------------------------------------------------------------------------------------------------------+
# | |
# | The "alternate" option can be used to create a selector to switch languages. |
# | |
# | Using this requires you to create a specific, more complicated MkDocs setup. |
# | |
# | A Setup Guide for multi-language docs can be found here: |
# | https://github.com/squidfunk/mkdocs-material/discussions/2346 |
# | |
# | Read More: |
# | - https://squidfunk.github.io/mkdocs-material/setup/changing-the-language/#site-language-selector |
# | |
# +------------------------------------------------------------------------------------------------------+
#alternate:
# +--------------------------------------------------------------------------------------------------------+
# | |
# | MkDocs allows the usage of Markdown extensions which can do various things. |
# | |
# | Material includes the pymdownx extension which provides a lot of useful features to use. |
# | |
# | Note that some extensions may use specific settings that you need to set. |
# | Please check out the official documentation of PyMdownx for more information: |
# | https://facelessuser.github.io/pymdown-extensions/ |
# | |
# | Material already provides required CSS and JS values for the PyMdownX Extensions, which means you do |
# | not need to set them up yourself. |
# | |
# | Read More: |
# | - https://www.mkdocs.org/user-guide/configuration/#markdown_extensions |
# | |
# +--------------------------------------------------------------------------------------------------------+
markdown_extensions:
- markdown.extensions.admonition:
- markdown.extensions.toc:
permalink: true
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
- pymdownx.highlight:
- pymdownx.magiclink:
- pymdownx.superfences:
- pymdownx.tabbed:
alternate_style: true
+1 -1
View File
@@ -46,7 +46,7 @@
<repositories>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public</url>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository>
<id>placeholderapi-repo</id>
@@ -25,22 +25,23 @@
package ch.andre601.advancedserverlist.paper;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
import ch.andre601.advancedserverlist.core.AdvancedServerList;
import ch.andre601.advancedserverlist.core.interfaces.PluginLogger;
import ch.andre601.advancedserverlist.core.interfaces.core.ServerCore;
import ch.andre601.advancedserverlist.core.interfaces.core.PluginCore;
import ch.andre601.advancedserverlist.core.parsing.ComponentParser;
import ch.andre601.advancedserverlist.core.profiles.favicon.FaviconHandler;
import ch.andre601.advancedserverlist.core.profiles.replacer.placeholders.Placeholders;
import ch.andre601.advancedserverlist.paper.commands.CmdAdvancedServerList;
import ch.andre601.advancedserverlist.paper.events.JoinEvent;
import ch.andre601.advancedserverlist.paper.events.PingEvent;
import ch.andre601.advancedserverlist.paper.logging.PaperLogger;
import ch.andre601.advancedserverlist.paper.objects.PaperPlayer;
import ch.andre601.advancedserverlist.paper.objects.PlayerPlaceholders;
import com.destroystokyo.paper.profile.PlayerProfile;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.CachedServerIcon;
@@ -50,7 +51,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class PaperCore extends JavaPlugin implements ServerCore<CachedServerIcon, PlayerProfile, OfflinePlayer>{
public class PaperCore extends JavaPlugin implements PluginCore<CachedServerIcon, PlayerProfile, PaperPlayer>{
private final PluginLogger logger = new PaperLogger(getLogger());
@@ -151,16 +152,15 @@ public class PaperCore extends JavaPlugin implements ServerCore<CachedServerIcon
}
@Override
public List<PlayerProfile> createPlayers(List<String> lines, OfflinePlayer player, Placeholders... placeholders){
public List<PlayerProfile> createPlayers(List<String> lines, PaperPlayer player, GenericServer server){
List<PlayerProfile> players = new ArrayList<>(lines.size());
for(String line : lines){
String parsed = ComponentParser.text(line)
.replacements(placeholders[0])
.replacements(placeholders[1])
.applyReplacements(player, server)
.modifyText(text -> {
if(getServer().getPluginManager().isPluginEnabled("PlaceholderAPI"))
return PlaceholderAPI.setPlaceholders(player, text);
return PlaceholderAPI.setPlaceholders(player.getPlayer(), text);
return text;
})
@@ -173,7 +173,7 @@ public class PaperCore extends JavaPlugin implements ServerCore<CachedServerIcon
}
private void enable(){
this.core = new AdvancedServerList(this);
this.core = new AdvancedServerList(this, new PlayerPlaceholders());
}
private void printSpigotWarning(){
@@ -25,15 +25,14 @@
package ch.andre601.advancedserverlist.paper.events;
import ch.andre601.advancedserverlist.core.interfaces.events.GenericEventWrapper;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
import ch.andre601.advancedserverlist.core.interfaces.core.PluginCore;
import ch.andre601.advancedserverlist.core.interfaces.events.GenericEventWrapper;
import ch.andre601.advancedserverlist.core.objects.CachedPlayer;
import ch.andre601.advancedserverlist.core.profiles.players.GenericPlayer;
import ch.andre601.advancedserverlist.core.profiles.replacer.placeholders.PlayerPlaceholders;
import ch.andre601.advancedserverlist.core.profiles.replacer.placeholders.ServerPlaceholders;
import ch.andre601.advancedserverlist.paper.PaperCore;
import ch.andre601.advancedserverlist.paper.PaperPlayer;
import ch.andre601.advancedserverlist.paper.objects.PaperPlayer;
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
import com.destroystokyo.paper.profile.PlayerProfile;
import me.clip.placeholderapi.PlaceholderAPI;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
@@ -43,7 +42,7 @@ import org.bukkit.util.CachedServerIcon;
import java.awt.image.BufferedImage;
import java.util.List;
public class PaperEventWrapper implements GenericEventWrapper<OfflinePlayer, CachedServerIcon>{
public class PaperEventWrapper implements GenericEventWrapper<CachedServerIcon, PlayerProfile, PaperPlayer>{
private final PaperCore plugin;
private final PaperServerListPingEvent event;
@@ -75,11 +74,11 @@ public class PaperEventWrapper implements GenericEventWrapper<OfflinePlayer, Cac
}
@Override
public void setPlayers(List<String> players, GenericPlayer<OfflinePlayer> player, PlayerPlaceholders playerPlaceholders, ServerPlaceholders serverPlaceholders){
public void setPlayers(List<String> players, PaperPlayer player, GenericServer server){
event.getPlayerSample().clear();
event.getPlayerSample().addAll(
plugin.createPlayers(players, player.getPlayer(), playerPlaceholders, serverPlaceholders)
plugin.createPlayers(players, player, server)
);
}
@@ -124,7 +123,7 @@ public class PaperEventWrapper implements GenericEventWrapper<OfflinePlayer, Cac
}
@Override
public String parsePAPIPlaceholders(String text, GenericPlayer<OfflinePlayer> player){
public String parsePAPIPlaceholders(String text, PaperPlayer player){
if(plugin.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI"))
return PlaceholderAPI.setPlaceholders(player.getPlayer(), text);
@@ -137,12 +136,12 @@ public class PaperEventWrapper implements GenericEventWrapper<OfflinePlayer, Cac
}
@Override
public PluginCore<CachedServerIcon> getPlugin(){
public PluginCore<CachedServerIcon, PlayerProfile, PaperPlayer> getPlugin(){
return plugin;
}
@Override
public GenericPlayer<OfflinePlayer> createPlayer(CachedPlayer player, int protocol){
public PaperPlayer createPlayer(CachedPlayer player, int protocol){
OfflinePlayer pl = Bukkit.getOfflinePlayer(player.getUuid());
return new PaperPlayer(pl.hasPlayedBefore() ? pl : null, player, protocol);
@@ -23,20 +23,21 @@
*
*/
package ch.andre601.advancedserverlist.paper;
package ch.andre601.advancedserverlist.paper.objects;
import ch.andre601.advancedserverlist.api.objects.GenericPlayer;
import ch.andre601.advancedserverlist.core.objects.CachedPlayer;
import ch.andre601.advancedserverlist.core.profiles.players.GenericPlayer;
import org.bukkit.OfflinePlayer;
public class PaperPlayer extends GenericPlayer<OfflinePlayer>{
public class PaperPlayer extends GenericPlayer{
private final OfflinePlayer player;
public PaperPlayer(OfflinePlayer player, CachedPlayer cachedPlayer, int protocol){
this.player = player;
this.name = player == null ? cachedPlayer.getName() : player.getName();
this.protocol = protocol;
this.uuid = player == null ? cachedPlayer.getUuid() : player.getUniqueId();
if(player == null)
@@ -46,4 +47,8 @@ public class PaperPlayer extends GenericPlayer<OfflinePlayer>{
this.banned = player.isBanned();
this.whitelisted = player.isWhitelisted();
}
public OfflinePlayer getPlayer(){
return player;
}
}
@@ -0,0 +1,56 @@
/*
* MIT License
*
* Copyright (c) 2022-2023 Andre_601
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
package ch.andre601.advancedserverlist.paper.objects;
import ch.andre601.advancedserverlist.api.PlaceholderProvider;
import ch.andre601.advancedserverlist.api.objects.GenericPlayer;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
public class PlayerPlaceholders extends PlaceholderProvider{
public PlayerPlaceholders(){
super("player");
}
@Override
public String parsePlaceholder(String placeholder, GenericPlayer player, GenericServer server){
PaperPlayer paperPlayer = (PaperPlayer)player;
return switch(placeholder){
case "name" -> paperPlayer.getName();
case "protocol" -> String.valueOf(paperPlayer.getProtocol());
case "uuid" -> String.valueOf(paperPlayer.getUUID());
case "hasPlayedBefore" -> returnValue(paperPlayer, player.hasPlayedBefore());
case "isBanned" -> returnValue(paperPlayer, player.isBanned());
case "isWhitelisted" -> returnValue(paperPlayer, player.isWhitelisted());
default -> null;
};
}
private String returnValue(PaperPlayer player, Object value){
return player.getPlayer() == null ? null : String.valueOf(value);
}
}
+2 -2
View File
@@ -37,7 +37,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<plugin.version>1.11.0</plugin.version>
<plugin.version>2.0.0</plugin.version>
<plugin.description>Create multiple Server lists based on conditions.</plugin.description>
<maven.compiler.source>16</maven.compiler.source>
@@ -45,11 +45,11 @@
</properties>
<modules>
<module>api</module>
<module>core</module>
<module>bungeecord</module>
<module>paper</module>
<module>spigot</module>
<module>velocity</module>
</modules>
</project>
+1
View File
@@ -0,0 +1 @@
mkdocs-material==9.0.6
@@ -25,21 +25,22 @@
package ch.andre601.advancedserverlist.spigot;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
import ch.andre601.advancedserverlist.core.AdvancedServerList;
import ch.andre601.advancedserverlist.core.interfaces.PluginLogger;
import ch.andre601.advancedserverlist.core.interfaces.core.ServerCore;
import ch.andre601.advancedserverlist.core.interfaces.core.PluginCore;
import ch.andre601.advancedserverlist.core.parsing.ComponentParser;
import ch.andre601.advancedserverlist.core.profiles.favicon.FaviconHandler;
import ch.andre601.advancedserverlist.core.profiles.replacer.placeholders.Placeholders;
import ch.andre601.advancedserverlist.spigot.commands.CmdAdvancedServerList;
import ch.andre601.advancedserverlist.spigot.events.LoadEvent;
import ch.andre601.advancedserverlist.spigot.logging.SpigotLogger;
import ch.andre601.advancedserverlist.spigot.objects.PlayerPlaceholders;
import ch.andre601.advancedserverlist.spigot.objects.SpigotPlayer;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.comphenix.protocol.wrappers.WrappedServerPing;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
@@ -48,7 +49,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class SpigotCore extends JavaPlugin implements ServerCore<WrappedServerPing.CompressedImage, WrappedGameProfile, OfflinePlayer>{
public class SpigotCore extends JavaPlugin implements PluginCore<WrappedServerPing.CompressedImage, WrappedGameProfile, SpigotPlayer>{
private final PluginLogger logger = new SpigotLogger(getLogger());
@@ -70,7 +71,7 @@ public class SpigotCore extends JavaPlugin implements ServerCore<WrappedServerPi
}catch(ClassNotFoundException ignored){}
}
this.core = new AdvancedServerList(this);
this.core = new AdvancedServerList(this, new PlayerPlaceholders());
}
@Override
@@ -147,16 +148,15 @@ public class SpigotCore extends JavaPlugin implements ServerCore<WrappedServerPi
}
@Override
public List<WrappedGameProfile> createPlayers(List<String> lines, OfflinePlayer player, Placeholders... placeholders){
public List<WrappedGameProfile> createPlayers(List<String> lines, SpigotPlayer player, GenericServer server){
List<WrappedGameProfile> players = new ArrayList<>(lines.size());
for(String line : lines){
String parsed = ComponentParser.text(line)
.replacements(placeholders[0])
.replacements(placeholders[1])
.applyReplacements(player, server)
.modifyText(text -> {
if(getServer().getPluginManager().isPluginEnabled("PlaceholderAPI"))
return PlaceholderAPI.setPlaceholders(player, text);
return PlaceholderAPI.setPlaceholders(player.getPlayer(), text);
return text;
})
@@ -25,16 +25,15 @@
package ch.andre601.advancedserverlist.spigot.events;
import ch.andre601.advancedserverlist.core.interfaces.events.GenericEventWrapper;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
import ch.andre601.advancedserverlist.core.interfaces.core.PluginCore;
import ch.andre601.advancedserverlist.core.interfaces.events.GenericEventWrapper;
import ch.andre601.advancedserverlist.core.objects.CachedPlayer;
import ch.andre601.advancedserverlist.core.profiles.players.GenericPlayer;
import ch.andre601.advancedserverlist.core.profiles.replacer.placeholders.PlayerPlaceholders;
import ch.andre601.advancedserverlist.core.profiles.replacer.placeholders.ServerPlaceholders;
import ch.andre601.advancedserverlist.spigot.SpigotCore;
import ch.andre601.advancedserverlist.spigot.SpigotPlayer;
import ch.andre601.advancedserverlist.spigot.objects.SpigotPlayer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.AdventureComponentConverter;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.comphenix.protocol.wrappers.WrappedServerPing;
import me.clip.placeholderapi.PlaceholderAPI;
import net.kyori.adventure.text.Component;
@@ -45,7 +44,7 @@ import java.awt.image.BufferedImage;
import java.util.List;
import java.util.Map;
public class ProtocolLibEventWrapper implements GenericEventWrapper<OfflinePlayer, WrappedServerPing.CompressedImage>{
public class ProtocolLibEventWrapper implements GenericEventWrapper<WrappedServerPing.CompressedImage, WrappedGameProfile, SpigotPlayer>{
private final SpigotCore plugin;
private final PacketEvent event;
@@ -83,9 +82,9 @@ public class ProtocolLibEventWrapper implements GenericEventWrapper<OfflinePlaye
}
@Override
public void setPlayers(List<String> players, GenericPlayer<OfflinePlayer> player, PlayerPlaceholders playerPlaceholders, ServerPlaceholders serverPlaceholders){
public void setPlayers(List<String> players, SpigotPlayer player, GenericServer server){
ping.setPlayers(
plugin.createPlayers(players, player.getPlayer(), playerPlaceholders, serverPlaceholders)
plugin.createPlayers(players, player, server)
);
}
@@ -129,7 +128,7 @@ public class ProtocolLibEventWrapper implements GenericEventWrapper<OfflinePlaye
}
@Override
public String parsePAPIPlaceholders(String text, GenericPlayer<OfflinePlayer> player){
public String parsePAPIPlaceholders(String text, SpigotPlayer player){
if(plugin.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI"))
return PlaceholderAPI.setPlaceholders(player.getPlayer(), text);
@@ -146,12 +145,12 @@ public class ProtocolLibEventWrapper implements GenericEventWrapper<OfflinePlaye
}
@Override
public PluginCore<WrappedServerPing.CompressedImage> getPlugin(){
public PluginCore<WrappedServerPing.CompressedImage, WrappedGameProfile, SpigotPlayer> getPlugin(){
return plugin;
}
@Override
public GenericPlayer<OfflinePlayer> createPlayer(CachedPlayer player, int protocol){
public SpigotPlayer createPlayer(CachedPlayer player, int protocol){
OfflinePlayer pl = Bukkit.getOfflinePlayer(player.getUuid());
return new SpigotPlayer(pl.hasPlayedBefore() ? pl : null, player, protocol);
@@ -23,35 +23,34 @@
*
*/
package ch.andre601.advancedserverlist.core.profiles.replacer.placeholders;
package ch.andre601.advancedserverlist.spigot.objects;
import ch.andre601.advancedserverlist.core.profiles.players.GenericPlayer;
import ch.andre601.advancedserverlist.api.PlaceholderProvider;
import ch.andre601.advancedserverlist.api.objects.GenericPlayer;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
import java.util.HashMap;
import java.util.Map;
public class PlayerPlaceholders implements Placeholders{
public class PlayerPlaceholders extends PlaceholderProvider{
private final Map<String, Object> replacements = new HashMap<>();
public PlayerPlaceholders(GenericPlayer<?> player){
this.replacements.put("${player name}", player.getName());
this.replacements.put("${player protocol}", player.getProtocol());
this.replacements.put("${player uuid}", player.getUniqueId());
if(player.getVersion() != null)
this.replacements.put("${player version}", player.getVersion());
if(player.getPlayer() == null)
return;
this.replacements.put("${player hasPlayedBefore}", player.hasPlayedBefore());
this.replacements.put("${player isBanned}", player.isBanned());
this.replacements.put("${player isWhitelisted}", player.isWhitelisted());
public PlayerPlaceholders(){
super("player");
}
@Override
public Map<String, Object> getReplacements(){
return replacements;
public String parsePlaceholder(String placeholder, GenericPlayer player, GenericServer server){
SpigotPlayer spigotPlayer = (SpigotPlayer)player;
return switch(placeholder){
case "name" -> spigotPlayer.getName();
case "protocol" -> String.valueOf(spigotPlayer.getProtocol());
case "uuid" -> String.valueOf(spigotPlayer.getUUID());
case "hasPlayedBefore" -> returnValue(spigotPlayer, player.hasPlayedBefore());
case "isBanned" -> returnValue(spigotPlayer, player.isBanned());
case "isWhitelisted" -> returnValue(spigotPlayer, player.isWhitelisted());
default -> null;
};
}
private String returnValue(SpigotPlayer player, Object value){
return player.getPlayer() == null ? null : String.valueOf(value);
}
}
@@ -23,13 +23,15 @@
*
*/
package ch.andre601.advancedserverlist.spigot;
package ch.andre601.advancedserverlist.spigot.objects;
import ch.andre601.advancedserverlist.api.objects.GenericPlayer;
import ch.andre601.advancedserverlist.core.objects.CachedPlayer;
import ch.andre601.advancedserverlist.core.profiles.players.GenericPlayer;
import org.bukkit.OfflinePlayer;
public class SpigotPlayer extends GenericPlayer<OfflinePlayer>{
public class SpigotPlayer extends GenericPlayer{
private final OfflinePlayer player;
public SpigotPlayer(OfflinePlayer player, CachedPlayer cachedPlayer, int protocol){
this.player = player;
@@ -46,4 +48,8 @@ public class SpigotPlayer extends GenericPlayer<OfflinePlayer>{
this.banned = player.isBanned();
this.whitelisted = player.isWhitelisted();
}
public OfflinePlayer getPlayer(){
return player;
}
}
@@ -25,16 +25,18 @@
package ch.andre601.advancedserverlist.velocity;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
import ch.andre601.advancedserverlist.core.AdvancedServerList;
import ch.andre601.advancedserverlist.core.interfaces.PluginLogger;
import ch.andre601.advancedserverlist.core.interfaces.core.ProxyCore;
import ch.andre601.advancedserverlist.core.interfaces.core.PluginCore;
import ch.andre601.advancedserverlist.core.parsing.ComponentParser;
import ch.andre601.advancedserverlist.core.profiles.favicon.FaviconHandler;
import ch.andre601.advancedserverlist.core.profiles.replacer.placeholders.Placeholders;
import ch.andre601.advancedserverlist.velocity.commands.CmdAdvancedServerList;
import ch.andre601.advancedserverlist.velocity.events.JoinEvent;
import ch.andre601.advancedserverlist.velocity.events.PingEvent;
import ch.andre601.advancedserverlist.velocity.logging.VelocityLogger;
import ch.andre601.advancedserverlist.velocity.objects.PlayerPlaceholders;
import ch.andre601.advancedserverlist.velocity.objects.VelocityPlayer;
import com.google.inject.Inject;
import com.velocitypowered.api.command.CommandMeta;
import com.velocitypowered.api.event.Subscribe;
@@ -53,7 +55,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class VelocityCore implements ProxyCore<Favicon, ServerPing.SamplePlayer>{
public class VelocityCore implements PluginCore<Favicon, ServerPing.SamplePlayer, VelocityPlayer>{
private final PluginLogger logger;
private final ProxyServer proxy;
@@ -74,7 +76,7 @@ public class VelocityCore implements ProxyCore<Favicon, ServerPing.SamplePlayer>
@Subscribe
public void init(ProxyInitializeEvent event){
this.core = new AdvancedServerList(this);
this.core = new AdvancedServerList(this, new PlayerPlaceholders());
}
@Subscribe
@@ -137,13 +139,12 @@ public class VelocityCore implements ProxyCore<Favicon, ServerPing.SamplePlayer>
}
@Override
public List<ServerPing.SamplePlayer> createPlayers(List<String> lines, Placeholders... placeholders){
public List<ServerPing.SamplePlayer> createPlayers(List<String> lines, VelocityPlayer player, GenericServer server){
List<ServerPing.SamplePlayer> players = new ArrayList<>(lines.size());
for(String line : lines){
String parsed = ComponentParser.text(line)
.replacements(placeholders[0])
.replacements(placeholders[1])
.applyReplacements(player, server)
.toString();
players.add(new ServerPing.SamplePlayer(parsed, UUID.randomUUID()));
@@ -25,16 +25,13 @@
package ch.andre601.advancedserverlist.velocity.events;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
import ch.andre601.advancedserverlist.core.interfaces.core.PluginCore;
import ch.andre601.advancedserverlist.core.interfaces.events.GenericEventWrapper;
import ch.andre601.advancedserverlist.core.objects.CachedPlayer;
import ch.andre601.advancedserverlist.core.profiles.players.GenericPlayer;
import ch.andre601.advancedserverlist.core.profiles.replacer.placeholders.PlayerPlaceholders;
import ch.andre601.advancedserverlist.core.profiles.replacer.placeholders.ServerPlaceholders;
import ch.andre601.advancedserverlist.velocity.VelocityCore;
import ch.andre601.advancedserverlist.velocity.VelocityPlayer;
import ch.andre601.advancedserverlist.velocity.objects.VelocityPlayer;
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.server.ServerPing;
import com.velocitypowered.api.util.Favicon;
import net.kyori.adventure.text.Component;
@@ -42,7 +39,7 @@ import net.kyori.adventure.text.Component;
import java.awt.image.BufferedImage;
import java.util.List;
public class VelocityEventWrapper implements GenericEventWrapper<Player, Favicon>{
public class VelocityEventWrapper implements GenericEventWrapper<Favicon, ServerPing.SamplePlayer, VelocityPlayer>{
private final VelocityCore plugin;
private final ProxyPingEvent event;
@@ -77,8 +74,8 @@ public class VelocityEventWrapper implements GenericEventWrapper<Player, Favicon
}
@Override
public void setPlayers(List<String> players, GenericPlayer<Player> player, PlayerPlaceholders playerPlaceholders, ServerPlaceholders serverPlaceholders){
ServerPing.SamplePlayer[] playerSamples = plugin.createPlayers(players, playerPlaceholders, serverPlaceholders)
public void setPlayers(List<String> players, VelocityPlayer player, GenericServer server){
ServerPing.SamplePlayer[] playerSamples = plugin.createPlayers(players, player, server)
.toArray(new ServerPing.SamplePlayer[0]);
if(playerSamples.length > 0)
@@ -125,7 +122,7 @@ public class VelocityEventWrapper implements GenericEventWrapper<Player, Favicon
}
@Override
public String parsePAPIPlaceholders(String text, GenericPlayer<Player> player){
public String parsePAPIPlaceholders(String text, VelocityPlayer player){
return text;
}
@@ -135,12 +132,12 @@ public class VelocityEventWrapper implements GenericEventWrapper<Player, Favicon
}
@Override
public PluginCore<Favicon> getPlugin(){
public PluginCore<Favicon, ServerPing.SamplePlayer, VelocityPlayer> getPlugin(){
return plugin;
}
@Override
public GenericPlayer<Player> createPlayer(CachedPlayer player, int protocol){
public VelocityPlayer createPlayer(CachedPlayer player, int protocol){
return new VelocityPlayer(player, protocol);
}
@@ -23,12 +23,26 @@
*
*/
package ch.andre601.advancedserverlist.core.interfaces.core;
package ch.andre601.advancedserverlist.velocity.objects;
import ch.andre601.advancedserverlist.core.profiles.replacer.placeholders.Placeholders;
import ch.andre601.advancedserverlist.api.PlaceholderProvider;
import ch.andre601.advancedserverlist.api.objects.GenericPlayer;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
import java.util.List;
public interface ServerCore<F, P, P2> extends PluginCore<F>{
List<P> createPlayers(List<String> lines, P2 player, Placeholders... placeholders);
public class PlayerPlaceholders extends PlaceholderProvider{
public PlayerPlaceholders(){
super("player");
}
@Override
public String parsePlaceholder(String placeholder, GenericPlayer player, GenericServer server){
return switch(placeholder){
case "name" -> player.getName();
case "protocol" -> String.valueOf(player.getProtocol());
case "uuid" -> String.valueOf(player.getUUID());
case "version" -> player.getVersion();
default -> null;
};
}
}
@@ -23,14 +23,13 @@
*
*/
package ch.andre601.advancedserverlist.velocity;
package ch.andre601.advancedserverlist.velocity.objects;
import ch.andre601.advancedserverlist.api.objects.GenericPlayer;
import ch.andre601.advancedserverlist.core.objects.CachedPlayer;
import ch.andre601.advancedserverlist.core.profiles.players.GenericPlayer;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.Player;
public class VelocityPlayer extends GenericPlayer<Player>{
public class VelocityPlayer extends GenericPlayer{
public VelocityPlayer(CachedPlayer player, int protocol){
this.name = player.getName();