Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Command Parser #874

Merged
merged 47 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4526cbd
init refactor
CoolLoong Dec 15, 2022
4594b55
update lang and add command output
CoolLoong Dec 15, 2022
aa15f1b
init commandLogger
CoolLoong Dec 18, 2022
d2db567
refactor ExecuteCommand with new API
CoolLoong Dec 19, 2022
b1f65b9
annotation
CoolLoong Dec 19, 2022
517b8e7
not default testPermission
CoolLoong Dec 19, 2022
ba52001
Merge branch 'master' into feature/refactor-commandparser
CoolLoong Dec 30, 2022
5a1edc5
some change
CoolLoong Dec 30, 2022
0e86059
fix test
CoolLoong Dec 30, 2022
77504da
add successcount
CoolLoong Jan 1, 2023
498800b
AbilityCommand
CoolLoong Jan 2, 2023
0684412
ban banip give
CoolLoong Jan 4, 2023
65771d0
optimize
CoolLoong Jan 5, 2023
5bec721
fix test
CoolLoong Jan 5, 2023
e067ff9
ClearCommand CameraShakeCommand
CoolLoong Jan 5, 2023
9a322ec
optimize error message
CoolLoong Jan 6, 2023
d4cd996
ClearSpawnPointCommand
CoolLoong Jan 6, 2023
c9cbfea
add GenericParameter
CoolLoong Jan 6, 2023
f4ce5f0
clone damage daylock debug
CoolLoong Jan 7, 2023
20616a4
deop Difficulty effect enchant executeold
CoolLoong Jan 8, 2023
0d7f4e0
fill fog
CoolLoong Jan 8, 2023
47e164c
many command
CoolLoong Jan 12, 2023
148a4e2
fix test
CoolLoong Jan 12, 2023
8e99f64
Merge branch 'master' into feature/refactor-commandparser
CoolLoong Jan 15, 2023
3925229
to ReplaceItemCommand
CoolLoong Jan 15, 2023
a5d0bdc
to SeedCommand
CoolLoong Jan 15, 2023
f115b47
to SetBlockCommand
CoolLoong Jan 15, 2023
848b104
final
CoolLoong Jan 15, 2023
a68ee82
fix a before bug
CoolLoong Jan 15, 2023
65c5435
to SpreadPlayersCommand
CoolLoong Jan 15, 2023
cb2008d
update baselang
CoolLoong Jan 15, 2023
5953680
fix lang error
CoolLoong Jan 16, 2023
48bf9f0
Plugin Multilanguage Support
CoolLoong Jan 16, 2023
f7d5659
to TimeCommand
CoolLoong Jan 16, 2023
7021e9f
to WorldCommand
CoolLoong Jan 16, 2023
e63b6dc
complete
CoolLoong Jan 16, 2023
1a2a612
fix some bug
CoolLoong Jan 17, 2023
0fbe3ec
fix some bug2
CoolLoong Jan 17, 2023
c9248ae
fix some bug3
CoolLoong Jan 17, 2023
6da55ad
fix some bug4
CoolLoong Jan 17, 2023
d83a31a
fix some bug5
CoolLoong Jan 17, 2023
4246920
fix some bug6
CoolLoong Jan 18, 2023
339b732
fix some bug7
CoolLoong Jan 18, 2023
cd46875
Merge branch 'master' into feature/refactor-commandparser
CoolLoong Jan 20, 2023
a61301d
merge
CoolLoong Jan 20, 2023
10a47c2
remove debug
CoolLoong Jan 20, 2023
ebf6454
doc
CoolLoong Jan 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 19 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@
<activeByDefault>false</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<profiles.active>test</profiles.active>
<skipShade>true</skipShade>
<skipCopyLibs>true</skipCopyLibs>
<skipGpg>true</skipGpg>
<maven.javadoc.skip>true</maven.javadoc.skip>
<skipDelombok>true</skipDelombok>
<skipNexus>true</skipNexus>
<skipTests>false</skipTests>
</properties>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
</profile>
</profiles>

