Skip to content

Commit

Permalink
fix reload command
Browse files Browse the repository at this point in the history
  • Loading branch information
zimzaza4 committed Dec 22, 2024
1 parent edb962f commit 5936210
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 33 deletions.
62 changes: 33 additions & 29 deletions src/main/java/re/imc/geysermodelengine/GeyserModelEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -68,6 +65,7 @@ public final class GeyserModelEngine extends JavaPlugin {

@Getter
private ScheduledExecutorService scheduler;
private ScheduledFuture<?> updateTask;

@Override
public void onLoad() {
Expand All @@ -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(() -> {
Expand All @@ -106,17 +90,7 @@ public void onEnable() {
*/

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();
}
}, 10, entityPositionUpdatePeriod, TimeUnit.MILLISECONDS);


reload();
getCommand("geysermodelengine").setExecutor(new ReloadCommand(this));
Bukkit.getPluginManager().registerEvents(new ModelListener(), this);
Bukkit.getScheduler()
Expand All @@ -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<ActiveModel, ModelEntity> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/re/imc/geysermodelengine/model/EntityTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Player> players, boolean firstSend) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public boolean isValid() {
public void sendSpawnPacket(Collection<Player> 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));
}

Expand Down

0 comments on commit 5936210

Please sign in to comment.