org.bukkit.block.Skull Java Examples

The following examples show how to use org.bukkit.block.Skull. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SkullBlock.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public boolean set(Block block) {
    Skull skull = (Skull) block.getState();
    if(skullOwnerName != null){
        skull.setOwner(skullOwnerName);
    }
    skull.setSkullType(skullType);
    skull.setRotation(skullRotation);
    skull.setRawData((byte) skullStanding);
    // Texture update
    if(skullTextureValue != null){
        setSkullWithNonPlayerProfile(skullTextureValue, skullTextureSignature, skullOwnerUUID, skullOwnerName, skull);
    }
    skull.update(true, false);
    return true;
}
 
Example #2
Source File: SkullPlaceHolders.java    From VoxelGamesLibv2 with MIT License 6 votes vote down vote up
@EventHandler
public void handleInteract(@Nonnull PlayerInteractEvent event) {
    if (event.getAction() == org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK && event.getClickedBlock() != null) {
        if (event.getClickedBlock().getState() instanceof Skull) {
            Skull skull = (Skull) event.getClickedBlock().getState();
            if (skull.hasMetadata("UpdateCooldown")) {
                long cooldown = skull.getMetadata("UpdateCooldown").get(0).asLong();
                if (cooldown > System.currentTimeMillis() - 1 * 1000) {
                    return;
                }
            }
            skull.update();
            skull.setMetadata("UpdateCooldown", new FixedMetadataValue(voxelGamesLib, System.currentTimeMillis()));
        }
    }
}
 
Example #3
Source File: MapScanner.java    From VoxelGamesLibv2 with MIT License 6 votes vote down vote up
@Nullable
private String getMarkerData(@Nonnull Skull skull) {
    if (skull.getOwningPlayer() != null) {
        String markerData = skull.getOwningPlayer().getName();
        if (markerData == null) {
            //log.warning("owning player name null?!");
            markerData = skull.getOwner();
            if (markerData == null) {
                log.warning("Could not find data about the owner for the skull at " + skull.getLocation().toVector());
                markerData = "undefined";
            }
        }

        if (isPlaceholder(markerData)) {
            return null;
        } else {
            return markerData;
        }
    } else {
        return null;
    }
}
 
Example #4
Source File: WorldProblemMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private void checkChunk(ChunkPosition pos, @Nullable Chunk chunk) {
    if(repairedChunks.add(pos)) {
        if(chunk == null) {
            chunk = pos.getChunk(match.getWorld());
        }

        for(BlockState state : chunk.getTileEntities()) {
            if(state instanceof Skull) {
                if(!NMSHacks.isSkullCached((Skull) state)) {
                    Location loc = state.getLocation();
                    broadcastDeveloperWarning("Uncached skull \"" + ((Skull) state).getOwner() + "\" at " + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ());
                }
            }
        }

        // Replace formerly invisible half-iron-door blocks with barriers
        for(Block ironDoor : chunk.getBlocks(Material.IRON_DOOR_BLOCK)) {
            BlockFace half = (ironDoor.getData() & 8) == 0 ? BlockFace.DOWN : BlockFace.UP;
            if(ironDoor.getRelative(half.getOppositeFace()).getType() != Material.IRON_DOOR_BLOCK) {
                ironDoor.setType(Material.BARRIER, false);
            }
        }

        // Remove all block 36 and remember the ones at y=0 so VoidFilter can check them
        for(Block block36 : chunk.getBlocks(Material.PISTON_MOVING_PIECE)) {
            if(block36.getY() == 0) {
                block36Locations.add(block36.getX(), block36.getY(), block36.getZ());
            }
            block36.setType(Material.AIR, false);
        }
    }
}
 
Example #5
Source File: PlayerHeadProvider.java    From UHC with MIT License 5 votes vote down vote up
public void setBlockAsHead(String name, Block headBlock, BlockFaceXZ direction) {
    // set the type to skull
    headBlock.setType(Material.SKULL);
    headBlock.setData((byte) 1);

    final Skull state = (Skull) headBlock.getState();

    state.setSkullType(SkullType.PLAYER);
    state.setOwner(name);
    state.setRotation(direction.getBlockFace());
    state.update();
}
 
Example #6
Source File: SkullCreator.java    From Crazy-Crates with MIT License 5 votes vote down vote up
/**
 * Sets the block to a skull with the given UUID.
 *
 * @param block The block to set
 * @param id The player to set it to
 */
