Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Noryea authored Jan 27, 2022
1 parent f83e8ec commit e0a2e60
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 49 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ loader_version=0.12.12
fabric_version=0.46.0+1.18

# Mod Properties
mod_version = 1.0.1
mod_version = 1.0.2
maven_group = cn.noryea
archives_base_name = manhunt-fabric
12 changes: 6 additions & 6 deletions src/main/java/cn/noryea/manhunt/Manhunt.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ public void onInitialize() {
Scoreboard scoreboard = world.getServer().getScoreboard();
if (scoreboard.getTeam("hunters") == null) {
Team team = scoreboard.addTeam("hunters");
team.setDisplayName((new LiteralText("猎人")).formatted(huntersColor));
team.setDisplayName(new LiteralText("猎人"));
team.setColor(huntersColor);
}

if (scoreboard.getTeam("runners") == null) {
Team team= scoreboard.addTeam("runners");
team.setDisplayName((new LiteralText("逃者")).formatted(runnersColor));
Team team = scoreboard.addTeam("runners");
team.setDisplayName(new LiteralText("逃者"));
team.setColor(runnersColor);
}

//获取玩家列表
Expand All @@ -57,9 +59,7 @@ public void onInitialize() {
});

//命令注册
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
ManhuntCommand.registerCommands(dispatcher);
});
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> ManhuntCommand.registerCommands(dispatcher));

}
}
4 changes: 0 additions & 4 deletions src/main/java/cn/noryea/manhunt/ManhuntCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ private static int executeJoin(ServerCommandSource source, Team team) throws Com
Scoreboard scoreboard = source.getServer().getScoreboard();

scoreboard.addPlayerToTeam(source.getPlayer().getName().asString(), team);

PlayerListS2CPacket packet = new PlayerListS2CPacket(PlayerListS2CPacket.Action.UPDATE_DISPLAY_NAME, source.getPlayer().getServer().getPlayerManager().getPlayerList());
source.getPlayer().getServer().getPlayerManager().sendToAll(packet);

source.sendFeedback(new TranslatableText("commands.team.join.success.single", source.getPlayer().getName(), team.getFormattedName()), true);

return 1;
Expand Down
68 changes: 33 additions & 35 deletions src/main/java/cn/noryea/manhunt/mixin/ServerPlayerEntityMixin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cn.noryea.manhunt.mixin;

import cn.noryea.manhunt.Manhunt;
import com.mojang.authlib.GameProfile;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.damage.DamageSource;
Expand All @@ -10,12 +9,10 @@
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.packet.s2c.play.OverlayMessageS2CPacket;
import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.scoreboard.Team;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.*;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.GameMode;
import net.minecraft.world.World;
Expand All @@ -24,7 +21,6 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Objects;

Expand Down Expand Up @@ -93,44 +89,46 @@ public void tick(CallbackInfo ci) {
public void onDeath(DamageSource source, CallbackInfo ci) {
Scoreboard scoreboard = server.getScoreboard();

if (this.getScoreboardTeam().isEqual(scoreboard.getTeam("runners"))) {
if (this.getScoreboardTeam() != null) {
if (this.getScoreboardTeam().isEqual(scoreboard.getTeam("runners"))) {

changeGameMode(GameMode.SPECTATOR);
scoreboard.clearPlayerTeam(this.getName().asString());
changeGameMode(GameMode.SPECTATOR);
scoreboard.clearPlayerTeam(this.getName().asString());

if (server.getScoreboard().getTeam("runners").getPlayerList().isEmpty()) {
server.getCommandManager().execute(this.getCommandSource().withSilent().withLevel(2), "title @a subtitle {\"text\":\"所有逃者已阵亡\",\"color\":\"white\"}");
server.getCommandManager().execute(this.getCommandSource().withSilent().withLevel(2), "title @a title {\"text\":\"猎人胜利!\",\"color\":\"red\"}");
if (server.getScoreboard().getTeam("runners").getPlayerList().isEmpty()) {
server.getCommandManager().execute(this.getCommandSource().withSilent().withLevel(2), "title @a subtitle {\"text\":\"所有逃者已阵亡\",\"color\":\"white\"}");
server.getCommandManager().execute(this.getCommandSource().withSilent().withLevel(2), "title @a title {\"text\":\"猎人胜利!\",\"color\":\"red\"}");
}
}
}
}

//玩家列表的名字
@Inject(method = "getPlayerListName", at = @At("TAIL"), cancellable = true)
private void replacePlayerListName(CallbackInfoReturnable<Text> cir) {
try {
if (this.getScoreboardTeam() != null) {

Team team = server.getScoreboard().getTeam(this.getScoreboardTeam().getName());

MutableText mutableText = (new LiteralText("")).append(team.getFormattedName()).append(this.getName());

Formatting formatting = team.getColor();
if (formatting != Formatting.RESET) {
mutableText.formatted(formatting);
} else if (team.getName().equals("hunters")) {
mutableText.formatted(Manhunt.huntersColor);
} else if (team.getName().equals("runners")) {
mutableText.formatted(Manhunt.runnersColor);
}

cir.setReturnValue(mutableText);

}
} catch (Exception e) {
e.printStackTrace();
}
}
// @Inject(method = "getPlayerListName", at = @At("TAIL"), cancellable = true)
// private void replacePlayerListName(CallbackInfoReturnable<Text> cir) {
// try {
// if (this.getScoreboardTeam() != null) {
//
// Team team = server.getScoreboard().getTeam(this.getScoreboardTeam().getName());
//
// MutableText mutableText = (new LiteralText("")).append(team.getFormattedName()).append(this.getName());
//
// Formatting formatting = team.getColor();
// if (formatting != Formatting.RESET) {
// mutableText.formatted(formatting);
// } else if (team.getName().equals("hunters")) {
// mutableText.formatted(Manhunt.huntersColor);
// } else if (team.getName().equals("runners")) {
// mutableText.formatted(Manhunt.runnersColor);
// }
//
// cir.setReturnValue(mutableText);
//
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// }

private void showInfo(NbtCompound info) {
String text_color = "\u00a7a";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.network.ServerPlayerInteractionManager;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.LiteralText;
Expand Down Expand Up @@ -115,7 +114,7 @@ private void updateCompass(ServerPlayerEntity player, NbtCompound nbt, ServerPla
nbt.remove("LodestoneDimension");
nbt.put("Info", new NbtCompound());

if (Objects.equals(trackedPlayer.getScoreboardTeam().getName(), "runners")) {
if (Objects.equals(Objects.requireNonNull(trackedPlayer.getScoreboardTeam()).getName(), "runners")) {
NbtCompound playerTag = trackedPlayer.writeNbt(new NbtCompound());
NbtList positions = playerTag.getList("Positions", 10);
int i;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "manhunt",
"version": "1.0.1",
"version": "1.0.2",
"name": "Manhunt",
"description": "Fabric下的猎人游戏模组 | Manhunt mod for Fabric.",
"authors": [
Expand Down

0 comments on commit e0a2e60

Please sign in to comment.