Minecraft Player On World 加入活动
Minecraft Player On World Join event
我是 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();
}
}
}
...
我是 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();
}
}
}
...