Skip to content

Commit

Permalink
Signs now update quicker when updated, as opposed to waiting for the
Browse files Browse the repository at this point in the history
next update
  • Loading branch information
Famous_Longwing authored and Famous_Longwing committed Feb 19, 2024
1 parent 7ed6a06 commit f1b2003
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/me/EtienneDx/RealEstate/REListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.block.Sign;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -29,7 +30,6 @@ void registerEvents()
pm.registerEvents(this, RealEstate.instance);
//RealEstate.instance.getCommand("re").setExecutor(this);
}

@EventHandler
public void onSignChange(SignChangeEvent event)
{
Expand All @@ -40,7 +40,6 @@ public void onSignChange(SignChangeEvent event)
{
Player player = event.getPlayer();
Location loc = event.getBlock().getLocation();

Claim claim = GriefPrevention.instance.dataStore.getClaimAt(loc, false, null);
if(claim == null)// must have something to sell
{
Expand Down Expand Up @@ -259,6 +258,7 @@ else if(type.equals("claim") && !player.getUniqueId().equals(claim.ownerID))// o
event.setCancelled(true);
RealEstate.transactionsStore.rent(claim, player, price, event.getBlock().getLocation(), duration, rentPeriods,
RealEstate.instance.config.cfgRentKeywords.contains(event.getLine(0).toLowerCase()));

}
else if(RealEstate.instance.config.cfgLeaseKeywords.contains(event.getLine(0).toLowerCase()))// we want to rent it
{
Expand Down Expand Up @@ -364,6 +364,17 @@ else if(type.equals("claim") && !player.getUniqueId().equals(claim.ownerID))// o
event.setCancelled(true);
RealEstate.transactionsStore.lease(claim, player, price, event.getBlock().getLocation(), frequency, paymentsCount);
}
RealEstate.instance.getServer().getScheduler().scheduleSyncDelayedTask(RealEstate.instance, new Runnable() {
@Override
public void run() {
//in short we want to have the transaction update here...
//
Transaction tr = RealEstate.transactionsStore.getTransaction(claim);
RealEstate.transactionsStore.kickTransaction(tr);

}

});
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.util.Map;


import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
Expand Down
17 changes: 17 additions & 0 deletions src/me/EtienneDx/RealEstate/Transactions/TransactionsStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,23 @@ public void cancelTransaction(Transaction tr)
}
saveData();
}
public void kickTransaction (Transaction tr)
{
if(tr instanceof ClaimSell)
{
tr.update();
}
if(tr instanceof ClaimRent)
{
tr.update();
}
if(tr instanceof ClaimLease)
{
tr.update();
}


}
public boolean canCancelTransaction(Transaction tr)
{
return tr instanceof ClaimSell || (tr instanceof ClaimRent && ((ClaimRent)tr).buyer == null) ||
Expand Down Expand Up @@ -227,6 +243,7 @@ public void sell(Claim claim, Player player, double price, Location sign)

public void rent(Claim claim, Player player, double price, Location sign, int duration, int rentPeriods, boolean buildTrust)
{

ClaimRent cr = new ClaimRent(claim, claim.isAdminClaim() ? null : player, price, sign, duration, rentPeriods, buildTrust);
claimRent.put(claim.getID().toString(), cr);
cr.update();
Expand Down

0 comments on commit f1b2003

Please sign in to comment.