Skip to content

Commit

Permalink
Remove unnecessary version guards in BukkitWorld, as all supported ve…
Browse files Browse the repository at this point in the history
…rsions have these now
  • Loading branch information
me4502 committed Sep 3, 2023
1 parent 6165efb commit 3f16563
Showing 1 changed file with 14 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ public class BukkitWorld extends AbstractWorld {

private static final Logger LOGGER = LogManagerCompat.getLogger();

private static final boolean HAS_3D_BIOMES;
private static final boolean HAS_MIN_Y;

private static final Map<Integer, Effect> effects = new HashMap<>();

static {
Expand All @@ -88,22 +85,6 @@ public class BukkitWorld extends AbstractWorld {
int id = effect.getId();
effects.put(id, effect);
}

boolean temp;
try {
World.class.getMethod("getBiome", int.class, int.class, int.class);
temp = true;
} catch (NoSuchMethodException e) {
temp = false;
}
HAS_3D_BIOMES = temp;
try {
World.class.getMethod("getMinHeight");
temp = true;
} catch (NoSuchMethodException e) {
temp = false;
}
HAS_MIN_Y = temp;
}

private final WeakReference<World> worldRef;
Expand Down Expand Up @@ -160,11 +141,10 @@ public com.sk89q.worldedit.entity.Entity createEntity(com.sk89q.worldedit.util.L
return null;
}
} catch (Exception e) {
LOGGER.warn("Corrupt entity found when creating: " + entity.getType().getId());
LOGGER.warn("Corrupt entity found when creating: " + entity.getType().getId(), e);
if (entity.getNbt() != null) {
LOGGER.warn(entity.getNbt().toString());
}
e.printStackTrace();
return null;
}
} else {
Expand Down Expand Up @@ -194,15 +174,11 @@ public String getId() {
@Override
public Path getStoragePath() {
Path worldFolder = getWorld().getWorldFolder().toPath();
switch (getWorld().getEnvironment()) {
case NETHER:
return worldFolder.resolve("DIM-1");
case THE_END:
return worldFolder.resolve("DIM1");
case NORMAL:
default:
return worldFolder;
}
return switch (getWorld().getEnvironment()) {
case NETHER -> worldFolder.resolve("DIM-1");
case THE_END -> worldFolder.resolve("DIM1");
default -> worldFolder;
};
}

@Override
Expand Down Expand Up @@ -243,14 +219,13 @@ public boolean clearContainerBlockContents(BlockVector3 pt) {

Block block = getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
BlockState state = PaperLib.getBlockState(block, false).getState();
if (!(state instanceof InventoryHolder)) {
if (!(state instanceof InventoryHolder inventoryHolder)) {
return false;
}

InventoryHolder chest = (InventoryHolder) state;
Inventory inven = chest.getInventory();
if (chest instanceof Chest) {
inven = ((Chest) chest).getBlockInventory();
Inventory inven = inventoryHolder.getInventory();
if (inventoryHolder instanceof Chest) {
inven = ((Chest) inventoryHolder).getBlockInventory();
}
inven.clear();
return true;
Expand Down Expand Up @@ -343,13 +318,9 @@ public int getMaxY() {

@Override
public int getMinY() {
if (HAS_MIN_Y) {
return getWorld().getMinHeight();
}
return super.getMinY();
return getWorld().getMinHeight();
}

@SuppressWarnings("deprecation")
@Override
public void fixAfterFastMode(Iterable<BlockVector2> chunks) {
World world = getWorld();
Expand Down Expand Up @@ -541,36 +512,26 @@ public boolean useItem(BlockVector3 position, BaseItem item, Direction face) {
@Override
public boolean fullySupports3DBiomes() {
// Supports if API does and we're not in the overworld
return HAS_3D_BIOMES && (getWorld().getEnvironment() != World.Environment.NORMAL || PaperLib.isVersion(18));
return getWorld().getEnvironment() != World.Environment.NORMAL || PaperLib.isVersion(18);
}

@SuppressWarnings("deprecation")
@Override
public BiomeType getBiome(BlockVector3 position) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null && adapter.hasCustomBiomeSupport()) {
return adapter.getBiome(BukkitAdapter.adapt(getWorld(), position));
} else {
if (HAS_3D_BIOMES) {
return BukkitAdapter.adapt(getWorld().getBiome(position.getBlockX(), position.getBlockY(), position.getBlockZ()));
} else {
return BukkitAdapter.adapt(getWorld().getBiome(position.getBlockX(), position.getBlockZ()));
}
return BukkitAdapter.adapt(getWorld().getBiome(position.getBlockX(), position.getBlockY(), position.getBlockZ()));
}
}

@SuppressWarnings("deprecation")
@Override
public boolean setBiome(BlockVector3 position, BiomeType biome) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null && adapter.hasCustomBiomeSupport()) {
adapter.setBiome(BukkitAdapter.adapt(getWorld(), position), biome);
} else {
if (HAS_3D_BIOMES) {
getWorld().setBiome(position.getBlockX(), position.getBlockY(), position.getBlockZ(), BukkitAdapter.adapt(biome));
} else {
getWorld().setBiome(position.getBlockX(), position.getBlockZ(), BukkitAdapter.adapt(biome));
}
getWorld().setBiome(position.getBlockX(), position.getBlockY(), position.getBlockZ(), BukkitAdapter.adapt(biome));
}
return true;
}
Expand Down

0 comments on commit 3f16563

Please sign in to comment.