Skip to content

Commit

Permalink
Reduce responsibility of main class
Browse files Browse the repository at this point in the history
This should make the plugin a ton more testable (though I don't have it in me right now to write tests).
  • Loading branch information
Jikoo committed Jul 25, 2024
1 parent 64899e5 commit dbceff0
Show file tree
Hide file tree
Showing 25 changed files with 938 additions and 776 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.errorprone.annotations.RestrictedApi;
import com.lishid.openinv.internal.ISpecialInventory;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

Expand All @@ -11,6 +12,8 @@
*/
public class OpenPlayerSaveEvent extends PlayerSaveEvent {

private static final HandlerList HANDLERS = new HandlerList();

private final ISpecialInventory inventory;

/**
Expand Down Expand Up @@ -40,4 +43,14 @@ public class OpenPlayerSaveEvent extends PlayerSaveEvent {
return inventory;
}

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

public static HandlerList getHandlerList() {
return HANDLERS;
}

}
4 changes: 2 additions & 2 deletions common/src/main/java/com/lishid/openinv/event/OpenEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public static boolean saveCancelled(@NotNull Player player) {
return call(new PlayerSaveEvent(player));
}

public static boolean saveCancelled(@NotNull Player player, @NotNull ISpecialInventory inventory) {
return call(new OpenPlayerSaveEvent(player, inventory));
public static boolean saveCancelled(@NotNull ISpecialInventory inventory) {
return call(new OpenPlayerSaveEvent((Player) inventory.getPlayer(), inventory));
}

private static <T extends Event & Cancellable> boolean call(T event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private void addTranslationFallthrough(@NotNull LangLocation location, @NotNull
if (sender instanceof Player) {
return ((Player) sender).getLocale();
} else {
return plugin.getConfig().getString("settings.locale", "en_us");
return plugin.getConfig().getString("settings.locale", "en");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,6 @@ public PlayerManager(@NotNull Logger logger, @NotNull LanguageManager lang) {

@Override
public @Nullable Player loadPlayer(@NotNull final OfflinePlayer offline) {
// Ensure player has data
if (!offline.hasPlayedBefore()) {
return null;
}

MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
ServerLevel worldServer = server.getLevel(Level.OVERWORLD);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,6 @@ public PlayerManager(@NotNull Logger logger, @NotNull LanguageManager lang) {

@Override
public @Nullable Player loadPlayer(@NotNull final OfflinePlayer offline) {
// Ensure player has data
if (!offline.hasPlayedBefore()) {
return null;
}

MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
ServerLevel worldServer = server.getLevel(Level.OVERWORLD);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ public PlayerManager(@NotNull Logger logger) {

@Override
public @Nullable Player loadPlayer(@NotNull final OfflinePlayer offline) {
// Ensure player has data
if (!offline.hasPlayedBefore()) {
return null;
}

MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
ServerLevel worldServer = server.getLevel(Level.OVERWORLD);

Expand Down
105 changes: 0 additions & 105 deletions plugin/src/main/java/com/lishid/openinv/InventoryListener.java

This file was deleted.

42 changes: 0 additions & 42 deletions plugin/src/main/java/com/lishid/openinv/OfflineHandler.java

This file was deleted.

Loading

0 comments on commit dbceff0

Please sign in to comment.