Skip to content

Commit

Permalink
Implement ability to define mixed generator types in each tier.
Browse files Browse the repository at this point in the history
The naming is self explanatory and I do not think it requires clarification.
  • Loading branch information
BONNe committed Sep 21, 2020
1 parent b162aa9 commit 223f142
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,37 @@ public void setActivationCost(double activationCost)
*/
public enum GeneratorType
{
COBBLESTONE,
STONE,
BASALT
COBBLESTONE(1),
STONE(2),
BASALT(4),
COBBLESTONE_OR_STONE(3),
BASALT_OR_COBBLESTONE(5),
BASALT_OR_STONE(6),
ANY(7);

GeneratorType(int id)
{
this.id = id;
}


/**
* This method returns if given generator type is included by current generator.
* @param type Generator type that must be checked. Most likely it is just basic
* basalt, cobblestone or stone.
* @return {@code true} if current generator is compatible with given generator
* type, {@code false} otherwise.
*/
public boolean includes(GeneratorType type)
{
return (this.id & type.id) != 0;
}


/**
* ID of the generator.
*/
private final int id;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private void createGenerators(YamlConfiguration config, @Nullable User user, Gam
details.getString("type", "COBBLESTONE").toUpperCase()));

if (!canAddBasaltGenerator &&
generatorTier.getGeneratorType().equals(GeneratorTierObject.GeneratorType.BASALT))
generatorTier.getGeneratorType().includes(GeneratorTierObject.GeneratorType.BASALT))
{
// Basalt generators cannot be added yet in 1.15.2
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public GeneratorTierObject getGeneratorByID(String generatorId)
// Filter out generators that are not deployed.
filter(GeneratorTierObject::isDeployed).
// Filter objects with the same generator type.
filter(generator -> generator.getGeneratorType().equals(generatorType)).
filter(generator -> generator.getGeneratorType().includes(generatorType)).
// Filter out objects with incorrect biomes.
filter(generator -> generator.getRequiredBiomes().isEmpty() ||
generator.getRequiredBiomes().contains(biome)).
Expand All @@ -305,11 +305,21 @@ else if (o1.getPriority() != o2.getPriority())
// Larger priority must be in the end.
return Integer.compare(o1.getPriority(), o2.getPriority());
}
else
else if (o1.isDefaultGenerator() || o2.isDefaultGenerator())
{
// Default should be placed last one.
return Boolean.compare(o2.isDefaultGenerator(), o1.isDefaultGenerator());
}
else if (o1.getGeneratorType() != o2.getGeneratorType())
{
// Compare by type. Generators which are more specified should be first.
return o1.getGeneratorType().compareTo(o2.getGeneratorType());
}
else
{
// Compare by unique id.
return o1.getUniqueId().compareTo(o2.getUniqueId());
}
});

return optionalGenerator.orElse(null);
Expand Down Expand Up @@ -342,7 +352,7 @@ GeneratorTierObject findDefaultGeneratorTier(World world,
// Filter all default generators
filter(GeneratorTierObject::isDefaultGenerator).
// Filter generators with necessary type.
filter(generator -> generator.getGeneratorType().equals(generatorType)).
filter(generator -> generator.getGeneratorType().includes(generatorType)).
// Filter generators that starts with name.
filter(generator -> generator.getUniqueId().startsWith(gameMode.toLowerCase())).
// Return first or null.
Expand Down Expand Up @@ -392,7 +402,7 @@ public List<GeneratorTierObject> getAllGeneratorTiers(World world)
public List<GeneratorTierObject> findDefaultGeneratorList(World world)
{
String gameMode = this.addon.getPlugin().getIWM().getAddon(world).map(
gameModeAddon -> gameModeAddon.getDescription().getName()).orElse("");
gameModeAddon -> gameModeAddon.getDescription().getName()).orElse("");

if (gameMode.isEmpty())
{
Expand All @@ -402,13 +412,13 @@ public List<GeneratorTierObject> findDefaultGeneratorList(World world)

// Find default generator from cache.
return this.generatorTierCache.values().stream().
// Filter generators that starts with name.
filter(generator -> generator.getUniqueId().startsWith(gameMode.toLowerCase())).
// Filter deployed and default generators.
filter(GeneratorTierObject::isDefaultGenerator).
filter(GeneratorTierObject::isDeployed).
// Return as list collection.
collect(Collectors.toList());
// Filter generators that starts with name.
filter(generator -> generator.getUniqueId().startsWith(gameMode.toLowerCase())).
// Filter deployed and default generators.
filter(GeneratorTierObject::isDefaultGenerator).
filter(GeneratorTierObject::isDeployed).
// Return as list collection.
collect(Collectors.toList());
}


Expand All @@ -425,20 +435,20 @@ public List<GeneratorTierObject> findDefaultGeneratorList(World world)
public void loadUserIslands(UUID uniqueId)
{
this.operationWorlds.stream().
map(world -> this.addon.getIslands().getIsland(world, uniqueId)).
filter(Objects::nonNull).
forEach(island -> {
if (island.getOwner() == uniqueId)
{
// Owner island must be validated.
this.validateIslandData(island);
}
else
{
// Members does not influence island data.
this.addIslandData(island);
}
});
map(world -> this.addon.getIslands().getIsland(world, uniqueId)).
filter(Objects::nonNull).
forEach(island -> {
if (island.getOwner() == uniqueId)
{
// Owner island must be validated.
this.validateIslandData(island);
}
else
{
// Members does not influence island data.
this.addIslandData(island);
}
});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,21 @@ public void build()

// Do not show cobblestone button if there are no cobblestone generators.
if (this.generatorList.stream().anyMatch(generator ->
generator.getGeneratorType().equals(GeneratorTierObject.GeneratorType.COBBLESTONE)))
generator.getGeneratorType().includes(GeneratorTierObject.GeneratorType.COBBLESTONE)))
{
panelBuilder.item(4, this.createButton(Action.SHOW_COBBLESTONE));
}

