Help out a newb, with a check for sign text

Discussion in 'Plugin Development' started by Prominentc, Mar 8, 2013.

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

    Prominentc

    I have the below code for a lock picking plugin and it does a check to see if a sign is connected to a chest prior to the lock picking taking place.

    Could somebody edit the code for me, so rather than it checking if a sign is connected to a chest it instead checks that the sign has the word "[Private]" on it, that way it would pick all lockette private signs and not just ones on chests.

    I really need someone to edit the code as java might as well be Urdu to me. I've tried for two days to edit this code in my own newb way and got nowhere (sigh)

    Code:
    package me.danslayerx.pick;
     
    import java.util.HashSet;
    import java.util.Random;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockFace;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
     
    import com.massivecraft.factions.Board;
    import com.massivecraft.factions.FLocation;
    import com.massivecraft.factions.FPlayer;
    import com.massivecraft.factions.Faction;
     
    public class PickLockEvents implements Listener {
       
        static HashSet<String> cooldown = new HashSet<String>();
       
        @EventHandler(priority=EventPriority.HIGHEST)
        public void pickLockInteraction(PlayerInteractEvent e){
           
            Player p = e.getPlayer();
           
            if(e.getAction() != Action.LEFT_CLICK_BLOCK){
                return;
            }
           
            if(!p.hasPermission("PickLock.Use")){
                return;
            }
           
            if(playerIsLockPicking(p, e.getClickedBlock())){
               
                if(GetObject.factionProtectionEnabled()){
                   
                    e.setCancelled(true);
                   
                    Faction faction = Board.getFactionAt(new FLocation(e.getClickedBlock().getLocation()));
                   
                    if(!faction.isNone()){
                       
                        if(!p.hasPermission("PickLock.Faction")){
                            p.sendMessage(ChatColor.RED + "You are not able to pick this lock in the faction " + faction.getTag() + ".");
                            return;
                        }
                       
                        for(FPlayer fp : faction.getFPlayers()){
                            if(Bukkit.getPlayer(fp.getName()).hasPermission("PickLock.Faction.Immunity")){
                               
                                p.sendMessage(ChatColor.RED + "The faction " + faction.getTag() + " has locks that are impossible to pick!");
                                return;
                            }
                        }
                       
                    }
                }
               
               
                if(GetObject.cooldownEnabled()){
                   
                    if(cooldown.contains(p.getName())){
                        p.sendMessage(ChatColor.RED + "Picklocking is on cooldown.");
                        return;
                    }
                   
                    scheduleDelay(p);
                }
                   
                    int Rand = new Random().nextInt(GetObject.getPickLockChance());
                   
                    if(Rand != 1){
                       
                        p.sendMessage(ChatColor.RED + GetObject.getFailMessage());
                        if(GetObject.removeItemEnabled()){
                           
                            if(p.getItemInHand().getAmount() > 1){
                                p.getItemInHand().setAmount(p.getItemInHand().getAmount()-1);
                            }else{
                                p.setItemInHand(null);
                            }
                           
                            p.sendMessage(ChatColor.RED + "You break your picklock!");
                           
                        }
                        if(GetObject.withdrawMoneyFailedEnabled()){
                           
                            if(Main.economy.getBalance(p.getName()) >= GetObject.getWithdrawFailedAmount()){
                                Main.economy.withdrawPlayer(p.getName(), GetObject.getWithdrawFailedAmount());
                                p.sendMessage(ChatColor.RED + "For failing this pick lock attempt you lost $" + GetObject.getWithdrawFailedAmount() + ".");
                            }
                           
                        }
                        return;
                    }
                   
                    p.sendMessage(ChatColor.GREEN + GetObject.getSuccessMessage());
                   
                    e.getClickedBlock().breakNaturally();
                   
                    if(GetObject.withdrawSuccessMoneyEnabled()){
                       
                            if(Main.economy.getBalance(p.getName()) >= GetObject.getWithdrawSuccessAmount()){
                                Main.economy.withdrawPlayer(p.getName(), GetObject.getWithdrawSuccessAmount());
                                p.sendMessage(ChatColor.GREEN + "For picking this lock you lost $" + GetObject.getWithdrawSuccessAmount() + ".");
                            }
                       
                    }
                   
                   
     
               
            }
           
        }
     
        private void scheduleDelay(final Player p) {
            int time = GetObject.getCooldownTimer();
            cooldown.add(p.getName());
            Main.p.getServer().getScheduler().scheduleSyncDelayedTask(Main.p, new Runnable() {
                @Override
                public void run(){
           
                    cooldown.remove(p.getName());   
                   
                }                               
        }, time * 20L);
           
        }
     
        private boolean playerIsLockPicking(Player p, Block block) {
                if(p.getItemInHand().getTypeId() == GetObject.getLockPick()){
                    if(block.getTypeId() == 68){
                        if(blockIsConnectedToChest(block)){
                        return true;
                        }
                    }
                }
            return false;
        }
     
        private boolean blockIsConnectedToChest(Block b) {
            Boolean flag = false;
            if(b.getRelative(BlockFace.NORTH).getType().equals(Material.CHEST)){
                flag = true;
            }else if(b.getRelative(BlockFace.WEST).getType().equals(Material.CHEST)){
                flag = true;
            }else if(b.getRelative(BlockFace.EAST).getType().equals(Material.CHEST)){
                flag = true;
            }else if(b.getRelative(BlockFace.SOUTH).getType().equals(Material.CHEST)){
                flag = true;
            }
            if(flag){
                return true;
            }
            return false;
        }
     
    }
    
     
  2. Offline

    ZeusAllMighty11

    if blockIsConnectedToChest(Block b)

    Then you can get the block and check it's a sign, then check blockstate and getLine(0) and see if it's 'Private' or whatever
     
  3. Offline

    Prominentc

    Umm I'll try that. Thanks

    Might be a few days work for me if I even get to complete it without errors :p

    Too complex for a newbie, I tried and I feel like bashing my head on a wall.

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

Share This Page