generated from Matt-MX/KtPaperPluginTemplate
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from kxtsoo/main
SkinRestorer integration (not working on client side)
- Loading branch information
Showing
7 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/com/mattmx/nametags/hook/SkinRestorerHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.mattmx.nametags.hook; | ||
|
||
import com.mattmx.nametags.NameTags; | ||
import com.mattmx.nametags.entity.NameTagEntity; | ||
import net.kyori.adventure.text.Component; | ||
import net.kyori.adventure.text.format.NamedTextColor; | ||
import net.skinsrestorer.api.SkinsRestorer; | ||
import net.skinsrestorer.api.SkinsRestorerProvider; | ||
import net.skinsrestorer.api.event.SkinApplyEvent; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.scheduler.BukkitRunnable; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class SkinRestorerHook { | ||
|
||
public static void inject(@NotNull NameTags plugin) { | ||
Bukkit.getScheduler().runTask(plugin, SkinRestorerHook::start); | ||
} | ||
|
||
private static void start() { | ||
final boolean isSkinRestorer = Bukkit.getPluginManager().isPluginEnabled("SkinsRestorer"); | ||
|
||
if (!isSkinRestorer) return; | ||
|
||
NameTags plugin = NameTags.getInstance(); | ||
SkinsRestorer skinsRestorer = SkinsRestorerProvider.get(); | ||
|
||
if (skinsRestorer != null) { | ||
plugin.getLogger().info("Registering SkinRestorer event listeners."); | ||
skinsRestorer.getEventBus().subscribe(plugin, SkinApplyEvent.class, SkinRestorerHook::onSkinApply); | ||
} else { | ||
plugin.getLogger().warning("SkinsRestorer is enabled, but the API provider is null."); | ||
} | ||
} | ||
|
||
private static void onSkinApply(SkinApplyEvent event) { | ||
Player player = event.getPlayer(Player.class); | ||
|
||
if (player == null) return; | ||
|
||
new BukkitRunnable() { | ||
@Override | ||
public void run() { | ||
NameTags plugin = NameTags.getInstance(); | ||
|
||
plugin.getEntityManager().removeLastSentPassengersCache(player.getEntityId()); | ||
|
||
NameTagEntity entity = plugin.getEntityManager().removeEntity(player); | ||
|
||
if (entity != null) { | ||
entity.destroy(); | ||
} | ||
|
||
NameTagEntity newEntity = plugin.getEntityManager().getOrCreateNameTagEntity(player); | ||
newEntity.updateVisibility(); | ||
newEntity.updateLocation(); | ||
|
||
if (plugin.getConfig().getBoolean("show-self", false)) { | ||
newEntity.getPassenger().removeViewer(newEntity.getBukkitEntity().getUniqueId()); | ||
newEntity.getPassenger().addViewer(newEntity.getBukkitEntity().getUniqueId()); | ||
newEntity.sendPassengerPacket(event.getPlayer(Player.class)); | ||
|
||
player.sendMessage(Component.text("Please re-join for update your nametag!").color(NamedTextColor.GREEN)); | ||
} | ||
} | ||
}.runTask(NameTags.getInstance()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ depend: | |
softdepend: | ||
- PlaceholderAPI | ||
- TAB | ||
- SkinsRestorer | ||
|
||
commands: | ||
nametags-reload: | ||
|