mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-30 04:19:28 +00:00
Delay Option + Removal of all NMS in common module
This commit is contained in:
@@ -13,6 +13,9 @@ public class DatabaseSettings {
|
||||
private static final String MYSQL_HOST = "host";
|
||||
private static final String MYSQL_USER = "user";
|
||||
private static final String MYSQL_PORT = "port";
|
||||
private static final String DELAY_PATH = "delay";
|
||||
private static final String ENABLE_DELAY = "enabled";
|
||||
private static final String DELAY_LENGTH = "delay";
|
||||
|
||||
private static String databaseType;
|
||||
private static String database;
|
||||
@@ -20,6 +23,8 @@ public class DatabaseSettings {
|
||||
private static String host;
|
||||
private static String username;
|
||||
private static int port;
|
||||
private static boolean enabledDelay;
|
||||
private static int delayLength;
|
||||
|
||||
public static void load(ConfigurationNode source) {
|
||||
//ConfigurationNode databaseSettings = source.node(DATABASE_SETTINGS_PATH);
|
||||
@@ -33,6 +38,11 @@ public class DatabaseSettings {
|
||||
host = mySql.node(MYSQL_HOST).getString();
|
||||
username = mySql.node(MYSQL_USER).getString();
|
||||
port = mySql.node(MYSQL_PORT).getInt();
|
||||
|
||||
ConfigurationNode delay = source.node(DELAY_PATH);
|
||||
|
||||
enabledDelay = delay.node(ENABLE_DELAY).getBoolean(false);
|
||||
delayLength = delay.node(DELAY_LENGTH).getInt(2);
|
||||
}
|
||||
|
||||
public static String getDatabaseType() {
|
||||
@@ -58,4 +68,12 @@ public class DatabaseSettings {
|
||||
public static int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public static boolean isEnabledDelay() {
|
||||
return enabledDelay;
|
||||
}
|
||||
|
||||
public static int getDelayLength() {
|
||||
return delayLength;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.hibiscusmc.hmccosmetics.listener;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
|
||||
import com.hibiscusmc.hmccosmetics.database.Database;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
@@ -11,16 +12,25 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class PlayerConnectionListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
CosmeticUser user = Database.get(event.getPlayer().getUniqueId());
|
||||
CosmeticUsers.addUser(user);
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
user.updateCosmetic();
|
||||
}, 2);
|
||||
Runnable run = () -> {
|
||||
CosmeticUser user = Database.get(event.getPlayer().getUniqueId());
|
||||
CosmeticUsers.addUser(user);
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Run User Join");
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> user.updateCosmetic(), 2);
|
||||
};
|
||||
|
||||
if (DatabaseSettings.isEnabledDelay()) {
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Delay Enabled with " + DatabaseSettings.getDelayLength() + " ticks");
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), run, DatabaseSettings.getDelayLength());
|
||||
} else {
|
||||
run.run();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package com.hibiscusmc.hmccosmetics.nms;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.entities.BalloonEntity;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface NMSHandler {
|
||||
|
||||
int getNextEntityId();
|
||||
@@ -23,7 +25,12 @@ public interface NMSHandler {
|
||||
|
||||
BalloonEntity spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType);
|
||||
|
||||
void sendPacket(Player player, Packet packet);
|
||||
void equipmentSlotUpdate(
|
||||
int entityId,
|
||||
CosmeticUser user,
|
||||
CosmeticSlot cosmeticSlot,
|
||||
List<Player> sendTo
|
||||
);
|
||||
|
||||
default boolean getSupported () {
|
||||
return false;
|
||||
|
||||
@@ -227,7 +227,6 @@ public class CosmeticUser {
|
||||
if (invisibleArmorstand == null) return;
|
||||
invisibleArmorstand.setHealth(0);
|
||||
invisibleArmorstand.remove();
|
||||
//invisibleArmorstand.remove(net.minecraft.world.entity.Entity.RemovalReason.DISCARDED);
|
||||
this.invisibleArmorstand = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,8 @@ package com.hibiscusmc.hmccosmetics.user;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
||||
@@ -2,16 +2,10 @@ package com.hibiscusmc.hmccosmetics.util.packets;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BasePacket {
|
||||
|
||||
public static void sendPacket(Player player, Packet<?> packet) {
|
||||
NMSHandlers.getHandler().sendPacket(player, packet);
|
||||
}
|
||||
|
||||
public static void sendPacket(Player player, PacketContainer packet) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
|
||||
@@ -5,28 +5,17 @@ import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.*;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerNamedEntitySpawn;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerPlayerInfo;
|
||||
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.ClientboundSetEquipmentPacket;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -55,7 +44,11 @@ public class PacketManager extends BasePacket {
|
||||
Player player,
|
||||
int gamemode
|
||||
) {
|
||||
sendPacket(player, new ClientboundGameEventPacket(ClientboundGameEventPacket.CHANGE_GAME_MODE, (float) gamemode));
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.GAME_STATE_CHANGE);
|
||||
packet.getGameStateIDs().write(0, 3);
|
||||
// Tells what event this is. This is a change gamemode event.
|
||||
packet.getFloat().write(0, (float) gamemode);
|
||||
sendPacket(player, packet);
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Gamemode Change sent to " + player + " to be " + gamemode);
|
||||
}
|
||||
|
||||
@@ -92,38 +85,10 @@ public class PacketManager extends BasePacket {
|
||||
CosmeticSlot cosmeticSlot,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
EquipmentSlot nmsSlot = null;
|
||||
ItemStack nmsItem = null;
|
||||
|
||||
if (cosmeticSlot == CosmeticSlot.BACKPACK || cosmeticSlot == CosmeticSlot.BALLOON) return;
|
||||
|
||||
if (!(user.getCosmetic(cosmeticSlot) instanceof CosmeticArmorType)) {
|
||||
NMSHandlers.getHandler().equipmentSlotUpdate(entityId, user, cosmeticSlot, sendTo);
|
||||
|
||||
nmsSlot = CraftEquipmentSlot.getNMS(InventoryUtils.getEquipmentSlot(cosmeticSlot));
|
||||
nmsItem = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.AIR));
|
||||
|
||||
Pair<EquipmentSlot, ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
|
||||
|
||||
List<Pair<EquipmentSlot, ItemStack>> pairs = Collections.singletonList(pair);
|
||||
|
||||
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
return;
|
||||
}
|
||||
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(cosmeticSlot);
|
||||
|
||||
// Converting EquipmentSlot and ItemStack to NMS ones.
|
||||
nmsSlot = CraftEquipmentSlot.getNMS(cosmeticArmor.getEquipSlot());
|
||||
nmsItem = CraftItemStack.asNMSCopy(user.getUserCosmeticItem(cosmeticArmor));
|
||||
|
||||
if (nmsSlot == null) return;
|
||||
|
||||
Pair<EquipmentSlot, ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
|
||||
|
||||
List<Pair<EquipmentSlot, ItemStack>> pairs = Collections.singletonList(pair);
|
||||
|
||||
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
public static void armorStandMetaPacket(
|
||||
@@ -230,7 +195,7 @@ public class PacketManager extends BasePacket {
|
||||
*/
|
||||
public static void sendEntityDestroyPacket(final int entityId, List<Player> sendTo) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
|
||||
packet.getModifier().write(0, new IntArrayList(new int[]{entityId}));
|
||||
packet.getModifier().write(0, new int[]{entityId});
|
||||
for (final Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user