implemented player revive
This commit is contained in:
parent
4f2da2ddd8
commit
9438b1b526
@ -5,12 +5,14 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
public class HardcoreRevive extends JavaPlugin {
|
public class HardcoreRevive extends JavaPlugin {
|
||||||
DropHead dropHead;
|
DropHead dropHead;
|
||||||
SummonHead summonHead;
|
SummonHead summonHead;
|
||||||
|
RevivePlayer revivePlayer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
if(this.getServer().isHardcore()){
|
if(this.getServer().isHardcore()){
|
||||||
dropHead = new DropHead(this);
|
dropHead = new DropHead(this);
|
||||||
summonHead = new SummonHead(this);
|
summonHead = new SummonHead(this);
|
||||||
|
revivePlayer = new RevivePlayer(this);
|
||||||
this.getLogger().info("hardcore-revive plugin enabled.");
|
this.getLogger().info("hardcore-revive plugin enabled.");
|
||||||
}else{
|
}else{
|
||||||
this.getLogger().info("Not running in hardcore mode. hardcore-revive disabled.");
|
this.getLogger().info("Not running in hardcore mode. hardcore-revive disabled.");
|
||||||
|
63
src/main/java/org/kapelle/hardcore_revive/RevivePlayer.java
Normal file
63
src/main/java/org/kapelle/hardcore_revive/RevivePlayer.java
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package org.kapelle.hardcore_revive;
|
||||||
|
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
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.Vector;
|
||||||
|
|
||||||
|
public class RevivePlayer implements Listener {
|
||||||
|
private 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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){
|
||||||
|
Skull skull = (Skull) (head.getState());
|
||||||
|
return skull.getOwningPlayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void revivePlayer(Player player, Location headLocation){
|
||||||
|
// Break blocks
|
||||||
|
headLocation.getBlock().setType(Material.AIR);
|
||||||
|
headLocation.add(new Vector(0,-1,0)).getBlock().setType(Material.AIR);
|
||||||
|
headLocation.add(new Vector(0,-1,0)).getBlock().setType(Material.AIR);
|
||||||
|
|
||||||
|
// Teleport player
|
||||||
|
player.teleport(headLocation);
|
||||||
|
|
||||||
|
// Set player gamemode
|
||||||
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user