Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock committed Oct 17, 2024
2 parents 98389d3 + 772b517 commit da924a9
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 167 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>Jobs</groupId>
<artifactId>jobs</artifactId>
<version>5.2.4.4</version>
<version>5.2.4.5</version>
<name>Jobs</name>
<url>http://maven.apache.org</url>

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/gamingmesh/jobs/Jobs.java
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ public void onDisable() {
if (dao != null && Jobs.getGeneralConfigManager().ExploreSaveIntoDatabase)
dao.saveExplore();

blockOwnerShipsMaterial.values().forEach(BlockOwnerShip::save);
BlockOwnerShip.save(blockOwnerShipsMaterial);

if (saveTask != null)
saveTask.shutdown();
Expand Down Expand Up @@ -1047,9 +1047,8 @@ public static void action(JobsPlayer jPlayer, ActionInfo info, Block block, Enti
List<JobProgression> progression = jPlayer.getJobProgression();
int numjobs = progression.size();

if (!Jobs.getGCManager().useBlockProtectionBlockTracker && !Jobs.getExploitManager().isProtectionValidAddIfNotExists(jPlayer, info, block, true)) {
if (!Jobs.getGCManager().useBlockProtectionBlockTracker && !Jobs.getExploitManager().isProtectionValidAddIfNotExists(jPlayer, info, block, true))
return;
}

// no job
if (numjobs == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import java.util.UUID;
import java.util.WeakHashMap;

import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.commands.Cmd;
import com.gamingmesh.jobs.commands.JobsCommands;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.container.blockOwnerShip.BlockTypes;
import com.gamingmesh.jobs.i18n.Language;
Expand Down Expand Up @@ -65,8 +67,11 @@ public Boolean perform(Jobs plugin, final CommandSender sender, final String[] a
}
}

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));

Bukkit.dispatchCommand(sender, JobsCommands.LABEL + " " + ownedblocks.class.getSimpleName() + (sender.getName().equals(jPlayer.getName()) ? "" : jPlayer.getName()));

return true;
}
}
17 changes: 9 additions & 8 deletions src/main/java/com/gamingmesh/jobs/config/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;

