Skip to content

Commit

Permalink
MySQL changed and update checker
Browse files Browse the repository at this point in the history
  • Loading branch information
MinecraftDorado committed Nov 19, 2020
1 parent 4d24097 commit 9a72a1f
Show file tree
Hide file tree
Showing 24 changed files with 397 additions and 18 deletions.
Binary file not shown.
Binary file modified bin/dev/minecraftdorado/BlackMarket/MainClass/MainClass.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified bin/dev/minecraftdorado/BlackMarket/Utils/Market/BlackItem.class
Binary file not shown.
Binary file modified bin/dev/minecraftdorado/BlackMarket/Utils/Market/Market.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
30 changes: 28 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
main: dev.minecraftdorado.BlackMarket.MainClass.MainClass
name: BlackMarket
author: MinecraftDorado
version: 1.1
version: 1.11
api-version: 1.13
softdepend: [Vault]
commands:
sell:
bm:
bm:

permissions:
blackmarket.admin:
description: Allows the use of all commands
default: op
children:
blackmarket.limit.*: true
blackmarket.reload: true
blackmarket.npc: true
blackmarket.open: true
blackmarket.npc:
description: Allows the use of commands for NPCs
default: op
children:
blackmarket.setnpc: true
blackmarket.removenpc: true
blackmarket.setnpc:
description: Allows usage of the /bm setnpc command
blackmarket.removenpc:
description: Allows usage of the /bm removenpc command
blackmarket.limit:
description: Limit of published articles
blackmarket.reload:
description: Allows usage of the /bm reload command
blackmarket.open:
description: Allows usage of the /bm open command
132 changes: 131 additions & 1 deletion resources/categories/potions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,135 @@ materials:
- CAULDRON
- BREWING_STAND
- GHAST_TEAR
- FERMENTED_SPIDER_EYE

- LINGERING_POTION
- LINGERING_POTION_AWKWARD
- LINGERING_POTION_FIRE_RESISTANCE
- LINGERING_POTION_FIRE_RESISTANCE_EXTENDED
- LINGERING_POTION_HARMING_1
- LINGERING_POTION_HARMING_2
- LINGERING_POTION_HEALING_1
- LINGERING_POTION_HEALING_2
- LINGERING_POTION_INVISIBILITY
- LINGERING_POTION_INVISIBILITY_EXTENDED
- LINGERING_POTION_LEAPING_1
- LINGERING_POTION_LEAPING_1_EXTENDED
- LINGERING_POTION_LEAPING_2
- LINGERING_POTION_LUCK
- LINGERING_POTION_MUNDANE
- LINGERING_POTION_NIGHT_VISION
- LINGERING_POTION_NIGHT_VISION_EXTENDED
- LINGERING_POTION_POISON_1
- LINGERING_POTION_POISON_1_EXTENDED
- LINGERING_POTION_POISON_2
- LINGERING_POTION_REGENERATION_1
- LINGERING_POTION_REGENERATION_1_EXTENDED
- LINGERING_POTION_REGENERATION_2
- LINGERING_POTION_SLOW_FALLING
- LINGERING_POTION_SLOW_FALLING_EXTENDED
- LINGERING_POTION_SLOWNESS_1
- LINGERING_POTION_SLOWNESS_1_EXTENDED
- LINGERING_POTION_SLOWNESS_2
- LINGERING_POTION_STRENGTH_1
- LINGERING_POTION_STRENGTH_1_EXTENDED
- LINGERING_POTION_STRENGTH_2
- LINGERING_POTION_SWIFTNESS_1
- LINGERING_POTION_SWIFTNESS_1_EXTENDED
- LINGERING_POTION_SWIFTNESS_2
- LINGERING_POTION_THICK
- LINGERING_POTION_TURTLE_MASTER_1
- LINGERING_POTION_TURTLE_MASTER_1_EXTENDED
- LINGERING_POTION_TURTLE_MASTER_2
- LINGERING_POTION_WATER
- LINGERING_POTION_WATER_BREATHING
- LINGERING_POTION_WATER_BREATHING_EXTENDED
- LINGERING_POTION_WEAKNESS
- LINGERING_POTION_WEAKNESS_EXTENDED

