Skip to content

Commit

Permalink
Added: New single SkinAPI to be used in all refine plugins
Browse files Browse the repository at this point in the history
Signed-off-by: DevDrizzy <[email protected]>
  • Loading branch information
DevDrizzy committed Sep 28, 2024
1 parent a41a692 commit a4deef7
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 286 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,30 @@ You can initiate and register a TablistAdapter using the following code:
```java
import xyz.refinedev.api.tablist.TablistHandler;
import xyz.refinedev.api.tablist.adapter.impl.ExampleAdapter;
import xyz.refinedev.api.skin.SkinAPI;

import com.github.retrooper.packetevents.PacketEventsAPI;

public class ExamplePlugin extends JavaPlugin {

private TablistHandler tablistHandler;
private PacketEventsAPI<?> packetEvents;
private SkinAPI skinAPI;

@Override
public void onEnable() {
//this.packetEvents.init();
//this.skinAPI = new SkinAPI(plugin, gson);

this.tablistHandler = new TablistHandler(plugin);
this.tablistHandler.init(this.packetEvents, new TeamsPacketListener(this.packetEvents));
this.tablistHandler.init(this.packetEvents);
this.tablistHandler.setupSkinCache(this.skinAPI, true);
this.tablistHandler.registerAdapter(new ExampleAdapter(tablist), 20L);
}

public void onDisable() {
//this.skinAPI.unload();
}
}
```

Expand Down
45 changes: 40 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</repository>
<repository>
<id>refine-public</id>
<url>https://maven.refinedev.xyz/repository/public-repo/</url>
<url>https://maven.refinedev.xyz/public-repo</url>
</repository>
<repository>
<id>codemc-repo</id>
Expand All @@ -47,16 +47,40 @@
<distributionManagement>
<repository>
<id>refine-public</id>
<url>https://maven.refinedev.xyz/repository/public-repo/</url>
<url>https://maven.refinedev.xyz/public-repo</url>
</repository>
</distributionManagement>

<dependencies>
<dependency>
<groupId>com.github.retrooper</groupId>
<artifactId>packetevents-spigot</artifactId>
<version>2.4.0</version>
<scope>provided</scope>
<version>2.5.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</exclusion>
<exclusion>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
</exclusion>
<exclusion>
<groupId>com.github.retrooper</groupId>
<artifactId>packetevents-api</artifactId>
</exclusion>
<exclusion>
<groupId>com.github.retrooper.packetevents</groupId>
<artifactId>netty-common</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.retrooper</groupId>
<artifactId>packetevents-api</artifactId>
<version>2.5.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>com.google.code.gson</groupId>
Expand All @@ -66,14 +90,25 @@
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
</exclusion>
<exclusion>
<groupId>com.github.retrooper.packetevents</groupId>
<artifactId>netty-common</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>xyz.refinedev.api</groupId>
<artifactId>SkinAPI</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>

<!--Annotations-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<version>1.18.32</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
Expand Down
31 changes: 19 additions & 12 deletions src/main/java/xyz/refinedev/api/tablist/TablistHandler.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
package xyz.refinedev.api.tablist;

import com.github.retrooper.packetevents.PacketEventsAPI;

import com.google.common.base.Preconditions;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.log4j.Log4j2;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scoreboard.Team;

import xyz.refinedev.api.skin.SkinAPI;

import xyz.refinedev.api.tablist.adapter.TabAdapter;
import xyz.refinedev.api.tablist.adapter.impl.ExampleAdapter;
import xyz.refinedev.api.tablist.listener.SkinCacheListener;
import xyz.refinedev.api.tablist.listener.TabListener;
import xyz.refinedev.api.tablist.listener.TeamsPacketListener;
import xyz.refinedev.api.tablist.setup.TabLayout;
import xyz.refinedev.api.tablist.skin.SkinCache;
import xyz.refinedev.api.tablist.thread.TablistThread;

import java.util.Map;
Expand All @@ -41,7 +46,7 @@ public class TablistHandler {
/**
* Our custom Skin Cache that stores every online player's Skin
*/
private SkinCache skinCache;
private SkinAPI skinAPI;
/**
* Tablist Adapter of this instance
*/
Expand All @@ -56,7 +61,6 @@ public class TablistHandler {
*/
private TablistThread thread;
private PacketEventsAPI<?> packetEvents;
private TeamsPacketListener teamsPacketListener;
private final boolean debug;
@Setter private boolean hook, ignore1_7;
private long ticks = 20L;
Expand All @@ -71,24 +75,27 @@ public TablistHandler(JavaPlugin plugin) {
* Set up the PacketEvents instance of this Tablist Handler.
* We let the plugin initialize and handle the PacketEvents instance.
*/
public void init(PacketEventsAPI<?> packetEventsAPI, TeamsPacketListener listener) {
public void init(PacketEventsAPI<?> packetEventsAPI) {
this.packetEvents = packetEventsAPI;
this.adapter = new ExampleAdapter();
this.listener = new TabListener(this);

this.teamsPacketListener = listener;
this.packetEvents.getEventManager().registerListener(listener);
this.packetEvents.getEventManager().registerListener(new TeamsPacketListener(this.packetEvents));
Bukkit.getPluginManager().registerEvents(this.listener, plugin);

this.setupSkinCache();
}

public void setupSkinCache() {
this.skinCache = new SkinCache();
Bukkit.getPluginManager().registerEvents(new SkinCacheListener(this), plugin);
/**
* Attach the plugin's skin api instance to this tablist.
*
* @param skinAPI {@link SkinAPI}
*/
public void setupSkinCache(SkinAPI skinAPI) {
this.skinAPI = skinAPI;
}

public void registerAdapter(TabAdapter tabAdapter, long ticks) {
Preconditions.checkNotNull(skinAPI, "SkinAPI was not registered!");

this.adapter = tabAdapter == null ? new ExampleAdapter() : tabAdapter;

if (ticks < 20L) {
Expand Down

This file was deleted.

38 changes: 0 additions & 38 deletions src/main/java/xyz/refinedev/api/tablist/skin/CachedSkin.java

This file was deleted.

Loading

0 comments on commit a4deef7

Please sign in to comment.