-
Notifications
You must be signed in to change notification settings - Fork 14
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
Showing
16 changed files
with
203 additions
and
17 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
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
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
54 changes: 54 additions & 0 deletions
54
Allay-Server/src/main/java/org/allaymc/server/command/defaults/EnchantCommand.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,54 @@ | ||
package org.allaymc.server.command.defaults; | ||
|
||
import org.allaymc.api.command.SimpleCommand; | ||
import org.allaymc.api.command.tree.CommandTree; | ||
import org.allaymc.api.container.Container; | ||
import org.allaymc.api.container.FullContainerType; | ||
import org.allaymc.api.entity.interfaces.EntityPlayer; | ||
import org.allaymc.api.i18n.TrKeys; | ||
import org.allaymc.api.item.enchantment.EnchantmentType; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Allay Project 2024/6/15 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
public class EnchantCommand extends SimpleCommand { | ||
|
||
public EnchantCommand() { | ||
super("enchant", TrKeys.M_COMMANDS_ENCHANT_DESCRIPTION); | ||
} | ||
|
||
@Override | ||
public void prepareCommandTree(CommandTree tree) { | ||
tree.getRoot() | ||
.playerTarget("player") | ||
.enchantmentNode("enchantmentName") | ||
.shortNum("level") | ||
.exec(ctx -> { | ||
Collection<EntityPlayer> players = ctx.getFirstResult(); | ||
EnchantmentType enchantmentType = ctx.getSecondResult(); | ||
short level = ctx.getThirdResult(); | ||
for (var player : players) { | ||
var item = player.getContainer(FullContainerType.PLAYER_INVENTORY).getItemInHand(); | ||
if (item == Container.EMPTY_SLOT_PLACE_HOLDER) { | ||
// 手上没东西 | ||
ctx.addOutput(TrKeys.M_COMMANDS_ENCHANT_NOITEM); | ||
return ctx.fail(); | ||
} | ||
var incompatibleEnchantmentType = item.getIncompatibleEnchantmentType(enchantmentType); | ||
if (incompatibleEnchantmentType != null) { | ||
// 新附魔和已有附魔有冲突 | ||
ctx.addOutput(TrKeys.M_COMMANDS_ENCHANT_CANTCOMBINE, incompatibleEnchantmentType.getIdentifier(), enchantmentType.getIdentifier()); | ||
return ctx.fail(); | ||
} | ||
item.addEnchantment(enchantmentType, level); | ||
player.sendItemInHandUpdate(); | ||
ctx.addOutput(TrKeys.M_COMMANDS_ENCHANT_SUCCESS, enchantmentType.getIdentifier()); | ||
} | ||
return ctx.success(); | ||
}); | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
Allay-Server/src/main/java/org/allaymc/server/command/tree/node/EnchantmentNode.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,31 @@ | ||
package org.allaymc.server.command.tree.node; | ||
|
||
import org.allaymc.api.command.tree.CommandNode; | ||
import org.allaymc.api.item.enchantment.EnchantmentRegistry; | ||
import org.allaymc.api.item.enchantment.EnchantmentType; | ||
import org.allaymc.api.utils.Identifier; | ||
|
||
import static org.allaymc.api.utils.Identifier.DEFAULT_NAMESPACE; | ||
|
||
/** | ||
* Allay Project 2024/6/15 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
public class EnchantmentNode extends EnumNode { | ||
|
||
protected static final String[] ENCHANTMENT_STR_ARRAY = | ||
EnchantmentRegistry.getRegistry().getContent().m1().values() | ||
.stream() | ||
.map(type -> type.getIdentifier().path()) | ||
.toArray(String[]::new); | ||
|
||
public EnchantmentNode(String name, CommandNode parent, EnchantmentType defaultValue) { | ||
super(name, parent, defaultValue, ENCHANTMENT_STR_ARRAY); | ||
} | ||
|
||
@Override | ||
protected Object argToResult(String arg) { | ||
return EnchantmentRegistry.getRegistry().getByK2(new Identifier(DEFAULT_NAMESPACE, arg)); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
Allay-Server/src/main/java/org/allaymc/server/command/tree/node/ShortNode.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 org.allaymc.server.command.tree.node; | ||
|
||
import org.allaymc.api.command.tree.BaseNode; | ||
import org.allaymc.api.command.tree.CommandContext; | ||
import org.allaymc.api.command.tree.CommandNode; | ||
import org.cloudburstmc.protocol.bedrock.data.command.CommandParam; | ||
import org.cloudburstmc.protocol.bedrock.data.command.CommandParamData; | ||
|
||
/** | ||
* Allay Project 2024/6/15 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
public class ShortNode extends BaseNode { | ||
|
||
public ShortNode(String name, CommandNode parent, short defaultValue) { | ||
super(name, parent, defaultValue); | ||
} | ||
|
||
@Override | ||
public boolean match(CommandContext context) { | ||
var arg = context.queryArg(); | ||
short number; | ||
try { | ||
number = Short.parseShort(arg); | ||
} catch (NumberFormatException e) { | ||
return false; | ||
} | ||
context.putResult(number); | ||
context.popArg(); | ||
return true; | ||
} | ||
|
||
@Override | ||
public CommandParamData toNetworkData() { | ||
var data = super.toNetworkData(); | ||
data.setType(CommandParam.INT); | ||
return data; | ||
} | ||
} |
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
Oops, something went wrong.