Cleanup CostumePage and implement some new Christmas particles

This commit is contained in:
Sam 2017-11-20 15:46:35 +00:00 committed by Alexander Meech
parent 131cb12620
commit a9fbbc2e27
14 changed files with 241 additions and 144 deletions

View File

@ -0,0 +1,43 @@
package mineplex.core.common.shape;
import org.bukkit.Location;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
public class ShapeFidgetSpinner extends Shape implements CosmeticShape
{
public ShapeFidgetSpinner(int petalCount, int rotationDegrees)
{
double x0, y0;
double sinRotation = Math.sin(rotationDegrees);
double cosRotation = Math.cos(rotationDegrees);
for (double theta = 0; theta <= 2 * Math.PI; theta += Math.PI / 90)
{
double radius = Math.sin(petalCount * theta);
double x1 = radius * Math.cos(theta);
double y1 = radius * Math.sin(theta);
x0 = cosRotation * x1 - sinRotation * y1;
y0 = 0.2 + sinRotation * x1 + cosRotation * y1;
addPoint(new Vector(x0, y0, 0.4));
}
}
@Override
public void display(Location location)
{
Shape clone = clone();
clone.rotateOnYAxis(Math.toRadians(location.getYaw() + 180));
for (Vector vector : clone.getPoints())
{
UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, location.clone().add(vector), null, 0, 1, ViewDist.NORMAL);
}
}
}

View File

