Skip to content

Commit

Permalink
Added retrolambda - allows making the code a fair bit neater until we…
Browse files Browse the repository at this point in the history
… can use Java 8
  • Loading branch information
me4502 committed Jul 28, 2015
1 parent 68263d3 commit 09a605b
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 57 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ buildscript {
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.2'
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1'
classpath 'org.ajoberstar:gradle-git:0.12.0'
classpath 'me.tatarka:gradle-retrolambda:3.2.0'
}
}

Expand All @@ -51,13 +52,14 @@ apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'com.jfrog.artifactory-upload'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'me.tatarka.retrolambda'

group = 'com.sk89q.craftbook'
version = '4.0-SNAPSHOT'
ext.internalVersion = version + ";" + gitCommitHash

sourceCompatibility = 1.6
targetCompatibility = 1.6
sourceCompatibility = 1.8
targetCompatibility = 1.8

//checkstyle.configFile = new File(rootProject.projectDir, "config/checkstyle/checkstyle.xml")

Expand Down
16 changes: 6 additions & 10 deletions src/main/java/com/sk89q/craftbook/sponge/CraftBookPlugin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.sk89q.craftbook.sponge;

import com.google.common.base.Predicate;
import com.google.inject.Inject;
import com.me4502.modularframework.ModuleController;
import com.me4502.modularframework.ShadedModularFramework;
Expand Down Expand Up @@ -81,16 +80,13 @@ public void onInitialization(ServerStartedEvent event) throws IllegalAccessExcep
cache = new SpongeDataCache();
blockBagManager = new BlockBagManager();

