Skip to content

Commit

Permalink
Fix or suppress deprecation warnings in most code (#1404)
Browse files Browse the repository at this point in the history
Didn't touch commands or some of Sponge
  • Loading branch information
octylFractal committed Jul 1, 2020
1 parent eaea1e6 commit 8aa034c
Show file tree
Hide file tree
Showing 39 changed files with 157 additions and 59 deletions.
Expand Up @@ -389,13 +389,15 @@ public static Biome adapt(BiomeType biomeType) {
* @return WorldEdit EntityType
*/
public static EntityType adapt(org.bukkit.entity.EntityType entityType) {
@SuppressWarnings("deprecation")
final String name = entityType.getName();
if (name == null) {
return null;
}
return EntityTypes.get(name.toLowerCase(Locale.ROOT));
}

@SuppressWarnings("deprecation")
public static org.bukkit.entity.EntityType adapt(EntityType entityType) {
if (!entityType.getId().startsWith("minecraft:")) {
throw new IllegalArgumentException("Bukkit only supports vanilla entities");
Expand Down
Expand Up @@ -29,6 +29,8 @@
import java.util.Set;
import java.util.stream.Collectors;

import static com.google.common.base.Preconditions.checkNotNull;

public class BukkitBlockCategoryRegistry implements BlockCategoryRegistry {

private Set<BlockType> getFromBukkitTag(Tag<Material> tag) {
Expand All @@ -40,7 +42,9 @@ public Set<BlockType> getCategorisedByName(String category) {
String[] split = category.split(":");
String namespace = split.length > 1 ? split[0] : "minecraft";
String key = split.length > 1 ? split[1] : category;
@SuppressWarnings("deprecation")
Tag<Material> tag = Bukkit.getTag(Tag.REGISTRY_BLOCKS, new NamespacedKey(namespace, key), Material.class);
checkNotNull(tag);
return getFromBukkitTag(tag);
}
}
Expand Up @@ -96,7 +96,7 @@ public void printError(String msg) {

@Override
public void print(Component component) {
TextAdapter.sendComponent(sender, WorldEditText.format(component, getLocale()));
TextAdapter.sendMessage(sender, WorldEditText.format(component, getLocale()));
}

@Override
Expand Down
Expand Up @@ -103,6 +103,7 @@ public boolean isBurnable() {
return material.isBurnable();
}

@SuppressWarnings("deprecation")
@Override
public boolean isTranslucent() {
return material.isTransparent();
Expand Down
Expand Up @@ -96,7 +96,7 @@ public void printError(String msg) {

@Override
public void print(Component component) {
TextAdapter.sendComponent(sender, WorldEditText.format(component, getLocale()));
TextAdapter.sendMessage(sender, WorldEditText.format(component, getLocale()));
}

@Override
Expand Down
Expand Up @@ -29,6 +29,8 @@
import java.util.Set;
import java.util.stream.Collectors;

import static com.google.common.base.Preconditions.checkNotNull;

public class BukkitItemCategoryRegistry implements ItemCategoryRegistry {

private Set<ItemType> getFromBukkitTag(Tag<Material> tag) {
Expand All @@ -40,7 +42,9 @@ public Set<ItemType> getCategorisedByName(String category) {
String[] split = category.split(":");
String namespace = split.length > 1 ? split[0] : "minecraft";
String key = split.length > 1 ? split[1] : category;
@SuppressWarnings("deprecation")
Tag<Material> tag = Bukkit.getTag(Tag.REGISTRY_ITEMS, new NamespacedKey(namespace, key), Material.class);
checkNotNull(tag);
return getFromBukkitTag(tag);
}
}
Expand Up @@ -135,7 +135,7 @@ public void printError(String msg) {

@Override
public void print(Component component) {
TextAdapter.sendComponent(player, WorldEditText.format(component, getLocale()));
TextAdapter.sendMessage(player, WorldEditText.format(component, getLocale()));
}

@Override
Expand Down
Expand Up @@ -109,6 +109,7 @@ public boolean isValidMobType(String type) {
if (!type.startsWith("minecraft:")) {
return false;
}
@SuppressWarnings("deprecation")
final EntityType entityType = EntityType.fromName(type.substring(10));
return entityType != null && entityType.isAlive();
}
Expand Down
Expand Up @@ -77,7 +77,9 @@ public class BukkitWorld extends AbstractWorld {
private static final Map<Integer, Effect> effects = new HashMap<>();
static {
for (Effect effect : Effect.values()) {
effects.put(effect.getId(), effect);
@SuppressWarnings("deprecation")
int id = effect.getId();
effects.put(id, effect);
}

boolean temp;
Expand Down Expand Up @@ -349,6 +351,7 @@ public int getMaxY() {
return getWorld().getMaxHeight() - 1;
}

@SuppressWarnings("deprecation")
@Override
public void fixAfterFastMode(Iterable<BlockVector2> chunks) {
World world = getWorld();
Expand Down Expand Up @@ -504,7 +507,7 @@ public boolean fullySupports3DBiomes() {
return HAS_3D_BIOMES && getWorld().getEnvironment() != World.Environment.NORMAL;
}

@SuppressWarnings("deprecated")
@SuppressWarnings("deprecation")
@Override
public BiomeType getBiome(BlockVector3 position) {
if (HAS_3D_BIOMES) {
Expand All @@ -514,7 +517,7 @@ public BiomeType getBiome(BlockVector3 position) {
}
}

@SuppressWarnings("deprecated")
@SuppressWarnings("deprecation")
@Override
public boolean setBiome(BlockVector3 position, BiomeType biome) {
if (HAS_3D_BIOMES) {
Expand Down
Expand Up @@ -171,6 +171,7 @@ private void setupWorldData() {
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent());
}

@SuppressWarnings("deprecation")
private void initializeRegistries() {
// Biome
for (Biome biome : Biome.values()) {
Expand Down
Expand Up @@ -162,11 +162,15 @@ public void deleteChunks(Actor actor, World world, LocalSession session,
throw new StopExecutionException(TextComponent.of("Failed to write chunk list: " + e.getMessage()));
}

actor.print(String.format("%d chunk(s) have been marked for deletion the next time the server starts.",
newBatch.getChunkCount()));
actor.print(TextComponent.of(
String.format("%d chunk(s) have been marked for deletion the next time the server starts.",
newBatch.getChunkCount())
));
if (currentInfo.batches.size() > 1) {
actor.printDebug(String.format("%d chunks total marked for deletion. (May have overlaps).",
currentInfo.batches.stream().mapToInt(ChunkDeletionInfo.ChunkBatch::getChunkCount).sum()));
actor.printDebug(TextComponent.of(
String.format("%d chunks total marked for deletion. (May have overlaps).",
currentInfo.batches.stream().mapToInt(ChunkDeletionInfo.ChunkBatch::getChunkCount).sum())
));
}
actor.print(TextComponent.of("You can mark more chunks for deletion, or to stop now, run: ", TextColor.LIGHT_PURPLE)
.append(TextComponent.of("/stop", TextColor.AQUA)
Expand Down
Expand Up @@ -27,18 +27,21 @@
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;

import javax.annotation.Nullable;

/**
* A super pickaxe mode that will remove blocks in an area.
*/
public class AreaPickaxe implements BlockTool {

private int range;
private final int range;

public AreaPickaxe(int range) {
this.range = range;
Expand All @@ -50,7 +53,7 @@ public boolean canUse(Actor player) {
}

@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
int ox = clicked.getBlockX();
int oy = clicked.getBlockY();
int oz = clicked.getBlockZ();
Expand Down
Expand Up @@ -29,6 +29,7 @@
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
Expand All @@ -40,6 +41,8 @@
import java.util.Map;
import java.util.UUID;

import javax.annotation.Nullable;

/**
* A mode that cycles the data values of supported blocks.
*/
Expand Down Expand Up @@ -115,12 +118,12 @@ private boolean handleCycle(LocalConfiguration config, Player player, LocalSessi
}

@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
return handleCycle(config, player, session, clicked, true);
}

@Override
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
return handleCycle(config, player, session, clicked, false);
}

Expand Down
Expand Up @@ -29,11 +29,13 @@
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.block.BaseBlock;

import javax.annotation.Nullable;

/**
* A mode that replaces one block.
*/
Expand All @@ -51,7 +53,7 @@ public boolean canUse(Actor player) {
}

@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
BlockBag bag = session.getBlockBag(player);

try (EditSession editSession = session.createEditSession(player)) {
Expand All @@ -74,7 +76,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla


@Override
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
BaseBlock targetBlock = player.getWorld().getFullBlock(clicked.toVector().toBlockPoint());

if (targetBlock != null) {
Expand Down
Expand Up @@ -23,6 +23,8 @@
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.internal.util.DeprecationUtil;
import com.sk89q.worldedit.internal.util.NonAbstractForCompatibility;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.Location;

Expand All @@ -33,32 +35,35 @@ public interface BlockTool extends Tool {
/**
* Perform the primary action of this tool.
*
* @param server
* @param config
* @param player
* @param session
* @param clicked
* @return true to cancel the original event which triggered this action (if possible)
* @deprecated New subclasses should override
* {@link #actPrimary(Platform, LocalConfiguration, Player, LocalSession, Location, Direction)}
* instead
*/
@Deprecated
default boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
throw new AssertionError("actPrimary must be overridden");
return actPrimary(server, config, player, session, clicked, null);
}

/**
* Perform the primary action of this tool.
*
* <p>Note: This will not be default in WorldEdit 8</p>
*
* @param server The platform
* @param config The config instance
* @param player The player
* @param session The local session
* @param clicked The location that was clicked
* @param face The face that was clicked
* @return true to cancel the original event which triggered this action (if possible)
* @apiNote This must be overridden by new subclasses. See {@link NonAbstractForCompatibility}
* for details
*/
@NonAbstractForCompatibility(
delegateName = "actPrimary",
delegateParams = { Platform.class, LocalConfiguration.class, Player.class, LocalSession.class, Location.class }
)
default boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
DeprecationUtil.checkDelegatingOverride(getClass());
return actPrimary(server, config, player, session, clicked);
}
}
Expand Up @@ -23,6 +23,8 @@
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.internal.util.DeprecationUtil;
import com.sk89q.worldedit.internal.util.NonAbstractForCompatibility;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.Location;

Expand All @@ -36,32 +38,35 @@ public interface DoubleActionBlockTool extends BlockTool {
/**
* Perform the secondary action of this block tool.
*
* @param server
* @param config
* @param player
* @param session
* @param clicked
* @return true to cancel the original event which triggered this action (if possible)
* @deprecated New subclasses must override
* {@link #actSecondary(Platform, LocalConfiguration, Player, LocalSession, Location, Direction)}
* instead
*/
@Deprecated
default boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
throw new AssertionError("actPrimary must be overridden");
return actSecondary(server, config, player, session, clicked, null);
}

/**
* Perform the secondary action of this block tool.
*
* <p>Note: This will not be default in WorldEdit 8</p>
*
* @param server The platform
* @param config The config instance
* @param player The player
* @param session The local session
* @param clicked The location that was clicked
* @param face The face that was clicked
* @return true to cancel the original event which triggered this action (if possible)
* @apiNote This must be overridden by new subclasses. See {@link NonAbstractForCompatibility}
* for details
*/
@NonAbstractForCompatibility(
delegateName = "actSecondary",
delegateParams = { Platform.class, LocalConfiguration.class, Player.class, LocalSession.class, Location.class }
)
default boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
DeprecationUtil.checkDelegatingOverride(getClass());
return actSecondary(server, config, player, session, clicked);
}

Expand Down
Expand Up @@ -40,6 +40,8 @@
import java.util.LinkedList;
import java.util.Set;

import javax.annotation.Nullable;

/**
* A pickaxe mode that removes floating treetops (logs and leaves not connected
* to anything else)
Expand Down Expand Up @@ -67,7 +69,8 @@ private boolean isTreeBlock(BlockType type) {

@Override
public boolean actPrimary(Platform server, LocalConfiguration config,
Player player, LocalSession session, Location clicked) {
Player player, LocalSession session, Location clicked,
@Nullable Direction face) {

final World world = (World) clicked.getExtent();
final BlockState state = world.getBlock(clicked.toVector().toBlockPoint());
Expand Down

0 comments on commit 8aa034c

Please sign in to comment.