Version 1.0

This commit is contained in:
Thijs Wiefferink 2014-03-21 18:13:24 +01:00
commit d870885454
15 changed files with 2941 additions and 0 deletions

2
AreaShop/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/.project
/.classpath

1
AreaShop/.settings/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/org.eclipse.jdt.core.prefs

1
AreaShop/bin/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/nl

64
AreaShop/config.yml Normal file
View File

@ -0,0 +1,64 @@
##############################################
# config.yml of the AreaShop plugin #
# This plugin has been created by NLThijs48 #
# Check the server minecraft.go-craft.com #
# and then the Prison server for a demo #
##############################################
########## GENERAL ##########
## Chatprefix used for all messages in the chat
chatPrefix: '&2[AreaShop]&r '
## The character used for the prices of regions, for the euro character use '%euro%'
moneyCharacter: '$'
## Enables / disables debug messages in the console, no need to change
debug: false
## The .yml language file that should be used, provided by this plugin: EN, NL
language: EN
## Maximum total amount of rents and buys together
maximumTotal: 1
########## RENTING ##########
## The tag you have to write on the sign for renting a region
rentSign: '[rent]'
## The line that should be placed on the sign when the region is not rented
signRentable: '&2&l[For Rent]'
## The line that should be placed on the sign when the region is rented
signRented: '&4&l[Rented]'
## How much regions a player can rent at the same time, -1 for not limited
maximumRents: 1
## The percentage of the renting price you get back if you unrent the region (price of time left will be multiplied by this/100)
rentMoneyBack: 100
## How much seconds between checking if renting has expired (don't put this to low)
checkDelay: 60
## Flags for the 'For Rent' regions, flags and options to apply when the region is not rented
## All region flags can be used + members, owners, priority and parent.
flagsForRent:
members: -%player%
greeting: '%region% can be rented for %price% per %duration%'
## Flags for the 'Rented' regions, flags and options to apply when the region is rented
## All region flags can be used + members, owners, priority and parent.
flagsRented:
members: +%player%
greeting: '%region% is rented by %player% until %until%'
########## BUYING ##########
## The tag you have to write on the sign for renting a region
buySign: '[buy]'
## The line that should be placed on the sign when the region is not sold
signBuyable: '&2&l[For Sale]'
## The line that should be placed on the sign when the region is sold
signBuyed: '&4&l[Sold]'
## How much regions a player can buy at the same time, -1 for not limited
maximumBuys: 1
## The percentage of the buying price you get back if you sell the region
buyMoneyBack: 100
## Flags for the 'For Sale' regions, flags and options to apply when the region is for sale
## All region flags can be used + members, owners, priority and parent.
flagsForSale:
members: -%player%
greeting: '%region% can be bought for %price%'
## Flags for the 'Sold' regions, flags and options to apply when the region is rented
## All region flags can be used + members, owners, priority and parent.
flagsSold:
members: +%player%
greeting: '%region% is bought by %player%'

116
AreaShop/lang/EN.yml Normal file
View File

@ -0,0 +1,116 @@
###################################################
# English language file for the AreaShop plugin #
###################################################
# Copy this file and change the strings to your #
# favor. Then change the 'language' setting in #
# the config to the filename (excluding .yml) #
###################################################
########## Command strings
total-maximum: "You can't rent and buy more than %0% region(s) in total"
cmd-notValid: "That command is not valid, use '/as help' for info"
cmd-onlyByPlayer: "This command can only be run by a player"
rent-regionNotRentable: "That region is not available for renting"
rent-help: "/as rent <regionname>"
rent-noPermission: "You don't have permission to rent a region"
rent-maximum: "You can't rent more than %0% region(s)"
rent-payError: "Something went wrong with paying, try again later"
rent-rented: "You rented %0% until %1%"
rent-extended: "You extended your rent of %0% until %1%"
rent-extend: "You can extend your rent by rightclicking the sign again or using /rs rent"
rent-lowMoneyExtend: "You don't have enough money to extend the rent (you have %0% and you need %1%)"
rent-lowMoneyRent: "You don't have enough money to rent this region (you have %0% and you need %1%)"
rent-someoneElse: "Someone else already rented this region"
buy-help: "/as buy <regionname>"
buy-noPermission: "You don't have permission to buy a region"
buy-notBuyable: "That region is not available for buying"
buy-maximum: "You can't buy more than %0% region(s)"
buy-payError: "Something went wrong with paying, try again later"
buy-succes: "You succesfully bought %0%"
buy-lowMoney: "You don't have enough money to buy this region (you have %0% and you need %1%)"
buy-yours: "You already own this region"
buy-someoneElse: "Someone else already bought this region"
unrent-help: "/as unrent <regionname>"
unrent-noPermission: "You don't have permission to unrent a region"
unrent-noPermissionOther: "You don't have permission to unrent another region"
unrent-notRegistered: "The region can't be unrent because it is not registered for renting"
unrent-notRented: "The region can't be unrent because it is not rented"
unrent-unrented: "Your region has been unrented"
unrent-other: "The region has been unrented for player %0%"
unrent-expired: "Your rent of %0% has expired"
sell-help: "/as sell <regionname>"
sell-notRegistered: "The region can't be selled because it is not registered for buying"
sell-notBought: "The region can't be selled because it is not someone's property"
sell-sold: "The region has been sold for player %0%"
sell-soldYours: "Your region has been sold"
sell-noPermission: "You don't have permission to sell a region"
sell-noPermissionOther: "You don't have permission to sell another region"
rentsigns-updated: "All signs for renting have been updated"
rentsigns-notUpdated: "Not all signs have been updated, maybe reload fixes it"
rentsgins-noPermission: "You don't have permission to update all rentsigns"
buysigns-updated: "All signs for selling have been updated"
buysigns-notUpdated: "Not all signs have been updated, maybe reload fixes it"
buysigns-noPermission: "You don't have permission to update all buysigns"
rentregions-updated: "All renting regions have been updated"
rentregions-noPermission: "You don't have permission to update all renting regions"
buyregions-updated: "All buying regions have been updated"
buyregions-noPermission: "You don't have permission to update all buying regions"
reload-reloaded: "The config has been reloaded successfully"
reload-noPermission: "You don't have permission to reload the config"
info-help: "/rs info <all|rented|forrent|sold|forsale|player|region>"
info-all-rents: "Regions registered for renting: %0%"
info-all-noRents: "There are no regions registered for renting"
info-all-buys: "Regions registered for buying: %0%"
info-all-noBuys: "There are no regions registered for buying"
info-rented: "Rented regions: %0%"
info-noRented: "No regions are rented"
info-unrented: "Unrented regions: %0%"
info-noUnrented: "All regions are rented"
info-sold: "Sold regions: %0%"
info-noSold: "No regions are sold"
info-forsale: "Regions for sale: %0%"
info-noForsale: "All regions are sold"
info-playerHelp: "/rs info player <name>"
info-playerRents: "Regions rented by %0%: %1%"
info-playerNoRents: "%0% has not rented a region"
info-playerBuys: "Regions bought by %0%: %1%"
info-playerNoBuys: "%0% has not bought a region"
info-regionHelp: "/rs info region <name>"
info-regionNoRenting: "%0% is not registered for renting"
info-regionRenting: "&6Renting details for %0%"
info-regionRentedBy: "Rented by: %0% until %1%"
info-regionNotRented: "Currently not rented"
info-regionBuying: "&6Buying details for %0%"
info-regionNoBuying: "%0% is not registered for buying"
info-regionNotBought: "Currently not sold"
info-regionBoughtBy: "Bought by: %0%"
info-regionSign: "Sign position: world=%0%, X=%1%, Y=%2%, Z=%3%"
info-regionPriceDuration: "Price: %0% for each %1%"
info-regionPrice: "Price: %0%"
help-header: "Help page, commands that you can execute"
help-alias: "Command aliases: /areashop, /as"
help-help: "&6/as help &7-&r Shows this help page"
help-info: "&6/as info &7-&r Get info about current regions"
help-rent: "&6/as rent &7-&r Rent a region or extend your current rent"
help-buy: "&6/as buy &7-&r Buy a region"
help-unrent: "&6/as unrent &7-&r Unrent a region"
help-unrentOwn: "&6/as unrent &7-&r Unrent your own region"
help-sell: "&6/as sell &7-&r Sell a region"
help-sellOwn: "&6/as sell &7-&r Sell your own region"
help-updaterentsigns: "&6/as updaterentsigns &7-&r Update all rent signs"
help-updatebuysigns: "&6/as updatebuysigns &7-&r Update all buy signs"
help-updaterentregions: "&6/as updaterentregions &7-&r Update all rent regions"
help-updatebuyregions: "&6/as updatebuyregions &7-&r Update all buy regions"
help-reload: "&6/as reload &7-&r Reload the config and languages"

