use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class GoldRushInstance method checkFloodType.
private void checkFloodType() {
if (foundPhantomHymn) {
return;
}
for (Player player : getPlayers(PlayerClassifier.PARTICIPANT)) {
net.minecraft.item.ItemStack[] itemStacks = tf(player).inventory.mainInventory;
for (net.minecraft.item.ItemStack is : itemStacks) {
if (is == null || is.getItem() != CustomItemTypes.PRIZE_BOX) {
continue;
}
Optional<ItemStack> optContained = PrizeBox.getPrizeStack(is);
if (optContained.isPresent() && optContained.get().getItem() == CustomItemTypes.PHANTOM_HYMN) {
// Force away all water
drainAll();
floodBlockType = BlockTypes.FLOWING_LAVA;
multiplier = multiplier.multiply(new BigDecimal(1.35));
foundPhantomHymn = true;
break;
}
}
/*for (Inventory slot : player.getInventory().query((ItemType) CustomItemTypes.PRIZE_BOX)) {
Optional<ItemStack> optStack = slot.peek();
if (optStack.isPresent()) {
Optional<ItemStack> optContained = PrizeBox.getPrizeStack(optStack.get());
if (optContained.isPresent() && optContained.get().getItem() == CustomItemTypes.PHANTOM_HYMN) {
drainAll(); // Force away all water
floodBlockType = BlockTypes.FLOWING_LAVA;
break;
}
}
}*/
}
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class JungleRaidEffectListener method onPlayerInteract.
@Listener
public void onPlayerInteract(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
Optional<JungleRaidInstance> optInst = manager.getApplicableZone(player);
if (!optInst.isPresent()) {
return;
}
JungleRaidInstance inst = optInst.get();
Optional<ItemStack> optStack = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optStack.isPresent()) {
return;
}
ItemStack stack = optStack.get();
if (stack.getItem() == ItemTypes.COMPASS) {
event.setUseBlockResult(Tristate.FALSE);
if (inst.getState() == JungleRaidState.IN_PROGRESS && inst.isFlagEnabled(JungleRaidFlag.ENHANCED_COMPASS)) {
Set<Text> resultSet = new HashSet<>();
for (Player aPlayer : inst.getPlayers(PlayerClassifier.PARTICIPANT)) {
// Check validity
if (player.equals(aPlayer))
continue;
// Check team
if (inst.isFriendlyFire(player, aPlayer))
continue;
TextColor color = tf(player).canEntityBeSeen(tf(aPlayer)) ? TextColors.DARK_RED : TextColors.RED;
resultSet.add(Text.of(color, aPlayer.getName(), " - ", player.getLocation().getPosition().distance(aPlayer.getLocation().getPosition())));
}
if (resultSet.isEmpty()) {
player.sendMessage(Text.of(TextColors.RED, "No players found."));
}
player.sendMessage(Text.of(TextColors.YELLOW, "Player - Distance"));
player.sendMessages(resultSet);
} else if (inst.getState() == JungleRaidState.INITIALIZE) {
player.setLocation(inst.getRandomLocation());
}
}
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class PlayerStateServiceImpl method load.
@Override
public void load(Player player, String saveName) {
Iterator<Inventory> slots = player.getInventory().slots().iterator();
List<JsonElement> persistedInventoryContents = getInventoryContents(player, saveName);
for (int i = 0; slots.hasNext(); ++i) {
Inventory slot = slots.next();
if (i < persistedInventoryContents.size()) {
try {
ItemStack stack = deserializeItemStack(persistedInventoryContents.get(i));
slot.set(stack);
continue;
} catch (IOException e) {
e.printStackTrace();
}
}
slot.set(newItemStack(ItemTypes.NONE));
}
}
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);
}
Aggregations