Add event handlers and mod config
This commit is contained in:
parent
3dfd7478f3
commit
3a753887c6
|
@ -1,17 +1,21 @@
|
|||
package arcanitor.civilengineering;
|
||||
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@Mod(
|
||||
modid = CivilEngineering.MODID,
|
||||
name = CivilEngineering.NAME,
|
||||
version = CivilEngineering.VERSION,
|
||||
serverSideOnly = true,
|
||||
useMetadata = true
|
||||
useMetadata = true,
|
||||
acceptableRemoteVersions = "*"
|
||||
)
|
||||
public class CivilEngineering {
|
||||
public static final String MODID = "civilengineering";
|
||||
|
@ -22,11 +26,17 @@ public class CivilEngineering {
|
|||
public static CivilEngineering instance;
|
||||
|
||||
public static Logger logger;
|
||||
public static Configuration config;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
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
|
||||
|
@ -37,6 +47,9 @@ public class CivilEngineering {
|
|||
@Mod.EventHandler
|
||||
public void init(FMLPostInitializationEvent event) {
|
||||
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
|
||||
public class HandleChatMessage {
|
||||
@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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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