Skip to content

Commit

Permalink
Merge pull request #2 from HibiscusMC/remapped
Browse files Browse the repository at this point in the history
[pull] remapped from HibiscusMC:remapped
  • Loading branch information
INSide-734 authored Jul 14, 2024
2 parents 5cac87f + f81d350 commit feb3e0d
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 33 deletions.
14 changes: 7 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,23 @@ allprojects {
compileOnly("com.mojang:authlib:1.5.25")
//compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT")
compileOnly("org.jetbrains:annotations:23.0.0")
compileOnly("org.jetbrains:annotations:24.1.0")
compileOnly("com.comphenix.protocol:ProtocolLib:5.1.0")
compileOnly("me.clip:placeholderapi:2.11.3")
compileOnly("me.clip:placeholderapi:2.11.6")
compileOnly("com.ticxo.modelengine:ModelEngine:R4.0.2")
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
compileOnly("it.unimi.dsi:fastutil:8.5.11")
compileOnly("org.projectlombok:lombok:1.18.2")
compileOnly("it.unimi.dsi:fastutil:8.5.13")
compileOnly("org.projectlombok:lombok:1.18.34")
compileOnly("me.lojosho:HibiscusCommons:0.4.1")

// Handled by Spigot Library Loader
compileOnly("net.kyori:adventure-api:4.17.0")
compileOnly("net.kyori:adventure-text-minimessage:4.17.0")
compileOnly("net.kyori:adventure-platform-bukkit:4.3.3")

annotationProcessor("org.projectlombok:lombok:1.18.28")
testCompileOnly("org.projectlombok:lombok:1.18.28")
testAnnotationProcessor("org.projectlombok:lombok:1.18.28")
annotationProcessor("org.projectlombok:lombok:1.18.34")
testCompileOnly("org.projectlombok:lombok:1.18.34")
testAnnotationProcessor("org.projectlombok:lombok:1.18.34")

implementation("dev.triumphteam:triumph-gui:3.1.10") {
exclude("net.kyori") // Already have adventure API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ public void onStart() {
if (!Path.of(getDataFolder().getPath() + "/cosmetics/").toFile().exists()) saveResource("cosmetics/defaultcosmetics.yml", false);
if (!Path.of(getDataFolder().getPath() + "/menus/").toFile().exists()) saveResource("menus/defaultmenu.yml", false);

// Emote folder setup
File emoteFile = new File(getDataFolder().getPath() + "/emotes");
if (!emoteFile.exists()) emoteFile.mkdir();

// Player Animator
if (HMCCosmeticsAPI.getNMSVersion().contains("v1_19_R3") || HMCCosmeticsAPI.getNMSVersion().contains("v1_20_R1")) PlayerAnimatorImpl.initialize(this); // PlayerAnimator does not support 1.20.2 yet

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class Settings {
private static final String COSMETIC_DISABLED_WORLDS_PATH = "disabled-worlds";
private static final String COSMETIC_PACKET_ENTITY_TELEPORT_COOLDOWN_PATH = "entity-cooldown-teleport-packet";
private static final String COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH = "backpack-force-riding-packet";
private static final String COSMETIC_BACKPACK_LIGHT_EMINATION_PATH = "backpack-light-emination";
private static final String COSMETIC_BACKPACK_LIGHT_BLOCK_DETECTION = "backpack-block-detection";
private static final String COSMETIC_DESTROY_LOOSE_COSMETIC_PATH = "destroy-loose-cosmetics";
private static final String COSMETIC_BALLOON_HEAD_FORWARD_PATH = "balloon-head-forward";
private static final String MENU_SETTINGS_PATH = "menu-settings";
Expand Down Expand Up @@ -105,6 +107,10 @@ public class Settings {
@Getter
private static boolean backpackForceRidingEnabled;
@Getter
private static boolean backpackLightEmination;
@Getter
private static boolean backpackBlockDetection;
@Getter
private static boolean emotesEnabled;
@Getter
private static boolean disabledGamemodesEnabled;
Expand Down Expand Up @@ -196,6 +202,8 @@ public static void load(ConfigurationNode source) {
emoteInvincible = cosmeticSettings.node(COSMETIC_EMOTE_INVINCIBLE_PATH).getBoolean(false);
destroyLooseCosmetics = cosmeticSettings.node(COSMETIC_DESTROY_LOOSE_COSMETIC_PATH).getBoolean(false);
backpackForceRidingEnabled = cosmeticSettings.node(COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH).getBoolean(false);
backpackLightEmination = cosmeticSettings.node(COSMETIC_BACKPACK_LIGHT_EMINATION_PATH).getBoolean(true);
backpackBlockDetection = cosmeticSettings.node(COSMETIC_BACKPACK_LIGHT_BLOCK_DETECTION).getBoolean(true);

cosmeticSettings.node(SLOT_OPTIONS_PATH).childrenMap().forEach((key, value) -> {
EquipmentSlot slot = convertConfigToEquipment(key.toString().toLowerCase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import lombok.Getter;
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
import me.lojosho.shaded.configurate.ConfigurationNode;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -56,37 +58,39 @@ public void update(@NotNull CosmeticUser user) {
}
List<Player> outsideViewers = user.getUserBackpackManager().getEntityManager().refreshViewers(loc);

user.getUserBackpackManager().getEntityManager().teleport(loc);
user.getUserBackpackManager().getEntityManager().setRotation((int) loc.getYaw(), isFirstPersonCompadible());
UserBackpackManager backpackManager = user.getUserBackpackManager();
backpackManager.getEntityManager().teleport(loc);
backpackManager.getEntityManager().setRotation((int) loc.getYaw(), isFirstPersonCompadible());

HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), user.getUserBackpackManager().getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), outsideViewers);
HMCCPacketManager.sendArmorstandMetadata(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
PacketManager.equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(this, getItem()), outsideViewers);
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), backpackManager.getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), outsideViewers);
//HMCCPacketManager.sendArmorstandMetadata(backpackManager.getFirstArmorStandId(), outsideViewers);
PacketManager.equipmentSlotUpdate(backpackManager.getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(this, getItem()), outsideViewers);
// If true, it will send the riding packet to all players. If false, it will send the riding packet only to new players
if (Settings.isBackpackForceRidingEnabled()) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), user.getUserBackpackManager().getEntityManager().getViewers());
if (Settings.isBackpackForceRidingEnabled()) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), backpackManager.getFirstArmorStandId(), backpackManager.getEntityManager().getViewers());
else HMCCPacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);