<distributionManagement>
Expand Down Expand Up @@ -197,9 +213,9 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.powernukkit</groupId>
<artifactId>powernukkit-tests-junit5</artifactId>
<version>0.1.1</version>
<groupId>cn.powernukkitx</groupId>
<artifactId>powernukkitx-tests-junit5</artifactId>
<version>0.0.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/nukkit/Achievement.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static boolean broadcast(Player player, String achievementId) {
if (!achievements.containsKey(achievementId)) {
return false;
}
String translation = Server.getInstance().getLanguage().translateString("chat.type.achievement", player.getDisplayName(), TextFormat.GREEN + achievements.get(achievementId).getMessage() + TextFormat.RESET);
String translation = Server.getInstance().getLanguage().tr("chat.type.achievement", player.getDisplayName(), TextFormat.GREEN + achievements.get(achievementId).getMessage() + TextFormat.RESET);

if (Server.getInstance().getPropertyBoolean("announce-player-achievements", true)) {
Server.getInstance().broadcastMessage(translation);
Expand Down Expand Up @@ -62,7 +62,7 @@ public String getMessage() {
}

public void broadcast(Player player) {
String translation = Server.getInstance().getLanguage().translateString("chat.type.achievement", player.getDisplayName(), TextFormat.GREEN + this.getMessage(), null);
String translation = Server.getInstance().getLanguage().tr("chat.type.achievement", player.getDisplayName(), TextFormat.GREEN + this.getMessage());

if (Server.getInstance().getPropertyBoolean("announce-player-achievements", true)) {
Server.getInstance().broadcastMessage(translation);
Expand Down
47 changes: 32 additions & 15 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import cn.nukkit.item.customitem.ItemCustom;
import cn.nukkit.item.enchantment.Enchantment;
import cn.nukkit.item.enchantment.sideeffect.SideEffect;
import cn.nukkit.lang.CommandOutputContainer;
import cn.nukkit.lang.LangCode;
import cn.nukkit.lang.TextContainer;
import cn.nukkit.lang.TranslationContainer;
import cn.nukkit.level.*;
Expand Down Expand Up @@ -1089,7 +1091,7 @@ protected void handleMovement(Location clientPos) {
PlayerInvalidMoveEvent event = new PlayerInvalidMoveEvent(this, true);
this.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled() && (invalidMotion = event.isRevert())) {
log.warn(this.getServer().getLanguage().translateString("nukkit.player.invalidMove", this.getName()));
this.server.getLogger().warning(this.getServer().getLanguage().tr("nukkit.player.invalidMove", this.getName()));
}
}

Expand Down Expand Up @@ -1551,7 +1553,7 @@ protected void completeLoginSequence() {
this.setNameTagAlwaysVisible(true);
this.setCanClimb(true);

log.info(this.getServer().getLanguage().translateString("nukkit.player.logIn",
log.info(this.getServer().getLanguage().tr("nukkit.player.logIn",
TextFormat.AQUA + this.username + TextFormat.WHITE,
this.getAddress(),
String.valueOf(this.getPort()),
Expand Down Expand Up @@ -2721,7 +2723,7 @@ public boolean dataPacket(DataPacket packet) {
if (log.isTraceEnabled() && !server.isIgnoredPacket(packet.getClass())) {
log.trace("Outbound {}: {}", this.getName(), packet);
}
this.interfaz.putPacket(this, packet, false, false);
this.getNetworkSession().sendPacket(packet);
}
return true;
}
Expand Down Expand Up @@ -4213,7 +4215,7 @@ public void onCompletion(Server server) {
break;
}
this.kick(PlayerKickEvent.Reason.INVALID_PVE, "Attempting to interact with an invalid entity");
log.warn(this.getServer().getLanguage().translateString("nukkit.player.invalidEntity", this.getName()));
log.warn(this.getServer().getLanguage().tr("nukkit.player.invalidEntity", this.getName()));
break;
}

Expand Down Expand Up @@ -5528,7 +5530,7 @@ public boolean chat(String message) {
PlayerChatEvent chatEvent = new PlayerChatEvent(this, msg);
this.server.getPluginManager().callEvent(chatEvent);
if (!chatEvent.isCancelled()) {
this.server.broadcastMessage(this.getServer().getLanguage().translateString(chatEvent.getFormat(), new String[]{chatEvent.getPlayer().getDisplayName(), chatEvent.getMessage()}), chatEvent.getRecipients());
this.server.broadcastMessage(this.getServer().getLanguage().tr(chatEvent.getFormat(), new String[]{chatEvent.getPlayer().getDisplayName(), chatEvent.getMessage()}), chatEvent.getRecipients());
}
}
}
Expand Down Expand Up @@ -5652,7 +5654,7 @@ public int getViewDistance() {
public void sendMessage(String message) {
TextPacket pk = new TextPacket();
pk.type = TextPacket.TYPE_RAW;
pk.message = this.server.getLanguage().translateString(message);
pk.message = this.server.getLanguage().tr(message);
this.dataPacket(pk);
}

Expand All @@ -5665,6 +5667,17 @@ public void sendMessage(TextContainer message) {
this.sendMessage(message.getText());
}

@PowerNukkitXOnly
@Since("1.19.50-r4")
public void sendCommandOutput(CommandOutputContainer container) {
var pk = new CommandOutputPacket();
pk.messages.addAll(container.getMessages());
pk.commandOriginData = new CommandOriginData(CommandOriginData.Origin.PLAYER, this.getUniqueId(), "", null);//Only players can effect
pk.type = CommandOutputType.ALL_OUTPUT;//Useless
pk.successCount = container.getSuccessCount();//Useless,maybe used for server-client interaction
this.dataPacket(pk);
}

/**
* 在玩家聊天栏发送一个JSON文本
* <p>
Expand Down Expand Up @@ -5702,15 +5715,14 @@ public void sendTranslation(String message, String[] parameters) {
TextPacket pk = new TextPacket();
if (!this.server.isLanguageForced()) {
pk.type = TextPacket.TYPE_TRANSLATION;
pk.message = this.server.getLanguage().translateString(message, parameters, "nukkit.");
pk.message = this.server.getLanguage().tr(message, parameters, "nukkit.", true);
for (int i = 0; i < parameters.length; i++) {
parameters[i] = this.server.getLanguage().translateString(parameters[i], parameters, "nukkit.");

parameters[i] = this.server.getLanguage().tr(parameters[i], parameters, "nukkit.", true);
}
pk.parameters = parameters;
} else {
pk.type = TextPacket.TYPE_RAW;
pk.message = this.server.getLanguage().translateString(message, parameters);
pk.message = this.server.getLanguage().tr(message, parameters);
}
this.dataPacket(pk);
}
Expand All @@ -5733,7 +5745,7 @@ public void sendChat(String source, String message) {
TextPacket pk = new TextPacket();
pk.type = TextPacket.TYPE_CHAT;
pk.source = source;
pk.message = this.server.getLanguage().translateString(message);
pk.message = this.server.getLanguage().tr(message);
this.dataPacket(pk);
}

Expand Down Expand Up @@ -6090,11 +6102,11 @@ public void close(TextContainer message, String reason, boolean notify) {

this.server.getPluginManager().unsubscribeFromPermission(Server.BROADCAST_CHANNEL_USERS, this);
this.spawned = false;
log.info(this.getServer().getLanguage().translateString("nukkit.player.logOut",
log.info(this.getServer().getLanguage().tr("nukkit.player.logOut",
TextFormat.AQUA + (this.getName() == null ? "" : this.getName()) + TextFormat.WHITE,
this.getAddress(),
String.valueOf(this.getPort()),
this.getServer().getLanguage().translateString(reason)));
this.getServer().getLanguage().tr(reason)));
this.windows.clear();
this.usedChunks.clear();
this.loadQueue.clear();
Expand Down Expand Up @@ -6217,6 +6229,12 @@ public String getName() {
return this.username;
}

@PowerNukkitXOnly
@Since("1.19.50-r4")
public LangCode getLanguageCode() {
return LangCode.valueOf(this.getLoginChainData().getLanguageCode());
}

@Override
public void kill() {
if (!this.spawned) {
Expand Down Expand Up @@ -7937,8 +7955,7 @@ public boolean dataPacketImmediately(DataPacket packet) {
if (log.isTraceEnabled() && !server.isIgnoredPacket(packet.getClass())) {
log.trace("Immediate Outbound {}: {}", this.getName(), packet);
}

this.interfaz.putPacket(this, packet, false, true);
this.getNetworkSession().sendImmediatePacket(packet);
}

return true;
Expand Down