diff --git a/src/main/java/com/comandante/creeper/world/MapMatrix.java b/src/main/java/com/comandante/creeper/world/MapMatrix.java index 4b8ee70b9c7a80c13d2bd88a17baddd7f622d55b..2ff949178f884984f870139762abe029d86a1fba 100644 --- a/src/main/java/com/comandante/creeper/world/MapMatrix.java +++ b/src/main/java/com/comandante/creeper/world/MapMatrix.java @@ -261,7 +261,7 @@ public class MapMatrix { roomOpts.add(0); } } - return new MapMatrix(lists, Maps.<Integer, Set<RemoteExit>>newHashMap()); + return new MapMatrix(lists, Maps.newHashMap()); } public String renderMap(Integer roomId, RoomManager roomManager) { @@ -269,18 +269,14 @@ public class MapMatrix { Iterator<List<Integer>> rows = getRows(); while (rows.hasNext()) { List<Integer> next = rows.next(); - Iterator<String> transform = Iterators.transform(next.iterator(), MapsManager.render(roomId, roomManager)); - while (transform.hasNext()) { - String s = transform.next(); - sb.append(s); - } + next.stream().map(MapsManager.render(roomId, roomManager)).forEach(sb::append); sb.append("\r\n"); } return sb.toString(); } public void addRow(boolean startOfArray) { - ArrayList<Integer> newRow = Lists.<Integer>newArrayList(); + ArrayList<Integer> newRow = Lists.newArrayList(); for (int i = 0; i < matrix.get(0).size(); i++) { newRow.add(0); } diff --git a/src/main/java/com/comandante/creeper/world/MapsManager.java b/src/main/java/com/comandante/creeper/world/MapsManager.java index 74adcf72c8d82cffe543210dcd737a1254bd6776..ea2c8e10bfb32cc249b35d3ccffa51e84578ab12 100644 --- a/src/main/java/com/comandante/creeper/world/MapsManager.java +++ b/src/main/java/com/comandante/creeper/world/MapsManager.java @@ -5,15 +5,15 @@ import com.comandante.creeper.CreeperConfiguration; import com.comandante.creeper.Main; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.server.Color; -import com.google.common.base.Function; -import com.google.common.base.Optional; import com.google.common.collect.Maps; import org.apache.log4j.Logger; import java.util.Iterator; import java.util.Map; +import java.util.Optional; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.function.Function; import static com.codahale.metrics.MetricRegistry.name; @@ -57,29 +57,26 @@ public class MapsManager { } public static Function<Integer, String> render(final Integer currentroomId, final RoomManager roomManager) { - return new Function<Integer, String>() { - @Override - public String apply(Integer roomId) { - Room room = roomManager.getRoom(roomId); - if (roomId > 0) { - if (roomId.equals(currentroomId)) { - return "[" + Color.BOLD_ON + Color.RED + "*" + Color.RESET + "]"; - } else if (roomId.equals(1)) { - return "[" + Color.BOLD_ON + Color.BLUE + "L" + Color.RESET + "]"; - } else if (room.getMerchants().size() > 0) { - return "[" + Color.YELLOW + "m" + Color.RESET + "]"; - } else if (room.getEnterExits().size() > 0) { - return "[" + Color.CYAN + "e" + Color.RESET + "]"; - } else if (room.getUpId().isPresent()) { - return "[" + Color.GREEN + "^" + Color.RESET + "]"; - } else if (room.getDownId().isPresent()) { - return "[" + Color.GREEN + "v" + Color.RESET + "]"; - } else { - return "[ ]"; - } + return roomId -> { + Room room = roomManager.getRoom(roomId); + if (roomId > 0) { + if (roomId.equals(currentroomId)) { + return "[" + Color.BOLD_ON + Color.RED + "*" + Color.RESET + "]"; + } else if (roomId.equals(1)) { + return "[" + Color.BOLD_ON + Color.BLUE + "L" + Color.RESET + "]"; + } else if (room.getMerchants().size() > 0) { + return "[" + Color.YELLOW + "m" + Color.RESET + "]"; + } else if (room.getEnterExits().size() > 0) { + return "[" + Color.CYAN + "e" + Color.RESET + "]"; + } else if (room.getUpId().isPresent()) { + return "[" + Color.GREEN + "^" + Color.RESET + "]"; + } else if (room.getDownId().isPresent()) { + return "[" + Color.GREEN + "v" + Color.RESET + "]"; } else { - return " "; + return "[ ]"; } + } else { + return " "; } }; } diff --git a/src/main/java/com/comandante/creeper/world/Room.java b/src/main/java/com/comandante/creeper/world/Room.java index ad8b25af7ab6d295d48e2286f38eb31d9c97471f..1002180a310f62611c01fc456f705e5d48e50df6 100644 --- a/src/main/java/com/comandante/creeper/world/Room.java +++ b/src/main/java/com/comandante/creeper/world/Room.java @@ -7,13 +7,13 @@ import com.comandante.creeper.entity.CreeperEntity; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.merchant.Merchant; import com.comandante.creeper.spawner.ItemSpawner; -import com.google.common.base.Optional; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; public abstract class Room extends CreeperEntity { @@ -30,12 +30,12 @@ public abstract class Room extends CreeperEntity { private String roomTitle; private final Integer floorId; - private java.util.Optional<Integer> northId; - private java.util.Optional<Integer> westId; - private java.util.Optional<Integer> eastId; - private java.util.Optional<Integer> southId; - private java.util.Optional<Integer> downId; - private java.util.Optional<Integer> upId; + private Optional<Integer> northId; + private Optional<Integer> westId; + private Optional<Integer> eastId; + private Optional<Integer> southId; + private Optional<Integer> downId; + private Optional<Integer> upId; private List<RemoteExit> enterExits = Lists.newArrayList(); private String roomDescription; private final Set<String> presentPlayerIds = Sets.<String>newConcurrentHashSet(); @@ -43,7 +43,7 @@ public abstract class Room extends CreeperEntity { private final Set<String> itemIds = Sets.newConcurrentHashSet(); private List<ItemSpawner> itemSpawners = Lists.newArrayList(); private Set<Area> areas = Sets.newConcurrentHashSet(); - private Optional<String> mapData = Optional.absent(); + private Optional<String> mapData = Optional.empty(); private final Set<String> roomTags; private final Set<Merchant> merchants = Sets.newConcurrentHashSet(); private Map<ItemType, Forage> forages = Maps.newHashMap(); @@ -53,12 +53,12 @@ public abstract class Room extends CreeperEntity { public Room(Integer roomId, String roomTitle, Integer floorId, - java.util.Optional<Integer> northId, - java.util.Optional<Integer> southId, - java.util.Optional<Integer> eastId, - java.util.Optional<Integer> westId, - java.util.Optional<Integer> upId, - java.util.Optional<Integer> downId, + Optional<Integer> northId, + Optional<Integer> southId, + Optional<Integer> eastId, + Optional<Integer> westId, + Optional<Integer> upId, + Optional<Integer> downId, List<RemoteExit> enterExits, String roomDescription, Set<String> roomTags, Set<Area> areas, @@ -101,27 +101,27 @@ public abstract class Room extends CreeperEntity { return roomTags; } - public void setNorthId(java.util.Optional<Integer> northId) { + public void setNorthId(Optional<Integer> northId) { this.northId = northId; } - public void setWestId(java.util.Optional<Integer> westId) { + public void setWestId(Optional<Integer> westId) { this.westId = westId; } - public void setEastId(java.util.Optional<Integer> eastId) { + public void setEastId(Optional<Integer> eastId) { this.eastId = eastId; } - public void setSouthId(java.util.Optional<Integer> southId) { + public void setSouthId(Optional<Integer> southId) { this.southId = southId; } - public void setDownId(java.util.Optional<Integer> downId) { + public void setDownId(Optional<Integer> downId) { this.downId = downId; } - public void setUpId(java.util.Optional<Integer> upId) { + public void setUpId(Optional<Integer> upId) { this.upId = upId; } @@ -199,27 +199,27 @@ public abstract class Room extends CreeperEntity { return roomId; } - public java.util.Optional<Integer> getNorthId() { + public Optional<Integer> getNorthId() { return northId; } - public java.util.Optional<Integer> getWestId() { + public Optional<Integer> getWestId() { return westId; } - public java.util.Optional<Integer> getEastId() { + public Optional<Integer> getEastId() { return eastId; } - public java.util.Optional<Integer> getSouthId() { + public Optional<Integer> getSouthId() { return southId; } - public java.util.Optional<Integer> getUpId() { + public Optional<Integer> getUpId() { return upId; } - public java.util.Optional<Integer> getDownId() { + public Optional<Integer> getDownId() { return downId; }