Skip to content

Commit

Permalink
Fix another NPE with Shulker boxes and a fix for vault sign validation (
Browse files Browse the repository at this point in the history
#173)

* Fix another NPE with Shulker boxes

* Use same pattern for vault sign validation as creation

* Bump build version
  • Loading branch information
weaves7 authored Apr 4, 2024
1 parent 9ace3f6 commit f7ade10
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>minecraftwars</groupId>
<artifactId>gringotts</artifactId>
<version>2.12.6-SNAPSHOT</version>
<version>2.12.7-SNAPSHOT</version>

<properties>
<maven.deploy.skip>false</maven.deploy.skip>
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/org/gestern/gringotts/AccountChest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.gestern.gringotts;

import io.papermc.lib.PaperLib;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
Expand All @@ -10,13 +11,20 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Represents a storage unit for an account.
*
* @author jast
*/
public class AccountChest {

private final Pattern VAULT_PATTERN = Pattern.compile(Configuration.CONF.vaultPattern, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);

public final String id;

/**
* Sign marking the chest as an account chest.
*/
Expand Down Expand Up @@ -186,9 +194,12 @@ public boolean notValid() {
}

String[] lines = sign.getLines();
String line0 = lines[0];
String line0 = ChatColor.stripColor(lines[0]).trim();


Matcher match = VAULT_PATTERN.matcher(line0);

if (!line0.matches(Configuration.CONF.vaultPattern)) {
if (!match.matches()) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/gestern/gringotts/GringottsAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public long addToShulkerBox(long remaining, Inventory inventory) {

public long removeFromShulkerBox(long remaining, Inventory inventory) {
for (ItemStack itemStack : inventory.getContents()) {
if (Tag.SHULKER_BOXES.isTagged(itemStack.getType()) && itemStack.getItemMeta() instanceof BlockStateMeta) {
if (itemStack != null && Tag.SHULKER_BOXES.isTagged(itemStack.getType()) && itemStack.getItemMeta() instanceof BlockStateMeta) {
BlockStateMeta blockState = (BlockStateMeta) itemStack.getItemMeta();
if (blockState.getBlockState() instanceof ShulkerBox) {
ShulkerBox shulkerBox = (ShulkerBox) blockState.getBlockState();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.gestern.gringotts.event;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -19,7 +20,7 @@
*/
public class AccountListener implements Listener {

private final Pattern vaultPattern = Pattern.compile(Configuration.CONF.vaultPattern, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
private final Pattern VAULT_PATTERN = Pattern.compile(Configuration.CONF.vaultPattern, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);

/**
* Create an account chest by adding a sign marker over it.
Expand All @@ -28,13 +29,13 @@ public class AccountListener implements Listener {
*/
@EventHandler
public void onSignChange(SignChangeEvent event) {
String line0String = event.getLine(0);
String line0String = ChatColor.stripColor(event.getLine(0)).trim();

if (line0String == null) {
return;
}

Matcher match = vaultPattern.matcher(line0String);
Matcher match = VAULT_PATTERN.matcher(line0String);

// consider only signs with proper formatting
if (!match.matches()) {
Expand Down

0 comments on commit f7ade10

Please sign in to comment.