Add event handlers and mod config
This commit is contained in:
parent
3dfd7478f3
commit
3a753887c6
|
@ -1,17 +1,21 @@
|
||||||
package arcanitor.civilengineering;
|
package arcanitor.civilengineering;
|
||||||
|
|
||||||
|
import net.minecraftforge.common.config.Configuration;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
@Mod(
|
@Mod(
|
||||||
modid = CivilEngineering.MODID,
|
modid = CivilEngineering.MODID,
|
||||||
name = CivilEngineering.NAME,
|
name = CivilEngineering.NAME,
|
||||||
version = CivilEngineering.VERSION,
|
version = CivilEngineering.VERSION,
|
||||||
serverSideOnly = true,
|
serverSideOnly = true,
|
||||||
useMetadata = true
|
useMetadata = true,
|
||||||
|
acceptableRemoteVersions = "*"
|
||||||
)
|
)
|
||||||
public class CivilEngineering {
|
public class CivilEngineering {
|
||||||
public static final String MODID = "civilengineering";
|
public static final String MODID = "civilengineering";
|
||||||
|
@ -22,11 +26,17 @@ public class CivilEngineering {
|
||||||
public static CivilEngineering instance;
|
public static CivilEngineering instance;
|
||||||
|
|
||||||
public static Logger logger;
|
public static Logger logger;
|
||||||
|
public static Configuration config;
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
public void preInit(FMLPreInitializationEvent event) {
|
public void preInit(FMLPreInitializationEvent event) {
|
||||||
logger = event.getModLog();
|
logger = event.getModLog();
|
||||||
logger.info("Bridge building pre-init.");
|
|
||||||
|
logger.info("Reading bridge blueprints...");
|
||||||
|
|
||||||
|
File directory = event.getModConfigurationDirectory();
|
||||||
|
config = new Configuration(new File(directory.getPath(), "CivilEngineering.cfg"));
|
||||||
|
Config.readConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
|
@ -37,6 +47,9 @@ public class CivilEngineering {
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
public void init(FMLPostInitializationEvent event) {
|
public void init(FMLPostInitializationEvent event) {
|
||||||
logger.info("Bridge building post-init.");
|
logger.info("Bridge building post-init.");
|
||||||
|
if (config.hasChanged()) {
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
package arcanitor.civilengineering;
|
||||||
|
|
||||||
|
import net.minecraftforge.common.config.Configuration;
|
||||||
|
import org.apache.logging.log4j.Level;
|
||||||
|
|
||||||
|
public class Config {
|
||||||
|
private static final String CATEGORY_RELAY_OPTIONS = "relay_options";
|
||||||
|
private static final String CATEGORY_CONNECTION = "connection";
|
||||||
|
|
||||||
|
public static boolean relayDeathEvents = false;
|
||||||
|
public static boolean relayAdvancements = false; //unused for now
|
||||||
|
|
||||||
|
public static String connectURL = "localhost";
|
||||||
|
|
||||||
|
public static void readConfig() {
|
||||||
|
Configuration config = CivilEngineering.config;
|
||||||
|
try {
|
||||||
|
config.load();
|
||||||
|
initConfig(config);
|
||||||
|
} catch (Exception expt) {
|
||||||
|
CivilEngineering.logger.log(Level.ERROR,"Could not read config file!", expt);
|
||||||
|
} finally {
|
||||||
|
if (config.hasChanged()) {
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void initConfig(Configuration cfg) {
|
||||||
|
cfg.addCustomCategoryComment(CATEGORY_RELAY_OPTIONS,"Relay options");
|
||||||
|
cfg.addCustomCategoryComment(CATEGORY_CONNECTION,"Connection settings");
|
||||||
|
relayDeathEvents = cfg.getBoolean(
|
||||||
|
"relayDeathEvents",
|
||||||
|
CATEGORY_RELAY_OPTIONS,
|
||||||
|
false,
|
||||||
|
"Set to true to send death messages over the chat relay."
|
||||||
|
);
|
||||||
|
relayAdvancements = cfg.getBoolean(
|
||||||
|
"relayAdvancements",
|
||||||
|
CATEGORY_RELAY_OPTIONS,
|
||||||
|
false,
|
||||||
|
"This option does nothing as advancement relays are not implemented."
|
||||||
|
);
|
||||||
|
connectURL = cfg.getString(
|
||||||
|
"connectURL",
|
||||||
|
CATEGORY_CONNECTION,
|
||||||
|
"localhost",
|
||||||
|
"The URL or IP address of the bridge server"
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -8,7 +8,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
@Mod.EventBusSubscriber
|
@Mod.EventBusSubscriber
|
||||||
public class HandleChatMessage {
|
public class HandleChatMessage {
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void chatMessageGlobal(ServerChatEvent event) {
|
public static void handleServerChatEvent (ServerChatEvent event) {
|
||||||
CivilEngineering.logger.info("Message on server: "+event.getMessage()+" sent by "+event.getUsername());
|
CivilEngineering.logger.info("Message on server: "+event.getMessage()+" sent by "+event.getUsername());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package arcanitor.civilengineering.eventhandlers;
|
||||||
|
|
||||||
|
import arcanitor.civilengineering.CivilEngineering;
|
||||||
|
import arcanitor.civilengineering.Config;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
|
||||||
|
@Mod.EventBusSubscriber
|
||||||
|
public class HandleDeath {
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void handleLivingDeathEvent (LivingDeathEvent event) {
|
||||||
|
if(Config.relayDeathEvents) {
|
||||||
|
EntityLivingBase entity = event.getEntityLiving();
|
||||||
|
if (entity instanceof EntityPlayer) {
|
||||||
|
String message = entity.getCombatTracker().getDeathMessage().getUnformattedText();
|
||||||
|
CivilEngineering.logger.info(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue