-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8a983ba
Showing
36 changed files
with
2,858 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target/ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# SimpleShopGUI | ||
|
||
**SimpleShopGUI** is a simple and user-friendly Minecraft shop plugin based on GUIs. The primary and current database is SQLite3, other providers are still not supported. | ||
|
||
The plugin requires one depedency, [**Vault**](https://www.spigotmc.org/resources/vault.34315/). | ||
|
||
## How to install | ||
Go to the [releases section](https://github.com/TFAGaming/SimpleShopGUI/releases), scroll down to find the version you want to use, click on **Assets** and then click on the **.jar** file. | ||
|
||
After the download completes, simply copy the **.jar** file and navigate to the plugins folder within your Minecraft server directory, and paste the file there. If your Minecraft server is currently running, you can use the command `/reload` to activate the plugin. However, for optimal performance, we advise stopping the server and then restarting it for a clean startup. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>simpleshopgui</groupId> | ||
<artifactId>simpleshopgui</artifactId> | ||
<version>1.0.0-prerelease-1</version> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<repositories> | ||
<!-- This adds the Spigot Maven repository to the build --> | ||
<repository> | ||
<id>spigot-repo</id> | ||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> | ||
</repository> | ||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.spigotmc</groupId> | ||
<artifactId>spigot-api</artifactId> | ||
<version>1.21-R0.1-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.MilkBowl</groupId> | ||
<artifactId>VaultAPI</artifactId> | ||
<version>1.7</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.postgresql</groupId> | ||
<artifactId>postgresql</artifactId> | ||
<version>42.7.4</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.xerial</groupId> | ||
<artifactId>sqlite-jdbc</artifactId> | ||
<version>3.45.2.0</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-clean-plugin</artifactId> | ||
<version>3.1.0</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<version>2.5.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<version>2.8.2</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package simpleshopgui; | ||
|
||
import java.sql.SQLException; | ||
|
||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import simpleshopgui.commands.ListedCommand; | ||
import simpleshopgui.commands.SellCommand; | ||
import simpleshopgui.commands.ShopCommand; | ||
import simpleshopgui.database.Database; | ||
import simpleshopgui.events.gui.NormalGUIListener; | ||
import simpleshopgui.events.gui.PaginationGUIListener; | ||
import simpleshopgui.plugins.Vault; | ||
import simpleshopgui.utils.console.Console; | ||
|
||
public class Plugin extends JavaPlugin { | ||
public static Database database; | ||
public static Vault vaultapi; | ||
public static FileConfiguration config; | ||
|
||
public void onEnable() { | ||
Console.pluginBanner(); | ||
Console.warning("Enabling the plugin..."); | ||
|
||
saveDefaultConfig(); | ||
|
||
vaultapi = new Vault(this); | ||
|
||
if (!Plugin.vaultapi.setupPermissions()) { | ||
Console.error("Failed to load permissions from Vault, disabling..."); | ||
disablePlugin(); | ||
return; | ||
} else { | ||
Console.info("Successfully loaded Vault permissions."); | ||
} | ||
|
||
if (!Plugin.vaultapi.setupEconomy()) { | ||
Console.error("Failed to load economy from Vault., disabling..."); | ||
disablePlugin(); | ||
return; | ||
} else { | ||
Console.info("Successfully loaded Vault economy."); | ||
} | ||
|
||
if (!getDataFolder().exists()) { | ||
getDataFolder().mkdirs(); | ||
} | ||
|
||
config = Plugin.getPlugin(Plugin.class).getConfig(); | ||
|
||
String jdbcUrl = getDataFolder().getAbsolutePath() + config.getString("database.path"); | ||
|
||
database = new Database(config.getString("database.provider"), jdbcUrl); | ||
|
||
try { | ||
database.getConnection(); | ||
database.prepareTables(); | ||
|
||
Console.info("Successfully connected to the database."); | ||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
Console.error("Failed to connect to the database, disabling..."); | ||
disablePlugin(); | ||
} | ||
|
||
getServer().getPluginManager().registerEvents(new NormalGUIListener(), this); | ||
getServer().getPluginManager().registerEvents(new PaginationGUIListener(), this); | ||
|
||
getCommand("shop").setExecutor(new ShopCommand()); | ||
getCommand("sell").setExecutor(new SellCommand()); | ||
getCommand("listed").setExecutor(new ListedCommand()); | ||
|
||
Console.info("The plugin is now enabled."); | ||
} | ||
|
||
public void onDisable() { | ||
Console.warning("Disabling the plugin..."); | ||
Console.info("The plugin is now disabled."); | ||
} | ||
|
||
public static String getVersion() { | ||
return "1.0.0-prerelease-1"; | ||
} | ||
|
||
private void disablePlugin() { | ||
getServer().getPluginManager().disablePlugin(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package simpleshopgui.commands; | ||
|
||
import java.util.List; | ||
|
||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.command.TabExecutor; | ||
import org.bukkit.entity.Player; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
import simpleshopgui.gui.ListedItemsGUI; | ||
|
||
public class ListedCommand implements TabExecutor { | ||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
if (sender instanceof Player) { | ||
Player player = (Player) sender; | ||
|
||
ListedItemsGUI.create(player); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) { | ||
return Lists.newArrayList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package simpleshopgui.commands; | ||
|
||
import java.util.List; | ||
|
||
import org.bukkit.Material; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.command.TabExecutor; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
import simpleshopgui.Plugin; | ||
import simpleshopgui.managers.ShopDatabaseManager; | ||
import simpleshopgui.utils.colors.ChatColorTranslator; | ||
import simpleshopgui.utils.shop.ShopUtils; | ||
|
||
public class SellCommand implements TabExecutor { | ||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
if (sender instanceof Player) { | ||
Player player = (Player) sender; | ||
|
||
ItemStack itemInHand = player.getInventory().getItemInMainHand(); | ||
|
||
if (itemInHand == null || itemInHand.getType() == Material.AIR) { | ||
player.sendMessage(ChatColorTranslator | ||
.translate(Plugin.config.getString("messages.commands.sell.no_item_in_hand"))); | ||
return true; | ||
} | ||
|
||
if (args.length == 0) { | ||
player.sendMessage(ChatColorTranslator | ||
.translate(Plugin.config.getString("messages.commands.sell.no_price_provided"))); | ||
return true; | ||
} | ||
|
||
try { | ||
if (ShopUtils.parseFromStringToDouble(args[0]) <= 0) { | ||
player.sendMessage(ChatColorTranslator | ||
.translate(Plugin.config.getString("messages.commands.sell.price_error"))); | ||
return true; | ||
} | ||
} catch (NumberFormatException err) { | ||
player.sendMessage(ChatColorTranslator | ||
.translate(Plugin.config.getString("messages.commands.sell.price_error"))); | ||
return true; | ||
} | ||
|
||
double price = ShopUtils.parseFromStringToDouble(args[0]); | ||
|
||
ItemStack itemStack = itemInHand.clone(); | ||
|
||
ShopDatabaseManager.addItemToShop(player, itemStack, price); | ||
|
||
player.getInventory().setItemInMainHand(new ItemStack(Material.AIR)); | ||
|
||
player.sendMessage(ChatColorTranslator | ||
.translate(Plugin.config.getString("messages.commands.sell.item_sold") | ||
.replace("%item_amount%", "" + itemStack.getAmount()) | ||
.replace("%item_name%", ShopUtils.userFriendlyItemName(itemStack.getType().name())))); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) { | ||
try { | ||
if (args.length == 1) { | ||
double parsed = ShopUtils.parseFromStringToDouble(args[0]); | ||
|
||
if (parsed <= 0) { | ||
return Lists.newArrayList(); | ||
} | ||
|
||
return Lists.newArrayList(ShopUtils.parseFromDoubleToString(parsed).replace(",", ".")); | ||
} | ||
|
||
return Lists.newArrayList(); | ||
} catch (NumberFormatException err) { | ||
return Lists.newArrayList(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package simpleshopgui.commands; | ||
|
||
import java.util.List; | ||
|
||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.command.TabExecutor; | ||
import org.bukkit.entity.Player; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
import simpleshopgui.gui.ShopGUI; | ||
|
||
public class ShopCommand implements TabExecutor { | ||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
if (sender instanceof Player) { | ||
Player player = (Player) sender; | ||
|
||
ShopGUI gui = new ShopGUI(player); | ||
|
||
gui.openInventory(); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) { | ||
return Lists.newArrayList(); | ||
} | ||
} |
Oops, something went wrong.