diff --git a/build.gradle b/build.gradle index 1b5f1d0..78b1426 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ apply plugin: "maven" apply plugin: "idea-utils" group = "net.doubledoordev.craycrafting" -version = "1.2.0" +version = "1.3.0" targetCompatibility = 1.7 sourceCompatibility = 1.7 @@ -41,6 +41,17 @@ minecraft { runDir = "jars" } +repositories { + maven { + name "DDD repo" + url "http://doubledoordev.net/maven/" + } +} + +dependencies { + compile "net.doubledoordev.d3core:D3Core:" + project.minecraft.version + "-+:dev" +} + if (System.getenv().BUILD_NUMBER != null) version += "." + System.getenv().BUILD_NUMBER def builder = new groovy.json.JsonBuilder() builder (version: version, mcversion: project.minecraft.version, apiversion: project.minecraft.apiVersion) diff --git a/src/main/java/net/doubledoordev/craycrafting/CrayCrafting.java b/src/main/java/net/doubledoordev/craycrafting/CrayCrafting.java index 661fe8e..4c44301 100644 --- a/src/main/java/net/doubledoordev/craycrafting/CrayCrafting.java +++ b/src/main/java/net/doubledoordev/craycrafting/CrayCrafting.java @@ -31,6 +31,7 @@ package net.doubledoordev.craycrafting; import com.google.common.base.Strings; +import cpw.mods.fml.client.config.IConfigElement; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.event.FMLPreInitializationEvent; @@ -45,15 +46,18 @@ import net.doubledoordev.craycrafting.network.RecipeMessage; import net.doubledoordev.craycrafting.network.ResetMessage; import net.doubledoordev.craycrafting.recipes.*; -import net.doubledoordev.craycrafting.util.Config; +import net.doubledoordev.d3core.util.ID3Mod; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.server.MinecraftServer; import net.minecraft.util.ChatComponentText; import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.config.ConfigElement; +import net.minecraftforge.common.config.Configuration; import org.apache.logging.log4j.Logger; import java.io.File; +import java.util.List; import java.util.Timer; import java.util.TimerTask; @@ -62,27 +66,27 @@ /** * @author Dries007 */ -@Mod(modid = MODID) -public class CrayCrafting +@Mod(modid = MODID, canBeDeactivated = false) +public class CrayCrafting implements ID3Mod { @Mod.Instance(MODID) public static CrayCrafting instance; public Logger logger; private SimpleNetworkWrapper snw; - private Config config; private File recipeFile; + private Configuration configuration; + + public int timer = 0; + public String timermessage = "[CrayCrafting] Recipes have been rotated!"; + public boolean listType = false; + public Integer[] list = new Integer[0]; public static SimpleNetworkWrapper getSnw() { return instance.snw; } - public static Config getConfig() - { - return instance.config; - } - @Mod.EventHandler public void preInit(FMLPreInitializationEvent event) { @@ -90,7 +94,8 @@ public void preInit(FMLPreInitializationEvent event) MinecraftForge.EVENT_BUS.register(this); FMLCommonHandler.instance().bus().register(this); - config = new Config(event.getSuggestedConfigurationFile()); + configuration = new Configuration(event.getSuggestedConfigurationFile()); + syncConfig(); new ShapedRecipesType(); new ShapelessRecipesType(); @@ -113,7 +118,7 @@ public void eventHandler(FMLServerStoppingEvent event) @Mod.EventHandler() public void eventHandler(FMLServerStartingEvent event) { - RecipeRegistry.setConfigFromServer(config.listType, config.list); + RecipeRegistry.setConfigFromServer(listType, list); recipeFile = new File(DimensionManager.getCurrentSaveRootDirectory(), MODID + ".dat"); if (recipeFile.exists()) @@ -132,12 +137,12 @@ public void eventHandler(FMLServerStartingEvent event) RecipeRegistry.randomizeRecipes(recipeFile); } - if (config.timer > 0) setupTimer(); + if (timer > 0) setupTimer(); } public void setupTimer() { - if (config.timer >= 1) + if (timer >= 1) { new Timer(MODID + "-Timer").schedule(new TimerTask() { @@ -149,11 +154,11 @@ public void run() RecipeRegistry.randomizeRecipes(recipeFile); if (MinecraftServer.getServer().isDedicatedServer()) RecipeRegistry.sendPacketToAll(); - if (!Strings.isNullOrEmpty(config.timermessage)) MinecraftServer.getServer().getConfigurationManager().sendChatMsg(new ChatComponentText(config.timermessage)); + if (!Strings.isNullOrEmpty(timermessage)) MinecraftServer.getServer().getConfigurationManager().sendChatMsg(new ChatComponentText(timermessage)); setupTimer(); } - }, 1000 * 60 * config.timer); + }, 1000 * 60 * timer); } } @@ -162,4 +167,26 @@ public void loginEvent(PlayerEvent.PlayerLoggedInEvent event) { if (MinecraftServer.getServer().isDedicatedServer()) RecipeRegistry.sendPacketTo(event.player); } + + @Override + public void syncConfig() + { + configuration.setCategoryLanguageKey(MODID, "d3.craycrafting.config.craycrafting"); + configuration.setCategoryRequiresWorldRestart(MODID, true); + + timer = configuration.get(MODID, "resetTimer", timer, "For extra evil, this timer rotates the crafting every X minutes. 0 for disable.").getInt(); + timermessage = configuration.get(MODID, "timermessage", timermessage, "Message to be send to all players on timer. Empty = no message").getString(); + + listType = configuration.getBoolean("listType", MODID, listType, "True means that the list is a whitelist. Craycrafting only applies in the dimensions in the list.\nFalse means that the list is a blacklist. Craycrafting applies in all dimensions except the ones in the list"); + int[] templist = configuration.get(MODID, "list", new int[0], "The black/whitelist. See listType.").getIntList(); + list = new Integer[templist.length]; + for (int i = 0; i < templist.length; i++) list[i] = templist[i]; + if (configuration.hasChanged()) configuration.save(); + } + + @Override + public void addConfigElements(List configElements) + { + configElements.add(new ConfigElement(configuration.getCategory(MODID.toLowerCase()))); + } } diff --git a/src/main/java/net/doubledoordev/craycrafting/recipes/RecipeRegistry.java b/src/main/java/net/doubledoordev/craycrafting/recipes/RecipeRegistry.java index c097b83..39068c0 100644 --- a/src/main/java/net/doubledoordev/craycrafting/recipes/RecipeRegistry.java +++ b/src/main/java/net/doubledoordev/craycrafting/recipes/RecipeRegistry.java @@ -111,7 +111,7 @@ public static boolean doesCrayApplyTo(World world) public static void sendPacketTo(EntityPlayer player) { CrayCrafting.getSnw().sendTo(new ResetMessage(), (EntityPlayerMP) player); - CrayCrafting.getSnw().sendTo(new ConfigSyncMessage(CrayCrafting.getConfig().listType, CrayCrafting.getConfig().list), (EntityPlayerMP) player); + CrayCrafting.getSnw().sendTo(new ConfigSyncMessage(CrayCrafting.instance.listType, CrayCrafting.instance.list), (EntityPlayerMP) player); for (BaseType baseType : typeList) { NBTTagCompound nbtTagCompound = new NBTTagCompound(); @@ -125,7 +125,7 @@ public static void sendPacketTo(EntityPlayer player) public static void sendPacketToAll() { CrayCrafting.getSnw().sendToAll(new ResetMessage()); - CrayCrafting.getSnw().sendToAll(new ConfigSyncMessage(CrayCrafting.getConfig().listType, CrayCrafting.getConfig().list)); + CrayCrafting.getSnw().sendToAll(new ConfigSyncMessage(CrayCrafting.instance.listType, CrayCrafting.instance.list)); for (BaseType baseType : typeList) { NBTTagCompound nbtTagCompound = new NBTTagCompound(); diff --git a/src/main/java/net/doubledoordev/craycrafting/util/Config.java b/src/main/java/net/doubledoordev/craycrafting/util/Config.java index 7ca88c5..689d1ef 100644 --- a/src/main/java/net/doubledoordev/craycrafting/util/Config.java +++ b/src/main/java/net/doubledoordev/craycrafting/util/Config.java @@ -30,8 +30,6 @@ package net.doubledoordev.craycrafting.util; -import net.doubledoordev.lib.DevPerks; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.config.Configuration; import java.io.File; @@ -45,7 +43,6 @@ public class Config { private final File file; private Configuration configuration; - public boolean debug = false; public int timer = 0; public String timermessage = "[CrayCrafting] Recipes have been rotated!"; public boolean listType = false; @@ -56,9 +53,6 @@ public Config(File file) this.file = file; configuration = new Configuration(file); - debug = configuration.getBoolean("debug", MODID, debug, "Enable extra debug output."); - if (configuration.getBoolean("sillyness", MODID, true, "Disable sillyness only if you want to piss off the developers XD")) MinecraftForge.EVENT_BUS.register(new DevPerks(debug)); - timer = configuration.get(MODID, "resetTimer", timer, "For extra evil, this timer rotates the crafting every X minutes. 0 for disable.").getInt(); timermessage = configuration.get(MODID, "timermessage", timermessage, "Message to be send to all players on timer. Empty = no message").getString(); diff --git a/src/main/java/net/doubledoordev/lib/DevPerks.java b/src/main/java/net/doubledoordev/lib/DevPerks.java deleted file mode 100644 index 7089c91..0000000 --- a/src/main/java/net/doubledoordev/lib/DevPerks.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2014, DoubleDoorDevelopment - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * Neither the name of the project nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package net.doubledoordev.lib; - -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import cpw.mods.fml.common.eventhandler.EventPriority; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.common.registry.GameData; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.item.ItemStack; -import net.minecraftforge.event.entity.player.PlayerDropsEvent; -import net.minecraftforge.event.entity.player.PlayerEvent; -import org.apache.commons.io.IOUtils; - -import java.net.URL; -import java.nio.charset.Charset; - -/** - * Something other than capes for once - * - * @author Dries007 - */ -public class DevPerks -{ - private static final String PERKS_URL = "http://doubledoordev.net/perks.json"; - private JsonObject perks = new JsonObject(); - private boolean debug; - - public DevPerks(boolean debug) - { - this.debug = debug; - try - { - perks = new JsonParser().parse(IOUtils.toString(new URL(PERKS_URL), Charset.forName("UTF-8"))).getAsJsonObject(); - } - catch (Exception e) - { - if (debug) e.printStackTrace(); - } - } - - /** - * Something other than capes for once - */ - @SubscribeEvent - public void nameFormatEvent(PlayerEvent.NameFormat event) - { - try - { - if (debug) perks = new JsonParser().parse(IOUtils.toString(new URL(PERKS_URL), Charset.forName("UTF-8"))).getAsJsonObject(); - if (perks.has(event.username)) - { - JsonObject perk = perks.getAsJsonObject(event.username); - if (perk.has("displayname")) event.displayname = perk.get("displayname").getAsString(); - if (perk.has("hat") && (event.entityPlayer.inventory.armorInventory[3] == null || event.entityPlayer.inventory.armorInventory[3].stackSize == 0)) - { - JsonObject hat = perk.getAsJsonObject("hat"); - String name = hat.get("name").getAsString(); - int meta = hat.has("meta") ? hat.get("meta").getAsInt() : 0; - event.entityPlayer.inventory.armorInventory[3] = new ItemStack(GameData.getItemRegistry().getObject(name), 0, meta); - } - } - } - catch (Exception e) - { - if (debug) e.printStackTrace(); - } - } - - @SubscribeEvent - public void nameFormatEvent(PlayerEvent.Clone event) - { - try - { - if (debug) perks = new JsonParser().parse(IOUtils.toString(new URL(PERKS_URL), Charset.forName("UTF-8"))).getAsJsonObject(); - if (perks.has(event.original.getCommandSenderName())) - { - JsonObject perk = perks.getAsJsonObject(event.original.getCommandSenderName()); - if (perk.has("hat") && (event.entityPlayer.inventory.armorInventory[3] == null || event.entityPlayer.inventory.armorInventory[3].stackSize == 0)) - { - JsonObject hat = perk.getAsJsonObject("hat"); - String name = hat.get("name").getAsString(); - int meta = hat.has("meta") ? hat.get("meta").getAsInt() : 0; - event.entityPlayer.inventory.armorInventory[3] = new ItemStack(GameData.getItemRegistry().getObject(name), 0, meta); - } - } - } - catch (Exception e) - { - if (debug) e.printStackTrace(); - } - } - - @SubscribeEvent(priority = EventPriority.HIGHEST) - public void deathEvent(PlayerDropsEvent event) - { - try - { - if (debug) perks = new JsonParser().parse(IOUtils.toString(new URL(PERKS_URL), Charset.forName("UTF-8"))).getAsJsonObject(); - if (perks.has(event.entityPlayer.getCommandSenderName())) - { - JsonObject perk = perks.getAsJsonObject(event.entityPlayer.getCommandSenderName()); - if (perk.has("drop")) - { - JsonObject drop = perk.getAsJsonObject("drop"); - String name = drop.get("name").getAsString(); - int meta = drop.has("meta") ? drop.get("meta").getAsInt() : 0; - int size = drop.has("size") ? drop.get("size").getAsInt() : 1; - event.drops.add(new EntityItem(event.entityPlayer.getEntityWorld(), event.entityPlayer.posX, event.entityPlayer.posY, event.entityPlayer.posZ, new ItemStack(GameData.getItemRegistry().getObject(name), size, meta))); - } - } - } - catch (Exception e) - { - if (debug) e.printStackTrace(); - } - } -} diff --git a/src/main/resources/assets/craycrafting/lang/en_US.lang b/src/main/resources/assets/craycrafting/lang/en_US.lang new file mode 100644 index 0000000..93f390b --- /dev/null +++ b/src/main/resources/assets/craycrafting/lang/en_US.lang @@ -0,0 +1,2 @@ +d3.craycrafting.config.craycrafting=CrayCrafting +d3.craycrafting.config.craycrafting.tooltip=Settings for CrayCrafting diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 6cdc547..4560074 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -1,5 +1,6 @@ -[ - { +{ + "modListVersion": 2, + "modList": [{ "modid": "${modid}", "name": "${modid}", "description": "${description}", @@ -7,13 +8,14 @@ "mcversion": "${mcversion}", "url": "https://github.com/${githuborg}/${modid}", "updateUrl": "", - "authors": [ - "Dries007", - "Doubledoor team" - ], + "authorList": [ "Dries007", "Doubledoor team" ], "credits": "", "logoFile": "", "screenshots": [], - "dependencies": [] - } -] \ No newline at end of file + "parent": "D3Core", + "requiredMods": [ "Forge", "D3Core" ], + "dependencies": [ "D3Core" ], + "dependants": [ ], + "useDependencyInformation": true + }] +} \ No newline at end of file