Simple but so hard for me

Discussion in 'Plugin Development' started by Prominentc, Sep 5, 2013.

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

    Prominentc

    I have a problem with a custom plugin and need help to get aspects of it altered to suit new API (I don't know java but can compile the .java files to .class files in Eclipse.

    The lock pick plugin worked fine with the Factions 1.6.9.5 plugin, however the Factions plugin as since been updated quite a lot and it's just now that I decided to upgrade Factions to the latest version Factions 2.1.0 MCore 6.7.X .

    But of course the API has changed and now I'm getting 5 errors in one class file and my plugin doesn't work, this is the code from the class file below:

    Code:java
    1. package lockpick;
    2.  
    3. import java.util.HashSet;
    4. import java.util.Random;
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.block.Block;
    8. import org.bukkit.block.BlockState;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.EventPriority;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.event.block.Action;
    14. import org.bukkit.event.player.PlayerInteractEvent;
    15. import org.bukkit.block.Sign;
    16.  
    17. import com.massivecraft.factions.Board;
    18. import com.massivecraft.factions.FLocation;
    19. import com.massivecraft.factions.Faction;
    20.  
    21. public class LockPickEvents implements Listener {
    22.  
    23. static HashSet<String> cooldown = new HashSet<String>();
    24.  
    25. @EventHandler(priority=EventPriority.HIGHEST)
    26. public void pickLockInteraction(PlayerInteractEvent e){
    27. Player p = e.getPlayer();
    28. if (e.getAction() != Action.LEFT_CLICK_BLOCK) {
    29. return;
    30. }
    31.  
    32. if(!p.hasPermission("LockPick.Use")){
    33. return;
    34. }
    35.  
    36. if(playerIsLockPicking(p, e.getClickedBlock())){
    37.  
    38. if(GetObject.factionProtectionEnabled()){
    39.  
    40. e.setCancelled(true);
    41.  
    42. Faction faction = Board.getFactionAt(new FLocation(e.getClickedBlock().getLocation()));
    43.  
    44. if(!faction.isNone()){
    45.  
    46. if(!p.hasPermission("LockPick.Faction")){
    47. p.sendMessage(ChatColor.RED + "You can only pick locks in the " + ChatColor.YELLOW + "~ " + ChatColor.DARK_GREEN + "Wilderness" + ChatColor.RED + ".");
    48. p.sendMessage(ChatColor.RED + "This chest is on " + ChatColor.YELLOW + faction.getTag() + ChatColor.RED + " faction" + " land.");
    49. return;
    50. }
    51.  
    52. }
    53. }
    54.  
    55.  
    56. if(GetObject.cooldownEnabled()){
    57.  
    58. if(cooldown.contains(p.getName())){
    59. p.sendMessage(ChatColor.RED + "Picklocking is on cooldown.");
    60. return;
    61. }
    62.  
    63. scheduleDelay(p);
    64. }
    65.  
    66. int Rand = new Random().nextInt(GetObject.getlockpickChance());
    67.  
    68. if(Rand != 1){
    69.  
    70. p.sendMessage(ChatColor.RED + GetObject.getFailMessage());
    71. if(GetObject.removeItemEnabled()){
    72.  
    73. if(p.getItemInHand().getAmount() > 1){
    74. p.getItemInHand().setAmount(p.getItemInHand().getAmount()-1);
    75. }else{
    76. p.setItemInHand(null);
    77. }
    78.  
    79. p.sendMessage(ChatColor.GOLD + "You used your picklock!");
    80.  
    81. }
    82. if(GetObject.withdrawMoneyFailedEnabled()){
    83.  
    84. if(Main.economy.getBalance(p.getName()) >= GetObject.getWithdrawFailedAmount()){
    85. Main.economy.withdrawPlayer(p.getName(), GetObject.getWithdrawFailedAmount());
    86. p.sendMessage(ChatColor.RED + "For failing this pick lock attempt you lost $" + GetObject.getWithdrawFailedAmount() + ".");
    87. }
    88.  
    89. }
    90. return;
    91. }
    92.  
    93. p.sendMessage(ChatColor.GREEN + GetObject.getSuccessMessage());
    94.  
    95. e.getClickedBlock().breakNaturally();
    96.  
    97. if(GetObject.withdrawSuccessMoneyEnabled()){
    98.  
    99. if(Main.economy.getBalance(p.getName()) >= GetObject.getWithdrawSuccessAmount()){
    100. Main.economy.withdrawPlayer(p.getName(), GetObject.getWithdrawSuccessAmount());
    101. p.sendMessage(ChatColor.GREEN + "For picking this lock you lost $" + GetObject.getWithdrawSuccessAmount() + ".");
    102. }
    103.  
    104. }
    105.  
    106.  
    107.  
    108.  
    109. }
    110.  
    111. }
    112.  
    113. private void scheduleDelay(final Player p) {
    114. int time = GetObject.getCooldownTimer();
    115. cooldown.add(p.getName());
    116. Main.p.getServer().getScheduler().scheduleSyncDelayedTask(Main.p, new Runnable() {
    117. @Override
    118. public void run(){
    119.  
    120. cooldown.remove(p.getName());
    121.  
    122. }
    123. }, time * 20L);
    124.  
    125. }
    126.  
    127. private boolean playerIsLockPicking(Player p, Block block) {
    128. if(p.getItemInHand().getTypeId() == GetObject.getLockPick() && block.getTypeId() == 68) {
    129. BlockState state = block.getState();
    130. if(state instanceof Sign) {
    131. Sign sign = (Sign)state;
    132. return "[private]".replaceAll("(?i)\u00A7[0-F]", "").equalsIgnoreCase(sign.getLine(0));
    133. }
    134. }
    135. return false;
    136. }}
    137.  


    Would anyone be kind enough to look at the new Factions API and actually replace the old in the code? It's giving errors on lines 17, 18, 19 and 42.

    Telling me what's bits need altering won't make much difference lol
     
  2. Offline

    chasechocolate

    Hitting control + shift + O (letter) in Eclipse I think should fix it.
     
  3. Offline

    Prominentc

    I'm afraid not :(

    Actually I don't think it did anything :/
     
  4. Offline

    WhatAaCow

    @Prominentc
    Error in line
    can't be. There is nothing
     
  5. Offline

    Prominentc

    I re-pasted the entire code incase I missed something:

    42 is;

    Code:java
    1. Faction faction = Board.getFactionAt(new FLocation(e.getClickedBlock().getLocation()));


    And thanks for any help and those that tried to help:)

    If some can do this I would be willing to pay and/or if you need the full source to do this you can also use the plugin.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page