Fixing some more things

This commit is contained in:
boy0001
2015-07-31 00:25:16 +10:00
parent bfa877e607
commit e1dad77d8f
264 changed files with 6920 additions and 2146 deletions

View File

@ -20,8 +20,6 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.object;
import org.bukkit.World;
import org.bukkit.block.Block;
/**
* Wrapper class for blocks, using pure data rather than the object.

View File

@ -1,14 +1,16 @@
package com.intellectualcrafters.plot.object;
import java.util.HashMap;
import java.util.Set;
import java.util.UUID;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.commands.RequiredType;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.util.MainUtil;
import java.util.HashMap;
import java.util.Set;
import java.util.UUID;
import com.intellectualcrafters.plot.util.PlotGamemode;
import com.intellectualcrafters.plot.util.PlotWeather;
public class ConsolePlayer implements PlotPlayer {
@ -134,5 +136,28 @@ public class ConsolePlayer implements PlotPlayer {
public RequiredType getSuperCaller() {
return RequiredType.CONSOLE;
}
@Override
public void setWeather(PlotWeather weather) {}
@Override
public PlotGamemode getGamemode() {
return PlotGamemode.CREATIVE;
}
@Override
public void setGamemode(PlotGamemode gamemode) {}
@Override
public void setTime(long time) {}
@Override
public void setFlight(boolean fly) {}
@Override
public void playMusic(Location loc, int id) {}
@Override
public void kick(String message) {}
}

View File

@ -20,18 +20,18 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.UUID;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
/**
* The plot class
*

View File

@ -1,5 +1,13 @@
package com.intellectualcrafters.plot.object;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import com.intellectualcrafters.configuration.file.YamlConfiguration;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.flag.Flag;
@ -9,14 +17,6 @@ import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.bukkit.util.BukkitHybridUtils;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
public class PlotAnalysis {
public int changes;
public int faces;
@ -87,21 +87,21 @@ public class PlotAnalysis {
*/
public static void calcOptimalModifiers(final Runnable whenDone, final double threshold) {
if (running) {
PS.log("Calibration task already in progress!");
PS.debug("Calibration task already in progress!");
return;
}
if (threshold <= 0 || threshold >= 1) {
PS.log("Invalid threshold provided! (Cannot be 0 or 100 as then there's no point calibrating)");
PS.debug("Invalid threshold provided! (Cannot be 0 or 100 as then there's no point calibrating)");
return;
}
running = true;
PS.log(" - Fetching all plots");
PS.debug(" - Fetching all plots");
final ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
Iterator<Plot> iter = plots.iterator();
PS.log(" - $1Reducing " + plots.size() + " plots to those with sufficient data");
PS.debug(" - $1Reducing " + plots.size() + " plots to those with sufficient data");
while (iter.hasNext()) {
Plot plot = iter.next();
if (plot.getSettings().ratings == null || plot.getSettings().ratings.size() == 0) {
@ -111,10 +111,10 @@ public class PlotAnalysis {
MainUtil.runners.put(plot, 1);
}
}
PS.log(" - | Reduced to " + plots.size() + " plots");
PS.debug(" - | Reduced to " + plots.size() + " plots");
if (plots.size() < 3) {
PS.log("Calibration cancelled due to insufficient comparison data, please try again later");
PS.debug("Calibration cancelled due to insufficient comparison data, please try again later");
running = false;
for (Plot plot : plots) {
MainUtil.runners.remove(plot);
@ -122,7 +122,7 @@ public class PlotAnalysis {
return;
}
PS.log(" - $1Analyzing plot contents (this may take a while)");
PS.debug(" - $1Analyzing plot contents (this may take a while)");
final int[] changes = new int[plots.size()];
final int[] faces = new int[plots.size()];
@ -147,7 +147,7 @@ public class PlotAnalysis {
int i = mi.intValue();
Plot plot = plots.get(i);
ratings[i] = (int) ((plot.getAverageRating() + plot.getSettings().ratings.size()) * 100);
PS.log(" | " + plot + " (rating) " + (ratings[i]));
PS.debug(" | " + plot + " (rating) " + (ratings[i]));
}
}
});
@ -159,7 +159,7 @@ public class PlotAnalysis {
if (queuePlot == null) {
break;
}
PS.log(" | " + queuePlot);
PS.debug(" | " + queuePlot);
final Object lock = new Object();
TaskManager.runTask(new Runnable() {
@Override
@ -188,17 +188,17 @@ public class PlotAnalysis {
}
}
PS.log(" - $1Waiting on plot rating thread: " + ((mi.intValue() * 100) / plots.size()) + "%");
PS.debug(" - $1Waiting on plot rating thread: " + ((mi.intValue() * 100) / plots.size()) + "%");
try {
ratingAnalysis.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
PS.log(" - $1Processing and grouping single plot analysis for bulk processing");
PS.debug(" - $1Processing and grouping single plot analysis for bulk processing");
for (int i = 0; i < plots.size(); i++) {
Plot plot = plots.get(i);
PS.log(" | " + plot);
PS.debug(" | " + plot);
PlotAnalysis analysis = plot.getComplexity();
changes[i] = analysis.changes;
@ -214,16 +214,16 @@ public class PlotAnalysis {
variety_sd[i] = analysis.variety_sd;
}
PS.log(" - $1Calculating rankings");
PS.debug(" - $1Calculating rankings");
int[] rank_ratings = rank(ratings);
int n = rank_ratings.length;
int optimal_index = (int) Math.round((1 - threshold) * (n - 1));
PS.log(" - $1Calculating rank correlation: ");
PS.log(" - The analyzed plots which were processed and put into bulk data will be compared and correlated to the plot ranking");
PS.log(" - The calculated correlation constant will then be used to calibrate the threshold for auto plot clearing");
PS.debug(" - $1Calculating rank correlation: ");
PS.debug(" - The analyzed plots which were processed and put into bulk data will be compared and correlated to the plot ranking");
PS.debug(" - The calculated correlation constant will then be used to calibrate the threshold for auto plot clearing");
int[] rank_changes = rank(changes);
int[] sd_changes = getSD(rank_changes, rank_ratings);
@ -231,7 +231,7 @@ public class PlotAnalysis {
int sum_changes = sum(variance_changes);
double factor_changes = getCC(n, sum_changes);
PlotAnalysis.MODIFIERS.changes = factor_changes == 1 ? 0 : (int) (factor_changes * 1000 / MathMan.getMean(changes));
PS.log(" - | changes " + factor_changes);
PS.debug(" - | changes " + factor_changes);
int[] rank_faces = rank(faces);
int[] sd_faces = getSD(rank_faces, rank_ratings);
@ -239,7 +239,7 @@ public class PlotAnalysis {
int sum_faces = sum(variance_faces);
double factor_faces = getCC(n, sum_faces);
PlotAnalysis.MODIFIERS.faces = factor_faces == 1 ? 0 : (int) (factor_faces * 1000 / MathMan.getMean(faces));
PS.log(" - | faces " + factor_faces);
PS.debug(" - | faces " + factor_faces);
int[] rank_data = rank(data);
int[] sd_data = getSD(rank_data, rank_ratings);
@ -247,7 +247,7 @@ public class PlotAnalysis {
int sum_data = sum(variance_data);
double factor_data = getCC(n, sum_data);
PlotAnalysis.MODIFIERS.data = factor_data == 1 ? 0 : (int) (factor_data * 1000 / MathMan.getMean(data));
PS.log(" - | data " + factor_data);
PS.debug(" - | data " + factor_data);
int[] rank_air = rank(air);
int[] sd_air = getSD(rank_air, rank_ratings);
@ -255,7 +255,7 @@ public class PlotAnalysis {
int sum_air = sum(variance_air);
double factor_air = getCC(n, sum_air);
PlotAnalysis.MODIFIERS.air = factor_air == 1 ? 0 : (int) (factor_air * 1000 / MathMan.getMean(air));
PS.log(" - | air " + factor_air);
PS.debug(" - | air " + factor_air);
int[] rank_variety = rank(variety);
int[] sd_variety = getSD(rank_variety, rank_ratings);
@ -263,7 +263,7 @@ public class PlotAnalysis {
int sum_variety = sum(variance_variety);
double factor_variety = getCC(n, sum_variety);
PlotAnalysis.MODIFIERS.variety = factor_variety == 1 ? 0 : (int) (factor_variety * 1000 / MathMan.getMean(variety));
PS.log(" - | variety " + factor_variety);
PS.debug(" - | variety " + factor_variety);
int[] rank_changes_sd = rank(changes_sd);
int[] sd_changes_sd = getSD(rank_changes_sd, rank_ratings);
@ -271,7 +271,7 @@ public class PlotAnalysis {
int sum_changes_sd = sum(variance_changes_sd);
double factor_changes_sd = getCC(n, sum_changes_sd);
PlotAnalysis.MODIFIERS.changes_sd = factor_changes_sd == 1 ? 0 : (int) (factor_changes_sd * 1000 / MathMan.getMean(changes_sd));
PS.log(" - | changes_sd " + factor_changes_sd);
PS.debug(" - | changes_sd " + factor_changes_sd);
int[] rank_faces_sd = rank(faces_sd);
int[] sd_faces_sd = getSD(rank_faces_sd, rank_ratings);
@ -279,7 +279,7 @@ public class PlotAnalysis {
int sum_faces_sd = sum(variance_faces_sd);
double factor_faces_sd = getCC(n, sum_faces_sd);
PlotAnalysis.MODIFIERS.faces_sd = factor_faces_sd == 1 ? 0 : (int) (factor_faces_sd * 1000 / MathMan.getMean(faces_sd));
PS.log(" - | faces_sd " + factor_faces_sd);
PS.debug(" - | faces_sd " + factor_faces_sd);
int[] rank_data_sd = rank(data_sd);
int[] sd_data_sd = getSD(rank_data_sd, rank_ratings);
@ -287,7 +287,7 @@ public class PlotAnalysis {
int sum_data_sd = sum(variance_data_sd);
double factor_data_sd = getCC(n, sum_data_sd);
PlotAnalysis.MODIFIERS.data_sd = factor_data_sd == 1 ? 0 : (int) (factor_data_sd * 1000 / MathMan.getMean(data_sd));
PS.log(" - | data_sd " + factor_data_sd);
PS.debug(" - | data_sd " + factor_data_sd);
int[] rank_air_sd = rank(air_sd);
int[] sd_air_sd = getSD(rank_air_sd, rank_ratings);
@ -295,7 +295,7 @@ public class PlotAnalysis {
int sum_air_sd = sum(variance_air_sd);
double factor_air_sd = getCC(n, sum_air_sd);
PlotAnalysis.MODIFIERS.air_sd = factor_air_sd == 1 ? 0 : (int) (factor_air_sd * 1000 / MathMan.getMean(air_sd));
PS.log(" - | air_sd " + factor_air_sd);
PS.debug(" - | air_sd " + factor_air_sd);
int[] rank_variety_sd = rank(variety_sd);
int[] sd_variety_sd = getSD(rank_variety_sd, rank_ratings);
@ -303,11 +303,11 @@ public class PlotAnalysis {
int sum_variety_sd = sum(variance_variety_sd);
double factor_variety_sd = getCC(n, sum_variety_sd);
PlotAnalysis.MODIFIERS.variety_sd = factor_variety_sd == 1 ? 0 : (int) (factor_variety_sd * 1000 / MathMan.getMean(variety_sd));
PS.log(" - | variety_sd " + factor_variety_sd);
PS.debug(" - | variety_sd " + factor_variety_sd);
int[] complexity = new int[n];
PS.log(" $1Calculating threshold");
PS.debug(" $1Calculating threshold");
int max = 0;
int min = 0;
for (int i = 0; i < n; i++) {
@ -337,7 +337,7 @@ public class PlotAnalysis {
logln("Correlation: ");
logln(getCC(n, sum(square(getSD(rank_complexity, rank_ratings)))));
if (optimal_complexity == Integer.MAX_VALUE) {
PS.log("Insufficient data to determine correlation! " + optimal_index + " | " + n);
PS.debug("Insufficient data to determine correlation! " + optimal_index + " | " + n);
running = false;
for (Plot plot : plots) {
MainUtil.runners.remove(plot);
@ -356,7 +356,7 @@ public class PlotAnalysis {
}
// Save calibration
PS.log(" $1Saving calibration");
PS.debug(" $1Saving calibration");
YamlConfiguration config = PS.get().config;
config.set("clear.auto.threshold", optimal_complexity);
config.set("clear.auto.calibration.changes", PlotAnalysis.MODIFIERS.changes);
@ -375,7 +375,7 @@ public class PlotAnalysis {
e.printStackTrace();
}
PS.log("$1Done!");
PS.debug("$1Done!");
running = false;
for (Plot plot : plots) {
MainUtil.runners.remove(plot);

View File

@ -1,10 +1,10 @@
package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.database.DBFunc;
import java.util.HashSet;
import java.util.UUID;
import com.intellectualcrafters.plot.database.DBFunc;
public class PlotCluster {
public final String world;
public PlotSettings settings;

View File

@ -1,14 +1,14 @@
package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.UUIDHandler;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.UUID;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.UUIDHandler;
public class PlotHandler {
public static HashSet<UUID> getOwners(Plot plot) {
if (plot.owner == null) {

View File

@ -1,5 +1,7 @@
package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.util.BlockManager;
public class PlotItemStack {
public final int id;
public final short data;
@ -7,6 +9,7 @@ public class PlotItemStack {
public final String name;
public final String[] lore;
@Deprecated
public PlotItemStack(int id, short data, int amount, String name, String... lore) {
this.id = id;
this.data = data;
@ -14,4 +17,13 @@ public class PlotItemStack {
this.name = name;
this.lore = lore;
}
public PlotItemStack(String id, int amount, String name, String... lore) {
PlotBlock block = BlockManager.manager.getPlotBlockFromString(id);
this.id = block.id;
this.data = block.data;
this.amount = amount;
this.name = name;
this.lore = lore;
}
}

View File

@ -20,13 +20,13 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.commands.Template;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import com.intellectualcrafters.plot.commands.Template;
public abstract class PlotManager {
/*
* Plot locations (methods with Abs in them will not need to consider mega

View File

@ -1,9 +1,11 @@
package com.intellectualcrafters.plot.object;
import com.plotsquared.general.commands.CommandCaller;
import java.util.UUID;
import com.intellectualcrafters.plot.util.PlotGamemode;
import com.intellectualcrafters.plot.util.PlotWeather;
import com.plotsquared.general.commands.CommandCaller;
/**
* Created 2015-02-20 for PlotSquared
*
@ -60,4 +62,18 @@ public interface PlotPlayer extends CommandCaller {
void setMeta(String key, Object value);
Object getMeta(String key);
void deleteMeta(String key);
void setWeather(PlotWeather weather);
PlotGamemode getGamemode();
void setGamemode(PlotGamemode gamemode);
void setTime(long time);
void setFlight(boolean fly);
void playMusic(Location loc, int id);
void kick(String message);
}

View File

@ -20,17 +20,17 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.object;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.comment.PlotComment;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
/**
* plot settings
*

View File

@ -20,6 +20,11 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.object;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.Configuration;
@ -28,13 +33,9 @@ import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.PlotGamemode;
import com.intellectualcrafters.plot.util.StringMan;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
/**
* @author Jesse Boyd
*/
@ -60,6 +61,7 @@ public abstract class PlotWorld {
public final static boolean WORLD_BORDER_DEFAULT = false;
public final static int MAX_PLOT_MEMBERS_DEFAULT = 128;
public final static int MAX_BUILD_HEIGHT_DEFAULT = 256;
public final static PlotGamemode GAMEMODE_DEFAULT = PlotGamemode.CREATIVE;
// are plot clusters enabled
// require claim in cluster
// TODO make this configurable
@ -95,6 +97,7 @@ public abstract class PlotWorld {
public boolean HOME_ALLOW_NONMEMBER;
public PlotLoc DEFAULT_HOME;
public int MAX_BUILD_HEIGHT;
public PlotGamemode GAMEMODE = PlotGamemode.CREATIVE;
public PlotWorld(final String worldname) {
this.worldname = worldname;
@ -152,6 +155,26 @@ public abstract class PlotWorld {
this.WORLD_BORDER = config.getBoolean("world.border");
this.MAX_BUILD_HEIGHT = config.getInt("world.max_height");
switch (config.getString("world.gamemode").toLowerCase()) {
case "survival":
case "s":
case "0":
this.GAMEMODE = PlotGamemode.SURVIVAL;
case "creative":
case "c":
case "1":
this.GAMEMODE = PlotGamemode.CREATIVE;
case "adventure":
case "a":
case "2":
this.GAMEMODE = PlotGamemode.ADVENTURE;
case "spectator":
case "3":
this.GAMEMODE = PlotGamemode.SPECTATOR;
default:
PS.debug("&cInvalid gamemode set for: " + worldname);
}
this.HOME_ALLOW_NONMEMBER = config.getBoolean("home.allow-nonmembers");
String homeDefault = config.getString("home.default");
if (homeDefault.equalsIgnoreCase("side")) {
@ -188,7 +211,7 @@ public abstract class PlotWorld {
this.DEFAULT_FLAGS = FlagManager.parseFlags(flags);
} catch (final Exception e) {
e.printStackTrace();
PS.log("&cInvalid default flags for " + this.worldname + ": " + StringMan.join(flags, ","));
PS.debug("&cInvalid default flags for " + this.worldname + ": " + StringMan.join(flags, ","));
this.DEFAULT_FLAGS = new HashMap<>();
}
this.PVP = config.getBoolean("event.pvp");
@ -232,6 +255,7 @@ public abstract class PlotWorld {
options.put("home.default", "side");
options.put("home.allow-nonmembers", false);
options.put("world.max_height", PlotWorld.MAX_BUILD_HEIGHT_DEFAULT);
options.put("world.gamemode", PlotWorld.GAMEMODE_DEFAULT.name().toLowerCase());
if (Settings.ENABLE_CLUSTERS && (this.TYPE != 0)) {
options.put("generator.terrain", this.TERRAIN);

View File

@ -1,12 +1,12 @@
package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.config.Settings;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import com.intellectualcrafters.plot.config.Settings;
public class Rating {
/**
@ -14,6 +14,9 @@ public class Rating {
*/
private HashMap<String, Integer> ratingMap;
private boolean changed;
private int initial;
public Rating(int value) {
ratingMap = new HashMap<>();
if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() > 1) {
@ -25,6 +28,7 @@ public class Rating {
else {
ratingMap.put(null, value);
}
this.initial = value;
}
public List<String> getCategories() {
@ -46,5 +50,30 @@ public class Rating {
return ratingMap.get(category);
}
public boolean setRating(String category, int value) {
changed = true;
if (!this.ratingMap.containsKey(category)) {
return false;
}
return this.ratingMap.put(category, value) != null;
}
public int getAggregate() {
if (!changed) {
return initial;
}
if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() > 1) {
int val = 0;
for (int i = 0; i < Settings.RATING_CATEGORIES.size(); i++) {
val += (i + 1) * Math.pow(10, ratingMap.get(Settings.RATING_CATEGORIES.get(i)));
}
return val;
}
else {
return ratingMap.get(null);
}
}
}

View File

@ -1,5 +1,7 @@
package com.intellectualcrafters.plot.object.comment;
import java.util.ArrayList;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler;
@ -8,8 +10,6 @@ import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
import java.util.ArrayList;
public class InboxOwner extends CommentInbox {
@Override

View File

@ -1,5 +1,7 @@
package com.intellectualcrafters.plot.object.comment;
import java.util.ArrayList;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler;
@ -8,8 +10,6 @@ import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
import java.util.ArrayList;
public class InboxPublic extends CommentInbox {
@Override