116
AreaShop/lang/NL.yml Normal file
View File

@ -0,0 +1,116 @@
###################################################
# Dutch language file for the AreaShop plugin #
###################################################
# Copy this file and change the strings to your #
# favor. Then change the 'language' setting in #
# the config to the filename (excluding .yml) #
###################################################
########## Command strings
total-maximum: "Je kunt niet meer dan %0% gebied(en) in totaal huren en kopen"
cmd-onlyByPlayer: "Dit commando kan alleen door een speler uitgevoert worden"
cmd-notValid: "Dat commando is niet geldig , gebruik '/rs help' voor informatie"
rent-regionNotRentable: "Dat gebied is niet beschikbaar om te huren"
rent-help: "/as rent <gebiednaam>"
rent-noPermission: "Je hebt geen toestemming om een gebied te huren"
rent-maximum: "Je kunt niet meer dan %0% gebied(en) huren"
rent-payError: "Er is iets mis gegaan met betalen, probeer het later opnieuw"
rent-rented: "Je hebt %0% tot %1% gehuurd"
rent-extended: "Je hebt je huur van %0% verlengt tot %1%"
rent-extend: "Je kunt je huur verlengen door opnieuw op het bordje te klikken of gebruik te maken van /rs rent"
rent-lowMoneyExtend: "Je hebt niet genoeg geld om de huur te verlengen (je hebt %0% van de %1%)"
rent-lowMoneyRent: "Je hebt niet genoeg geld om het gebied te huren (je hebt %0% van de %1%)"
rent-someoneElse: "Iemand anders heeft dit gebied al gehuurd"
buy-help: "/as buy <gebiednaam>"
buy-noPermission: "Je hebt geen toestemming om een gebied te kopen"
buy-notBuyable: "Dat gebied is niet beschikbaar om te kopen"
buy-maximum: "Je kunt niet meer dan %0% gebied(en) kopen"
buy-payError: "Er is iets mis gegaan met betalen, probeer het later opnieuw"
buy-succes: "Je hebt %0% succesvol gekocht"
buy-lowMoney: "Je hebt niet genoeg geld om het gebied te kopen (je hebt %0% van de %1%)"
buy-yours: "Je hebt dit gebied al gekocht"
buy-someoneElse: "Iemand anders heeft dit gebied al gekocht"
unrent-help: "/as unrent <gebiednaam>"
unrent-noPermission: "Je hebt geen toestemming om te stoppen met huren"
unrent-noPermissionOther: "Je hebt geen toestemming om iemand anders huur te stoppen"
unrent-notRegistered: "De huur kan niet gestopt worden want het gebied is niet geregistreerd om te huren"
unrent-notRented: "De huur kan niet gestopt worden want het gebied is niet gehuurd"
unrent-unrented: "De huur van je gebied is gestopt"
unrent-other: "De huur voor het gebied is gestopt voor speler %0%"
unrent-expired: "De huur van je gebied %0% is gestopt"
sell-help: "/as sell <gebiednaam>"
sell-notRegistered: "Het gebied kan niet verkocht worden want het staat niet geregistreerd om te kopen"
sell-notBought: "Het gebied kan niet verkocht worden want het is niet gekocht"
sell-sold: "Het gebied is verkocht voor speler %0%"
sell-soldYours: "Je gebied is verkocht"
sell-noPermission: "Je hebt geen toestemming om een gebied te verkopen"
sell-noPermissionOther: "Je hebt geen toestemming om een gebied van iemand anders te verkopen"
rentsigns-updated: "Alle bordjes voor de verhuur zijn geupdate"
rentsigns-notUpdated: "Niet alle bordjes zijn geupdate, een reload zou het op kunnen lossen"
rentsgins-noPermission: "Je hebt geen toestemming om alle verhuur bordjes te updaten"
buysigns-updated: "All bordjes voor de verkoop zijn geupdate"
buysigns-notUpdated: "Niet alle bordjes zijn geupdate, een reload zou het op kunnen lossen"
buysigns-noPermission: "Je hebt geen toestemming om alle verkoop bordjes te updaten"
rentregions-updated: "Alle verhuur gebieden zijn geupdate"
rentregions-noPermission: "Je hebt geen toestemming om de verhuur gebieden te updaten"
buyregions-updated: "Alle verkoop gebieden zijn geupdate"
buyregions-noPermission: "Je hebt geen toestemming om alle verkoop gebieden te updaten"
reload-reloaded: "De config is succesvol opnieuw ingeladen"
reload-noPermission: "Je hebt geen toestemming om de config opnieuw in te laden"
info-help: "/as info <all|rented|forrent|sold|forsale|player|region>"
info-all-rents: "Gebieden geregistreerd voor de verhuur: %0%"
info-all-noRents: "Er zijn geen gebieden geregistreerd voor de verhuur"
info-all-buys: "Gebieden geregistreerd voor de verkoop: %0%"
info-all-noBuys: "Er zijn geen gebieden geregistreerd voor de verkoop"
info-rented: "Verhuurde gebieden: %0%"
info-noRented: "Er zijn geen verhuurde gebieden"
info-unrented: "Gebieden te huur: %0%"
info-noUnrented: "Alle gebieden zijn verhuurd"
info-sold: "Verkochte gebieden: %0%"
info-noSold: "Alle gebieden zijn verkocht"
info-forsale: "Gebieden te koop: %0%"
info-noForsale: "Alle gebieden zijn verkocht"
info-playerHelp: "/rs info player <naam>"
info-playerRents: "Gebieden gehuurd door %0%: %1%"
info-playerNoRents: "%0% heeft geen gebied gehuurd"
info-playerBuys: "Gebieden gekocht door %0%: %1%"
info-playerNoBuys: "%0% heeft geen gebieden gekocht"
info-regionHelp: "/rs info region <naam>"
info-regionNoRenting: "%0% is niet geregistreerd voor verhuur"
info-regionRenting: "&6Huur informatie voor %0%"
info-regionRentedBy: "Gehuurd door: %0% tot %1%"
info-regionNotRented: "Nu niet verhuurd"
info-regionBuying: "&6Verkoop informatie voor %0%"
info-regionNoBuying: "%0% is niet geregistreerd voor verkoop"
info-regionNotBought: "Nu niet verkocht"
info-regionBoughtBy: "Gekocht door: %0%"
info-regionSign: "Plek van het bordje: wereld=%0%, X=%1%, Y=%2%, Z=%3%"
info-regionPriceDuration: "Prijs: %0% voor elke %1%"
info-regionPrice: "Prijs: %0%"
help-header: "Help pagina, commando's die jij kunt uitvoeren"
help-alias: "Commando aliassen: /areashop, /as"
help-help: "&6/as help &7-&r Laat deze help pagina zien"
help-info: "&6/as info &7-&r Vraag informatie over gebieden op"
help-rent: "&6/as rent &7-&r Huur een gebied of verleng de huur"
help-buy: "&6/as buy &7-&r Koop een gebied"
help-unrent: "&6/as unrent &7-&r Stop de huur van een gebied"
help-unrentOwn: "&6/as unrent &7-&r Stop de huur van een eigen gebied"
help-sell: "&6/as sell &7-&r Verkoop een gebied"
help-sellOwn: "&6/as sell &7-&r Verkoop een eigen gebied"
help-updaterentsigns: "&6/as updaterentsigns &7-&r Update alle huur borden"
help-updatebuysigns: "&6/as updatebuysigns &7-&r Update alle koop borden"
help-updaterentregions: "&6/as updaterentregions &7-&r Update alle huur gebieden"
help-updatebuyregions: "&6/as updatebuyregions &7-&r Update alle koop gebieden"
help-reload: "&6/as reload &7-&r Herlaad de config en de taalbestanden"

