Skip to content

Commit

Permalink
Added a bunch of null checks in the PortalDataManager in case its cal…
Browse files Browse the repository at this point in the history
…led from the client, closes #124
  • Loading branch information
Buuz135 committed Jun 19, 2022
1 parent fc08946 commit b24fbf9
Showing 1 changed file with 38 additions and 24 deletions.
62 changes: 38 additions & 24 deletions src/main/java/com/buuz135/portality/data/PortalDataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,21 @@ public static void removeInformation(LevelAccessor world, BlockPos blockPos) {
@Nullable
public static PortalInformation getInfoFromID(Level world, UUID uuid) {
PortalDataManager dataManager = getData(world);
for (PortalInformation information : dataManager.getInformationList()) {
if (information.getId().equals(uuid)) return information;
if (dataManager != null){
for (PortalInformation information : dataManager.getInformationList()) {
if (information.getId().equals(uuid)) return information;
}
}
return null;
}

@Nullable
public static PortalInformation getInfoFromPos(Level world, BlockPos pos) {
PortalDataManager dataManager = getData(world);
for (PortalInformation information : dataManager.getInformationList()) {
if (information.getLocation().equals(pos)) return information;
if (dataManager != null){
for (PortalInformation information : dataManager.getInformationList()) {
if (information.getLocation().equals(pos)) return information;
}
}
return null;
}
Expand All @@ -92,40 +96,48 @@ public static PortalInformation getInfoFromLink(Level world, PortalLinkData data

public static void setPortalPrivacy(Level world, BlockPos pos, boolean privacy) {
PortalDataManager dataManager = getData(world);
for (PortalInformation information : dataManager.getInformationList()) {
if (information.getLocation().equals(pos)) {
information.setPrivate(privacy);
dataManager.setDirty();
if (dataManager != null){
for (PortalInformation information : dataManager.getInformationList()) {
if (information.getLocation().equals(pos)) {
information.setPrivate(privacy);
dataManager.setDirty();
}
}
}
}

public static void setPortalName(Level world, BlockPos pos, String name) {
PortalDataManager dataManager = getData(world);
for (PortalInformation information : dataManager.getInformationList()) {
if (information.getLocation().equals(pos)) {
information.setName(name);
dataManager.setDirty();
if (dataManager != null){
for (PortalInformation information : dataManager.getInformationList()) {
if (information.getLocation().equals(pos)) {
information.setName(name);
dataManager.setDirty();
}
}
}
}

public static void setPortalInterdimensional(Level world, BlockPos pos, boolean interdimensional) {
PortalDataManager dataManager = getData(world);
for (PortalInformation information : dataManager.getInformationList()) {
if (information.getLocation().equals(pos)) {
information.setInterdimensional(interdimensional);
dataManager.setDirty();
if (dataManager != null){
for (PortalInformation information : dataManager.getInformationList()) {
if (information.getLocation().equals(pos)) {
information.setInterdimensional(interdimensional);
dataManager.setDirty();
}
}
}
}

public static void setPortalDisplay(Level world, BlockPos pos, ItemStack stack) {
PortalDataManager dataManager = getData(world);
for (PortalInformation information : dataManager.getInformationList()) {
if (information.getLocation().equals(pos)) {
information.setDisplay(stack);
dataManager.setDirty();
if (dataManager != null){
for (PortalInformation information : dataManager.getInformationList()) {
if (information.getLocation().equals(pos)) {
information.setDisplay(stack);
dataManager.setDirty();
}
}
}
}
Expand All @@ -142,10 +154,12 @@ public static PortalDataManager getData(LevelAccessor world) {

public static void setActiveStatus(Level world, BlockPos pos, boolean active) {
PortalDataManager dataManager = getData(world);
for (PortalInformation information : dataManager.getInformationList()) {
if (information.getLocation().equals(pos)) {
information.setActive(active);
dataManager.setDirty();
if (dataManager != null){
for (PortalInformation information : dataManager.getInformationList()) {
if (information.getLocation().equals(pos)) {
information.setActive(active);
dataManager.setDirty();
}
}
}
}
Expand Down

0 comments on commit b24fbf9

Please sign in to comment.