Solved Help me with a plugin please

Discussion in 'Plugin Development' started by AKZOBIE74, May 21, 2014.

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

    AKZOBIE74

    Guys can you give me a code that will allow the player if they have permission to right click a diamond sword and then it will turn into a stick and when you right click the stick it will turn into a diamond sword and when you left click the diamond sword at a player or mob it will shoot lightning?Make sure the coding works for minecraft 1.6.4.Thanks!
     
  2. Offline

    MrSparkzz

    AKZOBIE74
    1. You shouldn't be asking for people to code your plugins for you, that's not what this section is for. You come here for help or assistance when you get stuck. If you want someone to code something for you go to the plugin request section.

    2. If you are asking for help and already have some code, elaborate on what you're looking for. Are you asking for when you right click with a diamond sword in your hand? or right clicking it in your inventory?

    And for the lightning, does it have to be at a mob or can it just strike where your cursor is pointed?
     
  3. Offline

    Iroh

    Do you want help creating a plugin or to have one made for you?
     
  4. Offline

    AKZOBIE74

    I dont want people to create the plugin for me i just need help with the code i already have most of my plugin finished its just that i am stuck on this problem and i need help
     
  5. Offline

    Iroh

    Moved to plugin dev.
     
  6. Offline

    AKZOBIE74


    I am asking to right click with the diamond sword.For the lightning it can be where the cursor is pointing at.

    P.S. I accidentally typed my name AKZOBIE74 it should be AKZOMBIE74 I have a thread on that for staff to help me change my username to AKZOMBIE74
     
  7. Offline

    es359

    Can you post your code?
     
  8. Offline

    MrSparkzz

    Iroh
    Wasn't this already in Plugin Development?
     
  9. Offline

    Iroh

    I don't think it was xD anyway doesn't matter.
     
    MrSparkzz likes this.
  10. Offline

    AKZOBIE74

    Sure
    Code:java
    1. package me.AKZOMBIE74;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5. import java.io.PrintStream;
    6. import java.util.ArrayList;
    7. import java.util.HashMap;
    8. import java.util.Map;
    9. import org.bukkit.Bukkit;
    10. import org.bukkit.ChatColor;
    11. import org.bukkit.Location;
    12. import org.bukkit.Material;
    13. import org.bukkit.Server;
    14. import org.bukkit.command.Command;
    15. import org.bukkit.command.CommandSender;
    16. import org.bukkit.configuration.file.FileConfiguration;
    17. import org.bukkit.configuration.file.FileConfigurationOptions;
    18. import org.bukkit.configuration.file.YamlConfiguration;
    19. import org.bukkit.enchantments.Enchantment;
    20. import org.bukkit.entity.Player;
    21. import org.bukkit.event.EventHandler;
    22. import org.bukkit.event.Listener;
    23. import org.bukkit.inventory.ItemStack;
    24. import org.bukkit.inventory.ShapedRecipe;
    25. import org.bukkit.inventory.meta.ItemMeta;
    26. import org.bukkit.plugin.PluginManager;
    27. import org.bukkit.plugin.java.JavaPlugin;
    28.  
    29. public class Riptide
    30. extends JavaPlugin implements Listener
    31. {
    32. private static boolean rsword;
    33. private static boolean rbow;
    34. private static boolean rfists = false;
    35. public static int dmgm = 5;
    36. public static Map<String, TrackedPlayer> tplayers = new HashMap();
    37. private static Riptide instance = null;
    38. private DamageListener damageListener;
    39. private PlayerHandle playerHandle;
    40.  
    41.  
    42. public DamageListener getDamageListener()
    43. {
    44. return this.damageListener;
    45. }
    46.  
    47. public PlayerHandle getPlayerHandle()
    48. {
    49. return this.playerHandle;
    50. }
    51.  
    52. public void onEnable()
    53. {
    54. loadConfig();
    55. instance = this;
    56. reloadTrackedPlayers();
    57.  
    58. this.damageListener = new DamageListener();
    59. this.playerHandle = new PlayerHandle();
    60. Bukkit.getPluginManager().registerEvents(this.damageListener, this);
    61. Bukkit.getPluginManager().registerEvents(this.playerHandle, this);
    62. getServer().getPluginManager().registerEvents(this, this);
    63.  
    64. ItemStack EmeraldSword = new ItemStack(Material.DIAMOND_SWORD, 1);
    65. ItemMeta EmeraldSwordmeta = EmeraldSword.getItemMeta();
    66. EmeraldSwordmeta.setDisplayName(ChatColor.DARK_RED + "Riptide");
    67. EmeraldSword.setItemMeta(EmeraldSwordmeta);
    68. ShapedRecipe recipe = new ShapedRecipe(EmeraldSword);
    69. recipe.shape(new String[] { "£££", "£*£", "£££" });
    70. recipe.setIngredient('£', Material.EMERALD_BLOCK);
    71. recipe.setIngredient('*', Material.EMERALD_ORE);
    72. Bukkit.getServer().addRecipe(recipe);
    73.  
    74. }
    75.  
    76. public void onDisable()
    77. {
    78. saveTrackedPlayers();
    79. instance = null;
    80. tplayers = null;
    81. dmgm = 0;
    82. Bukkit.getServer().clearRecipes();
    83. }
    84.  
    85.  
    86. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    87. {
    88. if (cmd.getName().equalsIgnoreCase("riptide"))
    89. {
    90. if ((sender instanceof Player))
    91. {
    92. Player player = (Player)sender;
    93. TrackedPlayer tplr = (TrackedPlayer)tplayers.get(player.getName());
    94. if (args.length != 0)
    95. {
    96. if ((args[0].equalsIgnoreCase("toggle")) || (args[0].equalsIgnoreCase("t")))
    97. {
    98. if (args.length >= 2)
    99. {
    100. if ((args[1].equalsIgnoreCase("sword")) || (args[1].equalsIgnoreCase("s")))
    101. {
    102. if (player.hasPermission("riptide.use.sword"))
    103. {
    104. if (rsword)
    105. {
    106. boolean result = tplr.toggleSword().booleanValue();
    107. player.sendMessage(ChatColor.GOLD + "Your Riptide has been " + ChatColor.RED + boolToString(Boolean.valueOf(result)));
    108. return true;
    109. }
    110. player.sendMessage(ChatColor.RED + "Riptide Sword's are disabled for the server!");
    111. return true;
    112. }
    113. player.sendMessage(ChatColor.RED + "You do not have permission to run this command!");
    114. return true;
    115. }
    116. if ((args[1].equalsIgnoreCase("bow")) || (args[1].equalsIgnoreCase("b")))
    117. {
    118. if (player.hasPermission("riptide.use.bow"))
    119. {
    120. if (rbow)
    121. {
    122. boolean result = tplr.toggleBow().booleanValue();
    123. player.sendMessage(ChatColor.GOLD + "Your RipBow has been " + ChatColor.RED + boolToString(Boolean.valueOf(result)));
    124. return true;
    125. }
    126. player.sendMessage(ChatColor.RED + "RipBows are disabled for the server!");
    127. return true;
    128. }
    129. player.sendMessage(ChatColor.RED + "You do not have permission to run this command!");
    130. return true;
    131. }
    132. if ((args[1].equalsIgnoreCase("fists")) || (args[1].equalsIgnoreCase("f")))
    133. {
    134. if (player.hasPermission("riptide.use.fists"))
    135. {
    136. if (rfists)
    137. {
    138. boolean result = tplr.toggleFists().booleanValue();
    139. player.sendMessage(ChatColor.GOLD + "Your RipFists has been " + ChatColor.RED + boolToString(Boolean.valueOf(result)));
    140. return true;
    141. }
    142. player.sendMessage(ChatColor.RED + "RipFists are disabled for the server!");
    143. return true;
    144. }
    145. player.sendMessage(ChatColor.RED + "You do not have permission to run this command!");
    146. return true;
    147. }
    148. player.sendMessage(ChatColor.RED + "Invalid toggle type; Sword, Bow, Fists");
    149. return true;
    150. }
    151. getServer().dispatchCommand(sender, "riptide help");
    152. return true;
    153. }
    154. if ((args[0].equalsIgnoreCase("set")) || (args[0].equalsIgnoreCase("s")))
    155. {
    156. if ((args.length >= 3) && (
    157. (args[1].equalsIgnoreCase("multiplyer")) || (args[1].equalsIgnoreCase("m")))) {
    158. if (player.hasPermission("riptide.set.multiplyer"))
    159. {
    160. if (isInteger(args[2]))
    161. {
    162. int tmult = Integer.parseInt(args[2]);
    163. if (tmult < 50000)
    164. {
    165. dmgm = tmult;
    166. player.sendMessage(ChatColor.GOLD + "Set the server multiplyer to " + ChatColor.RED + tmult);
    167. return true;
    168. }
    169. player.sendMessage(ChatColor.RED + "Your multiplyer is too high! It must be 50000 or under.");
    170. return true;
    171. }
    172. }
    173. else
    174. {
    175. player.sendMessage(ChatColor.RED + "You do not have permission to run this command!");
    176. return true;
    177. }
    178. }
    179. getServer().dispatchCommand(sender, "riptide help");
    180. return true;
    181. }
    182. if ((args[0].equalsIgnoreCase("help")) || (args[0].equalsIgnoreCase("h")))
    183. {
    184. player.sendMessage(ChatColor.YELLOW + "===============================================");
    185. player.sendMessage(ChatColor.DARK_AQUA + "Riptide Version 2.0 by AKZOMBIE74");
    186. player.sendMessage(ChatColor.YELLOW + "===============================================");
    187. player.sendMessage(ChatColor.DARK_RED + "/riptide toggle (sword, bow, fists)" + ChatColor.AQUA + " - toggles your Riptide sword, bow or fists.");
    188. player.sendMessage(ChatColor.DARK_RED + "/riptide set multiplyer (number)" + ChatColor.AQUA + " - sets the damage multiplyer for everyone.");
    189. return true;
    190. }
    191. getServer().dispatchCommand(sender, "riptide help");
    192. return true;
    193. }
    194. getServer().dispatchCommand(sender, "riptide help");
    195. return true;
    196. }
    197. System.out.println("[Riptide] Sorry but this command can only be run by a player.");
    198. return true;
    199. }
    200. return false;
    201. }
    202.  
    203. private void loadConfig()
    204. {
    205. getConfig().addDefault("RiptideSwords", Boolean.valueOf(true));
    206. getConfig().addDefault("RipBows", Boolean.valueOf(true));
    207. getConfig().addDefault("RipFists", Boolean.valueOf(true));
    208. getConfig().addDefault("DamageMultiplyer", Integer.valueOf(5));
    209.  
    210. getConfig().options().copyDefaults(true);
    211. saveConfig();
    212.  
    213. rsword = getConfig().getBoolean("RiptideSwords");
    214. rbow = getConfig().getBoolean("RipBows");
    215. rfists = getConfig().getBoolean("RipFists");
    216. if (getConfig().getInt("DamageMultiplyer") < 50000) {
    217. dmgm = getConfig().getInt("DamageMultiplyer");
    218. } else {
    219. dmgm = 50000;
    220. }
    221. File plrConfigDir = new File("./Plugins/Riptide/players");
    222. if (!plrConfigDir.exists()) {
    223. plrConfigDir.mkdirs();
    224. }
    225. }
    226.  
    227. public FileConfiguration loadPlayerConfig(String player)
    228. {
    229. FileConfiguration customConfig = null;
    230. File customConfigFile = null;
    231. File plrConfigDir = new File("./Plugins/Riptide/players");
    232. if (!plrConfigDir.exists()) {
    233. plrConfigDir.mkdirs();
    234. }
    235. customConfigFile = new File("./Plugins/Riptide/players", player + ".yml");
    236. try
    237. {
    238. if (!customConfigFile.exists()) {
    239. customConfigFile.createNewFile();
    240. }
    241. }
    242. catch (IOException e)
    243. {
    244. e.printStackTrace();
    245. System.out.println(customConfigFile.getAbsolutePath());
    246. System.out.println("[Riptide] Could not create Player config for " + player);
    247. }
    248. customConfig = YamlConfiguration.loadConfiguration(customConfigFile);
    249.  
    250. customConfig.addDefault("Sword", Boolean.valueOf(true));
    251. customConfig.addDefault("Bow", Boolean.valueOf(true));
    252. customConfig.addDefault("Fist", Boolean.valueOf(true));
    253.  
    254. customConfig.options().copyDefaults(true);
    255. try
    256. {
    257. if (!customConfigFile.exists()) {
    258. customConfigFile.createNewFile();
    259. }
    260. }
    261. catch (IOException e)
    262. {
    263. e.printStackTrace();
    264. System.out.println(customConfigFile.getAbsolutePath());
    265. System.out.println("[Riptide]Could not save config for " + player);
    266. }
    267. return customConfig;
    268. }
    269.  
    270. public void savePlayerConfig(String player)
    271. {
    272. File plrConfigDir = new File("./Plugins/Riptide/players");
    273. if (!plrConfigDir.exists()) {
    274. plrConfigDir.mkdirs();
    275. }
    276. if (tplayers.containsKey(player))
    277. {
    278. File customConfigFile = new File("./Plugins/Riptide/players", player + ".yml");
    279. TrackedPlayer tplr = (TrackedPlayer)tplayers.get(player);
    280. FileConfiguration config = loadPlayerConfig(player);
    281.  
    282. config.set("Sword", tplr.getSword());
    283. config.set("Bow", tplr.getBow());
    284. config.set("Fist", tplr.getFists());
    285. try
    286. {
    287. if (!customConfigFile.exists()) {
    288. customConfigFile.createNewFile();
    289. }
    290. config.save(customConfigFile);
    291. }
    292. catch (IOException ex)
    293. {
    294. ex.printStackTrace();
    295. System.out.println("[Riptide]Could not save config for " + player);
    296. }
    297. }
    298. }
    299.  
    300. public void reloadTrackedPlayers()
    301. {
    302. Player[] players = getServer().getOnlinePlayers();
    303. for (Player cplayer : players)
    304. {
    305. FileConfiguration plrconfig = loadPlayerConfig(cplayer.getName());
    306. TrackedPlayer tplr = new TrackedPlayer(cplayer, plrconfig.getBoolean("Sword"), plrconfig.getBoolean("Bow"), plrconfig.getBoolean("Fists"));
    307. tplayers.put(cplayer.getName(), tplr);
    308. }
    309. }
    310.  
    311. public void saveTrackedPlayers()
    312. {
    313. Player[] players = getServer().getOnlinePlayers();
    314. for (Player cplayer : players) {
    315. savePlayerConfig(cplayer.getName());
    316. }
    317. }
    318.  
    319. public static Boolean getGlobalSword()
    320. {
    321. return Boolean.valueOf(rsword);
    322. }
    323.  
    324. public static Boolean getGlobalBow()
    325. {
    326. return Boolean.valueOf(rbow);
    327. }
    328.  
    329. public static Boolean getGlobalFists()
    330. {
    331. return Boolean.valueOf(rfists);
    332. }
    333.  
    334. public String boolToString(Boolean in)
    335. {
    336. String out = "Disabled";
    337. if (in.booleanValue()) {
    338. out = "Enabled";
    339. }
    340. return out;
    341. }
    342.  
    343. public static boolean isInteger(String s)
    344. {
    345. try
    346. {
    347. Integer.parseInt(s);
    348. }
    349. {
    350. return false;
    351. }
    352. return true;
    353. }
    354. }
    355.  
     
  11. Offline

    AKZOBIE74

    bump it hasn't been replied to in a while guys plese help me
     
  12. Offline

    _feedDz

    well... ill right the code for you just give me a min. by the looks of this you have quite a bit of experience why cant you do this yourself?
     
  13. Offline

    AKZOBIE74

    Its because i have never needed to do this so i don't how to do it.
     
  14. Offline

    _feedDz

    here this should work for you :)
    Code:java
    1. @SuppressWarnings("deprecation")
    2. public void interact(PlayerInteractEvent event) {
    3. Player player = event.getPlayer();
    4.  
    5. if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
    6. if (player.hasPermission("your.permision")) {
    7. if (player.getItemInHand().equals(Material.DIAMOND_SWORD)) {
    8. player.getItemInHand().setType(Material.STICK);
    9. }
    10.  
    11. if (player.getItemInHand().equals(Material.STICK)) {
    12. player.getItemInHand().setType(Material.DIAMOND_SWORD);
    13.  
    14. }
    15. }
    16. }
    17. if (event.getAction().equals(Action.LEFT_CLICK_AIR) || event.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
    18. if (player.hasPermission("your.permision")) {
    19. if (player.getItemInHand().equals(Material.DIAMOND_SWORD)) {
    20. player.getWorld().strikeLightning(player.getTargetBlock(null, 200).getLocation());
    21.  
    22. }
    23. }
    24.  
    25. }
    26. }
     
  15. Offline

    AKZOBIE74

    Where do i put it?
     
  16. Offline

    _feedDz

    id make another event listener class then register your listener class in your onEnable()
     
    AKZOBIE74 likes this.
  17. Offline

    AKZOBIE74

    Thank you so much man!! :)

    _feedDz Dude i want them to select a specific diamond sword i hve the craftig recipe of the specific diamond sword i want here i will post the code can you please help me with that?
    Code:java
    1. ItemStack Riptide = new ItemStack(Material.DIAMOND_SWORD, 1);
    2. ItemMeta Riptidemeta = Riptide.getItemMeta();
    3. Riptidemeta.setDisplayName(ChatColor.DARK_RED + "Riptide");
    4. Riptide.setItemMeta(Riptidemeta);
    5. ShapedRecipe recipe = new ShapedRecipe(Riptide);
    6. recipe.shape(new String[] { "£££", "£*£", "£££" });
    7. recipe.setIngredient('£', Material.EMERALD_BLOCK);
    8. recipe.setIngredient('*', Material.EMERALD_ORE);
    9. Bukkit.getServer().addRecipe(recipe);


    _feedDz Dude the code doesn't work here i created a new class and here is my main class

    Class:
    Code:java
    1. package me.AKZOMBIE74;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.block.Action;
    7. import org.bukkit.event.player.PlayerInteractEvent;
    8.  
    9. public class Clicklistener implements Listener {
    10.  
    11.  
    12. @SuppressWarnings("deprecation")
    13. public void interact(PlayerInteractEvent event) {
    14. Player player = event.getPlayer();
    15.  
    16. if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
    17. if (player.hasPermission("Switch.permision")) {
    18. if (player.getItemInHand().equals(Material.DIAMOND_SWORD)) {
    19. player.getItemInHand().setType(Material.STICK);
    20. }
    21.  
    22. if (player.getItemInHand().equals(Material.STICK)) {
    23. player.getItemInHand().setType(Material.DIAMOND_SWORD);
    24.  
    25. }
    26. }
    27. }
    28. if (event.getAction().equals(Action.LEFT_CLICK_AIR) || event.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
    29. if (player.hasPermission("LS.permision")) {
    30. if (player.getItemInHand().equals(Material.DIAMOND_SWORD)) {
    31. player.getWorld().strikeLightning(player.getTargetBlock(null, 200).getLocation());
    32.  
    33. }
    34. }
    35.  
    36. }
    37. }
    38. }


    Main(I just entered the onEnable part):
    Code:java
    1. public class Riptide
    2. extends JavaPlugin implements Listener
    3. {
    4. private static boolean rsword;
    5. private static boolean rbow;
    6. private static boolean rfists = false;
    7. public static int dmgm = 5;
    8. public static Map<String, TrackedPlayer> tplayers = new HashMap();
    9. private static Riptide instance = null;
    10. private DamageListener damageListener;
    11. private PlayerHandle playerHandle;
    12. private Clicklistener clicklistener;
    13.  
    14.  
    15. public Clicklistener getClicklistener()
    16. {
    17. return this.clicklistener;
    18. }
    19.  
    20. public DamageListener getDamageListener()
    21. {
    22. return this.damageListener;
    23. }
    24.  
    25. public PlayerHandle getPlayerHandle()
    26. {
    27. return this.playerHandle;
    28. }
    29.  
    30. public void onEnable()
    31. {
    32. loadConfig();
    33. instance = this;
    34. reloadTrackedPlayers();
    35.  
    36. this.damageListener = new DamageListener();
    37. this.playerHandle = new PlayerHandle();
    38. this.clicklistener = new Clicklistener();
    39. Bukkit.getPluginManager().registerEvents(this.damageListener, this);
    40. Bukkit.getPluginManager().registerEvents(this.playerHandle, this);
    41. Bukkit.getPluginManager().registerEvents(this.clicklistener, this);
    42.  
    43. ItemStack Riptide = new ItemStack(Material.DIAMOND_SWORD, 1);
    44. ItemMeta Riptidemeta = Riptide.getItemMeta();
    45. Riptidemeta.setDisplayName(ChatColor.DARK_RED + "Riptide");
    46. Riptide.setItemMeta(Riptidemeta);
    47. ShapedRecipe recipe = new ShapedRecipe(Riptide);
    48. recipe.shape(new String[] { "£££", "£*£", "£££" });
    49. recipe.setIngredient('£', Material.EMERALD_BLOCK);
    50. recipe.setIngredient('*', Material.EMERALD_ORE);
    51. Bukkit.getServer().addRecipe(recipe);
    52.  
    53. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  18. Offline

    MeRPG

    What do you mean by the code doesn't work? What's the error?
     
  19. Offline

    _feedDz

    AKZOBIE74 im not sure how you want to create the sword with the event when you right click it turns to a stick do you want it to be this specific sword?

    Code:java
    1. @SuppressWarnings("deprecation")
    2. public void interact(PlayerInteractEvent event) {
    3. ItemStack sword = new ItemStack(Material.DIAMOND_SWORD, 1);
    4. sword.getItemMeta().setDisplayName(ChatColor.DARK_RED + "Riptide");
    5. Player player = event.getPlayer();
    6.  
    7. if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
    8. if (player.hasPermission("your.permision")) {
    9. if (player.getItemInHand().equals(Material.DIAMOND_SWORD)) {
    10. if(player.getItemInHand().getItemMeta().getDisplayName() == ChatColor.DARK_RED + "Riptide"){
    11. player.getItemInHand().setType(Material.STICK);
    12. }
    13. }
    14.  
    15. if (player.getItemInHand().equals(Material.STICK)) {
    16. player.getInventory().setItemInHand(sword);
    17.  
    18. }
    19. }
    20. }
    21. if (event.getAction().equals(Action.LEFT_CLICK_AIR) || event.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
    22. if (player.hasPermission("your.permision")) {
    23. if (player.getItemInHand().equals(Material.DIAMOND_SWORD)) {
    24. if(player.getItemInHand().getItemMeta().getDisplayName() == ChatColor.DARK_RED + "Riptide"){
    25. player.getWorld().strikeLightning(player.getTargetBlock(null, 200).getLocation());
    26.  
    27. }
    28. }
    29. }
    30.  
    31. }
    32. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  20. Offline

    AKZOBIE74

    MeRPG It doesnt turn the diamond sword into a stick and it doesnt shoot out lightning

    _feedDz yes i do

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  21. Offline

    _feedDz

    add @EventHandler
     
  22. Offline

    AKZOBIE74

    Ok guys just so you know i am using a 1.6.4 bukkit api

    Ok guys here is the code i am using
    Code:java
    1. package me.AKZOMBIE74;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.block.Action;
    9. import org.bukkit.event.player.PlayerInteractEvent;
    10. import org.bukkit.inventory.ItemStack;
    11.  
    12. public class Clicklistener implements Listener {
    13.  
    14. Riptide mainClass = new Riptide();
    15.  
    16. @EventHandler
    17. @SuppressWarnings("deprecation")
    18. public void interact(PlayerInteractEvent event) {
    19. ItemStack sword = new ItemStack(Material.DIAMOND_SWORD, 1);
    20. sword.getItemMeta().setDisplayName(ChatColor.DARK_RED + "Riptide");
    21. Player player = event.getPlayer();
    22.  
    23. if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
    24. if (player.hasPermission("Switch.riptide")) {
    25. if (player.getItemInHand().equals(Material.DIAMOND_SWORD)) {
    26. if(player.getItemInHand().getItemMeta().getDisplayName() == ChatColor.DARK_RED + "Riptide"){
    27. player.getItemInHand().setType(Material.STICK);
    28. }
    29. }
    30.  
    31. if (player.getItemInHand().equals(Material.STICK)) {
    32. player.getInventory().setItemInHand(sword);
    33.  
    34. }
    35. }
    36. }
    37. if (event.getAction().equals(Action.LEFT_CLICK_AIR) || event.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
    38. if (player.hasPermission("LS.riptide")) {
    39. if (player.getItemInHand().equals(Material.DIAMOND_SWORD)) {
    40. if(player.getItemInHand().getItemMeta().getDisplayName() == ChatColor.DARK_RED + "Riptide"){
    41. player.getWorld().strikeLightning(player.getTargetBlock(null, 200).getLocation());
    42.  
    43. }
    44. }
    45. }
    46.  
    47. }
    48. }
    49. }
    50.  


    _feedDz dude are you still here? if you are check out the post above this one

    the code still does not work

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  23. Offline

    _feedDz

    ok well can you post your onEnable()
     
  24. Offline

    AKZOBIE74

    _feedDz sure here you go
    Code:java
    1. public void onEnable()
    2. {
    3. loadConfig();
    4. instance = this;
    5. reloadTrackedPlayers();
    6.  
    7. this.damageListener = new DamageListener();
    8. this.playerHandle = new PlayerHandle();
    9. this.clicklistener = new Clicklistener();
    10. Bukkit.getPluginManager().registerEvents(this.damageListener, this);
    11. Bukkit.getPluginManager().registerEvents(this.playerHandle, this);
    12. Bukkit.getPluginManager().registerEvents(this.clicklistener, this);
    13.  
    14. ItemStack Riptide = new ItemStack(Material.DIAMOND_SWORD, 1);
    15. ItemMeta Riptidemeta = Riptide.getItemMeta();
    16. Riptidemeta.setDisplayName(ChatColor.DARK_RED + "Riptide");
    17. Riptide.setItemMeta(Riptidemeta);
    18. ShapedRecipe recipe = new ShapedRecipe(Riptide);
    19. recipe.shape(new String[] { "£££", "£*£", "£££" });
    20. recipe.setIngredient('£', Material.EMERALD_BLOCK);
    21. recipe.setIngredient('*', Material.EMERALD_ORE);
    22. Bukkit.getServer().addRecipe(recipe);
     
  25. Offline

    _feedDz

    is all the classes in 1 package?
     
  26. Offline

    AKZOBIE74

  27. Offline

    _feedDz

    Code:java
    1. //You should use this to register events
    2. getServer().getPluginManager().registerEvents(new [Your class name](this),this);


    Code:java
    1. //example
    2. getServer().getPluginManager().registerEvents(new damageListener(this), this)


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  28. Offline

    AKZOBIE74

    _feedDz ok so i put in the code but it says "the contructor "Riptide" is undefined"
    Code:java
    1. getServer().getPluginManager().registerEvents(new Clicklistener(this),this);
     
  29. Offline

    _feedDz

    does your other classes extends JavaPlugin?
     
  30. Offline

    AKZOBIE74

Thread Status:
Not open for further replies.

Share This Page