Skip to content

Commit

Permalink
合并nkmot分支
Browse files Browse the repository at this point in the history
  • Loading branch information
lt-name committed Jan 1, 2025
1 parent 6607c34 commit 2fe6608
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 21 deletions.
Binary file added lib/NsGameBase_FakeLib.jar
Binary file not shown.
29 changes: 21 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
</properties>

Expand Down Expand Up @@ -140,43 +140,56 @@
<id>repo-lanink-cn</id>
<url>https://repo.lanink.cn/</url>
</repository>
<repository>
<id>maven_central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>24.0.1</version>
<version>24.1.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
<version>1.18.34</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>cn.nukkit</groupId>
<artifactId>nukkit</artifactId>
<version>1.0-SNAPSHOT</version>
<artifactId>Nukkit</artifactId>
<version>MOT-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>cn.lanink</groupId>
<artifactId>MemoriesOfTime-GameCore</artifactId>
<version>1.6.11</version>
<version>1.6.13-PM1E</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.smallaswater</groupId>
<artifactId>RsNPC</artifactId>
<version>2.3.1</version>
<version>2.4.4</version>
<scope>provided</scope>
</dependency>

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


Expand Down
48 changes: 44 additions & 4 deletions src/main/java/cn/lanink/huntgame/HuntGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
import cn.lanink.huntgame.room.IntegralConfig;
import cn.lanink.huntgame.room.animal.AnimalModeRoom;
import cn.lanink.huntgame.room.block.BlockModeRoom;
import cn.lanink.huntgame.utils.GameCoreDownload;
import cn.lanink.huntgame.utils.MetricsLite;
import cn.lanink.huntgame.utils.RsNpcXVariable;
import cn.lanink.huntgame.utils.update.ConfigUpdateUtils;
import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.entity.data.Skin;
import cn.nukkit.level.Level;
import cn.nukkit.plugin.PluginBase;
Expand Down Expand Up @@ -81,6 +79,11 @@ public class HuntGame extends PluginBase {
private final HashMap<Integer, List<String>> rewardCmd = new HashMap<>(); // 积分下限 => 命令列表

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

private final HashMap<Integer, Map<String, Integer>> fapRewardIntegral = new HashMap<>();
private Integer[] fapRewardBound;

public static HuntGame getInstance() {
return huntGame;
Expand All @@ -98,7 +101,7 @@ public void onEnable() {
this.getLogger().info("§l§eVersion: " + this.getVersion());

//检查依赖
switch (GameCoreDownload.checkAndDownload()) {
/*switch (GameCoreDownload.checkAndDownload()) {
case 1:
Server.getInstance().getPluginManager().disablePlugin(this);
return;
Expand All @@ -107,7 +110,7 @@ public void onEnable() {
this.getLogger().warning(this.getLanguage().translateString("MemoriesOfTime-GameCore Dependency download complete! It is strongly recommended to restart the server to ensure proper loading!"))
);
break;
}
}*/

this.saveDefaultConfig();
this.config = new Config(this.getDataFolder() + "/config.yml", Config.YAML);
Expand Down Expand Up @@ -151,6 +154,14 @@ public void onEnable() {
this.hasTips = true;
} catch (Exception ignored) {

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

}

this.cmdUser = this.config.getString("cmdUser", "HuntGame").toLowerCase();
Expand Down Expand Up @@ -178,6 +189,21 @@ public void onEnable() {
this.rewardBound = this.rewardCmd.keySet().toArray(new Integer[0]);
Arrays.sort(this.rewardBound);

if (this.hasNsGB) {
Map<String, Object> fapRewardIntegral = this.config.getSection("fapRewardIntegral").getAllMap();
for (Map.Entry<String, Object> entry : fapRewardIntegral.entrySet()) {
try {
int bound = Integer.parseInt(entry.getKey());
this.fapRewardIntegral.put(bound, (Map<String, Integer>) entry.getValue());
} catch (NumberFormatException ignored) {
this.getLogger().info("§c Parsing 'fapRewardIntegral' failed!, invalid key '" + entry.getKey() + "' skip it.");
} catch (ClassCastException ignored) {
this.getLogger().info("§c Parsing 'fapRewardIntegral' failed!, invalid value '" + entry.getValue() + "' skip it.");
}
}
this.fapRewardBound = this.fapRewardIntegral.keySet().toArray(new Integer[0]);
}

this.getServer().getCommandMap().register("", new UserCommand(this.cmdUser));
this.getServer().getCommandMap().register("", new AdminCommand(this.cmdAdmin));

Expand Down Expand Up @@ -338,6 +364,20 @@ public String getCmdAdmin() {
return this.cmdAdmin;
}

public Map<String, Integer> getfapReward(int points) {
if (!this.hasNsGB) {
return null;
}
int idx = Arrays.binarySearch(this.fapRewardBound, points);
int bound;
if (idx >= 0) {
bound = this.fapRewardBound[idx];
} else {
bound = this.fapRewardBound[-idx - 2];
}
return this.fapRewardIntegral.get(bound);
}

public IScoreboard getScoreboard() {
return this.scoreboard;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.lanink.huntgame.entity;

import cn.lanink.gamecore.utils.NukkitTypeUtils;
import cn.lanink.huntgame.room.block.BlockInfo;
import cn.nukkit.Player;
import cn.nukkit.entity.EntityCreature;
Expand Down Expand Up @@ -57,7 +58,13 @@ public EntityCamouflageBlock(FullChunk chunk, CompoundTag nbt, @NonNull Player m

public void setBlockInfo(@NonNull BlockInfo blockInfo) {
this.blockInfo = blockInfo;
this.setDataProperty(new IntEntityData(DATA_VARIANT, GlobalBlockPalette.getOrCreateRuntimeId(this.blockInfo.getId(), this.blockInfo.getDamage())));
int runtimeId = 0;
if (NukkitTypeUtils.getNukkitType() == NukkitTypeUtils.NukkitType.MOT) {
runtimeId = GlobalBlockPalette.getOrCreateRuntimeId(this.getMaster().protocol, this.blockInfo.getId(), this.blockInfo.getDamage());
} else {
runtimeId = GlobalBlockPalette.getOrCreateRuntimeId(this.blockInfo.getId(), this.blockInfo.getDamage());
}
this.setDataProperty(new IntEntityData(DATA_VARIANT, runtimeId));
this.respawnToAll();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import cn.nukkit.entity.data.Skin;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.utils.SerializedImage;
import lombok.Getter;
import lombok.Setter;

import java.util.Base64;
import java.util.HashSet;

/**
Expand All @@ -22,8 +22,8 @@ public class EntityCamouflageBlockDamage extends EntityHuman implements IEntityC
public static final Skin EMPTY_SKIN = new Skin();

static {
EMPTY_SKIN.setSkinData(SerializedImage.fromLegacy(new byte[Skin.DOUBLE_SKIN_SIZE]));
EMPTY_SKIN.generateSkinId("EntityCamouflageBlock");
EMPTY_SKIN.setSkinId("Standard_Custom");
EMPTY_SKIN.setSkinData(Base64.getDecoder().decode(Skin.STEVE_SKIN));
}

@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
import cn.nukkit.Server;
import cn.nukkit.block.Block;
import cn.nukkit.entity.Entity;
import cn.nukkit.entity.item.EntityFirework;
import cn.nukkit.entity.weather.EntityLightning;
import cn.nukkit.event.EventHandler;
import cn.nukkit.event.EventPriority;
import cn.nukkit.event.entity.EntityDamageByChildEntityEvent;
import cn.nukkit.event.entity.EntityDamageEvent;
import cn.nukkit.event.entity.EntityShootBowEvent;
import cn.nukkit.event.entity.ProjectileLaunchEvent;
import cn.nukkit.event.entity.*;
import cn.nukkit.event.inventory.InventoryClickEvent;
import cn.nukkit.event.player.*;
import cn.nukkit.inventory.PlayerInventory;
Expand All @@ -37,6 +35,19 @@ public class DefaultGameListener extends BaseGameListener<BaseRoom> {

private final HuntGame huntGame = HuntGame.getInstance();

@EventHandler
public void onEntityExplosionPrime(EntityExplosionPrimeEvent event) {
/*
禁止HuntGame烟花爆炸伤害
*/
if (event.getEntity() instanceof EntityFirework) {
Entity entity = event.getEntity();
if (entity.namedTag != null && entity.namedTag.getBoolean("IsHuntGameFirework")) {
event.setCancelled();
}
}
}

@EventHandler
public void onPlayerChangeSkin(PlayerChangeSkinEvent event) { //此事件仅玩家主动修改皮肤时触发,不需要针对插件修改特判
Player player = event.getPlayer();
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/cn/lanink/huntgame/room/BaseRoom.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import cn.lanink.huntgame.tasks.WaitTask;
import cn.lanink.huntgame.tasks.game.TimeTask;
import cn.lanink.huntgame.utils.Tools;
import cn.lanink.huntgame.utils.nsgb.HuntGameDataGamePlayerPojo;
import cn.nsgamebase.api.GbGameApi;
import cn.nukkit.AdventureSettings;
import cn.nukkit.Player;
import cn.nukkit.Server;
Expand Down Expand Up @@ -321,10 +323,30 @@ public synchronized void endGame(PlayerIdentity victory) {
victoryPlayers.forEach((player, points) -> {
Tools.executeCommands(player, huntGame.getVictoryCmd());
Tools.executeCommands(player, huntGame.getRewardCmd(points));
if (this.huntGame.isHasNsGB()) {
Map<String, Integer> integerMap = this.huntGame.getfapReward(points);
HuntGameDataGamePlayerPojo pojo = new HuntGameDataGamePlayerPojo();
pojo.add("played");
int money = integerMap.get("money");
int point = integerMap.get("point");
int exp = integerMap.get("exp");
int maxMultiplier = integerMap.get("maxMultiplier");
GbGameApi.saveAndReward(player.getName(), "HuntGame", pojo, money, exp, maxMultiplier);
}
});
defeatPlayers.forEach((player, points) -> {
Tools.executeCommands(player, huntGame.getDefeatCmd());
Tools.executeCommands(player, huntGame.getRewardCmd(points));
if (this.huntGame.isHasNsGB()) {
Map<String, Integer> integerMap = this.huntGame.getfapReward(points);
HuntGameDataGamePlayerPojo pojo = new HuntGameDataGamePlayerPojo();
pojo.add("played");
int money = integerMap.get("money");
int point = integerMap.get("point");
int exp = integerMap.get("exp");
int maxMultiplier = integerMap.get("maxMultiplier");
GbGameApi.saveAndReward(player.getName(), "HuntGame", pojo, money, exp, maxMultiplier);
}
});
}, 1);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/cn/lanink/huntgame/utils/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ public static void spawnFirework(Position position) {
.putList(new ListTag<CompoundTag>("Explosions").add(ex)).putByte("Flight",1));
item.setNamedTag(tag);
CompoundTag nbt = new CompoundTag();
nbt.putBoolean("IsHuntGameFirework", true);
nbt.putList(new ListTag<DoubleTag>("Pos")
.add(new DoubleTag("",position.x+0.5D))
.add(new DoubleTag("",position.y+0.5D))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package cn.lanink.huntgame.utils.nsgb;

import cn.nsgamebase.entity.pojo.AbstractDataGamePlayerPojo;

/**
* @author LT_Name
*/
public class HuntGameDataGamePlayerPojo extends AbstractDataGamePlayerPojo {

}
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,42 @@ private static void update1_X_X_To_1_2_2() {
config.save();
}

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

Config config = getConfig();

LinkedHashMap<String, Object> fapRewardIntegral = new LinkedHashMap<>();

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

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

fapRewardIntegral.put("0", map1);
fapRewardIntegral.put("60", map2);

boolean needSave = false;
if (!config.exists("fapRewardIntegral")) {
config.set("fapRewardIntegral", fapRewardIntegral);
needSave = true;
}

if (needSave) {
config.save();
}
} catch (Exception ignored) {

}
}

}
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: HuntGame
main: cn.lanink.huntgame.HuntGame
version: "1.3.1"
version: "1.3.2-SNAPSHOT"
api: ["1.0.9"]
load: POSTWORLD
author: "LT_Name"
Expand Down

0 comments on commit 2fe6608

Please sign in to comment.