Files
CustomNPC-Plus/src/main/java/noppes/npcs/NoppesUtilServer.java
T

1159 lines
48 KiB
Java
Raw Normal View History

2018-09-13 12:03:28 -04:00
package noppes.npcs;
import io.netty.buffer.ByteBuf;
2025-01-30 09:26:10 -05:00
import kamkeel.npcs.controllers.SyncController;
2025-01-29 21:50:55 -05:00
import kamkeel.npcs.network.PacketHandler;
2025-02-20 21:40:39 -05:00
import kamkeel.npcs.network.packets.data.ParticlePacket;
2025-02-20 00:41:45 -05:00
import kamkeel.npcs.network.packets.data.PlayerDataInfoPacket;
import kamkeel.npcs.network.packets.data.gui.GuiClosePacket;
import kamkeel.npcs.network.packets.data.gui.GuiErrorPacket;
import kamkeel.npcs.network.packets.data.gui.GuiOpenPacket;
2025-02-20 21:40:39 -05:00
import kamkeel.npcs.network.packets.data.gui.GuiTeleporterPacket;
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
2025-02-10 16:38:50 -05:00
import kamkeel.npcs.network.packets.data.large.ScrollDataPacket;
import kamkeel.npcs.network.packets.data.large.ScrollListPacket;
import kamkeel.npcs.network.packets.data.npc.DeleteNpcPacket;
2025-02-20 21:40:39 -05:00
import kamkeel.npcs.network.packets.data.npc.DialogPacket;
import kamkeel.npcs.network.packets.data.npc.EditNpcPacket;
import kamkeel.npcs.network.packets.data.npc.RolePacket;
2025-02-20 21:40:39 -05:00
import kamkeel.npcs.network.packets.data.script.ScriptedParticlePacket;
2025-01-29 21:50:55 -05:00
import kamkeel.npcs.util.ByteBufUtils;
2018-09-13 12:03:28 -04:00
import net.minecraft.command.server.CommandBlockLogic;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.entity.projectile.EntityThrowable;
2018-09-13 12:03:28 -04:00
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.MobSpawnerBaseLogic;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityCommandBlock;
import net.minecraft.tileentity.TileEntityMobSpawner;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.DamageSource;
2018-09-13 12:03:28 -04:00
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
2023-01-12 21:33:06 -05:00
import noppes.npcs.api.entity.IPlayer;
2023-06-02 03:37:18 -04:00
import noppes.npcs.config.ConfigMain;
2018-09-13 12:03:28 -04:00
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.constants.EnumPlayerData;
import noppes.npcs.constants.EnumRoleType;
2025-03-03 18:44:05 -05:00
import noppes.npcs.constants.EnumScrollData;
2018-09-13 12:03:28 -04:00
import noppes.npcs.containers.ContainerManageBanks;
import noppes.npcs.containers.ContainerManageRecipes;
2023-01-10 17:17:15 -05:00
import noppes.npcs.controllers.*;
import noppes.npcs.controllers.data.*;
2018-09-13 12:03:28 -04:00
import noppes.npcs.entity.EntityDialogNpc;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.roles.RoleTransporter;
import noppes.npcs.scripted.NpcAPI;
2022-07-13 19:27:27 -05:00
import noppes.npcs.scripted.ScriptSound;
2025-04-08 22:37:26 -04:00
import noppes.npcs.scripted.event.player.DialogEvent;
2023-01-12 21:33:06 -05:00
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.*;
2018-09-13 12:03:28 -04:00
import static kamkeel.npcs.network.packets.data.large.ScrollDataPacket.sendScrollData;
2025-01-29 15:04:19 -05:00
2018-09-13 12:03:28 -04:00
public class NoppesUtilServer {
2025-03-13 17:14:45 -04:00
private static HashMap<String, Quest> editingQuests = new HashMap<String, Quest>();
2018-09-13 12:03:28 -04:00
2025-02-10 14:58:45 -05:00
public static IPlayer getIPlayer(EntityPlayer p) {
return (IPlayer) NpcAPI.Instance().getIEntity(p);
}
public static UUID getUUID(Entity entity) {
return entity instanceof EntityPlayer ? ((EntityPlayer) entity).getGameProfile().getId() : entity.getUniqueID();
}
2025-03-13 17:14:45 -04:00
public static boolean isScriptableItem(Item item) {
2025-02-17 16:02:56 -05:00
return item == CustomItems.scripted_item || item == CustomItems.linked_item;
}
2025-03-13 17:14:45 -04:00
public static void setEditingNpc(EntityPlayer player, EntityNPCInterface npc) {
PlayerData data = PlayerData.get(player);
2025-01-29 21:50:55 -05:00
data.editingNpc = npc;
2025-03-13 17:14:45 -04:00
if (npc != null)
PacketHandler.Instance.sendToPlayer(new EditNpcPacket(npc.getEntityId()), (EntityPlayerMP) player);
2018-09-13 12:03:28 -04:00
}
2025-01-29 21:50:55 -05:00
2025-03-13 17:14:45 -04:00
public static EntityNPCInterface getEditingNpc(EntityPlayer player) {
PlayerData data = PlayerData.get(player);
2025-01-29 21:50:55 -05:00
return data.editingNpc;
}
public static void setEditingQuest(EntityPlayer player, Quest quest) {
editingQuests.put(player.getCommandSenderName(), quest);
2018-09-13 12:03:28 -04:00
}
2025-03-13 17:14:45 -04:00
public static Quest getEditingQuest(EntityPlayer player) {
2025-01-29 21:50:55 -05:00
return editingQuests.get(player.getCommandSenderName());
2018-09-13 12:03:28 -04:00
}
2025-03-13 17:14:45 -04:00
public static void sendRoleData(EntityPlayer player, EntityNPCInterface npc) {
if (npc.advanced.role == EnumRoleType.None)
2025-01-29 21:50:55 -05:00
return;
NBTTagCompound comp = new NBTTagCompound();
npc.roleInterface.writeToNBT(comp);
comp.setInteger("EntityId", npc.getEntityId());
comp.setInteger("Role", npc.advanced.role.ordinal());
2025-03-13 17:14:45 -04:00
PacketHandler.Instance.sendToPlayer(new RolePacket(comp), (EntityPlayerMP) player);
}
public static void sendFactionDataAll(EntityPlayerMP player) {
Map<String, Integer> map = new HashMap<String, Integer>();
for (Faction faction : FactionController.getInstance().factions.values()) {
map.put(faction.name, faction.id);
}
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendAnimationDataAll(EntityPlayerMP player) {
Map<String, Integer> map = new HashMap<String, Integer>();
for (Animation animation : AnimationController.getInstance().animations.values()) {
map.put(animation.name, animation.id);
}
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendTagDataAll(EntityPlayerMP player) {
Map<String, Integer> map = new HashMap<String, Integer>();
for (Tag tag : TagController.getInstance().tags.values()) {
map.put(tag.name, tag.id);
}
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendBankDataAll(EntityPlayerMP player) {
Map<String, Integer> map = new HashMap<String, Integer>();
for (Bank bank : BankController.getInstance().banks.values()) {
map.put(bank.name, bank.id);
}
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static NBTTagCompound writeItem(ItemStack item, NBTTagCompound nbt) {
2018-09-13 12:03:28 -04:00
String resourcelocation = Item.itemRegistry.getNameForObject(item.getItem());
nbt.setString("id", resourcelocation == null ? "minecraft:air" : resourcelocation.toString());
2025-03-13 17:14:45 -04:00
nbt.setByte("Count", (byte) item.stackSize);
nbt.setShort("Damage", (short) item.getItemDamage());
2018-09-13 12:03:28 -04:00
2025-03-13 17:14:45 -04:00
if (item.stackTagCompound != null) {
2018-09-13 12:03:28 -04:00
nbt.setTag("tag", item.stackTagCompound);
}
return nbt;
}
2025-03-13 17:14:45 -04:00
public static ItemStack readItem(NBTTagCompound nbt) {
Item item;
if (nbt.hasKey("id", 8)) {
item = getByNameOrId(nbt.getString("id"));
} else {
item = Item.getItemById(nbt.getShort("id"));
2018-09-13 12:03:28 -04:00
}
2025-03-13 17:14:45 -04:00
if (item == null)
return null;
2018-09-13 12:03:28 -04:00
ItemStack itemstack = new ItemStack(item);
itemstack.stackSize = nbt.getByte("Count");
itemstack.setItemDamage(nbt.getShort("Damage"));
2025-03-13 17:14:45 -04:00
if (itemstack.getItemDamage() < 0) {
itemstack.setItemDamage(0);
2018-09-13 12:03:28 -04:00
}
2025-03-13 17:14:45 -04:00
if (nbt.hasKey("tag", 10)) {
itemstack.stackTagCompound = nbt.getCompoundTag("tag");
2018-09-13 12:03:28 -04:00
}
return itemstack;
}
2024-02-19 19:14:51 -05:00
2025-03-13 17:14:45 -04:00
public static Item getByNameOrId(String id) {
Item item = (Item) Item.itemRegistry.getObject(id);
2018-09-13 12:03:28 -04:00
2025-03-13 17:14:45 -04:00
if (item == null) {
try {
2018-09-13 12:03:28 -04:00
return Item.getItemById(Integer.parseInt(id));
2025-03-13 17:14:45 -04:00
} catch (NumberFormatException numberformatexception) {
2018-09-13 12:03:28 -04:00
;
}
}
return item;
}
2024-02-19 19:14:51 -05:00
2025-03-13 17:14:45 -04:00
public static void openDialog(EntityPlayer player, EntityNPCInterface npc, Dialog dia, int optionId) {
Dialog dialog = dia.copy(player);
PlayerData playerdata = PlayerData.get(player);
2025-03-13 17:14:45 -04:00
if (!npc.isRemote()) {
if (EventHooks.onNPCDialog(npc, player, dialog.id, optionId, dialog)) {
return;
}
2025-04-09 01:55:34 -04:00
if (EventHooks.onDialogOpen(player, new DialogEvent.DialogOpen((IPlayer) NpcAPI.Instance().getIEntity(player), dialog))) {
2025-03-13 17:14:45 -04:00
return;
}
}
if (npc instanceof EntityDialogNpc || dia.id < 0) {
dialog.hideNPC = true;
PacketHandler.Instance.sendToPlayer(new DialogPacket(npc.getCommandSenderName(), -1, dialog.writeToNBT(new NBTTagCompound())), (EntityPlayerMP) player);
} else
PacketHandler.Instance.sendToPlayer(new DialogPacket("Real", npc.getEntityId(), dialog.writeToNBT(new NBTTagCompound())), (EntityPlayerMP) player);
2025-01-29 21:50:55 -05:00
dia.factionOptions.addPoints(player);
2025-03-13 17:14:45 -04:00
if (dialog.hasQuest())
PlayerQuestController.addActiveQuest(new QuestData(dialog.getQuest()), player);
if (!dialog.command.isEmpty()) {
2018-09-13 12:03:28 -04:00
runCommand(player, npc.getCommandSenderName(), dialog.command);
}
2025-03-13 17:14:45 -04:00
if (dialog.mail.isValid())
PlayerDataController.Instance.addPlayerMessage(player.getCommandSenderName(), dialog.mail);
PlayerDialogData data = PlayerData.get(player).dialogData;
2025-03-13 17:14:45 -04:00
if (!data.dialogsRead.contains(dialog.id) && dialog.id >= 0) {
data.dialogsRead.add(dialog.id);
playerdata.updateClient = true;
}
2025-03-13 17:14:45 -04:00
setEditingNpc(player, npc);
}
public static void runCommand(EntityPlayer player, String name, String command) {
2018-09-13 12:03:28 -04:00
runCommand(player, name, command, player);
2025-03-13 17:14:45 -04:00
}
2024-02-19 19:14:51 -05:00
2024-03-08 02:07:02 -05:00
public static void runCommand(EntityLivingBase executer, String name, String command, EntityPlayer player) {
2025-03-13 17:14:45 -04:00
if (player != null)
2024-03-08 02:07:02 -05:00
command = command.replace("@dp", player.getCommandSenderName());
command = command.replace("@npc", name);
// Trim the command to remove leading/trailing spaces
command = command.trim();
2024-03-13 19:32:22 -04:00
String[] commands = command.split("@x"); // Split the command by @x
2024-03-08 02:07:02 -05:00
// Create TileEntityCommandBlock instance outside the loop
2018-09-13 12:03:28 -04:00
TileEntityCommandBlock tile = new TileEntityCommandBlock();
tile.setWorldObj(executer.worldObj);
tile.xCoord = MathHelper.floor_double(executer.posX);
tile.yCoord = MathHelper.floor_double(executer.posY);
tile.zCoord = MathHelper.floor_double(executer.posZ);
2024-02-19 19:14:51 -05:00
2024-03-08 02:07:02 -05:00
// Create CommandBlockLogic instance outside the loop
2018-09-13 12:03:28 -04:00
CommandBlockLogic logic = tile.func_145993_a();
2024-03-08 02:07:02 -05:00
for (String cmd : commands) {
logic.func_145752_a(cmd.trim()); // Trim the command to remove any leading/trailing spaces
logic.func_145754_b("@" + name);
logic.func_145755_a(executer.worldObj);
}
}
public static void runCommand(World world, String name, String command) {
2025-03-13 17:14:45 -04:00
TileEntityCommandBlock tile = new TileEntityCommandBlock();
tile.setWorldObj(world.provider.worldObj);
tile.xCoord = 0;
tile.yCoord = 0;
tile.zCoord = 0;
2024-03-08 02:07:02 -05:00
// Trim the command to remove leading/trailing spaces
command = command.trim();
2024-03-13 19:32:22 -04:00
String[] commands = command.split("@x"); // Split the command by @x
2024-03-08 02:07:02 -05:00
CommandBlockLogic logic = tile.func_145993_a();
for (String cmd : commands) {
logic.func_145752_a(cmd.trim()); // Trim the command to remove any leading/trailing spaces
logic.func_145754_b("@" + name);
logic.func_145755_a(world);
}
2025-03-13 17:14:45 -04:00
}
2024-02-19 19:14:51 -05:00
2025-03-13 17:14:45 -04:00
public static void consumeItemStack(int i, EntityPlayer player) {
ItemStack item = player.inventory.getCurrentItem();
if (player.capabilities.isCreativeMode || item == null)
return;
2024-02-19 19:14:51 -05:00
2018-09-13 12:03:28 -04:00
--item.stackSize;
if (item.stackSize <= 0)
2025-03-13 17:14:45 -04:00
player.destroyCurrentEquippedItem();
}
public static void sendOpenGui(EntityPlayer player,
EnumGuiType gui, EntityNPCInterface npc) {
sendOpenGui(player, gui, npc, 0, 0, 0);
}
public static void sendOpenGuiNoDelay(EntityPlayer player,
EnumGuiType gui, EntityNPCInterface npc) {
sendOpenGuiNoDelay(player, gui, npc, 0, 0, 0);
}
public static void sendOpenGui(final EntityPlayer player,
final EnumGuiType gui, final EntityNPCInterface npc, final int i, final int j, final int k) {
if (!(player instanceof EntityPlayerMP))
return;
setEditingNpc(player, npc);
sendExtraData(player, npc, gui, i, j, k);
if (CustomNpcs.proxy.getServerGuiElement(gui.ordinal(), player, player.worldObj, i, j, k) != null) {
player.openGui(CustomNpcs.instance, gui.ordinal(), player.worldObj, i, j, k);
return;
} else {
GuiOpenPacket.openGUI((EntityPlayerMP) player, gui, i, j, k);
}
ArrayList<String> list = getScrollData(player, gui, npc);
if (list == null || list.isEmpty())
return;
ScrollListPacket.sendList((EntityPlayerMP) player, list, EnumScrollData.OPTIONAL);
}
public static void sendOpenGuiNoDelay(final EntityPlayer player,
final EnumGuiType gui, final EntityNPCInterface npc, final int i, final int j, final int k) {
if (!(player instanceof EntityPlayerMP))
return;
setEditingNpc(player, npc);
sendExtraData(player, npc, gui, i, j, k);
if (CustomNpcs.proxy.getServerGuiElement(gui.ordinal(), player, player.worldObj, i, j, k) != null) {
player.openGui(CustomNpcs.instance, gui.ordinal(), player.worldObj, i, j, k);
return;
} else {
GuiOpenPacket.openGUI((EntityPlayerMP) player, gui, i, j, k);
}
ArrayList<String> list = getScrollData(player, gui, npc);
if (list == null || list.isEmpty())
return;
ScrollListPacket.sendList((EntityPlayerMP) player, list, EnumScrollData.OPTIONAL);
}
private static void sendExtraData(EntityPlayer player, EntityNPCInterface npc, EnumGuiType gui, int i, int j, int k) {
if (gui == EnumGuiType.PlayerFollower || gui == EnumGuiType.PlayerFollowerHire || gui == EnumGuiType.PlayerTrader || gui == EnumGuiType.PlayerTransporter) {
sendRoleData(player, npc);
}
}
private static ArrayList<String> getScrollData(EntityPlayer player, EnumGuiType gui, EntityNPCInterface npc) {
if (gui == EnumGuiType.PlayerTransporter) {
RoleTransporter role = (RoleTransporter) npc.roleInterface;
ArrayList<String> list = new ArrayList<String>();
TransportLocation location = role.getLocation();
String name = role.getLocation().name;
for (TransportLocation loc : location.category.getDefaultLocations()) {
if (!list.contains(loc.name)) {
list.add(loc.name);
}
}
PlayerTransportData playerdata = PlayerData.get(player).transportData;
2025-03-13 17:14:45 -04:00
for (int i : playerdata.transports) {
TransportLocation loc = TransportController.getInstance().getTransport(i);
if (loc != null && location.category.locations.containsKey(loc.id)) {
if (!list.contains(loc.name)) {
list.add(loc.name);
}
}
}
list.remove(name);
return list;
}
return null;
}
public static void spawnParticle(Entity entity, String particle, int dimension) {
2025-01-29 23:33:35 -05:00
PacketHandler.Instance.sendTracking(new ParticlePacket(entity.posX, entity.posY, entity.posZ, entity.height, entity.width, entity.yOffset, particle), entity);
2018-09-13 12:03:28 -04:00
}
2025-03-13 17:14:45 -04:00
public static void spawnScriptedParticle(NBTTagCompound compound, int dimensionId) {
2025-01-29 23:33:35 -05:00
PacketHandler.Instance.sendToDimension(new ScriptedParticlePacket(compound), dimensionId);
2025-03-13 17:14:45 -04:00
}
public static void playSound(int id, ScriptSound sound) {
List<EntityPlayer> list = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
for (EntityPlayer player : list) {
NoppesUtilPlayer.playSoundTo((EntityPlayerMP) player, id, sound);
}
}
public static void playSound(ScriptSound sound) {
List<EntityPlayer> list = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
for (EntityPlayer player : list) {
NoppesUtilPlayer.playSoundTo((EntityPlayerMP) player, sound);
}
}
public static void stopSound(int id) {
List<EntityPlayer> list = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
for (EntityPlayer player : list) {
NoppesUtilPlayer.stopSoundFor((EntityPlayerMP) player, id);
}
}
public static void pauseSounds() {
List<EntityPlayer> list = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
for (EntityPlayer player : list) {
NoppesUtilPlayer.pauseSoundsFor((EntityPlayerMP) player);
}
}
public static void continueSounds() {
List<EntityPlayer> list = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
for (EntityPlayer player : list) {
NoppesUtilPlayer.continueSoundsFor((EntityPlayerMP) player);
}
}
public static void stopSounds() {
List<EntityPlayer> list = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
for (EntityPlayer player : list) {
NoppesUtilPlayer.stopSoundsFor((EntityPlayerMP) player);
}
}
public static void deleteNpc(EntityNPCInterface npc, EntityPlayer player) {
2025-01-29 23:33:35 -05:00
PacketHandler.Instance.sendTracking(new DeleteNpcPacket(npc.getEntityId()), npc);
2025-03-13 17:14:45 -04:00
}
public static void createMobSpawner(int x, int y, int z, NBTTagCompound comp, EntityPlayer player) {
comp.removeTag("Pos");
ServerCloneController.Instance.cleanTags(comp);
if (comp.getString("id").equalsIgnoreCase("entityhorse")) {
player.addChatMessage(new ChatComponentTranslation("Currently you cant create horse spawner, its a minecraft bug"));
return;
}
player.worldObj.setBlock(x, y, z, Blocks.mob_spawner); //setBlock
TileEntityMobSpawner tile = (TileEntityMobSpawner) player.worldObj.getTileEntity(x, y, z);
MobSpawnerBaseLogic logic = tile.func_145881_a();
logic.setRandomEntity(logic.new WeightedRandomMinecart(comp, comp.getString("id")));
}
public static void sendQuestCategoryData(EntityPlayerMP player) {
Map<String, Integer> map = new HashMap<String, Integer>();
for (QuestCategory category : QuestController.Instance.categories.values()) {
map.put(category.title, category.id);
}
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendPlayerData(EnumPlayerData type, EntityPlayerMP player, String name) throws IOException {
Map<String, Integer> map = new HashMap<String, Integer>();
if (type == EnumPlayerData.Players) {
for (String username : PlayerDataController.Instance.nameUUIDs.keySet()) {
map.put(username, 0);
}
for (String username : MinecraftServer.getServer().getConfigurationManager().getAllUsernames()) {
map.put(username, 0);
}
} else {
PlayerData playerdata = PlayerDataController.Instance.getDataFromUsername(name);
if (type == EnumPlayerData.Dialog) {
PlayerDialogData data = playerdata.dialogData;
for (int questId : data.dialogsRead) {
Dialog dialog = DialogController.Instance.dialogs.get(questId);
if (dialog == null)
continue;
map.put(dialog.category.title + ": " + dialog.title, questId);
}
} else if (type == EnumPlayerData.Quest) {
PlayerQuestData data = playerdata.questData;
for (int questId : data.activeQuests.keySet()) {
Quest quest = QuestController.Instance.quests.get(questId);
if (quest == null)
continue;
map.put(quest.category.title + ": " + quest.title + " (Active)", questId);
}
for (int questId : data.finishedQuests.keySet()) {
Quest quest = QuestController.Instance.quests.get(questId);
if (quest == null)
continue;
map.put(quest.category.title + ": " + quest.title + " (Finished)", questId);
}
} else if (type == EnumPlayerData.Transport) {
PlayerTransportData data = playerdata.transportData;
for (int questId : data.transports) {
TransportLocation location = TransportController.getInstance().getTransport(questId);
if (location == null)
continue;
map.put(location.category.title + ": " + location.name, questId);
}
} else if (type == EnumPlayerData.Bank) {
PlayerBankData data = playerdata.bankData;
for (int bankId : data.banks.keySet()) {
Bank bank = BankController.getInstance().banks.get(bankId);
if (bank == null)
continue;
map.put(bank.name, bankId);
}
} else if (type == EnumPlayerData.Factions) {
PlayerFactionData data = playerdata.factionData;
for (int factionId : data.factionData.keySet()) {
Faction faction = FactionController.getInstance().factions.get(factionId);
if (faction == null)
continue;
map.put(faction.name + "(" + data.getFactionPoints(factionId) + ")", factionId);
}
}
}
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void removePlayerData(ByteBuf buffer, EntityPlayerMP player) throws IOException {
int id = buffer.readInt();
if (EnumPlayerData.values().length <= id)
return;
String name = ByteBufUtils.readString(buffer);
EnumPlayerData type = EnumPlayerData.values()[id];
2018-09-13 12:03:28 -04:00
EntityPlayer pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(name);
2025-03-13 17:14:45 -04:00
PlayerData playerdata = null;
if (pl == null)
playerdata = PlayerDataController.Instance.getDataFromUsername(name);
else
playerdata = PlayerData.get(pl);
2025-03-13 17:14:45 -04:00
if (type == EnumPlayerData.Players) {
String fileType = ".json";
if (ConfigMain.DatFormat) {
fileType = ".dat";
}
2023-06-05 19:35:27 -04:00
File file = new File(PlayerDataController.Instance.getSaveDir(), playerdata.uuid + fileType);
2025-03-13 17:14:45 -04:00
if (file.exists())
file.delete();
if (pl != null) {
PlayerDataController.Instance.removePlayerDataCache(pl.getUniqueID().toString());
2025-03-13 17:14:45 -04:00
PlayerDataController.Instance.nameUUIDs.remove(name);
PlayerDataController.Instance.savePlayerDataMap();
2025-03-13 17:14:45 -04:00
playerdata.setNBT(new NBTTagCompound());
2018-09-13 12:03:28 -04:00
sendPlayerData(type, player, name);
playerdata.save();
2018-09-13 12:03:28 -04:00
return;
}
}
2025-03-13 17:14:45 -04:00
if (type == EnumPlayerData.Quest) {
PlayerQuestData data = playerdata.questData;
int questId = buffer.readInt();
data.activeQuests.remove(questId);
data.finishedQuests.remove(questId);
playerdata.save();
2018-09-13 12:03:28 -04:00
}
2025-03-13 17:14:45 -04:00
if (type == EnumPlayerData.Dialog) {
PlayerDialogData data = playerdata.dialogData;
data.dialogsRead.remove(buffer.readInt());
playerdata.save();
2018-09-13 12:03:28 -04:00
}
2025-03-13 17:14:45 -04:00
if (type == EnumPlayerData.Transport) {
PlayerTransportData data = playerdata.transportData;
data.transports.remove(buffer.readInt());
playerdata.save();
2018-09-13 12:03:28 -04:00
}
2025-03-13 17:14:45 -04:00
if (type == EnumPlayerData.Bank) {
PlayerBankData data = playerdata.bankData;
data.banks.remove(buffer.readInt());
playerdata.save();
2018-09-13 12:03:28 -04:00
}
2025-03-13 17:14:45 -04:00
if (type == EnumPlayerData.Factions) {
PlayerFactionData data = playerdata.factionData;
data.factionData.remove(buffer.readInt());
playerdata.save();
2018-09-13 12:03:28 -04:00
}
2025-03-13 17:14:45 -04:00
if (type == EnumPlayerData.Magic) {
2025-03-07 16:00:06 -05:00
MagicData data = playerdata.magicData;
data.removeMagic(buffer.readInt());
playerdata.save();
}
2025-03-13 17:14:45 -04:00
if (pl != null) {
2025-01-30 09:26:10 -05:00
SyncController.syncPlayer((EntityPlayerMP) pl);
}
2018-09-13 12:03:28 -04:00
sendPlayerData(type, player, name);
2025-03-13 17:14:45 -04:00
}
public static void regenPlayerData(EntityPlayerMP player) throws IOException {
PlayerDataController.Instance.generatePlayerMap(player);
}
public static void sendRecipeData(EntityPlayerMP player, int size) {
HashMap<String, Integer> map = new HashMap<String, Integer>();
if (size == 3) {
for (RecipeCarpentry recipe : RecipeController.Instance.globalRecipes.values()) {
2025-02-10 02:44:28 -05:00
map.put(recipe.name, recipe.id);
}
2025-03-13 17:14:45 -04:00
} else if (size == 4) {
for (RecipeCarpentry recipe : RecipeController.Instance.carpentryRecipes.values()) {
2025-02-10 02:44:28 -05:00
map.put(recipe.name, recipe.id);
}
2025-03-13 17:14:45 -04:00
} else {
for (RecipeAnvil recipe : RecipeController.Instance.anvilRecipes.values()) {
map.put(recipe.name, recipe.id);
}
}
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendDialogData(EntityPlayerMP player, DialogCategory category) {
if (category == null)
return;
HashMap<String, Integer> map = new HashMap<String, Integer>();
for (Dialog dialog : category.dialogs.values()) {
map.put(dialog.title, dialog.id);
}
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendDialogGroup(EntityPlayerMP player, DialogCategory category) {
if (category == null)
return;
HashMap<String, Integer> map = new HashMap<String, Integer>();
for (Dialog dialog : category.dialogs.values()) {
map.put(dialog.title, dialog.id);
}
2023-06-07 22:49:54 -04:00
2025-03-03 18:44:05 -05:00
sendScrollData(player, map, EnumScrollData.DIALOG_GROUP);
2025-03-13 17:14:45 -04:00
}
public static void sendQuestData(EntityPlayerMP player, QuestCategory category) {
if (category == null)
return;
HashMap<String, Integer> map = new HashMap<String, Integer>();
for (Quest quest : category.quests.values()) {
map.put(quest.title, quest.id);
}
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendQuestGroup(EntityPlayerMP player, QuestCategory category) {
if (category == null)
return;
HashMap<String, Integer> map = new HashMap<String, Integer>();
for (Quest quest : category.quests.values()) {
map.put(quest.title, quest.id);
}
2023-06-11 16:05:15 -04:00
2025-03-03 18:44:05 -05:00
sendScrollData(player, map, EnumScrollData.QUEST_GROUP);
2025-03-13 17:14:45 -04:00
}
2018-09-13 12:03:28 -04:00
2025-02-10 16:38:50 -05:00
public static void sendCustomEffectDataAll(EntityPlayerMP player) {
Map<String, Integer> map = new HashMap<String, Integer>();
2025-02-12 03:15:28 -05:00
for (CustomEffect effect : CustomEffectController.getInstance().getCustomEffects().values()) {
2025-02-10 16:38:50 -05:00
map.put(effect.name, effect.id);
}
2025-03-03 18:44:05 -05:00
ScrollDataPacket.sendScrollData(player, map, EnumScrollData.OPTIONAL);
2025-02-10 16:38:50 -05:00
}
2025-02-16 04:54:21 -05:00
public static void sendLinkedItemDataAll(EntityPlayerMP player) {
Map<String, Integer> map = new HashMap<String, Integer>();
for (LinkedItem linkedItem : LinkedItemController.getInstance().linkedItems.values()) {
map.put(linkedItem.name, linkedItem.id);
}
2025-03-03 18:44:05 -05:00
ScrollDataPacket.sendScrollData(player, map, EnumScrollData.OPTIONAL);
2025-02-16 04:54:21 -05:00
}
2025-03-13 17:14:45 -04:00
public static void sendTransportCategoryData(EntityPlayerMP player) {
HashMap<String, Integer> map = new HashMap<String, Integer>();
for (TransportCategory category : TransportController.getInstance().categories.values()) {
map.put(category.title, category.id);
}
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendTransportData(EntityPlayerMP player, int categoryid) {
TransportCategory category = TransportController.getInstance().categories.get(categoryid);
if (category == null)
return;
HashMap<String, Integer> map = new HashMap<String, Integer>();
for (TransportLocation transport : category.locations.values()) {
map.put(transport.name, transport.id);
}
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendNpcDialogs(EntityPlayer player) {
EntityNPCInterface npc = getEditingNpc(player);
if (npc == null)
return;
for (int pos : npc.dialogs.keySet()) {
DialogOption option = npc.dialogs.get(pos);
if (option == null || !option.hasDialog())
continue;
NBTTagCompound compound = option.writeNBT();
compound.setInteger("Position", pos);
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
}
}
2018-09-13 12:03:28 -04:00
2025-03-03 23:08:18 -05:00
public static void sendMagicInfo(EntityPlayerMP player, boolean cycles) {
2025-03-13 17:14:45 -04:00
HashMap<String, Integer> map = new HashMap<String, Integer>();
if (cycles) {
for (MagicCycle magicCycle : MagicController.getInstance().cycles.values()) {
2025-03-03 23:08:18 -05:00
map.put(magicCycle.name, magicCycle.id);
}
sendScrollData(player, map, EnumScrollData.MAGIC_CYCLES);
2025-03-14 20:32:26 -04:00
} else {
for (Magic magic : MagicController.getInstance().magics.values()) {
map.put(magic.name, magic.id);
}
sendScrollData(player, map, EnumScrollData.MAGIC);
2025-03-03 23:08:18 -05:00
}
}
2025-03-13 17:14:45 -04:00
public static DialogOption setNpcDialog(int slot, int dialogId, EntityPlayer player) throws IOException {
return setNpcDialog(slot, dialogId, getEditingNpc(player));
}
2025-03-13 17:14:45 -04:00
public static DialogOption setNpcDialog(int slot, int dialogId, EntityNPCInterface npc) {
if (npc == null)
return null;
if (!npc.dialogs.containsKey(slot))
npc.dialogs.put(slot, new DialogOption());
2025-03-13 17:14:45 -04:00
DialogOption option = npc.dialogs.get(slot);
option.dialogId = dialogId;
if (option.hasDialog())
option.title = option.getDialog().title;
2025-03-13 17:14:45 -04:00
return option;
}
2018-09-13 12:03:28 -04:00
2025-03-13 17:14:45 -04:00
public static void saveTileEntity(EntityPlayerMP player, NBTTagCompound compound) {
int x = compound.getInteger("x");
int y = compound.getInteger("y");
int z = compound.getInteger("z");
2024-02-19 19:14:51 -05:00
2025-03-13 17:14:45 -04:00
TileEntity tile = player.worldObj.getTileEntity(x, y, z);
if (tile != null)
tile.readFromNBT(compound);
2024-02-19 19:14:51 -05:00
2025-03-13 17:14:45 -04:00
}
2018-09-13 12:03:28 -04:00
2025-03-13 17:14:45 -04:00
public static void setClonerGui(EntityPlayerMP player, int x, int y, int z) {
if (player == null)
2024-02-19 19:14:51 -05:00
return;
GuiOpenPacket.openGUI(player, EnumGuiType.Cloner, x, y, z);
2024-02-19 19:14:51 -05:00
}
2025-03-13 17:14:45 -04:00
public static void setTeleporterGUI(EntityPlayerMP player) {
if (player == null)
2024-02-19 19:47:13 -05:00
return;
2025-01-29 23:33:35 -05:00
PacketHandler.Instance.sendToPlayer(new GuiTeleporterPacket(), player);
2024-02-19 19:47:13 -05:00
}
2025-03-13 17:14:45 -04:00
public static void setRecipeGui(EntityPlayerMP player, RecipeCarpentry recipe) {
if (recipe == null)
return;
if (!(player.openContainer instanceof ContainerManageRecipes))
return;
2024-02-19 19:14:51 -05:00
2025-03-13 17:14:45 -04:00
ContainerManageRecipes container = (ContainerManageRecipes) player.openContainer;
container.setRecipe(recipe);
GuiDataPacket.sendGuiData((EntityPlayerMP) player, recipe.writeNBT());
}
2018-09-13 12:03:28 -04:00
2025-03-13 17:14:45 -04:00
public static void setRecipeAnvilGui(EntityPlayerMP player, RecipeAnvil recipe) {
if (recipe == null)
2025-02-10 02:44:28 -05:00
return;
2025-03-13 17:14:45 -04:00
if (!(player.openContainer instanceof ContainerManageRecipes))
2025-02-10 02:44:28 -05:00
return;
ContainerManageRecipes container = (ContainerManageRecipes) player.openContainer;
container.setRecipe(recipe);
2025-03-13 17:14:45 -04:00
GuiDataPacket.sendGuiData((EntityPlayerMP) player, recipe.writeNBT());
}
public static void sendBank(EntityPlayerMP player, Bank bank) {
NBTTagCompound compound = new NBTTagCompound();
bank.writeEntityToNBT(compound);
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
if (player.openContainer instanceof ContainerManageBanks) {
((ContainerManageBanks) player.openContainer).setBank(bank);
}
player.sendContainerAndContentsToPlayer(player.openContainer, player.openContainer.getInventory());
}
public static void sendNearbyNpcs(EntityPlayerMP player) {
List<EntityNPCInterface> npcs = player.worldObj.getEntitiesWithinAABB(EntityNPCInterface.class, player.boundingBox.expand(120, 120, 120));
HashMap<String, Integer> map = new HashMap<String, Integer>();
for (EntityNPCInterface npc : npcs) {
if (npc.isDead)
continue;
float distance = player.getDistanceToEntity(npc);
DecimalFormat df = new DecimalFormat("#.#");
String s = df.format(distance);
if (distance < 10)
s = "0" + s;
map.put(s + " : " + npc.display.name, npc.getEntityId());
}
sendScrollData(player, map, EnumScrollData.OPTIONAL);
}
public static void sendGuiError(EntityPlayer player, int i) {
GuiErrorPacket.errorGUI((EntityPlayerMP) player, i, new NBTTagCompound());
}
public static void sendGuiClose(EntityPlayerMP player, int i, NBTTagCompound comp) {
if (player.openContainer != player.inventoryContainer) {
player.openContainer = player.inventoryContainer;
}
GuiClosePacket.closeGUI(player, i, comp);
2025-03-13 17:14:45 -04:00
}
public static Entity spawnCloneWithProtection(NBTTagCompound compound, int x, int y,
int z, World worldObj) {
ServerCloneController.Instance.cleanTags(compound);
compound.setTag("Pos", NBTTags.nbtDoubleList(x + 0.5, y, z + 0.5));
Entity entity = EntityList.createEntityFromNBT(compound, worldObj);
if (entity == null) {
return null;
}
entity.setPosition((double) x + 0.5, (double) y, (double) z + 0.5);
if (entity instanceof EntityNPCInterface) {
EntityNPCInterface npc = (EntityNPCInterface) entity;
npc.ais.startPos = new int[]{MathHelper.floor_double(npc.posX), MathHelper.floor_double(npc.posY), MathHelper.floor_double(npc.posZ)};
npc.ticksExisted = 0;
npc.totalTicksAlive = 0;
}
worldObj.spawnEntityInWorld(entity);
entity.prevPosY = entity.lastTickPosY = entity.posY = y + 1;
return entity;
}
public static Entity getEntityFromNBT(NBTTagCompound compound, int x, int y,
int z, World worldObj) {
ServerCloneController.Instance.cleanTags(compound);
compound.setTag("Pos", NBTTags.nbtDoubleList(x + 0.5, y + 1, z + 0.5));
Entity entity = EntityList.createEntityFromNBT(compound, worldObj);
if (entity == null) {
return null;
}
if (entity instanceof EntityNPCInterface) {
EntityNPCInterface npc = (EntityNPCInterface) entity;
npc.ais.startPos = new int[]{MathHelper.floor_double(npc.posX), MathHelper.floor_double(npc.posY), MathHelper.floor_double(npc.posZ)};
npc.ticksExisted = 0;
npc.totalTicksAlive = 0;
}
return entity;
}
public static Entity spawnClone(NBTTagCompound compound, int x, int y,
int z, World worldObj) {
Entity entity = getEntityFromNBT(compound, x, y, z, worldObj);
if (entity == null) {
return null;
}
entity.dimension = worldObj.provider.dimensionId;
int i = MathHelper.floor_double(entity.posX / 16.0D);
int j = MathHelper.floor_double(entity.posZ / 16.0D);
if (!entity.forceSpawn && !worldObj.checkChunksExist(
(int) entity.posX, (int) entity.posY, (int) entity.posZ, (int) entity.posX, (int) entity.posY, (int) entity.posZ)) {
return null;
} else {
worldObj.getChunkFromChunkCoords(i, j).addEntity(entity);
worldObj.loadedEntityList.add(entity);
worldObj.onEntityAdded(entity);
return entity;
}
}
2024-03-28 18:16:17 -04:00
public static boolean isOp(EntityPlayer player) {
2025-03-13 17:14:45 -04:00
return MinecraftServer.getServer().getConfigurationManager().func_152596_g(player.getGameProfile());
}
2018-09-13 12:03:28 -04:00
public static void GivePlayerItem(Entity entity, EntityPlayer player, ItemStack item) {
if (entity.worldObj.isRemote || item == null) {
return;
}
item = item.copy();
float f = 0.7F;
double d = (double) (entity.worldObj.rand.nextFloat() * f) + (double) (1.0F - f);
double d1 = (double) (entity.worldObj.rand.nextFloat() * f) + (double) (1.0F - f);
double d2 = (double) (entity.worldObj.rand.nextFloat() * f) + (double) (1.0F - f);
EntityItem entityitem = new EntityItem(entity.worldObj, entity.posX + d, entity.posY + d1, entity.posZ + d2,
2025-03-13 17:14:45 -04:00
item);
2018-09-13 12:03:28 -04:00
entityitem.delayBeforeCanPickup = 2;
entity.worldObj.spawnEntityInWorld(entityitem);
int i = item.stackSize;
if (player.inventory.addItemStackToInventory(item)) {
entity.worldObj.playSoundAtEntity(entityitem, "random.pop", 0.2F,
2025-03-13 17:14:45 -04:00
((entity.worldObj.rand.nextFloat() - entity.worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
2018-09-13 12:03:28 -04:00
player.onItemPickup(entityitem, i);
if (item.stackSize <= 0) {
entityitem.setDead();
}
}
}
2025-03-13 17:14:45 -04:00
public static EntityPlayer getPlayer(UUID id) {
List<EntityPlayer> list = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
for (EntityPlayer player : list) {
if (id.equals(player.getUniqueID()))
return player;
}
2018-09-13 12:03:28 -04:00
return null;
2025-03-13 17:14:45 -04:00
}
2024-02-21 03:02:39 -05:00
public static Entity getEntityFromUUID(World world, UUID uuid) {
for (Object obj : world.loadedEntityList) {
if (obj instanceof Entity) {
Entity entity = (Entity) obj;
if (entity.getUniqueID().equals(uuid)) {
return entity;
}
}
}
return null;
}
2025-03-13 17:14:45 -04:00
static public EntityPlayer getPlayerByName(String playername) {
return MinecraftServer.getServer().getConfigurationManager().func_152612_a(playername);
}
public static Entity GetDamageSource(DamageSource damagesource) {
Entity entity = damagesource.getEntity();
if (entity == null) {
entity = damagesource.getSourceOfDamage();
}
if (entity instanceof EntityArrow && ((EntityArrow) entity).shootingEntity instanceof EntityLivingBase) {
entity = ((EntityArrow) entity).shootingEntity;
} else if (entity instanceof EntityThrowable) {
entity = ((EntityThrowable) entity).getThrower();
}
return entity;
}
public static void isGUIOpen(ByteBuf buffer, EntityPlayer player) throws IOException {
PlayerData playerdata = PlayerData.get(player);
2025-03-13 17:14:45 -04:00
boolean isGUIOpen = buffer.readBoolean();
playerdata.setGUIOpen(isGUIOpen);
}
public static boolean IsItemStackNull(ItemStack is) {
return is == null || is.stackSize == 0 || is.getItem() == null;
}
public static String millisToTime(long millis) {
long seconds = millis / 1000;
long minutes = seconds / 60;
long hours = minutes / 60;
long days = hours / 24;
seconds %= 60;
minutes %= 60;
hours %= 24;
StringBuilder sb = new StringBuilder();
if (days > 0) {
sb.append(days).append(" day").append(days == 1 ? "" : "s").append(", ");
}
if (hours > 0) {
sb.append(hours).append(" hour").append(hours == 1 ? "" : "s").append(", ");
}
if (minutes > 0) {
sb.append(minutes).append(" minute").append(minutes == 1 ? "" : "s").append(", ");
}
sb.append(seconds).append(" second").append(seconds == 1 ? "" : "s");
return sb.toString();
}
2025-02-20 00:41:45 -05:00
/**
* Retrieves the player's data from the existing PlayerDataController and sends
* a large packet to the client containing all the maps, including categories.
*/
public static void sendPlayerDataInfo(String playerName, EntityPlayerMP player) {
PlayerData playerdata;
EntityPlayer pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(playerName);
2025-03-13 17:14:45 -04:00
if (pl == null)
2025-02-20 00:41:45 -05:00
playerdata = PlayerDataController.Instance.getDataFromUsername(playerName);
else
playerdata = PlayerData.get(pl);
2025-02-20 00:41:45 -05:00
// Assemble quest maps:
Map<String, Integer> questActiveMap = new HashMap<>();
Map<String, Integer> questFinishedMap = new HashMap<>();
Map<String, Integer> questCategoriesMap = new HashMap<>();
QuestController qc = QuestController.Instance;
PlayerQuestData qData = playerdata.questData;
for (Integer questId : qData.activeQuests.keySet()) {
2025-03-13 17:14:45 -04:00
if (!qc.quests.containsKey(questId))
2025-02-20 00:41:45 -05:00
continue;
Quest quest = qc.quests.get(questId);
questActiveMap.put(quest.category.title + ": " + quest.title, questId);
if (!questCategoriesMap.containsKey(quest.category.title))
questCategoriesMap.put(quest.category.title, quest.category.id);
}
for (Integer questId : qData.finishedQuests.keySet()) {
2025-03-13 17:14:45 -04:00
if (!qc.quests.containsKey(questId))
2025-02-20 00:41:45 -05:00
continue;
Quest quest = qc.quests.get(questId);
questFinishedMap.put(quest.category.title + ": " + quest.title, questId);
if (!questCategoriesMap.containsKey(quest.category.title))
questCategoriesMap.put(quest.category.title, quest.category.id);
}
// Assemble dialog maps:
Map<String, Integer> dialogReadMap = new HashMap<>();
Map<String, Integer> dialogCategoriesMap = new HashMap<>();
PlayerDialogData dData = playerdata.dialogData;
for (Integer dialogId : dData.dialogsRead) {
2025-03-13 17:14:45 -04:00
if (!DialogController.Instance.dialogs.containsKey(dialogId))
2025-02-20 00:41:45 -05:00
continue;
Dialog dialog = DialogController.Instance.dialogs.get(dialogId);
dialogReadMap.put(dialog.category.title + ": " + dialog.title, dialogId);
if (!dialogCategoriesMap.containsKey(dialog.category.title))
dialogCategoriesMap.put(dialog.category.title, dialog.category.id);
}
// Assemble transport maps:
Map<String, Integer> transportLocationsMap = new HashMap<>();
Map<String, Integer> transportCategoriesMap = new HashMap<>();
PlayerTransportData tData = playerdata.transportData;
TransportController tc = TransportController.getInstance();
for (Integer id : tData.transports) {
TransportLocation location = tc.getTransport(id);
2025-03-13 17:14:45 -04:00
if (location == null)
2025-02-20 00:41:45 -05:00
continue;
transportLocationsMap.put(location.category.title + ": " + location.name, id);
if (!transportCategoriesMap.containsKey(location.category.title))
transportCategoriesMap.put(location.category.title, location.category.id);
}
// Assemble bank map:
Map<String, Integer> bankMap = new HashMap<>();
PlayerBankData bData = playerdata.bankData;
BankController bc = BankController.getInstance();
for (Integer bankId : bData.banks.keySet()) {
2025-03-13 17:14:45 -04:00
if (!bc.banks.containsKey(bankId))
2025-02-20 00:41:45 -05:00
continue;
Bank bank = bc.banks.get(bankId);
bankMap.put(bank.name, bankId);
}
// Assemble faction map:
Map<String, Integer> factionMap = new HashMap<>();
PlayerFactionData fData = playerdata.factionData;
FactionController fc = FactionController.getInstance();
for (Integer factionId : fData.factionData.keySet()) {
2025-03-13 17:14:45 -04:00
if (!fc.factions.containsKey(factionId))
2025-02-20 00:41:45 -05:00
continue;
Faction faction = fc.factions.get(factionId);
factionMap.put(faction.name + "(" + fData.getFactionPoints(factionId) + ")", factionId);
}
// Send the full packet with categories, active/finished data, dialogs, transports, banks, and factions.
PlayerDataInfoPacket packet = new PlayerDataInfoPacket(playerName,
questCategoriesMap, questActiveMap, questFinishedMap,
dialogCategoriesMap, dialogReadMap,
transportCategoriesMap, transportLocationsMap,
2025-03-07 16:00:06 -05:00
bankMap, factionMap, playerdata.magicData);
2025-02-20 00:41:45 -05:00
PacketHandler.Instance.sendToPlayer(packet, player);
}
/**
* Removes a specific data entry from the player's data.
2025-03-13 17:14:45 -04:00
* <p>
2025-02-20 00:41:45 -05:00
* The tabType parameter is used as follows:
2025-03-13 17:14:45 -04:00
* 0: Quest – remove from both activeQuests and finishedQuests.
* 1: Dialog – remove from dialogsRead.
* 2: Transport – remove from transports.
* 3: Bank – remove from banks.
* 4: Factions – remove from factionData.
* 5: Magic - remove from magicData.
* <p>
2025-02-20 00:41:45 -05:00
* The selectedKey is expected to be the string representation of the entry's ID.
*/
public static void removePlayerDataInfo(String playerName, int tabType, int value, EntityPlayerMP player) {
EntityPlayer pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(playerName);
PlayerData playerdata;
2025-02-20 01:02:27 -05:00
EnumPlayerData enumPlayerData = EnumPlayerData.values()[tabType];
2025-03-13 17:14:45 -04:00
if (pl == null)
2025-02-20 00:41:45 -05:00
playerdata = PlayerDataController.Instance.getDataFromUsername(playerName);
else
playerdata = PlayerData.get(pl);
2025-02-20 00:41:45 -05:00
2025-03-13 17:14:45 -04:00
if (enumPlayerData == EnumPlayerData.Quest) { // Quest removal
2025-02-20 00:41:45 -05:00
playerdata.questData.activeQuests.remove(value);
playerdata.questData.finishedQuests.remove(value);
}
2025-03-13 17:14:45 -04:00
if (enumPlayerData == EnumPlayerData.Dialog) { // Dialog removal
2025-02-20 00:41:45 -05:00
playerdata.dialogData.dialogsRead.remove(value);
}
2025-03-13 17:14:45 -04:00
if (enumPlayerData == EnumPlayerData.Transport) { // Transport removal
2025-02-20 00:41:45 -05:00
playerdata.transportData.transports.remove(value);
}
2025-03-13 17:14:45 -04:00
if (enumPlayerData == EnumPlayerData.Bank) { // Bank removal
2025-02-20 00:41:45 -05:00
playerdata.bankData.banks.remove(value);
}
2025-03-13 17:14:45 -04:00
if (enumPlayerData == EnumPlayerData.Factions) { // Faction removal
2025-02-20 00:41:45 -05:00
playerdata.factionData.factionData.remove(value);
}
2025-03-13 17:14:45 -04:00
if (enumPlayerData == EnumPlayerData.Magic) { // Faction removal
2025-03-07 16:00:06 -05:00
playerdata.magicData.removeMagic(value);
}
2025-02-20 00:41:45 -05:00
playerdata.save();
2025-03-13 17:14:45 -04:00
if (pl != null) {
2025-02-20 00:41:45 -05:00
SyncController.syncPlayer((EntityPlayerMP) pl);
}
}
2025-03-07 16:00:06 -05:00
/**
* Removes a specific data entry from the player's data.
2025-03-13 17:14:45 -04:00
* <p>
2025-03-07 16:00:06 -05:00
* The tabType parameter is used as follows:
2025-03-13 17:14:45 -04:00
* 0: Quest – remove from both activeQuests and finishedQuests.
* 1: Dialog – remove from dialogsRead.
* 2: Transport – remove from transports.
* 3: Bank – remove from banks.
* 4: Factions – remove from factionData.
* <p>
2025-03-07 16:00:06 -05:00
* The selectedKey is expected to be the string representation of the entry's ID.
*/
public static void savePlayerDataInfo(String playerName, int tabType, NBTTagCompound compound, EntityPlayerMP player) {
EntityPlayer pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(playerName);
PlayerData playerdata;
EnumPlayerData enumPlayerData = EnumPlayerData.values()[tabType];
2025-03-13 17:14:45 -04:00
if (pl == null)
2025-03-07 16:00:06 -05:00
playerdata = PlayerDataController.Instance.getDataFromUsername(playerName);
else
playerdata = PlayerData.get(pl);
2025-03-07 16:00:06 -05:00
2025-03-13 17:14:45 -04:00
if (enumPlayerData == EnumPlayerData.Magic) { // Quest removal
2025-03-07 16:00:06 -05:00
playerdata.magicData.readToNBT(compound);
}
playerdata.save();
2025-03-13 17:14:45 -04:00
if (pl != null) {
2025-03-07 16:00:06 -05:00
SyncController.syncPlayer((EntityPlayerMP) pl);
}
}
2018-09-13 12:03:28 -04:00
}