[Not Fixed] Factions API Hook

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

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

    Prominentc

    I have a Factions API problem with a custom plugin and need help to get aspects of it altered to suit new Factions API.

    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 .

    Basically there are 2 small hooks to the Factions API one checks the the location of the click sign and checks if the faction is in the ~Wilderness the other tells you the sign is on faction claimed land and returns the faction name with a message saying you can't pick.

    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.  


    Current code is giving errors on lines 17, 18, 19 and 42.

    Can anyone give any pointers or actually edit the code to work?

    Any help is appreciated, without this plugin the whole server is screwed.

    Just one problem now "FLocation cannot be resolved to a typeLockPickEvents.java":

    The code:

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


    I think I managed to fix the code although I could be wrong I just do trial and error, but how do I fix the above error :/

    Any help is appreciated.

    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