Compare commits

...

3 Commits

Author SHA1 Message Date
f0e8ee791a implemented new multiblock for summon head 2020-06-28 18:12:11 +02:00
350858d221 changed revive multiblock 2020-06-28 18:11:51 +02:00
93209ff3f2 implemented multiblock on revive player 2020-06-28 15:32:18 +02:00
2 changed files with 119 additions and 73 deletions

View File

@@ -7,40 +7,81 @@ 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);
IBlockComponent obsidian = new SingleBlock(Material.CRYING_OBSIDIAN);
IBlockComponent dia = new SingleBlock(Material.DIAMOND_BLOCK);
return new MultiblockStructure(
Arrays.asList(
// Bottom layer
Arrays.asList(
Arrays.asList(gold, obsidian, gold),
Arrays.asList(obsidian, dia, obsidian),
Arrays.asList(gold, obsidian, 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){

View File

@@ -1,76 +1,84 @@
package org.kapelle.hardcore_revive;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
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.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
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 SummonHead implements Listener {
import java.util.Arrays;
import java.util.HashSet;
public class SummonHead{
private final JavaPlugin plugin;
public SummonHead(JavaPlugin plugin){
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event){
if(event.getBlockPlaced().getType() == Material.SOUL_CAMPFIRE && !event.isCancelled()){
if (isValidMultiblock(event.getBlockPlaced().getLocation())){
summonHead(event.getBlockPlaced().getLocation());
new MultiblockListener(plugin, getMultiblockStructure(), new BlockVector(0, 0, 0)) {
@Override
protected void callback(Location coreBlockLocation) {
summonHead(coreBlockLocation);
}
}
};
}
/**
* Checks if a block type is a sign that is standing (not mounted on a wall)
* @param block
* @return
*/
private boolean isStandingSign(Material block){
return block == Material.SPRUCE_SIGN
|| block == Material.ACACIA_SIGN
|| block == Material.BIRCH_SIGN
|| block == Material.CRIMSON_SIGN
|| block == Material.DARK_OAK_SIGN
|| block == Material.JUNGLE_SIGN
|| block == Material.OAK_SIGN
|| block == Material.WARPED_SIGN;
}
private MultiblockStructure getMultiblockStructure(){
IBlockComponent sign = new MultipleBlocks(new HashSet<Material>(){{
add(Material.SPRUCE_SIGN);
add(Material.ACACIA_SIGN);
add(Material.CRIMSON_SIGN);
add(Material.JUNGLE_SIGN);
add(Material.OAK_SIGN);
add(Material.WARPED_SIGN);
}});
/**
* Checks if the last placed block is a valid multiblock.
* The valid structure is from top to bottom: Standing sign, soul sand, soul campfire, soul sand
* @param lastBlockLocation Exprected to be the soul campfire
* @return if the structure is valid
*/
private boolean isValidMultiblock(Location lastBlockLocation){
return lastBlockLocation.clone().add(new Vector(0,-1,0)).getBlock().getType() == Material.SOUL_SAND
&& lastBlockLocation.clone().add(new Vector(0,1,0)).getBlock().getType() == Material.SOUL_SAND
&& isStandingSign(lastBlockLocation.clone().add(new Vector(0,2,0)).getBlock().getType());
IBlockComponent hayBale = new SingleBlock(Material.HAY_BLOCK);
IBlockComponent pumpkin = new MultipleBlocks(new HashSet<Material>(){{
add(Material.JACK_O_LANTERN);
add(Material.CARVED_PUMPKIN);
}});
return new MultiblockStructure(Arrays.asList(
// Bottom layer
Arrays.asList(
Arrays.asList(hayBale)
),
// Mid Layer
Arrays.asList(
Arrays.asList(pumpkin)
),
// Top layer
Arrays.asList(
Arrays.asList(sign)
)
));
}
/**
* Perform the head summoning ritual.
* @param lastBlockLocation The location of the core block of the multiblock structure. In this case
* @param coreBlockLocation The location of the core block of the multiblock structure. In this case
* the soul campfire.
*/
private void summonHead(Location lastBlockLocation){
Block topBlock = lastBlockLocation.clone().add(new Vector(0,2,0)).getBlock();
private void summonHead(Location coreBlockLocation){
Location signBlock = coreBlockLocation.clone().add(new Vector(0,2,0));
Location pumpkin = coreBlockLocation.clone().add(new Vector(0,1,0));
String spiritName = getSignText((Sign) topBlock.getState());
String spiritName = getSignText((Sign) signBlock.getBlock().getState());
Player spirit = plugin.getServer().getPlayerExact(spiritName);
if (spirit == null) {
@@ -79,10 +87,11 @@ public class SummonHead implements Listener {
}
// Remove sign
topBlock.setType(Material.AIR);
signBlock.getBlock().setType(Material.AIR);
pumpkin.getBlock().setType(Material.AIR);
// Spawn particle at sign
topBlock.getWorld().spawnParticle(Particle.SPELL_WITCH,topBlock.getLocation(),20);
pumpkin.getWorld().spawnParticle(Particle.SPELL_WITCH,pumpkin,20);
// Prepare head to be spawned
ItemStack head = new ItemStack(Material.PLAYER_HEAD);
@@ -92,11 +101,7 @@ public class SummonHead implements Listener {
head.setItemMeta(headMeta);
// Spawn head at the position of the sign
lastBlockLocation.getWorld().dropItem(topBlock.getLocation(),head);
// Remove soul campfire
// FIXME: removing the campfire raises an execption somewhere else. But i think its fine. Maybe removing a tile entity works different
lastBlockLocation.getBlock().setType(Material.AIR);
pumpkin.getWorld().dropItem(pumpkin,head);
}
/**