public static void blockWithUuid(Block block, UUID id) {
    notNull(block, "block");
    notNull(id, "id");
    
    setBlockType(block);
    ((Skull) block.getState()).setOwningPlayer(Bukkit.getOfflinePlayer(id));
}
 
Example #7
Source File: SkullCreator.java    From Crazy-Crates with MIT License 5 votes vote down vote up
/**
 * Sets the block to a skull with the given name.
 *
 * @param block The block to set
 * @param name The player to set it to
 *
 * @deprecated names don't make for good identifiers
 */
@Deprecated
public static void blockWithName(Block block, String name) {
    notNull(block, "block");
    notNull(name, "name");
    
    setBlockType(block);
    ((Skull) block.getState()).setOwningPlayer(Bukkit.getOfflinePlayer(name));
}
 
Example #8
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updateSkull(Skull skull, UUID uuid) {
	if (skull.getType().equals(Material.SKELETON_SKULL)) {
		Block block = skull.getBlock();
		block.setType(Material.PLAYER_HEAD);
		Skull s = (Skull) block.getState();
		s.setOwningPlayer(Bukkit.getOfflinePlayer(uuid));
	} else {
		skull.setOwningPlayer(Bukkit.getOfflinePlayer(uuid));
	}
}
 
Example #9
Source File: SkullPlaceHolders.java    From VoxelGamesLibv2 with MIT License 5 votes vote down vote up
@EventHandler
public void chunkLoad(@Nonnull ChunkLoadEvent event) {
    Arrays.stream(event.getChunk().getTileEntities())
            .filter(blockState -> blockState instanceof Skull)
            .map((blockState) -> (Skull) blockState)
            .forEach(skull -> lastSeenSkulls.put(skull.getLocation(), skull));
}
 
Example #10
Source File: SkullPlaceHolders.java    From VoxelGamesLibv2 with MIT License 5 votes vote down vote up
public PacketContainer modifySkull(WrapperPlayServerTileEntityData packet, Player player) {
    NbtCompound nbt = (NbtCompound) packet.getNbtData();

    Location location = new Location(player.getWorld(), packet.getLocation().getX(), packet.getLocation().getY(), packet.getLocation().getZ());

    if (nbt.containsKey("Owner")) {
        NbtCompound owner = nbt.getCompound("Owner");
        if (owner.containsKey("Name")) {
            String name = owner.getString("Name");
            PlayerProfile profile = null;

            String[] args = name.split(":");
            SkullPlaceHolder skullPlaceHolder = placeHolders.get(args[0]);
            if (skullPlaceHolder != null) {
                profile = skullPlaceHolder.apply(name, player, location, args);
            }

            if (profile != null && profile.hasTextures()) {
                NBTUtil.setPlayerProfile(owner, profile);
            } else {
                //log.warning("Error while applying placeholder '" + name + "' null? " + (profile == null) + " textures? " + (profile == null ? "" : profile.hasTextures()));
                NBTUtil.setPlayerProfile(owner, textureHandler.getErrorProfile());
            }

            owner.setName(name);
        }

        // update last seen signs
        Block b = location.getBlock();
        if (!(b.getState() instanceof Skull)) {
            return packet.getHandle();
        }
        Skull skull = (Skull) b.getState();
        lastSeenSkulls.put(location, skull);
    }

    return packet.getHandle();
}
 
Example #11
Source File: SkullPlaceHolders.java    From VoxelGamesLibv2 with MIT License 5 votes vote down vote up
public void init() {
    Bukkit.getPluginManager().registerEvents(this, voxelGamesLib);

    registerPlaceholders();

    // listener
    protocolManager.addPacketListener(new PacketAdapter(voxelGamesLib, PacketType.Play.Server.TILE_ENTITY_DATA) {
        @Override
        public void onPacketSending(PacketEvent event) {
            WrapperPlayServerTileEntityData packet = new WrapperPlayServerTileEntityData(event.getPacket());
            event.setPacket(modifySkull(packet, event.getPlayer()));
        }
    });

    // search for already loaded skulls
    Bukkit.getWorlds().stream()
            .flatMap(w -> Arrays.stream(w.getLoadedChunks()))
            .flatMap(s -> Arrays.stream(s.getTileEntities()))
            .filter(s -> s instanceof Skull)
            .map(s -> (Skull) s)
            .forEach(s -> lastSeenSkulls.put(s.getLocation(), s));

    // update task
    new BukkitRunnable() {

        @Override
        public void run() {
            lastSeenSkulls.forEach((loc, skull) -> skull.update());
        }
    }.runTaskTimer(voxelGamesLib, 20, 20);
}
 
