Signs now update quicker when updated, as opposed to waiting for the

next update
This commit is contained in:
Famous_Longwing 2024-02-19 01:05:47 -05:00
parent 7ed6a0674b
commit f1b20038c5
3 changed files with 32 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import java.util.regex.Pattern;
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;
@ -29,7 +30,6 @@ public class REListener implements Listener
pm.registerEvents(this, RealEstate.instance);
//RealEstate.instance.getCommand("re").setExecutor(this);
}
@EventHandler
public void onSignChange(SignChangeEvent event)
{
@ -40,7 +40,6 @@ public class REListener implements Listener
{
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
{
@ -259,6 +258,7 @@ public class REListener implements Listener
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
{
@ -364,6 +364,17 @@ public class REListener implements Listener
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);
}
});
}
}

View File

@ -7,6 +7,8 @@ import java.time.LocalTime;
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;

View File

@ -175,7 +175,23 @@ public class TransactionsStore
}
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) ||
@ -227,6 +243,7 @@ public class TransactionsStore
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();