Advertisement
xmorose

Untitled

Jun 8th, 2023
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.24 KB | None | 0 0
  1. // Decompiled with: CFR 0.152
  2. // Class Version: 16
  3. package io.lumine.mythic.core.skills.projectiles.bullet;
  4.  
  5. import io.lumine.mythic.api.adapters.AbstractEntity;
  6. import io.lumine.mythic.api.adapters.AbstractLocation;
  7. import io.lumine.mythic.api.adapters.AbstractVector;
  8. import io.lumine.mythic.api.config.MythicLineConfig;
  9. import io.lumine.mythic.api.skills.placeholders.PlaceholderString;
  10. import io.lumine.mythic.api.volatilecode.virtual.PacketTextDisplayEntity;
  11. import io.lumine.mythic.bukkit.BukkitAdapter;
  12. import io.lumine.mythic.core.logging.MythicLogger;
  13. import io.lumine.mythic.core.skills.SkillAudience;
  14. import io.lumine.mythic.core.skills.projectiles.Projectile;
  15. import io.lumine.mythic.core.skills.projectiles.ProjectileBullet;
  16. import io.lumine.mythic.core.skills.projectiles.ProjectileBulletType;
  17. import io.lumine.mythic.core.utils.annotations.MythicField;
  18. import org.bukkit.Color;
  19. import org.bukkit.Location;
  20. import org.bukkit.entity.Display;
  21. import org.bukkit.util.Vector;
  22.  
  23. public class TextDisplayPacketBullet
  24. extends ProjectileBullet {
  25.     @MythicField(name="audience", description="The audience of the message")
  26.     protected SkillAudience audience;
  27.     @MythicField(name="bulletText", aliases={"text"}, description="The text of the bullet", defValue="*")
  28.     protected PlaceholderString bulletText = null;
  29.     @MythicField(name="bulletBillboard", aliases={"billboard"}, description="The billboard mode of the bullet", defValue="CENTER")
  30.     protected Display.Billboard bulletBillboard = Display.Billboard.CENTER;
  31.     @MythicField(name="bulletScale", description="The bullet's size scale")
  32.     protected AbstractVector bulletScale;
  33.     @MythicField(name="backgroundColor", aliases={"color"}, description="The background color to use", defValue="1073741824")
  34.     private Color backgroundColor;
  35.     private PacketTextDisplayEntity.PacketTextDisplayEntityOptions options;
  36.  
  37.     public TextDisplayPacketBullet(ProjectileBulletType type, Projectile projectile, MythicLineConfig config) {
  38.         super(type, projectile, config);
  39.         this.audience = config.getAudience("audience", "world");
  40.         this.bulletText = config.getPlaceholderString(new String[]{"bulletText", "text"}, "*", new String[0]);
  41.         String strBulletScale = config.getString(new String[]{"bulletscale", "scale"}, "0.5,0.5,0.5", new String[0]);
  42.         try {
  43.             String[] splitStr = strBulletScale.split(",");
  44.             double x = Double.parseDouble(splitStr[0]);
  45.             double y = Double.parseDouble(splitStr[1]);
  46.             double z = Double.parseDouble(splitStr[2]);
  47.             this.bulletScale = new AbstractVector(x, y, z);
  48.         }
  49.         catch (Throwable ex) {
  50.             this.bulletScale = new AbstractVector(0.5, 0.5, 0.5);
  51.             MythicLogger.errorMechanic(projectile, "Invalid bullet scale set: " + strBulletScale);
  52.         }
  53.         String strBulletBillboard = config.getString(new String[]{"bulletbillboard", "billboard"}, "CENTER", new String[0]);
  54.         try {
  55.             this.bulletBillboard = Display.Billboard.valueOf((String)strBulletBillboard.toUpperCase());
  56.         }
  57.         catch (Throwable ex) {
  58.             this.bulletBillboard = Display.Billboard.CENTER;
  59.             MythicLogger.errorMechanic(projectile, "Invalid bullet billboard mode: " + strBulletBillboard);
  60.         }
  61.         String colorStr = config.getString(new String[]{"backgroundcolor", "color"}, "64,0,0,0", new String[0]);
  62.         try {
  63.             String[] splitStr = colorStr.split(",");
  64.             int a = Integer.parseInt(splitStr[0]);
  65.             int r = Integer.parseInt(splitStr[1]);
  66.             int g = Integer.parseInt(splitStr[2]);
  67.             int b = Integer.parseInt(splitStr[3]);
  68.             this.backgroundColor = Color.fromARGB((int)a, (int)r, (int)g, (int)b);
  69.         }
  70.         catch (Throwable e) {
  71.             this.backgroundColor = Color.fromARGB((int)64, (int)0, (int)0, (int)0);
  72.             MythicLogger.errorMechanic(projectile, "Invalid bullet background color set: " + colorStr);
  73.         }
  74.         this.options = PacketTextDisplayEntity.PacketTextDisplayEntityOptions.builder().text(this.bulletText.get()).billboard(this.bulletBillboard).scale(this.bulletScale).backgroundColor(this.backgroundColor).build();
  75.     }
  76.  
  77.     @Override
  78.     public ProjectileBullet.BulletTracker create(Projectile.ProjectileTracker projectile, AbstractEntity target) {
  79.         return new ArmorStandBulletTracker(projectile, target);
  80.     }
  81.  
  82.     @Override
  83.     public boolean isVirtual() {
  84.         return true;
  85.     }
  86.  
  87.     public class ArmorStandBulletTracker
  88.     extends ProjectileBullet.BulletTracker {
  89.         protected PacketTextDisplayEntity bullet;
  90.  
  91.         public ArmorStandBulletTracker(Projectile.ProjectileTracker projectile, AbstractEntity target) {
  92.             super(TextDisplayPacketBullet.this, projectile, target);
  93.         }
  94.  
  95.         @Override
  96.         public void spawn(AbstractLocation start) {
  97.             AbstractLocation l = start.clone();
  98.             this.bullet = TextDisplayPacketBullet.this.getPlugin().getVolatileCodeHandler().getWorldHandler().createVirtualTextDisplayEntity(l, TextDisplayPacketBullet.this.options);
  99.             AbstractLocation currentLocation = this.getProjectile().getPreviousLocation();
  100.             AbstractVector currentVelocity = this.getProjectile().getCurrentVelocity();
  101.             Location to = BukkitAdapter.adapt(currentLocation).clone();
  102.             Vector delta = BukkitAdapter.adapt(currentVelocity).normalize().multiply(this.getProjectile().getVelocityMagnitude() / 7.6);
  103.             double yaw = Math.atan2(delta.getX(), delta.getZ());
  104.             double len = delta.getZ() / Math.cos(yaw);
  105.             float pitch = (float)Math.atan2(delta.getY(), len);
  106.             Location loc = to.clone().add(delta);
  107.             float newYaw = (float)Math.toDegrees(-yaw) + 180.0f;
  108.             float newPitch = (float)Math.toDegrees(-pitch);
  109.             loc.setYaw(newYaw);
  110.             loc.setPitch(newPitch);
  111.             this.bullet.spawn(TextDisplayPacketBullet.this.audience.get(this.getProjectile().getData(), this.getTarget()));
  112.         }
  113.  
  114.         @Override
  115.         public void tick(AbstractLocation origin) {
  116.             if (this.getProjectile().getTimesRan() % 5 == 0) {
  117.                 this.bullet.updateRenderedPlayers();
  118.             }
  119.             AbstractLocation currentLocation = this.getProjectile().getPreviousLocation();
  120.             AbstractVector currentVelocity = this.getProjectile().getCurrentVelocity();
  121.             Location to = BukkitAdapter.adapt(currentLocation).clone();
  122.             Vector delta = BukkitAdapter.adapt(currentVelocity).normalize().multiply(this.getProjectile().getVelocityMagnitude() / 7.6);
  123.             double yaw = Math.atan2(delta.getX(), delta.getZ());
  124.             double len = delta.getZ() / Math.cos(yaw);
  125.             float pitch = (float)Math.atan2(delta.getY(), len);
  126.             Location loc = to.clone().add(delta);
  127.             float newYaw = (float)Math.toDegrees(-yaw) + 180.0f;
  128.             float newPitch = (float)Math.toDegrees(-pitch);
  129.             loc.setYaw(newYaw);
  130.             loc.setPitch(newPitch);
  131.             this.bullet.update(BukkitAdapter.adapt(loc));
  132.         }
  133.  
  134.         @Override
  135.         public void despawn() {
  136.             this.bullet.destroy();
  137.         }
  138.     }
  139. }
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement