From 2a43e5384279b5a38b8b392b548dc094e3a54316 Mon Sep 17 00:00:00 2001 From: Nicholas Ignoffo Date: Tue, 27 Feb 2018 16:59:51 -0800 Subject: [PATCH] Rewrite IBindable to provide an object instead of storing 2 strings --- .../bloodmagic/altar/BloodAltar.java | 22 ++- .../bloodmagic/block/BlockAltar.java | 8 +- .../block/BlockRitualController.java | 3 +- .../client/gui/GuiItemRoutingNode.java | 2 +- .../command/sub/SubCommandBind.java | 18 ++- .../DataProviderRitualController.java | 2 +- .../bloodmagic/core/RegistrarBloodMagic.java | 25 ++-- .../bloodmagic/core/data/Binding.java | 71 ++++++++++ .../bloodmagic/core/data/SoulNetwork.java | 3 +- .../bloodmagic/event/ItemBindEvent.java | 19 ++- .../bloodmagic/event/RitualEvent.java | 26 ++-- .../bloodmagic/event/SoulNetworkEvent.java | 21 +-- .../bloodmagic/iface/IActivatable.java | 21 ++- .../WayofTime/bloodmagic/iface/IBindable.java | 27 ++-- .../item/ItemActivationCrystal.java | 8 +- .../bloodmagic/item/ItemBindableBase.java | 8 +- .../bloodmagic/item/ItemBloodOrb.java | 18 +-- .../bloodmagic/item/ItemBoundSword.java | 49 +------ .../bloodmagic/item/ItemBoundTool.java | 49 +------ .../bloodmagic/item/ItemInscriptionTool.java | 8 +- .../bloodmagic/item/ItemLavaCrystal.java | 30 ++-- .../bloodmagic/item/ItemSigilToggleable.java | 11 +- .../item/ItemTelepositionFocus.java | 5 +- .../bloodmagic/item/sigil/ItemSigilAir.java | 2 +- .../bloodmagic/item/sigil/ItemSigilBase.java | 7 +- .../item/sigil/ItemSigilBloodLight.java | 6 +- .../item/sigil/ItemSigilDivination.java | 17 ++- .../item/sigil/ItemSigilHolding.java | 5 +- .../bloodmagic/item/sigil/ItemSigilLava.java | 4 +- .../item/sigil/ItemSigilTeleposition.java | 2 +- .../item/sigil/ItemSigilToggleableBase.java | 8 +- .../item/sigil/ItemSigilTransposition.java | 2 +- .../bloodmagic/item/sigil/ItemSigilVoid.java | 6 +- .../bloodmagic/item/sigil/ItemSigilWater.java | 2 +- .../WayofTime/bloodmagic/orb/BloodOrb.java | 9 +- .../bloodmagic/ritual/RitualExpulsion.java | 38 +++-- .../bloodmagic/ritual/RitualPortal.java | 5 +- .../ritual/data/IMasterRitualStone.java | 3 +- .../bloodmagic/ritual/data/Ritual.java | 7 +- .../bloodmagic/ritual/portal/Teleports.java | 26 ++-- .../bloodmagic/teleport/Teleport.java | 20 +-- .../tile/TileMasterRitualStone.java | 37 +++-- .../bloodmagic/tile/TileTeleposer.java | 27 ++-- .../util/handler/event/GenericHandler.java | 29 ++-- .../util/helper/BindableHelper.java | 130 ++---------------- .../bloodmagic/util/helper/NetworkHelper.java | 32 +++-- .../bloodmagic/util/helper/PlayerHelper.java | 48 +------ 47 files changed, 416 insertions(+), 510 deletions(-) create mode 100644 src/main/java/WayofTime/bloodmagic/core/data/Binding.java diff --git a/src/main/java/WayofTime/bloodmagic/altar/BloodAltar.java b/src/main/java/WayofTime/bloodmagic/altar/BloodAltar.java index 9d1272ca..2da8895d 100644 --- a/src/main/java/WayofTime/bloodmagic/altar/BloodAltar.java +++ b/src/main/java/WayofTime/bloodmagic/altar/BloodAltar.java @@ -4,6 +4,8 @@ import WayofTime.bloodmagic.api.event.BloodMagicCraftedEvent; import WayofTime.bloodmagic.api.impl.BloodMagicAPI; import WayofTime.bloodmagic.api.impl.recipe.RecipeBloodAltar; import WayofTime.bloodmagic.block.enums.BloodRuneType; +import WayofTime.bloodmagic.core.data.Binding; +import WayofTime.bloodmagic.iface.IBindable; import WayofTime.bloodmagic.iface.IBloodRune; import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.orb.BloodOrb; @@ -329,27 +331,21 @@ public class BloodAltar implements IFluidHandler { } } } else { - ItemStack returnedItem = tileAltar.getStackInSlot(0); + ItemStack contained = tileAltar.getStackInSlot(0); - if (returnedItem.isEmpty() || !(returnedItem.getItem() instanceof IBloodOrb)) + if (contained.isEmpty() || !(contained.getItem() instanceof IBloodOrb) || !(contained.getItem() instanceof IBindable)) return; - IBloodOrb item = (IBloodOrb) (returnedItem.getItem()); - NBTTagCompound itemTag = returnedItem.getTagCompound(); + BloodOrb orb = ((IBloodOrb) contained.getItem()).getOrb(contained); + Binding binding = ((IBindable) contained.getItem()).getBinding(contained); - if (itemTag == null) - return; - - String ownerUUID = itemTag.getString(Constants.NBT.OWNER_UUID); - - if (Strings.isNullOrEmpty(ownerUUID)) + if (binding == null || orb == null) return; if (fluid != null && fluid.amount >= 1) { - int liquidDrained = Math.min((int) (altarTier.ordinal() >= 2 ? consumptionRate * (1 + consumptionMultiplier) : consumptionRate), fluid.amount); + int liquidDrained = Math.min((int) (altarTier.ordinal() >= 2 ? orb.getFillRate() * (1 + consumptionMultiplier) : orb.getFillRate()), fluid.amount); - BloodOrb orb = item.getOrb(returnedItem); - int drain = orb == null ? 0 : NetworkHelper.getSoulNetwork(ownerUUID).add(liquidDrained, (int) (orb.getCapacity() * this.orbCapacityMultiplier)); + int drain = NetworkHelper.getSoulNetwork(binding).add(liquidDrained, (int) (orb.getCapacity() * this.orbCapacityMultiplier)); fluid.amount = fluid.amount - drain; if (drain > 0 && internalCounter % 4 == 0 && world instanceof WorldServer) { diff --git a/src/main/java/WayofTime/bloodmagic/block/BlockAltar.java b/src/main/java/WayofTime/bloodmagic/block/BlockAltar.java index 7a63b22d..7f9d2236 100644 --- a/src/main/java/WayofTime/bloodmagic/block/BlockAltar.java +++ b/src/main/java/WayofTime/bloodmagic/block/BlockAltar.java @@ -5,6 +5,7 @@ import WayofTime.bloodmagic.altar.BloodAltar; import WayofTime.bloodmagic.altar.EnumAltarComponent; import WayofTime.bloodmagic.altar.IAltarManipulator; import WayofTime.bloodmagic.altar.IBloodAltar; +import WayofTime.bloodmagic.core.data.Binding; import WayofTime.bloodmagic.iface.IAltarReader; import WayofTime.bloodmagic.iface.IBindable; import WayofTime.bloodmagic.iface.IDocumentedBlock; @@ -15,7 +16,6 @@ import WayofTime.bloodmagic.util.helper.NetworkHelper; import WayofTime.bloodmagic.client.IVariantProvider; import WayofTime.bloodmagic.tile.TileAltar; import WayofTime.bloodmagic.util.Utils; -import com.google.common.base.Strings; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; @@ -68,9 +68,9 @@ public class BlockAltar extends Block implements IVariantProvider, IDocumentedBl if (world.getBlockState(pos.down()).getBlock() instanceof BlockDecorative) { if (orbStack.getItem() instanceof IBloodOrb && orbStack.getItem() instanceof IBindable) { BloodOrb orb = ((IBloodOrb) orbStack.getItem()).getOrb(orbStack); - IBindable bindable = (IBindable) orbStack.getItem(); - if (orb != null && !Strings.isNullOrEmpty(bindable.getOwnerUUID(orbStack))) { - SoulNetwork soulNetwork = NetworkHelper.getSoulNetwork(bindable.getOwnerUUID(orbStack)); + Binding binding = ((IBindable) orbStack.getItem()).getBinding(orbStack); + if (orb != null && binding != null) { + SoulNetwork soulNetwork = NetworkHelper.getSoulNetwork(binding); int maxEssence = orb.getCapacity(); int currentEssence = soulNetwork.getCurrentEssence(); diff --git a/src/main/java/WayofTime/bloodmagic/block/BlockRitualController.java b/src/main/java/WayofTime/bloodmagic/block/BlockRitualController.java index 4b4c1b61..2824b6f0 100644 --- a/src/main/java/WayofTime/bloodmagic/block/BlockRitualController.java +++ b/src/main/java/WayofTime/bloodmagic/block/BlockRitualController.java @@ -50,8 +50,7 @@ public class BlockRitualController extends BlockEnum imple if (state.getValue(getProperty()) != EnumRitualController.IMPERFECT && tile instanceof TileMasterRitualStone) { if (heldItem.getItem() == RegistrarBloodMagicItems.ACTIVATION_CRYSTAL) { - IBindable bindable = (IBindable) heldItem.getItem(); - if (Strings.isNullOrEmpty(bindable.getOwnerName(heldItem))) + if (((IBindable) heldItem.getItem()).getBinding(heldItem) == null) return false; String key = RitualHelper.getValidRitual(world, pos); diff --git a/src/main/java/WayofTime/bloodmagic/client/gui/GuiItemRoutingNode.java b/src/main/java/WayofTime/bloodmagic/client/gui/GuiItemRoutingNode.java index 564494e6..ffba0f12 100644 --- a/src/main/java/WayofTime/bloodmagic/client/gui/GuiItemRoutingNode.java +++ b/src/main/java/WayofTime/bloodmagic/client/gui/GuiItemRoutingNode.java @@ -197,7 +197,7 @@ public class GuiItemRoutingNode extends GuiContainer { // { // if (slotInd == 0) // { -// this.nameField.setText(stack == null ? "" : stack.getDisplayName()); +// this.nameField.setText(stack == null ? "" : stack.getOwnerName()); // this.nameField.setEnabled(stack != null); // // if (stack != null) diff --git a/src/main/java/WayofTime/bloodmagic/command/sub/SubCommandBind.java b/src/main/java/WayofTime/bloodmagic/command/sub/SubCommandBind.java index f01b70ee..7548e3ec 100644 --- a/src/main/java/WayofTime/bloodmagic/command/sub/SubCommandBind.java +++ b/src/main/java/WayofTime/bloodmagic/command/sub/SubCommandBind.java @@ -1,5 +1,6 @@ package WayofTime.bloodmagic.command.sub; +import WayofTime.bloodmagic.core.data.Binding; import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.iface.IBindable; import WayofTime.bloodmagic.util.helper.BindableHelper; @@ -38,8 +39,6 @@ public class SubCommandBind extends CommandBase { try { EntityPlayer player = CommandBase.getCommandSenderAsPlayer(commandSender); - String playerName = player.getName(); - String uuid = PlayerHelper.getUUIDFromPlayer(player).toString(); ItemStack held = player.getHeldItemMainhand(); boolean bind = true; @@ -53,21 +52,20 @@ public class SubCommandBind extends CommandBase { bind = Boolean.parseBoolean(args[0]); if (args.length > 2) - playerName = args[1]; + player = CommandBase.getPlayer(server, commandSender, args[1]); } else { - playerName = args[0]; - uuid = PlayerHelper.getUUIDFromPlayer(CommandBase.getPlayer(server, commandSender, playerName)).toString(); + player = CommandBase.getPlayer(server, commandSender, args[0]); } } if (bind) { - BindableHelper.setItemOwnerName(held, playerName); - BindableHelper.setItemOwnerUUID(held, uuid); + Binding binding = new Binding(player.getGameProfile().getId(), player.getGameProfile().getName()); + BindableHelper.applyBinding(held, binding); commandSender.sendMessage(new TextComponentTranslation("commands.bind.success")); } else { - if (!Strings.isNullOrEmpty(((IBindable) held.getItem()).getOwnerUUID(held))) { - held.getTagCompound().removeTag(Constants.NBT.OWNER_UUID); - held.getTagCompound().removeTag(Constants.NBT.OWNER_NAME); + Binding binding = ((IBindable) held.getItem()).getBinding(held); + if (binding != null) { + held.getTagCompound().removeTag("binding"); commandSender.sendMessage(new TextComponentTranslation("commands.bind.remove.success")); } } diff --git a/src/main/java/WayofTime/bloodmagic/compat/waila/provider/DataProviderRitualController.java b/src/main/java/WayofTime/bloodmagic/compat/waila/provider/DataProviderRitualController.java index 5f5ac41a..f246bc48 100644 --- a/src/main/java/WayofTime/bloodmagic/compat/waila/provider/DataProviderRitualController.java +++ b/src/main/java/WayofTime/bloodmagic/compat/waila/provider/DataProviderRitualController.java @@ -63,7 +63,7 @@ public class DataProviderRitualController implements IWailaDataProvider { if (mrs.getCurrentRitual() != null) { tag.setString("ritual", mrs.getCurrentRitual().getUnlocalizedName()); tag.setBoolean("active", mrs.isActive()); - if (!Strings.isNullOrEmpty(mrs.getOwner())) + if (mrs.getOwner() != null) tag.setString("owner", PlayerHelper.getUsernameFromUUID(mrs.getOwner())); tag.setBoolean("enabled", RitualRegistry.ritualEnabled(mrs.getCurrentRitual())); } diff --git a/src/main/java/WayofTime/bloodmagic/core/RegistrarBloodMagic.java b/src/main/java/WayofTime/bloodmagic/core/RegistrarBloodMagic.java index 992bb9a1..c23234a9 100644 --- a/src/main/java/WayofTime/bloodmagic/core/RegistrarBloodMagic.java +++ b/src/main/java/WayofTime/bloodmagic/core/RegistrarBloodMagic.java @@ -30,18 +30,19 @@ import net.minecraftforge.registries.RegistryBuilder; @GameRegistry.ObjectHolder(BloodMagic.MODID) public class RegistrarBloodMagic { + private static final BloodOrb ORB_DEF = new BloodOrb("", 0, 0, 0); @GameRegistry.ObjectHolder("weak") - public static final BloodOrb ORB_WEAK = new BloodOrb("", 0, 0); + public static final BloodOrb ORB_WEAK = ORB_DEF; @GameRegistry.ObjectHolder("apprentice") - public static final BloodOrb ORB_APPRENTICE = new BloodOrb("", 0, 0); + public static final BloodOrb ORB_APPRENTICE = ORB_DEF; @GameRegistry.ObjectHolder("magician") - public static final BloodOrb ORB_MAGICIAN = new BloodOrb("", 0, 0); + public static final BloodOrb ORB_MAGICIAN = ORB_DEF; @GameRegistry.ObjectHolder("master") - public static final BloodOrb ORB_MASTER = new BloodOrb("", 0, 0); + public static final BloodOrb ORB_MASTER = ORB_DEF; @GameRegistry.ObjectHolder("archmage") - public static final BloodOrb ORB_ARCHMAGE = new BloodOrb("", 0, 0); + public static final BloodOrb ORB_ARCHMAGE = ORB_DEF; @GameRegistry.ObjectHolder("transcendent") - public static final BloodOrb ORB_TRANSCENDENT = new BloodOrb("", 0, 0); + public static final BloodOrb ORB_TRANSCENDENT = ORB_DEF; public static final Potion BOOST = MobEffects.HASTE; public static final Potion WHIRLWIND = MobEffects.HASTE; @@ -62,12 +63,12 @@ public class RegistrarBloodMagic { public static void registerBloodOrbs(RegistryEvent.Register event) { ResourceLocation orb = RegistrarBloodMagicItems.BLOOD_ORB.getRegistryName(); event.getRegistry().registerAll( - new BloodOrb("weak", 1, 5000).withModel(new ModelResourceLocation(orb, "type=weak")).setRegistryName("weak"), - new BloodOrb("apprentice", 2, 25000).withModel(new ModelResourceLocation(orb, "type=apprentice")).setRegistryName("apprentice"), - new BloodOrb("magician", 3, 150000).withModel(new ModelResourceLocation(orb, "type=magician")).setRegistryName("magician"), - new BloodOrb("master", 4, 1000000).withModel(new ModelResourceLocation(orb, "type=master")).setRegistryName("master"), - new BloodOrb("archmage", 5, 10000000).withModel(new ModelResourceLocation(orb, "type=archmage")).setRegistryName("archmage"), - new BloodOrb("transcendent", 6, 30000000).withModel(new ModelResourceLocation(orb, "type=transcendent")).setRegistryName("transcendent") + new BloodOrb("weak", 1, 5000, 2).withModel(new ModelResourceLocation(orb, "type=weak")).setRegistryName("weak"), + new BloodOrb("apprentice", 2, 25000, 5).withModel(new ModelResourceLocation(orb, "type=apprentice")).setRegistryName("apprentice"), + new BloodOrb("magician", 3, 150000, 15).withModel(new ModelResourceLocation(orb, "type=magician")).setRegistryName("magician"), + new BloodOrb("master", 4, 1000000, 25).withModel(new ModelResourceLocation(orb, "type=master")).setRegistryName("master"), + new BloodOrb("archmage", 5, 10000000, 50).withModel(new ModelResourceLocation(orb, "type=archmage")).setRegistryName("archmage"), + new BloodOrb("transcendent", 6, 30000000, 50).withModel(new ModelResourceLocation(orb, "type=transcendent")).setRegistryName("transcendent") ); } diff --git a/src/main/java/WayofTime/bloodmagic/core/data/Binding.java b/src/main/java/WayofTime/bloodmagic/core/data/Binding.java new file mode 100644 index 00000000..e8182e9a --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/core/data/Binding.java @@ -0,0 +1,71 @@ +package WayofTime.bloodmagic.core.data; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTUtil; +import net.minecraftforge.common.util.INBTSerializable; + +import javax.annotation.Nullable; +import java.util.UUID; + +public class Binding implements INBTSerializable { + + private UUID uuid; + private String name; + + public Binding(UUID uuid, String name) { + this.uuid = uuid; + this.name = name; + } + + private Binding() { + // No-op + } + + @Override + public NBTTagCompound serializeNBT() { + NBTTagCompound tag = new NBTTagCompound(); + tag.setTag("id", NBTUtil.createUUIDTag(uuid)); + tag.setString("name", name); + return tag; + } + + @Override + public void deserializeNBT(NBTTagCompound nbt) { + this.uuid = NBTUtil.getUUIDFromTag(nbt.getCompoundTag("id")); + this.name = nbt.getString("name"); + } + + public UUID getOwnerId() { + return uuid; + } + + public Binding setOwnerId(UUID uuid) { + this.uuid = uuid; + return this; + } + + public String getOwnerName() { + return name; + } + + public Binding setOwnerName(String name) { + this.name = name; + return this; + } + + @Nullable + public static Binding fromStack(ItemStack stack) { + if (!stack.hasTagCompound()) // Definitely hasn't been bound yet. + return null; + + NBTBase bindingTag = stack.getTagCompound().getTag("binding"); + if (bindingTag == null || bindingTag.getId() != 10 || bindingTag.hasNoTags()) // Make sure it's both a tag compound and that it has actual data. + return null; + + Binding binding = new Binding(); + binding.deserializeNBT((NBTTagCompound) bindingTag); + return binding; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/core/data/SoulNetwork.java b/src/main/java/WayofTime/bloodmagic/core/data/SoulNetwork.java index acc83e58..a9ec1ff2 100644 --- a/src/main/java/WayofTime/bloodmagic/core/data/SoulNetwork.java +++ b/src/main/java/WayofTime/bloodmagic/core/data/SoulNetwork.java @@ -1,6 +1,5 @@ package WayofTime.bloodmagic.core.data; -import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.util.BMLog; import WayofTime.bloodmagic.util.PleaseStopUsingMe; import WayofTime.bloodmagic.event.AddToNetworkEvent; @@ -74,7 +73,7 @@ public class SoulNetwork implements INBTSerializable { return false; if (!Strings.isNullOrEmpty(playerId.toString())) { - SoulNetworkEvent.ItemDrainNetworkEvent event = new SoulNetworkEvent.ItemDrainNetworkEvent(user, playerId.toString(), null, toSyphon); + SoulNetworkEvent.ItemDrainNetworkEvent event = new SoulNetworkEvent.ItemDrainNetworkEvent(user, playerId, null, toSyphon); if (MinecraftForge.EVENT_BUS.post(event)) return false; diff --git a/src/main/java/WayofTime/bloodmagic/event/ItemBindEvent.java b/src/main/java/WayofTime/bloodmagic/event/ItemBindEvent.java index 7f7e7bf4..e5cf73c5 100644 --- a/src/main/java/WayofTime/bloodmagic/event/ItemBindEvent.java +++ b/src/main/java/WayofTime/bloodmagic/event/ItemBindEvent.java @@ -7,24 +7,29 @@ import net.minecraftforge.fml.common.eventhandler.Event; @Cancelable public class ItemBindEvent extends Event { - public final EntityPlayer player; - public String key; - public ItemStack itemStack; + + private final EntityPlayer player; + private final ItemStack itemStack; /** * This event is called whenever a player attempts to bind a * {@link WayofTime.bloodmagic.iface.IBindable} item. * * @param player The player doing the binding - * @param key The UUID of the player doing the binding * @param itemStack The {@link ItemStack} that the player is binding *

* This event is {@link Cancelable}.
*/ - public ItemBindEvent(EntityPlayer player, String key, ItemStack itemStack) { - super(); + public ItemBindEvent(EntityPlayer player, ItemStack itemStack) { this.player = player; - this.key = key; this.itemStack = itemStack; } + + public EntityPlayer getNewOwner() { + return player; + } + + public ItemStack getBindingStack() { + return itemStack; + } } diff --git a/src/main/java/WayofTime/bloodmagic/event/RitualEvent.java b/src/main/java/WayofTime/bloodmagic/event/RitualEvent.java index d65da6a4..bf69e5b7 100644 --- a/src/main/java/WayofTime/bloodmagic/event/RitualEvent.java +++ b/src/main/java/WayofTime/bloodmagic/event/RitualEvent.java @@ -10,14 +10,16 @@ import net.minecraft.world.World; import net.minecraftforge.fml.common.eventhandler.Cancelable; import net.minecraftforge.fml.common.eventhandler.Event; +import java.util.UUID; + public class RitualEvent extends Event { public final IMasterRitualStone mrs; - public final String ownerName; + public final UUID ownerId; public final Ritual ritual; - private RitualEvent(IMasterRitualStone mrs, String ownerName, Ritual ritual) { + private RitualEvent(IMasterRitualStone mrs, UUID ownerId, Ritual ritual) { this.mrs = mrs; - this.ownerName = ownerName; + this.ownerId = ownerId; this.ritual = ritual; } @@ -33,8 +35,8 @@ public class RitualEvent extends Event { public final ItemStack crystalStack; public int crystalTier; - public RitualActivatedEvent(IMasterRitualStone mrs, String owner, Ritual ritual, EntityPlayer player, ItemStack activationCrystal, int crystalTier) { - super(mrs, owner, ritual); + public RitualActivatedEvent(IMasterRitualStone mrs, UUID ownerId, Ritual ritual, EntityPlayer player, ItemStack activationCrystal, int crystalTier) { + super(mrs, ownerId, ritual); this.player = player; this.crystalStack = activationCrystal; @@ -50,8 +52,8 @@ public class RitualEvent extends Event { */ @Cancelable public static class RitualRunEvent extends RitualEvent { - public RitualRunEvent(IMasterRitualStone mrs, String owner, Ritual ritual) { - super(mrs, owner, ritual); + public RitualRunEvent(IMasterRitualStone mrs, UUID ownerId, Ritual ritual) { + super(mrs, ownerId, ritual); } } @@ -65,8 +67,8 @@ public class RitualEvent extends Event { public final Ritual.BreakType method; - public RitualStopEvent(IMasterRitualStone mrs, String owner, Ritual ritual, Ritual.BreakType method) { - super(mrs, owner, ritual); + public RitualStopEvent(IMasterRitualStone mrs, UUID ownerId, Ritual ritual, Ritual.BreakType method) { + super(mrs, ownerId, ritual); this.method = method; } @@ -76,12 +78,12 @@ public class RitualEvent extends Event { public static class ImperfectRitualActivatedEvent extends Event { public final IImperfectRitualStone ims; - public final String ownerName; + public final UUID ownerId; public final ImperfectRitual imperfectRitual; - public ImperfectRitualActivatedEvent(IImperfectRitualStone ims, String ownerName, ImperfectRitual imperfectRitual) { + public ImperfectRitualActivatedEvent(IImperfectRitualStone ims, UUID ownerId, ImperfectRitual imperfectRitual) { this.ims = ims; - this.ownerName = ownerName; + this.ownerId = ownerId; this.imperfectRitual = imperfectRitual; } } diff --git a/src/main/java/WayofTime/bloodmagic/event/SoulNetworkEvent.java b/src/main/java/WayofTime/bloodmagic/event/SoulNetworkEvent.java index fc81dbe7..cb962fdd 100644 --- a/src/main/java/WayofTime/bloodmagic/event/SoulNetworkEvent.java +++ b/src/main/java/WayofTime/bloodmagic/event/SoulNetworkEvent.java @@ -6,6 +6,7 @@ import net.minecraftforge.fml.common.eventhandler.Cancelable; import net.minecraftforge.fml.common.eventhandler.Event; import javax.annotation.Nullable; +import java.util.UUID; /** * Base event class for Soul Network related events. @@ -14,17 +15,17 @@ import javax.annotation.Nullable; * amount of LP to be drained */ public class SoulNetworkEvent extends Event { - public final String ownerUUID; + public final UUID ownerUUID; public int syphon; - public SoulNetworkEvent(String ownerUUID, int syphon) { + public SoulNetworkEvent(UUID ownerUUID, int syphon) { this.ownerUUID = ownerUUID; this.syphon = syphon; } /** * This event is called when an - * {@link WayofTime.bloodmagic.apibutnotreally.impl.ItemBindable} is being drained + * {@link WayofTime.bloodmagic.iface.IBindable} is being drained * inside of a {@link net.minecraft.tileentity.TileEntity}. *

* If canceled, the drain will not be executed. @@ -33,8 +34,8 @@ public class SoulNetworkEvent extends Event { public static class ItemDrainInContainerEvent extends SoulNetworkEvent { public ItemStack stack; - public ItemDrainInContainerEvent(ItemStack stack, String ownerName, int syphon) { - super(ownerName, syphon); + public ItemDrainInContainerEvent(ItemStack stack, UUID ownerId, int syphon) { + super(ownerId, syphon); this.stack = stack; } } @@ -50,8 +51,8 @@ public class SoulNetworkEvent extends Event { // If true, will damage regardless of if the network had enough inside it public boolean shouldDamage; - public PlayerDrainNetworkEvent(EntityPlayer player, String ownerNetwork, int drainAmount) { - super(ownerNetwork, drainAmount); + public PlayerDrainNetworkEvent(EntityPlayer player, UUID ownerId, int drainAmount) { + super(ownerId, drainAmount); this.shouldDamage = false; this.player = player; } @@ -72,12 +73,12 @@ public class SoulNetworkEvent extends Event { * event prevents action without penalties * * @param player Player using the item - * @param ownerNetwork Network that the item is tied to + * @param ownerId Network that the item is tied to * @param itemStack Item used * @param drainAmount Original drain amount - change to alter cost */ - public ItemDrainNetworkEvent(EntityPlayer player, String ownerNetwork, @Nullable ItemStack itemStack, int drainAmount) { - super(player, ownerNetwork, drainAmount); + public ItemDrainNetworkEvent(EntityPlayer player, UUID ownerId, @Nullable ItemStack itemStack, int drainAmount) { + super(player, ownerId, drainAmount); this.itemStack = itemStack; this.damageAmount = (float) (drainAmount) / 100.0f; } diff --git a/src/main/java/WayofTime/bloodmagic/iface/IActivatable.java b/src/main/java/WayofTime/bloodmagic/iface/IActivatable.java index f9b39342..e5ee95e9 100644 --- a/src/main/java/WayofTime/bloodmagic/iface/IActivatable.java +++ b/src/main/java/WayofTime/bloodmagic/iface/IActivatable.java @@ -1,9 +1,26 @@ package WayofTime.bloodmagic.iface; +import WayofTime.bloodmagic.util.Constants; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import javax.annotation.Nonnull; public interface IActivatable { - boolean getActivated(ItemStack stack); - ItemStack setActivatedState(ItemStack stack, boolean activated); + default boolean getActivated(ItemStack stack) { + return !stack.isEmpty() && stack.hasTagCompound() && stack.getTagCompound().getBoolean(Constants.NBT.ACTIVATED); + } + + @Nonnull + default ItemStack setActivatedState(ItemStack stack, boolean activated) { + if (!stack.isEmpty()) { + if (!stack.hasTagCompound()) + stack.setTagCompound(new NBTTagCompound()); + + stack.getTagCompound().setBoolean(Constants.NBT.ACTIVATED, activated); + } + + return stack; + } } diff --git a/src/main/java/WayofTime/bloodmagic/iface/IBindable.java b/src/main/java/WayofTime/bloodmagic/iface/IBindable.java index 164d77ff..cc2dad03 100644 --- a/src/main/java/WayofTime/bloodmagic/iface/IBindable.java +++ b/src/main/java/WayofTime/bloodmagic/iface/IBindable.java @@ -1,37 +1,28 @@ package WayofTime.bloodmagic.iface; -import WayofTime.bloodmagic.util.Constants; +import WayofTime.bloodmagic.core.data.Binding; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import javax.annotation.Nullable; + /** * Implement this interface on any Item that can be bound to a player. */ public interface IBindable { /** - * Gets the username of the Item's owner. Usually for display, such as in - * the tooltip. + * Gets an object that stores who this item is bound to. *

* If the item is not bound, this will be null. * * @param stack - The owned ItemStack - * @return - The username of the Item's owner + * @return - The binding object */ - default String getOwnerName(ItemStack stack) { - return !stack.isEmpty() && stack.hasTagCompound() ? stack.getTagCompound().getString(Constants.NBT.OWNER_NAME) : null; - } - - /** - * Gets the UUID of the Item's owner. - *

- * If the item is not bound, this will be null. - * - * @param stack - The owned ItemStack - * @return - The UUID of the Item's owner - */ - default String getOwnerUUID(ItemStack stack) { - return !stack.isEmpty() && stack.hasTagCompound() ? stack.getTagCompound().getString(Constants.NBT.OWNER_UUID) : null; + @Nullable + default Binding getBinding(ItemStack stack) { + Binding binding = Binding.fromStack(stack); + return !stack.isEmpty() && binding != null ? binding : null; } /** diff --git a/src/main/java/WayofTime/bloodmagic/item/ItemActivationCrystal.java b/src/main/java/WayofTime/bloodmagic/item/ItemActivationCrystal.java index dfb40d9d..65c0c354 100644 --- a/src/main/java/WayofTime/bloodmagic/item/ItemActivationCrystal.java +++ b/src/main/java/WayofTime/bloodmagic/item/ItemActivationCrystal.java @@ -1,12 +1,11 @@ package WayofTime.bloodmagic.item; import WayofTime.bloodmagic.BloodMagic; +import WayofTime.bloodmagic.core.data.Binding; import WayofTime.bloodmagic.iface.IBindable; -import WayofTime.bloodmagic.util.helper.PlayerHelper; import WayofTime.bloodmagic.core.RegistrarBloodMagicItems; import WayofTime.bloodmagic.item.types.ISubItem; import WayofTime.bloodmagic.util.helper.TextHelper; -import com.google.common.base.Strings; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.item.ItemStack; import net.minecraft.world.World; @@ -34,8 +33,9 @@ public class ItemActivationCrystal extends ItemEnum.Variant implemen if (!stack.hasTagCompound()) return; - if (!Strings.isNullOrEmpty(getOwnerUUID(stack))) - tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", PlayerHelper.getUsernameFromStack(stack))); + Binding binding = getBinding(stack); + if (binding != null) + tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", binding.getOwnerName())); } } diff --git a/src/main/java/WayofTime/bloodmagic/item/ItemLavaCrystal.java b/src/main/java/WayofTime/bloodmagic/item/ItemLavaCrystal.java index 2e2d6d21..ddb05494 100644 --- a/src/main/java/WayofTime/bloodmagic/item/ItemLavaCrystal.java +++ b/src/main/java/WayofTime/bloodmagic/item/ItemLavaCrystal.java @@ -1,6 +1,7 @@ package WayofTime.bloodmagic.item; import WayofTime.bloodmagic.BloodMagic; +import WayofTime.bloodmagic.core.data.Binding; import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.util.helper.NetworkHelper; import WayofTime.bloodmagic.util.helper.PlayerHelper; @@ -13,39 +14,42 @@ import net.minecraft.item.ItemStack; import net.minecraft.potion.PotionEffect; import org.apache.commons.lang3.tuple.Pair; +import javax.annotation.Nullable; import java.util.List; public class ItemLavaCrystal extends ItemBindableBase implements IVariantProvider { + public ItemLavaCrystal() { super(); setUnlocalizedName(BloodMagic.MODID + ".lavaCrystal"); } @Override - public ItemStack getContainerItem(ItemStack itemStack) { - String uuid = getOwnerUUID(itemStack); - if (!Strings.isNullOrEmpty(uuid)) - NetworkHelper.getSoulNetwork(uuid).syphon(25); + public ItemStack getContainerItem(ItemStack stack) { + Binding binding = getBinding(stack); + if (binding != null) + NetworkHelper.getSoulNetwork(binding.getOwnerId()).syphon(25); ItemStack returnStack = new ItemStack(this); - returnStack.setTagCompound(itemStack.getTagCompound()); + returnStack.setTagCompound(stack.getTagCompound()); return returnStack; } @Override - public boolean hasContainerItem(ItemStack itemStack) { + public boolean hasContainerItem(ItemStack stack) { return true; } @Override public int getItemBurnTime(ItemStack stack) { - if (Strings.isNullOrEmpty(getOwnerUUID(stack))) + Binding binding = getBinding(stack); + if (binding == null) return -1; if (NetworkHelper.canSyphonFromContainer(stack, 25)) return 200; else { - EntityPlayer player = PlayerHelper.getPlayerFromUUID(getOwnerUUID(stack)); + EntityPlayer player = PlayerHelper.getPlayerFromUUID(binding.getOwnerId()); if (player != null) player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 99)); } @@ -53,14 +57,10 @@ public class ItemLavaCrystal extends ItemBindableBase implements IVariantProvide return -1; } + @Nullable @Override - public String getOwnerName(ItemStack stack) { - return stack.hasTagCompound() ? stack.getTagCompound().getString(Constants.NBT.OWNER_NAME) : null; - } - - @Override - public String getOwnerUUID(ItemStack stack) { - return stack.hasTagCompound() ? stack.getTagCompound().getString(Constants.NBT.OWNER_UUID) : null; + public Binding getBinding(ItemStack stack) { + return Binding.fromStack(stack); } @Override diff --git a/src/main/java/WayofTime/bloodmagic/item/ItemSigilToggleable.java b/src/main/java/WayofTime/bloodmagic/item/ItemSigilToggleable.java index c340021c..9b9bbe27 100644 --- a/src/main/java/WayofTime/bloodmagic/item/ItemSigilToggleable.java +++ b/src/main/java/WayofTime/bloodmagic/item/ItemSigilToggleable.java @@ -1,12 +1,12 @@ package WayofTime.bloodmagic.item; +import WayofTime.bloodmagic.core.data.Binding; import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.iface.IActivatable; import WayofTime.bloodmagic.iface.ISigil; import WayofTime.bloodmagic.util.helper.NBTHelper; import WayofTime.bloodmagic.util.helper.NetworkHelper; import WayofTime.bloodmagic.util.helper.PlayerHelper; -import com.google.common.base.Strings; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -22,6 +22,7 @@ import net.minecraft.world.World; * Base class for all toggleable sigils. */ public class ItemSigilToggleable extends ItemSigil implements IActivatable { + public ItemSigilToggleable(int lpUsed) { super(lpUsed); } @@ -64,10 +65,12 @@ public class ItemSigilToggleable extends ItemSigil implements IActivatable { ItemStack stack = player.getHeldItem(hand); if (stack.getItem() instanceof ISigil.Holding) stack = ((Holding) stack.getItem()).getHeldItem(stack, player); - if (Strings.isNullOrEmpty(getOwnerUUID(stack)) || player.isSneaking()) // Make sure Sigils are bound before handling. Also ignores while toggling state + + Binding binding = getBinding(stack); + if (binding == null || player.isSneaking()) // Make sure Sigils are bound before handling. Also ignores while toggling state return EnumActionResult.PASS; - return (NetworkHelper.getSoulNetwork(getOwnerUUID(player.getHeldItem(hand))).syphonAndDamage(player, getLpUsed()) && onSigilUse(player.getHeldItem(hand), player, world, pos, side, hitX, hitY, hitZ)) ? EnumActionResult.SUCCESS : EnumActionResult.FAIL; + return (NetworkHelper.getSoulNetwork(binding).syphonAndDamage(player, getLpUsed()) && onSigilUse(player.getHeldItem(hand), player, world, pos, side, hitX, hitY, hitZ)) ? EnumActionResult.SUCCESS : EnumActionResult.FAIL; } public boolean onSigilUse(ItemStack itemStack, EntityPlayer player, World world, BlockPos blockPos, EnumFacing side, float hitX, float hitY, float hitZ) { @@ -78,7 +81,7 @@ public class ItemSigilToggleable extends ItemSigil implements IActivatable { public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { if (!worldIn.isRemote && entityIn instanceof EntityPlayerMP && getActivated(stack)) { if (entityIn.ticksExisted % 100 == 0) { - if (!NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage((EntityPlayer) entityIn, getLpUsed())) { + if (!NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage((EntityPlayer) entityIn, getLpUsed())) { setActivatedState(stack, false); } } diff --git a/src/main/java/WayofTime/bloodmagic/item/ItemTelepositionFocus.java b/src/main/java/WayofTime/bloodmagic/item/ItemTelepositionFocus.java index b12011d1..2d645ba2 100644 --- a/src/main/java/WayofTime/bloodmagic/item/ItemTelepositionFocus.java +++ b/src/main/java/WayofTime/bloodmagic/item/ItemTelepositionFocus.java @@ -1,5 +1,6 @@ package WayofTime.bloodmagic.item; +import WayofTime.bloodmagic.core.data.Binding; import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.iface.IBindable; import WayofTime.bloodmagic.util.helper.NBTHelper; @@ -51,11 +52,13 @@ public class ItemTelepositionFocus extends ItemEnum.Variant 0) return super.onItemRightClick(world, player, hand); + SoulNetwork network = NetworkHelper.getSoulNetwork(getBinding(stack)); if (mop != null && mop.typeOfHit == RayTraceResult.Type.BLOCK) { BlockPos blockPos = mop.getBlockPos().offset(mop.sideHit); if (world.isAirBlock(blockPos)) { world.setBlockState(blockPos, RegistrarBloodMagicBlocks.BLOOD_LIGHT.getDefaultState()); if (!world.isRemote) - NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed()); + network.syphonAndDamage(player, getLpUsed()); resetCooldown(stack); player.swingArm(hand); return super.onItemRightClick(world, player, hand); @@ -55,7 +57,7 @@ public class ItemSigilBloodLight extends ItemSigilBase { } else { if (!world.isRemote) { world.spawnEntity(new EntityBloodLight(world, player)); - NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed()); + network.syphonAndDamage(player, getLpUsed()); } resetCooldown(stack); } diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilDivination.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilDivination.java index 0447c242..a9a4b26f 100644 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilDivination.java +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilDivination.java @@ -1,21 +1,21 @@ package WayofTime.bloodmagic.item.sigil; +import WayofTime.bloodmagic.core.data.Binding; import WayofTime.bloodmagic.iface.IAltarReader; import WayofTime.bloodmagic.iface.ISigil; import WayofTime.bloodmagic.util.helper.NetworkHelper; import WayofTime.bloodmagic.util.helper.PlayerHelper; import WayofTime.bloodmagic.util.ChatUtil; +import com.google.common.collect.Lists; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; -import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; -import java.util.ArrayList; import java.util.List; public class ItemSigilDivination extends ItemSigilBase implements IAltarReader { @@ -35,13 +35,12 @@ public class ItemSigilDivination extends ItemSigilBase implements IAltarReader { if (!world.isRemote) { super.onItemRightClick(world, player, hand); - RayTraceResult rayTrace = rayTrace(world, player, false); - - if (rayTrace == null) { - int currentEssence = NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).getCurrentEssence(); - List toSend = new ArrayList(); - if (!getOwnerName(stack).equals(PlayerHelper.getUsernameFromPlayer(player))) - toSend.add(new TextComponentTranslation(tooltipBase + "otherNetwork", getOwnerName(stack))); + Binding binding = getBinding(stack); + if (binding != null) { + int currentEssence = NetworkHelper.getSoulNetwork(binding).getCurrentEssence(); + List toSend = Lists.newArrayList(); + if (!binding.getOwnerId().equals(player.getGameProfile().getId())) + toSend.add(new TextComponentTranslation(tooltipBase + "otherNetwork", binding.getOwnerName())); toSend.add(new TextComponentTranslation(tooltipBase + "currentEssence", currentEssence)); ChatUtil.sendNoSpam(player, toSend.toArray(new ITextComponent[toSend.size()])); } diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilHolding.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilHolding.java index d6f77a58..32fa6957 100644 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilHolding.java +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilHolding.java @@ -11,7 +11,6 @@ import WayofTime.bloodmagic.client.key.IKeybindable; import WayofTime.bloodmagic.client.key.KeyBindings; import WayofTime.bloodmagic.util.Utils; import WayofTime.bloodmagic.util.helper.TextHelper; -import com.google.common.base.Strings; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; @@ -90,7 +89,7 @@ public class ItemSigilHolding extends ItemSigilBase implements IKeybindable, IAl List inv = getInternalInventory(stack); ItemStack itemUsing = inv.get(currentSlot); - if (itemUsing.isEmpty() || Strings.isNullOrEmpty(((IBindable) itemUsing.getItem()).getOwnerUUID(itemUsing))) + if (itemUsing.isEmpty() || ((IBindable) itemUsing.getItem()).getBinding(stack) == null) return EnumActionResult.PASS; EnumActionResult result = itemUsing.getItem().onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ); @@ -109,7 +108,7 @@ public class ItemSigilHolding extends ItemSigilBase implements IKeybindable, IAl List inv = getInternalInventory(stack); ItemStack itemUsing = inv.get(currentSlot); - if (itemUsing.isEmpty() || Strings.isNullOrEmpty(((IBindable) itemUsing.getItem()).getOwnerUUID(itemUsing))) + if (itemUsing.isEmpty() || ((IBindable) itemUsing.getItem()).getBinding(stack) == null) return ActionResult.newResult(EnumActionResult.PASS, stack); itemUsing.getItem().onItemRightClick(world, player, hand); diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilLava.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilLava.java index 3a70741c..b02e3f3c 100644 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilLava.java +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilLava.java @@ -59,7 +59,7 @@ public class ItemSigilLava extends ItemSigilBase { return super.onItemRightClick(world, player, hand); } - if (this.canPlaceLava(world, blockpos1) && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed()) && this.tryPlaceLava(world, blockpos1)) { + if (this.canPlaceLava(world, blockpos1) && NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage(player, getLpUsed()) && this.tryPlaceLava(world, blockpos1)) { return super.onItemRightClick(world, player, hand); } } @@ -85,7 +85,7 @@ public class ItemSigilLava extends ItemSigilBase { FluidStack fluid = new FluidStack(FluidRegistry.LAVA, 1000); int amount = handler.fill(fluid, false); - if (amount > 0 && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed())) { + if (amount > 0 && NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage(player, getLpUsed())) { handler.fill(fluid, true); return EnumActionResult.SUCCESS; } diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilTeleposition.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilTeleposition.java index 38535e96..4a9566da 100644 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilTeleposition.java +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilTeleposition.java @@ -55,7 +55,7 @@ public class ItemSigilTeleposition extends ItemSigilBase { if (!world.isRemote && NBTHelper.checkNBT(stack) != null && stack.getTagCompound().hasKey(Constants.NBT.DIMENSION_ID) && stack.getTagCompound().hasKey(Constants.NBT.X_COORD) && stack.getTagCompound().hasKey(Constants.NBT.Y_COORD) && stack.getTagCompound().hasKey(Constants.NBT.Z_COORD)) { BlockPos blockPos = new BlockPos(getValue(stack.getTagCompound(), Constants.NBT.X_COORD), getValue(stack.getTagCompound(), Constants.NBT.Y_COORD), getValue(stack.getTagCompound(), Constants.NBT.Z_COORD)).up(); if (world.provider.getDimension() == getValue(stack.getTagCompound(), Constants.NBT.DIMENSION_ID)) { - TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(blockPos, player, getOwnerUUID(stack), true)); + TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(blockPos, player, getBinding(stack).getOwnerId(), true)); } // FIXME - Fix cross-dimension teleports causing major desync // } else { diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilToggleableBase.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilToggleableBase.java index 1b6b777c..f54bc75b 100644 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilToggleableBase.java +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilToggleableBase.java @@ -1,6 +1,7 @@ package WayofTime.bloodmagic.item.sigil; import WayofTime.bloodmagic.BloodMagic; +import WayofTime.bloodmagic.core.data.Binding; import WayofTime.bloodmagic.item.ItemSigilToggleable; import WayofTime.bloodmagic.util.helper.PlayerHelper; import WayofTime.bloodmagic.client.IMeshProvider; @@ -21,6 +22,7 @@ import java.util.List; import java.util.Locale; public class ItemSigilToggleableBase extends ItemSigilToggleable implements IMeshProvider { + protected final String tooltipBase; private final String name; @@ -40,10 +42,12 @@ public class ItemSigilToggleableBase extends ItemSigilToggleable implements IMes super.addInformation(stack, world, tooltip, flag); if (!stack.hasTagCompound()) return; + tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic." + (getActivated(stack) ? "activated" : "deactivated"))); - if (!Strings.isNullOrEmpty(getOwnerName(stack))) - tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", PlayerHelper.getUsernameFromStack(stack))); + Binding binding = getBinding(stack); + if (binding != null) + tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", binding.getOwnerName())); } @Override diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilTransposition.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilTransposition.java index b150306d..3a00e1fe 100644 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilTransposition.java +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilTransposition.java @@ -99,7 +99,7 @@ public class ItemSigilTransposition extends ItemSigilBase { stack.getTagCompound().setByte(Constants.NBT.CONTAINED_BLOCK_META, metadata); stack.getTagCompound().setTag(Constants.NBT.CONTAINED_TILE_ENTITY, tileNBTTag); - NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, cost); + NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage(player, cost); world.removeTileEntity(blockPos); world.setBlockToAir(blockPos); diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilVoid.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilVoid.java index a4b54fda..a2e20146 100644 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilVoid.java +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilVoid.java @@ -1,5 +1,6 @@ package WayofTime.bloodmagic.item.sigil; +import WayofTime.bloodmagic.core.data.SoulNetwork; import WayofTime.bloodmagic.iface.ISigil; import WayofTime.bloodmagic.util.helper.NetworkHelper; import WayofTime.bloodmagic.util.helper.PlayerHelper; @@ -85,12 +86,13 @@ public class ItemSigilVoid extends ItemSigilBase { return EnumActionResult.FAIL; } + SoulNetwork network = NetworkHelper.getSoulNetwork(getBinding(stack)); TileEntity tile = world.getTileEntity(blockPos); if (tile != null && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) { IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side); FluidStack amount = handler.drain(1000, false); - if (amount != null && amount.amount > 0 && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed())) { + if (amount != null && amount.amount > 0 && network.syphonAndDamage(player, getLpUsed())) { handler.drain(1000, true); return EnumActionResult.SUCCESS; } @@ -104,7 +106,7 @@ public class ItemSigilVoid extends ItemSigilBase { return EnumActionResult.FAIL; } - if (world.getBlockState(newPos).getBlock() instanceof IFluidBlock && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed())) { + if (world.getBlockState(newPos).getBlock() instanceof IFluidBlock && network.syphonAndDamage(player, getLpUsed())) { world.setBlockToAir(newPos); return EnumActionResult.SUCCESS; } diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilWater.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilWater.java index fd73d938..396c2aa5 100644 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilWater.java +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilWater.java @@ -54,7 +54,7 @@ public class ItemSigilWater extends ItemSigilBase { if (!player.canPlayerEdit(blockpos1, rayTrace.sideHit, stack)) return super.onItemRightClick(world, player, hand); - if (this.canPlaceWater(world, blockpos1) && NetworkHelper.getSoulNetwork(getOwnerUUID(stack)).syphonAndDamage(player, getLpUsed()) && this.tryPlaceWater(world, blockpos1)) + if (this.canPlaceWater(world, blockpos1) && NetworkHelper.getSoulNetwork(getBinding(stack)).syphonAndDamage(player, getLpUsed()) && this.tryPlaceWater(world, blockpos1)) return super.onItemRightClick(world, player, hand); } } diff --git a/src/main/java/WayofTime/bloodmagic/orb/BloodOrb.java b/src/main/java/WayofTime/bloodmagic/orb/BloodOrb.java index 2c23d393..6a8b5a1b 100644 --- a/src/main/java/WayofTime/bloodmagic/orb/BloodOrb.java +++ b/src/main/java/WayofTime/bloodmagic/orb/BloodOrb.java @@ -15,6 +15,7 @@ public class BloodOrb extends IForgeRegistryEntry.Impl { private final String name; private final int tier; private final int capacity; + private final int fillRate; @Nullable private ModelResourceLocation modelLocation; @@ -25,11 +26,13 @@ public class BloodOrb extends IForgeRegistryEntry.Impl { * @param name - A name for the Orb. Gets put into an unlocalized name. * @param tier - The tier of the Orb. * @param capacity - The max amount of LP the Orb can store. + * @param fillRate - The amount of LP per tick the Altar can fill the network with. */ - public BloodOrb(String name, int tier, int capacity) { + public BloodOrb(String name, int tier, int capacity, int fillRate) { this.name = name; this.tier = tier; this.capacity = capacity; + this.fillRate = fillRate; } public String getName() { @@ -44,6 +47,10 @@ public class BloodOrb extends IForgeRegistryEntry.Impl { return capacity; } + public int getFillRate() { + return fillRate; + } + @Nullable public ModelResourceLocation getModelLocation() { return modelLocation; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/RitualExpulsion.java b/src/main/java/WayofTime/bloodmagic/ritual/RitualExpulsion.java index d706b79c..ba6a2fa7 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/RitualExpulsion.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/RitualExpulsion.java @@ -1,11 +1,12 @@ package WayofTime.bloodmagic.ritual; import WayofTime.bloodmagic.BloodMagic; +import WayofTime.bloodmagic.core.data.Binding; import WayofTime.bloodmagic.iface.IBindable; import WayofTime.bloodmagic.util.helper.PlayerHelper; import WayofTime.bloodmagic.ritual.data.*; import WayofTime.bloodmagic.util.Utils; -import com.google.common.base.Strings; +import com.google.common.collect.Lists; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -23,6 +24,7 @@ import net.minecraftforge.items.IItemHandler; import java.util.ArrayList; import java.util.List; import java.util.Random; +import java.util.UUID; public class RitualExpulsion extends Ritual { public static final String EXPULSION_RANGE = "expulsionRange"; @@ -48,7 +50,7 @@ public class RitualExpulsion extends Ritual { AreaDescriptor expulsionRange = getBlockRange(EXPULSION_RANGE); - List allowedNames = new ArrayList(); + List whitelist = Lists.newArrayList(); BlockPos masterPos = masterRitualStone.getBlockPos(); TileEntity tile = world.getTileEntity(masterPos.up()); @@ -57,10 +59,10 @@ public class RitualExpulsion extends Ritual { if (handler != null) { for (int i = 0; i < handler.getSlots(); i++) { ItemStack itemStack = handler.getStackInSlot(i); - if (itemStack != null && itemStack.getItem() instanceof IBindable) { - IBindable bindable = (IBindable) itemStack.getItem(); - if (!Strings.isNullOrEmpty(bindable.getOwnerName(itemStack)) && !allowedNames.contains(bindable.getOwnerName(itemStack))) - allowedNames.add(bindable.getOwnerUUID(itemStack)); + if (!itemStack.isEmpty() && itemStack.getItem() instanceof IBindable) { + Binding binding = ((IBindable) itemStack.getItem()).getBinding(itemStack); + if (binding != null && !whitelist.contains(binding.getOwnerId())) + whitelist.add(binding.getOwnerId()); } } } @@ -69,14 +71,14 @@ public class RitualExpulsion extends Ritual { final int teleportDistance = 100; for (EntityPlayer player : world.getEntitiesWithinAABB(EntityPlayer.class, expulsionRange.getAABB(masterRitualStone.getBlockPos()))) { - if (player.capabilities.isCreativeMode || PlayerHelper.getUUIDFromPlayer(player).toString().equals(masterRitualStone.getOwner()) || allowedNames.contains(PlayerHelper.getUUIDFromPlayer(player).toString())) + if (player.capabilities.isCreativeMode || PlayerHelper.getUUIDFromPlayer(player).toString().equals(masterRitualStone.getOwner()) || whitelist.contains(player.getGameProfile().getId())) continue; if (teleportRandomly(player, teleportDistance)) masterRitualStone.getOwnerNetwork().syphon(getRefreshCost() * 1000); } - allowedNames.clear(); + whitelist.clear(); } public boolean teleportRandomly(EntityLivingBase entityLiving, double distance) { @@ -162,20 +164,16 @@ public class RitualExpulsion extends Ritual { } public void moveEntityViaTeleport(EntityLivingBase entityLiving, double x, double y, double z) { - if (entityLiving != null && entityLiving instanceof EntityPlayer) { - if (entityLiving instanceof EntityPlayerMP) { - EntityPlayerMP entityplayermp = (EntityPlayerMP) entityLiving; + if (entityLiving instanceof EntityPlayerMP) { + EntityPlayerMP player = (EntityPlayerMP) entityLiving; - if (entityplayermp.getEntityWorld() == entityLiving.getEntityWorld()) { - EnderTeleportEvent event = new EnderTeleportEvent(entityplayermp, x, y, z, 5.0F); + EnderTeleportEvent event = new EnderTeleportEvent(player, x, y, z, 5.0F); - if (!MinecraftForge.EVENT_BUS.post(event)) { - if (entityLiving.isRiding()) { - entityplayermp.mountEntityAndWakeUp(); - } - entityLiving.setPositionAndUpdate(event.getTargetX(), event.getTargetY(), event.getTargetZ()); - } - } + if (!MinecraftForge.EVENT_BUS.post(event)) { + if (entityLiving.isRiding()) + player.mountEntityAndWakeUp(); + + entityLiving.setPositionAndUpdate(event.getTargetX(), event.getTargetY(), event.getTargetZ()); } } else if (entityLiving != null) { entityLiving.setPosition(x, y, z); diff --git a/src/main/java/WayofTime/bloodmagic/ritual/RitualPortal.java b/src/main/java/WayofTime/bloodmagic/ritual/RitualPortal.java index 0c4503d8..2dd00fe1 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/RitualPortal.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/RitualPortal.java @@ -18,6 +18,7 @@ import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.ForgeRegistries; import java.util.ArrayList; +import java.util.UUID; public class RitualPortal extends Ritual { @@ -31,14 +32,14 @@ public class RitualPortal extends Ritual { } @Override - public boolean activateRitual(IMasterRitualStone masterRitualStone, EntityPlayer player, String owner) { + public boolean activateRitual(IMasterRitualStone masterRitualStone, EntityPlayer player, UUID owner) { World world = masterRitualStone.getWorldObj(); int x = masterRitualStone.getBlockPos().getX(); int y = masterRitualStone.getBlockPos().getY(); int z = masterRitualStone.getBlockPos().getZ(); EnumFacing direction = masterRitualStone.getDirection(); - String name = owner; + String name = owner.toString(); IBlockState blockState; if (!world.isRemote) { diff --git a/src/main/java/WayofTime/bloodmagic/ritual/data/IMasterRitualStone.java b/src/main/java/WayofTime/bloodmagic/ritual/data/IMasterRitualStone.java index 781988fc..320757ef 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/data/IMasterRitualStone.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/data/IMasterRitualStone.java @@ -9,6 +9,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import java.util.List; +import java.util.UUID; /** * This interface is for internal implementation only. @@ -16,7 +17,7 @@ import java.util.List; * It is provided via the API for easy obtaining of basic data. */ public interface IMasterRitualStone { - String getOwner(); + UUID getOwner(); SoulNetwork getOwnerNetwork(); diff --git a/src/main/java/WayofTime/bloodmagic/ritual/data/Ritual.java b/src/main/java/WayofTime/bloodmagic/ritual/data/Ritual.java index d75447ce..b2a4d680 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/data/Ritual.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/data/Ritual.java @@ -14,10 +14,7 @@ import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; import org.apache.commons.lang3.builder.ToStringBuilder; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; /** @@ -100,7 +97,7 @@ public abstract class Ritual { * owner of the ritual if being reactivated. * @return - Whether activation was successful */ - public boolean activateRitual(IMasterRitualStone masterRitualStone, EntityPlayer player, String owner) { + public boolean activateRitual(IMasterRitualStone masterRitualStone, EntityPlayer player, UUID owner) { return true; } diff --git a/src/main/java/WayofTime/bloodmagic/ritual/portal/Teleports.java b/src/main/java/WayofTime/bloodmagic/ritual/portal/Teleports.java index b2571e6d..5e24db13 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/portal/Teleports.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/portal/Teleports.java @@ -20,17 +20,19 @@ import net.minecraft.world.WorldServer; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.FMLCommonHandler; +import java.util.UUID; + public class Teleports { public static class TeleportSameDim extends Teleport { private final boolean teleposer; - public TeleportSameDim(int x, int y, int z, Entity entity, String networkToDrain, boolean teleposer) { - this(new BlockPos(x, y, z), entity, networkToDrain, teleposer); + public TeleportSameDim(int x, int y, int z, Entity entity, UUID networkOwner, boolean teleposer) { + this(new BlockPos(x, y, z), entity, networkOwner, teleposer); } - public TeleportSameDim(BlockPos blockPos, Entity entity, String networkToDrain, boolean teleposer) { - super(blockPos, entity, networkToDrain); + public TeleportSameDim(BlockPos blockPos, Entity entity, UUID networkOwner, boolean teleposer) { + super(blockPos, entity, networkOwner); this.teleposer = teleposer; } @@ -39,7 +41,7 @@ public class Teleports { if (entity != null) { if (entity.timeUntilPortal <= 0) { if (entity instanceof EntityPlayer) { - SoulNetwork network = NetworkHelper.getSoulNetwork(networkToDrain); + SoulNetwork network = NetworkHelper.getSoulNetwork(networkOwner); if (network.getCurrentEssence() < getTeleportCost()) return; @@ -60,7 +62,7 @@ public class Teleports { if (teleposer) MinecraftForge.EVENT_BUS.post(new TeleposeEvent.Ent.Post(entity, entity.getEntityWorld(), entity.getPosition(), entity.getEntityWorld(), new BlockPos(x, y, z))); } else { - SoulNetwork network = NetworkHelper.getSoulNetwork(networkToDrain); + SoulNetwork network = NetworkHelper.getSoulNetwork(networkOwner); if (network.getCurrentEssence() < (getTeleportCost() / 10)) return; @@ -95,12 +97,12 @@ public class Teleports { private int newWorldID; private boolean teleposer; - public TeleportToDim(int x, int y, int z, Entity entity, String networkToDrain, World oldWorld, int newWorld, boolean teleposer) { - this(new BlockPos(x, y, z), entity, networkToDrain, oldWorld, newWorld, teleposer); + public TeleportToDim(int x, int y, int z, Entity entity, UUID networkOwner, World oldWorld, int newWorld, boolean teleposer) { + this(new BlockPos(x, y, z), entity, networkOwner, oldWorld, newWorld, teleposer); } - public TeleportToDim(BlockPos blockPos, Entity entity, String networkToDrain, World oldWorld, int newWorldID, boolean teleposer) { - super(blockPos, entity, networkToDrain); + public TeleportToDim(BlockPos blockPos, Entity entity, UUID networkOwner, World oldWorld, int newWorldID, boolean teleposer) { + super(blockPos, entity, networkOwner); this.oldWorld = oldWorld; this.newWorldID = newWorldID; this.teleposer = teleposer; @@ -118,7 +120,7 @@ public class Teleports { EntityPlayerMP player = (EntityPlayerMP) entity; if (!player.getEntityWorld().isRemote) { - SoulNetwork network = NetworkHelper.getSoulNetwork(networkToDrain); + SoulNetwork network = NetworkHelper.getSoulNetwork(networkOwner); if (network.getCurrentEssence() < getTeleportCost()) return; @@ -138,7 +140,7 @@ public class Teleports { } } else if (!entity.getEntityWorld().isRemote) { - SoulNetwork network = NetworkHelper.getSoulNetwork(networkToDrain); + SoulNetwork network = NetworkHelper.getSoulNetwork(networkOwner); if (network.getCurrentEssence() < (getTeleportCost() / 10)) return; diff --git a/src/main/java/WayofTime/bloodmagic/teleport/Teleport.java b/src/main/java/WayofTime/bloodmagic/teleport/Teleport.java index 18719e16..742b4000 100644 --- a/src/main/java/WayofTime/bloodmagic/teleport/Teleport.java +++ b/src/main/java/WayofTime/bloodmagic/teleport/Teleport.java @@ -3,23 +3,25 @@ package WayofTime.bloodmagic.teleport; import net.minecraft.entity.Entity; import net.minecraft.util.math.BlockPos; +import java.util.UUID; + public abstract class Teleport implements ITeleport { protected int x; protected int y; protected int z; protected Entity entity; - protected String networkToDrain; + protected UUID networkOwner; - public Teleport(int x, int y, int z, Entity entity, String networkToDrain) { + public Teleport(int x, int y, int z, Entity entity, UUID networkOwner) { this.x = x; this.y = y; this.z = z; this.entity = entity; - this.networkToDrain = networkToDrain; + this.networkOwner = networkOwner; } - public Teleport(BlockPos blockPos, Entity entity, String networkToDrain) { - this(blockPos.getX(), blockPos.getY(), blockPos.getZ(), entity, networkToDrain); + public Teleport(BlockPos blockPos, Entity entity, UUID networkOwner) { + this(blockPos.getX(), blockPos.getY(), blockPos.getZ(), entity, networkOwner); } public int getX() { @@ -38,8 +40,8 @@ public abstract class Teleport implements ITeleport { return entity; } - public String getNetworkToDrain() { - return networkToDrain; + public UUID getNetworkOwner() { + return networkOwner; } @Override @@ -53,7 +55,7 @@ public abstract class Teleport implements ITeleport { if (y != teleport.y) return false; if (z != teleport.z) return false; if (entity != null ? !entity.equals(teleport.entity) : teleport.entity != null) return false; - return networkToDrain != null ? networkToDrain.equals(teleport.networkToDrain) : teleport.networkToDrain == null; + return networkOwner != null ? networkOwner.equals(teleport.networkOwner) : teleport.networkOwner == null; } @Override @@ -62,7 +64,7 @@ public abstract class Teleport implements ITeleport { result = 31 * result + y; result = 31 * result + z; result = 31 * result + (entity != null ? entity.hashCode() : 0); - result = 31 * result + (networkToDrain != null ? networkToDrain.hashCode() : 0); + result = 31 * result + (networkOwner != null ? networkOwner.hashCode() : 0); return result; } } diff --git a/src/main/java/WayofTime/bloodmagic/tile/TileMasterRitualStone.java b/src/main/java/WayofTime/bloodmagic/tile/TileMasterRitualStone.java index aaf844d2..9bce3ea8 100644 --- a/src/main/java/WayofTime/bloodmagic/tile/TileMasterRitualStone.java +++ b/src/main/java/WayofTime/bloodmagic/tile/TileMasterRitualStone.java @@ -1,5 +1,7 @@ package WayofTime.bloodmagic.tile; +import WayofTime.bloodmagic.core.data.Binding; +import WayofTime.bloodmagic.iface.IBindable; import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.event.RitualEvent; import WayofTime.bloodmagic.core.registry.RitualRegistry; @@ -7,10 +9,7 @@ import WayofTime.bloodmagic.ritual.data.IMasterRitualStone; import WayofTime.bloodmagic.ritual.data.Ritual; import WayofTime.bloodmagic.core.data.SoulNetwork; import WayofTime.bloodmagic.soul.EnumDemonWillType; -import WayofTime.bloodmagic.util.helper.NBTHelper; -import WayofTime.bloodmagic.util.helper.NetworkHelper; -import WayofTime.bloodmagic.util.helper.PlayerHelper; -import WayofTime.bloodmagic.util.helper.RitualHelper; +import WayofTime.bloodmagic.util.helper.*; import WayofTime.bloodmagic.core.RegistrarBloodMagicItems; import WayofTime.bloodmagic.item.ItemActivationCrystal; import WayofTime.bloodmagic.tile.base.TileTicking; @@ -29,9 +28,10 @@ import net.minecraftforge.fml.common.eventhandler.Event; import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; +import java.util.UUID; public class TileMasterRitualStone extends TileTicking implements IMasterRitualStone { - private String owner; + private UUID owner; private SoulNetwork cachedNetwork; private boolean active; private boolean redstoned; @@ -57,7 +57,7 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS if (!isActive() && !isPowered() && isRedstoned() && getCurrentRitual() != null) { active = true; ItemStack crystalStack = NBTHelper.checkNBT(new ItemStack(RegistrarBloodMagicItems.ACTIVATION_CRYSTAL, 1, getCurrentRitual().getCrystalLevel())); - crystalStack.getTagCompound().setString(Constants.NBT.OWNER_UUID, getOwner()); + BindableHelper.applyBinding(crystalStack, new Binding(owner, PlayerHelper.getUsernameFromUUID(owner))); activateRitual(crystalStack, null, getCurrentRitual()); redstoned = false; } @@ -72,8 +72,8 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS @Override public void deserialize(NBTTagCompound tag) { - owner = tag.getString(Constants.NBT.OWNER_UUID); - if (!Strings.isNullOrEmpty(owner)) + owner = tag.hasUniqueId("owner") ? tag.getUniqueId("owner") : null; + if (owner != null) cachedNetwork = NetworkHelper.getSoulNetwork(owner); currentRitual = RitualRegistry.getRitualForId(tag.getString(Constants.NBT.CURRENT_RITUAL)); if (currentRitual != null) { @@ -97,7 +97,8 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS @Override public NBTTagCompound serialize(NBTTagCompound tag) { String ritualId = RitualRegistry.getIdForRitual(getCurrentRitual()); - tag.setString(Constants.NBT.OWNER_UUID, Strings.isNullOrEmpty(getOwner()) ? "" : getOwner()); + if (owner != null) + tag.setUniqueId(Constants.NBT.OWNER_UUID, owner); tag.setString(Constants.NBT.CURRENT_RITUAL, Strings.isNullOrEmpty(ritualId) ? "" : ritualId); if (currentRitual != null) { NBTTagCompound ritualTag = new NBTTagCompound(); @@ -121,15 +122,13 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS if (PlayerHelper.isFakePlayer(activator)) return false; - activationCrystal = NBTHelper.checkNBT(activationCrystal); - String crystalOwner = activationCrystal.getTagCompound().getString(Constants.NBT.OWNER_UUID); - - if (!Strings.isNullOrEmpty(crystalOwner) && ritual != null) { + Binding binding = ((IBindable) activationCrystal.getItem()).getBinding(activationCrystal); + if (binding != null && ritual != null) { if (activationCrystal.getItem() instanceof ItemActivationCrystal) { int crystalLevel = ((ItemActivationCrystal) activationCrystal.getItem()).getCrystalLevel(activationCrystal); if (RitualHelper.canCrystalActivate(ritual, crystalLevel)) { if (!getWorld().isRemote) { - SoulNetwork network = NetworkHelper.getSoulNetwork(crystalOwner); + SoulNetwork network = NetworkHelper.getSoulNetwork(binding); if (!isRedstoned() && network.getCurrentEssence() < ritual.getActivationCost() && (activator != null && !activator.capabilities.isCreativeMode)) { activator.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.weak"), true); @@ -139,7 +138,7 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS if (currentRitual != null) currentRitual.stopRitual(this, Ritual.BreakType.ACTIVATE); - RitualEvent.RitualActivatedEvent event = new RitualEvent.RitualActivatedEvent(this, crystalOwner, ritual, activator, activationCrystal, crystalLevel); + RitualEvent.RitualActivatedEvent event = new RitualEvent.RitualActivatedEvent(this, binding.getOwnerId(), ritual, activator, activationCrystal, crystalLevel); if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY) { if (activator != null) @@ -147,7 +146,7 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS return false; } - if (ritual.activateRitual(this, activator, crystalOwner)) { + if (ritual.activateRitual(this, activator, binding.getOwnerId())) { if (!isRedstoned() && (activator != null && !activator.capabilities.isCreativeMode)) network.syphon(ritual.getActivationCost()); @@ -155,7 +154,7 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS activator.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.activate"), true); this.active = true; - this.owner = crystalOwner; + this.owner = binding.getOwnerId(); this.cachedNetwork = network; this.currentRitual = ritual; @@ -240,11 +239,11 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS } @Override - public String getOwner() { + public UUID getOwner() { return owner; } - public void setOwner(String owner) { + public void setOwner(UUID owner) { this.owner = owner; } diff --git a/src/main/java/WayofTime/bloodmagic/tile/TileTeleposer.java b/src/main/java/WayofTime/bloodmagic/tile/TileTeleposer.java index f91052d9..416c37f7 100644 --- a/src/main/java/WayofTime/bloodmagic/tile/TileTeleposer.java +++ b/src/main/java/WayofTime/bloodmagic/tile/TileTeleposer.java @@ -1,19 +1,19 @@ package WayofTime.bloodmagic.tile; +import WayofTime.bloodmagic.core.data.Binding; import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.event.TeleposeEvent; import WayofTime.bloodmagic.teleport.TeleportQueue; -import WayofTime.bloodmagic.util.helper.NBTHelper; import WayofTime.bloodmagic.util.helper.NetworkHelper; import WayofTime.bloodmagic.util.helper.PlayerHelper; import WayofTime.bloodmagic.block.BlockTeleposer; import WayofTime.bloodmagic.item.ItemTelepositionFocus; import WayofTime.bloodmagic.ritual.portal.Teleports; import WayofTime.bloodmagic.util.Utils; -import com.google.common.base.Strings; import net.minecraft.entity.Entity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ITickable; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; @@ -59,17 +59,23 @@ public class TileTeleposer extends TileInventory implements ITickable { } public void initiateTeleport() { - if (!getWorld().isRemote && canInitiateTeleport(this) && getBlockType() instanceof BlockTeleposer) { - ItemStack focusStack = NBTHelper.checkNBT(getStackInSlot(0)); + if (!getWorld().isRemote && canInitiateTeleport() && getBlockType() instanceof BlockTeleposer) { + ItemStack focusStack = getStackInSlot(0); ItemTelepositionFocus focus = (ItemTelepositionFocus) focusStack.getItem(); + Binding binding = focus.getBinding(focusStack); + if (binding == null) + return; BlockPos focusPos = focus.getBlockPos(getStackInSlot(0)); World focusWorld = focus.getWorld(getStackInSlot(0)); + if (focusWorld == null) + return; - if (focusWorld != null && focusWorld.getTileEntity(focusPos) instanceof TileTeleposer && !focusWorld.getTileEntity(focusPos).equals(this)) { + TileEntity boundTile = focusWorld.getTileEntity(focusPos); + if (boundTile instanceof TileTeleposer && boundTile != this) { final int focusLevel = (getStackInSlot(0).getItemDamage() + 1); final int lpToBeDrained = (int) (0.5F * Math.sqrt((pos.getX() - focusPos.getX()) * (pos.getX() - focusPos.getX()) + (pos.getY() - focusPos.getY() + 1) * (pos.getY() - focusPos.getY() + 1) + (pos.getZ() - focusPos.getZ()) * (pos.getZ() - focusPos.getZ()))); - if (NetworkHelper.getSoulNetwork(focus.getOwnerUUID(focusStack)).syphonAndDamage(PlayerHelper.getPlayerFromUUID(focus.getOwnerUUID(focusStack)), lpToBeDrained * (focusLevel * 2 - 1) * (focusLevel * 2 - 1) * (focusLevel * 2 - 1))) { + if (NetworkHelper.getSoulNetwork(binding).syphonAndDamage(PlayerHelper.getPlayerFromUUID(binding.getOwnerId()), lpToBeDrained * (focusLevel * 2 - 1) * (focusLevel * 2 - 1) * (focusLevel * 2 - 1))) { int blocksTransported = 0; for (int i = -(focusLevel - 1); i <= (focusLevel - 1); i++) { @@ -95,13 +101,13 @@ public class TileTeleposer extends TileInventory implements ITickable { if (focusWorld.equals(getWorld())) { if (!originalWorldEntities.isEmpty()) { for (Entity entity : originalWorldEntities) { - TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, focusStack.getTagCompound().getString(Constants.NBT.OWNER_UUID), true)); + TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, binding.getOwnerId(), true)); } } if (!focusWorldEntities.isEmpty()) { for (Entity entity : focusWorldEntities) { - TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, focusStack.getTagCompound().getString(Constants.NBT.OWNER_UUID), true)); + TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, binding.getOwnerId(), true)); } } } @@ -124,7 +130,8 @@ public class TileTeleposer extends TileInventory implements ITickable { } } - private boolean canInitiateTeleport(TileTeleposer teleposer) { - return !teleposer.getStackInSlot(0).isEmpty() && teleposer.getStackInSlot(0).getItem() instanceof ItemTelepositionFocus && !Strings.isNullOrEmpty(((ItemTelepositionFocus) teleposer.getStackInSlot(0).getItem()).getOwnerName(teleposer.getStackInSlot(0))); + private boolean canInitiateTeleport() { + ItemStack focusStack = getStackInSlot(0); + return !focusStack.isEmpty() && focusStack.getItem() instanceof ItemTelepositionFocus && ((ItemTelepositionFocus) focusStack.getItem()).getBinding(focusStack) != null; } } diff --git a/src/main/java/WayofTime/bloodmagic/util/handler/event/GenericHandler.java b/src/main/java/WayofTime/bloodmagic/util/handler/event/GenericHandler.java index d9a4d4f2..cd8bebf3 100644 --- a/src/main/java/WayofTime/bloodmagic/util/handler/event/GenericHandler.java +++ b/src/main/java/WayofTime/bloodmagic/util/handler/event/GenericHandler.java @@ -3,6 +3,7 @@ package WayofTime.bloodmagic.util.handler.event; import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.ConfigHandler; import WayofTime.bloodmagic.api.impl.BloodMagicAPI; +import WayofTime.bloodmagic.core.data.Binding; import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.event.ItemBindEvent; import WayofTime.bloodmagic.event.SacrificeKnifeUsedEvent; @@ -53,6 +54,7 @@ import net.minecraft.init.MobEffects; import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.DamageSource; import net.minecraft.util.EnumHand; import net.minecraft.util.EnumParticleTypes; @@ -79,10 +81,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent; import net.minecraftforge.fml.common.registry.EntityEntry; import net.minecraftforge.fml.common.registry.EntityRegistry; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; +import java.util.*; @Mod.EventBusSubscriber(modid = BloodMagic.MODID) public class GenericHandler { @@ -339,25 +338,25 @@ public class GenericHandler { return; ItemStack held = event.getItemStack(); - if (!held.isEmpty() && held.getItem() instanceof IBindable) { - held = NBTHelper.checkNBT(held); + if (!held.isEmpty() && held.getItem() instanceof IBindable) { // Make sure it's bindable IBindable bindable = (IBindable) held.getItem(); - if (Strings.isNullOrEmpty(bindable.getOwnerUUID(held))) { + Binding binding = bindable.getBinding(held); + if (binding == null) { // If the binding is null, let's create one if (bindable.onBind(player, held)) { - String uuid = PlayerHelper.getUUIDFromPlayer(player).toString(); - ItemBindEvent toPost = new ItemBindEvent(player, uuid, held); - if (MinecraftForge.EVENT_BUS.post(toPost) || toPost.getResult() == Result.DENY) + ItemBindEvent toPost = new ItemBindEvent(player, held); + if (MinecraftForge.EVENT_BUS.post(toPost)) // Allow cancellation of binding return; - BindableHelper.setItemOwnerUUID(held, uuid); - BindableHelper.setItemOwnerName(held, player.getDisplayNameString()); + BindableHelper.applyBinding(held, player); // Bind item to the player } - } else if (bindable.getOwnerUUID(held).equals(PlayerHelper.getUUIDFromPlayer(player).toString()) && !bindable.getOwnerName(held).equals(player.getDisplayNameString())) - BindableHelper.setItemOwnerName(held, player.getDisplayNameString()); + // If the binding exists, we'll check if the player's name has changed since they last used it and update that if so. + } else if (binding.getOwnerId().equals(player.getGameProfile().getId()) && !binding.getOwnerName().equals(player.getGameProfile().getName())) { + binding.setOwnerName(player.getGameProfile().getName()); + BindableHelper.applyBinding(held, binding); + } } if (!held.isEmpty() && held.getItem() instanceof IBloodOrb) { - held = NBTHelper.checkNBT(held); IBloodOrb bloodOrb = (IBloodOrb) held.getItem(); SoulNetwork network = NetworkHelper.getSoulNetwork(player); diff --git a/src/main/java/WayofTime/bloodmagic/util/helper/BindableHelper.java b/src/main/java/WayofTime/bloodmagic/util/helper/BindableHelper.java index f74bb848..2606eae9 100644 --- a/src/main/java/WayofTime/bloodmagic/util/helper/BindableHelper.java +++ b/src/main/java/WayofTime/bloodmagic/util/helper/BindableHelper.java @@ -1,17 +1,26 @@ package WayofTime.bloodmagic.util.helper; +import WayofTime.bloodmagic.core.data.Binding; import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.event.ItemBindEvent; -import WayofTime.bloodmagic.iface.IBindable; -import WayofTime.bloodmagic.util.handler.event.GenericHandler; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.entity.player.PlayerInteractEvent; - -import java.util.UUID; +import net.minecraft.nbt.NBTTagCompound; public class BindableHelper { + + public static void applyBinding(ItemStack stack, EntityPlayer player) { + Binding binding = new Binding(player.getGameProfile().getId(), player.getGameProfile().getName()); + applyBinding(stack, binding); + } + + public static void applyBinding(ItemStack stack, Binding binding) { + if (!stack.hasTagCompound()) + stack.setTagCompound(new NBTTagCompound()); + + stack.getTagCompound().setTag("binding", binding.serializeNBT()); + } + /** * Sets the Owner Name of the item without checking if it is already bound. * Also bypasses {@link ItemBindEvent}. @@ -37,113 +46,4 @@ public class BindableHelper { stack.getTagCompound().setString(Constants.NBT.OWNER_UUID, ownerUUID); } - - // Everything below is to be removed. - - /** - * Deprecated. - *

- * Built into {@link IBindable} now. - * - * @param stack - The ItemStack to check the owner of - * @return - The username of the ItemStack's owner - */ - @Deprecated - public static String getOwnerName(ItemStack stack) { - stack = NBTHelper.checkNBT(stack); - - return PlayerHelper.getUsernameFromStack(stack); - } - - /** - * Deprecated. - *

- * Built into {@link IBindable} now. - * - * @param stack - The ItemStack to check the owner of - * @return - The UUID of the ItemStack's owner - */ - @Deprecated - public static String getOwnerUUID(ItemStack stack) { - stack = NBTHelper.checkNBT(stack); - - return stack.getTagCompound().getString(Constants.NBT.OWNER_UUID); - } - - /** - * Deprecated. - *

- * Now handled automatically with - * {@link GenericHandler#onInteract(PlayerInteractEvent.RightClickItem)} - * - * @param stack - The ItemStack to bind - * @param player - The Player to bind the ItemStack to - * @return - Whether binding was successful - */ - @Deprecated - public static boolean checkAndSetItemOwner(ItemStack stack, EntityPlayer player) { - return !PlayerHelper.isFakePlayer(player) && checkAndSetItemOwner(stack, PlayerHelper.getUUIDFromPlayer(player), player.getName()); - } - - /** - * Deprecated. - *

- * Now handled automatically with - * {@link GenericHandler#onInteract(PlayerInteractEvent.RightClickItem)} - * - * @param stack - The ItemStack to bind - * @param uuid - The username to bind the ItemStack to - * @param currentUsername - The current name of the player. - * @return - Whether the binding was successful - */ - @Deprecated - public static boolean checkAndSetItemOwner(ItemStack stack, String uuid, String currentUsername) { - stack = NBTHelper.checkNBT(stack); - - if (!(stack.getItem() instanceof IBindable)) - return false; - - String currentOwner = stack.getTagCompound().getString(Constants.NBT.OWNER_UUID); - - if (currentOwner == "") //The player has not been set yet, so set everything. - { - MinecraftForge.EVENT_BUS.post(new ItemBindEvent(PlayerHelper.getPlayerFromUUID(uuid), uuid, stack)); - ((IBindable) stack.getItem()).onBind(PlayerHelper.getPlayerFromUUID(uuid), stack); - stack.getTagCompound().setString(Constants.NBT.OWNER_UUID, uuid); - stack.getTagCompound().setString(Constants.NBT.OWNER_NAME, currentUsername); - return true; - } else if (currentOwner.equals(uuid)) //The player has been set, so this will simply update the display name - { - stack.getTagCompound().setString(Constants.NBT.OWNER_NAME, currentUsername); - } - - return true; - } - - /** - * Deprecated. - *

- * Now handled automatically with - * {@link GenericHandler#onInteract(PlayerInteractEvent.RightClickItem)} - * - * @param stack - ItemStack to check - * @param uuid - UUID of the Player - * @param currentUsername - The current name of the player. - */ - @Deprecated - public static boolean checkAndSetItemOwner(ItemStack stack, UUID uuid, String currentUsername) { - return checkAndSetItemOwner(stack, uuid.toString(), currentUsername); - } - - /** - * Deprecated. - * - * @param stack - The ItemStack to bind - * @param ownerName - The username to bind the ItemStack to - * @see #setItemOwnerName(ItemStack, String) - */ - @Deprecated - public static void setItemOwner(ItemStack stack, String ownerName) { - setItemOwnerName(stack, ownerName); - } } diff --git a/src/main/java/WayofTime/bloodmagic/util/helper/NetworkHelper.java b/src/main/java/WayofTime/bloodmagic/util/helper/NetworkHelper.java index 81f9dabe..1b3a4bda 100644 --- a/src/main/java/WayofTime/bloodmagic/util/helper/NetworkHelper.java +++ b/src/main/java/WayofTime/bloodmagic/util/helper/NetworkHelper.java @@ -1,5 +1,7 @@ package WayofTime.bloodmagic.util.helper; +import WayofTime.bloodmagic.core.data.Binding; +import WayofTime.bloodmagic.iface.IBindable; import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.event.SoulNetworkEvent; import WayofTime.bloodmagic.orb.BloodOrb; @@ -57,6 +59,10 @@ public class NetworkHelper { return getSoulNetwork(PlayerHelper.getUUIDFromPlayer(player)); } + public static SoulNetwork getSoulNetwork(Binding binding) { + return getSoulNetwork(binding.getOwnerId()); + } + /** * Gets the current orb tier of the SoulNetwork. * @@ -99,7 +105,7 @@ public class NetworkHelper { @Deprecated public static boolean syphonAndDamage(SoulNetwork soulNetwork, EntityPlayer user, int toSyphon) { -// if (soulNetwork.getPlayer() == null) +// if (soulNetwork.getNewOwner() == null) // { // soulNetwork.syphon(toSyphon); // return true; @@ -117,15 +123,16 @@ public class NetworkHelper { */ public static boolean syphonFromContainer(ItemStack stack, int toSyphon) //TODO: Change to a String, int? { - stack = NBTHelper.checkNBT(stack); - String ownerName = stack.getTagCompound().getString(Constants.NBT.OWNER_UUID); - - if (Strings.isNullOrEmpty(ownerName)) + if (!(stack.getItem() instanceof IBindable)) return false; - SoulNetwork network = getSoulNetwork(ownerName); + Binding binding = ((IBindable) stack.getItem()).getBinding(stack); + if (binding == null) + return false; - SoulNetworkEvent.ItemDrainInContainerEvent event = new SoulNetworkEvent.ItemDrainInContainerEvent(stack, ownerName, toSyphon); + SoulNetwork network = getSoulNetwork(binding); + + SoulNetworkEvent.ItemDrainInContainerEvent event = new SoulNetworkEvent.ItemDrainInContainerEvent(stack, binding.getOwnerId(), toSyphon); return !(MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY) && network.syphon(event.syphon) >= toSyphon; } @@ -138,13 +145,14 @@ public class NetworkHelper { * @return - If syphoning is possible */ public static boolean canSyphonFromContainer(ItemStack stack, int toSyphon) { - stack = NBTHelper.checkNBT(stack); - String ownerName = stack.getTagCompound().getString(Constants.NBT.OWNER_UUID); - - if (Strings.isNullOrEmpty(ownerName)) + if (!(stack.getItem() instanceof IBindable)) return false; - SoulNetwork network = getSoulNetwork(ownerName); + Binding binding = ((IBindable) stack.getItem()).getBinding(stack); + if (binding == null) + return false; + + SoulNetwork network = getSoulNetwork(binding); return network.getCurrentEssence() >= toSyphon; } diff --git a/src/main/java/WayofTime/bloodmagic/util/helper/PlayerHelper.java b/src/main/java/WayofTime/bloodmagic/util/helper/PlayerHelper.java index 2354b3e1..601a9240 100644 --- a/src/main/java/WayofTime/bloodmagic/util/helper/PlayerHelper.java +++ b/src/main/java/WayofTime/bloodmagic/util/helper/PlayerHelper.java @@ -1,12 +1,7 @@ package WayofTime.bloodmagic.util.helper; -import WayofTime.bloodmagic.util.Constants; -import com.google.common.base.Strings; import com.google.common.collect.Lists; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.MobEffects; -import net.minecraft.item.ItemStack; -import net.minecraft.potion.PotionEffect; import net.minecraftforge.common.UsernameCache; import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.fml.common.FMLCommonHandler; @@ -23,43 +18,25 @@ public class PlayerHelper { */ private static final ArrayList knownFakePlayers = Lists.newArrayList(); - public static String getUsernameFromPlayer(EntityPlayer player) { - return player.getEntityWorld().isRemote ? "" : UsernameCache.getLastKnownUsername(getUUIDFromPlayer(player)); - } - - public static EntityPlayer getPlayerFromUsername(String username) { + public static EntityPlayer getPlayerFromId(UUID uuid) { if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) return null; - return FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUsername(username); - } - - public static EntityPlayer getPlayerFromUUID(String uuid) { - return getPlayerFromUsername(getUsernameFromUUID(uuid)); + return FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUUID(uuid); } public static EntityPlayer getPlayerFromUUID(UUID uuid) { - return getPlayerFromUsername(getUsernameFromUUID(uuid)); + return getPlayerFromId(uuid); } public static UUID getUUIDFromPlayer(EntityPlayer player) { return player.getGameProfile().getId(); } - public static String getUsernameFromUUID(String uuid) { - return UsernameCache.getLastKnownUsername(UUID.fromString(uuid)); - } - public static String getUsernameFromUUID(UUID uuid) { return UsernameCache.getLastKnownUsername(uuid); } - public static String getUsernameFromStack(ItemStack stack) { - stack = NBTHelper.checkNBT(stack); - - return stack.getTagCompound().getString(Constants.NBT.OWNER_NAME); - } - /** * Checks whether or not the given player is an "actual" player * @@ -69,23 +46,4 @@ public class PlayerHelper { public static boolean isFakePlayer(EntityPlayer player) { return player instanceof FakePlayer || (player != null && knownFakePlayers.contains(player.getClass().getCanonicalName())); } - - public static void causeNauseaToPlayer(ItemStack stack) { - if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) - return; - - stack = NBTHelper.checkNBT(stack); - - if (!Strings.isNullOrEmpty(stack.getTagCompound().getString(Constants.NBT.OWNER_UUID))) - causeNauseaToPlayer(stack.getTagCompound().getString(Constants.NBT.OWNER_UUID)); - } - - public static void causeNauseaToPlayer(String ownerName) { - EntityPlayer player = getPlayerFromUsername(ownerName); - - if (player == null) - return; - - player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 80)); - } }