mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-25 18:47:40 +01:00
Prefer nullable over optional
This commit is contained in:
parent
3514547610
commit
3b3a86a402
@ -35,7 +35,7 @@ public class BlockEnumGenerator extends MinestomEnumGenerator<BlockContainer> {
|
||||
private final String targetVersion;
|
||||
private final File targetFolder;
|
||||
|
||||
private CodeBlock.Builder staticBlock = CodeBlock.builder();
|
||||
private final CodeBlock.Builder staticBlock = CodeBlock.builder();
|
||||
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
@ -161,8 +161,6 @@ public class BlockEnumGenerator extends MinestomEnumGenerator<BlockContainer> {
|
||||
}
|
||||
|
||||
return blocks;
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,8 +176,6 @@ public class BlockEnumGenerator extends MinestomEnumGenerator<BlockContainer> {
|
||||
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(blockFile))) {
|
||||
PrismarineJSBlock[] blocks = gson.fromJson(bufferedReader, PrismarineJSBlock[].class);
|
||||
return Arrays.asList(blocks);
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,8 +85,6 @@ public class ItemEnumGenerator extends MinestomEnumGenerator<ItemContainer> {
|
||||
items.add(item);
|
||||
}
|
||||
return items;
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ public interface CommandSender extends PermissionHandler {
|
||||
* */
|
||||
default void sendMessage(@NotNull JsonMessage text) {
|
||||
if (this instanceof Player) {
|
||||
((Player) this).sendMessage((JsonMessage) text);
|
||||
this.sendMessage(text);
|
||||
} else {
|
||||
sendMessage(text.getRawMessage());
|
||||
}
|
||||
|
@ -536,7 +536,7 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
|
||||
// #buildDeathScreenText can return null, check here
|
||||
if (deathText != null) {
|
||||
CombatEventPacket deathPacket = CombatEventPacket.death(this, Optional.empty(), deathText);
|
||||
CombatEventPacket deathPacket = CombatEventPacket.death(this, null, deathText);
|
||||
playerConnection.sendPacket(deathPacket);
|
||||
}
|
||||
|
||||
|
@ -58,8 +58,7 @@ public class MinestomExtensionClassLoader extends HierarchyClassLoader {
|
||||
} catch (ClassNotFoundException e) {
|
||||
for(MinestomExtensionClassLoader child : children) {
|
||||
try {
|
||||
Class<?> loaded = child.loadClassAsChild(name, resolve);
|
||||
return loaded;
|
||||
return child.loadClassAsChild(name, resolve);
|
||||
} catch (ClassNotFoundException e1) {
|
||||
// move on to next child
|
||||
}
|
||||
|
@ -31,19 +31,19 @@ public class CombatEventPacket implements ServerPacket {
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static CombatEventPacket end(int durationInTicks, Optional<Entity> opponent) {
|
||||
public static CombatEventPacket end(int durationInTicks, Entity opponent) {
|
||||
CombatEventPacket packet = new CombatEventPacket();
|
||||
packet.type = EventType.END_COMBAT;
|
||||
packet.duration = durationInTicks;
|
||||
packet.opponent = opponent.map(Entity::getEntityId).orElse(-1);
|
||||
packet.opponent = opponent != null ? opponent.getEntityId() : -1;
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static CombatEventPacket death(Player player, Optional<Entity> killer, JsonMessage message) {
|
||||
public static CombatEventPacket death(Player player, Entity killer, JsonMessage message) {
|
||||
CombatEventPacket packet = new CombatEventPacket();
|
||||
packet.type = EventType.DEATH;
|
||||
packet.playerID = player.getEntityId();
|
||||
packet.opponent = killer.map(Entity::getEntityId).orElse(-1);
|
||||
packet.opponent = killer != null ? killer.getEntityId() : -1;
|
||||
packet.deathMessage = message;
|
||||
return packet;
|
||||
}
|
||||
|
@ -281,20 +281,20 @@ public class EntityFinder {
|
||||
closestDistance = distance;
|
||||
}
|
||||
}
|
||||
return Arrays.asList(entity);
|
||||
return Collections.singletonList(entity);
|
||||
} else if (targetSelector == TargetSelector.RANDOM_PLAYER) {
|
||||
Collection<Player> instancePlayers = instance != null ?
|
||||
instance.getPlayers() : MinecraftServer.getConnectionManager().getOnlinePlayers();
|
||||
final int index = ThreadLocalRandom.current().nextInt(instancePlayers.size());
|
||||
final Player player = instancePlayers.stream().skip(index).findFirst().orElseThrow();
|
||||
return Arrays.asList(player);
|
||||
return Collections.singletonList(player);
|
||||
} else if (targetSelector == TargetSelector.ALL_PLAYERS) {
|
||||
return new ArrayList<>(instance != null ?
|
||||
instance.getPlayers() : MinecraftServer.getConnectionManager().getOnlinePlayers());
|
||||
} else if (targetSelector == TargetSelector.ALL_ENTITIES) {
|
||||
return new ArrayList<>(instance.getEntities());
|
||||
} else if (targetSelector == TargetSelector.SELF) {
|
||||
return Arrays.asList(self);
|
||||
return Collections.singletonList(self);
|
||||
}
|
||||
throw new IllegalStateException("Weird thing happened");
|
||||
}
|
||||
|
@ -36,8 +36,7 @@ public class DimensionCommand implements CommandProcessor {
|
||||
// targetDimensionType = DimensionType.OVERWORLD;
|
||||
//}
|
||||
|
||||
DimensionType finalTargetDimensionType = targetDimensionType;
|
||||
Optional<Instance> targetInstance = MinecraftServer.getInstanceManager().getInstances().stream().filter(in -> in.getDimensionType() == finalTargetDimensionType).findFirst();
|
||||
Optional<Instance> targetInstance = MinecraftServer.getInstanceManager().getInstances().stream().filter(in -> in.getDimensionType() == targetDimensionType).findFirst();
|
||||
if (targetInstance.isPresent()) {
|
||||
player.sendMessage("You were in " + instance.getDimensionType());
|
||||
player.setInstance(targetInstance.get());
|
||||
|
@ -25,11 +25,10 @@ public class ReloadExtensionCommand extends Command {
|
||||
private static String[] extensionsName;
|
||||
|
||||
static {
|
||||
List<String> extensionsName = MinecraftServer.getExtensionManager().getExtensions()
|
||||
ReloadExtensionCommand.extensionsName = MinecraftServer.getExtensionManager().getExtensions()
|
||||
.stream()
|
||||
.map(extension -> extension.getDescription().getName())
|
||||
.collect(Collectors.toList());
|
||||
ReloadExtensionCommand.extensionsName = extensionsName.toArray(new String[0]);
|
||||
.toArray(String[]::new);
|
||||
}
|
||||
|
||||
public ReloadExtensionCommand() {
|
||||
|
Loading…
Reference in New Issue
Block a user