Bukkit地图投票 [英] Bukkit Map Voting

查看:87
本文介绍了Bukkit地图投票的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助. 我用地图投票创建了迷你游戏插件,但我不知道该怎么做.

I need help. I creating mini game plugin with map voting and I don't know how to do that.

HashMap<World, Integer> votes = new HashMap<World, Integer>();

比方说,投票已关闭,服务器正在选择地图.哪一个? 当2张地图的最大数量相同时该怎么办.投票?

Let's say the votes are closed and the server is choosing map. Which one? What when 2 maps will have the same biggest num. of votes?

eNcoo,感谢您的帮助.

Thanks for help, eNcoo.

推荐答案

平局投票

再次投票,但将选择限制在得分相同的世界中.

Have another vote, but restrict choices to top worlds with equal high score.

随机领带破坏者

使用随机数生成器打破平局,如下所示:

Use a random number generator to break the tie, such as shown in the following:

Map<World, Integer> votes = new HashMap<>();

...

// Get list of entries and sort descending by value
List<Entry<World, Integer>> entries = new ArrayList<>( votes.entrySet() );
Collections.sort( entries, (e1,e2) -> -e1.getValue().compareTo( e2.getValue() ) );

// Collect top scoring worlds
List<World> topWorlds = new ArrayList<>();
int highScore = entries.get( 0 ).getValue();
for ( Entry<World,Integer> e : entries )
    if ( e.getValue() == highScore )
        topWorlds.add( e.getKey() );
    else
        break;

// Pick one at random
World pick = topWorlds.get( new Random().nextInt( topWorlds.size() ) );

最早或最新的投票

跟踪每个世界的最旧或最新投票的时间戳记也可以用来打破关系.例如,跟踪最早的投票将优先于(在一组关系中)第一世界的投票,而最新的投票将优先于最后的世界进行投票.我不确定这是否可行,仅作为练习来提及.

Tracking the timestamp of the oldest or newest vote for each world could also be used to break ties. For example, tracking the oldest vote gives preference to the first world vote on (in the set of ties), while the newest vote gives preference to the last world voted on. I am not sure if this is practical and mention it only as an exercise.

这篇关于Bukkit地图投票的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