[Help] Sign Teleport/Breaking/Items

Discussion in 'Plugin Development' started by Wolf_Jacob, Apr 4, 2013.

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

    Wolf_Jacob

    The things i need help with are

    1. [Solved] Not letting me break blocks
    2. [Solver] The teleport signs no longer stay teleport signs when i stop server
    3. [Solved] When i teleport it does give me the items but i cant see it from my perspective but other players can.

    Normal Class:

    Code:
    package Me.Jacob.Lunar;
     
    import java.util.logging.Logger;
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Lunar extends JavaPlugin {
        public final Logger logger = Logger.getLogger("Minecraft");
        public static Lunar plugin;
        public final Sign_Tele pl = new Sign_Tele();
     
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Has Been Disabled!");
        }
     
        @Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Enabled!");
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this.pl, this);
        }
     
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            return false;
        }
    }
    Sign_Teleport Class:

    Code:
    package Me.Jacob.Lunar;
     
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Sign;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.block.SignChangeEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
     
    public class Sign_Tele implements Listener {
        public static Lunar plugin;
     
        @EventHandler
        public void onSignChange(SignChangeEvent e) {
     
            if (e.getLine(1).equalsIgnoreCase("1")) {
                e.getPlayer().sendMessage("Teleportation Sign Created");
            }
        }
     
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            World world = p.getWorld();
            ItemStack Head = new ItemStack(Material.GLASS);
            ItemStack Chest = new ItemStack(Material.LEATHER_CHESTPLATE);
            Chest.setDurability((short) 40);
            ItemStack Legs = new ItemStack(Material.LEATHER_LEGGINGS);
            Legs.setDurability((short) 25);
            ItemStack Boots = new ItemStack(Material.LEATHER_BOOTS);
            Boots.setDurability((short) 35);
            PlayerInventory pi = p.getInventory();
            Location loc = new Location(world, 61.5, 67.0, 196.5);
     
            if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK))
                return;
     
            if (e.getClickedBlock().getState() instanceof Sign) {
                Sign s = (Sign) e.getClickedBlock().getState();
                if (s.getLine(1).equalsIgnoreCase("1")) {
                    e.setCancelled(true);
                    p.teleport(loc);
                    pi.setHelmet(Head);
                    pi.setChestplate(Chest);
                    pi.setLeggings(Legs);
                    pi.setBoots(Boots);
                    p.updateInventory();
                }
            } else {
                return;
            }
        }
    }
    
     
  2. Offline

    CreeperShift

    Try updateInventory, it's deprecated but you can still use it. Might fix your armor not showing up ;)
     
  3. Offline

    Wolf_Jacob

    What would i do for that? cause when i do pi. nothing shows up for update
     
  4. Offline

    CreeperShift

    One sec, let me check what it was called exactly :p

    Wolf_Jacob

    There I found it, you don't use it from the Inventory, you use it from the player.
    player.updateInventory(); maybe it will fix your armor issue :)

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

    Wolf_Jacob

    Thanks it worked

    @ CreeperShift

    Do you by chance know anyways to fix the other stuff?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  6. Offline

    Tamewolf

    Maintaining the signs after reloading means that you will either need to log their locations and then save it (loading them back up on server start up) and then compare the location with a sign that has been clicked, or check the signs themselves for certain lines that execute the appropriate command when clicked. I'd opt for the second bit, lot less messy.

    Code:java
    1. event.setCancelled(true);

    Is why you can't break blocks.
     
  7. Offline

    CreeperShift

    Wolf_Jacob

    If I understand what you are trying to do right, you should also check in your onBlockBreak event if the block that is being broken is actually the block you are trying to protect, right now you just check for sign text, but you don't check if the block is actually a sign :S

    EDIT:
    Nevermind, didn't see the Hashmap,

    you should probably add a 2nd if statement checking if the player is OP and if he is, let him break it?
    Another EDIT:

    uh, the forums make code look so messy,

    right now you are saying:

    If the Hashmap doesn't contain the player in the event or IF the player is OP, then stop them from breaking blocks.

    I assume you want it the other way around?

    If the player is in the hashmap, don't allow them to break the sign? Or don't allow anyone but OP's to break stuff?

    You should look over that IF statement again, it doesn't do what you want it to do i assume :p
     
  8. Offline

    Wolf_Jacob

    @ Tamewolf

    Thanks it worked

    @ Tamewolf

    Do you know how to make the Teleport signs stay teleport signs even after the server is stopped

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  9. Offline

    CreeperShift

    Save the HashMap and load it again when the server starts.
     
  10. Offline

    Tamewolf

    [Redacted]

    Now, if that sign had some writing on it that was vital, or was marked as a sign shop, then it would probably be a good idea to protect it in such a manner, however you would want to first make sure the block was a sign, and after that, ensure that it was a shop sign.. THEN enable the proper protection.
     
  11. Offline

    Wolf_Jacob

    Sorry, Im new to this and havent quit learned all about HashMap how do i save them and reload it?
     
  12. Offline

    CreeperShift

    Look at his hashmap, he actually does check for the specific signs that he placed.

    Wolf_Jacob
    I'm not really sure, never needed it. Try to google it/ search on the forum, I'm sure there is a topic about it.

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

    Tamewolf

    CreeperShift

    Indeed, I misread the code. My apologies to Jacob.

    What is being said is "If the sign is in the hashmap AND the player is in the hashmap OR the player is op then don't break the block." And this applies to all blocks, so you actually want to just check to make sure the block is a sign first.

    Edit: Oh, and make sure that it is !player.isOp(), because otherwise if the player is OP, it won't break the sign.
     
    CreeperShift likes this.
  14. Offline

    CreeperShift

    Tamewolf
    Yup I pretty much already told him but for some reason he doesn't get it :p

    The IF statement is messed up big time.

    However he does store the location in the hashmap, so when he removes the OP check, it actually makes perfect sense.
     
  15. Offline

    Tamewolf

    CreeperShift

    The OP check makes it so that OPs can destroy it, regardless of who's portal it is, otherwise I could see where it would be an issue. I'd suggest using a permission node rather than OP check.
     
  16. Offline

    CreeperShift

    But isn't that what hes trying to do :confused:

    His current OP check makes it so he can't break anything haha, but even if it would do what hes trying, I think he probably wants the plugin for himself? If he plans to release it, then yes he needs to add permissions.
     
  17. Offline

    Tamewolf

    CreeperShift

    I believe that's what he's trying to do, yes. You said something about removing it, which I don't believe would be a good route. However it is vital to make sure that the block is a sign first.
     
  18. Offline

    CreeperShift

    Oh no no, I meant something like this instead:
    (removing it from it's current place and putting it here:)

    Code:
     
    if(signs.containsKey(event.getBlock()) && player.isOp()){
    signs.remove(event.getBlock().getLocation());
    }
    else if (signs.containsKey(event.getBlock()) && !signs.containsValue(event.getPlayer())) {
                event.setCancelled(true);
            } else if (signs.containsKey(event.getBlock()) && signs.containsValue(event.getPlayer())) {
                signs.remove(event.getBlock().getLocation());
            }
    }
    This looks horrible (I typed it on my iPhone xD) but I mean something like that
     
  19. Offline

    Wolf_Jacob

    @CreeperShift @ Tamewolf

    So do eaither of u know how to make it so i can keep them Teleport signs even after the server stops...CreeperShift said i could save the HashMap and then reload it but im new to HashMaps and im not sure how to do that
     
  20. Offline

    CreeperShift

    I'm sorry I've never needed to save a hashmap. Alternatively you could try SQL-Lite.
     
  21. Offline

    Wolf_Jacob

    Well do you know a way to make it stay a teleport sign? @ Tamewolf or @Creepershift
     
  22. Offline

    CreeperShift

    Yes lol, you need a way to reinitialize the signs when the server starts up, for that you need to save all the signs somewhere and put them back into the hashmap when the server starts up.

    You could simply store the signs in a file when they get created ADDITIONALLY to storing them in a hashmap, then simply add something in onEnable() that puts all the signs in the file into the hashmap.
     
  23. Offline

    Wolf_Jacob

    So how can i do that?
     
  24. Offline

    CreeperShift

    Take a look in the ressource section and try google. I'm not going to write up a tutorial on how to store stuff in a file, it's been done before :p
     
  25. Offline

    Tamewolf

  26. Offline

    Burnett1

  27. Offline

    Tamewolf

    It's what I suggested in the first place. Especially if the location that is being teleported to is set and stone.
     
Thread Status:
Not open for further replies.

Share This Page