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

Commit

Permalink
Fix some small bugs; Optimize project structure
Browse files Browse the repository at this point in the history
Fix some small bugs
Optimize project structure
Correct error translation
  • Loading branch information
WetABQ authored May 22, 2019
1 parent e6fdcbd commit 123a433
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 23 deletions.
6 changes: 3 additions & 3 deletions language - chs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ language:
'&cThat is not your own shop.': '&c这个商店不属于你'
'&eItem: {}': '&e物品: {}'
'&b/qs help(h) - View help': '&b/qs help(h) - 查看帮助'
'&cYour money is not enough to buy,you still need ${} to buy': '&c你的钱不足以去购买,你仅仅只有 ${}'
'&cYour money is not enough to buy,you still need ${} to buy': '&c你的钱不足以去购买,仍然还需要 ${}'
'Please enter the &e&lprice &r&ato set up your shop!': '请输入 &e&l价格 &r&a去创建你的商店!'
'&aSuccessfully sold &6{}*{}': '&a成功卖出物品 &6{} x{}'
'&b/qs unlimited(ul) - Set the current clicked shop as unlimited': '&b/qs unlimited(ul) - 设置当前点击的商店为无限制商店(系统商店)'
'&b/qs unlimited(ul) - Set the current clicked shop as unlimited': '&b/qs unlimited(ul) - 设置当前点击的商店为无限制商店(系统商店)/第二次取消'
'Successfully changed the shop price': '成功更改商店的价格'
'&b/qs buy(b) - Set the current clicked shop as the buy type': '&b/qs buy(b) - 设置当前点击的商店为购买类型'
'&cThe shop is out of stock and cannot be sold': '&c该商店缺货,无法出售'
'Successfully changed the shop unlimited[{}]': '成功将商店更改为无限制[{}]'
'Successfully changed the shop unlimited[{}]': '成功将商店更改为无限制,当前状态为[{}]'
'&cThe owner money is not enough to buy': '&c商店的主人已经没有钱来回收你的东西了'
'&aPlayer &e{} &asuccessfully sold &6{}*{} &aand reduce &e{}$': '&a玩家 &e{} &a成功回收 &6{}*{} &a并且减少了你 &e${}'
'&b/qs price(p) <price: Int> - Set the current clicked shop''s price': '&b/qs price(p) <价格: 正整数> - 设置当前商店的价格'
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/wetabq/quickshop/QuickShop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class QuickShop : PluginBase(){
companion object {
lateinit var instance : QuickShop
var TITLE = ""
const val VERSION = "v1.0.1"
const val VERSION = "v1.0.2.1"

fun isInteger(str: String): Boolean {
val pattern = Pattern.compile("^[-\\+]?[\\d]*$")
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/wetabq/quickshop/config/MasterConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.wetabq.quickshop.QuickShop
*/
class MasterConfig : QuickShopConfig("config") {
var title = "&l&eQuick&6Shop &r&c» &a"
var waitTime = 8000 // 8000 ms

init {
init()
Expand All @@ -19,6 +20,7 @@ class MasterConfig : QuickShopConfig("config") {
if (!isEmpty()) {
try {
title = configSection.getString("title")
waitTime = configSection.getInt("waitTime")
} catch (e: Exception) {
QuickShop.instance.logger.warning(e.message)
QuickShop.instance.logger.error("Master Config(config.yml) while loading config")
Expand All @@ -32,6 +34,7 @@ class MasterConfig : QuickShopConfig("config") {
override fun spawnDefaultConfig() {
if (isEmpty()) {
configSection["title"] = title
configSection["waitTime"] = waitTime
}
save()
init()
Expand All @@ -42,6 +45,7 @@ class MasterConfig : QuickShopConfig("config") {
try {
configSection.clear()
configSection["title"] = title
configSection["waitTime"] = waitTime
config.setAll(configSection)
config.save()
} catch (e: Exception) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/wetabq/quickshop/event/PlayerBuyEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.wetabq.quickshop.event
import cn.nukkit.Player
import cn.nukkit.event.Cancellable
import cn.nukkit.event.HandlerList
import cn.nukkit.event.player.PlayerEvent
import io.wetabq.quickshop.data.ShopData

/**
Expand All @@ -12,7 +11,7 @@ import io.wetabq.quickshop.data.ShopData
* @author WetABQ Copyright (c) 2018.09
* @version 1.0
*/
class PlayerBuyEvent(player : Player,val shopData: ShopData,val count: Int) : PlayerEvent(),Cancellable {
class PlayerBuyEvent(player : Player,shopData: ShopData,val count: Int) : QuickShopPlayerEvent(player,shopData),Cancellable {

init {
super.player = player
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.wetabq.quickshop.event

import cn.nukkit.Player
import cn.nukkit.event.Cancellable
import cn.nukkit.event.HandlerList
import cn.nukkit.event.player.PlayerEvent
import io.wetabq.quickshop.data.ShopData

/**
Expand All @@ -11,7 +11,7 @@ import io.wetabq.quickshop.data.ShopData
* @author WetABQ Copyright (c) 2018.09
* @version 1.0
*/
class PlayerCreateShopEvent(player : Player,shopData: ShopData) : PlayerEvent() {
class PlayerCreateShopEvent(player : Player,shopData: ShopData) : QuickShopPlayerEvent(player,shopData),Cancellable {

init {
super.player = player
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import io.wetabq.quickshop.data.ShopData
* @author WetABQ Copyright (c) 2018.09
* @version 1.0
*/
class PlayerRemoveShopEvent(player : Player,shopData: ShopData) : PlayerEvent(),Cancellable {
class PlayerRemoveShopEvent(player : Player,shopData: ShopData) : QuickShopPlayerEvent(player,shopData),Cancellable {

init {
super.player = player
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/wetabq/quickshop/event/PlayerSellEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import io.wetabq.quickshop.data.ShopData
* @author WetABQ Copyright (c) 2018.09
* @version 1.0
*/
class PlayerSellEvent(player : Player,val shopData: ShopData, val count: Int) : PlayerEvent(), Cancellable {
class PlayerSellEvent(player : Player,shopData: ShopData, val count: Int) : QuickShopPlayerEvent(player,shopData), Cancellable {

init {
super.player = player
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/io/wetabq/quickshop/event/QuickShopPlayerEvent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.wetabq.quickshop.event

import cn.nukkit.Player
import cn.nukkit.event.Cancellable
import cn.nukkit.event.HandlerList
import cn.nukkit.event.player.PlayerEvent
import io.wetabq.quickshop.data.ShopData

/**
* QuickShop
*
* @author WetABQ Copyright (c) 2019.05
* @version 1.0
*/
open class QuickShopPlayerEvent(player : Player, val shopData: ShopData) : PlayerEvent(), Cancellable {

init {
super.player = player
}

companion object {

private val handlers = HandlerList()

@JvmStatic
fun getHandlers(): HandlerList {
return handlers
}

}

}
20 changes: 12 additions & 8 deletions src/main/java/io/wetabq/quickshop/listener/CreateShopListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CreateShopListener : Listener {
val pair = Shop.findShop(event.block)
val sign: BlockEntitySign? = pair?.first
if (sign != null && pair.second == null && event.item.id != Item.SIGN && event.item.id != 0) {
createShopPlayer[event.player.name] = Pair(System.currentTimeMillis() + 8000,event.block)
createShopPlayer[event.player.name] = Pair(System.currentTimeMillis() + QuickShop.instance.masterConfig.waitTime,event.block)
event.player.sendMessage(Lang.getMessage("Please enter the &e&lprice &r&ato set up your shop!"))
event.setCancelled()
}
Expand All @@ -49,13 +49,17 @@ class CreateShopListener : Listener {
val sign: BlockEntitySign? = Shop.findShop(chest)?.first
if (sign != null) {
val item = player.inventory.itemInHand
sign.setText(Lang.getMessage("&c[&l&eQuick&6Shop&r&c]",false),
Lang.getMessage("&aType: {}", arrayOf("BUY"),false),
Lang.getMessage("&eItem: {}", arrayOf(Lang.getItemName(item)),false),
Lang.getMessage("&c&lPrice: {}$ /count", arrayOf(event.message),false))
QuickShop.addItemEntity(chest, Item.get(item.id,item.damage,1),(sign.x.toInt()+sign.z.toInt()).toLong())
player.sendMessage(Lang.getMessage("Successfully created the shop"))
Shop.createShop(player, chest, sign, event.message.toInt(), item, ShopType.BUY)
val cancel = Shop.createShop(player, chest, sign, event.message.toInt(), item, ShopType.BUY)
if (cancel) {
sign.setText(Lang.getMessage("&c[&l&eQuick&6Shop&r&c]", false),
Lang.getMessage("&aType: {}", arrayOf("BUY"), false),
Lang.getMessage("&eItem: {}", arrayOf(Lang.getItemName(item)), false),
Lang.getMessage("&c&lPrice: {}$ /count", arrayOf(event.message), false))
QuickShop.addItemEntity(chest, Item.get(item.id, item.damage, 1), (sign.x.toInt() + sign.z.toInt()).toLong())
player.sendMessage(Lang.getMessage("Successfully created the shop"))
} else {
player.sendMessage(Lang.getMessage("Error, create shop is canceled"))
}
} else {
player.sendMessage(Lang.getMessage("&cPlease put a sign around your chest."))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class InteractionShopListener : Listener {
"&d+------------------+"
,arrayOf(shopData.owner,Lang.getItemName(Item.get(shopData.itemId,shopData.itemMeta)),shopData.price,if(shopData.type == ShopType.BUY) "SELLING" else "BUYING")))
player.sendMessage(Lang.getMessage("Please enter the &l&ecount &r&ayou need to &d&l{}", arrayOf(if(shopData.type == ShopType.BUY) "BUY" else "SELL")))
interactShop[player.name] = Pair(System.currentTimeMillis() + 8000, shop)
interactShop[player.name] = Pair(System.currentTimeMillis() + QuickShop.instance.masterConfig.waitTime, shop)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/wetabq/quickshop/shop/BuyShop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class BuyShop(sign: String) : Shop(sign) {
}
}
} else {
player.sendMessage(Lang.getMessage("&cYour money is not enough to buy,you still need \${} to buy", arrayOf(shopData.price - money)))
player.sendMessage(Lang.getMessage("&cYour money is not enough to buy,you still need \${} to buy", arrayOf(price - money)))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/wetabq/quickshop/shop/SellShop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SellShop(sign: String) : Shop(sign) {
}
}
} else {
player.sendMessage(Lang.getMessage("&cThe owner money is not enough to buy", arrayOf(shopData.price - money)))
player.sendMessage(Lang.getMessage("&cThe owner money is not enough to buy"))
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/wetabq/quickshop/shop/Shop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ abstract class Shop(sign: String) {
}

@JvmStatic
fun createShop(owner: Player, chest: Position, sign: Position, price: Int, item: Item,type: Int) {
fun createShop(owner: Player, chest: Position, sign: Position, price: Int, item: Item,type: Int): Boolean {
val shopData = ShopData(owner.name,type,price,chest.x.toInt(),chest.y.toInt(),chest.z.toInt(),sign.x.toInt(),sign.z.toInt(),chest.level.folderName,item.id,item.damage,false)

val event = PlayerCreateShopEvent(owner, shopData)
Server.getInstance().pluginManager.callEvent(event)
if (event.isCancelled) return false

QuickShop.instance.shopConfig.addShop(shopData)
return true
}

@JvmStatic
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: QuickShop
main: io.wetabq.quickshop.QuickShop
version: "1.0.2"
version: "1.0.2.1"
api: ["1.0.0"]
author: WetABQ
depend:
Expand Down

0 comments on commit 123a433

Please sign in to comment.