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

Java16 Sonar Changes - 2

This commit is contained in:
Sefiraat 2022-07-02 21:03:20 +01:00
parent b4bd9d7acf
commit f32dfa4d76
8 changed files with 83 additions and 92 deletions

View File

@ -70,21 +70,19 @@ final class CargoUtils {
Material type = block.getType();
switch (type) {
case CHEST:
case TRAPPED_CHEST:
case FURNACE:
case DISPENSER:
case DROPPER:
case HOPPER:
case BREWING_STAND:
case BARREL:
case BLAST_FURNACE:
case SMOKER:
return true;
default:
return SlimefunTag.SHULKER_BOXES.isTagged(type);
}
return switch (type) {
case CHEST,
TRAPPED_CHEST,
FURNACE,
DISPENSER,
DROPPER,
HOPPER,
BREWING_STAND,
BARREL,
BLAST_FURNACE,
SMOKER -> true;
default -> SlimefunTag.SHULKER_BOXES.isTagged(type);
};
}
@Nonnull
@ -145,8 +143,8 @@ final class CargoUtils {
BlockState state = PaperLib.getBlockState(target, false).getState();
if (state instanceof InventoryHolder) {
inventory = ((InventoryHolder) state).getInventory();
if (state instanceof InventoryHolder inventoryHolder) {
inventory = inventoryHolder.getInventory();
inventories.put(target.getLocation(), inventory);
return withdrawFromVanillaInventory(network, node, template, inventory);
}
@ -230,8 +228,8 @@ final class CargoUtils {
BlockState state = PaperLib.getBlockState(target, false).getState();
if (state instanceof InventoryHolder) {
inventory = ((InventoryHolder) state).getInventory();
if (state instanceof InventoryHolder inventoryHolder) {
inventory = inventoryHolder.getInventory();
inventories.put(target.getLocation(), inventory);
return withdrawFromVanillaInventory(network, node, inventory);
}
@ -278,8 +276,8 @@ final class CargoUtils {
BlockState state = PaperLib.getBlockState(target, false).getState();
if (state instanceof InventoryHolder) {
inventory = ((InventoryHolder) state).getInventory();
if (state instanceof InventoryHolder inventoryHolder) {
inventory = inventoryHolder.getInventory();
inventories.put(target.getLocation(), inventory);
return insertIntoVanillaInventory(stack, wrapper, smartFill, inventory);
}

View File

@ -75,16 +75,13 @@ public class EnergyNet extends Network implements HologramOwner {
if (component == null) {
return null;
} else {
switch (component.getEnergyComponentType()) {
case CONNECTOR:
case CAPACITOR:
return NetworkComponent.CONNECTOR;
case CONSUMER:
case GENERATOR:
return NetworkComponent.TERMINUS;
default:
return null;
}
return switch (component.getEnergyComponentType()) {
case CONNECTOR,
CAPACITOR -> NetworkComponent.CONNECTOR;
case CONSUMER,
GENERATOR -> NetworkComponent.TERMINUS;
default -> null;
};
}
}
@ -106,10 +103,10 @@ public class EnergyNet extends Network implements HologramOwner {
consumers.put(l, component);
break;
case GENERATOR:
if (component instanceof EnergyNetProvider) {
generators.put(l, (EnergyNetProvider) component);
} else if (component instanceof SlimefunItem) {
((SlimefunItem) component).warn("This Item is marked as a GENERATOR but does not implement the interface EnergyNetProvider!");
if (component instanceof EnergyNetProvider energyNetProvider) {
generators.put(l, energyNetProvider);
} else if (component instanceof SlimefunItem slimefunItem) {
slimefunItem.warn("This Item is marked as a GENERATOR but does not implement the interface EnergyNetProvider!");
}
break;
default:
@ -275,8 +272,8 @@ public class EnergyNet extends Network implements HologramOwner {
private static EnergyNetComponent getComponent(@Nonnull Location l) {
SlimefunItem item = BlockStorage.check(l);
if (item instanceof EnergyNetComponent) {
return ((EnergyNetComponent) item);
if (item instanceof EnergyNetComponent energyNetComponent) {
return energyNetComponent;
}
return null;

View File

@ -72,9 +72,9 @@ public class BlockDataService implements Keyed {
*/
BlockState state = b.getState();
if (state instanceof TileState) {
if (state instanceof TileState tileState) {
try {
PersistentDataContainer container = ((TileState) state).getPersistentDataContainer();
PersistentDataContainer container = tileState.getPersistentDataContainer();
container.set(namespacedKey, PersistentDataType.STRING, value);
state.update();
} catch (Exception x) {
@ -111,8 +111,8 @@ public class BlockDataService implements Keyed {
@Nullable
private PersistentDataContainer getPersistentDataContainer(@Nonnull BlockState state) {
if (state instanceof TileState) {
return ((TileState) state).getPersistentDataContainer();
if (state instanceof TileState tileState) {
return tileState.getPersistentDataContainer();
} else {
return null;
}
@ -137,31 +137,31 @@ public class BlockDataService implements Keyed {
return false;
}
switch (type) {
case PLAYER_HEAD:
case PLAYER_WALL_HEAD:
case CHEST:
case DISPENSER:
case BREWING_STAND:
case DROPPER:
case FURNACE:
case BLAST_FURNACE:
case HOPPER:
case LECTERN:
case JUKEBOX:
case ENDER_CHEST:
case ENCHANTING_TABLE:
case DAYLIGHT_DETECTOR:
case SMOKER:
case BARREL:
case SPAWNER:
case BEACON:
return switch (type) {
case PLAYER_HEAD,
PLAYER_WALL_HEAD,
CHEST,
DISPENSER,
BREWING_STAND,
DROPPER,
FURNACE,
BLAST_FURNACE,
HOPPER,
LECTERN,
JUKEBOX,
ENDER_CHEST,
ENCHANTING_TABLE,
DAYLIGHT_DETECTOR,
SMOKER,
BARREL,
SPAWNER,
BEACON ->
// All of the above Materials are Tile Entities
return true;
default:
true;
default ->
// Otherwise we assume they're not Tile Entities
return false;
}
false;
};
}
}

View File

@ -82,7 +82,7 @@ class GitHubTask implements Runnable {
}
for (GitHubConnector connector : gitHubService.getConnectors()) {
if (connector instanceof ContributionsConnector && !((ContributionsConnector) connector).hasFinished()) {
if (connector instanceof ContributionsConnector contributionsConnector && !contributionsConnector.hasFinished()) {
return;
}
}

View File

@ -62,9 +62,9 @@ class Hologram {
ArmorStand getArmorStand() {
Entity n = Bukkit.getEntity(uniqueId);
if (n instanceof ArmorStand && n.isValid()) {
if (n instanceof ArmorStand armorStand && n.isValid()) {
this.lastAccess = System.currentTimeMillis();
return (ArmorStand) n;
return armorStand;
} else {
this.lastAccess = 0;
return null;

View File

@ -191,11 +191,9 @@ public class HologramsService {
* @return Whether this could be a hologram
*/
private boolean isHologram(@Nonnull Entity n) {
if (n instanceof ArmorStand) {
ArmorStand armorstand = (ArmorStand) n;
if (n instanceof ArmorStand armorStand) {
// The absolute minimum requirements to count as a hologram
return !armorstand.isVisible() && armorstand.isSilent() && !armorstand.hasGravity();
return !armorStand.isVisible() && armorStand.isSilent() && !armorStand.hasGravity();
} else {
return false;
}
@ -216,22 +214,20 @@ public class HologramsService {
*/
@Nullable
private Hologram getAsHologram(@Nonnull BlockPosition position, @Nonnull Entity entity, @Nonnull PersistentDataContainer container) {
if (entity instanceof ArmorStand) {
ArmorStand armorstand = (ArmorStand) entity;
armorstand.setVisible(false);
armorstand.setInvulnerable(true);
armorstand.setSilent(true);
armorstand.setMarker(true);
armorstand.setAI(false);
armorstand.setGravity(false);
armorstand.setRemoveWhenFarAway(false);
if (entity instanceof ArmorStand armorStand) {
armorStand.setVisible(false);
armorStand.setInvulnerable(true);
armorStand.setSilent(true);
armorStand.setMarker(true);
armorStand.setAI(false);
armorStand.setGravity(false);
armorStand.setRemoveWhenFarAway(false);
// Set a persistent tag to re-identify the correct hologram later
container.set(persistentDataKey, PersistentDataType.LONG, position.getPosition());
// Store in cache for faster access
Hologram hologram = new Hologram(armorstand.getUniqueId());
Hologram hologram = new Hologram(armorStand.getUniqueId());
cache.put(position, hologram);
return hologram;

View File

@ -348,8 +348,8 @@ public abstract class SlimefunLocalization implements Keyed {
String prefix = addPrefix ? getChatPrefix() : "";
if (recipient instanceof Player) {
recipient.sendMessage(ChatColors.color(prefix + getMessage((Player) recipient, key)));
if (recipient instanceof Player player) {
recipient.sendMessage(ChatColors.color(prefix + getMessage(player, key)));
} else {
recipient.sendMessage(ChatColor.stripColor(ChatColors.color(prefix + getMessage(key))));
}
@ -383,8 +383,8 @@ public abstract class SlimefunLocalization implements Keyed {
String prefix = addPrefix ? getChatPrefix() : "";
if (recipient instanceof Player) {
recipient.sendMessage(ChatColors.color(prefix + function.apply(getMessage((Player) recipient, key))));
if (recipient instanceof Player player) {
recipient.sendMessage(ChatColors.color(prefix + function.apply(getMessage(player, key))));
} else {
recipient.sendMessage(ChatColor.stripColor(ChatColors.color(prefix + function.apply(getMessage(key)))));
}
@ -393,8 +393,8 @@ public abstract class SlimefunLocalization implements Keyed {
public void sendMessages(@Nonnull CommandSender recipient, @Nonnull String key) {
String prefix = getChatPrefix();
if (recipient instanceof Player) {
for (String translation : getMessages((Player) recipient, key)) {
if (recipient instanceof Player player) {
for (String translation : getMessages(player, key)) {
String message = ChatColors.color(prefix + translation);
recipient.sendMessage(message);
}
@ -410,8 +410,8 @@ public abstract class SlimefunLocalization implements Keyed {
public void sendMessages(CommandSender recipient, String key, boolean addPrefix, UnaryOperator<String> function) {
String prefix = addPrefix ? getChatPrefix() : "";
if (recipient instanceof Player) {
for (String translation : getMessages((Player) recipient, key)) {
if (recipient instanceof Player player) {
for (String translation : getMessages(player, key)) {
String message = ChatColors.color(prefix + function.apply(translation));
recipient.sendMessage(message);
}

View File

@ -95,9 +95,9 @@ class PerformanceSummary {
List<Entry<String, Long>> results = stream.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList());
String prefix = count + " " + name + (count != 1 ? 's' : "");
if (inspector instanceof PlayerPerformanceInspector) {
if (inspector instanceof PlayerPerformanceInspector playerPerformanceInspector) {
TextComponent component = summarizeAsTextComponent(count, prefix, results, formatter);
((PlayerPerformanceInspector) inspector).sendMessage(component);
playerPerformanceInspector.sendMessage(component);
} else {
String text = summarizeAsString(inspector, count, prefix, results, formatter);
inspector.sendMessage(text);