mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-12-25 16:57:53 +01:00
Implement command, ViaCommandSender
This commit is contained in:
parent
5ed38fbd5b
commit
11033ad2ee
@ -24,9 +24,7 @@
|
||||
|
||||
package com.github.creeper123123321.viarift;
|
||||
|
||||
import com.github.creeper123123321.viarift.platform.VRInjector;
|
||||
import com.github.creeper123123321.viarift.platform.VRLoader;
|
||||
import com.github.creeper123123321.viarift.platform.VRPlatform;
|
||||
import com.github.creeper123123321.viarift.platform.*;
|
||||
import com.github.creeper123123321.viarift.util.JLoggerToLog4j;
|
||||
import io.netty.channel.DefaultEventLoop;
|
||||
import io.netty.channel.EventLoop;
|
||||
@ -37,10 +35,16 @@ import org.dimdev.riftloader.listener.InitializationListener;
|
||||
import org.spongepowered.asm.launch.MixinBootstrap;
|
||||
import org.spongepowered.asm.mixin.Mixins;
|
||||
import us.myles.ViaVersion.ViaManager;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
public class ViaRift implements InitializationListener {
|
||||
@ -53,8 +57,33 @@ public class ViaRift implements InitializationListener {
|
||||
public void onInitialization() {
|
||||
MixinBootstrap.init();
|
||||
Mixins.addConfiguration("mixins.viarift.main.json");
|
||||
Via.init(ViaManager.builder().injector(new VRInjector()).loader(new VRLoader()).platform(new VRPlatform()).build());
|
||||
Via.init(ViaManager.builder()
|
||||
.injector(new VRInjector())
|
||||
.loader(new VRLoader())
|
||||
.commandHandler(new VRCommandHandler())
|
||||
.platform(new VRPlatform()).build());
|
||||
Via.getManager().init();
|
||||
ProtocolRegistry.getProtocolPath(ProtocolVersion.v1_13.getId(), ProtocolVersion.v1_12_2.getId()) // XGH to intercept /viarift commands
|
||||
.get(0).getValue().registerIncoming(State.PLAY, 0x02, 0x02, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.STRING);
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper packetWrapper) throws Exception {
|
||||
String msg = packetWrapper.get(Type.STRING, 0);
|
||||
ProtocolInfo info = packetWrapper.user().get(ProtocolInfo.class);
|
||||
if (msg.startsWith("/viarift")) {
|
||||
Via.getManager().getCommandHandler().onCommand(
|
||||
new VRCommandSender(info.getUuid(), info.getUsername()),
|
||||
(msg.length() == 8 ? "" : msg.substring(9)).split(" ", -1)
|
||||
);
|
||||
packetWrapper.cancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
//Via.getManager().setDebug(true);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.viarift.platform;
|
||||
|
||||
import us.myles.ViaVersion.commands.ViaCommandHandler;
|
||||
|
||||
public class VRCommandHandler extends ViaCommandHandler {
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.viarift.platform;
|
||||
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class VRCommandSender implements ViaCommandSender {
|
||||
private UUID uuid;
|
||||
private String name;
|
||||
|
||||
public VRCommandSender(UUID uuid, String name) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String s) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String s) {
|
||||
Via.getPlatform().sendMessage(uuid, s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
@ -29,12 +29,14 @@ import com.github.creeper123123321.viarift.util.FutureTaskId;
|
||||
import com.github.creeper123123321.viarift.util.ThreadTaskId;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.ViaAPI;
|
||||
import us.myles.ViaVersion.api.ViaVersionConfig;
|
||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
||||
import us.myles.ViaVersion.api.platform.TaskId;
|
||||
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.sponge.VersionInfo;
|
||||
import us.myles.viaversion.libs.gson.JsonObject;
|
||||
|
||||
@ -111,13 +113,18 @@ public class VRPlatform implements ViaPlatform {
|
||||
|
||||
@Override
|
||||
public ViaCommandSender[] getOnlinePlayers() {
|
||||
throw new UnsupportedOperationException();
|
||||
return Via.getManager().getPortedPlayers().values().stream().map(it -> {
|
||||
ProtocolInfo info = it.get(ProtocolInfo.class);
|
||||
return new VRCommandSender(info.getUuid(), info.getUsername());
|
||||
}).toArray(ViaCommandSender[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(UUID uuid, String s) {
|
||||
if (uuid.equals(Minecraft.getMinecraft().player.getUniqueID())) {
|
||||
Minecraft.getMinecraft().player.sendMessage(new TextComponentString(s));
|
||||
Minecraft.getMinecraft().addScheduledTask(() ->
|
||||
Minecraft.getMinecraft().player.sendMessage(new TextComponentString(s))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,7 @@ public class VRViaAPI implements ViaAPI<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean isPorted(UUID uuid) {
|
||||
return Via.getManager().getPortedPlayers().containsKey(uuid);
|
||||
}
|
||||
|
@ -108,6 +108,7 @@ public class VRViaConfig extends Config implements ViaVersionConfig {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean isUnknownEntitiesSuppressed() {
|
||||
return false;
|
||||
}
|
||||
@ -118,6 +119,7 @@ public class VRViaConfig extends Config implements ViaVersionConfig {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean isBlockBreakPatch() {
|
||||
return false;
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
package com.github.creeper123123321.viarift.util;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
@ -71,17 +72,7 @@ public class JLoggerToLog4j extends Logger {
|
||||
}
|
||||
|
||||
public void log(Level level, String msg, Object[] params) {
|
||||
if (level == Level.FINE) {
|
||||
this.base.debug(msg, params);
|
||||
} else if (level == Level.WARNING) {
|
||||
this.base.warn(msg, params);
|
||||
} else if (level == Level.SEVERE) {
|
||||
this.base.error(msg, params);
|
||||
} else if (level == Level.INFO) {
|
||||
this.base.info(msg, params);
|
||||
} else {
|
||||
this.base.trace(msg, params);
|
||||
}
|
||||
log(level, MessageFormat.format(msg, params));
|
||||
}
|
||||
|
||||
public void log(Level level, String msg, Throwable params) {
|
||||
|
Loading…
Reference in New Issue
Block a user