Solved Minecraft plugin problem

Discussion in 'Plugin Development' started by YTLexan, Jun 29, 2020.

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

    YTLexan

    Hello,
    I'm experimenting a bit with my plugin:
    [​IMG]
    The plugin is relatively simple: it places a pumpkin in front of a player. The problem, however, is that the pumpkin is always placed on the x-axis by the player, regardless of where the player is looking.

    My question would be, how can I do it or with what command that the position of the player is included? So if I look in the Y direction, the pumpkin should also be placed in the Y direction, etc.
     
  2. Offline

    Legendary_zotar

    Get the direction the player is looking at, Get the location he is at, get the block that's towards that location and set it.
    There are a few posts out there of how to get the direction, Heres one:
    https://bukkit.org/threads/direction-the-playser-faces-north-south.20773/

    Getting the block at the direction the player is looking at
    #Location.getBlock().getRelative(BlockFace.#Direction)
    then set it
     
  3. Offline

    YTLexan

    Code:
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class KuerbisPlugin extends JavaPlugin {
      public void onEnable() {
      }
    
      public void onDisable() {
      }
    
      public boolean onCommand(CommandSender sender, Command befehl, String befehlsname, String[] args){
      Player spieler = (Player) sender;
    
      Location position = spieler.getLocation();
      World welt = spieler.getWorld();
      
      
      
      
      float yawX = spieler.getLocation().getYaw();
      float yawX1 = spieler.getLocation().getYaw();
      float yawZ = spieler.getLocation().getYaw();
      float yawZ1 = spieler.getLocation().getYaw();
      
      if((yawZ >= 90 && yawZ <= -90) ){
        
         position.setX(position.getX()-2);
         Block block = welt.getBlockAt(position);
      block.setType(Material.PUMPKIN);
      
      }
        
      if(yawX >= -45.1 && yawX <= 134.9) {
        
         position.setZ(position.getZ()+2);
         Block block = welt.getBlockAt(position);
      block.setType(Material.PUMPKIN);
      
      }
        
      if(yawZ1 >= -44.9 && yawZ <= 44.9){
        
         position.setX(position.getX()-2);
         Block block = welt.getBlockAt(position);
      block.setType(Material.PUMPKIN);
      
      }
        
      if(yawX1 >= 45.1 && yawX <= 134.9){
        
         position.setZ(position.getZ()+2);
         Block block = welt.getBlockAt(position);
      block.setType(Material.PUMPKIN);
        
      }
      
      
      
      return true;
      }
    }
    Unfortunately its not working fine. I want that if I write the command there will spawn a pumkpkin but how i can make this?

    Solved it!!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2020
  4. Offline

    caderapee

    @YTLexan
    float yawX = spieler.getLocation().getYaw();
    float yawX1 = spieler.getLocation().getYaw();
    float yawZ = spieler.getLocation().getYaw();
    float yawZ1 = spieler.getLocation().getYaw();


    this will be always the same since u call the same method 4x
     
Thread Status:
Not open for further replies.

Share This Page