Skip to content

Commit

Permalink
Update code to Java 17 structures and syntax.
Browse files Browse the repository at this point in the history
Fixed some JavaDoc errors.
  • Loading branch information
tastybento committed Dec 12, 2021
1 parent 3dd686b commit f4303ec
Show file tree
Hide file tree
Showing 41 changed files with 867 additions and 1,304 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package world.bentobox.magiccobblestonegenerator;


import java.util.Optional;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import java.util.Optional;

import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.addons.GameModeAddon;
Expand Down Expand Up @@ -286,7 +287,7 @@ private void findVault()

Optional<VaultHook> vault = this.getPlugin().getVault();

if (!vault.isPresent())
if (vault.isEmpty())
{
this.vaultHook = null;
this.logWarning("Vault plugin not found. Economy will not work!");
Expand All @@ -308,7 +309,7 @@ private void findLevel()

Optional<Addon> level = this.getAddonByName("Level");

if (!level.isPresent())
if (level.isEmpty())
{
this.logWarning("Level add-on not found so Magic Cobblestone Generator, some parts may not work!");
this.levelAddon = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package world.bentobox.magiccobblestonegenerator.commands.admin;


import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;

import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.localization.TextVariables;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package world.bentobox.magiccobblestonegenerator.commands.player;


import org.bukkit.World;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.bukkit.World;

import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package world.bentobox.magiccobblestonegenerator.config;


import org.bukkit.Material;
import java.util.HashSet;
import java.util.Set;

import org.bukkit.Material;

import world.bentobox.bentobox.api.configuration.ConfigComment;
import world.bentobox.bentobox.api.configuration.ConfigEntry;
import world.bentobox.bentobox.api.configuration.ConfigObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
package world.bentobox.magiccobblestonegenerator.database.adapters;


import com.google.gson.*;
import java.lang.reflect.Type;
import java.util.HashSet;
import java.util.Set;

import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import world.bentobox.magiccobblestonegenerator.StoneGeneratorAddon;
import world.bentobox.magiccobblestonegenerator.database.objects.GeneratorTierObject;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
package world.bentobox.magiccobblestonegenerator.database.objects;


import com.google.gson.annotations.Expose;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.*;

import com.google.gson.annotations.Expose;

import world.bentobox.bentobox.database.objects.DataObject;
import world.bentobox.bentobox.database.objects.Table;
Expand Down Expand Up @@ -216,8 +222,8 @@ public GeneratorBundleObject clone()
*/
public final static GeneratorBundleObject dummyBundle;

/**
* Populate dummy bundle with some values.
/*
Populate dummy bundle with some values.
*/
static
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
package world.bentobox.magiccobblestonegenerator.database.objects;


import com.google.gson.annotations.Expose;
import org.jetbrains.annotations.Nullable;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import org.jetbrains.annotations.Nullable;

import com.google.gson.annotations.Expose;

import world.bentobox.bentobox.database.objects.DataObject;
import world.bentobox.bentobox.database.objects.Table;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
package world.bentobox.magiccobblestonegenerator.database.objects;


import com.google.gson.annotations.Expose;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeMap;

import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.inventory.ItemStack;
import java.util.*;

import com.google.gson.annotations.Expose;

import world.bentobox.bentobox.database.objects.DataObject;
import world.bentobox.bentobox.database.objects.Table;
Expand Down Expand Up @@ -497,9 +504,7 @@ public GeneratorTierObject clone()

// Cloning must be done like this
TreeMap<Double, ItemStack> cloneMap = new TreeMap<>();
this.treasureItemChanceMap.forEach((chance, item) -> {
cloneMap.put(chance, item.clone());
});
this.treasureItemChanceMap.forEach((chance, item) -> cloneMap.put(chance, item.clone()));
clone.setTreasureItemChanceMap(cloneMap);

clone.setTreasureChance(this.treasureChance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
package world.bentobox.magiccobblestonegenerator.events;


import java.util.UUID;

import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import java.util.UUID;

import world.bentobox.bentobox.api.events.BentoBoxEvent;
import world.bentobox.bentobox.api.user.User;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
package world.bentobox.magiccobblestonegenerator.events;


import org.bukkit.event.HandlerList;
import java.util.UUID;

import org.bukkit.event.HandlerList;

import world.bentobox.bentobox.api.events.BentoBoxEvent;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.magiccobblestonegenerator.database.objects.GeneratorTierObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
package world.bentobox.magiccobblestonegenerator.events;


import java.util.UUID;

import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;

import world.bentobox.bentobox.api.events.BentoBoxEvent;
import world.bentobox.bentobox.api.user.User;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
package world.bentobox.magiccobblestonegenerator.listeners;


import java.util.Objects;
import java.util.Random;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
Expand All @@ -17,8 +20,6 @@
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.Nullable;
import java.util.Objects;
import java.util.Random;

import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
package world.bentobox.magiccobblestonegenerator.listeners;


import java.util.Optional;

import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockFromToEvent;

import java.util.Optional;

import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.magiccobblestonegenerator.StoneGeneratorAddon;

Expand Down Expand Up @@ -92,7 +92,7 @@ public void onBlockFromToEvent(BlockFromToEvent event)

Optional<Island> islandOptional = this.addon.getIslands().getIslandAt(eventSourceBlock.getLocation());

if (!islandOptional.isPresent())
if (islandOptional.isEmpty())
{
// If not operating in non-island regions.
return;
Expand Down Expand Up @@ -213,34 +213,28 @@ private boolean canGenerateStone(Material liquid, Block targetBlock)
*/
private boolean canLavaGenerateCobblestone(Block airBlock, BlockFace flowDirection)
{
switch (flowDirection)
{
case NORTH:
case EAST:
case SOUTH:
case WEST:
// Since waterlogged blocks, it is also necessary to check block above.
// Check if block in flow direction is water
// Check if block on the left side is water
// Check if block on the right side is water

return MagicGeneratorListener.containsWater(airBlock.getRelative(BlockFace.UP)) ||
MagicGeneratorListener.containsWater(airBlock.getRelative(flowDirection)) ||
MagicGeneratorListener.containsWater(airBlock
.getRelative(MagicGeneratorListener.getClockwiseDirection(flowDirection))) ||
MagicGeneratorListener.containsWater(airBlock
.getRelative(MagicGeneratorListener.getCounterClockwiseDirection(flowDirection)));

case DOWN:
// If lava flows down then we should search for water in horizontally adjacent blocks.

return MagicGeneratorListener.containsWater(airBlock.getRelative(BlockFace.NORTH)) ||
MagicGeneratorListener.containsWater(airBlock.getRelative(BlockFace.EAST)) ||
MagicGeneratorListener.containsWater(airBlock.getRelative(BlockFace.SOUTH)) ||
MagicGeneratorListener.containsWater(airBlock.getRelative(BlockFace.WEST));
default:
return false;
}
return switch (flowDirection) {
case NORTH, EAST, SOUTH, WEST ->
// Since waterlogged blocks, it is also necessary to check block above.
// Check if block in flow direction is water
// Check if block on the left side is water
// Check if block on the right side is water

MagicGeneratorListener.containsWater(airBlock.getRelative(BlockFace.UP)) ||
MagicGeneratorListener.containsWater(airBlock.getRelative(flowDirection)) ||
MagicGeneratorListener.containsWater(airBlock
.getRelative(MagicGeneratorListener.getClockwiseDirection(flowDirection))) ||
MagicGeneratorListener.containsWater(airBlock
.getRelative(MagicGeneratorListener.getCounterClockwiseDirection(flowDirection)));
case DOWN ->
// If lava flows down then we should search for water in horizontally adjacent blocks.

MagicGeneratorListener.containsWater(airBlock.getRelative(BlockFace.NORTH)) ||
MagicGeneratorListener.containsWater(airBlock.getRelative(BlockFace.EAST)) ||
MagicGeneratorListener.containsWater(airBlock.getRelative(BlockFace.SOUTH)) ||
MagicGeneratorListener.containsWater(airBlock.getRelative(BlockFace.WEST));
default -> false;
};
}


Expand Down Expand Up @@ -386,20 +380,15 @@ private static boolean isFlowingLavaBlock(Block block)
*/
private static BlockFace getClockwiseDirection(BlockFace face)
{
switch (face)
{
case NORTH:
return BlockFace.EAST;
case EAST:
return BlockFace.SOUTH;
case SOUTH:
return BlockFace.WEST;
case WEST:
return BlockFace.NORTH;
default:
// Not interested in other directions
return face;
}
return switch (face) {
case NORTH -> BlockFace.EAST;
case EAST -> BlockFace.SOUTH;
case SOUTH -> BlockFace.WEST;
case WEST -> BlockFace.NORTH;
default ->
// Not interested in other directions
face;
};
}


Expand All @@ -412,19 +401,14 @@ private static BlockFace getClockwiseDirection(BlockFace face)
*/
private static BlockFace getCounterClockwiseDirection(BlockFace face)
{
switch (face)
{
case NORTH:
return BlockFace.WEST;
case EAST:
return BlockFace.NORTH;
case SOUTH:
return BlockFace.EAST;
case WEST:
return BlockFace.SOUTH;
default:
// Not interested in other directions
return face;
}
return switch (face) {
case NORTH -> BlockFace.WEST;
case EAST -> BlockFace.NORTH;
case SOUTH -> BlockFace.EAST;
case WEST -> BlockFace.SOUTH;
default ->
// Not interested in other directions
face;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
package world.bentobox.magiccobblestonegenerator.listeners;


import java.util.Optional;

import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockFormEvent;

import java.util.Optional;

import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.magiccobblestonegenerator.StoneGeneratorAddon;
import world.bentobox.magiccobblestonegenerator.utils.Why;
Expand Down Expand Up @@ -61,7 +61,7 @@ public void onBlockFormEvent(BlockFormEvent event)

Optional<Island> islandOptional = this.addon.getIslands().getIslandAt(eventSourceBlock.getLocation());

if (!islandOptional.isPresent())
if (islandOptional.isEmpty())
{
// If not operating in non-island regions.
return;
Expand Down

0 comments on commit f4303ec

Please sign in to comment.