mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Plot analysis, Inventory GUI API, rating system
This commit is contained in:
parent
a81ea1726b
commit
8e499dffb2
@ -8,7 +8,7 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<artifactId>PlotSquared</artifactId>
|
||||
<version>2.11.25</version>
|
||||
<version>2.11.27</version>
|
||||
<name>PlotSquared</name>
|
||||
<packaging>jar</packaging>
|
||||
<build>
|
||||
|
@ -112,6 +112,7 @@ import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.ConsoleColors;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.InventoryUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.PlayerManager;
|
||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||
@ -119,6 +120,7 @@ import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitChunkManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitEconHandler;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitEventUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitInventoryUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitPlayerManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitSetupUtils;
|
||||
@ -579,4 +581,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
public PlayerManager initPlayerManager() {
|
||||
return new BukkitPlayerManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryUtil initInventoryUtil() {
|
||||
return new BukkitInventoryUtil();
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.InventoryUtil;
|
||||
import com.intellectualcrafters.plot.util.PlayerManager;
|
||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
@ -60,6 +61,8 @@ public interface IPlotMain {
|
||||
public HybridUtils initHybridUtils();
|
||||
|
||||
public UUIDWrapper initUUIDHandler();
|
||||
|
||||
public InventoryUtil initInventoryUtil();
|
||||
|
||||
public boolean initPlotMeConverter();
|
||||
|
||||
|
@ -62,6 +62,7 @@ import com.intellectualcrafters.plot.util.ClusterManager;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.ExpireManager;
|
||||
import com.intellectualcrafters.plot.util.InventoryUtil;
|
||||
import com.intellectualcrafters.plot.util.Logger;
|
||||
import com.intellectualcrafters.plot.util.Logger.LogLevel;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
@ -555,6 +556,8 @@ public class PlotSquared {
|
||||
EventUtil.manager = IMP.initEventUtil();
|
||||
// create Hybrid utility class
|
||||
HybridUtils.manager = IMP.initHybridUtils();
|
||||
// Inventory utility class
|
||||
InventoryUtil.manager = IMP.initInventoryUtil();
|
||||
// create setup util class
|
||||
SetupUtils.manager = IMP.initSetupUtils();
|
||||
// Set block
|
||||
@ -720,6 +723,7 @@ public class PlotSquared {
|
||||
FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.UnsignedIntegerValue()));
|
||||
}
|
||||
FlagManager.addFlag(new AbstractFlag("modified-blocks", new FlagValue.IntegerValue()), true);
|
||||
FlagManager.addFlag(new AbstractFlag("analysis", new FlagValue.DoubleListValue()), true);
|
||||
FlagManager.addFlag(new AbstractFlag("disable-physics", new FlagValue.BooleanValue()));
|
||||
FlagManager.addFlag(new AbstractFlag("fly", new FlagValue.BooleanValue()));
|
||||
FlagManager.addFlag(new AbstractFlag("explosion", new FlagValue.BooleanValue()));
|
||||
@ -925,6 +929,10 @@ public class PlotSquared {
|
||||
Settings.PERMISSION_CACHING = config.getBoolean("cache.permissions");
|
||||
Settings.CACHE_RATINGS = config.getBoolean("cache.ratings");
|
||||
|
||||
// Rating system
|
||||
Settings.RATING_CATEGORIES = config.getStringList("ratings.categories");
|
||||
|
||||
|
||||
// Titles
|
||||
Settings.TITLES = config.getBoolean("titles");
|
||||
|
||||
|
@ -35,7 +35,10 @@ import org.bukkit.Bukkit;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotSquared;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.flag.FlagValue;
|
||||
import com.intellectualcrafters.plot.flag.FlagValue.IntegerListValue;
|
||||
import com.intellectualcrafters.plot.generator.BukkitHybridUtils;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
@ -62,23 +65,20 @@ public class DebugExec extends SubCommand {
|
||||
final String arg = args[0].toLowerCase();
|
||||
switch (arg) {
|
||||
case "analyze": {
|
||||
Plot plot = MainUtil.getPlot(player.getLocation());
|
||||
final Plot plot = MainUtil.getPlot(player.getLocation());
|
||||
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>() {
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.print("changes_sd: " + this.value.changes_sd);
|
||||
System.out.print("changes_total: " + this.value.changes_total);
|
||||
System.out.print("data_sd: " + this.value.data_sd);
|
||||
System.out.print("data_total: " + this.value.data_total);
|
||||
System.out.print("height_sd: " + this.value.height_sd);
|
||||
System.out.print("height_total: " + this.value.height_total);
|
||||
System.out.print("rotations_sd: " + this.value.rotations_sd);
|
||||
System.out.print("rotations_total: " + this.value.rotations_total);
|
||||
System.out.print("uniformity_sd: " + this.value.uniformity_sd);
|
||||
System.out.print("variety_sd: " + this.value.variety_sd);
|
||||
System.out.print("variety_total: " + this.value.variety_total);
|
||||
System.out.print("verticies_sd: " + this.value.verticies_sd);
|
||||
System.out.print("verticies_total: " + this.value.verticies_total);
|
||||
List<Double> result = new ArrayList<>();
|
||||
result.add((double) (Math.round(value.air * 100) / 100d));
|
||||
result.add((double) (Math.round(value.changes * 100) / 100d));
|
||||
result.add((double) (Math.round(value.complexity * 100) / 100d));
|
||||
result.add((double) (Math.round(value.data * 100) / 100d));
|
||||
result.add((double) (Math.round(value.faces * 100) / 100d));
|
||||
result.add((double) (Math.round(value.air * 100) / 100d));
|
||||
result.add((double) (Math.round(value.variety * 100) / 100d));
|
||||
Flag flag = new Flag(FlagManager.getFlag("analysis"), result);
|
||||
FlagManager.addPlotFlag(plot, flag);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
|
@ -30,6 +30,7 @@ import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotSquared;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.InfoInventory;
|
||||
@ -55,6 +56,7 @@ public class Info extends SubCommand {
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, String... args) {
|
||||
String arg = null;
|
||||
Plot plot;
|
||||
if (args.length > 0) arg = args[0] + "";
|
||||
if (arg != null) {
|
||||
switch (arg) {
|
||||
@ -69,10 +71,27 @@ public class Info extends SubCommand {
|
||||
case "members":
|
||||
case "owner":
|
||||
case "rating":
|
||||
arg = null;
|
||||
plot = MainUtil.getPlotFromString(player, null, player == null);
|
||||
break;
|
||||
default:
|
||||
System.out.print("CHECKING: " + arg);
|
||||
plot = MainUtil.getPlotFromString(player, arg, player == null);
|
||||
System.out.print(plot);
|
||||
if (args.length == 2) {
|
||||
arg = args[1];
|
||||
}
|
||||
else {
|
||||
arg = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
Plot plot = MainUtil.getPlotFromString(player, arg, player == null);
|
||||
else {
|
||||
plot = MainUtil.getPlotFromString(player, null, player == null);
|
||||
}
|
||||
if (plot == null && arg != null) {
|
||||
plot = MainUtil.getPlotFromString(player, null, player == null);
|
||||
}
|
||||
if (plot == null) {
|
||||
if (player == null) {
|
||||
return false;
|
||||
@ -113,14 +132,17 @@ public class Info extends SubCommand {
|
||||
owner = getPlayerList(plot.getOwners());
|
||||
}
|
||||
String info = C.PLOT_INFO.s();
|
||||
if (args.length == 1) {
|
||||
info = getCaption(args[0].toLowerCase());
|
||||
if (arg != null) {
|
||||
info = getCaption(arg);
|
||||
if (info == null) {
|
||||
MainUtil.sendMessage(player, "&6Categories&7: &amembers&7, &aalias&7, &abiome&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, &aowner&7, &arating");
|
||||
return false;
|
||||
}
|
||||
formatAndSend(info, plot.world, plot, player, true);
|
||||
}
|
||||
else {
|
||||
formatAndSend(info, plot.world, plot, player, false);
|
||||
}
|
||||
formatAndSend(info, plot.world, plot, player);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -151,7 +173,7 @@ public class Info extends SubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private void formatAndSend(String info, final String world, final Plot plot, final PlotPlayer player) {
|
||||
private void formatAndSend(String info, final String world, final Plot plot, final PlotPlayer player, final boolean full) {
|
||||
final PlotId id = plot.id;
|
||||
final PlotId id2 = MainUtil.getTopPlot(plot).id;
|
||||
final int num = MainUtil.getPlotSelectionIds(id, id2).size();
|
||||
@ -191,7 +213,24 @@ public class Info extends SubCommand {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String info = newInfo.replaceAll("%rating%", String.format("%.1f", MainUtil.getAverageRating(plot)));
|
||||
int max = 10;
|
||||
if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() > 0) {
|
||||
max = 8;
|
||||
}
|
||||
String info;
|
||||
if (full && Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() > 1) {
|
||||
String rating = "";
|
||||
String prefix = "";
|
||||
double[] ratings = MainUtil.getAverageRatings(plot);
|
||||
for (int i = 0; i < ratings.length; i++) {
|
||||
rating += prefix + Settings.RATING_CATEGORIES.get(i) + "=" + String.format("%.1f", ratings[i]);
|
||||
prefix = ",";
|
||||
}
|
||||
info = newInfo.replaceAll("%rating%", rating);
|
||||
}
|
||||
else {
|
||||
info = newInfo.replaceAll("%rating%", String.format("%.1f", MainUtil.getAverageRating(plot)) + "/" + max);
|
||||
}
|
||||
MainUtil.sendMessage(player, C.PLOT_INFO_HEADER);
|
||||
MainUtil.sendMessage(player, info, false);
|
||||
}
|
||||
|
@ -20,19 +20,17 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.listeners.PlotPlusListener;
|
||||
import com.intellectualcrafters.plot.object.BukkitPlayer;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.listeners.PlotListener;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.PlotInventory;
|
||||
import com.intellectualcrafters.plot.object.PlotItemStack;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class MusicSubcommand extends SubCommand {
|
||||
@ -51,17 +49,24 @@ public class MusicSubcommand extends SubCommand {
|
||||
sendMessage(player, C.NO_PLOT_PERMS);
|
||||
return true;
|
||||
}
|
||||
final org.bukkit.inventory.Inventory inventory = Bukkit.createInventory(null, 9, ChatColor.RED + "Plot Jukebox");
|
||||
for (final PlotPlusListener.RecordMeta meta : PlotPlusListener.RecordMeta.metaList) {
|
||||
final ItemStack stack = new ItemStack(meta.getMaterial());
|
||||
final ItemMeta itemMeta = stack.getItemMeta();
|
||||
itemMeta.setDisplayName(ChatColor.GOLD + meta.toString());
|
||||
itemMeta.setLore(Arrays.asList(ChatColor.GRAY + "Click to play the record"));
|
||||
stack.setItemMeta(itemMeta);
|
||||
inventory.addItem(stack);
|
||||
PlotInventory inv = new PlotInventory(player, 2, "Plot Jukebox") {
|
||||
public boolean onClick(int index) {
|
||||
PlotItemStack item = getItem(index);
|
||||
FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("music"), item.id));
|
||||
PlotListener.manager.plotEntry(player, plot);
|
||||
close();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
int index = 0;
|
||||
for (int i = 2256; i < 2268; i++) {
|
||||
String name = "&r&6" + BlockManager.manager.getClosestMatchingName(new PlotBlock((short) i, (byte) 0));
|
||||
String[] lore = {"&r&aClick to play!"};
|
||||
PlotItemStack item = new PlotItemStack(i, (byte) 0, 1, name, lore);
|
||||
inv.setItem(index, item);
|
||||
index++;
|
||||
}
|
||||
// FIXME unchecked casting
|
||||
((BukkitPlayer) player).player.openInventory(inventory);
|
||||
inv.openInventory();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -29,13 +29,22 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.mutable.MutableInt;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotSquared;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.listeners.PlotListener;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.PlotInventory;
|
||||
import com.intellectualcrafters.plot.object.PlotItemStack;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
@ -49,81 +58,138 @@ public class Rate extends SubCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length < 1) {
|
||||
sendMessage(plr, C.RATING_NOT_VALID);
|
||||
return true;
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("next")) {
|
||||
ArrayList<Plot> plots = new ArrayList<>(PlotSquared.getPlots());
|
||||
Collections.sort(plots, new Comparator<Plot>() {
|
||||
@Override
|
||||
public int compare(Plot p1, Plot p2) {
|
||||
int v1 = 0;
|
||||
int v2 = 0;
|
||||
if (p1.settings.ratings != null) {
|
||||
for (Entry<UUID, Integer> entry : p1.settings.ratings.entrySet()) {
|
||||
v1 -= 11 - entry.getValue();
|
||||
}
|
||||
}
|
||||
if (p2.settings.ratings != null) {
|
||||
for (Entry<UUID, Integer> entry : p2.settings.ratings.entrySet()) {
|
||||
v2 -= 11 - entry.getValue();
|
||||
}
|
||||
}
|
||||
return v2 - v1;
|
||||
}
|
||||
});
|
||||
UUID uuid = player.getUUID();
|
||||
for (Plot p : plots) {
|
||||
if (p.settings.ratings == null || !p.settings.ratings.containsKey(uuid)) {
|
||||
MainUtil.teleportPlayer(player, player.getLocation(), p);
|
||||
MainUtil.sendMessage(player, C.RATE_THIS);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(player, C.FOUND_NO_PLOTS);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final Location loc = player.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
return !sendMessage(player, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!plot.hasOwner()) {
|
||||
sendMessage(plr, C.RATING_NOT_OWNED);
|
||||
sendMessage(player, C.RATING_NOT_OWNED);
|
||||
return true;
|
||||
}
|
||||
if (plot.isOwner(plr.getUUID())) {
|
||||
sendMessage(plr, C.RATING_NOT_YOUR_OWN);
|
||||
if (plot.isOwner(player.getUUID())) {
|
||||
sendMessage(player, C.RATING_NOT_YOUR_OWN);
|
||||
return true;
|
||||
}
|
||||
if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() != 0) {
|
||||
final Runnable run = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (plot.settings.ratings.containsKey(player.getUUID())) {
|
||||
sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString());
|
||||
return;
|
||||
}
|
||||
final MutableInt index = new MutableInt(0);
|
||||
final MutableInt rating = new MutableInt(0);
|
||||
String title = Settings.RATING_CATEGORIES.get(0);
|
||||
PlotInventory inventory = new PlotInventory(player, 1, title) {
|
||||
public boolean onClick(int i) {
|
||||
rating.add((i + 1) * Math.pow(10, index.intValue()));
|
||||
index.increment();
|
||||
if (index.intValue() >= Settings.RATING_CATEGORIES.size()) {
|
||||
close();
|
||||
// set rating!
|
||||
plot.settings.ratings.put(player.getUUID(), rating.intValue());
|
||||
DBFunc.setRating(plot, player.getUUID(), rating.intValue());
|
||||
sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
|
||||
sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
|
||||
return false;
|
||||
}
|
||||
setTitle(Settings.RATING_CATEGORIES.get(index.intValue()));
|
||||
return false;
|
||||
}
|
||||
};
|
||||
inventory.setItem(0, new PlotItemStack(35, (short) 12, 0, "0/8", null));
|
||||
inventory.setItem(1, new PlotItemStack(35, (short) 14, 1, "1/8", null));
|
||||
inventory.setItem(2, new PlotItemStack(35, (short) 1, 2, "2/8", null));
|
||||
inventory.setItem(3, new PlotItemStack(35, (short) 4, 3, "3/8", null));
|
||||
inventory.setItem(4, new PlotItemStack(35, (short) 5, 4, "4/8", null));
|
||||
inventory.setItem(5, new PlotItemStack(35, (short) 9, 5, "5/8", null));
|
||||
inventory.setItem(6, new PlotItemStack(35, (short) 11, 6, "6/8", null));
|
||||
inventory.setItem(7, new PlotItemStack(35, (short) 10, 7, "7/8", null));
|
||||
inventory.setItem(8, new PlotItemStack(35, (short) 2, 8, "8/8", null));
|
||||
inventory.openInventory();
|
||||
}
|
||||
};
|
||||
if (plot.settings.ratings == null) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
plot.settings.ratings = DBFunc.getRatings(plot);
|
||||
run.run();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
run.run();
|
||||
return true;
|
||||
}
|
||||
if (args.length < 1) {
|
||||
sendMessage(player, C.RATING_NOT_VALID);
|
||||
return true;
|
||||
}
|
||||
final String arg = args[0];
|
||||
|
||||
if (arg.equalsIgnoreCase("next")) {
|
||||
ArrayList<Plot> plots = new ArrayList<>(PlotSquared.getPlots());
|
||||
Collections.sort(plots, new Comparator<Plot>() {
|
||||
@Override
|
||||
public int compare(Plot p1, Plot p2) {
|
||||
int v1 = 0;
|
||||
int v2 = 0;
|
||||
if (p1.settings.ratings != null) {
|
||||
for (Entry<UUID, Integer> entry : p1.settings.ratings.entrySet()) {
|
||||
v1 -= 11 - entry.getValue();
|
||||
}
|
||||
}
|
||||
if (p2.settings.ratings != null) {
|
||||
for (Entry<UUID, Integer> entry : p2.settings.ratings.entrySet()) {
|
||||
v2 -= 11 - entry.getValue();
|
||||
}
|
||||
}
|
||||
return v2 - v1;
|
||||
}
|
||||
});
|
||||
UUID uuid = plr.getUUID();
|
||||
for (Plot p : plots) {
|
||||
if (plot.settings.ratings == null || !plot.settings.ratings.containsKey(uuid)) {
|
||||
MainUtil.teleportPlayer(plr, plr.getLocation(), p);
|
||||
MainUtil.sendMessage(plr, C.RATE_THIS);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.FOUND_NO_PLOTS);
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
final int rating;
|
||||
if (StringUtils.isNumeric(arg) && arg.length() < 3 && arg.length() > 0) {
|
||||
rating = Integer.parseInt(arg);
|
||||
if (rating > 10) {
|
||||
sendMessage(plr, C.RATING_NOT_VALID);
|
||||
sendMessage(player, C.RATING_NOT_VALID);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
sendMessage(plr, C.RATING_NOT_VALID);
|
||||
sendMessage(player, C.RATING_NOT_VALID);
|
||||
return false;
|
||||
}
|
||||
final UUID uuid = plr.getUUID();
|
||||
final UUID uuid = player.getUUID();
|
||||
final Runnable run = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (plot.settings.ratings.containsKey(uuid)) {
|
||||
sendMessage(plr, C.RATING_ALREADY_EXISTS, plot.getId().toString());
|
||||
sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString());
|
||||
return;
|
||||
}
|
||||
plot.settings.ratings.put(uuid, rating);
|
||||
DBFunc.setRating(plot, uuid, rating);
|
||||
sendMessage(plr, C.RATING_APPLIED, plot.getId().toString());
|
||||
sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
|
||||
}
|
||||
};
|
||||
if (plot.settings.ratings == null) {
|
||||
|
@ -77,7 +77,7 @@ public class SchematicCmd extends SubCommand {
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
sendMessage(plr, C.NOT_IN_PLOT);
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
if (this.running) {
|
||||
MainUtil.sendMessage(plr, "&cTask is already running.");
|
||||
@ -168,18 +168,22 @@ public class SchematicCmd extends SubCommand {
|
||||
}
|
||||
if (args.length < 2) {
|
||||
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
sendMessage(plr, C.NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
file = args[1];
|
||||
schematic = SchematicHandler.manager.getSchematic(file);
|
||||
if (schematic == null) {
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent");
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
final Location loc = plr.getLocation();
|
||||
final int l1 = schematic.getSchematicDimension().getX();
|
||||
final int l2 = schematic.getSchematicDimension().getZ();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
final int length = MainUtil.getPlotWidth(loc.getWorld(), plot.id);
|
||||
if ((l1 < length) || (l2 < length)) {
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, String.format("Wrong size (x: %s, z: %d) vs %d ", l1, l2, length));
|
||||
|
@ -350,7 +350,7 @@ public enum C {
|
||||
PLOT_UNOWNED("$2The current plot must have an owner to perform this action", "Info"),
|
||||
PLOT_INFO_UNCLAIMED("$2Plot $1%s$2 is not yet claimed", "Info"),
|
||||
PLOT_INFO_HEADER("$3====== $1INFO $3======", false, "Info"),
|
||||
PLOT_INFO("$1ID: $2%id%$1\n" + "$1Alias: $2%alias%$1\n" + "$1Owner: $2%owner%$1\n" + "$1Biome: $2%biome%$1\n" + "$1Can Build: $2%build%$1\n" + "$1Rating: $2%rating%$1/$210$1\n" + "$1Trusted: $2%trusted%$1\n" + "$1Members: $2%members%$1\n" + "$1Denied: $2%denied%$1\n" + "$1Flags: $2%flags%", "Info"),
|
||||
PLOT_INFO("$1ID: $2%id%$1\n" + "$1Alias: $2%alias%$1\n" + "$1Owner: $2%owner%$1\n" + "$1Biome: $2%biome%$1\n" + "$1Can Build: $2%build%$1\n" + "$1Rating: $2%rating%\n" + "$1Trusted: $2%trusted%$1\n" + "$1Members: $2%members%$1\n" + "$1Denied: $2%denied%$1\n" + "$1Flags: $2%flags%", "Info"),
|
||||
PLOT_INFO_TRUSTED("$1Trusted:$2 %trusted%", "Info"),
|
||||
PLOT_INFO_MEMBERS("$1Members:$2 %members%", "Info"),
|
||||
PLOT_INFO_DENIED("$1Denied:$2 %denied%", "Info"),
|
||||
|
@ -38,6 +38,10 @@ public class Settings {
|
||||
public static boolean PERMISSION_CACHING = false;
|
||||
public static boolean CACHE_RATINGS = true;
|
||||
public static boolean UUID_FROM_DISK = false;
|
||||
/**
|
||||
* Ratings
|
||||
*/
|
||||
public static List<String> RATING_CATEGORIES = null;
|
||||
/**
|
||||
* PlotMe settings
|
||||
*/
|
||||
|
@ -1,6 +1,9 @@
|
||||
package com.intellectualcrafters.plot.flag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
@ -349,6 +352,100 @@ public abstract class FlagValue<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class IntegerListValue extends FlagValue<List<Integer>> implements ListValue {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public String toString(final Object t) {
|
||||
return StringUtils.join((List<Integer>) t, ",");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<Integer> getValue(final Object t) {
|
||||
return (List<Integer>) t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> parse(final String t) {
|
||||
String[] split = (t.split(","));
|
||||
ArrayList<Integer> numbers = new ArrayList<Integer>();
|
||||
for (String element : split) {
|
||||
numbers.add(Integer.parseInt(element));
|
||||
}
|
||||
return numbers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Flag value must be a integer list";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(final Object t, final String value) {
|
||||
try {
|
||||
((List<Integer>) t).addAll(parse(value));
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(final Object t, final String value) {
|
||||
try {
|
||||
for (final Integer item : parse(value)) {
|
||||
((List<Integer>) t).remove(item);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class DoubleListValue extends FlagValue<List<Double>> implements ListValue {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public String toString(final Object t) {
|
||||
return StringUtils.join((List<Double>) t, ",");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<Double> getValue(final Object t) {
|
||||
return (List<Double>) t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Double> parse(final String t) {
|
||||
String[] split = (t.split(","));
|
||||
ArrayList<Double> numbers = new ArrayList<Double>();
|
||||
for (String element : split) {
|
||||
numbers.add(Double.parseDouble(element));
|
||||
}
|
||||
return numbers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Flag value must be a integer list";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(final Object t, final String value) {
|
||||
try {
|
||||
((List<Double>) t).addAll(parse(value));
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(final Object t, final String value) {
|
||||
try {
|
||||
for (final Double item : parse(value)) {
|
||||
((List<Double>) t).remove(item);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class StringValue extends FlagValue<String> {
|
||||
@Override
|
||||
|
@ -10,6 +10,7 @@ import java.util.Random;
|
||||
import org.apache.commons.lang.mutable.MutableInt;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
@ -54,8 +55,7 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
return count / array.length;
|
||||
}
|
||||
|
||||
public double getSD(double[] array) {
|
||||
double av = getMean(array);
|
||||
public double getSD(double[] array, double av) {
|
||||
double sd = 0;
|
||||
for (int i=0; i<array.length;i++)
|
||||
{
|
||||
@ -64,8 +64,7 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
return Math.sqrt(sd/array.length);
|
||||
}
|
||||
|
||||
public double getSD(int[] array) {
|
||||
double av = getMean(array);
|
||||
public double getSD(int[] array, double av) {
|
||||
double sd = 0;
|
||||
for (int i=0; i<array.length;i++)
|
||||
{
|
||||
@ -103,41 +102,136 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
return;
|
||||
}
|
||||
final BiomeGrid base = new BiomeGrid() { @Override public void setBiome(int a, int b, Biome c) {} @Override public Biome getBiome(int a, int b) {return null;}};
|
||||
ClassicPlotWorld cpw = (ClassicPlotWorld) PlotSquared.getPlotWorld(plot.world);
|
||||
final Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
|
||||
final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id).add(1, 0, 1);
|
||||
final int bx = bot.getX() >> 4;
|
||||
final int bz = bot.getZ() >> 4;
|
||||
final int tx = top.getX() >> 4;
|
||||
final int tz = top.getZ() >> 4;
|
||||
Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
|
||||
Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
|
||||
final int bx = bot.getX();
|
||||
final int bz = bot.getZ();
|
||||
final int tx = top.getX();
|
||||
final int tz = top.getZ();
|
||||
final int cbx = bx >> 4;
|
||||
final int cbz = bz >> 4;
|
||||
final int ctx = tx >> 4;
|
||||
final int ctz = tz >> 4;
|
||||
final Random r = new Random();
|
||||
AugmentedPopulator.initCache();
|
||||
|
||||
final PlotAnalysis analysis = new PlotAnalysis();
|
||||
final int width = tx - bx + 1;
|
||||
final int length = tz - bz + 1;
|
||||
|
||||
int num_chunks = (tx - bx + 1) * (tz - bz + 1);
|
||||
|
||||
short[][][] oldblocks = new short[256][top.getX() - bot.getX() + 1][top.getZ() - bot.getZ() + 1];
|
||||
short[][][] newblocks = new short[256][top.getX() - bot.getX() + 1][top.getZ() - bot.getZ() + 1];
|
||||
final short[][][] oldblocks = new short[256][width][length];
|
||||
final short[][][] newblocks = new short[256][width][length];
|
||||
|
||||
final List<Chunk> chunks = new ArrayList<>();
|
||||
final List<Chunk> processed_chunks = new ArrayList<>();
|
||||
|
||||
for (int X = bx; X <= tx; X++) {
|
||||
for (int Z = bz; Z <= tz; Z++) {
|
||||
for (int X = cbx; X <= ctx; X++) {
|
||||
for (int Z = cbz; Z <= ctz; Z++) {
|
||||
Chunk chunk = world.getChunkAt(X, Z);
|
||||
chunks.add(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
final double[] changes_sd = new double[num_chunks];
|
||||
final double[] rotations_sd = new double[num_chunks];
|
||||
final double[] data_sd = new double[num_chunks];
|
||||
final double[] variety_sd = new double[num_chunks];
|
||||
final double[] uniformity_sd = new double[num_chunks];
|
||||
final double[] verticies_sd = new double[num_chunks];
|
||||
final double[] height_sd = new double[num_chunks];
|
||||
final Runnable run = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int t = 0;
|
||||
for (Chunk chunk : processed_chunks) {
|
||||
short[][] result = gen.generateExtBlockSections(world, r, chunk.getX(), chunk.getZ(), base);
|
||||
int X = chunk.getX();
|
||||
int Z = chunk.getZ();
|
||||
int xb = ((X - cbx) << 4) - bx;
|
||||
int zb = ((Z - cbz) << 4) - bz;
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
if (result[i] == null) {
|
||||
for (int j = 0; j < 4096; j++) {
|
||||
int x = AugmentedPopulator.x_loc[i][j] + xb;
|
||||
if (x < 0 || x >= width) continue;
|
||||
int z = AugmentedPopulator.z_loc[i][j] + zb;
|
||||
if (z < 0 || z >= length) continue;
|
||||
int y = AugmentedPopulator.y_loc[i][j];
|
||||
oldblocks[y][x][z] = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < result[i].length; j++) {
|
||||
int x = AugmentedPopulator.x_loc[i][j] + xb;
|
||||
if (x < 0 || x >= width) continue;
|
||||
int z = AugmentedPopulator.z_loc[i][j] + zb;
|
||||
if (z < 0 || z >= length) continue;
|
||||
int y = AugmentedPopulator.y_loc[i][j];
|
||||
oldblocks[y][x][z] = result[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int size = width * length;
|
||||
int[] changes = new int[size];
|
||||
int[] faces = new int[size];
|
||||
int[] data = new int[size];
|
||||
int[] air = new int[size];
|
||||
int[] variety = new int[size];
|
||||
|
||||
int i = 0;
|
||||
for (int x = 0; x < width;x++) {
|
||||
for (int z = 0; z < length;z++) {
|
||||
HashSet<Short> types = new HashSet<>();
|
||||
for (int y = 0; y < 256; y++) {
|
||||
short old = oldblocks[y][x][z];
|
||||
short now = newblocks[y][x][z];
|
||||
if (old != now) {
|
||||
t++;
|
||||
changes[i]++;
|
||||
}
|
||||
if (now == 0) {
|
||||
air[i]++;
|
||||
}
|
||||
else {
|
||||
// check verticies
|
||||
// modifications_adjacent
|
||||
|
||||
if (x > 0 && z > 0 && y > 0 && x < width - 1 && z < length - 1 && y < 255) {
|
||||
if (oldblocks[y - 1][x][z] == 0) faces[i]++;
|
||||
if (oldblocks[y][x - 1][z] == 0) faces[i]++;
|
||||
if (oldblocks[y][x][z - 1] == 0) faces[i]++;
|
||||
if (oldblocks[y + 1][x][z] == 0) faces[i]++;
|
||||
if (oldblocks[y][x + 1][z] == 0) faces[i]++;
|
||||
if (oldblocks[y][x][z + 1] == 0) faces[i]++;
|
||||
}
|
||||
|
||||
Material material = Material.getMaterial(now);
|
||||
Class<? extends MaterialData> md = material.getData();
|
||||
if (md.equals(Directional.class)) {
|
||||
data[i] += 8;
|
||||
}
|
||||
else if (!md.equals(MaterialData.class)) {
|
||||
data[i]++;
|
||||
}
|
||||
types.add(now);
|
||||
}
|
||||
}
|
||||
variety[i] = types.size();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
// analyze plot
|
||||
// put in analysis obj
|
||||
|
||||
// run whenDone
|
||||
PlotAnalysis analysis = new PlotAnalysis();
|
||||
analysis.changes = getMean(changes);
|
||||
analysis.faces = getMean(faces);
|
||||
analysis.data = getMean(data);
|
||||
analysis.air = getMean(air);
|
||||
analysis.variety = getMean(variety);
|
||||
analysis.complexity = getSD(changes, analysis.changes) + getSD(faces, analysis.faces) + getSD(data, analysis.data) + getSD(air, analysis.air) + getSD(variety, analysis.variety);
|
||||
whenDone.value = analysis;
|
||||
whenDone.run();
|
||||
}
|
||||
};
|
||||
|
||||
final HashSet<Short> variety = new HashSet<>();
|
||||
System.gc();
|
||||
AugmentedPopulator.initCache();
|
||||
|
||||
TaskManager.index.increment();
|
||||
final Integer currentIndex = TaskManager.index.toInteger();
|
||||
@ -146,117 +240,41 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
public void run() {
|
||||
int index = chunks.size() - 1;
|
||||
if (index == -1) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlotSquared.TASK.cancelTask(TaskManager.tasks.get(currentIndex));
|
||||
analysis.variety_total = variety.size();
|
||||
analysis.changes_sd = getSD(changes_sd);
|
||||
analysis.rotations_sd = getSD(rotations_sd);
|
||||
analysis.data_sd = getSD(data_sd);
|
||||
analysis.uniformity_sd = getSD(uniformity_sd);
|
||||
analysis.variety_sd = getSD(variety_sd);
|
||||
analysis.verticies_sd = getSD(verticies_sd);
|
||||
analysis.height_sd = getSD(height_sd);
|
||||
whenDone.value = analysis;
|
||||
whenDone.run();
|
||||
}
|
||||
});
|
||||
PlotSquared.TASK.cancelTask(TaskManager.tasks.get(currentIndex));
|
||||
TaskManager.runTaskAsync(run);
|
||||
return;
|
||||
}
|
||||
Chunk chunk = chunks.remove(0);
|
||||
processed_chunks.add(chunk);
|
||||
int X = chunk.getX();
|
||||
int Z = chunk.getZ();
|
||||
short[][] result = gen.generateExtBlockSections(world, r, chunk.getX(), chunk.getZ(), base);
|
||||
short[][] current = new short[16][];
|
||||
int minX;
|
||||
int minZ;
|
||||
int maxX;
|
||||
int maxZ;
|
||||
if (X == bx) minX = mod(bot.getX());
|
||||
if (X == cbx) minX = mod(bx);
|
||||
else minX = 0;
|
||||
if (Z == bz) minZ = mod(bot.getZ());
|
||||
if (Z == cbz) minZ = mod(bz);
|
||||
else minZ = 0;
|
||||
if (X == tx) maxX = mod(top.getX());
|
||||
if (X == ctx) maxX = mod(tx);
|
||||
else maxX = 16;
|
||||
if (Z == tz) maxZ = mod(top.getZ());
|
||||
if (Z == ctz) maxZ = mod(tz);
|
||||
else maxZ = 16;
|
||||
long changes = 0;
|
||||
long rotations = 0;
|
||||
long materialdata = 0;
|
||||
int[] height = new int[256];
|
||||
|
||||
int collumn_index = 0;
|
||||
for (int x = minX; x < maxX; x++) {
|
||||
for (int z = minZ; z < maxZ; z++) {
|
||||
int max = 0;
|
||||
int xb = ((X - cbx) << 4) - bx;
|
||||
int zb = ((Z - cbz) << 4) - bz;
|
||||
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
for (int y = 0; y < 256; y++) {
|
||||
Block block = chunk.getBlock(x, y, z);
|
||||
int i = y >> 4;
|
||||
int j = ((y & 0xF) << 8) | (z << 4) | x;
|
||||
short id = (short) block.getTypeId();
|
||||
if (id != 0) {
|
||||
if (y > max) {
|
||||
max = y;
|
||||
}
|
||||
BlockState state = block.getState();
|
||||
MaterialData data = state.getData();
|
||||
if (data instanceof Directional) {
|
||||
rotations++;
|
||||
}
|
||||
else if (!data.getClass().equals(MaterialData.class)) {
|
||||
materialdata++;
|
||||
}
|
||||
else {
|
||||
variety.add(id);
|
||||
}
|
||||
}
|
||||
if (current[i] == null) {
|
||||
current[i] = new short[4096];
|
||||
}
|
||||
current[i][j] = id;
|
||||
if (result[i] == null && id != 0 || result[i] != null && result[i][j] != id) {
|
||||
changes++;
|
||||
}
|
||||
int xx = xb + x;
|
||||
int zz = zb + z;
|
||||
newblocks[y][xx][zz] = (short) block.getTypeId();
|
||||
}
|
||||
height[collumn_index] = max;
|
||||
collumn_index++;
|
||||
}
|
||||
}
|
||||
long verticies = 0;
|
||||
int[] uniformity = new int[254];
|
||||
for (int y = 1; y < 255; y++) {
|
||||
HashSet<Integer> blocks = new HashSet<>();
|
||||
for (int x = minX + 1; x < maxX - 1; x++) {
|
||||
for (int z = minZ + 1; z < maxZ - 1; z++) {
|
||||
short id = current[y >> 4][((y & 0xF) << 8) | (z << 4) | x];
|
||||
if (id == 0) continue;
|
||||
blocks.add((int) id);
|
||||
if (current[(y + 1) >> 4][(((y + 1) & 0xF) << 8) | (z << 4) | x] != 0) verticies--;
|
||||
if (current[(y - 1) >> 4][(((y - 1) & 0xF) << 8) | (z << 4) | x] != 0) verticies--;
|
||||
if (current[y >> 4][((y & 0xF) << 8) | ((z + 1) << 4) | x] != 0) verticies--;
|
||||
if (current[y >> 4][((y & 0xF) << 8) | ((z - 1) << 4) | x] != 0) verticies--;
|
||||
if (current[y >> 4][((y & 0xF) << 8) | (z << 4) | (x + 1)] != 0) verticies--;
|
||||
if (current[y >> 4][((y & 0xF) << 8) | (z << 4) | (x - 1)] != 0) verticies--;
|
||||
verticies += 6;
|
||||
}
|
||||
}
|
||||
uniformity[y-1] = blocks.size();
|
||||
}
|
||||
analysis.changes_total += changes;
|
||||
analysis.rotations_total += rotations;
|
||||
analysis.data_total += materialdata;
|
||||
analysis.verticies_total += verticies;
|
||||
double tmp = getSD(height);
|
||||
analysis.height_total += tmp;
|
||||
|
||||
changes_sd[index] = changes;
|
||||
rotations_sd[index] = rotations;
|
||||
data_sd[index] = materialdata;
|
||||
uniformity_sd[index] = getSD(uniformity);
|
||||
variety_sd[index] = variety.size();
|
||||
verticies_sd[index] = verticies;
|
||||
height_sd[index] = tmp;
|
||||
};
|
||||
}, 1);
|
||||
TaskManager.tasks.put(currentIndex, task);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.intellectualcrafters.plot.listeners;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@ -7,6 +8,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Chunk;
|
||||
@ -22,6 +24,7 @@ import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.FallingBlock;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -56,6 +59,7 @@ import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
||||
import org.bukkit.event.hanging.HangingPlaceEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||
import org.bukkit.event.player.PlayerBucketFillEvent;
|
||||
@ -72,6 +76,7 @@ import org.bukkit.event.vehicle.VehicleCreateEvent;
|
||||
import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.material.Tree;
|
||||
import org.bukkit.material.Wool;
|
||||
@ -94,6 +99,7 @@ import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.PlotHandler;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotInventory;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
@ -292,7 +298,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
|
||||
if (split[0].equals("plotme") || split[0].equals("ap")) {
|
||||
final Player player = event.getPlayer();
|
||||
if (Settings.USE_PLOTME_ALIAS) {
|
||||
player.performCommand(message.replace("/plotme", "plots"));
|
||||
player.performCommand("plots " + StringUtils.join(Arrays.copyOfRange(split, 1, split.length), " "));
|
||||
} else {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOT_USING_PLOTME);
|
||||
}
|
||||
@ -1158,12 +1164,31 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onInventoryClick(final InventoryClickEvent event) {
|
||||
if (event.getInventory().getName().equalsIgnoreCase("PlotSquared Commands")) {
|
||||
event.setCancelled(true);
|
||||
HumanEntity clicker = event.getWhoClicked();
|
||||
if (!(clicker instanceof Player) ) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) clicker;
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
PlotInventory inv = (PlotInventory) pp.getMeta("inventory");
|
||||
if (inv != null && event.getRawSlot() == event.getSlot()) {
|
||||
if (!inv.onClick(event.getSlot())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onInventoryClose(final InventoryCloseEvent event) {
|
||||
HumanEntity closer = event.getPlayer();
|
||||
if (!(closer instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) closer;
|
||||
BukkitUtil.getPlayer(player).deleteMeta("inventory");
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority= EventPriority.MONITOR)
|
||||
public void onLeave(final PlayerQuitEvent event) {
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
|
||||
|
@ -22,10 +22,8 @@ package com.intellectualcrafters.plot.listeners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -40,18 +38,14 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent;
|
||||
import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotHandler;
|
||||
@ -103,58 +97,6 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
||||
}, 0l, 20l);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(final InventoryClickEvent event) {
|
||||
final Player player = (Player) event.getWhoClicked();
|
||||
Inventory inv = event.getInventory();
|
||||
if (inv == null) {
|
||||
return;
|
||||
}
|
||||
if (!event.getInventory().getName().equals(ChatColor.RED + "Plot Jukebox")) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
final Plot plot = MainUtil.getPlot(BukkitUtil.getLocation(player));
|
||||
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
if (plot == null) {
|
||||
MainUtil.sendMessage(pp, C.NOT_IN_PLOT);
|
||||
return;
|
||||
}
|
||||
final UUID uuid = pp.getUUID();
|
||||
if (!plot.isAdded(uuid)) {
|
||||
MainUtil.sendMessage(pp, C.NO_PLOT_PERMS);
|
||||
return;
|
||||
}
|
||||
final Set<Player> plotPlayers = new HashSet<>();
|
||||
for (final Player p : player.getWorld().getPlayers()) {
|
||||
final Plot newPlot = MainUtil.getPlot(BukkitUtil.getLocation(player));
|
||||
if (plot.equals(newPlot)) {
|
||||
plotPlayers.add(p);
|
||||
}
|
||||
}
|
||||
RecordMeta meta = null;
|
||||
for (final RecordMeta m : RecordMeta.metaList) {
|
||||
ItemStack item = event.getCurrentItem();
|
||||
if (item != null && m.getMaterial() == item.getType()) {
|
||||
meta = m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (meta == null) {
|
||||
return;
|
||||
}
|
||||
if (meta != null) {
|
||||
int id = meta.getMaterial().getId();
|
||||
FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("music"), id));
|
||||
player.playEffect(player.getLocation(), Effect.RECORD_PLAY, 0);
|
||||
for (final Player p : plotPlayers) {
|
||||
player.playEffect(player.getLocation(), Effect.RECORD_PLAY, 0);
|
||||
player.playEffect(player.getLocation(), Effect.RECORD_PLAY, id);
|
||||
APlotListener.manager.plotEntry(BukkitUtil.getPlayer(p), plot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onInteract(final BlockDamageEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
|
@ -1,18 +1,10 @@
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
public class PlotAnalysis {
|
||||
public int changes_total;
|
||||
public int rotations_total;
|
||||
public int data_total;
|
||||
public int variety_total;
|
||||
public int verticies_total;
|
||||
public double height_total;
|
||||
|
||||
public double changes_sd;
|
||||
public double rotations_sd;
|
||||
public double data_sd;
|
||||
public double variety_sd;
|
||||
public double uniformity_sd;
|
||||
public double verticies_sd;
|
||||
public double height_sd;
|
||||
public double changes;
|
||||
public double faces;
|
||||
public double data;
|
||||
public double air;
|
||||
public double variety;
|
||||
public double complexity;
|
||||
}
|
||||
|
@ -42,9 +42,29 @@ public abstract class PlotGenerator extends ChunkGenerator {
|
||||
public int X;
|
||||
public int Z;
|
||||
private PseudoRandom random = new PseudoRandom();
|
||||
public static short[][][] CACHE_I = null;
|
||||
public static short[][][] CACHE_J = null;
|
||||
|
||||
public PlotGenerator(String world) {
|
||||
WorldEvents.lastWorld = world;
|
||||
initCache();
|
||||
}
|
||||
|
||||
public void initCache() {
|
||||
if (CACHE_I == null) {
|
||||
CACHE_I = new short[256][16][16];
|
||||
CACHE_J = new short[256][16][16];
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int y = 0; y < 256; y++) {
|
||||
short i = (short) (y >> 4);
|
||||
short j = (short) (((y & 0xF) << 8) | (z << 4) | x);
|
||||
CACHE_I[y][x][z] = i;
|
||||
CACHE_J[y][x][z] = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -136,10 +156,10 @@ public abstract class PlotGenerator extends ChunkGenerator {
|
||||
}
|
||||
|
||||
public void setBlock(final int x, final int y, final int z, final short blkid) {
|
||||
if (result[y >> 4] == null) {
|
||||
result[y >> 4] = new short[4096];
|
||||
if (result[CACHE_I[y][x][z]] == null) {
|
||||
result[CACHE_I[y][x][z]] = new short[4096];
|
||||
}
|
||||
result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blkid;
|
||||
result[CACHE_I[y][x][z]][CACHE_J[y][x][z]] = blkid;
|
||||
}
|
||||
|
||||
public void setBlock(final int x, final int y, final int z, final short[] blkid) {
|
||||
@ -147,10 +167,10 @@ public abstract class PlotGenerator extends ChunkGenerator {
|
||||
setBlock(x, y, z, blkid[0]);
|
||||
}
|
||||
short id = blkid[random.random(blkid.length)];
|
||||
if (result[y >> 4] == null) {
|
||||
result[y >> 4] = new short[4096];
|
||||
if (result[CACHE_I[y][x][z]] == null) {
|
||||
result[CACHE_I[y][x][z]] = new short[4096];
|
||||
}
|
||||
result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = id;
|
||||
result[CACHE_I[y][x][z]][CACHE_J[y][x][z]] = id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,81 @@
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
import com.intellectualcrafters.plot.util.InventoryUtil;
|
||||
|
||||
public class PlotInventory {
|
||||
|
||||
public final PlotPlayer player;
|
||||
public final int size;
|
||||
private String title;
|
||||
private final PlotItemStack[] items;
|
||||
|
||||
private boolean open = false;
|
||||
|
||||
public PlotInventory(PlotPlayer player) {
|
||||
this.size = 4;
|
||||
this.title = null;
|
||||
this.player = player;
|
||||
items = InventoryUtil.manager.getItems(player);
|
||||
}
|
||||
|
||||
public PlotInventory(PlotPlayer player, int size, String name) {
|
||||
this.size = size;
|
||||
this.title = name == null ? "" : name;
|
||||
this.player = player;
|
||||
items = new PlotItemStack[size * 9];
|
||||
}
|
||||
|
||||
public boolean onClick(int index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void openInventory() {
|
||||
if (title == null) {
|
||||
return;
|
||||
}
|
||||
open = true;
|
||||
InventoryUtil.manager.open(this);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (title == null) {
|
||||
return;
|
||||
}
|
||||
InventoryUtil.manager.close(this);
|
||||
open = false;
|
||||
}
|
||||
|
||||
public void setItem(int index, PlotItemStack item) {
|
||||
items[index] = item;
|
||||
InventoryUtil.manager.setItem(this, index, item);
|
||||
}
|
||||
|
||||
public PlotItemStack getItem(int index) {
|
||||
return items[index];
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
if (title == null) {
|
||||
return;
|
||||
}
|
||||
boolean tmp = open;
|
||||
close();
|
||||
this.title = title;
|
||||
if (tmp) {
|
||||
openInventory();
|
||||
}
|
||||
}
|
||||
|
||||
public PlotItemStack[] getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return open;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
public class PlotItemStack {
|
||||
public final int id;
|
||||
public final short data;
|
||||
public final int amount;
|
||||
public final String name;
|
||||
public final String[] lore;
|
||||
|
||||
public PlotItemStack(int id, short data, int amount, String name, String[] lore) {
|
||||
this.id = id;
|
||||
this.data = data;
|
||||
this.amount = amount;
|
||||
this.name = name;
|
||||
this.lore = lore;
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.intellectualcrafters.plot.util;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotInventory;
|
||||
import com.intellectualcrafters.plot.object.PlotItemStack;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
|
||||
/**
|
||||
* This class is only used by internal functions, for most cases use the PlotInventory class
|
||||
*/
|
||||
public abstract class InventoryUtil {
|
||||
|
||||
/**
|
||||
* This class is only used by internal functions, for most cases use the PlotInventory class
|
||||
*/
|
||||
public static InventoryUtil manager = null;
|
||||
public abstract void open(PlotInventory inv);
|
||||
public abstract void close(PlotInventory inv);
|
||||
public abstract void setItem(PlotInventory plotInventory, int index, PlotItemStack item);
|
||||
public abstract PlotItemStack[] getItems(PlotPlayer player);
|
||||
public abstract boolean isOpen(PlotInventory plotInventory);
|
||||
}
|
@ -78,6 +78,7 @@ public class MainUtil {
|
||||
if (arg == null) {
|
||||
if (player == null) {
|
||||
if (message) MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD);
|
||||
System.out.print(1);
|
||||
return null;
|
||||
}
|
||||
return getPlot(player.getLocation());
|
||||
@ -87,7 +88,10 @@ public class MainUtil {
|
||||
if (player != null) {
|
||||
worldname = player.getLocation().getWorld();
|
||||
}
|
||||
System.out.print(arg);
|
||||
String[] split = arg.split(";|,");
|
||||
System.out.print(split[0]);
|
||||
System.out.print(split[1]);
|
||||
if (split.length == 3) {
|
||||
worldname = split[0];
|
||||
id = PlotId.fromString(split[1] + ";" + split[2]);
|
||||
@ -122,12 +126,15 @@ public class MainUtil {
|
||||
}
|
||||
if (worldname == null || !PlotSquared.isPlotWorld(worldname)) {
|
||||
if (message) MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD);
|
||||
System.out.print("INVALID WORLD: ");
|
||||
return null;
|
||||
}
|
||||
if (id == null) {
|
||||
System.out.print("INVALID ID: ");
|
||||
if (message) MainUtil.sendMessage(player, C.NOT_VALID_PLOT_ID);
|
||||
return null;
|
||||
}
|
||||
System.out.print("VALID PLOT: ");
|
||||
return getPlot(worldname, id);
|
||||
}
|
||||
|
||||
@ -1566,9 +1573,55 @@ public class MainUtil {
|
||||
return 0;
|
||||
}
|
||||
double val = 0;
|
||||
int size = 0;
|
||||
for (Entry<UUID, Integer> entry : rating.entrySet()) {
|
||||
val += entry.getValue();
|
||||
int current = entry.getValue();
|
||||
if (Settings.RATING_CATEGORIES == null || Settings.RATING_CATEGORIES.size() == 0) {
|
||||
val += current;
|
||||
size++;
|
||||
}
|
||||
else {
|
||||
for (int i = 0 ; i < Settings.RATING_CATEGORIES.size(); i++) {
|
||||
val += (current % 10) - 1;
|
||||
current /= 10;
|
||||
size++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return val / (double) rating.size();
|
||||
return val / (double) size;
|
||||
}
|
||||
|
||||
public static double[] getAverageRatings(Plot plot) {
|
||||
HashMap<UUID, Integer> rating;
|
||||
if (plot.settings.ratings != null) {
|
||||
rating = plot.settings.ratings;
|
||||
}
|
||||
else {
|
||||
rating = DBFunc.getRatings(plot);
|
||||
}
|
||||
int size = 1;
|
||||
if (Settings.RATING_CATEGORIES != null) {
|
||||
size = Math.max(1, Settings.RATING_CATEGORIES.size());
|
||||
}
|
||||
double[] ratings = new double[size];
|
||||
if (rating == null || rating.size() == 0) {
|
||||
return ratings;
|
||||
}
|
||||
for (Entry<UUID, Integer> entry : rating.entrySet()) {
|
||||
int current = entry.getValue();
|
||||
if (Settings.RATING_CATEGORIES == null || Settings.RATING_CATEGORIES.size() == 0) {
|
||||
ratings[0] += current;
|
||||
}
|
||||
else {
|
||||
for (int i = 0 ; i < Settings.RATING_CATEGORIES.size(); i++) {
|
||||
ratings[i] += (current % 10) - 1;
|
||||
current /= 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < size; i++) {
|
||||
ratings[i] /= (double) rating.size();
|
||||
}
|
||||
return ratings;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,127 @@
|
||||
package com.intellectualcrafters.plot.util.bukkit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotInventory;
|
||||
import com.intellectualcrafters.plot.object.PlotItemStack;
|
||||
import com.intellectualcrafters.plot.object.BukkitPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.InventoryUtil;
|
||||
|
||||
public class BukkitInventoryUtil extends InventoryUtil {
|
||||
|
||||
@Override
|
||||
public void open(PlotInventory inv) {
|
||||
BukkitPlayer bp = ((BukkitPlayer) inv.player);
|
||||
Inventory inventory = Bukkit.createInventory(null, inv.size * 9, inv.getTitle());
|
||||
PlotItemStack[] items = inv.getItems();
|
||||
for (int i = 0; i < inv.size * 9; i++) {
|
||||
PlotItemStack item = items[i];
|
||||
if (item != null) {
|
||||
inventory.setItem(i, getItem(item));
|
||||
}
|
||||
}
|
||||
inv.player.setMeta("inventory", inv);
|
||||
bp.player.openInventory(inventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(PlotInventory inv) {
|
||||
if (!inv.isOpen()) {
|
||||
return;
|
||||
}
|
||||
inv.player.deleteMeta("inventory");
|
||||
BukkitPlayer bp = ((BukkitPlayer) inv.player);
|
||||
bp.player.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(PlotInventory inv, int index, PlotItemStack item) {
|
||||
BukkitPlayer bp = ((BukkitPlayer) inv.player);
|
||||
InventoryView opened = bp.player.getOpenInventory();
|
||||
if (!inv.isOpen()) {
|
||||
return;
|
||||
}
|
||||
opened.setItem(index, getItem(item));
|
||||
bp.player.updateInventory();
|
||||
}
|
||||
|
||||
public PlotItemStack getItem(ItemStack item ) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
int id = item.getTypeId();
|
||||
short data = item.getDurability();
|
||||
int amount = item.getAmount();
|
||||
String name = null;
|
||||
String[] lore = null;
|
||||
if (item.hasItemMeta()) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta.hasDisplayName()) {
|
||||
name = meta.getDisplayName();
|
||||
}
|
||||
if (meta.hasLore()) {
|
||||
List<String> itemLore = meta.getLore();
|
||||
lore = itemLore.toArray(new String[itemLore.size()]);
|
||||
}
|
||||
}
|
||||
return new PlotItemStack(id, data, amount, name, lore);
|
||||
}
|
||||
|
||||
public static ItemStack getItem(PlotItemStack item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
ItemStack stack = new ItemStack(item.id, item.amount, item.data);
|
||||
ItemMeta meta = null;
|
||||
if (item.name != null) {
|
||||
meta = stack.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', item.name));
|
||||
}
|
||||
if (item.lore != null) {
|
||||
if (meta == null) {
|
||||
meta = stack.getItemMeta();
|
||||
}
|
||||
List<String> lore = new ArrayList<>();
|
||||
for (String entry : item.lore) {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', entry));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
}
|
||||
if (meta != null) {
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotItemStack[] getItems(PlotPlayer player) {
|
||||
BukkitPlayer bp = ((BukkitPlayer) player);
|
||||
PlayerInventory inv = bp.player.getInventory();
|
||||
PlotItemStack[] items = new PlotItemStack[36];
|
||||
for (int i = 0; i < 36; i++) {
|
||||
items[i] = getItem(inv.getItem(i));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen(PlotInventory inv) {
|
||||
if (!inv.isOpen()) {
|
||||
return false;
|
||||
}
|
||||
BukkitPlayer bp = ((BukkitPlayer) inv.player);
|
||||
InventoryView opened = bp.player.getOpenInventory();
|
||||
return (inv.isOpen() && opened.getType() == InventoryType.CRAFTING && opened.getTitle() == null);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user