Skip to content

Commit

Permalink
support 1.20
Browse files Browse the repository at this point in the history
Signed-off-by: LSDog <2509863159@qq.com>
  • Loading branch information
LSDog committed Jun 12, 2023
1 parent 905d6dc commit c0376fb
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 56 deletions.
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -16,8 +16,8 @@ ___
|:-------------------:|--------------------------------------------------------------|
| ![logo](logo64.png) | CustomSprays <br> 花样喷漆 |
| 作者 <br> Author | LSDog |
| 版本 <br> Version | 1.5.7 |
| 支持 <br> Support | **1.8 ~ 1.19** (Bukkit Spigot Paper CatServer Mohist...) |
| 版本 <br> Version | 1.5.8 |
| 支持 <br> Support | **1.8 ~ 1.20** (Bukkit Spigot Paper CatServer Mohist...) |
| 指令 <br> Cmd | `/cspray ...` - 主命令 <br>`/spray` - 喷漆<br>`/spray big` - 喷大喷漆 |
| 权限 <br> Perm | 请见 "config.yml" / see "config.yml" |
>
Expand All @@ -26,8 +26,8 @@ ___
> | [Spigot](https://www.spigotmc.org/resources/customsprays-upload-image-and-spray-it-on-the-wall.98979/)
> | [PlanetMinecraft](https://www.planetminecraft.com/mod/customsprays-spray-your-image-like-in-source-games/)
## **下载 | Download**:
### [发布页](https://github.com/LSDogX/CustomSprays/releases) / [Releases](https://github.com/LSDogX/CustomSprays/releases) !!
## **下载 | Download**[发布页](https://github.com/LSDogX/CustomSprays/releases) | [Releases](https://github.com/LSDogX/CustomSprays/releases) !!
(上面Github打不开? → [Gitee发布页](https://gitee.com/pixelmc/CustomSprays/releases))


**[喷漆音效资源包](https://github.com/LSDogX/CustomSprays/blob/master/spray_sound_pack.zip?raw=true) / [Spray sound resource pack](https://github.com/LSDogX/CustomSprays/blob/master/spray_sound_pack.zip?raw=true) ! ⭐**
Expand Down Expand Up @@ -69,7 +69,7 @@ ___

## 🎮 版本支持 | Version Support
___
> 🔷 **1.8 ~ 1.19.4**
> 🔷 **1.8 ~ 1.20**
> 📏 支持的 **"领域"** 插件 | Supported **"region"** plugins:
> - [x] Residence .......... [ *?* ~ 5.0.1.3+ ]
Expand Down
11 changes: 6 additions & 5 deletions src/fun/LSDog/CustomSprays/CustomSprays.java
Expand Up @@ -87,11 +87,12 @@ public void onEnable() {
new Metrics(this, 13633);

if (getConfig().getBoolean("check_update")) Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
String nVersion = CustomSprays.instance.getDescription().getVersion();
String lVersion = UpdateChecker.check();
if (lVersion == null) return;
if (nVersion.equals(lVersion)) return;
latestVersion = lVersion;
String pluginVersion = CustomSprays.instance.getDescription().getVersion();
String latestVersion = UpdateChecker.checkGithub();
if (latestVersion == null) latestVersion = UpdateChecker.checkGitee();
if (latestVersion == null) return;
if (pluginVersion.equals(latestVersion)) return;
CustomSprays.latestVersion = latestVersion;
});

Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
Expand Down
2 changes: 2 additions & 0 deletions src/fun/LSDog/CustomSprays/spray/MapFrameFactory.java
Expand Up @@ -137,6 +137,8 @@ public static Object getMcMap(int mapViewId) throws ReflectiveOperationException
default:
case 3: itemFieldName = "rb"; break;
}
} else if (subVer == 20) {
itemFieldName = "rf";
}
// MAP
if (cItem == null) {
Expand Down
11 changes: 0 additions & 11 deletions src/fun/LSDog/CustomSprays/utils/ImageDownloader.java
Expand Up @@ -6,7 +6,6 @@
import javax.imageio.ImageIO;
import javax.net.ssl.SSLHandshakeException;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -59,16 +58,6 @@ private static void setPixivSimulationProp(URLConnection conn) {
conn.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,ja;q=0.7");
}

public static String inputStreamToString(InputStream inputStream) throws IOException {
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
return result.toString("UTF-8");
}

@Override
public void close() {
if (downloadCount > 0) downloadCount--;
Expand Down
25 changes: 20 additions & 5 deletions src/fun/LSDog/CustomSprays/utils/NMS.java
Expand Up @@ -216,16 +216,25 @@ public static Class<?> getMcNBTTagCompoundClass() {
}

public static Object getMcPlayerConnection(Player player) throws ReflectiveOperationException {
if (getSubVer() < 17) return getMcEntityPlayerClass().getField("playerConnection").get(getMcEntityPlayer(player));
else return getMcEntityPlayerClass().getField("b").get(getMcEntityPlayer(player));
int subVer = getSubVer();
String fieldName = "playerConnection";
if (subVer >= 18) switch (subVer) {
case 18:
case 19:
fieldName = "b"; break;
case 20:
default:
fieldName = "c"; break;
}
return getMcEntityPlayerClass().getField(fieldName).get(getMcEntityPlayer(player));
}

public static int getMcEntityId(Object mcEntity) throws ReflectiveOperationException {
int subVer = getSubVer();
int subRVer = getSubRVer();
if (Entity_getId == null) {
String methodName = "getId";
switch (subVer) {
if (subVer >= 18) switch (subVer) {
case 18:
methodName = "ae";
break;
Expand All @@ -238,8 +247,11 @@ public static int getMcEntityId(Object mcEntity) throws ReflectiveOperationExcep
// 真牛逼他又改了 1_19_R3
}
break;
case 20:
default:
methodName = "af"; break;
}
Entity_getId = NMS.getMcEntityItemFrameClass().getMethod(methodName);
Entity_getId = NMS.getMcEntityClass().getMethod(methodName);
Entity_getId.setAccessible(true);
}
return (int) Entity_getId.invoke(mcEntity);
Expand All @@ -249,7 +261,7 @@ public static Object getDataWatcher(Object entity) throws ReflectiveOperationExc
int subVer = getSubVer();
if (Entity_getDataWatcher == null) {
String methodName = "getDataWatcher";
switch (subVer) {
if (subVer >= 18) switch (subVer) {
case 18:
methodName = "ai";
break;
Expand All @@ -260,6 +272,9 @@ public static Object getDataWatcher(Object entity) throws ReflectiveOperationExc
case 3: methodName = "aj"; break;
}
break;
case 20:
default:
methodName = "aj"; break;
}
Entity_getDataWatcher = NMS.getMcEntityItemFrameClass().getMethod(methodName);
Entity_getDataWatcher.setAccessible(true);
Expand Down
57 changes: 42 additions & 15 deletions src/fun/LSDog/CustomSprays/utils/UpdateChecker.java
Expand Up @@ -4,36 +4,63 @@
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public class UpdateChecker {


public static String check() {
public static String checkGithub() {

try {
URL url = new URL("https://api.github.com/repos/LSDogX/CustomSprays/releases/latest");
return getVersionFromUrlApi(url);
} catch (Exception e) {
CustomSprays.log("failed to check version...");
CustomSprays.log(e);
}
return null;
}

public static String checkGitee() {

try {
URL url = new URL("https://gitee.com/api/v5/repos/PixelMC/CustomSprays/releases/latest");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setUseCaches(false);
conn.setConnectTimeout(10000);
conn.connect();
try (InputStream in = conn.getInputStream()) {
byte[] bytes = new byte[in.available()];
int read = in.read(bytes);
if (read == -1) return null;
JSONObject jsonObject = (JSONObject) JSONValue.parse(new String(bytes, StandardCharsets.UTF_8));
CustomSprays.log("found new version: " + jsonObject.get("tag_name"));
return (String) jsonObject.get("tag_name");
}
return getVersionFromUrlApi(url);
} catch (Exception e) {
CustomSprays.log("failed to check version...");
CustomSprays.log(e);
}
return null;
}


private static String getVersionFromUrlApi(URL url) throws IOException {
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setUseCaches(false);
conn.setConnectTimeout(10000);
conn.connect();
try (InputStream in = conn.getInputStream()) {
String string = inputStreamToString(in);
JSONObject jsonObject = (JSONObject) JSONValue.parse(string);
CustomSprays.log("found new version: " + jsonObject.get("tag_name"));
return (String) jsonObject.get("tag_name");
}
}


public static String inputStreamToString(InputStream inputStream) throws IOException {
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
return result.toString("UTF-8");
}

}
2 changes: 1 addition & 1 deletion src/plugin.yml
@@ -1,5 +1,5 @@
name: CustomSprays
version: 1.5.7
version: 1.5.8
main: fun.LSDog.CustomSprays.CustomSprays
authors: [LSDog]
softdepend: [PlaceholderAPI,WorldEdit,FastAsyncWorldEdit,Residence,WorldGuard,GriefDefender,Vault]
Expand Down
14 changes: 0 additions & 14 deletions test/ColorTest.java

This file was deleted.

0 comments on commit c0376fb

Please sign in to comment.