Skip to content

Commit

Permalink
Remove deprecated methods, restructure (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jikoo authored Jul 10, 2024
1 parent 1cfa9bd commit b895cb4
Show file tree
Hide file tree
Showing 63 changed files with 970 additions and 917 deletions.
8 changes: 3 additions & 5 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ As OpenInv is compiled against Mojang's mappings, you must run BuildTools with t
`java -jar BuildTools.jar --remapped --rev $serverVersion`
`$serverVersion` is the version of the server, i.e. `1.18.1`

To compile for a single version, specify the module you are targeting:
`mvn -pl $moduleName -am clean install`
`$moduleName` is the name of the module, i.e. `internal/v1_18_R1`.
To compile just the API, execute Maven as usual:
`mvn clean package`

To compile for a set of versions, use a profile. Select a profile using the `-P` argument:
To compile the full plugin, use the provided profile with `-P all`:
`mvn clean package -am -P all`
The only provided profile is `all`. The final file is `target/OpenInv.jar`
For more information, check out the [official Maven guide](http://maven.apache.org/guides/introduction/introduction-to-profiles.html).
111 changes: 3 additions & 108 deletions api/src/main/java/com/lishid/openinv/IOpenInv.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@
package com.lishid.openinv;

import com.lishid.openinv.internal.IAnySilentContainer;
import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialInventory;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import com.lishid.openinv.util.InventoryAccess;
import java.util.UUID;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.UUID;
import java.util.logging.Logger;

/**
* Interface defining behavior for the OpenInv plugin.
*/
Expand Down Expand Up @@ -80,22 +78,6 @@ public interface IOpenInv {
*/
@NotNull IAnySilentContainer getAnySilentContainer();

/**
* @deprecated Use static {@link InventoryAccess} methods.
*/
@Deprecated(forRemoval = true)
default @NotNull IInventoryAccess getInventoryAccess() {
return new InventoryAccess();
}

/**
* @deprecated Use {@link #getAnyContainerStatus(OfflinePlayer)}. Not all containers are chests.
*/
@Deprecated(forRemoval = true, since = "4.2.0")
default boolean getPlayerAnyChestStatus(@NotNull OfflinePlayer offline) {
return getAnyContainerStatus(offline);
}

/**
* Get whether a user has AnyContainer mode enabled.
*
Expand All @@ -104,14 +86,6 @@ default boolean getPlayerAnyChestStatus(@NotNull OfflinePlayer offline) {
*/
boolean getAnyContainerStatus(@NotNull OfflinePlayer offline);

/**
* @deprecated Use {@link #setAnyContainerStatus(OfflinePlayer, boolean)}. Not all containers are chests.
*/
@Deprecated(forRemoval = true, since = "4.2.0")
default void setPlayerAnyChestStatus(@NotNull OfflinePlayer offline, boolean status) {
setAnyContainerStatus(offline, status);
}

/**
* Set whether a user has AnyContainer mode enabled.
*
Expand All @@ -120,14 +94,6 @@ default void setPlayerAnyChestStatus(@NotNull OfflinePlayer offline, boolean sta
*/
void setAnyContainerStatus(@NotNull OfflinePlayer offline, boolean status);

/**
* @deprecated Use {@link #getSilentContainerStatus(OfflinePlayer)}. Not all containers are chests.
*/
@Deprecated(forRemoval = true, since = "4.2.0")
default boolean getPlayerSilentChestStatus(@NotNull OfflinePlayer offline) {
return getSilentContainerStatus(offline);
}

/**
* Get whether a user has SilentContainer mode enabled.
*
Expand All @@ -136,14 +102,6 @@ default boolean getPlayerSilentChestStatus(@NotNull OfflinePlayer offline) {
*/
boolean getSilentContainerStatus(@NotNull OfflinePlayer offline);

/**
* @deprecated Use {@link #setSilentContainerStatus(OfflinePlayer, boolean)}. Not all containers are chests.
*/
@Deprecated(forRemoval = true, since = "4.2.0")
default void setPlayerSilentChestStatus(@NotNull OfflinePlayer offline, boolean status) {
setSilentContainerStatus(offline, status);
}

/**
* Set whether a user has SilentContainer mode enabled.
*
Expand All @@ -152,20 +110,6 @@ default void setPlayerSilentChestStatus(@NotNull OfflinePlayer offline, boolean
*/
void setSilentContainerStatus(@NotNull OfflinePlayer offline, boolean status);

/**
* Get a unique identifier by which the OfflinePlayer can be referenced.
*
* @deprecated Use {@link OfflinePlayer#getUniqueId()} and {@link UUID#toString()}. This was necessary for non-UUID
* versions of Minecraft, but support for them has been dropped for years.
* @param offline the OfflinePlayer
* @return the identifier
* @throws IllegalStateException if the server version is unsupported
*/
@Deprecated(forRemoval = true)
default @NotNull String getPlayerID(@NotNull OfflinePlayer offline) {
return offline.getUniqueId().toString();
}

/**
* Get an {@link ISpecialEnderChest} for a user.
*
Expand Down Expand Up @@ -229,55 +173,6 @@ default void setPlayerSilentChestStatus(@NotNull OfflinePlayer offline, boolean
*/
@Nullable OfflinePlayer matchPlayer(@NotNull String name);

/**
* @deprecated OpenInv uses action bar chat for notifications. Whether they show is based on language settings.
*/
@Deprecated(forRemoval = true)
default boolean notifyAnyChest() {
return true;
}

/**
* @deprecated OpenInv uses action bar chat for notifications. Whether they show is based on language settings.
*/
@Deprecated(forRemoval = true)
default boolean notifySilentChest() {
return true;
}

/**
* @deprecated see {@link #retainPlayer(Player, Plugin)}
*/
@Deprecated(forRemoval = true, since = "4.2.0")
default void releasePlayer(@NotNull Player player, @NotNull Plugin plugin) {}

/**
* @deprecated OpenInv no longer uses an internal cache beyond maintaining copies of currently open inventories.
* If you wish to use/modify a player, ensure either {@link IOpenInv#isPlayerLoaded(UUID)} is false or the player
* instance is the same memory address as the one in use by OpenInv.
* <pre>
* public &#64;NotNull Player savePlayerData(&#64;NotNull Player player) {
* IOpenInv openInv = ...
* if (!openInv.disableSaving() && openInv.isPlayerLoaded(player.getUniqueId())) {
* Player openInvLoadedPlayer = openInv.loadPlayer(myInUsePlayer);
* if (openInvLoadedPlayer != player) {
* // The copy loaded by OpenInv is not the same as our loaded copy. Push our changes.
* copyPlayerModifications(player, openInvLoadedPlayer);
* }
* // OpenInv will handle saving data when the player is unloaded.
* // Optionally, to be sure our changes will persist, save now.
* // openInvLoadedPlayer.saveData();
* return openInvLoadedPlayer;
* }
*
* player.saveData();
* return player;
* }
* </pre>
*/
@Deprecated(forRemoval = true, since = "4.2.0")
default void retainPlayer(@NotNull Player player, @NotNull Plugin plugin) {}

/**
* Forcibly close inventories of and unload any cached data for a user.
*
Expand Down
65 changes: 17 additions & 48 deletions api/src/main/java/com/lishid/openinv/event/OpenPlayerSaveEvent.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
package com.lishid.openinv.event;

import com.google.errorprone.annotations.RestrictedApi;
import com.lishid.openinv.internal.ISpecialInventory;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

/**
* Event fired before OpenInv saves a player's data.
* Event fired before OpenInv saves a player's data when closing an {@link ISpecialInventory}.
*/
public class OpenPlayerSaveEvent extends Event implements Cancellable {
public class OpenPlayerSaveEvent extends PlayerSaveEvent {

private static final HandlerList HANDLERS = new HandlerList();

private final Player player;
private final ISpecialInventory inventory;
private boolean cancelled = false;

public OpenPlayerSaveEvent(@NotNull Player player, @NotNull ISpecialInventory inventory) {
this.player = player;
this.inventory = inventory;
}

/**
* Get the {@link Player} whose data is being saved.
* Construct a new {@code OpenPlayerSaveEvent}.
*
* <p>The constructor is not considered part of the API, and may be subject to change.</p>
*
* @return player the Player whose data is being saved
* @param player the player to be saved
* @param inventory the {@link ISpecialInventory} being closed
*/
public @NotNull Player getPlayer() {
return player;
@RestrictedApi(
explanation = "Constructor is not considered part of the API and may be subject to change.",
link = "",
allowedOnPath = ".*/com/lishid/openinv/event/OpenEvents.java")
@ApiStatus.Internal
OpenPlayerSaveEvent(@NotNull Player player, @NotNull ISpecialInventory inventory) {
super(player);
this.inventory = inventory;
}

/**
Expand All @@ -41,34 +40,4 @@ public OpenPlayerSaveEvent(@NotNull Player player, @NotNull ISpecialInventory in
return inventory;
}

/**
* Get whether the event is cancelled.
*
* @return true if the event is cancelled
*/
@Override
public boolean isCancelled() {
return cancelled;
}

/**
* Set whether the event is cancelled.
*
* @param cancel whether the event is cancelled
*/
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}

@NotNull
@Override
public HandlerList getHandlers() {
return HANDLERS;
}

public static HandlerList getHandlerList() {
return HANDLERS;
}

}
67 changes: 67 additions & 0 deletions api/src/main/java/com/lishid/openinv/event/PlayerSaveEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.lishid.openinv.event;


import com.google.errorprone.annotations.RestrictedApi;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

/**
* Event fired before a {@link Player} loaded via OpenInv is saved.
*/
public class PlayerSaveEvent extends PlayerEvent implements Cancellable {

private static final HandlerList HANDLERS = new HandlerList();

private boolean cancelled = false;

/**
* Construct a new {@code PlayerSaveEvent}.
*
* <p>The constructor is not considered part of the API, and may be subject to change.</p>
*
* @param player the player to be saved
*/
@RestrictedApi(
explanation = "Constructor is not considered part of the API and may be subject to change.",
link = "",
allowedOnPath = ".*/com/lishid/openinv/event/(OpenPlayerSaveEvent|OpenEvents).java")
@ApiStatus.Internal
PlayerSaveEvent(@NotNull Player player) {
super(player);
}

/**
* Get whether the event is cancelled.
*
* @return true if the event is cancelled
*/
@Override
public boolean isCancelled() {
return cancelled;
}

/**
* Set whether the event is cancelled.
*
* @param cancel whether the event is cancelled
*/
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}

@NotNull
@Override
public HandlerList getHandlers() {
return HANDLERS;
}

public static HandlerList getHandlerList() {
return HANDLERS;
}

}
Loading

0 comments on commit b895cb4

Please sign in to comment.