Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
update nc and use unified maven repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Librazy committed Aug 10, 2018
1 parent a54f466 commit b4052e9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 28 deletions.
9 changes: 2 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,8 @@ repositories {
}

maven {
name 'NyaaCore'
url 'https://raw.githubusercontent.com/NyaaCat/NyaaCore/maven-repo'
}

maven {
name 'nu-langchecker'
url 'https://raw.githubusercontent.com/Librazy/NyaaUtilsLangChecker/maven-repo'
name 'NyaaCentral'
url 'https://raw.githubusercontent.com/NyaaCat/NyaaCentral/maven-repo'
}

maven {
Expand Down
33 changes: 16 additions & 17 deletions src/main/java/cat/nyaa/HamsterEcoHelper/database/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import cat.nyaa.HamsterEcoHelper.signshop.ShopMode;
import cat.nyaa.nyaacore.database.DatabaseUtils;
import cat.nyaa.nyaacore.database.relational.RelationalDB;
import cat.nyaa.nyaacore.database.relational.SynchronizedQuery;
import cat.nyaa.nyaacore.database.relational.Query;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
import org.bukkit.configuration.InvalidConfigurationException;
Expand Down Expand Up @@ -32,7 +32,7 @@ public Database(HamsterEcoHelper plugin) {
}

public List<ItemStack> getTemporaryStorage(OfflinePlayer player) {
try (SynchronizedQuery<TempStorageRepo> result = database.queryTransactional(TempStorageRepo.class).whereEq("player_id", player.getUniqueId().toString())) {
try (Query<TempStorageRepo> result = database.queryTransactional(TempStorageRepo.class).whereEq("player_id", player.getUniqueId().toString())) {
if (result.count() == 0) return Collections.emptyList();
YamlConfiguration cfg = new YamlConfiguration();
try {
Expand All @@ -51,7 +51,7 @@ public List<ItemStack> getTemporaryStorage(OfflinePlayer player) {
}

public void addTemporaryStorage(OfflinePlayer player, ItemStack item) {
try (SynchronizedQuery<TempStorageRepo> result = database.queryTransactional(TempStorageRepo.class).whereEq("player_id", player.getUniqueId().toString())) {
try (Query<TempStorageRepo> result = database.queryTransactional(TempStorageRepo.class).whereEq("player_id", player.getUniqueId().toString())) {
YamlConfiguration cfg = new YamlConfiguration();
boolean update;
if (result.count() == 0) {
Expand Down Expand Up @@ -91,7 +91,7 @@ public void addTemporaryStorage(OfflinePlayer player, ItemStack item) {
}

public void clearTemporaryStorage(OfflinePlayer player) {
try (SynchronizedQuery<TempStorageRepo> query = database.queryTransactional(TempStorageRepo.class).whereEq("player_id", player.getUniqueId().toString())) {
try (Query<TempStorageRepo> query = database.queryTransactional(TempStorageRepo.class).whereEq("player_id", player.getUniqueId().toString())) {
if (query.count() != 0) {
query.delete();
query.commit();
Expand All @@ -101,7 +101,7 @@ public void clearTemporaryStorage(OfflinePlayer player) {

public List<MarketItem> getMarketItems(int offset, int limit, UUID seller) {
ArrayList<MarketItem> list = new ArrayList<>();
try (SynchronizedQuery<MarketItem> result =
try (Query<MarketItem> result =
seller == null ?
database.queryTransactional(MarketItem.class).where("amount", ">", 0) :
database.queryTransactional(MarketItem.class).where("amount", ">", 0).whereEq("player_id", seller.toString())) {
Expand Down Expand Up @@ -129,7 +129,7 @@ public long marketOffer(Player player, ItemStack itemStack, double unit_price) {
item.playerId = player.getUniqueId();
item.unitPrice = unit_price;
long id = 1;
try (SynchronizedQuery<MarketItem> query = database.queryTransactional(MarketItem.class)) {
try (Query<MarketItem> query = database.queryTransactional(MarketItem.class)) {
for (MarketItem marketItem : query.select()) {
if (marketItem.id >= id) {
id = marketItem.id + 1;
Expand All @@ -143,7 +143,7 @@ public long marketOffer(Player player, ItemStack itemStack, double unit_price) {
}

public void marketBuy(Player player, long itemId, int amount) {
try (SynchronizedQuery<MarketItem> query = database.queryTransactional(MarketItem.class).whereEq("id", itemId)) {
try (Query<MarketItem> query = database.queryTransactional(MarketItem.class).whereEq("id", itemId)) {
if (query.count() != 0) {
MarketItem mItem = query.selectUnique();
mItem.amount = mItem.amount - amount;
Expand Down Expand Up @@ -180,7 +180,7 @@ public long addItemLog(OfflinePlayer player, ItemStack item, double price, int a
i.price = price;
i.amount = amount;
long id = 1;
try (SynchronizedQuery<ItemLog> query = database.queryTransactional(ItemLog.class)) {
try (Query<ItemLog> query = database.queryTransactional(ItemLog.class)) {
for (ItemLog log : query.select()) {
if (log.id >= id) {
id = log.id + 1;
Expand All @@ -202,7 +202,7 @@ public Sign createShopSign(OfflinePlayer player, Block block, ShopMode mode) {
shopLocation.owner = player.getUniqueId();
shopLocation.setLocation(block.getLocation());
shopLocation.shopMode = mode;
try (SynchronizedQuery<Sign> sign = database.queryTransactional(Sign.class).whereEq("id", shopLocation.id)) {
try (Query<Sign> sign = database.queryTransactional(Sign.class).whereEq("id", shopLocation.id)) {
sign.delete();
sign.insert(shopLocation);
sign.commit();
Expand All @@ -216,7 +216,7 @@ public Sign createLottoSign(OfflinePlayer player, Block block, ShopMode mode, do
shopLocation.setLocation(block.getLocation());
shopLocation.shopMode = mode;
shopLocation.lotto_price = price;
try (SynchronizedQuery<Sign> sign = database.queryTransactional(Sign.class).whereEq("id", shopLocation.id)) {
try (Query<Sign> sign = database.queryTransactional(Sign.class).whereEq("id", shopLocation.id)) {
if (sign != null) {
sign.delete();
sign.insert(shopLocation);
Expand All @@ -229,7 +229,7 @@ public Sign createLottoSign(OfflinePlayer player, Block block, ShopMode mode, do
public boolean removeShopSign(Block block) {
Sign shopLocation = new Sign();
shopLocation.setLocation(block.getLocation());
try (SynchronizedQuery<Sign> sign = database.query(Sign.class).whereEq("id", shopLocation.id)) {
try (Query<Sign> sign = database.query(Sign.class).whereEq("id", shopLocation.id)) {
if (sign != null) {
sign.delete();
sign.commit();
Expand All @@ -242,7 +242,7 @@ public boolean removeShopSign(Block block) {
public boolean removeShopSign(String world, int x, int y, int z) {
Sign shopLocation = new Sign();
shopLocation.setLocation(world, x, y, z);
try (SynchronizedQuery<Sign> sign = database.queryTransactional(Sign.class).whereEq("id", shopLocation.id)) {
try (Query<Sign> sign = database.queryTransactional(Sign.class).whereEq("id", shopLocation.id)) {
if (sign != null) {
sign.delete();
sign.commit();
Expand All @@ -257,7 +257,7 @@ public List<SignShop> getSignShops() {
}

public SignShop getSignShop(UUID owner) {
try (SynchronizedQuery<SignShop> shop = database.queryTransactional(SignShop.class).whereEq("id", owner.toString())) {
try (Query<SignShop> shop = database.queryTransactional(SignShop.class).whereEq("id", owner.toString())) {
if (shop != null && shop.count() == 1) {
return shop.selectUnique();
}
Expand All @@ -268,7 +268,7 @@ public SignShop getSignShop(UUID owner) {
}

public void setSignShop(UUID owner, SignShop shop) {
try (SynchronizedQuery<SignShop> s = database.queryTransactional(SignShop.class).whereEq("id", owner.toString())) {
try (Query<SignShop> s = database.queryTransactional(SignShop.class).whereEq("id", owner.toString())) {
s.delete();
s.insert(shop);
s.commit();
Expand All @@ -280,20 +280,19 @@ public ShopStorageLocation getChestLocation(UUID owner) {
}

public void setChestLocation(UUID owner, ShopStorageLocation location) {
try (SynchronizedQuery<ShopStorageLocation> s = database.queryTransactional(ShopStorageLocation.class).whereEq("owner", owner.toString())) {
try (Query<ShopStorageLocation> s = database.queryTransactional(ShopStorageLocation.class).whereEq("owner", owner.toString())) {
s.delete();
s.insert(location);
s.commit();
}

}

public LottoStorageLocation getLottoStorageLocation(UUID owner) {
return database.query(LottoStorageLocation.class).whereEq("owner", owner.toString()).selectUniqueUnchecked();
}

public void setLottoStorageLocation(UUID owner, LottoStorageLocation location) {
try (SynchronizedQuery<LottoStorageLocation> s = database.queryTransactional(LottoStorageLocation.class).whereEq("owner", owner.toString())) {
try (Query<LottoStorageLocation> s = database.queryTransactional(LottoStorageLocation.class).whereEq("owner", owner.toString())) {
s.delete();
s.insert(location);
s.commit();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cat.nyaa.HamsterEcoHelper.database;

import cat.nyaa.nyaacore.database.relational.SynchronizedQuery;
import cat.nyaa.nyaacore.database.relational.Query;
import cat.nyaa.nyaacore.utils.ItemStackUtils;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
Expand Down Expand Up @@ -35,7 +35,7 @@ public static String convertYamlItemStackToNbtItemStack(String base64dYaml) {
*/
public static void updateVersion0To1(Database db) {
int total, counter = 0;
try (SynchronizedQuery<ItemLog> transaction = db.database.queryTransactional(ItemLog.class)) {
try (Query<ItemLog> transaction = db.database.queryTransactional(ItemLog.class)) {
total = transaction.count();
for (ItemLog record : transaction.select()) {
if (((++counter) % 100) == 0)
Expand All @@ -51,7 +51,7 @@ public static void updateVersion0To1(Database db) {
transaction.commit();
}

try (SynchronizedQuery<MarketItem> transaction = db.database.queryTransactional(MarketItem.class)) {
try (Query<MarketItem> transaction = db.database.queryTransactional(MarketItem.class)) {
counter = 0;
total = transaction.count();
for (MarketItem record : transaction.select()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void Requisition(CommandSender sender, Arguments args) {
if (material != null) {
item = new ItemStack(material);
}
if (item == null || !ReflectionUtils.isValidItem(item)) {
if (item == null || !material.isItem()) {
msg(sender, "user.error.unknown_item", itemName);
return;
}
Expand Down

0 comments on commit b4052e9

Please sign in to comment.