80
AreaShop/plugin.yml Normal file
View File

@ -0,0 +1,80 @@
name: AreaShop
main: nl.evolutioncoding.AreaShop.AreaShop
version: 1.0
depend: [Vault, WorldGuard]
commands:
AreaShop:
description: For all commands use /as help
usage: /AreaShop or /AS
permission: areashop.help
permission-message: You don't have <permission>
aliases: [as]
permissions:
areashop.*:
description: Give access to all commands of RegionRent
children:
areashop.help: true
areashop.createrent: true
areashop.createbuy: true
areashop.destroyrent: true
areashop.destroybuy: true
areashop.rent: true
areashop.buy: true
areashop.unrent: true
areashop.info: true
areashop.updaterentsigns: true
areashop.updatebuysigns: true
areashop.updaterentregions: true
areashop.updatebuyregions: true
areashop.reload: true
areashop.help:
description: Allows you to see the help pages
default: true
areashop.rent:
description: Allows you to rent a region
default: true
areashop.buy:
description: Allows you to buy a region
default: true
areashop.unrent:
description: Allows you to unrent a specific region
default: op
areashop.unrentown:
description: Allows you to unrent your own region
default: true
areashop.sell:
description: Allows you to sell a specific region
default: op
areashop.sellown:
description: Allows you to sell your own region
default: true
areashop.createrent:
description: Allows you to set up signs for renting regions
default: op
areashop.createbuy:
description: Allows you to set up signs for buying regions
default: op
areashop.destroyrent:
description: Allows you to break signs used for renting regions
default: op
areashop.destroybuy:
description: Allows you to break signs used for renting regions
default: op
areashop.info:
description: Allows you check the status of regions and players
default: true
areashop.updaterentsigns:
description: Allows you to update all rent signs
default: op
areashop.updatebuysigns:
description: Allows you to update all buy signs
default: op
areashop.updaterentregions:
description: Allows you to update all rent regions
default: op
areashop.updatebuyregions:
description: Allows you to update all buy regions
default: op
areashop.reload:
description: Allows you to reload the config
default: op

View File

