Skip to content

Commit

Permalink
PhatLoots v5.6.6
Browse files Browse the repository at this point in the history
- Properly support dynamic maps in BattleArena
  • Loading branch information
Redned235 committed Aug 25, 2024
1 parent 633d1b9 commit 30e02a0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
val supportedVersions = listOf("1.20", "1.20.1", "1.20.2", "1.20.3", "1.20.4", "1.20.5", "1.20.6", "1.21")

group = "com.codisimus.plugins"
version = "5.6.5"
version = "5.6.6"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

class BattleArenaListener implements Listener {
private static final ArenaOptionType<BooleanArenaOption> SHUFFLE_LOOT = ArenaOptionType.create("shuffle-loot", BooleanArenaOption::new);
public class BattleArenaListener implements Listener {
public static final ArenaOptionType<BooleanArenaOption> SHUFFLE_LOOT = ArenaOptionType.create("shuffle-loot", BooleanArenaOption::new);

@EventHandler
public void onLoot(PlayerLootEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@

import com.codisimus.plugins.phatloots.PhatLoot;
import com.codisimus.plugins.phatloots.PhatLootChest;
import com.codisimus.plugins.phatloots.loot.LootBundle;
import org.battleplugins.arena.Arena;
import org.battleplugins.arena.ArenaPlayer;
import org.battleplugins.arena.competition.Competition;
import org.battleplugins.arena.competition.LiveCompetition;
import org.battleplugins.arena.competition.map.MapType;
import org.battleplugins.arena.competition.map.options.Bounds;
import org.battleplugins.arena.event.action.EventAction;
import org.battleplugins.arena.options.types.BooleanArenaOption;
import org.battleplugins.arena.resolver.Resolvable;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
Expand All @@ -37,18 +48,58 @@ public void postProcess(Arena arena, Competition<?> competition, Resolvable reso
return;
}

for (PhatLootChest chest : PhatLootChest.getChests()) {
if (!chest.isInWorld(liveCompetition.getMap().getWorld())) {
continue;
}
if (liveCompetition.getMap().getType() == MapType.STATIC) {
for (PhatLootChest chest : PhatLootChest.getChests()) {
if (!chest.isInWorld(liveCompetition.getMap().getWorld())) {
continue;
}

Location location = chest.getLocation();
if (!bounds.isInside(location)) {
continue;
}

Location location = chest.getLocation();
if (!bounds.isInside(location)) {
continue;
for (PhatLoot phatLoot : chest.getLinkedPhatLoots()) {
phatLoot.reset(chest.getBlock());
}
}
} else {
// For dynamic maps, we don't want to actually set a loot table since
// the world is only dynamic and will be removed. Instead, locate all the
// loot tables in the parent world, and if we are dealing with a container
// (i.e. a chest), we roll for the loot and populate the container
for (PhatLootChest chest : PhatLootChest.getChests()) {
if (!chest.isInWorld(liveCompetition.getMap().getParentWorld())) {
continue;
}

Location parentLocation = chest.getLocation();
if (!bounds.isInside(parentLocation)) {
continue;
}

Location mapLocation = new Location(liveCompetition.getMap().getWorld(), parentLocation.getX(), parentLocation.getY(), parentLocation.getZ());
Block block = mapLocation.getBlock();
BlockState state = block.getState();
if ((!(state instanceof InventoryHolder inventoryHolder))) {
continue;
}

Inventory inventory = inventoryHolder.getInventory();

for (PhatLoot phatLoot : chest.getLinkedPhatLoots()) {
LootBundle bundle = phatLoot.rollForLoot();
for (ItemStack item : bundle.getItemList()) {
inventory.addItem(item);
}
}

for (PhatLoot phatLoot : chest.getLinkedPhatLoots()) {
phatLoot.reset(chest.getBlock());
boolean shuffleLoot = liveCompetition.option(BattleArenaListener.SHUFFLE_LOOT).map(BooleanArenaOption::isEnabled).orElse(false);
if (shuffleLoot) {
List<ItemStack> contents = Arrays.asList(inventory.getContents());
Collections.shuffle(contents);
inventory.setContents(contents.toArray(ItemStack[]::new));
}
}
}
}
Expand Down

0 comments on commit 30e02a0

Please sign in to comment.