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

Commit

Permalink
Merge pull request #50 from Andre601/feature/paper-plugin-support
Browse files Browse the repository at this point in the history
First steps towards paper-plugin support
  • Loading branch information
Andre601 authored Mar 23, 2023
2 parents b541518 + afa8058 commit 07cef34
Show file tree
Hide file tree
Showing 32 changed files with 841 additions and 136 deletions.
22 changes: 7 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,11 @@ jobs:
path: bungeecord/target/AdvancedServerList-*.jar
if-no-files-found: error
retention-days: 1
- name: Save Paper Jar file
uses: actions/upload-artifact@v3
with:
name: asl-paper
path: paper/target/AdvancedServerList-*.jar
if-no-files-found: error
retention-days: 1
- name: Save Spigot Jar file
- name: Save Bukkit Jar file
uses: actions/upload-artifact@v3
with:
name: asl-spigot
path: spigot/target/AdvancedServerList-*.jar
path: bukkit/target/AdvancedServerList-*.jar
if-no-files-found: error
retention-days: 1
- name: Save Velocity Jar file
Expand All @@ -61,12 +54,11 @@ jobs:
loaders: |
bungeecord
waterfall
- platforms: Paper
directory: paper
loaders: paper
- platforms: Spigot
directory: spigot
loaders: spigot
- platforms: Spigot, Paper
directory: bukkit
loaders: |
spigot
paper
- platforms: Velocity
directory: velocity
loaders: velocity
Expand Down
14 changes: 12 additions & 2 deletions spigot/pom.xml → bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>spigot</artifactId>
<artifactId>bukkit</artifactId>
<packaging>jar</packaging>
<version>${plugin.version}</version>

Expand All @@ -44,6 +44,10 @@
</properties>

