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:
Thijs Wiefferink 2014-11-15 21:57:26 +01:00
parent 5eae75fef1
commit a6f5a2eb5e
8 changed files with 142 additions and 8 deletions

View File

@ -36,7 +36,7 @@ general:
rent: rent:
## The default price of a renting region ## The default price of a renting region
price: 1000 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' 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) ## 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 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 ## 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 ## -1 means never, 1440 is one day, 43200 is one month, 525600 is one year
inactiveTimeUntilUnrent: -1 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 │ # │ BUY: Options for buy regions │

View File

@ -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-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-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-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-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" buy-noPermission: "You don't have permission to buy a region"

View File

@ -128,6 +128,7 @@ public final class AreaShop extends JavaPlugin {
this.getServer().getPluginManager().registerEvents(new SignChangeListener(this), this); this.getServer().getPluginManager().registerEvents(new SignChangeListener(this), this);
this.getServer().getPluginManager().registerEvents(new SignBreakListener(this), this); this.getServer().getPluginManager().registerEvents(new SignBreakListener(this), this);
this.getServer().getPluginManager().registerEvents(new SignClickListener(this), this); this.getServer().getPluginManager().registerEvents(new SignClickListener(this), this);
this.getServer().getPluginManager().registerEvents(new PlayerLoginListener(this), this);
setupTasks(); setupTasks();
@ -148,14 +149,17 @@ public final class AreaShop extends JavaPlugin {
* Called on shutdown or reload of the server * Called on shutdown or reload of the server
*/ */
public void onDisable() { public void onDisable() {
fileManager.saveRequiredFiles(); fileManager.saveRequiredFilesAtOnce();
Bukkit.getServer().getScheduler().cancelTasks(this); Bukkit.getServer().getScheduler().cancelTasks(this);
/* set variables to null to prevent memory leaks */ /* set variables to null to prevent memory leaks */
worldGuard = null; worldGuard = null;
worldEdit = null;
economy = null; economy = null;
fileManager = null; fileManager = null;
languageManager = null; languageManager = null;
commandManager = null;
chatprefix = null;
debug = false; debug = false;
} }

View File

@ -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() { public void saveRequiredFiles() {
if(isSaveGroupsRequired()) { if(isSaveGroupsRequired()) {
@ -493,6 +493,20 @@ public class FileManager {
}.runTaskTimer(plugin, 1, 1); }.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() { public String getRegionFolder() {
return regionsPath; return regionsPath;
} }

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

View File

@ -35,6 +35,9 @@ public final class SignBreakListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onSignBreak(BlockBreakEvent event) { public void onSignBreak(BlockBreakEvent event) {
if(event.isCancelled()) {
return;
}
Block block = event.getBlock(); Block block = event.getBlock();
/* Check if it is a sign */ /* Check if it is a sign */
if(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) { if(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) {

View File

@ -39,8 +39,11 @@ public final class SignChangeListener implements Listener {
* Called when a sign is changed * Called when a sign is changed
* @param event The event * @param event The event
*/ */
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.MONITOR)
public void onSignChange(SignChangeEvent event) { public void onSignChange(SignChangeEvent event) {
if(event.isCancelled()) {
return;
}
Player player = event.getPlayer(); Player player = event.getPlayer();
// Check if the sign is meant for this plugin // Check if the sign is meant for this plugin

View File

@ -204,8 +204,18 @@ public class RentRegion extends GeneralRegion {
* @return The duration in milliseconds of 1 rent period * @return The duration in milliseconds of 1 rent period
*/ */
public long getDuration() { public long getDuration() {
/* Get the time until the region will be rented */ return durationStringToLong(getDurationString());
String duration = 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 calendar = Calendar.getInstance();
calendar.setTimeInMillis(0); calendar.setTimeInMillis(0);
@ -216,7 +226,10 @@ public class RentRegion extends GeneralRegion {
ArrayList<String> years = new ArrayList<String>(plugin.getConfig().getStringList("years")); ArrayList<String> years = new ArrayList<String>(plugin.getConfig().getStringList("years"));
String durationString = duration.substring(duration.indexOf(' ')+1, duration.length()); 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)) { if(minutes.contains(durationString)) {
calendar.add(Calendar.MINUTE, durationInt); calendar.add(Calendar.MINUTE, durationInt);