@ -0,0 +1,448 @@
package nl.evolutioncoding.AreaShop;
import java.util.ArrayList;
import java.util.logging.Logger;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.Configuration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
/**
* Main class for the AreaShop plugin
* @author NLThijs48
*/
public final class AreaShop extends JavaPlugin {
/* General variables */
private WorldGuardPlugin worldGuard = null;
private Economy economy = null;
private ShopManager shopManager = null;
private LanguageManager languageManager = null;
private boolean configOk = false;
private boolean debug = false;
private String chatprefix = null;
/* Folder where the language files will be stored */
public final String languageFolder = "lang";
/* Euro tag for in the config */
public final String currencyEuro = "%euro%";
/* Keys for adding things to the hashmap */
public final String keyWorld = "world";
public final String keyX = "x";
public final String keyY = "y";
public final String keyZ = "z";
public final String keyDuration = "duration";
public final String keyPrice = "price";
public final String keyPlayer = "player";
public final String keyRentedUntil = "rented";
public final String keyName = "name";
/* Keys for replacing parts of flags */
public final String tagPlayerName = "%player%";
public final String tagRegionName = "%region%";
public final String tagPrice = "%price%";
public final String tagDuration = "%duration%";
public final String tagRentedUntil = "%until%";
/**
* Called on start or reload of the server
*/
public void onEnable(){
boolean error = false;
/* Save a copy of the default config.yml if one is not present */
this.saveDefaultConfig();
/* Check the config, loads default if errors */
configOk = this.checkConfig();
/* Check if WorldGuard is present */
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
this.getLogger().info("Error: WorldGuard plugin is not present or has not loaded correctly");
error = true;
} else {
worldGuard = (WorldGuardPlugin)plugin;
}
/* Check if Vault is present */
RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
if (economyProvider == null) {
this.getLogger().info("Error: Vault plugin is not present or has not loaded correctly");
error = true;
} else {
economy = economyProvider.getProvider();
}
/* Create a LanguageMananager */
languageManager = new LanguageManager(this);
/* Save the chatPrefix */
chatprefix = this.config().getString("chatPrefix");
/* Load all data from files */
shopManager = new ShopManager(this);
error = error & !shopManager.loadRents();
shopManager.checkRents();
error = error & !shopManager.loadBuys();
if(error) {
this.getLogger().info("The plugin has not started, fix the errors listed above");
} else {
/* Register the event listeners */
this.getServer().getPluginManager().registerEvents(new SignChangeListener(this), this);
this.getServer().getPluginManager().registerEvents(new SignBreakListener(this), this);
this.getServer().getPluginManager().registerEvents(new RightClickListener(this), this);
/* Start thread for checking renting */
int checkDelay = Integer.parseInt(this.config().getString("checkDelay"))*20;
new RentCheck(this).runTaskTimer(this, checkDelay, checkDelay);
/* Bind commands for this plugin */
getCommand("AreaShop").setExecutor(new ShopCommands(this));
}
}
/**
* Called on shutdown or reload of the server
*/
public void onDisable() {
/* set variables to null to prevent memory leaks */
worldGuard = null;
economy = null;
shopManager = null;
languageManager = null;
configOk = false;
debug = false;
}
/**
* Function to get the WorldGuard plugin
* @return WorldGuardPlugin
*/
public WorldGuardPlugin getWorldGuard() {
return worldGuard;
}
/**
* Function to get the WorldGuard plugin
* @return WorldGuardPlugin
*/
public LanguageManager getLanguageManager() {
return languageManager;
}
/**
* Function to get the Vault plugin
* @return Economy
*/
public Economy getEconomy() {
return economy;
}
/**
* Method to get the ShopManager
* @return The shopManager
*/
public ShopManager getShopManager() {
return shopManager;
}
/**
* Method to send a message to a CommandSender, using chatprefix if it is a player
* @param target The CommandSender you wan't to send the message to (e.g. a player)
* @param key The key to get the translation
* @param params The parameters to inject into the message string
*/
public void message(Object target, String key, Object... params) {
String langString = this.fixColors(languageManager.getLang(key, params));
if(langString == null) {
this.getLogger().info("Something is wrong with the language file, could not find key: " + key);
} else {
if(target instanceof Player) {
((Player)target).sendMessage(this.fixColors(chatprefix) + langString);
} else if(target instanceof CommandSender) {
((CommandSender)target).sendMessage(langString);
}
else if(target instanceof Logger) {
((Logger)target).info(langString);
} else {
this.getLogger().info("Could not send message, target is wrong: " + langString);
}
}
}
/**
* Convert color and formatting codes to bukkit values
* @param input Start string with color and formatting codes in it
* @return String with the color and formatting codes in the bukkit format
*/
public String fixColors(String input) {
String result = null;
if(input != null) {
result = input.replaceAll("(&([a-f0-9]))", "\u00A7$2");
result = result.replaceAll("&k", ChatColor.MAGIC.toString());
result = result.replaceAll("&l", ChatColor.BOLD.toString());
result = result.replaceAll("&m", ChatColor.STRIKETHROUGH.toString());
result = result.replaceAll("&n", ChatColor.UNDERLINE.toString());
result = result.replaceAll("&o", ChatColor.ITALIC.toString());
result = result.replaceAll("&r", ChatColor.RESET.toString());
result = result.replaceAll("", "\u20AC");
}
return result;
}
/**
* Get the currency character, fixes problems with euro character acting weird
* @return Currency character
*/
public String getCurrencyCharacter() {
String result = this.config().getString("moneyCharacter");
result = result.replace(currencyEuro, "\u20ac");
return result;
}
/**
* Function for quitting the plugin, NOT USED ATM
*/
public void quit() {
this.getLogger().info("Plugin will be stopped");
Bukkit.getPluginManager().disablePlugin(this);
}
/**
* Return the config configured by the user or the default
*/
public Configuration config() {
if(configOk) {
return this.getConfig();
} else {
return this.getConfig().getDefaults();
}
}
/**
* Shows the help page for the player
* @param player The player to show the help to
*/
public void showHelp(CommandSender target) {
/* Set up the list of messages to be sent */
ArrayList<String> messages = new ArrayList<String>();
messages.add(this.config().getString("chatPrefix") + languageManager.getLang("help-header"));
messages.add(this.config().getString("chatPrefix") + languageManager.getLang("help-alias"));
if(target.hasPermission("areashop.help")) {
messages.add(languageManager.getLang("help-help"));
}
if(target.hasPermission("areashop.info")) {
messages.add(languageManager.getLang("help-info"));
}
if(target.hasPermission("areashop.rent")) {
messages.add(languageManager.getLang("help-rent"));
}
if(target.hasPermission("areashop.buy")) {
messages.add(languageManager.getLang("help-buy"));
}
if(target.hasPermission("areashop.unrent")) {
messages.add(languageManager.getLang("help-unrent"));
} else if(target.hasPermission("areashop.unrentown")) {
messages.add(languageManager.getLang("help-unrentOwn"));
}
if(target.hasPermission("areashop.sell")) {
messages.add(languageManager.getLang("help-sell"));
} else if(target.hasPermission("areashop.sellown")) {
messages.add(languageManager.getLang("help-sellOwn"));
}
if(target.hasPermission("areashop.updaterentsigns")) {
messages.add(languageManager.getLang("help-updaterentsigns"));
}
if(target.hasPermission("areashop.updatebuysigns")) {
messages.add(languageManager.getLang("help-updatebuysigns"));
}
if(target.hasPermission("areashop.updaterentregions")) {
messages.add(languageManager.getLang("help-updaterentregions"));
}
if(target.hasPermission("areashop.updatebuyregions")) {
messages.add(languageManager.getLang("help-updatebuyregions"));
}
if(target.hasPermission("areashop.reload")) {
messages.add(languageManager.getLang("help-reload"));
}
/* Send them all */
for(int i=0; i<messages.size(); i++) {
target.sendMessage(this.fixColors(messages.get(i)));
}
}
/**
* Checks the config for errors, loads default config if they occur
*/
public boolean checkConfig() {
int error = 0;
debug = this.getConfig().getString("debug").equalsIgnoreCase("true");
/* GENERAL */
String chatPrefix = this.getConfig().getString("chatPrefix");
if (chatPrefix.length() == 0) {
this.getLogger().info("Config-Error: chatPrefix has length zero");
error++;
}
String moneyCharacter = this.getCurrencyCharacter();
if (moneyCharacter.length() > 14) {
this.getLogger().info("Config-Error: moneyCharacter is longer than 14 characters");
error++;
}
String maximumTotal = this.getConfig().getString("maximumTotal");
try {
int maximumTotalInt = Integer.parseInt(maximumTotal);
if(maximumTotalInt < -1) {
this.getLogger().info("Config-Error: maximumTotal must be -1 or higher");
error++;
}
} catch (NumberFormatException e) {
this.getLogger().info("Config-Error: maximumTotal is not a valid number");
error++;
}
/* RENTING */
String rentSign = this.getConfig().getString("rentSign");
if (rentSign.length() > 15) {
this.getLogger().info("Config-Error: rentSign is too long, maximum length is 15 characters");
error++;
}
String signRentable = this.getConfig().getString("signRentable");
if (signRentable.length() > 15) {
this.getLogger().info("Config-Error: signRentable is too long, maximum length is 15 characters");
error++;
}
String signRented = this.getConfig().getString("signRented");
if (signRented.length() > 15) {
this.getLogger().info("Config-Error: signRented is too long, maximum length is 15 characters");
error++;
}
String maximumRents = this.getConfig().getString("maximumRents");
try {
int maximumRentsInt = Integer.parseInt(maximumRents);
if(maximumRentsInt < -1) {
this.getLogger().info("Config-Error: maximumRents must be -1 or higher");
error++;
}
} catch (NumberFormatException e) {
this.getLogger().info("Config-Error: maximumRents is not a valid number");
error++;
}
String rentMoneyBack = this.getConfig().getString("rentMoneyBack");
try {
int rentMoneyBackInt = Integer.parseInt(rentMoneyBack);
if(rentMoneyBackInt < 0 || rentMoneyBackInt > 100) {
this.getLogger().info("Config-Error: rentMoneyBack must be between 0 and 100");
error++;
}
} catch (NumberFormatException e) {
this.getLogger().info("Config-Error: rentMoneyBack is not a valid number");
error++;
}
String checkDelay = this.getConfig().getString("checkDelay");
try {
int checkDelayInt = Integer.parseInt(checkDelay);
if(checkDelayInt < 1) {
this.getLogger().info("Config-Error: checkDelay can't be below 1");
error++;
}
} catch (NumberFormatException e) {
this.getLogger().info("Config-Error: checkDelay is not a valid number");
error++;
}
/* BUYING */
String buySign = this.getConfig().getString("buySign");
if (buySign.length() > 15) {
this.getLogger().info("Config-Error: buySign is too long, maximum length is 15 characters");
error++;
}
String signBuyable = this.getConfig().getString("signBuyable");
if (signBuyable.length() > 15) {
this.getLogger().info("Config-Error: signBuyable is too long, maximum length is 15 characters");
error++;
}
String signBuyed = this.getConfig().getString("signBuyed");
if (signBuyed.length() > 15) {
this.getLogger().info("Config-Error: signBuyed is too long, maximum length is 15 characters");
error++;
}
String maximumBuys = this.getConfig().getString("maximumBuys");
try {
int maximumBuysInt = Integer.parseInt(maximumBuys);
if(maximumBuysInt < -1) {
this.getLogger().info("Config-Error: maximumBuys must be -1 or higher");
error++;
}
} catch (NumberFormatException e) {
this.getLogger().info("Config-Error: maximumBuys is not a valid number");
error++;
}
String buyMoneyBack = this.getConfig().getString("buyMoneyBack");
try {
int buyMoneyBackInt = Integer.parseInt(buyMoneyBack);
if(buyMoneyBackInt < 0 || buyMoneyBackInt > 100) {
this.getLogger().info("Config-Error: buyMoneyBack must be between 0 and 100");
error++;
}
} catch (NumberFormatException e) {
this.getLogger().info("Config-Error: buyMoneyBack is not a valid number");
error++;
}
/* Load default config if errors have occurred */
if (error > 0) {
this.getLogger().info("The plugin has " + error + " error(s) in the config, default config will be used");
}
/* return true if no errors, false if there are errors */
return (error == 0);
}
/**
* Sends an debug message to the console
* @param message The message that should be printed to the console
*/
public void debug(String message) {
if(this.debug) {
this.getLogger().info("Debug: " + message);
}
}
/**
* Reload the config of the plugin
*/
public void reload() {
this.saveDefaultConfig();
this.reloadConfig();
configOk = this.checkConfig();
chatprefix = this.config().getString("chatPrefix");
languageManager = new LanguageManager(this);
shopManager.checkRents();
}
}

