Solved addParticle error

Discussion in 'Plugin Development' started by michiletsplay, Mar 22, 2014.

Thread Status:
Not open for further replies.
  1. Hi
    Im just wondering why this code doesn't work:
    Code:java
    1. World world = (World) loc.getWorld(); // error here
    2. world.addParticle("portal", loc.getX(), loc.getY(), loc.getZ(), 0.0D, 1.0D, 0.0D);

    Maybe fireblast709 can help here.
     
  2. Offline

    willeb96

    Location.getWorld() already returns a World, no need for typecasting.
    Make sure loc is a Location and not null.
     
  3. Offline

    Ivan

    You probably have the imported the wrong World object, hence you're casting it again. Check your imports.
     
  4. I imported net.minecraft.server.v1_7_R1.World
    The other import does not work
    loc is not null
     
  5. Offline

    DarkBladee12

    michiletsplay use "World world = ((CraftWorld) loc.getWorld()).getHandle();"
     
  6. Also not working
    Code:java
    1. if (cmd.getName().equalsIgnoreCase("test")) {
    2. if (sender.isOp()) {
    3. Player p = (Player) sender;
    4.  
    5. Location loc = p.getLocation();
    6. World world = ((CraftWorld) loc.getWorld()).getHandle();
    7. world.addParticle("portal", loc.getX(), loc.getY(), loc.getZ(), 1.0, 1.0, 1.0);
    8. } else {
    9. sender.sendMessage(CC.DRED + "No Premission");
    10. }
    11. }
    12.  
     
  7. Offline

    Konkz

    PHP:
    public void portalparticle(Location locationint offsetint idint amount) {
            
    PacketPlayOutWorldParticles portal= new PacketPlayOutWorldParticles(
                    
    "portal", (float) location.getX(), (float) location.getY(),
                    (float) 
    location.getZ(), offsetoffsetoffsetidamount);
            for (
    Player player Bukkit.getOnlinePlayers())
                ((
    CraftPlayerplayer).getHandle().playerConnection
                        
    .sendPacket(portal);
        }
    So when you want to make the particle do portalparticle(location, offset, id, amount);

    Eg:
    PHP:
    if (p.hasPermission("particles")) {
      
    portalparticle(p.getLocation(), 111);
    } else {
      
    p.sendMessage("You can't use this as you haven't got particles permission!");
    }
    michiletsplay
     
    michiletsplay likes this.
  8. Offline

    fireblast709

    If you want to use particles, I suggest ProtocolLib :p
     
Thread Status:
Not open for further replies.

Share This Page