if (!user.isInWardrobe() && isFirstPersonCompadible() && user.getPlayer() != null) {
List<Player> owner = List.of(user.getPlayer());

ArrayList<Integer> particleCloud = user.getUserBackpackManager().getAreaEffectEntityId();
ArrayList<Integer> particleCloud = backpackManager.getAreaEffectEntityId();
for (int i = 0; i < particleCloud.size(); i++) {
if (i == 0) {
HMCCPacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
} else {
HMCCPacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner);
}
}
HMCCPacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), user.getUserBackpackManager().getFirstArmorStandId(), owner);
HMCCPacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), backpackManager.getFirstArmorStandId(), owner);
if (!user.isHidden()) {
//if (loc.getPitch() < -70) NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, new ItemStack(Material.AIR), owner);
//else NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, firstPersonBackpack, owner);
PacketManager.equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(this, firstPersonBackpack), owner);
PacketManager.equipmentSlotUpdate(backpackManager.getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(this, firstPersonBackpack), owner);
}
MessagesUtil.sendDebugMessages("First Person Backpack Update[owner=" + user.getUniqueId() + ",player_location=" + loc + "]!", Level.INFO);
}

user.getUserBackpackManager().showBackpack();
MessagesUtil.sendDebugMessages("TTTTTTT " + backpackManager.refreshBlock(backpackManager.getEntityManager().getViewers()));
backpackManager.showBackpack();
}

public boolean isFirstPersonCompadible() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
import com.hibiscusmc.hmccosmetics.database.types.Data;
import com.hibiscusmc.hmccosmetics.database.types.MySQLData;
import com.hibiscusmc.hmccosmetics.database.types.NoneData;
import com.hibiscusmc.hmccosmetics.database.types.SQLiteData;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
Expand All @@ -11,25 +12,33 @@
import org.bukkit.entity.Player;

import java.util.UUID;
import java.util.logging.Level;

