Trapping player in ice

Discussion in 'Plugin Development' started by damo1995, Mar 9, 2014.

Thread Status:
Not open for further replies.
  1. Hi there,

    I was earlier speaking with people on the BukkitDev IRC in regards to trapping players inside an icebox when i found this:
    https://forums.bukkit.org/threads/encasing-a-player-in-glass.161632/#post-1764600

    I've followed this but it is a little outdated and some of its methods now depreciated, also it dosen't quite do what I want it too.

    this allows me to put them in a fully square icebox, but im wanting something along the lines of this below:
    [​IMG]

    but i also need to be able to set this back to air on the player disconnect so it needs to be a two way process.

    Would anybody be willing to help me in regards to figuring how I could do this exactly?
     
  2. Offline

    creepers84

    damo1995
    This is relatively simple. The easiest and most effective way, would be to suddenly freeze the player, either with a high potency potion, or with cancelling movement. Once frozen you would detect the blocks around the player and set them to the ice blocks.
    Example:
    Code:java
    1. Block block = player.getLocation().getBlock().getRelative(BlockFace.EAST));
    2. block.setType(Material.ICE);

    Then, because you can then specify that block, you would do something like:
    Code:java
    1. block.setType(Material.AIR);
    2. //or
    3. block.remove();
    for when the player leaves the game, or at a specific time. Perhaps, save that block as a hashmap, and then remove it, in a seperate onQuit event. :) Hope this Helped!
    Quick Tip:
    This would allow you to make a 2 block high wall around the player on the east side. Hope you can see the simple pattern:
    Code:java
    1. Block block = player.getLocation().getBlock().getRelative(BlockFace.EAST));
    2. block.setType(Material.ICE);
    3. Block block2 = block.getLocation().getBlock().getRelative(BlockFace.UP));
    4. block2.setType(Material.ICE);
     
  3. Thanks for the responce, My problem im facing is how exactly would I link the actual blocks to the player inside the hash map though? also save their previous types?

    Regards.
     
  4. Offline

    creepers84

    Alright.
    You need to create the Hashmap and add the block to it, making sure you place something like this at the beginning of your code:
    Code:java
    1. public static HashMap<Location, Integer> block = new HashMap<Location, Integer>();

    To store the location! Do this for all of your blocks created. Meaning, that when the player quits, you can set the blocks to AIR. Once done, you might want to consider adding the player (once frozen) into an arraylist to stop them from breaking/placing blocks. Then once they have quit, you can remove them from the list.
    Hope this Helped :)
     
  5. Offline

    Garris0n

    A quick thing, if you "froze" them by just teleporting them back to the same spot on a timer and used sendBlockChange on them to add the "ice" blocks, you could avoid having to worry about setting it back because the blocks wouldn't actually be there. It would start to get complicated if you had to deal with other people seeing it, but probably still far better than trying to save and rollback the blocks.
     
  6. Offline

    creepers84

    Garris0n
    Great idea! Didn't think of that. ;)
     
Thread Status:
Not open for further replies.

Share This Page