Skip to content

Commit

Permalink
feat: 1.3.0 (beta)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuhtin committed Feb 27, 2022
1 parent e9b3797 commit 64698fc
Show file tree
Hide file tree
Showing 14 changed files with 286 additions and 56 deletions.
22 changes: 18 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ plugins {
id 'net.minecrell.plugin-yml.bukkit' version '0.3.0'
}

def getGitHash = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}

group 'com.nextplugins'
version '1.2.0'
version "1.3.0-${getGitHash}"

tasks.build.dependsOn('shadowJar')

Expand All @@ -23,14 +32,15 @@ repositories {
}

dependencies {
compileOnly "org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT"
compileOnly "org.spigotmc:spigot-api:1.18.1-R0.1-SNAPSHOT"
compileOnly "com.github.MilkBowl:VaultAPI:1.7"

implementation 'com.github.Yuhtin:update-checker:1.2'
implementation 'com.github.HenryFabio:inventory-api:2.0.3'
implementation 'com.github.HenryFabio:sql-provider:9561f20fd2'
implementation 'com.github.tr7zw.Item-NBT-API:item-nbt-api:2.9.0'

implementation 'com.github.SaiintBrisson.command-framework:bukkit:1.2.0'

implementation "com.google.inject:guice:5.0.1"

def lombok = "org.projectlombok:lombok:1.18.16"
Expand All @@ -49,8 +59,9 @@ bukkit {
}

shadowJar {
archiveName("${project.name}.jar")
archiveName("${project.name}-${project.version}.jar")

relocate 'com.yuhtin.updatechecker', 'com.nextplugins.nextmarket.libs.updatechecker'
relocate 'com.henryfabio.minecraft.inventoryapi', 'com.nextplugins.nextmarket.libs.inventoryapi'

relocate 'com.henryfabio.sqlprovider', 'com.nextplugins.nextmarket.libs.sqlprovider'
Expand All @@ -62,6 +73,9 @@ shadowJar {
relocate 'com.google.common', 'com.nextplugins.nextmarket.libs.guice.common'
relocate 'com.google.inject', 'com.nextplugins.nextmarket.libs.guice.inject'
relocate 'com.google.thirdparty', 'com.nextplugins.nextmarket.libs.guice.thirdparty'

relocate 'de.tr7zw.changeme.nbtapi', 'com.nextplugins.nextmarket.libs.nbtapi'
relocate 'de.tr7zw.annotations', 'com.nextplugins.nextmarket.libs.annotations'
}

compileJava {
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/nextplugins/nextmarket/NextMarket.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
import com.nextplugins.nextmarket.listener.ProductBuyListener;
import com.nextplugins.nextmarket.listener.ProductCreateListener;
import com.nextplugins.nextmarket.listener.ProductRemoveListener;
import com.nextplugins.nextmarket.listener.UpdateCheckerListener;
import com.nextplugins.nextmarket.manager.CategoryManager;
import com.nextplugins.nextmarket.manager.ProductManager;
import com.nextplugins.nextmarket.registry.InventoryButtonRegistry;
import com.nextplugins.nextmarket.registry.InventoryRegistry;
import com.nextplugins.nextmarket.util.MessageUtils;
import com.yuhtin.updatechecker.UpdateChecker;
import lombok.Getter;
import lombok.val;
import me.saiintbrisson.bukkit.command.BukkitFrame;
import me.saiintbrisson.minecraft.command.message.MessageType;
import org.bukkit.Bukkit;
import org.bukkit.configuration.Configuration;
import org.bukkit.event.Listener;
Expand All @@ -46,8 +50,13 @@ public final class NextMarket extends JavaPlugin {

@Getter private Configuration categoriesConfig;

@Getter private UpdateChecker updateChecker;

@Override
public void onLoad() {
updateChecker = new UpdateChecker(this, "NextPlugins");
updateChecker.check();

saveDefaultConfig();
}

Expand All @@ -56,6 +65,18 @@ public void onEnable() {
getLogger().info("Iniciando carregamento do plugin.");

val loadTime = Stopwatch.createStarted();
if (updateChecker.canUpdate()) {
val lastRelease = updateChecker.getLastRelease();

getLogger().info("");
getLogger().info("[NextUpdate] ATENÇÃO!");
getLogger().info("[NextUpdate] Você está usando uma versão antiga do NextMarket!");
getLogger().info("[NextUpdate] Nova versão: " + lastRelease.getVersion());
getLogger().info("[NextUpdate] Baixe aqui: " + lastRelease.getDownloadURL());
getLogger().info("");
} else {
getLogger().info("[NextUpdate] Olá! Vim aqui revisar se a versão do NextMarket está atualizada, e pelo visto sim! Obrigado por usar nossos plugins!");
}

this.categoriesConfig = ConfigurationLoader.of("categories.yml").saveResource().create();
InventoryManager.enable(this);
Expand All @@ -79,6 +100,7 @@ public void onEnable() {
registerListener(ProductCreateListener.class);
registerListener(ProductRemoveListener.class);
registerListener(ProductBuyListener.class);
registerListener(UpdateCheckerListener.class);

MetricProvider.of(this).register();

Expand All @@ -94,6 +116,7 @@ public static NextMarket getInstance() {

private void enableCommandFrame() {
BukkitFrame bukkitFrame = new BukkitFrame(this);
bukkitFrame.getMessageHolder().setMessage(MessageType.INCORRECT_USAGE, MessageUtils.colored("&cUso incorreto, use: &f{usage}&c."));
bukkitFrame.registerCommands(
injector.getInstance(MarketCommand.class)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ public final class MetricProvider {
private final JavaPlugin plugin;

public void register() {

System.setProperty("bstats.relocatecheck", "false");

new MetricsConnector(plugin, 9933);
plugin.getLogger().info("Métrica de uso habilitada com sucesso.");

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public final class Category {

private final String id;
private final boolean trashTable;

private final String displayName;
private final List<String> description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public final class CategoryConfiguration {
private final String inventoryTitle;
private final List<MaterialData> materials;
private final List<String> names;
private final List<String> nbts;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.inject.Inject;
import com.henryfabio.minecraft.inventoryapi.viewer.property.ViewerPropertyMap;
import com.nextplugins.nextmarket.NextMarket;
import com.nextplugins.nextmarket.api.event.ProductCreateEvent;
import com.nextplugins.nextmarket.api.model.category.Category;
import com.nextplugins.nextmarket.api.model.product.Product;
Expand All @@ -12,13 +13,16 @@
import com.nextplugins.nextmarket.manager.ProductManager;
import com.nextplugins.nextmarket.registry.InventoryRegistry;
import com.nextplugins.nextmarket.storage.ProductStorage;
import com.nextplugins.nextmarket.util.MessageUtils;
import com.nextplugins.nextmarket.util.NumberUtils;
import lombok.val;
import me.saiintbrisson.minecraft.command.annotation.Command;
import me.saiintbrisson.minecraft.command.annotation.Optional;
import me.saiintbrisson.minecraft.command.command.Context;
import me.saiintbrisson.minecraft.command.target.CommandTarget;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public final class MarketCommand {
Expand All @@ -41,6 +45,34 @@ public void marketCommand(Context<Player> context) {
context.sendMessage(MessageValue.get(MessageValue::commandMessage).toArray(new String[]{}));
}

@Command(
name = "mercado.info",
permission = "nextmarket.admin",
target = CommandTarget.ALL,
async = true
)
public void infoCommand(Context<CommandSender> context) {
val updateChecker = NextMarket.getInstance().getUpdateChecker();

double itemCount = categoryManager.getCategoryMap().values()
.stream()
.map(Category::getConfiguration)
.map(config -> config.getMaterials().size() + config.getNbts().size() + config.getNames().size())
.mapToInt(Integer::intValue)
.sum();

context.sendMessage("");
context.sendMessage(MessageUtils.colored(" &6&lNextMarket &f- &eInformações"));
context.sendMessage("");
context.sendMessage(MessageUtils.colored(" &fCategorias: &e" + categoryManager.getCategoryMap().size()));
context.sendMessage(MessageUtils.colored(" &fItens registrados: &e" + itemCount));
context.sendMessage(MessageUtils.colored(" &fVersão atual: &e" + updateChecker.getCurrentVersion()));

if (!MessageUtils.sendUpdateMessage(context.getSender())) {
context.sendMessage("");
}
}

@Command(
name = "mercado.ver",
aliases = {"show"},
Expand Down Expand Up @@ -82,6 +114,7 @@ public void personalMarketCommand(Context<Player> context) {
@Command(
name = "mercado.vender",
aliases = {"sell"},
usage = "/mercado vender <valor> [jogador]",
async = true
)
public void sellMarketCommand(Context<Player> context, String priceText, @Optional String destination) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.nextplugins.nextmarket.listener;

import com.nextplugins.nextmarket.NextMarket;
import com.nextplugins.nextmarket.util.MessageUtils;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

public final class UpdateCheckerListener implements Listener {

@EventHandler
public void onJoin(PlayerJoinEvent event) {
if (!event.getPlayer().hasPermission("nextmarket.admin")) return;
Bukkit.getScheduler().runTaskLater(NextMarket.getInstance(), () -> MessageUtils.sendUpdateMessage(event.getPlayer()), 60L);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import com.nextplugins.nextmarket.api.model.category.Category;
import com.nextplugins.nextmarket.api.model.product.MaterialData;
import com.nextplugins.nextmarket.parser.CategoryParser;
import de.tr7zw.changeme.nbtapi.NBTItem;
import lombok.val;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.util.LinkedHashMap;
import java.util.Map;
Expand All @@ -20,16 +22,21 @@
public final class CategoryManager {

private final Map<String, Category> categoryMap = new LinkedHashMap<>();
private Category trashTableCategory;

@Inject @Named("categories") private Configuration categoriesConfiguration;

@Inject
private CategoryParser categoryParser;
@Inject private CategoryParser categoryParser;

public void init() {
ConfigurationSection categoriesSection = categoriesConfiguration.getConfigurationSection("categories");
if (categoriesSection == null) return;

for (String categoryId : categoriesSection.getKeys(false)) {
registerCategory(categoryParser.parse(categoriesSection.getConfigurationSection(categoryId)));
val category = categoryParser.parse(categoriesSection.getConfigurationSection(categoryId));
if (category == null) continue;

if (category.isTrashTable()) trashTableCategory = category;
registerCategory(category);
}
}

Expand All @@ -41,24 +48,36 @@ public Optional<Category> findCategoryById(String id) {
return Optional.ofNullable(this.categoryMap.get(id));
}

public Optional<Category> findCategory(ItemStack itemStack) {
public Optional<Category> findCategory(@NotNull ItemStack itemStack) {
val materialData = MaterialData.of(itemStack, false);
val itemMeta = itemStack.getItemMeta();
val nbtItem = new NBTItem(itemStack);

for (Category category : categoryMap.values()) {
for (String name : category.getConfiguration().getNames()) {
val itemMeta = itemStack.getItemMeta();
if (itemMeta != null && itemMeta.getDisplayName() != null && itemMeta.getDisplayName().equalsIgnoreCase(name)) {
if (category.isTrashTable()) continue;

val configuration = category.getConfiguration();
for (String nbt : configuration.getNbts()) {
if (nbtItem.hasKey(nbt)) {
return Optional.of(category);
}
}

val materialData = MaterialData.of(itemStack, false);
for (MaterialData material : category.getConfiguration().getMaterials()) {
for (MaterialData material : configuration.getMaterials()) {
if (material.equals(materialData)) {
return Optional.of(category);
}
}

for (String name : configuration.getNames()) {
if (itemMeta != null && itemMeta.getDisplayName() != null && itemMeta.getDisplayName().equalsIgnoreCase(name)) {
return Optional.of(category);
}
}
}

return Optional.empty();
if (trashTableCategory == null) return Optional.empty();
return Optional.of(trashTableCategory);
}

public Map<String, Category> getCategoryMap() {
Expand Down
Loading

0 comments on commit 64698fc

Please sign in to comment.