- 89
- 2
Ошибка:
Код:
Java:
The method registerMessage(Class<? extends IMessageHandler<REQ,REPLY>>, Class<REQ>, int, Side) in the type SimpleNetworkWrapper is not applicable for the arguments (Class<NotificationMessage>, Class<NotificationMessage>, int, Side)
Код:
Java:
package ru.stepan1404.notifications;
import java.io.File;
import java.util.Timer;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartedEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.relauncher.Side;
import ru.stepan1404.notifications.commands.CommandNotifications;
import ru.stepan1404.notifications.config.Config;
import ru.stepan1404.notifications.event.RenderEvent;
import ru.stepan1404.notifications.network.NotificationMessage;
import ru.stepan1404.notifications.network.NotificationPluginMessage;
import ru.stepan1404.notifications.task.NotificationTask;
import ru.stepan1404.notifications.utils.Events;
@Mod(
modid = "skolm",
name = "SkolMod",
version = "1.0.0"
)
public class NotificationsMod {
@Instance
private static NotificationsMod mod;
private Config config;
private File configFile;
private SimpleNetworkWrapper network;
@EventHandler
public void onPreInit(FMLPreInitializationEvent event) {
this.initModules(event.getSuggestedConfigurationFile());
if(FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
Events.registerEvent(new RenderEvent());
}
}
public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("lp_notifications");
private void initModules(File file) {
this.configFile = file;
INSTANCE.registerMessage(NotificationMessage.class, NotificationMessage.class, 0, Side.CLIENT);
INSTANCE.registerMessage(NotificationPluginMessage.class, NotificationPluginMessage.class, 1, Side.SERVER);
}
@EventHandler
public void onServerStarting(FMLServerStartingEvent event) {
event.registerServerCommand(new CommandNotifications());
}
@EventHandler
public void onServerStarted(FMLServerStartedEvent event) {
this.config = new Config(this.configFile);
this.config.launch();
Timer timer = new Timer();
timer.scheduleAtFixedRate(new NotificationTask(), 0L, (long)(getMod().getConfig().getDelay() * 1000));
}
public static NotificationsMod getMod() {
return mod;
}
public Config getConfig() {
return this.config;
}
public SimpleNetworkWrapper getNetwork() {
return this.network;
}
}
Java:
package ru.stepan1404.notifications.network;
import io.netty.buffer.ByteBuf;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import ru.stepan1404.notifications.gui.NotificationGui;
import ru.stepan1404.notifications.model.Notification;
public class NotificationMessage<RED, REPLY> implements IMessage {
private String text;
public NotificationMessage() {
}
public NotificationMessage(String text) {
this.text = text;
}
public void fromBytes(ByteBuf buf) {
this.text = ByteBufUtils.readUTF8String(buf);
}
public void toBytes(ByteBuf buf) {
ByteBufUtils.writeUTF8String(buf, this.text);
}
public void onMessage(NotificationMessage message, MessageContext ctx) {
try {
String[] args = message.text.split(":");
String letterType = args[0];
String messageText = args[2];
int lifetime = Integer.parseInt(args[1]);
Notification model = new Notification(letterType, messageText, lifetime);
NotificationGui.getInstance().getNotificationList().add(model);
return;
} catch (Throwable var8) {
return;
}
}
}