Skip to content

Commit

Permalink
fix: Some events that were not functional in the old version
Browse files Browse the repository at this point in the history
  • Loading branch information
blank038 committed Dec 2, 2023
1 parent e73e2b1 commit 00934a5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
9 changes: 7 additions & 2 deletions src/main/java/com/blank038/servermarket/ServerMarket.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import com.blank038.servermarket.data.DataContainer;
import com.blank038.servermarket.i18n.I18n;
import com.blank038.servermarket.listen.impl.CoreListener;
import com.blank038.servermarket.listen.impl.PlayerListener;
import com.blank038.servermarket.listen.impl.PlayerCommonListener;
import com.blank038.servermarket.listen.impl.PlayerLatestListener;
import com.blank038.servermarket.metrics.Metrics;
import de.tr7zw.nbtapi.utils.MinecraftVersion;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -44,7 +46,10 @@ public void onEnable() {
super.getCommand("servermarket").setExecutor(new MainCommand(this));
// 注册事件监听类
new CoreListener().register();
new PlayerListener().register();
new PlayerCommonListener().register();
if (MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_13_R1)) {
new PlayerLatestListener().register();
}
// start tasks
Bukkit.getScheduler().runTaskTimerAsynchronously(this, storageHandler::removeTimeOutItem, 200L, 200L);
Bukkit.getScheduler().runTaskTimerAsynchronously(this, storageHandler::saveAll, 1200L, 1200L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerCommandSendEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;

Expand All @@ -21,7 +20,7 @@
* @author Blank038
* @date 2021/03/05
*/
public class PlayerListener extends AbstractListener {
public class PlayerCommonListener extends AbstractListener {

/**
* 玩家加入服务器事件
Expand Down Expand Up @@ -52,18 +51,13 @@ public void onPlayerQuit(PlayerQuitEvent event) {
});
}

@EventHandler
public void onPlayerCommandSend(PlayerCommandSendEvent event) {
event.getCommands().addAll(DataContainer.REGISTERED_COMMAND);
}

private synchronized void checkResult(Player player) {
ServerMarket.getStorageHandler().getOfflineTransactionByPlayer(player.getUniqueId()).forEach((k, v) -> {
if (ServerMarket.getStorageHandler().removeOfflineTransaction(k)) {
// 获取市场数据
MarketData marketData = DataContainer.MARKET_DATA.getOrDefault(v.getSourceMarket(), null);
// 获取可获得货币
double price = v.getAmount(), last = marketData == null ? price : marketData.getLastMoney(marketData.getTaxSection(), player, price);
double price = v.getAmount(), last = marketData == null ? price : (price - price * marketData.getPermsValueForPlayer(marketData.getTaxSection(), player));
// 判断货币桥是否存在
if (BaseEconomy.PAY_TYPES.containsKey(v.getPayType())) {
DecimalFormat df = new DecimalFormat("#0.00");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.blank038.servermarket.listen.impl;

import com.blank038.servermarket.data.DataContainer;
import com.blank038.servermarket.listen.AbstractListener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandSendEvent;

/**
* @author Blank038
*/
public class PlayerLatestListener extends AbstractListener
implements Listener {

@EventHandler
public void onPlayerCommandSend(PlayerCommandSendEvent event) {
event.getCommands().addAll(DataContainer.REGISTERED_COMMAND);
}
}

0 comments on commit 00934a5

Please sign in to comment.