[Help] Spawn player on dragon upon login.

Discussion in 'Plugin Development' started by MetamorphicPanda, May 3, 2014.

Thread Status:
Not open for further replies.
  1. Hello Bukkit community,

    I have an idea for a plugin where a player is spawned on a dragon when they login and flown to the spawnpoint then the dragon despawns. Does anyone know the event I should call upon
    Code:
    PlayerLoginEvent(Player player) 
    to get the player to spawn already on the dragon and fly on the defined path?

    Thanks!
     
  2. Offline

    tommycake50

    You need the first method in which the player is an actual entity. I would say PlayerJoinEvent possible but I'm not quite sure.
     
  3. You should use this im not sure if its working with the dragon:
    Code:java
    1.  
    2. @EventHandler
    3. Public void onJoin(PlayerJoinEvent e){
    4. Player p = e.getPlayer();
    5. LivingEntity dragon = (LivingEntity) p.getLocation().SpawnEntity(EntityType.ENDER_DRAGON);
    6. dragon.setPassenger(p);
    7. //now the player is riding the dragon
    8.  
    9. Location spawnLoc = new Location(p.getWorld, x, y, z);
    10. Entity target = loc.spawnEntity(EntityType.WOLF);
    11.  
    12. //now let the dragon fly to the wolf at its location (at spawn)
    13. dragon.setTarget(target);
    14.  
    15. //i think the dragon fly to the wolf but im not sure
    16.  
    17.  
    18. }
    19.  

    You should too give the wolf a slowness and vanish effect. Then check if the enderdragon is near the wolf and remove booth entities
     
  4. Ok, I've gotten to this point:
    Code:java
    1. package com.minecloud.dragonjoin;
    2.  
    3. import org.bukkit.Location;
    4. import org.bukkit.entity.Entity;
    5. import org.bukkit.entity.EntityType;
    6. import org.bukkit.entity.LivingEntity;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.player.PlayerJoinEvent;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11. // FisheyLP helped with this code
    12. public class Main extends JavaPlugin {
    13. @EventHandler
    14. public void onJoin(PlayerJoinEvent e){
    15. Player p = e.getPlayer();
    16. LivingEntity dragon = (LivingEntity) p.getWorld().spawnEntity(p.getLocation(), EntityType.ENDER_DRAGON);
    17. dragon.setPassenger(p);
    18. //now the player is riding tha dragon
    19. Location spawnLoc = new Location(p.getWorld(), 16, 28, 40);
    20. Entity target = spawnLoc.spawnEntity(EntityType.WOLF);
    21.  
    22. //now the plugin lets the dragon fly to the wolf at its location (at spawn)
    23. dragon.setTarget(EntityType.WOLF);
    24.  
    25. //it shuld work now idk
    26. }
    27. }
    28.  

    Eclipse is having trouble processing the
    Code:java
    1. Entity target = spawnLoc.spawnEntity(EntityType.WOLF);
    and
    Code:java
    1. dragon.setTarget(EntityType.WOLF);
    lines of code, as dragon.setTarget is not even a real Bukkit event.

    Please help with these errors.

    bump

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

    TGRHavoc

    MetamorphicPanda
    Did you try dragon.setTarget(target) and not dragon.setTarget(EntityType.WOLF) ?
     
    tommycake50 likes this.
  6. Offline

    akabarblake

    TGRHavoc Yeah, I mean (I think) that could go anywhere, because I bet theres more than 1 wolf.
     
  7. You need to register the events, make a new method like this:
    Code:java
    1.  
    2. public void onEnable(){
    3. Bukkit.getPluginManager().registerEvents(this, this);
    4. }
    5.  

    And let your class implement Listener:
    Code:java
    1.  
    2. public class Main extends JavaPlugin implements Listener {
    3.  

    The thing with the wolf:
    Code:java
    1.  
    2. Entity target = (Entity) loc.spawnEntity(EntityType.WOLF);
    3.  

    try it out ;)
     
  8. Offline

    tommycake50

    Do what TGRHavoc said.
    setTarget expects an Entity not an EntityType.
     
  9. Still getting errors with setTarget.
    [​IMG]
     
  10. Offline

    tommycake50

    it's spawnEntity() I think not SpawnEntity.
     
  11. Offline

    Onlineids

    Pictures broke for me
     
  12. Still bugged.
    [​IMG]
     
  13. oh setTarget is broken i think :( but to get rid of the other errors make it like this:
    Code:Java
    1.  
    2. @EventHandler
    3. public void onJoin(PlayerJoinEvent e){
    4. Player p = e.getPlayer();
    5. LivingEntity dragon = (LivingEntity) p.getLocation().getWorld().spawnEntity(p.getLocation(), EntityType.ENDER_DRAGON);
    6. dragon.setPassenger(p);
    7.  
    8. //Put here your location in (x, y and z) ------->
    9. Location loc = new Location(p.getWorld, 0, 0, 0);
    10. Entity target = (Entity) loc.getWorld().spawnEntity(loc, EntityType.Wolf);
    11.  
    12. //This should work but it doesnt you must wait for a new craftbukkit:
    13. //dragon.setTarget(target);
    14. }
     
  14. Offline

    tommycake50

    Do this p.getLocation().getWorld().spawnEntity(p.getLocation(), EntityType.ENDER_DRAGON);
     
  15. New code:
    [​IMG]
    dragon.setTarget is still broken, is there a replacement event for this?
     
  16. Offline

    tommycake50

    Do the same thing to spawn the target as you did with the dragon.
     
  17. I spawned the dragon and wolf, except now I need the dragon to lock onto the wolf and fly to its location.
     
  18. Offline

    tommycake50

    Yeah but you are spawning the wolf wrong.
     
  19. I can't spawn the wolf in the same location as the player, as I want the dragon to travel to the wolf's location (at spawn).
     
  20. Offline

    AoH_Ruthless

    MetamorphicPanda
    Don't spawn a wolf. Whoever told you that is not being very efficient.

    Instead, when you spawn the dragon, add metadata to it.

    (If the variable is dragon):

    Code:java
    1. dragon.setMetadata(p.getName(), new FixedMetadataValue(plugin, "DRAGON")); // p is your passenger, plugin is an instance of your main class, and dragon is the ender dragon.
    2.  
    3.  


    First, to remove it, you have to loop through all the dragons in the world, and check if the dragon has a right metadata.
    Code:java
    1. // using same variables in above code
    2. for (Dragon d : p.getWorld().getEntitiesByClass(EnderDragon.class)) {
    3. if (!d.hasMetadata(p.getName())
    4. continue;
    5.  
    6. d.remove();
    7. break;
    8. }
     
Thread Status:
Not open for further replies.

Share This Page