diff --git a/src/main/java/re/imc/geysermodelengine/GeyserModelEngine.java b/src/main/java/re/imc/geysermodelengine/GeyserModelEngine.java index 54c7918..398e125 100644 --- a/src/main/java/re/imc/geysermodelengine/GeyserModelEngine.java +++ b/src/main/java/re/imc/geysermodelengine/GeyserModelEngine.java @@ -26,10 +26,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; public final class GeyserModelEngine extends JavaPlugin { @@ -68,6 +65,7 @@ public final class GeyserModelEngine extends JavaPlugin { @Getter private ScheduledExecutorService scheduler; + private ScheduledFuture updateTask; @Override public void onLoad() { @@ -78,20 +76,6 @@ public void onLoad() { @Override public void onEnable() { PacketEvents.getAPI().init(); - saveDefaultConfig(); - // alwaysSendSkin = getConfig().getBoolean("always-send-skin"); - sendDelay = getConfig().getInt("data-send-delay", 0); - scheduler = Executors.newScheduledThreadPool(getConfig().getInt("thread-pool-size", 4)); - viewDistance = getConfig().getInt("entity-view-distance", 60); - debug = getConfig().getBoolean("debug", false); - joinSendDelay = getConfig().getInt("join-send-delay", 20); - entityPositionUpdatePeriod = getConfig().getLong("entity-position-update-period", 35); - enablePartVisibilityModels.addAll(getConfig().getStringList("enable-part-visibility-models")); - if (joinSendDelay > 0) { - joinedPlayer = CacheBuilder.newBuilder() - .expireAfterWrite(joinSendDelay * 50L, TimeUnit.MILLISECONDS).build(); - } - instance = this; PacketEvents.getAPI().getEventManager().registerListener(new MountPacketListener(), PacketListenerPriority.NORMAL); /* scheduler.scheduleAtFixedRate(() -> { @@ -106,17 +90,7 @@ public void onEnable() { */ - scheduler.scheduleWithFixedDelay(() -> { - try { - for (Map models : ModelEntity.ENTITIES.values()) { - models.values().forEach(model -> model.getTask().updateEntityProperties(model.getViewers(), false)); - } - } catch (Throwable t) { - t.printStackTrace(); - } - }, 10, entityPositionUpdatePeriod, TimeUnit.MILLISECONDS); - - + reload(); getCommand("geysermodelengine").setExecutor(new ReloadCommand(this)); Bukkit.getPluginManager().registerEvents(new ModelListener(), this); Bukkit.getScheduler() @@ -140,6 +114,36 @@ public void onEnable() { BedrockMountControl.startTask(); } + public void reload() { + saveDefaultConfig(); + // alwaysSendSkin = getConfig().getBoolean("always-send-skin"); + sendDelay = getConfig().getInt("data-send-delay", 0); + scheduler = Executors.newScheduledThreadPool(getConfig().getInt("thread-pool-size", 4)); + viewDistance = getConfig().getInt("entity-view-distance", 60); + debug = getConfig().getBoolean("debug", false); + joinSendDelay = getConfig().getInt("join-send-delay", 20); + entityPositionUpdatePeriod = getConfig().getLong("entity-position-update-period", 35); + enablePartVisibilityModels.addAll(getConfig().getStringList("enable-part-visibility-models")); + if (joinSendDelay > 0) { + joinedPlayer = CacheBuilder.newBuilder() + .expireAfterWrite(joinSendDelay * 50L, TimeUnit.MILLISECONDS).build(); + } + instance = this; + if (updateTask != null) { + updateTask.cancel(true); + } + + updateTask = scheduler.scheduleWithFixedDelay(() -> { + try { + for (Map models : ModelEntity.ENTITIES.values()) { + models.values().forEach(model -> model.getTask().updateEntityProperties(model.getViewers(), false)); + } + } catch (Throwable t) { + t.printStackTrace(); + } + }, 10, entityPositionUpdatePeriod, TimeUnit.MILLISECONDS); + } + @Override public void onDisable() { PacketEvents.getAPI().terminate(); diff --git a/src/main/java/re/imc/geysermodelengine/commands/ReloadCommand.java b/src/main/java/re/imc/geysermodelengine/commands/ReloadCommand.java index 660948d..418b640 100644 --- a/src/main/java/re/imc/geysermodelengine/commands/ReloadCommand.java +++ b/src/main/java/re/imc/geysermodelengine/commands/ReloadCommand.java @@ -23,7 +23,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } plugin.reloadConfig(); - plugin.onEnable(); + plugin.reload(); sender.sendMessage("§aGeyserModelEngine configuration reloaded!"); return true; diff --git a/src/main/java/re/imc/geysermodelengine/model/EntityTask.java b/src/main/java/re/imc/geysermodelengine/model/EntityTask.java index 44345a0..43ff631 100644 --- a/src/main/java/re/imc/geysermodelengine/model/EntityTask.java +++ b/src/main/java/re/imc/geysermodelengine/model/EntityTask.java @@ -149,8 +149,8 @@ public void sendEntityData(Player player, int delay) { sendScale(Collections.singleton(player), true); sendColor(Collections.singleton(player), true); updateEntityProperties(Collections.singleton(player), true); - }, 1000, TimeUnit.MILLISECONDS); - }, 100, TimeUnit.MILLISECONDS); + }, 500, TimeUnit.MILLISECONDS); + }, delay * 50L, TimeUnit.MILLISECONDS); } public void sendScale(Collection players, boolean firstSend) { diff --git a/src/main/java/re/imc/geysermodelengine/packet/entity/PacketEntity.java b/src/main/java/re/imc/geysermodelengine/packet/entity/PacketEntity.java index 4f6210e..4ae553d 100644 --- a/src/main/java/re/imc/geysermodelengine/packet/entity/PacketEntity.java +++ b/src/main/java/re/imc/geysermodelengine/packet/entity/PacketEntity.java @@ -76,7 +76,7 @@ public boolean isValid() { public void sendSpawnPacket(Collection players) { // EntitySpawnPacket packet = new EntitySpawnPacket(id, uuid, type, location); // EntityMetadataPacket metadataPacket = new EntityMetadataPacket(id); - WrapperPlayServerSpawnEntity spawnEntity = new WrapperPlayServerSpawnEntity(id, uuid, EntityTypes.BAT, SpigotConversionUtil.fromBukkitLocation(location), location.getYaw(), 0, null); + WrapperPlayServerSpawnEntity spawnEntity = new WrapperPlayServerSpawnEntity(id, uuid, type, SpigotConversionUtil.fromBukkitLocation(location), location.getYaw(), 0, null); players.forEach(player -> PacketEvents.getAPI().getPlayerManager().sendPacket(player, spawnEntity)); }