Skip to content

Commit

Permalink
Fix a NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
minus1over12 committed Jun 15, 2024
1 parent 3d564dd commit f21abc3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = 'io.github.minus1over12'
version = '1.0.0'
version = '1.0.1'

repositories {
mavenCentral()
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/io/github/minus1over12/ctfbuddy/FlagTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ protected FlagTracker(JavaPlugin plugin) {
* @return True if the item is the flag item, false otherwise
*/
private boolean isFlag(PersistentDataHolder item) {
if (item == null) {
return false;
}
return item.getPersistentDataContainer()
return item != null && item.getPersistentDataContainer()
.getOrDefault(isFlagKey, PersistentDataType.BOOLEAN, false);
}

Expand Down Expand Up @@ -246,7 +243,7 @@ public void onEntityDeath(EntityDeathEvent event) {
EntityEquipment equipment = entity.getEquipment();
if (equipment != null) {
ItemStack helmet = equipment.getHelmet();
if (isFlag(helmet.getItemMeta())) {
if (helmet != null && isFlag(helmet.getItemMeta())) {
// Handles keepInventory true case
entity.getWorld().dropItemNaturally(entity.getLocation(), helmet);
entity.setGlowing(false);
Expand Down Expand Up @@ -296,8 +293,8 @@ public void onEntityPortal(EntityPortalEvent event) {
if (!allowEnd && event.getPortalType().equals(PortalType.ENDER)) {
// Prevent the flag from being teleported to the end, if not allowed
Entity entity = event.getEntity();
if ((entity instanceof Item item && isFlag(item.getItemStack().getItemMeta()) ||
isFlag(entity))) {
if (entity instanceof Item item && isFlag(item.getItemStack().getItemMeta()) ||
isFlag(entity)) {
event.setCancelled(true);
} else if (entity instanceof LivingEntity livingEntity) {
EntityEquipment equipment = livingEntity.getEquipment();
Expand Down

0 comments on commit f21abc3

Please sign in to comment.