Patch a few null references

This commit is contained in:
zontreck 2023-12-20 17:55:35 -07:00
parent bd3e570097
commit 46142e36aa
8 changed files with 54 additions and 16 deletions

View file

@ -49,7 +49,7 @@ mod_name=OTEMod
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=GPLv3
# The mod version. See https://semver.org/
mod_version=1.4.122023.1704
mod_version=1.4.122023.1755
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View file

@ -32,6 +32,7 @@ import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.GameType;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerEvent;
@ -158,6 +159,18 @@ public class OTEMod
public static void checkFirstJoin(ServerPlayer p){
try {
Profile prof = Profile.get_profile_of(p.getStringUUID());
ItemStackHandler startKit = StarterProvider.getStarter().getItems();
boolean isEmpty=true;
for(int i = 0;i<startKit.getSlots();i++)
{
ItemStack is = startKit.getStackInSlot(i);
if(!is.is(Items.AIR))
{
isEmpty=false;
}
}
if(isEmpty)return;
PlayerFirstJoinTag tag = PlayerFirstJoinTag.load(prof.NBT);
if(tag == null)
@ -178,21 +191,16 @@ public class OTEMod
//p.addTag(OTEMod.FIRST_JOIN_TAG);
try {
ItemStackHandler startKit = StarterProvider.getStarter().getItems();
ChatHelpers.broadcastTo(p, ChatHelpers.macro(Messages.STARTER_KIT_GIVEN), p.server);
ChatHelpers.broadcastTo(p, ChatHelpers.macro(Messages.STARTER_KIT_GIVEN), p.server);
for(int i = 0;i<startKit.getSlots();i++)
for(int i = 0;i<startKit.getSlots();i++)
{
if(i>=p.getInventory().getContainerSize())
{
if(i>=p.getInventory().getContainerSize())
{
break;
} else {
p.getInventory().add(startKit.getStackInSlot(i));
}
break;
} else {
p.getInventory().add(startKit.getStackInSlot(i));
}
} catch (NoMoreVaultException e) {
throw new RuntimeException(e);
}
} catch (UserProfileNotYetExistsException e) {
throw new RuntimeException(e);

View file

@ -12,6 +12,7 @@ import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.configs.OTEServerConfig;
import dev.zontreck.otemod.configs.PlayerFlyCache;
import dev.zontreck.otemod.enchantments.ModEnchantments;
import dev.zontreck.otemod.implementation.vault.StarterProvider;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.server.level.ServerPlayer;
@ -53,7 +54,8 @@ public class ChatServerOverride {
c.FlyEnabled = mayFly;
c.Assert(play);
OTEMod.checkFirstJoin(ev.player);
if(StarterProvider.exists())
OTEMod.checkFirstJoin(ev.player);
if(!OTEServerConfig.USE_CUSTOM_JOINLEAVE.get()) return;

View file

@ -0,0 +1,5 @@
package dev.zontreck.otemod.implementation;
public class StarterKitDoesNotExistException extends Exception
{
}

View file

@ -6,6 +6,7 @@ import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
import dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.configs.OTEServerConfig;
import dev.zontreck.otemod.implementation.StarterKitDoesNotExistException;
import dev.zontreck.otemod.implementation.events.VaultModifiedEvent;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
@ -32,6 +33,7 @@ public class StarterContainer
public UUID owner;
private MinecraftServer server;
public final UUID VaultID;
private boolean invalid = false;
public Starter main_accessor;
public StarterContainer(ServerPlayer player) throws NoMoreVaultException {
myInventory = new ItemStackHandler(54); // Vaults have a fixed size at the same as a double chest
@ -68,6 +70,7 @@ public class StarterContainer
public void commit()
{
if(invalid)return;
boolean isEmpty=true;
CompoundTag saved = myInventory.serializeNBT();
ChatHelpers.broadcastToAbove(owner, Component.literal(ChatColor.BOLD+ChatColor.DARK_GREEN+"Saving the starter kit's contents..."), server);
@ -98,8 +101,13 @@ public class StarterContainer
main_accessor.delete();
VaultModifiedEvent vme = new VaultModifiedEvent(-2, profile, VaultProvider.getInUse(profile), myInventory, startingInventory);
OTEMod.bus.post(vme);
//VaultModifiedEvent vme = new VaultModifiedEvent(-2, profile, 0, myInventory, startingInventory);
//OTEMod.bus.post(vme);
}
public void invalidate()
{
invalid=true;
}
}

View file

@ -53,4 +53,10 @@ public class StarterProvider extends OTEDatastore
return v;
}else return null;
}
public static boolean exists()
{
Path v = FILE_TREE_PATH.resolve("starter.nbt");
return v.toFile().exists();
}
}

View file

@ -33,6 +33,7 @@ public class VaultContainer
public final int VAULT_NUMBER;
public final UUID VaultID;
public Vault main_accessor;
private boolean invalid;
public VaultContainer(ServerPlayer player, int vaultNum) throws NoMoreVaultException {
myInventory = new ItemStackHandler(54); // Vaults have a fixed size at the same as a double chest
startingInventory = new ItemStackHandler(64);
@ -73,6 +74,7 @@ public class VaultContainer
public void commit()
{
if(invalid)return;
if(VAULT_NUMBER == -1)return; // We have no need to save the trash
boolean isEmpty=true;
CompoundTag saved = myInventory.serializeNBT();
@ -106,4 +108,9 @@ public class VaultContainer
OTEMod.bus.post(vme);
}
public void invalidate()
{
invalid=true;
}
}

View file

@ -27,6 +27,7 @@ public class VaultWatcher {
if(entry.getKey() == ev.getEntity().getUUID())
{
entry.getValue().commit();
entry.getValue().invalidate();
}
}
} else if(ev.getContainer() instanceof StarterMenu)
@ -36,6 +37,7 @@ public class VaultWatcher {
if(entry.getKey() == ev.getEntity().getUUID())
{
entry.getValue().commit();
entry.getValue().invalidate();
}
}
}