mirror of
https://github.com/GeyserExtensionists/GeyserModelEnginePackGenerator.git
synced 2025-12-20 07:29:29 +00:00
add reload command(geysermodelenginepackgenerator reload)
This commit is contained in:
@@ -1,10 +1,16 @@
|
|||||||
package re.imc.geysermodelenginepackgenerator;
|
package re.imc.geysermodelenginepackgenerator;
|
||||||
|
|
||||||
import me.zimzaza4.geyserutils.geyser.GeyserUtils;
|
import me.zimzaza4.geyserutils.geyser.GeyserUtils;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.geysermc.event.subscribe.Subscribe;
|
import org.geysermc.event.subscribe.Subscribe;
|
||||||
|
import org.geysermc.geyser.api.command.Command;
|
||||||
|
import org.geysermc.geyser.api.command.CommandExecutor;
|
||||||
|
import org.geysermc.geyser.api.command.CommandSource;
|
||||||
|
import org.geysermc.geyser.api.event.lifecycle.GeyserDefineCommandsEvent;
|
||||||
import org.geysermc.geyser.api.event.lifecycle.GeyserLoadResourcePacksEvent;
|
import org.geysermc.geyser.api.event.lifecycle.GeyserLoadResourcePacksEvent;
|
||||||
import org.geysermc.geyser.api.event.lifecycle.GeyserPreInitializeEvent;
|
import org.geysermc.geyser.api.event.lifecycle.GeyserPreInitializeEvent;
|
||||||
import org.geysermc.geyser.api.extension.Extension;
|
import org.geysermc.geyser.api.extension.Extension;
|
||||||
|
import org.geysermc.geyser.api.extension.ExtensionLogger;
|
||||||
import re.imc.geysermodelenginepackgenerator.generator.Entity;
|
import re.imc.geysermodelenginepackgenerator.generator.Entity;
|
||||||
import re.imc.geysermodelenginepackgenerator.generator.Geometry;
|
import re.imc.geysermodelenginepackgenerator.generator.Geometry;
|
||||||
import re.imc.geysermodelenginepackgenerator.util.ZipUtil;
|
import re.imc.geysermodelenginepackgenerator.util.ZipUtil;
|
||||||
@@ -15,18 +21,42 @@ import java.nio.channels.FileChannel;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.List;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
public class ExtensionMain implements Extension {
|
public class ExtensionMain implements Extension {
|
||||||
|
|
||||||
private File source;
|
private File source;
|
||||||
|
|
||||||
|
public static ExtensionLogger logger;
|
||||||
Path generatedPackZip;
|
Path generatedPackZip;
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onLoad(GeyserPreInitializeEvent event) {
|
public void onLoad(GeyserPreInitializeEvent event) {
|
||||||
source = dataFolder().resolve("input").toFile();
|
source = dataFolder().resolve("input").toFile();
|
||||||
source.mkdirs();
|
source.mkdirs();
|
||||||
|
logger = logger();
|
||||||
|
loadConfig();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onDefineCommand(GeyserDefineCommandsEvent event) {
|
||||||
|
event.register(Command.builder(this)
|
||||||
|
.name("reload")
|
||||||
|
.source(CommandSource.class)
|
||||||
|
.executableOnConsole(true)
|
||||||
|
.description("GeyserModelPackGenerator Reload Command")
|
||||||
|
.suggestedOpOnly(true)
|
||||||
|
.permission("geysermodelenginepackgenerator.admin")
|
||||||
|
.executor((source, command, args) -> {
|
||||||
|
loadConfig();
|
||||||
|
source.sendMessage("GeyserModelEnginePackGenerator reloaded!");
|
||||||
|
})
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadConfig() {
|
||||||
|
|
||||||
File generatedPack = dataFolder().resolve("generated_pack").toFile();
|
File generatedPack = dataFolder().resolve("generated_pack").toFile();
|
||||||
|
|
||||||
@@ -36,7 +66,6 @@ public class ExtensionMain implements Extension {
|
|||||||
|
|
||||||
try (ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(generatedPackZip))) {
|
try (ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(generatedPackZip))) {
|
||||||
ZipUtil.compressFolder(generatedPack, null, zipOutputStream);
|
ZipUtil.compressFolder(generatedPack, null, zipOutputStream);
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ public class GeneratorMain {
|
|||||||
|
|
||||||
public static void generateFromZip(String currentPath, String modelId, ZipFile zip) {
|
public static void generateFromZip(String currentPath, String modelId, ZipFile zip) {
|
||||||
Entity entity = new Entity(modelId);
|
Entity entity = new Entity(modelId);
|
||||||
|
if (entityMap.containsKey(modelId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
ModelConfig modelConfig = new ModelConfig();
|
ModelConfig modelConfig = new ModelConfig();
|
||||||
ZipEntry textureConfigFile = null;
|
ZipEntry textureConfigFile = null;
|
||||||
for (Iterator<? extends ZipEntry> it = zip.entries().asIterator(); it.hasNext(); ) {
|
for (Iterator<? extends ZipEntry> it = zip.entries().asIterator(); it.hasNext(); ) {
|
||||||
@@ -141,6 +144,9 @@ public class GeneratorMain {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (entityMap.containsKey(modelId)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (e.getName().endsWith(".png")) {
|
if (e.getName().endsWith(".png")) {
|
||||||
String textureName = e.getName().replace(".png", "");
|
String textureName = e.getName().replace(".png", "");
|
||||||
Set<String> bindingBones = new HashSet<>();
|
Set<String> bindingBones = new HashSet<>();
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ import java.util.*;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class Entity {
|
public class Entity {
|
||||||
|
|
||||||
|
public static final Set<String> REGISTERED_ENTITIES = new HashSet<>();
|
||||||
|
|
||||||
public static final String TEMPLATE = """
|
public static final String TEMPLATE = """
|
||||||
{
|
{
|
||||||
"format_version": "1.10.0",
|
"format_version": "1.10.0",
|
||||||
@@ -116,7 +119,14 @@ public class Entity {
|
|||||||
|
|
||||||
public void register() {
|
public void register() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String id = "modelengine:" + modelId;
|
String id = "modelengine:" + modelId;
|
||||||
|
boolean registered = REGISTERED_ENTITIES.contains(id);
|
||||||
|
if (registered) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
REGISTERED_ENTITIES.add(id);
|
||||||
GeyserUtils.addCustomEntity(id);
|
GeyserUtils.addCustomEntity(id);
|
||||||
if (geometry == null) {
|
if (geometry == null) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user