Remove API module
This commit is contained in:
parent
aeb6d79495
commit
5ccd5b6f0c
|
|
@ -1,23 +0,0 @@
|
||||||
plugins {
|
|
||||||
`maven-publish`
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
compileOnly("com.alttd:Galaxy-API:1.18.2-R0.1-SNAPSHOT")
|
|
||||||
}
|
|
||||||
|
|
||||||
publishing {
|
|
||||||
publications {
|
|
||||||
create<MavenPublication>("mavenJava") {
|
|
||||||
from(components["java"])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories{
|
|
||||||
maven {
|
|
||||||
name = "maven"
|
|
||||||
url = uri("https://repo.destro.xyz/snapshots")
|
|
||||||
credentials(PasswordCredentials::class)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
package com.alttd.playershops.api;
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public interface Shop { // TODO finish docs
|
|
||||||
|
|
||||||
String getOwnerName();
|
|
||||||
|
|
||||||
UUID getOwnerUUID();
|
|
||||||
|
|
||||||
ShopType getType();
|
|
||||||
|
|
||||||
Location getSignLocation();
|
|
||||||
|
|
||||||
Location getContainerLocation();
|
|
||||||
|
|
||||||
String getServer();
|
|
||||||
|
|
||||||
double getPrice();
|
|
||||||
|
|
||||||
void setPrice(double price);
|
|
||||||
|
|
||||||
int getAmount();
|
|
||||||
|
|
||||||
void setAmount(int amount);
|
|
||||||
|
|
||||||
double getBalance();
|
|
||||||
|
|
||||||
void setBalance(double balance);
|
|
||||||
|
|
||||||
ItemStack getItemStack();
|
|
||||||
|
|
||||||
void setItemStack(ItemStack itemStack);
|
|
||||||
|
|
||||||
ItemStack getSecondaryItem();
|
|
||||||
|
|
||||||
void setSecondaryItem(ItemStack itemStack);
|
|
||||||
|
|
||||||
boolean isInitialized();
|
|
||||||
}
|
|
||||||
|
|
@ -1,79 +0,0 @@
|
||||||
package com.alttd.playershops.api;
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public interface ShopHandler { // TODO finish docs
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the shop at a given location
|
|
||||||
*
|
|
||||||
* @param location Location of the shop
|
|
||||||
* @return Shop at the given location or <b>null</b> if no shop is found there
|
|
||||||
*/
|
|
||||||
Shop getShop(Location location);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the shop at a given location
|
|
||||||
*
|
|
||||||
* @param signLocation Location of the shopSign
|
|
||||||
* @return Shop at the given location or <b>null</b> if no shop is found there
|
|
||||||
*/
|
|
||||||
Shop getShopBySignLocation(Location signLocation);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether there is a shop at a given location
|
|
||||||
* @param location Location to check
|
|
||||||
* @return Whether there is a shop at the given location
|
|
||||||
*/
|
|
||||||
boolean isShop(Location location);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a collection of all loaded shops
|
|
||||||
*
|
|
||||||
* This collection is safe to use for looping over and removing shops.
|
|
||||||
*
|
|
||||||
* @return Read-only collection of all shops
|
|
||||||
*/
|
|
||||||
Collection<Shop> getShops();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a player's custom shop limit
|
|
||||||
*
|
|
||||||
* @param uuid The uuid linked to this player
|
|
||||||
* @param limit The new maximum amount of shops this player can have
|
|
||||||
*/
|
|
||||||
void addPlayerLimit(UUID uuid, int limit);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the maximum amount of shops this player is allowed to have
|
|
||||||
*
|
|
||||||
* @param uuid The uuid linked to this player
|
|
||||||
* @return The limit of shops for this player
|
|
||||||
*/
|
|
||||||
int getShopLimit(UUID uuid);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks wether this block is valid to be used as a shop
|
|
||||||
*
|
|
||||||
* @param block the block to check
|
|
||||||
* @return true if this block can be a shop
|
|
||||||
*/
|
|
||||||
boolean isShopMaterial(Block block);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all the shops owned by a player
|
|
||||||
*
|
|
||||||
* @param uuid The uuid linked to this player
|
|
||||||
* @return List of shops this player owns
|
|
||||||
*/
|
|
||||||
List<Shop> getShops(UUID uuid);
|
|
||||||
|
|
||||||
ArrayList<Material> getShopMaterials();
|
|
||||||
}
|
|
||||||
|
|
@ -2,15 +2,15 @@ import java.io.ByteArrayOutputStream
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("java")
|
id("java")
|
||||||
|
id("net.minecrell.plugin-yml.bukkit") version "0.5.1"
|
||||||
|
id("com.github.johnrengelman.shadow") version "7.1.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
group = "com.alttd.playershops"
|
group = "com.alttd.playershops"
|
||||||
version = "1.0-SNAPSHOT"
|
version = "1.0-SNAPSHOT"
|
||||||
description = "Player Shop plugin for Altitude."
|
description = "Player Shop plugin for Altitude."
|
||||||
}
|
|
||||||
|
|
||||||
subprojects {
|
|
||||||
apply<JavaLibraryPlugin>()
|
apply<JavaLibraryPlugin>()
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
|
@ -30,6 +30,17 @@ subprojects {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly("com.alttd:Galaxy-API:1.18.2-R0.1-SNAPSHOT")
|
||||||
|
compileOnly("com.github.milkbowl:VaultAPI:1.7") {
|
||||||
|
exclude("org.bukkit","bukkit")
|
||||||
|
}
|
||||||
|
compileOnly("com.github.TechFortress:GriefPrevention:16.17.1")
|
||||||
|
|
||||||
|
compileOnly("org.projectlombok:lombok:1.18.24")
|
||||||
|
annotationProcessor("org.projectlombok:lombok:1.18.24")
|
||||||
|
}
|
||||||
|
|
||||||
fun gitCommit(): String {
|
fun gitCommit(): String {
|
||||||
val os = ByteArrayOutputStream()
|
val os = ByteArrayOutputStream()
|
||||||
project.exec {
|
project.exec {
|
||||||
|
|
@ -37,4 +48,13 @@ fun gitCommit(): String {
|
||||||
standardOutput = os
|
standardOutput = os
|
||||||
}
|
}
|
||||||
return String(os.toByteArray()).trim()
|
return String(os.toByteArray()).trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
bukkit {
|
||||||
|
name = rootProject.name
|
||||||
|
main = "$group.${rootProject.name}"
|
||||||
|
version = "${rootProject.version}-${gitCommit()}"
|
||||||
|
apiVersion = "1.18"
|
||||||
|
authors = listOf("destro174")
|
||||||
|
depend = listOf("Vault")
|
||||||
}
|
}
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
import java.io.ByteArrayOutputStream
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
id("java")
|
|
||||||
id("net.minecrell.plugin-yml.bukkit") version "0.5.1"
|
|
||||||
id("com.github.johnrengelman.shadow") version "7.1.0"
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation(project(":api"))
|
|
||||||
|
|
||||||
compileOnly("com.alttd:Galaxy-API:1.18.2-R0.1-SNAPSHOT")
|
|
||||||
compileOnly("com.github.milkbowl:VaultAPI:1.7") {
|
|
||||||
exclude("org.bukkit","bukkit")
|
|
||||||
}
|
|
||||||
compileOnly("com.github.TechFortress:GriefPrevention:16.17.1")
|
|
||||||
|
|
||||||
compileOnly("org.projectlombok:lombok:1.18.24")
|
|
||||||
annotationProcessor("org.projectlombok:lombok:1.18.24")
|
|
||||||
}
|
|
||||||
|
|
||||||
bukkit {
|
|
||||||
name = rootProject.name
|
|
||||||
main = "$group.${rootProject.name}"
|
|
||||||
version = "${rootProject.version}-${gitCommit()}"
|
|
||||||
apiVersion = "1.18"
|
|
||||||
authors = listOf("destro174")
|
|
||||||
depend = listOf("Vault")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun gitCommit(): String {
|
|
||||||
val os = ByteArrayOutputStream()
|
|
||||||
project.exec {
|
|
||||||
commandLine = "git rev-parse --short HEAD".split(" ")
|
|
||||||
standardOutput = os
|
|
||||||
}
|
|
||||||
return String(os.toByteArray()).trim()
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks {
|
|
||||||
|
|
||||||
shadowJar {
|
|
||||||
archiveFileName.set("${rootProject.name}-${project.version}.jar")
|
|
||||||
}
|
|
||||||
|
|
||||||
build {
|
|
||||||
dependsOn(shadowJar)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -21,5 +21,3 @@ pluginManagement {
|
||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
include("api")
|
|
||||||
include("plugin")
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
package com.alttd.playershops;
|
package com.alttd.playershops;
|
||||||
|
|
||||||
import com.alttd.playershops.api.ShopHandler;
|
import com.alttd.playershops.config.Config;
|
||||||
import com.alttd.playershops.config.MessageConfig;
|
import com.alttd.playershops.config.MessageConfig;
|
||||||
|
import com.alttd.playershops.handler.ShopHandler;
|
||||||
import com.alttd.playershops.listener.PlayerListener;
|
import com.alttd.playershops.listener.PlayerListener;
|
||||||
import com.alttd.playershops.listener.ShopListener;
|
import com.alttd.playershops.listener.ShopListener;
|
||||||
import com.alttd.playershops.config.Config;
|
|
||||||
import com.alttd.playershops.handler.ShopHandlerImpl;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
@ -37,7 +36,7 @@ public class PlayerShops extends JavaPlugin {
|
||||||
registerListeners();
|
registerListeners();
|
||||||
registerCommands();
|
registerCommands();
|
||||||
|
|
||||||
shopHandler = new ShopHandlerImpl(instance);
|
shopHandler = new ShopHandler(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean setupEconomy() {
|
private boolean setupEconomy() {
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.alttd.playershops.config;
|
package com.alttd.playershops.config;
|
||||||
|
|
||||||
import com.alttd.galaxy.configuration.AbstractConfiguration;
|
import com.alttd.galaxy.configuration.AbstractConfiguration;
|
||||||
import com.alttd.playershops.api.ShopType;
|
import com.alttd.playershops.shop.ShopType;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.alttd.playershops.config;
|
package com.alttd.playershops.config;
|
||||||
|
|
||||||
import com.alttd.galaxy.configuration.AbstractConfiguration;
|
import com.alttd.galaxy.configuration.AbstractConfiguration;
|
||||||
import com.alttd.playershops.api.ShopType;
|
import com.alttd.playershops.shop.ShopType;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.alttd.playershops.config;
|
package com.alttd.playershops.config;
|
||||||
|
|
||||||
import com.alttd.galaxy.configuration.AbstractConfiguration;
|
import com.alttd.galaxy.configuration.AbstractConfiguration;
|
||||||
import com.alttd.playershops.api.ShopType;
|
import com.alttd.playershops.shop.ShopType;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
package com.alttd.playershops.database;
|
package com.alttd.playershops.database;
|
||||||
|
|
||||||
import com.alttd.playershops.api.Shop;
|
|
||||||
import com.alttd.playershops.api.ShopType;
|
|
||||||
import com.alttd.playershops.shop.AbstractShop;
|
import com.alttd.playershops.shop.AbstractShop;
|
||||||
|
import com.alttd.playershops.shop.ShopType;
|
||||||
import com.alttd.playershops.utils.AMath;
|
import com.alttd.playershops.utils.AMath;
|
||||||
import com.alttd.playershops.utils.Logger;
|
import com.alttd.playershops.utils.Logger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
@ -63,7 +62,7 @@ public class ShopQueries {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Shop loadShop(int id) {
|
public static AbstractShop loadShop(int id) {
|
||||||
String sql = "SELECT * FROM shops WHERE id = ?";
|
String sql = "SELECT * FROM shops WHERE id = ?";
|
||||||
try {
|
try {
|
||||||
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
||||||
|
|
@ -78,15 +77,15 @@ public class ShopQueries {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Shop> loadShops() {
|
public static List<AbstractShop> loadShops() {
|
||||||
String sql = "SELECT * FROM shops";
|
String sql = "SELECT * FROM shops";
|
||||||
ArrayList<Shop> shops = new ArrayList<>();
|
ArrayList<AbstractShop> shops = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
|
||||||
|
|
||||||
ResultSet resultSet = statement.executeQuery();
|
ResultSet resultSet = statement.executeQuery();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
Shop shop = shopFromResultSet(resultSet);
|
AbstractShop shop = shopFromResultSet(resultSet);
|
||||||
if (shop == null) {
|
if (shop == null) {
|
||||||
Logger.warn("Tried to load a shop but failed [" + resultSet + "]");
|
Logger.warn("Tried to load a shop but failed [" + resultSet + "]");
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -105,7 +104,7 @@ public class ShopQueries {
|
||||||
* @return A shop
|
* @return A shop
|
||||||
* @throws SQLException if data is missing or formatted incorrectly
|
* @throws SQLException if data is missing or formatted incorrectly
|
||||||
*/
|
*/
|
||||||
private static Shop shopFromResultSet(ResultSet resultSet) throws SQLException {
|
private static AbstractShop shopFromResultSet(ResultSet resultSet) throws SQLException {
|
||||||
int id = resultSet.getInt("id");
|
int id = resultSet.getInt("id");
|
||||||
String ownerName = resultSet.getString("owner_name");
|
String ownerName = resultSet.getString("owner_name");
|
||||||
UUID ownerUuid = UUID.fromString(resultSet.getString("owner_uuid"));
|
UUID ownerUuid = UUID.fromString(resultSet.getString("owner_uuid"));
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.alttd.playershops.api.events;
|
package com.alttd.playershops.events;
|
||||||
|
|
||||||
import com.alttd.playershops.api.Shop;
|
import com.alttd.playershops.shop.AbstractShop;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
@ -9,7 +9,7 @@ public class PlayerCreateShopEvent extends ShopEvent {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final Player player;
|
private final Player player;
|
||||||
|
|
||||||
public PlayerCreateShopEvent(Player player, Shop shop) {
|
public PlayerCreateShopEvent(Player player, AbstractShop shop) {
|
||||||
super(shop);
|
super(shop);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.alttd.playershops.api.events;
|
package com.alttd.playershops.events;
|
||||||
|
|
||||||
import com.alttd.playershops.api.Shop;
|
import com.alttd.playershops.shop.AbstractShop;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
@ -10,7 +10,7 @@ public class PlayerDestroyShopEvent extends ShopEvent {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final Player player;
|
private final Player player;
|
||||||
|
|
||||||
public PlayerDestroyShopEvent(Player player, Shop shop) {
|
public PlayerDestroyShopEvent(Player player, AbstractShop shop) {
|
||||||
super(shop);
|
super(shop);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.alttd.playershops.api.events;
|
package com.alttd.playershops.events;
|
||||||
|
|
||||||
import com.alttd.playershops.api.Shop;
|
import com.alttd.playershops.shop.AbstractShop;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
@ -10,7 +10,7 @@ public class PlayerExchangeShopEvent extends ShopEvent {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final Player player;
|
private final Player player;
|
||||||
|
|
||||||
public PlayerExchangeShopEvent(Player player, Shop shop) {
|
public PlayerExchangeShopEvent(Player player, AbstractShop shop) {
|
||||||
super(shop);
|
super(shop);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.alttd.playershops.api.events;
|
package com.alttd.playershops.events;
|
||||||
|
|
||||||
import com.alttd.playershops.api.Shop;
|
import com.alttd.playershops.shop.AbstractShop;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
@ -10,7 +10,7 @@ public class PlayerInitializeShopEvent extends ShopEvent {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final Player player;
|
private final Player player;
|
||||||
|
|
||||||
public PlayerInitializeShopEvent(Player player, Shop shop) {
|
public PlayerInitializeShopEvent(Player player, AbstractShop shop) {
|
||||||
super(shop);
|
super(shop);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.alttd.playershops.api.events;
|
package com.alttd.playershops.events;
|
||||||
|
|
||||||
import com.alttd.playershops.api.Shop;
|
import com.alttd.playershops.shop.AbstractShop;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
|
@ -8,7 +8,7 @@ public class ShopBalanceChangeEvent extends ShopEvent {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final ChangeReason changeReason;
|
private final ChangeReason changeReason;
|
||||||
|
|
||||||
public ShopBalanceChangeEvent(Shop shop, ChangeReason reason) {
|
public ShopBalanceChangeEvent(AbstractShop shop, ChangeReason reason) {
|
||||||
super(shop);
|
super(shop);
|
||||||
this.changeReason = reason;
|
this.changeReason = reason;
|
||||||
}
|
}
|
||||||
|
|
@ -1,19 +1,19 @@
|
||||||
package com.alttd.playershops.api.events;
|
package com.alttd.playershops.events;
|
||||||
|
|
||||||
import com.alttd.playershops.api.Shop;
|
import com.alttd.playershops.shop.AbstractShop;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
public abstract class ShopEvent extends Event implements Cancellable {
|
public abstract class ShopEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
private final Shop shop;
|
private final AbstractShop shop;
|
||||||
|
|
||||||
public ShopEvent(Shop shop) {
|
public ShopEvent(AbstractShop shop) {
|
||||||
this.shop = shop;
|
this.shop = shop;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Shop getShop() {
|
public AbstractShop getShop() {
|
||||||
return shop;
|
return shop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2,8 +2,9 @@ package com.alttd.playershops.handler;
|
||||||
|
|
||||||
import com.alttd.playershops.PlayerShops;
|
import com.alttd.playershops.PlayerShops;
|
||||||
import com.alttd.playershops.config.Config;
|
import com.alttd.playershops.config.Config;
|
||||||
import com.alttd.playershops.api.Shop;
|
import com.alttd.playershops.events.PlayerCreateShopEvent;
|
||||||
import com.alttd.playershops.api.ShopHandler;
|
import com.alttd.playershops.shop.AbstractShop;
|
||||||
|
import com.alttd.playershops.shop.ShopType;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
@ -12,21 +13,22 @@ import org.bukkit.Material;
|
||||||
import org.bukkit.Tag;
|
import org.bukkit.Tag;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class ShopHandlerImpl implements ShopHandler {
|
public class ShopHandler {
|
||||||
|
|
||||||
private final PlayerShops plugin;
|
private final PlayerShops plugin;
|
||||||
@Getter
|
@Getter
|
||||||
private final Object2IntMap<UUID> shopBuildLimits;
|
private final Object2IntMap<UUID> shopBuildLimits;
|
||||||
@Getter
|
@Getter
|
||||||
private final Map<Location, Shop> shopLocation;
|
private final Map<Location, AbstractShop> shopLocation;
|
||||||
@Getter
|
@Getter
|
||||||
private final ArrayList<Material> shopMaterials;
|
private final ArrayList<Material> shopMaterials;
|
||||||
|
|
||||||
public ShopHandlerImpl(PlayerShops instance) {
|
public ShopHandler(PlayerShops instance) {
|
||||||
plugin = instance;
|
plugin = instance;
|
||||||
shopLocation = new ConcurrentHashMap<>();
|
shopLocation = new ConcurrentHashMap<>();
|
||||||
shopBuildLimits = new Object2IntOpenHashMap<>();
|
shopBuildLimits = new Object2IntOpenHashMap<>();
|
||||||
|
|
@ -34,7 +36,7 @@ public class ShopHandlerImpl implements ShopHandler {
|
||||||
shopMaterials = new ArrayList<>(); // TODO move into parent method where materials are loaded in.
|
shopMaterials = new ArrayList<>(); // TODO move into parent method where materials are loaded in.
|
||||||
}
|
}
|
||||||
|
|
||||||
public Shop getShop(Location location) {
|
public AbstractShop getShop(Location location) {
|
||||||
Location newLocation = new Location(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
Location newLocation = new Location(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||||
|
|
||||||
return shopLocation.get(newLocation);
|
return shopLocation.get(newLocation);
|
||||||
|
|
@ -44,7 +46,7 @@ public class ShopHandlerImpl implements ShopHandler {
|
||||||
return getShop(location) != null;
|
return getShop(location) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Shop> getShops() {
|
public Collection<AbstractShop> getShops() {
|
||||||
return Collections.unmodifiableCollection(shopLocation.values());
|
return Collections.unmodifiableCollection(shopLocation.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,24 +69,24 @@ public class ShopHandlerImpl implements ShopHandler {
|
||||||
return shopMaterials.contains(block.getType());
|
return shopMaterials.contains(block.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Shop> getShops(UUID uuid) {
|
public List<AbstractShop> getShops(UUID uuid) {
|
||||||
List<Shop> shops = new ArrayList<>();
|
List<AbstractShop> shops = new ArrayList<>();
|
||||||
for (Shop shop : shopLocation.values()) {
|
for (AbstractShop shop : shopLocation.values()) {
|
||||||
if (shop.getOwnerUUID().equals(uuid))
|
if (shop.getOwnerUUID().equals(uuid))
|
||||||
shops.add(shop);
|
shops.add(shop);
|
||||||
}
|
}
|
||||||
return shops;
|
return shops;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Shop getShopBySignLocation(Location signLocation) {
|
public AbstractShop getShopBySignLocation(Location signLocation) {
|
||||||
for (Shop shop : shopLocation.values()) {
|
for (AbstractShop shop : shopLocation.values()) {
|
||||||
if (shop.getSignLocation().equals(signLocation))
|
if (shop.getSignLocation().equals(signLocation))
|
||||||
return shop;
|
return shop;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Shop getShopNearBlock(Block block) {
|
public AbstractShop getShopNearBlock(Block block) {
|
||||||
BlockFace[] faces = {BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST};
|
BlockFace[] faces = {BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST};
|
||||||
for (BlockFace face : faces) {
|
for (BlockFace face : faces) {
|
||||||
if (this.isShopMaterial(block.getRelative(face))) {
|
if (this.isShopMaterial(block.getRelative(face))) {
|
||||||
|
|
@ -96,4 +98,15 @@ public class ShopHandlerImpl implements ShopHandler {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AbstractShop createShop(Location signLocation, Player player, double price, int amount, ShopType shopType) {
|
||||||
|
AbstractShop shop = AbstractShop.create(signLocation, player.getUniqueId(), price, amount, shopType);
|
||||||
|
|
||||||
|
PlayerCreateShopEvent playerCreateShopEvent = new PlayerCreateShopEvent(player, shop);
|
||||||
|
plugin.getServer().getPluginManager().callEvent(playerCreateShopEvent);
|
||||||
|
|
||||||
|
if(playerCreateShopEvent.isCancelled())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return shop;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
package com.alttd.playershops.listener;
|
package com.alttd.playershops.listener;
|
||||||
|
|
||||||
import com.alttd.playershops.PlayerShops;
|
import com.alttd.playershops.PlayerShops;
|
||||||
import com.alttd.playershops.api.Shop;
|
|
||||||
import com.alttd.playershops.api.ShopHandler;
|
|
||||||
import com.alttd.playershops.config.Config;
|
import com.alttd.playershops.config.Config;
|
||||||
import com.alttd.playershops.config.MessageConfig;
|
import com.alttd.playershops.config.MessageConfig;
|
||||||
|
import com.alttd.playershops.handler.ShopHandler;
|
||||||
|
import com.alttd.playershops.shop.AbstractShop;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
|
|
@ -68,7 +68,7 @@ public class PlayerListener extends EventListener {
|
||||||
|
|
||||||
if (!(block.getState() instanceof Sign)) return;
|
if (!(block.getState() instanceof Sign)) return;
|
||||||
|
|
||||||
Shop shop = plugin.getShopHandler().getShop(block.getLocation());
|
AbstractShop shop = plugin.getShopHandler().getShop(block.getLocation());
|
||||||
if(shop == null) return;
|
if(shop == null) return;
|
||||||
|
|
||||||
if(shop.isInitialized()) event.setCancelled(true);
|
if(shop.isInitialized()) event.setCancelled(true);
|
||||||
|
|
@ -101,7 +101,7 @@ public class PlayerListener extends EventListener {
|
||||||
if (!signLineString.equalsIgnoreCase(Config.shopCreationWord))
|
if (!signLineString.equalsIgnoreCase(Config.shopCreationWord))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Shop shop = shopHandler.getShop(bRelative.getLocation());
|
AbstractShop shop = shopHandler.getShop(bRelative.getLocation());
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if(shop != null) {
|
if(shop != null) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
@ -109,7 +109,6 @@ public class PlayerListener extends EventListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UUID playerUUID = player.getUniqueId();
|
UUID playerUUID = player.getUniqueId();
|
||||||
if (!player.hasPermission("shop.create")) {
|
if (!player.hasPermission("shop.create")) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.alttd.playershops.listener;
|
package com.alttd.playershops.listener;
|
||||||
|
|
||||||
import com.alttd.playershops.PlayerShops;
|
import com.alttd.playershops.PlayerShops;
|
||||||
import com.alttd.playershops.api.Shop;
|
import com.alttd.playershops.shop.AbstractShop;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Tag;
|
import org.bukkit.Tag;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
|
@ -25,7 +25,7 @@ public class ShopListener extends EventListener {
|
||||||
// This might be heavy when tnt is chained, would it be better to expand the unbreakable block api in galaxy and use that?
|
// This might be heavy when tnt is chained, would it be better to expand the unbreakable block api in galaxy and use that?
|
||||||
// No need for slow bukkit events eating up cpu and memory
|
// No need for slow bukkit events eating up cpu and memory
|
||||||
Iterator<Block> blockIterator = event.blockList().iterator();
|
Iterator<Block> blockIterator = event.blockList().iterator();
|
||||||
Shop shop = null;
|
AbstractShop shop = null;
|
||||||
while (blockIterator.hasNext()) {
|
while (blockIterator.hasNext()) {
|
||||||
|
|
||||||
Block block = blockIterator.next();
|
Block block = blockIterator.next();
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package com.alttd.playershops.shop;
|
package com.alttd.playershops.shop;
|
||||||
|
|
||||||
import com.alttd.playershops.api.Shop;
|
|
||||||
import com.alttd.playershops.api.ShopType;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
@ -12,7 +10,7 @@ import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public abstract class AbstractShop implements Shop {
|
public abstract class AbstractShop {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private int id;
|
private int id;
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package com.alttd.playershops.shop;
|
package com.alttd.playershops.shop;
|
||||||
|
|
||||||
import com.alttd.playershops.api.ShopType;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package com.alttd.playershops.shop;
|
package com.alttd.playershops.shop;
|
||||||
|
|
||||||
import com.alttd.playershops.api.ShopType;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package com.alttd.playershops.shop;
|
package com.alttd.playershops.shop;
|
||||||
|
|
||||||
import com.alttd.playershops.api.ShopType;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package com.alttd.playershops.shop;
|
package com.alttd.playershops.shop;
|
||||||
|
|
||||||
import com.alttd.playershops.api.ShopType;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package com.alttd.playershops.api;
|
package com.alttd.playershops.shop;
|
||||||
|
|
||||||
public enum ShopType {
|
public enum ShopType {
|
||||||
|
|
||||||
SELL,
|
SELL,
|
||||||
BUY,
|
BUY,
|
||||||
GAMBLE,
|
GAMBLE,
|
||||||
|
|
@ -11,5 +10,4 @@ public enum ShopType {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name().toLowerCase();
|
return name().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user