<repositories>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository>
<id>spigot</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
Expand Down Expand Up @@ -75,6 +79,12 @@
<version>${api.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.19.3-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
Expand Down Expand Up @@ -112,7 +122,7 @@
</dependencies>

<build>
<finalName>AdvancedServerList-Spigot-${plugin.version}</finalName>
<finalName>AdvancedServerList-Bukkit-${plugin.version}</finalName>
<resources>
<resource>
<filtering>true</filtering>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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.bukkit.commands;

import ch.andre601.advancedserverlist.core.interfaces.commands.CmdSender;
import ch.andre601.advancedserverlist.core.interfaces.core.PluginCore;
import ch.andre601.advancedserverlist.paper.commands.PaperCmdSender;
import ch.andre601.advancedserverlist.spigot.commands.SpigotCmdSender;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;

public class CmdAdvancedServerList extends Command{

private final PluginCore<?> plugin;
private final BukkitAudiences audiences;

public CmdAdvancedServerList(PluginCore<?> plugin){
this(plugin, null);
}

public CmdAdvancedServerList(PluginCore<?> plugin, BukkitAudiences audiences){
super(
"advancedserverlist",
"Main command of the plugin",
"/asl [reload|help]",
Collections.singletonList("asl")
);

this.plugin = plugin;
this.audiences = audiences;
}

public boolean execute(@NotNull CommandSender sender, @NotNull String s, @NotNull String[] args){
plugin.getCore().getCommandHandler().handle(getSender(sender), args);
return true;
}

private CmdSender getSender(CommandSender sender){
return audiences == null ? new PaperCmdSender(sender) : new SpigotCmdSender(sender, audiences);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
*
*/

package ch.andre601.advancedserverlist.spigot.events;
package ch.andre601.advancedserverlist.bukkit.events;

import ch.andre601.advancedserverlist.spigot.SpigotCore;
import ch.andre601.advancedserverlist.core.interfaces.core.PluginCore;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -35,9 +35,9 @@

public class JoinEvent implements Listener{

private final SpigotCore plugin;
private final PluginCore<?> plugin;

public JoinEvent(SpigotCore plugin){
public JoinEvent(PluginCore<?> plugin){
this.plugin = plugin;
}

Expand All @@ -46,7 +46,7 @@ public void onJoin(PlayerJoinEvent event){
InetSocketAddress address = event.getPlayer().getAddress();
if(address == null)
return;

Player player = event.getPlayer();
plugin.getCore().getPlayerHandler().addPlayer(address.getHostString(), player.getName(), player.getUniqueId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
*
*/

package ch.andre601.advancedserverlist.spigot.events;
package ch.andre601.advancedserverlist.bukkit.events;

import ch.andre601.advancedserverlist.api.profiles.ProfileEntry;
import ch.andre601.advancedserverlist.spigot.events.PreServerListSetEvent;

public class PreServerListSetEventImpl extends PreServerListSetEvent{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
*
*/

package ch.andre601.advancedserverlist.spigot.logging;
package ch.andre601.advancedserverlist.bukkit.logging;

import ch.andre601.advancedserverlist.core.interfaces.PluginLogger;

import java.util.logging.Level;
import java.util.logging.Logger;

public class SpigotLogger implements PluginLogger{
public class BukkitLogger implements PluginLogger{

private final Logger logger;

public SpigotLogger(Logger logger){
public BukkitLogger(Logger logger){
this.logger = logger;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,30 @@
*
*/

package ch.andre601.advancedserverlist.spigot.objects;
package ch.andre601.advancedserverlist.bukkit.objects;

import ch.andre601.advancedserverlist.api.PlaceholderProvider;
import ch.andre601.advancedserverlist.api.objects.GenericPlayer;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
import ch.andre601.advancedserverlist.spigot.objects.SpigotPlayer;

public class SpigotPlayerPlaceholders extends PlaceholderProvider{
public class BukkitPlayerPlaceholders extends PlaceholderProvider{

public SpigotPlayerPlaceholders(){
public BukkitPlayerPlaceholders(){
super("player");
}

@Override
public String parsePlaceholder(String placeholder, GenericPlayer player, GenericServer server){
SpigotPlayer spigotPlayer = (SpigotPlayer)player;
SpigotPlayer bukkitPlayer = (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, spigotPlayer.hasPlayedBefore());
case "isBanned" -> returnValue(spigotPlayer, spigotPlayer.isBanned());
case "isWhitelisted" -> returnValue(spigotPlayer, spigotPlayer.isWhitelisted());
case "name" -> bukkitPlayer.getName();
case "protocol" -> String.valueOf(bukkitPlayer.getProtocol());
case "uuid" -> bukkitPlayer.getUUID().toString();
case "hasPlayedBefore" -> returnValue(bukkitPlayer, bukkitPlayer.hasPlayedBefore());
case "isBanned" -> returnValue(bukkitPlayer, bukkitPlayer.isBanned());
case "isWhitelisted" -> returnValue(bukkitPlayer, bukkitPlayer.isWhitelisted());
default -> null;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@
*
*/

package ch.andre601.advancedserverlist.spigot.objects;
package ch.andre601.advancedserverlist.bukkit.objects;

import ch.andre601.advancedserverlist.api.objects.GenericPlayer;
import ch.andre601.advancedserverlist.api.objects.GenericServer;
import ch.andre601.advancedserverlist.api.profiles.ProfileEntry;
import ch.andre601.advancedserverlist.core.interfaces.core.PluginCore;
import ch.andre601.advancedserverlist.core.objects.CachedPlayer;
import ch.andre601.advancedserverlist.core.objects.GenericServerImpl;
import ch.andre601.advancedserverlist.core.parsing.ComponentParser;
import ch.andre601.advancedserverlist.core.profiles.ServerListProfile;
import ch.andre601.advancedserverlist.core.profiles.profile.ProfileManager;
import ch.andre601.advancedserverlist.core.profiles.replacer.StringReplacer;
import ch.andre601.advancedserverlist.spigot.SpigotCore;
import ch.andre601.advancedserverlist.spigot.events.PingEvent;
import ch.andre601.advancedserverlist.spigot.events.ProtocolLibEvents;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.viaversion.viaversion.api.Via;
import me.clip.placeholderapi.PlaceholderAPI;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
Expand All @@ -50,10 +50,9 @@

public class PAPIPlaceholders extends PlaceholderExpansion{

private final SpigotCore plugin;
private final ProtocolManager manager = ProtocolLibrary.getProtocolManager();
private final PluginCore<?> plugin;

public PAPIPlaceholders(SpigotCore plugin){
public PAPIPlaceholders(PluginCore<?> plugin){
this.plugin = plugin;
this.register();
}
Expand All @@ -65,30 +64,22 @@ public PAPIPlaceholders(SpigotCore plugin){

@Override
public @NotNull String getAuthor(){
return String.join(", ", plugin.getDescription().getAuthors());
return "Andre601";
}

@Override
public @NotNull String getVersion(){
return plugin.getDescription().getVersion();
return plugin.getCore().getVersion();
}

@Override
public String onPlaceholderRequest(Player pl, @NotNull String identifier){
InetSocketAddress address = pl.getAddress();

String host = address == null ? null : PingEvent.getHostAddresses().get(address.getHostString());
String host = address == null ? null : ProtocolLibEvents.getHostAddresses().get(address.getHostString());
CachedPlayer cached = plugin.getCore().getPlayerHandler().getCachedPlayer(pl.getUniqueId());

// Check if ViaVersion is enabled to resolve the player's protocol version.
// If not can we assume the client's version to be the same as the server's.
int protocol;
if(Bukkit.getPluginManager().isPluginEnabled("ViaVersion")){
protocol = Via.getAPI().getPlayerVersion(pl.getUniqueId());
}else{
protocol = manager.getProtocolVersion(pl);
}

int protocol = resolveProtocol(pl);
int online = Bukkit.getOnlinePlayers().size();
int max = Bukkit.getMaxPlayers();
GenericServer server = new GenericServerImpl(online, max, host);
Expand Down Expand Up @@ -126,4 +117,16 @@ public String onPlaceholderRequest(Player pl, @NotNull String identifier){
default -> null;
};
}

private int resolveProtocol(Player player){
if(Bukkit.getPluginManager().isPluginEnabled("ViaVersion"))
return Via.getAPI().getPlayerVersion(player.getUniqueId());

// Since Spigot version requires ProtocolLib can we use it here safely if the plugin instance is SpigotCore.
if(plugin instanceof SpigotCore)
return ProtocolLibrary.getProtocolManager().getProtocolVersion(player);

// getProtocolVersion is only in Paper, so this is only called when
return Bukkit.getUnsafe().getProtocolVersion();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
*
*/

package ch.andre601.advancedserverlist.spigot.objects;
package ch.andre601.advancedserverlist.bukkit.objects;

import ch.andre601.advancedserverlist.core.objects.CachedPlayer;
import ch.andre601.advancedserverlist.core.profiles.players.GenericPlayerImpl;
import ch.andre601.advancedserverlist.spigot.objects.SpigotPlayer;
import org.bukkit.OfflinePlayer;

public class SpigotPlayerImpl extends GenericPlayerImpl implements SpigotPlayer{
Expand Down
Loading

0 comments on commit 07cef34

Please sign in to comment.