Guest User

Untitled

a guest
Jan 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.04 KB | None | 0 0
  1. package com.bukkit.gemo.FalseBookIC.IC;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.Location;
  7. import org.bukkit.Material;
  8. import org.bukkit.World;
  9. import org.bukkit.block.Sign;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.event.block.BlockRedstoneEvent;
  12. import org.bukkit.event.block.SignChangeEvent;
  13.  
  14. import com.bukkit.gemo.FalseBookIC.FalseBookICCore;
  15.  
  16. public class MC1208 extends MCBlock {
  17. // CREATED BY SHOOT
  18.  
  19. public MC1208(FalseBookICCore plugin, SignChangeEvent event, boolean creation) {
  20. super(plugin, event, creation);
  21. Name = "SET MBLOCK";
  22. MCName = "[MC1208]";
  23.  
  24. if (!event.getBlock().getType().equals(Material.WALL_SIGN)) {
  25. cancelCreation(event, ChatColor.RED + "There was an internal error while creating this IC.");
  26. return;
  27. }
  28. if (creation) {
  29. Player player = event.getPlayer();
  30. if (plugin.playerCanUseCommand(player, "falsebook.ic.worldedit") || plugin.playerCanUseCommand(player, "falsebook.ic." + MCName.toLowerCase().substring(1, MCName.length() - 1)) || plugin.playerCanUseCommand(player, "falsebook.anyic") || plugin.playerCanUseCommand(player, "*")) {
  31. event.setLine(0, Name);
  32. event.setLine(1, MCName);
  33.  
  34. if (event.getLine(2) == null) {
  35. cancelCreation(event, "Item not found");
  36. return;
  37. }
  38.  
  39. String[] lineSplit = event.getLine(2).split("-");
  40. String[] split = lineSplit[0].split(":");
  41. try {
  42. if (!isValidBlock(Integer.valueOf(split[0]))) {
  43. cancelCreation(event, "Block not found");
  44. return;
  45. }
  46. } catch (Exception e) {
  47. if (!isValidBlock(getItemIDFromName(split[0]))) {
  48. cancelCreation(event, "Block not found.");
  49. return;
  50. }
  51. }
  52. if (lineSplit.length > 1) {
  53. split = lineSplit[1].split(":");
  54. try {
  55. if (!isValidBlock(Integer.valueOf(split[0]))) {
  56. cancelCreation(event, "Block not found");
  57. return;
  58. }
  59. } catch (Exception e) {
  60. if (!isValidBlock(split[0])) {
  61. cancelCreation(event, "Block not found.");
  62. return;
  63. }
  64. }
  65. }
  66.  
  67. if (event.getLine(3).length() > 0) {
  68. try {
  69. System.out.println(event.getLine(3));
  70. String[] splitLineT = event.getLine(3).split(":");
  71. Integer.valueOf(splitLineT[0]);
  72. if (splitLineT.length == 2) {
  73. if (splitLineT[1].equalsIgnoreCase("X")) {
  74. } else {
  75. Integer.valueOf(splitLineT[1]);
  76. }
  77. }
  78. } catch (Exception e) {
  79. cancelCreation(event, "Line 4 must be a number.");
  80. e.printStackTrace();
  81. return;
  82. }
  83. } else {
  84. cancelCreation(event, "Line 4 must be a number.");
  85. return;
  86. }
  87.  
  88. player.sendMessage(ChatColor.GREEN + Name + " created.");
  89. } else {
  90. cancelCreation(event, "You are not allowed to build a " + Name + ".");
  91. return;
  92. }
  93. }
  94. }
  95.  
  96. public static void Execute(Sign signBlock, int State, BlockRedstoneEvent event) {
  97. World w = signBlock.getWorld();
  98. String[] lineSplit = signBlock.getLine(2).split("-");
  99.  
  100. int ItemID = -1;
  101. int count = 1;
  102. int pos = 0;
  103. int secret = 1;
  104. if (signBlock.getLine(3) != null) {
  105. String[] splitLineT = signBlock.getLine(3).split(":");
  106. count = Integer.valueOf(splitLineT[0]);
  107. if (splitLineT.length == 2) {
  108. if (splitLineT[1].equalsIgnoreCase("X")) {
  109. secret = -1;
  110. pos = 0;
  111. } else {
  112. pos = Integer.parseInt(splitLineT[1]);
  113. if(pos < 0){
  114. secret = -1;
  115. }
  116. }
  117. }
  118. }
  119. Byte ItemData = 0;
  120.  
  121. String[] split = lineSplit[0].split(":");
  122. if (split.length > 1) {
  123. ItemID = getItemIDFromName(split[0]);
  124.  
  125. if (ItemID < 0) {
  126. try {
  127. ItemID = Integer.valueOf(split[0]);
  128. } catch (Exception e) {
  129. return;
  130. }
  131. }
  132. try {
  133. ItemData = Byte.valueOf(split[1]);
  134. } catch (Exception e) {
  135. return;
  136. }
  137. } else {
  138. // KEINE SUBID ANGEGEBEN
  139. ItemID = getItemIDFromName(lineSplit[0]);
  140. if (ItemID < 0) {
  141. try {
  142. ItemID = Integer.valueOf(lineSplit[0]);
  143.  
  144. } catch (Exception e) {
  145. return;
  146. }
  147. }
  148. }
  149.  
  150. int ItemID2 = 0;
  151. Byte ItemData2 = 0;
  152. if (lineSplit.length > 1) {
  153. split = lineSplit[1].split(":");
  154.  
  155. if (split.length > 1) {
  156. ItemID2 = getItemIDFromName(split[0]);
  157. if (ItemID2 < 0) {
  158. try {
  159. ItemID2 = Integer.valueOf(split[0]);
  160. } catch (Exception e) {
  161. return;
  162. }
  163. }
  164. try {
  165. ItemData2 = Byte.valueOf(split[1]);
  166. } catch (Exception e) {
  167. return;
  168. }
  169. } else {
  170. // KEINE SUBID ANGEGEBEN
  171. ItemID2 = getItemIDFromName(lineSplit[1]);
  172. if (ItemID2 < 0) {
  173. try {
  174. ItemID2 = Integer.valueOf(lineSplit[1]);
  175. } catch (Exception e) {
  176. return;
  177. }
  178. }
  179. }
  180. }
  181.  
  182. // keine ItemID gefunden?
  183. if (ItemID < 0 || ItemID2 < 0) {
  184. return;
  185. }
  186.  
  187. if ((ItemID < 0 && !isValidBlock(ItemID)) || (!isValidBlock(ItemID2) && ItemID2 > 0)) {
  188. return;
  189. }
  190.  
  191. // DROP VORBEREITEN
  192. Location loc = getSignOnBlockPos(signBlock);
  193. Location[] newBlockLocs = new Location[count];
  194. //Location newBlockLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + dist, loc.getZ());
  195.  
  196. for (int i = 0; i < count; i++) {
  197. newBlockLocs[i] = new Location(loc.getWorld(), loc.getX(), loc.getY() + ((i*secret) + secret) + pos, loc.getZ());
  198. }
  199. // DROP ITEM
  200. ArrayList<Location> positions = getBlockPositions(signBlock);
  201.  
  202. if (!isActivator(signBlock, positions.get(0))) {
  203. return;
  204. }
  205.  
  206. if (!(LocationEquals(event.getBlock().getLocation(), positions.get(0)))) {
  207. return;
  208. }
  209.  
  210. if (State > 0 && isLow(signBlock, positions.get(0))) {
  211. for (Location locc : newBlockLocs) {
  212. w.getBlockAt(locc).setTypeId(ItemID);
  213. w.getBlockAt(locc).setData(ItemData);
  214. switchLever(signBlock, true);
  215. }
  216. } else if (State == 0 && isPowered(signBlock, positions.get(0))) {
  217. for (Location locc : newBlockLocs) {
  218. w.getBlockAt(locc).setTypeId(ItemID2);
  219. w.getBlockAt(locc).setData(ItemData2);
  220. switchLever(signBlock, false);
  221. }
  222. }
  223. }
  224. }
Add Comment
Please, Sign In to add comment