Expand Down Expand Up @@ -410,7 +411,7 @@ private void updateExampleFile() {
cfg.addComment(pt + ".Brew", "Brewing miscellaneous items");
generate(cfg, pt + ".Brew.nether_stalk");
generate(cfg, pt + ".Brew.redstone");

cfg.addComment(pt + ".Brush", "Brushing blocks and getting items from them");
generate(cfg, pt + ".Brush.suspicious_sand");
generate(cfg, pt + ".Brush.suspicious_gravel");
Expand Down Expand Up @@ -810,10 +811,10 @@ public KeyValues getKeyValue(String myKey, ActionType actionType, String jobName

Jobs.getExploreManager().setExploreEnabled();
Jobs.getExploreManager().setPlayerAmount(amount);

Jobs.getChunkExplorationManager().setExploreEnabled();
Jobs.getChunkExplorationManager().setPlayerAmount(amount);
Jobs.getChunkExplorationManager().setPlayerAmount(amount);

} else if (actionType == ActionType.CRAFT) {
if (myKey.startsWith("!")) {
type = myKey.substring(1, myKey.length());
Expand All @@ -840,12 +841,12 @@ public KeyValues getKeyValue(String myKey, ActionType actionType, String jobName
meta = "ALL";
// case for ":all" identifier
type = (actionType == ActionType.SHEAR && myKey.startsWith("color")) ? "color" : CMIMaterial.getGeneralMaterialName(type);

CMIEntityType entity = CMIEntityType.get(type);
if (entity != null) {
type = entity.toString();
}
type = entity.toString();
}

}

if (actionType == ActionType.TNTBREAK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ public boolean isProtectionValidAddIfNotExists(JobsPlayer player, ActionInfo inf
if (exploitProtection.getProtectedUntil() != 0) {
long time = exploitProtection.getProtectedUntil();

if (time == -1L) {
remove(block);
return false;
}

if (time < System.currentTimeMillis()) {
remove(block);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,17 +871,18 @@ private void loadGeneralSettings() {
FurnacesMaxDefault = c.get("ExploitProtections.Furnaces.MaxDefaultAvailable", 20);

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);

SmokerReassign = c.get("ExploitProtections.Smokers.Reassign", false);
SmokerReassign = c.get("ExploitProtections.Smokers.Reassign", true);
SmokersMaxDefault = c.get("ExploitProtections.Smokers.MaxDefaultAvailable", 15);
}
}

c.addComment("ExploitProtections.BrewingStands.Reassign",
"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");
BrewingStandsReassign = c.get("ExploitProtections.BrewingStands.Reassign", true);

c.addComment("ExploitProtections.BrewingStands.MaxDefaultAvailable",
"Defines max available brewing stands each player can have to get paid from",
"Set to 0 if you want to disable this limitation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ else if (curr.equals(CurrencyType.EXP))
c.get("command.clearownership.help.info", "Clear block ownership");
c.get("command.clearownership.help.args", "[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.skipquest.help.info", "Skip defined quest and get new one");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Map.Entry;
import java.util.UUID;

import com.gamingmesh.jobs.api.JobsBlockOwnershipRegisterEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
Expand All @@ -19,12 +18,15 @@
import org.bukkit.metadata.MetadataValue;

import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.api.JobsBlockOwnershipRegisterEvent;
import com.gamingmesh.jobs.config.YmlMaker;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.blockLoc;

import net.Zrips.CMILib.Container.CMILocation;
import net.Zrips.CMILib.FileHandler.ConfigReader;
import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.Logs.CMIDebug;
import net.Zrips.CMILib.Messages.CMIMessages;

public class BlockOwnerShip {
Expand Down Expand Up @@ -127,10 +129,10 @@ public ownershipFeedback register(Player player, Block block) {

if (ownerUUID != null && !ownerUUID.equals(player.getUniqueId())) {
if (Jobs.getGCManager().blockOwnershipTakeOver) {

if (Jobs.getPermissionManager().hasPermission(jPlayer, "jobs.noownershiptakeover"))
return ownershipFeedback.invalid;

// Removing ownership to record new player
this.remove(ownerUUID, CMILocation.toString(block.getLocation(), ":", true, true));
block.removeMetadata(metadataName, plugin);
Expand Down Expand Up @@ -290,8 +292,9 @@ public int clear(UUID uuid) {

public int remove(UUID uuid, String location) {
HashMap<String, blockLoc> ls = blockOwnerShips.get(uuid);
int ret = 0;
if (ls == null)
return 0;
return ret;

for (Entry<String, blockLoc> one : new HashMap<String, blockLoc>(ls).entrySet()) {

Expand All @@ -303,11 +306,13 @@ public int remove(UUID uuid, String location) {
ls.remove(one.getKey());

Map<String, UUID> oldRecord = ownerMapByLocation.get(one.getValue().getWorldName());
if (oldRecord != null)
if (oldRecord != null) {
oldRecord.remove(one.getValue().toVectorString());
ret++;
}
}

return 1;
return ret;
}

public List<MetadataValue> getBlockMetadatas(Block block) {
Expand All @@ -320,34 +325,12 @@ public int getTotal(UUID uuid) {
}

public void load() {
YmlMaker f = new YmlMaker(Jobs.getFolder(), "furnaceBrewingStands.yml");
YmlMaker f2 = new YmlMaker(Jobs.getFolder(), "blockOwnerShips.yml");
if (!f.exists() && !f2.exists())
return;

if (f.exists()) {
f.getConfigFile().renameTo(f2.getConfigFile());
}

f = f2;
YmlMaker f = new YmlMaker(Jobs.getFolder(), "blockOwnerShips.yml");
if (!f.exists())
return;

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;
}
String path = type.getPath();

if (isReassignDisabled())
return;
Expand Down Expand Up @@ -375,17 +358,24 @@ public void load() {
}

HashMap<String, blockLoc> blist = new HashMap<String, blockLoc>();
boolean informed = false;
for (String oneL : ls) {
blockLoc bl = new blockLoc(oneL);
CMILocation cmil = CMILocation.fromString(oneL, ":");
try {
blockLoc bl = new blockLoc(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>());
oldRecord.put(bl.toVectorString(), uuid);
ownerMapByLocation.put(bl.getWorldName(), oldRecord);
Map<String, UUID> oldRecord = ownerMapByLocation.getOrDefault(bl.getWorldName(), new HashMap<String, UUID>());
oldRecord.put(bl.toVectorString(), uuid);
ownerMapByLocation.put(bl.getWorldName(), oldRecord);

total++;
total++;

} catch (Throwable e) {
if (!informed)
e.printStackTrace();
informed = true;
}
}

if (!blist.isEmpty()) {
Expand All @@ -398,46 +388,45 @@ public void load() {
}
}

public void save() {
YmlMaker f = new YmlMaker(Jobs.getFolder(), "furnaceBrewingStands.yml");
if (f.exists()) {
f.getConfigFile().renameTo(new File(Jobs.getFolder(), "blockOwnerShips.yml"));
}
public static void save(HashMap<CMIMaterial, BlockOwnerShip> blockOwnerShipsMaterial) {

f = new YmlMaker(Jobs.getFolder(), "blockOwnerShips.yml");
File f = new File(Jobs.getInstance().getDataFolder(), "blockOwnerShips.yml");

if (blockOwnerShips.isEmpty() && f.getConfigFile().length() == 0L) {
f.getConfigFile().delete();
return;
ConfigReader cfg = null;
try {
cfg = new ConfigReader(f);
} catch (Exception e) {
e.printStackTrace();
}

f.createNewFile();
f.saveDefaultConfig();

if (isReassignDisabled()) {
if (cfg == null)
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);
cfg.getC().options().copyDefaults(true);

for (Entry<UUID, HashMap<String, blockLoc>> one : blockOwnerShips.entrySet()) {
StringBuilder full = new StringBuilder();
for (BlockOwnerShip ownership : blockOwnerShipsMaterial.values()) {
if (ownership.isReassignDisabled()) {
return;
}
String path = ownership.getType().getPath();

for (String oneL : one.getValue().keySet()) {
if (!full.toString().isEmpty())
full.append(";");
cfg.getC().set(path, null);

full.append(oneL);
}
for (Entry<UUID, HashMap<String, blockLoc>> one : ownership.blockOwnerShips.entrySet()) {
StringBuilder full = new StringBuilder();

if (!full.toString().isEmpty())
f.getConfig().set(path + "." + one.getKey().toString(), full.toString());
for (String oneL : one.getValue().keySet()) {
if (!full.toString().isEmpty())
full.append(";");
full.append(oneL);
}

if (!full.toString().isEmpty())
cfg.get(path + "." + one.getKey().toString(), full.toString());
}
}

f.saveConfig();
cfg.save();
}

public boolean isReassignDisabled() {
Expand Down
Loading

0 comments on commit da924a9

Please sign in to comment.