Skip to content

Commit

Permalink
enhance: 允许设定无法飞行的世界
Browse files Browse the repository at this point in the history
enhance: 允许通过指令设定部分列表类型的配置
misc: 调整FlyAbility更新的频率
misc: 一些本地化
  • Loading branch information
MATRIX-feather committed Dec 8, 2023
1 parent ce3b083 commit ed78e6d
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 52 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ minecraft_version=1.20.2-R0.1-SNAPSHOT

# Dependencies
ld_version=10.0.33
pluginbase_version=76b1510
pluginbase_version=306d580
gsit_version=1.4.1
papi_version=2.11.3
bstats_version=3.0.1
11 changes: 10 additions & 1 deletion src/main/java/xiamomc/morph/abilities/impl/FlyAbility.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import xiamomc.pluginbase.Annotations.Initializer;
import xiamomc.pluginbase.Annotations.Resolved;
import xiamomc.pluginbase.Bindables.Bindable;
import xiamomc.pluginbase.Bindables.BindableList;

import java.util.List;

Expand Down Expand Up @@ -51,6 +52,8 @@ public boolean applyToPlayer(Player player, DisguiseState state)
return false;
}

private final BindableList<String> noFlyWorlds = new BindableList<>();

@Initializer
private void load(MorphConfigManager configManager)
{
Expand All @@ -60,6 +63,8 @@ private void load(MorphConfigManager configManager)
this.exhaustionScaled = exhaustionBase * scale;
}, true);

configManager.bind(String.class, noFlyWorlds, ConfigOption.NOFLY_WORLDS);

configManager.getBindable(Boolean.class, ConfigOption.FLYABILITY_IDLE_CONSUME).onValueChanged((o, n) ->
idleConsumption = n ? 0.1D : 0D, true);

Expand All @@ -75,6 +80,8 @@ private void load(MorphConfigManager configManager)
@Override
public boolean handle(Player player, DisguiseState state)
{
if (plugin.getCurrentTick() % 4 != 0) return true;

var gameMode = player.getGameMode();
if (gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR)
return super.handle(player, state);
Expand All @@ -83,7 +90,9 @@ public boolean handle(Player player, DisguiseState state)
var config = options.get(state.getSkillLookupIdentifier());

var data = nmsPlayer.getFoodData();
var allowFlight = this.allowFlight.get() && data.foodLevel > config.getMinimumHunger();
var allowFlight = this.allowFlight.get()
&& data.foodLevel > config.getMinimumHunger()
&& !noFlyWorlds.contains(player.getWorld().getName());

if (player.isFlying())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import xiamomc.morph.config.MorphConfigManager;
import xiamomc.morph.events.InteractionMirrorProcessor;
import xiamomc.morph.messages.*;
import xiamomc.morph.utilities.BindableUtils;
import xiamomc.pluginbase.Annotations.Resolved;
import xiamomc.pluginbase.Command.ISubCommand;
import xiamomc.pluginbase.Exceptions.NullDependencyException;
Expand Down Expand Up @@ -76,6 +77,9 @@ public OptionSubCommand()
subCommands.add(getToggle("client_renderer", ConfigOption.USE_CLIENT_RENDERER, "client_renderer"));

subCommands.add(getList("banned_disguises", ConfigOption.BANNED_DISGUISES, "banned_disguises", null));
subCommands.add(getList("nofly_worlds", ConfigOption.NOFLY_WORLDS, "nofly_worlds", null));
subCommands.add(getList("blacklist_tags", ConfigOption.BLACKLIST_TAGS, "blacklist_tags", null));
subCommands.add(getList("blacklist_nbt_pattern", ConfigOption.BLACKLIST_PATTERNS, "blacklist_patterns", null));
}

