HyCodeYourTale
classpublicabstractPriority 3

CountObjectiveTask

com.hypixel.hytale.builtin.adventure.objectives.task.CountObjectiveTask

extends ObjectiveTask

7

Methods

7

Public Methods

1

Fields

2

Constructors

Constants

BuilderCodec<CountObjectiveTask>CODEC= BuilderCodec.abstractBuilder(CountObjectiveTask.class, ObjectiveTask.BASE_CODEC) .append(ne...

Constructors

protected
CountObjectiveTask()
public
CountObjectiveTask(CountObjectiveTaskAsset asset, int taskSetIndex, int taskIndex)

Methods

Public Methods (7)

public
void assetChanged(Objective objective)
@Override
public
boolean checkCompletion()
@Override
public
CountObjectiveTaskAsset getAsset()
@Nonnull
public
Message getInfoMessage(Objective objective)
@Nonnull@Override
public
void increaseTaskCompletion(Store<EntityStore> store, Ref<EntityStore> ref, int qty, Objective objective)
public
void setTaskCompletion(Store<EntityStore> store, Ref<EntityStore> ref, int qty, Objective objective)
public
com.hypixel.hytale.protocol.ObjectiveTask toPacket(Objective objective)
@Nonnull

Fields

Protected Fields (1)

protectedint count

Inheritance

Parent
Current
Interface
Child

Use mouse wheel to zoom, drag to pan. Click nodes to navigate.

Related Classes

Source Code

package com.hypixel.hytale.builtin.adventure.objectives.task;

import com.hypixel.hytale.builtin.adventure.objectives.Objective;
import com.hypixel.hytale.builtin.adventure.objectives.config.task.CountObjectiveTaskAsset;
import com.hypixel.hytale.codec.Codec;
import com.hypixel.hytale.codec.KeyedCodec;
import com.hypixel.hytale.codec.builder.BuilderCodec;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.math.util.MathUtil;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import javax.annotation.Nonnull;

public abstract class CountObjectiveTask extends ObjectiveTask {
   public static final BuilderCodec<CountObjectiveTask> CODEC = BuilderCodec.abstractBuilder(CountObjectiveTask.class, ObjectiveTask.BASE_CODEC)
      .append(new KeyedCodec<>("Count", Codec.INTEGER), (countTask, integer) -> countTask.count = integer, countTask -> countTask.count)
      .add()
      .build();
   protected int count;

   public CountObjectiveTask(@Nonnull CountObjectiveTaskAsset asset, int taskSetIndex, int taskIndex) {
      super(asset, taskSetIndex, taskIndex);
   }

   protected CountObjectiveTask() {
   }

   @Nonnull
   public CountObjectiveTaskAsset getAsset() {
      return (CountObjectiveTaskAsset)super.getAsset();
   }

   @Nonnull
   @Override
   public Message getInfoMessage(@Nonnull Objective objective) {
      return super.getInfoMessage(objective).insert(" " + this.count + "/" + this.getAsset().getCount());
   }

   @Override
   public boolean checkCompletion() {
      return this.count >= this.getAsset().getCount();
   }

   @Override
   public void assetChanged(@Nonnull Objective objective) {
      if (this.complete) {
         this.count = this.getAsset().getCount();
      }

      super.assetChanged(objective);
   }

   public void increaseTaskCompletion(@Nonnull Store<EntityStore> store, @Nonnull Ref<EntityStore> ref, int qty, @Nonnull Objective objective) {
      if (this.areTaskConditionsFulfilled(store, ref, objective.getActivePlayerUUIDs())) {
         this.count = MathUtil.clamp(this.count + qty, this.count, this.getAsset().getCount());
         this.updateTaskCompletion(store, ref, objective);
      }
   }

   public void setTaskCompletion(@Nonnull Store<EntityStore> store, @Nonnull Ref<EntityStore> ref, int qty, @Nonnull Objective objective) {
      if (this.areTaskConditionsFulfilled(store, ref, objective.getActivePlayerUUIDs())) {
         this.count = MathUtil.clamp(qty, 0, this.getAsset().getCount());
         this.updateTaskCompletion(store, ref, objective);
      }
   }

   private void updateTaskCompletion(@Nonnull Store<EntityStore> store, @Nonnull Ref<EntityStore> ref, @Nonnull Objective objective) {
      objective.markDirty();
      this.sendUpdateObjectiveTaskPacket(objective);
      if (this.checkCompletion()) {
         this.consumeTaskConditions(store, ref, objective.getActivePlayerUUIDs());
         this.complete(objective, store);
         objective.checkTaskSetCompletion(store);
      }
   }

   @Nonnull
   public com.hypixel.hytale.protocol.ObjectiveTask toPacket(@Nonnull Objective objective) {
      com.hypixel.hytale.protocol.ObjectiveTask packet = new com.hypixel.hytale.protocol.ObjectiveTask();
      packet.taskDescriptionKey = this.asset.getDescriptionKey(objective.getObjectiveId(), this.taskSetIndex, this.taskIndex);
      packet.currentCompletion = this.count;
      packet.completionNeeded = this.getAsset().getCount();
      return packet;
   }
}