sponge changes / documentation / cleanup / event tweak
This commit is contained in:
Jesse Boyd 2016-03-13 03:57:24 +11:00
parent edc43bd53b
commit a8fd1b49ca
20 changed files with 562 additions and 240 deletions

View File

@ -53,14 +53,18 @@ import java.util.Set;
import java.util.UUID;
/**
* PlotSquared API
*
* @version API 2.0
*
* PlotSquared API<br>
* <br>
* @version API 3.3.1
* <br>
* Useful classes:<br>
* @see BukkitUtil
* @see PlotPlayer
* @see Plot
* @see com.intellectualcrafters.plot.object.Location
* @see PlotArea
* @see PS
*/
public class PlotAPI {
/**

View File

@ -5,13 +5,38 @@ import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.util.*;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
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.PlotPlayer;
import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.RegExUtil;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.bukkit.BukkitMain;
import com.plotsquared.bukkit.object.BukkitLazyBlock;
import com.plotsquared.bukkit.object.BukkitPlayer;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.listener.PlayerBlockEventType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -20,17 +45,64 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.*;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Creature;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Hanging;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.*;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockGrowEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockRedstoneEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.EntityBlockFormEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.entity.PotionSplashEvent;
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.*;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerEggThrowEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.vehicle.VehicleCreateEvent;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.event.world.StructureGrowEvent;
@ -43,10 +115,6 @@ import org.bukkit.projectiles.BlockProjectileSource;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;
import java.util.*;
import java.util.Map.Entry;
import java.util.regex.Pattern;
/**
* Player Events involving plots
*
@ -1009,7 +1077,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
}
lb = new BukkitLazyBlock(blockId, block);
final ItemStack hand = player.getItemInHand();
if (eventType != null && !player.isSneaking()) {
if (eventType != null) {
break;
}
Material type = (hand == null) ? null : hand.getType();

View File

@ -58,7 +58,7 @@ public class Auto extends SubCommand {
return new PlotId(id.x + 1, id.y);
}
} else {
if (id.x.equals(id.y) && (id.x > 0)) {
if (id.x == id.y && (id.x > 0)) {
return new PlotId(id.x, id.y + step);
}
if (id.x == absX) {
@ -159,6 +159,7 @@ public class Auto extends SubCommand {
return true;
}
}
// TODO handle type 2 the same as normal worlds!
if (plotarea.TYPE == 2) {
final PlotId bot = plotarea.getMin();
final PlotId top = plotarea.getMax();
@ -180,34 +181,26 @@ public class Auto extends SubCommand {
MainUtil.sendMessage(plr, C.NO_FREE_PLOTS);
return false;
}
plotarea.setMeta("lastPlot", new PlotId(0, 0));
boolean br = false;
if ((size_x == 1) && (size_z == 1)) {
while (!br) {
Plot plot = plotarea.getPlotAbs(getLastPlotId(plotarea));
if (plot.canClaim(plr)) {
plot.claim(plr, true, null);
br = true;
}
plotarea.setMeta("lastPlot", getNextPlotId(plot.getId(), 1));
}
} else {
while (!br) {
final PlotId start = getNextPlotId(getLastPlotId(plotarea), 1);
final PlotId end = new PlotId((start.x + size_x) - 1, (start.y + size_z) - 1);
plotarea.setMeta("lastPlot", start);
if (plotarea.canClaim(plr, start, end)) {
for (int i = start.x; i <= end.x; i++) {
for (int j = start.y; j <= end.y; j++) {
Plot plot = plotarea.getPlotAbs(new PlotId(i, j));
final boolean teleport = ((i == end.x) && (j == end.y));
plot.claim(plr, teleport, null);
}
while (true) {
final PlotId start = getNextPlotId(getLastPlotId(plotarea), 1);
final PlotId end = new PlotId((start.x + size_x) - 1, (start.y + size_z) - 1);
plotarea.setMeta("lastPlot", start);
if (plotarea.canClaim(plr, start, end)) {
for (int i = start.x; i <= end.x; i++) {
for (int j = start.y; j <= end.y; j++) {
Plot plot = plotarea.getPlotAbs(new PlotId(i, j));
final boolean teleport = ((i == end.x) && (j == end.y));
plot.claim(plr, teleport, null);
}
}
if ((size_x != 1) || (size_z != 1)) {
if (!plotarea.mergePlots(MainUtil.getPlotSelectionIds(start, end), Settings.MERGE_REMOVES_ROADS, true)) {
return false;
}
br = true;
}
break;
}
}
plotarea.setMeta("lastPlot", new PlotId(0, 0));

View File

@ -68,7 +68,7 @@ public class Buy extends SubCommand {
}
} else {
plot = loc.getPlotAbs();
plots = plot.getConnectedPlots();
plots = plot != null ? plot.getConnectedPlots() : null;
}
if (plots == null) {
return sendMessage(plr, C.NOT_IN_PLOT);

View File

@ -8,6 +8,11 @@ import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.PlotChunk;
/**
* This class allows for implementation independent world generation<br>
* - Sponge/Bukkit API<br><br>
* Use the specify method to get the generator for that platform.
*/
public abstract class IndependentPlotGenerator {
/**

View File

@ -45,7 +45,12 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
/**
* The plot class
* The plot class<br>
* [IMPORTANT]
* - Unclaimed plots will not have persistent information.
* - Any information set/modified in an unclaimed object may not be reflected in other instances
* - Using the `new` operator will create an unclaimed plot instance
* - Use the methods from the PlotArea/PS/Location etc to get existing plots
*/
@SuppressWarnings("javadoc")
public class Plot {
@ -211,7 +216,13 @@ public class Plot {
this.timestamp = timestamp;
this.temp = temp;
}
/**
* Get a plot from a string e.g. [area];[id]
* @param defaultArea If no area is specified
* @param string plot id/area + id
* @return New or existing plot object
*/
public static Plot fromString(final PlotArea defaultArea, final String string) {
final String[] split = string.split(";|,");
if (split.length == 2) {
@ -430,7 +441,13 @@ public class Plot {
public PlotArea getArea() {
return this.area;
}
/**
* Assign this plot to a plot area.<br>
* (Mostly used during startup when worlds are being created)<br>
* Note: Using this when it doesn't make sense will result in strange behavior
* @param area
*/
public void setArea(final PlotArea area) {
if (this.getArea() == area) {
return;
@ -497,7 +514,7 @@ public class Plot {
this.origin = this;
PlotId min = this.id;
for (final Plot plot : this.getConnectedPlots()) {
if ((plot.id.y < min.y) || (plot.id.y.equals(min.y) && (plot.id.x < min.x))) {
if ((plot.id.y < min.y) || (plot.id.y == min.y && plot.id.x < min.x)) {
this.origin = plot;
min = plot.id;
}
@ -1022,7 +1039,12 @@ public class Plot {
}
return value;
}
/**
* Decrement the number of tracked tasks this plot is running<br>
* - Used to track/limit the number of things a player can do on the plot at once
* @return previous number of tasks (int)
*/
public int removeRunning() {
final int value = this.getRunning();
if (value < 2) {
@ -1036,12 +1058,22 @@ public class Plot {
}
return value;
}
/**
* Get the number of tracked running tasks for this plot<br>
* - Used to track/limit the number of things a player can do on the plot at once
* @return number of tasks (int)
*/
public int getRunning() {
final Integer value = (Integer) this.getMeta("running");
return value == null ? 0 : value;
}
/**
* Unclaim the plot (does not modify terrain)<br>
* - Changes made to this plot will not be reflected in unclaimed plot objects<br>
* @return
*/
public boolean unclaim() {
if (owner == null) {
return false;
@ -1759,7 +1791,7 @@ public class Plot {
}
});
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
@ -1776,8 +1808,10 @@ public class Plot {
}
/**
* Get the plot hashcode
*
* Get the plot hashcode<br>
* Note: The hashcode is unique if:<br>
* - Plots are in the same world<br>
* - The x,z coordinates are between Short.MIN_VALUE and Short.MAX_VALUE<br>
* @return integer.
*/
@Override
@ -1853,7 +1887,7 @@ public class Plot {
if (value) {
final Plot other = this.getRelative(direction).getBasePlot(false);
if (!other.equals(this.getBasePlot(false))) {
final Plot base = (other.id.y < this.id.y) || (other.id.y.equals(this.id.y) && (other.id.x < this.id.x)) ? other : this.origin;
final Plot base = (other.id.y < this.id.y) || (other.id.y == this.id.y && (other.id.x < this.id.x)) ? other : this.origin;
this.origin.origin = base;
other.origin = base;
this.origin = base;
@ -1919,7 +1953,12 @@ public class Plot {
}
return this.settings.getPosition();
}
/**
* Check if a plot can be claimed
* @param player
* @return
*/
public boolean canClaim(final PlotPlayer player) {
if (Settings.ENABLE_CLUSTERS) {
final PlotCluster cluster = this.getCluster();
@ -1929,9 +1968,14 @@ public class Plot {
}
}
}
return this.guessOwner() == null;
return this.guessOwner() == null && !isMerged();
}
/**
* Guess the owner of a plot either by the value in memory, or the sign data<br>
* Note: Recovering from sign information is useful if e.g. PlotMe conversion wasn't successful
* @return UUID
*/
public UUID guessOwner() {
if (this.hasOwner()) {
return this.owner;
@ -2137,7 +2181,10 @@ public class Plot {
this.addDenied(uuid);
}
}
/**
* Remove the SE road (only effects terrain)
*/
public void removeRoadSouthEast() {
if ((this.area.TYPE != 0) && (this.area.TERRAIN > 1)) {
if (this.area.TERRAIN == 3) {
@ -2153,11 +2200,28 @@ public class Plot {
this.area.getPlotManager().removeRoadSouthEast(this.area, this);
}
}
/**
* Get the plot in a relative location<br>
* Note: May be null if the partial plot area does not include the relative location
* @param x
* @param y
* @return Plot
*/
public Plot getRelative(final int x, final int y) {
return this.area.getPlotAbs(this.id.getRelative(x, y));
}
/**
* Get the plot in a relative direction<br>
* 0 = north<br>
* 1 = east<br>
* 2 = south<br>
* 3 = west<br>
* Note: May be null if the partial plot area does not include the relative location
* @param direction
* @return
*/
public Plot getRelative(final int direction) {
return this.area.getPlotAbs(this.id.getRelative(direction));
}
@ -2427,7 +2491,11 @@ public class Plot {
}
return max;
}
/**
* Do the plot entry tasks for each player in the plot<br>
* - Usually called when the plot state changes (unclaimed/claimed/flag change etc)
*/
public void reEnter() {
TaskManager.runTaskLater(new Runnable() {
@Override
@ -2564,7 +2632,7 @@ public class Plot {
*/
public void mergePlot(Plot lesserPlot, final boolean removeRoads) {
Plot greaterPlot = this;
if (lesserPlot.getId().x.equals(greaterPlot.getId().x)) {
if (lesserPlot.getId().x == greaterPlot.getId().x) {
if (lesserPlot.getId().y > greaterPlot.getId().y) {
final Plot tmp = lesserPlot;
lesserPlot = greaterPlot;

View File

@ -97,7 +97,13 @@ public abstract class PlotArea {
}
this.worldhash = worldname.hashCode();
}
/**
* Create a new PlotArea object with no functionality/information<br>
* - Mainly used during startup before worlds are created as a temporary object
* @param world
* @return
*/
public static PlotArea createGeneric(String world) {
return new PlotArea(world, null, null, null, null) {
@Override
@ -108,8 +114,9 @@ public abstract class PlotArea {
}
/**
* Returns the region for this PlotArea
* @return
* Returns the region for this PlotArea or a RegionWrapper encompassing the whole world if none exists
* @NotNull
* @return RegionWrapper
*/
public RegionWrapper getRegion() {
region = getRegionAbs();
@ -118,7 +125,12 @@ public abstract class PlotArea {
}
return region;
}
/**
* Returns the region for this PlotArea
* @Nullable
* @return RegionWrapper or null if no applicable region
*/
public RegionWrapper getRegionAbs() {
if (region == null) {
if (min != null) {
@ -146,6 +158,11 @@ public abstract class PlotArea {
return max == null ? new PlotId(Integer.MAX_VALUE, Integer.MAX_VALUE) : max;
}
/**
* Get the implementation independent generator for this area
* @Nullable
* @return
*/
public IndependentPlotGenerator getGenerator() {
return generator;
}
@ -169,6 +186,11 @@ public abstract class PlotArea {
return clusters == null ? new HashSet<PlotCluster>() : clusters.getAll();
}
/**
* Check if a PlotArea is compatible (move/copy etc)
* @param plotarea
* @return
*/
public boolean isCompatible(PlotArea plotarea) {
final ConfigurationSection section = PS.get().config.getConfigurationSection("worlds");
for (final ConfigurationNode setting : plotarea.getSettingNodes()) {
@ -358,7 +380,12 @@ public abstract class PlotArea {
* @return ConfigurationNode[]
*/
public abstract ConfigurationNode[] getSettingNodes();
/**
* Get the Plot at a location
* @param loc
* @return Plot
*/
public Plot getPlotAbs(Location loc) {
PlotId pid = manager.getPlotId(this, loc.getX(), loc.getY(), loc.getZ());
if (pid == null) {
@ -366,7 +393,12 @@ public abstract class PlotArea {
}
return getPlotAbs(pid);
}
/**
* Get the base plot at a location
* @param loc
* @return base Plot
*/
public Plot getPlot(Location loc) {
PlotId pid = manager.getPlotId(this, loc.getX(), loc.getY(), loc.getZ());
if (pid == null) {
@ -374,7 +406,12 @@ public abstract class PlotArea {
}
return getPlot(pid);
}
/**
* Get the base owned plot at a location
* @param loc
* @return base Plot or null
*/
public Plot getOwnedPlot(Location loc) {
PlotId pid = manager.getPlotId(this, loc.getX(), loc.getY(), loc.getZ());
if (pid == null) {
@ -383,7 +420,12 @@ public abstract class PlotArea {
Plot plot = plots.get(pid);
return plot == null ? null : plot.getBasePlot(false);
}
/**
* Get the owned plot at a location
* @param loc
* @return Plot or null
*/
public Plot getOwnedPlotAbs(Location loc) {
PlotId pid = manager.getPlotId(this, loc.getX(), loc.getY(), loc.getZ());
if (pid == null) {
@ -391,7 +433,12 @@ public abstract class PlotArea {
}
return plots.get(pid);
}
/**
* Get the owned Plot at a PlotId
* @param id
* @return Plot or null
*/
public Plot getOwnedPlotAbs(PlotId id) {
return plots.get(id);
}
@ -688,7 +735,7 @@ public abstract class PlotArea {
for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) {
final PlotId id = new PlotId(x, y);
final Plot plot = getPlot(id);
final Plot plot = getPlotAbs(id);
if (!plot.canClaim(player)) {
return false;
}

View File

@ -24,11 +24,11 @@ public class PlotId {
/**
* x value
*/
public Integer x;
public int x;
/**
* y value
*/
public Integer y;
public int y;
private int hash;
/**
@ -68,10 +68,25 @@ public class PlotId {
return new PlotId(x, y);
}
/**
* Get the PlotId from the HashCode<br>
* Note: Only accurate for small x,z values (short)
* @param hash
* @return
*/
public static PlotId unpair(int hash) {
return new PlotId(hash >> 16, hash & 0xFFFF);
}
/**
* Get the PlotId in a relative direction
* 0 = north<br>
* 1 = east<br>
* 2 = south<br>
* 3 = west<br>
* @param direction
* @return PlotId
*/
public PlotId getRelative(final int direction) {
switch (direction) {
case 0:
@ -85,7 +100,13 @@ public class PlotId {
}
return this;
}
/**
* Get the PlotId in a relative location
* @param x
* @param y
* @return PlotId
*/
public PlotId getRelative(int x, int y) {
return new PlotId(this.x + x, this.y + y);
}
@ -98,18 +119,31 @@ public class PlotId {
if (obj == null) {
return false;
}
if (this.hashCode() != obj.hashCode()) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final PlotId other = (PlotId) obj;
return ((x.equals(other.x)) && (y.equals(other.y)));
return x == other.x && y == other.y;
}
/**
* e.g.
* 5;-6
* @return
*/
@Override
public String toString() {
return x + ";" + y;
}
/**
* The PlotId object caches the hashcode for faster mapping/fetching/sorting<br>
* - Recalculation is required if the x/y values change
* TODO maybe make x/y values private and add this to the mutators
*/
public void recalculateHash() {
hash = 0;
hashCode();

View File

@ -1,8 +1,15 @@
package com.intellectualcrafters.plot.util;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
/**
* The PlotChunk class is primarily used for world generation and mass block placement.<br>
* - With mass block placement, it is associated with a queue<br>
* - World Generation has no queue, so don't use those methods in that case
* @param <T>
*/
public abstract class PlotChunk<T> implements Cloneable {
private ChunkWrapper chunk;
private T objChunk;
@ -31,43 +38,153 @@ public abstract class PlotChunk<T> implements Cloneable {
return chunk.z;
}
/**
* Adds this PlotChunk to the SetQueue for later block placement<br>
* - Will cause issues if not the right type for the implementation
*/
public void addToQueue() {
if (chunk == null) {
throw new IllegalArgumentException("Chunk location cannot be null!");
}
((PlotQueue<T>) SetQueue.IMP.queue).setChunk(this);
}
/**
* Force the queue to finish processing this chunk
* @param fixLighting
*/
public void flush(boolean fixLighting) {
((PlotQueue<T>) SetQueue.IMP.queue).next(getChunkWrapper(), fixLighting);
}
/**
* Force the queue to fix lighting for this chunk
*/
public void fixLighting() {
((PlotQueue<T>) SetQueue.IMP.queue).fixLighting(this, true);
}
/**
* Fill this chunk with a block
* @param id
* @param data
*/
public void fill(int id, byte data) {
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 256; y++) {
for (int z = 0; z < 16; z++) {
fillCuboid(0, 15, 0, 255, 0, 15, id, data);
}
/**
* Fill this chunk with blocks (random)
* @param blocks
*/
public void fill(PlotBlock[] blocks) {
fillCuboid(0, 15, 0, 255, 0, 15, blocks);
}
/**
* Fill a cuboid in this chunk with a block
* @param x1
* @param x2
* @param y1
* @param y2
* @param z1
* @param z2
* @param id
* @param data
*/
public void fillCuboid(int x1, int x2, int y1, int y2, int z1, int z2, int id, byte data) {
for (int x = x1; x <= x2; x++) {
for (int y = y1; y <= y2; y++) {
for (int z = z1; z <= z2; z++) {
setBlock(x, y, z, id, data);
}
}
}
}
/**
* Fill a cuboid in this chunk with blocks
* @param x1
* @param x2
* @param y1
* @param y2
* @param z1
* @param z2
* @param blocks
*/
public void fillCuboid(int x1, int x2, int y1, int y2, int z1, int z2, PlotBlock[] blocks) {
if (blocks.length == 1) {
fillCuboid(x1, x2, y1, y2, z1, z2, blocks[0]);
return;
}
if (chunk != null) {
PseudoRandom.random.state = (chunk.x << 16) | (chunk.z & 0xFFFF);
}
for (int x = x1; x <= x2; x++) {
for (int y = y1; y <= y2; y++) {
for (int z = z1; z <= z2; z++) {
setBlock(x, y, z, blocks[PseudoRandom.random.random(blocks.length)]);
}
}
}
}
/**
* Fill a cuboid in this chunk with a block
* @param x1
* @param x2
* @param y1
* @param y2
* @param z1
* @param z2
* @param block
*/
public void fillCuboid(int x1, int x2, int y1, int y2, int z1, int z2, PlotBlock block) {
fillCuboid(x1, x2, y1, y2, z1, z2, block.id, block.data);
}
/**
* Get the implementation specific chunk
* @Nullable If no location is tied to this container
* @return Chunk
*/
public T getChunk() {
return objChunk != null ? objChunk : getChunkAbs();
}
/**
* Get the implementation specific chunk (no caching)
* @return
*/
public abstract T getChunkAbs();
/**
* Set a block in this container
* @param x
* @param y
* @param z
* @param id
* @param data
*/
public abstract void setBlock(final int x, final int y, final int z, final int id, final byte data);
/**
* Set a block in this container
* @param x
* @param y
* @param z
* @param block
*/
public void setBlock(int x, int y, int z, PlotBlock block) {
setBlock(x, y, z, block.id, block.data);
}
/**
* Set a biome in this container
* @param x
* @param z
* @param biome
*/
public abstract void setBiome(int x, int z, int biome);
@Override
@ -87,9 +204,19 @@ public abstract class PlotChunk<T> implements Cloneable {
public String toString() {
return getChunkWrapper().toString();
}
/**
* Attempt to clone this PlotChunk object<br>
* - Depending on the implementation, this may not work
* @return
*/
@Override
public abstract PlotChunk clone();
/**
* Attempt a shallow clone i.e. block mappings share the same reference<br>
* - Depending on the implementation, this may not work
* @return
*/
public abstract PlotChunk shallowClone();
}

View File

@ -1,64 +1,64 @@
package com.intellectualcrafters.plot;
import static com.intellectualcrafters.plot.PS.log;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.List;
public class UpdaterTest {
@org.junit.Test
public void getUpdate() throws Exception {
String str = null;
BufferedReader reader = null;
try {
URL url = new URL("https://api.github.com/repos/IntellectualSites/PlotSquared/releases/latest");
reader = new BufferedReader(new InputStreamReader(url.openStream()));
StringBuilder buffer = new StringBuilder();
int read;
char[] chars = new char[1024];
while ((read = reader.read(chars)) != -1) {
buffer.append(chars, 0, read);
}
str = buffer.toString();
} catch (IOException e) {
log("&dCould not check for updates (0)");
e.printStackTrace();
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
if (str == null) {
return;
}
Gson gson = new Gson();
Release release = gson.fromJson(str, Release.class);
System.out.println(release.name);
for (Release.Assets asset : release.assets) {
System.out.println(asset.name);
System.out.println(asset.downloadUrl);
}
}
private static class Release {
String name;
List<Assets> assets;
private static class Assets {
String name;
@SerializedName("browser_download_url") String downloadUrl;
}
}
}
//package com.intellectualcrafters.plot;
//
//import static com.intellectualcrafters.plot.PS.log;
//
//import com.google.gson.Gson;
//import com.google.gson.annotations.SerializedName;
//
//import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStreamReader;
//import java.net.URL;
//import java.util.List;
//
//public class UpdaterTest {
//
// @org.junit.Test
// public void getUpdate() throws Exception {
// String str = null;
// BufferedReader reader = null;
// try {
// URL url = new URL("https://api.github.com/repos/IntellectualSites/PlotSquared/releases/latest");
// reader = new BufferedReader(new InputStreamReader(url.openStream()));
// StringBuilder buffer = new StringBuilder();
// int read;
// char[] chars = new char[1024];
// while ((read = reader.read(chars)) != -1) {
// buffer.append(chars, 0, read);
// }
//
// str = buffer.toString();
// } catch (IOException e) {
// log("&dCould not check for updates (0)");
// e.printStackTrace();
// } finally {
// try {
// if (reader != null) {
// reader.close();
// }
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// if (str == null) {
// return;
// }
// Gson gson = new Gson();
// Release release = gson.fromJson(str, Release.class);
// System.out.println(release.name);
// for (Release.Assets asset : release.assets) {
// System.out.println(asset.name);
// System.out.println(asset.downloadUrl);
// }
// }
// private static class Release {
// String name;
// List<Assets> assets;
// private static class Assets {
// String name;
// @SerializedName("browser_download_url") String downloadUrl;
// }
//
// }
//
//}

View File

@ -44,13 +44,16 @@ import org.spongepowered.api.world.gen.WorldGenerator;
import org.spongepowered.api.world.gen.WorldGeneratorModifier;
import java.io.File;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
/**
* Created by robin on 01/11/2014
*/
@Plugin(id = "PlotSquared", name = "PlotSquared", version = "3.3.1", dependencies = "before:WorldEdit")
@Plugin(id = "com.plotsquared", name = "PlotSquared", description = "Easy, yet powerful Plot World generation and management.", url = "https://github.com/IntellectualSites/PlotSquared", version = "3.3.1")
public class SpongeMain implements IPlotMain {
public static SpongeMain THIS;
@ -86,33 +89,6 @@ public class SpongeMain implements IPlotMain {
return THIS;
}
// @Override
public String getId() {
return "PlotSquared";
}
// @Override
public Optional<Object> getInstance() {
return Optional.<Object> of(THIS);
}
// @Override
public String getName() {
return "PlotSquared";
}
// @Override
public String getVersion() {
final int[] version = PS.get().getVersion();
String result = "";
String prefix = "";
for (final int i : version) {
result += prefix + i;
prefix = ".";
}
return result;
}
@Listener
public void init(final GameInitializationEvent event) {
log("PlotSquared: Game init");
@ -163,8 +139,8 @@ public class SpongeMain implements IPlotMain {
@Override
public int[] getPluginVersion() {
final PluginContainer plugin = game.getPluginManager().getPlugin("PlotSquared").get();
final String version = plugin.getVersion();
PluginContainer plugin = game.getPluginManager().fromInstance(this).get();
String version = plugin.getVersion().get();
log("Checking plugin version: PlotSquared: ");
final String[] split = version.split("\\.");
return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 };

View File

@ -120,7 +120,6 @@ public class MainListener {
final String sender = player.getName();
final PlotId id = plot.getId();
final String newMessage = StringMan.replaceAll(C.PLOT_CHAT_FORMAT.s(), "%plot_id%", id.x + ";" + id.y, "%sender%", sender);
final Text forcedMessage = event.getMessage();
// String forcedMessage = StringMan.replaceAll(C.PLOT_CHAT_FORCED.s(), "%plot_id%", id.x + ";" + id.y, "%sender%", sender);
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
PlotPlayer user = entry.getValue();
@ -128,7 +127,7 @@ public class MainListener {
if (plot.equals(user.getLocation().getPlot())) {
toSend = newMessage;
} else if (Permissions.hasPermission(user, C.PERMISSION_COMMANDS_CHAT)) {
((SpongePlayer) user).player.sendMessage(forcedMessage);
((SpongePlayer) user).player.sendMessage(message);
continue;
} else {
continue;
@ -146,7 +145,7 @@ public class MainListener {
}
((SpongePlayer) user).player.sendMessage(Text.join(components));
}
event.clearMessage();
event.setMessage(null);
}
@Listener

View File

@ -131,7 +131,7 @@ public class SpongePlayer extends PlotPlayer {
@Override
public void setCompassTarget(final Location loc) {
final TargetedLocationData target = player.getOrCreate(TargetedLocationData.class).get();
target.set(Keys.TARGETED_LOCATION, SpongeUtil.getLocation(loc));
target.set(Keys.TARGETED_LOCATION, SpongeUtil.getLocation(loc).getPosition());
}
@Override

View File

@ -1,24 +1,22 @@
package com.plotsquared.sponge.util;
import java.math.BigDecimal;
import java.util.Optional;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.service.ChangeServiceProviderEvent;
import org.spongepowered.api.service.economy.EconomyService;
import org.spongepowered.api.service.economy.account.UniqueAccount;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.sponge.object.SpongePlayer;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.service.ChangeServiceProviderEvent;
import org.spongepowered.api.service.economy.EconomyService;
import org.spongepowered.api.service.economy.account.UniqueAccount;
import java.math.BigDecimal;
import java.util.Optional;
public class SpongeEconHandler extends EconHandler {
private EconomyService econ;
public SpongeEconHandler() {
if (Sponge.getServiceManager().isRegistered(EconomyService.class)) {
econ = Sponge.getServiceManager().provide(EconomyService.class).get();
@ -35,11 +33,11 @@ public class SpongeEconHandler extends EconHandler {
@Override
public void withdrawMoney(PlotPlayer player, double amount) {
if (econ != null) {
Optional<UniqueAccount> accOpt = econ.getAccount(player.getUUID());
Optional<UniqueAccount> accOpt = econ.getOrCreateAccount(player.getUUID());
if (accOpt.isPresent()) {
UniqueAccount acc = accOpt.get();
acc.withdraw(econ.getDefaultCurrency(), new BigDecimal(amount), Cause.of("PlotSquared"));
acc.withdraw(econ.getDefaultCurrency(), new BigDecimal(amount), SpongeUtil.CAUSE);
}
}
}
@ -47,10 +45,10 @@ public class SpongeEconHandler extends EconHandler {
@Override
public void depositMoney(PlotPlayer player, double amount) {
if (econ != null) {
Optional<UniqueAccount> accOpt = econ.getAccount(player.getUUID());
Optional<UniqueAccount> accOpt = econ.getOrCreateAccount(player.getUUID());
if (accOpt.isPresent()) {
UniqueAccount acc = accOpt.get();
acc.deposit(econ.getDefaultCurrency(), new BigDecimal(amount), Cause.of("PlotSquared"));
acc.deposit(econ.getDefaultCurrency(), new BigDecimal(amount), SpongeUtil.CAUSE);
}
}
}
@ -58,10 +56,10 @@ public class SpongeEconHandler extends EconHandler {
@Override
public void depositMoney(OfflinePlotPlayer player, double amount) {
if (econ != null) {
Optional<UniqueAccount> accOpt = econ.getAccount(player.getUUID());
Optional<UniqueAccount> accOpt = econ.getOrCreateAccount(player.getUUID());
if (accOpt.isPresent()) {
UniqueAccount acc = accOpt.get();
acc.deposit(econ.getDefaultCurrency(), new BigDecimal(amount), Cause.of("PlotSquared"));
acc.deposit(econ.getDefaultCurrency(), new BigDecimal(amount), SpongeUtil.CAUSE);
}
}
}
@ -85,7 +83,7 @@ public class SpongeEconHandler extends EconHandler {
@Override
public double getBalance(PlotPlayer player) {
if (econ != null) {
Optional<UniqueAccount> accOpt = econ.getAccount(player.getUUID());
Optional<UniqueAccount> accOpt = econ.getOrCreateAccount(player.getUUID());
if (accOpt.isPresent()) {
UniqueAccount acc = accOpt.get();
BigDecimal balance = acc.getBalance(econ.getDefaultCurrency());

View File

@ -1,7 +1,11 @@
package com.plotsquared.sponge.util;
import java.util.ArrayList;
import com.intellectualcrafters.plot.object.PlotInventory;
import com.intellectualcrafters.plot.object.PlotItemStack;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.InventoryUtil;
import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.object.SpongePlayer;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.item.ItemType;
import org.spongepowered.api.item.ItemTypes;
@ -11,12 +15,7 @@ import org.spongepowered.api.item.inventory.custom.CustomInventory;
import org.spongepowered.api.item.inventory.property.SlotIndex;
import org.spongepowered.api.item.inventory.type.CarriedInventory;
import com.intellectualcrafters.plot.object.PlotInventory;
import com.intellectualcrafters.plot.object.PlotItemStack;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.InventoryUtil;
import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.object.SpongePlayer;
import java.util.ArrayList;
public class SpongeInventoryUtil extends InventoryUtil {
@ -41,7 +40,7 @@ public class SpongeInventoryUtil extends InventoryUtil {
}
}
inv.player.setMeta("inventory", inv);
player.openInventory(inventory);
player.openInventory(inventory, SpongeUtil.CAUSE);
}
public ItemStack getItem(final PlotItemStack item) {
@ -56,7 +55,7 @@ public class SpongeInventoryUtil extends InventoryUtil {
}
inv.player.deleteMeta("inventory");
final SpongePlayer sp = (SpongePlayer) inv.player;
sp.player.closeInventory();
sp.player.closeInventory(SpongeUtil.CAUSE);
}
@Override

View File

@ -28,6 +28,8 @@ package com.plotsquared.sponge.util;
* either expressed or implied, of anybody else.
*/
import com.google.inject.Inject;
import com.intellectualcrafters.plot.PS;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
@ -42,18 +44,13 @@ import java.net.URLEncoder;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPOutputStream;
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
import ninja.leaping.configurate.loader.ConfigurationLoader;
import org.spongepowered.api.Game;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.scheduler.Task;
import com.google.inject.Inject;
import com.intellectualcrafters.plot.PS;
public class SpongeMetrics {
/**
@ -404,7 +401,7 @@ public class SpongeMetrics {
// Server software specific section
final String pluginName = plugin.getName();
final boolean onlineMode = game.getServer().getOnlineMode(); // TRUE if online mode is enabled
final String pluginVersion = plugin.getVersion();
final String pluginVersion = plugin.getVersion().get();
// TODO no visible way to get MC version at the moment
// TODO added by game.getPlatform().getMinecraftVersion() -- impl in 2.1
final String serverVersion = String.format("%s %s", "Sponge", game.getPlatform().getMinecraftVersion());

View File

@ -32,6 +32,7 @@ import org.spongepowered.api.data.value.mutable.ListValue;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.cause.NamedCause;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.serializer.TextSerializers;
import org.spongepowered.api.text.translation.Translation;
@ -49,7 +50,9 @@ import java.util.Locale;
import java.util.Optional;
public class SpongeUtil extends WorldUtil {
public static Cause CAUSE = Cause.of(NamedCause.source("PlotSquared"));
public static Location getLocation(final Entity player) {
final String world = player.getWorld().getName();
final org.spongepowered.api.world.Location loc = player.getLocation();

View File

@ -1,17 +1,16 @@
package com.plotsquared.sponge.uuid;
import java.util.Collection;
import java.util.UUID;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.profile.GameProfile;
import com.google.common.base.Charsets;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.sponge.SpongeMain;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.profile.GameProfile;
import java.util.Collection;
import java.util.UUID;
public class SpongeLowerOfflineUUIDWrapper extends UUIDWrapper {
@ -36,7 +35,7 @@ public class SpongeLowerOfflineUUIDWrapper extends UUIDWrapper {
try {
final GameProfile profile = SpongeMain.THIS.getResolver().get(uuid).get();
if (profile != null) {
name = profile.getName();
name = profile.getName().orElse(null);
}
} catch (final Exception e) {
e.printStackTrace();
@ -44,9 +43,12 @@ public class SpongeLowerOfflineUUIDWrapper extends UUIDWrapper {
}
if (name == null) {
for (final GameProfile profile : SpongeMain.THIS.getResolver().getCachedProfiles()) {
if (getUUID(profile.getName()).equals(uuid)) {
name = profile.getName();
break;
String tmp = profile.getName().orElse(null);
if (tmp != null) {
if (getUUID(name).equals(uuid)) {
name = tmp;
break;
}
}
}
}

View File

@ -1,7 +1,5 @@
package com.plotsquared.sponge.uuid;
import java.util.UUID;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.UUIDHandler;
@ -9,6 +7,8 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.object.SpongePlayer;
import java.util.UUID;
public class SpongeOnlineUUIDWrapper extends UUIDWrapper {
@Override
@ -35,7 +35,7 @@ public class SpongeOnlineUUIDWrapper extends UUIDWrapper {
public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) {
String name;
try {
name = SpongeMain.THIS.getResolver().get(uuid, true).get().getName();
name = SpongeMain.THIS.getResolver().get(uuid, true).get().getName().orElse(null);
} catch (final Exception e) {
name = null;
}

View File

@ -1,9 +1,5 @@
package com.plotsquared.sponge.uuid;
import java.util.UUID;
import org.spongepowered.api.profile.GameProfile;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.StringWrapper;
@ -11,6 +7,9 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.sponge.SpongeMain;
import org.spongepowered.api.profile.GameProfile;
import java.util.UUID;
public class SpongeUUIDHandler extends UUIDHandlerImplementation {
@ -29,7 +28,10 @@ public class SpongeUUIDHandler extends UUIDHandlerImplementation {
public boolean cache(final Runnable whenDone) {
add(new StringWrapper("*"), DBFunc.everyone);
for (final GameProfile profile : SpongeMain.THIS.getResolver().getCachedProfiles()) {
add(new StringWrapper(profile.getName()), profile.getUniqueId());
String name = profile.getName().orElse(null);
if (name != null) {
add(new StringWrapper(name), profile.getUniqueId());
}
}
return true;
}