2019-11-10 05:09:16 +01:00
|
|
|
package world.bentobox.level.calculators;
|
|
|
|
|
|
|
|
import java.util.List;
|
2020-06-22 02:54:51 +02:00
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
import java.util.concurrent.atomic.AtomicLong;
|
2019-11-10 05:09:16 +01:00
|
|
|
|
|
|
|
import org.bukkit.Material;
|
|
|
|
|
|
|
|
import com.google.common.collect.HashMultiset;
|
|
|
|
import com.google.common.collect.Multiset;
|
|
|
|
|
|
|
|
public class Results {
|
2020-08-15 19:01:16 +02:00
|
|
|
public enum Result {
|
|
|
|
/**
|
|
|
|
* A level calc is already in progress
|
|
|
|
*/
|
|
|
|
IN_PROGRESS,
|
|
|
|
/**
|
|
|
|
* Results will be available
|
|
|
|
*/
|
|
|
|
AVAILABLE,
|
|
|
|
/**
|
|
|
|
* Result if calculation timed out
|
|
|
|
*/
|
|
|
|
TIMEOUT
|
|
|
|
}
|
2020-06-22 02:54:51 +02:00
|
|
|
List<String> report;
|
|
|
|
final Multiset<Material> mdCount = HashMultiset.create();
|
|
|
|
final Multiset<Material> uwCount = HashMultiset.create();
|
|
|
|
final Multiset<Material> ncCount = HashMultiset.create();
|
|
|
|
final Multiset<Material> ofCount = HashMultiset.create();
|
|
|
|
// AtomicLong and AtomicInteger must be used because they are changed by multiple concurrent threads
|
|
|
|
AtomicLong rawBlockCount = new AtomicLong(0);
|
|
|
|
AtomicLong underWaterBlockCount = new AtomicLong(0);
|
|
|
|
AtomicLong level = new AtomicLong(0);
|
|
|
|
AtomicInteger deathHandicap = new AtomicInteger(0);
|
|
|
|
AtomicLong pointsToNextLevel = new AtomicLong(0);
|
|
|
|
AtomicLong initialLevel = new AtomicLong(0);
|
2023-01-17 00:00:40 +01:00
|
|
|
AtomicLong totalPoints = new AtomicLong(0);
|
2020-08-15 19:01:16 +02:00
|
|
|
final Result state;
|
|
|
|
|
|
|
|
public Results(Result state) {
|
|
|
|
this.state = state;
|
|
|
|
}
|
2019-11-10 05:09:16 +01:00
|
|
|
|
2020-08-15 19:01:16 +02:00
|
|
|
public Results() {
|
|
|
|
this.state = Result.AVAILABLE;
|
|
|
|
}
|
2019-11-10 05:09:16 +01:00
|
|
|
/**
|
|
|
|
* @return the deathHandicap
|
|
|
|
*/
|
|
|
|
public int getDeathHandicap() {
|
2020-06-22 02:54:51 +02:00
|
|
|
return deathHandicap.get();
|
2019-11-10 05:09:16 +01:00
|
|
|
}
|
2020-07-03 21:16:13 +02:00
|
|
|
/**
|
|
|
|
* Set the death handicap
|
|
|
|
* @param handicap
|
|
|
|
*/
|
|
|
|
public void setDeathHandicap(int handicap) {
|
|
|
|
deathHandicap.set(handicap);
|
|
|
|
}
|
2019-11-10 05:09:16 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the report
|
|
|
|
*/
|
|
|
|
public List<String> getReport() {
|
|
|
|
return report;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Set level
|
|
|
|
* @param level - level
|
|
|
|
*/
|
|
|
|
public void setLevel(long level) {
|
2020-06-22 02:54:51 +02:00
|
|
|
this.level.set(level);
|
2019-11-10 05:09:16 +01:00
|
|
|
}
|
|
|
|
/**
|
2020-06-22 02:54:51 +02:00
|
|
|
* @return the level
|
2019-11-10 05:09:16 +01:00
|
|
|
*/
|
2020-06-22 02:54:51 +02:00
|
|
|
public long getLevel() {
|
|
|
|
return level.get();
|
2019-11-10 05:09:16 +01:00
|
|
|
}
|
|
|
|
/**
|
2020-06-22 02:54:51 +02:00
|
|
|
* @return the pointsToNextLevel
|
2019-11-10 05:09:16 +01:00
|
|
|
*/
|
2020-06-22 02:54:51 +02:00
|
|
|
public long getPointsToNextLevel() {
|
|
|
|
return pointsToNextLevel.get();
|
2019-11-10 05:09:16 +01:00
|
|
|
}
|
|
|
|
|
2020-07-03 21:16:13 +02:00
|
|
|
/**
|
|
|
|
* Set the points to next level
|
|
|
|
* @param points
|
|
|
|
*/
|
|
|
|
public void setPointsToNextLevel(long points) {
|
|
|
|
pointsToNextLevel.set(points);
|
|
|
|
}
|
|
|
|
|
2023-01-17 00:00:40 +01:00
|
|
|
/**
|
|
|
|
* @return the totalPoints
|
|
|
|
*/
|
|
|
|
public long getTotalPoints() {
|
|
|
|
return totalPoints.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the total points
|
|
|
|
* @param points
|
|
|
|
*/
|
|
|
|
public void setTotalPoints(long points) {
|
|
|
|
totalPoints.set(points);
|
|
|
|
}
|
|
|
|
|
2020-06-22 02:54:51 +02:00
|
|
|
public long getInitialLevel() {
|
|
|
|
return initialLevel.get();
|
2019-11-10 05:09:16 +01:00
|
|
|
}
|
|
|
|
|
2020-06-22 02:54:51 +02:00
|
|
|
public void setInitialLevel(long initialLevel) {
|
|
|
|
this.initialLevel.set(initialLevel);
|
2019-11-10 05:09:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see java.lang.Object#toString()
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
2020-06-22 02:54:51 +02:00
|
|
|
return "Results [report=" + report + ", mdCount=" + mdCount + ", uwCount=" + uwCount + ", ncCount="
|
2019-11-10 05:09:16 +01:00
|
|
|
+ ncCount + ", ofCount=" + ofCount + ", rawBlockCount=" + rawBlockCount + ", underWaterBlockCount="
|
2020-06-22 02:54:51 +02:00
|
|
|
+ underWaterBlockCount + ", level=" + level + ", deathHandicap=" + deathHandicap
|
2023-01-17 00:00:40 +01:00
|
|
|
+ ", pointsToNextLevel=" + pointsToNextLevel + ", totalPoints=" + totalPoints + ", initialLevel=" + initialLevel + "]";
|
2019-11-10 05:09:16 +01:00
|
|
|
}
|
2020-07-04 00:27:05 +02:00
|
|
|
/**
|
|
|
|
* @return the mdCount
|
|
|
|
*/
|
|
|
|
public Multiset<Material> getMdCount() {
|
|
|
|
return mdCount;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @return the uwCount
|
|
|
|
*/
|
|
|
|
public Multiset<Material> getUwCount() {
|
|
|
|
return uwCount;
|
|
|
|
}
|
2020-08-15 19:01:16 +02:00
|
|
|
/**
|
|
|
|
* @return the state
|
|
|
|
*/
|
|
|
|
public Result getState() {
|
|
|
|
return state;
|
|
|
|
}
|
2019-11-10 05:09:16 +01:00
|
|
|
|
2023-01-17 00:00:40 +01:00
|
|
|
}
|