Skip to content

Commit

Permalink
Merge pull request #2 from Xiao-MoMi/main
Browse files Browse the repository at this point in the history
[pull] main from Xiao-MoMi:main
  • Loading branch information
INSide-734 authored Jul 6, 2024
2 parents 86e06c2 + 3000b26 commit e173423
Show file tree
Hide file tree
Showing 22 changed files with 156 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ public enum StorageType {
MySQL,
MariaDB,
MongoDB,
Redis
Redis,
None
}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {

allprojects {

version = "2.4.0"
version = "2.4.1"

apply<JavaPlugin>()
apply(plugin = "java")
Expand Down
6 changes: 3 additions & 3 deletions paper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ dependencies {
// api module
implementation(project(":api"))
implementation(project(":common"))
implementation(files("libs/Sparrow-Heart-0.17.jar"))
implementation(files("libs/Sparrow-Heart-0.19.jar"))

// adventure
compileOnly("net.kyori:adventure-api:4.17.0")
compileOnly("net.kyori:adventure-platform-bukkit:4.3.3")
implementation("net.kyori:adventure-api:4.17.0")
implementation("net.kyori:adventure-platform-bukkit:4.3.3")
}

tasks {
Expand Down
Binary file removed paper/libs/Sparrow-Heart-0.17.jar
Binary file not shown.
Binary file added paper/libs/Sparrow-Heart-0.19.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ public void onLoad() {
Dependency.SLF4J_SIMPLE,
versionManager.isMojmap() ? Dependency.COMMAND_API_MOJMAP : Dependency.COMMAND_API,
Dependency.BOOSTED_YAML,
Dependency.BIOME_API,
Dependency.ADVENTURE_BUNDLE,
Dependency.MYSQL_DRIVER,
Dependency.MARIADB_DRIVER,
Dependency.MONGODB_DRIVER_SYNC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public void reload() {
this.cacheSystem = new CacheSystem(CNConfig.cacheSize);
}

public WrappedChatComponent getWrappedChatComponentFromMiniMessage(String text) {
return cacheSystem.getWrappedChatComponentFromCache(text);
public String getJsonComponentFromMiniMessage(String text) {
return cacheSystem.getJsonComponentFromCache(text);
}

public Object getIChatComponentFromMiniMessage(String text) {
Expand Down Expand Up @@ -294,7 +294,7 @@ public class CacheSystem {

private final LoadingCache<String, Object> miniMessageToIChatComponentCache;
private final LoadingCache<String, Component> miniMessageToComponentCache;
private final LoadingCache<String, WrappedChatComponent> miniMessageToWrappedChatComponentCache;
private final LoadingCache<String, String> miniMessageToJsonChatComponentCache;

public CacheSystem(int size) {
miniMessageToIChatComponentCache = CacheBuilder.newBuilder()
Expand All @@ -319,15 +319,15 @@ public Component load(@NotNull String text) {
return fetchComponent(text);
}
});
miniMessageToWrappedChatComponentCache = CacheBuilder.newBuilder()
miniMessageToJsonChatComponentCache = CacheBuilder.newBuilder()
.maximumSize(size)
.expireAfterWrite(10, TimeUnit.MINUTES)
.build(
new CacheLoader<>() {
@NotNull
@Override
public WrappedChatComponent load(@NotNull String text) {
return fetchWrappedChatComponent(text);
public String load(@NotNull String text) {
return fetchJsonChatComponent(text);
}
});
}
Expand All @@ -353,11 +353,11 @@ private Component fetchComponent(String text) {
}

@NotNull
private WrappedChatComponent fetchWrappedChatComponent(String text) {
private String fetchJsonChatComponent(String text) {
if (CNConfig.legacyColorSupport) {
return WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(legacyToMiniMessage(text))));
return GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(legacyToMiniMessage(text)));
} else {
return WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(text)));
return GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(text));
}
}

Expand All @@ -379,12 +379,12 @@ public Component getComponentFromCache(String text) {
}
}

