use of com.voxelgameslib.voxelgameslib.user.User in project VoxelGamesLibv2 by VoxelGamesLib.
the class ChatHandler method removeChannel.
/**
* Removes a channel
*
* @param id the id of the channel that should be removed
*/
public void removeChannel(@Nonnull String id) {
// remove any existing listeners from the channel, set them to the default channel.
// you should *really* handle this yourself if you're removing a channel
getChannel(id).ifPresent(chatChannel -> {
Iterator<User> itr = chatChannel.getListeners().iterator();
while (itr.hasNext()) {
User user = itr.next();
user.removeListeningChannel(id);
if (user.getActiveChannel().equals(chatChannel)) {
user.setActiveChannel("default");
}
}
});
activeChannels.remove(id);
}
use of com.voxelgameslib.voxelgameslib.user.User in project VoxelGamesLibv2 by VoxelGamesLib.
the class TeamSelectFeature method balance.
private void balance() {
// TODO Balancing by rating
Map<String, Integer> sizes = calcSizes();
String large = findLargest(sizes);
if (large == null || large.equals("")) {
log.finer("no balancing");
teams.stream().map(t -> t.getName() + ": " + t.getPlayers().size()).forEach(log::finer);
return;
}
int largeCount = sizes.get(large);
String small = findSmallest(sizes);
int smallCount = sizes.get(small);
log.finer("LARGE: " + large + " : " + largeCount);
log.finer("SMALL: " + small + " : " + smallCount);
if (!(largeCount == smallCount || largeCount == smallCount + 1)) {
Team largeT = getTeam(large).orElseThrow(() -> new RuntimeException("Null team encountered"));
Team smallT = getTeam(small).orElseThrow(() -> new RuntimeException("Null team encountered"));
boolean switched = false;
for (int i = largeT.getPlayers().size() - 1; i > 0; i--) {
User player = largeT.getPlayers().get(i);
// if(playerIsInParty) {TODO party handling for team select
log.finer("SWITCH: " + player + " from " + large + " to " + small);
largeT.leave(player);
smallT.join(player, player.getRating(getPhase().getGame().getGameMode()));
Lang.msg(player, LangKey.TEAM_AUTO_BALANCED, largeT.getName(), smallT.getName());
switched = true;
break;
// }
}
if (!switched) {
log.finer(largeT.getName());
log.finer(largeT.getPlayers().size() + "");
User player = largeT.getPlayers().get(largeT.getPlayers().size() - 1);
largeT.leave(player);
smallT.join(player, player.getRating(getPhase().getGame().getGameMode()));
Lang.msg(player, LangKey.TEAM_AUTO_BALANCED, largeT.getName(), smallT.getName());
}
balance();
}
}
use of com.voxelgameslib.voxelgameslib.user.User in project VoxelGamesLibv2 by VoxelGamesLib.
the class DuelFeature method enable.
@Override
public void enable() {
if (getPhase().getGame().getPlayers().size() != 2) {
getPhase().getGame().broadcastMessage(LangKey.DUEL_WRONG_PLAYER_COUNT, getPhase().getGame().getPlayers().size());
getPhase().getGame().abortGame();
return;
}
one = getPhase().getGame().getPlayers().get(0);
two = getPhase().getGame().getPlayers().get(1);
if (ThreadLocalRandom.current().nextBoolean()) {
User temp = one;
one = two;
two = temp;
}
}
use of com.voxelgameslib.voxelgameslib.user.User in project VoxelGamesLibv2 by VoxelGamesLib.
the class FeatureTest method getMockUser.
@Nonnull
public User getMockUser(@Nonnull String name) {
User user = Mockito.spy(new GamePlayer());
user.setDisplayName(name);
return user;
}
use of com.voxelgameslib.voxelgameslib.user.User in project VoxelGamesLibv2 by VoxelGamesLib.
the class EloHandler method update.
private void update(@Nonnull Game game, @Nonnull Map<IPlayer, Rating> newRatings) {
for (IPlayer iPlayer : newRatings.keySet()) {
if (!(iPlayer instanceof User)) {
log.warning("WTF");
continue;
}
User user = (User) iPlayer;
user.saveRating(game.getGameMode(), newRatings.get(iPlayer));
// TODO fixme
log.info("New Rating for " + user.getRawDisplayName() + " is " + newRatings.get(iPlayer).getMean() + "(" + newRatings.get(iPlayer).getStandardDeviation() + ")");
}
}
Aggregations