Try fixing block break (didn't work). Also add more metrics

This commit is contained in:
EOT3000 2019-09-30 12:44:25 -04:00
parent 29105e8c2e
commit da0c59446f
7 changed files with 129 additions and 235 deletions

View file

@ -11,6 +11,7 @@
<artifactId>connector</artifactId>
<dependencies>
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>api</artifactId>
<version>1.0-SNAPSHOT</version>

View file

@ -96,6 +96,7 @@ public class GeyserConnector implements Connector {
}
private GeyserConnector() {
long startupTime = System.currentTimeMillis();
// Metric
@ -159,6 +160,7 @@ public class GeyserConnector implements Connector {
metrics = new Metrics("GeyserMC", config.getMetrics().getUUID(), true, java.util.logging.Logger.getLogger(""));
metrics.addCustomChart(new Metrics.SingleLineChart("servers", () -> 1));
metrics.addCustomChart(new Metrics.SingleLineChart("players", Geyser::getPlayerCount));
metrics.addCustomChart(new Metrics.SimplePie("authMode", config.getRemote()::getAuthType));
}
double completeTime = (System.currentTimeMillis() - startupTime) / 1000D;

View file

@ -81,7 +81,7 @@ public class Metrics {
* Starts the Scheduler which submits our data every 30 minutes.
*/
private void startSubmitting() {
Geyser.getGeneralThreadPool().scheduleAtFixedRate(this::submitData, 5, 30, TimeUnit.MINUTES);
Geyser.getGeneralThreadPool().scheduleAtFixedRate(this::submitData, 1, 30, TimeUnit.MINUTES);
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
// WARNING: Just don't do it!

View file

@ -64,6 +64,14 @@ import java.util.UUID;
@Getter
public class GeyserSession implements Player {
@Getter
@Setter
private volatile boolean breaking;
@Getter
@Setter
private volatile boolean threadStop;
private final GeyserConnector connector;
private final BedrockServerSession upstream;
private RemoteServer remoteServer;
@ -93,6 +101,10 @@ public class GeyserSession implements Player {
private boolean spawned;
private boolean closed;
@Getter
@Setter
private Thread breakThread;
public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServerSession) {
this.connector = connector;
this.upstream = bedrockServerSession;

View file

@ -80,10 +80,12 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
ClientPlayerActionPacket dropItemPacket = new ClientPlayerActionPacket(PlayerAction.DROP_ITEM, position, BlockFace.values()[packet.getFace()]);
session.getDownstream().getSession().send(dropItemPacket);
break;
case STOP_SLEEP:
ClientPlayerStatePacket stopSleepingPacket = new ClientPlayerStatePacket((int) session.getPlayerEntity().getGeyserId(), PlayerState.LEAVE_BED);
session.getDownstream().getSession().send(stopSleepingPacket);
break;
case BLOCK_INTERACT:
ClientPlayerPlaceBlockPacket blockPacket = new ClientPlayerPlaceBlockPacket(position,
BlockFace.values()[packet.getFace()],
@ -91,17 +93,56 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
session.getDownstream().getSession().send(blockPacket);
break;
case START_BREAK:
ClientPlayerActionPacket actionPacket = new ClientPlayerActionPacket(PlayerAction.START_DIGGING, position, BlockFace.values()[packet.getFace()]);
System.out.println("a");
ClientPlayerActionPacket actionPacket = new ClientPlayerActionPacket(PlayerAction.START_DIGGING, position, BlockFace.values()[1]);
session.getDownstream().getSession().send(actionPacket);
break;
case ABORT_BREAK:
ClientPlayerActionPacket actionPacket2 = new ClientPlayerActionPacket(PlayerAction.CANCEL_DIGGING, position, BlockFace.values()[packet.getFace()]);
session.getDownstream().getSession().send(actionPacket2);
break;
session.setThreadStop(false);
session.setBreaking(true);
Thread thread = new Thread() {
@Override
public void run() {
while (session.isThreadStop()) {
try {
Thread.sleep(1);
} catch (Exception e) {
e.printStackTrace();
}
if(session.isBreaking()) {
session.setBreaking(false);
} else {
ClientPlayerActionPacket actionPacket = new ClientPlayerActionPacket(PlayerAction.CANCEL_DIGGING, position, BlockFace.values()[1]);
session.getDownstream().getSession().send(actionPacket);
}
}
}
};
session.setBreakThread(thread);
thread.start();
case STOP_BREAK:
ClientPlayerActionPacket actionPacket3 = new ClientPlayerActionPacket(PlayerAction.FINISH_DIGGING, position, BlockFace.values()[packet.getFace()]);
session.getDownstream().getSession().send(actionPacket3);
System.out.println("b");
session.getBreakThread().stop();
break;
case ABORT_BREAK:
System.out.println("c");
//ClientPlayerActionPacket actionPacket3 = new ClientPlayerActionPacket(PlayerAction.CANCEL_DIGGING, position, BlockFace.values()[1]);
//session.getDownstream().getSession().send(actionPacket3);
break;
case CONTINUE_BREAK:
System.out.println("d");
session.setBreaking(true);
break;
}
}

View file

@ -0,0 +1,64 @@
/*
* Copyright (c) 2019 GeyserMC. http://geysermc.org
*
* 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.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network.translators.bedrock;
import com.flowpowered.math.vector.Vector3f;
import com.flowpowered.math.vector.Vector3i;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction;
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerState;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPlaceBlockPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket;
import com.nukkitx.protocol.bedrock.packet.InteractPacket;
import com.nukkitx.protocol.bedrock.packet.PlayerActionPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
public class BedrockInteractTranslator extends PacketTranslator<InteractPacket> {
@Override
public void translate(InteractPacket packet, GeyserSession session) {
Vector3f vector = packet.getMousePosition();
InteractAction action;
if(packet.getAction() == 1) {
action = InteractAction.ATTACK;
} else {
action = InteractAction.INTERACT;
}
ClientPlayerInteractEntityPacket entityPacket = new ClientPlayerInteractEntityPacket((int) packet.getRuntimeEntityId(),
action, vector.getX(), vector.getY(), vector.getZ(), Hand.MAIN_HAND);
session.getDownstream().getSession().send(entityPacket);
}
}