// Do not show stone if there are no stone generators.
if (this.generatorList.stream().anyMatch(generator ->
generator.getGeneratorType().equals(GeneratorTierObject.GeneratorType.STONE)))
generator.getGeneratorType().includes(GeneratorTierObject.GeneratorType.STONE)))
{
panelBuilder.item(5, this.createButton(Action.SHOW_STONE));
}

// Do not show basalt if there are no basalt generators.
if (this.generatorList.stream().anyMatch(generator ->
generator.getGeneratorType().equals(GeneratorTierObject.GeneratorType.BASALT)))
generator.getGeneratorType().includes(GeneratorTierObject.GeneratorType.BASALT)))
{
panelBuilder.item(6, this.createButton(Action.SHOW_BASALT));
}
Expand Down Expand Up @@ -249,19 +249,19 @@ private void fillGeneratorTiers(PanelBuilder panelBuilder)
case SHOW_COBBLESTONE:
filteredList = this.generatorList.stream().
filter(generatorTier ->
generatorTier.getGeneratorType().equals(GeneratorTierObject.GeneratorType.COBBLESTONE)).
generatorTier.getGeneratorType().includes(GeneratorTierObject.GeneratorType.COBBLESTONE)).
collect(Collectors.toList());
break;
case SHOW_STONE:
filteredList = this.generatorList.stream().
filter(generatorTier ->
generatorTier.getGeneratorType().equals(GeneratorTierObject.GeneratorType.STONE)).
generatorTier.getGeneratorType().includes(GeneratorTierObject.GeneratorType.STONE)).
collect(Collectors.toList());
break;
case SHOW_BASALT:
filteredList = this.generatorList.stream().
filter(generatorTier ->
generatorTier.getGeneratorType().equals(GeneratorTierObject.GeneratorType.BASALT)).
generatorTier.getGeneratorType().includes(GeneratorTierObject.GeneratorType.BASALT)).
collect(Collectors.toList());
break;
case TOGGLE_VISIBILITY:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ else if (this.generatorTier.getGeneratorType() == GeneratorTierObject.GeneratorT
itemStack = new ItemStack(Material.getMaterial("BASALT"));
}
}
else
{
// TODO: Icon for mixed generator types?
itemStack = new ItemStack(Material.ANDESITE);
}
break;
}
case REQUIRED_MIN_LEVEL:
Expand Down
9 changes: 8 additions & 1 deletion src/main/resources/generatorTemplate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ tiers:
- stone a bit
# Icon used in GUI's
icon: "COBBLESTONE:1"
# Generator type: COBBLESTONE, STONE or BASALT. Self explanatory.
# Valid Generator types:
# - COBBLESTONE - classic block generator
# - STONE - https://minecraft.gamepedia.com/File:Stone_generator.gif
# - BASALT - https://minecraft.gamepedia.com/File:Basalt_generator.gif
# - COBBLESTONE_OR_STONE - to specify that this tier works with cobblestone and stone generators
# - BASALT_OR_COBBLESTONE - to specify that this tier works with basalt and cobblestone generators
# - BASALT_OR_STONE - to specify that this tier works with basalt and stone generators
# - ANY - to specify that this tier works with all generator types.
type: COBBLESTONE
# Indicates that generator is used as default.
# Requirements will be ignored.
Expand Down

0 comments on commit 223f142

Please sign in to comment.