mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-11-16 10:45:15 +01:00
Add update listener, fix ViaVersion dependency, fix UUID usages
This commit is contained in:
parent
c8b991d5df
commit
c9b6313a72
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2018 creeper123123321 and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.creeper123123321.viafabric.listeners;
|
||||||
|
|
||||||
|
import com.github.creeper123123321.viafabric.commands.NMSCommandSender;
|
||||||
|
import com.github.creeper123123321.viafabric.platform.VRClientSideUserConnection;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import us.myles.ViaVersion.api.Via;
|
||||||
|
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||||
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
|
import us.myles.ViaVersion.update.UpdateUtil;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class UpdateListener {
|
||||||
|
public static void onJoin(UserConnection conn) {
|
||||||
|
UUID id = conn.getProtocolInfo().getUuid();
|
||||||
|
if (conn instanceof VRClientSideUserConnection) {
|
||||||
|
onClientJoin(id);
|
||||||
|
} else {
|
||||||
|
onServerJoin(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void onClientJoin(UUID id) {
|
||||||
|
MinecraftClient.getInstance().execute(() -> {
|
||||||
|
Entity entity = MinecraftClient.getInstance().targetedEntity;
|
||||||
|
if (entity != null) {
|
||||||
|
onSenderJoin(new NMSCommandSender(entity.getCommandSource()), id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void onServerJoin(UUID id) {
|
||||||
|
Via.getPlatform().runSync(() -> {
|
||||||
|
Arrays.stream(Via.getPlatform().getOnlinePlayers())
|
||||||
|
.filter(it -> it.getUUID().equals(id)).findAny().ifPresent(sender -> {
|
||||||
|
onSenderJoin(sender, id);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void onSenderJoin(ViaCommandSender sender, UUID connId) {
|
||||||
|
if (sender.hasPermission("viaversion.admin")
|
||||||
|
&& Via.getConfig().isCheckForUpdates()) {
|
||||||
|
UpdateUtil.sendUpdateMessage(connId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
package com.github.creeper123123321.viafabric.platform;
|
package com.github.creeper123123321.viafabric.platform;
|
||||||
|
|
||||||
|
import com.github.creeper123123321.viafabric.listeners.UpdateListener;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.platform.ViaConnectionManager;
|
import us.myles.ViaVersion.api.platform.ViaConnectionManager;
|
||||||
|
|
||||||
@ -32,4 +33,22 @@ public class VRConnectionManager extends ViaConnectionManager {
|
|||||||
public boolean isFrontEnd(UserConnection connection) {
|
public boolean isFrontEnd(UserConnection connection) {
|
||||||
return !(connection instanceof VRClientSideUserConnection);
|
return !(connection instanceof VRClientSideUserConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoginSuccess(UserConnection connection) {
|
||||||
|
super.onLoginSuccess(connection);
|
||||||
|
if (!isFrontEnd(connection)) {
|
||||||
|
// We'll use it later
|
||||||
|
this.clients.put(connection.getProtocolInfo().getUuid(), connection);
|
||||||
|
UpdateListener.onJoin(connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisconnect(UserConnection connection) {
|
||||||
|
super.onDisconnect(connection);
|
||||||
|
if (!isFrontEnd(connection)) {
|
||||||
|
this.clients.remove(connection.getProtocolInfo().getUuid());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ public class VRPlatform implements ViaPlatform<UUID> {
|
|||||||
// ViaVersion seems to not need to run delayed tasks on main thread
|
// ViaVersion seems to not need to run delayed tasks on main thread
|
||||||
return new FutureTaskId(
|
return new FutureTaskId(
|
||||||
ViaFabric.EVENT_LOOP
|
ViaFabric.EVENT_LOOP
|
||||||
.schedule(runnable, ticks * 50, TimeUnit.MILLISECONDS)
|
.schedule(() -> runSync(runnable), ticks * 50, TimeUnit.MILLISECONDS)
|
||||||
.addListener(errorLogger())
|
.addListener(errorLogger())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -177,7 +177,7 @@ public class VRPlatform implements ViaPlatform<UUID> {
|
|||||||
// ViaVersion seems to not need to run repeating tasks on main thread
|
// ViaVersion seems to not need to run repeating tasks on main thread
|
||||||
return new FutureTaskId(
|
return new FutureTaskId(
|
||||||
ViaFabric.EVENT_LOOP
|
ViaFabric.EVENT_LOOP
|
||||||
.scheduleAtFixedRate(runnable, 0, ticks * 50, TimeUnit.MILLISECONDS)
|
.scheduleAtFixedRate(() -> runSync(runnable), 0, ticks * 50, TimeUnit.MILLISECONDS)
|
||||||
.addListener(errorLogger())
|
.addListener(errorLogger())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
"fabric-resource-loader-v0": "*",
|
"fabric-resource-loader-v0": "*",
|
||||||
"fabric-command-api-v1": "*",
|
"fabric-command-api-v1": "*",
|
||||||
"minecraft": ">1.15.2",
|
"minecraft": ">1.15.2",
|
||||||
"viaversion": ">=3.0.2-SNAPSHOT"
|
"viaversion": ">3.0.1"
|
||||||
},
|
},
|
||||||
"conflicts": {
|
"conflicts": {
|
||||||
"fabric-registry-sync": "*"
|
"fabric-registry-sync": "*"
|
||||||
|
Loading…
Reference in New Issue
Block a user