mirror of
https://github.com/NLthijs48/AreaShop.git
synced 2024-11-23 10:45:53 +01:00
Expire warning on login for players that rent regions + bugfixes
An option has been added to show a warning to players when their rent almost runs out on login (so when they login they get a message for each region that almost runs out, that means lower timeleft than the 'warningOnLoginTime' setting). Also a bug with schematic restoring has been fixed and some other minor changes done.
This commit is contained in:
parent
5eae75fef1
commit
a6f5a2eb5e
@ -36,7 +36,7 @@ general:
|
||||
rent:
|
||||
## The default price of a renting region
|
||||
price: 1000
|
||||
## The default duration of a renting region
|
||||
## The default duration of a renting region, you can find all time indicators in config.yml below the RENTING header
|
||||
duration: '1 day'
|
||||
## The percentage of the renting price you get back if you unrent the region (price of time left will be multiplied by this/100)
|
||||
moneyBack: 100
|
||||
@ -48,6 +48,9 @@ rent:
|
||||
## Automatically unrent the region after the specified number of minutes between the last login time of the renter and the current time
|
||||
## -1 means never, 1440 is one day, 43200 is one month, 525600 is one year
|
||||
inactiveTimeUntilUnrent: -1
|
||||
## If a region of a player has less then this time left when he joins the server he will get a warning
|
||||
## You can find all time indicators in config.yml below the RENTING header, change to '' to disable
|
||||
warningOnLoginTime: '1 day'
|
||||
|
||||
# ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
|
||||
# │ BUY: Options for buy regions │
|
||||
|
@ -67,6 +67,7 @@ rent-maxExtends: "You cannot extend this rent anymore (the maximum is %0% times)
|
||||
rent-maxRentTime: "You cannot rent this region more time in advance, the maximum time is %0% minutes and you have currently rented it for %1% minutes"
|
||||
rent-restrictedToWorld: "You need to be in the '%0%' world to rent this region (you are in '%1%')"
|
||||
rent-restrictedToRegion: "You need to be inside '%0%' to rent it"
|
||||
rent-loginExpireWarning: "Your region %region% has only %timeleft% left, be sure to extend it if you want to keep it"
|
||||
|
||||
buy-help: "/as buy [regionname], the region you stand in will be used if not specified"
|
||||
buy-noPermission: "You don't have permission to buy a region"
|
||||
|
@ -128,6 +128,7 @@ public final class AreaShop extends JavaPlugin {
|
||||
this.getServer().getPluginManager().registerEvents(new SignChangeListener(this), this);
|
||||
this.getServer().getPluginManager().registerEvents(new SignBreakListener(this), this);
|
||||
this.getServer().getPluginManager().registerEvents(new SignClickListener(this), this);
|
||||
this.getServer().getPluginManager().registerEvents(new PlayerLoginListener(this), this);
|
||||
|
||||
setupTasks();
|
||||
|
||||
@ -148,14 +149,17 @@ public final class AreaShop extends JavaPlugin {
|
||||
* Called on shutdown or reload of the server
|
||||
*/
|
||||
public void onDisable() {
|
||||
fileManager.saveRequiredFiles();
|
||||
fileManager.saveRequiredFilesAtOnce();
|
||||
Bukkit.getServer().getScheduler().cancelTasks(this);
|
||||
|
||||
/* set variables to null to prevent memory leaks */
|
||||
worldGuard = null;
|
||||
worldEdit = null;
|
||||
economy = null;
|
||||
fileManager = null;
|
||||
languageManager = null;
|
||||
commandManager = null;
|
||||
chatprefix = null;
|
||||
debug = false;
|
||||
}
|
||||
|
||||
|
@ -465,7 +465,7 @@ public class FileManager {
|
||||
|
||||
|
||||
/**
|
||||
* Save all region related files
|
||||
* Save all region related files spread over time (low load)
|
||||
*/
|
||||
public void saveRequiredFiles() {
|
||||
if(isSaveGroupsRequired()) {
|
||||
@ -493,6 +493,20 @@ public class FileManager {
|
||||
}.runTaskTimer(plugin, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save all region related files directly (only for cases like onDisable())
|
||||
*/
|
||||
public void saveRequiredFilesAtOnce() {
|
||||
if(isSaveGroupsRequired()) {
|
||||
saveGroupsNow();
|
||||
}
|
||||
for(GeneralRegion region : getRegions()) {
|
||||
if(region.isSaveRequired()) {
|
||||
region.saveNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getRegionFolder() {
|
||||
return regionsPath;
|
||||
}
|
||||
|
93
src/nl/evolutioncoding/areashop/PlayerLoginListener.java
Normal file
93
src/nl/evolutioncoding/areashop/PlayerLoginListener.java
Normal file
@ -0,0 +1,93 @@
|
||||
package nl.evolutioncoding.areashop;
|
||||
|
||||
import nl.evolutioncoding.areashop.regions.RentRegion;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* Checks for placement of signs for this plugin
|
||||
* @author NLThijs48
|
||||
*/
|
||||
public final class PlayerLoginListener implements Listener {
|
||||
AreaShop plugin;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param plugin The AreaShop plugin
|
||||
*/
|
||||
public PlayerLoginListener(AreaShop plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a sign is changed
|
||||
* @param event The event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||
if(event.getResult() != Result.ALLOWED) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
|
||||
for(RentRegion region : plugin.getFileManager().getRents()) {
|
||||
if(region.isRenter(player)) {
|
||||
String warningSetting = region.getStringSetting("rent.warningOnLoginTime");
|
||||
if(warningSetting == null || warningSetting.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
long warningTime = region.durationStringToLong(warningSetting);
|
||||
if(region.getTimeLeft() < warningTime) {
|
||||
// Send the warning message later to let it appear after general MOTD messages
|
||||
final Player finalPlayer = player;
|
||||
final AreaShop finalPlugin = plugin;
|
||||
final RentRegion finalRegion = region;
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
finalPlugin.message(finalPlayer, "rent-loginExpireWarning", finalRegion);
|
||||
}
|
||||
}.runTaskLater(plugin, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -35,6 +35,9 @@ public final class SignBreakListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onSignBreak(BlockBreakEvent event) {
|
||||
if(event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Block block = event.getBlock();
|
||||
/* Check if it is a sign */
|
||||
if(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) {
|
||||
|
@ -39,8 +39,11 @@ public final class SignChangeListener implements Listener {
|
||||
* Called when a sign is changed
|
||||
* @param event The event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onSignChange(SignChangeEvent event) {
|
||||
if(event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
|
||||
// Check if the sign is meant for this plugin
|
||||
|
@ -203,9 +203,19 @@ public class RentRegion extends GeneralRegion {
|
||||
* Get the duration of 1 rent period
|
||||
* @return The duration in milliseconds of 1 rent period
|
||||
*/
|
||||
public long getDuration() {
|
||||
/* Get the time until the region will be rented */
|
||||
String duration = getDurationString();
|
||||
public long getDuration() {
|
||||
return durationStringToLong(getDurationString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Methode to tranlate a duration string to a millisecond value
|
||||
* @param duration The duration string
|
||||
* @return The duration in milliseconds translated from the durationstring, or if it is invalid then 0
|
||||
*/
|
||||
public long durationStringToLong(String duration) {
|
||||
if(duration == null) {
|
||||
return 0;
|
||||
}
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(0);
|
||||
|
||||
@ -216,7 +226,10 @@ public class RentRegion extends GeneralRegion {
|
||||
ArrayList<String> years = new ArrayList<String>(plugin.getConfig().getStringList("years"));
|
||||
|
||||
String durationString = duration.substring(duration.indexOf(' ')+1, duration.length());
|
||||
int durationInt = Integer.parseInt(duration.substring(0, duration.indexOf(' ')));
|
||||
int durationInt = 0;
|
||||
try {
|
||||
durationInt = Integer.parseInt(duration.substring(0, duration.indexOf(' ')));
|
||||
} catch(NumberFormatException exception) {}
|
||||
|
||||
if(minutes.contains(durationString)) {
|
||||
calendar.add(Calendar.MINUTE, durationInt);
|
||||
|
Loading…
Reference in New Issue
Block a user