1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-06 00:08:13 +01:00

Lets shorten restrictedBlocks file and use material names instead

This commit is contained in:
Zrips 2018-10-16 15:17:37 +03:00
parent 85ec42abb7
commit f5183b3bac
3 changed files with 55 additions and 145 deletions

View File

@ -783,6 +783,9 @@ public class Jobs extends JavaPlugin {
YmlMaker jobShopItems = new YmlMaker(this, "shopItems.yml");
jobShopItems.saveDefaultConfig();
YmlMaker restrictedBlocks = new YmlMaker(this, "restrictedBlocks.yml");
restrictedBlocks.saveDefaultConfig();
setPermissionHandler(new PermissionHandler(this));
setJobsClassloader();
setPlayerManager();

View File

@ -1,16 +1,13 @@
package com.gamingmesh.jobs.config;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Set;
import org.bukkit.configuration.file.YamlConfiguration;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.CMIItemStack;
import com.gamingmesh.jobs.CMILib.ConfigReader;
import com.gamingmesh.jobs.CMILib.ItemManager;
import com.gamingmesh.jobs.container.LocaleReader;
import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial;
public class RestrictedBlockManager {
@ -28,158 +25,68 @@ public class RestrictedBlockManager {
* loads from Jobs/restrictedAreas.yml
*/
public synchronized void load() {
// No file create/load when boolean is false
if (!Jobs.getGCManager().useBlockProtection) {
return;
}
// No file create/load when boolean is false
if (!Jobs.getGCManager().useBlockProtection) {
return;
}
ConfigReader cfg = null;
try {
cfg = new ConfigReader("restrictedBlocks.yml");
} catch (Exception e1) {
e1.printStackTrace();
}
if (cfg == null)
return;
File f = new File(plugin.getDataFolder(), "restrictedBlocks.yml");
YamlConfiguration config = YamlConfiguration.loadConfiguration(f);
CommentedYamlConfiguration writer = new CommentedYamlConfiguration();
LocaleReader c = new LocaleReader(config, writer);
config.options().copyDefaults(true);
c.getW().addComment("blocksTimer", "Block protected by timer in sec",
cfg.addComment("blocksTimer", "Block protected by timer in sec",
"Category name can be any you like to be easily recognized",
"id can be actual block id (use /jobs blockinfo to get correct id) or use block name",
"By setting time to -1 will keep block protected until global cleanup, mainly used for structure blocks like diamond",
"If you want to have default value for all blocks, enale GlobalBlockTimer in generalConfig file");
"If you want to have default value for all blocks, enable GlobalBlockTimer in generalConfig file");
if (!c.getC().isConfigurationSection("blocksTimer")) {
c.getC().addDefault("blocksTimer.Sapling.id", 6);
c.getC().addDefault("blocksTimer.Sapling.cd", 60);
c.getC().addDefault("blocksTimer.leaves.id", 18);
c.getC().addDefault("blocksTimer.leaves.cd", 60);
c.getC().addDefault("blocksTimer.grass.id", "longgrass");
c.getC().addDefault("blocksTimer.grass.cd", 60);
c.getC().addDefault("blocksTimer.deadBush.id", 32);
c.getC().addDefault("blocksTimer.deadBush.cd", 60);
c.getC().addDefault("blocksTimer.rail.id", 66);
c.getC().addDefault("blocksTimer.rail.cd", 60);
c.getC().addDefault("blocksTimer.rail2.id", 27);
c.getC().addDefault("blocksTimer.rail2.cd", 60);
c.getC().addDefault("blocksTimer.rail3.id", 28);
c.getC().addDefault("blocksTimer.rail3.cd", 60);
c.getC().addDefault("blocksTimer.rail4.id", 157);
c.getC().addDefault("blocksTimer.rail4.cd", 60);
c.getC().addDefault("blocksTimer.web.id", 30);
c.getC().addDefault("blocksTimer.web.cd", 60);
c.getC().addDefault("blocksTimer.dandelion.id", 37);
c.getC().addDefault("blocksTimer.dandelion.cd", 60);
c.getC().addDefault("blocksTimer.poppy.id", 38);
c.getC().addDefault("blocksTimer.poppy.cd", 60);
c.getC().addDefault("blocksTimer.flower.id", 175);
c.getC().addDefault("blocksTimer.flower.cd", 60);
c.getC().addDefault("blocksTimer.mushroom.id", 39);
c.getC().addDefault("blocksTimer.mushroom.cd", 60);
c.getC().addDefault("blocksTimer.mushroomRed.id", 40);
c.getC().addDefault("blocksTimer.mushroomRed.cd", 60);
c.getC().addDefault("blocksTimer.torch.id", 50);
c.getC().addDefault("blocksTimer.torch.cd", 60);
c.getC().addDefault("blocksTimer.redTorch.id", 76);
c.getC().addDefault("blocksTimer.redTorch.cd", 60);
c.getC().addDefault("blocksTimer.lader.id", 65);
c.getC().addDefault("blocksTimer.lader.cd", 5);
c.getC().addDefault("blocksTimer.carpet.id", 171);
c.getC().addDefault("blocksTimer.carpet.cd", 60);
c.getC().addDefault("blocksTimer.button.id", 77);
c.getC().addDefault("blocksTimer.button.cd", 5);
c.getC().addDefault("blocksTimer.button2.id", 143);
c.getC().addDefault("blocksTimer.button2.cd", 5);
c.getC().addDefault("blocksTimer.lever.id", 69);
c.getC().addDefault("blocksTimer.lever.cd", 60);
c.getC().addDefault("blocksTimer.snow.id", 78);
c.getC().addDefault("blocksTimer.snow.cd", 60);
c.getC().addDefault("blocksTimer.snow2.id", 80);
c.getC().addDefault("blocksTimer.snow2.cd", 60);
c.getC().addDefault("blocksTimer.hook.id", 131);
c.getC().addDefault("blocksTimer.hook.cd", 60);
c.getC().addDefault("blocksTimer.tripWire.id", 132);
c.getC().addDefault("blocksTimer.tripWire.cd", 60);
c.getC().addDefault("blocksTimer.redstone.id", 55);
c.getC().addDefault("blocksTimer.redstone.cd", 60);
c.getC().addDefault("blocksTimer.repeater.id", 93);
c.getC().addDefault("blocksTimer.repeater.cd", 60);
c.getC().addDefault("blocksTimer.comparator.id", 149);
c.getC().addDefault("blocksTimer.comparator.cd", 60);
c.getC().addDefault("blocksTimer.lily.id", 111);
c.getC().addDefault("blocksTimer.lily.cd", 30);
c.getC().addDefault("blocksTimer.vines.id", 106);
c.getC().addDefault("blocksTimer.vines.cd", 30);
c.getC().addDefault("blocksTimer.wheat.id", 59);
c.getC().addDefault("blocksTimer.wheat.cd", 5);
c.getC().addDefault("blocksTimer.sugarcane.id", 83);
c.getC().addDefault("blocksTimer.sugarcane.cd", 30);
c.getC().addDefault("blocksTimer.cactus.id", 81);
c.getC().addDefault("blocksTimer.cactus.cd", 30);
c.getC().addDefault("blocksTimer.beatroot.id", 207);
c.getC().addDefault("blocksTimer.beatroot.cd", 60);
c.getC().addDefault("blocksTimer.potato.id", 142);
c.getC().addDefault("blocksTimer.potato.cd", 60);
c.getC().addDefault("blocksTimer.carrot.id", 141);
c.getC().addDefault("blocksTimer.carrot.cd", 60);
c.getC().addDefault("blocksTimer.warts.id", 115);
c.getC().addDefault("blocksTimer.warts.cd", 60);
c.getC().addDefault("blocksTimer.pumpkin.id", 86);
c.getC().addDefault("blocksTimer.pumpkin.cd", 30);
c.getC().addDefault("blocksTimer.pumpkinstem.id", 104);
c.getC().addDefault("blocksTimer.pumpkinstem.cd", 30);
c.getC().addDefault("blocksTimer.melon.id", 103);
c.getC().addDefault("blocksTimer.melon.cd", 30);
c.getC().addDefault("blocksTimer.melonstem.id", 105);
c.getC().addDefault("blocksTimer.melonstem.cd", 30);
c.getC().addDefault("blocksTimer.goldore.id", "goldore");
c.getC().addDefault("blocksTimer.goldore.cd", -1);
c.getC().addDefault("blocksTimer.ironore.id", "ironore");
c.getC().addDefault("blocksTimer.ironore.cd", -1);
c.getC().addDefault("blocksTimer.coalore.id", "coalore");
c.getC().addDefault("blocksTimer.coalore.cd", -1);
c.getC().addDefault("blocksTimer.lapisore.id", "lapisore");
c.getC().addDefault("blocksTimer.lapisore.cd", -1);
c.getC().addDefault("blocksTimer.diamondore.id", "diamondore");
c.getC().addDefault("blocksTimer.diamondore.cd", -1);
c.getC().addDefault("blocksTimer.redstoneore.id", "redstoneore");
c.getC().addDefault("blocksTimer.redstoneore.cd", -1);
c.getC().addDefault("blocksTimer.emeraldore.id", "emeraldore");
c.getC().addDefault("blocksTimer.emeraldore.cd", -1);
c.getC().addDefault("blocksTimer.quartzore.id", "quartzore");
c.getC().addDefault("blocksTimer.quartzore.cd", -1);
}
if (c.getC().isConfigurationSection("blocksTimer")) {
Set<String> lss = c.getC().getConfigurationSection("blocksTimer").getKeys(false);
if (cfg.getC().isConfigurationSection("blocksTimer")) {
Set<String> lss = cfg.getC().getConfigurationSection("blocksTimer").getKeys(false);
for (String one : lss) {
if (((c.getC().isString("blocksTimer." + one + ".id")) || (c.getC().isInt("blocksTimer." + one + ".id"))) && (c.getC().isInt("blocksTimer." + one
if (((cfg.getC().isString("blocksTimer." + one + ".id")) || (cfg.getC().isInt("blocksTimer." + one + ".id"))) && (cfg.getC().isInt("blocksTimer." + one
+ ".cd"))) {
CMIItemStack cm = ItemManager.getItem(c.getC().getString("blocksTimer." + one + ".id"));
CMIItemStack cm = ItemManager.getItem(cfg.getC().getString("blocksTimer." + one + ".id"));
if ((cm == null) || (!cm.getCMIType().isBlock())) {
Jobs.consoleMsg("&e[Jobs] Your defined (" + c.getC().getString(new StringBuilder("blocksTimer.").append(one)
.append(".id").toString()) + ") protected block id/name is not correct!");
} else {
this.restrictedBlocksTimer.put(cm.getId(), c.getC().getInt("blocksTimer." + one + ".cd"));
Jobs.consoleMsg("&e[Jobs] Your defined (" + one + ") protected block id/name is not correct!");
continue;
}
this.restrictedBlocksTimer.put(cm.getCMIType().getId(), cfg.getC().getInt("blocksTimer." + one + ".cd"));
cfg.set("blocksTimer." + cm.getCMIType().name(), cfg.getC().getInt("blocksTimer." + one + ".cd"));
} else {
int timer = cfg.get("blocksTimer." + one, -99);
CMIMaterial mat = CMIMaterial.get(one);
if (mat == null)
continue;
if (timer == -99) {
cfg.set("blocksTimer." + one, null);
continue;
}
cfg.set("blocksTimer." + one, null);
cfg.get("blocksTimer." + mat.name(), timer);
if (!mat.isBlock()) {
Jobs.consoleMsg("&e[Jobs] Your defined (" + one + ") protected block id/name is not correct!");
continue;
}
this.restrictedBlocksTimer.put(mat.getId(), timer);
}
}
}
c.copySetting("blocksTimer");
if (restrictedBlocksTimer.size() != 0)
Jobs.consoleMsg("&e[Jobs] Loaded " + this.restrictedBlocksTimer.size() + " protected blocks timers!");
try {
writer.save(f);
} catch (IOException e) {
e.printStackTrace();
}
Jobs.consoleMsg("&e[Jobs] Loaded " + this.restrictedBlocksTimer.size() + " protected blocks timers!");
cfg.save();
}
}

View File

@ -1116,7 +1116,7 @@ Jobs:
income: 0.25
points: 0.25
experience: 0.25
GRASS:
GRASS_BLOCK:
income: 0.3
points: 0.3
experience: 0.3