Skip to content

Commit

Permalink
v3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
MORIMORI0317 committed May 8, 2022
1 parent a365ecf commit d6a7eb9
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,19 @@ public void render(PoseStack poseStack, float f, int mouseX, int mouseY) {
tx = CONNECTING_CHECKING;
py = 0;
}
if (tx != null)
drawSmartFixedWidthText(poseStack, tx, st, getStartY() + 23 + py, 270);
if (tx != null) drawSmartFixedWidthText(poseStack, tx, st, getStartY() + 23 + py, 270);

if (canUpload()) {
if (!isUploading())
drawSmartText(poseStack, DROP_INFO_TEXT, st, getStartY() + 120);
if (UPLOAD_INFO_TEXT != null)
drawSmartText(poseStack, UPLOAD_INFO_TEXT, st, getStartY() + 43);
if (!isUploading()) drawSmartText(poseStack, DROP_INFO_TEXT, st, getStartY() + 120);
if (UPLOAD_INFO_TEXT != null) drawSmartText(poseStack, UPLOAD_INFO_TEXT, st, getStartY() + 43);
if (UPLOAD_ERROR_TEXT != null && !isUploading())
drawSmartText(poseStack, UPLOAD_ERROR_TEXT, st, getStartY() + 83, 0xFFFF0000);

drawSmartFixedWidthText(poseStack, HOW_TEXT, st, getStartY() + 53, 270, 0xFF0000FF);
drawSmartFixedWidthText(poseStack, WARNING_TEXT, st, getStartY() + 63, 270, 0xFFFF0000);
drawSmartFixedWidthText(poseStack, RESPONSIBILITY_TEXT, st, getStartY() + 73, 270, 0xFFFF0000);

if (isUploading())
drawSmartText(poseStack, UPLOADING_TEXT, st, getStartY() + 83);
if (isUploading()) drawSmartText(poseStack, UPLOADING_TEXT, st, getStartY() + 83);
}
}