View File

@ -0,0 +1,179 @@
package nl.evolutioncoding.AreaShop;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.bukkit.configuration.file.YamlConfiguration;
public class LanguageManager {
private AreaShop plugin = null;
private String languages[] = {"EN", "NL"};
private HashMap<String, String> currentLanguage, defaultLanguage;
/**
* Constructor
* @param plugin The AreaShop plugin
*/
public LanguageManager(AreaShop plugin) {
this.plugin = plugin;
/* Save default language files if not present */
this.saveDefaults();
/* Open current language file */
this.loadLanguage();
}
/**
* Saves the default language files if not already present
*/
public void saveDefaults() {
/* Create the language folder if it not exists */
File langFolder;
langFolder = new File(plugin.getDataFolder() + File.separator + plugin.languageFolder);
if(!langFolder.exists()) {
langFolder.mkdirs();
}
/* Create the language files, overwrites if a file already exists */
/* Overriding is necessary because otherwise with an update the new lang */
/* files would not be used, when translating your own use another */
/* file name as the default */
File langFile;
for(int i=0; i<languages.length; i++) {
langFile = new File(plugin.getDataFolder() + File.separator + plugin.languageFolder + File.separator + languages[i] + ".yml");
InputStream input = null;
OutputStream output = null;
try {
input = plugin.getResource(plugin.languageFolder + "/" + languages[i] + ".yml");
output = new FileOutputStream(langFile);
int read = 0;
byte[] bytes = new byte[1024];
while ((read = input.read(bytes)) != -1) {
output.write(bytes, 0, read);
}
input.close();
output.close();
} catch(IOException e) {
try {
input.close();
output.close();
} catch (IOException e1) {} catch (NullPointerException e2) {}
plugin.getLogger().info("Something went wrong saving a default language file: " + langFile.getPath());
}
}
}
/**
* Loads the current language file specified in the config
*/
public void loadLanguage() {
Map<String, Object> map;
Set<String> set;
YamlConfiguration ymlFile;
/* Save the current language file to the HashMap */
currentLanguage = new HashMap<String, String>();
File file = new File(plugin.getDataFolder() + File.separator + plugin.languageFolder + File.separator + plugin.config().getString("language") + ".yml");
ymlFile = YamlConfiguration.loadConfiguration(file);
map = ymlFile.getValues(true);
set = map.keySet();
try {
for(String key : set) {
currentLanguage.put(key, (String)map.get(key));
}
} catch(ClassCastException e) {}
/* Save the default strings to the HashMap */
defaultLanguage = new HashMap<String, String>();
InputStream defConfigStream = plugin.getResource(plugin.languageFolder + "/" + plugin.config().getString("language") + ".yml");
if (defConfigStream == null) {
defConfigStream = plugin.getResource(plugin.languageFolder + "/" + languages[0]+ ".yml");
}
ymlFile = YamlConfiguration.loadConfiguration(defConfigStream);
map = ymlFile.getValues(true);
set = map.keySet();
try {
for(String key : set) {
defaultLanguage.put(key, (String)map.get(key));
}
} catch(ClassCastException e) {}
}
/**
* Function to get the string in the language that has been set
* @param key Key to the language string
* @param params The replacements for the %1% tags
* @return String The language string specified with the key
*/
public String getLang(String key, Object... params) {
String result = null;
/* Get the language string */
if(currentLanguage.containsKey(key)) {
result = currentLanguage.get(key);
} else {
result = defaultLanguage.get(key);
}
if(result == null) {
plugin.getLogger().info("Wrong key for getting translation: " + key);
} else {
/* Replace all tags, e.g. %1% */
for (int i=0; i<params.length; i++) {
result = result.replace("%" + i + "%", params[i].toString());
}
}
return result;
}
}

View File

@ -0,0 +1,21 @@
package nl.evolutioncoding.AreaShop;
import org.bukkit.scheduler.BukkitRunnable;
public class RentCheck extends BukkitRunnable {
AreaShop plugin;
/**
* Constructor
* @param plugin The AreaShop plugin
*/
public RentCheck(AreaShop plugin) {
this.plugin = plugin;
}
@Override
public void run() {
plugin.getShopManager().checkRents();
}
}

View File

@ -0,0 +1,89 @@
package nl.evolutioncoding.AreaShop;
import java.util.HashMap;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
public class RightClickListener implements Listener {
AreaShop plugin;
/**
* Constructor
* @param plugin The AreaShop plugin
*/
public RightClickListener(AreaShop plugin) {
this.plugin = plugin;
}
/**
* Called when a player interacts
* @param event The event
*/
@EventHandler(priority = EventPriority.HIGH)
public void onRightClick(PlayerInteractEvent event) {
Block block = event.getClickedBlock();
/* Check for clicking a sign and rightclicking */
if(event.getAction() == Action.RIGHT_CLICK_BLOCK && (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN)) {
/* Check if the rent sign is really the same as a saved rent */
String regionName = ((Sign)(event.getClickedBlock().getState())).getLine(1);
HashMap<String,String> rent = plugin.getShopManager().getRent(regionName);
HashMap<String,String> buy = plugin.getShopManager().getBuy(regionName);
if(rent != null && block.getWorld().getName().equals(rent.get(plugin.keyWorld))
&& rent.get(plugin.keyX).equals(String.valueOf(block.getX()))
&& rent.get(plugin.keyY).equals(String.valueOf(block.getY()))
&& rent.get(plugin.keyZ).equals(String.valueOf(block.getZ())) ) {
plugin.getShopManager().rent(event.getPlayer(), regionName);
/* Cancel placing a block */
event.setCancelled(true);
} else if(buy != null && block.getWorld().getName().equals(buy.get(plugin.keyWorld))
&& buy.get(plugin.keyX).equals(String.valueOf(block.getX()))
&& buy.get(plugin.keyY).equals(String.valueOf(block.getY()))
&& buy.get(plugin.keyZ).equals(String.valueOf(block.getZ())) ) {
plugin.getShopManager().buy(event.getPlayer(), regionName);
/* Cancel placing a block */
event.setCancelled(true);
}
}
}
}

View File

