Пример #1
0
 public static ParticleType getTypeFromName(String name) {
   for (ParticleType type : ParticleType.values()) {
     if (type.name != null && type.name.equals(name)) {
       return type;
     }
   }
   return UNKNOWN;
 }
Пример #2
0
 /**
  * Constructs a new particle packet.
  *
  * @param location the location to spawn the particle effect at
  * @return the constructed packet
  */
 private Object createPacket(Location location) {
   try {
     if (this.count <= 0) {
       this.count = 1;
     }
     Object packet;
     if (netty) {
       if (newParticlePacketConstructor) {
         Object particleType = enumParticle.getEnumConstants()[type.getId()];
         if (useOffset) {
           packet =
               packetConstructor.newInstance(
                   particleType,
                   true,
                   (float) location.getX(),
                   (float) location.getY(),
                   (float) location.getZ(),
                   (float) this.offX,
                   (float) this.offY,
                   (float) this.offZ,
                   (float) this.speed,
                   this.count,
                   new int[0]);
         } else {
           packet =
               packetConstructor.newInstance(
                   particleType,
                   true,
                   (float) location.getX(),
                   (float) location.getY(),
                   (float) location.getZ(),
                   (float) this.radius,
                   (float) this.radius,
                   (float) this.radius,
                   (float) this.speed,
                   this.count,
                   new int[0]);
         }
       } else {
         packet =
             packetConstructor.newInstance(
                 type.getName(),
                 (float) location.getX(),
                 (float) location.getY(),
                 (float) location.getZ(),
                 (float) this.radius,
                 (float) this.radius,
                 (float) this.radius,
                 (float) this.speed,
                 this.count);
       }
     } else {
       packet = packetConstructor.newInstance();
       for (Field f : fields) {
         f.setAccessible(true);
         if (f.getName().equals("a")) f.set(packet, type.getName());
         else if (f.getName().equals("b")) f.set(packet, (float) location.getX());
         else if (f.getName().equals("c")) f.set(packet, (float) location.getY());
         else if (f.getName().equals("d")) f.set(packet, (float) location.getZ());
         else if (f.getName().equals("e") || f.getName().equals("f") || f.getName().equals("g"))
           f.set(packet, this.radius);
         else if (f.getName().equals("h")) f.set(packet, this.speed);
         else if (f.getName().equals("i")) f.set(packet, this.count);
       }
     }
     return packet;
   } catch (IllegalAccessException ex) {
     ex.printStackTrace();
     Bukkit.getLogger().severe("{ParticleLib] Failed to construct particle effect packet!");
   } catch (InstantiationException ex) {
     ex.printStackTrace();
     Bukkit.getLogger().severe("{ParticleLib] Failed to construct particle effect packet!");
   } catch (InvocationTargetException ex) {
     ex.printStackTrace();
     Bukkit.getLogger().severe("{ParticleLib] Failed to construct particle effect packet!");
   }
   return null;
 }