implemented multiblock on revive player

This commit is contained in:
Niklas 2020-06-28 15:32:18 +02:00
parent f8a466a955
commit 93209ff3f2

View File

@ -7,41 +7,80 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.Skull; import org.bukkit.block.Skull;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.BlockVector;
import org.bukkit.util.Vector; 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 { import java.util.Arrays;
private JavaPlugin plugin; import java.util.HashSet;
public class RevivePlayer{
private final JavaPlugin plugin;
public RevivePlayer(JavaPlugin plugin){ public RevivePlayer(JavaPlugin plugin){
this.plugin = plugin; this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin); new MultiblockListener(plugin, getMultiblockStructure(), new BlockVector(1, 2, 1)) {
@Override
protected void callback(Location coreBlockLocation) {
onMultiblockValid(coreBlockLocation);
}
};
} }
@EventHandler private MultiblockStructure getMultiblockStructure() {
public void onBlockPlace(BlockPlaceEvent event){ IBlockComponent gold = new SingleBlock(Material.GOLD_BLOCK);
if(event.getBlockPlaced().getType() == Material.PLAYER_HEAD && !event.isCancelled()){ IBlockComponent soulSand = new MultipleBlocks(new HashSet<Material>() {{
if(isValidMultiblock(event.getBlockPlaced().getLocation())){ add(Material.SOUL_SAND);
OfflinePlayer spirit = getPlayerFromHead(event.getBlockPlaced()); 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 */){ if (spirit.isOnline() /* && spirit.getPlayer().getGameMode() == GameMode.SPECTATOR */){
revivePlayer(spirit.getPlayer(),event.getBlockPlaced().getLocation()); revivePlayer(spirit.getPlayer(),coreBlockLocation);
}else{ }else{
// Player is not online or not dead // Player is not online or not dead
plugin.getServer().broadcastMessage("Player not ded"); plugin.getServer().broadcastMessage("Player not ded");
// TODO // TODO
} }
} }
}
}
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 OfflinePlayer getPlayerFromHead(Block head){ private OfflinePlayer getPlayerFromHead(Block head){
Skull skull = (Skull) (head.getState()); Skull skull = (Skull) (head.getState());