mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-11 23:07:37 +00:00
NpcAPI:
-Added millisToTime(long) and ticksToTime(long) functions to return time formatted strings from long values. IPlayerQuestData: -Added last completed time functions for repeating quests. IQuest: -Added repeat functions for repeating quests. ServerCloneController: -Fixed cloned NPCs having identical UUIDs.
This commit is contained in:
1 parent
73ceeab907
commit
a895c8bd24
7 files changed
+105
-1
No files matched your search
+1
-1
Submodule src/api updated: 705bf53aea...3e537043dc.
@@ -798,4 +798,41 @@ public class NoppesUtilServer {
|
||||
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;
|
||||
long months = days / 30;
|
||||
long years = months / 12;
|
||||
|
||||
months = months % 12;
|
||||
days = days % 30;
|
||||
hours = hours % 24;
|
||||
minutes = minutes % 60;
|
||||
seconds = seconds % 60;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (years > 0) {
|
||||
sb.append(years + " year(s) ");
|
||||
}
|
||||
if (months > 0) {
|
||||
sb.append(months + " month(s) ");
|
||||
}
|
||||
if (days > 0) {
|
||||
sb.append(days + " day(s) ");
|
||||
}
|
||||
if (hours > 0) {
|
||||
sb.append(hours + " hour(s) ");
|
||||
}
|
||||
if (minutes > 0) {
|
||||
sb.append(minutes + " minute(s) ");
|
||||
}
|
||||
if (seconds > 0) {
|
||||
sb.append(seconds + " second(s)");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,10 @@ import java.util.Vector;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.NoppesStringUtils;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.EnumQuestRepeat;
|
||||
@@ -42,6 +45,13 @@ public class PlayerQuestController {
|
||||
data.activeQuests.put(quest.id,new QuestData(quest));
|
||||
Server.sendData((EntityPlayerMP)player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title);
|
||||
Server.sendData((EntityPlayerMP)player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title);
|
||||
} else {
|
||||
long timeUntilRepeat = quest.getTimeUntilRepeat(player);
|
||||
if (timeUntilRepeat > 0 && quest.getIsRepeatable() && quest.repeat != EnumQuestRepeat.NONE && quest.repeat != EnumQuestRepeat.REPEATABLE) {
|
||||
String timeString = NoppesUtilServer.millisToTime(timeUntilRepeat);
|
||||
String message = "You have " + timeString + " left until you can repeat this quest.";
|
||||
player.addChatMessage(new ChatComponentTranslation(NoppesStringUtils.formatText(message,player)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -170,6 +170,8 @@ public class ServerCloneController implements ICloneHandler {
|
||||
nbttagcompound.removeTag("MovingPathNew");
|
||||
nbttagcompound.removeTag("Pos");
|
||||
nbttagcompound.removeTag("Riding");
|
||||
nbttagcompound.removeTag("UUIDMost");
|
||||
nbttagcompound.removeTag("UUIDLeast");
|
||||
|
||||
if(!nbttagcompound.hasKey("ModRev"))
|
||||
nbttagcompound.setInteger("ModRev", 1);
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.NoppesUtilPlayer;
|
||||
import noppes.npcs.Server;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.EnumQuestCompletion;
|
||||
import noppes.npcs.constants.EnumQuestType;
|
||||
@@ -213,4 +214,18 @@ public class PlayerQuestData implements IPlayerQuestData {
|
||||
|
||||
return (IQuest[])quests.toArray(new IQuest[0]);
|
||||
}
|
||||
|
||||
public long getLastCompletedTime(int id) {
|
||||
if (this.hasFinishedQuest(id)) {
|
||||
return this.finishedQuests.get(id);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setLastCompletedTime(int id,long time) {
|
||||
Quest quest = QuestController.instance.quests.get(id);
|
||||
if (quest == null)
|
||||
return;
|
||||
this.finishedQuests.put(id,time);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.EnumQuestCompletion;
|
||||
import noppes.npcs.constants.EnumQuestRepeat;
|
||||
import noppes.npcs.constants.EnumQuestType;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.quests.QuestDialog;
|
||||
import noppes.npcs.quests.QuestInterface;
|
||||
@@ -146,6 +147,22 @@ public class Quest implements ICompatibilty, IQuest {
|
||||
quest.readNBT(this.writeToNBT(new NBTTagCompound()));
|
||||
return quest;
|
||||
}
|
||||
|
||||
public long getTimeUntilRepeat(EntityPlayer player) {
|
||||
long questTime = PlayerDataController.instance.getPlayerData(player).getQuestData().getLastCompletedTime(this.id);
|
||||
|
||||
switch (repeat) {
|
||||
case MCDAILY:
|
||||
return Math.max(0, questTime + 24000 - player.worldObj.getTotalWorldTime());
|
||||
case MCWEEKLY:
|
||||
return Math.max(0, questTime + 168000 - player.worldObj.getTotalWorldTime());
|
||||
case RLDAILY:
|
||||
return Math.max(0, questTime + 86400000 - System.currentTimeMillis());
|
||||
case RLWEEKLY:
|
||||
return Math.max(0, questTime + 604800000 - System.currentTimeMillis());
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVersion() {
|
||||
@@ -239,6 +256,21 @@ public class Quest implements ICompatibilty, IQuest {
|
||||
return this.repeat != EnumQuestRepeat.NONE;
|
||||
}
|
||||
|
||||
public long getTimeUntilRepeat(IPlayer player) {
|
||||
return this.getTimeUntilRepeat((EntityPlayer) player.getMCEntity());
|
||||
}
|
||||
|
||||
public void setRepeatType(int type) {
|
||||
if (type < 0 || type >= EnumQuestRepeat.values().length) {
|
||||
return;
|
||||
}
|
||||
this.repeat = EnumQuestRepeat.values()[type];
|
||||
}
|
||||
|
||||
public int getRepeatType() {
|
||||
return this.repeat.ordinal();
|
||||
}
|
||||
|
||||
public IContainer getRewards() {
|
||||
return NpcAPI.Instance().getIContainer(this.rewardItems);
|
||||
}
|
||||
|
||||
@@ -546,4 +546,12 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
public ISkinOverlay createSkinOverlay(String texture) {
|
||||
return new SkinOverlay(texture);
|
||||
}
|
||||
|
||||
public String millisToTime(long millis) {
|
||||
return NoppesUtilServer.millisToTime(millis);
|
||||
}
|
||||
|
||||
public String ticksToTime(long ticks) {
|
||||
return this.millisToTime(ticks * 50);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user