Added a way to highlight shops that are low on stock
This commit is contained in:
parent
55cb197b0b
commit
59ef4c23ea
|
|
@ -7,12 +7,15 @@ import com.alttd.playershops.commands.Subcommand;
|
|||
import com.alttd.playershops.shop.PlayerShop;
|
||||
import com.alttd.playershops.utils.ShopUtil;
|
||||
import com.alttd.playershops.utils.Util;
|
||||
import com.destroystokyo.paper.ParticleBuilder;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
|
|
@ -76,12 +79,62 @@ public class CheckStockCommand implements Subcommand {
|
|||
}
|
||||
List<Stock> stockList = checkStock(player.getLocation().getBlockX(), player.getLocation().getBlockZ(), radius, player);
|
||||
sendStockMessage(player, stockList);
|
||||
highlightLowStock(player, stockList);
|
||||
return true;
|
||||
}
|
||||
|
||||
//Stole this code from AlttdUtility by ___Kappa___ and reworked it slightly
|
||||
private void highlightLowStock(Player player, List<Stock> stockList) {
|
||||
ParticleBuilder particleBuilder = new ParticleBuilder(Particle.REDSTONE);
|
||||
particleBuilder.color(255, 255, 255);
|
||||
particleBuilder.receivers(player);
|
||||
particleBuilder.count(3);
|
||||
|
||||
List<Location[]> collect = stockList.stream().map(stock -> {
|
||||
Location centerOfBlock = stock.shopCenter;
|
||||
Location[] cornersOfBlock = new Location[8];
|
||||
cornersOfBlock[0] = centerOfBlock.clone().add(0.5, 0.5, 0.5);
|
||||
cornersOfBlock[1] = centerOfBlock.clone().add(0.5, 0.5, -0.5);
|
||||
cornersOfBlock[2] = centerOfBlock.clone().add(-0.5, 0.5, 0.5);
|
||||
cornersOfBlock[3] = centerOfBlock.clone().add(-0.5, 0.5, -0.5);
|
||||
cornersOfBlock[4] = centerOfBlock.clone().add(0.5, -0.5, 0.5);
|
||||
cornersOfBlock[5] = centerOfBlock.clone().add(0.5, -0.5, -0.5);
|
||||
cornersOfBlock[6] = centerOfBlock.clone().add(-0.5, -0.5, 0.5);
|
||||
cornersOfBlock[7] = centerOfBlock.clone().add(-0.5, -0.5, -0.5);
|
||||
return cornersOfBlock;
|
||||
}).toList();
|
||||
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
new ParticleSpawnTask(collect, particleBuilder).runTaskLater(PlayerShops.getInstance(), i * 10);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ParticleSpawnTask extends BukkitRunnable {
|
||||
|
||||
private final List<Location[]> chestLocations;
|
||||
private final ParticleBuilder particleBuilder;
|
||||
|
||||
public ParticleSpawnTask(List<Location[]> chestLocations, ParticleBuilder particleBuilder) {
|
||||
this.chestLocations = chestLocations;
|
||||
this.particleBuilder = particleBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (Location[] particleLocations : chestLocations) {
|
||||
for (Location location : particleLocations) {
|
||||
particleBuilder.location(location);
|
||||
particleBuilder.spawn();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//End stolen code
|
||||
|
||||
/**
|
||||
* @param x Coordinate to center search on
|
||||
* @param z Coordinate to center search on
|
||||
* @param x Coordinate to shopCenter search on
|
||||
* @param z Coordinate to shopCenter search on
|
||||
* @param radius Range to check in
|
||||
* @param caller Player who is checking for stock, can only see the stock from their shops unless they have base_perm.checkstock.bypass
|
||||
* @return A list of Stock that the player is allowed to see
|
||||
|
|
@ -90,12 +143,13 @@ public class CheckStockCommand implements Subcommand {
|
|||
List<PlayerShop> shops = PlayerShops.getInstance().getShopHandler().getShopsInRadius(x, z, radius);
|
||||
Stream<PlayerShop> playerShopStream = shops.stream();
|
||||
if (minimumStock != -1)
|
||||
playerShopStream = playerShopStream.filter(shop -> shop.getRemainingStock() / shop.getAmount() < minimumStock);
|
||||
playerShopStream = playerShopStream.filter(shop -> shop.getRemainingStock() < minimumStock);
|
||||
if (!caller.hasPermission(PlayerShopCommand.BASE_PERM + ".checkstock.any"))
|
||||
playerShopStream = playerShopStream.filter(shop -> shop.getOwnerUUID().equals(caller.getUniqueId()));
|
||||
return playerShopStream.map(shop -> {
|
||||
Location signLocation = shop.getSignLocation();
|
||||
return new Stock(shop.getRemainingStock() / shop.getAmount(),
|
||||
return new Stock(shop.getRemainingStock(),
|
||||
shop.getShopLocation().toCenterLocation(),
|
||||
signLocation.getBlockX(),
|
||||
signLocation.getBlockY(),
|
||||
signLocation.getBlockZ(),
|
||||
|
|
@ -130,5 +184,5 @@ public class CheckStockCommand implements Subcommand {
|
|||
player.sendMessage(component);
|
||||
}
|
||||
|
||||
private record Stock(int stock, int x, int y, int z, Component itemNameComponent) {}
|
||||
private record Stock(int stock, Location shopCenter, int x, int y, int z, Component itemNameComponent) {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user