implemented multiblock on revive player
This commit is contained in:
parent
f8a466a955
commit
93209ff3f2
@ -7,40 +7,79 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Skull;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.BlockVector;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.kapelle.multiblock.MultiblockListener;
|
||||
import org.kapelle.multiblock.MultiblockStructure;
|
||||
import org.kapelle.multiblock.block_component.IBlockComponent;
|
||||
import org.kapelle.multiblock.block_component.MultipleBlocks;
|
||||
import org.kapelle.multiblock.block_component.SingleBlock;
|
||||
|
||||
public class RevivePlayer implements Listener {
|
||||
private JavaPlugin plugin;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class RevivePlayer{
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
public RevivePlayer(JavaPlugin plugin){
|
||||
this.plugin = plugin;
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event){
|
||||
if(event.getBlockPlaced().getType() == Material.PLAYER_HEAD && !event.isCancelled()){
|
||||
if(isValidMultiblock(event.getBlockPlaced().getLocation())){
|
||||
OfflinePlayer spirit = getPlayerFromHead(event.getBlockPlaced());
|
||||
if (spirit.isOnline() /* && spirit.getPlayer().getGameMode() == GameMode.SPECTATOR */){
|
||||
revivePlayer(spirit.getPlayer(),event.getBlockPlaced().getLocation());
|
||||
}else{
|
||||
// Player is not online or not dead
|
||||
plugin.getServer().broadcastMessage("Player not ded");
|
||||
// TODO
|
||||
}
|
||||
new MultiblockListener(plugin, getMultiblockStructure(), new BlockVector(1, 2, 1)) {
|
||||
@Override
|
||||
protected void callback(Location coreBlockLocation) {
|
||||
onMultiblockValid(coreBlockLocation);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private boolean isValidMultiblock(Location lastPlacedBlock){
|
||||
return lastPlacedBlock.clone().add(new Vector(0,-1,0)).getBlock().getType() == Material.GOLD_BLOCK
|
||||
&& lastPlacedBlock.clone().add(new Vector(0,-2,0)).getBlock().getType() == Material.MAGMA_BLOCK;
|
||||
private MultiblockStructure getMultiblockStructure() {
|
||||
IBlockComponent gold = new SingleBlock(Material.GOLD_BLOCK);
|
||||
IBlockComponent soulSand = new MultipleBlocks(new HashSet<Material>() {{
|
||||
add(Material.SOUL_SAND);
|
||||
add(Material.SOUL_SOIL);
|
||||
}});
|
||||
IBlockComponent head = new SingleBlock(Material.PLAYER_HEAD);
|
||||
IBlockComponent air = new SingleBlock(Material.AIR);
|
||||
|
||||
return new MultiblockStructure(
|
||||
Arrays.asList(
|
||||
// Bottom layer
|
||||
Arrays.asList(
|
||||
Arrays.asList(gold, gold, gold),
|
||||
Arrays.asList(gold, gold, gold),
|
||||
Arrays.asList(gold, gold, gold)
|
||||
),
|
||||
|
||||
// Mid layer
|
||||
Arrays.asList(
|
||||
Arrays.asList(air, air, air),
|
||||
Arrays.asList(air, soulSand, air),
|
||||
Arrays.asList(air, air, air)
|
||||
|
||||
),
|
||||
|
||||
// Top layer
|
||||
Arrays.asList(
|
||||
Arrays.asList(air, air, air),
|
||||
Arrays.asList(air, head, air),
|
||||
Arrays.asList(air, air, air)
|
||||
)
|
||||
|
||||
));
|
||||
}
|
||||
|
||||
private void onMultiblockValid(Location coreBlockLocation){
|
||||
OfflinePlayer spirit = getPlayerFromHead(coreBlockLocation.getBlock());
|
||||
|
||||
if (spirit.isOnline() /* && spirit.getPlayer().getGameMode() == GameMode.SPECTATOR */){
|
||||
revivePlayer(spirit.getPlayer(),coreBlockLocation);
|
||||
}else{
|
||||
// Player is not online or not dead
|
||||
plugin.getServer().broadcastMessage("Player not ded");
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
private OfflinePlayer getPlayerFromHead(Block head){
|
||||
|
Loading…
Reference in New Issue
Block a user