Example #12
Source File: SkullBlock.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
private static void setSkullProfile(Skull skull, GameProfile gameProfile) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { 	

        Field profileField = null;
        try {
            profileField = skull.getClass().getDeclaredField("profile");
            profileField.setAccessible(true);
            profileField.set(skull, gameProfile);
        } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
 
Example #13
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void updateSkull(Skull skull, UUID uuid) {
	skull.setSkullType(SkullType.PLAYER);
	skull.setOwner(Bukkit.getOfflinePlayer(uuid).getName());
}
 
Example #14
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
public void updateSkull(Skull skull, UUID uuid) {
	skull.setOwningPlayer(Bukkit.getOfflinePlayer(uuid));
}
 
Example #15
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void updateSkull(Skull skull, UUID uuid) {
	skull.setSkullType(SkullType.PLAYER);
	skull.setOwningPlayer(Bukkit.getOfflinePlayer(uuid));
}
 
Example #16
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void updateSkull(Skull skull, UUID uuid) {
	skull.setSkullType(SkullType.PLAYER);
	skull.setOwner(Bukkit.getOfflinePlayer(uuid).getName());
}
 
Example #17
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void updateSkull(Skull skull, UUID uuid) {
	skull.setSkullType(SkullType.PLAYER);
	skull.setOwner(Bukkit.getOfflinePlayer(uuid).getName());
}
 
Example #18
Source File: DebugFishListener.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
private void sendInfo(Player p, Block b) {
    SlimefunItem item = BlockStorage.check(b);

    p.sendMessage(" ");
    p.sendMessage(ChatColors.color("&d" + b.getType() + " &e@ X: " + b.getX() + " Y: " + b.getY() + " Z: " + b.getZ()));
    p.sendMessage(ChatColors.color("&dId: " + "&e" + item.getID()));
    p.sendMessage(ChatColors.color("&dPlugin: " + "&e" + item.getAddon().getName()));

    if (b.getState() instanceof Skull) {
        p.sendMessage(ChatColors.color("&dSkull: " + enabledTooltip));

        // Check if the skull is a wall skull, and if so use Directional instead of Rotatable.
        if (b.getType() == Material.PLAYER_WALL_HEAD) {
            p.sendMessage(ChatColors.color("  &dFacing: &e" + ((Directional) b.getBlockData()).getFacing().toString()));
        }
        else {
            p.sendMessage(ChatColors.color("  &dRotation: &e" + ((Rotatable) b.getBlockData()).getRotation().toString()));
        }
    }

    if (BlockStorage.getStorage(b.getWorld()).hasInventory(b.getLocation())) {
        p.sendMessage(ChatColors.color("&dInventory: " + enabledTooltip));
    }
    else {
        p.sendMessage(ChatColors.color("&dInventory: " + disabledTooltip));
    }

    TickerTask ticker = SlimefunPlugin.getTickerTask();

    if (item.isTicking()) {
        p.sendMessage(ChatColors.color("&dTicker: " + enabledTooltip));
        p.sendMessage(ChatColors.color("  &dAsync: &e" + (BlockStorage.check(b).getBlockTicker().isSynchronized() ? disabledTooltip : enabledTooltip)));
        p.sendMessage(ChatColors.color("  &dTimings: &e" + NumberUtils.getAsMillis(ticker.getTimings(b))));
        p.sendMessage(ChatColors.color("  &dTotal Timings: &e" + NumberUtils.getAsMillis(ticker.getTimings(BlockStorage.checkID(b)))));
        p.sendMessage(ChatColors.color("  &dChunk Timings: &e" + NumberUtils.getAsMillis(ticker.getTimings(b.getChunk()))));
    }
    else if (item.getEnergyTicker() != null) {
        p.sendMessage(ChatColors.color("&dTicking: " + "&3Indirect"));
        p.sendMessage(ChatColors.color("  &dTimings: &e" + NumberUtils.getAsMillis(ticker.getTimings(b))));
        p.sendMessage(ChatColors.color("  &dChunk Timings: &e" + NumberUtils.getAsMillis(ticker.getTimings(b.getChunk()))));
    }
    else {
        p.sendMessage(ChatColors.color("&dTicker: " + disabledTooltip));
        p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&dTicking: " + disabledTooltip));
    }

    if (ChargableBlock.isChargable(b)) {
        p.sendMessage(ChatColors.color("&dChargeable: " + enabledTooltip));
        p.sendMessage(ChatColors.color("  &dEnergy: &e" + ChargableBlock.getCharge(b) + " / " + ChargableBlock.getMaxCharge(b)));
    }
    else {
        p.sendMessage(ChatColors.color("&dChargeable: " + disabledTooltip));
    }

    p.sendMessage(ChatColors.color("  &dEnergyNet Type: &e" + EnergyNet.getComponent(b.getLocation())));

    p.sendMessage(ChatColors.color("&6" + BlockStorage.getBlockInfoAsJson(b)));
    p.sendMessage(" ");
}
 
Example #19
Source File: ExtensionLeaderboardPodium.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public void update(Map<String, Statistic> statistics, boolean forceBlocks, boolean delete) {
	BlockFace2D rightDir = direction.right();
	BlockFace2D leftDir = direction.left();
	
	BlockFace rightFace = rightDir.getBlockFace3D();
	BlockFace leftFace = leftDir.getBlockFace3D();
	
	Block baseBlock = baseLocation.getBlock();
	if (delete) {
		baseBlock.setType(Material.AIR);
	}
	
	SignLayout layout = layoutConfig.getLayout();
	
	Iterator<Entry<String, Statistic>> iterator = statistics != null ? statistics.entrySet().iterator() : null;
	for (int i = 0; i < size.getStatisticAmount(); i++) {
		Entry<String, Statistic> entry = iterator != null && iterator.hasNext() ? iterator.next() : null;
		
		Block position = null;
		Material type = null;
		
		switch (i) {
		case 0:
			//Top
			position = baseBlock.getRelative(BlockFace.UP);
			type = Material.DIAMOND_BLOCK;
			break;
		case 1:
			//First left
			position = baseBlock.getRelative(leftFace);
			type = Material.GOLD_BLOCK;
			break;
		case 2:
			//First right
			position = baseBlock.getRelative(rightFace);
			type = Material.IRON_BLOCK;
			break;
		case 3:
			//Second left
			position = baseBlock.getRelative(leftFace, 2);
			type = Material.DOUBLE_STEP;
			break;
		case 4:
			//Second right
			position = baseBlock.getRelative(rightFace, 2);
			type = Material.DOUBLE_STEP;
			break;
		}
		
		if (position == null) {
			continue;
		}
		
		Block signBlock = position.getRelative(direction.getBlockFace3D());
		Block skullBlock = position.getRelative(BlockFace.UP);
		
		if (delete) {
			signBlock.setType(Material.AIR);
			skullBlock.setType(Material.AIR);
			position.setType(Material.AIR);
			continue;
		}
		
		if (baseBlock.getType() == Material.AIR || forceBlocks) {
			baseBlock.setType(Material.DOUBLE_STEP);
		}
		
		if (position.getType() == Material.AIR || forceBlocks) {
			position.setType(type);
		}
		
		if (entry == null) {
			continue;
		}
		
		/* For legacy reasons and compatibility */
		signBlock.setTypeId(Material.WALL_SIGN.getId(), false);
		skullBlock.setTypeId(Material.SKULL.getId(), false);
		
		Skull skull = (Skull) skullBlock.getState();
		skull.setRotation(direction.getBlockFace3D());
		skull.setSkullType(SkullType.PLAYER);
		skull.setOwner(entry.getKey());
		skull.setRawData(SKULL_ON_FLOOR);
		skull.update(true, false);
		
		Sign sign = (Sign) signBlock.getState();
		
		Set<Variable> variables = Sets.newHashSet();
		entry.getValue().supply(variables, null);
		variables.add(new Variable("player", entry.getKey()));
		variables.add(new Variable("rank", i + 1));
		
		layout.inflate(sign, variables);
		org.bukkit.material.Sign data = new org.bukkit.material.Sign(Material.WALL_SIGN);
		data.setFacingDirection(direction.getBlockFace3D());
		sign.setData(data);
		sign.update();
	}
}
 
Example #20
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void updateSkull(Skull skull, UUID uuid) {
	skull.setSkullType(SkullType.PLAYER);
	skull.setOwner(Bukkit.getOfflinePlayer(uuid).getName());
}
 
Example #21
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
@Override 
public void updateSkull(Skull skull, UUID uuid) {
	skull.setSkullType(SkullType.PLAYER);
	skull.setOwner(Bukkit.getOfflinePlayer(uuid).getName());
}
 
Example #22
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void updateSkull(Skull skull, UUID uuid) {
	skull.setSkullType(SkullType.PLAYER);
	skull.setOwner(Bukkit.getOfflinePlayer(uuid).getName());
}
 
Example #23
Source File: SkullPlaceHolders.java    From VoxelGamesLibv2 with MIT License 4 votes vote down vote up
@EventHandler
public void chunkUnload(@Nonnull ChunkUnloadEvent event) {
    Arrays.stream(event.getChunk().getTileEntities())
            .filter(blockState -> blockState instanceof Skull)
            .forEach(sign -> lastSeenSkulls.remove(sign.getLocation()));
}
 
Example #24
Source File: MapScanner.java    From VoxelGamesLibv2 with MIT License 4 votes vote down vote up
/**
 * Searches the map for "markers". Most of the time these are implemented as tile entities (skulls)
 *
 * @param map    the map to scan
 * @param center the center location
 * @param range  the range in where to scan
 */
public void searchForMarkers(@Nonnull Map map, @Nonnull Vector3D center, int range, @Nonnull UUID gameid) {
    World world = Bukkit.getWorld(map.getLoadedName(gameid));
    if (world == null) {
        throw new MapException("Could not find world " + map.getLoadedName(gameid) + "(" + map.getInfo().getDisplayName() + ")" + ". Is it loaded?");
    }

    List<Marker> markers = new ArrayList<>();
    List<ChestMarker> chestMarkers = new ArrayList<>();

    int startX = (int) center.getX();
    int startY = (int) center.getZ();

    int minX = Math.min(startX - range, startX + range);
    int minZ = Math.min(startY - range, startY + range);

    int maxX = Math.max(startX - range, startX + range);
    int maxZ = Math.max(startY - range, startY + range);

    for (int x = minX; x <= maxX; x += 16) {
        for (int z = minZ; z <= maxZ; z += 16) {
            Chunk chunk = world.getChunkAt(x >> 4, z >> 4);
            for (BlockState te : chunk.getTileEntities()) {
                if (te.getType() == Material.PLAYER_HEAD) {
                    Skull skull = (Skull) te;
                    String markerData = getMarkerData(skull);
                    if (markerData == null) continue;
                    MarkerDefinition markerDefinition = mapHandler.createMarkerDefinition(markerData);
                    markers.add(new Marker(new Vector3D(skull.getX(), skull.getY(), skull.getZ()),
                            DirectionUtil.directionToYaw(skull.getRotation()),
                            markerData, markerDefinition));
                } else if (te.getType() == Material.CHEST) {
                    Chest chest = (Chest) te;
                    String name = chest.getBlockInventory().getName();
                    ItemStack[] items = new ItemStack[chest.getBlockInventory()
                            .getStorageContents().length];
                    for (int i = 0; i < items.length; i++) {
                        ItemStack is = chest.getBlockInventory().getItem(i);
                        if (is == null) {
                            items[i] = new ItemStack(Material.AIR);
                        } else {
                            items[i] = is;
                        }
                    }
                    chestMarkers
                            .add(new ChestMarker(new Vector3D(chest.getX(), chest.getY(), chest.getZ()), name,
                                    items));
                }
            }
        }
    }

    map.setMarkers(markers);
    map.setChestMarkers(chestMarkers);
}
 
Example #25
Source File: PlayerDeathListener.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerDeath(PlayerDeathEvent event){
	Player player = event.getEntity();
	GameManager gm = GameManager.getGameManager();
	PlayersManager pm = gm.getPlayersManager();
	MainConfiguration cfg = gm.getConfiguration();
	UhcPlayer uhcPlayer = pm.getUhcPlayer(player);

	if (uhcPlayer.getState() != PlayerState.PLAYING){
		Bukkit.getLogger().warning("[UhcCore] " + player.getName() + " died while already in 'DEAD' mode!");
		player.kickPlayer("Don't cheat!");
		return;
	}

	pm.setLastDeathTime();

	// kill event
	Player killer = player.getKiller();
	if(killer != null){
		UhcPlayer uhcKiller = pm.getUhcPlayer(killer);

		uhcKiller.kills++;

		// Call Bukkit event
		UhcPlayerKillEvent killEvent = new UhcPlayerKillEvent(uhcPlayer, uhcKiller);
		Bukkit.getServer().getPluginManager().callEvent(killEvent);

		if(cfg.getEnableKillEvent()){
			double reward = cfg.getRewardKillEvent();
			List<String> killCommands = cfg.getKillCommands();
			if (reward > 0) {
				VaultManager.addMoney(killer, reward);
				if (!Lang.EVENT_KILL_REWARD.isEmpty()) {
					killer.sendMessage(Lang.EVENT_KILL_REWARD.replace("%money%", "" + reward));
				}
			}
			// If the list is empty, this will never execute
			killCommands.forEach(cmd -> {
				try {
					Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd.replace("%name%", uhcKiller.getRealName()));
				} catch (CommandException exception){
					Bukkit.getLogger().warning("[UhcCore] Failed to execute kill reward command: " + cmd);
					exception.printStackTrace();
				}
			});
		}
	}

	// Store drops in case player gets re-spawned.
	uhcPlayer.getStoredItems().clear();
	uhcPlayer.getStoredItems().addAll(event.getDrops());

	// eliminations
	ScenarioManager sm = gm.getScenarioManager();
	if (!sm.isActivated(Scenario.SILENTNIGHT) || !((SilentNightListener) sm.getScenarioListener(Scenario.SILENTNIGHT)).isNightMode()) {
		gm.broadcastInfoMessage(Lang.PLAYERS_ELIMINATED.replace("%player%", player.getName()));
	}

	if(cfg.getRegenHeadDropOnPlayerDeath()){
		event.getDrops().add(UhcItems.createRegenHead(uhcPlayer));
	}

	if(cfg.getEnableGoldenHeads()){
		if (cfg.getPlaceHeadOnFence() && !gm.getScenarioManager().isActivated(Scenario.TIMEBOMB)){
			// place head on fence
			Location loc = player.getLocation().clone().add(1,0,0);
			loc.getBlock().setType(UniversalMaterial.OAK_FENCE.getType());
			loc.add(0, 1, 0);
			loc.getBlock().setType(UniversalMaterial.PLAYER_HEAD_BLOCK.getType());

			Skull skull = (Skull) loc.getBlock().getState();
			VersionUtils.getVersionUtils().setSkullOwner(skull, uhcPlayer);
			skull.setRotation(BlockFace.NORTH);
			skull.update();
		}else{
			event.getDrops().add(UhcItems.createGoldenHeadPlayerSkull(player.getName(), player.getUniqueId()));
		}
	}

	if(cfg.getEnableExpDropOnDeath()){
		UhcItems.spawnExtraXp(player.getLocation(), cfg.getExpDropOnDeath());
	}

	uhcPlayer.setState(PlayerState.DEAD);
	pm.strikeLightning(uhcPlayer);
	pm.playSoundPlayerDeath();

	// handle player leaving the server
	boolean canContinueToSpectate = player.hasPermission("uhc-core.spectate.override")
			|| cfg.getCanSpectateAfterDeath();

	if (!canContinueToSpectate) {
		if (cfg.getEnableBungeeSupport()) {
			Bukkit.getScheduler().runTaskAsynchronously(UhcCore.getPlugin(), new TimeBeforeSendBungeeThread(uhcPlayer, cfg.getTimeBeforeSendBungeeAfterDeath()));
		} else {
			player.kickPlayer(Lang.DISPLAY_MESSAGE_PREFIX + " " + Lang.KICK_DEAD);
		}
	}

	pm.checkIfRemainingPlayers();
}
 
