9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-19 15:09:19 +00:00

Late night work with backpacks

This commit is contained in:
LoJoSho
2022-11-10 22:47:01 -06:00
parent 28181497c7
commit 451ddf4779
8 changed files with 24 additions and 9 deletions

View File

@@ -31,8 +31,8 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
instance = this;
// File setup
if (!getDataFolder().exists()) {
saveDefaultConfig();
if (!getDataFolder().exists()) {
saveResource("translations.yml", false);
saveResource("messages.yml", false);
saveResource("cosmetics/examplecosmetics.yml", false);

View File

@@ -32,9 +32,7 @@ public class CosmeticBackpackType extends Cosmetic {
List<Player> sendTo = PlayerUtils.getNearbyPlayers(player.getLocation());
Location loc = player.getLocation();
PacketManager.armorStandMetaPacket(user.getBackpackEntity().getBukkitEntity(), sendTo);
PacketManager.sendRotationPacket(user.getArmorstandId(), loc, false, sendTo);
PacketManager.sendLookPacket(user.getArmorstandId(), loc, sendTo);
user.getBackpackEntity().getBukkitLivingEntity().setRotation(loc.getYaw(), loc.getPitch());
}

View File

@@ -19,7 +19,7 @@ public class Database {
public Database() {
String databaseType = DatabaseSettings.getDatabaseType();
switch (databaseType) {
case "INTERNAL_DATA":
case "INTERNAL":
data = INTERNAL_DATA;
case "MYSQL":
data = MYSQL_DATA;

View File

@@ -16,5 +16,8 @@ public class InvisibleArmorstand extends ArmorStand {
this.setPos(loc.getX(), loc.getY(), loc.getZ());
setInvisible(true);
setInvulnerable(true);
setMarker(true);
getBukkitLivingEntity().setCollidable(false);
persist = false;
}
}

View File

@@ -11,18 +11,22 @@ import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
import com.hibiscusmc.hmccosmetics.entities.InvisibleArmorstand;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.event.world.EntitiesUnloadEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@@ -78,6 +82,15 @@ public class PlayerGameListener implements Listener {
user.updateCosmetic();
}
@EventHandler
public void onPlayerLook(PlayerMoveEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
HMCCosmeticsPlugin.getInstance().getLogger().info("PlayerLookEvent");
user.updateCosmetic(CosmeticSlot.BACKPACK);
}
private void registerInventoryClickListener() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.WINDOW_CLICK) {
@Override

View File

@@ -134,7 +134,7 @@ public class CosmeticUser {
((CraftWorld) player.getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM);
PacketManager.armorStandMetaPacket(invisibleArmorstand.getBukkitEntity(), sentTo);
PacketManager.ridingMountPacket(player.getEntityId(), invisibleArmorstand.getId(), sentTo);
//PacketManager.ridingMountPacket(player.getEntityId(), invisibleArmorstand.getId(), sentTo);
player.addPassenger(invisibleArmorstand.getBukkitEntity());

View File

@@ -15,6 +15,7 @@ import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerPlayer
import com.mojang.datafixers.util.Pair;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import net.minecraft.network.protocol.game.ClientboundGameEventPacket;
import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket;
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ItemStack;
@@ -193,8 +194,8 @@ public class PacketManager extends BasePacket {
float pitch = location.getPitch() * ROTATION_FACTOR;
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_LOOK);
packet.getIntegers().write(0, entityId);
packet.getBytes().write(0, (byte) (location.getYaw() * ROTATION_FACTOR));
packet.getBytes().write(1, (byte) (location.getPitch() * ROTATION_FACTOR));
packet.getBytes().write(0, (byte) yaw);
packet.getBytes().write(1, (byte) pitch);
//Bukkit.getLogger().info("DEBUG: Yaw: " + (location.getYaw() * ROTATION_FACTOR) + " | Original Yaw: " + location.getYaw());
packet.getBooleans().write(0, onGround);