Remove API module

This commit is contained in:
Len 2022-08-07 17:28:38 +02:00
parent aeb6d79495
commit 5ccd5b6f0c
34 changed files with 88 additions and 263 deletions

View File

@ -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)
}
}
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -2,15 +2,15 @@ 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"
}
allprojects {
group = "com.alttd.playershops"
version = "1.0-SNAPSHOT"
description = "Player Shop plugin for Altitude."
}
subprojects {
apply<JavaLibraryPlugin>()
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 {
val os = ByteArrayOutputStream()
project.exec {
@ -37,4 +48,13 @@ fun gitCommit(): String {
standardOutput = os
}
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")
}

View File

@ -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)
}
}

View File

@ -21,5 +21,3 @@ pluginManagement {
gradlePluginPortal()
}
}
include("api")
include("plugin")

View File

@ -1,11 +1,10 @@
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.handler.ShopHandler;
import com.alttd.playershops.listener.PlayerListener;
import com.alttd.playershops.listener.ShopListener;
import com.alttd.playershops.config.Config;
import com.alttd.playershops.handler.ShopHandlerImpl;
import lombok.Getter;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
@ -37,7 +36,7 @@ public class PlayerShops extends JavaPlugin {
registerListeners();
registerCommands();
shopHandler = new ShopHandlerImpl(instance);
shopHandler = new ShopHandler(instance);
}
private boolean setupEconomy() {

View File

@ -1,7 +1,7 @@
package com.alttd.playershops.config;
import com.alttd.galaxy.configuration.AbstractConfiguration;
import com.alttd.playershops.api.ShopType;
import com.alttd.playershops.shop.ShopType;
import java.io.File;
import java.util.HashMap;

View File

@ -1,7 +1,7 @@
package com.alttd.playershops.config;
import com.alttd.galaxy.configuration.AbstractConfiguration;
import com.alttd.playershops.api.ShopType;
import com.alttd.playershops.shop.ShopType;
import java.util.HashMap;

View File

@ -1,7 +1,7 @@
package com.alttd.playershops.config;
import com.alttd.galaxy.configuration.AbstractConfiguration;
import com.alttd.playershops.api.ShopType;
import com.alttd.playershops.shop.ShopType;
import java.util.HashMap;

View File

@ -1,8 +1,7 @@
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.ShopType;
import com.alttd.playershops.utils.AMath;
import com.alttd.playershops.utils.Logger;
import org.bukkit.Bukkit;
@ -63,7 +62,7 @@ public class ShopQueries {
return false;
}
public static Shop loadShop(int id) {
public static AbstractShop loadShop(int id) {
String sql = "SELECT * FROM shops WHERE id = ?";
try {
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
@ -78,15 +77,15 @@ public class ShopQueries {
return null;
}
public static List<Shop> loadShops() {
public static List<AbstractShop> loadShops() {
String sql = "SELECT * FROM shops";
ArrayList<Shop> shops = new ArrayList<>();
ArrayList<AbstractShop> shops = new ArrayList<>();
try {
PreparedStatement statement = Database.getDatabase().getConnection().prepareStatement(sql);
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
Shop shop = shopFromResultSet(resultSet);
AbstractShop shop = shopFromResultSet(resultSet);
if (shop == null) {
Logger.warn("Tried to load a shop but failed [" + resultSet + "]");
continue;
@ -105,7 +104,7 @@ public class ShopQueries {
* @return A shop
* @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");
String ownerName = resultSet.getString("owner_name");
UUID ownerUuid = UUID.fromString(resultSet.getString("owner_uuid"));

View File

@ -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.event.HandlerList;
import org.jetbrains.annotations.NotNull;
@ -9,7 +9,7 @@ public class PlayerCreateShopEvent extends ShopEvent {
private static final HandlerList handlers = new HandlerList();
private final Player player;
public PlayerCreateShopEvent(Player player, Shop shop) {
public PlayerCreateShopEvent(Player player, AbstractShop shop) {
super(shop);
this.player = player;
}

View File

@ -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.event.HandlerList;
import org.jetbrains.annotations.NotNull;
@ -10,7 +10,7 @@ public class PlayerDestroyShopEvent extends ShopEvent {
private static final HandlerList handlers = new HandlerList();
private final Player player;
public PlayerDestroyShopEvent(Player player, Shop shop) {
public PlayerDestroyShopEvent(Player player, AbstractShop shop) {
super(shop);
this.player = player;
}

View File

@ -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.event.HandlerList;
import org.jetbrains.annotations.NotNull;
@ -10,7 +10,7 @@ public class PlayerExchangeShopEvent extends ShopEvent {
private static final HandlerList handlers = new HandlerList();
private final Player player;
public PlayerExchangeShopEvent(Player player, Shop shop) {
public PlayerExchangeShopEvent(Player player, AbstractShop shop) {
super(shop);
this.player = player;
}

View File

@ -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.event.HandlerList;
import org.jetbrains.annotations.NotNull;
@ -10,7 +10,7 @@ public class PlayerInitializeShopEvent extends ShopEvent {
private static final HandlerList handlers = new HandlerList();
private final Player player;
public PlayerInitializeShopEvent(Player player, Shop shop) {
public PlayerInitializeShopEvent(Player player, AbstractShop shop) {
super(shop);
this.player = player;
}

View File

@ -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.jetbrains.annotations.NotNull;
@ -8,7 +8,7 @@ public class ShopBalanceChangeEvent extends ShopEvent {
private static final HandlerList handlers = new HandlerList();
private final ChangeReason changeReason;
public ShopBalanceChangeEvent(Shop shop, ChangeReason reason) {
public ShopBalanceChangeEvent(AbstractShop shop, ChangeReason reason) {
super(shop);
this.changeReason = reason;
}

View File

@ -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.Event;
public abstract class ShopEvent extends Event implements Cancellable {
private boolean cancelled;
private final Shop shop;
private final AbstractShop shop;
public ShopEvent(Shop shop) {
public ShopEvent(AbstractShop shop) {
this.shop = shop;
}
public Shop getShop() {
public AbstractShop getShop() {
return shop;
}

View File

@ -2,8 +2,9 @@ package com.alttd.playershops.handler;
import com.alttd.playershops.PlayerShops;
import com.alttd.playershops.config.Config;
import com.alttd.playershops.api.Shop;
import com.alttd.playershops.api.ShopHandler;
import com.alttd.playershops.events.PlayerCreateShopEvent;
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.Object2IntOpenHashMap;
import lombok.Getter;
@ -12,21 +13,22 @@ import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class ShopHandlerImpl implements ShopHandler {
public class ShopHandler {
private final PlayerShops plugin;
@Getter
private final Object2IntMap<UUID> shopBuildLimits;
@Getter
private final Map<Location, Shop> shopLocation;
private final Map<Location, AbstractShop> shopLocation;
@Getter
private final ArrayList<Material> shopMaterials;
public ShopHandlerImpl(PlayerShops instance) {
public ShopHandler(PlayerShops instance) {
plugin = instance;
shopLocation = new ConcurrentHashMap<>();
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.
}
public Shop getShop(Location location) {
public AbstractShop getShop(Location location) {
Location newLocation = new Location(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
return shopLocation.get(newLocation);
@ -44,7 +46,7 @@ public class ShopHandlerImpl implements ShopHandler {
return getShop(location) != null;
}
public Collection<Shop> getShops() {
public Collection<AbstractShop> getShops() {
return Collections.unmodifiableCollection(shopLocation.values());
}
@ -67,24 +69,24 @@ public class ShopHandlerImpl implements ShopHandler {
return shopMaterials.contains(block.getType());
}
public List<Shop> getShops(UUID uuid) {
List<Shop> shops = new ArrayList<>();
for (Shop shop : shopLocation.values()) {
public List<AbstractShop> getShops(UUID uuid) {
List<AbstractShop> shops = new ArrayList<>();
for (AbstractShop shop : shopLocation.values()) {
if (shop.getOwnerUUID().equals(uuid))
shops.add(shop);
}
return shops;
}
public Shop getShopBySignLocation(Location signLocation) {
for (Shop shop : shopLocation.values()) {
public AbstractShop getShopBySignLocation(Location signLocation) {
for (AbstractShop shop : shopLocation.values()) {
if (shop.getSignLocation().equals(signLocation))
return shop;
}
return null;
}
public Shop getShopNearBlock(Block block) {
public AbstractShop getShopNearBlock(Block block) {
BlockFace[] faces = {BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST};
for (BlockFace face : faces) {
if (this.isShopMaterial(block.getRelative(face))) {
@ -96,4 +98,15 @@ public class ShopHandlerImpl implements ShopHandler {
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;
}
}

View File

@ -1,10 +1,10 @@
package com.alttd.playershops.listener;
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.MessageConfig;
import com.alttd.playershops.handler.ShopHandler;
import com.alttd.playershops.shop.AbstractShop;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
@ -68,7 +68,7 @@ public class PlayerListener extends EventListener {
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.isInitialized()) event.setCancelled(true);
@ -101,7 +101,7 @@ public class PlayerListener extends EventListener {
if (!signLineString.equalsIgnoreCase(Config.shopCreationWord))
return;
Shop shop = shopHandler.getShop(bRelative.getLocation());
AbstractShop shop = shopHandler.getShop(bRelative.getLocation());
Player player = event.getPlayer();
if(shop != null) {
event.setCancelled(true);
@ -109,7 +109,6 @@ public class PlayerListener extends EventListener {
return;
}
UUID playerUUID = player.getUniqueId();
if (!player.hasPermission("shop.create")) {
event.setCancelled(true);

View File

@ -1,7 +1,7 @@
package com.alttd.playershops.listener;
import com.alttd.playershops.PlayerShops;
import com.alttd.playershops.api.Shop;
import com.alttd.playershops.shop.AbstractShop;
import org.bukkit.Location;
import org.bukkit.Tag;
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?
// No need for slow bukkit events eating up cpu and memory
Iterator<Block> blockIterator = event.blockList().iterator();
Shop shop = null;
AbstractShop shop = null;
while (blockIterator.hasNext()) {
Block block = blockIterator.next();

View File

@ -1,7 +1,5 @@
package com.alttd.playershops.shop;
import com.alttd.playershops.api.Shop;
import com.alttd.playershops.api.ShopType;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
@ -12,7 +10,7 @@ import org.bukkit.inventory.ItemStack;
import java.util.UUID;
public abstract class AbstractShop implements Shop {
public abstract class AbstractShop {
@Getter
private int id;

View File

@ -1,6 +1,5 @@
package com.alttd.playershops.shop;
import com.alttd.playershops.api.ShopType;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;

View File

@ -1,6 +1,5 @@
package com.alttd.playershops.shop;
import com.alttd.playershops.api.ShopType;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;

View File

@ -1,6 +1,5 @@
package com.alttd.playershops.shop;
import com.alttd.playershops.api.ShopType;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;

View File

@ -1,6 +1,5 @@
package com.alttd.playershops.shop;
import com.alttd.playershops.api.ShopType;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;

View File

@ -1,7 +1,6 @@
package com.alttd.playershops.api;
package com.alttd.playershops.shop;
public enum ShopType {
SELL,
BUY,
GAMBLE,
@ -11,5 +10,4 @@ public enum ShopType {
public String toString() {
return name().toLowerCase();
}
}