mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-26 04:25:15 +01:00
Better block ownership saving
Better feedback on ownership manual removal
This commit is contained in:
parent
0c0c0ff9ba
commit
4a2862281b
@ -936,7 +936,7 @@ public final class Jobs extends JavaPlugin {
|
|||||||
if (dao != null && Jobs.getGeneralConfigManager().ExploreSaveIntoDatabase)
|
if (dao != null && Jobs.getGeneralConfigManager().ExploreSaveIntoDatabase)
|
||||||
dao.saveExplore();
|
dao.saveExplore();
|
||||||
|
|
||||||
blockOwnerShipsMaterial.values().forEach(BlockOwnerShip::save);
|
BlockOwnerShip.save(blockOwnerShipsMaterial);
|
||||||
|
|
||||||
if (saveTask != null)
|
if (saveTask != null)
|
||||||
saveTask.shutdown();
|
saveTask.shutdown();
|
||||||
|
@ -4,11 +4,13 @@ import java.util.Map;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gamingmesh.jobs.Jobs;
|
import com.gamingmesh.jobs.Jobs;
|
||||||
import com.gamingmesh.jobs.commands.Cmd;
|
import com.gamingmesh.jobs.commands.Cmd;
|
||||||
|
import com.gamingmesh.jobs.commands.JobsCommands;
|
||||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||||
import com.gamingmesh.jobs.container.blockOwnerShip.BlockTypes;
|
import com.gamingmesh.jobs.container.blockOwnerShip.BlockTypes;
|
||||||
import com.gamingmesh.jobs.i18n.Language;
|
import com.gamingmesh.jobs.i18n.Language;
|
||||||
@ -67,6 +69,9 @@ public class clearownership implements Cmd {
|
|||||||
|
|
||||||
Language.sendMessage(sender, "command.clearownership.output.cleared", "[furnaces]", amounts.getOrDefault(BlockTypes.FURNACE, 0), "[brewing]", amounts.getOrDefault(
|
Language.sendMessage(sender, "command.clearownership.output.cleared", "[furnaces]", amounts.getOrDefault(BlockTypes.FURNACE, 0), "[brewing]", amounts.getOrDefault(
|
||||||
BlockTypes.BREWING_STAND, 0), "[smoker]", amounts.getOrDefault(BlockTypes.SMOKER, 0), "[blast]", amounts.getOrDefault(BlockTypes.BLAST_FURNACE, 0));
|
BlockTypes.BREWING_STAND, 0), "[smoker]", amounts.getOrDefault(BlockTypes.SMOKER, 0), "[blast]", amounts.getOrDefault(BlockTypes.BLAST_FURNACE, 0));
|
||||||
|
|
||||||
|
Bukkit.dispatchCommand(sender, JobsCommands.LABEL + " " + ownedblocks.class.getSimpleName() + (sender.getName().equals(jPlayer.getName()) ? "" : jPlayer.getName()));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -870,10 +870,10 @@ public class GeneralConfigManager {
|
|||||||
FurnacesMaxDefault = c.get("ExploitProtections.Furnaces.MaxDefaultAvailable", 20);
|
FurnacesMaxDefault = c.get("ExploitProtections.Furnaces.MaxDefaultAvailable", 20);
|
||||||
|
|
||||||
if (Version.isCurrentEqualOrHigher(Version.v1_14_R1)) {
|
if (Version.isCurrentEqualOrHigher(Version.v1_14_R1)) {
|
||||||
BlastFurnacesReassign = c.get("ExploitProtections.BlastFurnaces.Reassign", false);
|
BlastFurnacesReassign = c.get("ExploitProtections.BlastFurnaces.Reassign", true);
|
||||||
BlastFurnacesMaxDefault = c.get("ExploitProtections.BlastFurnaces.MaxDefaultAvailable", 15);
|
BlastFurnacesMaxDefault = c.get("ExploitProtections.BlastFurnaces.MaxDefaultAvailable", 15);
|
||||||
|
|
||||||
SmokerReassign = c.get("ExploitProtections.Smokers.Reassign", false);
|
SmokerReassign = c.get("ExploitProtections.Smokers.Reassign", true);
|
||||||
SmokersMaxDefault = c.get("ExploitProtections.Smokers.MaxDefaultAvailable", 15);
|
SmokersMaxDefault = c.get("ExploitProtections.Smokers.MaxDefaultAvailable", 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -881,6 +881,7 @@ public class GeneralConfigManager {
|
|||||||
"When enabled, players interacted brewing stands will be saved into file and will be reassigned after restart to keep giving out money",
|
"When enabled, players interacted brewing stands will be saved into file and will be reassigned after restart to keep giving out money",
|
||||||
"Players will no longer need to click on brewing stand to get paid from it after server restart");
|
"Players will no longer need to click on brewing stand to get paid from it after server restart");
|
||||||
BrewingStandsReassign = c.get("ExploitProtections.BrewingStands.Reassign", true);
|
BrewingStandsReassign = c.get("ExploitProtections.BrewingStands.Reassign", true);
|
||||||
|
|
||||||
c.addComment("ExploitProtections.BrewingStands.MaxDefaultAvailable",
|
c.addComment("ExploitProtections.BrewingStands.MaxDefaultAvailable",
|
||||||
"Defines max available brewing stands each player can have to get paid from",
|
"Defines max available brewing stands each player can have to get paid from",
|
||||||
"Set to 0 if you want to disable this limitation",
|
"Set to 0 if you want to disable this limitation",
|
||||||
|
@ -495,7 +495,7 @@ public class LanguageManager {
|
|||||||
c.get("command.clearownership.help.info", "Clear block ownership");
|
c.get("command.clearownership.help.info", "Clear block ownership");
|
||||||
c.get("command.clearownership.help.args", "[playername]");
|
c.get("command.clearownership.help.args", "[playername]");
|
||||||
Jobs.getGCManager().getCommandArgs().put("clearownership", Arrays.asList("[playername]"));
|
Jobs.getGCManager().getCommandArgs().put("clearownership", Arrays.asList("[playername]"));
|
||||||
c.get("command.clearownership.output.cleared", "&2Removed &7[furnaces] &2furnaces, &7[brewing] &2brewing stands, &7[smoker]&2 smokers and &7[blast]&2 blast furnaces.");
|
c.get("command.clearownership.output.cleared", "&2Removed &7[furnaces] &2furnaces &7[brewing] &2brewing &7[smoker]&2 smokers &7[blast]&2 blast");
|
||||||
c.get("command.clearownership.output.lost", "&cLost ownership of &7[type] &cat [location]");
|
c.get("command.clearownership.output.lost", "&cLost ownership of &7[type] &cat [location]");
|
||||||
|
|
||||||
c.get("command.skipquest.help.info", "Skip defined quest and get new one");
|
c.get("command.skipquest.help.info", "Skip defined quest and get new one");
|
||||||
|
@ -9,7 +9,6 @@ import java.util.Map;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import com.gamingmesh.jobs.api.JobsBlockOwnershipRegisterEvent;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -19,12 +18,15 @@ import org.bukkit.metadata.FixedMetadataValue;
|
|||||||
import org.bukkit.metadata.MetadataValue;
|
import org.bukkit.metadata.MetadataValue;
|
||||||
|
|
||||||
import com.gamingmesh.jobs.Jobs;
|
import com.gamingmesh.jobs.Jobs;
|
||||||
|
import com.gamingmesh.jobs.api.JobsBlockOwnershipRegisterEvent;
|
||||||
import com.gamingmesh.jobs.config.YmlMaker;
|
import com.gamingmesh.jobs.config.YmlMaker;
|
||||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||||
import com.gamingmesh.jobs.stuff.blockLoc;
|
import com.gamingmesh.jobs.stuff.blockLoc;
|
||||||
|
|
||||||
import net.Zrips.CMILib.Container.CMILocation;
|
import net.Zrips.CMILib.Container.CMILocation;
|
||||||
|
import net.Zrips.CMILib.FileHandler.ConfigReader;
|
||||||
import net.Zrips.CMILib.Items.CMIMaterial;
|
import net.Zrips.CMILib.Items.CMIMaterial;
|
||||||
|
import net.Zrips.CMILib.Logs.CMIDebug;
|
||||||
import net.Zrips.CMILib.Messages.CMIMessages;
|
import net.Zrips.CMILib.Messages.CMIMessages;
|
||||||
|
|
||||||
public class BlockOwnerShip {
|
public class BlockOwnerShip {
|
||||||
@ -290,8 +292,9 @@ public class BlockOwnerShip {
|
|||||||
|
|
||||||
public int remove(UUID uuid, String location) {
|
public int remove(UUID uuid, String location) {
|
||||||
HashMap<String, blockLoc> ls = blockOwnerShips.get(uuid);
|
HashMap<String, blockLoc> ls = blockOwnerShips.get(uuid);
|
||||||
|
int ret = 0;
|
||||||
if (ls == null)
|
if (ls == null)
|
||||||
return 0;
|
return ret;
|
||||||
|
|
||||||
for (Entry<String, blockLoc> one : new HashMap<String, blockLoc>(ls).entrySet()) {
|
for (Entry<String, blockLoc> one : new HashMap<String, blockLoc>(ls).entrySet()) {
|
||||||
|
|
||||||
@ -303,11 +306,13 @@ public class BlockOwnerShip {
|
|||||||
ls.remove(one.getKey());
|
ls.remove(one.getKey());
|
||||||
|
|
||||||
Map<String, UUID> oldRecord = ownerMapByLocation.get(one.getValue().getWorldName());
|
Map<String, UUID> oldRecord = ownerMapByLocation.get(one.getValue().getWorldName());
|
||||||
if (oldRecord != null)
|
if (oldRecord != null) {
|
||||||
oldRecord.remove(one.getValue().toVectorString());
|
oldRecord.remove(one.getValue().toVectorString());
|
||||||
|
ret++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MetadataValue> getBlockMetadatas(Block block) {
|
public List<MetadataValue> getBlockMetadatas(Block block) {
|
||||||
@ -320,34 +325,12 @@ public class BlockOwnerShip {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void load() {
|
public void load() {
|
||||||
YmlMaker f = new YmlMaker(Jobs.getFolder(), "furnaceBrewingStands.yml");
|
|
||||||
YmlMaker f2 = new YmlMaker(Jobs.getFolder(), "blockOwnerShips.yml");
|
YmlMaker f = new YmlMaker(Jobs.getFolder(), "blockOwnerShips.yml");
|
||||||
if (!f.exists() && !f2.exists())
|
if (!f.exists())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (f.exists()) {
|
String path = type.getPath();
|
||||||
f.getConfigFile().renameTo(f2.getConfigFile());
|
|
||||||
}
|
|
||||||
|
|
||||||
f = f2;
|
|
||||||
|
|
||||||
String path = "";
|
|
||||||
switch (type) {
|
|
||||||
case BLAST_FURNACE:
|
|
||||||
path = "BlastFurnace";
|
|
||||||
break;
|
|
||||||
case BREWING_STAND:
|
|
||||||
path = "Brewing";
|
|
||||||
break;
|
|
||||||
case FURNACE:
|
|
||||||
path = "Furnace";
|
|
||||||
break;
|
|
||||||
case SMOKER:
|
|
||||||
path = "Smoker";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isReassignDisabled())
|
if (isReassignDisabled())
|
||||||
return;
|
return;
|
||||||
@ -375,17 +358,24 @@ public class BlockOwnerShip {
|
|||||||
}
|
}
|
||||||
|
|
||||||
HashMap<String, blockLoc> blist = new HashMap<String, blockLoc>();
|
HashMap<String, blockLoc> blist = new HashMap<String, blockLoc>();
|
||||||
|
boolean informed = false;
|
||||||
for (String oneL : ls) {
|
for (String oneL : ls) {
|
||||||
|
try {
|
||||||
blockLoc bl = new blockLoc(oneL);
|
blockLoc bl = new blockLoc(oneL);
|
||||||
CMILocation cmil = CMILocation.fromString(oneL, ":");
|
|
||||||
|
|
||||||
blist.put(CMILocation.toString(cmil, ":", true, true), bl);
|
blist.put(oneL, bl);
|
||||||
|
|
||||||
Map<String, UUID> oldRecord = ownerMapByLocation.getOrDefault(bl.getWorldName(), new HashMap<String, UUID>());
|
Map<String, UUID> oldRecord = ownerMapByLocation.getOrDefault(bl.getWorldName(), new HashMap<String, UUID>());
|
||||||
oldRecord.put(bl.toVectorString(), uuid);
|
oldRecord.put(bl.toVectorString(), uuid);
|
||||||
ownerMapByLocation.put(bl.getWorldName(), oldRecord);
|
ownerMapByLocation.put(bl.getWorldName(), oldRecord);
|
||||||
|
|
||||||
total++;
|
total++;
|
||||||
|
|
||||||
|
} catch (Throwable e) {
|
||||||
|
if (!informed)
|
||||||
|
e.printStackTrace();
|
||||||
|
informed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!blist.isEmpty()) {
|
if (!blist.isEmpty()) {
|
||||||
@ -398,46 +388,45 @@ public class BlockOwnerShip {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public static void save(HashMap<CMIMaterial, BlockOwnerShip> blockOwnerShipsMaterial) {
|
||||||
YmlMaker f = new YmlMaker(Jobs.getFolder(), "furnaceBrewingStands.yml");
|
|
||||||
if (f.exists()) {
|
File f = new File(Jobs.getInstance().getDataFolder(), "blockOwnerShips.yml");
|
||||||
f.getConfigFile().renameTo(new File(Jobs.getFolder(), "blockOwnerShips.yml"));
|
|
||||||
|
ConfigReader cfg = null;
|
||||||
|
try {
|
||||||
|
cfg = new ConfigReader(f);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
f = new YmlMaker(Jobs.getFolder(), "blockOwnerShips.yml");
|
if (cfg == null)
|
||||||
|
return;
|
||||||
|
|
||||||
if (blockOwnerShips.isEmpty() && f.getConfigFile().length() == 0L) {
|
cfg.getC().options().copyDefaults(true);
|
||||||
f.getConfigFile().delete();
|
|
||||||
|
for (BlockOwnerShip ownership : blockOwnerShipsMaterial.values()) {
|
||||||
|
if (ownership.isReassignDisabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
String path = ownership.getType().getPath();
|
||||||
|
|
||||||
f.createNewFile();
|
cfg.getC().set(path, null);
|
||||||
f.saveDefaultConfig();
|
|
||||||
|
|
||||||
if (isReassignDisabled()) {
|
for (Entry<UUID, HashMap<String, blockLoc>> one : ownership.blockOwnerShips.entrySet()) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String path = (type == BlockTypes.FURNACE ? "Furnace"
|
|
||||||
: type == BlockTypes.BLAST_FURNACE ? "BlastFurnace"
|
|
||||||
: type == BlockTypes.BREWING_STAND ? "Brewing" : type == BlockTypes.SMOKER ? "Smoker" : "");
|
|
||||||
f.getConfig().set(path, null);
|
|
||||||
|
|
||||||
for (Entry<UUID, HashMap<String, blockLoc>> one : blockOwnerShips.entrySet()) {
|
|
||||||
StringBuilder full = new StringBuilder();
|
StringBuilder full = new StringBuilder();
|
||||||
|
|
||||||
for (String oneL : one.getValue().keySet()) {
|
for (String oneL : one.getValue().keySet()) {
|
||||||
if (!full.toString().isEmpty())
|
if (!full.toString().isEmpty())
|
||||||
full.append(";");
|
full.append(";");
|
||||||
|
|
||||||
full.append(oneL);
|
full.append(oneL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!full.toString().isEmpty())
|
if (!full.toString().isEmpty())
|
||||||
f.getConfig().set(path + "." + one.getKey().toString(), full.toString());
|
cfg.get(path + "." + one.getKey().toString(), full.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
f.saveConfig();
|
cfg.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isReassignDisabled() {
|
public boolean isReassignDisabled() {
|
||||||
|
@ -6,14 +6,16 @@ import net.Zrips.CMILib.Items.CMIMaterial;
|
|||||||
|
|
||||||
public enum BlockTypes {
|
public enum BlockTypes {
|
||||||
|
|
||||||
BREWING_STAND("BREWING_STAND", "LEGACY_BREWING_STAND"),
|
BREWING_STAND("Brewing", "BREWING_STAND", "LEGACY_BREWING_STAND"),
|
||||||
FURNACE("FURNACE", "LEGACY_BURNING_FURNACE"),
|
FURNACE("Furnace", "FURNACE", "LEGACY_BURNING_FURNACE"),
|
||||||
SMOKER,
|
SMOKER("Smoker"),
|
||||||
BLAST_FURNACE;
|
BLAST_FURNACE("BlastFurnace");
|
||||||
|
|
||||||
private String[] names;
|
private String[] names;
|
||||||
|
private String path = "_";
|
||||||
|
|
||||||
private static HashMap<CMIMaterial, BlockTypes> cache = new HashMap<>();
|
private static HashMap<CMIMaterial, BlockTypes> cache = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
for (CMIMaterial one : CMIMaterial.values()) {
|
for (CMIMaterial one : CMIMaterial.values()) {
|
||||||
for (BlockTypes b : values()) {
|
for (BlockTypes b : values()) {
|
||||||
@ -26,11 +28,13 @@ public enum BlockTypes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockTypes() {
|
BlockTypes(String path) {
|
||||||
|
this.path = path;
|
||||||
names = new String[] { toString() };
|
names = new String[] { toString() };
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockTypes(String... names) {
|
BlockTypes(String path, String... names) {
|
||||||
|
this.path = path;
|
||||||
this.names = names;
|
this.names = names;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,4 +45,8 @@ public enum BlockTypes {
|
|||||||
public static BlockTypes getFromCMIMaterial(CMIMaterial type) {
|
public static BlockTypes getFromCMIMaterial(CMIMaterial type) {
|
||||||
return cache.get(type);
|
return cache.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPath() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user