use of com.voxelgameslib.voxelgameslib.map.MapInfo in project VoxelGamesLibv2 by VoxelGamesLib.
the class VoteFeature method sendVoteMessage.
/**
* Sends the vote message to that user
*
* @param user the user that should receive the message
*/
public void sendVoteMessage(@Nonnull User user) {
Lang.msg(user, LangKey.VOTE_MESSAGE_TOP);
for (int id : availableMaps.keySet()) {
MapInfo info = availableMaps.get(id);
Lang.msg(user, LangKey.VOTE_MESSAGE_MAP, "/vote " + id, id, info.getName(), info.getAuthor());
}
Lang.msg(user, LangKey.VOTE_MESSAGE_BOT);
}
use of com.voxelgameslib.voxelgameslib.map.MapInfo in project VoxelGamesLibv2 by VoxelGamesLib.
the class VoteFeature method confirmVote.
/**
* Confirms a vote for a map
*/
private void confirmVote(@Nonnull User voter, @Nonnull Integer mapId) {
if (votes.containsKey(voter.getUuid())) {
Lang.msg(voter, LangKey.VOTE_ALREADY_VOTED);
} else {
MapInfo mapInfo = availableMaps.get(mapId);
if (mapInfo == null) {
Lang.msg(voter, LangKey.VOTE_UNKNOWN_MAP, mapId);
return;
}
votes.put(voter.getUuid(), mapId);
Lang.msg(voter, LangKey.VOTE_SUBMITTED, mapInfo.getName(), mapId);
}
}
use of com.voxelgameslib.voxelgameslib.map.MapInfo in project VoxelGamesLibv2 by VoxelGamesLib.
the class VoteFeature method enable.
@Override
public void enable() {
String mode = getPhase().getGame().getGameMode().getName();
int id = 1;
for (MapInfo info : config.maps) {
if (info.getGamemodes().contains(mode)) {
availableMaps.put(id++, info);
}
if (id == maxMaps - 1) {
break;
}
}
if (availableMaps.size() == 0) {
getPhase().getGame().broadcastMessage(LangKey.VOTE_NO_MAPS_FOUND);
getPhase().getGame().abortGame();
log.warning("Game " + getPhase().getGame().getUuid() + "(" + getPhase().getGame().getGameMode().getName() + ")" + " was aborted because it didn't find any maps to play!");
return;
}
getPhase().getGame().getPlayers().forEach(this::sendVoteMessage);
if (enableVoteMenu) {
getPhase().getGame().getPlayers().forEach(this::giveVoteMenuItem);
}
}
use of com.voxelgameslib.voxelgameslib.map.MapInfo in project VoxelGamesLibv2 by VoxelGamesLib.
the class VoteFeature method disable.
@Override
public void disable() {
Map<Integer, Integer> votes = new HashMap<>();
int max = -1;
int maxMap = -1;
for (Integer map : this.votes.values()) {
int old = votes.getOrDefault(map, 0);
old++;
if (old > max) {
max = old;
maxMap = map;
}
votes.put(map, old);
}
MapInfo winner = availableMaps.get(maxMap);
if (winner == null) {
// use first map if nobody won
winner = availableMaps.values().iterator().next();
}
DefaultGameData gameData = getPhase().getGame().getGameData(DefaultGameData.class).orElse(new DefaultGameData());
gameData.voteWinner = winner;
getPhase().getGame().putGameData(gameData);
getPhase().getGame().broadcastMessage(LangKey.VOTE_END, winner.getName(), winner.getAuthor(), Math.max(max, 0));
}
use of com.voxelgameslib.voxelgameslib.map.MapInfo in project VoxelGamesLibv2 by VoxelGamesLib.
the class WorldHandler method loadMap.
/**
* Tries to load the map data for a name
*
* @param name the name of the map to load
* @return the loaded map
* @throws MapException when
*/
@Nonnull
public Map loadMap(@Nonnull String name) {
Optional<Map> map = getMap(name);
if (!map.isPresent()) {
Optional<MapInfo> mapInfo = getMapInfo(name);
if (!mapInfo.isPresent()) {
throw new MapException("Unknown map " + name + ". Did you register it into the world config?");
}
try {
ZipFile zipFile = new ZipFile(new File(worldsFolder, mapInfo.get().getName() + ".zip"));
for (FileHeader header : (List<FileHeader>) zipFile.getFileHeaders()) {
if (header.getFileName().endsWith("config.json")) {
InputStream stream = zipFile.getInputStream(header);
Map m = gson.fromJson(new JsonReader(new InputStreamReader(stream)), Map.class);
m.initMarkers(mapHandler);
maps.add(m);
return m;
}
}
throw new MapException("Could not load map config for map " + name + ". Fileheader was null. Does it has a map.json?");
} catch (Exception e) {
throw new MapException("Error while trying to load map config " + name, e);
}
} else {
return map.get();
}
}
Aggregations