Added java docs and tweaked code

* Fixed possible duplication bug in MulitBlockUpdaterAgent
* Tweaked some of the factor methods for Shape.java
* Cleaned some code in ShapeWings.java
This commit is contained in:
xGamingDudex 2016-05-15 15:32:44 +02:00
parent 24f7a4b409
commit abddc446fd
17 changed files with 370 additions and 29 deletions

View File

@ -9,6 +9,10 @@ import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
/**
* Self sufficient animator to animate task with steps using local vector logic
*/
public class Animator
{
private Plugin _plugin;
@ -37,14 +41,25 @@ public class Animator
_points.remove(point);
}
/**
* @return Returns a cloned list of the animator points for this instance.
*/
public Set<AnimationPoint> getSet() {
return (Set<AnimationPoint>) _points.clone();
}
/**
* @return Returns the actual list of animator points used by this instance. As this is not a copy, editing this list will apply
* changes to the current instance.
*/
public Set<AnimationPoint> getSetRaw() {
return _points;
}
/**
* Start the animation at the given location. If the animator is already running then this call will be silently ignored.
* @param loc Location the animation will start relative too. The vector poitns will be added to relative to this location.
*/
public void start(Location loc)
{
if(isRunning()) return;

View File

@ -1,10 +1,15 @@
package mineplex.core.common.animation;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector;
/**
* An implementation of the {@link Animator} which will teleport the provided entity along the animation path each tick.
*/
public class AnimatorEntity extends Animator
{

View File

@ -20,11 +20,23 @@ import net.minecraft.server.v1_8_R3.ChunkCoordIntPair;
import net.minecraft.server.v1_8_R3.PacketPlayOutMultiBlockChange;
import net.minecraft.server.v1_8_R3.PacketPlayOutMultiBlockChange.MultiBlockChangeInfo;
/**
* An agent used to easily record and send multi-block update packets to players. The agent handles if the packet should be a
* MultiBlock packet or a chunk update. It also supports blocks across multiple chunks.
*/
public class MultiBlockUpdaterAgent
{
private Map<Chunk, List<BlockVector>> _chunks = new HashMap<Chunk, List<BlockVector>>();
/**
* Add a block to the list of blocks to send to the player. The agent supports blocks across different chunks and
* will not send duplicates.
* @param block The block to send. The block is stored using a BlockVector, meaning that when the send method is called, it will use
* the material and data found for the block at the moment you call the send method.
* @see #send(Collection)
*/
public void addBlock(Block block)
{
Chunk c = ((CraftChunk)block.getChunk()).getHandle();
@ -38,19 +50,33 @@ public class MultiBlockUpdaterAgent
if(list.size() >= 64) return;
list.add(block.getLocation().toVector().toBlockVector());
BlockVector bv = block.getLocation().toVector().toBlockVector();
if(list.contains(bv)) return;
list.add(bv);
}
/**
* Sends all the record blocks to all online players. Players out of range will not receive packets.
* @see #send(Collection)
*/
public void send()
{
send(UtilServer.getPlayersCollection());
}
/**
* Clear all blocks for this agent.
*/
public void reset()
{
_chunks.clear();
}
/**
* Send all the recorded blocks to the provided players. This will only send packets to players in range. If the blocks span multiple
* chunks then players will only receive block updates for chunks close to them.
* @param players The players which will the packets will be sent to.
*/
public void send(Collection<? extends Player> players)
{
for(Player p : players)

View File

@ -2,9 +2,16 @@ package mineplex.core.common.shape;
import org.bukkit.Location;
/**
* Interface used by classes which can display visuals at provided locations.
*/
public interface ICosmeticShape
{
/**
* Display a visual at the given location
* @param loc The location to display the visual at
*/
public void display(Location loc);
}

View File

@ -8,6 +8,10 @@ import java.util.Set;
import org.bukkit.util.Vector;
/**
* A simple 3D vector stored shape
*/
public class Shape
{
@ -26,6 +30,10 @@ public class Shape
for(Vector v : points) this._points.add(v);
}
/**
* Rotate this shape along the X-axis
* @param radians Radians to rotate the shape
*/
public void rotateOnXAxis(double radians)
{
for(Vector v : _points)
@ -37,6 +45,10 @@ public class Shape
}
}
/**
* Rotate this shape along the Y-axis
* @param radians Radians to rotate the shape
*/
public void rotateOnYAxis(double radians)
{
for(Vector v : _points)
@ -48,6 +60,10 @@ public class Shape
}
}
/**
* Rotate this shape along the Z-axis
* @param radians Radians to rotate the shape
*/
public void rotateOnZAxis(double radians)
{
for(Vector v : _points)
@ -145,21 +161,33 @@ public class Shape
return min;
}
/*
* Returns the smallest possible BoundingBox containing this shape
* @return
* TODO
/**
* Get the closest length which will be a factor of the provided length, but not longer then max
* E.g. You want to split a length of 9 into even peaces, but the peaces should not be longer than the max 5, then this will
* return 4.5, as 4.5 goes 2 times to make up precisely 9.
* @param length The length which the returned factor should fit into
* @param max The max distance of the returned length
* @return The closest to length to be a factor of the provided length which is <= max
*/
public static double getRoundFactor(double length, double max)
{
return max/Math.ceil(length/max);
return length/Math.ceil(length/max);
}
/**
* Get the closest RoundFactor length applied to a vector, using the vector as the max length. The returned vector is a cloned
* parallel vector to the provided length
* @param length The vector used as length and direction
* @param maxLength The max length of the new returned vector
* @return Returns a parallel vector to the given length vector which is also a factor of the provided vector, but not longer
* then maxLength
*
* @see #getRoundFactor(double, double)
*/
public static Vector getVectorFactor(Vector length, double maxLength)
{
return length.multiply(getRoundFactor(length.length(), maxLength));
return length.clone().multiply(getRoundFactor(length.length(), maxLength));
}

View File

@ -2,19 +2,46 @@ package mineplex.core.common.shape;
import org.bukkit.util.Vector;
/**
* An extension of {@link Shape} creating a simple box
*/
public class ShapeBox extends Shape
{
/**
* Define a parallelepiped using three vectors using default density {@link Shape#DefaultDensity} and is not hollow
* @param localx The first vector to use as local x direction, does not have to align to global x direction
* @param localy The second vector to use as local y direction, does not have to align to global y direction
* @param localz The third vector to use as local z direction, does not have to align to global z direction
*/
public ShapeBox(Vector localx, Vector localy, Vector localz)
{
this(localx, localy, localz, false, DefaultDensity);
}
/**
* Define a parallelepiped using three vectors using default density {@link Shape#DefaultDensity}
* @param localx The first vector to use as local x direction, does not have to align to global x direction
* @param localy The second vector to use as local y direction, does not have to align to global y direction
* @param localz The third vector to use as local z direction, does not have to align to global z direction
* @param hollow If the parallelepiped box should be hollow or not
*/
public ShapeBox(Vector localx, Vector localy, Vector localz, boolean hollow)
{
this(localx, localy, localz, hollow, DefaultDensity);
}
/**
* Define a parallelepiped using three vectors
* @param localx The first vector to use as local x direction, does not have to align to global x direction
* @param localy The second vector to use as local y direction, does not have to align to global y direction
* @param localz The third vector to use as local z direction, does not have to align to global z direction
* @param hollow If the parallelepiped box should be hollow or not
* @param density The density of the vector points
*/
public ShapeBox(Vector localx, Vector localy, Vector localz, boolean hollow, double density)
{
Vector x = Shape.getVectorFactor(localx, density);

View File

@ -2,6 +2,10 @@ package mineplex.core.common.shape;
import org.bukkit.util.Vector;
/**
* A simple grid shape which uses string inputs to define points
*/
public class ShapeGrid extends Shape
{

View File

@ -4,19 +4,33 @@ import java.util.Collection;
import org.bukkit.util.Vector;
/**
* A bag collection of several shapes. This will add all the points from the given shapes into a new shape
*/
public class ShapeMulti extends Shape
{
/**
* @param shapes Shapes which points will be added to this instance of a shape
*/
public ShapeMulti(Collection<Shape> shapes)
{
for(Shape shape : shapes) addShape(shape);
}
/**
* @param shapes Shapes which points will be added to this instance of a shape
*/
public ShapeMulti(Shape... shapes)
{
for(Shape shape : shapes) addShape(shape);
}
/**
* Add all the points from the given shape to this shape
* @param shape
*/
public void addShape(Shape shape) {
for(Vector v : shape._points) add(v);
}

View File

@ -2,24 +2,53 @@ package mineplex.core.common.shape;
import org.bukkit.util.Vector;
/**
* A simple sphere defined using vector points extending {@link Shape}
*/
public class ShapeSphere extends Shape
{
/**
* Define a sphere with radius r that is not hollow and using default density {@link Shape#DefaultDensity}
* @param r Radius for the sphere
*/
public ShapeSphere(double r)
{
this(r,r,r);
}
/**
* A sphere with different radiuses on different planes that is not hollow and using default density {@link Shape#DefaultDensity}
* @param x Radius in x direction
* @param y Radius in y direction
* @param z Radius in z direction
*/
public ShapeSphere(double x, double y, double z)
{
this(x, y, z, false, DefaultDensity);
}
/**
* A sphere with different radiuses on different planes using default density {@link Shape#DefaultDensity}
* @param x Radius in x direction
* @param y Radius in y direction
* @param z Radius in z direction
* @param hollow If the sphere should be hollow or not
*/
public ShapeSphere(double x, double y, double z, boolean hollow)
{
this(x, y, z, hollow, DefaultDensity);
}
/**
* A sphere with different radiuses on different planes
* @param x Radius in x direction
* @param y Radius in y direction
* @param z Radius in z direction
* @param hollow If the sphere should be hollow or not
* @param density Density between points
*/
public ShapeSphere(double x, double y, double z, boolean hollow, double density)
{
for(double px = -x; px <= x; x += Shape.getRoundFactor(2*x, density))

View File

@ -7,6 +7,10 @@ import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
/**
* Some simple wing shapes implementing {@link ICosmeticShape} storing additional particle information
*/
public class ShapeWings extends ShapeGrid implements ICosmeticShape
{
public static final String[] ANGEL_WING_PATTERN = new String[]
@ -51,7 +55,9 @@ public class ShapeWings extends ShapeGrid implements ICosmeticShape
};
/**
* Default rotation to give the wings a little tilt when displayed on players for instance
*/
public static double DEFAULT_ROTATION = Math.PI/0.05;
@ -60,46 +66,76 @@ public class ShapeWings extends ShapeGrid implements ICosmeticShape
private float _speed;
private int _count;
/**
* A simple non-edge wing shape using the default butterfly pattern {@link ShapeWings#BUTTERFLY_WING_PATTERN}
* and x-rotation {@link #DEFAULT_ROTATION}. It also uses default redstone dust particle with offset of 0, speed of 0 and count 1
*/
public ShapeWings()
{
this(ParticleType.RED_DUST.particleName);
}
/**
* A simple non-edge wing shape using the default butterfly pattern {@link ShapeWings#BUTTERFLY_WING_PATTERN}
* and x-rotation {@link #DEFAULT_ROTATION}
* @param particle The particle to display at each point in the wing shape. Using offset of 0, speed of 0 and count 1
*/
public ShapeWings(String particle)
{
this(particle, null, 0, 1);
}
/**
* A simple non-edge wing shape using the default butterfly pattern {@link ShapeWings#BUTTERFLY_WING_PATTERN}
* and x-rotation {@link #DEFAULT_ROTATION}
* @param particle The particle to display at each point in the wing shape
* @param offsetData Particle data
* @param speed Particle speed
* @param count Particle count
*/
public ShapeWings(String particle, Vector offsetData, float speed, int count)
{
this(particle, offsetData, speed, count, false);
}
/**
* A simple wing shape using the default butterfly pattern {@link ShapeWings#BUTTERFLY_WING_PATTERN}
* and x-rotation {@link #DEFAULT_ROTATION}
* @param particle The particle to display at each point in the wing shape
* @param offsetData Particle data
* @param speed Particle speed
* @param count Particle count
* @param edge If this is the edge of the wings or not
*/
public ShapeWings(String particle, Vector offsetData, float speed, int count, boolean edge)
{
this(particle, offsetData, speed, count, edge, Math.PI/0.05);
this(particle, offsetData, speed, count, edge, DEFAULT_ROTATION);
}
/**
* A simple wing shape using the default butterfly pattern {@link ShapeWings#BUTTERFLY_WING_PATTERN}
* @param particle The particle to display at each point in the wing shape
* @param offsetData Particle data
* @param speed Particle speed
* @param count Particle count
* @param edge If this is the edge of the wings or not
* @param xRotation Rotation on the x axis
*/
public ShapeWings(String particle, Vector offsetData, float speed, int count, boolean edge, double xRotation)
{
this(particle, offsetData, speed, count, edge, xRotation,
"0$$0000000000000000$$0",
"$##$00000000000000$##$",
"0$##$000000000000$##$0",
"00$##$0000000000$##$00",
"00$###$00000000$###$00",
"000$####$0000$####$000",
"000$######$$#####$0000",
"0000$############$0000",
"00000$##########$00000",
"00000$##########$00000",
"00000$####$$$###$00000",
"00000$###$000$###$0000",
"00000$##$00000$##$0000",
"000000$000000000$00000"
);
this(particle, offsetData, speed, count, edge, xRotation, BUTTERFLY_WING_PATTERN);
}
/**
* A simple wing shape
* @param particle The particle to display at each point in the wing shape
* @param offsetData Particle data
* @param speed Particle speed
* @param count Particle count
* @param edge If this is the edge of the wings or not
* @param xRotation Rotation on the x axis
* @param pattern Pattern to use as wing shape
*/
public ShapeWings(String particle, Vector offsetData, float speed, int count, boolean edge, double xRotation, String... pattern)
{
super(0.15, edge? '$' : '#',

View File

@ -5,9 +5,16 @@ import java.util.Random;
import org.bukkit.World;
import org.bukkit.generator.ChunkGenerator;
/**
* A simple clean room void chunk generator
*/
public class WorldGenCleanRoom extends ChunkGenerator
{
/**
* Creates a clean void chunk with no blocks
*/
@Override
public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome)
{

View File

@ -10,6 +10,10 @@ import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilText;
import mineplex.core.itemstack.ItemStackFactory;
/**
* The game modifier type. Normal a specific game.
*/
public enum GameModifierType
{

View File

@ -11,6 +11,10 @@ import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.gadgets.gamemodifiers.GameModifierType;
import mineplex.core.gadget.types.GadgetGameModifier;
/**
* A gamemodifier to apply custom skin data to {@link GameModifierType#MineStrike} weapons
*/
public class GameModifierMineStrikeSkin extends GadgetGameModifier
{
@ -18,6 +22,17 @@ public class GameModifierMineStrikeSkin extends GadgetGameModifier
private Material _skinMat;
private byte _skinData;
/**
* @param manager Normal gadget manager
* @param name Display name of skin
* @param lore Lore description of skin
* @param weaponName The exact name of the weapon which this skin will replace
* @param newSkin Skin material
* @param newSkinData Skin item data
* @param cost Cost of this MineStrike skin
* @param displayMat Display material for GUI, no in-game impact
* @param displayData Display data for GUI, no in-game impact
*/
public GameModifierMineStrikeSkin(GadgetManager manager, String name, String[] lore, String weaponName, Material newSkin, byte newSkinData,
int cost, Material displayMat, int displayData)
{
@ -28,11 +43,24 @@ public class GameModifierMineStrikeSkin extends GadgetGameModifier
_skinData = newSkinData;
}
/**
* Return a {@link GameModifierMineStrikeSkin} with empty lore
* @param manager Normal gadget manager
* @param skin {@link MineStrikeSkin} used to apply name, item data and display data from
* @param cost Cost of this MineStrike skin
*/
public GameModifierMineStrikeSkin(GadgetManager manager, MineStrikeSkin skin, int cost)
{
this(manager, skin, new String[]{""}, cost);
}
/**
* Return a {@link GameModifierMineStrikeSkin} using the {@link MineStrikeSkin} to apply additional data
* @param manager Normal gadget manager
* @param skin {@link MineStrikeSkin} used to apply name, item data and display data from
* @param lore Lore to apply to the gadget
* @param cost Cost of this MineStrike skin
*/
public GameModifierMineStrikeSkin(GadgetManager manager, MineStrikeSkin skin, String[] lore, int cost)
{
this(manager, skin.getSkinName(), lore, skin.getWeaponName(), skin.getSkinMaterial(), skin.getSkinData(), cost,
@ -62,6 +90,12 @@ public class GameModifierMineStrikeSkin extends GadgetGameModifier
super.EnableCustom(player);
}
/**
* A simple {@link GadgetGameModifier} filter which filters out {@link GameModifierMineStrikeSkin} gadgets depending on weapon name
* @param weaponName Exact weapon name to test for
* @return Returns a weapon filter which will filter out any {@link GadgetGameModifier}
* which is not instance of {@link GameModifierMineStrikeSkin} and which does not match the provided weapon name
*/
public static Predicate<GadgetGameModifier> getWeaponFilter(String weaponName)
{
return new Predicate<GadgetGameModifier>()

View File

@ -8,11 +8,23 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.gadgets.gamemodifiers.GameModifierType;
/**
* An abstract wrapper for Gadgets of the type GameModifiers
*/
public abstract class GadgetGameModifier extends Gadget
{
protected final GameModifierType _type;
/**
* @param manager Normal GadgetManager
* @param type The type of the GameModifier, normally a specific game mode
* @param name The display name of the GameModifier
* @param desc The lore description of the GameModifier
* @param cost The shard cost of the GameModifier
* @param mat The display material used in GUIs
* @param data The display data used in GUIs
*/
public GadgetGameModifier(GadgetManager manager, GameModifierType type, String name, String[] desc, int cost, Material mat, byte data)
{
super(manager, GadgetType.GameModifier, name, desc, cost, mat, data);

View File

@ -1,5 +1,8 @@
package mineplex.core.gadget.types;
/**
* The type of the different gadgets with some extra name data
*/
public enum GadgetType
{
Item("Items"),

View File

@ -7,10 +7,24 @@ import org.bukkit.event.EventHandler;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
/**
* A wrapper for particle trail gadgets
*/
public abstract class ParticleGadget extends Gadget
{
/**
* @param manager The normal gadget manager
* @param name The display name of the particle trail
* @param desc The display description of the particle trail
* @param cost The shard cost of the particle trail
* @param mat The Material type used to display this particle trail in GUIs
* @param data The data used to display this particle trail in GUIs
* @param altNames Alternative packet names
*/
public ParticleGadget(GadgetManager manager, String name, String[] desc, int cost, Material mat, byte data, String...altNames)
{
super(manager, GadgetType.Particle, name, desc, cost, mat, data, 1, altNames);
@ -55,5 +69,11 @@ public abstract class ParticleGadget extends Gadget
}
}
/**
* Called every time time {@link UpdateType} is called, used to display this particle trail to the provided player
* No need to check if the particle is valid for display for this player.
* @param player The player which the trail should be displayed to.
* @param event The update event
*/
public abstract void playParticle(Player player, UpdateEvent event);
}

View File

@ -27,6 +27,10 @@ import mineplex.core.common.util.UtilServer;
import mineplex.core.disguise.disguises.DisguisePlayer;
import mineplex.core.gadget.GadgetManager;
/**
* A wrapper for different win effects
*/
public abstract class WinEffectGadget extends Gadget
{
@ -35,6 +39,10 @@ public abstract class WinEffectGadget extends Gadget
protected long _finish;
protected Location _baseLocation;
/**
* The file name of the schematic used for this win room. Schematics can be found in the "schematic" folder
* in the server root folder. This name should not contain the file suffix of ".schematic" as this is automatically applied later.
*/
protected String _schematicName = "WinRoomPodium";
/** All the players on the winners team. Empty if solo game. */
@ -44,7 +52,15 @@ public abstract class WinEffectGadget extends Gadget
/** All players on the team that didn't win + spectators which were not in the game at all. */
protected List<Player> other;
/**
* @param manager The normal GadgetManager
* @param name The display name of the WinEffect
* @param desc The description of the WinEffect
* @param cost The shard cost of the WinEffect
* @param mat The display material of the WinEffect
* @param data The display data of the WinEffect
* @param alternativesalepackageNames Alternative packet names used to check if the player owns this WinEffect
*/
public WinEffectGadget(GadgetManager manager, String name, String[] desc, int cost, Material mat, byte data,
String... alternativesalepackageNames)
{
@ -74,6 +90,10 @@ public abstract class WinEffectGadget extends Gadget
play();
}
/**
* Lock the player. Disabling any jump or walk movement
* @param p The player to lock in place
*/
public void lockPlayer(Player p)
{
p.setWalkSpeed(0);
@ -81,6 +101,10 @@ public abstract class WinEffectGadget extends Gadget
p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, 250, true, false), true);
}
/**
* Unlock the player, allowing the player to walk and jump as normal again.
* @param p The player to unlock
*/
public void unlockPlayer(Player p)
{
p.setWalkSpeed(0.2f);
@ -123,8 +147,15 @@ public abstract class WinEffectGadget extends Gadget
other = null;
}
/**
* This method is called when the win effect should start playing
*/
public abstract void play();
/**
* This method is called when this win effect is finished. Do any necessary clean up here. Note that entities do not need to be
* cleared.
*/
public abstract void finish();
public boolean isRunning()
@ -145,16 +176,31 @@ public abstract class WinEffectGadget extends Gadget
return _baseLocation.clone();
}
/**
* @return The time stamp of when this effect started
*/
public long getStart()
{
return _start;
}
/**
* @return The time stamp of when this effect should end
*/
public long getFinish()
{
return _finish;
}
/**
* @return Returns how many milliseconds there is left before this effect should end. It will return negative values if the
* effect has finished.
*/
public long getTimeLeft()
{
return getFinish()-getStart();
}
public void activate(Player player, List<Player> team, List<Player> nonTeam, Location loc)
{
this._player = player;
@ -168,6 +214,13 @@ public abstract class WinEffectGadget extends Gadget
this._baseLocation = loc.clone();
}
/**
* Teleport the players to the win room
* @param player The player that won or is selected to play the win effect
* @param team The team of the winning player. This is empty if the game was a solo game
* @param other All players on the server, except the winner and the winning team
* @param loc The base location to teleport the players too
*/
public void teleport(Player player, List<Player> team, List<Player> other, Location loc)
{
Location l = loc.clone();
@ -189,12 +242,23 @@ public abstract class WinEffectGadget extends Gadget
}
}
/**
* Build the win room, by default this will paste the scheamtic. Do any major setup here. This is called before the players are
* teleported.
* @param loc
*/
public void buildWinnerRoom(Location loc)
{
pasteScematic(_schematicName);
}
/**
* Get a disguised ArmorStand with the skin of the provided player at the provided location. The ArmorStand got no gravity and
* 2048 health.
* @param player The player to create the disguise from
* @param loc The location to spawn the ArmorStand at
* @return Returns a disguised ArmorStand at the given location
*/
public DisguisePlayer getNPC(Player player, Location loc) {
ArmorStand stand = loc.getWorld().spawn(loc, ArmorStand.class);
@ -210,6 +274,12 @@ public abstract class WinEffectGadget extends Gadget
return disguise;
}
/**
* Paste a schematic relative to the base location
* @param schematicName Schematic name without the file suffix ".schematic". The file should be located in the "schematic" folder
* in the server root directory
* @return Returns the schematic after pasting it. Will return <code>null</code> if any errors ocured.
*/
public Schematic pasteScematic(String schematicName) {
try
{