Flowers where player walks

This commit is contained in:
LCastr0 2017-03-20 08:23:32 -03:00
parent e1d9a568c9
commit 75ad5b9d51
5 changed files with 217 additions and 79 deletions

View File

@ -7,6 +7,16 @@ import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.Blocks;
import net.minecraft.server.v1_8_R3.IBlockData;
import net.minecraft.server.v1_8_R3.Item;
import net.minecraft.server.v1_8_R3.MathHelper;
import net.minecraft.server.v1_8_R3.MinecraftKey;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import net.minecraft.server.v1_8_R3.TileEntityFlowerPot;
import net.minecraft.server.v1_8_R3.WorldServer;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.SkullType;
@ -35,15 +45,6 @@ import com.mojang.authlib.GameProfile;
import mineplex.core.common.Pair;
import mineplex.core.common.block.MultiBlockUpdaterAgent;
import mineplex.core.common.skin.SkinData;
import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.Blocks;
import net.minecraft.server.v1_8_R3.IBlockData;
import net.minecraft.server.v1_8_R3.Item;
import net.minecraft.server.v1_8_R3.MathHelper;
import net.minecraft.server.v1_8_R3.MinecraftKey;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import net.minecraft.server.v1_8_R3.TileEntityFlowerPot;
import net.minecraft.server.v1_8_R3.WorldServer;
public class UtilBlock
{
@ -394,7 +395,17 @@ public class UtilBlock
{
return blockUseSet.contains(block);
}
public static Set<Block> getBlocksInRadius(Location loc, double radius)
{
return getInRadius(loc, radius).keySet();
}
public static Set<Block> getBlocksInRadius(Location loc, double radius, int maxHeight)
{
return getInRadius(loc, radius, maxHeight).keySet();
}
public static HashMap<Block, Double> getInRadius(Location loc, double dR)
{
return getInRadius(loc, dR, 9999);

View File

@ -164,7 +164,7 @@ import mineplex.core.gadget.gadgets.particle.ParticleCoalFumes;
import mineplex.core.gadget.gadgets.particle.ParticleFairy;
import mineplex.core.gadget.gadgets.particle.ParticleFireRings;
import mineplex.core.gadget.gadgets.particle.ParticleLegend;
import mineplex.core.gadget.gadgets.particle.ParticleSpringHalo;
import mineplex.core.gadget.gadgets.particle.spring.ParticleSpringHalo;
import mineplex.core.gadget.gadgets.particle.ParticleWingsAngel;
import mineplex.core.gadget.gadgets.particle.ParticleWingsDemons;
import mineplex.core.gadget.gadgets.particle.ParticleWingsInfernal;

View File

@ -1,68 +0,0 @@
package mineplex.core.gadget.gadgets.particle;
import java.awt.Color;
import java.time.Month;
import java.time.YearMonth;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilText;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.types.GadgetType;
import mineplex.core.gadget.types.OutfitGadget;
import mineplex.core.gadget.types.ParticleGadget;
import mineplex.core.particleeffects.ColoredCircleEffect;
import mineplex.core.updater.event.UpdateEvent;
public class ParticleSpringHalo extends ParticleGadget
{
private Map<Player, ColoredCircleEffect> _effects = new HashMap<>();
public ParticleSpringHalo(GadgetManager manager)
{
// TODO CHANGE LORE BEFORE RELEASE
super(manager, "Spring Halo", UtilText.splitLinesToArray(new String[]{C.cGray + "Placeholder"}, LineFormat.LORE), -14, Material.GLASS, (byte) 0, YearMonth.of(2017, Month.APRIL));
}
@Override
public void enableCustom(Player player, boolean message)
{
super.enableCustom(player, message);
Manager.removeGadgetType(player, GadgetType.MORPH, this);
Manager.removeOutfit(player, OutfitGadget.ArmorSlot.HELMET);
ColoredCircleEffect circleEffect = new ColoredCircleEffect(Manager.getPlugin(), player, 0.7d, false,
Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW);
circleEffect.setYOffset(2.3d);
circleEffect.start();
_effects.put(player, circleEffect);
player.getEquipment().setHelmet(new ItemStack(Material.RED_ROSE, 1, (byte) 8));
}
@Override
public void disableCustom(Player player, boolean message)
{
super.disableCustom(player, message);
if (_effects.containsKey(player))
{
ColoredCircleEffect circleEffect = _effects.get(player);
if (circleEffect != null)
{
circleEffect.stop();
}
}
_effects.remove(player);
player.getInventory().setHelmet(null);
}
@Override
public void playParticle(Player player, UpdateEvent event)
{}
}

View File

@ -0,0 +1,161 @@
package mineplex.core.gadget.gadgets.particle.spring;
import java.awt.Color;
import java.time.Month;
import java.time.YearMonth;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.UtilTime;
import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.types.GadgetType;
import mineplex.core.gadget.types.OutfitGadget;
import mineplex.core.gadget.types.ParticleGadget;
import mineplex.core.particleeffects.ColoredCircleEffect;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class ParticleSpringHalo extends ParticleGadget
{
private Map<Player, ColoredCircleEffect> _effects = new HashMap<>();
private List<SpringHaloData> _springHaloData = new ArrayList<>();
private Map<Player, List<SpringHaloData>> _playerSpringHaloData = new HashMap<>();
public ParticleSpringHalo(GadgetManager manager)
{
// TODO CHANGE LORE BEFORE RELEASE
super(manager, "Spring Halo", UtilText.splitLinesToArray(new String[]{C.cGray + "Placeholder"}, LineFormat.LORE), -14, Material.GLASS, (byte) 0, YearMonth.of(2017, Month.APRIL));
}
@Override
public void enableCustom(Player player, boolean message)
{
super.enableCustom(player, message);
Manager.removeGadgetType(player, GadgetType.MORPH, this);
Manager.removeOutfit(player, OutfitGadget.ArmorSlot.HELMET);
ColoredCircleEffect circleEffect = new ColoredCircleEffect(Manager.getPlugin(), player, 0.7d, false,
Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW);
circleEffect.setYOffset(2.3d);
circleEffect.start();
_effects.put(player, circleEffect);
player.getEquipment().setHelmet(new ItemStack(Material.RED_ROSE, 1, (byte) 8));
}
@Override
public void disableCustom(Player player, boolean message)
{
super.disableCustom(player, message);
if (_effects.containsKey(player))
{
ColoredCircleEffect circleEffect = _effects.get(player);
if (circleEffect != null)
{
circleEffect.stop();
}
}
_effects.remove(player);
player.getInventory().setHelmet(null);
if (_playerSpringHaloData.containsKey(player))
{
Iterator<SpringHaloData> iterator = _playerSpringHaloData.get(player).iterator();
while (iterator.hasNext())
{
SpringHaloData springHaloData = iterator.next();
springHaloData.getBlock().setType(Material.AIR);
springHaloData.getBlock().setData((byte) 0);
removeSpringHalo(springHaloData);
}
_playerSpringHaloData.get(player).clear();
_playerSpringHaloData.remove(player);
}
}
@Override
public void playParticle(Player player, UpdateEvent event)
{
}
@EventHandler
public void spawnFlowers(PlayerMoveEvent event)
{
if (!isActive(event.getPlayer()))
return;
Player player = event.getPlayer();
Block block = event.getFrom().getBlock();
if (block.getType() != Material.AIR)
return;
if (block.getLocation().subtract(0, 1, 0).getBlock().getType() != Material.GRASS
&& block.getLocation().subtract(0, 1, 0).getBlock().getType() != Material.DIRT)
return;
block.setType(Material.RED_ROSE);
block.setData((byte) UtilMath.random.nextInt(8));
SpringHaloData springHaloData = new SpringHaloData(player, block, System.currentTimeMillis());
addFlower(player, springHaloData);
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
Iterator<SpringHaloData> iterator = _springHaloData.iterator();
while (iterator.hasNext())
{
SpringHaloData springHaloData = iterator.next();
if (UtilTime.elapsed(springHaloData.getSpawned(), 1500))
{
springHaloData.getBlock().setType(Material.AIR);
springHaloData.getBlock().setData((byte) 0);
removeSpringHalo(springHaloData);
iterator.remove();
}
}
}
private void addFlower(Player player, SpringHaloData springHaloData)
{
_springHaloData.add(springHaloData);
if (_playerSpringHaloData.containsKey(player))
{
List<SpringHaloData> list = _playerSpringHaloData.get(player);
list.add(springHaloData);
}
else
{
List<SpringHaloData> list = new ArrayList<>();
list.add(springHaloData);
_playerSpringHaloData.put(player, list);
}
}
private void removeSpringHalo(SpringHaloData springHaloData)
{
Player player = springHaloData.getPlayer();
List<SpringHaloData> list = _playerSpringHaloData.get(player);
if (list != null)
{
list.remove(springHaloData);
}
}
}

View File

@ -0,0 +1,34 @@
package mineplex.core.gadget.gadgets.particle.spring;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
public class SpringHaloData
{
private Player _player;
private Block _block;
private long _spawned;
public SpringHaloData(Player player, Block block, long spawned)
{
_player = player;
_block = block;
_spawned = spawned;
}
public Player getPlayer()
{
return _player;
}
public Block getBlock()
{
return _block;
}
public long getSpawned()
{
return _spawned;
}
}