2019-07-24 20:12:42 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2019-07-26 04:26:42 +00:00
|
|
|
package org.geysermc.connector.network.translators.java.world;
|
2019-07-24 20:12:42 +00:00
|
|
|
|
2019-08-04 01:01:16 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
2019-07-24 20:12:42 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerNotifyClientPacket;
|
2019-10-09 18:39:38 +00:00
|
|
|
import com.nukkitx.math.vector.Vector3f;
|
2019-07-24 20:12:42 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
|
2019-08-04 01:01:16 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket;
|
2019-09-16 01:34:57 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.packet.ShowCreditsPacket;
|
|
|
|
import org.geysermc.connector.entity.Entity;
|
2019-07-24 20:12:42 +00:00
|
|
|
import org.geysermc.connector.network.session.GeyserSession;
|
|
|
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
|
|
|
|
|
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
|
|
|
|
|
|
public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyClientPacket> {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void translate(ServerNotifyClientPacket packet, GeyserSession session) {
|
|
|
|
switch (packet.getNotification()) {
|
|
|
|
case START_RAIN:
|
|
|
|
LevelEventPacket startRainPacket = new LevelEventPacket();
|
|
|
|
startRainPacket.setEvent(LevelEventPacket.Event.START_RAIN);
|
|
|
|
startRainPacket.setData(ThreadLocalRandom.current().nextInt(50000) + 10000);
|
2019-10-09 18:39:38 +00:00
|
|
|
startRainPacket.setPosition(Vector3f.ZERO);
|
2019-07-24 20:12:42 +00:00
|
|
|
session.getUpstream().sendPacket(startRainPacket);
|
|
|
|
break;
|
|
|
|
case STOP_RAIN:
|
|
|
|
LevelEventPacket stopRainPacket = new LevelEventPacket();
|
|
|
|
stopRainPacket.setEvent(LevelEventPacket.Event.STOP_RAIN);
|
|
|
|
stopRainPacket.setData(ThreadLocalRandom.current().nextInt(50000) + 10000);
|
2019-10-09 18:39:38 +00:00
|
|
|
stopRainPacket.setPosition(Vector3f.ZERO);
|
2019-07-24 20:12:42 +00:00
|
|
|
session.getUpstream().sendPacket(stopRainPacket);
|
|
|
|
break;
|
2019-08-04 01:01:16 +00:00
|
|
|
case CHANGE_GAMEMODE:
|
2019-08-04 01:20:15 +00:00
|
|
|
int gamemode = ((GameMode) packet.getValue()).ordinal();
|
2019-08-04 01:01:16 +00:00
|
|
|
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
|
|
|
|
playerGameTypePacket.setGamemode(gamemode);
|
2019-09-16 01:34:57 +00:00
|
|
|
session.getUpstream().sendPacket(playerGameTypePacket);
|
2019-08-04 01:01:16 +00:00
|
|
|
break;
|
2019-07-24 20:12:42 +00:00
|
|
|
case ENTER_CREDITS:
|
2019-09-16 01:34:57 +00:00
|
|
|
Entity entity = session.getPlayerEntity();
|
|
|
|
if (entity == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ShowCreditsPacket showCreditsPacket = new ShowCreditsPacket();
|
|
|
|
showCreditsPacket.setStatus(ShowCreditsPacket.Status.START_CREDITS);
|
|
|
|
showCreditsPacket.setRuntimeEntityId(entity.getGeyserId());
|
|
|
|
session.getUpstream().sendPacket(showCreditsPacket);
|
2019-07-24 20:12:42 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|