-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66799d1
commit ae12aea
Showing
9 changed files
with
337 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...va/club/mcams/carpet/helpers/rule/sendPlayerDeathLocation/PlayerDeathLocationContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* This file is part of the Carpet AMS Addition project, licensed under the | ||
* GNU Lesser General Public License v3.0 | ||
* | ||
* Copyright (C) 2024 A Minecraft Server and contributors | ||
* | ||
* Carpet AMS Addition is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Carpet AMS Addition is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Carpet AMS Addition. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package club.mcams.carpet.helpers.rule.sendPlayerDeathLocation; | ||
|
||
import club.mcams.carpet.helpers.FakePlayerHelper; | ||
import club.mcams.carpet.translations.Translator; | ||
import club.mcams.carpet.utils.MessageTextEventUtils.ClickEventUtil; | ||
import club.mcams.carpet.utils.MessageTextEventUtils.HoverEventUtil; | ||
import club.mcams.carpet.utils.Messenger; | ||
import club.mcams.carpet.utils.compat.DimensionWrapper; | ||
|
||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.text.BaseText; | ||
import net.minecraft.text.Style; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
import net.minecraft.world.World; | ||
|
||
public class PlayerDeathLocationContext { | ||
private static final Translator translator = new Translator("rule.sendPlayerDeathLocation"); | ||
|
||
public static void sendMessage(MinecraftServer server, ServerPlayerEntity player, World world) { | ||
final Text copyButton = copyButton(player); | ||
String message = formatMessage(player, world); | ||
Messenger.sendServerMessage(server, Messenger.s(message).formatted(Formatting.RED).append(copyButton)); | ||
} | ||
|
||
public static void realPlayerSendMessage(MinecraftServer server, ServerPlayerEntity player, World world) { | ||
if (!FakePlayerHelper.isFakePlayer(player)) { | ||
sendMessage(server, player, world); | ||
} | ||
} | ||
|
||
public static void fakePlayerSendMessage(MinecraftServer server, ServerPlayerEntity player, World world) { | ||
if (FakePlayerHelper.isFakePlayer(player)) { | ||
sendMessage(server, player, world); | ||
} | ||
} | ||
|
||
private static String getPlayerName(ServerPlayerEntity player) { | ||
return player.getName().getString(); | ||
} | ||
|
||
private static DimensionWrapper getDimension(World world) { | ||
return DimensionWrapper.of(world); | ||
} | ||
|
||
private static String getPlayerPos(ServerPlayerEntity player) { | ||
return player.getBlockPos().getX() + ", " + player.getBlockPos().getY() + ", " + player.getBlockPos().getZ(); | ||
} | ||
|
||
private static Text copyButton(ServerPlayerEntity player) { | ||
BaseText hoverText = Messenger.s(translator.tr("copy").getString(), "y"); | ||
String copyCoordText = getPlayerPos(player).replace(",", ""); // 1, 0, -24 -> 1 0 -24 | ||
|
||
return | ||
Messenger.s(" [C] ").setStyle( | ||
Style.EMPTY.withColor(Formatting.GREEN).withBold(true). | ||
withClickEvent(ClickEventUtil.event(ClickEventUtil.COPY_TO_CLIPBOARD, copyCoordText)). | ||
withHoverEvent(HoverEventUtil.event(HoverEventUtil.SHOW_TEXT, hoverText)) | ||
); | ||
} | ||
|
||
// Alex 死亡位置 @ minecraft:overworld -> [ 888, 20, 999 ] | ||
private static String formatMessage(ServerPlayerEntity player, World world) { | ||
String playerName = getPlayerName(player); | ||
DimensionWrapper dimension = getDimension(world); | ||
return String.format( | ||
"%s %s @ %s -> [ %s ]", | ||
playerName, | ||
translator.tr("location").getString(), | ||
dimension, | ||
getPlayerPos(player) | ||
); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...ava/club/mcams/carpet/mixin/rule/perfectInvisibility_sneakInvisibility/EntityInvoker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* This file is part of the Carpet AMS Addition project, licensed under the | ||
* GNU Lesser General Public License v3.0 | ||
* | ||
* Copyright (C) 2024 A Minecraft Server and contributors | ||
* | ||
* Carpet AMS Addition is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Carpet AMS Addition is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Carpet AMS Addition. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package club.mcams.carpet.mixin.rule.perfectInvisibility_sneakInvisibility; | ||
|
||
import net.minecraft.entity.Entity; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
||
@Mixin(Entity.class) | ||
public interface EntityInvoker { | ||
@Invoker("isInvisible") | ||
boolean invokeIsInvisible(); | ||
|
||
@Invoker("isSneaky") | ||
boolean invokeIsSneaky(); | ||
} |
51 changes: 51 additions & 0 deletions
51
...club/mcams/carpet/mixin/rule/perfectInvisibility_sneakInvisibility/LivingEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* This file is part of the Carpet AMS Addition project, licensed under the | ||
* GNU Lesser General Public License v3.0 | ||
* | ||
* Copyright (C) 2024 A Minecraft Server and contributors | ||
* | ||
* Carpet AMS Addition is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Carpet AMS Addition is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Carpet AMS Addition. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package club.mcams.carpet.mixin.rule.perfectInvisibility_sneakInvisibility; | ||
|
||
import club.mcams.carpet.AmsServerSettings; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyReturnValue; | ||
|
||
import net.minecraft.entity.LivingEntity; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
@Mixin(LivingEntity.class) | ||
public abstract class LivingEntityMixin implements EntityInvoker { | ||
@ModifyReturnValue(method = "getAttackDistanceScalingFactor", at = @At("RETURN")) | ||
private double modifyAttackDistanceScalingFactor(double original) { | ||
if (AmsServerSettings.perfectInvisibility && this.invokeIsInvisible()) { | ||
return 0.0D; | ||
} else { | ||
return original; | ||
} | ||
} | ||
|
||
@ModifyReturnValue(method = "getAttackDistanceScalingFactor", at = @At("RETURN")) | ||
private double sneakInvisibility(double original) { | ||
if (AmsServerSettings.sneakInvisibility && this.invokeIsSneaky()) { | ||
return 0.0D; | ||
} else { | ||
return original; | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
.../java/club/mcams/carpet/mixin/rule/sendPlayerDeathLocation/ServerPlayerEntityInvoker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* This file is part of the Carpet AMS Addition project, licensed under the | ||
* GNU Lesser General Public License v3.0 | ||
* | ||
* Copyright (C) 2024 A Minecraft Server and contributors | ||
* | ||
* Carpet AMS Addition is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Carpet AMS Addition is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Carpet AMS Addition. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package club.mcams.carpet.mixin.rule.sendPlayerDeathLocation; | ||
|
||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.server.world.ServerWorld; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
||
@Mixin(ServerPlayerEntity.class) | ||
public interface ServerPlayerEntityInvoker { | ||
//#if MC>=12000 | ||
//$$ @Invoker("getServerWorld") | ||
//#else | ||
@Invoker("getWorld") | ||
//#endif | ||
ServerWorld invokeGetWorld(); | ||
} |
59 changes: 59 additions & 0 deletions
59
...in/java/club/mcams/carpet/mixin/rule/sendPlayerDeathLocation/ServerPlayerEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* This file is part of the Carpet AMS Addition project, licensed under the | ||
* GNU Lesser General Public License v3.0 | ||
* | ||
* Copyright (C) 2024 A Minecraft Server and contributors | ||
* | ||
* Carpet AMS Addition is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Carpet AMS Addition is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Carpet AMS Addition. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package club.mcams.carpet.mixin.rule.sendPlayerDeathLocation; | ||
|
||
import club.mcams.carpet.AmsServer; | ||
import club.mcams.carpet.AmsServerSettings; | ||
import club.mcams.carpet.helpers.rule.sendPlayerDeathLocation.PlayerDeathLocationContext; | ||
|
||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.world.World; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.util.Objects; | ||
|
||
@Mixin(ServerPlayerEntity.class) | ||
public abstract class ServerPlayerEntityMixin implements ServerPlayerEntityInvoker { | ||
@Inject(method = "onDeath", at = @At("TAIL")) | ||
private void sendDeathLocation(CallbackInfo ci) { | ||
if (!Objects.equals(AmsServerSettings.sendPlayerDeathLocation, "false")) { | ||
MinecraftServer server = AmsServer.minecraftServer; | ||
ServerPlayerEntity player = (ServerPlayerEntity) (Object) this; | ||
World world = this.invokeGetWorld(); | ||
switch (AmsServerSettings.sendPlayerDeathLocation) { | ||
case "all": | ||
PlayerDeathLocationContext.sendMessage(server, player, world); | ||
break; | ||
case "realPlayerOnly": | ||
PlayerDeathLocationContext.realPlayerSendMessage(server, player, world); | ||
break; | ||
case "fakePlayerOnly": | ||
PlayerDeathLocationContext.fakePlayerSendMessage(server, player, world); | ||
break; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.