use of me.deecaad.core.compatibility.entity.FakeEntity in project MechanicsMain by WeaponMechanics.
the class FakeEntityCommand method execute.
@Override
public void execute(CommandSender sender, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "Player only command!");
return;
}
Player player = (Player) sender;
// Parse arguments of the command
EntityType type = args.length > 0 ? EntityType.valueOf(args[0]) : EntityType.ZOMBIE;
String moveType = args.length > 1 ? args[1] : "none";
int time = args.length > 2 ? Integer.parseInt(args[2]) : 1200;
boolean gravity = args.length > 3 ? Boolean.parseBoolean(args[3]) : false;
String name = args.length > 4 ? StringUtil.color(args[4]) : null;
FakeEntity entity = CompatibilityAPI.getEntityCompatibility().generateFakeEntity(player.getLocation(), type, type == EntityType.DROPPED_ITEM ? new ItemStack(Material.STONE_AXE) : null);
entity.setGravity(gravity);
entity.setDisplay(name);
entity.show(player);
entity.setMotion(0, 0, 0);
new BukkitRunnable() {
// Some temp vars for the different move types
int ticksAlive = 0;
boolean flash = true;
@Override
public void run() {
if (ticksAlive++ >= time) {
entity.remove();
cancel();
return;
}
switch(moveType) {
case "spin":
entity.setRotation(entity.getYaw() + 5.0f, entity.getYaw() / 2.0f);
break;
case "flash":
if (ticksAlive % 10 == 0) {
flash = !flash;
entity.setGlowing(flash);
entity.updateMeta();
}
break;
case "sky":
// entity.setMotion(0, 0.08, 0);
entity.setPosition(entity.getX(), entity.getY() + 0.1, entity.getZ());
break;
case "x":
// entity.setMotion(0.08, 0, 0);
entity.setPosition(entity.getX() + 0.1, entity.getY(), entity.getZ());
break;
}
}
}.runTaskTimerAsynchronously(WeaponMechanics.getPlugin(), 0, 0);
}
use of me.deecaad.core.compatibility.entity.FakeEntity in project MechanicsMain by WeaponMechanics.
the class Projectile method shoot.
/**
* Shoots created projectile object
*
* @param projectile the created projectile object
* @param location the location containing pitch and yaw
*/
public WeaponProjectile shoot(WeaponProjectile projectile, Location location) {
WeaponMechanics.getProjectilesRunnable().addProjectile(projectile);
if (mechanics != null)
mechanics.use(new CastData(projectile));
EntityType type = projectileSettings.getProjectileDisguise();
if (type != null) {
FakeEntity fakeEntity;
Object data = projectileSettings.getDisguiseData();
if (type == EntityType.ARMOR_STAND && data != null) {
// Armor stand height * eye height multiplier
// 1.975 * 0.85 = 1.67875
Location offset = new Location(location.getWorld(), 0, -1.67875, 0);
// Add the first offset before actually spawning
location.add(offset);
fakeEntity = CompatibilityAPI.getEntityCompatibility().generateFakeEntity(location, type, data);
fakeEntity.setEquipment(EquipmentSlot.HEAD, (ItemStack) data);
fakeEntity.setInvisible(true);
// Set the offset for new packets
fakeEntity.setOffset(offset);
} else {
fakeEntity = CompatibilityAPI.getEntityCompatibility().generateFakeEntity(location, type, data);
}
projectile.spawnDisguise(fakeEntity);
}
// Handle explosions
Explosion explosion = getConfigurations().getObject(projectile.getWeaponTitle() + ".Explosion", Explosion.class);
if (explosion != null)
explosion.handleExplosion(projectile.getShooter(), projectile, ExplosionTrigger.SPAWN);
return projectile;
}
use of me.deecaad.core.compatibility.entity.FakeEntity in project MechanicsMain by WeaponMechanics.
the class Explosion method spawnFallingBlock.
protected void spawnFallingBlock(Location location, BlockState state, Vector velocity) {
FakeEntity disguise = CompatibilityAPI.getEntityCompatibility().generateFakeEntity(location, state);
RemoveOnBlockCollisionProjectile projectile = new RemoveOnBlockCollisionProjectile(location, velocity, disguise);
WeaponMechanics.getProjectilesRunnable().addProjectile(projectile);
}
use of me.deecaad.core.compatibility.entity.FakeEntity in project MechanicsMain by WeaponMechanics.
the class FireworkCommand method execute.
@Override
public void execute(CommandSender sender, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "Player only command!");
return;
}
Player player = (Player) sender;
// Parse arguments of the command
byte flightTime = args.length > 0 ? Byte.parseByte(args[0]) : 40;
FireworkEffect.Type type = args.length > 1 ? FireworkEffect.Type.valueOf(args[1]) : FireworkEffect.Type.BURST;
Color color = args.length > 2 ? Color.fromRGB(Integer.parseInt(args[2], 16)) : Color.WHITE;
Color fade = args.length > 3 ? Color.fromRGB(Integer.parseInt(args[3], 16)) : Color.GRAY;
boolean flicker = args.length <= 4 || Boolean.parseBoolean(args[4]);
boolean trail = args.length <= 5 || Boolean.parseBoolean(args[5]);
ItemStack itemStack = new ItemStack(Material.FIREWORK_ROCKET);
FireworkMeta meta = (FireworkMeta) itemStack.getItemMeta();
FireworkEffect effect = FireworkEffect.builder().with(type).withColor(color).withFade(fade).flicker(flicker).trail(trail).build();
meta.addEffect(effect);
itemStack.setItemMeta(meta);
Random random = new Random();
FakeEntity fakeEntity = CompatibilityAPI.getCompatibility().getEntityCompatibility().generateFakeEntity(player.getLocation(), EntityType.FIREWORK, itemStack);
fakeEntity.setMotion(random.nextGaussian() * 0.001, 0.3, random.nextGaussian() * 0.001);
fakeEntity.show();
if (flightTime == 0) {
fakeEntity.playEffect(EntityEffect.FIREWORK_EXPLODE);
fakeEntity.remove();
return;
}
new BukkitRunnable() {
public void run() {
fakeEntity.playEffect(EntityEffect.FIREWORK_EXPLODE);
fakeEntity.remove();
}
}.runTaskLater(WeaponMechanics.getPlugin(), flightTime);
}
use of me.deecaad.core.compatibility.entity.FakeEntity in project MechanicsMain by WeaponMechanics.
the class FireworkMechanic method use.
@Override
public void use(CastData castData) {
Location location = locationAdjuster != null ? locationAdjuster.getNewLocation(castData.getCastLocation()) : castData.getCastLocation();
List<Player> players = DistanceUtil.getPlayersInRange(location);
if (players.isEmpty()) {
return;
}
int flightTime = ((FireworkMeta) fireworkItem.getItemMeta()).getPower();
FakeEntity fakeEntity = CompatibilityAPI.getCompatibility().getEntityCompatibility().generateFakeEntity(location, EntityType.FIREWORK, fireworkItem);
if (flightTime > 1)
fakeEntity.setMotion(0.001, 0.3, -0.001);
fakeEntity.show();
if (flightTime <= 0) {
fakeEntity.playEffect(EntityEffect.FIREWORK_EXPLODE);
fakeEntity.remove();
return;
}
new BukkitRunnable() {
public void run() {
fakeEntity.playEffect(EntityEffect.FIREWORK_EXPLODE);
fakeEntity.remove();
}
}.runTaskLater(WeaponMechanics.getPlugin(), flightTime);
}
Aggregations