Skip to content

Commit 185f9e4

Browse files
author
Jan Kluka
committed
1.5
Updated AutoSellAPI to support SellRegions
1 parent cc6a4b2 commit 185f9e4

4 files changed

Lines changed: 124 additions & 9 deletions

File tree

src/main/java/dev/drawethree/xprison/api/autosell/XPrisonAutoSellAPI.java

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package dev.drawethree.xprison.api.autosell;
22

33
import com.cryptomorin.xseries.XMaterial;
4+
import dev.drawethree.xprison.api.autosell.model.SellRegion;
5+
import org.bukkit.Location;
46
import org.bukkit.block.Block;
57
import org.bukkit.entity.Player;
68
import org.bukkit.inventory.ItemStack;
79

10+
import java.util.Collection;
811
import java.util.List;
912

1013
/**
@@ -15,15 +18,15 @@ public interface XPrisonAutoSellAPI {
1518

1619

1720
/**
18-
* Gets the price of a specific item
21+
* Gets the global price of a specific item
1922
*
2023
* @param item the item to get the price for
2124
* @return the price of the item
2225
*/
2326
double getPriceForItem(ItemStack item);
2427

2528
/**
26-
* Gets the price for a given block.
29+
* Gets the global price for a given block.
2730
*
2831
* @param block the block to get the price for
2932
* @return the price of the block
@@ -47,25 +50,49 @@ public interface XPrisonAutoSellAPI {
4750
boolean hasAutoSellEnabled(Player p);
4851

4952
/**
50-
* Adds or updates the sell price for a specific material
53+
* Adds or updates the global sell price for a specific material
5154
*
5255
* @param material the material to set the sell price for
5356
* @param price the price at which the material will be sold
5457
*/
5558
void addSellPrice(XMaterial material, double price);
5659

5760
/**
58-
* Removes a material from being sellable in this region.
61+
* Removes a material from being sellable globally.
5962
*
6063
* @param material the material to remove from the sell price list
6164
*/
6265
void removeSellPrice(XMaterial material);
6366

6467
/**
65-
* Gets the sell price for a specific material in this region.
68+
* Gets the global sell price for a specific material.
6669
*
6770
* @param material the material to get the price for
6871
* @return the sell price of the material, or 0 if not sellable
6972
*/
7073
double getSellPriceForMaterial(XMaterial material);
74+
75+
/**
76+
* Gets the price of a specific item in a given sell region.
77+
*
78+
* @param region the sell region to check pricing in
79+
* @param item the item to get the price for
80+
* @return the price of the item in the specified region
81+
*/
82+
double getPriceForItem(SellRegion region, ItemStack item);
83+
84+
/**
85+
* Gets a collection of all loaded and active sell regions.
86+
*
87+
* @return a collection of all sell regions
88+
*/
89+
Collection<SellRegion> getSellRegions();
90+
91+
/**
92+
* Gets the sell region at a specified location.
93+
*
94+
* @param location the location to check
95+
* @return the sell region at the given location, or {@code null} if none exists there
96+
*/
97+
SellRegion getSellRegionAtLocation(Location location);
7198
}

src/main/java/dev/drawethree/xprison/api/autosell/events/XPrisonAutoSellEvent.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package dev.drawethree.xprison.api.autosell.events;
22

33
import dev.drawethree.xprison.api.autosell.model.AutoSellItemStack;
4+
import dev.drawethree.xprison.api.autosell.model.SellRegion;
45
import dev.drawethree.xprison.api.shared.events.player.XPrisonPlayerEvent;
56
import lombok.Getter;
67
import lombok.Setter;
78
import org.bukkit.entity.Player;
89
import org.bukkit.event.Cancellable;
910
import org.bukkit.event.HandlerList;
1011

12+
import javax.annotation.Nullable;
1113
import java.util.Map;
1214