moduleController.enableModules(new Predicate<ModuleWrapper>() {
@Override
public boolean apply(ModuleWrapper input) {
if (config.enabledMechanics.contains(input.getName()) || "true".equalsIgnoreCase(System.getProperty("craftbook.enable-all"))) {
logger.info("Enabled: " + input.getName());
return true;
}

return false;
moduleController.enableModules(input -> {
if (config.enabledMechanics.contains(input.getName()) || "true".equalsIgnoreCase(System.getProperty("craftbook.enable-all"))) {
logger.info("Enabled: " + input.getName());
return true;
}

return false;
});

for (ModuleWrapper module : CraftBookPlugin.<CraftBookPlugin>inst().moduleController.getModules()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.sk89q.craftbook.sponge;

import com.google.common.base.Function;
import com.me4502.modularframework.module.ModuleWrapper;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
Expand Down Expand Up @@ -40,7 +39,7 @@ public void load() {

enabledMechanics = getValue(config.getNode("enabled-mechanics"), Arrays.asList("Elevator"), "The list of mechanics to load.");

List<String> disabledMechanics = new ArrayList<String>();
List<String> disabledMechanics = new ArrayList<>();

for(ModuleWrapper entry : plugin.moduleController.getModules()) {
if(!enabledMechanics.contains(entry.getName())) {
Expand All @@ -66,15 +65,11 @@ public static <T> T getValue(ConfigurationNode node, T defaultValue, String comm
((CommentedConfigurationNode)node).setComment(comment);
}

return node.getValue(new Function<Object, T>() {
@SuppressWarnings("unchecked")
@Override
public T apply(Object input) {
return node.getValue(input -> {

//Add converters into here where necessary.
//Add converters into here where necessary.

return (T)input;
}
return (T)input;
}, defaultValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void transportEntity(Entity entity, Location block, Direction direction)
// entity.setLocation(new Location(floor.getExtent(), new Vector3d(entity.getLocation().getPosition().getX(),
// floor.getLocation().getPosition().getY()+1, entity.getLocation().getPosition().getZ())));

entity.setLocationAndRotation(new Location(destination.getExtent(), new Vector3d(0, destination.getY() - 1, 0)), new Vector3d(0, 0, 0), EnumSet.<RelativePositions> of(RelativePositions.X, RelativePositions.Z, RelativePositions.PITCH, RelativePositions.YAW));
entity.setLocationAndRotation(new Location(destination.getExtent(), new Vector3d(0, destination.getY() - 1, 0)), new Vector3d(0, 0, 0), EnumSet.of(RelativePositions.X, RelativePositions.Z, RelativePositions.PITCH, RelativePositions.YAW));
if (entity instanceof CommandSource) ((CommandSource) entity).sendMessage(Texts.of("You've gone " + (direction == Direction.DOWN ? "down" : "up") + " a floor!"));
}

Expand Down
11 changes: 4 additions & 7 deletions src/main/java/com/sk89q/craftbook/sponge/mechanics/Snow.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,10 @@ public void disperseSnow(final Location location, Direction ignoredFace) {
increaseSnow(relative, false);
if(dir != Direction.NONE) {
decreaseSnow(location);
CraftBookPlugin.game.getScheduler().getTaskBuilder().delay(40L).execute(new Runnable() {
@Override
public void run() {
disperseSnow(relative, dir.getOpposite());
if(isBlockBuried(location))
disperseSnow(location.getRelative(Direction.UP), Direction.NONE);
}
CraftBookPlugin.game.getScheduler().getTaskBuilder().delay(40L).execute(() -> {
disperseSnow(relative, dir.getOpposite());
if(isBlockBuried(location))
disperseSnow(location.getRelative(Direction.UP), Direction.NONE);
}).submit(CraftBookPlugin.inst());
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TreeLopper extends SpongeMechanic {
public void onBlockBreak(PlayerBreakBlockEvent event) {

if(event.getBlock().getBlockType() == BlockTypes.LOG || event.getBlock().getBlockType() == BlockTypes.LOG2) {
checkBlocks(event.getBlock(), event.getEntity(), event.getBlock().getData(TreeData.class).get().getValue(), new ArrayList<Location>());
checkBlocks(event.getBlock(), event.getEntity(), event.getBlock().getData(TreeData.class).get().getValue(), new ArrayList<>());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public boolean triggerMechanic(Location block, Sign sign, Human human, Boolean f

if (SignUtil.getTextRaw(sign.getData().get(), 1).equals("[Gate]")) {

Set<GateColumn> columns = new HashSet<GateColumn>();
Set<GateColumn> columns = new HashSet<>();

findColumns(block, columns);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@

public class ICManager {

public static Set<ICType<? extends IC>> registeredICTypes = new HashSet<ICType<? extends IC>>();
public static Set<ICType<? extends IC>> registeredICTypes = new HashSet<>();

static {

registerICType(new ICType<Repeater>("MC1000", "REPEATER", Repeater.class));
registerICType(new ICType<Inverter>("MC1001", "INVERTER", Inverter.class));
registerICType(new ICType<>("MC1000", "REPEATER", Repeater.class));
registerICType(new ICType<>("MC1001", "INVERTER", Inverter.class));

registerICType(new ICType<Clock>("MC1421", "CLOCK", Clock.class));
registerICType(new ICType<>("MC1421", "CLOCK", Clock.class));

registerICType(new ICType<AndGate>("MC3002", "AND", AndGate.class, "3ISO"));
registerICType(new ICType<>("MC3002", "AND", AndGate.class, "3ISO"));
}

public static void registerICType(ICType<? extends IC> ic) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@Module(moduleName = "ICSocket", onEnable="onInitialize", onDisable="onDisable")
public class ICSocket extends SpongeBlockMechanic implements SelfTriggeringMechanic {

public static final HashMap<String, PinSet> PINSETS = new HashMap<String, PinSet>();
public static final HashMap<String, PinSet> PINSETS = new HashMap<>();

static {
PINSETS.put("SISO", new PinsSISO());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.sk89q.craftbook.sponge.mechanics.ics.IC;
import com.sk89q.craftbook.sponge.util.SignUtil;
import org.spongepowered.api.util.Direction;
import org.spongepowered.api.world.Location;

public class Pins3ISO extends PinSet {
Expand Down
31 changes: 14 additions & 17 deletions src/main/java/com/sk89q/craftbook/sponge/st/SelfTriggerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,21 @@ public void onChunkLoad(final ChunkLoadEvent event) {

// TODO change this if the world explodes.

event.getGame().getScheduler().getTaskBuilder().execute(new Runnable() {
@Override
public void run() {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
for (int y = 0; y < event.getChunk().getWorld().getBlockMax().getY(); y++) {
Location block = event.getChunk().getLocation(x, y, z).add(event.getChunk().getBlockMin().toDouble());
for (ModuleWrapper module : CraftBookPlugin.<CraftBookPlugin>inst().moduleController.getModules()) {
if(!module.isEnabled()) continue;
try {
SpongeMechanic mechanic = (SpongeMechanic) module.getModule();
if (mechanic instanceof SpongeBlockMechanic && mechanic instanceof SelfTriggeringMechanic) {
if (((SpongeBlockMechanic) mechanic).isValid(block))
register((SelfTriggeringMechanic) mechanic, block);
}
} catch (ModuleNotInstantiatedException e) {
e.printStackTrace();
event.getGame().getScheduler().getTaskBuilder().execute(() -> {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
for (int y = 0; y < event.getChunk().getWorld().getBlockMax().getY(); y++) {
Location block = event.getChunk().getLocation(x, y, z).add(event.getChunk().getBlockMin().toDouble());
for (ModuleWrapper module : CraftBookPlugin.<CraftBookPlugin>inst().moduleController.getModules()) {
if(!module.isEnabled()) continue;
try {
SpongeMechanic mechanic = (SpongeMechanic) module.getModule();
if (mechanic instanceof SpongeBlockMechanic && mechanic instanceof SelfTriggeringMechanic) {
if (((SpongeBlockMechanic) mechanic).isValid(block))
register((SelfTriggeringMechanic) mechanic, block);
}
} catch (ModuleNotInstantiatedException e) {
e.printStackTrace();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ protected <T extends MechanicData> T loadFromDisk(Class<T> clazz, String locatio
data = jsonConverter.deserialize(reader, clazz);

reader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 09a605b

Please sign in to comment.