use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class PlayerStateServiceImpl method createNewPlayerState.
private SavedPlayerState createNewPlayerState(Player player) {
SavedPlayerState playerState = new SavedPlayerState();
player.getInventory().slots().forEach(slot -> {
try {
ItemStack stackInSlot = slot.peek().orElse(newItemStack(ItemTypes.NONE));
JsonElement serializedStack = serializeItemStack(stackInSlot);
playerState.getInventoryContents().add(serializedStack);
} catch (IOException e) {
e.printStackTrace();
}
});
return playerState;
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class SkyWarsInstance method smartStart.
private void smartStart() {
HashMap<Player, Color> colorMapping = new HashMap<>();
for (Player player : getPlayers(PlayerClassifier.PARTICIPANT)) {
Optional<ItemStack> optHelmet = player.getHelmet();
if (!optHelmet.isPresent()) {
return;
}
ItemStack helmet = optHelmet.get();
Optional<Color> optColor = helmet.get(Keys.COLOR);
if (!optColor.isPresent()) {
return;
}
colorMapping.put(player, optColor.get());
}
// Reset the team mapping as it may have been corrupted by a bad run
teams = createTeamsMapping();
for (Map.Entry<Player, Color> entry : colorMapping.entrySet()) {
Color color = entry.getValue();
Set<Player> team = teams.get(color);
if (team == null) {
return;
}
Player player = entry.getKey();
// Update team mapping
team.add(player);
SkyWarsPlayerData playerData = playerDataMapping.get(player);
playerData.setTeam(team);
// Give player team equipment
giveTeamEquipment(player, color);
// Throw player
launchPlayer(player, 1);
playerData.stopPushBack();
}
if (getWinner().isPresent()) {
return;
}
getPlayerMessageChannel(PlayerClassifier.SPECTATOR).send(Text.of(TextColors.RED, "Fight!"));
state = SkyWarsState.IN_PROGRESS;
showStartingPlatform(false);
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class RespawnQueueServiceImpl method onRespawn.
@Listener
public void onRespawn(RespawnPlayerEvent event) {
EntityPlayer player = tf(event.getTargetEntity());
net.minecraft.item.ItemStack[] mainInv = player.inventory.mainInventory;
Task.builder().delayTicks(1).execute(() -> {
Deque<ItemStack> queue = playerQueue.remove(player.getUniqueID());
if (queue != null) {
for (int i = 0; !queue.isEmpty() && i < mainInv.length; ++i) {
if (mainInv[i] == null) {
mainInv[i] = tf(queue.poll());
}
}
if (!queue.isEmpty()) {
enque(tf(player), queue);
}
}
}).submit(SkreePlugin.inst());
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class SkyWarsInstance method awardPowerup.
public void awardPowerup(Player player, ItemStack held) {
ItemStack powerup;
Optional<String> optSuffix = SkyFeather.getSuffix(held);
if (optSuffix.isPresent() && optSuffix.get().equals("Doom"))
return;
int uses = 5;
double radius = 3;
double flight = 2;
double pushBack = 4;
if (Probability.getChance(2)) {
radius = 5;
pushBack = 6;
} else {
flight = 6;
}
if (Probability.getChance(50)) {
uses = -1;
radius = 7;
flight = 6;
pushBack = 6;
MutableMessageChannel targets = getPlayerMessageChannel(PlayerClassifier.SPECTATOR).asMutable();
targets.removeMember(player);
targets.send(Text.of(TextColors.RED, player.getName(), " has been given a Doom feather!"));
player.getInventory().clear();
}
powerup = newItemStack(CustomItemTypes.SKY_FEATHER);
SkyFeather.setFeatherProperties(powerup, uses, radius, flight, pushBack);
player.getInventory().offer(powerup);
tf(player).inventoryContainer.detectAndSendChanges();
// Display name doesn't need checked as all power ups have one assigned
player.sendMessage(Text.of(TextColors.YELLOW, "You obtain a power-up!"));
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class ItemStackFactory method newItemStack.
public static ItemStack newItemStack(ItemStack itemStack, int quantity) {
ItemStack stack = itemStack.copy();
stack.setQuantity(quantity);
return stack;
}
Aggregations