2018-09-13 12:03:28 -04:00
|
|
|
package noppes.npcs;
|
|
|
|
|
|
2023-01-12 21:33:06 -05:00
|
|
|
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
2018-09-13 12:03:28 -04:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
import io.netty.buffer.Unpooled;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
|
|
|
|
import net.minecraft.inventory.Container;
|
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
2022-05-29 04:45:38 -05:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.nbt.NBTTagList;
|
|
|
|
|
import net.minecraft.nbt.NBTTagString;
|
2018-09-13 12:03:28 -04:00
|
|
|
import net.minecraft.server.MinecraftServer;
|
|
|
|
|
import net.minecraft.util.ChatComponentText;
|
|
|
|
|
import net.minecraft.world.WorldServer;
|
|
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
2023-01-12 21:33:06 -05:00
|
|
|
import noppes.npcs.api.entity.IPlayer;
|
|
|
|
|
import noppes.npcs.api.handler.data.IQuestObjective;
|
|
|
|
|
import noppes.npcs.api.item.IItemStack;
|
2023-03-16 23:37:57 -05:00
|
|
|
import noppes.npcs.constants.*;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.containers.ContainerNPCBankInterface;
|
|
|
|
|
import noppes.npcs.containers.ContainerNPCFollower;
|
|
|
|
|
import noppes.npcs.containers.ContainerNPCFollowerHire;
|
2022-02-02 07:18:33 -06:00
|
|
|
import noppes.npcs.controllers.*;
|
2022-05-24 01:07:50 -05:00
|
|
|
import noppes.npcs.controllers.data.*;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.entity.EntityNPCInterface;
|
|
|
|
|
import noppes.npcs.roles.RoleFollower;
|
2023-01-12 21:33:06 -05:00
|
|
|
import noppes.npcs.scripted.NpcAPI;
|
2022-07-13 19:27:27 -05:00
|
|
|
import noppes.npcs.scripted.ScriptSound;
|
2022-01-12 22:59:03 -06:00
|
|
|
import noppes.npcs.scripted.event.DialogEvent;
|
2024-03-06 05:05:16 -05:00
|
|
|
import noppes.npcs.scripted.event.PartyEvent;
|
2022-01-12 20:12:16 -06:00
|
|
|
import noppes.npcs.scripted.event.QuestEvent;
|
2023-01-12 21:33:06 -05:00
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2023-05-11 20:17:16 -05:00
|
|
|
import java.util.*;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
public class NoppesUtilPlayer {
|
|
|
|
|
|
|
|
|
|
public static void changeFollowerState(EntityPlayerMP player, EntityNPCInterface npc) {
|
|
|
|
|
if(npc.advanced.role != EnumRoleType.Follower)
|
|
|
|
|
return;
|
2024-03-02 21:06:42 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
RoleFollower role = (RoleFollower) npc.roleInterface;
|
|
|
|
|
EntityPlayer owner = role.owner;
|
|
|
|
|
if(owner == null || !owner.getCommandSenderName().equals(player.getCommandSenderName()))
|
|
|
|
|
return;
|
2024-03-02 21:06:42 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
role.isFollowing = !role.isFollowing;
|
|
|
|
|
}
|
|
|
|
|
public static void hireFollower(EntityPlayerMP player, EntityNPCInterface npc) {
|
|
|
|
|
if(npc.advanced.role != EnumRoleType.Follower)
|
|
|
|
|
return;
|
|
|
|
|
Container con = player.openContainer;
|
|
|
|
|
if(con == null || !(con instanceof ContainerNPCFollowerHire))
|
|
|
|
|
return;
|
2024-03-02 21:06:42 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
ContainerNPCFollowerHire container = (ContainerNPCFollowerHire) con;
|
|
|
|
|
RoleFollower role = (RoleFollower) npc.roleInterface;
|
|
|
|
|
followerBuy(role, container.currencyMatrix, player, npc);
|
|
|
|
|
}
|
|
|
|
|
public static void extendFollower(EntityPlayerMP player, EntityNPCInterface npc) {
|
|
|
|
|
if(npc.advanced.role != EnumRoleType.Follower)
|
|
|
|
|
return;
|
|
|
|
|
Container con = player.openContainer;
|
|
|
|
|
if(con == null || !(con instanceof ContainerNPCFollower))
|
|
|
|
|
return;
|
2024-03-02 21:06:42 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
ContainerNPCFollower container = (ContainerNPCFollower) con;
|
|
|
|
|
RoleFollower role = (RoleFollower) npc.roleInterface;
|
|
|
|
|
followerBuy(role, container.currencyMatrix, player, npc);
|
|
|
|
|
}
|
|
|
|
|
public static void transport(EntityPlayerMP player, EntityNPCInterface npc, String location){
|
|
|
|
|
TransportLocation loc = TransportController.getInstance().getTransport(location);
|
2023-06-05 19:35:27 -04:00
|
|
|
PlayerTransportData playerdata = PlayerDataController.Instance.getPlayerData(player).transportData;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
if(loc == null || !loc.isDefault() && !playerdata.transports.contains(loc.id))
|
|
|
|
|
return;
|
2024-03-02 21:06:42 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
teleportPlayer(player, loc.posX, loc.posY, loc.posZ, loc.dimension);
|
|
|
|
|
}
|
2024-03-02 21:06:42 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
public static void teleportPlayer(EntityPlayerMP player, double posX, double posY, double posZ, int dimension){
|
|
|
|
|
if(player.dimension != dimension){
|
|
|
|
|
int dim = player.dimension;
|
|
|
|
|
MinecraftServer server = MinecraftServer.getServer();
|
|
|
|
|
WorldServer wor = server.worldServerForDimension(dimension);
|
|
|
|
|
if(wor == null){
|
2023-02-28 03:32:35 -05:00
|
|
|
player.addChatMessage(new ChatComponentText("Broken transporter. Dimension does not exist"));
|
2018-09-13 12:03:28 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
player.setLocationAndAngles(posX, posY, posZ, player.rotationYaw, player.rotationPitch);
|
|
|
|
|
server.getConfigurationManager().transferPlayerToDimension(player, dimension, new CustomTeleporter(wor));
|
|
|
|
|
player.playerNetServerHandler.setPlayerLocation(posX, posY, posZ, player.rotationYaw, player.rotationPitch);
|
|
|
|
|
|
|
|
|
|
if(!wor.playerEntities.contains(player))
|
|
|
|
|
wor.spawnEntityInWorld(player);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
player.playerNetServerHandler.setPlayerLocation(posX, posY, posZ, player.rotationYaw, player.rotationPitch);
|
|
|
|
|
}
|
|
|
|
|
player.worldObj.updateEntityWithOptionalForce(player, false);
|
|
|
|
|
}
|
2021-10-24 23:33:22 -05:00
|
|
|
|
|
|
|
|
public static void teleportPlayer(EntityPlayerMP player, double posX, double posY, double posZ, float yaw, float pitch, int dimension){
|
|
|
|
|
if(player.dimension != dimension){
|
|
|
|
|
int dim = player.dimension;
|
|
|
|
|
MinecraftServer server = MinecraftServer.getServer();
|
|
|
|
|
WorldServer wor = server.worldServerForDimension(dimension);
|
|
|
|
|
if(wor == null){
|
|
|
|
|
player.addChatMessage(new ChatComponentText("Broken transporter. Dimenion does not exist"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
player.setLocationAndAngles(posX, posY, posZ, yaw, pitch);
|
|
|
|
|
server.getConfigurationManager().transferPlayerToDimension(player, dimension, new CustomTeleporter(wor));
|
|
|
|
|
player.playerNetServerHandler.setPlayerLocation(posX, posY, posZ, yaw, pitch);
|
|
|
|
|
|
|
|
|
|
if(!wor.playerEntities.contains(player))
|
|
|
|
|
wor.spawnEntityInWorld(player);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
player.playerNetServerHandler.setPlayerLocation(posX, posY, posZ, yaw, pitch);
|
|
|
|
|
}
|
|
|
|
|
player.worldObj.updateEntityWithOptionalForce(player, false);
|
|
|
|
|
}
|
2022-05-02 01:41:43 -05:00
|
|
|
|
2022-06-13 17:21:02 -05:00
|
|
|
public static void disableMouseInput(EntityPlayerMP player, long time, int... buttonIds) {
|
|
|
|
|
StringBuilder stringedIds = new StringBuilder();
|
|
|
|
|
for (int i = 0; i < buttonIds.length; i++) {
|
|
|
|
|
stringedIds.append(i);
|
|
|
|
|
if (i < buttonIds.length - 1) {
|
|
|
|
|
stringedIds.append(";");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Server.sendData(player, EnumPacketClient.DISABLE_MOUSE_INPUT, time, stringedIds.toString());
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:41:43 -05:00
|
|
|
public static void swingPlayerArm(EntityPlayerMP player){
|
|
|
|
|
Server.sendData(player, EnumPacketClient.SWING_PLAYER_ARM);
|
|
|
|
|
}
|
2024-03-02 21:06:42 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
private static void followerBuy(RoleFollower role,IInventory currencyInv,EntityPlayerMP player, EntityNPCInterface npc){
|
|
|
|
|
ItemStack currency = currencyInv.getStackInSlot(0);
|
|
|
|
|
if(currency == null)
|
|
|
|
|
return;
|
|
|
|
|
HashMap<ItemStack,Integer> cd = new HashMap<ItemStack,Integer>();
|
|
|
|
|
for(int i : role.inventory.items.keySet()){
|
|
|
|
|
ItemStack is = role.inventory.items.get(i);
|
|
|
|
|
if(is == null || is.getItem() != currency.getItem() || is.getHasSubtypes() && is.getItemDamage() != currency.getItemDamage())
|
|
|
|
|
continue;
|
|
|
|
|
int days = 1;
|
|
|
|
|
if(role.rates.containsKey(i))
|
|
|
|
|
days = role.rates.get(i);
|
2024-03-02 21:06:42 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
cd.put(is,days);
|
|
|
|
|
}
|
|
|
|
|
if(cd.size() == 0)
|
|
|
|
|
return;
|
|
|
|
|
int stackSize = currency.stackSize;
|
|
|
|
|
int days = 0;
|
2024-03-02 21:06:42 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
int possibleDays = 0;
|
|
|
|
|
int possibleSize = stackSize;
|
|
|
|
|
while(true){
|
|
|
|
|
for(ItemStack item : cd.keySet()){
|
|
|
|
|
int rDays = cd.get(item);
|
|
|
|
|
int rValue = item.stackSize;
|
|
|
|
|
if(rValue > stackSize)
|
|
|
|
|
continue;
|
|
|
|
|
int newStackSize = stackSize % rValue;
|
|
|
|
|
int size = stackSize - newStackSize;
|
|
|
|
|
int posDays = (size / rValue) * rDays;
|
|
|
|
|
if(possibleDays <= posDays){
|
|
|
|
|
possibleDays = posDays;
|
|
|
|
|
possibleSize = newStackSize;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(stackSize == possibleSize)
|
|
|
|
|
break;
|
|
|
|
|
stackSize = possibleSize;
|
|
|
|
|
days += possibleDays;
|
|
|
|
|
possibleDays = 0;
|
|
|
|
|
}
|
|
|
|
|
if(days == 0)
|
|
|
|
|
return;
|
|
|
|
|
if(stackSize <= 0)
|
|
|
|
|
currencyInv.setInventorySlotContents(0, null);
|
|
|
|
|
else
|
|
|
|
|
currency = currency.splitStack(stackSize);
|
2024-03-02 21:06:42 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
npc.say(player, new Line(NoppesStringUtils.formatText(role.dialogHire.replace("{days}", days+""), player, npc)));
|
|
|
|
|
role.setOwner(player);
|
|
|
|
|
role.addDays(days);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void bankUpgrade(EntityPlayerMP player, EntityNPCInterface npc) {
|
|
|
|
|
if(npc.advanced.role != EnumRoleType.Bank)
|
|
|
|
|
return;
|
|
|
|
|
Container con = player.openContainer;
|
|
|
|
|
if(con == null || !(con instanceof ContainerNPCBankInterface))
|
|
|
|
|
return;
|
2024-03-02 21:06:42 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
ContainerNPCBankInterface container = (ContainerNPCBankInterface) con;
|
|
|
|
|
Bank bank = BankController.getInstance().getBank(container.bankid);
|
|
|
|
|
ItemStack item = bank.upgradeInventory.getStackInSlot(container.slot);
|
|
|
|
|
if(item == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int price = item.stackSize;
|
|
|
|
|
ItemStack currency = container.currencyMatrix.getStackInSlot(0);
|
|
|
|
|
if(currency == null || price > currency.stackSize)
|
|
|
|
|
return;
|
|
|
|
|
if(currency.stackSize - price == 0)
|
|
|
|
|
container.currencyMatrix.setInventorySlotContents(0, null);
|
|
|
|
|
else
|
|
|
|
|
currency = currency.splitStack(price);
|
|
|
|
|
player.closeContainer();
|
2023-06-05 19:35:27 -04:00
|
|
|
PlayerBankData data = PlayerDataController.Instance.getBankData(player,bank.id);
|
2018-09-13 12:03:28 -04:00
|
|
|
BankData bankData = data.getBank(bank.id);
|
|
|
|
|
bankData.upgradedSlots.put(container.slot, true);
|
|
|
|
|
|
|
|
|
|
bankData.openBankGui(player, npc, bank.id, container.slot);
|
|
|
|
|
}
|
|
|
|
|
public static void bankUnlock(EntityPlayerMP player, EntityNPCInterface npc) {
|
|
|
|
|
if(npc.advanced.role != EnumRoleType.Bank)
|
|
|
|
|
return;
|
|
|
|
|
Container con = player.openContainer;
|
|
|
|
|
if(con == null || !(con instanceof ContainerNPCBankInterface))
|
|
|
|
|
return;
|
|
|
|
|
ContainerNPCBankInterface container = (ContainerNPCBankInterface) con;
|
|
|
|
|
Bank bank = BankController.getInstance().getBank(container.bankid);
|
2024-03-02 21:06:42 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
ItemStack item = bank.currencyInventory.getStackInSlot(container.slot);
|
|
|
|
|
if(item == null)
|
|
|
|
|
return;
|
2024-03-02 21:06:42 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
int price = item.stackSize;
|
|
|
|
|
ItemStack currency = container.currencyMatrix.getStackInSlot(0);
|
|
|
|
|
if(currency == null || price > currency.stackSize)
|
|
|
|
|
return;
|
|
|
|
|
if(currency.stackSize - price == 0)
|
|
|
|
|
container.currencyMatrix.setInventorySlotContents(0, null);
|
|
|
|
|
else
|
|
|
|
|
currency = currency.splitStack(price);
|
|
|
|
|
player.closeContainer();
|
2023-06-05 19:35:27 -04:00
|
|
|
PlayerBankData data = PlayerDataController.Instance.getBankData(player,bank.id);
|
2018-09-13 12:03:28 -04:00
|
|
|
BankData bankData = data.getBank(bank.id);
|
|
|
|
|
if(bankData.unlockedSlots + 1 <= bank.maxSlots)
|
|
|
|
|
bankData.unlockedSlots++;
|
2024-03-02 21:06:42 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
bankData.openBankGui(player, npc, bank.id, container.slot);
|
|
|
|
|
}
|
|
|
|
|
public static void sendData(EnumPlayerPacket enu, Object... obs) {
|
|
|
|
|
ByteBuf buffer = Unpooled.buffer();
|
|
|
|
|
try {
|
|
|
|
|
if(!Server.fillBuffer(buffer, enu, obs))
|
|
|
|
|
return;
|
|
|
|
|
CustomNpcs.ChannelPlayer.sendToServer(new FMLProxyPacket(buffer,"CustomNPCsPlayer"));
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void dialogSelected(int dialogId, int optionId, EntityPlayerMP player, EntityNPCInterface npc) {
|
2023-06-05 22:12:48 -04:00
|
|
|
Dialog dialog = DialogController.Instance.dialogs.get(dialogId);
|
2018-09-13 12:03:28 -04:00
|
|
|
if(dialog == null)
|
|
|
|
|
return;
|
|
|
|
|
DialogOption option = dialog.options.get(optionId);
|
2022-11-24 14:36:09 -06:00
|
|
|
if (EventHooks.onDialogOption(new DialogEvent.DialogOption((IPlayer) NpcAPI.Instance().getIEntity(player), dialog)))
|
|
|
|
|
return;
|
|
|
|
|
|
2022-06-10 17:25:58 -05:00
|
|
|
if (!npc.isRemote()) {
|
|
|
|
|
EventHooks.onNPCDialogClosed(npc, player, dialogId, optionId + 1, dialog);
|
|
|
|
|
|
|
|
|
|
if (!dialog.hasDialogs(player) && !dialog.hasOtherOptions()) {
|
|
|
|
|
EventHooks.onDialogClosed(new DialogEvent.DialogClosed((IPlayer) NpcAPI.Instance().getIEntity(player), dialog));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (option == null || option.optionType == EnumOptionType.DialogOption && (!option.isAvailable(player) || !option.hasDialog()) || option.optionType == EnumOptionType.Disabled || option.optionType == EnumOptionType.QuitOption) {
|
|
|
|
|
EventHooks.onDialogClosed(new DialogEvent.DialogClosed((IPlayer) NpcAPI.Instance().getIEntity(player), dialog));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-01-12 22:59:03 -06:00
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
if(option.optionType == EnumOptionType.RoleOption){
|
|
|
|
|
if(npc.roleInterface != null)
|
|
|
|
|
npc.roleInterface.interact(player);
|
|
|
|
|
else
|
|
|
|
|
Server.sendData(player, EnumPacketClient.GUI_CLOSE);
|
|
|
|
|
}
|
|
|
|
|
else if(option.optionType == EnumOptionType.DialogOption){
|
2022-04-09 00:17:16 -05:00
|
|
|
NoppesUtilServer.openDialog(player, npc, option.getDialog(), optionId+1);
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
else if(option.optionType == EnumOptionType.CommandBlock){
|
|
|
|
|
Server.sendData(player, EnumPacketClient.GUI_CLOSE);
|
|
|
|
|
NoppesUtilServer.runCommand(player, npc.getCommandSenderName(), option.command);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
Server.sendData(player, EnumPacketClient.GUI_CLOSE);
|
|
|
|
|
}
|
2023-05-11 20:17:16 -05:00
|
|
|
|
|
|
|
|
public static void updateQuestLogData(ByteBuf buffer, EntityPlayerMP player) throws IOException {
|
2023-06-05 19:35:27 -04:00
|
|
|
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
|
2023-05-11 20:17:16 -05:00
|
|
|
|
|
|
|
|
NBTTagCompound compound = Server.readNBT(buffer);
|
|
|
|
|
HashMap<String,String> questAlerts = NBTTags.getStringStringMap(compound.getTagList("Alerts", 10));
|
|
|
|
|
for (Map.Entry<String,String> entry : questAlerts.entrySet()) {
|
|
|
|
|
Quest quest = getQuestFromStringKey(entry.getKey());
|
|
|
|
|
if (quest != null) {
|
|
|
|
|
playerData.questData.activeQuests.get(quest.id).sendAlerts = Boolean.parseBoolean(entry.getValue());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String trackedQuestString = Server.readString(buffer);
|
|
|
|
|
Quest trackedQuest = getQuestFromStringKey(trackedQuestString);
|
|
|
|
|
if (trackedQuest != null) {
|
|
|
|
|
playerData.questData.trackQuest(trackedQuest);
|
|
|
|
|
} else {
|
|
|
|
|
playerData.questData.untrackQuest();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-15 16:40:43 -04:00
|
|
|
public static void clearTrackQuest(EntityPlayerMP player) throws IOException {
|
|
|
|
|
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
|
|
|
|
|
playerData.questData.untrackQuest();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-03-15 15:43:29 -04:00
|
|
|
public static void updatePartyQuestLogData(ByteBuf buffer, EntityPlayerMP player) throws IOException {
|
|
|
|
|
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
|
|
|
|
|
String trackedQuestString = Server.readString(buffer);
|
|
|
|
|
Quest trackedQuest = getQuestFromStringKey(trackedQuestString);
|
|
|
|
|
if (trackedQuest != null) {
|
|
|
|
|
playerData.questData.trackParty(playerData.getPlayerParty());
|
|
|
|
|
} else {
|
|
|
|
|
playerData.questData.untrackQuest();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-11 20:17:16 -05:00
|
|
|
private static Quest getQuestFromStringKey(String string) {
|
|
|
|
|
if (string != null && string.contains(":")) {
|
|
|
|
|
String[] splitString = string.split(":");
|
2024-03-15 15:43:29 -04:00
|
|
|
|
|
|
|
|
String categoryName;
|
|
|
|
|
String questName;
|
|
|
|
|
if (splitString.length == 3 && splitString[0].equals("P")) {
|
|
|
|
|
categoryName = splitString[1];
|
|
|
|
|
questName = splitString[2];
|
|
|
|
|
} else if (splitString.length < 2) {
|
|
|
|
|
return null;
|
|
|
|
|
} else {
|
|
|
|
|
categoryName = splitString[0];
|
|
|
|
|
questName = splitString[1];
|
|
|
|
|
}
|
2023-05-11 20:17:16 -05:00
|
|
|
|
2023-06-05 22:12:48 -04:00
|
|
|
for (QuestCategory category : QuestController.Instance.categories.values()) {
|
2023-05-11 20:17:16 -05:00
|
|
|
if (category.title.equals(categoryName)) {
|
|
|
|
|
for (Quest quest : category.quests.values()) {
|
|
|
|
|
if (quest.title.equals(questName)) {
|
|
|
|
|
return quest;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-14 19:14:43 -05:00
|
|
|
public static void sendTrackedQuestData(EntityPlayerMP player) {
|
2023-06-05 19:35:27 -04:00
|
|
|
Quest trackedQuest = (Quest) PlayerDataController.Instance.getPlayerData(player).questData.getTrackedQuest();
|
2023-05-15 16:02:44 -04:00
|
|
|
if(trackedQuest != null){
|
|
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
|
|
|
|
compound.setTag("Quest",trackedQuest.writeToNBT(new NBTTagCompound()));
|
|
|
|
|
compound.setString("CategoryName", trackedQuest.getCategory().getName());
|
2023-07-29 02:35:15 -04:00
|
|
|
if(trackedQuest.completion == EnumQuestCompletion.Instant){
|
|
|
|
|
compound.setBoolean("Instant", true);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
compound.setString("TurnInNPC", trackedQuest.getNpcName());
|
|
|
|
|
}
|
2023-05-15 16:02:44 -04:00
|
|
|
NBTTagList nbtTagList = new NBTTagList();
|
|
|
|
|
for (IQuestObjective objective : trackedQuest.questInterface.getObjectives(player)) {
|
|
|
|
|
nbtTagList.appendTag(new NBTTagString(objective.getText()));
|
|
|
|
|
}
|
|
|
|
|
compound.setTag("ObjectiveList",nbtTagList);
|
2022-05-29 04:45:38 -05:00
|
|
|
|
2023-05-15 16:02:44 -04:00
|
|
|
Server.sendData(player, EnumPacketClient.OVERLAY_QUEST_TRACKING, compound);
|
2022-05-29 04:45:38 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-15 15:43:29 -04:00
|
|
|
public static void sendPartyTrackedQuestData(EntityPlayerMP player, Party party) {
|
|
|
|
|
Quest trackedQuest = (Quest) PlayerDataController.Instance.getPlayerData(player).questData.getTrackedQuest();
|
|
|
|
|
if(trackedQuest != null){
|
|
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
|
|
|
|
compound.setTag("Quest",trackedQuest.writeToNBT(new NBTTagCompound()));
|
|
|
|
|
compound.setString("CategoryName", trackedQuest.getCategory().getName());
|
|
|
|
|
if(trackedQuest.completion == EnumQuestCompletion.Instant){
|
|
|
|
|
compound.setBoolean("Instant", true);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
compound.setString("TurnInNPC", trackedQuest.getNpcName());
|
|
|
|
|
}
|
|
|
|
|
NBTTagList nbtTagList = new NBTTagList();
|
|
|
|
|
for (IQuestObjective objective : trackedQuest.questInterface.getPartyObjectives(party)) {
|
|
|
|
|
nbtTagList.appendTag(new NBTTagString(objective.getText()));
|
|
|
|
|
if(objective.getAdditionalText() != null)
|
|
|
|
|
nbtTagList.appendTag(new NBTTagString(objective.getAdditionalText()));
|
|
|
|
|
}
|
|
|
|
|
compound.setTag("ObjectiveList",nbtTagList);
|
|
|
|
|
|
|
|
|
|
Server.sendData(player, EnumPacketClient.OVERLAY_QUEST_TRACKING, compound);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
public static void sendQuestLogData(EntityPlayerMP player) {
|
|
|
|
|
if(!PlayerQuestController.hasActiveQuests(player)){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QuestLogData data = new QuestLogData();
|
|
|
|
|
data.setData(player);
|
|
|
|
|
Server.sendData(player, EnumPacketClient.GUI_DATA, data.writeNBT());
|
|
|
|
|
}
|
2024-03-15 15:43:29 -04:00
|
|
|
|
|
|
|
|
public static void sendTrackedQuest(EntityPlayerMP player) {
|
|
|
|
|
QuestLogData data = new QuestLogData();
|
|
|
|
|
data.setTrackedQuestKey(player);
|
|
|
|
|
Server.sendData(player, EnumPacketClient.PARTY_DATA, data.writeTrackedQuest());
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-16 23:37:57 -05:00
|
|
|
public static boolean questCompletion(EntityPlayerMP player, int questId) {
|
2022-10-02 23:07:12 -04:00
|
|
|
if(player == null)
|
2023-03-16 23:37:57 -05:00
|
|
|
return false;
|
2022-10-02 23:07:12 -04:00
|
|
|
|
2023-06-05 19:35:27 -04:00
|
|
|
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
|
2022-02-02 07:18:33 -06:00
|
|
|
PlayerQuestData questData = playerData.questData;
|
|
|
|
|
QuestData data = questData.activeQuests.get(questId);
|
2022-01-12 20:12:16 -06:00
|
|
|
|
2023-03-16 23:37:57 -05:00
|
|
|
if (data == null)
|
|
|
|
|
return false;
|
2022-01-12 20:12:16 -06:00
|
|
|
|
2023-03-16 23:37:57 -05:00
|
|
|
if (!data.quest.questInterface.isCompleted(playerData))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (data.quest.completion == EnumQuestCompletion.Instant) {
|
|
|
|
|
EventHooks.onQuestFinished(player, data.quest);
|
|
|
|
|
}
|
2022-01-12 20:12:16 -06:00
|
|
|
|
2022-05-11 22:08:31 -05:00
|
|
|
QuestEvent.QuestTurnedInEvent event = new QuestEvent.QuestTurnedInEvent((IPlayer) NpcAPI.Instance().getIEntity(player), data.quest);
|
2022-01-12 20:12:16 -06:00
|
|
|
|
2023-03-16 23:37:57 -05:00
|
|
|
event.expReward = data.quest.rewardExp;
|
2022-01-12 20:12:16 -06:00
|
|
|
List<IItemStack> list = new ArrayList();
|
|
|
|
|
Iterator var8 = data.quest.rewardItems.items.values().iterator();
|
|
|
|
|
|
|
|
|
|
while(var8.hasNext()) {
|
|
|
|
|
ItemStack item = (ItemStack)var8.next();
|
2022-12-19 16:09:18 -06:00
|
|
|
if (item != null && item.stackSize > 0) {
|
2022-10-02 23:07:12 -04:00
|
|
|
IItemStack iStack = NpcAPI.Instance().getIItemStack(item);
|
|
|
|
|
if (iStack != null){
|
|
|
|
|
list.add(iStack);
|
|
|
|
|
}
|
2022-01-12 20:12:16 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!data.quest.randomReward) {
|
|
|
|
|
event.itemRewards = (IItemStack[])list.toArray(new IItemStack[list.size()]);
|
|
|
|
|
} else if (!list.isEmpty()) {
|
|
|
|
|
event.itemRewards = new IItemStack[]{(IItemStack)list.get(player.getRNG().nextInt(list.size()))};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EventHooks.onQuestTurnedIn(event);
|
2023-03-16 23:37:57 -05:00
|
|
|
if (event.isCancelled())
|
|
|
|
|
return false;
|
|
|
|
|
|
2022-01-12 20:12:16 -06:00
|
|
|
IItemStack[] var12 = event.itemRewards;
|
|
|
|
|
int var14 = var12.length;
|
|
|
|
|
for(int var10 = 0; var10 < var14; ++var10) {
|
|
|
|
|
IItemStack item = var12[var10];
|
|
|
|
|
if (item != null) {
|
|
|
|
|
NoppesUtilServer.GivePlayerItem(player, player, item.getMCItemStack());
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
data.quest.questInterface.handleComplete(player);
|
|
|
|
|
if(data.quest.rewardExp > 0){
|
|
|
|
|
player.worldObj.playSoundAtEntity(player, "random.orb", 0.1F, 0.5F * ((player.worldObj.rand.nextFloat() - player.worldObj.rand.nextFloat()) * 0.7F + 1.8F));
|
2022-01-12 20:12:16 -06:00
|
|
|
player.addExperience(data.quest.rewardExp);
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
data.quest.factionOptions.addPoints(player);
|
|
|
|
|
if(data.quest.mail.isValid()){
|
2023-06-05 19:35:27 -04:00
|
|
|
PlayerDataController.Instance.addPlayerMessage(player.getCommandSenderName(), data.quest.mail);
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
2022-01-12 20:12:16 -06:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
if(!data.quest.command.isEmpty()){
|
|
|
|
|
NoppesUtilServer.runCommand(player, "QuestCompletion", data.quest.command);
|
|
|
|
|
}
|
2022-01-12 20:12:16 -06:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
PlayerQuestController.setQuestFinished(data.quest, player);
|
2022-12-19 17:18:28 -06:00
|
|
|
if (data.quest.hasNewQuest()) {
|
2023-03-16 23:37:57 -05:00
|
|
|
QuestData nextQuest = new QuestData(data.quest.getNextQuest());
|
|
|
|
|
nextQuest.sendAlerts = data.quest.id != data.quest.getNextQuest().id || data.sendAlerts;
|
2022-12-19 17:18:28 -06:00
|
|
|
PlayerQuestController.addActiveQuest(nextQuest, player);
|
2023-05-11 20:17:16 -05:00
|
|
|
questData.trackQuest(nextQuest.quest);
|
2022-12-19 17:18:28 -06:00
|
|
|
}
|
2023-03-16 23:37:57 -05:00
|
|
|
|
2023-05-21 02:48:30 -05:00
|
|
|
playerData.save();
|
|
|
|
|
|
2023-03-16 23:37:57 -05:00
|
|
|
return true;
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
2024-03-02 21:06:42 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean questPartyCompletion(Party party) {
|
|
|
|
|
if(party == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
QuestData data = party.getQuestData();
|
|
|
|
|
if (data == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!data.quest.questInterface.isPartyCompleted(party))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Quest quest = data.quest;
|
|
|
|
|
if(quest == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
2024-03-06 05:05:16 -05:00
|
|
|
if (data.quest.completion == EnumQuestCompletion.Instant)
|
|
|
|
|
EventHooks.onPartyFinished(party, data.quest);
|
|
|
|
|
|
|
|
|
|
PartyEvent.PartyQuestTurnedInEvent partyEv = new PartyEvent.PartyQuestTurnedInEvent(party, data.quest);
|
|
|
|
|
EventHooks.onPartyTurnIn(partyEv);
|
|
|
|
|
if (partyEv.isCancelled())
|
|
|
|
|
return false;
|
|
|
|
|
|
2024-03-15 15:43:29 -04:00
|
|
|
boolean hasNextQuest = data.quest.hasNewQuest();
|
2024-03-02 21:06:42 -05:00
|
|
|
PartyOptions partyOptions = quest.partyOptions;
|
|
|
|
|
EnumPartyExchange complete = partyOptions.completeFor;
|
|
|
|
|
EnumPartyExchange reward = partyOptions.rewardControl;
|
2024-03-04 05:15:50 -05:00
|
|
|
EnumPartyExchange command = partyOptions.executeCommand;
|
2024-03-02 21:06:42 -05:00
|
|
|
for(String name : party.getPlayerNames()){
|
|
|
|
|
EntityPlayer player = NoppesUtilServer.getPlayerByName(name);
|
|
|
|
|
if(player == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
|
|
|
|
|
if(playerData == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
boolean isLeader = party.getLeaderUUID().equals(player.getUniqueID());
|
|
|
|
|
boolean hasActiveQuest = playerData.questData.hasActiveQuest(quest.getId());
|
|
|
|
|
boolean hasFinishedQuest = playerData.questData.hasFinishedQuest(quest.getId());
|
|
|
|
|
|
|
|
|
|
boolean meetsComplete = meetsPartyExchange(complete, hasActiveQuest, hasFinishedQuest, isLeader);
|
|
|
|
|
boolean meetsReward = meetsPartyExchange(reward, hasActiveQuest, hasFinishedQuest, isLeader);
|
2024-03-04 05:15:50 -05:00
|
|
|
boolean meetsCommand = meetsPartyExchange(command, hasActiveQuest, hasFinishedQuest, isLeader);
|
2024-03-02 21:06:42 -05:00
|
|
|
|
|
|
|
|
if(meetsComplete){
|
|
|
|
|
if (data.quest.completion == EnumQuestCompletion.Instant) {
|
|
|
|
|
EventHooks.onQuestFinished(player, data.quest);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(meetsReward){
|
|
|
|
|
QuestEvent.QuestTurnedInEvent event = new QuestEvent.QuestTurnedInEvent((IPlayer) NpcAPI.Instance().getIEntity(player), data.quest);
|
|
|
|
|
|
|
|
|
|
event.expReward = data.quest.rewardExp;
|
|
|
|
|
List<IItemStack> list = new ArrayList();
|
|
|
|
|
Iterator var8 = data.quest.rewardItems.items.values().iterator();
|
|
|
|
|
|
|
|
|
|
while(var8.hasNext()) {
|
|
|
|
|
ItemStack item = (ItemStack)var8.next();
|
|
|
|
|
if (item != null && item.stackSize > 0) {
|
|
|
|
|
IItemStack iStack = NpcAPI.Instance().getIItemStack(item);
|
|
|
|
|
if (iStack != null){
|
|
|
|
|
list.add(iStack);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!data.quest.randomReward) {
|
|
|
|
|
event.itemRewards = (IItemStack[])list.toArray(new IItemStack[list.size()]);
|
|
|
|
|
} else if (!list.isEmpty()) {
|
|
|
|
|
event.itemRewards = new IItemStack[]{(IItemStack)list.get(player.getRNG().nextInt(list.size()))};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EventHooks.onQuestTurnedIn(event);
|
|
|
|
|
if (event.isCancelled())
|
2024-03-06 05:05:16 -05:00
|
|
|
continue;
|
2024-03-02 21:06:42 -05:00
|
|
|
|
|
|
|
|
IItemStack[] var12 = event.itemRewards;
|
|
|
|
|
int var14 = var12.length;
|
|
|
|
|
for(int var10 = 0; var10 < var14; ++var10) {
|
|
|
|
|
IItemStack item = var12[var10];
|
|
|
|
|
if (item != null) {
|
|
|
|
|
NoppesUtilServer.GivePlayerItem(player, player, item.getMCItemStack());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-15 19:14:14 -04:00
|
|
|
data.quest.questInterface.handlePartyComplete(player, party, isLeader, partyOptions.objectiveRequirement);
|
2024-03-02 21:06:42 -05:00
|
|
|
if(meetsReward){
|
|
|
|
|
if(data.quest.rewardExp > 0){
|
|
|
|
|
player.worldObj.playSoundAtEntity(player, "random.orb", 0.1F, 0.5F * ((player.worldObj.rand.nextFloat() - player.worldObj.rand.nextFloat()) * 0.7F + 1.8F));
|
|
|
|
|
player.addExperience(data.quest.rewardExp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data.quest.factionOptions.addPoints(player);
|
|
|
|
|
if(data.quest.mail.isValid()){
|
|
|
|
|
PlayerDataController.Instance.addPlayerMessage(player.getCommandSenderName(), data.quest.mail);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-04 05:15:50 -05:00
|
|
|
if(meetsCommand){
|
2024-03-02 21:06:42 -05:00
|
|
|
if(!data.quest.command.isEmpty()){
|
|
|
|
|
NoppesUtilServer.runCommand(player, "QuestCompletion", data.quest.command);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-04 05:15:50 -05:00
|
|
|
if(meetsComplete){
|
|
|
|
|
PlayerQuestController.setQuestPartyFinished(data.quest, player, data);
|
2024-03-15 15:43:29 -04:00
|
|
|
}
|
|
|
|
|
|
2024-03-15 19:14:14 -04:00
|
|
|
if (hasNextQuest && meetsComplete) {
|
|
|
|
|
QuestData nextQuest = new QuestData(data.quest.getNextQuest());
|
|
|
|
|
nextQuest.sendAlerts = data.quest.id != data.quest.getNextQuest().id || data.sendAlerts;
|
|
|
|
|
PlayerQuestController.addActiveQuest(nextQuest, player);
|
2024-03-02 21:06:42 -05:00
|
|
|
}
|
2024-03-04 05:15:50 -05:00
|
|
|
|
2024-03-02 21:06:42 -05:00
|
|
|
playerData.save();
|
2024-03-18 04:23:36 -04:00
|
|
|
Server.sendData((EntityPlayerMP)player, EnumPacketClient.QUEST_COMPLETION, data.quest.writeToNBT(new NBTTagCompound()));
|
2024-03-02 21:06:42 -05:00
|
|
|
}
|
|
|
|
|
|
2024-03-18 04:23:36 -04:00
|
|
|
if(quest.type == EnumQuestType.Item && partyOptions.objectiveRequirement == EnumPartyObjectives.Shared){
|
|
|
|
|
quest.questInterface.removePartyItems(party);
|
|
|
|
|
}
|
2024-03-15 15:43:29 -04:00
|
|
|
|
|
|
|
|
if (hasNextQuest) {
|
|
|
|
|
if(party.validateQuest(data.quest.getNextQuest().getId(), true)){
|
|
|
|
|
party.setQuest(data.quest.getNextQuest());
|
|
|
|
|
for(String name : party.getPlayerNames()) {
|
|
|
|
|
EntityPlayer player = NoppesUtilServer.getPlayerByName(name);
|
|
|
|
|
if (player == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
|
|
|
|
|
if (playerData == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
playerData.questData.trackParty(party);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
party.setQuest(null);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2024-03-07 19:53:04 -05:00
|
|
|
party.setQuest(null);
|
2024-03-15 15:43:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(data.quest.completion == EnumQuestCompletion.Npc){
|
2024-03-07 19:53:04 -05:00
|
|
|
PartyController.Instance().sendQuestChat(party, "party.completeChat");
|
|
|
|
|
PartyController.Instance().pingPartyUpdate(party);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-02 21:06:42 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean meetsPartyExchange(EnumPartyExchange exchange, boolean hasActive, boolean hasFinished, boolean isLeader){
|
|
|
|
|
if(exchange == EnumPartyExchange.All){
|
|
|
|
|
return true;
|
|
|
|
|
} else if (isLeader){
|
|
|
|
|
return true;
|
|
|
|
|
} else if(exchange == EnumPartyExchange.Enrolled && hasActive){
|
|
|
|
|
return true;
|
|
|
|
|
} else return exchange == EnumPartyExchange.Valid && (hasActive || hasFinished);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
public static boolean compareItems(ItemStack item, ItemStack item2, boolean ignoreDamage, boolean ignoreNBT){
|
|
|
|
|
if (item2 == null || item == null){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
boolean oreMatched = false;
|
|
|
|
|
OreDictionary.itemMatches(item, item2, false);
|
|
|
|
|
int[] ids = OreDictionary.getOreIDs(item);
|
|
|
|
|
if(ids.length > 0){
|
|
|
|
|
for(int id : ids){
|
|
|
|
|
boolean match1 = false, match2 = false;
|
|
|
|
|
for(ItemStack is : OreDictionary.getOres(id)){
|
|
|
|
|
if(compareItemDetails(item, is, ignoreDamage, ignoreNBT)){
|
|
|
|
|
match1 = true;
|
|
|
|
|
}
|
|
|
|
|
if(compareItemDetails(item2, is, ignoreDamage, ignoreNBT)){
|
|
|
|
|
match2 = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(match1 && match2)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return compareItemDetails(item, item2, ignoreDamage, ignoreNBT);
|
|
|
|
|
}
|
|
|
|
|
private static boolean compareItemDetails(ItemStack item, ItemStack item2, boolean ignoreDamage, boolean ignoreNBT){
|
|
|
|
|
if (item.getItem() != item2.getItem() ){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!ignoreDamage && item.getItemDamage() != -1 && item.getItemDamage() != item2.getItemDamage()){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if(!ignoreNBT && item.stackTagCompound != null && (item2.stackTagCompound == null || !item.stackTagCompound.equals(item2.stackTagCompound))){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if(!ignoreNBT && item2.stackTagCompound != null && item.stackTagCompound == null){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
public static boolean compareItems(EntityPlayer player, ItemStack item, boolean ignoreDamage, boolean ignoreNBT){
|
|
|
|
|
int size = 0;
|
|
|
|
|
for(ItemStack is : player.inventory.mainInventory){
|
2024-03-02 21:06:42 -05:00
|
|
|
if(is != null && compareItems(item, is, ignoreDamage, ignoreNBT))
|
2018-09-13 12:03:28 -04:00
|
|
|
size += is.stackSize;
|
|
|
|
|
}
|
|
|
|
|
return size >= item.stackSize;
|
|
|
|
|
}
|
|
|
|
|
public static void consumeItem(EntityPlayer player, ItemStack item, boolean ignoreDamage, boolean ignoreNBT) {
|
|
|
|
|
if(item == null)
|
|
|
|
|
return;
|
|
|
|
|
int size = item.stackSize;
|
|
|
|
|
for(int i = 0; i < player.inventory.mainInventory.length; i++){
|
|
|
|
|
ItemStack is = player.inventory.mainInventory[i];
|
|
|
|
|
if(is == null || !compareItems(item, is, ignoreDamage, ignoreNBT))
|
|
|
|
|
continue;
|
|
|
|
|
if(size >= is.stackSize){
|
|
|
|
|
size -= is.stackSize;
|
|
|
|
|
player.inventory.mainInventory[i] = null;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
player.inventory.mainInventory[i].splitStack(size);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-16 10:41:04 -06:00
|
|
|
public static void isGUIOpen(EntityPlayerMP player){
|
|
|
|
|
Server.sendData(player, EnumPacketClient.ISGUIOPEN);
|
|
|
|
|
}
|
2022-01-10 15:21:48 -06:00
|
|
|
|
|
|
|
|
public static List<ItemStack> countStacks(IInventory inv, boolean ignoreDamage, boolean ignoreNBT) {
|
|
|
|
|
List<ItemStack> list = new ArrayList();
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < inv.getSizeInventory(); ++i) {
|
|
|
|
|
ItemStack item = inv.getStackInSlot(i);
|
|
|
|
|
if (!NoppesUtilServer.IsItemStackNull(item)) {
|
|
|
|
|
boolean found = false;
|
|
|
|
|
Iterator var7 = list.iterator();
|
|
|
|
|
|
|
|
|
|
while(var7.hasNext()) {
|
|
|
|
|
ItemStack is = (ItemStack)var7.next();
|
|
|
|
|
if (compareItems(item, is, ignoreDamage, ignoreNBT)) {
|
|
|
|
|
is.stackSize = is.stackSize + item.stackSize;
|
|
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
|
list.add(item.copy());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
2022-07-13 19:27:27 -05:00
|
|
|
|
|
|
|
|
public static void playSoundTo(EntityPlayerMP player, int id, ScriptSound sound) {
|
|
|
|
|
NBTTagCompound compound = sound.writeToNBT();
|
|
|
|
|
if (sound.sourceEntity == null || player.worldObj.provider.dimensionId == sound.sourceEntity.getDimension()) {
|
|
|
|
|
Server.sendData(player, EnumPacketClient.PLAY_SOUND_TO, id, compound);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-21 19:07:19 -06:00
|
|
|
public static void playSoundTo(EntityPlayerMP player, ScriptSound sound) {
|
|
|
|
|
NBTTagCompound compound = sound.writeToNBT();
|
|
|
|
|
if (sound.sourceEntity == null || player.worldObj.provider.dimensionId == sound.sourceEntity.getDimension()) {
|
|
|
|
|
Server.sendData(player, EnumPacketClient.PLAY_SOUND_TO_NO_ID, compound);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-13 19:27:27 -05:00
|
|
|
public static void stopSoundFor(EntityPlayerMP player, int id) {
|
|
|
|
|
Server.sendData(player, EnumPacketClient.STOP_SOUND_FOR, id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void pauseSoundsFor(EntityPlayerMP player) {
|
|
|
|
|
Server.sendData(player, EnumPacketClient.PAUSE_SOUNDS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void continueSoundsFor(EntityPlayerMP player) {
|
|
|
|
|
Server.sendData(player, EnumPacketClient.CONTINUE_SOUNDS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void stopSoundsFor(EntityPlayerMP player) {
|
|
|
|
|
Server.sendData(player, EnumPacketClient.STOP_SOUNDS);
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|