mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-22 21:09:56 +00:00
Configuration!
Config options: handleDesktopPackets (Handle OpenBrowser and CopyClipboard packets? Insecure. Default false), handleLoadScripts (Proccess LoadScripts packet on client? Insecure, takes time, but update scripts on the fly... Default true), sendLoadScripts (Send scripts to players on logging in. Default true), sendScriptsOnReloading (Send scripts to players on command "mt reload". Default true), loadScriptsOnConnection (Load scripts before connect to server? Save time and traffic. Requires server with disabled sendLoadScripts. Default false), antiStuck (Do not reload scripts when relogging, saves time. Usable when playing on one server/singleplayer... Default false). Config lies at config/MineTweaker3.cfg
This commit is contained in:
1 parent
4d4fed2482
commit
86b4108e4f
9 files changed
+75
-24
No files matched your search
@@ -22,7 +22,7 @@ import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
public class FMLEventHandler {
|
||||
@SubscribeEvent
|
||||
public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent ev) {
|
||||
if (ev.player instanceof EntityPlayerMP) {
|
||||
if (ev.player instanceof EntityPlayerMP && MineTweakerConfig.sendLoadScripts) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) ev.player;
|
||||
MineTweakerMod.NETWORK.sendTo(new MineTweakerLoadScriptsPacket(MineTweakerAPI.tweaker.getScriptData()), player);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
package minetweaker.mc1710;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import minetweaker.*;
|
||||
import minetweaker.api.entity.*;
|
||||
import minetweaker.api.formatting.IFormattedText;
|
||||
@@ -15,10 +17,12 @@ import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import minetweaker.api.tooltip.IngredientTooltips;
|
||||
import minetweaker.mc1710.formatting.IMCFormattedString;
|
||||
import minetweaker.mc1710.item.*;
|
||||
import net.minecraft.client.multiplayer.GuiConnecting;
|
||||
import net.minecraft.entity.*;
|
||||
import net.minecraft.entity.item.*;
|
||||
import net.minecraft.entity.player.*;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraftforge.client.event.GuiOpenEvent;
|
||||
import net.minecraftforge.event.entity.living.*;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
@@ -42,6 +46,12 @@ public class ForgeEventHandler {
|
||||
MineTweakerImplementationAPI.events.publishPlayerInteract(event);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SubscribeEvent
|
||||
public void onPlayerGuiOpen(GuiOpenEvent ev) {
|
||||
if (ev.gui != null && ev.gui instanceof GuiConnecting) MineTweakerMod.INSTANCE.onClientAboutToConnect();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onItemTooltip(ItemTooltipEvent ev) {
|
||||
if(ev.itemStack!= null) {
|
||||
|
||||
@@ -32,7 +32,7 @@ public class MCPlatformFunctions implements IPlatformFunctions {
|
||||
|
||||
@Override
|
||||
public void distributeScripts(byte[] data) {
|
||||
MineTweakerMod.NETWORK.sendToAll(new MineTweakerLoadScriptsPacket(data));
|
||||
if (MineTweakerConfig.sendScriptsOnReloading) MineTweakerMod.NETWORK.sendToAll(new MineTweakerLoadScriptsPacket(data));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package minetweaker.mc1710;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
public class MineTweakerConfig {
|
||||
private MineTweakerConfig() { }
|
||||
public static boolean handleDesktopPackets = false, handleLoadScripts = true, sendLoadScripts = true,
|
||||
sendScriptsOnReloading = true, loadScriptsBeforeConnection = false, antiStuck = true;
|
||||
static File file;
|
||||
|
||||
public static void load() {
|
||||
Configuration config = new Configuration(file, "1");
|
||||
config.load();
|
||||
handleDesktopPackets = config.getBoolean("handleDesktopPackets",
|
||||
"network", false, "Handle OpenBrowser and CopyClipboard packets? Insecure.");
|
||||
handleLoadScripts = config.getBoolean("handleLoadScripts", "network", true,
|
||||
"Proccess LoadScripts packet on client? Insecure, takes time, but update scripts on the fly...");
|
||||
|
||||
sendLoadScripts = config.getBoolean("sendLoadScripts",
|
||||
"network", true, "Send scripts to players on logging in");
|
||||
sendScriptsOnReloading = config.getBoolean("sendScriptsOnReloading",
|
||||
"network", true, "Send scripts to players on command \"mt reload\"");
|
||||
|
||||
loadScriptsBeforeConnection = config.getBoolean("loadScriptsBeforeConnection",
|
||||
"core", false, "Load scripts before connect to server? Save time and traffic. Requires server with disabled sendLoadScripts.");
|
||||
antiStuck = config.getBoolean("antiStuck",
|
||||
"core", false, "Do not reload scripts when relogging, saves time. Usable when playing on one server/singleplayer...");
|
||||
config.save();
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ import minetweaker.runtime.*;
|
||||
import minetweaker.runtime.providers.ScriptProviderCascade;
|
||||
import minetweaker.runtime.providers.ScriptProviderCustom;
|
||||
import minetweaker.runtime.providers.ScriptProviderDirectory;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -82,6 +83,7 @@ public class MineTweakerMod {
|
||||
|
||||
private final IScriptProvider scriptsGlobal;
|
||||
private final ScriptProviderCustom scriptsIMC;
|
||||
private volatile boolean loaded = false;
|
||||
|
||||
public MineTweakerMod() {
|
||||
MCRecipeManager.recipes = (List<IRecipe>) CraftingManager.getInstance().getRecipeList();
|
||||
@@ -127,6 +129,8 @@ public class MineTweakerMod {
|
||||
|
||||
@EventHandler
|
||||
public void onLoad(FMLPreInitializationEvent ev) {
|
||||
MineTweakerConfig.file = new File(ev.getModConfigurationDirectory(), MODID + ".cfg");
|
||||
MineTweakerConfig.load();
|
||||
MinecraftForge.EVENT_BUS.register(new ForgeEventHandler());
|
||||
FMLCommonHandler.instance().bus().register(new FMLEventHandler());
|
||||
}
|
||||
@@ -148,17 +152,13 @@ public class MineTweakerMod {
|
||||
ItemBracketHandler.rebuildItemRegistry();
|
||||
LiquidBracketHandler.rebuildLiquidRegistry();
|
||||
MineTweakerAPI.logInfo("MineTweaker: Sucessfully built item registry");
|
||||
if (MineTweakerPlatformUtils.isClient()) {
|
||||
MineTweakerAPI.client = new MCClient();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerAboutToStart(FMLServerAboutToStartEvent ev) {
|
||||
// starts before loading worlds
|
||||
// perfect place to start MineTweaker!
|
||||
|
||||
if (MineTweakerPlatformUtils.isClient()) {
|
||||
MineTweakerAPI.client = new MCClient();
|
||||
}
|
||||
|
||||
File scriptsDir = new File(MineTweakerHacks.getWorldDirectory(ev.getServer()), "scripts");
|
||||
if (!scriptsDir.exists()) {
|
||||
scriptsDir.mkdir();
|
||||
@@ -168,12 +168,21 @@ public class MineTweakerMod {
|
||||
IScriptProvider cascaded = new ScriptProviderCascade(scriptsIMC, scriptsGlobal,scriptsLocal);
|
||||
|
||||
MineTweakerImplementationAPI.setScriptProvider(cascaded);
|
||||
MineTweakerImplementationAPI.onServerStart(new MCServer(ev.getServer()));
|
||||
MCServer srv = new MCServer(ev.getServer());
|
||||
if (loaded && MineTweakerConfig.antiStuck) MineTweakerAPI.server = srv;
|
||||
else {
|
||||
MineTweakerImplementationAPI.onServerStart(srv);
|
||||
loaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerStarting(FMLServerStartingEvent ev) {
|
||||
|
||||
public void onClientAboutToConnect() {
|
||||
if (!MineTweakerConfig.loadScriptsBeforeConnection) return;
|
||||
IScriptProvider cascaded = new ScriptProviderCascade(scriptsIMC, scriptsGlobal);
|
||||
MineTweakerImplementationAPI.setScriptProvider(cascaded);
|
||||
if (loaded && MineTweakerConfig.antiStuck) return;
|
||||
MineTweakerImplementationAPI.reload();
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
+3
-1
@@ -9,6 +9,8 @@ package minetweaker.mc1710.network;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import minetweaker.mc1710.MineTweakerConfig;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
@@ -21,7 +23,7 @@ import java.awt.datatransfer.StringSelection;
|
||||
public class MineTweakerCopyClipboardHandler implements IMessageHandler<MineTweakerCopyClipboardPacket, IMessage> {
|
||||
@Override
|
||||
public IMessage onMessage(MineTweakerCopyClipboardPacket message, MessageContext ctx) {
|
||||
if (Desktop.isDesktopSupported()) {
|
||||
if (Desktop.isDesktopSupported() && MineTweakerConfig.handleDesktopPackets) {
|
||||
StringSelection stringSelection = new StringSelection(message.getData());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
clipboard.setContents(stringSelection, null);
|
||||
|
||||
+2
-5
@@ -11,7 +11,7 @@ import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.MineTweakerImplementationAPI;
|
||||
import minetweaker.mc1710.client.MCClient;
|
||||
import minetweaker.mc1710.MineTweakerConfig;
|
||||
import minetweaker.runtime.providers.ScriptProviderMemory;
|
||||
|
||||
/**
|
||||
@@ -21,13 +21,10 @@ import minetweaker.runtime.providers.ScriptProviderMemory;
|
||||
public class MineTweakerLoadScriptsHandler implements IMessageHandler<MineTweakerLoadScriptsPacket, IMessage> {
|
||||
@Override
|
||||
public IMessage onMessage(MineTweakerLoadScriptsPacket message, MessageContext ctx) {
|
||||
if (MineTweakerAPI.server == null) {
|
||||
MineTweakerAPI.client = new MCClient();
|
||||
|
||||
if (MineTweakerAPI.server == null && MineTweakerConfig.handleLoadScripts) {
|
||||
MineTweakerImplementationAPI.setScriptProvider(new ScriptProviderMemory(message.getData()));
|
||||
MineTweakerImplementationAPI.reload();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -9,6 +9,8 @@ package minetweaker.mc1710.network;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import minetweaker.mc1710.MineTweakerConfig;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@@ -21,15 +23,13 @@ import java.net.URISyntaxException;
|
||||
public class MineTweakerOpenBrowserHandler implements IMessageHandler<MineTweakerOpenBrowserPacket, IMessage> {
|
||||
@Override
|
||||
public IMessage onMessage(MineTweakerOpenBrowserPacket message, MessageContext ctx) {
|
||||
if (Desktop.isDesktopSupported()) {
|
||||
if (Desktop.isDesktopSupported() && MineTweakerConfig.handleDesktopPackets) {
|
||||
Desktop desktop = Desktop.getDesktop();
|
||||
try {
|
||||
desktop.browse(new URI(message.getUrl()));
|
||||
} catch (IOException e) {
|
||||
} catch (URISyntaxException e) {
|
||||
}
|
||||
} else {
|
||||
System.out.println("Desktop not supported");
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -12,6 +12,7 @@ import minetweaker.api.data.IData;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.minecraft.MineTweakerMC;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.mc1710.MineTweakerConfig;
|
||||
import minetweaker.mc1710.MineTweakerMod;
|
||||
import minetweaker.mc1710.data.NBTConverter;
|
||||
import minetweaker.mc1710.network.MineTweakerCopyClipboardPacket;
|
||||
@@ -126,7 +127,7 @@ public class MCPlayer implements IPlayer {
|
||||
|
||||
@Override
|
||||
public void openBrowser(String url) {
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
if (player instanceof EntityPlayerMP && MineTweakerConfig.handleDesktopPackets) {
|
||||
MineTweakerMod.NETWORK.sendTo(
|
||||
new MineTweakerOpenBrowserPacket(url),
|
||||
(EntityPlayerMP) player);
|
||||
@@ -135,7 +136,7 @@ public class MCPlayer implements IPlayer {
|
||||
|
||||
@Override
|
||||
public void copyToClipboard(String value) {
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
if (player instanceof EntityPlayerMP && MineTweakerConfig.handleDesktopPackets) {
|
||||
MineTweakerMod.NETWORK.sendTo(
|
||||
new MineTweakerCopyClipboardPacket(value),
|
||||
(EntityPlayerMP) player);
|
||||
|
||||
Reference in new issue
Block a user