Expand Down Expand Up @@ -280,25 +276,20 @@ public void run() {
}
if ("Ok".equalsIgnoreCase(status)) {
var name = "No Name";
if (lastJo.has("Name"))
name = lastJo.get("Name").getAsString();
if (lastJo.has("Name")) name = lastJo.get("Name").getAsString();
RELAY_SERVER_NAME_TEXT = new TextComponent(name);

JsonObject time = null;
if (lastJo.has("Time"))
time = lastJo.getAsJsonObject("Time");
if (lastJo.has("Time")) time = lastJo.getAsJsonObject("Time");
long rt = 0;
if (time != null && time.has("ResponseSpeed"))
rt = time.get("ResponseSpeed").getAsLong();
if (time != null && time.has("ResponseSpeed")) rt = time.get("ResponseSpeed").getAsLong();
if (time != null && time.has("ResponseSpeed"))
SERVER_STATUS_TEXT = new TranslatableComponent("imp.text.relayServer.response", eqTime, rt);
maxFileSize = lastJo.get("MaxFileSize").getAsLong();
UPLOAD_INFO_TEXT = new TranslatableComponent("imp.text.relayServer.uploadInfo", FNStringUtil.getByteDisplay(maxFileSize, 1024));
String v = null;
if (lastJo.has("Version"))
v = lastJo.get("Version").getAsString();
if (v != null)
RELAY_SERVER_NAME_TEXT = ((TextComponent) RELAY_SERVER_NAME_TEXT).append(" V" + v);
if (lastJo.has("Version")) v = lastJo.get("Version").getAsString();
if (v != null) RELAY_SERVER_NAME_TEXT = ((TextComponent) RELAY_SERVER_NAME_TEXT).append(" V" + v);
uploadUrl = url;
connected = true;
} else {
Expand Down Expand Up @@ -348,7 +339,25 @@ private UploadThread(File file) {
@Override
public void run() {
try {
var url = uploadToFile(Files.readAllBytes(file.toPath()));
var ujo = uploadToFile(Files.readAllBytes(file.toPath()));
if (ujo == null) {
UPLOAD_ERROR_TEXT = new TranslatableComponent("imp.text.fileUpload.error", "json is null");
return;
}

if (!ujo.has("url")) {
String error = "";
if (ujo.has("Error"))
error = ujo.get("Error").getAsString();
String msg = "";
if (ujo.has("Message"))
msg = ujo.get("Message").getAsString();

UPLOAD_ERROR_TEXT = new TranslatableComponent("imp.text.fileUpload.failure", error, msg);
return;
}

var url = ujo.get("url").getAsString();
if (url == null || url.isEmpty()) {
UPLOAD_ERROR_TEXT = new TranslatableComponent("imp.text.fileUpload.noURL");
} else {
Expand All @@ -357,8 +366,7 @@ public void run() {
IIMPSmartRender.mc.submit(() -> {
setMusicSourceName(url);
setCreateName(file.getName());
if (img != null)
getScreen().musicFileImage = img;
if (img != null) getScreen().musicFileImage = img;
insMonitor(getParentType());
});
}
Expand All @@ -370,15 +378,15 @@ public void run() {
}
}

private String uploadToFile(byte[] data) throws IOException, InterruptedException {
private JsonObject uploadToFile(byte[] data) throws IOException, InterruptedException {
if (uploadUrl == null) return null;
var url = uploadUrl + "music-upload";
var client = HttpClient.newHttpClient();
var req = HttpRequest.newBuilder(URI.create(url)).header("mc-uuid", IIMPSmartRender.mc.player.getGameProfile().getId().toString()).POST(HttpRequest.BodyPublishers.ofByteArray(data)).build();
var res = client.send(req, HttpResponse.BodyHandlers.ofString());
var jo = GSON.fromJson(res.body(), JsonObject.class);
return jo.get("url").getAsString();
return GSON.fromJson(res.body(), JsonObject.class);
}
//{"Error":"There was a problem processing the server, please upload after a while","Message":""}

private byte[] getMusicImage(File file) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
"imp.text.fileUpload.tooManyFiles": "Too many files",
"imp.text.fileUpload.fileNotFound": "File not found",
"imp.text.fileUpload.error": "Upload Error!: %s",
"imp.text.fileUpload.failure": "%s: %s",
"imp.text.fileUpload.sizeOver": "Size over",
"imp.text.fileUpload.directory": "Directory",
"imp.text.fileUpload.noURL": "Empty URL",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
"imp.text.fileUpload.tooManyFiles": "ファイルが多すぎます",
"imp.text.fileUpload.fileNotFound": "ファイルが見つかりません",
"imp.text.fileUpload.error": "アップロードエラー!: %s",
"imp.text.fileUpload.failure": "%s: %s",
"imp.text.fileUpload.sizeOver": "容量が大きすぎます",
"imp.text.fileUpload.directory": "ディレクトリです",
"imp.text.fileUpload.noURL": "URLが空です",
Expand Down
2 changes: 1 addition & 1 deletion fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ curseforge {
relations {
requiredDependency "fabric-api"
requiredDependency "cloth-config"
requiredDependency "architectury-fabric"
requiredDependency "architectury-api"
requiredDependency "otyacraft-engine"
optionalDependency "patchouli-fabric"
}
Expand Down
4 changes: 2 additions & 2 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ curseforge {
addGameVersion 'Java 17'

relations {
requiredDependency "cloth-config-forge"
requiredDependency "architectury-forge"
requiredDependency "cloth-config"
requiredDependency "architectury-api"
requiredDependency "otyacraft-engine"
optionalDependency "patchouli"
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ minecraft_version=1.18.2
#-------------------MOD Data--------------------#
archives_base_name=iammusicplayer
mod_display_name=IamMusicPlayer
mod_version=3.11
mod_version=3.12
#-----------------Library Version---------------#
architectury_version=4.1.32
fabric_loader_version=0.13.3
Expand Down
4 changes: 2 additions & 2 deletions version_check.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"1.0": "The Frist Release."
},
"promos": {
"1.18.2-latest": "3.11",
"1.18.2-recommended": "3.11",
"1.18.2-latest": "3.12",
"1.18.2-recommended": "3.12",
"1.18.1-latest": "3.4",
"1.18.1-recommended": "3.4",
"1.17.1-latest": "3.0",
Expand Down

0 comments on commit d6a7eb9

Please sign in to comment.