[NEED YOUR HELP]God`s Stick!

Discussion in 'Plugin Development' started by Growl, Mar 12, 2014.

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

    Growl

    Hi guys! I want Plugin to make a light from a player, who holds the special Item - stick with name "Needed Stick". But I really don`t know how to do it. Is it possible at all?? Maybe it is something with creating a torch that would be on the same location with a player(bad variant), maybe something else.... Can you help me?My code:
    Code:java
    1. package mainTest;
    2.  
    3. import org.bukkit.Location;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.player.PlayerMoveEvent;
    7. import org.bukkit.inventory.meta.ItemMeta;
    8.  
    9. public class Spells extends mainClass implements Listener{
    10. public void lumos(PlayerMoveEvent move){
    11. Player player = move.getPlayer();
    12. Location loc = player.getLocation();
    13. ItemMeta stickMeta = player.getItemInHand().getItemMeta();
    14. if (stickMeta.hasDisplayName()) {
    15. String spellName = stickMeta.getDisplayName();
    16. if (spellName.equalsIgnoreCase("Needed Stick")){
    17. //And here must be something..Maybe..Maybe, it is a drivel...
    18. }
    19. }
    20. }
    21. }
     
    Wizehh and L33m4n123 like this.
  2. Offline

    Amgis

    Growl

    It is not possible to simply create a light source at a given location. You must resort to placing a light-producing block (torch, glowstone) near the player to produce light.

    Many light-source plugins achieve this by having a single block of glowstone under your feet at all times.

    This can be achieved by listening to PlayerMoveEvent, deleting the previous glowstone block and then creating a new one directly under the player. Of course, you will have to store the block that you are replacing with glowstone, such if that the player moves off the block, the block can be restored to its original state.

    Take a look at my rudimentary Carpet class-- it might give you some insight on how to achieve this.
    Code:java
    1. package smugglin.smugglin;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Location;
    5. import org.bukkit.Material;
    6. import org.bukkit.World;
    7. import org.bukkit.block.Block;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.player.PlayerMoveEvent;
    12.  
    13. public class Carpet implements Listener{
    14.  
    15. private final static int carpetLength = 5; // adjust accordingly
    16. private final static Material carpetMaterial = Material.GLASS; // the material that the carpet will be composed of
    17. private final static World world = Bukkit.getWorld("world"); // or whatever the name of your world is
    18.  
    19. private final Player player;
    20.  
    21. public Carpet(Player player) {
    22.  
    23. this.player = player;
    24. }
    25.  
    26. private void fill(Location location) {
    27.  
    28. Block block;
    29.  
    30. for(int x = -(carpetLength/2); x<carpetLength/2 + 1;x++) {
    31.  
    32. for(int z = -(carpetLength/2); z<carpetLength/2 + 1;z++) {
    33.  
    34. block = world.getBlockAt((int) (location.getX() + x),
    35. (int) location.getY() - 1,
    36. (int) (location.getZ() + z));
    37.  
    38. if(block.getType().equals(Material.AIR)) {
    39.  
    40. block.setType(carpetMaterial);
    41. }
    42. }
    43. }
    44. }
    45.  
    46. private void delete(Location location) {
    47.  
    48. Block block;
    49.  
    50. for(int x = -(carpetLength/2); x<carpetLength/2 + 1;x++) {
    51.  
    52. for(int z = -(carpetLength/2); z<carpetLength/2 + 1;z++) {
    53.  
    54. block = world.getBlockAt((int) (location.getX() + x),
    55. (int) location.getY() - 1,
    56. (int) (location.getZ() + z));
    57.  
    58. if(block.getType() == Material.GLASS) {
    59.  
    60. block.setType(Material.AIR);
    61. }
    62. }
    63. }
    64. }
    65.  
    66. public Player getPlayer() {
    67.  
    68. return this.player;
    69. }
    70.  
    71. @EventHandler
    72. public void onPlayerMove(PlayerMoveEvent event) {
    73.  
    74. if(event.getPlayer().equals(this.getPlayer())) {
    75.  
    76. this.delete(event.getFrom());
    77.  
    78. this.fill(event.getTo());
    79. }
    80. }
    81. }
    82.  
     
  3. Offline

    GameplayJDK

    Growl
    It's nearly impossible. Because a light source can only be a block. (Like glowstone, etc.)
    I don't know if it's possible to place a light source at a certain location..
     
Thread Status:
Not open for further replies.

Share This Page