[Unsolved]Spawning a Boss-Zombie in another world?

Discussion in 'Plugin Development' started by Gabum, Jul 8, 2013.

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

    Gabum

    Hey guys,
    I'm gonna build up a server using self-made-plug-ins, and i need help!
    The Server will have several dungeons which are in other worlds than the main world (to make it more modular).
    But now I have a problem:
    I want to spawn a zombie as a boss in a several room in a world called "Sewers" when a Command Block is activated. As far as good, but my Problem is now: How do I do that? I'm using Multiverse to create additional worlds, and i'm a newbie at programming :/ Please help!
     
  2. Offline

    LinearLogic

    If your "Sewers" world is a:
    • Regular CB world (World object): retrieve it by calling plugin.getServer().getWorld("Sewers);
    • Multiverse world (MVWorld object): use wm.getMVWorld("Sewers").getCBWorld(); (wm is a WorldManager object)
    Now that you have a World object (let's call it world), simply call world.spawnEntity(new Location(world, x, y, z), EntityType.ZOMBIE);
     
  3. Offline

    Gabum

    Thanks for the fast answer, but if i use wm.getMVWorld("Sewers").getCBWorld();
    it doesn't find wm! Is it an external Plugin i have to install/import?

    Oh, i found it in the MV api, but how do i initialise the WorldManager?

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

    LinearLogic

    It's automatically initialized. Get the MultiverseCore plugin instance and call getMVWorldManager()
     
  5. Offline

    Intangir

    im pretty sure you can use getWorld on the normal server object for any type of world regardless of how its loaded

    as long as its already loaded
     
  6. Needs to be loaded. get world and check if chunks are loaded.
     
  7. Offline

    LinearLogic

    Within the MV plugin context, retrieving the CB world from the MV seems safer, but yes, with a simple check both will work.
     
  8. Offline

    Gabum

    Thank you very much! I solved it using Sewers1.getWorld() (Sewers1 is a player who was in the queue) Now i have this code:

    Code:
    package main;
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Zombie;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
     
     
    public class SewersQueue extends JavaPlugin implements Listener{   
        static Player Sewers1;
        static Player Sewers2;
       
        @Override
        public void onEnable() {
            System.out.println("Sewers loaded");
     
        }
     
        public void onDisable() {
            System.out.println("Sewers disabled");
        }
     
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("sewers")) {                                                                                                                                              //QUEUE UP
                if ((Sewers1 == null) && (sender != Sewers2)) {
                    Sewers1 = (Player) sender;
                    Sewers1.sendMessage(ChatColor.AQUA + "Successfully queued up for Sewers.");
                }
                if ((Sewers2 == null)/* && (sender != Sewers1)*/) {
                    Sewers2 = (Player) sender;
                    Sewers2.sendMessage(ChatColor.AQUA + "Successfully queued up for Sewers.");
                }
                if ((Sewers1 != null) && (Sewers2 != null))
                sender.sendMessage(ChatColor.AQUA + "This dungeon is full at the moment.");
            return true;
            }
           
            if(cmd.getName().equalsIgnoreCase("l")) {                                                                                                                                                //LEAVE QUEUE
                if ((Player) sender == Sewers1) {
                    Sewers1.sendMessage(ChatColor.AQUA + "Successfully left the queue.");
                    Sewers1 = null;
                   
                }
                if ((Player) sender == Sewers2) {
                    Sewers2.sendMessage(ChatColor.AQUA + "Successfully left the queue.");
                    Sewers2 = null;
                }
                return true;
            }
           
            if((Sewers1 != null) && (Sewers2 != null)) {                                                                                                                              //Dungeon Start => Queue full
               
                Sewers1.sendMessage(ChatColor.BLUE + "Dungeon entered.");
                Sewers2.sendMessage(ChatColor.BLUE + "Dungeon entered.");
               
                Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv tp " + Sewers1.getName() + " Sewers");
                Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv tp " + Sewers2.getName() + " Sewers");
                return true;
     
            }
               
            if(cmd.getName().equalsIgnoreCase("GreaterZombie")) {
                    Sewers1.getWorld().spawnEntity(new Location(Sewers1.getWorld(), -692.5, 5, 596.5), EntityType.ZOMBIE);                                        //Boss GreaterZombie
                    return true;
            }
               
        return false;
        }
    }
    But now there's another problem: if i use "greaterzombie" with a command block, it just teleports all Players in the world to its spawn, and no zombie is spawned at the defined location! Any ideas how to fix that?
     
  9. Offline

    LinearLogic

    Strange. Is there any other handling of the "greaterzombie" command than below?
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("GreaterZombie")) {
    2. Sewers1.getWorld().spawnEntity(new Location(Sewers1.getWorld(), -692.5, 5, 596.5), EntityType.ZOMBIE);
    3. return true;
    4. }
     
  10. Offline

    xTrollxDudex

    Gabum
    Code:java
    1. Sewers1.getWorld().spawn(<location>, Zombie.class);

    Try that line to spawn zombies
     
  11. Offline

    LinearLogic

    Why use spawn(...) and satisfy generics when zombies are natively supported, enabling spawnEntity(<location>, EntityType.ZOMBIE)?

    And I have no idea what's causing the teleportation unless you've bound another command to the block, although your use of a static global Player object makes me nervous...
     
  12. Offline

    Gabum

    Well, if i try to "out-comment" the line with mv tp, it still teleports the players. So it's not a bug of wrong if-commands, but probably something with initialising the Player's Variable... Any ideas?
     
  13. Offline

    LinearLogic

    If you haven't written any code to teleport the players, I can't fathom why they're still teleporting...
    And try retrieving the player via plugin.getServer().getPlayer(<name>) rather than maintaining a global variable.
     
  14. Offline

    Gabum

    Well, i think i can fix the problem now. i found out that my changes only work if i stop the server completely, then export the .jar, and the starting the server again, a reload doesn't work! :D

    But it' around 11 pm, and i have to go to bed now. I will post it if i fixed the problem!
     
  15. Offline

    LinearLogic

    Best of luck, I'm interested to hear what ends up resolving this rather enigmatic issue.
     
  16. Offline

    Gabum

    YEEEEEEEEEEEAAAAAAAAAAAAAAAAH! I finally fixed the problem! It wasn't anything with commands etc, but something with wrong if-commands. As i said, nothing of my changes worked, because I just always reloaded the server. So the teleport bug was caused by a wrong if command, which was activated everytime the programm was running and the queue was filled (it was the if((Sewers1 != null) && (Sewers2 != null)) command). I fixed it by adding another if-command:
    Code:
            if((Sewers1 != null) && (Sewers2 != null)) {                                                                                                                              //Dungeon Start => Queue full
                if (!running) {
                    Sewers1.sendMessage(ChatColor.BLUE + "Dungeon entered.");
                    Sewers2.sendMessage(ChatColor.BLUE + "Dungeon entered.");
             
                    Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv tp " + Sewers1.getName() + " Sewers");
                    Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv tp " + Sewers2.getName() + " Sewers");
                    Sewers = Sewers1.getWorld();
                    running = true;
                }
                if (running) {
                    if (cmd.getName().equals("GreaterZombie")) {
                        Sewers.spawnEntity(new Location(Sewers, -692.5, 5, 596.5), EntityType.ZOMBIE);
                    }
                }
    Guys, i'm so happy :D
    And, now a final question: How do i add a Nametag to the zombie, and how do i set the Maximum health?
     
  17. Offline

    Alxlre

    This should add a name tag.
    Code:java
    1. livingentity.setCustomName("Name");
    2. livingentity.setCustomNameVisible(true);


    For the health, you may want to go poking around with this to add to the "bossyness". Not sure how to increase the max health.
     
  18. Offline

    Gabum

    well, the name tag works, and i tried to work with livingentity.setHealth(), but it did not work, due it seems to be deprecated. Do you guys know how i can set a Mob's maximum health? Or maybe code?
     
  19. Offline

    LinearLogic

    AFAIK, you can't modify a mob's max health without spawning a fake mob via packet manipulation, and even then it's tricky business. I'd stay away from it and instead implement a system whereby mobs with increased "max health" occasionally take no damage when attacked.
     
  20. Offline

    Gabum

    yeah, i already thought of something like a loop, and this is the result, but it doesn't work, i hit the zombie 100 times with diamond sword, but it wont't be removed:
    Code:
                    if (cmd.getName().equals("GreaterZombie")) {
                        LivingEntity greaterzombie = (LivingEntity) Sewers.spawnEntity(new Location(Sewers, -692.5, 5, 596.5), EntityType.ZOMBIE);
                        greaterzombierunning = true;
                        Sewers1.teleport(new Location(Sewers, -688.5, 5, 588.5));
                        Sewers2.teleport(new Location(Sewers, -688.5, 5, 588.5));
                        greaterzombie.setCustomName("Stinky Big Fat Zombie");
                        greaterzombie.setCustomNameVisible(true);
                        greaterzombie.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 1000000, 4));
                        for (double health = 100; health <= 0;){
                            health = greaterzombie.getLastDamage();
                            if (health <= 0) {
                                greaterzombie.remove();
                            }
                        }           
                    }
     
  21. Offline

    LinearLogic

    A diamond sword won't take any health off a zombie with a damage resistance potion effect of amplitude 4. With amplitude 3 it will take around 15 hits.
     
  22. Offline

    Gabum

    Well, i'm experimenting around with REGENERATION, but if a Player hits the zombie with more than 20 damage, which will be the case for higher dungeons, it kills it instantly...
     
  23. Offline

    LinearLogic

    Just double checked - using an amplifier of 4 makes the zombie invincible, regardless of the damage dealt. Another method would be to use EntityDamageByEntity events - you can manually alter the damage dealt.
     
  24. Offline

    Gabum

    Sorry, that i did not answer for a long time, i was in holidays with no internet, so I also couldn't work on the Problem. I will now try more, though i have much much time now :)
     
  25. Offline

    Gabum

    Ok guys, i just tried something: I used a "for-loop", which should send a message 10 times to a Sewers1, but it doesn't seem to do the loop! Someone help?:
    Code:java
    1. if ((running) && !(greaterzombierunning)) {
    2. if (cmd.getName().equals("GreaterZombie")) {
    3. greaterzombie = (LivingEntity) Sewers.spawnEntity(new Location(Sewers, -692.5, 5, 596.5), EntityType.ZOMBIE);
    4. greaterzombierunning = true;
    5. Sewers1.teleport(new Location(Sewers, -688.5, 5, 588.5));
    6. Sewers2.teleport(new Location(Sewers, -688.5, 5, 588.5));
    7. greaterzombie.setCustomName("Greater Sewers Zombie");
    8. greaterzombie.setCustomNameVisible(true);
    9. Sewers1.sendMessage(ChatColor.RED + "Encounter Started.");
    10. Sewers2.sendMessage(ChatColor.RED + "Encounter Started.");
    11.  
    12. for (greaterzombiehealth = 100; greaterzombiehealth <= 0;){
    13. Sewers1.sendMessage("test");
    14. greaterzombiehealth = greaterzombiehealth - 10;
    15. }
    16.  
    17. greaterzombie.remove();


    EDIT: Found the mistake. I used the wrong </> (in don't know how it's called in ENG :D) in the for-loop! xD
     
Thread Status:
Not open for further replies.

Share This Page