Any bugs?

Discussion in 'Plugin Development' started by TaiSmoove, Jun 30, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    TaiSmoove

    So here is my code: (Longest for me)

    Code:java
    1. package me.taismoove.lists;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5. import java.util.logging.Logger;
    6.  
    7. import me.taismoove.main.Main;
    8.  
    9. import org.bukkit.Bukkit;
    10. import org.bukkit.ChatColor;
    11. import org.bukkit.GameMode;
    12. import org.bukkit.Location;
    13. import org.bukkit.Material;
    14. import org.bukkit.World;
    15. import org.bukkit.block.Block;
    16. import org.bukkit.command.Command;
    17. import org.bukkit.command.CommandExecutor;
    18. import org.bukkit.command.CommandSender;
    19. import org.bukkit.entity.Player;
    20. import org.bukkit.inventory.ItemStack;
    21. import org.bukkit.inventory.PlayerInventory;
    22. import org.bukkit.plugin.PluginDescriptionFile;
    23.  
    24. public class CodeCommandExecutor implements CommandExecutor {
    25. public static Main plugin;
    26.  
    27. Logger l = Logger.getLogger("CodeCraft_Plugin");
    28.  
    29. private final String cPrefix = ChatColor.RED + "[" + ChatColor.BLUE
    30. + "CodeCraft" + ChatColor.RED + "]";
    31. private final String noPerms = cPrefix + " " + ChatColor.BLUE
    32. + "Insufficient permissions!";
    33. private final String cPrefixBroadcast = ChatColor.RED + "["
    34. + ChatColor.BLUE + "CodeCraftBroadcast" + ChatColor.RED + "]";
    35.  
    36. public int GM = 0;
    37. public int ID = 0;
    38. public int Amount = 0;
    39. public boolean isEnabled = false;
    40. public boolean noFall = false;
    41.  
    42. List<Player> enabledUsers = new ArrayList<Player>();
    43. List<Player> noFallUsers = new ArrayList<Player>();
    44.  
    45. public CodeCommandExecutor(Main main) {
    46. main = plugin;
    47. }
    48.  
    49. public boolean onCommand(CommandSender se, Command cmd, String cmdl,
    50. String[] args) {
    51. Player pl = (Player) se;
    52. if (cmd.getName().equalsIgnoreCase("gme")) {
    53. if (se.hasPermission(new Permissions().gme)) {
    54. if (se instanceof Player) {
    55. if (args.length == 0) {
    56. se.sendMessage(cPrefix + " " + ChatColor.BLUE
    57. + "[0 (Survival):1 (Creative):2 (Adventure)]");
    58. } else if (args.length == 1) {
    59. GM = Integer.parseInt(args[0]);
    60. pl.setGameMode(GameMode.getByValue(GM));
    61. pl.sendMessage(cPrefix + " " + ChatColor.BLUE
    62. + "You are now: " + ChatColor.RED + GM);
    63. } else if (args.length == 2) {
    64. Player target = pl.getServer().getPlayer(args[0]);
    65. target.setGameMode(GameMode.getByValue(GM));
    66. target.sendMessage(cPrefix + " " + ChatColor.BLUE
    67. + "You are now: " + ChatColor.RED + GM);
    68. } else if (args.length > 2) {
    69. se.sendMessage(cPrefix + " " + ChatColor.BLUE
    70. + "Usage: /gme [0:1:2] <Player>");
    71. }
    72. } else {
    73. PluginDescriptionFile p = plugin.getDescription();
    74. l.info("[" + p.getName() + "]" + " "
    75. + "You must be a player to perform that command!");
    76. }
    77. } else {
    78. se.sendMessage(noPerms);
    79. }
    80. }
    81. if (cmd.getName().equalsIgnoreCase("fme")) {
    82. if (se.hasPermission(new Permissions().fme)) {
    83. if (se instanceof Player) {
    84. if (args.length == 0) {
    85. if (!isEnabled) {
    86. isEnabled = true;
    87. enabledUsers.add(pl);
    88. pl.setAllowFlight(true);
    89. pl.sendMessage(cPrefix + " " + ChatColor.BLUE
    90. + "Flight has been enabled!");
    91. } else {
    92. isEnabled = false;
    93. enabledUsers.remove(pl);
    94. pl.setAllowFlight(false);
    95. pl.sendMessage(cPrefix + " " + ChatColor.BLUE
    96. + "Flight has been disabled!");
    97. }
    98. } else if (args.length == 1) {
    99. Player target = pl.getServer().getPlayer(args[0]);
    100. if (!isEnabled) {
    101. isEnabled = true;
    102. enabledUsers.add(target);
    103. target.setAllowFlight(true);
    104. target.sendMessage(cPrefix + " " + ChatColor.BLUE
    105. + "Flight has been enabled!");
    106. } else {
    107. isEnabled = false;
    108. enabledUsers.remove(target);
    109. target.setAllowFlight(false);
    110. target.sendMessage(cPrefix + " " + ChatColor.BLUE
    111. + "Flight has been disabled!");
    112. }
    113. }
    114. } else {
    115. PluginDescriptionFile pdf = plugin.getDescription();
    116. l.info("[" + pdf.getName() + "]" + " "
    117. + "You must bea player to perform that command!");
    118. }
    119. } else {
    120. se.sendMessage(noPerms);
    121. }
    122. }
    123. if (cmd.getName().equalsIgnoreCase("t")
    124. || cmd.getName().equalsIgnoreCase("tele")) {
    125. if (se.hasPermission(new Permissions().tele)) {
    126. if (se instanceof Player) {
    127. if (args.length == 0) {
    128. se.sendMessage(cPrefix + " " + ChatColor.BLUE
    129. + "Usage: /t <Player> or /t <Player> <Player>");
    130. } else if (args.length == 1) {
    131. Player target = pl.getServer().getPlayer(args[0]);
    132. Location targetLocation = target.getLocation();
    133. pl.teleport(targetLocation);
    134. se.sendMessage(cPrefix + " " + ChatColor.BLUE
    135. + "Whoosh!");
    136. } else if (args.length == 2) {
    137. Player target1 = pl.getServer().getPlayer(args[1]);
    138. Player target2 = pl.getServer().getPlayer(args[1]);
    139. Location target2Location = target2.getLocation();
    140. target1.teleport(target2Location);
    141. target1.sendMessage(cPrefix + " " + ChatColor.BLUE
    142. + "Whoosh!");
    143. }
    144. } else {
    145. PluginDescriptionFile p = plugin.getDescription();
    146. l.info("[" + p.getName() + "]" + " "
    147. + "You must be a player to perfrom this command!");
    148. }
    149. } else {
    150. se.sendMessage(noPerms);
    151. }
    152. }
    153. if (cmd.getName().equalsIgnoreCase("c")
    154. || cmd.getName().equalsIgnoreCase("cookie")) {
    155. if (se.hasPermission(new Permissions().cookie)) {
    156. if (se instanceof Player) {
    157. if (args.length == 0) {
    158. se.sendMessage(cPrefix + " " + ChatColor.BLUE
    159. + "Usage: /c <Amount> or /c <Amount> <Player>");
    160. } else if (args.length == 1) {
    161. Amount = Integer.parseInt(args[0]);
    162. ItemStack cookie = new ItemStack(Material.COOKIE,
    163. Amount);
    164. ItemStack milk = new ItemStack(Material.MILK_BUCKET, 1);
    165. PlayerInventory pi = pl.getInventory();
    166. pi.addItem(cookie);
    167. pi.addItem(milk);
    168. pl.sendMessage(cPrefix + " " + ChatColor.BLUE
    169. + "Here is your Milk and Cookie(s)!");
    170. } else if (args.length == 2) {
    171. ItemStack cookie = new ItemStack(Material.COOKIE,
    172. Amount);
    173. ItemStack milk = new ItemStack(Material.MILK_BUCKET, 1);
    174. Player target = pl.getServer().getPlayer(args[1]);
    175. PlayerInventory ti = target.getInventory();
    176. ti.addItem(cookie);
    177. ti.addItem(milk);
    178. target.sendMessage(cPrefix + " " + ChatColor.BLUE
    179. + "Here is Milk and Cookie(s)!");
    180. }
    181. } else {
    182. PluginDescriptionFile p = plugin.getDescription();
    183. l.info("[" + p.getName() + "]" + " "
    184. + "You must be a player to perform this command!");
    185. }
    186. } else {
    187. se.sendMessage(noPerms);
    188. }
    189. }
    190. if (cmd.getName().equalsIgnoreCase("co")
    191. || cmd.getName().equalsIgnoreCase("coords")) {
    192. if (se.hasPermission(new Permissions().coords)) {
    193. if (se instanceof Player) {
    194. if (args.length == 0) {
    195. int x = pl.getLocation().getBlockX();
    196. int y = pl.getLocation().getBlockY();
    197. int z = pl.getLocation().getBlockZ();
    198. pl.sendMessage(cPrefix + " " + ChatColor.BLUE
    199. + "You coords are: " + ChatColor.RED + "["
    200. + ChatColor.YELLOW + "X: " + ChatColor.BLUE + x
    201. + ChatColor.RED + ": " + ChatColor.YELLOW
    202. + "Y: " + ChatColor.BLUE + y + ChatColor.RED
    203. + ": " + ChatColor.YELLOW + "Z: "
    204. + ChatColor.BLUE + z);
    205. } else if (args.length == 1) {
    206. Player target = pl.getServer().getPlayer(args[0]);
    207. int xt = target.getLocation().getBlockX();
    208. int yt = target.getLocation().getBlockY();
    209. int zt = target.getLocation().getBlockZ();
    210. pl.sendMessage(cPrefix + " " + ChatColor.BLUE
    211. + target.getName() + "'s coords are: "
    212. + ChatColor.RED + "[" + ChatColor.YELLOW
    213. + "X: " + ChatColor.BLUE + xt + ChatColor.RED
    214. + ": " + ChatColor.YELLOW + "Y: "
    215. + ChatColor.BLUE + yt + ChatColor.RED + ": "
    216. + ChatColor.YELLOW + "Z: " + ChatColor.BLUE
    217. + zt);
    218. }
    219. } else {
    220. PluginDescriptionFile p = plugin.getDescription();
    221. l.info("[" + p.getName() + "]" + " "
    222. + "You must be a player to perform this command!");
    223. }
    224. } else {
    225. se.sendMessage(noPerms);
    226. }
    227. }
    228. if (cmd.getName().equalsIgnoreCase("ime")
    229. || cmd.getName().equalsIgnoreCase("item")) {
    230. if (se.hasPermission(new Permissions().ime)) {
    231. if (se instanceof Player) {
    232. if (args.length == 0) {
    233. se.sendMessage(cPrefix + " " + ChatColor.BLUE
    234. + "Usage: /ime <ID>");
    235. } else if (args.length == 1) {
    236. ID = Integer.parseInt(args[0]);
    237. Amount = Integer.parseInt(args[0]);
    238. ItemStack IDP = new ItemStack(ID, Amount);
    239. PlayerInventory pi = pl.getInventory();
    240. pi.addItem(IDP);
    241. se.sendMessage(cPrefix + " " + ChatColor.BLUE
    242. + "Here is your: " + ChatColor.RED + ID);
    243. } else if (args.length == 2) {
    244. Player target = pl.getServer().getPlayer(args[1]);
    245. ID = Integer.parseInt(args[1]);
    246. Amount = Integer.parseInt(args[1]);
    247. PlayerInventory ti = target.getInventory();
    248. ItemStack IDT = new ItemStack(ID, Amount);
    249. ti.addItem(IDT);
    250. target.sendMessage(cPrefix + " " + ChatColor.BLUE
    251. + "Here is your: " + ChatColor.RED + ID);
    252. }
    253. } else {
    254. PluginDescriptionFile p = plugin.getDescription();
    255. l.info("[" + p.getName() + "]" + " "
    256. + "You must be a player to perform this command!");
    257. }
    258. } else {
    259. se.sendMessage(noPerms);
    260. }
    261. }
    262. if (cmd.getName().equalsIgnoreCase("codecrafthelp")) {
    263. if (se.hasPermission(new Permissions().codecrafthelpadmin)) {
    264. if (args.length == 0) {
    265. se.sendMessage(cPrefix + " " + ChatColor.BLUE
    266. + "/gme [0:1:2]");
    267. se.sendMessage(cPrefix + " " + ChatColor.BLUE
    268. + "/fme <Player>");
    269. se.sendMessage(cPrefix + " " + ChatColor.BLUE
    270. + "/ime <ID> <Amount> <Player>");
    271. }
    272. } else {
    273. se.sendMessage(noPerms);
    274. }
    275. }
    276. if (cmd.getName().equalsIgnoreCase("codea")) {
    277. if (se.hasPermission(new Permissions().codea)) {
    278. if (args.length == 0) {
    279. Bukkit.broadcastMessage(ChatColor
    280. .translateAlternateColorCodes('&', plugin
    281. .getConfig().getString("CODEA")));
    282. } else if (args.length == 1) {
    283. se.sendMessage(cPrefix + " " + ChatColor.BLUE
    284. + "Usage: /codea");
    285. }
    286. } else {
    287. se.sendMessage(noPerms);
    288. }
    289. }
    290. if (cmd.getName().equalsIgnoreCase("tme")) {
    291. if (se instanceof Player) {
    292. if (args.length == 0) {
    293. long timeOfPlayer = pl.getWorld().getTime();
    294. se.sendMessage(cPrefix + " " + ChatColor.BLUE
    295. + "Your time is: " + ChatColor.RED + timeOfPlayer);
    296. } else if (args.length == 1) {
    297. Player target = pl.getServer().getPlayer(args[0]);
    298. long timeOfTarget = target.getWorld().getTime();
    299. se.sendMessage(cPrefix + " " + ChatColor.BLUE
    300. + target.getName() + "'s time is: " + ChatColor.RED
    301. + timeOfTarget);
    302. }
    303. } else {
    304. PluginDescriptionFile p = plugin.getDescription();
    305. l.info("[" + p.getName() + "]" + " "
    306. + "You must be a player to perform this command!");
    307. }
    308. }
    309. if (cmd.getName().equalsIgnoreCase("obsidian")) {
    310. if (se.hasPermission(new Permissions().obsidian)) {
    311. if (args.length == 0) {
    312. se.sendMessage(cPrefix + " " + ChatColor.BLUE
    313. + "Usage: /obsidian <Player>");
    314. } else if (args.length == 1) {
    315. Player target = pl.getServer().getPlayer(args[0]);
    316. World tW = target.getWorld();
    317. Location targetLocation = target.getLocation();
    318. Block changeMe = tW.getBlockAt(targetLocation);
    319. changeMe.setTypeId(11);
    320. Bukkit.broadcastMessage(cPrefixBroadcast + " "
    321. + ChatColor.BLUE + target.getName()
    322. + " has turned to " + ChatColor.RED + "obsidian"
    323. + ChatColor.BLUE + "!");
    324. }
    325. } else {
    326. se.sendMessage(noPerms);
    327. }
    328. }
    329. if (cmd.getName().equalsIgnoreCase("fakeop")) {
    330. if (se.hasPermission(new Permissions().fakeop)) {
    331. if (args.length == 0) {
    332. se.sendMessage(cPrefix + " " + ChatColor.BLUE
    333. + "Usage: /fakeop <Player>");
    334. } else if (args.length == 1) {
    335. Player target = pl.getServer().getPlayer(args[0]);
    336. target.sendMessage(ChatColor.YELLOW + "You are now op!");
    337. }
    338. } else {
    339. se.sendMessage(noPerms);
    340. }
    341. }
    342. if (cmd.getName().equalsIgnoreCase("scareban")) {
    343. if (se.hasPermission(new Permissions().scareban)) {
    344. if (args.length == 0) {
    345. se.sendMessage(cPrefix + " " + ChatColor.BLUE
    346. + "Usage: /scareban <Player>");
    347. } else if (args.length == 1) {
    348. Player target = pl.getServer().getPlayer(args[0]);
    349. for (int i = 5; i < 0; i--) {
    350. target.sendMessage(cPrefix + " " + ChatColor.BLUE
    351. + "You will be banned for grief in: "
    352. + ChatColor.RED + i);
    353. try {
    354. Thread.sleep(1000);
    355. } catch (InterruptedException e) {
    356.  
    357. }
    358. }
    359. }
    360. } else {
    361. se.sendMessage(noPerms);
    362. }
    363. }
    364. if (cmd.getName().equalsIgnoreCase("blowup")) {
    365. if (se.hasPermission(new Permissions().blowup)) {
    366. if (args.length == 0) {
    367. se.sendMessage(cPrefix + " " + ChatColor.BLUE
    368. + "Usage: /blowup <Player>");
    369. } else if (args.length == 1) {
    370. Player target = pl.getServer().getPlayer(args[0]);
    371. World tW = target.getWorld();
    372. Location targetLocation = target.getLocation();
    373. float floatF = 50.5f;
    374. tW.createExplosion(targetLocation, floatF);
    375. Bukkit.broadcastMessage(cPrefixBroadcast + " "
    376. + ChatColor.BLUE + target.getName() + " just got "
    377. + ChatColor.RED + "blown " + ChatColor.BLUE
    378. + "to pieces!");
    379. }
    380. } else {
    381. se.sendMessage(noPerms);
    382. }
    383. }
    384. if (cmd.getName().equalsIgnoreCase("trap")) {
    385. if (se.hasPermission(new Permissions().trap)) {
    386. if (args.length == 0) {
    387. se.sendMessage(cPrefix + " " + ChatColor.BLUE
    388. + "Usage: /trap <Player>");
    389. } else if (args.length == 1) {
    390. Player target = pl.getServer().getPlayer(args[0]);
    391. Location targetLocation = target.getLocation();
    392. int xChange = targetLocation.getBlockX() + 1;
    393. int zChange = targetLocation.getBlockZ() + 1;
    394. int yChange = targetLocation.getBlockY() + 1;
    395. World tW = target.getWorld();
    396. Block changeMe = tW.getBlockAt(xChange, yChange, zChange);
    397. changeMe.setTypeId(7);
    398. Bukkit.broadcastMessage(cPrefixBroadcast + " "
    399. + ChatColor.BLUE + "Hmm, where has "
    400. + target.getName() + " gone?");
    401. }
    402. }else{
    403. se.sendMessage(noPerms);
    404. }
    405. }
    406. return false;
    407. }
    408. }


    Are there any bugs in this?
     
  2. Offline

    MP5K

    Hello TaiSmoove,
    Isn't it your task to debug your code? :)
    Or is it just me who thinks that :?
     
    Minecrell likes this.
Thread Status:
Not open for further replies.

Share This Page