Skip to content

Commit

Permalink
简单适配NSGB
Browse files Browse the repository at this point in the history
  • Loading branch information
lt-name committed Oct 7, 2023
1 parent f0ef654 commit 1e8976c
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 3 deletions.
Binary file added lib/FakeNsGameBase.jar
Binary file not shown.
11 changes: 9 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cn.lanink</groupId>
<artifactId>MurderMystery</artifactId>
<version>1.4.2-PM1E<!-- -SNAPSHOT--></version>
<version>1.4.3-PM1E-SNAPSHOT</version>

<licenses>
<license>
Expand Down Expand Up @@ -169,6 +169,14 @@
<systemPath>${project.basedir}/lib/SimpleScoreboards-2.6.1.jar</systemPath>
</dependency>

<dependency>
<groupId>FakeNsGameBase</groupId>
<artifactId>FakeNsGameBase</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/FakeNsGameBase.jar</systemPath>
</dependency>

<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
Expand All @@ -182,7 +190,6 @@
<version>1.18.26</version>
<scope>provided</scope>
</dependency>

</dependencies>

</project>
13 changes: 12 additions & 1 deletion src/main/java/cn/lanink/murdermystery/MurderMystery.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public class MurderMystery extends PluginBase {

private IScoreboard scoreboard;
private boolean hasTips = false;
@Getter
private boolean hasNsGB = false;

private String serverWorldPath;
private String worldBackupPath;
Expand Down Expand Up @@ -294,8 +296,17 @@ public void onEnable() {
}
this.hasTips = true;
} catch (Exception ignored) {
//注册RsNPC变量

}
//检查FAP基础插件
try {
Class.forName("cn.nsgamebase.NsGameBaseMain");
ConfigUpdateUtils.checkFapNsGB(this);
this.hasNsGB = true;
} catch (Exception ignored) {

}
//注册RsNPC变量
try {
Class.forName("com.smallaswater.npc.variable.BaseVariableV2");
com.smallaswater.npc.variable.VariableManage.addVariableV2("MurderMysteryVariable", RsNpcVariable.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import cn.lanink.murdermystery.room.base.BaseRoom;
import cn.lanink.murdermystery.room.base.PlayerIdentity;
import cn.lanink.murdermystery.utils.Tools;
import cn.nsgamebase.api.GbGameApi;
import cn.nsgamebase.entity.pojo.AbstractDataGamePlayerPojo;
import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.level.Level;
Expand Down Expand Up @@ -51,7 +53,9 @@ protected void victoryReward(int victory) {
Player killerVictory = null;
Set<Player> commonPeopleVictory = new HashSet<>();
Set<Player> defeatPlayers = new HashSet<>();
Set<Player> players = new HashSet<>();
for (Map.Entry<Player, PlayerIdentity> entry : this.getPlayers().entrySet()) {
players.add(entry.getKey());
if (victory == 3) {
if (entry.getValue() == PlayerIdentity.KILLER) {
killerVictory = entry.getKey();
Expand Down Expand Up @@ -88,6 +92,23 @@ public void onRun(int i) {
for (Player player : defeatPlayers) {
Tools.executeCommands(player, murderMystery.getConfig().getStringList("defeatCmd"));
}

if (murderMystery.isHasNsGB()) {
for (Player player : players) {
AbstractDataGamePlayerPojo pojo = new AbstractDataGamePlayerPojo();
pojo.add("played");
Config config = murderMystery.getConfig();
int money = config.getInt("fapIntegral.money");
int point = config.getInt("fapIntegral.point");
int exp = config.getInt("fapIntegral.exp");
int maxMultiplier = config.getInt("fapIntegral.maxMultiplier");
if (maxMultiplier > 1) { //nsgb没有检查,这里检查下防止报错
GbGameApi.saveAndReward(player, "MurderMystery", pojo, money, point, exp, maxMultiplier);
} else {
GbGameApi.saveAndReward(player.getName(), "MurderMystery", pojo, money, point, exp);
}
}
}
}
}, 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.NotNull;

import java.util.LinkedHashMap;

/**
* @author LT_Name
*/
Expand Down Expand Up @@ -37,4 +39,26 @@ private static void update1_X_X_To_1_4_2() {
config.save();
}

// 需要在NsGB加载后检查,放到onEnable里
public static void checkFapNsGB(MurderMystery murderMystery) {
try {
Class.forName("cn.nsgamebase.NsGameBaseMain");

Config config = murderMystery.getConfig();

LinkedHashMap<String, Object> fapIntegral = new LinkedHashMap<>();
fapIntegral.put("money", 10);
fapIntegral.put("point", 0);
fapIntegral.put("exp", 10);
fapIntegral.put("maxMultiplier", 1);

if (!config.exists("fapIntegral")) {
config.set("fapIntegral", fapIntegral);
config.save();
}
} catch (Exception ignored) {

}
}

}

0 comments on commit 1e8976c

Please sign in to comment.