1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Java16 Sonar Changes - 4

This commit is contained in:
Sefiraat 2022-07-02 21:31:03 +01:00
parent cd9920b181
commit 0f6b6b244c
16 changed files with 60 additions and 67 deletions

View File

@ -61,8 +61,8 @@ public final class HashedArmorpiece {
this.hash = copy.hashCode();
}
if (item instanceof SlimefunArmorPiece) {
this.item = Optional.of((SlimefunArmorPiece) item);
if (item instanceof SlimefunArmorPiece slimefunArmorPiece) {
this.item = Optional.of(slimefunArmorPiece);
} else {
this.item = Optional.empty();
}

View File

@ -482,8 +482,8 @@ public class SlimefunItem implements Placeable {
}
// Lock the SlimefunItemStack from any accidental manipulations
if (itemStackTemplate instanceof SlimefunItemStack && isItemStackImmutable()) {
((SlimefunItemStack) itemStackTemplate).lock();
if (itemStackTemplate instanceof SlimefunItemStack slimefunItemStack && isItemStackImmutable()) {
slimefunItemStack.lock();
}
postRegister();

View File

@ -128,12 +128,12 @@ public class SlimefunItemStack extends ItemStack {
im.setLore(lines);
}
if (im instanceof LeatherArmorMeta) {
((LeatherArmorMeta) im).setColor(color);
if (im instanceof LeatherArmorMeta leatherArmorMeta) {
leatherArmorMeta.setColor(color);
}
if (im instanceof PotionMeta) {
((PotionMeta) im).setColor(color);
if (im instanceof PotionMeta potionMeta) {
potionMeta.setColor(color);
}
});
}
@ -154,9 +154,9 @@ public class SlimefunItemStack extends ItemStack {
im.setLore(lines);
}
if (im instanceof PotionMeta) {
((PotionMeta) im).setColor(color);
((PotionMeta) im).addCustomEffect(effect, true);
if (im instanceof PotionMeta potionMeta) {
potionMeta.setColor(color);
potionMeta.addCustomEffect(effect, true);
if (effect.getType().equals(PotionEffectType.SATURATION)) {
im.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);

View File

@ -487,9 +487,7 @@ public class PlayerProfile {
if (!armorPiece.isPresent()) {
setId = null;
} else if (armorPiece.get() instanceof ProtectiveArmor) {
ProtectiveArmor protectedArmor = (ProtectiveArmor) armorPiece.get();
} else if (armorPiece.get() instanceof ProtectiveArmor protectedArmor) {
if (setId == null && protectedArmor.isFullSetRequired()) {
setId = protectedArmor.getArmorSetId();
}

View File

@ -175,8 +175,8 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
if (isValidInventory(targetBlock)) {
BlockState state = PaperLib.getBlockState(targetBlock, false).getState();
if (state instanceof InventoryHolder) {
Inventory inv = ((InventoryHolder) state).getInventory();
if (state instanceof InventoryHolder inventoryHolder) {
Inventory inv = inventoryHolder.getInventory();
if (craft(inv, recipe)) {
// We are done crafting!
@ -202,14 +202,12 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
protected boolean isValidInventory(@Nonnull Block block) {
Material type = block.getType();
switch (type) {
case CHEST:
case TRAPPED_CHEST:
case BARREL:
return true;
default:
return SlimefunTag.SHULKER_BOXES.isTagged(type);
}
return switch (type) {
case CHEST,
TRAPPED_CHEST,
BARREL -> true;
default -> SlimefunTag.SHULKER_BOXES.isTagged(type);
};
}
/**
@ -251,16 +249,16 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
BlockStateSnapshotResult result = PaperLib.getBlockState(b, false);
BlockState state = result.getState();
if (state instanceof Skull) {
if (state instanceof Skull skull) {
if (recipe == null) {
// Clear the value from persistent data storage
PersistentDataAPI.remove((Skull) state, recipeStorageKey);
PersistentDataAPI.remove(skull, recipeStorageKey);
// Also remove the "enabled" state since this should be per-recipe.
PersistentDataAPI.remove((Skull) state, recipeEnabledKey);
PersistentDataAPI.remove(skull, recipeEnabledKey);
} else {
// Store the value to persistent data storage
PersistentDataAPI.setString((Skull) state, recipeStorageKey, recipe.toString());
PersistentDataAPI.setString(skull, recipeStorageKey, recipe.toString());
}
// Fixes #2899 - Update the BlockState if necessary
@ -337,12 +335,12 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
BlockState state = PaperLib.getBlockState(b, false).getState();
// Make sure the block is still a Skull
if (state instanceof Skull) {
if (state instanceof Skull skull) {
if (enabled) {
PersistentDataAPI.remove((Skull) state, recipeEnabledKey);
PersistentDataAPI.remove(skull, recipeEnabledKey);
Slimefun.getLocalization().sendMessage(p, "messages.auto-crafting.re-enabled");
} else {
PersistentDataAPI.setByte((Skull) state, recipeEnabledKey, (byte) 1);
PersistentDataAPI.setByte(skull, recipeEnabledKey, (byte) 1);
Slimefun.getLocalization().sendMessage(p, "messages.auto-crafting.temporarily-disabled");
}
}

View File

@ -136,10 +136,10 @@ public abstract class AbstractRecipe {
*/
@Nullable
public static AbstractRecipe of(@Nullable Recipe recipe) {
if (recipe instanceof ShapedRecipe) {
return new VanillaRecipe((ShapedRecipe) recipe);
} else if (recipe instanceof ShapelessRecipe) {
return new VanillaRecipe((ShapelessRecipe) recipe);
if (recipe instanceof ShapedRecipe shapedRecipe) {
return new VanillaRecipe(shapedRecipe);
} else if (recipe instanceof ShapelessRecipe shapelessRecipe) {
return new VanillaRecipe(shapelessRecipe);
} else {
return null;
}

View File

@ -60,9 +60,9 @@ public class SlimefunAutoCrafter extends AbstractAutoCrafter {
BlockState state = PaperLib.getBlockState(b, false).getState();
if (state instanceof Skull) {
if (state instanceof Skull skull) {
// Read the stored value from persistent data storage
PersistentDataContainer container = ((Skull) state).getPersistentDataContainer();
PersistentDataContainer container = skull.getPersistentDataContainer();
String value = container.get(recipeStorageKey, PersistentDataType.STRING);
SlimefunItem item = SlimefunItem.getById(value);

View File

@ -61,9 +61,9 @@ public class VanillaAutoCrafter extends AbstractAutoCrafter {
public @Nullable AbstractRecipe getSelectedRecipe(@Nonnull Block b) {
BlockState state = PaperLib.getBlockState(b, false).getState();
if (state instanceof Skull) {
if (state instanceof Skull skull) {
// Read the stored value from persistent data storage
PersistentDataContainer container = ((Skull) state).getPersistentDataContainer();
PersistentDataContainer container = skull.getPersistentDataContainer();
String value = container.get(recipeStorageKey, PersistentDataType.STRING);
if (value != null) {

View File

@ -81,19 +81,19 @@ class VanillaRecipe extends AbstractRecipe {
RecipeChoice[] choices = Slimefun.getMinecraftRecipeService().getRecipeShape(recipe);
ItemStack[] items = new ItemStack[9];
if (choices.length == 1 && choices[0] instanceof MaterialChoice) {
items[4] = new ItemStack(((MaterialChoice) choices[0]).getChoices().get(0));
if (choices.length == 1 && choices[0] instanceof MaterialChoice materialChoice) {
items[4] = new ItemStack(materialChoice.getChoices().get(0));
if (((MaterialChoice) choices[0]).getChoices().size() > 1) {
task.add(slots[4], (MaterialChoice) choices[0]);
if (materialChoice.getChoices().size() > 1) {
task.add(slots[4], materialChoice);
}
} else {
for (int i = 0; i < choices.length; i++) {
if (choices[i] instanceof MaterialChoice) {
items[i] = new ItemStack(((MaterialChoice) choices[i]).getChoices().get(0));
if (choices[i] instanceof MaterialChoice materialChoice) {
items[i] = new ItemStack(materialChoice.getChoices().get(0));
if (((MaterialChoice) choices[i]).getChoices().size() > 1) {
task.add(slots[i], (MaterialChoice) choices[i]);
if (materialChoice.getChoices().size() > 1) {
task.add(slots[i], materialChoice);
}
}
}
@ -107,8 +107,8 @@ class VanillaRecipe extends AbstractRecipe {
@Override
public String toString() {
if (recipe instanceof Keyed) {
return ((Keyed) recipe).getKey().toString();
if (recipe instanceof Keyed keyed) {
return keyed.getKey().toString();
} else {
return "invalid-recipe";
}

View File

@ -83,12 +83,11 @@ public abstract class AbstractMonsterSpawner extends SlimefunItem {
ItemMeta meta = item.getItemMeta();
// Fixes #2583 - Proper NBT handling of Spawners
if (meta instanceof BlockStateMeta) {
BlockStateMeta stateMeta = (BlockStateMeta) meta;
if (meta instanceof BlockStateMeta stateMeta) {
BlockState state = stateMeta.getBlockState();
if (state instanceof CreatureSpawner) {
((CreatureSpawner) state).setSpawnedType(type);
if (state instanceof CreatureSpawner creatureSpawner) {
creatureSpawner.setSpawnedType(type);
}
stateMeta.setBlockState(state);

View File

@ -222,8 +222,7 @@ public class BlockPlacer extends SlimefunItem {
if (meta.hasDisplayName()) {
BlockStateSnapshotResult blockState = PaperLib.getBlockState(facedBlock, false);
if ((blockState.getState() instanceof Nameable)) {
Nameable nameable = ((Nameable) blockState.getState());
if (blockState.getState() instanceof Nameable nameable) {
nameable.setCustomName(meta.getDisplayName());
if (blockState.isSnapshot()) {

View File

@ -203,10 +203,9 @@ public class Crucible extends SimpleSlimefunItem<BlockUseHandler> implements Rec
// Fixes #2903 - Cancel physics update to resolve weird overlapping
block.setType(water ? Material.WATER : Material.LAVA, false);
} else {
if (water && block.getBlockData() instanceof Waterlogged) {
Waterlogged wl = (Waterlogged) block.getBlockData();
wl.setWaterlogged(true);
block.setBlockData(wl, false);
if (water && block.getBlockData() instanceof Waterlogged waterlogged) {
waterlogged.setWaterlogged(true);
block.setBlockData(waterlogged, false);
block.getWorld().playSound(block.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1F, 1F);
return;
}

View File

@ -87,8 +87,8 @@ public class EnhancedFurnace extends SimpleSlimefunItem<BlockTicker> {
BlockState state = result.getState();
// Check if the BlockState is a Furnace and cooking something
if (state instanceof Furnace && ((Furnace) state).getCookTime() > 0) {
setProgress((Furnace) state);
if (state instanceof Furnace furnace && furnace.getCookTime() > 0) {
setProgress(furnace);
// Only update if necessary
if (result.isSnapshot()) {

View File

@ -140,11 +140,11 @@ public class HologramProjector extends SlimefunItem implements HologramOwner {
Location l = new Location(projector.getWorld(), projector.getX() + 0.5, projector.getY() + offset, projector.getZ() + 0.5);
for (Entity n : l.getChunk().getEntities()) {
if (n instanceof ArmorStand && l.distanceSquared(n.getLocation()) < 0.4) {
if (n instanceof ArmorStand armorStand && l.distanceSquared(n.getLocation()) < 0.4) {
String customName = n.getCustomName();
if (customName != null && customName.equals(nametag)) {
return (ArmorStand) n;
return armorStand;
}
}
}

View File

@ -116,8 +116,8 @@ public class IgnitionChamber extends SlimefunItem {
if (block.getType() == Material.DROPPER && BlockStorage.check(block) instanceof IgnitionChamber) {
BlockState state = PaperLib.getBlockState(b.getRelative(face), false).getState();
if (state instanceof Dropper) {
return ((Dropper) state).getInventory();
if (state instanceof Dropper dropper) {
return dropper.getInventory();
}
}
}

View File

@ -83,8 +83,8 @@ public class OutputChest extends SlimefunItem {
// Found the output chest! Now, let's check if we can fit the product in it.
BlockState state = PaperLib.getBlockState(potentialOutput, false).getState();
if (state instanceof Chest) {
Inventory inv = ((Chest) state).getInventory();
if (state instanceof Chest chest) {
Inventory inv = chest.getInventory();
// Check if the Item fits into that inventory.
if (InvUtils.fits(inv, item)) {