Plot home position + another attempt to fix minor UUID issue.

This commit is contained in:
boy0001 2015-01-13 02:52:33 +11:00
parent d833935a30
commit f70b7c3f93
12 changed files with 71 additions and 70 deletions

View File

@ -6,7 +6,7 @@
<groupId>com.intellectualcrafters</groupId>
<artifactId>PlotSquared</artifactId>
<version>2.5.6</version>
<version>2.5.7</version>
<name>PlotSquared</name>
<packaging>jar</packaging>
<build>

View File

@ -180,7 +180,7 @@ import java.util.UUID;
String owner = "none";
if (plot.owner != null) {
owner = UUIDHandler.uuidWrapper.getOfflinePlayer(plot.owner).getName();
owner = UUIDHandler.getName(plot.owner);
}
if (owner == null) {
owner = plot.owner.toString();

View File

@ -30,17 +30,20 @@ import com.intellectualcrafters.plot.flag.AbstractFlag;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.listeners.PlotListener;
import com.intellectualcrafters.plot.object.BlockLoc;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotHomePosition;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.PlayerFunctions;
import com.intellectualcrafters.plot.util.PlotHelper;
import com.intellectualcrafters.plot.util.StringComparison;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.entity.Player;
@ -174,23 +177,24 @@ public class Set extends SubCommand {
}
if (args[0].equalsIgnoreCase("home")) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.MISSING_POSITION);
return false;
}
PlotHomePosition position = null;
for (final PlotHomePosition p : PlotHomePosition.values()) {
if (p.isMatching(args[1])) {
position = p;
if (args.length > 1) {
if (args[1].equalsIgnoreCase("none")) {
plot.settings.setPosition(null);
DBFunc.setPosition(plr.getWorld().getName(), plot, "");
return true;
}
return PlayerFunctions.sendMessage(plr, C.HOME_ARGUMENT);
}
if (position == null) {
PlayerFunctions.sendMessage(plr, C.INVALID_POSITION);
return false;
}
DBFunc.setPosition(plr.getWorld().getName(), plot, position.toString());
PlayerFunctions.sendMessage(plr, C.POSITION_SET);
return true;
//set to current location
World world = plr.getWorld();
Location base = PlotHelper.getPlotBottomLoc(world, plot.id);
int y = PlotHelper.getHeighestBlock(world, base.getBlockX(), base.getBlockZ());
base.setY(y);
Location relative = plr.getLocation().subtract(base);
BlockLoc blockloc = new BlockLoc(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ());
plot.settings.setPosition(blockloc);
DBFunc.setPosition(plr.getWorld().getName(), plot, relative.getBlockX() + "," + relative.getBlockY() + "," + relative.getBlockZ());
return PlayerFunctions.sendMessage(plr, C.POSITION_SET);
}
if (args[0].equalsIgnoreCase("alias")) {

View File

@ -147,8 +147,9 @@ public enum C {
/*
* Position
*/
MISSING_POSITION("&cYou need to specify a position. Possible values: &6default&c, &6center"),
POSITION_SET("&cPlot home position set"),
MISSING_POSITION("&cYou need to specify a position. Possible values: &6none"),
POSITION_SET("&cPlot home position set to your current location"),
HOME_ARGUMENT("&cUse /plot set home [none]"),
INVALID_POSITION("&cThat is not a valid position value"),
/*
* Time

View File

@ -24,9 +24,9 @@ package com.intellectualcrafters.plot.database;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.BlockLoc;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotComment;
import com.intellectualcrafters.plot.object.PlotHomePosition;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
@ -540,7 +540,7 @@ public class SQLManager implements AbstractDB {
user = UUID.fromString(o);
uuids.put(o, user);
}
p = new Plot(plot_id, user, new ArrayList<UUID>(), new ArrayList<UUID>(), new ArrayList<UUID>(), "", PlotHomePosition.DEFAULT, null, worldname, new boolean[]{false, false, false, false});
p = new Plot(plot_id, user, new ArrayList<UUID>(), new ArrayList<UUID>(), new ArrayList<UUID>(), "", null, null, worldname, new boolean[]{false, false, false, false});
plots.put(id, p);
}
// stmt.close();
@ -632,15 +632,20 @@ public class SQLManager implements AbstractDB {
}
final String pos = r.getString("position");
if (pos != null) {
for (final PlotHomePosition plotHomePosition : PlotHomePosition.values()) {
if (plotHomePosition.isMatching(pos)) {
if (plotHomePosition != PlotHomePosition.DEFAULT) {
plot.settings.setPosition(plotHomePosition);
}
break;
switch (pos.toLowerCase()) {
case "":
case "default":
case "0,0,0":
case "center":
break;
default:
try {
String[] split = pos.split(",");
BlockLoc loc = new BlockLoc(Integer.parseInt(split[0]),Integer.parseInt(split[1]),Integer.parseInt(split[2]));
plot.settings.setPosition(loc);
}
}
catch (Exception e) {}
}
final Integer m = r.getInt("merged");
if (m != null) {
@ -886,7 +891,6 @@ public class SQLManager implements AbstractDB {
*/
@Override
public void setPosition(final String world, final Plot plot, final String position) {
plot.settings.setPosition(PlotHomePosition.valueOf(position));
TaskManager.runTask(new Runnable() {
@Override
public void run() {

View File

@ -1,5 +1,8 @@
package com.intellectualcrafters.plot.object;
import org.bukkit.Location;
import org.bukkit.World;
public class BlockLoc {
public int x;

View File

@ -109,7 +109,6 @@ import java.util.UUID;
this.denied = denied;
this.trusted = new ArrayList<>();
this.settings.setAlias("");
this.settings.setPosition(PlotHomePosition.DEFAULT);
this.delete = false;
this.settings.flags = new HashSet<Flag>();
this.world = world;
@ -132,7 +131,6 @@ import java.util.UUID;
this.denied = denied;
this.trusted = new ArrayList<>();
this.settings.setAlias("");
this.settings.setPosition(PlotHomePosition.DEFAULT);
this.delete = false;
this.settings.flags = new HashSet<Flag>();
this.world = world;
@ -152,7 +150,7 @@ import java.util.UUID;
*/
@Deprecated
@SuppressWarnings("unused")
public Plot(final PlotId id, final UUID owner, final Biome plotBiome, final ArrayList<UUID> helpers, final ArrayList<UUID> trusted, final ArrayList<UUID> denied, final String alias, final PlotHomePosition position, final Set<Flag> flags, final String world, final boolean[] merged) {
public Plot(final PlotId id, final UUID owner, final Biome plotBiome, final ArrayList<UUID> helpers, final ArrayList<UUID> trusted, final ArrayList<UUID> denied, final String alias, final BlockLoc position, final Set<Flag> flags, final String world, final boolean[] merged) {
this.id = id;
this.settings = new PlotSettings(this);
this.owner = owner;
@ -181,7 +179,7 @@ import java.util.UUID;
* @param denied
* @param merged
*/
public Plot(final PlotId id, final UUID owner, final ArrayList<UUID> helpers, final ArrayList<UUID> trusted, final ArrayList<UUID> denied, final String alias, final PlotHomePosition position, final Set<Flag> flags, final String world, final boolean[] merged) {
public Plot(final PlotId id, final UUID owner, final ArrayList<UUID> helpers, final ArrayList<UUID> trusted, final ArrayList<UUID> denied, final String alias, final BlockLoc position, final Set<Flag> flags, final String world, final boolean[] merged) {
this.id = id;
this.settings = new PlotSettings(this);
this.owner = owner;

View File

@ -26,6 +26,7 @@ import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.util.PlotHelper;
import com.sun.istack.internal.NotNull;
import org.bukkit.Location;
import org.bukkit.block.Biome;
import java.util.ArrayList;
@ -63,7 +64,7 @@ import java.util.Set;
/**
* Home Position
*/
private PlotHomePosition position;
private BlockLoc position;
/**
* Constructor
@ -112,11 +113,14 @@ import java.util.Set;
return PlotHelper.getPlotBottomLoc(this.plot.getWorld(), this.plot.getId()).add(1, 0, 1).getBlock().getBiome();
}
public PlotHomePosition getPosition() {
public BlockLoc getPosition() {
if (this.position == null) {
return new BlockLoc(0, 0, 0);
}
return this.position;
}
public void setPosition(final PlotHomePosition position) {
public void setPosition(BlockLoc position) {
this.position = position;
}

View File

@ -53,18 +53,6 @@ import java.util.*;
return getCurrentPlot(player) != null;
}
/**
* @param plot plot
*
* @return
*/
public static boolean hasExpired(final Plot plot) {
final OfflinePlayer player = UUIDHandler.uuidWrapper.getOfflinePlayer(plot.owner);
final long lp = player.getLastPlayed();
final long cu = System.currentTimeMillis();
return (lp - cu) > 30l;
}
public static ArrayList<PlotId> getPlotSelectionIds(@SuppressWarnings("unused") final World world, final PlotId pos1, final PlotId pos2) {
final ArrayList<PlotId> myplots = new ArrayList<>();
for (int x = pos1.x; x <= pos2.x; x++) {

View File

@ -280,7 +280,7 @@ import java.util.UUID;
return "unknown";
}
final OfflinePlayer plr = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
if (plr == null) {
if (!plr.hasPlayedBefore()) {
return "unknown";
}
return plr.getName();
@ -889,22 +889,19 @@ import java.util.UUID;
* @return Home Location
*/
public static Location getPlotHome(final World w, final PlotId plotid) {
if (getPlot(w, plotid).settings.getPosition() == PlotHomePosition.DEFAULT) {
final Location bot = getPlotBottomLoc(w, plotid);
final int x = bot.getBlockX();
final int z = bot.getBlockZ() - 2;
final int y = getHeighestBlock(w, x, z);
return new Location(w, x, y, z);
} else {
final Location bot = getPlotBottomLoc(w, plotid), top = getPlotTopLoc(w, plotid);
Plot plot = getPlot(w, plotid);
BlockLoc home = plot.settings.getPosition();
final Location bot = getPlotBottomLoc(w, plotid);
if (home == null) {
final Location top = getPlotTopLoc(w, plotid);
final int x = top.getBlockX() - bot.getBlockX();
final int z = top.getBlockZ() - bot.getBlockZ();
final int y = getHeighestBlock(w, x, z);
return new Location(w, bot.getBlockX() + (x / 2), y, bot.getBlockZ() + (z / 2));
}
else {
return bot.add(home.x, home.y, home.z);
}
}
/**

View File

@ -32,15 +32,17 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
name = null;
}
if (name != null) {
return Bukkit.getOfflinePlayer(name);
} else {
for (final OfflinePlayer player : Bukkit.getOfflinePlayers()) {
if (getUUID(player).equals(uuid)) {
return player;
}
OfflinePlayer op = Bukkit.getOfflinePlayer(name);
if (op.hasPlayedBefore()) {
return op;
}
}
return Bukkit.getOfflinePlayer(uuid.toString());
for (final OfflinePlayer player : Bukkit.getOfflinePlayers()) {
if (getUUID(player).equals(uuid)) {
return player;
}
}
return null;
}
@Override

View File

@ -19,7 +19,7 @@
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.object;
package com.intellectualcrafters.unused;
/**
* @author Citymonstret