Example #26
Source File: PlayersManager.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
public void killOfflineUhcPlayer(UhcPlayer uhcPlayer, @Nullable Location location, Set<ItemStack> playerDrops, @Nullable Player killer){
	GameManager gm = GameManager.getGameManager();
	PlayersManager pm = gm.getPlayersManager();
	MainConfiguration cfg = gm.getConfiguration();

	if (uhcPlayer.getState() != PlayerState.PLAYING){
		Bukkit.getLogger().warning("[UhcCore] " + uhcPlayer.getName() + " died while already in 'DEAD' mode!");
		return;
	}

	// kill event
	if(killer != null){
		UhcPlayer uhcKiller = pm.getUhcPlayer(killer);

		uhcKiller.kills++;

		// Call Bukkit event
		UhcPlayerKillEvent killEvent = new UhcPlayerKillEvent(uhcKiller, uhcPlayer);
		Bukkit.getServer().getPluginManager().callEvent(killEvent);

		if(cfg.getEnableKillEvent()){
			double reward = cfg.getRewardKillEvent();
			List<String> killCommands = cfg.getKillCommands();
			if (reward > 0) {
				VaultManager.addMoney(killer, reward);
				if (!Lang.EVENT_KILL_REWARD.isEmpty()) {
					killer.sendMessage(Lang.EVENT_KILL_REWARD.replace("%money%", "" + reward));
				}
			}

			killCommands.forEach(cmd -> {
				try {
					Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd.replace("%name%", killer.getName()));
				} catch (CommandException exception) {
					Bukkit.getLogger().warning("[UhcCore] Failed to execute kill reward command: " + cmd);
					exception.printStackTrace();
				}
			});

		}
	}

	// Store drops in case player gets re-spawned.
	uhcPlayer.getStoredItems().clear();
	uhcPlayer.getStoredItems().addAll(playerDrops);

	// eliminations
	ScenarioManager sm = gm.getScenarioManager();
	if (!sm.isActivated(Scenario.SILENTNIGHT) || !((SilentNightListener) sm.getScenarioListener(Scenario.SILENTNIGHT)).isNightMode()) {
		gm.broadcastInfoMessage(Lang.PLAYERS_ELIMINATED.replace("%player%", uhcPlayer.getName()));
	}

	if(cfg.getRegenHeadDropOnPlayerDeath()){
		playerDrops.add(UhcItems.createRegenHead(uhcPlayer));
	}

	if(location != null && cfg.getEnableGoldenHeads()){
		if (cfg.getPlaceHeadOnFence() && !gm.getScenarioManager().isActivated(Scenario.TIMEBOMB)){
			// place head on fence
			Location loc = location.clone().add(1,0,0);
			loc.getBlock().setType(UniversalMaterial.OAK_FENCE.getType());
			loc.add(0, 1, 0);
			loc.getBlock().setType(UniversalMaterial.PLAYER_HEAD_BLOCK.getType());

			Skull skull = (Skull) loc.getBlock().getState();
			VersionUtils.getVersionUtils().setSkullOwner(skull, uhcPlayer);
			skull.setRotation(BlockFace.NORTH);
			skull.update();
		}else{
			playerDrops.add(UhcItems.createGoldenHeadPlayerSkull(uhcPlayer.getName(), uhcPlayer.getUuid()));
		}
	}

	if(location != null && cfg.getEnableExpDropOnDeath()){
		UhcItems.spawnExtraXp(location, cfg.getExpDropOnDeath());
	}

	if (location != null){
		playerDrops.forEach(item -> location.getWorld().dropItem(location, item));
	}

	uhcPlayer.setState(PlayerState.DEAD);
	pm.strikeLightning(uhcPlayer);
	pm.playSoundPlayerDeath();

	pm.checkIfRemainingPlayers();
}
 
Example #27
Source File: VersionUtils_1_12.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setSkullOwner(Skull skull, UhcPlayer player) {
    skull.setOwningPlayer(Bukkit.getOfflinePlayer(player.getUuid()));
}
 
Example #28
Source File: VersionUtils_1_8.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setSkullOwner(Skull skull, UhcPlayer player) {
    skull.setOwner(player.getName());
}
 
Example #29
Source File: VersionUtils_1_13.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setSkullOwner(Skull skull, UhcPlayer player) {
    skull.setOwningPlayer(Bukkit.getOfflinePlayer(player.getUuid()));
}
 
Example #30
Source File: NMSHacks.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Test if a {@link Skull} has a cached skin. If this returns false, the skull will
 * likely try to fetch its skin the next time it is loaded.
 */
public static boolean isSkullCached(Skull skull) {
    TileEntitySkull nmsSkull = (TileEntitySkull) ((CraftWorld) skull.getWorld()).getTileEntityAt(skull.getX(), skull.getY(), skull.getZ());
    return nmsSkull.getGameProfile() == null ||
           nmsSkull.getGameProfile().getProperties().containsKey("textures");
}