Fix the "wooden pillar" bug with supply drops
This commit is contained in:
parent
9ad8e18175
commit
b85214c7f0
@ -5,19 +5,18 @@ import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import mineplex.core.common.util.*;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.FallingBlock;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
||||
import mineplex.core.common.block.schematic.Schematic;
|
||||
import mineplex.core.common.block.schematic.SchematicData;
|
||||
import mineplex.core.common.block.schematic.UtilSchematic;
|
||||
import mineplex.core.common.util.UtilFirework;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilShapes;
|
||||
|
||||
/**
|
||||
* Represents an instance of a Supply Drop. <br>
|
||||
@ -101,11 +100,7 @@ public class SupplyDrop
|
||||
|
||||
if (_blade != null)
|
||||
{
|
||||
if (UtilMath.offset2d(_blade, _destination) < 1)
|
||||
{
|
||||
spawnLootChest();
|
||||
}
|
||||
else if (UtilMath.offset2d(_blade, _despawn) < 1)
|
||||
if (UtilMath.offset2d(_blade, _despawn) < 1)
|
||||
{
|
||||
for (Block block : _bladeBlocks)
|
||||
{
|
||||
@ -197,16 +192,6 @@ public class SupplyDrop
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
public void spawnLootChest()
|
||||
{
|
||||
FallingBlock fallingBlock = _blade.getWorld().spawnFallingBlock(_blade.clone().subtract(0, 10, 0), Material.WOOD, (byte) 0);
|
||||
|
||||
fallingBlock.setHurtEntities(false);
|
||||
fallingBlock.setDropItem(false);
|
||||
|
||||
UtilFirework.playFirework(fallingBlock.getLocation().add(0.5, 1, 0.5), UtilFirework.getRandomFireworkEffect(false, 2, 1));
|
||||
}
|
||||
|
||||
public final String getName()
|
||||
{
|
||||
@ -222,4 +207,6 @@ public class SupplyDrop
|
||||
{
|
||||
return _destination;
|
||||
}
|
||||
|
||||
public final Location getBladeLocation() { return _blade; }
|
||||
}
|
||||
|
@ -1,37 +1,32 @@
|
||||
package mineplex.gemhunters.supplydrop;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.blockrestore.BlockRestore;
|
||||
import mineplex.core.common.Pair;
|
||||
import mineplex.core.common.util.*;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.gemhunters.loot.LootModule;
|
||||
import mineplex.gemhunters.supplydrop.command.SupplyDropCommand;
|
||||
import mineplex.gemhunters.world.WorldDataModule;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.FallingBlock;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.FallingBlock;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.blockrestore.BlockRestore;
|
||||
import mineplex.core.common.Pair;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.util.UtilTextMiddle;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.common.util.UtilWorld;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.gemhunters.loot.LootModule;
|
||||
import mineplex.gemhunters.supplydrop.command.SupplyDropCommand;
|
||||
import mineplex.gemhunters.world.WorldDataModule;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class SupplyDropModule extends MiniPlugin
|
||||
{
|
||||
@ -85,6 +80,10 @@ public class SupplyDropModule extends MiniPlugin
|
||||
{
|
||||
stopSequence();
|
||||
}
|
||||
else if (UtilMath.offset2d(_current.getBladeLocation(), _current.getChestLocation()) < 1)
|
||||
{
|
||||
spawnLootChest();
|
||||
}
|
||||
}
|
||||
else if (UtilTime.elapsed(_lastSupplyDrop, SEQUENCE_TIMER))
|
||||
{
|
||||
@ -103,31 +102,6 @@ public class SupplyDropModule extends MiniPlugin
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void fallingBlockChange(EntityChangeBlockEvent event)
|
||||
{
|
||||
if (event.getEntity() instanceof FallingBlock && event.getTo() == Material.WOOD && isActive() && UtilMath.offsetSquared(_current.getChestLocation(), event.getBlock().getLocation()) < 16)
|
||||
{
|
||||
Block block = event.getBlock();
|
||||
|
||||
block.setType(Material.CHEST);
|
||||
|
||||
// Add location that the chest will appear at into the spawned
|
||||
// chests list so that LootModule can populate it with loot.
|
||||
_loot.addSpawnedChest(block.getLocation(), CHEST_COLOUR);
|
||||
|
||||
// Remove beacon
|
||||
for (Block beacon : _beaconBlocks)
|
||||
{
|
||||
_blockRestore.restore(beacon);
|
||||
}
|
||||
|
||||
_beaconBlocks.clear();
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void startSequence(String locationKey)
|
||||
{
|
||||
Location spawn = _worldData.getCustomLocation(LOCATION_DATA + " " + locationKey + " Start").get(0);
|
||||
@ -168,6 +142,43 @@ public class SupplyDropModule extends MiniPlugin
|
||||
_current = null;
|
||||
}
|
||||
|
||||
public void spawnLootChest()
|
||||
{
|
||||
Location chest = _current.getBladeLocation().clone().subtract(0, 10, 0);
|
||||
|
||||
runSyncTimer(new BukkitRunnable()
|
||||
{
|
||||
|
||||
Block chestBlock = chest.getBlock();
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
chestBlock.setType(Material.AIR);
|
||||
chestBlock = chestBlock.getRelative(BlockFace.DOWN);
|
||||
chestBlock.setType(Material.CHEST);
|
||||
|
||||
if (chestBlock.getRelative(BlockFace.DOWN).getType() != Material.AIR)
|
||||
{
|
||||
// Add location that the chest will appear at into the spawned
|
||||
// chests list so that LootModule can populate it with loot.
|
||||
_loot.addSpawnedChest(chestBlock.getLocation(), CHEST_COLOUR);
|
||||
|
||||
// Remove beacon
|
||||
for (Block beacon : _beaconBlocks)
|
||||
{
|
||||
_blockRestore.restore(beacon);
|
||||
}
|
||||
|
||||
_beaconBlocks.clear();
|
||||
cancel();
|
||||
}
|
||||
|
||||
UtilFirework.playFirework(chestBlock.getLocation().add(0.5, 1, 0.5), FireworkEffect.Type.BALL, Color.YELLOW, true, false);
|
||||
}
|
||||
}, 0, 5);
|
||||
}
|
||||
|
||||
public boolean isActive()
|
||||
{
|
||||
return _current != null;
|
||||
|
Loading…
Reference in New Issue
Block a user