mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-16 16:34:46 +00:00
Add Insane Sync Data Control from BACK in the BROKEN 1.9 BETA >:D
This commit is contained in:
1 parent
d225122016
commit
dd7a0b7f12
25 files changed
+435
-79
No files matched your search
@@ -85,7 +85,7 @@ public class CmdDialog extends ChMcLogger {
|
||||
permissions={OpOnly.class}
|
||||
)
|
||||
public boolean reload(String args[]){
|
||||
new DialogController();
|
||||
new DialogController().load();;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ public class CmdQuest extends ChMcLogger{
|
||||
permissions={OpOnly.class}
|
||||
)
|
||||
public boolean reload(String args[]){
|
||||
new DialogController();
|
||||
new QuestController().load();;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,14 @@ import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.client.EntityUtil;
|
||||
import noppes.npcs.constants.EnumAvailabilityDialog;
|
||||
import noppes.npcs.constants.EnumAvailabilityQuest;
|
||||
import noppes.npcs.controllers.DialogController;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
import noppes.npcs.controllers.SyncController;
|
||||
import noppes.npcs.controllers.data.Availability;
|
||||
import noppes.npcs.controllers.data.Dialog;
|
||||
import noppes.npcs.controllers.data.DialogOption;
|
||||
@@ -85,7 +87,8 @@ public class DialogCommand extends CommandKamkeelBase {
|
||||
permission = 4
|
||||
)
|
||||
public void reload(ICommandSender sender, String args[]){
|
||||
new DialogController();
|
||||
new DialogController().load();
|
||||
SyncController.syncAllDialogs();
|
||||
sendResult(sender, "Dialogs Reloaded");
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import noppes.npcs.constants.EnumQuestCompletion;
|
||||
import noppes.npcs.constants.EnumQuestRepeat;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.SyncController;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.controllers.data.Quest;
|
||||
import noppes.npcs.controllers.data.QuestData;
|
||||
@@ -284,8 +285,8 @@ public class QuestCommand extends CommandKamkeelBase {
|
||||
permission = 4
|
||||
)
|
||||
public void reload(ICommandSender sender, String args[]){
|
||||
new QuestController();
|
||||
QuestController.Instance.load();
|
||||
new QuestController().load();
|
||||
SyncController.syncAllQuests();
|
||||
sendResult(sender, "Quests Reloaded");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,8 @@ public class CustomNpcs {
|
||||
|
||||
public static LegacyConfig legacyConfig;
|
||||
|
||||
public static MinecraftServer Server;
|
||||
|
||||
public CustomNpcs() {
|
||||
instance = this;
|
||||
}
|
||||
@@ -192,10 +194,11 @@ public class CustomNpcs {
|
||||
|
||||
@EventHandler
|
||||
public void setAboutToStart(FMLServerAboutToStartEvent event) {
|
||||
Server = event.getServer();
|
||||
ChunkController.Instance.clear();
|
||||
new QuestController();
|
||||
FactionController.getInstance().load();
|
||||
// VisibilityController.instance = new VisibilityController();
|
||||
new PlayerDataController();
|
||||
new FactionController();
|
||||
new TagController();
|
||||
new TransportController();
|
||||
new GlobalDataController();
|
||||
@@ -229,8 +232,8 @@ public class CustomNpcs {
|
||||
@EventHandler
|
||||
public void started(FMLServerStartedEvent event) {
|
||||
RecipeController.Instance.load();
|
||||
new DialogController();
|
||||
new BankController();
|
||||
DialogController.Instance.load();
|
||||
QuestController.Instance.load();
|
||||
ScriptController.HasStart = true;
|
||||
ServerCloneController.Instance = new ServerCloneController();
|
||||
|
||||
@@ -172,6 +172,7 @@ public class NoppesUtilServer {
|
||||
|
||||
public static void openDialog(EntityPlayer player, EntityNPCInterface npc, Dialog dia, int optionId){
|
||||
Dialog dialog = dia.copy(player);
|
||||
PlayerData playerdata = PlayerData.get(player);
|
||||
|
||||
if (!npc.isRemote()) {
|
||||
if (EventHooks.onNPCDialog(npc, player, dialog.id, optionId, dialog)) {
|
||||
@@ -197,8 +198,10 @@ public class NoppesUtilServer {
|
||||
if(dialog.mail.isValid())
|
||||
PlayerDataController.Instance.addPlayerMessage(player.getCommandSenderName(), dialog.mail);
|
||||
PlayerDialogData data = PlayerDataController.Instance.getPlayerData(player).dialogData;
|
||||
if(!data.dialogsRead.contains(dialog.id))
|
||||
data.dialogsRead.add(dialog.id);
|
||||
if(!data.dialogsRead.contains(dialog.id) && dialog.id >= 0){
|
||||
data.dialogsRead.add(dialog.id);
|
||||
playerdata.updateClient = true;
|
||||
}
|
||||
setEditingNpc(player, npc);
|
||||
}
|
||||
public static void runCommand(EntityPlayer player, String name, String command){
|
||||
@@ -550,6 +553,9 @@ public class NoppesUtilServer {
|
||||
data.factionData.remove(buffer.readInt());
|
||||
playerdata.save();
|
||||
}
|
||||
if(pl != null) {
|
||||
SyncController.syncPlayer((EntityPlayerMP) pl);
|
||||
}
|
||||
sendPlayerData(type, player, name);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,9 @@ import net.minecraftforge.event.entity.living.*;
|
||||
import net.minecraftforge.event.entity.player.*;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.EnumQuestType;
|
||||
import noppes.npcs.constants.SyncType;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
@@ -66,6 +68,12 @@ public class ScriptPlayerEventHandler {
|
||||
if (PlayerDataController.Instance != null) {
|
||||
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
|
||||
|
||||
if(playerData.updateClient) {
|
||||
Server.sendData((EntityPlayerMP)player, EnumPacketClient.SYNC_END, SyncType.PLAYER_DATA, playerData.getSyncNBT());
|
||||
// VisibilityController.instance.onUpdate((EntityPlayerMP) player);
|
||||
playerData.updateClient = false;
|
||||
}
|
||||
|
||||
if (playerData.timers.size() > 0) {
|
||||
playerData.timers.update();
|
||||
}
|
||||
@@ -517,4 +525,4 @@ public class ScriptPlayerEventHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -318,7 +318,7 @@ public class ServerEventsHandler {
|
||||
}
|
||||
|
||||
private void doQuest(EntityPlayer player, EntityLivingBase entity, boolean all) {
|
||||
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
PlayerQuestData questData = playerData.questData;
|
||||
boolean checkCompletion = false;
|
||||
String entityName = EntityList.getEntityString(entity);
|
||||
@@ -385,6 +385,7 @@ public class ServerEventsHandler {
|
||||
killed.put(name, amount + 1);
|
||||
}
|
||||
quest.setKilled(data, killed);
|
||||
playerData.updateClient = true;
|
||||
}
|
||||
if(!checkCompletion)
|
||||
return;
|
||||
@@ -393,10 +394,14 @@ public class ServerEventsHandler {
|
||||
}
|
||||
|
||||
private void doPartyQuest(EntityPlayer player, Party party, EntityLivingBase entity){
|
||||
PlayerData pdata = PlayerData.get(player);
|
||||
QuestData data = party.getQuestData();
|
||||
if(data == null)
|
||||
return;
|
||||
|
||||
if(pdata == null)
|
||||
return;
|
||||
|
||||
if (data.quest.type != EnumQuestType.Kill && data.quest.type != EnumQuestType.AreaKill)
|
||||
return;
|
||||
|
||||
@@ -441,6 +446,7 @@ public class ServerEventsHandler {
|
||||
killed.put(name, amount + 1);
|
||||
}
|
||||
quest.setKilled(data, killed);
|
||||
pdata.updateClient = true;
|
||||
}
|
||||
|
||||
PartyController.Instance().pingPartyQuestObjectiveUpdate(party);
|
||||
|
||||
@@ -4,10 +4,12 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import noppes.npcs.client.AnalyticsTracking;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
import noppes.npcs.controllers.SyncController;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
|
||||
import java.net.InetAddress;
|
||||
@@ -20,11 +22,12 @@ public class ServerTickHandler {
|
||||
NPCSpawning.findChunksForSpawning((WorldServer) event.world);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String serverName = null;
|
||||
|
||||
@SubscribeEvent
|
||||
public void playerLogin(PlayerEvent.PlayerLoggedInEvent event){
|
||||
EntityPlayerMP player = (EntityPlayerMP) event.player;
|
||||
if(serverName == null){
|
||||
String e = "local";
|
||||
MinecraftServer server = MinecraftServer.getServer();
|
||||
@@ -47,6 +50,8 @@ public class ServerTickHandler {
|
||||
if (playerData != null) {
|
||||
playerData.onLogin();
|
||||
}
|
||||
|
||||
SyncController.syncPlayer(player);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -55,7 +55,7 @@ public class NoppesUtil {
|
||||
float height = buffer.readFloat();
|
||||
float width = buffer.readFloat();
|
||||
float yOffset = buffer.readFloat();
|
||||
|
||||
|
||||
String particle = Server.readString(buffer);
|
||||
World worldObj = Minecraft.getMinecraft().theWorld;
|
||||
|
||||
@@ -121,7 +121,7 @@ public class NoppesUtil {
|
||||
}
|
||||
|
||||
public static void clickSound() {
|
||||
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
||||
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
||||
}
|
||||
|
||||
private static EntityNPCInterface lastNpc;
|
||||
@@ -135,7 +135,7 @@ public class NoppesUtil {
|
||||
public static void openGUI(EntityPlayer player, Object guiscreen) {
|
||||
CustomNpcs.proxy.openGui(player, guiscreen);
|
||||
}
|
||||
|
||||
|
||||
public static void openFolder(File dir){
|
||||
String s = dir.getAbsolutePath();
|
||||
|
||||
@@ -196,19 +196,19 @@ public class NoppesUtil {
|
||||
return;
|
||||
Vector<String> data = new Vector<String>();
|
||||
String line;
|
||||
|
||||
|
||||
try {
|
||||
int size = buffer.readInt();
|
||||
for(int i = 0; i < size; i++){
|
||||
data.add(Server.readString(buffer));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
((IScrollData)gui).setData(data,null);
|
||||
}
|
||||
|
||||
|
||||
private static HashMap<String,Integer> data = new HashMap<String,Integer>();
|
||||
private static HashMap<String,Integer> group = new HashMap<String,Integer>();
|
||||
|
||||
@@ -259,7 +259,7 @@ public class NoppesUtil {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void setScrollData(ByteBuf buffer) {
|
||||
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
|
||||
if(gui == null)
|
||||
@@ -291,10 +291,8 @@ public class NoppesUtil {
|
||||
NoppesUtil.openGUI(player, new GuiQuestCompletion(quest));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void openDialog(NBTTagCompound compound, EntityNPCInterface npc, EntityPlayer player){
|
||||
if(DialogController.Instance == null)
|
||||
DialogController.Instance = new DialogController();
|
||||
Dialog dialog = new Dialog();
|
||||
dialog.readNBT(compound);
|
||||
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
|
||||
@@ -309,20 +307,20 @@ public class NoppesUtil {
|
||||
int x = compound.getInteger("x");
|
||||
int y = compound.getInteger("y");
|
||||
int z = compound.getInteger("z");
|
||||
|
||||
|
||||
TileEntity tile = player.worldObj.getTileEntity(x, y, z);
|
||||
tile.readFromNBT(compound);
|
||||
|
||||
|
||||
CustomNpcs.proxy.openGui(x, y, z, EnumGuiType.RedstoneBlock, player);
|
||||
}
|
||||
public static void saveWayPointBlock(EntityPlayer player, NBTTagCompound compound){
|
||||
int x = compound.getInteger("x");
|
||||
int y = compound.getInteger("y");
|
||||
int z = compound.getInteger("z");
|
||||
|
||||
|
||||
TileEntity tile = player.worldObj.getTileEntity(x, y, z);
|
||||
tile.readFromNBT(compound);
|
||||
|
||||
|
||||
CustomNpcs.proxy.openGui(x, y, z, EnumGuiType.Waypoint, player);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,16 +33,20 @@ import noppes.npcs.config.ConfigClient;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.EnumPacketServer;
|
||||
import noppes.npcs.constants.SyncType;
|
||||
import noppes.npcs.controllers.RecipeController;
|
||||
import noppes.npcs.controllers.SyncController;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.controllers.data.AnimationData;
|
||||
import noppes.npcs.controllers.data.MarkData;
|
||||
import noppes.npcs.controllers.data.RecipeCarpentry;
|
||||
import noppes.npcs.entity.EntityDialogNpc;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.items.ItemScripted;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PacketHandlerClient extends PacketHandlerServer{
|
||||
|
||||
@@ -105,6 +109,27 @@ public class PacketHandlerClient extends PacketHandlerServer{
|
||||
RecipeController.Instance.anvilRecipes = RecipeController.syncRecipes;
|
||||
RecipeController.syncRecipes = new HashMap<Integer, RecipeCarpentry>();
|
||||
}
|
||||
else if(type == EnumPacketClient.SYNC_ADD || type == EnumPacketClient.SYNC_END){
|
||||
int synctype = buffer.readInt();
|
||||
NBTTagCompound compound = Server.readNBT(buffer);
|
||||
|
||||
SyncController.clientSync(synctype, compound, type == EnumPacketClient.SYNC_END);
|
||||
|
||||
if(synctype == SyncType.PLAYER_DATA){
|
||||
ClientProxy.playerData.setNBT(compound);
|
||||
}
|
||||
}
|
||||
else if(type == EnumPacketClient.SYNC_UPDATE){
|
||||
int synctype = buffer.readInt();
|
||||
NBTTagCompound compound = Server.readNBT(buffer);
|
||||
SyncController.clientSyncUpdate(synctype, compound, buffer);
|
||||
}
|
||||
else if(type == EnumPacketClient.SYNC_REMOVE){
|
||||
int synctype = buffer.readInt();
|
||||
int id = buffer.readInt();
|
||||
|
||||
SyncController.clientSyncRemove(synctype, id);
|
||||
}
|
||||
else if(type == EnumPacketClient.MARK_DATA){
|
||||
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(buffer.readInt());
|
||||
if(!(entity instanceof EntityNPCInterface))
|
||||
|
||||
@@ -55,5 +55,6 @@ public enum EnumPacketClient {
|
||||
STOP_SOUNDS,
|
||||
SYNC_WEAPON,
|
||||
MARK_DATA,
|
||||
SYNC_ADD, SYNC_END, SYNC_UPDATE, SYNC_REMOVE,
|
||||
PARTY_DATA
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package noppes.npcs.constants;
|
||||
|
||||
public class SyncType {
|
||||
public static final int FACTION = 1;
|
||||
public static final int QUEST = 2;
|
||||
public static final int QUEST_CATEGORY = 3;
|
||||
public static final int DIALOG = 4;
|
||||
public static final int DIALOG_CATEGORY = 5;
|
||||
public static final int RECIPE_NORMAL = 6;
|
||||
public static final int RECIPE_CARPENTRY = 7;
|
||||
public static final int PLAYER_DATA = 8;
|
||||
}
|
||||
@@ -6,10 +6,13 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.NoppesStringUtils;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.api.handler.IDialogHandler;
|
||||
import noppes.npcs.api.handler.data.IDialog;
|
||||
import noppes.npcs.api.handler.data.IDialogCategory;
|
||||
import noppes.npcs.constants.EnumOptionType;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.SyncType;
|
||||
import noppes.npcs.controllers.data.Dialog;
|
||||
import noppes.npcs.controllers.data.DialogCategory;
|
||||
import noppes.npcs.controllers.data.DialogOption;
|
||||
@@ -20,31 +23,31 @@ import java.io.FileInputStream;
|
||||
import java.util.*;
|
||||
|
||||
public class DialogController implements IDialogHandler {
|
||||
public HashMap<Integer,DialogCategory> categoriesSync = new HashMap<Integer, DialogCategory>();
|
||||
public HashMap<Integer,DialogCategory> categories = new HashMap<Integer, DialogCategory>();
|
||||
public HashMap<Integer,Dialog> dialogs = new HashMap<Integer, Dialog>();
|
||||
public static DialogController Instance;
|
||||
public static DialogController Instance = new DialogController();;
|
||||
|
||||
private int lastUsedDialogID = 0;
|
||||
private int lastUsedCatID = 0;
|
||||
|
||||
|
||||
public DialogController(){
|
||||
Instance = this;
|
||||
load();
|
||||
}
|
||||
|
||||
|
||||
public void load(){
|
||||
LogWriter.info("Loading Dialogs");
|
||||
loadCategories();
|
||||
LogWriter.info("Done loading Dialogs");
|
||||
}
|
||||
|
||||
|
||||
private void loadCategories(){
|
||||
categories.clear();
|
||||
dialogs.clear();
|
||||
|
||||
lastUsedCatID = 0;
|
||||
lastUsedDialogID = 0;
|
||||
|
||||
|
||||
try {
|
||||
File file = new File(CustomNpcs.getWorldSaveDirectory(), "dialog.dat");
|
||||
if(file.exists()){
|
||||
@@ -118,7 +121,7 @@ public class DialogController implements IDialogHandler {
|
||||
NBTTagList list = nbttagcompound1.getTagList("Data", 10);
|
||||
if(list == null)
|
||||
return;
|
||||
|
||||
|
||||
for(int i = 0; i < list.tagCount(); i++){
|
||||
DialogCategory category = new DialogCategory();
|
||||
category.readNBT(list.getCompoundTagAt(i));
|
||||
@@ -135,7 +138,7 @@ public class DialogController implements IDialogHandler {
|
||||
saveDialog(category.id, dialog);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,35 +146,35 @@ public class DialogController implements IDialogHandler {
|
||||
DialogCategory cat = new DialogCategory();
|
||||
cat.id = lastUsedCatID++;
|
||||
cat.title = "Villager";
|
||||
|
||||
|
||||
Dialog dia1 = new Dialog();
|
||||
dia1.id = 1;
|
||||
dia1.category = cat;
|
||||
dia1.title = "Start";
|
||||
dia1.text = "Hello {player}, "+'\n'+'\n'+"Welcome to our village. I hope you enjoy your stay";
|
||||
|
||||
|
||||
Dialog dia2 = new Dialog();
|
||||
dia2.id = 2;
|
||||
dia2.category = cat;
|
||||
dia2.title = "Ask about village";
|
||||
dia2.text = "This village has been around for ages. Enjoy your stay here.";
|
||||
|
||||
|
||||
Dialog dia3 = new Dialog();
|
||||
dia3.id = 3;
|
||||
dia3.category = cat;
|
||||
dia3.title = "Who are you";
|
||||
dia3.text = "I'm a villager here. I have lived in this village my whole life.";
|
||||
|
||||
|
||||
cat.dialogs.put(dia1.id, dia1);
|
||||
cat.dialogs.put(dia2.id, dia2);
|
||||
cat.dialogs.put(dia3.id, dia3);
|
||||
|
||||
|
||||
|
||||
DialogOption option = new DialogOption();
|
||||
option.title = "Tell me something about this village";
|
||||
option.dialogId = 2;
|
||||
option.optionType = EnumOptionType.DialogOption;
|
||||
|
||||
|
||||
DialogOption option2 = new DialogOption();
|
||||
option2.title = "Who are you?";
|
||||
option2.dialogId = 3;
|
||||
@@ -180,11 +183,11 @@ public class DialogController implements IDialogHandler {
|
||||
DialogOption option3 = new DialogOption();
|
||||
option3.title = "Goodbye";
|
||||
option3.optionType = EnumOptionType.QuitOption;
|
||||
|
||||
|
||||
dia1.options.put(0, option2);
|
||||
dia1.options.put(1, option);
|
||||
dia1.options.put(2, option3);
|
||||
|
||||
|
||||
|
||||
DialogOption option4 = new DialogOption();
|
||||
option4.title = "Back";
|
||||
@@ -198,7 +201,7 @@ public class DialogController implements IDialogHandler {
|
||||
saveDialog(cat.id, dia2);
|
||||
saveDialog(cat.id, dia3);
|
||||
}
|
||||
|
||||
|
||||
public void saveCategory(DialogCategory category){
|
||||
category.title = NoppesStringUtils.cleanFileName(category.title);
|
||||
if(categories.containsKey(category.id)){
|
||||
@@ -227,8 +230,9 @@ public class DialogController implements IDialogHandler {
|
||||
dir.mkdirs();
|
||||
}
|
||||
categories.put(category.id, category);
|
||||
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.DIALOG_CATEGORY, category.writeNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
|
||||
public void removeCategory(int category){
|
||||
DialogCategory cat = categories.get(category);
|
||||
if(cat == null)
|
||||
@@ -239,8 +243,9 @@ public class DialogController implements IDialogHandler {
|
||||
for(int dia : cat.dialogs.keySet())
|
||||
dialogs.remove(dia);
|
||||
categories.remove(category);
|
||||
Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.DIALOG_CATEGORY, category);
|
||||
}
|
||||
|
||||
|
||||
private boolean containsCategoryName(String name) {
|
||||
name = name.toLowerCase();
|
||||
for(DialogCategory cat : categories.values()){
|
||||
@@ -269,28 +274,30 @@ public class DialogController implements IDialogHandler {
|
||||
lastUsedDialogID++;
|
||||
dialog.id = lastUsedDialogID;
|
||||
}
|
||||
|
||||
|
||||
dialogs.put(dialog.id, dialog);
|
||||
category.dialogs.put(dialog.id, dialog);
|
||||
|
||||
|
||||
File dir = new File(getDir(), category.title);
|
||||
if(!dir.exists())
|
||||
dir.mkdirs();
|
||||
|
||||
File file = new File(dir, dialog.id + ".json_new");
|
||||
File file2 = new File(dir, dialog.id + ".json");
|
||||
|
||||
|
||||
try {
|
||||
NBTJsonUtil.SaveFile(file, dialog.writeToNBTPartial(new NBTTagCompound()));
|
||||
NBTTagCompound compound = dialog.writeToNBT(new NBTTagCompound());
|
||||
NBTJsonUtil.SaveFile(file, compound);
|
||||
if(file2.exists())
|
||||
file2.delete();
|
||||
file.renameTo(file2);
|
||||
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.DIALOG, compound, category.id);
|
||||
} catch (Exception e) {
|
||||
LogWriter.except(e);
|
||||
}
|
||||
return dialog;
|
||||
}
|
||||
|
||||
|
||||
public void removeDialog(Dialog dialog) {
|
||||
DialogCategory category = dialog.category;
|
||||
File file = new File(new File(getDir(), category.title), dialog.id + ".json");
|
||||
@@ -298,9 +305,9 @@ public class DialogController implements IDialogHandler {
|
||||
return;
|
||||
category.dialogs.remove(dialog.id);
|
||||
dialogs.remove(dialog.id);
|
||||
|
||||
Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.DIALOG, dialog.id);
|
||||
}
|
||||
|
||||
|
||||
private File getDir(){
|
||||
return new File(CustomNpcs.getWorldSaveDirectory(), "dialogs");
|
||||
}
|
||||
|
||||
@@ -5,8 +5,11 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.api.handler.IFactionHandler;
|
||||
import noppes.npcs.api.handler.data.IFaction;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.SyncType;
|
||||
import noppes.npcs.controllers.data.Faction;
|
||||
|
||||
import java.io.*;
|
||||
@@ -17,22 +20,16 @@ import java.util.Map;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class FactionController implements IFactionHandler {
|
||||
public HashMap<Integer,Faction> factionsSync = new HashMap<Integer,Faction>();
|
||||
public HashMap<Integer,Faction> factions;
|
||||
|
||||
private static FactionController instance;
|
||||
private static FactionController instance = new FactionController();
|
||||
|
||||
private int lastUsedID = 0;
|
||||
|
||||
public FactionController(){
|
||||
instance = this;
|
||||
factions = new HashMap<Integer, Faction>();
|
||||
loadFactions();
|
||||
if(factions.isEmpty()){
|
||||
factions.put(0,new Faction(0,"Friendly", 0x00DD00, 2000));
|
||||
factions.put(1,new Faction(1,"Neutral", 0xF2DD00, 1000));
|
||||
factions.put(2,new Faction(2,"Aggressive", 0xDD0000, 0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static FactionController getInstance(){
|
||||
@@ -43,7 +40,7 @@ public class FactionController implements IFactionHandler {
|
||||
return factions.get(faction);
|
||||
}
|
||||
|
||||
private void loadFactions(){
|
||||
public void load(){
|
||||
|
||||
File saveDir = CustomNpcs.getWorldSaveDirectory();
|
||||
if(saveDir == null){
|
||||
@@ -64,6 +61,12 @@ public class FactionController implements IFactionHandler {
|
||||
} catch (Exception ee) {
|
||||
}
|
||||
}
|
||||
|
||||
if(factions.isEmpty()){
|
||||
factions.put(0,new Faction(0,"Friendly", 0x00DD00, 2000));
|
||||
factions.put(1,new Faction(1,"Neutral", 0xF2DD00, 1000));
|
||||
factions.put(2,new Faction(2,"Aggressive", 0xDD0000, 0));
|
||||
}
|
||||
}
|
||||
|
||||
private void loadFactionsFile(File file) throws IOException{
|
||||
@@ -151,6 +154,10 @@ public class FactionController implements IFactionHandler {
|
||||
}
|
||||
factions.remove(faction.id);
|
||||
factions.put(faction.id, faction);
|
||||
|
||||
NBTTagCompound facCompound = new NBTTagCompound();
|
||||
faction.writeNBT(facCompound);
|
||||
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.FACTION, facCompound);
|
||||
saveFactions();
|
||||
}
|
||||
|
||||
@@ -185,6 +192,7 @@ public class FactionController implements IFactionHandler {
|
||||
} else {
|
||||
this.saveFactions();
|
||||
faction.id = -1;
|
||||
Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.FACTION, id);
|
||||
return faction;
|
||||
}
|
||||
} else {
|
||||
@@ -206,7 +214,7 @@ public class FactionController implements IFactionHandler {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public Faction getFactionFromName(String factioname){
|
||||
for (Map.Entry<Integer,Faction>entryfaction:FactionController.getInstance().factions.entrySet()){
|
||||
if (entryfaction.getValue().name.equalsIgnoreCase(factioname)){
|
||||
|
||||
@@ -33,7 +33,8 @@ public class PlayerQuestController {
|
||||
}
|
||||
|
||||
public static void addActiveQuest(QuestData questData, EntityPlayer player) {
|
||||
PlayerQuestData data = PlayerDataController.Instance.getPlayerData(player).questData;
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
PlayerQuestData data = playerData.questData;
|
||||
if(canQuestBeAccepted(questData.quest, player)){
|
||||
if (EventHooks.onQuestStarted(player, questData.quest)) {
|
||||
return;
|
||||
@@ -44,6 +45,7 @@ public class PlayerQuestController {
|
||||
Server.sendData((EntityPlayerMP) player, EnumPacketClient.MESSAGE, "quest.newquest", questData.quest.title);
|
||||
Server.sendData((EntityPlayerMP) player, EnumPacketClient.CHAT, "quest.newquest", ": ", questData.quest.title);
|
||||
}
|
||||
playerData.updateClient = true;
|
||||
} else {
|
||||
long timeUntilRepeat = questData.quest.getTimeUntilRepeat(player);
|
||||
if (timeUntilRepeat > 0 && questData.quest.getIsRepeatable() && questData.quest.repeat != EnumQuestRepeat.NONE && questData.quest.repeat != EnumQuestRepeat.REPEATABLE) {
|
||||
@@ -74,6 +76,7 @@ public class PlayerQuestController {
|
||||
Server.sendData((EntityPlayerMP) player, EnumPacketClient.MESSAGE, "quest.completed", questData.quest.title);
|
||||
Server.sendData((EntityPlayerMP) player, EnumPacketClient.CHAT, "quest.completed", ": ", questData.quest.title);
|
||||
}
|
||||
playerdata.updateClient = true;
|
||||
}
|
||||
|
||||
public static void setQuestPartyFinished(Quest quest, EntityPlayer player, QuestData questData ){
|
||||
@@ -95,6 +98,7 @@ public class PlayerQuestController {
|
||||
Server.sendData((EntityPlayerMP) player, EnumPacketClient.MESSAGE, "quest.completed", questData.quest.title);
|
||||
Server.sendData((EntityPlayerMP) player, EnumPacketClient.CHAT, "quest.completed", ": ", questData.quest.title);
|
||||
}
|
||||
playerdata.updateClient = true;
|
||||
}
|
||||
|
||||
public static boolean canQuestBeAccepted(Quest quest, EntityPlayer player){
|
||||
|
||||
@@ -6,9 +6,12 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.NoppesStringUtils;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.api.handler.IQuestHandler;
|
||||
import noppes.npcs.api.handler.data.IQuest;
|
||||
import noppes.npcs.api.handler.data.IQuestCategory;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.SyncType;
|
||||
import noppes.npcs.controllers.data.Quest;
|
||||
import noppes.npcs.controllers.data.QuestCategory;
|
||||
import noppes.npcs.util.NBTJsonUtil;
|
||||
@@ -18,10 +21,11 @@ import java.io.FileInputStream;
|
||||
import java.util.*;
|
||||
|
||||
public class QuestController implements IQuestHandler {
|
||||
public HashMap<Integer,QuestCategory> categoriesSync = new HashMap<Integer, QuestCategory>();
|
||||
public HashMap<Integer,QuestCategory> categories = new HashMap<Integer, QuestCategory>();
|
||||
public HashMap<Integer,Quest> quests = new HashMap<Integer, Quest>();
|
||||
|
||||
public static QuestController Instance;
|
||||
public static QuestController Instance = new QuestController();;
|
||||
|
||||
private int lastUsedCatID = 0;
|
||||
private int lastUsedQuestID = 0;
|
||||
@@ -142,6 +146,7 @@ public class QuestController implements IQuestHandler {
|
||||
for(int dia : cat.quests.keySet())
|
||||
quests.remove(dia);
|
||||
categories.remove(category);
|
||||
Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.QUEST_CATEGORY, category);
|
||||
}
|
||||
|
||||
public void saveCategory(QuestCategory category){
|
||||
@@ -172,6 +177,7 @@ public class QuestController implements IQuestHandler {
|
||||
dir.mkdirs();
|
||||
}
|
||||
categories.put(category.id, category);
|
||||
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.QUEST_CATEGORY, category.writeNBT(new NBTTagCompound()));
|
||||
}
|
||||
private boolean containsCategoryName(String name) {
|
||||
name = name.toLowerCase();
|
||||
@@ -215,10 +221,12 @@ public class QuestController implements IQuestHandler {
|
||||
File file2 = new File(dir, quest.id + ".json");
|
||||
|
||||
try {
|
||||
NBTJsonUtil.SaveFile(file, quest.writeToNBTPartial(new NBTTagCompound()));
|
||||
NBTTagCompound questCompound = quest.writeToNBTPartial(new NBTTagCompound());
|
||||
NBTJsonUtil.SaveFile(file, questCompound);
|
||||
if(file2.exists())
|
||||
file2.delete();
|
||||
file.renameTo(file2);
|
||||
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.QUEST, questCompound, category.id);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -7,8 +7,11 @@ import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.api.handler.IRecipeHandler;
|
||||
import noppes.npcs.api.handler.data.IRecipe;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.SyncType;
|
||||
import noppes.npcs.controllers.data.RecipeCarpentry;
|
||||
import noppes.npcs.controllers.data.RecipesDefault;
|
||||
|
||||
@@ -26,9 +29,9 @@ public class RecipeController implements IRecipeHandler {
|
||||
|
||||
public static final int version = 1;
|
||||
public int nextId = 1;
|
||||
|
||||
|
||||
public static HashMap<Integer,RecipeCarpentry> syncRecipes = new HashMap<Integer, RecipeCarpentry>();
|
||||
|
||||
|
||||
public RecipeController(){
|
||||
Instance = this;
|
||||
}
|
||||
@@ -41,7 +44,7 @@ public class RecipeController implements IRecipeHandler {
|
||||
if(prevRecipes != null){
|
||||
list.removeAll(prevRecipes);
|
||||
}
|
||||
|
||||
|
||||
prevRecipes = new HashSet<RecipeCarpentry>();
|
||||
for(RecipeCarpentry recipe : globalRecipes.values()){
|
||||
if(recipe.isValid())
|
||||
@@ -49,7 +52,7 @@ public class RecipeController implements IRecipeHandler {
|
||||
}
|
||||
list.addAll(prevRecipes);
|
||||
}
|
||||
|
||||
|
||||
private void loadCategories(){
|
||||
File saveDir = CustomNpcs.getWorldSaveDirectory();
|
||||
try {
|
||||
@@ -139,7 +142,7 @@ public class RecipeController implements IRecipeHandler {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public RecipeCarpentry findMatchingRecipe(InventoryCrafting par1InventoryCrafting){
|
||||
for(RecipeCarpentry recipe : anvilRecipes.values()){
|
||||
if(recipe.isValid() && recipe.matches(par1InventoryCrafting,null))
|
||||
@@ -158,13 +161,13 @@ public class RecipeController implements IRecipeHandler {
|
||||
|
||||
public RecipeCarpentry saveRecipe(NBTTagCompound compound) throws IOException {
|
||||
RecipeCarpentry recipe = RecipeCarpentry.read(compound);
|
||||
|
||||
|
||||
RecipeCarpentry current = getRecipe(recipe.id);
|
||||
if(current != null && !current.name.equals(recipe.name)){
|
||||
while(containsRecipeName(recipe.name))
|
||||
recipe.name += "_";
|
||||
}
|
||||
|
||||
|
||||
if(recipe.id == -1){
|
||||
recipe.id = getUniqueId();
|
||||
while(containsRecipeName(recipe.name))
|
||||
@@ -201,8 +204,14 @@ public class RecipeController implements IRecipeHandler {
|
||||
|
||||
public RecipeCarpentry delete(int id) {
|
||||
RecipeCarpentry recipe = getRecipe(id);
|
||||
if(recipe == null)
|
||||
return null;
|
||||
globalRecipes.remove(recipe.id);
|
||||
anvilRecipes.remove(recipe.id);
|
||||
if(recipe.isGlobal)
|
||||
Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.RECIPE_NORMAL, id);
|
||||
else
|
||||
Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.RECIPE_CARPENTRY, id);
|
||||
saveCategories();
|
||||
reloadGlobalRecipes(globalRecipes);
|
||||
return recipe;
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.SyncType;
|
||||
import noppes.npcs.controllers.data.*;
|
||||
import noppes.npcs.items.ItemScripted;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class SyncController {
|
||||
|
||||
public static void syncPlayer(EntityPlayerMP player){
|
||||
NBTTagList list = new NBTTagList();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
|
||||
for(Faction faction : FactionController.getInstance().factions.values()){
|
||||
NBTTagCompound factioNBT = new NBTTagCompound();
|
||||
faction.writeNBT(factioNBT);
|
||||
list.appendTag(factioNBT);
|
||||
if(list.tagCount() > 20){
|
||||
compound = new NBTTagCompound();
|
||||
compound.setTag("Data", list);
|
||||
Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.FACTION, compound);
|
||||
list = new NBTTagList();
|
||||
}
|
||||
}
|
||||
compound = new NBTTagCompound();
|
||||
compound.setTag("Data", list);
|
||||
Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.FACTION, compound);
|
||||
|
||||
for(QuestCategory category : QuestController.Instance.categories.values()){
|
||||
Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.QUEST_CATEGORY, category.writeNBT(new NBTTagCompound()));
|
||||
}
|
||||
Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.QUEST_CATEGORY, new NBTTagCompound());
|
||||
|
||||
for(DialogCategory category : DialogController.Instance.categories.values()){
|
||||
Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.DIALOG_CATEGORY, category.writeNBT(new NBTTagCompound()));
|
||||
}
|
||||
Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.DIALOG_CATEGORY, new NBTTagCompound());
|
||||
|
||||
list = new NBTTagList();
|
||||
for(RecipeCarpentry category : RecipeController.Instance.globalRecipes.values()){
|
||||
list.appendTag(category.writeNBT());
|
||||
if(list.tagCount() > 10){
|
||||
compound = new NBTTagCompound();
|
||||
compound.setTag("Data", list);
|
||||
Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.RECIPE_NORMAL, compound);
|
||||
list = new NBTTagList();
|
||||
}
|
||||
}
|
||||
compound = new NBTTagCompound();
|
||||
compound.setTag("Data", list);
|
||||
Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.RECIPE_NORMAL, compound);
|
||||
|
||||
list = new NBTTagList();
|
||||
for(RecipeCarpentry category : RecipeController.Instance.anvilRecipes.values()){
|
||||
list.appendTag(category.writeNBT());
|
||||
if(list.tagCount() > 10){
|
||||
compound = new NBTTagCompound();
|
||||
compound.setTag("Data", list);
|
||||
Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.RECIPE_CARPENTRY, compound);
|
||||
list = new NBTTagList();
|
||||
}
|
||||
}
|
||||
compound = new NBTTagCompound();
|
||||
compound.setTag("Data", list);
|
||||
Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.RECIPE_CARPENTRY, compound);
|
||||
|
||||
PlayerData data = PlayerData.get(player);
|
||||
if(data != null)
|
||||
Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.PLAYER_DATA, data.getNBT());
|
||||
}
|
||||
|
||||
public static void syncAllDialogs() {
|
||||
for(DialogCategory category : DialogController.Instance.categories.values()){
|
||||
Server.sendToAll(EnumPacketClient.SYNC_ADD, SyncType.DIALOG_CATEGORY, category.writeNBT(new NBTTagCompound()));
|
||||
}
|
||||
Server.sendToAll(EnumPacketClient.SYNC_END, SyncType.DIALOG_CATEGORY, new NBTTagCompound());
|
||||
}
|
||||
|
||||
public static void syncAllQuests() {
|
||||
for(QuestCategory category : QuestController.Instance.categories.values()){
|
||||
Server.sendToAll(EnumPacketClient.SYNC_ADD, SyncType.QUEST_CATEGORY, category.writeNBT(new NBTTagCompound()));
|
||||
}
|
||||
Server.sendToAll(EnumPacketClient.SYNC_END, SyncType.QUEST_CATEGORY, new NBTTagCompound());
|
||||
}
|
||||
|
||||
public static void clientSync(int synctype, NBTTagCompound compound, boolean syncEnd) {
|
||||
if(synctype == SyncType.FACTION){
|
||||
NBTTagList list = compound.getTagList("Data", 10);
|
||||
for(int i = 0; i < list.tagCount(); i++)
|
||||
{
|
||||
Faction faction = new Faction();
|
||||
faction.readNBT(list.getCompoundTagAt(i));
|
||||
FactionController.getInstance().factionsSync.put(faction.id, faction);
|
||||
}
|
||||
if(syncEnd){
|
||||
FactionController.getInstance().factions = FactionController.getInstance().factionsSync;
|
||||
FactionController.getInstance().factionsSync = new HashMap<Integer, Faction>();
|
||||
}
|
||||
}
|
||||
else if(synctype == SyncType.QUEST_CATEGORY){
|
||||
if(!compound.hasNoTags()){
|
||||
QuestCategory category = new QuestCategory();
|
||||
category.readNBT(compound);
|
||||
QuestController.Instance.categoriesSync.put(category.id, category);
|
||||
}
|
||||
if(syncEnd){
|
||||
HashMap<Integer,Quest> quests = new HashMap<Integer, Quest>();
|
||||
for(QuestCategory category : QuestController.Instance.categoriesSync.values()){
|
||||
for(Quest quest : category.quests.values()){
|
||||
quests.put(quest.id, quest);
|
||||
}
|
||||
}
|
||||
QuestController.Instance.categories = QuestController.Instance.categoriesSync;
|
||||
QuestController.Instance.quests = quests;
|
||||
QuestController.Instance.categoriesSync = new HashMap<Integer, QuestCategory>();
|
||||
}
|
||||
}
|
||||
else if(synctype == SyncType.DIALOG_CATEGORY){
|
||||
if(!compound.hasNoTags()){
|
||||
DialogCategory category = new DialogCategory();
|
||||
category.readNBT(compound);
|
||||
DialogController.Instance.categoriesSync.put(category.id, category);
|
||||
}
|
||||
if(syncEnd){
|
||||
HashMap<Integer,Dialog> dialogs = new HashMap<Integer, Dialog>();
|
||||
for(DialogCategory category : DialogController.Instance.categoriesSync.values()){
|
||||
for(Dialog dialog : category.dialogs.values()){
|
||||
dialogs.put(dialog.id, dialog);
|
||||
}
|
||||
}
|
||||
DialogController.Instance.categories = DialogController.Instance.categoriesSync;
|
||||
DialogController.Instance.dialogs = dialogs;
|
||||
DialogController.Instance.categoriesSync = new HashMap<Integer, DialogCategory>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void clientSyncUpdate(int synctype, NBTTagCompound compound, ByteBuf buffer) {
|
||||
if(synctype == SyncType.FACTION){
|
||||
Faction faction = new Faction();
|
||||
faction.readNBT(compound);
|
||||
FactionController.getInstance().factions.put(faction.id, faction);
|
||||
}
|
||||
else if(synctype == SyncType.DIALOG){
|
||||
DialogCategory category = DialogController.Instance.categories.get(buffer.readInt());
|
||||
Dialog dialog = new Dialog();
|
||||
dialog.category = category;
|
||||
dialog.readNBT(compound);
|
||||
DialogController.Instance.dialogs.put(dialog.id, dialog);
|
||||
category.dialogs.put(dialog.id, dialog);
|
||||
}
|
||||
else if(synctype == SyncType.DIALOG_CATEGORY){
|
||||
DialogCategory category = new DialogCategory();
|
||||
category.readNBT(compound);
|
||||
DialogController.Instance.categories.put(category.id, category);
|
||||
}
|
||||
else if(synctype == SyncType.QUEST){
|
||||
QuestCategory category = QuestController.Instance.categories.get(buffer.readInt());
|
||||
Quest quest = new Quest();
|
||||
quest.category = category;
|
||||
quest.readNBT(compound);
|
||||
QuestController.Instance.quests.put(quest.id, quest);
|
||||
category.quests.put(quest.id, quest);
|
||||
}
|
||||
else if(synctype == SyncType.QUEST_CATEGORY){
|
||||
QuestCategory category = new QuestCategory();
|
||||
category.readNBT(compound);
|
||||
QuestController.Instance.categories.put(category.id, category);
|
||||
}
|
||||
}
|
||||
|
||||
public static void clientSyncRemove(int synctype, int id) {
|
||||
if(synctype == SyncType.FACTION){
|
||||
FactionController.getInstance().factions.remove(id);
|
||||
}
|
||||
else if(synctype == SyncType.DIALOG){
|
||||
Dialog dialog = DialogController.Instance.dialogs.remove(id);
|
||||
if(dialog != null) {
|
||||
dialog.category.dialogs.remove(id);
|
||||
}
|
||||
}
|
||||
else if(synctype == SyncType.DIALOG_CATEGORY){
|
||||
DialogCategory category = DialogController.Instance.categories.remove(id);
|
||||
if(category != null) {
|
||||
DialogController.Instance.dialogs.keySet().removeAll(category.dialogs.keySet());
|
||||
}
|
||||
}
|
||||
else if(synctype == SyncType.QUEST){
|
||||
Quest quest = QuestController.Instance.quests.remove(id);
|
||||
if(quest != null) {
|
||||
quest.category.quests.remove(id);
|
||||
}
|
||||
}
|
||||
else if(synctype == SyncType.QUEST_CATEGORY){
|
||||
QuestCategory category = QuestController.Instance.categories.remove(id);
|
||||
if(category != null) {
|
||||
QuestController.Instance.quests.keySet().removeAll(category.quests.keySet());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IExtendedEntityProperties;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.PacketHandlerServer;
|
||||
import noppes.npcs.Server;
|
||||
@@ -62,6 +63,8 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
public boolean isGUIOpen = false;
|
||||
public boolean hadInteract = true;
|
||||
|
||||
public boolean updateClient = false;
|
||||
|
||||
public ScreenSize screenSize = new ScreenSize(-1,-1);
|
||||
|
||||
public void onLogin() {
|
||||
@@ -143,6 +146,15 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
return compound;
|
||||
}
|
||||
|
||||
public NBTTagCompound getSyncNBT(){
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
dialogData.saveNBTData(compound);
|
||||
questData.saveNBTData(compound);
|
||||
factionData.saveNBTData(compound);
|
||||
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Entity entity, World world) {
|
||||
|
||||
@@ -313,4 +325,11 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
}
|
||||
setNBT(data);
|
||||
}
|
||||
|
||||
public static PlayerData get(EntityPlayer player) {
|
||||
if(player.worldObj.isRemote)
|
||||
return CustomNpcs.proxy.getPlayerData(player);
|
||||
|
||||
return PlayerDataController.Instance.getPlayerData(player);
|
||||
}
|
||||
}
|
||||
@@ -204,6 +204,8 @@ public class PlayerQuestData implements IPlayerQuestData {
|
||||
activeQuests.put(id, questdata);
|
||||
Server.sendData((EntityPlayerMP)parent.player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title);
|
||||
Server.sendData((EntityPlayerMP)parent.player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title);
|
||||
|
||||
parent.updateClient = true;
|
||||
}
|
||||
|
||||
public void finishQuest(int id) {
|
||||
@@ -215,6 +217,8 @@ public class PlayerQuestData implements IPlayerQuestData {
|
||||
finishedQuests.put(quest.id, System.currentTimeMillis());
|
||||
else
|
||||
finishedQuests.put(quest.id, parent.player.worldObj.getTotalWorldTime());
|
||||
|
||||
parent.updateClient = true;
|
||||
}
|
||||
|
||||
public void stopQuest(int id) {
|
||||
@@ -222,6 +226,7 @@ public class PlayerQuestData implements IPlayerQuestData {
|
||||
if (quest == null)
|
||||
return;
|
||||
activeQuests.remove(id);
|
||||
parent.updateClient = true;
|
||||
}
|
||||
|
||||
public void removeQuest(int id) {
|
||||
@@ -230,6 +235,7 @@ public class PlayerQuestData implements IPlayerQuestData {
|
||||
return;
|
||||
activeQuests.remove(id);
|
||||
finishedQuests.remove(id);
|
||||
parent.updateClient = true;
|
||||
}
|
||||
|
||||
public boolean hasFinishedQuest(int id){
|
||||
|
||||
@@ -326,12 +326,14 @@ public class QuestDialog extends QuestInterface implements IQuestDialog {
|
||||
if (progress == 0 && completed) {
|
||||
data.dialogData.dialogsRead.remove(this.dialog.id);
|
||||
data.questData.checkQuestCompletion(data, EnumQuestType.values()[1]);
|
||||
data.updateClient = true;
|
||||
data.save();
|
||||
}
|
||||
|
||||
if (progress == 1 && !completed) {
|
||||
data.dialogData.dialogsRead.add(this.dialog.id);
|
||||
data.questData.checkQuestCompletion(data, EnumQuestType.values()[1]);
|
||||
data.updateClient = true;
|
||||
data.save();
|
||||
}
|
||||
} else if (party != null){
|
||||
@@ -353,11 +355,13 @@ public class QuestDialog extends QuestInterface implements IQuestDialog {
|
||||
if (progress == 0 && completed) {
|
||||
leaderData.dialogData.dialogsRead.remove(this.dialog.id);
|
||||
PartyController.Instance().checkQuestCompletion(party, EnumQuestType.values()[1]);
|
||||
leaderData.updateClient = true;
|
||||
leaderData.save();
|
||||
}
|
||||
if (progress == 1 && !completed) {
|
||||
leaderData.dialogData.dialogsRead.add(this.dialog.id);
|
||||
PartyController.Instance().checkQuestCompletion(party, EnumQuestType.values()[1]);
|
||||
leaderData.updateClient = true;
|
||||
leaderData.save();
|
||||
}
|
||||
} else {
|
||||
@@ -375,10 +379,12 @@ public class QuestDialog extends QuestInterface implements IQuestDialog {
|
||||
if (progress == 0 && completed) {
|
||||
individualData.dialogData.dialogsRead.remove(this.dialog.id);
|
||||
individualData.save();
|
||||
individualData.updateClient = true;
|
||||
}
|
||||
if (progress == 1 && !completed) {
|
||||
individualData.dialogData.dialogsRead.add(this.dialog.id);
|
||||
individualData.save();
|
||||
individualData.updateClient = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,6 +305,7 @@ public class QuestKill extends QuestInterface implements IQuestKill {
|
||||
this.parent.setKilled(questdata, killed);
|
||||
data.questData.checkQuestCompletion(data, EnumQuestType.values()[2]);
|
||||
data.questData.checkQuestCompletion(data, EnumQuestType.values()[4]);
|
||||
data.updateClient = true;
|
||||
data.save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,6 +332,7 @@ public class QuestLocation extends QuestInterface implements IQuestLocation {
|
||||
questData.extraData.setBoolean(this.nbtName, progress == 1);
|
||||
data.questData.checkQuestCompletion(data, EnumQuestType.values()[3]);
|
||||
data.save();
|
||||
data.updateClient = true;
|
||||
}
|
||||
} else if (party != null){
|
||||
QuestData questData = party.getQuestData();
|
||||
|
||||
@@ -193,11 +193,15 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
}
|
||||
|
||||
public void readDialog(int id) {
|
||||
PlayerDataController.Instance.getPlayerData(player).dialogData.dialogsRead.add(id);
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
playerData.dialogData.dialogsRead.add(id);
|
||||
playerData.updateClient = true;
|
||||
}
|
||||
|
||||
public void unreadDialog(int id) {
|
||||
PlayerDataController.Instance.getPlayerData(player).dialogData.dialogsRead.remove(id);
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
playerData.dialogData.dialogsRead.remove(id);
|
||||
playerData.updateClient = true;
|
||||
}
|
||||
|
||||
public boolean hasFinishedQuest(IQuest quest) {
|
||||
@@ -261,6 +265,7 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
data.questData.activeQuests.put(id, questdata);
|
||||
Server.sendData((EntityPlayerMP)player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title);
|
||||
Server.sendData((EntityPlayerMP)player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title);
|
||||
data.updateClient = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -271,12 +276,12 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
Quest quest = QuestController.Instance.quests.get(id);
|
||||
if (quest == null)
|
||||
return;
|
||||
PlayerData data = PlayerDataController.Instance.getPlayerData(player);
|
||||
|
||||
PlayerData data = PlayerData.get(player);
|
||||
if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY)
|
||||
data.questData.finishedQuests.put(quest.id, System.currentTimeMillis());
|
||||
else
|
||||
data.questData.finishedQuests.put(quest.id, player.worldObj.getTotalWorldTime());
|
||||
data.updateClient = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -289,6 +294,7 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
return;
|
||||
PlayerData data = PlayerDataController.Instance.getPlayerData(player);
|
||||
data.questData.activeQuests.remove(id);
|
||||
data.updateClient = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -299,9 +305,10 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
Quest quest = QuestController.Instance.quests.get(id);
|
||||
if (quest == null)
|
||||
return;
|
||||
PlayerData data = PlayerDataController.Instance.getPlayerData(player);
|
||||
PlayerData data = PlayerData.get(player);
|
||||
data.questData.activeQuests.remove(id);
|
||||
data.questData.finishedQuests.remove(id);
|
||||
data.updateClient = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user