我是Java新手,如何处理当前玩家加入的世界?
package page.a0x77.kubecraft;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.player.*;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
@Mod(
modid = Kubecraft.MOD_ID,
name = Kubecraft.MOD_NAME,
version = Kubecraft.VERSION
)
public class Kubecraft {
@SubscribeEvent
public void playerLoggedInEvent(EntityJoinWorldEvent event) {
// ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().player, "your command");
System.out.println("TEST");
}
}
我想在玩家加入的时候进行自动认证,在加入的时候发送消息给聊天者。
你应该用。
@EventBusSubscriber
public static class Class {
@SubscribeEvent
public static void onEvent(EntityJoinWorldEvent event) {
if ((event.getEntity() instanceof PlayerEntity)) {
LogManager.getLogger().info("Joined!");
}
}
}
我想也许你需要玩家的实例才能让它工作。
...
@Mod(
modid = Kubecraft.MOD_ID,
name = Kubecraft.MOD_NAME,
version = Kubecraft.VERSION
)
public class Kubecraft {
...
@SubscribeEvent
public static void onEvent(EntityJoinWorldEvent event) {
Timer timer = new Timer(3000, new ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
if(!sent) Minecraft.getMinecraft().player.sendChatMessage("/setblock ~ ~ ~ grass");
sent = true;
}
});
timer.setRepeats(false); // Only execute once
if(!sent) {
timer.start();
}
}
}
...