Skip to content

Commit

Permalink
3.6-M1
Browse files Browse the repository at this point in the history
  • Loading branch information
Dituon committed Jul 12, 2022
1 parent 4caee50 commit 3e8470a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ apply plugin: "java"


group = 'xmmt.dituon'
version = '3.5'
version = '3.6-M1'

repositories {
maven { url 'https://maven.aliyun.com/repository/public' }
Expand Down
2 changes: 1 addition & 1 deletion config/xmmt.dituon.petpet/PetPet.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
content:
version: 3.5
version: 3.6
command: pet
probability: 30
antialias: true
Expand Down
32 changes: 25 additions & 7 deletions src/main/java/xmmt/dituon/plugin/DataUpdater.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package xmmt.dituon.plugin;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import xmmt.dituon.share.BasePetService;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class DataUpdater {
final static String repositoryUrl = "https://dituon.github.io/petpet/";
Expand All @@ -21,7 +23,9 @@ public static void autoUpdate() {
}

public static void updateData() {
List<String> newPetList = UpdateIndex.getUpdate(getUrlText(repositoryUrl + "index.json")).getDataList();
System.out.println("开始更新PetData");
UpdateIndex index = UpdateIndex.getUpdate(Objects.requireNonNull(getUrlText(repositoryUrl + "index.json")));
List<String> newPetList = index.getDataList();
for (String pet : newPetList) {
if (Petpet.pluginPetService.getDataMap().containsKey(pet)) continue;
String petDataPath = "data/xmmt.dituon.petpet/" + pet;
Expand All @@ -33,11 +37,25 @@ public static void updateData() {
while (saveAs(petDataPath, i + ".png")) i++;
System.out.println("PetData/" + pet + "下载成功 (length:" + i + ')');
}

String fontsPath = "data/xmmt.dituon.petpet/" + BasePetService.FONTS_FOLDER;

List<String> localFonts = Arrays.stream(Objects.requireNonNull(new File(fontsPath).listFiles()))
.map(File::getName).distinct().collect(Collectors.toList());
index.getFontList().forEach(font -> {
if (localFonts.contains(font)) return;
if (!saveAs(fontsPath, font)) {
System.out.println("无法从远程仓库下载PetFont: " + fontsPath);
return;
}
System.out.println("PetFont/" + font + "下载成功");
});

System.out.println("PetData更新完毕, 请重启Mirai");
}

public static boolean checkUpdate() {
UpdateIndex update = UpdateIndex.getUpdate(getUrlText(repositoryUrl + "index.json"));
UpdateIndex update = UpdateIndex.getUpdate(Objects.requireNonNull(getUrlText(repositoryUrl + "index.json")));
if (Petpet.VERSION != update.getVersion()) System.out.println("PetpetPlugin可更新到最新版本: " + update.getVersion());
for (String pet : update.getDataList()) {
if (Petpet.pluginPetService.getDataMap().containsKey(pet)) continue;
Expand All @@ -53,7 +71,7 @@ private static String getUrlText(String url) {
connection.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));
StringBuilder str = new StringBuilder();
String line = "";
String line;
while ((line = reader.readLine()) != null) str.append(line);
reader.close();
connection.disconnect();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/xmmt/dituon/plugin/Petpet.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

public final class Petpet extends JavaPlugin {
public static final Petpet INSTANCE = new Petpet();
public static final float VERSION = 3.5F;
public static final float VERSION = 3.6F;

ArrayList<Group> disabledGroup = new ArrayList<>();
public static PluginPetService pluginPetService;
Expand Down Expand Up @@ -48,7 +48,7 @@ public void onEnable() {

getLogger().info("\n _ _ \n _ __ ___| |_ _ __ ___| |_ \n" +
" | '_ \\ / _ \\ __| | '_ \\ / _ \\ __|\n | |_) | __/ |_ | |_) | __/ |_ \n" +
" | .__/ \\___|\\__| | .__/ \\___|\\__|\n |_| |_| ");
" | .__/ \\___|\\__| | .__/ \\___|\\__|\n |_| |_| \n");

GlobalEventChannel.INSTANCE.subscribeAlways(GroupMessageEvent.class, this::onGroupMessage);
GlobalEventChannel.INSTANCE.subscribeAlways(NudgeEvent.class, this::onNudge);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/xmmt/dituon/plugin/PluginConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ fun PluginConfig.toBaseServiceConfig(): BaseServiceConfig {
@Serializable
data class UpdateIndex(
val version: Float,
val dataList: List<String>
val dataList: List<String>,
val fontList: List<String>,
) {
companion object {
@JvmStatic
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/xmmt/dituon/share/BasePetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


public class BasePetService {
private static final String FONTS_FOLDER = "fonts";
public static final String FONTS_FOLDER = "fonts";
protected boolean antialias = true;

protected File dataRoot;
Expand Down

0 comments on commit 3e8470a

Please sign in to comment.