mirror of
https://github.com/xSquishyLiam/mc-GeyserModelEngine-plugin.git
synced 2025-12-19 14:59:19 +00:00
huh
This commit is contained in:
@@ -69,7 +69,7 @@ public final class GeyserModelEngine extends JavaPlugin {
|
||||
private List<String> enablePartVisibilityModels = new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
private ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
|
||||
private ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(4);
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
@@ -108,10 +108,24 @@ public final class GeyserModelEngine extends JavaPlugin {
|
||||
|
||||
}, 100);
|
||||
|
||||
;
|
||||
|
||||
scheduler.scheduleAtFixedRate(() -> {
|
||||
try {
|
||||
for (Map<ActiveModel, ModelEntity> models : ModelEntity.ENTITIES.values()) {
|
||||
models.values().forEach(ModelEntity::teleportToModel);
|
||||
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}, 10, entityPositionUpdatePeriod, TimeUnit.MILLISECONDS);
|
||||
|
||||
|
||||
scheduler.scheduleWithFixedDelay(() -> {
|
||||
try {
|
||||
for (Map<ActiveModel, ModelEntity> models : ModelEntity.ENTITIES.values()) {
|
||||
models.values().forEach(model -> model.getTask().updateEntityProperties(model.getViewers(), false));
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
|
||||
@@ -114,16 +114,29 @@ public class ModelListener implements Listener {
|
||||
|
||||
task.playAnimation("attack", 55);
|
||||
}
|
||||
}|
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onAnimationPlay(AnimationPlayEvent event) {
|
||||
Map<ActiveModel, ModelEntity> map = ModelEntity.ENTITIES.get(event.getModel().getModeledEntity().getBase().getEntityId());
|
||||
if (map == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ModelEntity model = map.get(event.getModel());
|
||||
model.getTask().updateEntityProperties(model.getViewers(), false, event.getProperty().getName());
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onAnimationEnd(AnimationEndEvent event) {
|
||||
Map<ActiveModel, ModelEntity> map = ModelEntity.ENTITIES.get(event.getModel().getModeledEntity().getBase().getEntityId());
|
||||
if (map == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ModelEntity model = map.get(event.getModel());
|
||||
model.getTask().updateEntityProperties(model.getViewers(), false, event.getProperty().);
|
||||
}
|
||||
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
GeyserModelEngine.getInstance().getJoinedPlayer().put(event.getPlayer(), true);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package re.imc.geysermodelengine.model;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.ticxo.modelengine.api.animation.BlueprintAnimation;
|
||||
import com.ticxo.modelengine.api.animation.ModelState;
|
||||
import com.ticxo.modelengine.api.animation.handler.AnimationHandler;
|
||||
@@ -28,6 +29,7 @@ import re.imc.geysermodelengine.util.BooleanPacker;
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static re.imc.geysermodelengine.model.ModelEntity.ENTITIES;
|
||||
@@ -48,7 +50,7 @@ public class EntityTask {
|
||||
|
||||
float lastScale = -1.0f;
|
||||
Color lastColor = null;
|
||||
Map<String, Integer> lastIntSet = new HashMap<>();
|
||||
Map<String, Integer> lastIntSet = new ConcurrentHashMap<>();
|
||||
|
||||
// Map<String, Boolean> lastAnimPropertySet = new HashMap<>();
|
||||
private BukkitRunnable syncTask;
|
||||
@@ -110,7 +112,10 @@ public class EntityTask {
|
||||
// Optional<Player> player = viewers.stream().findAny();
|
||||
// if (player.isEmpty()) return
|
||||
|
||||
updateEntityProperties(viewers, false);
|
||||
if (viewers.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// do not actually use this, atleast bundle these up ;(
|
||||
sendScale(viewers, false);
|
||||
@@ -202,8 +207,9 @@ public class EntityTask {
|
||||
}
|
||||
|
||||
|
||||
public void updateEntityProperties(Collection<Player> players, boolean ignore) {
|
||||
public void updateEntityProperties(Collection<Player> players, boolean ignore, String... forceAnims) {
|
||||
int entity = model.getEntity().getEntityId();
|
||||
Set<String> forceAnimSet = Set.of(forceAnims);
|
||||
|
||||
Map<String, Boolean> boneUpdates = new HashMap<>();
|
||||
Map<String, Boolean> animUpdates = new HashMap<>();
|
||||
@@ -231,25 +237,23 @@ public class EntityTask {
|
||||
}
|
||||
|
||||
model.getActiveModel().getBlueprint().getAnimations().forEach((s, anim) -> {
|
||||
if (anim.isOverride() && model.getActiveModel().getAnimationHandler().isPlayingAnimation(s)) {
|
||||
if (anim.isOverride() && (model.getActiveModel().getAnimationHandler().isPlayingAnimation(s) || forceAnimSet.contains(s))) {
|
||||
overrideAnimUpdates.add(s);
|
||||
}
|
||||
});
|
||||
model.getActiveModel().getBlueprint().getAnimations().forEach((s, anim) -> {
|
||||
if (overrideAnimUpdates.isEmpty()) {
|
||||
animUpdates.put(s, model.getActiveModel().getAnimationHandler().isPlayingAnimation(s));
|
||||
animUpdates.put(s, model.getActiveModel().getAnimationHandler().isPlayingAnimation(s) || forceAnimSet.contains(s));
|
||||
} else {
|
||||
if (overrideAnimUpdates.contains(s)) {
|
||||
animUpdates.put(s, true);
|
||||
} else if (defaultAnims.contains(s)) {
|
||||
animUpdates.put(s, false);
|
||||
} else {
|
||||
animUpdates.put(s, model.getActiveModel().getAnimationHandler().isPlayingAnimation(s));
|
||||
animUpdates.put(s, model.getActiveModel().getAnimationHandler().isPlayingAnimation(s) || forceAnimSet.contains(s));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/*f
|
||||
if (!lastAnimProperty.equals(currentAnimProperty)) {
|
||||
|
||||
@@ -283,7 +287,8 @@ public class EntityTask {
|
||||
if (intUpdates.equals(lastIntSet)) {
|
||||
return;
|
||||
} else {
|
||||
lastIntSet = intUpdates;
|
||||
lastIntSet.clear();
|
||||
lastIntSet.putAll(intUpdates);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user