mirror of
https://github.com/xSquishyLiam/mc-GeyserModelEngine-plugin.git
synced 2025-12-19 14:59:19 +00:00
Added some fixes and improved schedulers - still waiting for 1.21.8 support
This commit is contained in:
8
.idea/workspace.xml
generated
8
.idea/workspace.xml
generated
@@ -4,7 +4,10 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="ff2e9770-ec88-4715-adeb-b9dbda130e1a" name="Changes" comment="" />
|
||||
<list default="true" id="ff2e9770-ec88-4715-adeb-b9dbda130e1a" name="Changes" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/build.gradle.kts" beforeDir="false" afterPath="$PROJECT_DIR$/build.gradle.kts" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
@@ -60,6 +63,9 @@
|
||||
<component name="MavenRunner">
|
||||
<option name="delegateBuildToMaven" value="true" />
|
||||
</component>
|
||||
<component name="ProblemsViewState">
|
||||
<option name="selectedTabId" value="DEPENDENCY_CHECKER_PROBLEMS_TAB" />
|
||||
</component>
|
||||
<component name="ProjectColorInfo">{
|
||||
"associatedIndex": 8
|
||||
}</component>
|
||||
|
||||
@@ -21,15 +21,15 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
compileOnly("io.papermc.paper:paper-api:1.21.7-R0.1-SNAPSHOT")
|
||||
|
||||
implementation("dev.jorel:commandapi-bukkit-shade-mojang-mapped:10.1.1")
|
||||
|
||||
compileOnly("com.ticxo.modelengine:ModelEngine:R4.0.4")
|
||||
compileOnly("com.ticxo.modelengine:ModelEngine:R4.0.9")
|
||||
|
||||
compileOnly(files("libs/geyserutils-spigot-1.0-SNAPSHOT.jar"))
|
||||
compileOnly("org.geysermc.floodgate:api:2.2.4-SNAPSHOT")
|
||||
|
||||
implementation("com.github.retrooper:packetevents-spigot:2.9.1")
|
||||
|
||||
implementation("com.github.retrooper:packetevents-spigot:2.9.3")
|
||||
|
||||
implementation("org.reflections:reflections:0.10.2")
|
||||
}
|
||||
@@ -42,10 +42,6 @@ tasks.compileJava {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
tasks.jar {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
relocate("dev.jorel.commandapi", "re.imc.geysermodelengine.libs.commandapi")
|
||||
|
||||
@@ -56,5 +52,6 @@ tasks.shadowJar {
|
||||
}
|
||||
|
||||
tasks.jar {
|
||||
enabled = false
|
||||
dependsOn(tasks.shadowJar)
|
||||
}
|
||||
@@ -30,6 +30,8 @@ public class GeyserModelEngine extends JavaPlugin {
|
||||
private ModelManager modelManager;
|
||||
private EntityTaskManager entityTaskManager;
|
||||
|
||||
private ScheduledExecutorService schedulerPool;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this));
|
||||
@@ -77,6 +79,8 @@ public class GeyserModelEngine extends JavaPlugin {
|
||||
}
|
||||
|
||||
private void loadRunnables() {
|
||||
this.schedulerPool = Executors.newScheduledThreadPool(configManager.getConfig().getInt("thread-pool-size", 4));
|
||||
|
||||
Bukkit.getAsyncScheduler().runAtFixedRate(this, new UpdateTaskRunnable(this), 10, configManager.getConfig().getLong("entity-position-update-period", 35), TimeUnit.MILLISECONDS);
|
||||
Bukkit.getAsyncScheduler().runAtFixedRate(this, new BedrockMountControlRunnable(this), 1, 1, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
@@ -96,4 +100,8 @@ public class GeyserModelEngine extends JavaPlugin {
|
||||
public EntityTaskManager getEntityTaskManager() {
|
||||
return entityTaskManager;
|
||||
}
|
||||
|
||||
public ScheduledExecutorService getSchedulerPool() {
|
||||
return schedulerPool;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,12 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.world.WorldInitEvent;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
import org.geysermc.floodgate.api.FloodgateApi;
|
||||
import re.imc.geysermodelengine.GeyserModelEngine;
|
||||
import re.imc.geysermodelengine.managers.model.data.ModelEntityData;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ModelListener implements Listener {
|
||||
|
||||
@@ -63,12 +65,15 @@ public class ModelListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
plugin.getModelManager().getPlayerJoinedCache().add(player.getUniqueId());
|
||||
if (!FloodgateApi.getInstance().isFloodgatePlayer(player.getUniqueId())) return;
|
||||
//TODO temp fix bc like why? - the issue is when a player logs out and the mob is there, the player logs back in sometimes it can display as a pig only
|
||||
Bukkit.getAsyncScheduler().runDelayed(plugin, scheduledTask -> plugin.getModelManager().getPlayerJoinedCache().add(player.getUniqueId()), 10, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!FloodgateApi.getInstance().isFloodgatePlayer(player.getUniqueId())) return;
|
||||
plugin.getModelManager().getPlayerJoinedCache().remove(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,9 +60,7 @@ public class EntityTaskManager {
|
||||
for (Player player : players) {
|
||||
EntityUtils.sendCustomScale(player, model.getEntity().getEntityId(), average);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
// ignore
|
||||
}
|
||||
} catch (Throwable ignored) {}
|
||||
}
|
||||
|
||||
public void sendColor(ModelEntityData model, Collection<Player> players, Color lastColor, boolean firstSend) {
|
||||
@@ -82,10 +80,9 @@ public class EntityTaskManager {
|
||||
|
||||
public void checkViewers(ModelEntityData model, Set<Player> viewers) {
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (FloodgateApi.getInstance().isFloodgatePlayer(onlinePlayer.getUniqueId())) {
|
||||
if (!FloodgateApi.getInstance().isFloodgatePlayer(onlinePlayer.getUniqueId())) continue;
|
||||
|
||||
if (canSee(onlinePlayer, model.getEntity())) {
|
||||
|
||||
if (!viewers.contains(onlinePlayer)) {
|
||||
sendSpawnPacket(model, onlinePlayer);
|
||||
viewers.add(onlinePlayer);
|
||||
@@ -98,8 +95,8 @@ public class EntityTaskManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Issue here - start: See ModelListener.class and look at function onPlayerJoin
|
||||
private void sendSpawnPacket(ModelEntityData model, Player onlinePlayer) {
|
||||
EntityTaskRunnable task = model.getEntityTask();
|
||||
boolean firstJoined = !plugin.getModelManager().getPlayerJoinedCache().contains(onlinePlayer.getUniqueId());
|
||||
@@ -125,6 +122,7 @@ public class EntityTaskManager {
|
||||
|
||||
return true;
|
||||
}
|
||||
// Issue here - end
|
||||
|
||||
public void sendHitBoxToAll(ModelEntityData model) {
|
||||
for (Player viewer : model.getViewers()) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.ticxo.modelengine.api.model.ActiveModel;
|
||||
import com.ticxo.modelengine.api.model.ModeledEntity;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import re.imc.geysermodelengine.GeyserModelEngine;
|
||||
@@ -12,7 +11,6 @@ import re.imc.geysermodelengine.packet.entity.PacketEntity;
|
||||
import re.imc.geysermodelengine.runnables.EntityTaskRunnable;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ModelEntityData {
|
||||
|
||||
@@ -50,7 +48,7 @@ public class ModelEntityData {
|
||||
|
||||
public void runEntityTask() {
|
||||
entityTask = new EntityTaskRunnable(plugin, this);
|
||||
Bukkit.getAsyncScheduler().runAtFixedRate(plugin, entityTask, 0, 20, TimeUnit.MILLISECONDS);
|
||||
entityTask.run();
|
||||
}
|
||||
|
||||
public PacketEntity getEntity() {
|
||||
|
||||
@@ -8,9 +8,7 @@ import com.ticxo.modelengine.api.generator.blueprint.BlueprintBone;
|
||||
import com.ticxo.modelengine.api.model.ActiveModel;
|
||||
import com.ticxo.modelengine.api.model.ModeledEntity;
|
||||
import com.ticxo.modelengine.api.model.bone.ModelBone;
|
||||
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
|
||||
import me.zimzaza4.geyserutils.spigot.api.EntityUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import re.imc.geysermodelengine.GeyserModelEngine;
|
||||
import re.imc.geysermodelengine.managers.model.data.ModelEntityData;
|
||||
@@ -21,10 +19,10 @@ import java.awt.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class EntityTaskRunnable implements Consumer<ScheduledTask> {
|
||||
public class EntityTaskRunnable {
|
||||
|
||||
private final GeyserModelEngine plugin;
|
||||
|
||||
@@ -43,16 +41,27 @@ public class EntityTaskRunnable implements Consumer<ScheduledTask> {
|
||||
|
||||
private final BooleanPacker booleanPacker = new BooleanPacker();
|
||||
|
||||
private ScheduledFuture scheduledFuture;
|
||||
|
||||
public EntityTaskRunnable(GeyserModelEngine plugin, ModelEntityData model) {
|
||||
this.plugin = plugin;
|
||||
|
||||
this.model = model;
|
||||
|
||||
plugin.getEntityTaskManager().sendHitBoxToAll(model);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ScheduledTask scheduledTask) {
|
||||
public void run() {
|
||||
plugin.getEntityTaskManager().sendHitBoxToAll(model);
|
||||
|
||||
Runnable asyncTask = () -> {
|
||||
try {
|
||||
runAsync();
|
||||
} catch (Throwable ignored) {}
|
||||
};
|
||||
|
||||
scheduledFuture = plugin.getSchedulerPool().scheduleAtFixedRate(asyncTask, 0, 20, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public void runAsync() {
|
||||
plugin.getEntityTaskManager().checkViewers(model, model.getViewers());
|
||||
|
||||
PacketEntity entity = model.getEntity();
|
||||
@@ -70,7 +79,7 @@ public class EntityTaskRunnable implements Consumer<ScheduledTask> {
|
||||
|
||||
plugin.getModelManager().getEntitiesCache().remove(modeledEntity.getBase().getEntityId());
|
||||
plugin.getModelManager().getModelEntitiesCache().remove(entity.getEntityId());
|
||||
scheduledTask.cancel();
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -96,20 +105,25 @@ public class EntityTaskRunnable implements Consumer<ScheduledTask> {
|
||||
plugin.getEntityTaskManager().sendColor(model, viewers, lastColor, false);
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
scheduledFuture.cancel(true);
|
||||
}
|
||||
|
||||
public void sendEntityData(ModelEntityData model, Player player, int delay) {
|
||||
//TODO with ModelEngine, you can define the namespace inside the config, make an option to change it here as well? if i'm right about this
|
||||
EntityUtils.setCustomEntity(player, model.getEntity().getEntityId(), "modelengine:" + model.getActiveModel().getBlueprint().getName().toLowerCase());
|
||||
|
||||
Bukkit.getAsyncScheduler().runDelayed(plugin, scheduledTask -> {
|
||||
plugin.getSchedulerPool().schedule(() -> {
|
||||
model.getEntity().sendSpawnPacket(Collections.singletonList(player));
|
||||
|
||||
Bukkit.getAsyncScheduler().runDelayed(plugin, scheduledTask1 -> {
|
||||
plugin.getSchedulerPool().schedule(() -> {
|
||||
plugin.getEntityTaskManager().sendHitBox(model, player);
|
||||
plugin.getEntityTaskManager().sendScale(model, Collections.singleton(player), lastScale, true);
|
||||
plugin.getEntityTaskManager().sendColor(model, Collections.singleton(player), lastColor, true);
|
||||
|
||||
updateEntityProperties(model, Collections.singleton(player), true);
|
||||
}, 500, TimeUnit.MILLISECONDS);
|
||||
}, delay * 50L, TimeUnit.MILLISECONDS);
|
||||
}, 500, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public void updateEntityProperties(ModelEntityData model, Collection<Player> players, boolean firstSend, String... forceAnims) {
|
||||
@@ -255,4 +269,8 @@ public class EntityTaskRunnable implements Consumer<ScheduledTask> {
|
||||
public Cache<String, Boolean> getLastPlayedAnim() {
|
||||
return lastPlayedAnim;
|
||||
}
|
||||
|
||||
public ScheduledFuture getScheduledFuture() {
|
||||
return scheduledFuture;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ data-send-delay: 5
|
||||
entity-view-distance: 50
|
||||
join-send-delay: 20
|
||||
entity-position-update-period: 35
|
||||
thread-pool-size: 4
|
||||
model-entity-type: BAT # must be a living entity
|
||||
enable-part-visibility-models:
|
||||
- example
|
||||
|
||||
Reference in New Issue
Block a user