mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-22 18:59:49 +00:00
-Parties: Kicking, inviting players, setting a leader, friendly fire toggle, and leaving a party are all functional over packets
-Created a new type of achievement that uses the bag icon, used for party messages
This commit is contained in:
1 parent
32d9869d43
commit
4abbb62e69
11 files changed
+224
-73
No files matched your search
@@ -2,6 +2,7 @@ package noppes.npcs.controllers.data;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -27,7 +28,6 @@ public class Party {
|
||||
private final ArrayList<UUID> partyOrder = new ArrayList<>();
|
||||
|
||||
private int currentQuestID = -1;
|
||||
|
||||
private boolean friendlyFire;
|
||||
|
||||
//Client-sided
|
||||
@@ -66,12 +66,10 @@ public class Party {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean removePlayer(String playerName) {
|
||||
UUID uuid = getUUID(playerName);
|
||||
if (uuid == null){
|
||||
return false;
|
||||
}
|
||||
public boolean removePlayer(EntityPlayer player) {
|
||||
if (player == null) return false;
|
||||
|
||||
UUID uuid = player.getUniqueID();
|
||||
if(partyMembers.containsKey(uuid)){
|
||||
partyMembers.remove(uuid);
|
||||
partyOrder.remove(uuid);
|
||||
@@ -88,22 +86,8 @@ public class Party {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean removePlayer(EntityPlayer player) {
|
||||
UUID uuid = player.getUniqueID();
|
||||
if(partyMembers.containsKey(uuid)){
|
||||
partyMembers.remove(uuid);
|
||||
partyOrder.remove(uuid);
|
||||
|
||||
if(uuid.equals(partyLeader)){
|
||||
if(partyMembers.size() > 0){
|
||||
partyLeader = partyOrder.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
public boolean removePlayer(String playerName) {
|
||||
return playerName != null && this.removePlayer(NoppesUtilServer.getPlayerByName(playerName));
|
||||
}
|
||||
|
||||
public boolean hasPlayer(EntityPlayer player) {
|
||||
@@ -149,7 +133,20 @@ public class Party {
|
||||
}
|
||||
|
||||
public Collection<String> getPlayerNames() {
|
||||
return this.partyMembers.values();
|
||||
return this.getPlayerNames(false);
|
||||
}
|
||||
|
||||
public Collection<String> getPlayerNames(boolean lowercase) {
|
||||
Collection<String> names = this.partyMembers.values();
|
||||
if (!lowercase) {
|
||||
return names;
|
||||
}
|
||||
|
||||
ArrayList<String> lowerNames = new ArrayList<>();
|
||||
for (String s : names) {
|
||||
lowerNames.add(s.toLowerCase());
|
||||
}
|
||||
return lowerNames;
|
||||
}
|
||||
|
||||
public Collection<UUID> getPlayerUUIDs() {
|
||||
@@ -215,6 +212,7 @@ public class Party {
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
this.partyLeaderName = compound.getString("PartyLeader");
|
||||
this.currentQuestID = compound.getInteger("PartyQuestID");
|
||||
this.friendlyFire = compound.getBoolean("FriendlyFire");
|
||||
|
||||
NBTTagList list = compound.getTagList("PartyMembers", 10);
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
@@ -231,7 +229,8 @@ public class Party {
|
||||
|
||||
compound.setString("PartyUUID", this.partyUUID.toString());
|
||||
compound.setInteger("PartyQuestID", this.currentQuestID);
|
||||
compound.setString("PartyLeader", getPartyLeader().getCommandSenderName());
|
||||
compound.setBoolean("FriendlyFire", this.friendlyFire);
|
||||
|
||||
NBTTagList list = new NBTTagList();
|
||||
for (UUID uuid : this.partyOrder) {
|
||||
NBTTagCompound uuidCompound = new NBTTagCompound();
|
||||
@@ -241,6 +240,25 @@ public class Party {
|
||||
}
|
||||
compound.setTag("PartyMembers", list);
|
||||
|
||||
compound.setString("PartyLeader", getPartyLeader().getCommandSenderName());
|
||||
Quest quest = (Quest) QuestController.Instance.get(this.getCurrentQuestID());
|
||||
if (quest != null) {
|
||||
compound.setString("QuestName", quest.getName());
|
||||
compound.setString("QuestCategory", quest.getCategory().getName());
|
||||
}
|
||||
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void readClientNBT(NBTTagCompound compound) {
|
||||
this.currentQuestID = compound.getInteger("PartyQuestID");
|
||||
this.friendlyFire = compound.getBoolean("FriendlyFire");
|
||||
}
|
||||
|
||||
public NBTTagCompound writeClientNBT() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setInteger("PartyQuestID", this.currentQuestID);
|
||||
compound.setBoolean("FriendlyFire", this.friendlyFire);
|
||||
return compound;
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,17 @@ package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IExtendedEntityProperties;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.api.handler.*;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.EnumRoleType;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
import noppes.npcs.entity.EntityCustomNpc;
|
||||
@@ -24,6 +27,7 @@ import noppes.npcs.util.NBTJsonUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
@@ -41,7 +45,9 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
|
||||
public EntityNPCInterface editingNpc;
|
||||
public NBTTagCompound cloned;
|
||||
|
||||
public UUID partyUUID = null;
|
||||
private final HashSet<UUID> partyInvites = new HashSet<>();
|
||||
|
||||
public EntityPlayer player;
|
||||
|
||||
@@ -55,6 +61,15 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
|
||||
public ScreenSize screenSize = new ScreenSize(-1,-1);
|
||||
|
||||
public void onLogin() {
|
||||
|
||||
}
|
||||
|
||||
public void onLogout() {
|
||||
this.partyUUID = null;
|
||||
this.partyInvites.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveNBTData(NBTTagCompound nbtTagCompound) {
|
||||
}
|
||||
@@ -128,7 +143,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
|
||||
@Override
|
||||
public void init(Entity entity, World world) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void setGUIOpen(boolean bool) {
|
||||
@@ -180,6 +195,14 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
world.spawnEntityInWorld(npc);
|
||||
}
|
||||
|
||||
public void inviteToParty(Party party) {
|
||||
if (party != null && this.partyUUID == null && !this.partyInvites.contains(party.getPartyUUID())) {
|
||||
this.partyInvites.add(party.getPartyUUID());
|
||||
Server.sendData((EntityPlayerMP)this.player, EnumPacketClient.PARTY_MESSAGE, "party.inviteAlert", party.getPartyLeader().getCommandSenderName());
|
||||
Server.sendData((EntityPlayerMP)this.player, EnumPacketClient.CHAT, "party.inviteChat", " ", party.getPartyLeader().getCommandSenderName(), "!");
|
||||
}
|
||||
}
|
||||
|
||||
public void setCompanion(ICustomNpc npc) {
|
||||
this.setCompanion((EntityNPCInterface) npc.getMCEntity());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user