public WrappedChatComponent getWrappedChatComponentFromCache(String text) {
public String getJsonComponentFromCache(String text) {
try {
return miniMessageToWrappedChatComponentCache.get(text);
return miniMessageToJsonChatComponentCache.get(text);
} catch (ExecutionException e) {
e.printStackTrace();
return WrappedChatComponent.fromText("");
return "{\"text\":\"\"}";
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,24 +202,6 @@ public enum Dependency {
"2.10.1",
null,
"gson"
),
BIOME_API(
"com{}github{}Xiao-MoMi",
"BiomeAPI",
"0.6",
"jitpack",
"biome-api",
Relocation.of("biomeapi", "net{}momirealms{}biomeapi")
),
ADVENTURE_BUNDLE(
"com.github.Xiao-MoMi",
"Adventure-Bundle",
"4.16.0",
"jitpack",
"adventure-bundle",
Relocation.of("adventure", "net{}kyori{}adventure"),
Relocation.of("option", "net{}kyori{}option"),
Relocation.of("examination", "net{}kyori{}examination")
);

private final String mavenRepoPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@

package net.momirealms.customnameplates.paper.mechanic.bossbar;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.InternalStructure;
import com.comphenix.protocol.events.PacketContainer;
import net.momirealms.customnameplates.paper.adventure.AdventureManagerImpl;
import net.momirealms.customnameplates.paper.mechanic.misc.PacketManager;
import net.momirealms.customnameplates.paper.util.ReflectionUtils;
import net.momirealms.sparrow.heart.SparrowHeart;
import net.momirealms.sparrow.heart.feature.bossbar.BossBarColor;
import net.momirealms.sparrow.heart.feature.bossbar.BossBarOverlay;
import org.bukkit.entity.Player;

import java.lang.reflect.InvocationTargetException;
import java.util.UUID;

public class BossBar {
Expand All @@ -46,17 +43,17 @@ public BossBar(Player owner, Overlay overlay, BarColor barColor) {
}

public void show() {
PacketManager.getInstance().send(owner, getCreatePacket());
SparrowHeart.getInstance().createBossBar(owner, uuid, AdventureManagerImpl.getInstance().getJsonComponentFromMiniMessage(latestMiniMessage), BossBarColor.valueOf(barColor.name()), BossBarOverlay.valueOf(overlay.name()), 0f, false, false, false);
this.visible = true;
}

public void hide() {
PacketManager.getInstance().send(owner, getRemovePacket());
SparrowHeart.getInstance().removeBossBar(owner, uuid);
this.visible = false;
}

public void update() {
PacketManager.getInstance().send(owner, getUpdatePacket());
SparrowHeart.getInstance().updateBossBarName(owner, uuid, AdventureManagerImpl.getInstance().getJsonComponentFromMiniMessage(latestMiniMessage));
}

public boolean isVisible() {
Expand All @@ -66,38 +63,4 @@ public boolean isVisible() {
public void setMiniMessageText(String text) {
latestMiniMessage = text;
}

private PacketContainer getCreatePacket() {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.BOSS);
packet.getModifier().write(0, uuid);
InternalStructure internalStructure = packet.getStructures().read(1);
internalStructure.getChatComponents().write(0, AdventureManagerImpl.getInstance().getWrappedChatComponentFromMiniMessage(latestMiniMessage));
internalStructure.getFloat().write(0,1F);
internalStructure.getEnumModifier(BarColor.class, 2).write(0, barColor);
internalStructure.getEnumModifier(Overlay.class, 3).write(0, overlay);
internalStructure.getModifier().write(4, false);
internalStructure.getModifier().write(5, false);
internalStructure.getModifier().write(6, false);
return packet;
}

private PacketContainer getUpdatePacket() {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.BOSS);
packet.getModifier().write(0, uuid);
try {
Object chatComponent = AdventureManagerImpl.getInstance().getIChatComponentFromMiniMessage(latestMiniMessage);
Object updatePacket = ReflectionUtils.getUpdateConstructor().newInstance(chatComponent);
packet.getModifier().write(1, updatePacket);
} catch (InvocationTargetException | IllegalAccessException | InstantiationException e) {
throw new RuntimeException(e);
}
return packet;
}

private PacketContainer getRemovePacket() {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.BOSS);
packet.getModifier().write(0, uuid);
packet.getModifier().write(1, ReflectionUtils.getRemoveBossBarPacket());
return packet;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public VersionManagerImpl(CustomNameplatesPluginImpl plugin) {
// Get the server version

String[] split = Bukkit.getServer().getBukkitVersion().split("-")[0].split("\\.");
this.mcVersion = Float.parseFloat(split[1] + "." + split[2]);
this.mcVersion = Float.parseFloat(split[1] + "." + (split.length >= 3 ? split[2] : "0"));

// Get the plugin version
this.pluginVersion = plugin.getDescription().getVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ public void handlePlayerQuit(Player player) {
this.removeEntityIDFromMap(player.getEntityId());
this.teamTagManager.handlePlayerQuit(player);
this.unlimitedTagManager.handlePlayerQuit(player);
this.removeNameplatePlayerFromMap(player.getUniqueId());

// nameplate module part
if (CNConfig.nameplateModule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void handlePlayerPose(Player player, Pose pose) {
}

public void handlePlayerQuit(Player quit) {
UnlimitedEntity unlimitedEntity = getUnlimitedObject(quit.getUniqueId());
UnlimitedEntity unlimitedEntity = removeUnlimitedEntityFromMap(quit.getUniqueId());
if (unlimitedEntity != null) {
unlimitedEntity.destroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public void generateResourcePack() {
// save unicodes
this.saveLegacyUnicodes();
// generate shaders
this.generateShaders();
this.generateShaders("ResourcePack" + File.separator + "assets" + File.separator + "minecraft" + File.separator + "shaders" + File.separator + "core" + File.separator);
this.generateShaders("ResourcePack" + File.separator + "overlay_1_20_5" + File.separator + "assets" + File.separator + "minecraft" + File.separator + "shaders" + File.separator + "core" + File.separator);

// add offset characters
this.getOffsets(texturesFolder).forEach(providers::add);
Expand All @@ -110,9 +111,8 @@ public void generateResourcePack() {
this.copyResourcePackToHookedPlugins(resourcePackFolder);
}

private void generateShaders() {
private void generateShaders(String path) {
if (!CNConfig.enableShader) return;
String path = "ResourcePack" + File.separator + "assets" + File.separator + "minecraft" + File.separator + "shaders" + File.separator + "core" + File.separator;
plugin.saveResource(path + "rendertype_text.fsh", true);
plugin.saveResource(path + "rendertype_text.json", true);
plugin.saveResource(path + "rendertype_text.vsh", true);
Expand Down Expand Up @@ -496,23 +496,23 @@ private List<JsonObject> getOffsets(File texturesFolder) {

private void setPackFormat() {
plugin.saveResource("ResourcePack" + File.separator + "pack.mcmeta", false);
File format_file = new File(plugin.getDataFolder(), "ResourcePack" + File.separator + "pack.mcmeta");
String line;
StringBuilder sb = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(format_file), StandardCharsets.UTF_8))) {
while ((line = reader.readLine()) != null) {
sb.append(line).append(System.lineSeparator());
}
} catch (IOException e) {
e.printStackTrace();
}
try (BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(new File(plugin.getDataFolder(),
"ResourcePack" + File.separator + "pack.mcmeta")), StandardCharsets.UTF_8))) {
writer.write(sb.toString().replace("%version%", String.valueOf(plugin.getVersionManager().getPackFormat())));
} catch (IOException e) {
e.printStackTrace();
}
// File format_file = new File(plugin.getDataFolder(), "ResourcePack" + File.separator + "pack.mcmeta");
// String line;
// StringBuilder sb = new StringBuilder();
// try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(format_file), StandardCharsets.UTF_8))) {
// while ((line = reader.readLine()) != null) {
// sb.append(line).append(System.lineSeparator());
// }
// } catch (IOException e) {
// e.printStackTrace();
// }
// try (BufferedWriter writer = new BufferedWriter(
// new OutputStreamWriter(new FileOutputStream(new File(plugin.getDataFolder(),
// "ResourcePack" + File.separator + "pack.mcmeta")), StandardCharsets.UTF_8))) {
// writer.write(sb.toString().replace("%version%", String.valueOf(plugin.getVersionManager().getPackFormat())));
// } catch (IOException e) {
// e.printStackTrace();
// }
}

public static class ShaderConstants {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,22 @@ public void createTeam(Player player) {
TeamVisibility.ALWAYS,
TeamCollisionRule.ALWAYS,
TeamColor.WHITE,
true,
true
false,
false
);
if (online == player) continue;
String onlineTeam = teamProvider.getTeam(online, null);
SparrowHeart.getInstance().addClientSideTeam(player, team,
Collections.singletonList(onlineTeam),
SparrowHeart.getInstance().addClientSideTeam(player, onlineTeam,
Collections.singletonList(online.getName()),
"{\"text\":\"\"}",
"{\"text\":\"\"}",
"{\"text\":\"\"}",
TeamVisibility.ALWAYS,
TeamVisibility.ALWAYS,
TeamCollisionRule.ALWAYS,
TeamColor.WHITE,
true,
true
false,
false
);
}
}
Expand Down Expand Up @@ -156,14 +156,14 @@ public void updateTeam(Player owner, Player viewer, String prefix, String suffix
SparrowHeart.getInstance().updateClientSideTeam(
viewer, team,
"{\"text\":\"\"}",
AdventureManagerImpl.getInstance().componentToJson(AdventureManagerImpl.getInstance().getComponentFromMiniMessage(prefix)),
AdventureManagerImpl.getInstance().componentToJson(AdventureManagerImpl.getInstance().getComponentFromMiniMessage(suffix)),
TeamVisibility.ALWAYS,
AdventureManagerImpl.getInstance().getJsonComponentFromMiniMessage(prefix),
AdventureManagerImpl.getInstance().getJsonComponentFromMiniMessage(suffix),
TeamVisibility.valueOf(visibility.name()),
TeamVisibility.ALWAYS,
TeamCollisionRule.ALWAYS,
TeamColor.valueOf(color.name()),
true,
true
false,
false
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.momirealms.customnameplates.api.manager.StorageManager;
import net.momirealms.customnameplates.api.util.LogUtils;
import net.momirealms.customnameplates.paper.CustomNameplatesPluginImpl;
import net.momirealms.customnameplates.paper.storage.method.NoneStorage;
import net.momirealms.customnameplates.paper.storage.method.database.nosql.MongoDBImpl;
import net.momirealms.customnameplates.paper.storage.method.database.nosql.RedisManager;
import net.momirealms.customnameplates.paper.storage.method.database.sql.H2Impl;
Expand Down Expand Up @@ -84,8 +85,10 @@ public void onPlayerJoin(PlayerJoinEvent event) {
if (player == null || !player.isOnline()) return;
var onlineUser = new OnlineUser(player, playerData);
this.putOnlineUserInMap(onlineUser);
NameplateDataLoadEvent syncEvent = new NameplateDataLoadEvent(uuid, onlineUser);
plugin.getServer().getPluginManager().callEvent(syncEvent);
plugin.getScheduler().runTaskAsync(() -> {
NameplateDataLoadEvent syncEvent = new NameplateDataLoadEvent(uuid, onlineUser);
plugin.getServer().getPluginManager().callEvent(syncEvent);
});
}
});
}
Expand Down Expand Up @@ -178,6 +181,7 @@ public void reload() {
case MySQL -> this.dataSource = new MySQLImpl(plugin);
case MariaDB -> this.dataSource = new MariaDBImpl(plugin);
case MongoDB -> this.dataSource = new MongoDBImpl(plugin);
case None -> this.dataSource = new NoneStorage(plugin);
}
if (this.dataSource != null) this.dataSource.initialize();
else LogUtils.severe("No storage type is set.");
Expand Down
Loading

0 comments on commit e173423

Please sign in to comment.