public class Database {

@Getter
private static Data data;
private static final MySQLData MYSQL_DATA = new MySQLData();
private static final SQLiteData SQLITE_DATA = new SQLiteData();
private static final NoneData NONE_DATA = new NoneData();

public Database() {
String databaseType = DatabaseSettings.getDatabaseType();
data = SQLITE_DATA; // default
if (databaseType.equalsIgnoreCase("MySQL")) {
data = MYSQL_DATA;
data = SQLITE_DATA; // default to SQLite, then check if it's anything different
switch (databaseType.toLowerCase()) {
case "mysql":
data = MYSQL_DATA;
break;
case "sqlite":
// already the default
break;
case "none":
data = NONE_DATA;
MessagesUtil.sendDebugMessages("Database is set to none. Data will not be saved.", Level.WARNING);
break;
default:
MessagesUtil.sendDebugMessages("Invalid database type. Defaulting to SQLite.", Level.WARNING);
}
/* SQLite is the default database. Might change in the future, so keep code here in case.
if (databaseType.equalsIgnoreCase("sqlite")) {
data = SQLITE_DATA;
}
*/
MessagesUtil.sendDebugMessages("Database is " + data);

setup();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.hibiscusmc.hmccosmetics.database.types;

import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.jetbrains.annotations.Nullable;

import java.util.UUID;

public class NoneData extends Data {
@Override
public void setup() {
// Nothing
}

@Override
public void save(CosmeticUser user) {
// Nothing
}

@Override
public @Nullable CosmeticUser get(UUID uniqueId) {
return new CosmeticUser(uniqueId);
}

@Override
public void clear(UUID uniqueId) {
// Nothing
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.hibiscusmc.hmccosmetics.user.manager;

import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import com.ticxo.modelengine.api.ModelEngineAPI;
import lombok.Getter;
import lombok.Setter;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.util.ServerUtils;
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
Expand All @@ -33,10 +36,13 @@ public class UserBackpackManager {
private final CosmeticUser user;
@Getter
private UserEntity entityManager;
@Getter @Setter
private boolean inBlock;

public UserBackpackManager(CosmeticUser user) {
this.user = user;
this.backpackHidden = false;
this.inBlock = false;
this.invisibleArmorStand = ServerUtils.getNextEntityId();
this.entityManager = new UserEntity(user.getUniqueId());
if (user.getEntity() != null) this.entityManager.refreshViewers(user.getEntity().getLocation()); // Fixes an issue where a player, who somehow removes their potions, but doesn't have an entity produces an NPE (it's dumb)
Expand All @@ -57,7 +63,17 @@ private void spawn(CosmeticBackpackType cosmeticBackpackType) {
getEntityManager().teleport(user.getEntity().getLocation());
List<Player> outsideViewers = getEntityManager().getViewers();
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), getEntityManager().getViewers());
HMCCPacketManager.sendArmorstandMetadata(getFirstArmorStandId(), outsideViewers);
if (Settings.isBackpackBlockDetection()) {
if (checkBlock()) {
setInBlock(true);
HMCCPacketManager.sendArmorstandMetadata(getFirstArmorStandId(), isInBlock(), outsideViewers);
} else {
HMCCPacketManager.sendArmorstandMetadata(getFirstArmorStandId(), isInBlock(), outsideViewers);
}
//refreshBlock(outsideViewers);
} else {
HMCCPacketManager.sendArmorstandMetadata(getFirstArmorStandId(), Settings.isBackpackLightEmination(), outsideViewers);
}

Entity entity = user.getEntity();

Expand Down Expand Up @@ -147,4 +163,33 @@ public void clearItems() {
ItemStack item = new ItemStack(Material.AIR);
PacketManager.equipmentSlotUpdate(getFirstArmorStandId(), EquipmentSlot.HEAD, item, getEntityManager().getViewers());
}

/**
* Refreshes the block detection for the backpack
* @param outsideViewers
* @return true if the entity was updated, false if not
*/
public boolean refreshBlock(List<Player> outsideViewers) {
if (Settings.isBackpackBlockDetection()) {
if (isInBlock() && checkBlock()) {
HMCCPacketManager.sendArmorstandMetadata(getFirstArmorStandId(), false, outsideViewers);
setInBlock(false);
return true;
}
if (!isInBlock() && !checkBlock()) {
HMCCPacketManager.sendArmorstandMetadata(getFirstArmorStandId(), true, outsideViewers);
setInBlock(true);
return true;
}
}
return false;
}

public boolean checkBlock() {
if (Settings.isBackpackBlockDetection()) {
Block block = getEntityManager().getLocation().clone().add(0, 1.5, 0).getBlock();
return block.getType().isAir();
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,26 @@ public static void sendArmorstandMetadata(
int entityId,
List<Player> sendTo
) {
sendArmorstandMetadata(entityId, false, sendTo);
}

public static void sendArmorstandMetadata(
int entityId,
boolean onFire,
List<Player> sendTo
) {
byte mask = 0x20;
if (onFire) {
// 0x21 = Invisible + Fire (Aka, burns to make it not take the light of the block its in, avoiding turning it black)
mask = 0x21;
}

PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packet.getModifier().writeDefaults();
packet.getIntegers().write(0, entityId);
final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();

// 0x21 = Invisible + Fire (Aka, burns to make it not take the light of the block its in, avoiding turning it black)
wrappedDataValueList.add(new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x21));
wrappedDataValueList.add(new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), mask));
wrappedDataValueList.add(new WrappedDataValue(15, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x10));
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
for (Player p : sendTo) sendPacket(p, packet);
Expand Down
11 changes: 10 additions & 1 deletion common/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ config-version: 1
default-menu: defaultmenu
debug-mode: false
database-settings:
type: sqlite #MYSQL, SQLite
type: sqlite # SQLite (Default), MYSQL, NONE
mysql:
database: database
password: cherryBomb
Expand Down Expand Up @@ -45,8 +45,17 @@ cosmetic-settings:
emote-camera: true
# If a player should be able to move in an emote. This option really only affects if "emote-camera" is false
emote-move: false


# This make it so it always sends the riding packets for the backpack. This sends more packets but is more reliable for servers which modify player passengers.
backpack-force-riding-packet: false
# This makes the plugin either (true) always have the backpack eminate light to avoid the black backpack bug or (false) turns it off.
backpack-light-emination: true
# This activates the block detection for the backpack. This allows backpacks to not appear completely black when in a block.
# Requires backpack-light-emination to be true.
backpack-block-detection: true


# This helps reduce the amount of packets sent for packet entities, but reduces accuracy of the entity. This is in milliseconds. -1 to disable.
# This is useful for servers with a lot of backpacks, as they are passengers, which means the client will update their position automatically within an area where the entity is located.
entity-cooldown-teleport-packet: 500
Expand Down

0 comments on commit feb3e0d

Please sign in to comment.