Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix another NPE with Shulker boxes and a fix for vault sign validation #173

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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