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

    _feedDz

    try and register events like this
    Code:java
    1. getServer().getPluginManager().registerEvents(new Clicklistener(),this);
     
  2. Offline

    AKZOBIE74

    _feedDz ok i did that and i made every class extend JavPlugin

    _feedDz this is wht my onEnable looks like
    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.  
    11. getServer().getPluginManager().registerEvents(new DamageListener(),this);
    12. getServer().getPluginManager().registerEvents(new PlayerHandle(),this);
    13. getServer().getPluginManager().registerEvents(new Clicklistener(),this);
    14.  
    15. ItemStack Riptide = new ItemStack(Material.DIAMOND_SWORD, 1);
    16. ItemMeta Riptidemeta = Riptide.getItemMeta();
    17. Riptidemeta.setDisplayName(ChatColor.DARK_RED + "Riptide");
    18. Riptide.setItemMeta(Riptidemeta);
    19. ShapedRecipe recipe = new ShapedRecipe(Riptide);
    20. recipe.shape(new String[] { "£££", "£*£", "£££" });
    21. recipe.setIngredient('£', Material.EMERALD_BLOCK);
    22. recipe.setIngredient('*', Material.EMERALD_ORE);
    23. Bukkit.getServer().addRecipe(recipe);
    24.  
    25. }


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

    _feedDz

    remove lines 7,8,9. then try it out
     
  4. Offline

    AKZOBIE74

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


    it doesnt work

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

    _feedDz

    i dont see anything sorry :/
     
  6. Offline

    AKZOBIE74

    _feedDz ok dude here i am going to give you my whole class's and tell me whats wrong

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


    Damage Listener:
    Code:java
    1. package me.AKZOMBIE74;
    2.  
    3. import java.io.PrintStream;
    4. import java.util.Map;
    5. import org.bukkit.entity.Arrow;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.EventPriority;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    11. import org.bukkit.inventory.ItemStack;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class DamageListener extends JavaPlugin
    15. implements Listener
    16. {
    17. Riptide mainClass = new Riptide();
    18.  
    19. @EventHandler(priority=EventPriority.MONITOR)
    20. public void damageListener(EntityDamageByEntityEvent event)
    21. {
    22. if ((event.getDamager() instanceof Player))
    23. {
    24. Player player = (Player)event.getDamager();
    25. TrackedPlayer tplr = (TrackedPlayer)Riptide.tplayers.get(player.getName());
    26. int item = player.getItemInHand().getTypeId();
    27. if (tplr != null)
    28. {
    29. if ((item == 267) || (item == 268) || (item == 272) || (item == 276) || (item == 283))
    30. {
    31. if ((Riptide.getGlobalSword().booleanValue()) && (tplr.getSword().booleanValue()) &&
    32. (player.hasPermission("riptide.use.sword"))) {
    33. event.setDamage(event.getDamage() * Riptide.dmgm);
    34. }
    35. }
    36. else if ((item == 0) && (tplr.getFists().booleanValue()) &&
    37. (Riptide.getGlobalFists().booleanValue()) &&
    38. (player.hasPermission("riptide.use.fists"))) {
    39. event.setDamage(event.getDamage() * Riptide.dmgm);
    40. }
    41. }
    42. else {
    43. System.out.println(Riptide.tplayers.size());
    44. }
    45. }
    46. else if (((event.getDamager() instanceof Arrow)) &&
    47. ((((Arrow)event.getDamager()).getShooter() instanceof Player)))
    48. {
    49. Player player = (Player)((Arrow)event.getDamager()).getShooter();
    50.  
    51. TrackedPlayer tplr = (TrackedPlayer)Riptide.tplayers.get(player.getName());
    52. int item = player.getItemInHand().getTypeId();
    53. if ((item == 261) && (tplr.getBow().booleanValue()) &&
    54. (Riptide.getGlobalBow().booleanValue()) &&
    55. (player.hasPermission("riptide.use.bow"))) {
    56. event.setDamage(event.getDamage() * Riptide.dmgm);
    57. }
    58. }
    59. }
    60. }


    Clicklistener:
    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. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class Clicklistener extends JavaPlugin implements Listener {
    14.  
    15. Riptide mainClass = new Riptide();
    16.  
    17. @EventHandler
    18. @SuppressWarnings("deprecation")
    19. public void interact(PlayerInteractEvent event) {
    20. ItemStack sword = new ItemStack(Material.DIAMOND_SWORD, 1);
    21. sword.getItemMeta().setDisplayName(ChatColor.DARK_RED + "Riptide");
    22. Player player = event.getPlayer();
    23.  
    24. if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
    25. if (player.hasPermission("Switch.riptide")) {
    26. if (player.getItemInHand().equals(Material.DIAMOND_SWORD)) {
    27. if(player.getItemInHand().getItemMeta().getDisplayName() == ChatColor.DARK_RED + "Riptide"){
    28. player.getItemInHand().setType(Material.STICK);
    29. }
    30. }
    31.  
    32. if (player.getItemInHand().equals(Material.STICK)) {
    33. player.getInventory().setItemInHand(sword);
    34.  
    35. }
    36. }
    37. }
    38. if (event.getAction().equals(Action.LEFT_CLICK_AIR) || event.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
    39. if (player.hasPermission("LS.riptide")) {
    40. if (player.getItemInHand().equals(Material.DIAMOND_SWORD)) {
    41. if(player.getItemInHand().getItemMeta().getDisplayName() == ChatColor.DARK_RED + "Riptide"){
    42. player.getWorld().strikeLightning(player.getTargetBlock(null, 200).getLocation());
    43.  
    44. }
    45. }
    46. }
    47.  
    48. }
    49. }
    50. }
    51.  
    52.  
    53.  
    54.  
    55.  


    Tracked Player:
    Code:java
    1. package me.AKZOMBIE74;
    2.  
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.plugin.java.JavaPlugin;
    5.  
    6. public class TrackedPlayer extends JavaPlugin
    7. {
    8. private Player player;
    9. private Boolean rsword;
    10. private Boolean rbow;
    11. private Boolean rfists = Boolean.valueOf(false);
    12.  
    13. public TrackedPlayer(Player plr, boolean sword, boolean bow, boolean fists)
    14. {
    15. this.player = plr;
    16. this.rsword = Boolean.valueOf(sword);
    17. this.rbow = Boolean.valueOf(bow);
    18. this.rfists = Boolean.valueOf(fists);
    19. }
    20.  
    21. public Player getPlayer()
    22. {
    23. return this.player;
    24. }
    25.  
    26. public Boolean getSword()
    27. {
    28. return this.rsword;
    29. }
    30.  
    31. public Boolean getBow()
    32. {
    33. return this.rbow;
    34. }
    35.  
    36. public Boolean getFists()
    37. {
    38. return this.rfists;
    39. }
    40.  
    41. public Boolean toggleSword()
    42. {
    43. if (this.rsword.booleanValue()) {
    44. this.rsword = Boolean.valueOf(false);
    45. } else {
    46. this.rsword = Boolean.valueOf(true);
    47. }
    48. return this.rsword;
    49. }
    50.  
    51. public Boolean toggleBow()
    52. {
    53. if (this.rbow.booleanValue()) {
    54. this.rbow = Boolean.valueOf(false);
    55. } else {
    56. this.rbow = Boolean.valueOf(true);
    57. }
    58. return this.rbow;
    59. }
    60.  
    61. public Boolean toggleFists()
    62. {
    63. if (this.rfists.booleanValue()) {
    64. this.rfists = Boolean.valueOf(false);
    65. } else {
    66. this.rfists = Boolean.valueOf(true);
    67. }
    68. return this.rfists;
    69. }
    70.  
    71. public void setSword(Boolean in)
    72. {
    73. this.rsword = in;
    74. }
    75.  
    76. public void setBow(Boolean in)
    77. {
    78. this.rbow = in;
    79. }
    80.  
    81. public void setFists(Boolean in)
    82. {
    83. this.rfists = in;
    84. }
    85.  
    86. public void setAll(boolean sword, boolean bow, boolean fists)
    87. {
    88. this.rsword = Boolean.valueOf(sword);
    89. this.rbow = Boolean.valueOf(bow);
    90. this.rfists = Boolean.valueOf(fists);
    91. }
    92. }


    Player Handle:
    Code:java
    1. package me.AKZOMBIE74;
    2.  
    3. import java.util.Map;
    4. import org.bukkit.configuration.file.FileConfiguration;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.EventPriority;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.player.PlayerJoinEvent;
    10. import org.bukkit.event.player.PlayerQuitEvent;
    11.  
    12. public class PlayerHandle
    13. implements Listener
    14. {
    15. Riptide mainClass = new Riptide();
    16.  
    17. @EventHandler(priority=EventPriority.MONITOR)
    18. public void playerJoin(PlayerJoinEvent event)
    19. {
    20. Player player = event.getPlayer();
    21. FileConfiguration plrconfig = this.mainClass.loadPlayerConfig(player.getName());
    22. TrackedPlayer tplr = new TrackedPlayer(player, plrconfig.getBoolean("Sword"), plrconfig.getBoolean("Bow"), plrconfig.getBoolean("Fists"));
    23. Riptide.tplayers.put(player.getName(), tplr);
    24. }
    25.  
    26. @EventHandler(priority=EventPriority.MONITOR)
    27. public void playerleave(PlayerQuitEvent event)
    28. {
    29. Player player = event.getPlayer();
    30. this.mainClass.savePlayerConfig(player.getName());
    31. Riptide.tplayers.remove(player.getName());
    32. }
    33. }


    bump somebody please help me!

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

    _feedDz

    is there a error? if so post it for me.
     
  8. Offline

    AKZOBIE74

    _feedDz i ws hoping you would check the class files and tell me
     
  9. Offline

    _feedDz

    no i mean is there a error int the code like a red line??
     
  10. Offline

    AKZOBIE74

    _feedDz no sir there is not keep in mind i am using bukkit-1.6.4-R2.0.jar api not craftbukkit api
     
  11. Offline

    ResultStatic

    AKZOBIE74 your @EventHandler needs to go right above the method. move the supress warning above it

    also your tracked player extends JavaPlugin only your main class should extend JavaPlugin.

    if you want your plugin instance do public TrackPlayer(Plugin plugin){
    or create a static reference to it and do Main.getPluginInstance();
     
  12. Offline

    AKZOBIE74

    ResultStatic it did not work

    Guys come on everything works except for the clicklistener class what do all the other classes have that make them work that the clicklistener class does not?

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

    _feedDz

    one sec... can you post your click listener class and just your onEnable().
    ResultStatic You should never create a static reference as your main class it is bad practice.
     
    ZodiacTheories likes this.
  14. Offline

    AKZOBIE74

    _feedDz

    OnEnable:
    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.entity.Player;
    20. import org.bukkit.event.Listener;
    21. import org.bukkit.event.block.Action;
    22. import org.bukkit.event.player.PlayerInteractEvent;
    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. private Clicklistener clicklistener;
    41.  
    42. public Clicklistener getClicklistener()
    43. {
    44. return this.clicklistener;
    45. }
    46.  
    47.  
    48. public DamageListener getDamageListener()
    49. {
    50. return this.damageListener;
    51. }
    52.  
    53. public PlayerHandle getPlayerHandle()
    54. {
    55. return this.playerHandle;
    56. }
    57.  
    58. public void onEnable()
    59. {
    60. loadConfig();
    61. instance = this;
    62. reloadTrackedPlayers();
    63.  
    64. getServer().getPluginManager().registerEvents(new DamageListener(),this);
    65. getServer().getPluginManager().registerEvents(new PlayerHandle(),this);
    66. getServer().getPluginManager().registerEvents(new Clicklistener(),this);
    67.  
    68. ItemStack Riptide = new ItemStack(Material.DIAMOND_SWORD, 1);
    69. ItemMeta Riptidemeta = Riptide.getItemMeta();
    70. Riptidemeta.setDisplayName(ChatColor.DARK_RED + "Riptide");
    71. Riptide.setItemMeta(Riptidemeta);
    72. ShapedRecipe recipe = new ShapedRecipe(Riptide);
    73. recipe.shape(new String[] { "£££", "£*£", "£££" });
    74. recipe.setIngredient('£', Material.EMERALD_BLOCK);
    75. recipe.setIngredient('*', Material.EMERALD_ORE);
    76. Bukkit.getServer().addRecipe(recipe);
    77.  
    78. ItemStack pen = new ItemStack(Material.STICK, 1);
    79. ItemMeta penmeta = pen.getItemMeta();
    80. penmeta.setDisplayName(ChatColor.WHITE + "Pen");
    81. pen.setItemMeta(penmeta);
    82. ShapedRecipe recipes = new ShapedRecipe(pen);
    83. recipes.shape(new String[] { "£££", "£*£", "£££" });
    84. recipes.setIngredient('£', Material.STICK);
    85. recipes.setIngredient('*', Material.EMERALD_ORE);
    86. Bukkit.getServer().addRecipe(recipes);
    87.  
    88. }
    89.  


    Clicklistener:
    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. public void interact(PlayerInteractEvent event) {
    18. ItemStack Riptide = new ItemStack(Material.DIAMOND_SWORD, 1);
    19. Riptide.getItemMeta().setDisplayName(ChatColor.DARK_RED + "Riptide");
    20. Player player = event.getPlayer();
    21. ItemStack pen = new ItemStack(Material.STICK, 1);
    22. pen.getItemMeta().setDisplayName(ChatColor.WHITE + "Pen");
    23.  
    24. if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
    25. if (player.hasPermission("Switch.riptide")) {
    26. if (player.getItemInHand().equals(Material.DIAMOND_SWORD)) {
    27. if(player.getItemInHand().getItemMeta().getDisplayName() == ChatColor.DARK_RED + "Riptide"){
    28. player.getInventory().setItemInHand(pen);
    29.  
    30. }
    31. }
    32.  
    33. if (player.getItemInHand().equals(Material.STICK)) {
    34. if(player.getItemInHand().getItemMeta().getDisplayName() == ChatColor.WHITE + "Pen"){
    35. player.getInventory().setItemInHand(Riptide);
    36.  
    37. }
    38. }
    39. }
    40.  
    41.  
    42. }
    43. }
    44.  
    45. }
    46.  
    47.  
    48.  
    49.  
    50.  
     
  15. Offline

    _feedDz

    try and add debug messsages and see if the event in your click listener is being called at all them post your results
     
  16. Offline

    AKZOBIE74

    _feedDz what do you mean by ebug messages?

    _feedDz when i launch the plugin the start.bat says everything is fine in the plugin.It doesnt show any error messages in the plugin

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

    xTigerRebornx

    AKZOBIE74
    Code:
     if (player.getItemInHand().equals(Material.DIAMOND_SWORD)) {
    This will never be true, you are seeing if an ItemStack is equal to a Material. You need to check the ItemStack's type to see if it is equal
     
  18. Offline

    AKZOBIE74

    xTigerRebornx could you post an example of it so i know what you mean?
     
  19. Offline

    xTigerRebornx

  20. Offline

    AKZOBIE74

    xTigerRebornx ok so i changed it to this is this what you mean?
    Code:java
    1. if (player.getItemInHand().equals(Riptide)) {


    @xTigerRebornx Dude i need your help.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  21. AKZOBIE74 In the clickListener, remove the new Riptide bit - that's just going to ruin everything.

    Instead of checking if they are holding a diamond sword, do this:
    [1] Make sure the type (getType()) is a DIAMOND_SWORD/STICK
    [2] Make sure it has ItemMeta and a Display name
    [3] Make sure the display name equals the display name on the specific item (include the chatcolor part)
    [4] Then you can be certain that they are holding the correct item with the correct display name.

    So,
    Code:
    if(player.getItemInHand.getType().equals(Material.DIAMOND_SWORD) && player.getItemInHand.hasItemMeta() && player.getItemInHand.getDisplayName().equals(ChatColor.DARK_RED + "Riptide") {
        player.setItemInHand(pen);
    }
    And vice versa with the pen.

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

    AKZOBIE74

    DJSkepter i dont understand what you mean

    @DJSkepter oh ok now i get it thanks

    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

    Code:java
    1. //replace
    2. if(p.getItemInHand().equals(Material.DIAMOND_SWORD)){
    3. p.setItemInHand(pen);
    4. }
    5. //with
    6. if(player.getItemInHand.getType().equals(Material.DIAMOND_SWORD) && player.getItemInHand.hasItemMeta() && player.getItemInHand.getDisplayName().equals(ChatColor.DARK_RED + "Riptide") {
    7. player.setItemInHand(pen);
    8. }
     
  24. Offline

    AKZOBIE74

    @DJSkepter a red line is under the code "getDisplayName() " what do i do?It says its undefined for the type ItemStack

    DJSkepter I need your help

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  25. AKZOBIE74 My bad -
    Code:
    getItemMeta().getDisplayName()
     
  26. Offline

    AKZOBIE74

    DJSkepter ok so when i craft my pen with my custom crafting recipe and i right click the pen it turns into a diamond sword and the name of the diamond sword is "diamond sword" when i right click the diamond sword it doesn't turn into the pen and when i use my custom crafting recipe for the Riptide and i right click the riptide the riptide doesn't turn into the pen here is my code:
    Code:java
    1. if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
    2. if (player.hasPermission("riptide.switch")) {
    3. if(player.getItemInHand().getType().equals(Material.DIAMOND_SWORD) && player.getItemInHand().hasItemMeta() && player.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.DARK_RED + "Riptide")) {
    4. player.setItemInHand(pen);
    5. }
    6. }
    7.  
    8. if(player.getItemInHand().getType().equals(Material.STICK) && player.getItemInHand().hasItemMeta() && player.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.WHITE + "Pen")) {
    9. player.setItemInHand(Riptide);
    10. }
    11. }
    12. }
    13. }
     
  27. AKZOBIE74 Do you have the permission enabled? You don't seem to need the permission riptide.switch to turn the pen into the diamond sword, but you do need the permission to turn the diamond sword into the pen.
     
  28. Offline

    AKZOBIE74

    DJSkepter i opped myself

    DJSkepter How do i make it so that when i right click the pen and the stick is turned into the diamond sword for the diamond sword to be named "Riptide" in dark red the same way around for when i right click the diamond sword but i except i want the stick to be named "Pen" in white.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  29. AKZOBIE74 Show me your entire command class.
     
  30. Offline

    AKZOBIE74

    DJSkepter here
    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. public void interact(PlayerInteractEvent event) {
    18. ItemStack Riptide = new ItemStack(Material.DIAMOND_SWORD, 1);
    19. Riptide.getItemMeta().setDisplayName(ChatColor.DARK_RED + "Riptide");
    20. Player player = event.getPlayer();
    21. ItemStack pen = new ItemStack(Material.STICK, 1);
    22. pen.getItemMeta().setDisplayName(ChatColor.WHITE + "Pen");
    23.  
    24. if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
    25. if (player.hasPermission("riptide.switch")) {
    26. if(player.getItemInHand().getType().equals(Material.DIAMOND_SWORD) && player.getItemInHand().hasItemMeta() && player.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.DARK_RED + "Riptide")) {
    27. player.setItemInHand(pen);
    28.  
    29. }
    30. }
    31. }
    32.  
    33. if(player.getItemInHand().getType().equals(Material.STICK) && player.getItemInHand().hasItemMeta() && player.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.WHITE + "Pen")) {
    34. player.setItemInHand(Riptide);
    35. }
    36. }
    37. }
     
Thread Status:
Not open for further replies.

Share This Page