Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrote clearTeamInventory #848

Merged
merged 4 commits into from
Dec 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -783,14 +784,51 @@ public void handleBlockPlaceOutsideTerritory(BlockPlaceEvent blockEvent) {

public void clearTeamInventory(Island island) {

if (IridiumSkyblock.getInstance().getConfiguration().clearInventoryOnRegen) {
IridiumSkyblock.getInstance().getIslandManager().getMembersOnIsland(island).forEach(member ->
member.getPlayer().getInventory().clear());
List<User> onlinePlayers = new ArrayList<>();
List<User> offlinePlayers = new ArrayList<>();

for(User user : island.getMembers()) {

if (user.getUserRank() == -1) continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think this is needed, island.getMembers() only returns a list of the island members which doesnt include visitors


try{
user.getPlayer();
onlinePlayers.add(user);
} catch (Exception e) {
offlinePlayers.add(user);
}
}

if (IridiumSkyblock.getInstance().getConfiguration().clearEnderChestOnRegen) {
IridiumSkyblock.getInstance().getIslandManager().getMembersOnIsland(island).forEach(member ->
member.getPlayer().getEnderChest().clear());
for (User user : onlinePlayers) {
if (IridiumSkyblock.getInstance().getConfiguration().clearInventoryOnRegen) user.getPlayer().getInventory().clear();
if (IridiumSkyblock.getInstance().getConfiguration().clearEnderChestOnRegen) user.getPlayer().getEnderChest().clear();
}

for(User user : offlinePlayers) {

try {
File file = new File(Bukkit.getWorlds().get(0).getWorldFolder().getPath() + File.pathSeparator + "playerdata" + File.pathSeparator + user.getUuid() + ".dat");
NBTFile playerFile = new NBTFile(file);

if (IridiumSkyblock.getInstance().getConfiguration().clearInventoryOnRegen) {
NBTCompound compound = playerFile.getCompound("").getCompound("Inventory");
compound.clearNBT();
playerFile.save();
}

if (IridiumSkyblock.getInstance().getConfiguration().clearEnderChestOnRegen) {
NBTCompound compound = playerFile.getCompound("").getCompound("EnderItems");
compound.clearNBT();
playerFile.save();
}

} catch (IOException e) {
IridiumSkyblock.getInstance().getLogger().warning("Cannot mutate user: " + user.getName() + ". See stacktrace for details.");
IridiumSkyblock.getInstance().getLogger().warning(e.getMessage());
} catch (NullPointerException e) {
IridiumSkyblock.getInstance().getLogger().warning("Cannot mutate user: " + user.getName() + ". Either player or compound doesn't exist (See stacktrace for details).");
IridiumSkyblock.getInstance().getLogger().warning(e.getMessage());
}
Comment on lines +807 to +831
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate this... why cant you access an offline player's inventory (Talking to the physical embodiment of the Spigot API here, not you)

}
}

Expand Down
Loading