|
15 | 15 | import com.sk89q.craftbook.util.SignUtil; |
16 | 16 | import com.sk89q.craftbook.util.events.SignClickEvent; |
17 | 17 | import com.sk89q.util.yaml.YAMLProcessor; |
| 18 | +import org.bukkit.inventory.ItemStack; |
18 | 19 | import org.bukkit.inventory.meta.MapMeta; |
19 | 20 |
|
20 | 21 | public class MapChanger extends AbstractCraftBookMechanic { |
@@ -59,20 +60,31 @@ public void onSignClick(SignClickEvent event) { |
59 | 60 | player.printError("area.use-permissions"); |
60 | 61 | return; |
61 | 62 | } |
62 | | - if (event.getPlayer().getInventory().getItemInMainHand() != null && event.getPlayer().getInventory().getItemInMainHand().getType() == Material.MAP) { |
63 | | - byte id; |
64 | | - try { |
65 | | - id = Byte.parseByte(sign.getLine(2)); |
66 | | - } catch (Exception e) { |
67 | | - id = -1; |
68 | | - } |
69 | | - if (id <= -1) { |
70 | | - player.printError("mech.map.invalid"); |
71 | | - return; |
72 | | - } |
73 | | - MapMeta meta = (MapMeta) event.getPlayer().getInventory().getItemInMainHand().getItemMeta(); |
74 | | - meta.setMapId(id); |
75 | | - event.getPlayer().getInventory().getItemInMainHand().setItemMeta(meta); |
| 63 | + |
| 64 | + ItemStack item = event.getPlayer().getInventory().getItemInMainHand(); |
| 65 | + if (item == null |
| 66 | + || (item.getType() != Material.MAP && item.getType() != Material.FILLED_MAP)) { |
| 67 | + return; |
| 68 | + } |
| 69 | + |
| 70 | + final int mapId; |
| 71 | + try { |
| 72 | + mapId = Integer.parseInt(sign.getLine(2).trim()); |
| 73 | + } catch (Exception e) { |
| 74 | + player.printError("mech.map.invalid"); |
| 75 | + return; |
| 76 | + } |
| 77 | + |
| 78 | + if (item.getType() == Material.MAP) { |
| 79 | + ItemStack filled = new ItemStack(Material.FILLED_MAP, item.getAmount()); |
| 80 | + MapMeta meta = (MapMeta) filled.getItemMeta(); |
| 81 | + meta.setMapId(mapId); |
| 82 | + filled.setItemMeta(meta); |
| 83 | + event.getPlayer().getInventory().setItemInMainHand(filled); |
| 84 | + } else { |
| 85 | + MapMeta meta = (MapMeta) item.getItemMeta(); |
| 86 | + meta.setMapId(mapId); |
| 87 | + item.setItemMeta(meta); |
76 | 88 | } |
77 | 89 | } |
78 | 90 |
|
|
0 commit comments