Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
Added rent template
Browse files Browse the repository at this point in the history
  • Loading branch information
bziemons committed Feb 9, 2014
1 parent c74619e commit 45a77b5
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}
}
} else {
sender.sendMessage(LanguageSupport.instance.getString("not.yet.implemented"));
return false;
}
return true;
Expand Down
29 changes: 19 additions & 10 deletions src/main/java/com/thezorro266/bukkit/srm/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,28 @@ public class Utils {
/**
* Generates a string, which represents the time left until the given time.
*
* @param renttime in seconds
* @param time in seconds
* @return the generated string
*/
public static String getTimeLeft(int renttime) {
renttime -= (int) (System.currentTimeMillis() / 1000);
public static String getTimeLeft(int time) {
return getTimeString(time - (int) (System.currentTimeMillis() / 1000));
}

/**
* Generates a time string for the passed time in seconds.
*
* @param time as seconds
* @return the time representated as string
*/
public static String getTimeString(int time) {
final int days = time / (24 * 60 * 60);
time = time % (24 * 60 * 60);
final int hours = time / (60 * 60);
time = time % (60 * 60);
final int minutes = time / 60;
time = time % (60);
final int seconds = time;

final int days = renttime / (24 * 60 * 60);
renttime = renttime % (24 * 60 * 60);
final int hours = renttime / (60 * 60);
renttime = renttime % (60 * 60);
final int minutes = renttime / 60;
renttime = renttime % (60);
final int seconds = renttime;
StringBuilder sb = new StringBuilder();
if (days > 0) {
sb.append(days);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void clickSign(Player player, SignFactory.Sign sign) {
if (isRegionOwner(player, region)) {
player.sendMessage(LanguageSupport.instance.getString("region.yours"));
} else {
player.sendMessage(LanguageSupport.instance.getString("region.already.sold"));
player.sendMessage(LanguageSupport.instance.getString("region.already.leased"));
}
} else {
// TODO: Player permissions
Expand Down
119 changes: 89 additions & 30 deletions src/main/java/com/thezorro266/bukkit/srm/templates/TemplateRent.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,56 +18,115 @@

package com.thezorro266.bukkit.srm.templates;

import com.thezorro266.bukkit.srm.LanguageSupport;
import com.thezorro266.bukkit.srm.SimpleRegionMarket;
import com.thezorro266.bukkit.srm.Utils;
import com.thezorro266.bukkit.srm.exceptions.ContentSaveException;
import com.thezorro266.bukkit.srm.factories.RegionFactory;
import com.thezorro266.bukkit.srm.factories.SignFactory;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;

import java.text.MessageFormat;

public class TemplateRent extends TemplateLease {
public TemplateRent(ConfigurationSection templateConfigSection) {
super(templateConfigSection);
type = "rent";
}

/*
@Override
public void ownerClicksTakenSign(String world, String region) {
final long newExpiredate = Utils.getEntryLong(this, world, region, "expiredate") + Utils.getEntryLong(this, world, region, "renttime");
final Player owner = Bukkit.getPlayer(Utils.getEntryString(this, world, region, "owner"));
if (Utils.getOptionLong(this, "renttime.max") == -1 || (newExpiredate - System.currentTimeMillis()) < Utils.getOptionLong(this, "renttime.max")) {
if (AlphaRegionMarket.instance.econManager.isEconomy()) {
String account = Utils.getEntryString(this, world, region, "account");
if (account.isEmpty()) {
account = null;
}
final double price = Utils.getEntryDouble(this, world, region, "price");
if (AlphaRegionMarket.instance.econManager.moneyTransaction(Utils.getEntryString(this, world, region, "owner"), account, price)) {
Utils.setEntry(this, world, region, "expiredate", newExpiredate);
tokenManager.updateSigns(this, world, region);
langHandler.playerNormalOut(owner, "PLAYER.REGION.ADDED_RENTTIME", null);
public void clickSign(Player player, SignFactory.Sign sign) {
RegionFactory.Region region = sign.getRegion();
if (isRegionOccupied(region)) {
if (isRegionOwner(player, region)) {
// TODO: Player permissions
// TODO: Player money

int time = (Integer) region.getOptions().get("time");
int newtime = (Integer) region.getOptions().get("renttime") + time;
if (newtime - (int) (System.currentTimeMillis() / 1000) <= maxTime) {
region.getOptions().set("renttime", newtime);

player.sendMessage(MessageFormat.format(LanguageSupport.instance.getString("region.expanded"),
Utils.getTimeString(time)));
} else {
player.sendMessage(LanguageSupport.instance.getString("region.expand.maxtime.reached"));
}
} else {
Utils.setEntry(this, world, region, "expiredate", newExpiredate);
tokenManager.updateSigns(this, world, region);
langHandler.playerNormalOut(owner, "PLAYER.REGION.ADDED_RENTTIME", null);
player.sendMessage(LanguageSupport.instance.getString("region.already.rented"));
}
} else {
langHandler.playerErrorOut(owner, "PLAYER.ERROR.RERENT_TOO_LONG", null);
// TODO: Player permissions
// TODO: Player money
clearRegion(region);
if (buyerIsOwner) {
setRegionOwners(region, new OfflinePlayer[] { player });
} else {
setRegionMembers(region, new OfflinePlayer[] { player });
}

int currentSecs = (int) (System.currentTimeMillis() / 1000);
int time = (Integer) region.getOptions().get("time");
region.getOptions().set("renttime", currentSecs + time);

region.getOptions().set("owner", player.getName());
setRegionOccupied(region, true);

try {
SimpleRegionMarket.getInstance().getTemplateManager().saveRegion(region);
} catch (ContentSaveException e) {
player.sendMessage(ChatColor.RED + LanguageSupport.instance.getString("region.save.problem.player"));
SimpleRegionMarket
.getInstance()
.getLogger()
.severe(MessageFormat.format(LanguageSupport.instance.getString("region.save.problem.console"),
region.getName()));
SimpleRegionMarket.getInstance().printError(e);
}

player.sendMessage(LanguageSupport.instance.getString("region.new.owner"));
}
region.updateSigns();
}

@Override
public void schedule(String world, String region) {
if (Utils.getEntryBoolean(this, world, region, "taken")) {
if (Utils.getEntryLong(this, world, region, "expiredate") < System.currentTimeMillis()) {
if (Utils.getEntry(this, world, region, "owner") != null) {
final Player player = Bukkit.getPlayer(Utils.getEntryString(this, world, region, "owner"));
if (player != null) {
final ArrayList<String> list = new ArrayList<String>();
list.add(region);
langHandler.playerNormalOut(player, "PLAYER.REGION.EXPIRED", list);
public void schedule() {
synchronized (regionList) {
for (RegionFactory.Region region : regionList) {
if (isRegionOccupied(region)) {
int currentSecs = (int) (System.currentTimeMillis() / 1000);

if (currentSecs > (Integer) region.getOptions().get("renttime")) {
OfflinePlayer op = Bukkit.getOfflinePlayer((String) region.getOptions().get("owner"));

clearRegion(region);

if (op.isOnline()) {
op.getPlayer().sendMessage(
MessageFormat.format(
LanguageSupport.instance.getString("region.lease.expired"),
region.getName()));
}

try {
SimpleRegionMarket.getInstance().getTemplateManager().saveRegion(region);
} catch (ContentSaveException e) {
SimpleRegionMarket
.getInstance()
.getLogger()
.severe(MessageFormat.format(
LanguageSupport.instance.getString("region.save.problem.console"),
region.getName()));
SimpleRegionMarket.getInstance().printError(e);
}
}
region.updateSigns();
}
releaseRegion(world, region);
}
}
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,11 @@ public void regionCommand(Region region, CommandSender sender, String[] args) {
SimpleRegionMarket.getInstance().printError(e);
}
} else {
sender.sendMessage(LanguageSupport.instance.getString("not.yet.implemented"));
// TODO: region command help
}
} else {
sender.sendMessage(LanguageSupport.instance.getString("not.yet.implemented"));
// TODO: region command help
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/lang/srm_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ region.in.world.not.found=Region {0} was not found in world {1}.
region.not.found=Region {0} was not found in any world.
region.yours=This is your region.
region.already.sold=This region is already sold.
region.already.leased=This region is already leased.
region.already.rented=This region is already rented.
region.new.owner=You're now the owner of this region
sign.break.not.allowed=You're not allowed to break this sign
sign.make.region.not.found=Could not find the region.
Expand All @@ -68,4 +70,6 @@ region.schematic.load.failure=Could not load region schematic {0}
region.schematic.save.successful=Successfully saved schematic of region {0}
region.specify=You must specify a region\!
vault.economy.problem=Vault economy problem\: {0}
permission.unknown.command.sender=I dont know the command sender {0}
permission.unknown.command.sender=I dont know the command sender {0}
region.expanded=Your region got expanded by {0}
region.expand.maxtime.reached=You are not allowed to expand the rent-time anymore.
6 changes: 5 additions & 1 deletion src/main/resources/lang/srm_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ region.in.world.not.found=Region {0} was not found in world {1}.
region.not.found=Region {0} was not found in any world.
region.yours=This is your region.
region.already.sold=This region is already sold.
region.already.leased=This region is already leased.
region.already.rented=This region is already rented.
region.new.owner=You're now the owner of this region
sign.break.not.allowed=You're not allowed to break this sign
sign.make.region.not.found=Could not find the region.
Expand All @@ -68,4 +70,6 @@ region.schematic.load.failure=Could not load region schematic {0}
region.schematic.save.successful=Successfully saved schematic of region {0}
region.specify=You must specify a region\!
vault.economy.problem=Vault economy problem\: {0}
permission.unknown.command.sender=I dont know the command sender {0}
permission.unknown.command.sender=I dont know the command sender {0}
region.expanded=Your region got expanded by {0}
region.expand.maxtime.reached=You are not allowed to expand the rent-time anymore.

0 comments on commit 45a77b5

Please sign in to comment.