- POTION
- FERMENTED_SPIDER_EYE
- POTION_AWKWARD
- POTION_FIRE_RESISTANCE
- POTION_FIRE_RESISTANCE_EXTENDED
- POTION_HARMING_1
- POTION_HARMING_2
- POTION_HEALING_1
- POTION_HEALING_2
- POTION_INVISIBILITY_EXTENDED
- POTION_LEAPING_1
- POTION_LEAPING_1_EXTENDED
- POTION_LEAPING_2
- POTION_LUCK
- POTION_MUNDANE
- POTION_NIGHT_VISION
- POTION_NIGHT_VISION_EXTENDED
- POTION_POISON_1
- POTION_POISON_1_EXTENDED
- POTION_POISON_2
- POTION_REGENERATION_1
- POTION_REGENERATION_1_EXTENDED
- POTION_REGENERATION_2
- POTION_SLOW_FALLING
- POTION_SLOW_FALLING_EXTENDED
- POTION_SLOWNESS_1
- POTION_SLOWNESS_1_EXTENDED
- POTION_SLOWNESS_2
- POTION_STRENGTH_1
- POTION_STRENGTH_1_EXTENDED
- POTION_STRENGTH_2
- POTION_SWIFTNESS_1
- POTION_SWIFTNESS_1_EXTENDED
- POTION_SWIFTNESS_2
- POTION_THICK
- POTION_TURTLE_MASTER_1
- POTION_TURTLE_MASTER_1_EXTENDED
- POTION_TURTLE_MASTER_2
- POTION_WATER
- POTION_WATER_BREATHING
- POTION_WATER_BREATHING_EXTENDED
- POTION_WEAKNESS
- POTION_WEAKNESS_EXTENDED
-
- SPLASH_POTION
- SPLASH_POTION_AWKWARD
- SPLASH_POTION_FIRE_RESISTANCE
- SPLASH_POTION_FIRE_RESISTANCE_EXTENDED
- SPLASH_POTION_HARMING_1
- SPLASH_POTION_HARMING_2
- SPLASH_POTION_HEALING_1
- SPLASH_POTION_HEALING_2
- SPLASH_POTION_INVISIBILITY
- SPLASH_POTION_INVISIBILITY_EXTENDED
- SPLASH_POTION_LEAPING_1
- SPLASH_POTION_LEAPING_1_EXTENDED
- SPLASH_POTION_LEAPING_2
- SPLASH_POTION_LUCK
- SPLASH_POTION_MUNDANE
- SPLASH_POTION_NIGHT_VISION
- SPLASH_POTION_NIGHT_VISION_EXTENDED
- SPLASH_POTION_POISON_1
- SPLASH_POTION_POISON_1_EXTENDED
- SPLASH_POTION_POISON_2
- SPLASH_POTION_REGENERATION_1
- SPLASH_POTION_REGENERATION_1_EXTENDED
- SPLASH_POTION_REGENERATION_2
- SPLASH_POTION_SLOW_FALLING
- SPLASH_POTION_SLOW_FALLING_EXTENDED
- SPLASH_POTION_SLOWNESS_1
- SPLASH_POTION_SLOWNESS_1_EXTENDED
- SPLASH_POTION_SLOWNESS_2
- SPLASH_POTION_STRENGTH_1
- SPLASH_POTION_STRENGTH_1_EXTENDED
- SPLASH_POTION_STRENGTH_2
- SPLASH_POTION_SWIFTNESS_1
- SPLASH_POTION_SWIFTNESS_1_EXTENDED
- SPLASH_POTION_SWIFTNESS_2
- SPLASH_POTION_THICK
- SPLASH_POTION_TURTLE_MASTER_1
- SPLASH_POTION_TURTLE_MASTER_1_EXTENDED
- SPLASH_POTION_TURTLE_MASTER_2
- SPLASH_POTION_WATER
- SPLASH_POTION_WATER_BREATHING
- SPLASH_POTION_WATER_BREATHING_EXTENDED
- SPLASH_POTION_WEAKNESS
- SPLASH_POTION_WEAKNESS_EXTENDED
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import dev.minecraftdorado.BlackMarket.MainClass.MainClass;
import dev.minecraftdorado.BlackMarket.Utils.Config;
import dev.minecraftdorado.BlackMarket.Utils.UpdateChecker;
import dev.minecraftdorado.BlackMarket.Utils.UpdateChecker.UpdateReason;
import dev.minecraftdorado.BlackMarket.Utils.Entities.NPC.Events.NPCInteractEvent;
import dev.minecraftdorado.BlackMarket.Utils.Inventory.InventoryManager;
import dev.minecraftdorado.BlackMarket.Utils.Market.Market;
Expand All @@ -28,7 +30,26 @@ public class PlayerListener implements Listener {
*/

@EventHandler
private void join(PlayerJoinEvent e) {PacketReader.get(e.getPlayer()).inject();}
private void join(PlayerJoinEvent e) {
PacketReader.get(e.getPlayer()).inject();

if(e.getPlayer().hasPermission("blackmarket.admin"))
UpdateChecker.init(MainClass.main, 79819).requestUpdateCheck().whenComplete((result, ee) -> {
if (result.requiresUpdate()) {
e.getPlayer().sendMessage("§6[BlackMarket] §7» " + String.format("An update is available! BlackMarket %s may be downloaded on SpigotMC", result.getNewestVersion()));
return;
}

UpdateReason reason = result.getReason();
if (reason == UpdateReason.UP_TO_DATE)
e.getPlayer().sendMessage("§6[BlackMarket] §7» " + String.format("Your version of BlackMarket (%s) is up to date!", result.getNewestVersion()));
else if (reason == UpdateReason.UNRELEASED_VERSION)
e.getPlayer().sendMessage("§6[BlackMarket] §7» " + String.format("Your version of BlackMarket (%s) is more recent than the one publicly available. Are you on a development build?", result.getNewestVersion()));
else
e.getPlayer().sendMessage("§6[BlackMarket] §7» " + "Could not check for a new version of BlackMarket. Reason: " + reason);
}
);
}

/*
* Uninject PacketReader
Expand Down
18 changes: 18 additions & 0 deletions src/dev/minecraftdorado/BlackMarket/MainClass/MainClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import dev.minecraftdorado.BlackMarket.Utils.Packets.PacketReader;
import net.milkbowl.vault.economy.Economy;
import dev.minecraftdorado.BlackMarket.Utils.Config;
import dev.minecraftdorado.BlackMarket.Utils.UpdateChecker;
import dev.minecraftdorado.BlackMarket.Utils.UpdateChecker.UpdateReason;
import dev.minecraftdorado.BlackMarket.Utils.Entities.Hologram.HologramManager;
import dev.minecraftdorado.BlackMarket.Utils.Entities.NPC.NPCManager;
import dev.minecraftdorado.BlackMarket.Utils.Entities.NPC.Skins.SkinData;
Expand All @@ -38,6 +40,22 @@ public void onEnable() {
return;
}

UpdateChecker.init(this, 85558).requestUpdateCheck().whenComplete((result, e) -> {
if (result.requiresUpdate()) {
this.getLogger().info(String.format("An update is available! BlackMarket %s may be downloaded on SpigotMC", result.getNewestVersion()));
return;
}

UpdateReason reason = result.getReason();
if (reason == UpdateReason.UP_TO_DATE)
this.getLogger().info(String.format("Your version of BlackMarket (%s) is up to date!", result.getNewestVersion()));
else if (reason == UpdateReason.UNRELEASED_VERSION)
this.getLogger().info(String.format("Your version of BlackMarket (%s) is more recent than the one publicly available. Are you on a development build?", result.getNewestVersion()));
else
this.getLogger().warning("Could not check for a new version of BlackMarket. Reason: " + reason);
}
);

getServer().getPluginCommand("sell").setExecutor(new sell());
getServer().getPluginCommand("bm").setExecutor(new bm());
getServer().getPluginCommand("bm").setTabCompleter(new bmTab());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public void createTables(URL url){
statement.close();
}
}catch(Exception ex){
MainClass.main.getLogger().severe(String.format("» MySQL can't create the table: " + url.toString(), MainClass.main.getDescription().getName()));
ex.printStackTrace();
String[] s = url.toString().split("/");
MainClass.main.getLogger().severe(String.format("» MySQL can't create the table or already exist: " + s[s.length-1], MainClass.main.getDescription().getName()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ public static void load() {
public static void save() {
for(Data data : PlayerData.list.values())
for(BlackItem bItem : data.getItems())
try {
addBlackItem(bItem);
} catch (SQLException e) {
e.printStackTrace();
}
updateStatus(bItem);
}

private static void loadBlackItems() throws SQLException {
Expand Down Expand Up @@ -87,8 +83,10 @@ private static void loadBlackItems() throws SQLException {
}
}

private static void updateStatus(BlackItem bItem) throws SQLException {
if(con == null || con.isClosed()) con = sql.getConnection();
public static void updateStatus(BlackItem bItem) {
try {
if(con == null || con.isClosed()) con = sql.getConnection();
} catch(Exception e) {e.printStackTrace();}

try {
PreparedStatement preparedStatement = null;
Expand All @@ -105,8 +103,10 @@ private static void updateStatus(BlackItem bItem) throws SQLException {
}
}

private static void addBlackItem(BlackItem bItem) throws SQLException {
if(con == null || con.isClosed()) con = sql.getConnection();
public static void addBlackItem(BlackItem bItem) {
try {
if(con == null || con.isClosed()) con = sql.getConnection();
} catch(Exception e) {e.printStackTrace();}

try {
PreparedStatement preparedStatement = null;
Expand All @@ -121,6 +121,7 @@ private static void addBlackItem(BlackItem bItem) throws SQLException {
updateStatus(bItem);
return;
}

resultSet.close();
preparedStatement.close();
queryBuilder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,9 @@ public static UMaterial matchPotion(ItemStack potion) {
: a : null;
if(type != null) {
final String g = base + type + (max != 1 && l <= max ? "_" + l : "") + (extended ? "_EXTENDED" : "");
return valueOf(g);
try {
return valueOf(g);
}catch(Exception e) {return valueOf(g + "_1");}
} else {
return UMaterial.POTION;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import dev.minecraftdorado.BlackMarket.Utils.Config;
import dev.minecraftdorado.BlackMarket.Utils.Utils;
import dev.minecraftdorado.BlackMarket.Utils.DataBase.MySQL.dbMySQL;
import dev.minecraftdorado.BlackMarket.Utils.Config.StorageType;

public class BlackItem {

Expand Down Expand Up @@ -49,6 +51,7 @@ public BlackItem(ItemStack item, double value, UUID owner) {
cal.setTime(new Date());
cal.add(Calendar.MINUTE, Config.getExpiredTime());
this.date = cal.getTime();
dbMySQL.addBlackItem(this);
}

public int getId() {
Expand Down Expand Up @@ -91,13 +94,15 @@ public UUID getOwner() {
public Status getStatus() {
if(status.equals(Status.ON_SALE)) {
if(Duration.between(new Date().toInstant(), date.toInstant()).getSeconds() <= 0)
status = Status.TIME_OUT;
setStatus(Status.TIME_OUT);
}
return status;
}

public void setStatus(Status status) {
this.status = status;
if(Config.getStorageType().equals(StorageType.MySQL))
dbMySQL.updateStatus(this);
}

public enum Status {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static Inv getMarketInventory(Player player) {

for(BlackItem bItem : list.values()) {
if(bItem.getStatus().equals(Status.ON_SALE)) {
if(category == null || category.getMaterials().isEmpty() || category.getMaterials().contains(UMaterial.match(bItem.getItemStack())))
if(category == null || category.getMaterials().isEmpty() || category.contain(UMaterial.match(bItem.getItemStack())))
l.add(bItem);
}else
toRemove.add(bItem.getId());
Expand Down
Loading

0 comments on commit 9a72a1f

Please sign in to comment.