@ -0,0 +1,406 @@
package nl.evolutioncoding.AreaShop;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Iterator;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ShopCommands implements CommandExecutor {
AreaShop plugin;
/**
* Constructor
* @param plugin The AreaShop plugin
*/
public ShopCommands(AreaShop plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) {
if(command.getName().equalsIgnoreCase("AreaShop")) {
ShopManager shopManager = plugin.getShopManager();
/* Commands with 1 argument or more */
if(args.length > 0 && args[0] != null) {
/* Help command */
if(args[0].equalsIgnoreCase("help")) {
plugin.showHelp(sender);
}
/* Renting command */
else if(args[0].equalsIgnoreCase("rent")) {
if (!(sender instanceof Player)) {
plugin.message(sender, "onlyByPlayer");
return true;
}
Player player = (Player)sender;
if(args.length > 1 && args[1] != null) {
shopManager.rent(player, args[1]);
} else {
plugin.message(sender, "rent-help");
}
}
/* Buying command */
else if(args[0].equalsIgnoreCase("buy")) {
if (!(sender instanceof Player)) {
plugin.message(sender, "onlyByPlayer");
return true;
}
Player player = (Player)sender;
if(args.length > 1 && args[1] != null) {
shopManager.buy(player, args[1]);
} else {
plugin.message(player, "buy-help");
}
}
/* Info command */
else if(args[0].equalsIgnoreCase("info")) {
if(args.length > 1 && args[1] != null) {
if(args[1].equalsIgnoreCase("all")) {
String message = "";
/* Message for rents */
Iterator<String> it = shopManager.getRents().keySet().iterator();
if(it.hasNext()) {
message = shopManager.getRent(it.next()).get(plugin.keyName);
while(it.hasNext()) {
message += ", " + shopManager.getRent(it.next()).get(plugin.keyName);
}
}
if(message.equals("")) {
plugin.message(sender, "info-all-noRents");
} else {
plugin.message(sender, "info-all-rents", message);
}
/* Message for buys */
it = shopManager.getBuys().keySet().iterator();
if(it.hasNext()) {
message = shopManager.getBuy(it.next()).get(plugin.keyName);
while(it.hasNext()) {
message += ", " + shopManager.getBuy(it.next()).get(plugin.keyName);
}
}
if(message.equals("")) {
plugin.message(sender, "info-all-noBuys");
} else {
plugin.message(sender, "info-all-buys", message);
}
}
else if(args[1].equalsIgnoreCase("rented")) {
String message = "";
Iterator<String> it = shopManager.getRents().keySet().iterator();
boolean first = true;
while(it.hasNext()) {
String next = shopManager.getRent(it.next()).get(plugin.keyName);
if(shopManager.getRent(next).get(plugin.keyPlayer) != null) {
if(!first) {
message += ", " + next;
} else {
first = false;
message = next;
}
}
}
if(message.equals("")) {
plugin.message(sender, "info-noRented");
} else {
plugin.message(sender, "info-rented", message);
}
} else if(args[1].equalsIgnoreCase("forrent")) {
String message = "";
Iterator<String> it = shopManager.getRents().keySet().iterator();
boolean first = true;
while(it.hasNext()) {
String next = shopManager.getRent(it.next()).get(plugin.keyName);
if(shopManager.getRent(next).get(plugin.keyPlayer) == null) {
if(!first) {
message += ", " + next;
} else {
first = false;
message = next;
}
}
}
if(message.equals("")) {
plugin.message(sender, "info-noUnrented");
} else {
plugin.message(sender, "info-unrented", message);
}
} else if(args[1].equalsIgnoreCase("sold")) {
String message = "";
Iterator<String> it = shopManager.getBuys().keySet().iterator();
boolean first = true;
while(it.hasNext()) {
String next = shopManager.getBuy(it.next()).get(plugin.keyName);
if(shopManager.getBuy(next).get(plugin.keyPlayer) != null) {
if(!first) {
message += ", ";
} else {
first = false;
}
message += next;
}
}
if(message.equals("")) {
plugin.message(sender, "info-noSold");
} else {
plugin.message(sender, "info-sold", message);
}
} else if(args[1].equalsIgnoreCase("forsale")) {
String message = "";
Iterator<String> it = shopManager.getBuys().keySet().iterator();
boolean first = true;
while(it.hasNext()) {
String next = shopManager.getBuy(it.next()).get(plugin.keyName);
if(shopManager.getBuy(next).get(plugin.keyPlayer) == null) {
if(!first) {
message += ", " + next;
} else {
first = false;
message = next;
}
}
}
if(message.equals("")) {
plugin.message(sender, "info-noForsale");
} else {
plugin.message(sender, "info-forsale", message);
}
} else if(args[1].equalsIgnoreCase("player")) {
if(args.length > 2 && args[2] != null) {
String message = "";
Iterator<String> it = shopManager.getRents().keySet().iterator();
boolean first = true;
while(it.hasNext()) {
String next = shopManager.getRent(it.next()).get(plugin.keyName);
if(shopManager.getRent(next).get(plugin.keyPlayer) != null && shopManager.getRent(next).get(plugin.keyPlayer).equalsIgnoreCase(args[2])) {
if(!first) {
message += ", " + next;
} else {
first = false;
message = next;
}
}
}
if(message.equals("")) {
plugin.message(sender, "info-playerNoRents", args[2]);
} else {
plugin.message(sender, "info-playerRents", args[2], message);
}
message = "";
it = shopManager.getBuys().keySet().iterator();
first = true;
while(it.hasNext()) {
String next = shopManager.getBuy(it.next()).get(plugin.keyName);
if(shopManager.getBuy(next).get(plugin.keyPlayer) != null && shopManager.getBuy(next).get(plugin.keyPlayer).equalsIgnoreCase(args[2])) {
if(!first) {
message += ", ";
} else {
first = false;
}
message += next;
}
}
if(message.equals("")) {
plugin.message(sender, "info-playerNoBuys", args[2]);
} else {
plugin.message(sender, "info-playerBuys", args[2], message);
}
} else {
plugin.message(sender, "info-playerHelp");
}
} else if(args[1].equalsIgnoreCase("region")) {
if(args.length > 2 && args[2] != null) {
HashMap<String,String> rent = shopManager.getRent(args[2]);
HashMap<String,String> buy = shopManager.getBuy(args[2]);
if(rent == null) {
plugin.message(sender, "info-regionRenting", args[2]);
plugin.message(sender, "info-regionNoRenting", args[2]);
} else {
plugin.message(sender, "info-regionRenting", rent.get(plugin.keyName));
plugin.message(sender, "info-regionSign", rent.get(plugin.keyWorld), rent.get(plugin.keyX), rent.get(plugin.keyY), rent.get(plugin.keyZ));
plugin.message(sender, "info-regionPriceDuration", plugin.getCurrencyCharacter() + rent.get(plugin.keyPrice), rent.get(plugin.keyDuration));
if(rent.get(plugin.keyPlayer) == null) {
plugin.message(sender, "info-regionNotRented");
} else {
SimpleDateFormat dateFull = new SimpleDateFormat("dd MMMMMMMMMMMMMMMMM yyyy HH:mm");
plugin.message(sender, "info-regionRentedBy", rent.get(plugin.keyPlayer), dateFull.format(Long.parseLong(rent.get(plugin.keyRentedUntil))));
}
}
if(buy == null) {
plugin.message(sender, "info-regionBuying", args[2]);
plugin.message(sender, "info-regionNoBuying", args[2]);
} else {
plugin.message(sender, "info-regionBuying", buy.get(plugin.keyName));
plugin.message(sender, "info-regionSign", buy.get(plugin.keyWorld), buy.get(plugin.keyX), buy.get(plugin.keyY), buy.get(plugin.keyZ));
plugin.message(sender, "info-regionPrice", plugin.getCurrencyCharacter() + buy.get(plugin.keyPrice));
if(buy.get(plugin.keyPlayer) == null) {
plugin.message(sender, "info-regionNotBought");
} else {
plugin.message(sender, "info-regionBoughtBy", buy.get(plugin.keyPlayer));
}
}
} else {
plugin.message(sender, "info-regionHelp");
}
} else {
plugin.message(sender, "info-help");
}
} else {
plugin.message(sender, "info-help");
}
}
/* Unrenting command */
else if(args[0].equalsIgnoreCase("unrent")) {
if(args.length > 1 && args[1] != null) {
HashMap<String,String> rent = shopManager.getRent(args[1]);
if(rent == null) {
plugin.message(sender, "unrent-notRegistered");
} else {
if(rent.get(plugin.keyPlayer) == null) {
plugin.message(sender, "unrent-notRented");
} else {
if(sender.hasPermission("areashop.unrent")) {
plugin.message(sender, "unrent-other", rent.get(plugin.keyPlayer));
shopManager.unRent(args[1]);
} else {
if(sender.hasPermission("areashop.unrentown")) {
if(rent.get(plugin.keyPlayer).equals(sender.getName())) {
plugin.message(sender, "unrent-unrented");
shopManager.unRent(args[1]);
} else {
plugin.message(sender, "unrent-noPermissionOther");
}
} else {
plugin.message(sender, "unrent-noPermission");
}
}
}
}
} else {
plugin.message(sender, "unrent-help");
}
}
/* Selling command */
else if(args[0].equalsIgnoreCase("sell")) {
if(args.length > 1 && args[1] != null) {
HashMap<String,String> buy = shopManager.getBuy(args[1]);
if(buy == null) {
plugin.message(sender, "sell-notRegistered");
} else {
if(buy.get(plugin.keyPlayer) == null) {
plugin.message(sender, "sell-notBought");
} else {
if(sender.hasPermission("areashop.sell")) {
plugin.message(sender, "sell-sold", buy.get(plugin.keyPlayer));
shopManager.unBuy(args[1]);
} else {
if(sender.hasPermission("areashop.sellown")) {
if(buy.get(plugin.keyPlayer).equals(sender.getName())) {
plugin.message(sender, "sell-soldYours");
shopManager.unBuy(args[1]);
} else {
plugin.message(sender, "sell-noPermissionOther");
}
} else {
plugin.message(sender, "sell-noPermission");
}
}
}
}
} else {
plugin.message(sender, "sell-help");
}
}
/* UpdateRentSigns command */
else if(args[0].equalsIgnoreCase("updaterentsigns")) {
if(sender.hasPermission("areashop.updaterentsigns")) {
boolean result = plugin.getShopManager().updateRentSigns();
if(result) {
plugin.message(sender, "rentsigns-updated");
} else {
plugin.message(sender, "rentsigns-notUpdated");
}
} else {
plugin.message(sender, "rentsigns-noPermission");
}
}
/* UpdateBuySigns command */
else if(args[0].equalsIgnoreCase("updatebuysigns")) {
if(sender.hasPermission("areashop.updatebuysigns")) {
boolean result = plugin.getShopManager().updateBuySigns();
if(result) {
plugin.message(sender, "buysigns-updated");
} else {
plugin.message(sender, "buysigns-notUpdated");
}
} else {
plugin.message(sender, "buysigns-noPermission");
}
}
/* updaterentregions command */
else if(args[0].equalsIgnoreCase("updaterentregions")) {
if(sender.hasPermission("areashop.updaterentregions")) {
plugin.getShopManager().updateRentRegions();
plugin.message(sender, "rentregions-updated");
} else {
plugin.message(sender, "rentregions-noPermission");
}
}
/* updatebuyregions command */
else if(args[0].equalsIgnoreCase("updatebuyregions")) {
if(sender.hasPermission("areashop.updatebuyregions")) {
plugin.getShopManager().updateBuyRegions();
plugin.message(sender, "buyregions-updated");
} else {
plugin.message(sender, "buyregions-noPermission");
}
}
/* reload command */
else if(args[0].equalsIgnoreCase("reload")) {
if(sender.hasPermission("areashop.reload")) {
plugin.reload();
plugin.message(sender, "reload-reloaded");
} else {
plugin.message(sender, "reload-noPermission");
}
}
/* Not a valid command */
else {
plugin.message(sender, "cmd-notValid");
}
} else {
plugin.showHelp(sender);
}
return true;
}
return false;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,162 @@
package nl.evolutioncoding.AreaShop;
import java.util.HashMap;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.event.Listener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
/**
* Checks for placement of signs for this plugin
* @author NLThijs48
*/
public final class SignBreakListener implements Listener {
AreaShop plugin;
/**
* Constructor
* @param plugin The AreaShop plugin
*/
public SignBreakListener(AreaShop plugin) {
this.plugin = plugin;
}
/**
* Called when a block is broken
* @param event The event
*/
@EventHandler(priority = EventPriority.HIGH)
public void onSignBreak(BlockBreakEvent event) {
Block block = event.getBlock();
/* Check if it is a sign */
if(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) {
Sign sign = (Sign)(block.getState());
/* Check if the rent sign is really the same as a saved rent */
HashMap<String,String> rent = plugin.getShopManager().getRent(sign.getLine(1));
HashMap<String,String> buy = plugin.getShopManager().getBuy(sign.getLine(1));
if(rent != null && rent.get(plugin.keyWorld).equals(block.getWorld().getName())
&& rent.get(plugin.keyX).equals(String.valueOf(block.getX()))
&& rent.get(plugin.keyY).equals(String.valueOf(block.getY()))
&& rent.get(plugin.keyZ).equals(String.valueOf(block.getZ())) ) {
/* Remove the rent if the player has permission */
if(event.getPlayer().hasPermission("areashop.destroyrent")) {
boolean result = plugin.getShopManager().removeRent(sign.getLine(1));
if(result) {
event.getPlayer().sendMessage(plugin.fixColors(plugin.config().getString("chatPrefix")) + "Renting of the region succesfully removed");
}
} else { /* Cancel the breaking of the sign */
event.setCancelled(true);
event.getPlayer().sendMessage(plugin.fixColors(plugin.config().getString("chatPrefix")) + "You don't have permission for destroying a sign for renting a region");
}
} else if(buy != null && buy.get(plugin.keyWorld).equals(block.getWorld().getName())
&& buy.get(plugin.keyX).equals(String.valueOf(block.getX()))
&& buy.get(plugin.keyY).equals(String.valueOf(block.getY()))
&& buy.get(plugin.keyZ).equals(String.valueOf(block.getZ())) ) {
/* Remove the buy if the player has permission */
if(event.getPlayer().hasPermission("areashop.destroybuy")) {
boolean result = plugin.getShopManager().removeBuy(sign.getLine(1));
if(result) {
event.getPlayer().sendMessage(plugin.fixColors(plugin.config().getString("chatPrefix")) + "Buying of the region succesfully removed");
}
} else { /* Cancel the breaking of the sign */
event.setCancelled(true);
event.getPlayer().sendMessage(plugin.fixColors(plugin.config().getString("chatPrefix")) + "You don't have permission for destroying a sign for buying a region");
}
}
}
}
/**
* Called when the physics of a block change
* @param event The event
*/
@EventHandler(priority = EventPriority.HIGH)
public void onIndirectSignBreak(BlockPhysicsEvent event){
Block block = event.getBlock();
if(block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN){
Sign sign = (Sign)block.getState();
Block attachedTo = block.getRelative(((org.bukkit.material.Sign)sign.getData()).getAttachedFace());
if(attachedTo.getType() == Material.AIR){
/* Check if the rent sign is really the same as a saved rent */
HashMap<String,String> rent = plugin.getShopManager().getRent(sign.getLine(1));
HashMap<String,String> buy = plugin.getShopManager().getBuy(sign.getLine(1));
if(rent != null && rent.get(plugin.keyWorld).equals(block.getWorld().getName())
&& rent.get(plugin.keyX).equals(String.valueOf(block.getX()))
&& rent.get(plugin.keyY).equals(String.valueOf(block.getY()))
&& rent.get(plugin.keyZ).equals(String.valueOf(block.getZ())) ) {
/* Remove the rent */
boolean result = plugin.getShopManager().removeRent(sign.getLine(1));
if(result) {
plugin.getLogger().info("Renting of region '" + sign.getLine(1) + "' has been removed by indirectly breaking the sign");
}
} else if(buy != null && buy.get(plugin.keyWorld).equals(block.getWorld().getName())
&& buy.get(plugin.keyX).equals(String.valueOf(block.getX()))
&& buy.get(plugin.keyY).equals(String.valueOf(block.getY()))
&& buy.get(plugin.keyZ).equals(String.valueOf(block.getZ())) ) {
/* Remove the buy */
boolean result = plugin.getShopManager().removeBuy(sign.getLine(1));
if(result) {
plugin.getLogger().info("Buying of region '" + sign.getLine(1) + "' has been removed by indirectly breaking the sign");
}
}
}
}
}
}

View File

@ -0,0 +1,235 @@
package nl.evolutioncoding.AreaShop;
import java.util.HashMap;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.SignChangeEvent;
import com.sk89q.worldguard.protection.managers.RegionManager;
/**
* Checks for placement of signs for this plugin
* @author NLThijs48
*/
public final class SignChangeListener implements Listener {
AreaShop plugin;
String chatPrefix;
String rentSign;
String buySign;
String signRentable;
String signBuyable;
/**
* Constructor
* @param plugin The AreaShop plugin
*/
public SignChangeListener(AreaShop plugin) {
this.plugin = plugin;
chatPrefix = plugin.fixColors(plugin.config().getString("chatPrefix"));
rentSign = plugin.config().getString("rentSign");
buySign = plugin.config().getString("buySign");
signRentable = plugin.fixColors(plugin.config().getString("signRentable"));
signBuyable = plugin.fixColors(plugin.config().getString("signBuyable"));
}
/**
* Called when a sign is changed
* @param event The event
*/
@EventHandler(priority = EventPriority.HIGH)
public void onSignChange(SignChangeEvent event) {
Player player = event.getPlayer();
/* Check if the sign is meant for this plugin */
if(event.getLine(0).contains(rentSign)) {
if(!player.hasPermission("areashop.createrent")) {
player.sendMessage(chatPrefix + "You don't have permission for setting up renting of regions");
return;
}
/* Get the other lines */
String secondLine = event.getLine(1);
String thirdLine = event.getLine(2);
if(!thirdLine.equals("M")) {
thirdLine = thirdLine.toLowerCase();
}
String fourthLine = event.getLine(3);
/* Get the regionManager for accessing regions */
RegionManager regionManager = plugin.getWorldGuard().getRegionManager(event.getPlayer().getWorld());
/* check if all the lines are correct */
if(secondLine == null || secondLine.length() == 0) {
player.sendMessage(chatPrefix + "You did not specify a region on the second line!");
return;
} else if(regionManager.getRegion(secondLine) == null) {
player.sendMessage(chatPrefix + "The region you specified does not exist!");
return;
} else if(plugin.getShopManager().getRent(secondLine) != null) {
player.sendMessage(chatPrefix + "The region you specified already has a sign for renting");
return;
} else if(thirdLine == null || thirdLine.length() == 0) {
player.sendMessage(chatPrefix + "You did not specify how long the region can be rented, do this on the third line");
return;
} else if(!this.checkTimeFormat(thirdLine)) {
player.sendMessage(chatPrefix + "The time specified is not in the correct format");
return;
} else if(fourthLine == null || fourthLine.length() == 0) {
player.sendMessage(chatPrefix + "You did not specify how much the renting costs on the fourth line!");
return;
} else {
/* Check the fourth line */
try {
Double.parseDouble(fourthLine);
} catch (NumberFormatException e) {
player.sendMessage(chatPrefix + "You did not specify the renting cost correctly, use a number only");
return;
}
/* Set the first line to signRentable */
event.setLine(0, signRentable);
event.setLine(1, regionManager.getRegion(secondLine).getId());
event.setLine(3, plugin.getCurrencyCharacter() + fourthLine);
/* Add rent to the ShopManager */
HashMap<String,String> rent = new HashMap<String,String>();
rent.put(plugin.keyWorld, event.getBlock().getWorld().getName());
rent.put(plugin.keyX, String.valueOf(event.getBlock().getX()));
rent.put(plugin.keyY, String.valueOf(event.getBlock().getY()));
rent.put(plugin.keyZ, String.valueOf(event.getBlock().getZ()));
rent.put(plugin.keyDuration, thirdLine);
rent.put(plugin.keyPrice, fourthLine);
rent.put(plugin.keyName, regionManager.getRegion(secondLine).getId());
plugin.getShopManager().addRent(secondLine, rent);
/* Set the flags for the region */
plugin.getShopManager().setRegionFlags(secondLine, plugin.config().getConfigurationSection("flagsForRent"), true);
player.sendMessage(chatPrefix + "Renting of the region is setup correctly");
}
} else if (event.getLine(0).contains(buySign)) {
/* Check for permission */
if(!player.hasPermission("areashop.createbuy")) {
player.sendMessage(chatPrefix + "You don't have permission for setting up buying of regions");
return;
}
/* Get the other lines */
String secondLine = event.getLine(1);
String thirdLine = event.getLine(2);
/* Get the regionManager for accessing regions */
RegionManager regionManager = plugin.getWorldGuard().getRegionManager(event.getPlayer().getWorld());
/* Check if all the lines are correct */
if(secondLine == null || secondLine.length() == 0) {
player.sendMessage(chatPrefix + "You did not specify a region on the second line!");
return;
} else if(regionManager.getRegion(secondLine) == null) {
player.sendMessage(chatPrefix + "The region you specified does not exist!");
return;
} else if(plugin.getShopManager().getBuy(secondLine) != null) {
player.sendMessage(chatPrefix + "The region you specified already has a sign for buying");
return;
} else if(thirdLine == null || thirdLine.length() == 0) {
player.sendMessage(chatPrefix + "You did not specify how much the buying costs on the fourth line!");
return;
} else {
/* Check the fourth line */
try {
Double.parseDouble(thirdLine);
} catch (NumberFormatException e) {
player.sendMessage(chatPrefix + "You did not specify the buying cost correctly, use a number only");
return;
}
/* Set the first line to signbuyable */
event.setLine(0, signBuyable);
event.setLine(1, regionManager.getRegion(secondLine).getId());
event.setLine(2, plugin.getCurrencyCharacter() + thirdLine);
/* Add buy to the ShopManager */
HashMap<String,String> buy = new HashMap<String,String>();
buy.put(plugin.keyWorld, event.getBlock().getWorld().getName());
buy.put(plugin.keyX, String.valueOf(event.getBlock().getX()));
buy.put(plugin.keyY, String.valueOf(event.getBlock().getY()));
buy.put(plugin.keyZ, String.valueOf(event.getBlock().getZ()));
buy.put(plugin.keyPrice, thirdLine);
buy.put(plugin.keyName, regionManager.getRegion(secondLine).getId());
plugin.getShopManager().addBuy(secondLine, buy);
/* Set the flags for the region */
plugin.getShopManager().setRegionFlags(secondLine, plugin.config().getConfigurationSection("flagsForSale"), false);
player.sendMessage(chatPrefix + "Buying of the region is setup correctly");
}
}
}
/**
* Checks if the string is a correct time period
* @param time String that has to be checked
* @return true if format is correct, false if not
*/
public boolean checkTimeFormat(String time) {
/* Check if the string is not empty and check the length */
if(time == null || time.length() <= 1 || time.indexOf(' ') == -1 || time.indexOf(' ') >= (time.length()-1)) {
return false;
}
/* Check if the suffix is one of these values */
String[] timeValues = {"m","min","mins","minute","minutes","minuten","minuut",
"h","hour","hours","uur","uren",
"M", "month", "months","maanden","maand",
"d","day","days","dag","dagen",
"y","year","years","jaar","jaren"};
String suffix = time.substring(time.indexOf(' ')+1, time.length());
boolean result = false;
for(int i=0; i<timeValues.length && !result; i++) {
result = timeValues[i].equals(suffix);
}
if(!result) {
return false;
}
/* check if the part before the space is a number */
String prefix = time.substring(0, (time.indexOf(' ')));
return prefix.matches("\\d+");
}
}