Skip to content

Commit

Permalink
兼容某些不支持旧版Material的服务端
Browse files Browse the repository at this point in the history
  • Loading branch information
R-Josef committed Aug 6, 2021
1 parent abb76cf commit c23e166
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>moe.feo</groupId>
<artifactId>BBSToper</artifactId>
<version>3.6.5</version>
<version>3.6.6</version>
<repositories>
<repository>
<id>spigot-repo</id>
Expand Down
2 changes: 1 addition & 1 deletion resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: BBSToper
main: moe.feo.bbstoper.BBSToper
version: 3.6.5
version: 3.6.6
author: Fengshuai(R_Josef)
website: https://www.mcbbs.net/thread-789082-1-1.html
softdepend: [PlaceholderAPI]
Expand Down
27 changes: 24 additions & 3 deletions src/moe/feo/bbstoper/gui/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ public void createGui(Player player) {
continue;
inv.setItem(i, getRandomPane());
}
ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
ItemStack skull;
try {
skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
} catch (NoSuchFieldError e) {// 某些高版本服务端不兼容旧版写法
skull = new ItemStack(Material.getMaterial("PLAYER_HEAD"), 1);
}
SkullMeta skullmeta = (SkullMeta) skull.getItemMeta();// 玩家头颅
if (Option.GUI_DISPLAYHEADSKIN.getBoolean()) {// 如果开启了头颅显示,才会设置头颅的所有者
try {
Expand All @@ -76,7 +81,12 @@ public void createGui(Player player) {
skullmeta.setLore(skulllores);
skull.setItemMeta(skullmeta);
inv.setItem(12, skull);
ItemStack sunflower = new ItemStack(Material.DOUBLE_PLANT);
ItemStack sunflower;
try {
sunflower = new ItemStack(Material.DOUBLE_PLANT);
} catch (NoSuchFieldError e) {// 某些高版本服务端不兼容旧版写法
sunflower = new ItemStack(Material.getMaterial("SUNFLOWER"));
}
ItemMeta sunflowermeta = sunflower.getItemMeta();
sunflowermeta.setDisplayName(Message.GUI_REWARDS.getString());
List<String> sunflowerlores = new ArrayList<String>(Message.GUI_REWARDSINFO.getStringList());// 自定义奖励信息
Expand Down Expand Up @@ -141,7 +151,18 @@ public ItemStack getRandomPane() {// 获取随机一种颜色的玻璃板
while (data == 8) {// 8号亮灰色染色玻璃板根本没有颜色
data = (short)(Math.random()* 16);
}
ItemStack frame = new ItemStack(Material.STAINED_GLASS_PANE, 1, data);
ItemStack frame;
try {
frame = new ItemStack(Material.STAINED_GLASS_PANE, 1, data);

} catch (NoSuchFieldError e) {// 某些高版本服务端不兼容旧版写法
String[] glasspanes = {"WHITE_STAINED_GLASS_PANE", "ORANGE_STAINED_GLASS_PANE", "MAGENTA_STAINED_GLASS_PANE",
"LIGHT_BLUE_STAINED_GLASS_PANE", "YELLOW_STAINED_GLASS_PANE", "LIME_STAINED_GLASS_PANE", "PINK_STAINED_GLASS_PANE",
"GRAY_STAINED_GLASS_PANE", "LIGHT_GRAY_STAINED_GLASS_PANE", "CYAN_STAINED_GLASS_PANE", "PURPLE_STAINED_GLASS_PANE",
"BLUE_STAINED_GLASS_PANE", "BROWN_STAINED_GLASS_PANE", "GREEN_STAINED_GLASS_PANE", "RED_STAINED_GLASS_PANE",
"BLACK_STAINED_GLASS_PANE"};
frame = new ItemStack(Material.getMaterial(glasspanes[data]), 1);
}
ItemMeta framemeta = frame.getItemMeta();
framemeta.setDisplayName(Message.GUI_FRAME.getString());
frame.setItemMeta(framemeta);
Expand Down

0 comments on commit c23e166

Please sign in to comment.