using java 16 syntax (#1958)

This commit is contained in:
Invvk 2022-04-01 00:12:47 +03:00 committed by GitHub
parent 36751d5573
commit c02e566266
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 25 deletions

View File

@ -257,8 +257,8 @@ public class BlueprintClipboard {
}
// Banners
if (blockState instanceof Banner) {
b.setBannerPatterns(((Banner) blockState).getPatterns());
if (blockState instanceof Banner banner) {
b.setBannerPatterns(banner.getPatterns());
}
return b;
@ -282,8 +282,8 @@ public class BlueprintClipboard {
BlueprintEntity bpe = new BlueprintEntity();
bpe.setType(entity.getType());
bpe.setCustomName(entity.getCustomName());
if (entity instanceof Villager) {
setVillager(entity, bpe);
if (entity instanceof Villager villager) {
setVillager(villager, bpe);
}
if (entity instanceof Colorable c) {
if (c.getColor() != null) {
@ -321,11 +321,10 @@ public class BlueprintClipboard {
/**
* Set the villager stats
* @param entity - villager
* @param v - villager
* @param bpe - Blueprint Entity
*/
private void setVillager(LivingEntity entity, BlueprintEntity bpe) {
Villager v = (Villager)entity;
private void setVillager(Villager v, BlueprintEntity bpe) {
bpe.setExperience(v.getVillagerExperience());
bpe.setLevel(v.getVillagerLevel());
bpe.setProfession(v.getProfession());

View File

@ -305,8 +305,8 @@ public class BlueprintPaster {
writeSign(block, bpBlock.getSignLines(), bpBlock.isGlowingText());
}
// Chests, in general
if (bs instanceof InventoryHolder) {
Inventory ih = ((InventoryHolder)bs).getInventory();
if (bs instanceof InventoryHolder holder) {
Inventory ih = holder.getInventory();
// Double chests are pasted as two blocks so inventory is filled twice.
// This code stops over-filling for the first block.
bpBlock.getInventory().forEach(ih::setItem);

View File

@ -56,23 +56,23 @@ public class BlueprintEntity {
* @since 1.8.0
*/
public void configureEntity(Entity e) {
if (e instanceof Villager) {
setVillager(e);
if (e instanceof Villager villager) {
setVillager(villager);
}
if (e instanceof Colorable) {
((Colorable) e).setColor(color);
if (e instanceof Colorable c) {
c.setColor(color);
}
if (tamed != null && e instanceof Tameable) {
((Tameable)e).setTamed(tamed);
if (tamed != null && e instanceof Tameable tameable) {
tameable.setTamed(tamed);
}
if (chest != null && e instanceof ChestedHorse) {
((ChestedHorse)e).setCarryingChest(chest);
if (chest != null && e instanceof ChestedHorse chestedHorse) {
chestedHorse.setCarryingChest(chest);
}
if (adult != null && e instanceof Ageable) {
if (adult != null && e instanceof Ageable ageable) {
if (adult) {
((Ageable)e).setAdult();
ageable.setAdult();
} else {
((Ageable)e).setBaby();
ageable.setBaby();
}
}
if (e instanceof AbstractHorse horse) {
@ -81,18 +81,17 @@ public class BlueprintEntity {
inventory.forEach(horse.getInventory()::setItem);
}
}
if (style != null && e instanceof Horse) {
((Horse)e).setStyle(style);
if (style != null && e instanceof Horse horse) {
horse.setStyle(style);
}
}
/**
* @param e - villager
* @param v - villager
* @since 1.16.0
*/
private void setVillager(Entity e) {
Villager v = (Villager)e;
private void setVillager(Villager v) {
v.setProfession(profession == null ? Profession.NONE : profession);
v.setVillagerExperience(experience == null ? 0 : experience);
v.setVillagerLevel(level == null ? 0 : level);