Skip to content

Commit

Permalink
添加NeoForge支持,添加HttpPost,优化API,删除bStats
Browse files Browse the repository at this point in the history
  • Loading branch information
CSneko committed Mar 30, 2024
1 parent e11890d commit be0145e
Show file tree
Hide file tree
Showing 15 changed files with 733 additions and 206 deletions.
43 changes: 38 additions & 5 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,7 @@ dependencies {
implementation 'net.byteflux:libby-nukkit:1.3.0'
implementation 'net.minecraftforge.gradle:ForgeGradle:6.0.14'
//implementation 'net.minecraftforge:forge:1.20-46.0.14'
implementation name: 'forge-1.20-46.0.14-universal'
implementation name: 'forge-1.20-46.0.14-userdev'
implementation name: 'fmlloader-1.20-46.0.14'
implementation name: 'fmlcore-1.20-46.0.14'
implementation name: 'javafmllanguage-1.20-46.0.14'
implementation name: 'eventbus-6.2.0'
implementation name: 'snakeyaml-2.2'
implementation name: 'synapse-api-1.0-SNAPSHOT'
implementation name: 'nukkit-1.0-SNAPSHOT'
implementation fileTree("libs")


}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.14.23

# Mod Properties
mod_version = 0.1.2
mod_version = 0.1.3
maven_group = com.crystalneko
archives_base_name = ctLibFabric

Expand Down
Binary file added libs/loader-2.0.17.jar
Binary file not shown.
8 changes: 0 additions & 8 deletions src/main/java/org/cneko/ctlib/bootstrap/ForgeBootstrap.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
package org.cneko.ctlib.bootstrap;


import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;


@Mod("ctlib")
public class ForgeBootstrap {
public ForgeBootstrap(){
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
modEventBus.addListener(this::setup);
}

private void setup(final FMLCommonSetupEvent event){

}
}
10 changes: 10 additions & 0 deletions src/main/java/org/cneko/ctlib/bootstrap/NeoForgeBootstrap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.cneko.ctlib.bootstrap;

import net.neoforged.fml.common.Mod;

@Mod("toneko")
public class NeoForgeBootstrap {
public NeoForgeBootstrap(){

}
}
181 changes: 175 additions & 6 deletions src/main/java/org/cneko/ctlib/common/file/JsonConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JsonConfiguration {
Expand All @@ -18,12 +20,12 @@ public class JsonConfiguration {

public JsonConfiguration(Path filePath) throws IOException {
this.filePath = filePath;
gson = new Gson(); // 初始化 Gson 对象
gson = new Gson();
configData = loadConfigData(filePath);
}

public JsonConfiguration(String jsonString) {
gson = new Gson(); // 初始化 Gson 对象
gson = new Gson();
if (jsonString == null) {
configData = new HashMap<>();
} else {
Expand All @@ -42,19 +44,177 @@ private Map<String, Object> loadConfigData(Path filePath) throws IOException {
}

public String getString(String key) {
return (String) configData.get(key);
Object value = get(key);
if (value instanceof String) {
return (String) value;
} else if (value instanceof Map || value instanceof List) {
return new Gson().toJson(value);
} else {
return null;
}
}

public int getInt(String key) {
return (int) configData.get(key);
try {
Object value = get(key);
return value instanceof Number ? ((Number) value).intValue() : 0;
} catch (Exception e) {
return 0;
}
}

public double getDouble(String key) {
return (double) configData.get(key);
try {
Object value = get(key);
return value instanceof Number ? ((Number) value).doubleValue() : 0;
} catch (Exception e) {
return 0;
}
}

public float getFloat(String key) {
try {
Object value = get(key);
return value instanceof Number ? ((Number) value).floatValue() : 0;
} catch (Exception e) {
return 0;
}
}

public boolean getBoolean(String key) {
try {
Object value = get(key);
return value instanceof Boolean ? (boolean) value : false;
} catch (Exception e) {
return false;
}
}

public boolean getBoolean(String key, boolean defaultValue) {
try {
Object value = get(key);
return value instanceof Boolean ? (boolean) value : defaultValue;
} catch (Exception e) {
return defaultValue;
}
}

public Object get(String key) {
return configData.get(key);
String[] keys = key.split("\\.");
Object value = configData;
for (String k : keys) {
if (value instanceof Map) {
value = ((Map<String, Object>) value).get(k);
} else if (value instanceof List && k.matches("\\d+")) {
int index = Integer.parseInt(k);
List<Object> list = (List<Object>) value;
if (index >= 0 && index < list.size()) {
value = list.get(index);
} else {
return null;
}
} else {
return null;
}
}
return value;
}

public ArrayList<String> getStringList(String key) {
Object value = get(key);
if (value instanceof List) {
ArrayList<String> list = new ArrayList<>();
for (Object obj : (List<?>) value) {
if (obj instanceof String) {
list.add((String) obj);
}
}
return list;
} else {
return new ArrayList<>();
}
}

public ArrayList<Integer> getIntList(String key) {
Object value = get(key);
if (value instanceof List) {
ArrayList<Integer> list = new ArrayList<>();
for (Object obj : (List<?>) value) {
if (obj instanceof Number) {
list.add(((Number) obj).intValue());
}
}
return list;
} else {
return new ArrayList<>();
}
}

public ArrayList<Double> getDoubleList(String key) {
Object value = get(key);
if (value instanceof List) {
ArrayList<Double> list = new ArrayList<>();
for (Object obj : (List<?>) value) {
if (obj instanceof Number) {
list.add(((Number) obj).doubleValue());
}
}
return list;
} else {
return new ArrayList<>();
}
}

public ArrayList<Float> getFloatList(String key) {
Object value = get(key);
if (value instanceof List) {
ArrayList<Float> list = new ArrayList<>();
for (Object obj : (List<?>) value) {
if (obj instanceof Number) {
list.add(((Number) obj).floatValue());
}
}
return list;
} else {
return new ArrayList<>();
}
}

public ArrayList<JsonConfiguration> getJsonList(String key) {
Object value = get(key);
if (value instanceof List) {
ArrayList<JsonConfiguration> list = new ArrayList<>();
for (Object obj : (List<?>) value) {
if (obj instanceof Map) {
list.add(new JsonConfiguration(new Gson().toJson(obj)));
}
}
return list;
} else {
return new ArrayList<>();
}
}

public ArrayList<Object> getList(String key) {
Object value = get(key);
if (value instanceof List) {
return new ArrayList<>((List<?>) value);
} else {
return new ArrayList<>();
}
}

public boolean contains(String key) {
return get(key) != null;
}

public JsonConfiguration getJsonConfiguration(String key) {
Object value = get(key);
if (value instanceof Map) {
return new JsonConfiguration(new Gson().toJson(value));
} else {
return null;
}
}

public void set(String key, Object value) {
Expand All @@ -66,4 +226,13 @@ public void save() throws IOException {
gson.toJson(configData, writer);
}
}

@Override
public String toString() {
return gson.toJson(configData);
}
public boolean equals(Object obj) {
return obj.toString().equals(this.toString());
}

}
Loading

0 comments on commit be0145e

Please sign in to comment.