@ -9,10 +9,6 @@ import mineplex.core.common.util.C;
import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.cosmetic.CosmeticManager;
import mineplex.core.cosmetic.ui.CosmeticShop; import mineplex.core.cosmetic.ui.CosmeticShop;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.gadget.gadgets.outfit.freezesuit.OutfitFreezeSuit;
import mineplex.core.gadget.gadgets.outfit.ravesuit.OutfitRaveSuit;
import mineplex.core.gadget.gadgets.outfit.spacesuit.OutfitSpaceSuit;
import mineplex.core.gadget.gadgets.outfit.stpatricks.OutfitStPatricksSuit;
import mineplex.core.gadget.types.Gadget; import mineplex.core.gadget.types.Gadget;
import mineplex.core.gadget.types.GadgetType; import mineplex.core.gadget.types.GadgetType;
import mineplex.core.gadget.types.OutfitGadget; import mineplex.core.gadget.types.OutfitGadget;
@ -21,7 +17,7 @@ import mineplex.core.shop.item.ShopItem;
public class CostumePage extends GadgetPage public class CostumePage extends GadgetPage
{ {
public CostumePage(CosmeticManager plugin, CosmeticShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player) CostumePage(CosmeticManager plugin, CosmeticShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player)
{ {
super(plugin, shop, clientManager, donationManager, name, player); super(plugin, shop, clientManager, donationManager, name, player);
@ -31,6 +27,8 @@ public class CostumePage extends GadgetPage
protected void buildPage() protected void buildPage()
{ {
int slot; int slot;
int offset = 0;
Class<? extends OutfitGadget> lastGadgetClass = null;
for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.COSTUME)) for (Gadget gadget : getPlugin().getGadgetManager().getGadgets(GadgetType.COSTUME))
{ {
@ -41,22 +39,26 @@ public class CostumePage extends GadgetPage
OutfitGadget outfitGadget = ((OutfitGadget) gadget); OutfitGadget outfitGadget = ((OutfitGadget) gadget);
int offset; if (lastGadgetClass == null || !(gadget.getClass().getSuperclass().isAssignableFrom(lastGadgetClass.getSuperclass())))
{
lastGadgetClass = outfitGadget.getClass();
offset++;
}
if (gadget instanceof OutfitRaveSuit) offset = 0; slot = offset + 18; // 18 = 2 lines down
else if (gadget instanceof OutfitSpaceSuit) offset = 1;
else if (gadget instanceof OutfitFreezeSuit) offset = 2;
else if (gadget instanceof OutfitStPatricksSuit) offset = 3;
else offset = 4;
slot = offset + 1 + 18; //1 buffer to left, 18 = 2 lines down switch (outfitGadget.getSlot())
{
if (outfitGadget.getSlot() == OutfitGadget.ArmorSlot.CHEST) case CHEST:
slot += 9; slot += 9;
else if (outfitGadget.getSlot() == OutfitGadget.ArmorSlot.LEGS) break;
case LEGS:
slot += 18; slot += 18;
else if (outfitGadget.getSlot() == OutfitGadget.ArmorSlot.BOOTS) break;
case BOOTS:
slot += 27; slot += 27;
break;
}
addGadget(gadget, slot); addGadget(gadget, slot);

View File

@ -227,6 +227,7 @@ import mineplex.core.gadget.gadgets.particle.ParticleCoalFumes;
import mineplex.core.gadget.gadgets.particle.ParticleEmerald; import mineplex.core.gadget.gadgets.particle.ParticleEmerald;
import mineplex.core.gadget.gadgets.particle.ParticleEnchant; import mineplex.core.gadget.gadgets.particle.ParticleEnchant;
import mineplex.core.gadget.gadgets.particle.ParticleFairy; import mineplex.core.gadget.gadgets.particle.ParticleFairy;
import mineplex.core.gadget.gadgets.particle.ParticleFidgetSpinner;
import mineplex.core.gadget.gadgets.particle.ParticleFireRings; import mineplex.core.gadget.gadgets.particle.ParticleFireRings;
import mineplex.core.gadget.gadgets.particle.ParticleFoot; import mineplex.core.gadget.gadgets.particle.ParticleFoot;
import mineplex.core.gadget.gadgets.particle.ParticleFrostLord; import mineplex.core.gadget.gadgets.particle.ParticleFrostLord;
@ -239,6 +240,7 @@ import mineplex.core.gadget.gadgets.particle.ParticleRain;
import mineplex.core.gadget.gadgets.particle.ParticleTitan; import mineplex.core.gadget.gadgets.particle.ParticleTitan;
import mineplex.core.gadget.gadgets.particle.ParticleWingsAngel; import mineplex.core.gadget.gadgets.particle.ParticleWingsAngel;
import mineplex.core.gadget.gadgets.particle.ParticleWingsBee; import mineplex.core.gadget.gadgets.particle.ParticleWingsBee;
import mineplex.core.gadget.gadgets.particle.ParticleWingsChristmas;
import mineplex.core.gadget.gadgets.particle.ParticleWingsDemons; import mineplex.core.gadget.gadgets.particle.ParticleWingsDemons;
import mineplex.core.gadget.gadgets.particle.ParticleWingsInfernal; import mineplex.core.gadget.gadgets.particle.ParticleWingsInfernal;
import mineplex.core.gadget.gadgets.particle.ParticleWingsLove; import mineplex.core.gadget.gadgets.particle.ParticleWingsLove;
@ -642,7 +644,8 @@ public class GadgetManager extends MiniPlugin
addGadget(new ParticleCanadian(this)); addGadget(new ParticleCanadian(this));
addGadget(new ParticleHalloween(this)); addGadget(new ParticleHalloween(this));
addGadget(new ParticleWingsChristmas(this));
addGadget(new ParticleFidgetSpinner(this));
// Arrow Trails // Arrow Trails
addGadget(new ArrowTrailFrostLord(this)); addGadget(new ArrowTrailFrostLord(this));
@ -1111,7 +1114,7 @@ public class GadgetManager extends MiniPlugin
if (armor.getSlot() == slot) if (armor.getSlot() == slot)
{ {
armor.removeArmor(player, true); armor.disableCustom(player, true);
} }
} }
} }

View File

@ -67,18 +67,6 @@ public class OutfitFreezeSuit extends OutfitGadget
} }
} }
@Override
public void enableCustom(Player player, boolean message)
{
applyArmor(player, message);
}
@Override
public void disableCustom(Player player, boolean message)
{
removeArmor(player, message);
}
@EventHandler @EventHandler
public void activateBridge(PlayerToggleSneakEvent event) public void activateBridge(PlayerToggleSneakEvent event)
{ {

View File

@ -39,14 +39,16 @@ public class OutfitRaveSuit extends OutfitGadget
@Override @Override
public void enableCustom(Player player, boolean message) public void enableCustom(Player player, boolean message)
{ {
applyArmor(player, message); super.enableCustom(player, message);
_colorPhase.put(player.getUniqueId(), -1); _colorPhase.put(player.getUniqueId(), -1);
} }
@Override @Override
public void disableCustom(Player player, boolean message) public void disableCustom(Player player, boolean message)
{ {
removeArmor(player, message); super.disableCustom(player, message);
_colorPhase.remove(player.getUniqueId()); _colorPhase.remove(player.getUniqueId());
} }

View File

@ -22,8 +22,8 @@ public class OutfitReindeerAntlers extends OutfitReindeer
{ {
private static final ItemStack IN_HAND = new ItemStack(Material.DEAD_BUSH); private static final ItemStack IN_HAND = new ItemStack(Material.DEAD_BUSH);
private static final EulerAngle LEFT_POS = new EulerAngle(Math.PI / 2D, 0, Math.PI / 4D); private static final EulerAngle LEFT_POS = new EulerAngle(Math.PI / 2D, 0, -Math.PI / 4D);
private static final EulerAngle RIGHT_POS = new EulerAngle(-LEFT_POS.getX(), 0, LEFT_POS.getZ()); private static final EulerAngle RIGHT_POS = new EulerAngle(-LEFT_POS.getX(), 0, Math.PI - (LEFT_POS.getZ()));
private final Map<Player, Pair<ArmorStand, ArmorStand>> _antlers; private final Map<Player, Pair<ArmorStand, ArmorStand>> _antlers;
@ -79,10 +79,11 @@ public class OutfitReindeerAntlers extends OutfitReindeer
private void updateRotation(Player player, ArmorStand left, ArmorStand right) private void updateRotation(Player player, ArmorStand left, ArmorStand right)
{ {
Location location = player.getLocation().add(0, player.isSneaking() ? 0.3 : 0.6, 0); Location location = player.getLocation().add(0, player.isSneaking() ? 0.3 : 0.6, 0);
location.setPitch(0);
Vector direction = location.getDirection(); Vector direction = location.getDirection();
direction.setY(0);
left.teleport(location.clone().add(direction).add(UtilAlg.getLeft(direction))); left.teleport(location.clone().add(direction.add(UtilAlg.getLeft(direction)).multiply(0.4)));
direction.normalize();
right.teleport(location.clone().add(direction.multiply(-0.4))); right.teleport(location.clone().add(direction.multiply(-0.4)));
} }

View File

@ -25,18 +25,6 @@ public class OutfitSpaceSuit extends OutfitGadget
cost, slot, mat, data); cost, slot, mat, data);
} }
@Override
public void enableCustom(Player player, boolean message)
{
applyArmor(player, message);
}
@Override
public void disableCustom(Player player, boolean message)
{
removeArmor(player, message);
}
@EventHandler @EventHandler
public void setBonus(UpdateEvent event) public void setBonus(UpdateEvent event)
{ {

View File

@ -42,18 +42,6 @@ public class OutfitStPatricksSuit extends OutfitGadget
setDisplayItem(displayItem); setDisplayItem(displayItem);
} }
@Override
public void enableCustom(Player player, boolean message)
{
applyArmor(player, message);
}
@Override
public void disableCustom(Player player, boolean message)
{
removeArmor(player, message);
}
@EventHandler @EventHandler
public void onUpdate(UpdateEvent event) public void onUpdate(UpdateEvent event)
{ {

View File

@ -45,7 +45,8 @@ public class OutfitWindUpSuit extends OutfitGadget
@Override @Override
public void enableCustom(Player player, boolean message) public void enableCustom(Player player, boolean message)
{ {
applyArmor(player, message); super.enableCustom(player, message);
_colorPhase.put(player, 0); _colorPhase.put(player, 0);
_percentage.put(player, 0); _percentage.put(player, 0);
} }
@ -53,7 +54,8 @@ public class OutfitWindUpSuit extends OutfitGadget
@Override @Override
public void disableCustom(Player player, boolean message) public void disableCustom(Player player, boolean message)
{ {
removeArmor(player, message); super.disableCustom(player, message);
_colorPhase.remove(player); _colorPhase.remove(player);
_percentage.remove(player); _percentage.remove(player);

View File

@ -0,0 +1,82 @@
package mineplex.core.gadget.gadgets.particle;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.shape.ShapeFidgetSpinner;
import mineplex.core.common.util.C;
import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilText;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.types.ParticleGadget;
import mineplex.core.gadget.util.CostConstants;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class ParticleFidgetSpinner extends ParticleGadget
{
private static final int MAX_ROTATION = 20;
private static final int PETAL_COUNT = 3;
private static final double HEIGHT = 0.9;
private final List<ShapeFidgetSpinner> _shapes = new ArrayList<>(MAX_ROTATION);
private int _shapeIndex;
public ParticleFidgetSpinner(GadgetManager manager)
{
super(manager, "Fidget Spinner Aura",
UtilText.splitLineToArray(C.cGray + "The best gift this Christmas!", LineFormat.LORE),
CostConstants.FOUND_IN_GINGERBREAD_CHESTS, Material.RECORD_3, (byte) 0);
for (int rotation = 0; rotation < MAX_ROTATION; rotation += 2)
{
_shapes.add(new ShapeFidgetSpinner(PETAL_COUNT, rotation));
}
}
@Override
public void playParticle(Player player, UpdateEvent event)
{
Location location = player.getLocation();
if (Manager.isMoving(player))
{
for (int i = 0; i < 5; i++)
{
UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, UtilAlg.getRandomLocation(location, 1.5, 1.5, 1.5), null, 0, 1, ViewDist.NORMAL);
}
return;
}
location.add(0, HEIGHT, 0);
ShapeFidgetSpinner shape = _shapes.get(_shapeIndex);
shape.display(location);
}
@Override
@EventHandler
public void Caller(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
{
return;
}
super.Caller(event);
if (++_shapeIndex == _shapes.size())
{
_shapeIndex = 0;
}
}
}

View File

@ -0,0 +1,66 @@
package mineplex.core.gadget.gadgets.particle;
import java.awt.*;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import mineplex.core.common.shape.ShapeWings;
import mineplex.core.common.skin.SkinData;
import mineplex.core.common.util.C;
import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilText;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.types.ParticleGadget;
import mineplex.core.gadget.util.CostConstants;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class ParticleWingsChristmas extends ParticleGadget
{
private static final Color GREEN = new Color(0, 158, 21);
private final ShapeWings _wings = new ShapeWings(ParticleType.RED_DUST.particleName, new Vector(1,1,1), 1, 0, false, ShapeWings.DEFAULT_ROTATION, ShapeWings.ANGEL_WING_PATTERN);
private final ShapeWings _wingsEdge = new ShapeWings(ParticleType.RED_DUST.particleName, new Vector(1,1,0.5), 1, 0, true, ShapeWings.DEFAULT_ROTATION, ShapeWings.ANGEL_WING_PATTERN);
public ParticleWingsChristmas(GadgetManager manager)
{
super(manager, "Christmas Wings",
UtilText.splitLineToArray(C.cGray + "TODO", LineFormat.LORE),
CostConstants.FOUND_IN_GINGERBREAD_CHESTS, Material.GLASS, (byte) 0);
setDisplayItem(SkinData.PRESENT.getSkull());
}
@Override
public void playParticle(Player player, UpdateEvent event)
{
if (event.getType() != UpdateType.FASTEST && event.getType() != UpdateType.FAST)
{
return;
}
Location location = player.getLocation();
location.add(0, 1.2, 0).add(location.getDirection().multiply(-0.2));
if (Manager.isMoving(player))
{
if (event.getType() == UpdateType.FASTEST)
{
UtilParticle.PlayParticleToAll(ParticleType.FIREWORKS_SPARK, location, 0.2F, 0.2F, 0.2F, 0, 3, ViewDist.NORMAL);
}
}
else if (event.getType() == UpdateType.FAST)
{
_wings.displayColored(location, GREEN);
_wingsEdge.displayColored(location, Color.RED);
}
}
}

View File

@ -26,7 +26,7 @@ public class SetReindeerSuit extends GadgetSet
{ {
private static final Vector VELOCITY = new Vector(0, 2, 0); private static final Vector VELOCITY = new Vector(0, 2, 0);
private static final long COOLDOWN = TimeUnit.SECONDS.toMillis(8); private static final long COOLDOWN = TimeUnit.SECONDS.toMillis(10);
public SetReindeerSuit(GadgetManager manager) public SetReindeerSuit(GadgetManager manager)
{ {
@ -43,7 +43,7 @@ public class SetReindeerSuit extends GadgetSet
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (event.isSneaking() || !isActive(player) || !Recharge.Instance.use(player, getName(), COOLDOWN, true, false)) if (event.isSneaking() || !isActive(player) || !Recharge.Instance.use(player, getName() + " Leap", COOLDOWN, true, false))
{ {
return; return;
} }
@ -69,7 +69,6 @@ public class SetReindeerSuit extends GadgetSet
UtilAction.velocity(player, velocity); UtilAction.velocity(player, velocity);
UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, location, 0, 0, 0, 0.1F, 1, ViewDist.NORMAL);
UtilParticle.PlayParticleToAll(ParticleType.FIREWORKS_SPARK, location.subtract(0, 0.5, 0), 0, 0, 0, 0.1F, 3, ViewDist.NORMAL); UtilParticle.PlayParticleToAll(ParticleType.FIREWORKS_SPARK, location.subtract(0, 0.5, 0), 0, 0, 0, 0.1F, 3, ViewDist.NORMAL);
if (iterations % 4 == 0) if (iterations % 4 == 0)

View File

@ -1,102 +1,29 @@
package mineplex.core.gadget.types; package mineplex.core.gadget.types;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.gadgets.hat.HatType; import mineplex.core.gadget.gadgets.hat.HatType;
public abstract class HatGadget extends OutfitGadget public abstract class HatGadget extends OutfitGadget
{ {
private ItemStack _hat;
private HatType _hatType; private final HatType _hatType;
public HatGadget(GadgetManager manager, HatType type) public HatGadget(GadgetManager manager, HatType type)
{ {
super(manager, type.getName(), type.getLore(), type.getCost(), ArmorSlot.HELMET, Material.GLASS, (byte) 0, type.getAltNames()); super(manager, type.getName(), type.getLore(), type.getCost(), ArmorSlot.HELMET, Material.GLASS, (byte) 0, type.getAltNames());
_hat = type.getHat();
_hatType = type; _hatType = type;
setDisplayItem(type.getHat()); setDisplayItem(type.getHat());
} }
public HatGadget(GadgetManager manager, String name, String[] desc, int cost, ItemStack item)
{
super(manager, name, desc, cost, ArmorSlot.HELMET, item.getType(), item.getData().getData());
}
public HatGadget(GadgetManager manager, String name, String[] desc, int cost, String playerName)
{
this(manager, name, desc, cost, getSkull(playerName));
}
public ItemStack getHelmetItem()
{
return _hat.clone();
}
public void applyArmor(Player player, boolean message)
{
Manager.removeGadgetType(player, GadgetType.MORPH, this);
Manager.removeGadgetType(player, GadgetType.FLAG, this);
Manager.removeOutfit(player, _slot);
_active.add(player);
if (message)
UtilPlayer.message(player, F.main("Gadget", "You put on " + F.elem(getName()) + "."));
player.getInventory().setHelmet(getHelmetItem());
}
public void removeArmor(Player player, boolean message)
{
if (!_active.remove(player))
return;
if (message)
UtilPlayer.message(player, F.main("Gadget", "You took off " + F.elem(getName()) + "."));
player.getInventory().setHelmet(null);
}
public static ItemStack getSkull(String playerName)
{
SkullMeta meta = (SkullMeta) Bukkit.getItemFactory().getItemMeta(Material.SKULL_ITEM);
meta.setOwner(playerName);
ItemStack stack = new ItemStack(Material.SKULL_ITEM,1 , (byte)3);
stack.setItemMeta(meta);
return stack;
}
@Override @Override
public GadgetType getGadgetType() public GadgetType getGadgetType()
{ {
return GadgetType.HAT; return GadgetType.HAT;
} }
@Override
public void enableCustom(Player player, boolean message)
{
applyArmor(player, message);
}
@Override
public void disableCustom(Player player, boolean message)
{
removeArmor(player, message);
}
public HatType getHatType() public HatType getHatType()
{ {
return _hatType; return _hatType;

View File

@ -63,6 +63,12 @@ public abstract class OutfitGadget extends Gadget
applyArmor(player, message); applyArmor(player, message);
} }
@Override
public void disableCustom(Player player, boolean message)
{
removeArmor(player, message);
}
public void applyArmor(Player player, boolean message) public void applyArmor(Player player, boolean message)
{ {
Manager.removeGadgetType(player, GadgetType.MORPH, this); Manager.removeGadgetType(player, GadgetType.MORPH, this);