<commit_before>package com.cardshifter.modapi.players;

import com.cardshifter.modapi.base.ComponentRetriever;
import com.cardshifter.modapi.base.Entity;
import com.cardshifter.modapi.base.PlayerComponent;
import com.cardshifter.modapi.base.Retrievers;
import com.cardshifter.modapi.cards.CardComponent;

public class Players {
	private static final ComponentRetriever<CardComponent> card = Retrievers.component(CardComponent.class);
	private static final ComponentRetriever<PlayerComponent> player = Retrievers.component(PlayerComponent.class);
	
	public static Entity findOwnerFor(Entity entity) {
		if (player.has(entity)) {
			return entity;
		}
		if (card.has(entity)) {
			return card.get(entity).getOwner();
		}
		return null;
	}

}<commit_msg>added getNextPlayer method<commit_after>package com.cardshifter.modapi.players;

import com.cardshifter.modapi.base.ComponentRetriever;
import com.cardshifter.modapi.base.Entity;
import com.cardshifter.modapi.base.PlayerComponent;
import com.cardshifter.modapi.base.Retrievers;
import com.cardshifter.modapi.cards.CardComponent;

import java.util.*;

public class Players {
	private static final ComponentRetriever<CardComponent> card = Retrievers.component(CardComponent.class);
	private static final ComponentRetriever<PlayerComponent> player = Retrievers.component(PlayerComponent.class);
	
	public static Entity findOwnerFor(Entity entity) {
		if (player.has(entity)) {
			return entity;
		}
		if (card.has(entity)) {
			return card.get(entity).getOwner();
		}
		return null;
	}

    public static Entity getNextPlayer(Entity entity) {
        List<Entity> players = new ArrayList<>(entity.getGame().getEntitiesWithComponent(PlayerComponent.class));
        players.sort(Comparator.comparingInt(pl -> player.get(pl).getIndex()));
        int myIndex = player.get(findOwnerFor(entity)).getIndex();
        Optional<Entity> result = players.stream().filter(pl -> player.get(pl).getIndex() == myIndex + 1).findFirst();
        return result.orElse(players.stream().filter(pl -> player.get(pl).getIndex() == 0).findFirst().get());
    }
}
{'fraction_non_alphanumeric': 0.12063188128291048, 'fraction_numerical': 0.0009573958831977022, 'mean_word_length': 5.35258358662614, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5014656', 'n_tokens_mistral': 663, 'n_tokens_neox': 627, 'n_words': 112}