Skip to content

Commit

Permalink
Fix: Methods not running sync
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueMB committed Aug 18, 2024
1 parent 4630013 commit ead087d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 34 deletions.
15 changes: 5 additions & 10 deletions src/main/java/me/truemb/rentit/filemanager/SignFileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.block.Block;
import org.bukkit.configuration.file.YamlConfiguration;

import me.truemb.rentit.enums.RentTypes;
Expand Down Expand Up @@ -97,11 +96,11 @@ public int getIdFromSign(Location loc, RentTypes type) {
return cfg.getInt(type.toString() + ".IDs." + locS);
}

public List<Sign> getSigns(RentTypes type, int id) {
public List<Block> getSigns(RentTypes type, int id) {

YamlConfiguration cfg = this.getConfig();

List<Sign> finalSigns = new ArrayList<>();
List<Block> finalSigns = new ArrayList<>();

List<String> signs = new ArrayList<>();
if(cfg.isSet(type.toString() + "." + String.valueOf(id)))
Expand All @@ -115,12 +114,8 @@ public List<Sign> getSigns(RentTypes type, int id) {
int z = Integer.parseInt(array[3]);

World w = Bukkit.getWorld(worldName);
BlockState state = w.getBlockAt(x, y, z).getState();

if(state instanceof Sign) {
Sign sign = (Sign) state;
finalSigns.add(sign);
}
Location loc = new Location(w, x, y, z);
finalSigns.add(w.getBlockAt(loc));
});

return finalSigns;
Expand Down
38 changes: 22 additions & 16 deletions src/main/java/me/truemb/rentit/runnable/PaymentRunnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.function.Consumer;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;

Expand Down Expand Up @@ -125,25 +126,30 @@ public void accept(Void t) {
rentHandler.setAutoPayment(autoPaymentDefault);
this.instance.getShopsSQL().reset(shopId, autoPaymentDefault);
this.instance.getPermissionsSQL().reset(RentTypes.SHOP, shopId);

//TODO No Sync Scheduler needed? If needed, then should be done in method.
this.instance.getShopCacheFileManager().createShopBackup(uuid, shopId);

//NPC has to be in the shop, just use that location for folia
this.instance.getThreadHandler().runTaskSync(this.instance.getNPCFileManager().getNPCLocForShop(shopId), (tt) -> {
this.instance.getShopCacheFileManager().createShopBackup(uuid, shopId);
});
rentHandler.reset();

//REMOVE NPC
if(!this.instance.manageFile().getBoolean("Options.disableNPC")) {
if(this.instance.getNpcUtils() != null) {
if(this.instance.getNpcUtils().isNPCSpawned(shopId))
this.instance.getNpcUtils().despawnNPC(shopId);
}else {
if(this.instance.getVillagerUtils().isVillagerSpawned(shopId))
this.instance.getVillagerUtils().destroyVillager(shopId);
}
Location loc = this.instance.getNPCFileManager().getNPCLocForShop(shopId);
this.instance.getThreadHandler().runTaskSync(loc, (tt) -> {
if(this.instance.getNpcUtils() != null) {
if(this.instance.getNpcUtils().isNPCSpawned(shopId))
this.instance.getNpcUtils().despawnNPC(shopId);
}else {
if(this.instance.getVillagerUtils().isVillagerSpawned(shopId))
this.instance.getVillagerUtils().destroyVillager(shopId);
}
});
}

BlockVector3 min = instance.getAreaFileManager().getMinBlockpoint(RentTypes.SHOP, shopId);
BlockVector3 max = instance.getAreaFileManager().getMaxBlockpoint(RentTypes.SHOP, shopId);
World world = instance.getAreaFileManager().getWorldFromArea(RentTypes.SHOP, shopId);
BlockVector3 min = this.instance.getAreaFileManager().getMinBlockpoint(RentTypes.SHOP, shopId);
BlockVector3 max = this.instance.getAreaFileManager().getMaxBlockpoint(RentTypes.SHOP, shopId);
World world = this.instance.getAreaFileManager().getWorldFromArea(RentTypes.SHOP, shopId);

this.instance.getBackupManager().paste(RentTypes.SHOP, shopId, min, max, world, false);
this.instance.getAdvancedChestsUtils().pasteChestsInArea(RentTypes.SHOP, shopId);
Expand Down Expand Up @@ -199,9 +205,9 @@ public void accept(Void t) {

//TODO No Sync Scheduler needed? If needed, then should be done in method.
rentHandler.reset();
BlockVector3 min = instance.getAreaFileManager().getMinBlockpoint(RentTypes.HOTEL, hotelId);
BlockVector3 max = instance.getAreaFileManager().getMaxBlockpoint(RentTypes.HOTEL, hotelId);
World world = instance.getAreaFileManager().getWorldFromArea(RentTypes.HOTEL, hotelId);
BlockVector3 min = this.instance.getAreaFileManager().getMinBlockpoint(RentTypes.HOTEL, hotelId);
BlockVector3 max = this.instance.getAreaFileManager().getMaxBlockpoint(RentTypes.HOTEL, hotelId);
World world = this.instance.getAreaFileManager().getWorldFromArea(RentTypes.HOTEL, hotelId);

this.instance.getBackupManager().paste(RentTypes.HOTEL, hotelId, min, max, world, false);
this.instance.getAdvancedChestsUtils().pasteChestsInArea(RentTypes.HOTEL, hotelId);
Expand Down
24 changes: 16 additions & 8 deletions src/main/java/me/truemb/rentit/utils/UtilMethodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.apache.commons.lang.StringUtils;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -306,10 +308,10 @@ public boolean isSettingActive(UUID uuid, RentTypes type, int id, Settings setti

public void deleteSigns(RentTypes type, int id) {

List<Sign> list = this.instance.getSignFileManager().getSigns(type, id);
List<Block> list = this.instance.getSignFileManager().getSigns(type, id);

list.forEach(signs -> {
signs.getBlock().breakNaturally();
list.forEach(blocks -> {
blocks.breakNaturally();
});
this.instance.getSignFileManager().clearSigns(type, id);
}
Expand Down Expand Up @@ -346,11 +348,17 @@ else if(owner == null)

public void updateSign(RentTypes type, int id, String owner, String time, double price, int size) {

List<Sign> list = this.instance.getSignFileManager().getSigns(type, id);

list.forEach(signs -> {
this.updateSign(type, id, signs, owner, time, price, size);
});
List<Block> list = this.instance.getSignFileManager().getSigns(type, id);
for(Block b : list) {
this.instance.getThreadHandler().runTaskSync(b.getLocation(), (t) -> {
BlockState state = b.getState();

if(state instanceof Sign) {
Sign sign = (Sign) state;
this.updateSign(type, id, sign, owner, time, price, size);
}
});
}
}

public void updateAllSigns(RentTypes type, int catId) {
Expand Down

0 comments on commit ead087d

Please sign in to comment.