1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 11:45: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(); this.hash = copy.hashCode();
} }
if (item instanceof SlimefunArmorPiece) { if (item instanceof SlimefunArmorPiece slimefunArmorPiece) {
this.item = Optional.of((SlimefunArmorPiece) item); this.item = Optional.of(slimefunArmorPiece);
} else { } else {
this.item = Optional.empty(); this.item = Optional.empty();
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -222,8 +222,7 @@ public class BlockPlacer extends SlimefunItem {
if (meta.hasDisplayName()) { if (meta.hasDisplayName()) {
BlockStateSnapshotResult blockState = PaperLib.getBlockState(facedBlock, false); BlockStateSnapshotResult blockState = PaperLib.getBlockState(facedBlock, false);
if ((blockState.getState() instanceof Nameable)) { if (blockState.getState() instanceof Nameable nameable) {
Nameable nameable = ((Nameable) blockState.getState());
nameable.setCustomName(meta.getDisplayName()); nameable.setCustomName(meta.getDisplayName());
if (blockState.isSnapshot()) { 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 // Fixes #2903 - Cancel physics update to resolve weird overlapping
block.setType(water ? Material.WATER : Material.LAVA, false); block.setType(water ? Material.WATER : Material.LAVA, false);
} else { } else {
if (water && block.getBlockData() instanceof Waterlogged) { if (water && block.getBlockData() instanceof Waterlogged waterlogged) {
Waterlogged wl = (Waterlogged) block.getBlockData(); waterlogged.setWaterlogged(true);
wl.setWaterlogged(true); block.setBlockData(waterlogged, false);
block.setBlockData(wl, false);
block.getWorld().playSound(block.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1F, 1F); block.getWorld().playSound(block.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1F, 1F);
return; return;
} }

View File

@ -87,8 +87,8 @@ public class EnhancedFurnace extends SimpleSlimefunItem<BlockTicker> {
BlockState state = result.getState(); BlockState state = result.getState();
// Check if the BlockState is a Furnace and cooking something // Check if the BlockState is a Furnace and cooking something
if (state instanceof Furnace && ((Furnace) state).getCookTime() > 0) { if (state instanceof Furnace furnace && furnace.getCookTime() > 0) {
setProgress((Furnace) state); setProgress(furnace);
// Only update if necessary // Only update if necessary
if (result.isSnapshot()) { 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); Location l = new Location(projector.getWorld(), projector.getX() + 0.5, projector.getY() + offset, projector.getZ() + 0.5);
for (Entity n : l.getChunk().getEntities()) { 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(); String customName = n.getCustomName();
if (customName != null && customName.equals(nametag)) { 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) { if (block.getType() == Material.DROPPER && BlockStorage.check(block) instanceof IgnitionChamber) {
BlockState state = PaperLib.getBlockState(b.getRelative(face), false).getState(); BlockState state = PaperLib.getBlockState(b.getRelative(face), false).getState();
if (state instanceof Dropper) { if (state instanceof Dropper dropper) {
return ((Dropper) state).getInventory(); 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. // Found the output chest! Now, let's check if we can fit the product in it.
BlockState state = PaperLib.getBlockState(potentialOutput, false).getState(); BlockState state = PaperLib.getBlockState(potentialOutput, false).getState();
if (state instanceof Chest) { if (state instanceof Chest chest) {
Inventory inv = ((Chest) state).getInventory(); Inventory inv = chest.getInventory();
// Check if the Item fits into that inventory. // Check if the Item fits into that inventory.
if (InvUtils.fits(inv, item)) { if (InvUtils.fits(inv, item)) {