forked from Jay113355/NBTEdit
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: 秋雨落 <[email protected]>
- Loading branch information
Showing
46 changed files
with
507 additions
and
675 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
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
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 |
---|---|---|
|
@@ -21,3 +21,11 @@ publishing { | |
repositories { | ||
} | ||
} | ||
|
||
sourceSets { | ||
main { | ||
resources { | ||
srcDir file('src/generated/resources') | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
common/src/generated/resources/.cache/2a65ee2815744be1ef1ffdae1c9a37f2a9cbe2ac
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,2 @@ | ||
// 1.20.1 2023-10-01T21:16:50.0633302 Languages: zh_cn | ||
b1886b14eefc7f775e9036becb02204f0de4034b assets/nbtedit/lang/zh_cn.json |
2 changes: 2 additions & 0 deletions
2
common/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8
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,2 @@ | ||
// 1.20.1 2023-10-01T21:16:50.0663481 Languages: en_us | ||
51fa5556855fd781a16c10497a93dc0bcc2cf4aa assets/nbtedit/lang/en_us.json |
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
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
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 |
---|---|---|
|
@@ -2,4 +2,6 @@ | |
|
||
public interface INBTEditConfig { | ||
boolean canEditOthers(); | ||
|
||
boolean isDebug(); | ||
} |
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
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
3 changes: 0 additions & 3 deletions
3
common/src/main/java/cx/rain/mc/nbtedit/gui/component/NBTNodeComponent.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
1 change: 0 additions & 1 deletion
1
common/src/main/java/cx/rain/mc/nbtedit/gui/component/button/NBTOperatorButton.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
83 changes: 83 additions & 0 deletions
83
common/src/main/java/cx/rain/mc/nbtedit/networking/NBTEditEditingHelper.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,83 @@ | ||
package cx.rain.mc.nbtedit.networking; | ||
|
||
import cx.rain.mc.nbtedit.NBTEdit; | ||
import cx.rain.mc.nbtedit.utility.Constants; | ||
import net.minecraft.ChatFormatting; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
import java.util.UUID; | ||
|
||
public class NBTEditEditingHelper { | ||
public static void editBlockEntity(ServerPlayer player, BlockPos pos) { | ||
if (!NBTEditNetworkingHelper.checkPermission(player)) { | ||
return; | ||
} | ||
|
||
if (!NBTEditNetworkingHelper.checkPosLoaded(player, pos)) { | ||
return; | ||
} | ||
|
||
NBTEdit.getInstance().getLogger().info("Player " + player.getName().getString() + " requested BlockEntity at " + | ||
pos.getX() + " " + pos.getY() + " " + pos.getZ() + "."); | ||
|
||
var blockEntity = player.serverLevel().getBlockEntity(pos); | ||
if (blockEntity == null) { | ||
player.createCommandSourceStack().sendFailure(Component.translatable(Constants.MESSAGE_TARGET_IS_NOT_BLOCK_ENTITY) | ||
.withStyle(ChatFormatting.RED)); | ||
return; | ||
} | ||
|
||
player.sendSystemMessage(Component.translatable(Constants.MESSAGE_EDITING_BLOCK_ENTITY, | ||
pos.getX(), pos.getY(), pos.getZ()).withStyle(ChatFormatting.GREEN)); | ||
NBTEdit.getInstance().getNetworking().serverOpenClientGui(player, pos, blockEntity); | ||
} | ||
|
||
public static void editEntity(ServerPlayer player, UUID entityUuid) { | ||
if (!NBTEditNetworkingHelper.checkPermission(player)) { | ||
return; | ||
} | ||
|
||
var entity = player.serverLevel().getEntity(entityUuid); | ||
|
||
assert entity != null; // XXX: qyl27: will it work? | ||
|
||
if (entity instanceof Player | ||
&& entity != player | ||
&& !NBTEdit.getInstance().getConfig().canEditOthers()) { | ||
NBTEdit.getInstance().getLogger().info("Player " + player.getName().getString() + | ||
" tried to use /nbtedit on a player. But config is not allow that."); | ||
player.createCommandSourceStack().sendFailure(Component | ||
.translatable(Constants.MESSAGE_CANNOT_EDIT_OTHER_PLAYER) | ||
.withStyle(ChatFormatting.RED)); | ||
return; | ||
} | ||
|
||
player.sendSystemMessage(Component.translatable(Constants.MESSAGE_EDITING_ENTITY, entityUuid) | ||
.withStyle(ChatFormatting.GREEN)); | ||
|
||
if (player == entity) { | ||
NBTEdit.getInstance().getNetworking().serverOpenClientGui(player); | ||
NBTEdit.getInstance().getLogger().info("Player " + player.getName().getString() + " is editing itself."); | ||
} else { | ||
NBTEdit.getInstance().getNetworking().serverOpenClientGui(player, entity); | ||
NBTEdit.getInstance().getLogger().info("Player " + player.getName().getString() + | ||
" is editing entity " + entity.getUUID() + "."); | ||
} | ||
} | ||
|
||
public static void editItemStack(ServerPlayer player, ItemStack stack) { | ||
if (!NBTEditNetworkingHelper.checkPermission(player)) { | ||
return; | ||
} | ||
|
||
player.sendSystemMessage(Component.translatable(Constants.MESSAGE_EDITING_ITEM_STACK, | ||
stack.getDisplayName().getString()).withStyle(ChatFormatting.GREEN)); | ||
NBTEdit.getInstance().getLogger().info("Player " + player.getName().getString() + | ||
" is editing ItemStack named " + stack.getDisplayName().getString() + "."); | ||
NBTEdit.getInstance().getNetworking().serverOpenClientGui(player, stack); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
common/src/main/java/cx/rain/mc/nbtedit/networking/NBTEditNetworkingHelper.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,40 @@ | ||
package cx.rain.mc.nbtedit.networking; | ||
|
||
import cx.rain.mc.nbtedit.NBTEdit; | ||
import cx.rain.mc.nbtedit.utility.Constants; | ||
import net.minecraft.ChatFormatting; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.server.level.ServerPlayer; | ||
|
||
public class NBTEditNetworkingHelper { | ||
public static boolean checkPermission(ServerPlayer player) { | ||
var result = NBTEdit.getInstance().getPermission().hasPermission(player); | ||
|
||
if (!result) { | ||
player.sendSystemMessage(Component.translatable(Constants.MESSAGE_NO_PERMISSION) | ||
.withStyle(ChatFormatting.RED)); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public static boolean checkPosLoaded(ServerPlayer player, BlockPos pos) { | ||
var result = player.serverLevel().isLoaded(pos); | ||
|
||
if (!result) { | ||
player.sendSystemMessage(Component.translatable(Constants.MESSAGE_NOT_LOADED) | ||
.withStyle(ChatFormatting.RED)); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public static boolean isDebug() { | ||
return NBTEdit.getInstance().getConfig().isDebug(); | ||
} | ||
|
||
public static boolean canEditOthers() { | ||
return NBTEdit.getInstance().getConfig().canEditOthers(); | ||
} | ||
} |
Oops, something went wrong.