Fixes #419 , among other things

This commit is contained in:
boy0001
2015-07-17 20:48:13 +10:00
parent 1564b58a3d
commit b2fbd74d4b
15 changed files with 226 additions and 141 deletions

View File

@ -24,12 +24,16 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
import sun.awt.SunHints.Value;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
@ -260,6 +264,18 @@ public class Plot implements Cloneable {
MainUtil.clear(this, false, whenDone);
}
/**
* This will return null if the plot hasn't been analyzed
* @return analysis of plot
*/
public PlotAnalysis getComplexity() {
return PlotAnalysis.getAnalysis(this);
}
public void analyze(RunnableVal<PlotAnalysis> whenDone) {
PlotAnalysis.analyzePlot(this, whenDone);
}
/**
* Delete a plot
* @see PS#removePlot(String, PlotId, boolean)

View File

@ -1,5 +1,12 @@
package com.intellectualcrafters.plot.object;
import java.util.List;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.generator.BukkitHybridUtils;
import com.intellectualcrafters.plot.util.TaskManager;
public class PlotAnalysis {
public double changes;
public double faces;
@ -7,4 +14,43 @@ public class PlotAnalysis {
public double air;
public double variety;
public double complexity;
public static double CHANGES_MODIFIER = 32;
public static double FACES_MODIFIER = 32;
public static double DATA_MODIFIER = 32;
public static double AIR_MODIFIER = 32;
public static double VARIETY_MODIFIER = 32;
public static PlotAnalysis getAnalysis(Plot plot) {
Flag flag = FlagManager.getPlotFlag(plot, "analysis");
if (flag != null) {
PlotAnalysis analysis = new PlotAnalysis();
List<Double> values = (List<Double>) flag.getValue();
analysis.changes = values.get(0);
analysis.faces = values.get(1);
analysis.data = values.get(3);
analysis.air = values.get(4);
analysis.variety = values.get(5);
return analysis;
}
return null;
}
public static void analyzePlot(Plot plot, RunnableVal<PlotAnalysis> whenDone) {
PlotAnalysis analysis = getAnalysis(plot);
if (analysis != null) {
whenDone.value = analysis;
whenDone.run();
return;
}
BukkitHybridUtils.manager.analyzePlot(plot, whenDone);
}
/**
*
* @param whenDone
*/
public static void calcOptimalModifiers(Runnable whenDone) {
}
}

View File

@ -15,6 +15,7 @@ public class Rating {
private HashMap<String, Integer> ratingMap;
public Rating(int value) {
ratingMap = new HashMap<>();
if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() > 1) {
for (int i = 0 ; i < Settings.RATING_CATEGORIES.size(); i++) {
ratingMap.put(Settings.RATING_CATEGORIES.get(i), (value % 10) - 1);