mirror of
https://github.com/kiranhart/Auction-House.git
synced 2025-01-07 12:47:36 +01:00
Added a lot of stuff, added listing the /ah gui w/pagination & a bunch of other stuff
This commit is contained in:
parent
ad9ca39152
commit
f0ba148672
8
.idea/artifacts/Auction_House_jar.xml
Normal file
8
.idea/artifacts/Auction_House_jar.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="Auction House:jar">
|
||||
<output-path>$USER_HOME$/Desktop/Plugin Testing/Pepper API/plugins</output-path>
|
||||
<root id="archive" name="Auction House.jar">
|
||||
<element id="module-output" name="Auction House" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
13
.idea/libraries/Maven__commons_io_commons_io_2_4.xml
Normal file
13
.idea/libraries/Maven__commons_io_commons_io_2_4.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Maven: commons-io:commons-io:2.4">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/commons-io/commons-io/2.4/commons-io-2.4.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/commons-io/commons-io/2.4/commons-io-2.4-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/commons-io/commons-io/2.4/commons-io-2.4-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
@ -0,0 +1,13 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Maven: javax.persistence:persistence-api:1.0">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/javax/persistence/persistence-api/1.0/persistence-api-1.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/javax/persistence/persistence-api/1.0/persistence-api-1.0-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/javax/persistence/persistence-api/1.0/persistence-api-1.0-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
13
.idea/libraries/Maven__net_milkbowl_vault_VaultAPI_1_6.xml
Normal file
13
.idea/libraries/Maven__net_milkbowl_vault_VaultAPI_1_6.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Maven: net.milkbowl.vault:VaultAPI:1.6">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/net/milkbowl/vault/VaultAPI/1.6/VaultAPI-1.6.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/net/milkbowl/vault/VaultAPI/1.6/VaultAPI-1.6-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/net/milkbowl/vault/VaultAPI/1.6/VaultAPI-1.6-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
13
.idea/libraries/Maven__org_avaje_ebean_2_8_1.xml
Normal file
13
.idea/libraries/Maven__org_avaje_ebean_2_8_1.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Maven: org.avaje:ebean:2.8.1">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/avaje/ebean/2.8.1/ebean-2.8.1.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/avaje/ebean/2.8.1/ebean-2.8.1-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/avaje/ebean/2.8.1/ebean-2.8.1-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
@ -0,0 +1,13 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Maven: org.bukkit:bukkit:1.9-R0.1-SNAPSHOT">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/bukkit/bukkit/1.9-R0.1-SNAPSHOT/bukkit-1.9-R0.1-20160330.160319-146.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/bukkit/bukkit/1.9-R0.1-SNAPSHOT/bukkit-1.9-R0.1-20160330.160319-146-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/bukkit/bukkit/1.9-R0.1-SNAPSHOT/bukkit-1.9-R0.1-20160330.160319-146-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
@ -31,5 +31,9 @@
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.19" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.12-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-io:commons-io:2.4" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: net.milkbowl.vault:VaultAPI:1.6" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.9-R0.1-SNAPSHOT" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.avaje:ebean:2.8.1" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.persistence:persistence-api:1.0" level="project" />
|
||||
</component>
|
||||
</module>
|
10
pom.xml
10
pom.xml
@ -63,6 +63,10 @@
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@ -77,5 +81,11 @@
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -1,15 +1,82 @@
|
||||
package com.shadebyte.auctionhouse;
|
||||
|
||||
import com.massivestats.MassiveStats;
|
||||
import com.shadebyte.auctionhouse.auction.AuctionItem;
|
||||
import com.shadebyte.auctionhouse.cmds.CommandManager;
|
||||
import com.shadebyte.auctionhouse.events.AGUIListener;
|
||||
import com.shadebyte.auctionhouse.util.ConfigWrapper;
|
||||
import com.shadebyte.auctionhouse.util.Debugger;
|
||||
import com.shadebyte.auctionhouse.util.Locale;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class Core extends JavaPlugin {
|
||||
|
||||
//Instance Variable
|
||||
private static Core instance;
|
||||
|
||||
//Instance for the command management system
|
||||
private CommandManager commandManager;
|
||||
|
||||
//Economy
|
||||
private static Economy economy = null;
|
||||
|
||||
//Settings
|
||||
private Settings settings = null;
|
||||
|
||||
//Data config instance from the config wrapper
|
||||
private ConfigWrapper data;
|
||||
|
||||
//Language system instance
|
||||
private Locale locale;
|
||||
|
||||
//Storage
|
||||
public List<AuctionItem> auctionItems;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
instance = this;
|
||||
|
||||
//Locales
|
||||
Locale.init(this);
|
||||
Locale.saveDefaultLocale("en_US");
|
||||
this.locale = Locale.getLocale(this.getConfig().getString("Locale", "en_US"));
|
||||
|
||||
settings = new Settings();
|
||||
|
||||
initDataFiles();
|
||||
|
||||
commandManager = new CommandManager();
|
||||
commandManager.initialize();
|
||||
|
||||
initEvents();
|
||||
initStorage();
|
||||
|
||||
try {
|
||||
MassiveStats stats = new MassiveStats(this);
|
||||
stats.setListenerDisabled(false);
|
||||
} catch (Exception e) {
|
||||
Debugger.report(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Bukkit.getServer().getScheduler().runTaskTimer(this, () -> {
|
||||
auctionItems.forEach(auctionItem -> auctionItem.updateTime(5));
|
||||
auctionItems.forEach(auctionItem -> {
|
||||
if (auctionItem.getTime() <= 0) auctionItems.remove(auctionItem);
|
||||
});
|
||||
}, 0, 20 * 5);
|
||||
} catch (Exception e) {
|
||||
//Debugger.report(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -18,7 +85,58 @@ public final class Core extends JavaPlugin {
|
||||
instance = null;
|
||||
}
|
||||
|
||||
private boolean setupEconomy() {
|
||||
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
return false;
|
||||
}
|
||||
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
return false;
|
||||
}
|
||||
economy = rsp.getProvider();
|
||||
return economy != null;
|
||||
}
|
||||
|
||||
private void initDataFiles() {
|
||||
getConfig().options().copyDefaults(true);
|
||||
saveDefaultConfig();
|
||||
data = new ConfigWrapper(this, "", "data.yml");
|
||||
if (!new File(this.getDataFolder(), "data.yml").exists()) {
|
||||
data.getConfig().createSection("data");
|
||||
}
|
||||
data.saveConfig();
|
||||
}
|
||||
|
||||
private void initEvents() {
|
||||
PluginManager pm = Bukkit.getPluginManager();
|
||||
pm.registerEvents(new AGUIListener(), this);
|
||||
}
|
||||
|
||||
private void initStorage() {
|
||||
auctionItems = new ArrayList<>();
|
||||
}
|
||||
|
||||
public static Core getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public CommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public ConfigWrapper getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public static Economy getEconomy() {
|
||||
return economy;
|
||||
}
|
||||
|
||||
public Settings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
|
22
src/main/java/com/shadebyte/auctionhouse/Settings.java
Normal file
22
src/main/java/com/shadebyte/auctionhouse/Settings.java
Normal file
@ -0,0 +1,22 @@
|
||||
package com.shadebyte.auctionhouse;
|
||||
|
||||
import com.shadebyte.auctionhouse.api.enums.Lang;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/6/2018
|
||||
* Time Created: 6:46 PM
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public class Settings {
|
||||
|
||||
private String prefix;
|
||||
|
||||
public Settings() {
|
||||
prefix = Core.getInstance().getLocale().getMessage(Lang.PREFIX.getNode()) + " ";
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
}
|
@ -1,5 +1,17 @@
|
||||
package com.shadebyte.auctionhouse.api;
|
||||
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
import com.shadebyte.auctionhouse.api.enums.Version;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/6/2018
|
||||
@ -7,4 +19,71 @@ package com.shadebyte.auctionhouse.api;
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public class AuctionAPI {
|
||||
|
||||
private static AuctionAPI instance;
|
||||
|
||||
private AuctionAPI() {
|
||||
}
|
||||
|
||||
public static AuctionAPI getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new AuctionAPI();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ItemStack createConfigItem(String node) {
|
||||
String[] rawItem = Core.getInstance().getConfig().getString(node + ".item").split(":");
|
||||
ItemStack stack = new ItemStack(Material.valueOf(rawItem[0].toUpperCase()), 1, Short.parseShort(rawItem[1]));
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', Core.getInstance().getConfig().getString(node + ".name")));
|
||||
List<String> lore = new ArrayList<>();
|
||||
Core.getInstance().getConfig().getStringList(node + ".lore").forEach(s -> lore.add(ChatColor.translateAlternateColorCodes('&', s)));
|
||||
meta.setLore(lore);
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public int availableSlots(PlayerInventory inventory) {
|
||||
int count = 0;
|
||||
for (ItemStack i : inventory) {
|
||||
if (i == null) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static ItemStack getItemInHand(Player player) {
|
||||
if (Version.getCurrentVersion().getCurrentVersionInteger() >= Version.v1_9_R1.getCurrentVersionInteger()) {
|
||||
return player.getInventory().getItemInMainHand();
|
||||
} else {
|
||||
return player.getItemInHand();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void setItemInHand(Player player, ItemStack item) {
|
||||
if (Version.getCurrentVersion().getCurrentVersionInteger() >= Version.v1_9_R1.getCurrentVersionInteger()) {
|
||||
player.getInventory().setItemInMainHand(item);
|
||||
} else {
|
||||
player.setItemInHand(item);
|
||||
}
|
||||
}
|
||||
|
||||
public String timeLeft(int totalSecs) {
|
||||
int hours = totalSecs / 3600;
|
||||
int minutes = (totalSecs % 3600) / 60;
|
||||
int seconds = totalSecs % 60;
|
||||
return String.format("%02d:%02d:%02d", hours, minutes, seconds);
|
||||
}
|
||||
|
||||
public ItemStack fill(String name) {
|
||||
ItemStack stack = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 1);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&6&l" + name));
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
@ -7,4 +7,23 @@ package com.shadebyte.auctionhouse.api.enums;
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public enum Lang {
|
||||
|
||||
PREFIX("prefix"),
|
||||
NO_PERMISSION("nopermission"),
|
||||
PLAYERS_ONLY("playersonly"),
|
||||
|
||||
INVALID_SUBCOMMAND("cmd.invalid"),
|
||||
CMD_SELL("cmd.sell"),
|
||||
|
||||
;
|
||||
|
||||
String node;
|
||||
|
||||
Lang(String node) {
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public String getNode() {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,9 @@ package com.shadebyte.auctionhouse.api.enums;
|
||||
*/
|
||||
public enum Permissions {
|
||||
|
||||
BASE("AuctionHouse");
|
||||
BASE("AuctionHouse"),
|
||||
MAX_AUCTIONS(BASE.getNode() + ".maxauctions"),
|
||||
;
|
||||
|
||||
private String node;
|
||||
|
||||
|
@ -1,5 +1,18 @@
|
||||
package com.shadebyte.auctionhouse.auction;
|
||||
|
||||
import com.shadebyte.auctionhouse.api.AuctionAPI;
|
||||
import com.shadebyte.auctionhouse.util.NBTEditor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.bukkit.ChatColor.translateAlternateColorCodes;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/6/2018
|
||||
@ -7,4 +20,135 @@ package com.shadebyte.auctionhouse.auction;
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public class AuctionItem {
|
||||
|
||||
private Player owner;
|
||||
private ItemStack item;
|
||||
private int startPrice;
|
||||
private int bidIncrement;
|
||||
private int buyNowPrice;
|
||||
private int currentPrice;
|
||||
private int time = 0;
|
||||
private String key;
|
||||
|
||||
public AuctionItem(ItemStack item, int time, int startPrice, int bidIncrement, int buyNowPrice) {
|
||||
this.owner = null;
|
||||
this.item = item.clone();
|
||||
this.startPrice = startPrice;
|
||||
this.bidIncrement = bidIncrement;
|
||||
this.bidIncrement = bidIncrement;
|
||||
this.buyNowPrice = buyNowPrice;
|
||||
this.time = time;
|
||||
key = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public AuctionItem(Player owner, ItemStack item, int time, int startPrice, int bidIncrement, int buyNowPrice) {
|
||||
this.owner = owner;
|
||||
this.item = item.clone();
|
||||
this.startPrice = startPrice;
|
||||
this.bidIncrement = bidIncrement;
|
||||
this.bidIncrement = bidIncrement;
|
||||
this.buyNowPrice = buyNowPrice;
|
||||
this.time = time;
|
||||
this.currentPrice = startPrice;
|
||||
key = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public Player getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(Player owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setItem(ItemStack item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public int getStartPrice() {
|
||||
return startPrice;
|
||||
}
|
||||
|
||||
public void setStartPrice(int startPrice) {
|
||||
this.startPrice = startPrice;
|
||||
}
|
||||
|
||||
public int getBidIncrement() {
|
||||
return bidIncrement;
|
||||
}
|
||||
|
||||
public void setBidIncrement(int bidIncrement) {
|
||||
this.bidIncrement = bidIncrement;
|
||||
}
|
||||
|
||||
public int getBuyNowPrice() {
|
||||
return buyNowPrice;
|
||||
}
|
||||
|
||||
public void setBuyNowPrice(int buyNowPrice) {
|
||||
this.buyNowPrice = buyNowPrice;
|
||||
}
|
||||
|
||||
public int getCurrentPrice() {
|
||||
return currentPrice;
|
||||
}
|
||||
|
||||
public void setCurrentPrice(int currentPrice) {
|
||||
this.currentPrice = currentPrice;
|
||||
}
|
||||
|
||||
public int getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(int time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void updateTime(int removeAmount) {
|
||||
if (time - removeAmount <= 0) {
|
||||
time = 0;
|
||||
} else {
|
||||
time = time - removeAmount;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack auctionStack() {
|
||||
ItemStack stack = item.clone();
|
||||
stack.setAmount((stack.getAmount() > 1) ? stack.getAmount() : 1);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
List<String> lore = null;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
} else {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
lore.add(translateAlternateColorCodes('&', "&7-------------------------"));
|
||||
if (owner == null)
|
||||
lore.add(translateAlternateColorCodes('&', "&eSeller&f: &bSample User"));
|
||||
else
|
||||
lore.add(translateAlternateColorCodes('&', "&eSeller&f: &b" + owner.getName()));
|
||||
lore.add(translateAlternateColorCodes('&', ""));
|
||||
lore.add(translateAlternateColorCodes('&', "&eBuy Now: &a$" + NumberFormat.getInstance().format(buyNowPrice)));
|
||||
lore.add(translateAlternateColorCodes('&', "&eCurrent Price: &a$" + NumberFormat.getInstance().format(currentPrice)));
|
||||
lore.add(translateAlternateColorCodes('&', "&eBid Increment: &a$" + NumberFormat.getInstance().format(bidIncrement)));
|
||||
lore.add(translateAlternateColorCodes('&', ""));
|
||||
lore.add(translateAlternateColorCodes('&', "&eTime Left: &b" + AuctionAPI.getInstance().timeLeft(getTime())));
|
||||
lore.add(translateAlternateColorCodes('&', "&7-------------------------"));
|
||||
lore.add(translateAlternateColorCodes('&', "&eLeft-Click&f: &bBid"));
|
||||
lore.add(translateAlternateColorCodes('&', "&eRight-Click&f: &bBuy Now"));
|
||||
lore.add(translateAlternateColorCodes('&', "&7-------------------------"));
|
||||
meta.setLore(lore);
|
||||
stack.setItemMeta(meta);
|
||||
stack = NBTEditor.setItemTag(stack, getKey(), "AuctionItemKey");
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,12 @@
|
||||
package com.shadebyte.auctionhouse.auction;
|
||||
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
import com.shadebyte.auctionhouse.api.enums.Permissions;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/6/2018
|
||||
@ -7,4 +14,41 @@ package com.shadebyte.auctionhouse.auction;
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public class AuctionPlayer {
|
||||
|
||||
private Player player;
|
||||
|
||||
public AuctionPlayer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public int getTotalActiveAuctions() {
|
||||
int total = 0;
|
||||
for (AuctionItem item : Core.getInstance().auctionItems) {
|
||||
if (item.getOwner().getUniqueId().equals(player.getUniqueId())) {
|
||||
total++;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public List<AuctionItem> getAuctionItems() {
|
||||
List<AuctionItem> list = new ArrayList<>();
|
||||
for (AuctionItem item : Core.getInstance().auctionItems) {
|
||||
if (item.getOwner().getUniqueId().equals(player.getUniqueId())) {
|
||||
list.add(item);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public boolean hasMaximumAuctionsActive() {
|
||||
if (!player.hasPermission(Permissions.MAX_AUCTIONS.getNode() + "." + getTotalActiveAuctions())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,15 @@
|
||||
package com.shadebyte.auctionhouse.cmds;
|
||||
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
import com.shadebyte.auctionhouse.api.enums.Lang;
|
||||
import com.shadebyte.auctionhouse.api.enums.Permissions;
|
||||
import com.shadebyte.auctionhouse.cmds.subcmds.SellCommand;
|
||||
import com.shadebyte.auctionhouse.inventory.inventories.AuctionGUI;
|
||||
import com.shadebyte.auctionhouse.util.Debugger;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -35,20 +39,24 @@ public class CommandManager implements CommandExecutor {
|
||||
|
||||
public void initialize() {
|
||||
Core.getInstance().getCommand(main).setExecutor(this);
|
||||
this.commands.add(new SellCommand());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if (!sender.hasPermission(Permissions.BASE.getNode())) {
|
||||
//sender.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.NO_PERMISSION.getNode()));
|
||||
sender.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.NO_PERMISSION.getNode()));
|
||||
return true;
|
||||
}
|
||||
|
||||
//Main command text
|
||||
if (command.getName().equalsIgnoreCase(main)) {
|
||||
if (args.length == 0) {
|
||||
//OPEN
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
p.openInventory(AuctionGUI.getInstance(p).getInventory());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -56,7 +64,7 @@ public class CommandManager implements CommandExecutor {
|
||||
SubCommand target = this.getSubcommand(args[0]);
|
||||
|
||||
if (target == null) {
|
||||
//sender.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.INVALID_SUBCOMMAND.getNode()));
|
||||
sender.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.INVALID_SUBCOMMAND.getNode()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,62 @@
|
||||
package com.shadebyte.auctionhouse.cmds.subcmds;
|
||||
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
import com.shadebyte.auctionhouse.api.AuctionAPI;
|
||||
import com.shadebyte.auctionhouse.api.enums.Lang;
|
||||
import com.shadebyte.auctionhouse.api.enums.Permissions;
|
||||
import com.shadebyte.auctionhouse.auction.AuctionItem;
|
||||
import com.shadebyte.auctionhouse.cmds.SubCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/6/2018
|
||||
* Time Created: 11:50 AM
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public class SellCommand {
|
||||
public class SellCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
|
||||
if (!sender.hasPermission(Permissions.BASE.getNode())) {
|
||||
sender.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.NO_PERMISSION.getNode()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.PLAYERS_ONLY.getNode()));
|
||||
return;
|
||||
}
|
||||
|
||||
Player p = (Player) sender;
|
||||
|
||||
if (args.length == 1) {
|
||||
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.CMD_SELL.getNode()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length == 4) {
|
||||
int buyNow = Integer.parseInt(args[1]);
|
||||
int startPrice = Integer.parseInt(args[2]);
|
||||
int increment = Integer.parseInt(args[3]);
|
||||
Core.getInstance().auctionItems.add(0, new AuctionItem(p, AuctionAPI.getItemInHand(p), 3600, startPrice, increment, buyNow));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return Core.getInstance().getCommandManager().sell;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String info() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] aliases() {
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
package com.shadebyte.auctionhouse.events;
|
||||
|
||||
import com.shadebyte.auctionhouse.inventory.AGUI;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/6/2018
|
||||
* Time Created: 4:03 PM
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public class AGUIListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onClick(InventoryClickEvent e) {
|
||||
if (e.getInventory().getHolder() instanceof AGUI) {
|
||||
AGUI gui = (AGUI) e.getInventory().getHolder();
|
||||
gui.click(e, e.getCurrentItem(), e.getRawSlot());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClose(InventoryCloseEvent e) {
|
||||
if (e.getInventory().getHolder() instanceof AGUI) {
|
||||
AGUI gui = (AGUI) e.getInventory().getHolder();
|
||||
gui.close(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,19 @@
|
||||
package com.shadebyte.auctionhouse.inventory;
|
||||
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/6/2018
|
||||
* Time Created: 11:54 AM
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public interface AGUI {
|
||||
public interface AGUI extends InventoryHolder {
|
||||
|
||||
}
|
||||
void click(InventoryClickEvent e, ItemStack clicked, int slot);
|
||||
|
||||
void close(InventoryCloseEvent e);
|
||||
}
|
@ -1,10 +1,133 @@
|
||||
package com.shadebyte.auctionhouse.inventory.inventories;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.shadebyte.auctionhouse.Core;
|
||||
import com.shadebyte.auctionhouse.api.AuctionAPI;
|
||||
import com.shadebyte.auctionhouse.auction.AuctionItem;
|
||||
import com.shadebyte.auctionhouse.inventory.AGUI;
|
||||
import com.shadebyte.auctionhouse.util.NBTEditor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
* Date Created: 7/6/2018
|
||||
* Time Created: 11:56 AM
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
|
||||
*/
|
||||
public class AuctionGUI {
|
||||
public class AuctionGUI implements AGUI {
|
||||
|
||||
private static AuctionGUI instance;
|
||||
private Player p;
|
||||
|
||||
private AuctionGUI(Player p) {
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
public static AuctionGUI getInstance(Player p) {
|
||||
if (instance == null) {
|
||||
instance = new AuctionGUI(p);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private int page = 1;
|
||||
|
||||
|
||||
@Override
|
||||
public void click(InventoryClickEvent e, ItemStack clicked, int slot) {
|
||||
e.setCancelled(true);
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
|
||||
|
||||
if (page >= 1 && slot == 48) p.openInventory(this.setPage(this.getPage() - 1).getInventory());
|
||||
if (page >= 1 && slot == 50) p.openInventory(this.setPage(this.getPage() + 1).getInventory());
|
||||
|
||||
|
||||
if (slot == 49) {
|
||||
p.closeInventory();
|
||||
p.openInventory(AuctionGUI.getInstance(p).getInventory());
|
||||
}
|
||||
|
||||
if (slot >= 0 & slot <= 44) {
|
||||
if (clicked == null || clicked.getType() == Material.AIR) {
|
||||
return;
|
||||
}
|
||||
|
||||
AuctionItem item = null;
|
||||
|
||||
if (e.getClick() == ClickType.LEFT) {
|
||||
String key = (String) NBTEditor.getItemTag(clicked, "AuctionItemKey");
|
||||
for (AuctionItem auctionItem : Core.getInstance().auctionItems) {
|
||||
if (auctionItem.getKey().equalsIgnoreCase(key)) item = auctionItem;
|
||||
}
|
||||
|
||||
item.setCurrentPrice(item.getCurrentPrice() + item.getBidIncrement());
|
||||
p.closeInventory();
|
||||
p.openInventory(AuctionGUI.getInstance(p).getInventory());
|
||||
}
|
||||
|
||||
if (e.getClick() == ClickType.RIGHT) {
|
||||
String key = (String) NBTEditor.getItemTag(clicked, "AuctionItemKey");
|
||||
for (AuctionItem auctionItem : Core.getInstance().auctionItems) {
|
||||
if (auctionItem.getKey().equalsIgnoreCase(key)) item = auctionItem;
|
||||
}
|
||||
|
||||
p.getInventory().addItem(item.getItem());
|
||||
item.setTime(0);
|
||||
Core.getInstance().auctionItems.remove(item);
|
||||
|
||||
p.closeInventory();
|
||||
p.openInventory(AuctionGUI.getInstance(p).getInventory());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(InventoryCloseEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
Inventory inventory = Bukkit.createInventory(this, 54, ChatColor.translateAlternateColorCodes('&', Core.getInstance().getConfig().getString("gui.auction.title")));
|
||||
|
||||
//Bottom Row
|
||||
inventory.setItem(45, AuctionAPI.getInstance().createConfigItem("gui.auction.items.yourauctions"));
|
||||
inventory.setItem(46, AuctionAPI.getInstance().createConfigItem("gui.auction.items.collectionbin"));
|
||||
inventory.setItem(48, AuctionAPI.getInstance().createConfigItem("gui.auction.items.previouspage"));
|
||||
inventory.setItem(49, AuctionAPI.getInstance().createConfigItem("gui.auction.items.refresh"));
|
||||
inventory.setItem(50, AuctionAPI.getInstance().createConfigItem("gui.auction.items.nextpage"));
|
||||
inventory.setItem(52, AuctionAPI.getInstance().createConfigItem("gui.auction.items.howtosell"));
|
||||
inventory.setItem(53, AuctionAPI.getInstance().createConfigItem("gui.auction.items.guide"));
|
||||
|
||||
//Pagination
|
||||
List<List<AuctionItem>> chunks = Lists.partition(Core.getInstance().auctionItems, 45);
|
||||
|
||||
if (chunks.size() != 0)
|
||||
chunks.get(getPage() - 1).forEach(item -> inventory.setItem(inventory.firstEmpty(), item.auctionStack()));
|
||||
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public AuctionGUI setPage(int page) {
|
||||
if (page <= 0)
|
||||
this.page = 1;
|
||||
else
|
||||
this.page = page;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getPage() {
|
||||
return page;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,67 @@
|
||||
gui:
|
||||
auction:
|
||||
title: "&7Auction House"
|
||||
items:
|
||||
guide:
|
||||
item: "BOOK:0"
|
||||
name: "&e&lGuide"
|
||||
lore:
|
||||
- "&7This is the auction house, here you can"
|
||||
- "&7list items for sale and purchase items"
|
||||
- "&7that others have listed for sale."
|
||||
- ""
|
||||
- "&7The auction is also a great way to make"
|
||||
- "&7money by selling farmable items other"
|
||||
- "&7players may be interested in buying."
|
||||
- ""
|
||||
- "&7All sell listings last for a max of &e60 minutes"
|
||||
- "&7unsold items are sent to your collection bin."
|
||||
- ""
|
||||
- "&7Each item is listed as a auction, so"
|
||||
- "&7players can out bid each other, or simply"
|
||||
- "&7purchase it right away with a set price."
|
||||
- ""
|
||||
- "&7For more help, use &e/ah help!"
|
||||
howtosell:
|
||||
item: "GOLD_INGOT:0"
|
||||
name: "&e&lHow to Sell"
|
||||
lore:
|
||||
- "&7To list an item on the auction house, just hold"
|
||||
- "&7the item in your hand and type the following command."
|
||||
- "&e/ah sell <buyNowPrice> <startPrice> <bidIncrement>"
|
||||
yourauctions:
|
||||
item: "DIAMOND:0"
|
||||
name: "&e&lYour Auctions"
|
||||
lore:
|
||||
- "&7Click here to view all of the items you"
|
||||
- "&7are currently selling on the auction."
|
||||
- ""
|
||||
- "&e&l{active_player_auctions} Item(s)"
|
||||
collectionbin:
|
||||
item: "ENDER_CHEST:0"
|
||||
name: "&e&lCollection Bin"
|
||||
lore:
|
||||
- "&7Click here to view and collect all of the"
|
||||
- "&7items you have cancelled or have expired."
|
||||
- ""
|
||||
- "&e&l{expired_player_auctions} Item(s)"
|
||||
previouspage:
|
||||
item: "PAPER:0"
|
||||
name: "&E&L<- Previous Page"
|
||||
lore:
|
||||
- "&7View the previous page of auctions."
|
||||
nextpage:
|
||||
item: "PAPER:0"
|
||||
name: "&e&lNext Page ->"
|
||||
lore:
|
||||
- "&7View the next page of auctions."
|
||||
refresh:
|
||||
item: "CHEST:0"
|
||||
name: "&6&lRefresh Auctions"
|
||||
lore:
|
||||
- "&7Click to refresh the currently"
|
||||
- "&7available auction listings."
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
prefix = "&8[eAuctionHouse&8]"
|
||||
|
||||
cmd.invalid = "&cThat isn't a valid subcommand!"
|
||||
cmd.sell = "&e/ah sell <buyNowPrice> <startPrice> <bidIncrement>"
|
||||
|
||||
nopermission = "&cYou do not have permission to do that!"
|
||||
playersonly = "&cOnly player's may use the command!"
|
@ -4,3 +4,8 @@ main: com.shadebyte.auctionhouse.Core
|
||||
authors: [TheCrystalStar]
|
||||
description: A premium auction house plugin
|
||||
website: https://www.shadebyte.com
|
||||
|
||||
commands:
|
||||
auctionhouse:
|
||||
description: Main command for the plugin
|
||||
aliases: [ah, auchouse]
|
Loading…
Reference in New Issue
Block a user