Skip to content

Commit

Permalink
Merge branch '1.20.2' into 1.20.2-folia
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Nov 3, 2023
2 parents 4d3e697 + 024fb8e commit 97d5053
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 34 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project_version=0.13.3
project_version=0.13.4

# FM Protocols
protocols_version=09b2b0a077
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/xiamomc/morph/MorphManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ private void load()

try
{
if (1+1==2)
throw new NoClassDefFoundError();

this.currentBackend = new LibsBackend();
}
catch (NoClassDefFoundError e)
Expand All @@ -141,6 +138,7 @@ private void load()
bannedDisguises = config.getBindableList(ConfigOption.BANNED_DISGUISES);
config.bind(allowHeadMorph, ConfigOption.ALLOW_HEAD_MORPH);
config.bind(allowAcquireMorph, ConfigOption.ALLOW_ACQUIRE_MORPHS);
config.bind(useClientRenderer, ConfigOption.USE_CLIENT_RENDERER);

registerProviders(ObjectList.of(
new VanillaDisguiseProvider(),
Expand Down Expand Up @@ -336,6 +334,7 @@ public boolean registerProviders(List<DisguiseProvider> providers)
private final Bindable<Boolean> allowHeadMorph = new Bindable<>(true);

private final Bindable<Boolean> allowAcquireMorph = new Bindable<>(true);
private final Bindable<Boolean> useClientRenderer = new Bindable<>(false);

private final Map<UUID, PlayerTextures> uuidPlayerTexturesMap = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -731,7 +730,7 @@ else if (!provider.isValid(key))

public boolean isUsingClientRenderer()
{
return currentBackend == nilBackend;
return currentBackend == nilBackend && useClientRenderer.get();
}

//region Command generating
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xiamomc.morph.commands.subcommands.plugin;

import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -53,6 +54,9 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull String[] args)
private void onRequestFinish(UpdateHandler.CheckResult result, CommandSender sender)
{
if (result == UpdateHandler.CheckResult.ALREADY_LATEST)
sender.sendMessage(MessageUtils.prefixes(sender, UpdateStrings.noNewVersionAvailable()));
{
var msg = UpdateStrings.noNewVersionAvailable().resolve("mc_version", Bukkit.getMinecraftVersion());
sender.sendMessage(MessageUtils.prefixes(sender, msg));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public OptionSubCommand()
subCommands.add(getToggle("allow_acquire_morphs", ConfigOption.ALLOW_ACQUIRE_MORPHS, "allow_acquire_morphs"));

subCommands.add(getToggle("allow_flight", ConfigOption.ALLOW_FLIGHT, "allow_flight"));

subCommands.add(getToggle("client_renderer", ConfigOption.USE_CLIENT_RENDERER, "client_renderer"));
}

private <T> ISubCommand getGeneric(String name, ConfigOption option, String perm,
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 @@ -39,6 +39,8 @@ public enum ConfigOption
LOG_INCOMING_PACKETS(clientNode().append("log_incoming_packets"), false),
LOG_OUTGOING_PACKETS(clientNode().append("log_outgoing_packets"), false),

USE_CLIENT_RENDERER(clientNode().append("client_renderer"), true),

MIRROR_CONTROL_DISTANCE(interactionMirrorNode().append("normalDistance"), -1),
MIRROR_IGNORE_DISGUISED(interactionMirrorNode().append("ignore_disguised"), true),
MIRROR_DESTROY_TIMEOUT(interactionMirrorNode().append("destroy_timeout"), 40),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/xiamomc/morph/config/MorphConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void reload()
super.reload();

//更新配置
int targetVersion = 26;
int targetVersion = 27;

var configVersion = getOrDefault(Integer.class, ConfigOption.VERSION);

Expand Down
15 changes: 8 additions & 7 deletions src/main/java/xiamomc/morph/events/CommonEventProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import xiamomc.morph.misc.NetworkingHelper;
import xiamomc.morph.misc.permissions.CommonPermissions;
import xiamomc.morph.network.commands.S2C.S2CSwapCommand;
import xiamomc.morph.network.commands.S2C.clientrender.S2CRenderMapMetaCommand;
import xiamomc.morph.network.commands.S2C.map.S2CMapRemoveCommand;
import xiamomc.morph.network.server.MorphClientHandler;
import xiamomc.morph.network.server.ServerSetEquipCommand;
Expand Down Expand Up @@ -166,7 +165,7 @@ public void onPlayerTookDamage(EntityDamageEvent e)

if (state != null)
{
state.getSoundHandler().resetAmbientSoundInterval();
state.getSoundHandler().resetSoundTime();

//如果伤害是0,那么取消事件
if (e.getDamage() > 0d)
Expand Down Expand Up @@ -445,14 +444,16 @@ public void onPlayerJoin(PlayerJoinEvent e)

networkingHelper.sendCommandToRevealablePlayers(morphs.genPartialMapCommand(state));

var metaCommand = networkingHelper.prepareMeta(player)
.forDisguiseState(state)
.build();
networkingHelper.sendCommandToAllPlayers(metaCommand);

if (morphs.isUsingClientRenderer())
{
networkingHelper.sendCommandToAllPlayers(morphs.genClientRenderAddCommand(state));

var metaCommand = networkingHelper.prepareMeta(player)
.forDisguiseState(state)
.build();
networkingHelper.sendCommandToAllPlayers(metaCommand);
}

//调用Morph事件
new PlayerJoinedWithDisguiseEvent(player, state).callEvent();

Expand Down
15 changes: 12 additions & 3 deletions src/main/java/xiamomc/morph/misc/DisguiseState.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.jetbrains.annotations.Nullable;
import xiamomc.morph.MorphManager;
import xiamomc.morph.MorphPluginObject;
import xiamomc.morph.abilities.AbilityHandler;
import xiamomc.morph.abilities.IMorphAbility;
import xiamomc.morph.backends.DisguiseWrapper;
import xiamomc.morph.config.ConfigOption;
Expand Down Expand Up @@ -518,7 +517,7 @@ public void setDisguise(@NotNull String identifier, @NotNull String skillIdentif
supportsDisguisedItems = skillHandler.hasSpeficSkill(skillIdentifier, SkillType.INVENTORY);

//设置声音
this.soundHandler.refreshSounds(getEntityType(), wrapper.isBaby());
this.soundHandler.refreshSounds(wrapper.getEntityType(), wrapper.isBaby());

//重置伪装物品
if (shouldRefreshDisguiseItems)
Expand Down Expand Up @@ -659,7 +658,7 @@ public static class SoundHandler
private int soundTime;
private double soundFrequency = 0D;

public void resetAmbientSoundInterval()
public void resetSoundTime()
{
soundTime = 0;
}
Expand Down Expand Up @@ -724,8 +723,18 @@ else if (sound != null && random.nextInt((int)(1000 * frequencyScale)) < soundTi

private final MorphConfigManager config = MorphConfigManager.getInstance();

public void resetSound()
{
ambientSoundPrimary = null;
ambientSoundSecondary = null;
ambientInterval = 0;
resetSoundTime();
}

public void refreshSounds(EntityType entityType, boolean isBaby)
{
resetSound();

this.entityType = entityType;

soundFrequency = MathUtils.clamp(0, 2, config.getBindable(Double.class, ConfigOption.AMBIENT_FREQUENCY).get());
Expand Down
25 changes: 14 additions & 11 deletions src/main/java/xiamomc/morph/network/server/MorphClientHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ private void logPacket(boolean isOutGoingPacket, Player player, String channel,

private final CommandRegistries registries = new CommandRegistries();
private final Bindable<Boolean> modifyBoundingBoxes = new Bindable<>(false);
private final Bindable<Boolean> useClientRenderer = new Bindable<>(false);

@Initializer
private void load(MorphPlugin plugin, MorphConfigManager configManager)
Expand Down Expand Up @@ -257,6 +258,8 @@ private void load(MorphPlugin plugin, MorphConfigManager configManager)

configManager.bind(modifyBoundingBoxes, ConfigOption.MODIFY_BOUNDING_BOX);

configManager.bind(useClientRenderer, ConfigOption.USE_CLIENT_RENDERER);

modifyBoundingBoxes.onValueChanged((o, n) ->
{
var players = Bukkit.getOnlinePlayers();
Expand All @@ -265,6 +268,7 @@ private void load(MorphPlugin plugin, MorphConfigManager configManager)

forceTargetVersion.onValueChanged((o, n) -> scheduleReAuthPlayers());
modifyBoundingBoxes.onValueChanged((o, n) -> scheduleReAuthPlayers());
useClientRenderer.onValueChanged((o, n) -> scheduleReAuthPlayers());

allowClient.onValueChanged((o, n) ->
{
Expand Down Expand Up @@ -623,21 +627,20 @@ public void onInitialCommand(C2SInitialCommand c2SInitialCommand)
sendCommand(player, manager.genMapCommand());

if (manager.isUsingClientRenderer())
{
sendCommand(player, manager.genRenderSyncCommand());

logger.info("READY!");
var disguises = manager.getDisguiseStates();
for (DisguiseState bindingState : disguises)
{
logger.info("STATE! " + bindingState);
var bindingPlayer = bindingState.getPlayer();
var disguises = manager.getDisguiseStates();
for (DisguiseState bindingState : disguises)
{
var bindingPlayer = bindingState.getPlayer();

var packet = networkingHelper.prepareMeta(bindingPlayer)
.forDisguiseState(bindingState)
.build();
var packet = networkingHelper.prepareMeta(bindingPlayer)
.forDisguiseState(bindingState)
.build();

this.sendCommand(player, packet);
logger.info("SEND! " + packet);
this.sendCommand(player, packet);
}
}

playerConnectionStates.put(player, InitializeState.DONE);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/xiamomc/morph/skills/MorphSkillHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public void executeDisguiseSkill(Player player, boolean bypassPermission)
var cd = skill.executeSkillGeneric(player, state, config, option);
cdInfo.setLastInvoke(plugin.getCurrentTick());

state.getSoundHandler().resetAmbientSoundInterval();
state.getSoundHandler().resetSoundTime();

if (!state.haveCooldown()) state.setCooldownInfo(cdInfo);
else state.setSkillCooldown(cd);
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/xiamomc/morph/updates/UpdateHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ private void onUpdateReqFinish(CloseableHttpResponse response, int reqId,
var supportedLoaders = m.supportedLoaders;
if (supportedLoaders == null) return false;

return supportedLoaders.stream().anyMatch(s -> s.equalsIgnoreCase(loader.getImplName()));
var isRelease = "Release".equalsIgnoreCase(m.versionType);
var loaderMatch = supportedLoaders.stream().anyMatch(s -> s.equalsIgnoreCase(loader.getImplName()));

return isRelease && loaderMatch;
}).findFirst().orElse(null);

if (matchMeta == null)
Expand All @@ -197,7 +200,7 @@ private void onUpdateReqFinish(CloseableHttpResponse response, int reqId,

if (currentVersion.equals(latestVersion))
{
logger.info("Already on the latest version");
logger.info("Already on the latest version for " + Bukkit.getMinecraftVersion());

if (onFinish != null)
onFinish.accept(CheckResult.ALREADY_LATEST);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/feathermorph/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"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",
"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",
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/feathermorph/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"update.msg_header_footer": "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-",
"update.checking_update": "检查更新中...",
"update.new_version_available": "FeatherMorph有新版本辣!(<current> -> <origin>)",
"update.no_new_ver_available": "FeatherMorph已是最新版本",
"update.no_new_ver_available": "FeatherMorph已是<mc_version>上的最新版本",
"update.update_here": "在此更新:<url>",
"requests.already_have_disguise": "<color:red>你已经有对方的形态了",
"requests.cant_send_to_self": "<color:red>你不能给自己发请求",
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,9 @@ root:
# Should we log packets sent to the client?
log_outgoing_packets: false

# Make clients render other players' disguises when LibsDisguises is not present?
# Requires the client to implement the v11 protocol
client_renderer: true

# Do not touch unless you know what you're doing!
version: 26
version: 27

0 comments on commit 97d5053

Please sign in to comment.