1315
/**
@@ -22,6 +24,8 @@ public final class XPrisonAutoSellEvent extends XPrisonPlayerEvent implements Ca
2224

2325
@Setter
2426
private Map<AutoSellItemStack, Double> itemsToSell;
27+
@Nullable
28+
private final SellRegion region;
2529

2630
@Setter
2731
private boolean cancelled;
@@ -31,11 +35,13 @@ public final class XPrisonAutoSellEvent extends XPrisonPlayerEvent implements Ca
3135
*
3236
* @param player The player who mined the blocks and triggered auto-sell
3337
* @param itemsToSell A map of items to be sold with their respective prices
38+
* @param region The sell region where the blocks were mined, can be null
3439
*/
35-
public XPrisonAutoSellEvent(Player player, Map<AutoSellItemStack, Double> itemsToSell) {
40+
public XPrisonAutoSellEvent(Player player, Map<AutoSellItemStack, Double> itemsToSell, @Nullable SellRegion region) {
3641
super(player);
3742
this.player = player;
3843
this.itemsToSell = itemsToSell;
44+
this.region = region;
3945
}
4046

4147
/**

src/main/java/dev/drawethree/xprison/api/autosell/events/XPrisonSellAllEvent.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package dev.drawethree.xprison.api.autosell.events;
22

33
import dev.drawethree.xprison.api.autosell.model.AutoSellItemStack;
4+
import dev.drawethree.xprison.api.autosell.model.SellRegion;
45
import dev.drawethree.xprison.api.shared.events.player.XPrisonPlayerEvent;
56
import lombok.Getter;
67
import lombok.Setter;
78
import org.bukkit.entity.Player;
89
import org.bukkit.event.Cancellable;
910
import org.bukkit.event.HandlerList;
1011

12+
import javax.annotation.Nullable;
1113
import java.util.Map;
1214

1315
/**
@@ -24,7 +26,10 @@ public final class XPrisonSellAllEvent extends XPrisonPlayerEvent implements Can
2426
@Setter
2527
private Map<AutoSellItemStack, Double> itemsToSell;
2628

27-
@Getter
29+
@Nullable
30+
private final SellRegion region;
31+
32+
@Getter
2833
@Setter
2934
private boolean cancelled;
3035

@@ -33,12 +38,14 @@ public final class XPrisonSellAllEvent extends XPrisonPlayerEvent implements Can
3338
*
3439
* @param player The player performing the sell-all
3540
* @param itemsToSell A map of items to sell and their respective prices
41+
* @param region The sell region where the blocks were mined, can be null
3642
*/
37-
public XPrisonSellAllEvent(Player player, Map<AutoSellItemStack, Double> itemsToSell) {
43+
public XPrisonSellAllEvent(Player player, Map<AutoSellItemStack, Double> itemsToSell, @Nullable SellRegion region) {
3844
super(player);
3945
this.player = player;
4046
this.itemsToSell = itemsToSell;
41-
}
47+
this.region = region;
48+
}
4249

4350
/**
4451
* Gets the list of event handlers.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package dev.drawethree.xprison.api.autosell.model;
2+
3+
import com.cryptomorin.xseries.XMaterial;
4+
import org.bukkit.Location;
5+
import org.bukkit.World;
6+
import org.bukkit.entity.Player;
7+
import org.codemc.worldguardwrapper.region.IWrappedRegion;
8+
9+
/**
10+
* Represents a region where auto-selling blocks or items is allowed.
11+
* Contains methods to manage sell prices and permissions within the region.
12+
*/
13+
public interface SellRegion {
14+
15+
/**
16+
* Gets the WorldGuard region this SellRegion represents.
17+
*
18+
* @return the wrapped WorldGuard region
19+
*/
20+
IWrappedRegion getRegion();
21+
22+
/**
23+
* Gets the {@link World} where this region is located.
24+
*
25+
* @return the world of the region
26+
*/
27+
World getWorld();
28+
29+
/**
30+
* Gets the permission node required for a player to sell items in this region.
31+
*
32+
* @return the required permission string
33+
*/
34+
String getRequiredPermission();
35+
36+
/**
37+
* Adds or updates the sell price for a specific material in this region.
38+
*
39+
* @param material the material to set the sell price for
40+
* @param price the price at which the material will be sold
41+
*/
42+
void addSellPrice(XMaterial material, double price);
43+
44+
/**
45+
* Removes a material from being sellable in this region.
46+
*
47+
* @param material the material to remove from the sell price list
48+
*/
49+
void removeSellPrice(XMaterial material);
50+
51+
/**
52+
* Gets the sell price for a specific material in this region.
53+
*
54+
* @param material the material to get the price for
55+
* @return the sell price of the material, or 0 if not sellable
56+
*/
57+
double getSellPriceForMaterial(XMaterial material);
58+
59+
/**
60+
* Checks whether a given {@link Location} is inside this sell region.
61+
*
62+
* @param location the location to check
63+
* @return true if the location is inside the region, false otherwise
64+
*/
65+
boolean contains(Location location);
66+
67+
/**
68+
* Checks if the given player has permission to sell in this region.
69+
* This is based on {@link SellRegion#getRequiredPermission()}.
70+
*
71+
* @param player the player to check
72+
* @return true if the player can sell in the region, false otherwise
73+
*/
74+
boolean canPlayerSellInRegion(Player player);
75+
}

0 commit comments

Comments
 (0)