forked from Lunatrius/InGame-Info-XML
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The server now sends the world seed to players on login.
- Loading branch information
Showing
6 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/com/github/lunatrius/ingameinfo/handler/PlayerHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.github.lunatrius.ingameinfo.handler; | ||
|
||
import com.github.lunatrius.ingameinfo.network.PacketHandler; | ||
import com.github.lunatrius.ingameinfo.network.message.MessageSeed; | ||
import com.github.lunatrius.ingameinfo.reference.Reference; | ||
import cpw.mods.fml.common.eventhandler.SubscribeEvent; | ||
import cpw.mods.fml.common.gameevent.PlayerEvent; | ||
import net.minecraft.entity.player.EntityPlayerMP; | ||
|
||
public class PlayerHandler { | ||
@SubscribeEvent | ||
public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) { | ||
if (event.player instanceof EntityPlayerMP) { | ||
try { | ||
PacketHandler.INSTANCE.sendTo(new MessageSeed(event.player.worldObj.getSeed()), (EntityPlayerMP) event.player); | ||
} catch (Exception ex) { | ||
Reference.logger.error("Failed to send the seed!", ex); | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/github/lunatrius/ingameinfo/network/PacketHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.github.lunatrius.ingameinfo.network; | ||
|
||
import com.github.lunatrius.ingameinfo.network.message.MessageSeed; | ||
import com.github.lunatrius.ingameinfo.reference.Reference; | ||
import cpw.mods.fml.common.network.NetworkRegistry; | ||
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; | ||
import cpw.mods.fml.relauncher.Side; | ||
|
||
public class PacketHandler { | ||
public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(Reference.MODID.toLowerCase()); | ||
|
||
public static void init() { | ||
INSTANCE.registerMessage(MessageSeed.class, MessageSeed.class, 0, Side.CLIENT); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/github/lunatrius/ingameinfo/network/message/MessageSeed.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.github.lunatrius.ingameinfo.network.message; | ||
|
||
import com.github.lunatrius.ingameinfo.tag.Tag; | ||
import cpw.mods.fml.common.network.simpleimpl.IMessage; | ||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; | ||
import cpw.mods.fml.common.network.simpleimpl.MessageContext; | ||
import cpw.mods.fml.relauncher.Side; | ||
import io.netty.buffer.ByteBuf; | ||
|
||
public class MessageSeed implements IMessage, IMessageHandler<MessageSeed, IMessage> { | ||
public long seed; | ||
|
||
public MessageSeed() { | ||
this.seed = 0; | ||
} | ||
|
||
public MessageSeed(long seed) { | ||
this.seed = seed; | ||
} | ||
|
||
@Override | ||
public void fromBytes(ByteBuf buf) { | ||
this.seed = buf.readLong(); | ||
} | ||
|
||
@Override | ||
public void toBytes(ByteBuf buf) { | ||
buf.writeLong(this.seed); | ||
} | ||
|
||
@Override | ||
public IMessage onMessage(MessageSeed message, MessageContext ctx) { | ||
if (ctx.side == Side.CLIENT) { | ||
Tag.setSeed(message.seed); | ||
} | ||
|
||
return null; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/github/lunatrius/ingameinfo/proxy/ServerProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.github.lunatrius.ingameinfo.proxy; | ||
|
||
import com.github.lunatrius.ingameinfo.handler.PlayerHandler; | ||
import cpw.mods.fml.common.FMLCommonHandler; | ||
|
||
public class ServerProxy extends CommonProxy { | ||
@Override | ||
public void registerEvents() { | ||
FMLCommonHandler.instance().bus().register(new PlayerHandler()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters