Skip to content

Commit

Permalink
fix configuration default init
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Beaucamps committed Dec 13, 2019
1 parent 6a80884 commit cbcf774
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/onaple/itemizer/Itemizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public void preInit(GamePreInitializationEvent event) {
.builder(new IdDataManipulator.Builder())
.build();

configurationHandler.createItemizerDirectory();
loadGlobalConfig();
try {
int size = configurationHandler.readItemsConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand Down Expand Up @@ -61,6 +62,17 @@ public List<ICraftRecipes> getCraftList() {
}


public void createItemizerDirectory(){
Path configPath = Paths.get(configDir + "/itemizer/");
if(!Files.exists(configPath)){
try {
Files.createDirectories(configPath);
} catch (IOException e) {
Itemizer.getLogger().error("Can't create config dir", e);
}
}
}

/**
* Read items configuration and interpret it
*/
Expand Down Expand Up @@ -154,9 +166,10 @@ private void initDefaultConfig(Path path) {
getLogger().info("No config file set for {} default config will be loaded",path);
if (itemsDefaultConfigFile.isPresent()) {
try {

itemsDefaultConfigFile.get().copyToFile(path);
} catch (IOException e) {
getLogger().error("Error while setting default configuration : {}", e.getMessage());
getLogger().error("Error while setting default configuration : ", e);
}
} else {
getLogger().warn("Default config not found");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ ItemStack toItemStack() throws ObjectMappingException {
return ItemStack.of(type);
}
if(ref == null){
Itemizer.getLogger().error("No 'name' or 'ref' provided.");
throw new ObjectMappingException();
throw new ObjectMappingException("No 'name' or 'ref' provided.");
}
return Itemizer.getItemService().retrieve(ref).orElseThrow(ObjectMappingException::new);
return Itemizer.getItemService().retrieve(ref).orElseThrow(() ->new ObjectMappingException("Invalid name ["+ type+"] or reference ["+ ref +"]"));
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/assets/itemizer/crafts.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ crafts = [
{
__class__ : "com.onaple.itemizer.data.beans.recipes.ShapedCrafting"
id : 3
result : {ref : "training_stick"},
result : {ref : "king_sword"},
pattern : [" a "," a "," a "],
ingredients : {
a : {name: "minecraft:stick"},
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/itemizer/global.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ DefaultColor {
unbreakable=GREEN
}
# Enchant name rewrite
# if an enchat is empty it don't apear
# if an enchantmentst is empty it don't apear
EnchantRewrite {
Efficiency="Powerful"
}
Expand Down
32 changes: 31 additions & 1 deletion src/main/resources/assets/itemizer/items.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
items = [
items=[
{
id="1"
item {
ContentVersion=2
Count=1
ItemType="minecraft:coal"
UnsafeDamage=0
UnsafeData {
RepairCost=0
display {
Name="Tin ore"
}
id="1"
}
}
thirdParties=[]
},
{
id="king_sword"
item {
ContentVersion=2
Count=1
ItemType="minecraft:golden_sword"
UnsafeDamage=0
UnsafeData {
id="king_sword"
}
}
thirdParties=[]
}
]
14 changes: 13 additions & 1 deletion src/main/resources/assets/itemizer/pools.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
pools = [

{
id: 1,
items: [
{
probability: 0.5,
type: "minecraft:cooked_porkchop"
},
{
probability: 0.2,
ref: 1
}
]
}
]
4 changes: 2 additions & 2 deletions version.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#Fri Nov 29 20:36:06 CET 2019
#Fri Dec 13 22:06:32 CET 2019
MAJOR=3
MINOR=0
PATCH=0
PRE_RELEASE=
BUILD=423
BUILD=434
CODE=0

0 comments on commit cbcf774

Please sign in to comment.