private <T> ISubCommand getGeneric(String name, ConfigOption option, String perm,
Expand All @@ -100,7 +104,7 @@ private ISubCommand getList(String optionName, ConfigOption option, String perm,
{
if (args.length < 1)
{
var displayValue = bindableList.toString();
var displayValue = BindableUtils.bindableListToString(bindableList);
sender.sendMessage(MessageUtils.prefixes(sender,
CommandStrings.optionValueString()
.withLocale(MessageUtils.getLocale(sender))
Expand All @@ -112,7 +116,10 @@ private ISubCommand getList(String optionName, ConfigOption option, String perm,

if (args.length < 2)
{
sender.sendMessage(MessageUtils.prefixes(sender, "参数数量不对"));
sender.sendMessage(MessageUtils.prefixes(sender,
CommandStrings.listNoEnoughArguments()
.withLocale(MessageUtils.getLocale(sender))));

return true;
}

Expand All @@ -124,15 +131,32 @@ private ISubCommand getList(String optionName, ConfigOption option, String perm,
{
bindableList.add(value);

//bug: bindableList的add和remove方法永远返回true
//workaround: List的add方法传入非null时永远返回true
if (bindableList.contains(value))
sender.sendMessage(MessageUtils.prefixes(sender, "成功添加" + value));
{
sender.sendMessage(MessageUtils.prefixes(sender,
CommandStrings.listAddSuccess()
.withLocale(MessageUtils.getLocale(sender))
.resolve("value", value)
.resolve("option", optionName)));
}
else
sender.sendMessage(MessageUtils.prefixes(sender, "未能添加" + value + ", 可能是类型不对"));
{
sender.sendMessage(MessageUtils.prefixes(sender,
CommandStrings.listAddFailUnknown()
.withLocale(MessageUtils.getLocale(sender))
.resolve("value", value)
.resolve("option", optionName)));
}
}
catch (Throwable t)
{
sender.sendMessage(MessageUtils.prefixes(sender, "未能添加" + value + ", 可能是类型不对"));
sender.sendMessage(MessageUtils.prefixes(sender,
CommandStrings.listAddFailUnknown()
.withLocale(MessageUtils.getLocale(sender))
.resolve("value", value)
.resolve("option", optionName)));

logger.error("Error adding option to bindable list: " + t.getMessage());
}

Expand All @@ -141,18 +165,34 @@ private ISubCommand getList(String optionName, ConfigOption option, String perm,
else if (operation.equalsIgnoreCase("remove"))
{
var value = args[1];
bindableList.remove(value);
var listChanged = bindableList.remove(value);

if (!bindableList.contains(value))
sender.sendMessage(MessageUtils.prefixes(sender, "成功移除" + value));
if (listChanged)
{
sender.sendMessage(MessageUtils.prefixes(sender,
CommandStrings.listRemoveSuccess()
.withLocale(MessageUtils.getLocale(sender))
.resolve("value", value)
.resolve("option", optionName)));
}
else
sender.sendMessage(MessageUtils.prefixes(sender, "未能移除" + value + ", 可能是其不在列表中"));
{
sender.sendMessage(MessageUtils.prefixes(sender,
CommandStrings.listRemoveFailUnknown()
.withLocale(MessageUtils.getLocale(sender))
.resolve("value", value)
.resolve("option", optionName)));
}

return true;
}
else
{
sender.sendMessage(MessageUtils.prefixes(sender, "未知操作: " + operation));
sender.sendMessage(MessageUtils.prefixes(sender,
CommandStrings.unknownOperation()
.withLocale(MessageUtils.getLocale(sender))
.resolve("operation", operation)));

return true;
}
});
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/xiamomc/morph/config/ConfigOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public enum ConfigOption

ALLOW_FLIGHT(ConfigNode.create().append("allow_flight"), true),

NOFLY_WORLDS(ConfigNode.create().append("nofly_worlds"), new ArrayList<String>()),

VERSION(ConfigNode.create().append("version"), 0);

public final ConfigNode node;
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/xiamomc/morph/messages/CommandStrings.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,46 @@ public static FormattableMessage argumentTypeErrorString()

//endregion Illegal arguments

//region Lists

public static FormattableMessage listNoEnoughArguments()
{
return getFormattable(getKey("not_enough_arguments"),
"参数不足");
}

public static FormattableMessage listAddSuccess()
{
return getFormattable(getKey("list_add_success"),
"成功添加<value>到<option>");
}

public static FormattableMessage listAddFailUnknown()
{
return getFormattable(getKey("list_add_fail_unknown"),
"未能添加<value>到<option>,可能是类型不对");
}

public static FormattableMessage listRemoveSuccess()
{
return getFormattable(getKey("list_remove_success"),
"成功从<option>移除<value>");
}

public static FormattableMessage listRemoveFailUnknown()
{
return getFormattable(getKey("list_remove_fail_unknown"),
"未能移除<value>,可能是其不在列表中");
}

public static FormattableMessage unknownOperation()
{
return getFormattable(getKey("unknown_operation"),
"未知操作:<operation>");
}

//endregion Lists

private static String getKey(String key)
{
return "commands." + key;
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/xiamomc/morph/utilities/BindableUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package xiamomc.morph.utilities;

import xiamomc.pluginbase.Bindables.BindableList;

public class BindableUtils
{
public static String bindableListToString(BindableList<?> bindableList)
{
var builder = new StringBuilder();
var it = bindableList.listIterator();

while (it.hasNext())
{
var obj = it.next();
builder.append(obj);

if (it.hasNext()) builder.append(", ");
}

return "[%s]".formatted(builder);
}
}
46 changes: 26 additions & 20 deletions src/main/resources/assets/feathermorph/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
"commands.illegal_argument": "Illegal argument: <detail>",
"commands.illegal_argument.type_error": "The type for this argument should be <type>",
"types.double": "Double",
"types.float": "Float",
"types.int": "Integer",
"types.string": "String",
"commands.list_add_fail_unknown": "<color:red>Cannot add \"<value>\" to <option>, maybe the type isn't correct",
"commands.list_add_success": "Added \"<value>\" to <option>",
"commands.list_remove_fail_unknown": "<color:red>Cannot remove \"<value>\", maybe it doesn't exist in the list...",
"commands.list_remove_success": "Removed \"<value>\" from <option>",
"commands.lookup_filter": "Found these disguises using the given filter:",
"commands.manage_grant_fail": "<color:red>Couldn't grant disguise '<what>' to <who>, do they already have this disguise?",
"commands.manage_grant_success": "<color:green>Granted disguise '<what>' to <who>",
"commands.manage_revoke_fail": "<color:red>Couldn't revoke disguise '<what>' from <who>",
"commands.manage_revoke_success": "<color:green>Successfully revoke disguise '<what>' from <who>",
"commands.morph_someone_success": "Disguised <who> as <what>!",
"commands.no_permission": "<color:red>You don't have permission to do that.",
"commands.not_enough_arguments": "<color:red>Not enough arguments!",
"commands.option.name.allow_ld": "Local disguise support",
"commands.option.name.bossbar": "Bossbar simulation",
"commands.option.name.chatoverride": "Chat override",
Expand All @@ -33,10 +36,9 @@
"commands.queryall_offline_store": "(Offline store)",
"commands.queryall_showing_disguised_item": "(Displaying disguised equipment)",
"commands.reload_complete": "Reload complete!",
"commands.unknown_operation": "<color:red>Unknown operation: \"<operation>\"",
"commands.unmorph_all_success": "Successfully undisguised everyone!",
"commands.unmorph_someone_success": "Undisguised <who> Successfully!",
"commands.morph_someone_success": "Disguised <who> as <what>!",
"commands.lookup_filter": "Found these disguises using the given filter:",
"common.command_not_found": "<color:red>Command not found",
"common.player_not_defined": "<color:red>No player specified",
"common.player_not_found": "<color:red>No such player or they are offline",
Expand Down Expand Up @@ -83,6 +85,7 @@
"morph.cooling_down": "<color:red>Please wait before disguising again",
"morph.disguise_banned_or_not_supported": "<color:red>This disguise is not supported or disabled by server",
"morph.disguise_not_defined": "<color:red>No disguise specified",
"morph.disguise_revealed": " (Revealed)",
"morph.disguising_as": "Disguising as <what>",
"morph.disguising_as_skill_avaliable": "<color:#8fe98d>Disguising as <what>",
"morph.disguising_as_skill_preparing": "<color:#eeb565>Disguising as <what>",
Expand All @@ -97,7 +100,9 @@
"morph.morph_unlocked": "<color:green>✔ Unlocked disguise of <what>!",
"morph.morph_visible_after_standup": "The disguise will be visible to you after standing up",
"morph.no_such_local_disguise": "<color:red>No such disguise",
"morph.operation_cancelled": "<red>Operation cancelled by other sources",
"morph.parse_error": "<color:red>Invalid disguise identifier: <id>",
"morph.partial_damaged": " (Partial Revealed)",
"morph.self_visible_off": "<color:red>Toggled SelfView off",
"morph.self_visible_on": "<color:green>Toggled SelfView on",
"morph.skill.difficulty_is_peaceful": "This doesn't work because the difficulty is Peaceful",
Expand All @@ -118,14 +123,6 @@
"morph.state.recovering_limited_hint": "<italic>The recovered disguise may differ from before",
"morph.state.reset": "Some feature has been reset, we are now canceling your disguise...",
"morph.unmorph_success": "Undisguised",
"morph.operation_cancelled": "<red>Operation cancelled by other sources",
"morph.disguise_revealed": " (Revealed)",
"morph.partial_damaged": " (Partial Revealed)",
"update.msg_header_footer": "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-",
"update.checking_update": "Checking update...",
"update.new_version_available": "A newer version of FeatherMorph has been released!(<current> -> <origin>)",
"update.no_new_ver_available": "You're already on the latest version for <mc_version>",
"update.update_here": "Update here: <url>",
"requests.already_have_disguise": "<color:red>You already have their disguise!",
"requests.cant_send_to_self": "<color:red>You can't send requests to yourself",
"requests.request_accepted": "Accepted <who>'s request!",
Expand All @@ -138,12 +135,21 @@
"requests.request_received_accept": "Send /request accept <who> to accept the request",
"requests.request_received_deny": "Send /request deny <who> to deny the request",
"requests.request_send": "Request sent! They have 1 minute to accept!",
"stat.version": "FeatherMorph <version> by <author> (Implementing protocol v<proto>)",
"stat.abilities": "Registered Abilities: <count>",
"stat.active_clients": "Active client connections: <count>",
"stat.active_disguises": "Active Disguises: <count>/<max>",
"stat.backend": "Current Backend: <backend>",
"stat.providers": "Registered Disguise Providers: <count>",
"stat.banned_disguises": "Banned Disguises: <count>",
"stat.abilities": "Registered Abilities: <count>",
"stat.providers": "Registered Disguise Providers: <count>",
"stat.skills": "Registered Skills: <count>",
"stat.active_clients": "Active client connections: <count>",
"stat.active_disguises": "Active Disguises: <count>/<max>"
}
"stat.version": "FeatherMorph <version> by <author> (Implementing protocol v<proto>)",
"types.double": "Double",
"types.float": "Float",
"types.int": "Integer",
"types.string": "String",
"update.checking_update": "Checking update...",
"update.msg_header_footer": "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-",
"update.new_version_available": "A newer version of FeatherMorph has been released!(<current> -> <origin>)",
"update.no_new_ver_available": "You're already on the latest version for <mc_version>",
"update.update_here": "Update here: <url>"
}
Loading

0 comments on commit ed78e6d

Please sign in to comment.