No red files anymore. Some stuff still unfinished.

+ weekly code cleanup
This commit is contained in:
Jesse Boyd 2014-10-11 00:33:10 -07:00
parent 2f5f3ac8e2
commit a6375796c0
94 changed files with 14237 additions and 12908 deletions

View File

@ -7,37 +7,38 @@ import org.apache.commons.lang.StringUtils;
*/
public class AbstractFlag {
private final String key;
private final String key;
/**
* AbstractFlag is a parameter used in creating a new Flag
*
* @param key
* The key must be alphabetical characters and <= 16 characters
* in length
*/
public AbstractFlag(String key) {
if (!StringUtils.isAlpha(key)) {
throw new IllegalArgumentException("Flag must be alphabetic characters");
}
if (key.length() > 16) {
throw new IllegalArgumentException("Key must be <= 16 characters");
}
this.key = key.toLowerCase();
}
/**
* AbstractFlag is a parameter used in creating a new Flag
*
* @param key
* The key must be alphabetical characters and <= 16 characters
* in length
*/
public AbstractFlag(String key) {
if (!StringUtils.isAlpha(key)) {
throw new IllegalArgumentException(
"Flag must be alphabetic characters");
}
if (key.length() > 16) {
throw new IllegalArgumentException("Key must be <= 16 characters");
}
this.key = key.toLowerCase();
}
/**
* AbstractFlag key
*
* @return String
*/
public String getKey() {
return this.key;
}
/**
* AbstractFlag key
*
* @return String
*/
public String getKey() {
return this.key;
}
@Override
public String toString() {
return this.key;
}
@Override
public String toString() {
return this.key;
}
}

View File

@ -13,246 +13,336 @@ import org.bukkit.ChatColor;
/**
* Captions class.
*
*
* @author Citymonstret
*
*
*/
public enum C {
/*
* Ratings
*/
RATING_NOT_VALID("&cYou need to specify a number between 1 and 10"), RATING_ALREADY_EXISTS("&cYou have already rated plot &c%s"), RATING_APPLIED("&cYou successfully rated plot &6%s"), RATING_NOT_YOUR_OWN("&cYou cannot rate your own plot"), RATING_NOT_OWNED("&cYou cannot rate a plot that is not claimed by anyone"),
/*
* Economy Stuff
*/
CANNOT_AFFORD_PLOT("&cYou cannot afford to buy this plot. It costs &6%s"), CANNOT_AFFORD_MERGE("&cYou cannot afford to merge the plots. It costs &6%s"), ADDED_BALANCE("&6%s &chas been added to your balance"), REMOVED_BALANCE("&6%s &chas been taken from your balance"),
/*
* Setup Stuff
*/
SETUP_INIT("&6PlotSquared Setup -> Setup a new plotworld"), SETUP_STEP("&cStep &6%s&c: %s &c<Expecting: &6%s&c, Default: &6%s&c>"), SETUP_INVALID_ARG("&c%s is not a valid argument for step %s. To cancel setup use: /plot setup cancel"), SETUP_VALID_ARG("&cValue &6%s &cset for step %s"), SETUP_FINISHED("&cFinished setup for world &c%s.\n&4If you are using MULTIVERSE or MULTIWORLD you will need to import this world. Otherwise you will need to add this world to the 'bukkit.yml' file (See installation tutorial for more info)"), SETUP_WORLD_TAKEN("&c%s is already a registered plotworld"), SETUP_MISSING_WORLD("&cYou need to specify a world name (&6/p setup {world}&c)\n&6Additional commands:\n&c - &6/p setup <value>\n&c - &6/p setup back\n&c - &6/p setup cancel"),
/*
* Schematic Stuff
*/
SCHEMATIC_MISSING_ARG("&cYou need to specify an argument. Possible values: &6test {name}"), SCHEMATIC_INVALID("&cThat is not a valid schematic. Reason: &c%s"), SCHEMATIC_VALID("&cThat's a valid schematic"), SCHEMATIC_PASTE_FAILED("&cFailed to paste schematic"), SCHEMATIC_PASTE_SUCCESS("&cSchematic pasted successfully"),
/*
* Title Stuff
*/
TITLE_ENTERED_PLOT("You entered plot %s"), TITLE_ENTERED_PLOT_COLOR("GOLD"), TITLE_ENTERED_PLOT_SUB("Owned by %s"), TITLE_ENTERED_PLOT_SUB_COLOR("RED"), TITLE_LEFT_PLOT("You entered plot %s"), TITLE_LEFT_PLOT_COLOR("GOLD"), TITLE_LEFT_PLOT_SUB("Owned by %s"), TITLE_LEFT_PLOT_SUB_COLOR("RED"),
/*
* Core Stuff
*/
PREFIX("&c[&6&lPlot&c] "), ENABLED("&6Plots are now enabled"), EXAMPLE_MESSAGE("&cThis is an example message &k!!!"),
/*
* Reload
*/
RELOADED_CONFIGS("&6The translation files has been reloaded"), RELOAD_FAILED("&cFailed to reload the translations file"),
/*
* BarAPI
*/
BOSSBAR_CLEARING("&cClearing plot: &6%id%"),
/*
* Alias
*/
ALIAS_SET_TO("&cPlot alias set to &6%alias%"), MISSING_ALIAS("&cYou need to specify the alias"), ALIAS_IS_TAKEN("&cThat alias is already taken"),
/*
* Position
*/
MISSING_POSITION("&cYou need to specify a position. Possible values: &6default&c, &6center"), POSITION_SET("&cPlot home position set"), INVALID_POSITION("&cThat is not a valid position value"),
/*
* Time
*/
TIME_FORMAT("&6%hours%, %min%, %sec%"),
/*
* Permission
*/
NO_SCHEMATIC_PERMISSION("&cYou don't have the permission required to use schematic &6%s"), NO_PERMISSION("&cYou don't have the permissions required to use this command."), NO_PLOT_PERMS("&cYou don't have the permissions to do that in this plot"), CANT_CLAIM_MORE_PLOTS("&cYou can't claim more plots."), YOU_BE_DENIED("&cYou are not allowed to enter this plot"),
/*
* Ratings
*/
RATING_NOT_VALID("&cYou need to specify a number between 1 and 10"), RATING_ALREADY_EXISTS(
"&cYou have already rated plot &c%s"), RATING_APPLIED(
"&cYou successfully rated plot &6%s"), RATING_NOT_YOUR_OWN(
"&cYou cannot rate your own plot"), RATING_NOT_OWNED(
"&cYou cannot rate a plot that is not claimed by anyone"),
/*
* Economy Stuff
*/
CANNOT_AFFORD_PLOT("&cYou cannot afford to buy this plot. It costs &6%s"), CANNOT_AFFORD_MERGE(
"&cYou cannot afford to merge the plots. It costs &6%s"), ADDED_BALANCE(
"&6%s &chas been added to your balance"), REMOVED_BALANCE(
"&6%s &chas been taken from your balance"),
/*
* Setup Stuff
*/
SETUP_INIT("&6PlotSquared Setup -> Setup a new plotworld"), SETUP_STEP(
"&cStep &6%s&c: %s &c<Expecting: &6%s&c, Default: &6%s&c>"), SETUP_INVALID_ARG(
"&c%s is not a valid argument for step %s. To cancel setup use: /plot setup cancel"), SETUP_VALID_ARG(
"&cValue &6%s &cset for step %s"), SETUP_FINISHED(
"&cFinished setup for world &c%s.\n&4If you are using MULTIVERSE or MULTIWORLD you will need to import this world. Otherwise you will need to add this world to the 'bukkit.yml' file (See installation tutorial for more info)"), SETUP_WORLD_TAKEN(
"&c%s is already a registered plotworld"), SETUP_MISSING_WORLD(
"&cYou need to specify a world name (&6/p setup {world}&c)\n&6Additional commands:\n&c - &6/p setup <value>\n&c - &6/p setup back\n&c - &6/p setup cancel"),
/*
* Schematic Stuff
*/
SCHEMATIC_MISSING_ARG(
"&cYou need to specify an argument. Possible values: &6test {name}"), SCHEMATIC_INVALID(
"&cThat is not a valid schematic. Reason: &c%s"), SCHEMATIC_VALID(
"&cThat's a valid schematic"), SCHEMATIC_PASTE_FAILED(
"&cFailed to paste schematic"), SCHEMATIC_PASTE_SUCCESS(
"&cSchematic pasted successfully"),
/*
* Title Stuff
*/
TITLE_ENTERED_PLOT("You entered plot %s"), TITLE_ENTERED_PLOT_COLOR("GOLD"), TITLE_ENTERED_PLOT_SUB(
"Owned by %s"), TITLE_ENTERED_PLOT_SUB_COLOR("RED"), TITLE_LEFT_PLOT(
"You entered plot %s"), TITLE_LEFT_PLOT_COLOR("GOLD"), TITLE_LEFT_PLOT_SUB(
"Owned by %s"), TITLE_LEFT_PLOT_SUB_COLOR("RED"),
/*
* Core Stuff
*/
PREFIX("&c[&6&lPlot&c] "), ENABLED("&6Plots are now enabled"), EXAMPLE_MESSAGE(
"&cThis is an example message &k!!!"),
/*
* Reload
*/
RELOADED_CONFIGS("&6The translation files has been reloaded"), RELOAD_FAILED(
"&cFailed to reload the translations file"),
/*
* BarAPI
*/
BOSSBAR_CLEARING("&cClearing plot: &6%id%"),
/*
* Alias
*/
ALIAS_SET_TO("&cPlot alias set to &6%alias%"), MISSING_ALIAS(
"&cYou need to specify the alias"), ALIAS_IS_TAKEN(
"&cThat alias is already taken"),
/*
* Position
*/
MISSING_POSITION(
"&cYou need to specify a position. Possible values: &6default&c, &6center"), POSITION_SET(
"&cPlot home position set"), INVALID_POSITION(
"&cThat is not a valid position value"),
/*
* Time
*/
TIME_FORMAT("&6%hours%, %min%, %sec%"),
/*
* Permission
*/
NO_SCHEMATIC_PERMISSION(
"&cYou don't have the permission required to use schematic &6%s"), NO_PERMISSION(
"&cYou don't have the permissions required to use this command."), NO_PLOT_PERMS(
"&cYou don't have the permissions to do that in this plot"), CANT_CLAIM_MORE_PLOTS(
"&cYou can't claim more plots."), YOU_BE_DENIED(
"&cYou are not allowed to enter this plot"),
NO_PERM_MERGE("&cYou are not the owner of the plot: &6%plot%"), UNLINK_REQUIRED("&cAn unlink is required to do this."), UNLINK_IMPOSSIBLE("&cYou can only unlink a mega-plot"), NO_MERGE_TO_MEGA("&cMega plots cannot be merged into. Please merge from the desired mega plot."),
/*
* Commands
*/
NOT_VALID_SUBCOMMAND("&cThat is not a valid subcommand."), NO_COMMANDS("&cI'm sorry, but you're not permitted to use any subcommands."), SUBCOMMAND_SET_OPTIONS_HEADER("&cPossible Values: "),
/*
* Player not found
*/
INVALID_PLAYER("&cPlayer not found: &6%player%."),
/*
*
*/
COMMAND_WENT_WRONG("&cSomething went wrong when executing that command..."),
/*
* No {plot}
*/
NOT_IN_PLOT("&cYou're not in a plot"), NOT_IN_PLOT_WORLD("&cYou're not in a plot world"), NOT_VALID_WORLD("&cThat is not a valid world (case sensitive)"), NOT_VALID_PLOT_WORLD("&cThat is not a valid plot world (case sensitive)"), NO_PLOTS("&cYou don't have any plots"),
/*
* Block List
*/
NOT_VALID_BLOCK_LIST_HEADER("&cThat's not a valid block. Valid blocks are:\\n"), BLOCK_LIST_ITEM(" &6%mat%&c,"), BLOCK_LIST_SEPARATER("&6,&c "),
/*
* Biome
*/
NEED_BIOME("&cYou've got to specify a biome"), BIOME_SET_TO("&cPlot biome set to &c"),
/*
* Teleport / Entry
*/
TELEPORTED_TO_PLOT("&6You have been teleported"),
/*
* Set Block
*/
SET_BLOCK_ACTION_FINISHED("&6The last setblock action is now finished."),
/*
* Debug
*/
DEUBG_HEADER("&6Debug Information\\n"), DEBUG_SECTION("&c>> &6&l%val%"), DEBUG_LINE("&c>> &6%var%&c:&6 %val%\\n"),
/*
* Invalid
*/
NOT_VALID_DATA("&cThat's not a valid data id."), NOT_VALID_BLOCK("&cThat's not a valid block."), NOT_VALID_NUMBER("&cThat's not a valid number"), NOT_VALID_PLOT_ID("&cThat's not a valid plot id."), NOT_YOUR_PLOT("&cThat is not your plot."), NO_SUCH_PLOT("&cThere is no such plot"), PLAYER_HAS_NOT_BEEN_ON("&cThat player hasn't been in the plotworld"), FOUND_NO_PLOTS("&cFound no plots with your search query"),
/*
* Camera
*/
CAMERA_STARTED("&cYou have entered camera mode for plot &6%s"), CAMERA_STOPPED("&cYou are no longer in camera mode"),
/*
* Need
*/
NEED_PLOT_NUMBER("&cYou've got to specify a plot number or alias"), NEED_BLOCK("&cYou've got to specify a block"), NEED_PLOT_ID("&cYou've got to specify a plot id."), NEED_USER("&cYou need to specify a username"),
/*
* Info
*/
PLOT_INFO_UNCLAIMED("&cPlot &6%s&c is not yet claimed"), PLOT_INFO("plot ID: &6%id%&c, plot Alias: &6%alias%&c, plot Owner: &6%owner%&c, plot Biome: &6%biome%&c, plot Time: &6%time%&c, plot Weather: &6%weather%&c, plot Helpers:&6%helpers%&c, plot Trusted:&6%trusted%&c, plot Denied:&6%denied%&c, plot Rating: &6%rating%, &cplot flags: &6%flags%"), PLOT_USER_LIST(" &6%user%&c,"),
/*
* Generating
*/
GENERATING_FLOOR("&6Started generating floor from your settings. It will take %time%"), GENERATING_WALL("&6Started generating wall from your settings"), GENERATING_WALL_FILLING("&cStarted generating wall filling from your settings."),
/*
* Clearing
*/
CLEARING_PLOT("&cClearing plot."), CLEARING_DONE("&6Done, took &a%time%&6 ms!"), CLEARING_DONE_PACKETS("&6(&a%time% &6ms for packets)"),
/*
* Claiming
*/
PLOT_NOT_CLAIMED("&cCannot claim plot"), PLOT_IS_CLAIMED("&cThis plot is already claimed"), CLAIMED("&6You successfully claimed the plot"),
/*
* List
*/
PLOT_LIST_HEADER("&6List of %word% plots"), PLOT_LIST_ITEM("&c>> &6%id% &c- &6%owner%"), PLOT_LIST_FOOTER("&c>> &6%word% a total of &c%num% &6claimed %plot%."),
/*
* Left
*/
LEFT_PLOT("&cYou left a plot"),
/*
* Wait
*/
WAIT_FOR_TIMER("&cA setblock timer is bound to either the current plot or you. Please wait for it to finish"),
/*
* Chat
*/
PLOT_CHAT_FORMAT("&c[&6Plot Chat&c][&6%plot_id%&c] &6%sender%&c: &6%msg%"),
/*
* Denied
*/
DENIED_REMOVED("&cYou successfully undenied the player from this plot"), DENIED_ADDED("&cYou successfully denied the player from this plot"), DENIED_NEED_ARGUMENT("&cArguments are missing. &6/plot denied add {name} &cor &6/plot helpers remove {name}"), WAS_NOT_DENIED("&cThat player was not denied on this plot"),
/*
* Rain
*/
NEED_ON_OFF("&cYou need to specify a value. Possible values: &6on&c, &6off"), SETTING_UPDATED("&cYou successfully updated the setting"),
/*
* Flag
*/
NEED_KEY("&cPossible values: &6%values%"), NOT_VALID_FLAG("&cThat is not a valid flag"), NOT_VALID_VALUE("&cFlag values must be alphanumerical"), FLAG_NOT_IN_PLOT("&cThe plot does not have that flag"), FLAG_NOT_REMOVED("&cThe flag could not be removed"), FLAG_NOT_ADDED("&cThe flag could not be added"), FLAG_REMOVED("&6Successfully removed flag"), FLAG_ADDED("&6Successfully added flag"),
/*
* Helper
*/
HELPER_ADDED("&6You successfully added a helper to the plot"), HELPER_REMOVED("&6You successfully removed a helper from the plot"), HELPER_NEED_ARGUMENT("&cArguments are missing. &6/plot helpers add {name} &cor &6/plot helpers remove {name}"), WAS_NOT_ADDED("&cThat player was not added as a helper on this plot"),
/*
* Trusted
*/
TRUSTED_ADDED("&6You successfully added a trusted user to the plot"), TRUSTED_REMOVED("&6You successfully removed a trusted user from the plot"), TRUSTED_NEED_ARGUMENT("&cArguments are missing. &6/plot trusted add {name} &cor &6/plot trusted remove {name}"), T_WAS_NOT_ADDED("&cThat player was not added as a trusted user on this plot"),
/*
* Set Owner
*/
SET_OWNER("&6You successfully set the plot owner"),
/*
* Signs
*/
OWNER_SIGN_LINE_1("&cID: &6%id%"), OWNER_SIGN_LINE_2("&cOwner:"), OWNER_SIGN_LINE_3("&6%plr%"), OWNER_SIGN_LINE_4("&2Claimed"),
/*
* Help
*/
HELP_CATEGORY("&6Current Category&c: &l%category%"), HELP_INFO("&6You need to specify a help category"), HELP_INFO_ITEM("&6/plots help %category% &c- &6%category_desc%"), HELP_PAGE("&c>> &6%usage% &c[&6%alias%&c] &c- &6%desc%"), HELP_HEADER("&6Help for Plots"),
/*
* Direction
*/
DIRECTION("&6Current direction: %dir%"),
/*
* Custom
*/
CUSTOM_STRING("-");
/**
* Default
*/
private String d;
/**
* Translated
*/
private String s;
NO_PERM_MERGE("&cYou are not the owner of the plot: &6%plot%"), UNLINK_REQUIRED(
"&cAn unlink is required to do this."), UNLINK_IMPOSSIBLE(
"&cYou can only unlink a mega-plot"), NO_MERGE_TO_MEGA(
"&cMega plots cannot be merged into. Please merge from the desired mega plot."),
/*
* Commands
*/
NOT_VALID_SUBCOMMAND("&cThat is not a valid subcommand."), NO_COMMANDS(
"&cI'm sorry, but you're not permitted to use any subcommands."), SUBCOMMAND_SET_OPTIONS_HEADER(
"&cPossible Values: "),
/*
* Player not found
*/
INVALID_PLAYER("&cPlayer not found: &6%player%."),
/*
*
*/
COMMAND_WENT_WRONG("&cSomething went wrong when executing that command..."),
/*
* No {plot}
*/
NOT_IN_PLOT("&cYou're not in a plot"), NOT_IN_PLOT_WORLD(
"&cYou're not in a plot world"), NOT_VALID_WORLD(
"&cThat is not a valid world (case sensitive)"), NOT_VALID_PLOT_WORLD(
"&cThat is not a valid plot world (case sensitive)"), NO_PLOTS(
"&cYou don't have any plots"),
/*
* Block List
*/
NOT_VALID_BLOCK_LIST_HEADER(
"&cThat's not a valid block. Valid blocks are:\\n"), BLOCK_LIST_ITEM(
" &6%mat%&c,"), BLOCK_LIST_SEPARATER("&6,&c "),
/*
* Biome
*/
NEED_BIOME("&cYou've got to specify a biome"), BIOME_SET_TO(
"&cPlot biome set to &c"),
/*
* Teleport / Entry
*/
TELEPORTED_TO_PLOT("&6You have been teleported"),
/*
* Set Block
*/
SET_BLOCK_ACTION_FINISHED("&6The last setblock action is now finished."),
/*
* Debug
*/
DEUBG_HEADER("&6Debug Information\\n"), DEBUG_SECTION("&c>> &6&l%val%"), DEBUG_LINE(
"&c>> &6%var%&c:&6 %val%\\n"),
/*
* Invalid
*/
NOT_VALID_DATA("&cThat's not a valid data id."), NOT_VALID_BLOCK(
"&cThat's not a valid block."), NOT_VALID_NUMBER(
"&cThat's not a valid number"), NOT_VALID_PLOT_ID(
"&cThat's not a valid plot id."), NOT_YOUR_PLOT(
"&cThat is not your plot."), NO_SUCH_PLOT("&cThere is no such plot"), PLAYER_HAS_NOT_BEEN_ON(
"&cThat player hasn't been in the plotworld"), FOUND_NO_PLOTS(
"&cFound no plots with your search query"),
/*
* Camera
*/
CAMERA_STARTED("&cYou have entered camera mode for plot &6%s"), CAMERA_STOPPED(
"&cYou are no longer in camera mode"),
/*
* Need
*/
NEED_PLOT_NUMBER("&cYou've got to specify a plot number or alias"), NEED_BLOCK(
"&cYou've got to specify a block"), NEED_PLOT_ID(
"&cYou've got to specify a plot id."), NEED_USER(
"&cYou need to specify a username"),
/*
* Info
*/
PLOT_INFO_UNCLAIMED("&cPlot &6%s&c is not yet claimed"), PLOT_INFO(
"plot ID: &6%id%&c, plot Alias: &6%alias%&c, plot Owner: &6%owner%&c, plot Biome: &6%biome%&c, plot Time: &6%time%&c, plot Weather: &6%weather%&c, plot Helpers:&6%helpers%&c, plot Trusted:&6%trusted%&c, plot Denied:&6%denied%&c, plot Rating: &6%rating%, &cplot flags: &6%flags%"), PLOT_USER_LIST(
" &6%user%&c,"),
/*
* Generating
*/
GENERATING_FLOOR(
"&6Started generating floor from your settings. It will take %time%"), GENERATING_WALL(
"&6Started generating wall from your settings"), GENERATING_WALL_FILLING(
"&cStarted generating wall filling from your settings."),
/*
* Clearing
*/
CLEARING_PLOT("&cClearing plot."), CLEARING_DONE(
"&6Done, took &a%time%&6 ms!"), CLEARING_DONE_PACKETS(
"&6(&a%time% &6ms for packets)"),
/*
* Claiming
*/
PLOT_NOT_CLAIMED("&cCannot claim plot"), PLOT_IS_CLAIMED(
"&cThis plot is already claimed"), CLAIMED(
"&6You successfully claimed the plot"),
/*
* List
*/
PLOT_LIST_HEADER("&6List of %word% plots"), PLOT_LIST_ITEM(
"&c>> &6%id% &c- &6%owner%"), PLOT_LIST_FOOTER(
"&c>> &6%word% a total of &c%num% &6claimed %plot%."),
/*
* Left
*/
LEFT_PLOT("&cYou left a plot"),
/*
* Wait
*/
WAIT_FOR_TIMER(
"&cA setblock timer is bound to either the current plot or you. Please wait for it to finish"),
/*
* Chat
*/
PLOT_CHAT_FORMAT("&c[&6Plot Chat&c][&6%plot_id%&c] &6%sender%&c: &6%msg%"),
/*
* Denied
*/
DENIED_REMOVED("&cYou successfully undenied the player from this plot"), DENIED_ADDED(
"&cYou successfully denied the player from this plot"), DENIED_NEED_ARGUMENT(
"&cArguments are missing. &6/plot denied add {name} &cor &6/plot helpers remove {name}"), WAS_NOT_DENIED(
"&cThat player was not denied on this plot"),
/*
* Rain
*/
NEED_ON_OFF("&cYou need to specify a value. Possible values: &6on&c, &6off"), SETTING_UPDATED(
"&cYou successfully updated the setting"),
/*
* Flag
*/
NEED_KEY("&cPossible values: &6%values%"), NOT_VALID_FLAG(
"&cThat is not a valid flag"), NOT_VALID_VALUE(
"&cFlag values must be alphanumerical"), FLAG_NOT_IN_PLOT(
"&cThe plot does not have that flag"), FLAG_NOT_REMOVED(
"&cThe flag could not be removed"), FLAG_NOT_ADDED(
"&cThe flag could not be added"), FLAG_REMOVED(
"&6Successfully removed flag"), FLAG_ADDED(
"&6Successfully added flag"),
/*
* Helper
*/
HELPER_ADDED("&6You successfully added a helper to the plot"), HELPER_REMOVED(
"&6You successfully removed a helper from the plot"), HELPER_NEED_ARGUMENT(
"&cArguments are missing. &6/plot helpers add {name} &cor &6/plot helpers remove {name}"), WAS_NOT_ADDED(
"&cThat player was not added as a helper on this plot"),
/*
* Trusted
*/
TRUSTED_ADDED("&6You successfully added a trusted user to the plot"), TRUSTED_REMOVED(
"&6You successfully removed a trusted user from the plot"), TRUSTED_NEED_ARGUMENT(
"&cArguments are missing. &6/plot trusted add {name} &cor &6/plot trusted remove {name}"), T_WAS_NOT_ADDED(
"&cThat player was not added as a trusted user on this plot"),
/*
* Set Owner
*/
SET_OWNER("&6You successfully set the plot owner"),
/*
* Signs
*/
OWNER_SIGN_LINE_1("&cID: &6%id%"), OWNER_SIGN_LINE_2("&cOwner:"), OWNER_SIGN_LINE_3(
"&6%plr%"), OWNER_SIGN_LINE_4("&2Claimed"),
/*
* Help
*/
HELP_CATEGORY("&6Current Category&c: &l%category%"), HELP_INFO(
"&6You need to specify a help category"), HELP_INFO_ITEM(
"&6/plots help %category% &c- &6%category_desc%"), HELP_PAGE(
"&c>> &6%usage% &c[&6%alias%&c] &c- &6%desc%"), HELP_HEADER(
"&6Help for Plots"),
/*
* Direction
*/
DIRECTION("&6Current direction: %dir%"),
/*
* Custom
*/
CUSTOM_STRING("-");
/**
* Default
*/
private String d;
/**
* Translated
*/
private String s;
/**
* Constructor for custom strings.
*/
@SuppressWarnings("unused")
C() {
/*
* use setCustomString();
*/
}
/**
* Constructor for custom strings.
*/
@SuppressWarnings("unused")
C() {
/*
* use setCustomString();
*/
}
/**
* Constructor
*
* @param d
* default
*/
C(String d) {
this.d = d;
if (PlotMain.translations == null) {
this.s = d;
} else {
this.s = PlotMain.translations.getString(this.toString());
}
if (this.s == null) {
this.s = "";
}
}
/**
* Constructor
*
* @param d
* default
*/
C(String d) {
this.d = d;
if (PlotMain.translations == null) {
this.s = d;
} else {
this.s = PlotMain.translations.getString(this.toString());
}
if (this.s == null) {
this.s = "";
}
}
/**
* Get the default string
*
* @return default
*/
@SuppressWarnings("unused")
public String d() {
return this.d;
}
/**
* Get the default string
*
* @return default
*/
@SuppressWarnings("unused")
public String d() {
return this.d;
}
/**
* Get translated if exists
*
* @return translated if exists else default
*/
public String s() {
if (this.s.length() < 1) {
return this.d.replace("\\n", "\n");
}
return this.s.replace("\\n", "\n");
}
/**
* Get translated if exists
*
* @return translated if exists else default
*/
public String s() {
if (this.s.length() < 1) {
return this.d.replace("\\n", "\n");
}
return this.s.replace("\\n", "\n");
}
/**
*
* @return translated and color decoded
*/
public String translated() {
return ChatColor.translateAlternateColorCodes('&', this.s());
}
/**
*
* @return translated and color decoded
*/
public String translated() {
return ChatColor.translateAlternateColorCodes('&', this.s());
}
}

View File

@ -5,203 +5,207 @@ import java.util.List;
import org.bukkit.block.Biome;
public class Configuration {
public static final SettingValue STRING = new SettingValue("STRING") {
@Override
public boolean validateValue(String string) {
return true;
}
public static final SettingValue STRING = new SettingValue("STRING") {
@Override
public boolean validateValue(String string) {
return true;
}
@Override
public Object parseString(String string) {
return string;
}
};
@Override
public Object parseString(String string) {
return string;
}
};
public static final SettingValue STRINGLIST = new SettingValue("STRINGLIST") {
@Override
public boolean validateValue(String string) {
return true;
}
public static final SettingValue STRINGLIST = new SettingValue("STRINGLIST") {
@Override
public boolean validateValue(String string) {
return true;
}
@Override
public Object parseString(String string) {
return string.split(",");
}
};
@Override
public Object parseString(String string) {
return string.split(",");
}
};
public static final SettingValue INTEGER = new SettingValue("INTEGER") {
@Override
public boolean validateValue(String string) {
try {
Integer.parseInt(string);
return true;
} catch (Exception e) {
return false;
}
}
public static final SettingValue INTEGER = new SettingValue("INTEGER") {
@Override
public boolean validateValue(String string) {
try {
Integer.parseInt(string);
return true;
} catch (Exception e) {
return false;
}
}
@Override
public Object parseString(String string) {
return Integer.parseInt(string);
}
};
@Override
public Object parseString(String string) {
return Integer.parseInt(string);
}
};
public static final SettingValue BOOLEAN = new SettingValue("BOOLEAN") {
@Override
public boolean validateValue(String string) {
try {
Boolean.parseBoolean(string);
return true;
} catch (Exception e) {
return false;
}
}
public static final SettingValue BOOLEAN = new SettingValue("BOOLEAN") {
@Override
public boolean validateValue(String string) {
try {
Boolean.parseBoolean(string);
return true;
} catch (Exception e) {
return false;
}
}
@Override
public Object parseString(String string) {
return Boolean.parseBoolean(string);
}
};
@Override
public Object parseString(String string) {
return Boolean.parseBoolean(string);
}
};
public static final SettingValue DOUBLE = new SettingValue("DOUBLE") {
@Override
public boolean validateValue(String string) {
try {
Double.parseDouble(string);
return true;
} catch (Exception e) {
return false;
}
}
public static final SettingValue DOUBLE = new SettingValue("DOUBLE") {
@Override
public boolean validateValue(String string) {
try {
Double.parseDouble(string);
return true;
} catch (Exception e) {
return false;
}
}
@Override
public Object parseString(String string) {
return Double.parseDouble(string);
}
};
@Override
public Object parseString(String string) {
return Double.parseDouble(string);
}
};
public static final SettingValue BIOME = new SettingValue("BIOME") {
@Override
public boolean validateValue(String string) {
try {
Biome.valueOf(string.toUpperCase());
return true;
} catch (Exception e) {
return false;
}
}
public static final SettingValue BIOME = new SettingValue("BIOME") {
@Override
public boolean validateValue(String string) {
try {
Biome.valueOf(string.toUpperCase());
return true;
} catch (Exception e) {
return false;
}
}
@Override
public Object parseString(String string) {
return Biome.valueOf(string.toUpperCase());
}
@Override
public Object parseObject(Object object) {
return ((Biome) object).toString();
}
};
@Override
public Object parseString(String string) {
return Biome.valueOf(string.toUpperCase());
}
public static final SettingValue BLOCK = new SettingValue("BLOCK") {
@Override
public boolean validateValue(String string) {
try {
if (string.contains(":")) {
String[] split = string.split(":");
Short.parseShort(split[0]);
Short.parseShort(split[1]);
} else {
Short.parseShort(string);
}
return true;
} catch (Exception e) {
return false;
}
}
@Override
public Object parseObject(Object object) {
return ((Biome) object).toString();
}
};
@Override
public Object parseString(String string) {
if (string.contains(":")) {
String[] split = string.split(":");
return new PlotBlock(Short.parseShort(split[0]), Byte.parseByte(split[1]));
} else {
return new PlotBlock(Short.parseShort(string), (byte) 0);
}
}
@Override
public Object parseObject(Object object) {
return ((PlotBlock) object).id+":"+((PlotBlock) object).data;
}
};
public static final SettingValue BLOCK = new SettingValue("BLOCK") {
@Override
public boolean validateValue(String string) {
try {
if (string.contains(":")) {
String[] split = string.split(":");
Short.parseShort(split[0]);
Short.parseShort(split[1]);
} else {
Short.parseShort(string);
}
return true;
} catch (Exception e) {
return false;
}
}
public static final SettingValue BLOCKLIST = new SettingValue("BLOCKLIST") {
@Override
public boolean validateValue(String string) {
try {
for (String block : string.split(",")) {
if (block.contains(":")) {
String[] split = block.split(":");
Short.parseShort(split[0]);
Short.parseShort(split[1]);
} else {
Short.parseShort(block);
}
}
return true;
} catch (Exception e) {
return false;
}
}
@Override
public Object parseString(String string) {
if (string.contains(":")) {
String[] split = string.split(":");
return new PlotBlock(Short.parseShort(split[0]),
Byte.parseByte(split[1]));
} else {
return new PlotBlock(Short.parseShort(string), (byte) 0);
}
}
@Override
public Object parseString(String string) {
String[] blocks = string.split(",");
PlotBlock[] values = new PlotBlock[blocks.length];
for (int i = 0; i<blocks.length; i++) {
if (string.contains(":")) {
String[] split = string.split(":");
values[i] = new PlotBlock(Short.parseShort(split[0]), Byte.parseByte(split[1]));
} else {
values[i] = new PlotBlock(Short.parseShort(string), (byte) 0);
}
}
return values;
}
@Override
public Object parseObject(Object object) {
List<String> list = new ArrayList<String>();
for (PlotBlock block:(PlotBlock[]) object) {
list.add((block.id+":"+(block.data)));
}
return list;
}
};
@Override
public Object parseObject(Object object) {
return ((PlotBlock) object).id + ":" + ((PlotBlock) object).data;
}
};
/**
*
* Create your own SettingValue object to make the management of plotworld configuration easier
*
*/
public static abstract class SettingValue {
private String type;
public static final SettingValue BLOCKLIST = new SettingValue("BLOCKLIST") {
@Override
public boolean validateValue(String string) {
try {
for (String block : string.split(",")) {
if (block.contains(":")) {
String[] split = block.split(":");
Short.parseShort(split[0]);
Short.parseShort(split[1]);
} else {
Short.parseShort(block);
}
}
return true;
} catch (Exception e) {
return false;
}
}
public SettingValue(String type) {
this.type = type;
}
@Override
public Object parseString(String string) {
String[] blocks = string.split(",");
PlotBlock[] values = new PlotBlock[blocks.length];
for (int i = 0; i < blocks.length; i++) {
if (string.contains(":")) {
String[] split = string.split(":");
values[i] = new PlotBlock(Short.parseShort(split[0]),
Byte.parseByte(split[1]));
} else {
values[i] = new PlotBlock(Short.parseShort(string),
(byte) 0);
}
}
return values;
}
public String getType() {
return this.type;
}
public Object parseObject(Object object) {
return object;
}
@Override
public Object parseObject(Object object) {
List<String> list = new ArrayList<String>();
for (PlotBlock block : (PlotBlock[]) object) {
list.add((block.id + ":" + (block.data)));
}
return list;
}
};
public abstract Object parseString(String string);
/**
*
* Create your own SettingValue object to make the management of plotworld
* configuration easier
*
*/
public static abstract class SettingValue {
private String type;
public abstract boolean validateValue(String string);
}
public SettingValue(String type) {
this.type = type;
}
public String getType() {
return this.type;
}
public Object parseObject(Object object) {
return object;
}
public abstract Object parseString(String string);
public abstract boolean validateValue(String string);
}
}

View File

@ -7,51 +7,64 @@ import org.apache.commons.lang.StringUtils;
import com.intellectualcrafters.plot.Configuration.SettingValue;
public class ConfigurationNode {
private String constant;
private Object default_value;
private String description;
private Object value = 0;
private SettingValue type;
private String constant;
private Object default_value;
private String description;
private Object value = 0;
private SettingValue type;
public ConfigurationNode(String constant, Object default_value, String description, SettingValue type, boolean required) {
this.constant = constant;
this.default_value = default_value;
this.description = description;
this.value = default_value;
this.type = type;
}
public ConfigurationNode(String constant, Object default_value,
String description, SettingValue type, boolean required) {
this.constant = constant;
this.default_value = default_value;
this.description = description;
this.value = default_value;
this.type = type;
}
public String getType() {
return this.type.getType();
}
public String getType() {
return this.type.getType();
}
public boolean setValue(String string) {
if (!this.type.validateValue(string)) {
return false;
}
this.value = this.type.parseString(string);
return true;
}
public boolean isValid(String string) {
try {
Object result = this.type.parseString(string);
if (result == null) {
return false;
}
return true;
} catch (Exception e) {
return false;
}
}
public Object getValue() {
if (this.value instanceof String[]) {
return Arrays.asList((String[]) this.value);
}
return this.value;
}
public boolean setValue(String string) {
if (!this.type.validateValue(string)) {
return false;
}
this.value = this.type.parseString(string);
return true;
}
public String getConstant() {
return this.constant;
}
public Object getValue() {
if (this.value instanceof String[]) {
return Arrays.asList((String[]) this.value);
}
return this.value;
}
public Object getDefaultValue() {
if (this.default_value instanceof String[]) {
return StringUtils.join((String[]) this.default_value, ",");
}
return this.default_value;
}
public String getConstant() {
return this.constant;
}
public String getDescription() {
return this.description;
}
public Object getDefaultValue() {
if (this.default_value instanceof String[]) {
return StringUtils.join((String[]) this.default_value, ",");
}
return this.default_value;
}
public String getDescription() {
return this.description;
}
}

View File

@ -7,95 +7,107 @@ import org.bukkit.ChatColor;
*/
public class ConsoleColors {
static enum ConsoleColor {
RESET ("\u001B[0m"),
BLACK ("\u001B[30m"),
RED ("\u001B[31m"),
GREEN ("\u001B[32m"),
YELLOW ("\u001B[33m"),
BLUE ("\u001B[34m"),
PURPLE ("\u001B[35m"),
CYAN ("\u001B[36m"),
WHITE ("\u001B[37m"),
BOLD ("\033[1m"),
UNDERLINE ("\033[0m"),
ITALIC ("\033[3m");
static enum ConsoleColor {
RESET("\u001B[0m"), BLACK("\u001B[30m"), RED("\u001B[31m"), GREEN(
"\u001B[32m"), YELLOW("\u001B[33m"), BLUE("\u001B[34m"), PURPLE(
"\u001B[35m"), CYAN("\u001B[36m"), WHITE("\u001B[37m"), BOLD(
"\033[1m"), UNDERLINE("\033[0m"), ITALIC("\033[3m");
private String win;
private String lin;
private String win;
private String lin;
ConsoleColor(String lin) {
this.lin = lin;
this.win = win;
}
ConsoleColor(String lin) {
this.lin = lin;
this.win = this.win;
}
public String getWin() {
return win;
}
public String getWin() {
return this.win;
}
public String getLin(){
return lin;
}
}
public String getLin() {
return this.lin;
}
}
/* public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_BLACK = "\u001B[30m";
public static final String ANSI_RED = "\u001B[31m";
public static final String ANSI_GREEN = "\u001B[32m";
public static final String ANSI_YELLOW = "\u001B[33m";
public static final String ANSI_BLUE = "\u001B[34m";
public static final String ANSI_PURPLE = "\u001B[35m";
public static final String ANSI_CYAN = "\u001B[36m";
public static final String ANSI_WHITE = "\u001B[37m";
public static final String ANSI_BOLD = "\033[1m";
public static final String ANSI_UNDERLINE = "\033[0m";
public static final String ANSI_ITALIC = "\033[3m]";*/
/*
* public static final String ANSI_RESET = "\u001B[0m"; public static final
* String ANSI_BLACK = "\u001B[30m"; public static final String ANSI_RED =
* "\u001B[31m"; public static final String ANSI_GREEN = "\u001B[32m";
* public static final String ANSI_YELLOW = "\u001B[33m"; public static
* final String ANSI_BLUE = "\u001B[34m"; public static final String
* ANSI_PURPLE = "\u001B[35m"; public static final String ANSI_CYAN =
* "\u001B[36m"; public static final String ANSI_WHITE = "\u001B[37m";
* public static final String ANSI_BOLD = "\033[1m"; public static final
* String ANSI_UNDERLINE = "\033[0m"; public static final String ANSI_ITALIC
* = "\033[3m]";
*/
public static String fromString(String input) {
input = input.replaceAll("&0", fromChatColor(ChatColor.BLACK)).replaceAll("&1", fromChatColor(ChatColor.DARK_BLUE)).replaceAll("&2", fromChatColor(ChatColor.DARK_GREEN)).replaceAll("&3", fromChatColor(ChatColor.DARK_AQUA)).replaceAll("&4", fromChatColor(ChatColor.DARK_RED)).replaceAll("&5", fromChatColor(ChatColor.DARK_PURPLE)).replaceAll("&6", fromChatColor(ChatColor.GOLD)).replaceAll("&7", fromChatColor(ChatColor.GRAY)).replaceAll("&8", fromChatColor(ChatColor.DARK_GRAY)).replaceAll("&9", fromChatColor(ChatColor.BLUE)).replaceAll("&a", fromChatColor(ChatColor.GREEN)).replaceAll("&b", fromChatColor(ChatColor.AQUA)).replaceAll("&c", fromChatColor(ChatColor.RED)).replaceAll("&d", fromChatColor(ChatColor.LIGHT_PURPLE)).replaceAll("&e", fromChatColor(ChatColor.YELLOW)).replaceAll("&f", fromChatColor(ChatColor.WHITE)).replaceAll("&k", fromChatColor(ChatColor.MAGIC)).replaceAll("&l", fromChatColor(ChatColor.BOLD)).replaceAll("&m", fromChatColor(ChatColor.STRIKETHROUGH))
.replaceAll("&n", fromChatColor(ChatColor.UNDERLINE)).replaceAll("&o", fromChatColor(ChatColor.ITALIC)).replaceAll("&r", fromChatColor(ChatColor.RESET));
return input + ConsoleColor.RESET.toString();
}
public static String fromString(String input) {
input = input.replaceAll("&0", fromChatColor(ChatColor.BLACK))
.replaceAll("&1", fromChatColor(ChatColor.DARK_BLUE))
.replaceAll("&2", fromChatColor(ChatColor.DARK_GREEN))
.replaceAll("&3", fromChatColor(ChatColor.DARK_AQUA))
.replaceAll("&4", fromChatColor(ChatColor.DARK_RED))
.replaceAll("&5", fromChatColor(ChatColor.DARK_PURPLE))
.replaceAll("&6", fromChatColor(ChatColor.GOLD))
.replaceAll("&7", fromChatColor(ChatColor.GRAY))
.replaceAll("&8", fromChatColor(ChatColor.DARK_GRAY))
.replaceAll("&9", fromChatColor(ChatColor.BLUE))
.replaceAll("&a", fromChatColor(ChatColor.GREEN))
.replaceAll("&b", fromChatColor(ChatColor.AQUA))
.replaceAll("&c", fromChatColor(ChatColor.RED))
.replaceAll("&d", fromChatColor(ChatColor.LIGHT_PURPLE))
.replaceAll("&e", fromChatColor(ChatColor.YELLOW))
.replaceAll("&f", fromChatColor(ChatColor.WHITE))
.replaceAll("&k", fromChatColor(ChatColor.MAGIC))
.replaceAll("&l", fromChatColor(ChatColor.BOLD))
.replaceAll("&m", fromChatColor(ChatColor.STRIKETHROUGH))
.replaceAll("&n", fromChatColor(ChatColor.UNDERLINE))
.replaceAll("&o", fromChatColor(ChatColor.ITALIC))
.replaceAll("&r", fromChatColor(ChatColor.RESET));
return input + ConsoleColor.RESET.toString();
}
public static String fromChatColor(ChatColor color) {
return chatColor(color).getLin();
}
public static String fromChatColor(ChatColor color) {
return chatColor(color).getLin();
}
public static ConsoleColor chatColor(ChatColor color) {
switch (color) {
case RESET:
return ConsoleColor.RESET;
case GRAY:
case DARK_GRAY:
return ConsoleColor.WHITE;
case BLACK:
return ConsoleColor.BLACK;
case DARK_RED:
case RED:
return ConsoleColor.RED;
case GOLD:
case YELLOW:
return ConsoleColor.YELLOW;
case DARK_GREEN:
case GREEN:
return ConsoleColor.GREEN;
case AQUA:
case DARK_AQUA:
return ConsoleColor.CYAN;
case LIGHT_PURPLE:
case DARK_PURPLE:
return ConsoleColor.PURPLE;
case BLUE:
case DARK_BLUE:
return ConsoleColor.BLUE;
case UNDERLINE:
return ConsoleColor.UNDERLINE;
case ITALIC:
return ConsoleColor.ITALIC;
case BOLD:
return ConsoleColor.BOLD;
default:
return ConsoleColor.RESET;
}
}
public static ConsoleColor chatColor(ChatColor color) {
switch (color) {
case RESET:
return ConsoleColor.RESET;
case GRAY:
case DARK_GRAY:
return ConsoleColor.WHITE;
case BLACK:
return ConsoleColor.BLACK;
case DARK_RED:
case RED:
return ConsoleColor.RED;
case GOLD:
case YELLOW:
return ConsoleColor.YELLOW;
case DARK_GREEN:
case GREEN:
return ConsoleColor.GREEN;
case AQUA:
case DARK_AQUA:
return ConsoleColor.CYAN;
case LIGHT_PURPLE:
case DARK_PURPLE:
return ConsoleColor.PURPLE;
case BLUE:
case DARK_BLUE:
return ConsoleColor.BLUE;
case UNDERLINE:
return ConsoleColor.UNDERLINE;
case ITALIC:
return ConsoleColor.ITALIC;
case BOLD:
return ConsoleColor.BOLD;
default:
return ConsoleColor.RESET;
}
}
}

View File

@ -4,85 +4,86 @@ import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
public class Flag {
private AbstractFlag key;
private String value;
private AbstractFlag key;
private String value;
/**
* Flag object used to store basic information for a Plot. Flags are a
* key/value pair. For a flag to be usable by a player, you need to register
* it with PlotSquared.
*
* @param key
* AbstractFlag
* @param value
* Value must be alphanumerical (can have spaces) and be <= 48
* characters
* @throws IllegalArgumentException
* if you provide inadequate inputs
*/
public Flag(AbstractFlag key, String value) {
if (!StringUtils.isAlphanumericSpace(ChatColor.stripColor(value))) {
throw new IllegalArgumentException("Flag must be alphanumerical");
}
if (value.length() > 48) {
throw new IllegalArgumentException("Value must be <= 48 characters");
}
this.key = key;
this.value = value;
}
/**
* Flag object used to store basic information for a Plot. Flags are a
* key/value pair. For a flag to be usable by a player, you need to register
* it with PlotSquared.
*
* @param key
* AbstractFlag
* @param value
* Value must be alphanumerical (can have spaces) and be <= 48
* characters
* @throws IllegalArgumentException
* if you provide inadequate inputs
*/
public Flag(AbstractFlag key, String value) {
if (!StringUtils.isAlphanumericSpace(ChatColor.stripColor(value))) {
throw new IllegalArgumentException("Flag must be alphanumerical");
}
if (value.length() > 48) {
throw new IllegalArgumentException("Value must be <= 48 characters");
}
this.key = key;
this.value = value;
}
/**
* Get the AbstractFlag used in creating the flag
*
* @return AbstractFlag
*/
public AbstractFlag getAbstractFlag() {
return this.key;
}
/**
* Get the AbstractFlag used in creating the flag
*
* @return AbstractFlag
*/
public AbstractFlag getAbstractFlag() {
return this.key;
}
/**
* Get the key for the AbstractFlag
*
* @return String
*/
public String getKey() {
return this.key.getKey();
}
/**
* Get the key for the AbstractFlag
*
* @return String
*/
public String getKey() {
return this.key.getKey();
}
/**
* Get the value
*
* @return String
*/
public String getValue() {
return this.value;
}
/**
* Get the value
*
* @return String
*/
public String getValue() {
return this.value;
}
@Override
public String toString() {
if (this.value.equals("")) {
return this.key.getKey();
}
return this.key + ":" + this.value;
}
@Override
public String toString() {
if (this.value.equals("")) {
return this.key.getKey();
}
return this.key + ":" + this.value;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Flag other = (Flag) obj;
return (this.key.getKey().equals(other.key.getKey()) && this.value.equals(other.value));
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Flag other = (Flag) obj;
return (this.key.getKey().equals(other.key.getKey()) && this.value
.equals(other.value));
}
@Override
public int hashCode() {
return this.key.getKey().hashCode();
}
@Override
public int hashCode() {
return this.key.getKey().hashCode();
}
}

View File

@ -6,91 +6,104 @@ import java.util.Set;
public class FlagManager {
// TODO add some flags
// - Plot clear interval
// - Mob cap
// - customized plot composition
// - greeting / leaving message
// OR in the flag command, allow users to set worldguard flags.
// TODO add some flags
// - Plot clear interval
// - Mob cap
// - customized plot composition
// - greeting / leaving message
// OR in the flag command, allow users to set worldguard flags.
private static ArrayList<AbstractFlag> flags = new ArrayList<AbstractFlag>();
private static ArrayList<AbstractFlag> flags = new ArrayList<AbstractFlag>();
/**
* Register an AbstractFlag with PlotSquared
*
* @param flag
* @return
*/
public static boolean addFlag(AbstractFlag flag) {
if (getFlag(flag.getKey()) != null) {
return false;
}
return flags.add(flag);
}
/**
* Register an AbstractFlag with PlotSquared
*
* @param flag
* @return
*/
public static boolean addFlag(AbstractFlag flag) {
if (getFlag(flag.getKey()) != null) {
return false;
}
return flags.add(flag);
}
/**
* Get a list of registered AbstractFlag objects
*
* @return List (AbstractFlag)
*/
public static List<AbstractFlag> getFlags() {
return flags;
}
/**
* Get a list of registered AbstractFlag objects
*
* @return List (AbstractFlag)
*/
public static List<AbstractFlag> getFlags() {
return flags;
}
/**
* Get an AbstractFlag by a string Returns null if flag does not exist
*
* @param string
* @return AbstractFlag
*/
public static AbstractFlag getFlag(String string) {
for (AbstractFlag flag : flags) {
if (flag.getKey().equalsIgnoreCase(string)) {
return flag;
}
}
return null;
}
/**
* Get an AbstractFlag by a string Returns null if flag does not exist
*
* @param string
* @return AbstractFlag
*/
public static AbstractFlag getFlag(String string) {
for (AbstractFlag flag : flags) {
if (flag.getKey().equalsIgnoreCase(string)) {
return flag;
}
}
return null;
}
/**
* Get an AbstractFlag by a string
*
* @param string
* @param create
* If to create the flag if it does not exist
* @return AbstractFlag
*/
public static AbstractFlag getFlag(String string, boolean create) {
if ((getFlag(string) == null) && create) {
AbstractFlag flag = new AbstractFlag(string);
addFlag(flag);
return flag;
}
return getFlag(string);
}
/**
* Get an AbstractFlag by a string
*
* @param string
* @param create
* If to create the flag if it does not exist
* @return AbstractFlag
*/
public static AbstractFlag getFlag(String string, boolean create) {
if ((getFlag(string) == null) && create) {
AbstractFlag flag = new AbstractFlag(string);
addFlag(flag);
return flag;
}
return getFlag(string);
}
/**
* Remove a registered AbstractFlag
*
* @param flag
* @return boolean Result of operation
*/
public static boolean removeFlag(AbstractFlag flag) {
return flags.remove(flag);
}
/**
* Remove a registered AbstractFlag
*
* @param flag
* @return boolean Result of operation
*/
public static boolean removeFlag(AbstractFlag flag) {
return flags.remove(flag);
}
/**
* Get the flags for a plot
*
* @param plot
* @return List (AbstractFlag)
*/
public static List<AbstractFlag> getPlotFlags(Plot plot) {
Set<Flag> plotFlags = plot.settings.getFlags();
List<AbstractFlag> flags = new ArrayList<>();
for (Flag flag : plotFlags) {
flags.add(flag.getAbstractFlag());
}
return flags;
}
public static Flag[] parseFlags(List<String> flagstrings) {
Flag[] flags = new Flag[flagstrings.size()];
for (int i = 0; i < flagstrings.size(); i++) {
String[] split = flagstrings.get(i).split(";");
if (split.length == 1) {
flags[i] = new Flag(getFlag(split[0], true), "");
} else {
flags[i] = new Flag(getFlag(split[0], true), split[1]);
}
}
return flags;
}
/**
* Get the flags for a plot
*
* @param plot
* @return List (AbstractFlag)
*/
public static List<AbstractFlag> getPlotFlags(Plot plot) {
Set<Flag> plotFlags = plot.settings.getFlags();
List<AbstractFlag> flags = new ArrayList<>();
for (Flag flag : plotFlags) {
flags.add(flag.getAbstractFlag());
}
return flags;
}
}

View File

@ -13,117 +13,119 @@ import org.bukkit.Location;
/**
* Cube utilities
*
*
* @author Citymonstret
*
*
*/
public class LSetCube {
/**
* Base locations
*/
private Location l1, l2;
/**
* Base locations
*/
private Location l1, l2;
/**
* Constructor
*
* @param l1
* @param l2
*/
public LSetCube(Location l1, Location l2) {
this.l1 = l1;
this.l1 = l2;
}
/**
* Constructor
*
* @param l1
* @param l2
*/
public LSetCube(Location l1, Location l2) {
this.l1 = l1;
this.l1 = l2;
}
/**
* Secondary constructor
*
* @param l1
* @param size
*/
public LSetCube(Location l1, int size) {
this.l1 = l1;
this.l2 = l1.clone().add(size, size, size);
}
/**
* Secondary constructor
*
* @param l1
* @param size
*/
public LSetCube(Location l1, int size) {
this.l1 = l1;
this.l2 = l1.clone().add(size, size, size);
}
/**
* Returns the absolute min. of the cube
*
* @return abs. min
*/
public Location minLoc() {
int x = Math.min(this.l1.getBlockX(), this.l2.getBlockX());
int y = Math.min(this.l1.getBlockY(), this.l2.getBlockY());
int z = Math.min(this.l1.getBlockZ(), this.l2.getBlockZ());
return new Location(this.l1.getWorld(), x, y, z);
}
/**
* Returns the absolute min. of the cube
*
* @return abs. min
*/
public Location minLoc() {
int x = Math.min(this.l1.getBlockX(), this.l2.getBlockX());
int y = Math.min(this.l1.getBlockY(), this.l2.getBlockY());
int z = Math.min(this.l1.getBlockZ(), this.l2.getBlockZ());
return new Location(this.l1.getWorld(), x, y, z);
}
/**
* Returns the absolute max. of the cube
*
* @return abs. max
*/
public Location maxLoc() {
int x = Math.max(this.l1.getBlockX(), this.l2.getBlockX());
int y = Math.max(this.l1.getBlockY(), this.l2.getBlockY());
int z = Math.max(this.l1.getBlockZ(), this.l2.getBlockZ());
return new Location(this.l1.getWorld(), x, y, z);
}
/**
* Returns the absolute max. of the cube
*
* @return abs. max
*/
public Location maxLoc() {
int x = Math.max(this.l1.getBlockX(), this.l2.getBlockX());
int y = Math.max(this.l1.getBlockY(), this.l2.getBlockY());
int z = Math.max(this.l1.getBlockZ(), this.l2.getBlockZ());
return new Location(this.l1.getWorld(), x, y, z);
}
/**
* Creates a LCycler for the cube.
*
* @return new lcycler
*/
public LCycler getCycler() {
return new LCycler(this);
}
/**
* Creates a LCycler for the cube.
*
* @return new lcycler
*/
public LCycler getCycler() {
return new LCycler(this);
}
/**
* @author Citymonstret
*/
protected class LCycler {
/**
*
*/
private Location min;
/**
*
*/
private Location max;
/**
*
*/
private Location current;
/**
* @author Citymonstret
*/
protected class LCycler {
/**
*
*/
private Location min;
/**
*
*/
private Location max;
/**
*
*/
private Location current;
/**
*
* @param cube
*/
public LCycler(LSetCube cube) {
this.min = cube.minLoc();
this.max = cube.maxLoc();
this.current = this.min;
}
/**
*
* @param cube
*/
public LCycler(LSetCube cube) {
this.min = cube.minLoc();
this.max = cube.maxLoc();
this.current = this.min;
}
/**
*
* @return
*/
public boolean hasNext() {
return ((this.current.getBlockX() + 1) <= this.max.getBlockX()) && ((this.current.getBlockY() + 1) <= this.max.getBlockY()) && ((this.current.getBlockZ() + 1) <= this.max.getBlockZ());
}
/**
*
* @return
*/
public boolean hasNext() {
return ((this.current.getBlockX() + 1) <= this.max.getBlockX())
&& ((this.current.getBlockY() + 1) <= this.max.getBlockY())
&& ((this.current.getBlockZ() + 1) <= this.max.getBlockZ());
}
/**
*
* @return
*/
public Location getNext() {
if (!hasNext()) {
return null;
}
this.current = this.current.add(1, 1, 1);
return this.current;
}
}
/**
*
* @return
*/
public Location getNext() {
if (!hasNext()) {
return null;
}
this.current = this.current.add(1, 1, 1);
return this.current;
}
}
}

View File

@ -11,85 +11,86 @@ package com.intellectualcrafters.plot;
/**
* TPS and Lag Checker.
*
*
* @author Citymonstret
*
*
*/
public class Lag implements Runnable {
/**
* Tick count
*/
public static int TC = 0;
/**
* Ticks
*/
public static long[] T = new long[600];
/**
* something :_:
*/
@SuppressWarnings("unused")
public static long LT = 0L;
/**
* Tick count
*/
public static int TC = 0;
/**
* Ticks
*/
public static long[] T = new long[600];
/**
* something :_:
*/
@SuppressWarnings("unused")
public static long LT = 0L;
/**
* Get the server TPS
*
* @return server tick per second
*/
public static double getTPS() {
return Math.round(getTPS(100)) > 20.0D ? 20.0D : Math.round(getTPS(100));
}
/**
* Get the server TPS
*
* @return server tick per second
*/
public static double getTPS() {
return Math.round(getTPS(100)) > 20.0D ? 20.0D : Math
.round(getTPS(100));
}
/**
* Return the tick per second (measured in $ticks)
*
* @param ticks
* Ticks
* @return ticks per second
*/
public static double getTPS(int ticks) {
if (TC < ticks) {
return 20.0D;
}
int t = (TC - 1 - ticks) % T.length;
long e = System.currentTimeMillis() - T[t];
return ticks / (e / 1000.0D);
}
/**
* Return the tick per second (measured in $ticks)
*
* @param ticks
* Ticks
* @return ticks per second
*/
public static double getTPS(int ticks) {
if (TC < ticks) {
return 20.0D;
}
int t = (TC - 1 - ticks) % T.length;
long e = System.currentTimeMillis() - T[t];
return ticks / (e / 1000.0D);
}
/**
* Get number of ticks since
*
* @param tI
* Ticks <
* @return number of ticks since $tI
*/
@SuppressWarnings("unused")
public static long getElapsed(int tI) {
long t = T[tI % T.length];
return System.currentTimeMillis() - t;
}
/**
* Get number of ticks since
*
* @param tI
* Ticks <
* @return number of ticks since $tI
*/
@SuppressWarnings("unused")
public static long getElapsed(int tI) {
long t = T[tI % T.length];
return System.currentTimeMillis() - t;
}
@Override
public void run() {
T[TC % T.length] = System.currentTimeMillis();
TC++;
}
@Override
public void run() {
T[TC % T.length] = System.currentTimeMillis();
TC++;
}
/**
* Get lag percentage
*
* @return lag percentage
*/
public static double getPercentage() {
return Math.round((1.0D - (Lag.getTPS() / 20.0D)) * 100.0D);
}
/**
* Get lag percentage
*
* @return lag percentage
*/
public static double getPercentage() {
return Math.round((1.0D - (Lag.getTPS() / 20.0D)) * 100.0D);
}
/**
* Get TPS percentage (of 20)
*
* @return TPS percentage
*/
public static double getFullPercentage() {
return getTPS() * 5.0D;
}
/**
* Get TPS percentage (of 20)
*
* @return TPS percentage
*/
public static double getFullPercentage() {
return getTPS() * 5.0D;
}
}

View File

@ -19,57 +19,58 @@ import java.util.Date;
/**
* Logging of errors and debug messages.
*
*
* @author Citymonstret
*
*
*/
public class Logger {
private static ArrayList<String> entries;
private static File log;
private static ArrayList<String> entries;
private static File log;
public static void setup(File file) {
log = file;
entries = new ArrayList<>();
try {
BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
while ((line = reader.readLine()) != null) {
entries.add(line);
}
reader.close();
} catch (IOException e) {
PlotMain.sendConsoleSenderMessage(C.PREFIX.s() + "File setup error Logger#setup");
}
}
public static void setup(File file) {
log = file;
entries = new ArrayList<>();
try {
BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
while ((line = reader.readLine()) != null) {
entries.add(line);
}
reader.close();
} catch (IOException e) {
PlotMain.sendConsoleSenderMessage(C.PREFIX.s()
+ "File setup error Logger#setup");
}
}
public enum LogLevel {
GENERAL("General"), WARNING("Warning"), DANGER("Danger");
private String name;
public enum LogLevel {
GENERAL("General"), WARNING("Warning"), DANGER("Danger");
private String name;
LogLevel(String name) {
this.name = name;
}
LogLevel(String name) {
this.name = name;
}
@Override
public String toString() {
return this.name;
}
}
@Override
public String toString() {
return this.name;
}
}
public static void write() throws IOException {
FileWriter writer = new FileWriter(log);
for (String string : entries) {
writer.write(string + System.lineSeparator());
}
writer.close();
}
public static void write() throws IOException {
FileWriter writer = new FileWriter(log);
for (String string : entries) {
writer.write(string + System.lineSeparator());
}
writer.close();
}
public static void add(LogLevel level, String string) {
append("[" + level.toString() + "] " + string);
}
public static void add(LogLevel level, String string) {
append("[" + level.toString() + "] " + string);
}
private static void append(String string) {
entries.add("[" + new Date().toString() + "]" + string);
}
private static void append(String string) {
entries.add("[" + new Date().toString() + "]" + string);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -13,92 +13,104 @@ import com.sk89q.worldedit.bukkit.BukkitPlayer;
import com.sk89q.worldedit.regions.CuboidRegion;
/**
*
*
* @author Citymonstret
*
*
*/
public class PWE {
public static void setMask(Player p, Location l) {
try {
LocalSession s;
if (PlotMain.worldEdit == null) {
s = WorldEdit.getInstance().getSession(p.getName());
} else {
s = PlotMain.worldEdit.getSession(p);
}
public static void setMask(Player p, Location l) {
try {
LocalSession s;
if (PlotMain.worldEdit == null) {
s = WorldEdit.getInstance().getSession(p.getName());
} else {
s = PlotMain.worldEdit.getSession(p);
}
PlotId id = PlayerFunctions.getPlot(l);
if (id != null) {
Plot plot = PlotMain.getPlots(l.getWorld()).get(id);
if (plot != null) {
boolean r;
r = (plot.getOwner() != null) && plot.getOwner().equals(p.getUniqueId()) || plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId());
if (!r) {
if (p.hasPermission("plots.worldedit.bypass")) {
removeMask(p, s);
return;
}
} else {
PlotId id = PlayerFunctions.getPlot(l);
if (id != null) {
Plot plot = PlotMain.getPlots(l.getWorld()).get(id);
if (plot != null) {
boolean r;
r = (plot.getOwner() != null)
&& plot.getOwner().equals(p.getUniqueId())
|| plot.helpers.contains(DBFunc.everyone)
|| plot.helpers.contains(p.getUniqueId());
if (!r) {
if (p.hasPermission("plots.worldedit.bypass")) {
removeMask(p, s);
return;
}
} else {
World w = p.getWorld();
World w = p.getWorld();
Location bloc = PlotHelper.getPlotBottomLoc(w, plot.id);
Location tloc = PlotHelper.getPlotTopLoc(w, plot.id);
Location bloc = PlotHelper.getPlotBottomLoc(w, plot.id);
Location tloc = PlotHelper.getPlotTopLoc(w, plot.id);
Vector bvec = new Vector(bloc.getBlockX() + 1, bloc.getBlockY() + 1, bloc.getBlockZ() + 1);
Vector tvec = new Vector(tloc.getBlockX(), tloc.getBlockY(), tloc.getBlockZ());
Vector bvec = new Vector(bloc.getBlockX() + 1,
bloc.getBlockY() + 1, bloc.getBlockZ() + 1);
Vector tvec = new Vector(tloc.getBlockX(),
tloc.getBlockY(), tloc.getBlockZ());
LocalWorld lw = PlotMain.worldEdit.wrapPlayer(p).getWorld();
LocalWorld lw = PlotMain.worldEdit.wrapPlayer(p)
.getWorld();
CuboidRegion region = new CuboidRegion(lw, bvec, tvec);
com.sk89q.worldedit.masks.RegionMask mask = new com.sk89q.worldedit.masks.RegionMask(region);
CuboidRegion region = new CuboidRegion(lw, bvec, tvec);
com.sk89q.worldedit.masks.RegionMask mask = new com.sk89q.worldedit.masks.RegionMask(
region);
s.setMask(mask);
return;
}
}
}
if (noMask(s)) {
BukkitPlayer plr = PlotMain.worldEdit.wrapPlayer(p);
Vector p1 = new Vector(69, 69, 69), p2 = new Vector(69, 69, 69);
s.setMask(mask);
return;
}
}
}
if (noMask(s)) {
BukkitPlayer plr = PlotMain.worldEdit.wrapPlayer(p);
Vector p1 = new Vector(69, 69, 69), p2 = new Vector(69, 69, 69);
s.setMask(new com.sk89q.worldedit.masks.RegionMask(new CuboidRegion(plr.getWorld(), p1, p2)));
}
} catch (Exception e) {
// throw new PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY, "WorldEdit == Null?");
}
}
s.setMask(new com.sk89q.worldedit.masks.RegionMask(
new CuboidRegion(plr.getWorld(), p1, p2)));
}
} catch (Exception e) {
// throw new
// PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY,
// "WorldEdit == Null?");
}
}
public static boolean noMask(LocalSession s) {
try {
com.sk89q.worldedit.masks.Mask mask = s.getMask();
return mask == null;
} catch (Throwable e) {
return true;
}
}
public static boolean noMask(LocalSession s) {
try {
com.sk89q.worldedit.masks.Mask mask = s.getMask();
return mask == null;
} catch (Throwable e) {
return true;
}
}
public static void removeMask(Player p, LocalSession s) {
try {
s.setMask(null);
} catch (Throwable e) {
com.sk89q.worldedit.masks.Mask mask = null;
s.setMask(mask);
}
}
public static void removeMask(Player p, LocalSession s) {
try {
s.setMask(null);
} catch (Throwable e) {
com.sk89q.worldedit.masks.Mask mask = null;
s.setMask(mask);
}
}
public static void removeMask(Player p) {
try {
LocalSession s;
if (PlotMain.worldEdit == null) {
s = WorldEdit.getInstance().getSession(p.getName());
} else {
s = PlotMain.worldEdit.getSession(p);
}
removeMask(p, s);
} catch (Exception e) {
// throw new PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY, "WorldEdit == Null?");
}
}
public static void removeMask(Player p) {
try {
LocalSession s;
if (PlotMain.worldEdit == null) {
s = WorldEdit.getInstance().getSession(p.getName());
} else {
s = PlotMain.worldEdit.getSession(p);
}
removeMask(p, s);
} catch (Exception e) {
// throw new
// PlotSquaredException(PlotSquaredException.PlotError.MISSING_DEPENDENCY,
// "WorldEdit == Null?");
}
}
}

View File

@ -26,238 +26,254 @@ import org.bukkit.entity.Player;
/**
* Functions involving players, plots and locations.
*
*
* @author Citymonstret
*
*
*/
@SuppressWarnings("javadoc")
public class PlayerFunctions {
/**
*
* @param player
* player
* @return
*/
public static boolean isInPlot(Player player) {
return getCurrentPlot(player) != null;
}
/**
*
* @param player
* player
* @return
*/
public static boolean isInPlot(Player player) {
return getCurrentPlot(player) != null;
}
/**
*
* @param plot
* plot
* @return
*/
public static boolean hasExpired(Plot plot) {
OfflinePlayer player = Bukkit.getOfflinePlayer(plot.owner);
long lp = player.getLastPlayed();
long cu = System.currentTimeMillis();
return (lp - cu) > 30l;
}
/**
*
* @param plot
* plot
* @return
*/
public static boolean hasExpired(Plot plot) {
OfflinePlayer player = Bukkit.getOfflinePlayer(plot.owner);
long lp = player.getLastPlayed();
long cu = System.currentTimeMillis();
return (lp - cu) > 30l;
}
public static ArrayList<PlotId> getPlotSelectionIds(World world, PlotId pos1, PlotId pos2) {
ArrayList<PlotId> myplots = new ArrayList<PlotId>();
for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) {
myplots.add(new PlotId(x, y));
}
}
public static ArrayList<PlotId> getPlotSelectionIds(World world,
PlotId pos1, PlotId pos2) {
ArrayList<PlotId> myplots = new ArrayList<PlotId>();
for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) {
myplots.add(new PlotId(x, y));
}
}
return myplots;
}
return myplots;
}
public static Plot getBottomPlot(World world, Plot plot) {
if (plot.settings.getMerged(0)) {
return getBottomPlot(world, PlotMain.getPlots(world).get(new PlotId(plot.id.x, plot.id.y - 1)));
}
if (plot.settings.getMerged(3)) {
return getBottomPlot(world, PlotMain.getPlots(world).get(new PlotId(plot.id.x - 1, plot.id.y)));
}
return plot;
}
public static Plot getBottomPlot(World world, Plot plot) {
if (plot.settings.getMerged(0)) {
return getBottomPlot(
world,
PlotMain.getPlots(world).get(
new PlotId(plot.id.x, plot.id.y - 1)));
}
if (plot.settings.getMerged(3)) {
return getBottomPlot(
world,
PlotMain.getPlots(world).get(
new PlotId(plot.id.x - 1, plot.id.y)));
}
return plot;
}
public static Plot getTopPlot(World world, Plot plot) {
if (plot.settings.getMerged(2)) {
return getTopPlot(world, PlotMain.getPlots(world).get(new PlotId(plot.id.x, plot.id.y + 1)));
}
if (plot.settings.getMerged(1)) {
return getTopPlot(world, PlotMain.getPlots(world).get(new PlotId(plot.id.x + 1, plot.id.y)));
}
return plot;
}
public static Plot getTopPlot(World world, Plot plot) {
if (plot.settings.getMerged(2)) {
return getTopPlot(
world,
PlotMain.getPlots(world).get(
new PlotId(plot.id.x, plot.id.y + 1)));
}
if (plot.settings.getMerged(1)) {
return getTopPlot(
world,
PlotMain.getPlots(world).get(
new PlotId(plot.id.x + 1, plot.id.y)));
}
return plot;
}
/**
*
* @param loc
* @return
*/
public static PlotId getPlotAbs(Location loc) {
String world = loc.getWorld().getName();
PlotManager manager = PlotMain.getPlotManager(world);
if (manager == null) {
return null;
}
PlotWorld plotworld = PlotMain.getWorldSettings(world);
return manager.getPlotIdAbs(plotworld, loc);
}
/**
*
* @param loc
* @return
*/
public static PlotId getPlotAbs(Location loc) {
String world = loc.getWorld().getName();
PlotManager manager = PlotMain.getPlotManager(world);
if (manager == null) {
return null;
}
PlotWorld plotworld = PlotMain.getWorldSettings(world);
return manager.getPlotIdAbs(plotworld, loc);
}
public static PlotId getPlot(Location loc) {
String world = loc.getWorld().getName();
PlotManager manager = PlotMain.getPlotManager(world);
if (manager == null) {
return null;
}
PlotWorld plotworld = PlotMain.getWorldSettings(world);
return manager.getPlotId(plotworld, loc);
}
public static PlotId getPlot(Location loc) {
String world = loc.getWorld().getName();
PlotManager manager = PlotMain.getPlotManager(world);
if (manager == null) {
return null;
}
PlotWorld plotworld = PlotMain.getWorldSettings(world);
return manager.getPlotId(plotworld, loc);
}
/**
*
* @param player
* @param plot
*/
public static void togglePlotWeather(Player player, Plot plot) {
player.setPlayerWeather(plot.settings.getRain() ? WeatherType.DOWNFALL : WeatherType.CLEAR);
}
/**
*
* @param player
* @param plot
*/
public static void togglePlotWeather(Player player, Plot plot) {
player.setPlayerWeather(plot.settings.getRain() ? WeatherType.DOWNFALL
: WeatherType.CLEAR);
}
/**
*
* @param player
* @param plot
*/
public static void togglePlotTime(Player player, Plot plot) {
player.setPlayerTime(plot.settings.getTime(), false);
}
/**
*
* @param player
* @param plot
*/
public static void togglePlotTime(Player player, Plot plot) {
player.setPlayerTime(plot.settings.getTime(), false);
}
/**
*
* @param player
* @return
*/
public static Plot getCurrentPlot(Player player) {
if (!PlotMain.isPlotWorld(player.getWorld())) {
return null;
}
PlotId id = getPlot(player.getLocation());
World world = player.getWorld();
if (id == null) {
return null;
}
HashMap<PlotId, Plot> plots = PlotMain.getPlots(world);
if (plots != null) {
if (plots.containsKey(id)) {
return plots.get(id);
}
}
return new Plot(id, null, Biome.FOREST, new ArrayList<UUID>(), new ArrayList<UUID>(), world.getName());
/**
*
* @param player
* @return
*/
public static Plot getCurrentPlot(Player player) {
if (!PlotMain.isPlotWorld(player.getWorld())) {
return null;
}
PlotId id = getPlot(player.getLocation());
World world = player.getWorld();
if (id == null) {
return null;
}
HashMap<PlotId, Plot> plots = PlotMain.getPlots(world);
if (plots != null) {
if (plots.containsKey(id)) {
return plots.get(id);
}
}
return new Plot(id, null, Biome.FOREST, new ArrayList<UUID>(),
new ArrayList<UUID>(), world.getName());
}
}
/**
* @deprecated
* @param id
* @param plot
*/
@Deprecated
public static void set(Integer[] id, Plot plot) {
PlotMain.updatePlot(plot);
}
/**
* @deprecated
* @param id
* @param plot
*/
@Deprecated
public static void set(Integer[] id, Plot plot) {
PlotMain.updatePlot(plot);
}
/**
*
* @param plr
* @return
*/
// public static Set<Plot> getPlayerPlots(Player plr) {
// return PlotMain.getPlots(plr);
// }
//
public static Set<Plot> getPlayerPlots(World world, Player plr) {
Set<Plot> p = PlotMain.getPlots(world, plr);
if (p == null) {
return new HashSet<Plot>();
}
return p;
}
/**
*
* @param plr
* @return
*/
// public static Set<Plot> getPlayerPlots(Player plr) {
// return PlotMain.getPlots(plr);
// }
//
public static Set<Plot> getPlayerPlots(World world, Player plr) {
Set<Plot> p = PlotMain.getPlots(world, plr);
if (p == null) {
return new HashSet<Plot>();
}
return p;
}
/**
*
* @param plr
* @return
*/
// public static int getPlayerPlotCount(Player plr) {
// return getPlayerPlots(plr).size();
// }
//
public static int getPlayerPlotCount(World world, Player plr) {
return getPlayerPlots(world, plr).size();
}
/**
*
* @param plr
* @return
*/
// public static int getPlayerPlotCount(Player plr) {
// return getPlayerPlots(plr).size();
// }
//
public static int getPlayerPlotCount(World world, Player plr) {
return getPlayerPlots(world, plr).size();
}
/**
*
* @param p
* @return
*/
@SuppressWarnings("SuspiciousNameCombination")
public static int getAllowedPlots(Player p) {
return PlotMain.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS);
}
/**
*
* @param p
* @return
*/
@SuppressWarnings("SuspiciousNameCombination")
public static int getAllowedPlots(Player p) {
return PlotMain.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS);
}
/**
*
* @return PlotMain.getPlots();
* @deprecated
*/
@Deprecated
public static Set<Plot> getPlots() {
return PlotMain.getPlots();
}
/**
*
* @return PlotMain.getPlots();
* @deprecated
*/
@Deprecated
public static Set<Plot> getPlots() {
return PlotMain.getPlots();
}
/**
* \\previous\\
*
* @param plr
* @param msg
* Was used to wrap the chat client length (Packets out--)
*/
public static void sendMessageWrapped(Player plr, String msg) {
plr.sendMessage(msg);
}
/**
* \\previous\\
*
* @param plr
* @param msg
* Was used to wrap the chat client length (Packets out--)
*/
public static void sendMessageWrapped(Player plr, String msg) {
plr.sendMessage(msg);
}
/**
* Send a message to the player
*
* @param plr
* Player to recieve message
* @param msg
* Message to send
*/
public static void sendMessage(Player plr, String msg) {
if ((msg.length() == 0) || msg.equalsIgnoreCase("")) {
return;
}
sendMessageWrapped(plr, ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + msg));
}
/**
* Send a message to the player
*
* @param plr
* Player to recieve message
* @param msg
* Message to send
*/
public static void sendMessage(Player plr, String msg) {
if ((msg.length() == 0) || msg.equalsIgnoreCase("")) {
return;
}
sendMessageWrapped(plr,
ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + msg));
}
/**
* Send a message to the player
*
* @param plr
* Player to recieve message
* @param c
* Caption to send
*/
public static void sendMessage(Player plr, C c, String... args) {
if (c.s().length() < 1) {
return;
}
String msg = c.s();
if ((args != null) && (args.length > 0)) {
for (String str : args) {
msg = msg.replaceFirst("%s", str);
}
}
sendMessage(plr, msg);
}
/**
* Send a message to the player
*
* @param plr
* Player to recieve message
* @param c
* Caption to send
*/
public static void sendMessage(Player plr, C c, String... args) {
if (c.s().length() < 1) {
return;
}
String msg = c.s();
if ((args != null) && (args.length > 0)) {
for (String str : args) {
msg = msg.replaceFirst("%s", str);
}
}
sendMessage(plr, msg);
}
}

View File

@ -21,268 +21,286 @@ import com.intellectualcrafters.plot.database.DBFunc;
/**
* The plot class
*
*
* @author Citymonstret
*
*
*/
@SuppressWarnings("javadoc")
public class Plot implements Cloneable {
/**
* plot ID
*/
public PlotId id;
/**
* plot world
*/
public String world;
/**
* plot owner
*/
public UUID owner;
/**
* Deny Entry
*/
public boolean deny_entry;
/**
* List of helpers (with plot permissions)
*/
public ArrayList<UUID> helpers;
/**
* List of trusted users (with plot permissions)
*/
public ArrayList<UUID> trusted;
/**
* List of denied players
*/
public ArrayList<UUID> denied;
/**
* External settings class
*/
public PlotSettings settings;
/**
* Delete on next save cycle?
*/
public boolean delete;
/**
* Has the plot changed since the last save cycle?
*/
public boolean hasChanged = false;
/**
* plot ID
*/
public PlotId id;
/**
* plot world
*/
public String world;
/**
* plot owner
*/
public UUID owner;
/**
* Deny Entry
*/
public boolean deny_entry;
/**
* List of helpers (with plot permissions)
*/
public ArrayList<UUID> helpers;
/**
* List of trusted users (with plot permissions)
*/
public ArrayList<UUID> trusted;
/**
* List of denied players
*/
public ArrayList<UUID> denied;
/**
* External settings class
*/
public PlotSettings settings;
/**
* Delete on next save cycle?
*/
public boolean delete;
/**
* Has the plot changed since the last save cycle?
*/
public boolean hasChanged = false;
/**
* Primary constructor
*
* @param id
* @param owner
* @param plotBiome
* @param helpers
* @param denied
*/
public Plot(PlotId id, UUID owner, Biome plotBiome, ArrayList<UUID> helpers, ArrayList<UUID> denied, String world) {
this.id = id;
this.settings = new PlotSettings(this);
this.settings.setBiome(plotBiome);
this.owner = owner;
this.deny_entry = this.owner == null;
this.helpers = helpers;
this.denied = denied;
this.trusted = new ArrayList<UUID>();
this.settings.setTime(8000l);
this.settings.setRain(false);
this.settings.setTimeChange(false);
this.settings.setAlias("");
this.settings.setPosition(PlotHomePosition.DEFAULT);
this.delete = false;
this.settings.setFlags(new Flag[0]);
this.world = world;
}
/**
* Primary constructor
*
* @param id
* @param owner
* @param plotBiome
* @param helpers
* @param denied
*/
public Plot(PlotId id, UUID owner, Biome plotBiome,
ArrayList<UUID> helpers, ArrayList<UUID> denied, String world) {
this.id = id;
this.settings = new PlotSettings(this);
this.settings.setBiome(plotBiome);
this.owner = owner;
this.deny_entry = this.owner == null;
this.helpers = helpers;
this.denied = denied;
this.trusted = new ArrayList<UUID>();
this.settings.setTime(8000l);
this.settings.setRain(false);
this.settings.setTimeChange(false);
this.settings.setAlias("");
this.settings.setPosition(PlotHomePosition.DEFAULT);
this.delete = false;
this.settings.setFlags(new Flag[0]);
this.world = world;
}
/**
* Constructor for saved plots
*
* @param id
* @param owner
* @param plotBiome
* @param helpers
* @param denied
* @param changeTime
* @param time
* @param merged
*/
public Plot(PlotId id, UUID owner, Biome plotBiome, ArrayList<UUID> helpers, ArrayList<UUID> trusted, ArrayList<UUID> denied, boolean changeTime, long time, boolean rain, String alias, PlotHomePosition position, Flag[] flags, String world, boolean[] merged) {
this.id = id;
this.settings = new PlotSettings(this);
this.settings.setBiome(plotBiome);
this.owner = owner;
this.deny_entry = this.owner != null;
this.trusted = trusted;
this.helpers = helpers;
this.denied = denied;
this.settings.setTime(time);
this.settings.setRain(rain);
this.settings.setTimeChange(changeTime);
this.settings.setAlias(alias);
this.settings.setPosition(position);
this.settings.setMerged(merged);
this.delete = false;
if (flags != null) {
this.settings.setFlags(flags);
} else {
this.settings.setFlags(new Flag[0]);
}
this.world = world;
}
/**
* Constructor for saved plots
*
* @param id
* @param owner
* @param plotBiome
* @param helpers
* @param denied
* @param changeTime
* @param time
* @param merged
*/
public Plot(PlotId id, UUID owner, Biome plotBiome,
ArrayList<UUID> helpers, ArrayList<UUID> trusted,
ArrayList<UUID> denied, boolean changeTime, long time,
boolean rain, String alias, PlotHomePosition position,
Flag[] flags, String world, boolean[] merged) {
this.id = id;
this.settings = new PlotSettings(this);
this.settings.setBiome(plotBiome);
this.owner = owner;
this.deny_entry = this.owner != null;
this.trusted = trusted;
this.helpers = helpers;
this.denied = denied;
this.settings.setTime(time);
this.settings.setRain(rain);
this.settings.setTimeChange(changeTime);
this.settings.setAlias(alias);
this.settings.setPosition(position);
this.settings.setMerged(merged);
this.delete = false;
if (flags != null) {
this.settings.setFlags(flags);
} else {
this.settings.setFlags(new Flag[0]);
}
this.world = world;
}
/**
* Check if the plot has a set owner
*
* @return false if there is no owner
*/
public boolean hasOwner() {
return this.owner != null;
}
/**
* Check if the plot has a set owner
*
* @return false if there is no owner
*/
public boolean hasOwner() {
return this.owner != null;
}
/**
* Set the owner
*
* @param player
*/
public void setOwner(Player player) {
this.owner = player.getUniqueId();
}
/**
* Set the owner
*
* @param player
*/
public void setOwner(Player player) {
this.owner = player.getUniqueId();
}
/**
* Check if the player is either the owner or on the helpers list
*
* @param player
* @return true if the player is added as a helper or is the owner
*/
public boolean hasRights(Player player) {
return player.hasPermission("plots.admin") || ((this.helpers != null) && this.helpers.contains(DBFunc.everyone)) || ((this.helpers != null) && this.helpers.contains(player.getUniqueId())) || ((this.owner != null) && this.owner.equals(player.getUniqueId())) || ((this.owner != null) && (this.trusted != null) && (Bukkit.getPlayer(this.owner) != null) && (this.trusted.contains(player.getUniqueId()) || this.trusted.contains(DBFunc.everyone)));
}
/**
* Check if the player is either the owner or on the helpers list
*
* @param player
* @return true if the player is added as a helper or is the owner
*/
public boolean hasRights(Player player) {
return player.hasPermission("plots.admin")
|| ((this.helpers != null) && this.helpers
.contains(DBFunc.everyone))
|| ((this.helpers != null) && this.helpers.contains(player
.getUniqueId()))
|| ((this.owner != null) && this.owner.equals(player
.getUniqueId()))
|| ((this.owner != null) && (this.trusted != null)
&& (Bukkit.getPlayer(this.owner) != null) && (this.trusted
.contains(player.getUniqueId()) || this.trusted
.contains(DBFunc.everyone)));
}
/**
* Should the player be allowed to enter?
*
* @param player
* @return false if the player is allowed to enter
*/
public boolean deny_entry(Player player) {
return (this.denied != null) && ((this.denied.contains(DBFunc.everyone) && !this.hasRights(player)) || (!this.hasRights(player) && this.denied.contains(player.getUniqueId())));
}
/**
* Should the player be allowed to enter?
*
* @param player
* @return false if the player is allowed to enter
*/
public boolean deny_entry(Player player) {
return (this.denied != null)
&& ((this.denied.contains(DBFunc.everyone) && !this
.hasRights(player)) || (!this.hasRights(player) && this.denied
.contains(player.getUniqueId())));
}
/**
* Get the UUID of the owner
*
*/
public UUID getOwner() {
return this.owner;
}
/**
* Get the UUID of the owner
*
*/
public UUID getOwner() {
return this.owner;
}
/**
* Get the plot ID
*
*/
public PlotId getId() {
return this.id;
}
/**
* Get the plot ID
*
*/
public PlotId getId() {
return this.id;
}
/**
* Get the plot World
*
*/
public World getWorld() {
return Bukkit.getWorld(this.world);
}
/**
* Get the plot World
*
*/
public World getWorld() {
return Bukkit.getWorld(this.world);
}
/**
* Get a clone of the plot
*
* @return
*/
@Override
public Object clone() throws CloneNotSupportedException {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
return null;
}
}
/**
* Get a clone of the plot
*
* @return
*/
@Override
public Object clone() throws CloneNotSupportedException {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
return null;
}
}
/**
* Deny someone (use DBFunc.addDenied() as well)
*
* @param uuid
*/
public void addDenied(UUID uuid) {
this.denied.add(uuid);
}
/**
* Deny someone (use DBFunc.addDenied() as well)
*
* @param uuid
*/
public void addDenied(UUID uuid) {
this.denied.add(uuid);
}
/**
* Add someone as a helper (use DBFunc as well)
*
* @param uuid
*/
public void addHelper(UUID uuid) {
this.helpers.add(uuid);
}
/**
* Add someone as a helper (use DBFunc as well)
*
* @param uuid
*/
public void addHelper(UUID uuid) {
this.helpers.add(uuid);
}
/**
* Add someone as a trusted user (use DBFunc as well)
*
* @param uuid
*/
public void addTrusted(UUID uuid) {
this.trusted.add(uuid);
}
/**
* Add someone as a trusted user (use DBFunc as well)
*
* @param uuid
*/
public void addTrusted(UUID uuid) {
this.trusted.add(uuid);
}
/**
* Get plot display name
*
* @return alias if set, else id
*/
public String getDisplayName() {
if (this.settings.getAlias().length() > 1) {
return this.settings.getAlias();
}
return this.getId().x + ";" + this.getId().y;
}
/**
* Get plot display name
*
* @return alias if set, else id
*/
public String getDisplayName() {
if (this.settings.getAlias().length() > 1) {
return this.settings.getAlias();
}
return this.getId().x + ";" + this.getId().y;
}
/**
* Remove a denied player (use DBFunc as well)
*
* @param uuid
*/
public void removeDenied(UUID uuid) {
this.denied.remove(uuid);
}
/**
* Remove a denied player (use DBFunc as well)
*
* @param uuid
*/
public void removeDenied(UUID uuid) {
this.denied.remove(uuid);
}
/**
* Remove a helper (use DBFunc as well)
*
* @param uuid
*/
public void removeHelper(UUID uuid) {
this.helpers.remove(uuid);
}
/**
* Remove a helper (use DBFunc as well)
*
* @param uuid
*/
public void removeHelper(UUID uuid) {
this.helpers.remove(uuid);
}
/**
* Remove a trusted user (use DBFunc as well)
*
* @param uuid
*/
public void removeTrusted(UUID uuid) {
this.trusted.remove(uuid);
}
/**
* Remove a trusted user (use DBFunc as well)
*
* @param uuid
*/
public void removeTrusted(UUID uuid) {
this.trusted.remove(uuid);
}
/**
* Clear a plot
*
* @param plr
* initiator
*/
public void clear(Player plr) {
PlotHelper.clear(plr, this);
}
/**
* Clear a plot
*
* @param plr
* initiator
*/
public void clear(Player plr) {
PlotHelper.clear(plr, this);
}
}

View File

@ -1,10 +1,11 @@
package com.intellectualcrafters.plot;
public class PlotBlock {
public short id;
public byte data;
public PlotBlock(short id, byte data) {
this.id = id;
this.data = data;
}
public short id;
public byte data;
public PlotBlock(short id, byte data) {
this.id = id;
this.data = data;
}
}

View File

@ -3,8 +3,8 @@ package com.intellectualcrafters.plot;
import org.bukkit.generator.ChunkGenerator;
public abstract class PlotGenerator extends ChunkGenerator {
public abstract PlotWorld getPlotWorld();
public abstract PlotManager getPlotManager();
public abstract PlotWorld getPlotWorld();
public abstract PlotManager getPlotManager();
}

File diff suppressed because it is too large Load Diff

View File

@ -13,24 +13,24 @@ package com.intellectualcrafters.plot;
* Created by Citymonstret on 2014-08-05.
*/
public enum PlotHomePosition {
CENTER("Center", 'c'), DEFAULT("Default", 'd');
CENTER("Center", 'c'), DEFAULT("Default", 'd');
private String string;
private char ch;
private String string;
private char ch;
PlotHomePosition(String string, char ch) {
this.string = string;
this.ch = ch;
}
PlotHomePosition(String string, char ch) {
this.string = string;
this.ch = ch;
}
public boolean isMatching(String string) {
if ((string.length() < 2) && (string.charAt(0) == this.ch)) {
return true;
}
if (string.equalsIgnoreCase(this.string)) {
return true;
}
return false;
}
public boolean isMatching(String string) {
if ((string.length() < 2) && (string.charAt(0) == this.ch)) {
return true;
}
if (string.equalsIgnoreCase(this.string)) {
return true;
}
return false;
}
}

View File

@ -1,54 +1,54 @@
package com.intellectualcrafters.plot;
public class PlotId {
/**
* x value
*/
public Integer x;
/**
* y value
*/
public Integer y;
/**
* x value
*/
public Integer x;
/**
* y value
*/
public Integer y;
/**
* PlotId class (PlotId x,y values do not correspond to Block locations)
*
* @param x
* The plot x coordinate
* @param y
* The plot y coordinate
*/
public PlotId(int x, int y) {
this.x = x;
this.y = y;
}
/**
* PlotId class (PlotId x,y values do not correspond to Block locations)
*
* @param x
* The plot x coordinate
* @param y
* The plot y coordinate
*/
public PlotId(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
PlotId other = (PlotId) obj;
return ((this.x == other.x) && (this.y == other.y));
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
PlotId other = (PlotId) obj;
return ((this.x == other.x) && (this.y == other.y));
}
@Override
public String toString() {
return this.x + ";" + this.y;
}
@Override
public String toString() {
return this.x + ";" + this.y;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = (prime * result) + this.x;
result = (prime * result) + this.y;
return result;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = (prime * result) + this.x;
result = (prime * result) + this.y;
return result;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -5,63 +5,68 @@ import java.util.ArrayList;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
public abstract class PlotManager {
/*
* Plot locations (methods with Abs in them will not need to consider mega
* plots)
*/
/*
* Plot locations (methods with Abs in them will not need to consider mega
* plots)
*/
public abstract PlotId getPlotIdAbs(PlotWorld plotworld, Location loc);
public abstract PlotId getPlotId(PlotWorld plotworld, Location loc);
public abstract PlotId getPlotIdAbs(PlotWorld plotworld, Location loc);
public abstract boolean isInPlotAbs(PlotWorld plotworld, Location loc, PlotId plotid);
// If you have a circular plot, just return the corner if it were a square
public abstract Location getPlotBottomLocAbs(PlotWorld plotworld, PlotId plotid);
// the same applies here
public abstract Location getPlotTopLocAbs(PlotWorld plotworld, PlotId plotid);
/*
* Plot clearing (return false if you do not support some method)
*
*
*/
public abstract PlotId getPlotId(PlotWorld plotworld, Location loc);
public abstract boolean clearPlot(Player player, Plot plot);
public abstract boolean isInPlotAbs(PlotWorld plotworld, Location loc,
PlotId plotid);
public abstract Location getSignLoc(Player player, PlotWorld plotworld, Plot plot);
// If you have a circular plot, just return the corner if it were a square
public abstract Location getPlotBottomLocAbs(PlotWorld plotworld,
PlotId plotid);
/*
* Plot set functions (return false if you do not support the specific set
* method)
*/
// the same applies here
public abstract Location getPlotTopLocAbs(PlotWorld plotworld, PlotId plotid);
public abstract boolean setWall(Player player, PlotWorld plotworld, PlotId plotid, PlotBlock block);
public abstract boolean setFloor(Player player, PlotWorld plotworld, PlotId plotid, PlotBlock[] block);
/*
* Plot clearing (return false if you do not support some method)
*/
public abstract boolean setBiome(Player player, Plot plot, Biome biome);
public abstract boolean clearPlot(Player player, Plot plot);
/*
* PLOT MERGING (return false if your generator does not support plot
* merging)
*/
public abstract boolean createRoadEast(PlotWorld plotworld, Plot plot);
public abstract Location getSignLoc(Player player, PlotWorld plotworld,
Plot plot);
public abstract boolean createRoadSouth(PlotWorld plotworld, Plot plot);
/*
* Plot set functions (return false if you do not support the specific set
* method)
*/
public abstract boolean createRoadSouthEast(PlotWorld plotworld, Plot plot);
public abstract boolean setWall(Player player, PlotWorld plotworld,
PlotId plotid, PlotBlock block);
public abstract boolean removeRoadEast(PlotWorld plotworld, Plot plot);
public abstract boolean setFloor(Player player, PlotWorld plotworld,
PlotId plotid, PlotBlock[] block);
public abstract boolean removeRoadSouth(PlotWorld plotworld, Plot plot);
public abstract boolean setBiome(Player player, Plot plot, Biome biome);
public abstract boolean removeRoadSouthEast(PlotWorld plotworld, Plot plot);
public abstract boolean finishPlotMerge(World world, PlotWorld plotworld, ArrayList<PlotId> plotIds);
/*
* PLOT MERGING (return false if your generator does not support plot
* merging)
*/
public abstract boolean createRoadEast(PlotWorld plotworld, Plot plot);
public abstract boolean createRoadSouth(PlotWorld plotworld, Plot plot);
public abstract boolean createRoadSouthEast(PlotWorld plotworld, Plot plot);
public abstract boolean removeRoadEast(PlotWorld plotworld, Plot plot);
public abstract boolean removeRoadSouth(PlotWorld plotworld, Plot plot);
public abstract boolean removeRoadSouthEast(PlotWorld plotworld, Plot plot);
public abstract boolean finishPlotMerge(World world, PlotWorld plotworld,
ArrayList<PlotId> plotIds);
}

View File

@ -17,209 +17,209 @@ import org.bukkit.block.Biome;
/**
* plot settings
*
*
* @author Citymonstret
*
*
*/
public class PlotSettings {
/**
* merged plots
*/
private boolean[] merged = new boolean[] { false, false, false, false };
/**
* plot alias
*/
private String alias;
/**
* plot biome
*/
private Biome biome;
/**
* plot rain
*/
private boolean rain;
/**
*
*/
private Set<Flag> flags;
/**
* plot time
*/
private Long time;
/**
* Change time?
*/
private boolean changeTime;
private PlotHomePosition position;
/**
* merged plots
*/
private boolean[] merged = new boolean[] { false, false, false, false };
/**
* plot alias
*/
private String alias;
/**
* plot biome
*/
private Biome biome;
/**
* plot rain
*/
private boolean rain;
/**
*
*/
private Set<Flag> flags;
/**
* plot time
*/
private Long time;
/**
* Change time?
*/
private boolean changeTime;
private PlotHomePosition position;
/**
* Constructor
*
* @param plot
*/
public PlotSettings(Plot plot) {
this.alias = "";
}
/**
* Constructor
*
* @param plot
*/
public PlotSettings(Plot plot) {
this.alias = "";
}
/**
* <b>Check if the plot is merged in a direction</b><br>
* 0 = North<br>
* 1 = East<br>
* 2 = South<br>
* 3 = West<br>
*
* @param direction
* @return boolean
*/
public boolean getMerged(int direction) {
return this.merged[direction];
}
/**
* <b>Check if the plot is merged in a direction</b><br>
* 0 = North<br>
* 1 = East<br>
* 2 = South<br>
* 3 = West<br>
*
* @param direction
* @return boolean
*/
public boolean getMerged(int direction) {
return this.merged[direction];
}
public boolean isMerged() {
return (this.merged[0] || this.merged[1] || this.merged[2] || this.merged[3]);
}
public boolean isMerged() {
return (this.merged[0] || this.merged[1] || this.merged[2] || this.merged[3]);
}
public boolean[] getMerged() {
return this.merged;
}
public boolean[] getMerged() {
return this.merged;
}
public void setMerged(boolean[] merged) {
this.merged = merged;
}
public void setMerged(boolean[] merged) {
this.merged = merged;
}
public void setMerged(int direction, boolean merged) {
this.merged[direction] = merged;
}
public void setMerged(int direction, boolean merged) {
this.merged[direction] = merged;
}
/**
*
* @param b
*/
public void setBiome(Biome b) {
this.biome = b;
}
/**
*
* @param b
*/
public void setBiome(Biome b) {
this.biome = b;
}
/**
*
* @param b
*/
public void setTimeChange(boolean b) {
this.changeTime = b;
}
/**
*
* @param b
*/
public void setTimeChange(boolean b) {
this.changeTime = b;
}
/**
*
* @param l
*/
public void setTime(long l) {
this.time = l;
}
/**
*
* @param l
*/
public void setTime(long l) {
this.time = l;
}
/**
*
* @return
* @deprecated
*/
@Deprecated
public Biome getBiome() {
return this.biome;
}
/**
*
* @return
* @deprecated
*/
@Deprecated
public Biome getBiome() {
return this.biome;
}
/**
*
* @return
*/
public boolean getRain() {
return this.rain;
}
/**
*
* @return
*/
public boolean getRain() {
return this.rain;
}
public void setRain(boolean b) {
this.rain = b;
}
public void setRain(boolean b) {
this.rain = b;
}
/**
*
* @return
*/
public long getTime() {
return this.time;
}
/**
*
* @return
*/
public long getTime() {
return this.time;
}
/**
*
* @return
*/
public boolean getChangeTime() {
return this.changeTime;
}
/**
*
* @return
*/
public boolean getChangeTime() {
return this.changeTime;
}
/**
*
* @param alias
*/
public void setAlias(String alias) {
this.alias = alias;
}
/**
*
* @param alias
*/
public void setAlias(String alias) {
this.alias = alias;
}
/**
*
* @param flag
*/
public void addFlag(Flag flag) {
Flag hasFlag = getFlag(flag.getKey());
if (hasFlag != null) {
this.flags.remove(hasFlag);
}
this.flags.add(flag);
}
/**
*
* @param flag
*/
public void addFlag(Flag flag) {
Flag hasFlag = getFlag(flag.getKey());
if (hasFlag != null) {
this.flags.remove(hasFlag);
}
this.flags.add(flag);
}
/**
*
* @param flags
*/
public void setFlags(Flag[] flags) {
this.flags = new HashSet<Flag>(Arrays.asList(flags));
}
/**
*
* @param flags
*/
public void setFlags(Flag[] flags) {
this.flags = new HashSet<Flag>(Arrays.asList(flags));
}
/**
*
* @return
*/
public Set<Flag> getFlags() {
return this.flags;
}
/**
*
* @return
*/
public Set<Flag> getFlags() {
return this.flags;
}
/**
*
* @param flag
* @return
*/
public Flag getFlag(String flag) {
for (Flag myflag : this.flags) {
if (myflag.getKey().equals(flag)) {
return myflag;
}
}
return null;
}
/**
*
* @param flag
* @return
*/
public Flag getFlag(String flag) {
for (Flag myflag : this.flags) {
if (myflag.getKey().equals(flag)) {
return myflag;
}
}
return null;
}
public PlotHomePosition getPosition() {
return this.position;
}
public PlotHomePosition getPosition() {
return this.position;
}
public void setPosition(PlotHomePosition position) {
this.position = position;
}
public void setPosition(PlotHomePosition position) {
this.position = position;
}
public String getAlias() {
return this.alias;
}
public String getAlias() {
return this.alias;
}
public String getJoinMessage() {
return "";
}
public String getJoinMessage() {
return "";
}
public String getLeaveMessage() {
return "";
}
public String getLeaveMessage() {
return "";
}
}

View File

@ -5,26 +5,27 @@ package com.intellectualcrafters.plot;
*/
public class PlotSquaredException extends RuntimeException {
public PlotSquaredException(PlotError error, String details) {
super("PlotError >> " + error.getHeader() + ": " + details);
PlotMain.sendConsoleSenderMessage("&cPlotError &6>> &c" + error.getHeader() + ": &6" + details);
}
public PlotSquaredException(PlotError error, String details) {
super("PlotError >> " + error.getHeader() + ": " + details);
PlotMain.sendConsoleSenderMessage("&cPlotError &6>> &c"
+ error.getHeader() + ": &6" + details);
}
public static enum PlotError {
MISSING_DEPENDENCY("Missing Dependency");
private String errorHeader;
public static enum PlotError {
MISSING_DEPENDENCY("Missing Dependency");
private String errorHeader;
PlotError(String errorHeader) {
this.errorHeader = errorHeader;
}
PlotError(String errorHeader) {
this.errorHeader = errorHeader;
}
public String getHeader() {
return this.errorHeader;
}
public String getHeader() {
return this.errorHeader;
}
@Override
public String toString() {
return this.getHeader();
}
}
@Override
public String toString() {
return this.getHeader();
}
}
}

View File

@ -1,109 +1,229 @@
package com.intellectualcrafters.plot;
import static org.bukkit.Material.ACACIA_STAIRS;
import static org.bukkit.Material.BEACON;
import static org.bukkit.Material.BEDROCK;
import static org.bukkit.Material.BIRCH_WOOD_STAIRS;
import static org.bukkit.Material.BOOKSHELF;
import static org.bukkit.Material.BREWING_STAND;
import static org.bukkit.Material.BRICK;
import static org.bukkit.Material.BRICK_STAIRS;
import static org.bukkit.Material.BURNING_FURNACE;
import static org.bukkit.Material.CAKE_BLOCK;
import static org.bukkit.Material.CAULDRON;
import static org.bukkit.Material.CLAY;
import static org.bukkit.Material.CLAY_BRICK;
import static org.bukkit.Material.COAL_BLOCK;
import static org.bukkit.Material.COAL_ORE;
import static org.bukkit.Material.COBBLESTONE;
import static org.bukkit.Material.COBBLESTONE_STAIRS;
import static org.bukkit.Material.COBBLE_WALL;
import static org.bukkit.Material.COMMAND;
import static org.bukkit.Material.DARK_OAK_STAIRS;
import static org.bukkit.Material.DAYLIGHT_DETECTOR;
import static org.bukkit.Material.DIAMOND_BLOCK;
import static org.bukkit.Material.DIAMOND_ORE;
import static org.bukkit.Material.DIRT;
import static org.bukkit.Material.DISPENSER;
import static org.bukkit.Material.DROPPER;
import static org.bukkit.Material.EMERALD_BLOCK;
import static org.bukkit.Material.EMERALD_ORE;
import static org.bukkit.Material.ENCHANTMENT_TABLE;
import static org.bukkit.Material.ENDER_PORTAL_FRAME;
import static org.bukkit.Material.ENDER_STONE;
import static org.bukkit.Material.FURNACE;
import static org.bukkit.Material.GLASS;
import static org.bukkit.Material.GLOWSTONE;
import static org.bukkit.Material.GOLD_BLOCK;
import static org.bukkit.Material.GOLD_ORE;
import static org.bukkit.Material.GRASS;
import static org.bukkit.Material.GRAVEL;
import static org.bukkit.Material.HARD_CLAY;
import static org.bukkit.Material.HAY_BLOCK;
import static org.bukkit.Material.HUGE_MUSHROOM_1;
import static org.bukkit.Material.HUGE_MUSHROOM_2;
import static org.bukkit.Material.IRON_BLOCK;
import static org.bukkit.Material.IRON_ORE;
import static org.bukkit.Material.JACK_O_LANTERN;
import static org.bukkit.Material.JUKEBOX;
import static org.bukkit.Material.JUNGLE_WOOD_STAIRS;
import static org.bukkit.Material.LAPIS_BLOCK;
import static org.bukkit.Material.LAPIS_ORE;
import static org.bukkit.Material.LEAVES;
import static org.bukkit.Material.LEAVES_2;
import static org.bukkit.Material.LOG;
import static org.bukkit.Material.LOG_2;
import static org.bukkit.Material.MELON_BLOCK;
import static org.bukkit.Material.MOB_SPAWNER;
import static org.bukkit.Material.MOSSY_COBBLESTONE;
import static org.bukkit.Material.MYCEL;
import static org.bukkit.Material.NETHERRACK;
import static org.bukkit.Material.NETHER_BRICK;
import static org.bukkit.Material.NETHER_BRICK_STAIRS;
import static org.bukkit.Material.NOTE_BLOCK;
import static org.bukkit.Material.OBSIDIAN;
import static org.bukkit.Material.PACKED_ICE;
import static org.bukkit.Material.PUMPKIN;
import static org.bukkit.Material.QUARTZ_BLOCK;
import static org.bukkit.Material.QUARTZ_ORE;
import static org.bukkit.Material.QUARTZ_STAIRS;
import static org.bukkit.Material.REDSTONE_BLOCK;
import static org.bukkit.Material.SAND;
import static org.bukkit.Material.SANDSTONE;
import static org.bukkit.Material.SANDSTONE_STAIRS;
import static org.bukkit.Material.SMOOTH_BRICK;
import static org.bukkit.Material.SMOOTH_STAIRS;
import static org.bukkit.Material.SNOW_BLOCK;
import static org.bukkit.Material.SOUL_SAND;
import static org.bukkit.Material.SPONGE;
import static org.bukkit.Material.SPRUCE_WOOD_STAIRS;
import static org.bukkit.Material.STONE;
import static org.bukkit.Material.WOOD;
import static org.bukkit.Material.WOOD_STAIRS;
import static org.bukkit.Material.WOOL;
import static org.bukkit.Material.WORKBENCH;
import static org.bukkit.Material.getMaterial;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.configuration.ConfigurationSection;
public abstract class PlotWorld {
public boolean AUTO_MERGE;
public static boolean AUTO_MERGE_DEFAULT = false;
public boolean MOB_SPAWNING;
public static boolean MOB_SPAWNING_DEFAULT = false;
public Biome PLOT_BIOME;
public static Biome PLOT_BIOME_DEFAULT = Biome.FOREST;
public boolean PLOT_CHAT;
public static boolean PLOT_CHAT_DEFAULT = false;
public boolean SCHEMATIC_CLAIM_SPECIFY = false;
public static boolean SCHEMATIC_CLAIM_SPECIFY_DEFAULT = false;
public boolean SCHEMATIC_ON_CLAIM;
public static boolean SCHEMATIC_ON_CLAIM_DEFAULT = false;
public String SCHEMATIC_FILE;
public static String SCHEMATIC_FILE_DEFAULT = "null";
public List<String> SCHEMATICS;
public static List<String> SCHEMATICS_DEFAULT = null;
public List<String> DEFAULT_FLAGS;
public static List<String> DEFAULT_FLAGS_DEFAULT = new ArrayList<String>();
public boolean USE_ECONOMY;
public static boolean USE_ECONOMY_DEFAULT = false;
public double PLOT_PRICE;
public static double PLOT_PRICE_DEFAULT = 100;
public double MERGE_PRICE;
public static double MERGE_PRICE_DEFAULT = 100;
public PlotWorld(String worldname) {
this.worldname = worldname;
}
/**
* When a world is created, the following method will be called for each node set in the configuration
* - You may ignore this if you generator does not support configuration, or if you want to implement your own methods
*
* @param key
* @param value
*/
public void loadConfiguration(ConfigurationSection config) {
this.MOB_SPAWNING = config.getBoolean("natural_mob_spawning");
this.AUTO_MERGE = config.getBoolean("plot.auto_merge");
this.PLOT_BIOME = (Biome) Configuration.BIOME.parseString(config.getString("plot.biome"));
this.SCHEMATIC_ON_CLAIM = config.getBoolean("schematic.on_claim");
this.SCHEMATIC_FILE = config.getString("schematic.file");
this.SCHEMATIC_CLAIM_SPECIFY = config.getBoolean("schematic.specify_on_claim");
this.SCHEMATICS = config.getStringList("schematic.schematics");
this.USE_ECONOMY = config.getBoolean("economy.use");
this.PLOT_PRICE = config.getDouble("economy.prices.claim");
this.MERGE_PRICE = config.getDouble("economy.prices.merge");
this.PLOT_CHAT = config.getBoolean("chat.enabled");
this.DEFAULT_FLAGS = config.getStringList("flags.default");
}
public void saveConfiguration(ConfigurationSection config) {
/*
* Saving core plotworld settings
*/
config.set("natural_mob_spawning",this.MOB_SPAWNING);
config.set("plot.auto_merge",this.AUTO_MERGE);
config.set("plot.biome",this.PLOT_BIOME.name());
config.set("schematic.on_claim",this.SCHEMATIC_ON_CLAIM);
config.set("schematic.file",this.SCHEMATIC_FILE);
config.set("schematic.specify_on_claim",this.SCHEMATIC_CLAIM_SPECIFY);
config.set("schematic.schematics",this.SCHEMATICS);
config.set("economy.use",this.USE_ECONOMY);
config.set("economy.prices.claim",this.PLOT_PRICE);
config.set("economy.prices.merge",this.MERGE_PRICE);
config.set("chat.enabled",this.PLOT_CHAT);
config.set("flags.default",this.DEFAULT_FLAGS);
ConfigurationNode[] settings = getSettingNodes();
/*
* Saving generator specific settings
*/
for (ConfigurationNode setting:settings) {
config.set(setting.getConstant(), setting.getValue());
}
}
public String worldname;
// TODO make this configurable
// make non static and static_default_valu + add config option
public static ArrayList<Material> BLOCKS = new ArrayList<Material>(
Arrays.asList(new Material[] { ACACIA_STAIRS, BEACON, BEDROCK,
BIRCH_WOOD_STAIRS, BOOKSHELF, BREWING_STAND, BRICK,
BRICK_STAIRS, BURNING_FURNACE, CAKE_BLOCK, CAULDRON,
CLAY_BRICK, CLAY, COAL_BLOCK, COAL_ORE, COBBLE_WALL,
COBBLESTONE, COBBLESTONE_STAIRS, COMMAND, DARK_OAK_STAIRS,
DAYLIGHT_DETECTOR, DIAMOND_ORE, DIAMOND_BLOCK, DIRT,
DISPENSER, DROPPER, EMERALD_BLOCK, EMERALD_ORE,
ENCHANTMENT_TABLE, ENDER_PORTAL_FRAME, ENDER_STONE,
FURNACE, GLOWSTONE, GOLD_ORE, GOLD_BLOCK, GRASS, GRAVEL,
GLASS, HARD_CLAY, HAY_BLOCK, HUGE_MUSHROOM_1,
HUGE_MUSHROOM_2, IRON_BLOCK, IRON_ORE, JACK_O_LANTERN,
JUKEBOX, JUNGLE_WOOD_STAIRS, LAPIS_BLOCK, LAPIS_ORE,
LEAVES, LEAVES_2, LOG, LOG_2, MELON_BLOCK, MOB_SPAWNER,
MOSSY_COBBLESTONE, MYCEL, NETHER_BRICK,
NETHER_BRICK_STAIRS, NETHERRACK, NOTE_BLOCK, OBSIDIAN,
PACKED_ICE, PUMPKIN, QUARTZ_BLOCK, QUARTZ_ORE,
QUARTZ_STAIRS, REDSTONE_BLOCK, SANDSTONE, SAND,
SANDSTONE_STAIRS, SMOOTH_BRICK, SMOOTH_STAIRS, SNOW_BLOCK,
SOUL_SAND, SPONGE, SPRUCE_WOOD_STAIRS, STONE, WOOD,
WOOD_STAIRS, WORKBENCH, WOOL, getMaterial(44),
getMaterial(126) }));
/**
* Used for the <b>/plot setup</b> command
* Return null if you do not want to support this feature
*
* @return ConfigurationNode[]
*/
public abstract ConfigurationNode[] getSettingNodes();
public boolean AUTO_MERGE;
public static boolean AUTO_MERGE_DEFAULT = false;
public boolean MOB_SPAWNING;
public static boolean MOB_SPAWNING_DEFAULT = false;
public Biome PLOT_BIOME;
public static Biome PLOT_BIOME_DEFAULT = Biome.FOREST;
public boolean PLOT_CHAT;
public static boolean PLOT_CHAT_DEFAULT = false;
public boolean SCHEMATIC_CLAIM_SPECIFY = false;
public static boolean SCHEMATIC_CLAIM_SPECIFY_DEFAULT = false;
public boolean SCHEMATIC_ON_CLAIM;
public static boolean SCHEMATIC_ON_CLAIM_DEFAULT = false;
public String SCHEMATIC_FILE;
public static String SCHEMATIC_FILE_DEFAULT = "null";
public List<String> SCHEMATICS;
public static List<String> SCHEMATICS_DEFAULT = null;
public List<String> DEFAULT_FLAGS;
public static List<String> DEFAULT_FLAGS_DEFAULT = new ArrayList<String>();
public boolean USE_ECONOMY;
public static boolean USE_ECONOMY_DEFAULT = false;
public double PLOT_PRICE;
public static double PLOT_PRICE_DEFAULT = 100;
public double MERGE_PRICE;
public static double MERGE_PRICE_DEFAULT = 100;
public double SELL_PRICE;
public static double SELL_PRICE_DEFAULT = 75;
public PlotWorld(String worldname) {
this.worldname = worldname;
}
/**
* When a world is created, the following method will be called for each
* node set in the configuration - You may ignore this if you generator does
* not support configuration, or if you want to implement your own methods
*
* @param key
* @param value
*/
public void loadConfiguration(ConfigurationSection config) {
this.MOB_SPAWNING = config.getBoolean("natural_mob_spawning");
this.AUTO_MERGE = config.getBoolean("plot.auto_merge");
this.PLOT_BIOME = (Biome) Configuration.BIOME.parseString(config
.getString("plot.biome"));
this.SCHEMATIC_ON_CLAIM = config.getBoolean("schematic.on_claim");
this.SCHEMATIC_FILE = config.getString("schematic.file");
this.SCHEMATIC_CLAIM_SPECIFY = config
.getBoolean("schematic.specify_on_claim");
this.SCHEMATICS = config.getStringList("schematic.schematics");
this.USE_ECONOMY = config.getBoolean("economy.use");
this.PLOT_PRICE = config.getDouble("economy.prices.claim");
this.MERGE_PRICE = config.getDouble("economy.prices.merge");
this.SELL_PRICE = config.getDouble("economy.prices.sell");
this.PLOT_CHAT = config.getBoolean("chat.enabled");
this.DEFAULT_FLAGS = config.getStringList("flags.default");
}
public void saveConfiguration(ConfigurationSection config) {
/*
* Saving core plotworld settings
*/
config.set("natural_mob_spawning", this.MOB_SPAWNING);
config.set("plot.auto_merge", this.AUTO_MERGE);
config.set("plot.biome", this.PLOT_BIOME.name());
config.set("schematic.on_claim", this.SCHEMATIC_ON_CLAIM);
config.set("schematic.file", this.SCHEMATIC_FILE);
config.set("schematic.specify_on_claim", this.SCHEMATIC_CLAIM_SPECIFY);
config.set("schematic.schematics", this.SCHEMATICS);
config.set("economy.use", this.USE_ECONOMY);
config.set("economy.prices.claim", this.PLOT_PRICE);
config.set("economy.prices.merge", this.MERGE_PRICE);
config.set("economy.prices.sell", this.SELL_PRICE);
config.set("chat.enabled", this.PLOT_CHAT);
config.set("flags.default", this.DEFAULT_FLAGS);
ConfigurationNode[] settings = getSettingNodes();
/*
* Saving generator specific settings
*/
for (ConfigurationNode setting : settings) {
config.set(setting.getConstant(), setting.getValue());
}
}
public String worldname;
/**
* Used for the <b>/plot setup</b> command Return null if you do not want to
* support this feature
*
* @return ConfigurationNode[]
*/
public abstract ConfigurationNode[] getSettingNodes();
}

View File

@ -14,76 +14,77 @@ import org.bukkit.entity.Player;
/**
* Random utilities
*
*
* @author Citymonstret
*
*
*/
public class RUtils {
public static long getTotalRam() {
return (Runtime.getRuntime().maxMemory() / 1024) / 1024;
}
public static long getTotalRam() {
return (Runtime.getRuntime().maxMemory() / 1024) / 1024;
}
public static long getFreeRam() {
return (Runtime.getRuntime().freeMemory() / 1024) / 1024;
}
public static long getFreeRam() {
return (Runtime.getRuntime().freeMemory() / 1024) / 1024;
}
public static long getRamPercentage() {
return (getFreeRam() / getTotalRam()) * 100;
}
public static long getRamPercentage() {
return (getFreeRam() / getTotalRam()) * 100;
}
public static String formatTime(double sec) {
double h = sec / 3600;
double m = (sec % 3600) / 60;
double s = sec % 60;
String string = C.TIME_FORMAT.s();
public static String formatTime(double sec) {
double h = sec / 3600;
double m = (sec % 3600) / 60;
double s = sec % 60;
String string = C.TIME_FORMAT.s();
@SuppressWarnings("unused")
// String s_d = (int) d + " " + (d != 1 ? "days" : "day");
String s_h = (int) h + " " + ((int) h != 1 ? "hours" : "hour");
String s_m = (int) m + " " + ((int) m != 1 ? "minutes" : "minute");
String s_s = (int) s + " " + ((int) s != 1 ? "seconds" : "second");
return string.replaceAll("%sec%", s_s).replaceAll("%min%", s_m).replaceAll("%hours%", s_h);
}
@SuppressWarnings("unused")
// String s_d = (int) d + " " + (d != 1 ? "days" : "day");
String s_h = (int) h + " " + ((int) h != 1 ? "hours" : "hour");
String s_m = (int) m + " " + ((int) m != 1 ? "minutes" : "minute");
String s_s = (int) s + " " + ((int) s != 1 ? "seconds" : "second");
return string.replaceAll("%sec%", s_s).replaceAll("%min%", s_m)
.replaceAll("%hours%", s_h);
}
enum Direction {
SOUTH(0), EAST(1), NORTH(2), WEST(3);
private int i;
enum Direction {
SOUTH(0), EAST(1), NORTH(2), WEST(3);
private int i;
Direction(int i) {
this.i = i;
}
Direction(int i) {
this.i = i;
}
public int getInt() {
return this.i;
}
}
public int getInt() {
return this.i;
}
}
public void forceTexture(Player p) {
p.setResourcePack(Settings.PLOT_SPECIFIC_RESOURCE_PACK);
}
public void forceTexture(Player p) {
p.setResourcePack(Settings.PLOT_SPECIFIC_RESOURCE_PACK);
}
public Direction getDirection(Location l) {
double d = ((l.getYaw() * 4.0F) / 360.0F) + 0.5D;
int i = (int) d;
int x = d < i ? i - 1 : i;
public Direction getDirection(Location l) {
double d = ((l.getYaw() * 4.0F) / 360.0F) + 0.5D;
int i = (int) d;
int x = d < i ? i - 1 : i;
switch (x) {
case 0:
return Direction.SOUTH;
case 1:
return Direction.EAST;
case 2:
return Direction.NORTH;
case 3:
return Direction.WEST;
default:
return null;
}
}
switch (x) {
case 0:
return Direction.SOUTH;
case 1:
return Direction.EAST;
case 2:
return Direction.NORTH;
case 3:
return Direction.WEST;
default:
return null;
}
}
public boolean compareDirections(Location l1, Location l2) {
return getDirection(l1) == getDirection(l2);
}
public boolean compareDirections(Location l1, Location l2) {
return getDirection(l1) == getDirection(l2);
}
}

View File

@ -24,154 +24,166 @@ import com.sk89q.worldedit.bukkit.BukkitWorld;
*/
public class SchematicHandler {
@SuppressWarnings("deprecation")
public boolean paste(Location location, Schematic schematic, Plot plot) {
if (schematic == null) {
PlotMain.sendConsoleSenderMessage("Schematic == null :|");
return false;
}
try {
EditSession session = new EditSession(new BukkitWorld(location.getWorld()), 999999999);
CuboidClipboard clipboard = CuboidClipboard.loadSchematic(schematic.getFile());
Location l1 = PlotHelper.getPlotBottomLoc(plot.getWorld(), plot.getId());
PlotHelper.getPlotTopLoc(plot.getWorld(), plot.getId());
int x = l1.getBlockX() + 1;
int z = l1.getBlockZ() + 1;
int y = location.getWorld().getHighestBlockYAt(x,z);
Vector v1 = new Vector(x, y+1, z);
clipboard.paste(session, v1, true);
} catch (Exception e) {
return false;
}
return true;
}
@SuppressWarnings("deprecation")
public boolean paste(Location location, Schematic schematic, Plot plot) {
if (schematic == null) {
PlotMain.sendConsoleSenderMessage("Schematic == null :|");
return false;
}
try {
EditSession session = new EditSession(new BukkitWorld(
location.getWorld()), 999999999);
CuboidClipboard clipboard = CuboidClipboard.loadSchematic(schematic
.getFile());
Location l1 = PlotHelper.getPlotBottomLoc(plot.getWorld(),
plot.getId());
PlotHelper.getPlotTopLoc(plot.getWorld(), plot.getId());
int x = l1.getBlockX() + 1;
int z = l1.getBlockZ() + 1;
int y = location.getWorld().getHighestBlockYAt(x, z);
Vector v1 = new Vector(x, y + 1, z);
clipboard.paste(session, v1, true);
} catch (Exception e) {
return false;
}
return true;
}
public Schematic getSchematic(String name) {
{
File parent = new File(JavaPlugin.getPlugin(PlotMain.class).getDataFolder() + File.separator + "schematics");
if (!parent.exists()) {
parent.mkdir();
}
}
File file = new File(JavaPlugin.getPlugin(PlotMain.class).getDataFolder() + File.separator + "schematics" + File.separator + name + ".schematic");
if (!file.exists()) {
PlotMain.sendConsoleSenderMessage(file.toString() + " doesn't exist");
return null;
}
public Schematic getSchematic(String name) {
{
File parent = new File(JavaPlugin.getPlugin(PlotMain.class)
.getDataFolder() + File.separator + "schematics");
if (!parent.exists()) {
parent.mkdir();
}
}
File file = new File(JavaPlugin.getPlugin(PlotMain.class)
.getDataFolder()
+ File.separator
+ "schematics"
+ File.separator + name + ".schematic");
if (!file.exists()) {
PlotMain.sendConsoleSenderMessage(file.toString()
+ " doesn't exist");
return null;
}
Schematic schematic = null;
try {
InputStream iStream = new FileInputStream(file);
NBTInputStream stream = new NBTInputStream(new GZIPInputStream(iStream));
CompoundTag tag = (CompoundTag) stream.readTag();
Map<String, Tag> tagMap = tag.getValue();
Schematic schematic = null;
try {
InputStream iStream = new FileInputStream(file);
NBTInputStream stream = new NBTInputStream(new GZIPInputStream(
iStream));
CompoundTag tag = (CompoundTag) stream.readTag();
Map<String, Tag> tagMap = tag.getValue();
byte[] addId = new byte[0];
if (tagMap.containsKey("AddBlocks")) {
addId = ByteArrayTag.class.cast(tagMap.get("AddBlocks")).getValue();
}
byte[] addId = new byte[0];
if (tagMap.containsKey("AddBlocks")) {
addId = ByteArrayTag.class.cast(tagMap.get("AddBlocks"))
.getValue();
}
short width = ShortTag.class.cast(tagMap.get("Width")).getValue();
short length = ShortTag.class.cast(tagMap.get("Length")).getValue();
short height = ShortTag.class.cast(tagMap.get("Height")).getValue();
short width = ShortTag.class.cast(tagMap.get("Width")).getValue();
short length = ShortTag.class.cast(tagMap.get("Length")).getValue();
short height = ShortTag.class.cast(tagMap.get("Height")).getValue();
byte[] b = ByteArrayTag.class.cast(tagMap.get("Blocks")).getValue();
byte[] d = ByteArrayTag.class.cast(tagMap.get("Data")).getValue();
short[] blocks = new short[b.length];
byte[] b = ByteArrayTag.class.cast(tagMap.get("Blocks")).getValue();
byte[] d = ByteArrayTag.class.cast(tagMap.get("Data")).getValue();
short[] blocks = new short[b.length];
Dimension dimension = new Dimension(width, height, length);
Dimension dimension = new Dimension(width, height, length);
for (int index = 0; index < b.length; index++) {
if ((index >> 1) >= addId.length) { // No corresponding
// AddBlocks index
blocks[index] = (short) (b[index] & 0xFF);
} else {
if ((index & 1) == 0) {
blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (b[index] & 0xFF));
} else {
blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (b[index] & 0xFF));
}
}
}
for (int index = 0; index < b.length; index++) {
if ((index >> 1) >= addId.length) { // No corresponding
// AddBlocks index
blocks[index] = (short) (b[index] & 0xFF);
} else {
if ((index & 1) == 0) {
blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (b[index] & 0xFF));
} else {
blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (b[index] & 0xFF));
}
}
}
DataCollection[] collection = new DataCollection[b.length];
DataCollection[] collection = new DataCollection[b.length];
for (int x = 0; x < b.length; x++) {
collection[x] = new DataCollection(blocks[x], d[x]);
}
for (int x = 0; x < b.length; x++) {
collection[x] = new DataCollection(blocks[x], d[x]);
}
schematic = new Schematic(collection, dimension, file);
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
return schematic;
}
}
schematic = new Schematic(collection, dimension, file);
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
return schematic;
}
}
public static class Schematic {
private DataCollection[] blockCollection;
private Dimension schematicDimension;
private File file;
public static class Schematic {
private DataCollection[] blockCollection;
private Dimension schematicDimension;
private File file;
public Schematic(DataCollection[] blockCollection, Dimension schematicDimension, File file) {
this.blockCollection = blockCollection;
this.schematicDimension = schematicDimension;
this.file = file;
}
public Schematic(DataCollection[] blockCollection,
Dimension schematicDimension, File file) {
this.blockCollection = blockCollection;
this.schematicDimension = schematicDimension;
this.file = file;
}
public File getFile() {
return this.file;
}
public File getFile() {
return this.file;
}
public Dimension getSchematicDimension() {
return this.schematicDimension;
}
public Dimension getSchematicDimension() {
return this.schematicDimension;
}
public DataCollection[] getBlockCollection() {
return this.blockCollection;
}
}
public DataCollection[] getBlockCollection() {
return this.blockCollection;
}
}
public class Dimension {
private int x;
private int y;
private int z;
public class Dimension {
private int x;
private int y;
private int z;
public Dimension(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public Dimension(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public int getX() {
return this.x;
}
public int getX() {
return this.x;
}
public int getY() {
return this.y;
}
public int getY() {
return this.y;
}
public int getZ() {
return this.z;
}
}
public int getZ() {
return this.z;
}
}
public class DataCollection {
private short block;
private byte data;
public class DataCollection {
private short block;
private byte data;
public DataCollection(short block, byte data) {
this.block = block;
this.data = data;
}
public DataCollection(short block, byte data) {
this.block = block;
this.data = data;
}
public short getBlock() {
return this.block;
}
public short getBlock() {
return this.block;
}
public byte getData() {
return this.data;
}
}
public byte getData() {
return this.data;
}
}
}

View File

@ -8,45 +8,50 @@ import com.intellectualcrafters.plot.ReflectionUtils.RefClass;
import com.intellectualcrafters.plot.ReflectionUtils.RefMethod;
/**
*
*
* SetBlockFast class<br>
* Used to do fast world editing
*
*
*/
public class SetBlockFast {
private static final RefClass classBlock = getRefClass("{nms}.Block");
private static final RefClass classChunk = getRefClass("{nms}.Chunk");
private static final RefClass classWorld = getRefClass("{nms}.World");
private static final RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
private static final RefClass classBlock = getRefClass("{nms}.Block");
private static final RefClass classChunk = getRefClass("{nms}.Chunk");
private static final RefClass classWorld = getRefClass("{nms}.World");
private static final RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
private static RefMethod methodGetHandle;
private static RefMethod methodGetChunkAt;
private static RefMethod methodA;
private static RefMethod methodGetById;
private static RefMethod methodGetHandle;
private static RefMethod methodGetChunkAt;
private static RefMethod methodA;
private static RefMethod methodGetById;
public SetBlockFast() throws NoSuchMethodException {
methodGetHandle = classCraftWorld.getMethod("getHandle");
methodGetChunkAt = classWorld.getMethod("getChunkAt", int.class, int.class);
methodA = classChunk.getMethod("a", int.class, int.class, int.class, classBlock, int.class);
methodGetById = classBlock.getMethod("getById", int.class);
}
public SetBlockFast() throws NoSuchMethodException {
methodGetHandle = classCraftWorld.getMethod("getHandle");
methodGetChunkAt = classWorld.getMethod("getChunkAt", int.class,
int.class);
methodA = classChunk.getMethod("a", int.class, int.class, int.class,
classBlock, int.class);
methodGetById = classBlock.getMethod("getById", int.class);
}
public static boolean set(org.bukkit.World world, int x, int y, int z, int blockId, byte data) throws NoSuchMethodException {
public static boolean set(org.bukkit.World world, int x, int y, int z,
int blockId, byte data) throws NoSuchMethodException {
Object w = methodGetHandle.of(world).call();
Object chunk = methodGetChunkAt.of(w).call(x >> 4, z >> 4);
Object block = methodGetById.of(null).call(blockId);
methodA.of(chunk).call(x & 0x0f, y, z & 0x0f, block, data);
return true;
}
Object w = methodGetHandle.of(world).call();
Object chunk = methodGetChunkAt.of(w).call(x >> 4, z >> 4);
Object block = methodGetById.of(null).call(blockId);
methodA.of(chunk).call(x & 0x0f, y, z & 0x0f, block, data);
return true;
}
public static void update(org.bukkit.entity.Player player) {
int distance = Bukkit.getViewDistance() + 1;
for (int cx = -distance; cx < distance; cx++) {
for (int cz = -distance; cz < distance; cz++) {
player.getWorld().refreshChunk(player.getLocation().getChunk().getX() + cx, player.getLocation().getChunk().getZ() + cz);
}
}
}
public static void update(org.bukkit.entity.Player player) {
int distance = Bukkit.getViewDistance() + 1;
for (int cx = -distance; cx < distance; cx++) {
for (int cz = -distance; cz < distance; cz++) {
player.getWorld().refreshChunk(
player.getLocation().getChunk().getX() + cx,
player.getLocation().getChunk().getZ() + cz);
}
}
}
}

View File

@ -11,87 +11,88 @@ package com.intellectualcrafters.plot;
/**
* Updater and DB settings
*
*
* @author Citymonstret
*
*
* @author Empire92
*/
public class Settings {
public static int MAX_PLOTS = 20;
/**
* WorldGuard region on claimed plots
*/
public static boolean WORLDGUARD = false;
/**
* metrics
*/
public static boolean METRICS = true;
/**
* plot specific resource pack
*/
public static String PLOT_SPECIFIC_RESOURCE_PACK = "";
/**
* Kill road mobs?
*/
public static boolean KILL_ROAD_MOBS;
/**
* Default kill road mobs: true
*/
public static boolean KILL_ROAD_MOBS_DEFAULT = true;
/**
* mob pathfinding?
*/
public static boolean MOB_PATHFINDING;
/**
* Default mob pathfinding: true
*/
public static boolean MOB_PATHFINDING_DEFAULT = true;
/**
* Update settings
*
* @author Citymonstret
*
*/
public static String URL = "http://dev.bukkit.org/bukkit-plugins/plotsquared/";
public static int MAX_PLOTS = 20;
/**
* WorldGuard region on claimed plots
*/
public static boolean WORLDGUARD = false;
/**
* metrics
*/
public static boolean METRICS = true;
/**
* plot specific resource pack
*/
public static String PLOT_SPECIFIC_RESOURCE_PACK = "";
/**
* Kill road mobs?
*/
public static boolean KILL_ROAD_MOBS;
/**
* Default kill road mobs: true
*/
public static boolean KILL_ROAD_MOBS_DEFAULT = true;
/**
* mob pathfinding?
*/
public static boolean MOB_PATHFINDING;
/**
* Default mob pathfinding: true
*/
public static boolean MOB_PATHFINDING_DEFAULT = true;
/**
* Update settings
*
* @author Citymonstret
*
*/
public static String URL = "http://dev.bukkit.org/bukkit-plugins/plotsquared/";
public static boolean DEBUG = true;
public static boolean DEBUG = true;
public static boolean AUTO_CLEAR = false;
public static int AUTO_CLEAR_DAYS = 365;
public static boolean AUTO_CLEAR = false;
public static int AUTO_CLEAR_DAYS = 365;
public static class Update {
/**
* Update plugin?
*
* @deprecated
*/
@Deprecated
public static boolean AUTO_UPDATE = false;
}
public static class Update {
/**
* Update plugin?
*
* @deprecated
*/
@Deprecated
public static boolean AUTO_UPDATE = false;
}
public static class Web {
public static boolean ENABLED = false;
public static int PORT = 9000;
}
public static class Web {
public static boolean ENABLED = false;
public static int PORT = 9000;
}
/**
* Database settings
*
* @author Citymonstret
*
*/
public static class DB {
public static boolean USE_MONGO = false; /*
* TODO: Implement Mongo
* @Brandon
*/;
public static boolean USE_SQLITE = false;
public static boolean USE_MYSQL = true; /* NOTE: Fixed connector */
public static String SQLITE_DB = "storage";
public static String HOST_NAME = "localhost";
public static String PORT = "3306";
public static String DATABASE = "plot_db";
public static String USER = "root";
public static String PASSWORD = "password";
}
/**
* Database settings
*
* @author Citymonstret
*
*/
public static class DB {
public static boolean USE_MONGO = false; /*
* TODO: Implement Mongo
*
* @Brandon
*/;
public static boolean USE_SQLITE = false;
public static boolean USE_MYSQL = true; /* NOTE: Fixed connector */
public static String SQLITE_DB = "storage";
public static String HOST_NAME = "localhost";
public static String PORT = "3306";
public static String DATABASE = "plot_db";
public static String USER = "root";
public static String PASSWORD = "password";
}
}

View File

@ -11,397 +11,437 @@ import org.bukkit.entity.Player;
/**
* Minecraft 1.8 Title
*
*
* @version 1.0.3
* @author Maxim Van de Wynckel
*/
@SuppressWarnings("unused")
public class Title {
/* Title packet */
private Class<?> packetTitle;
/* Title packet actions ENUM */
private Class<?> packetActions;
/* Chat serializer */
private Class<?> nmsChatSerializer;
/* Title text and color */
private String title = "";
private ChatColor titleColor = ChatColor.WHITE;
/* Subtitle text and color */
private String subtitle = "";
private ChatColor subtitleColor = ChatColor.WHITE;
/* Title timings */
private int fadeInTime = -1;
private int stayTime = -1;
private int fadeOutTime = -1;
private boolean ticks = false;
/* Title packet */
private Class<?> packetTitle;
/* Title packet actions ENUM */
private Class<?> packetActions;
/* Chat serializer */
private Class<?> nmsChatSerializer;
/* Title text and color */
private String title = "";
private ChatColor titleColor = ChatColor.WHITE;
/* Subtitle text and color */
private String subtitle = "";
private ChatColor subtitleColor = ChatColor.WHITE;
/* Title timings */
private int fadeInTime = -1;
private int stayTime = -1;
private int fadeOutTime = -1;
private boolean ticks = false;
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES;
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES;
static {
CORRESPONDING_TYPES = new HashMap<>();
}
static {
CORRESPONDING_TYPES = new HashMap<>();
}
/**
* Create a new 1.8 title
*
* @param title
* Title
*/
public Title(String title) {
this.title = title;
loadClasses();
}
/**
* Create a new 1.8 title
*
* @param title
* Title
*/
public Title(String title) {
this.title = title;
loadClasses();
}
/**
* Create a new 1.8 title
*
* @param title
* Title text
* @param subtitle
* Subtitle text
*/
public Title(String title, String subtitle) {
this.title = title;
this.subtitle = subtitle;
loadClasses();
}
/**
* Create a new 1.8 title
*
* @param title
* Title text
* @param subtitle
* Subtitle text
*/
public Title(String title, String subtitle) {
this.title = title;
this.subtitle = subtitle;
loadClasses();
}
/**
* Create a new 1.8 title
*
* @param title
* Title text
* @param subtitle
* Subtitle text
* @param fadeInTime
* Fade in time
* @param stayTime
* Stay on screen time
* @param fadeOutTime
* Fade out time
*/
public Title(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
this.title = title;
this.subtitle = subtitle;
this.fadeInTime = fadeInTime;
this.stayTime = stayTime;
this.fadeOutTime = fadeOutTime;
loadClasses();
}
/**
* Create a new 1.8 title
*
* @param title
* Title text
* @param subtitle
* Subtitle text
* @param fadeInTime
* Fade in time
* @param stayTime
* Stay on screen time
* @param fadeOutTime
* Fade out time
*/
public Title(String title, String subtitle, int fadeInTime, int stayTime,
int fadeOutTime) {
this.title = title;
this.subtitle = subtitle;
this.fadeInTime = fadeInTime;
this.stayTime = stayTime;
this.fadeOutTime = fadeOutTime;
loadClasses();
}
/**
* Load spigot and NMS classes
*/
private void loadClasses() {
this.packetTitle = getClass("org.spigotmc.ProtocolInjector$PacketTitle");
this.packetActions = getClass("org.spigotmc.ProtocolInjector$PacketTitle$Action");
this.nmsChatSerializer = getNMSClass("ChatSerializer");
}
/**
* Load spigot and NMS classes
*/
private void loadClasses() {
this.packetTitle = getClass("org.spigotmc.ProtocolInjector$PacketTitle");
this.packetActions = getClass("org.spigotmc.ProtocolInjector$PacketTitle$Action");
this.nmsChatSerializer = getNMSClass("ChatSerializer");
}
/**
* Set the title color
*
* @param color
* Chat color
*/
public void setTitleColor(ChatColor color) {
this.titleColor = color;
}
/**
* Set the title color
*
* @param color
* Chat color
*/
public void setTitleColor(ChatColor color) {
this.titleColor = color;
}
/**
* Set the subtitle color
*
* @param color
* Chat color
*/
public void setSubtitleColor(ChatColor color) {
this.subtitleColor = color;
}
/**
* Set the subtitle color
*
* @param color
* Chat color
*/
public void setSubtitleColor(ChatColor color) {
this.subtitleColor = color;
}
/**
* Set title fade in time
*
* @param time
* Time
*/
public void setFadeInTime(int time) {
this.fadeInTime = time;
}
/**
* Set title fade in time
*
* @param time
* Time
*/
public void setFadeInTime(int time) {
this.fadeInTime = time;
}
/**
* Set title fade out time
*
* @param time
* Time
*/
public void setFadeOutTime(int time) {
this.fadeOutTime = time;
}
/**
* Set title fade out time
*
* @param time
* Time
*/
public void setFadeOutTime(int time) {
this.fadeOutTime = time;
}
/**
* Set title stay time
*
* @param time
* Time
*/
public void setStayTime(int time) {
this.stayTime = time;
}
/**
* Set title stay time
*
* @param time
* Time
*/
public void setStayTime(int time) {
this.stayTime = time;
}
/**
* Set timings to ticks
*/
public void setTimingsToTicks() {
this.ticks = true;
}
/**
* Set timings to ticks
*/
public void setTimingsToTicks() {
this.ticks = true;
}
/**
* Set timings to seconds
*/
public void setTimingsToSeconds() {
this.ticks = false;
}
/**
* Set timings to seconds
*/
public void setTimingsToSeconds() {
this.ticks = false;
}
/**
* Send the title to a player
*
* @param player
* Player
*/
public void send(Player player) {
if ((getProtocolVersion(player) >= 47) && isSpigot() && (this.packetTitle != null)) {
// First reset previous settings
resetTitle(player);
try {
// Send timings first
Object handle = getHandle(player);
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
Object[] actions = this.packetActions.getEnumConstants();
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
Object packet = this.packetTitle.getConstructor(this.packetActions, Integer.TYPE, Integer.TYPE, Integer.TYPE).newInstance(actions[2], this.fadeInTime * (this.ticks ? 1 : 20), this.stayTime * (this.ticks ? 1 : 20), this.fadeOutTime * (this.ticks ? 1 : 20));
// Send if set
if ((this.fadeInTime != -1) && (this.fadeOutTime != -1) && (this.stayTime != -1)) {
sendPacket.invoke(connection, packet);
}
/**
* Send the title to a player
*
* @param player
* Player
*/
public void send(Player player) {
if ((getProtocolVersion(player) >= 47) && isSpigot()
&& (this.packetTitle != null)) {
// First reset previous settings
resetTitle(player);
try {
// Send timings first
Object handle = getHandle(player);
Object connection = getField(handle.getClass(),
"playerConnection").get(handle);
Object[] actions = this.packetActions.getEnumConstants();
Method sendPacket = getMethod(connection.getClass(),
"sendPacket");
Object packet = this.packetTitle.getConstructor(
this.packetActions, Integer.TYPE, Integer.TYPE,
Integer.TYPE).newInstance(actions[2],
this.fadeInTime * (this.ticks ? 1 : 20),
this.stayTime * (this.ticks ? 1 : 20),
this.fadeOutTime * (this.ticks ? 1 : 20));
// Send if set
if ((this.fadeInTime != -1) && (this.fadeOutTime != -1)
&& (this.stayTime != -1)) {
sendPacket.invoke(connection, packet);
}
// Send title
Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null, "{text:\"" + ChatColor.translateAlternateColorCodes('&', this.title) + "\",color:" + this.titleColor.name().toLowerCase() + "}");
packet = this.packetTitle.getConstructor(this.packetActions, getNMSClass("IChatBaseComponent")).newInstance(actions[0], serialized);
sendPacket.invoke(connection, packet);
if (!this.subtitle.equals("")) {
// Send subtitle if present
serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null, "{text:\"" + ChatColor.translateAlternateColorCodes('&', this.subtitle) + "\",color:" + this.subtitleColor.name().toLowerCase() + "}");
packet = this.packetTitle.getConstructor(this.packetActions, getNMSClass("IChatBaseComponent")).newInstance(actions[1], serialized);
sendPacket.invoke(connection, packet);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
// Send title
Object serialized = getMethod(this.nmsChatSerializer, "a",
String.class).invoke(
null,
"{text:\""
+ ChatColor.translateAlternateColorCodes('&',
this.title) + "\",color:"
+ this.titleColor.name().toLowerCase() + "}");
packet = this.packetTitle.getConstructor(this.packetActions,
getNMSClass("IChatBaseComponent")).newInstance(
actions[0], serialized);
sendPacket.invoke(connection, packet);
if (!this.subtitle.equals("")) {
// Send subtitle if present
serialized = getMethod(this.nmsChatSerializer, "a",
String.class).invoke(
null,
"{text:\""
+ ChatColor.translateAlternateColorCodes(
'&', this.subtitle) + "\",color:"
+ this.subtitleColor.name().toLowerCase()
+ "}");
packet = this.packetTitle.getConstructor(
this.packetActions,
getNMSClass("IChatBaseComponent")).newInstance(
actions[1], serialized);
sendPacket.invoke(connection, packet);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* Broadcast the title to all players
*/
public void broadcast() {
for (Player p : Bukkit.getOnlinePlayers()) {
send(p);
}
}
/**
* Broadcast the title to all players
*/
public void broadcast() {
for (Player p : Bukkit.getOnlinePlayers()) {
send(p);
}
}
/**
* Clear the title
*
* @param player
* Player
*/
public void clearTitle(Player player) {
if ((getProtocolVersion(player) >= 47) && isSpigot()) {
try {
// Send timings first
Object handle = getHandle(player);
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
Object[] actions = this.packetActions.getEnumConstants();
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
Object packet = this.packetTitle.getConstructor(this.packetActions).newInstance(actions[3]);
sendPacket.invoke(connection, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* Clear the title
*
* @param player
* Player
*/
public void clearTitle(Player player) {
if ((getProtocolVersion(player) >= 47) && isSpigot()) {
try {
// Send timings first
Object handle = getHandle(player);
Object connection = getField(handle.getClass(),
"playerConnection").get(handle);
Object[] actions = this.packetActions.getEnumConstants();
Method sendPacket = getMethod(connection.getClass(),
"sendPacket");
Object packet = this.packetTitle.getConstructor(
this.packetActions).newInstance(actions[3]);
sendPacket.invoke(connection, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* Reset the title settings
*
* @param player
* Player
*/
public void resetTitle(Player player) {
if ((getProtocolVersion(player) >= 47) && isSpigot()) {
try {
// Send timings first
Object handle = getHandle(player);
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
Object[] actions = this.packetActions.getEnumConstants();
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
Object packet = this.packetTitle.getConstructor(this.packetActions).newInstance(actions[4]);
sendPacket.invoke(connection, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* Reset the title settings
*
* @param player
* Player
*/
public void resetTitle(Player player) {
if ((getProtocolVersion(player) >= 47) && isSpigot()) {
try {
// Send timings first
Object handle = getHandle(player);
Object connection = getField(handle.getClass(),
"playerConnection").get(handle);
Object[] actions = this.packetActions.getEnumConstants();
Method sendPacket = getMethod(connection.getClass(),
"sendPacket");
Object packet = this.packetTitle.getConstructor(
this.packetActions).newInstance(actions[4]);
sendPacket.invoke(connection, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* Get the protocol version of the player
*
* @param player
* Player
* @return Protocol version
*/
private int getProtocolVersion(Player player) {
int version = 0;
try {
Object handle = getHandle(player);
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
Object networkManager = getValue("networkManager", connection);
version = (Integer) getMethod("getVersion", networkManager.getClass()).invoke(networkManager);
/**
* Get the protocol version of the player
*
* @param player
* Player
* @return Protocol version
*/
private int getProtocolVersion(Player player) {
int version = 0;
try {
Object handle = getHandle(player);
Object connection = getField(handle.getClass(), "playerConnection")
.get(handle);
Object networkManager = getValue("networkManager", connection);
version = (Integer) getMethod("getVersion",
networkManager.getClass()).invoke(networkManager);
return version;
} catch (Exception ex) {
// ex.printStackTrace(); <-- spammy console
}
return version;
}
return version;
} catch (Exception ex) {
// ex.printStackTrace(); <-- spammy console
}
return version;
}
/**
* Check if running spigot
*
* @return Spigot
*/
private boolean isSpigot() {
return Bukkit.getVersion().contains("Spigot");
}
/**
* Check if running spigot
*
* @return Spigot
*/
private boolean isSpigot() {
return Bukkit.getVersion().contains("Spigot");
}
/**
* Get class by url
*
* @param namespace
* Namespace url
* @return Class
*/
private Class<?> getClass(String namespace) {
try {
return Class.forName(namespace);
} catch (Exception e) {
return null;
}
}
/**
* Get class by url
*
* @param namespace
* Namespace url
* @return Class
*/
private Class<?> getClass(String namespace) {
try {
return Class.forName(namespace);
} catch (Exception e) {
return null;
}
}
private Field getField(String name, Class<?> clazz) throws Exception {
return clazz.getDeclaredField(name);
}
private Field getField(String name, Class<?> clazz) throws Exception {
return clazz.getDeclaredField(name);
}
private Object getValue(String name, Object obj) throws Exception {
Field f = getField(name, obj.getClass());
f.setAccessible(true);
return f.get(obj);
}
private Object getValue(String name, Object obj) throws Exception {
Field f = getField(name, obj.getClass());
f.setAccessible(true);
return f.get(obj);
}
private Class<?> getPrimitiveType(Class<?> clazz) {
return CORRESPONDING_TYPES.containsKey(clazz) ? CORRESPONDING_TYPES.get(clazz) : clazz;
}
private Class<?> getPrimitiveType(Class<?> clazz) {
return CORRESPONDING_TYPES.containsKey(clazz) ? CORRESPONDING_TYPES
.get(clazz) : clazz;
}
private Class<?>[] toPrimitiveTypeArray(Class<?>[] classes) {
int a = classes != null ? classes.length : 0;
Class<?>[] types = new Class<?>[a];
for (int i = 0; i < a; i++) {
types[i] = getPrimitiveType(classes[i]);
}
return types;
}
private Class<?>[] toPrimitiveTypeArray(Class<?>[] classes) {
int a = classes != null ? classes.length : 0;
Class<?>[] types = new Class<?>[a];
for (int i = 0; i < a; i++) {
types[i] = getPrimitiveType(classes[i]);
}
return types;
}
private static boolean equalsTypeArray(Class<?>[] a, Class<?>[] o) {
if (a.length != o.length) {
return false;
}
for (int i = 0; i < a.length; i++) {
if (!a[i].equals(o[i]) && !a[i].isAssignableFrom(o[i])) {
return false;
}
}
return true;
}
private static boolean equalsTypeArray(Class<?>[] a, Class<?>[] o) {
if (a.length != o.length) {
return false;
}
for (int i = 0; i < a.length; i++) {
if (!a[i].equals(o[i]) && !a[i].isAssignableFrom(o[i])) {
return false;
}
}
return true;
}
private Object getHandle(Object obj) {
try {
return getMethod("getHandle", obj.getClass()).invoke(obj);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private Object getHandle(Object obj) {
try {
return getMethod("getHandle", obj.getClass()).invoke(obj);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private Method getMethod(String name, Class<?> clazz, Class<?>... paramTypes) {
Class<?>[] t = toPrimitiveTypeArray(paramTypes);
for (Method m : clazz.getMethods()) {
Class<?>[] types = toPrimitiveTypeArray(m.getParameterTypes());
if (m.getName().equals(name) && equalsTypeArray(types, t)) {
return m;
}
}
return null;
}
private Method getMethod(String name, Class<?> clazz,
Class<?>... paramTypes) {
Class<?>[] t = toPrimitiveTypeArray(paramTypes);
for (Method m : clazz.getMethods()) {
Class<?>[] types = toPrimitiveTypeArray(m.getParameterTypes());
if (m.getName().equals(name) && equalsTypeArray(types, t)) {
return m;
}
}
return null;
}
private String getVersion() {
String name = Bukkit.getServer().getClass().getPackage().getName();
return name.substring(name.lastIndexOf('.') + 1) + ".";
}
private String getVersion() {
String name = Bukkit.getServer().getClass().getPackage().getName();
return name.substring(name.lastIndexOf('.') + 1) + ".";
}
private Class<?> getNMSClass(String className) {
String fullName = "net.minecraft.server." + getVersion() + className;
Class<?> clazz = null;
try {
clazz = Class.forName(fullName);
} catch (Exception e) {
e.printStackTrace();
}
return clazz;
}
private Class<?> getNMSClass(String className) {
String fullName = "net.minecraft.server." + getVersion() + className;
Class<?> clazz = null;
try {
clazz = Class.forName(fullName);
} catch (Exception e) {
e.printStackTrace();
}
return clazz;
}
private Field getField(Class<?> clazz, String name) {
try {
Field field = clazz.getDeclaredField(name);
field.setAccessible(true);
return field;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private Field getField(Class<?> clazz, String name) {
try {
Field field = clazz.getDeclaredField(name);
field.setAccessible(true);
return field;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private Method getMethod(Class<?> clazz, String name, Class<?>... args) {
for (Method m : clazz.getMethods()) {
if (m.getName().equals(name) && ((args.length == 0) || ClassListEqual(args, m.getParameterTypes()))) {
m.setAccessible(true);
return m;
}
}
return null;
}
private Method getMethod(Class<?> clazz, String name, Class<?>... args) {
for (Method m : clazz.getMethods()) {
if (m.getName().equals(name)
&& ((args.length == 0) || ClassListEqual(args,
m.getParameterTypes()))) {
m.setAccessible(true);
return m;
}
}
return null;
}
private boolean ClassListEqual(Class<?>[] l1, Class<?>[] l2) {
boolean equal = true;
if (l1.length != l2.length) {
return false;
}
for (int i = 0; i < l1.length; i++) {
if (l1[i] != l2[i]) {
equal = false;
break;
}
}
return equal;
}
private boolean ClassListEqual(Class<?>[] l1, Class<?>[] l2) {
boolean equal = true;
if (l1.length != l2.length) {
return false;
}
for (int i = 0; i < l1.length; i++) {
if (l1[i] != l2[i]) {
equal = false;
break;
}
}
return equal;
}
}

View File

@ -1,205 +1,215 @@
package com.intellectualcrafters.plot;
import com.google.common.base.Charsets;
import com.intellectualcrafters.plot.uuid.NameFetcher;
import com.intellectualcrafters.plot.uuid.UUIDFetcher;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Arrays;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.base.Charsets;
import com.intellectualcrafters.plot.uuid.NameFetcher;
import com.intellectualcrafters.plot.uuid.UUIDFetcher;
public class UUIDHandler {
private static ConcurrentHashMap<String, UUID> uuidMap = new ConcurrentHashMap<>();
private static ConcurrentHashMap<String, UUID> uuidMap = new ConcurrentHashMap<>();
public static boolean uuidExists(UUID uuid) {
return uuidMap.containsValue(uuid);
}
public static boolean uuidExists(UUID uuid) {
return uuidMap.containsValue(uuid);
}
public static boolean nameExists(String name) {
return uuidMap.containsKey(name);
}
public static boolean nameExists(String name) {
return uuidMap.containsKey(name);
}
public static void add(String name, UUID uuid) {
uuidMap.put(name, uuid);
}
public static void add(String name, UUID uuid) {
uuidMap.put(name, uuid);
}
/**
*
* @param plugin
*/
public static void startFetch(JavaPlugin plugin) {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
OfflinePlayer[] offlinePlayers = Bukkit.getOfflinePlayers();
int lenght = offlinePlayers.length;
long start = System.currentTimeMillis();
/**
*
* @param plugin
*/
public static void startFetch(JavaPlugin plugin) {
plugin.getServer().getScheduler()
.runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
OfflinePlayer[] offlinePlayers = Bukkit
.getOfflinePlayers();
int lenght = offlinePlayers.length;
long start = System.currentTimeMillis();
String name;
UUID uuid;
for(OfflinePlayer player : offlinePlayers) {
name = player.getName();
uuid = player.getUniqueId();
if(!uuidExists(uuid))
add(name, uuid);
}
String name;
UUID uuid;
for (OfflinePlayer player : offlinePlayers) {
name = player.getName();
uuid = player.getUniqueId();
if (!uuidExists(uuid)) {
add(name, uuid);
}
}
long time = System.currentTimeMillis() - start;
PlotMain.sendConsoleSenderMessage("&cFinished caching of offlineplayers! Took &6" + time + "&cms, &6" + lenght + " &cUUID's were cached" +
" and there is now a grand total of &6" + uuidMap.size() + " &ccached.");
}
});
}
long time = System.currentTimeMillis() - start;
PlotMain.sendConsoleSenderMessage("&cFinished caching of offlineplayers! Took &6"
+ time
+ "&cms, &6"
+ lenght
+ " &cUUID's were cached"
+ " and there is now a grand total of &6"
+ uuidMap.size() + " &ccached.");
}
});
}
/**
*
* @param name
* @return
*/
public static UUID getUUID(String name) {
if (nameExists(name)) {
return uuidMap.get(name);
}
UUID uuid;
if ((uuid = getUuidOnlinePlayer(name)) != null) {
return uuid;
}
if ((uuid = getUuidOfflinePlayer(name)) != null) {
return uuid;
}
if(Bukkit.getOnlineMode()) {
try {
UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name));
uuid = fetcher.call().get(name);
add(name, uuid);
} catch(Exception e) {
e.printStackTrace();
}
} else {
return getUuidOfflineMode(name);
}
return null;
}
/**
*
* @param name
* @return
*/
public static UUID getUUID(String name) {
if (nameExists(name)) {
return uuidMap.get(name);
}
UUID uuid;
if ((uuid = getUuidOnlinePlayer(name)) != null) {
return uuid;
}
if ((uuid = getUuidOfflinePlayer(name)) != null) {
return uuid;
}
if (Bukkit.getOnlineMode()) {
try {
UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name));
uuid = fetcher.call().get(name);
add(name, uuid);
} catch (Exception e) {
e.printStackTrace();
}
} else {
return getUuidOfflineMode(name);
}
return null;
}
/**
*
* @param uuid
* @return
*/
private static String loopSearch(UUID uuid) {
for(Map.Entry<String, UUID> entry : uuidMap.entrySet()) {
if(entry.getValue().equals(uuid)) {
return entry.getKey();
}
}
return "";
}
/**
*
* @param uuid
* @return
*/
private static String loopSearch(UUID uuid) {
for (Map.Entry<String, UUID> entry : uuidMap.entrySet()) {
if (entry.getValue().equals(uuid)) {
return entry.getKey();
}
}
return "";
}
/**
*
* @param uuid
* @return
*/
public static String getName(UUID uuid) {
if(uuidExists(uuid)) {
return loopSearch(uuid);
}
String name;
if ((name = getNameOnlinePlayer(uuid)) != null) {
return name;
}
if ((name = getNameOfflinePlayer(uuid)) != null) {
return name;
}
if (Bukkit.getOnlineMode()) {
try {
NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid));
name = fetcher.call().get(uuid);
add(name, uuid);
return name;
} catch(Exception e) {
e.printStackTrace();
}
} else {
return "unknown";
}
return "";
}
/**
*
* @param uuid
* @return
*/
public static String getName(UUID uuid) {
if (uuidExists(uuid)) {
return loopSearch(uuid);
}
String name;
if ((name = getNameOnlinePlayer(uuid)) != null) {
return name;
}
if ((name = getNameOfflinePlayer(uuid)) != null) {
return name;
}
if (Bukkit.getOnlineMode()) {
try {
NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid));
name = fetcher.call().get(uuid);
add(name, uuid);
return name;
} catch (Exception e) {
e.printStackTrace();
}
} else {
return "unknown";
}
return "";
}
/**
*
* @param name
* @return
*/
private static UUID getUuidOfflineMode(String name) {
UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
add(name, uuid);
return uuid;
}
/**
*
* @param name
* @return
*/
private static UUID getUuidOfflineMode(String name) {
UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name)
.getBytes(Charsets.UTF_8));
add(name, uuid);
return uuid;
}
/**
*
* @param uuid
* @return
*/
private static String getNameOnlinePlayer(UUID uuid) {
Player player = Bukkit.getPlayer(uuid);
if(player == null || !player.isOnline()) {
return null;
}
String name = player.getName();
add(name, uuid);
return name;
}
/**
*
* @param uuid
* @return
*/
private static String getNameOnlinePlayer(UUID uuid) {
Player player = Bukkit.getPlayer(uuid);
if (player == null || !player.isOnline()) {
return null;
}
String name = player.getName();
add(name, uuid);
return name;
}
/**
*
* @param uuid
* @return
*/
private static String getNameOfflinePlayer(UUID uuid) {
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
if (player == null || !player.hasPlayedBefore()) {
return null;
}
String name = player.getName();
add(name, uuid);
return name;
}
/**
*
* @param uuid
* @return
*/
private static String getNameOfflinePlayer(UUID uuid) {
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
if (player == null || !player.hasPlayedBefore()) {
return null;
}
String name = player.getName();
add(name, uuid);
return name;
}
/**
*
* @param name
* @return
*/
private static UUID getUuidOnlinePlayer(String name) {
Player player = Bukkit.getPlayer(name);
if (player == null || !player.isOnline()) {
return null;
}
UUID uuid = player.getUniqueId();
add(name, uuid);
return uuid;
}
/**
*
* @param name
* @return
*/
private static UUID getUuidOnlinePlayer(String name) {
Player player = Bukkit.getPlayer(name);
if (player == null || !player.isOnline()) {
return null;
}
UUID uuid = player.getUniqueId();
add(name, uuid);
return uuid;
}
/**
*
* @param name
* @return
*/
private static UUID getUuidOfflinePlayer(String name) {
OfflinePlayer player = Bukkit.getOfflinePlayer(name);
if (player == null || !player.hasPlayedBefore()) {
return null;
}
UUID uuid = player.getUniqueId();
add(name, uuid);
return uuid;
}
/**
*
* @param name
* @return
*/
private static UUID getUuidOfflinePlayer(String name) {
OfflinePlayer player = Bukkit.getOfflinePlayer(name);
if (player == null || !player.hasPlayedBefore()) {
return null;
}
UUID uuid = player.getUniqueId();
add(name, uuid);
return uuid;
}
}

View File

@ -32,291 +32,294 @@ import com.intellectualcrafters.plot.commands.SubCommand;
/**
* The plotMain api class.
*
*
* @author Citymonstret
*/
@SuppressWarnings({ "unused", "javadoc" })
public class PlotAPI {
// To access plotMain stuff.
private PlotMain plotMain;
// Reference
public static final String ADMIN_PERMISSION = "plots.admin";
// To access plotMain stuff.
private PlotMain plotMain;
// Reference
public static final String ADMIN_PERMISSION = "plots.admin";
/**
* Constructor. Insert any Plugin.
*
* @param plugin
*/
public PlotAPI(JavaPlugin plugin) {
this.plotMain = JavaPlugin.getPlugin(PlotMain.class);
}
/**
* Constructor. Insert any Plugin.
*
* @param plugin
*/
public PlotAPI(JavaPlugin plugin) {
this.plotMain = JavaPlugin.getPlugin(PlotMain.class);
}
/**
* Send a message to a player.
*
* @param player
* @param c
* (Caption)
*/
public void sendMessage(Player player, C c) {
PlayerFunctions.sendMessage(player, c);
}
/**
* Send a message to a player.
*
* @param player
* @param c
* (Caption)
*/
public void sendMessage(Player player, C c) {
PlayerFunctions.sendMessage(player, c);
}
/**
* Send a message to a player.
*
* @param player
* @param string
*/
public void sendMessage(Player player, String string) {
PlayerFunctions.sendMessage(player, string);
}
/**
* Send a message to a player.
*
* @param player
* @param string
*/
public void sendMessage(Player player, String string) {
PlayerFunctions.sendMessage(player, string);
}
/**
* Send a message to the console.
*
* @param msg
*/
public void sendConsoleMessage(String msg) {
PlotMain.sendConsoleSenderMessage(msg);
}
/**
* Send a message to the console.
*
* @param msg
*/
public void sendConsoleMessage(String msg) {
PlotMain.sendConsoleSenderMessage(msg);
}
/**
* Send a message to the console
*
* @param c
* (Caption)
*/
public void sendConsoleMessage(C c) {
sendConsoleMessage(c.s());
}
/**
* Send a message to the console
*
* @param c
* (Caption)
*/
public void sendConsoleMessage(C c) {
sendConsoleMessage(c.s());
}
/**
* Register a flag for use in plots
*
* @param flag
*/
public void addFlag(AbstractFlag flag) {
FlagManager.addFlag(flag);
}
/**
* Register a flag for use in plots
*
* @param flag
*/
public void addFlag(AbstractFlag flag) {
FlagManager.addFlag(flag);
}
/**
* get all the currently registered flags
*
* @return array of Flag[]
*/
public AbstractFlag[] getFlags() {
return FlagManager.getFlags().toArray(new AbstractFlag[0]);
}
/**
* get all the currently registered flags
*
* @return array of Flag[]
*/
public AbstractFlag[] getFlags() {
return FlagManager.getFlags().toArray(new AbstractFlag[0]);
}
/**
* Get a plot based on the ID
*
* @param world
* @param x
* @param z
* @return plot, null if ID is wrong
*/
public Plot getPlot(World world, int x, int z) {
return PlotHelper.getPlot(world, new PlotId(x, z));
}
/**
* Get a plot based on the ID
*
* @param world
* @param x
* @param z
* @return plot, null if ID is wrong
*/
public Plot getPlot(World world, int x, int z) {
return PlotHelper.getPlot(world, new PlotId(x, z));
}
/**
* Get a plot based on the location
*
* @param l
* @return plot if found, otherwise it creates a temporary plot-
*/
public Plot getPlot(Location l) {
return PlotHelper.getCurrentPlot(l);
}
/**
* Get a plot based on the location
*
* @param l
* @return plot if found, otherwise it creates a temporary plot-
*/
public Plot getPlot(Location l) {
return PlotHelper.getCurrentPlot(l);
}
/**
* Get a plot based on the player location
*
* @param player
* @return plot if found, otherwise it creates a temporary plot
*/
public Plot getPlot(Player player) {
return this.getPlot(player.getLocation());
}
/**
* Get a plot based on the player location
*
* @param player
* @return plot if found, otherwise it creates a temporary plot
*/
public Plot getPlot(Player player) {
return this.getPlot(player.getLocation());
}
/**
* Check whether or not a player has a plot
*
* @param player
* @return true if player has a plot, false if not.
*/
public boolean hasPlot(World world, Player player) {
return (getPlots(world, player, true) != null) && (getPlots(world, player, true).length > 0);
}
/**
* Check whether or not a player has a plot
*
* @param player
* @return true if player has a plot, false if not.
*/
public boolean hasPlot(World world, Player player) {
return (getPlots(world, player, true) != null)
&& (getPlots(world, player, true).length > 0);
}
/**
* Get all plots for the player
*
* @param plr
* to search for
* @param just_owner
* should we just search for owner? Or with rights?
*/
public Plot[] getPlots(World world, Player plr, boolean just_owner) {
ArrayList<Plot> pPlots = new ArrayList<>();
for (Plot plot : PlotMain.getPlots(world).values()) {
if (just_owner) {
if ((plot.owner != null) && (plot.owner == plr.getUniqueId())) {
pPlots.add(plot);
}
} else {
if (plot.hasRights(plr)) {
pPlots.add(plot);
}
}
}
return (Plot[]) pPlots.toArray();
}
/**
* Get all plots for the player
*
* @param plr
* to search for
* @param just_owner
* should we just search for owner? Or with rights?
*/
public Plot[] getPlots(World world, Player plr, boolean just_owner) {
ArrayList<Plot> pPlots = new ArrayList<>();
for (Plot plot : PlotMain.getPlots(world).values()) {
if (just_owner) {
if ((plot.owner != null) && (plot.owner == plr.getUniqueId())) {
pPlots.add(plot);
}
} else {
if (plot.hasRights(plr)) {
pPlots.add(plot);
}
}
}
return (Plot[]) pPlots.toArray();
}
/**
* Get all plots for the world
*
* @param world
* to get plots of
* @return Plot[] - array of plot objects in world
*/
public Plot[] getPlots(World world) {
return PlotMain.getWorldPlots(world);
}
/**
* Get all plots for the world
*
* @param world
* to get plots of
* @return Plot[] - array of plot objects in world
*/
public Plot[] getPlots(World world) {
return PlotMain.getWorldPlots(world);
}
/**
* Get all plot worlds
*
* @return World[] - array of plot worlds
*/
public String[] getPlotWorlds() {
return PlotMain.getPlotWorlds();
}
/**
* Get all plot worlds
*
* @return World[] - array of plot worlds
*/
public String[] getPlotWorlds() {
return PlotMain.getPlotWorlds();
}
/**
* Get if plot world
*
* @param world
* (to check if plot world)
* @return boolean (if plot world or not)
*/
public boolean isPlotWorld(World world) {
return PlotMain.isPlotWorld(world);
}
/**
* Get if plot world
*
* @param world
* (to check if plot world)
* @return boolean (if plot world or not)
*/
public boolean isPlotWorld(World world) {
return PlotMain.isPlotWorld(world);
}
/**
* Get the settings for a world (settings bundled in PlotWorld class)
*
* @param world
* (to get settings of)
* @return PlotWorld class for ther world ! will return null if not a plot
* world
*/
public PlotWorld getWorldSettings(World world) {
return PlotMain.getWorldSettings(world);
}
/**
* Get the settings for a world (settings bundled in PlotWorld class)
*
* @param world
* (to get settings of)
* @return PlotWorld class for ther world ! will return null if not a plot
* world
*/
public PlotWorld getWorldSettings(World world) {
return PlotMain.getWorldSettings(world);
}
/**
* Get plot locations
*
* @param p
* @return [0] = bottomLc, [1] = topLoc, [2] = home
*/
public Location[] getLocations(Plot p) {
World world = Bukkit.getWorld(p.world);
return new Location[] { PlotHelper.getPlotBottomLoc(world, p.id), PlotHelper.getPlotTopLoc(world, p.id), PlotHelper.getPlotHome(world, p.id) };
}
/**
* Get plot locations
*
* @param p
* @return [0] = bottomLc, [1] = topLoc, [2] = home
*/
public Location[] getLocations(Plot p) {
World world = Bukkit.getWorld(p.world);
return new Location[] { PlotHelper.getPlotBottomLoc(world, p.id),
PlotHelper.getPlotTopLoc(world, p.id),
PlotHelper.getPlotHome(world, p.id) };
}
/**
* Get home location
*
* @param p
* @return plot bottom location
*/
public Location getHomeLocation(Plot p) {
return PlotHelper.getPlotHome(p.getWorld(), p.id);
}
/**
* Get home location
*
* @param p
* @return plot bottom location
*/
public Location getHomeLocation(Plot p) {
return PlotHelper.getPlotHome(p.getWorld(), p.id);
}
/**
* Get Bottom Location
*
* @param p
* @return plot bottom location
*/
public Location getBottomLocation(Plot p) {
World world = Bukkit.getWorld(p.world);
return PlotHelper.getPlotBottomLoc(world, p.id);
}
/**
* Get Bottom Location
*
* @param p
* @return plot bottom location
*/
public Location getBottomLocation(Plot p) {
World world = Bukkit.getWorld(p.world);
return PlotHelper.getPlotBottomLoc(world, p.id);
}
/**
* Get Top Location
*
* @param p
* @return plot top location
*/
public Location getTopLocation(Plot p) {
World world = Bukkit.getWorld(p.world);
return PlotHelper.getPlotTopLoc(world, p.id);
}
/**
* Get Top Location
*
* @param p
* @return plot top location
*/
public Location getTopLocation(Plot p) {
World world = Bukkit.getWorld(p.world);
return PlotHelper.getPlotTopLoc(world, p.id);
}
/**
* Check whether or not a player is in a plot
*
* @param player
* @return true if the player is in a plot, false if not-
*/
public boolean isInPlot(Player player) {
return PlayerFunctions.isInPlot(player);
}
/**
* Check whether or not a player is in a plot
*
* @param player
* @return true if the player is in a plot, false if not-
*/
public boolean isInPlot(Player player) {
return PlayerFunctions.isInPlot(player);
}
/**
* Register a subcommand
*
* @param c
*/
public void registerCommand(SubCommand c) {
MainCommand.subCommands.add(c);
}
/**
* Register a subcommand
*
* @param c
*/
public void registerCommand(SubCommand c) {
MainCommand.subCommands.add(c);
}
/**
* Get the plotMain class
*
* @return PlotMain Class
*/
public PlotMain getPlotMain() {
return this.plotMain;
}
/**
* Get the plotMain class
*
* @return PlotMain Class
*/
public PlotMain getPlotMain() {
return this.plotMain;
}
/**
* Get the player plot count
*
* @param player
* @return
*/
public int getPlayerPlotCount(World world, Player player) {
return PlayerFunctions.getPlayerPlotCount(world, player);
}
/**
* Get the player plot count
*
* @param player
* @return
*/
public int getPlayerPlotCount(World world, Player player) {
return PlayerFunctions.getPlayerPlotCount(world, player);
}
/**
* Get a players plots
*
* @param player
* @return a set containing the players plots
*/
public Set<Plot> getPlayerPlots(World world, Player player) {
return PlayerFunctions.getPlayerPlots(world, player);
}
/**
* Get a players plots
*
* @param player
* @return a set containing the players plots
*/
public Set<Plot> getPlayerPlots(World world, Player player) {
return PlayerFunctions.getPlayerPlots(world, player);
}
/**
* Get the allowed plot count for a player
*
* @param player
* @return the number of allowed plots
*/
public int getAllowedPlots(Player player) {
return PlayerFunctions.getAllowedPlots(player);
}
/**
* Get the allowed plot count for a player
*
* @param player
* @return the number of allowed plots
*/
public int getAllowedPlots(Player player) {
return PlayerFunctions.getAllowedPlots(player);
}
}

View File

@ -8,156 +8,172 @@
*/
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.*;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotWorld;
@SuppressWarnings("deprecation")
public class Auto extends SubCommand {
public Auto() {
super("auto", "plots.auto", "Claim the nearest plot", "auto", "a", CommandCategory.CLAIMING);
}
public Auto() {
super("auto", "plots.auto", "Claim the nearest plot", "auto", "a",
CommandCategory.CLAIMING);
}
// TODO auto claim a mega plot!!!!!!!!!!!!
@Override
public boolean execute(Player plr, String... args) {
World world;
int size_x = 1;
int size_z = 1;
String schematic = "";
if (PlotMain.getPlotWorlds().length == 1) {
world = Bukkit.getWorld(PlotMain.getPlotWorlds()[0]);
} else {
if (PlotMain.isPlotWorld(plr.getWorld())) {
world = plr.getWorld();
} else {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return false;
}
}
if (args.length > 0) {
if (PlotMain.hasPermission(plr, "plots.auto.mega")) {
try {
String[] split = args[0].split(",");
size_x = Integer.parseInt(split[0]);
size_z = Integer.parseInt(split[1]);
if ((size_x < 1) || (size_z < 1)) {
PlayerFunctions.sendMessage(plr, "&cError: size<=0");
}
if ((size_x > 4) || (size_z > 4)) {
PlayerFunctions.sendMessage(plr, "&cError: size>4");
}
if(args.length > 1) {
schematic = args[1];
}
} catch (Exception e) {
schematic = args[0];
//PlayerFunctions.sendMessage(plr, "&cError: Invalid size (X,Y)");
//return false;
}
} else {
schematic = args[0];
//PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
//return false;
}
}
if (PlayerFunctions.getPlayerPlotCount(world, plr) >= PlayerFunctions.getAllowedPlots(plr)) {
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
return false;
}
PlotWorld pWorld = PlotMain.getWorldSettings(world);
if(PlotMain.useEconomy && pWorld.USE_ECONOMY) {
double cost = pWorld.PLOT_PRICE;
cost = (size_x * size_z) * cost;
if (cost > 0d) {
Economy economy = PlotMain.economy;
if (economy.getBalance(plr) < cost) {
sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
return true;
}
economy.withdrawPlayer(plr, cost);
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
}
}
if(!schematic.equals("")) {
if (pWorld.SCHEMATIC_CLAIM_SPECIFY) {
if(pWorld.SCHEMATICS.contains(schematic.toLowerCase())) {
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
return true;
}
if (!plr.hasPermission("plots.claim." + schematic) && !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
return true;
}
}
}
boolean br = false;
int x = 0, z = 0, q = 100;
PlotId id;
if ((size_x == 1) && (size_z == 1)) {
while (!br) {
id = new PlotId(x, z);
if (PlotHelper.getPlot(world, id).owner == null) {
Plot plot = PlotHelper.getPlot(world, id);
boolean result = Claim.claimPlot(plr, plot, true);
br = !result;
}
if ((z < q) && ((z - x) < q)) {
z++;
} else if (x < q) {
x++;
z = q - 100;
} else {
q += 100;
x = q;
z = q;
}
}
} else {
while (!br) {
PlotId start = new PlotId(x, z);
PlotId end = new PlotId((x + size_x) - 1, (z + size_z) - 1);
if (isUnowned(world, start, end)) {
for (int i = start.x; i <= end.x; i++) {
for (int j = start.y; j <= end.y; j++) {
Plot plot = PlotHelper.getPlot(world, new PlotId(i, j));
boolean teleport = ((i == end.x) && (j == end.y));
Claim.claimPlot(plr, plot, teleport);
}
}
if(!PlotHelper.mergePlots(plr, world, PlayerFunctions.getPlotSelectionIds(world, start, end))) {
return false;
}
br = true;
}
if ((z < q) && ((z - x) < q)) {
z += size_z;
} else if (x < q) {
x += size_x;
z = q - 100;
} else {
q += 100;
x = q;
z = q;
}
}
}
return true;
}
// TODO auto claim a mega plot!!!!!!!!!!!!
@Override
public boolean execute(Player plr, String... args) {
World world;
int size_x = 1;
int size_z = 1;
String schematic = "";
if (PlotMain.getPlotWorlds().length == 1) {
world = Bukkit.getWorld(PlotMain.getPlotWorlds()[0]);
} else {
if (PlotMain.isPlotWorld(plr.getWorld())) {
world = plr.getWorld();
} else {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return false;
}
}
if (args.length > 0) {
if (PlotMain.hasPermission(plr, "plots.auto.mega")) {
try {
String[] split = args[0].split(",");
size_x = Integer.parseInt(split[0]);
size_z = Integer.parseInt(split[1]);
if ((size_x < 1) || (size_z < 1)) {
PlayerFunctions.sendMessage(plr, "&cError: size<=0");
}
if ((size_x > 4) || (size_z > 4)) {
PlayerFunctions.sendMessage(plr, "&cError: size>4");
}
if (args.length > 1) {
schematic = args[1];
}
} catch (Exception e) {
schematic = args[0];
// PlayerFunctions.sendMessage(plr,
// "&cError: Invalid size (X,Y)");
// return false;
}
} else {
schematic = args[0];
// PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
// return false;
}
}
if (PlayerFunctions.getPlayerPlotCount(world, plr) >= PlayerFunctions
.getAllowedPlots(plr)) {
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
return false;
}
PlotWorld pWorld = PlotMain.getWorldSettings(world);
if (PlotMain.useEconomy && pWorld.USE_ECONOMY) {
double cost = pWorld.PLOT_PRICE;
cost = (size_x * size_z) * cost;
if (cost > 0d) {
Economy economy = PlotMain.economy;
if (economy.getBalance(plr) < cost) {
sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
return true;
}
economy.withdrawPlayer(plr, cost);
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
}
}
if (!schematic.equals("")) {
if (pWorld.SCHEMATIC_CLAIM_SPECIFY) {
if (pWorld.SCHEMATICS.contains(schematic.toLowerCase())) {
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: "
+ schematic);
return true;
}
if (!plr.hasPermission("plots.claim." + schematic)
&& !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION,
schematic);
return true;
}
}
}
boolean br = false;
int x = 0, z = 0, q = 100;
PlotId id;
if ((size_x == 1) && (size_z == 1)) {
while (!br) {
id = new PlotId(x, z);
if (PlotHelper.getPlot(world, id).owner == null) {
Plot plot = PlotHelper.getPlot(world, id);
boolean result = Claim.claimPlot(plr, plot, true);
br = !result;
}
if ((z < q) && ((z - x) < q)) {
z++;
} else if (x < q) {
x++;
z = q - 100;
} else {
q += 100;
x = q;
z = q;
}
}
} else {
while (!br) {
PlotId start = new PlotId(x, z);
PlotId end = new PlotId((x + size_x) - 1, (z + size_z) - 1);
if (isUnowned(world, start, end)) {
for (int i = start.x; i <= end.x; i++) {
for (int j = start.y; j <= end.y; j++) {
Plot plot = PlotHelper.getPlot(world, new PlotId(i,
j));
boolean teleport = ((i == end.x) && (j == end.y));
Claim.claimPlot(plr, plot, teleport);
}
}
if (!PlotHelper.mergePlots(plr, world, PlayerFunctions
.getPlotSelectionIds(world, start, end))) {
return false;
}
br = true;
}
if ((z < q) && ((z - x) < q)) {
z += size_z;
} else if (x < q) {
x += size_x;
z = q - 100;
} else {
q += 100;
x = q;
z = q;
}
}
}
return true;
}
public boolean isUnowned(World world, PlotId pos1, PlotId pos2) {
for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) {
PlotId id = new PlotId(x, y);
if (PlotMain.getPlots(world).get(id) != null) {
if (PlotMain.getPlots(world).get(id).owner != null) {
return false;
}
}
}
}
return true;
}
public boolean isUnowned(World world, PlotId pos1, PlotId pos2) {
for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) {
PlotId id = new PlotId(x, y);
if (PlotMain.getPlots(world).get(id) != null) {
if (PlotMain.getPlots(world).get(id).owner != null) {
return false;
}
}
}
}
return true;
}
}

View File

@ -17,78 +17,78 @@ import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotWorld;
/**
* Created by Citymonstret on 2014-08-15.
*/
public class Camera extends SubCommand implements Listener {
private CameraAPI api;
private CameraAPI api;
public Camera() {
super("camera", "plots.camera", "Go into camera mode", "camera", "c", CommandCategory.TELEPORT);
this.api = CameraAPI.getInstance();
this.travelers = new ArrayList<String>();
}
public Camera() {
super("camera", "plots.camera", "Go into camera mode", "camera", "c",
CommandCategory.TELEPORT);
this.api = CameraAPI.getInstance();
this.travelers = new ArrayList<String>();
}
private ArrayList<String> travelers;
private ArrayList<String> travelers;
@Override
public boolean execute(Player player, String... args) {
if (!PlayerFunctions.isInPlot(player)) {
PlayerFunctions.sendMessage(player, C.NOT_IN_PLOT);
return false;
}
this.api = CameraAPI.getInstance();
Plot plot = PlotHelper.getCurrentPlot(player.getLocation());
if (this.api.isTravelling(player)) {
this.api.stopTravel(player);
PlayerFunctions.sendMessage(player, C.CAMERA_STOPPED);
return true;
}
this.api.travel(getController(player, plot));
PlayerFunctions.sendMessage(player, C.CAMERA_STARTED, plot.getId().x + ";" + plot.getId().y);
this.travelers.add(player.getName());
return true;
}
@Override
public boolean execute(Player player, String... args) {
if (!PlayerFunctions.isInPlot(player)) {
PlayerFunctions.sendMessage(player, C.NOT_IN_PLOT);
return false;
}
this.api = CameraAPI.getInstance();
Plot plot = PlotHelper.getCurrentPlot(player.getLocation());
if (this.api.isTravelling(player)) {
this.api.stopTravel(player);
PlayerFunctions.sendMessage(player, C.CAMERA_STOPPED);
return true;
}
this.api.travel(getController(player, plot));
PlayerFunctions.sendMessage(player, C.CAMERA_STARTED, plot.getId().x
+ ";" + plot.getId().y);
this.travelers.add(player.getName());
return true;
}
@EventHandler
public void onTravelEnded(TravelEndEvent event) {
if (this.travelers.contains(event.getPlayer().getName())) {
@EventHandler
public void onTravelEnded(TravelEndEvent event) {
if (this.travelers.contains(event.getPlayer().getName())) {
this.travelers.remove(event.getPlayer().getName());
PlayerFunctions.sendMessage(event.getPlayer(), C.CAMERA_STOPPED);
}
if (this.travelers.contains(event.getPlayer().getName())) {
event.getHandlers().bake();
}
}
this.travelers.remove(event.getPlayer().getName());
PlayerFunctions.sendMessage(event.getPlayer(), C.CAMERA_STOPPED);
}
if (this.travelers.contains(event.getPlayer().getName())) {
event.getHandlers().bake();
}
}
public CameraController getController(Player player, Plot plot) {
World w = Bukkit.getWorld(plot.world);
PlotWorld plotworld = PlotMain.getWorldSettings(w);
int seconds = plotworld.PLOT_WIDTH * 5;
Location loc1, loc2, loc3, loc4, loc5;
double y = player.getLocation().getY();
Location bottomLoc = PlotHelper.getPlotBottomLoc(w, plot.id);
Location topLoc = PlotHelper.getPlotTopLoc(w, plot.id);
World world = bottomLoc.getWorld();
int maxX = Math.max(bottomLoc.getBlockX(), topLoc.getBlockX());
int maxZ = Math.max(bottomLoc.getBlockZ(), topLoc.getBlockZ());
int minX = Math.min(bottomLoc.getBlockX(), topLoc.getBlockX());
int minZ = Math.min(bottomLoc.getBlockZ(), topLoc.getBlockZ());
loc1 = new Location(world, maxX, y, maxZ);
loc2 = new Location(world, maxX, y, minZ);
loc3 = new Location(world, minX, y, minZ);
loc4 = new Location(world, minX, y, maxZ);
loc1.setYaw(((3 / 4.0F) * 360.0F) - 0.5F);
loc3.setYaw(((1 / 4.0F) * 360.0F) - 0.5F);
loc4.setYaw(((2 / 4.0F) * 360.0F) - 0.5F);
loc2.setYaw(((0 / 4.0F) * 360.0F) - 0.5F);
loc5 = loc1.clone();
CameraController controller = this.api.createController(player, seconds, loc1, loc2, loc3, loc4, loc5);
return controller;
}
public CameraController getController(Player player, Plot plot) {
World w = Bukkit.getWorld(plot.world);
int seconds = PlotHelper.getPlotWidth(w, plot.id) * 5;
Location loc1, loc2, loc3, loc4, loc5;
double y = player.getLocation().getY();
Location bottomLoc = PlotHelper.getPlotBottomLoc(w, plot.id);
Location topLoc = PlotHelper.getPlotTopLoc(w, plot.id);
World world = bottomLoc.getWorld();
int maxX = Math.max(bottomLoc.getBlockX(), topLoc.getBlockX());
int maxZ = Math.max(bottomLoc.getBlockZ(), topLoc.getBlockZ());
int minX = Math.min(bottomLoc.getBlockX(), topLoc.getBlockX());
int minZ = Math.min(bottomLoc.getBlockZ(), topLoc.getBlockZ());
loc1 = new Location(world, maxX, y, maxZ);
loc2 = new Location(world, maxX, y, minZ);
loc3 = new Location(world, minX, y, minZ);
loc4 = new Location(world, minX, y, maxZ);
loc1.setYaw(((3 / 4.0F) * 360.0F) - 0.5F);
loc3.setYaw(((1 / 4.0F) * 360.0F) - 0.5F);
loc4.setYaw(((2 / 4.0F) * 360.0F) - 0.5F);
loc2.setYaw(((0 / 4.0F) * 360.0F) - 0.5F);
loc5 = loc1.clone();
CameraController controller = this.api.createController(player,
seconds, loc1, loc2, loc3, loc4, loc5);
return controller;
}
}

View File

@ -15,6 +15,7 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.FlagManager;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
@ -24,99 +25,106 @@ import com.intellectualcrafters.plot.SchematicHandler;
import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent;
/**
*
*
* @author Citymonstret
*
*
*/
public class Claim extends SubCommand {
public Claim() {
super(Command.CLAIM, "Claim the current plot you're standing on.", "claim", CommandCategory.CLAIMING);
}
public Claim() {
super(Command.CLAIM, "Claim the current plot you're standing on.",
"claim", CommandCategory.CLAIMING);
}
@Override
public boolean execute(Player plr, String... args) {
String schematic = "";
if (args.length >= 1) {
schematic = args[0];
}
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
return true;
}
if (PlayerFunctions.getPlayerPlotCount(plr.getWorld(), plr) >= PlayerFunctions.getAllowedPlots(plr)) {
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
return true;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (plot.hasOwner()) {
PlayerFunctions.sendMessage(plr, C.PLOT_IS_CLAIMED);
return false;
}
PlotWorld world = PlotMain.getWorldSettings(plot.getWorld());
if (PlotMain.useEconomy && world.USE_ECONOMY) {
double cost = world.PLOT_PRICE;
if (cost > 0d) {
Economy economy = PlotMain.economy;
if (economy.getBalance(plr) < cost) {
sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
return true;
}
economy.withdrawPlayer(plr, cost);
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
}
}
if (!schematic.equals("")) {
if (world.SCHEMATIC_CLAIM_SPECIFY) {
if (!world.SCHEMATICS.contains(schematic.toLowerCase())) {
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
return true;
}
if (!plr.hasPermission("plots.claim." + schematic) && !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
return true;
}
}
}
boolean result = claimPlot(plr, plot, false, schematic);
if (result) {
PlayerFunctions.sendMessage(plr, C.PLOT_NOT_CLAIMED);
return false;
}
return true;
@Override
public boolean execute(Player plr, String... args) {
String schematic = "";
if (args.length >= 1) {
schematic = args[0];
}
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
return true;
}
if (PlayerFunctions.getPlayerPlotCount(plr.getWorld(), plr) >= PlayerFunctions
.getAllowedPlots(plr)) {
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
return true;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (plot.hasOwner()) {
PlayerFunctions.sendMessage(plr, C.PLOT_IS_CLAIMED);
return false;
}
PlotWorld world = PlotMain.getWorldSettings(plot.getWorld());
if (PlotMain.useEconomy && world.USE_ECONOMY) {
double cost = world.PLOT_PRICE;
if (cost > 0d) {
Economy economy = PlotMain.economy;
if (economy.getBalance(plr) < cost) {
sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
return true;
}
economy.withdrawPlayer(plr, cost);
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
}
}
if (!schematic.equals("")) {
if (world.SCHEMATIC_CLAIM_SPECIFY) {
if (!world.SCHEMATICS.contains(schematic.toLowerCase())) {
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: "
+ schematic);
return true;
}
if (!plr.hasPermission("plots.claim." + schematic)
&& !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION,
schematic);
return true;
}
}
}
boolean result = claimPlot(plr, plot, false, schematic);
if (result) {
PlayerFunctions.sendMessage(plr, C.PLOT_NOT_CLAIMED);
return false;
}
return true;
}
}
public static boolean claimPlot(Player player, Plot plot, boolean teleport) {
return claimPlot(player, plot, teleport, "");
}
public static boolean claimPlot(Player player, Plot plot, boolean teleport) {
return claimPlot(player, plot, teleport, "");
}
public static boolean claimPlot(Player player, Plot plot, boolean teleport, String schematic) {
PlayerClaimPlotEvent event = new PlayerClaimPlotEvent(player, plot);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
PlotHelper.createPlot(player, plot);
PlotHelper.setSign(player, plot);
PlayerFunctions.sendMessage(player, C.CLAIMED);
if (teleport) {
PlotMain.teleportPlayer(player, player.getLocation(), plot);
}
PlotWorld world = PlotMain.getWorldSettings(plot.getWorld());
if (world.SCHEMATIC_ON_CLAIM) {
SchematicHandler handler = new SchematicHandler();
SchematicHandler.Schematic sch;
if (schematic.equals("")) {
sch = handler.getSchematic(world.SCHEMATIC_FILE);
} else {
sch = handler.getSchematic(schematic);
if (sch == null) {
sch = handler.getSchematic(world.SCHEMATIC_FILE);
}
}
handler.paste(player.getLocation(), sch, plot);
}
plot.settings.setFlags(PlotMain.getWorldSettings(player.getWorld()).DEFAULT_FLAGS);
}
return event.isCancelled();
}
public static boolean claimPlot(Player player, Plot plot, boolean teleport,
String schematic) {
PlayerClaimPlotEvent event = new PlayerClaimPlotEvent(player, plot);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
PlotHelper.createPlot(player, plot);
PlotHelper.setSign(player, plot);
PlayerFunctions.sendMessage(player, C.CLAIMED);
if (teleport) {
PlotMain.teleportPlayer(player, player.getLocation(), plot);
}
PlotWorld world = PlotMain.getWorldSettings(plot.getWorld());
if (world.SCHEMATIC_ON_CLAIM) {
SchematicHandler handler = new SchematicHandler();
SchematicHandler.Schematic sch;
if (schematic.equals("")) {
sch = handler.getSchematic(world.SCHEMATIC_FILE);
} else {
sch = handler.getSchematic(schematic);
if (sch == null) {
sch = handler.getSchematic(world.SCHEMATIC_FILE);
}
}
handler.paste(player.getLocation(), sch, plot);
}
plot.settings.setFlags(FlagManager.parseFlags(PlotMain
.getWorldSettings(player.getWorld()).DEFAULT_FLAGS));
}
return event.isCancelled();
}
}

View File

@ -20,22 +20,24 @@ import com.intellectualcrafters.plot.Plot;
*/
public class Clear extends SubCommand {
public Clear() {
super(Command.CLEAR, "Clear a plot", "clear", CommandCategory.ACTIONS);
}
public Clear() {
super(Command.CLEAR, "Clear a plot", "clear", CommandCategory.ACTIONS);
}
@Override
public boolean execute(Player plr, String... args) {
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, "You're not in a plot.");
return false;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
plot.clear(plr);
return true;
}
@Override
public boolean execute(Player plr, String... args) {
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, "You're not in a plot.");
return false;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(
plr.getUniqueId()))
&& !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
plot.clear(plr);
return true;
}
}

View File

@ -11,167 +11,167 @@ package com.intellectualcrafters.plot.commands;
/**
* Created by Citymonstret on 2014-08-03.
*
*
* @author Citymonstret
*/
public enum Command {
// TODO new commands
// (allow a plot to be transferred from one plot to another of the same
// size)
// - /plot copy
// - /plot paste
// (economy)
// - /plot buy
// - /plot sell <value>
// (Rating system) (ratings can be stored as the average, and number of
// ratings)
// - /plot rate <number out of 10>
// - /plot list <some parameter to list the most popular, and highest rated
// plots>
TRUSTED("trusted", "trust"),
/**
*
*/
COPY("copy"),
/**
*
*/
KICK("kick", "k"),
/**
*
*/
HELPERS("helpers", "hp"),
/**
*
*/
DENIED("denied", "dn"),
/**
*
*/
CLAIM("claim", "c"),
/**
*
*/
MERGE("merge", "m"),
/**
*
*/
UNLINK("unlink", "u"),
/**
*
*/
CLEAR("clear", "clear", new CommandPermission("plots.clear")),
/**
*
*/
DELETE("delete", "d", new CommandPermission("plots.delete")),
/**
*
*/
DEBUG("debug", "database", new CommandPermission("plots.admin")),
/**
*
*/
HOME("home", "h"),
/**
*
*/
INFO("info", "i"),
/**
*
*/
LIST("list", "l"),
/**
*
*/
SET("set", "s"),
/**
*
*/
SETUP("setup"),
/**
*
*/
TP("tp", "tp");
/**
*
*/
private String command;
/**
*
*/
private String alias;
/**
*
*/
private CommandPermission permission;
// TODO new commands
// (allow a plot to be transferred from one plot to another of the same
// size)
// - /plot copy
// - /plot paste
// (economy)
// - /plot buy
// - /plot sell <value>
// (Rating system) (ratings can be stored as the average, and number of
// ratings)
// - /plot rate <number out of 10>
// - /plot list <some parameter to list the most popular, and highest rated
// plots>
TRUSTED("trusted", "trust"),
/**
*
*/
COPY("copy"),
/**
*
*/
KICK("kick", "k"),
/**
*
*/
HELPERS("helpers", "hp"),
/**
*
*/
DENIED("denied", "dn"),
/**
*
*/
CLAIM("claim", "c"),
/**
*
*/
MERGE("merge", "m"),
/**
*
*/
UNLINK("unlink", "u"),
/**
*
*/
CLEAR("clear", "clear", new CommandPermission("plots.clear")),
/**
*
*/
DELETE("delete", "d", new CommandPermission("plots.delete")),
/**
*
*/
DEBUG("debug", "database", new CommandPermission("plots.admin")),
/**
*
*/
HOME("home", "h"),
/**
*
*/
INFO("info", "i"),
/**
*
*/
LIST("list", "l"),
/**
*
*/
SET("set", "s"),
/**
*
*/
SETUP("setup"),
/**
*
*/
TP("tp", "tp");
/**
*
*/
private String command;
/**
*
*/
private String alias;
/**
*
*/
private CommandPermission permission;
/**
*
* @param command
*/
Command(String command) {
this.command = command;
this.alias = command;
this.permission = new CommandPermission("plots." + command);
}
/**
*
* @param command
*/
Command(String command) {
this.command = command;
this.alias = command;
this.permission = new CommandPermission("plots." + command);
}
/**
*
* @param command
* @param permission
*/
Command(String command, CommandPermission permission) {
this.command = command;
this.permission = permission;
this.alias = command;
}
/**
*
* @param command
* @param permission
*/
Command(String command, CommandPermission permission) {
this.command = command;
this.permission = permission;
this.alias = command;
}
/**
*
* @param command
* @param alias
*/
Command(String command, String alias) {
this.command = command;
this.alias = alias;
this.permission = new CommandPermission("plots." + command);
}
/**
*
* @param command
* @param alias
*/
Command(String command, String alias) {
this.command = command;
this.alias = alias;
this.permission = new CommandPermission("plots." + command);
}
/**
*
* @param Command
* @param alias
* @param permission
*/
Command(String command, String alias, CommandPermission permission) {
this.command = command;
this.alias = alias;
this.permission = permission;
}
/**
*
* @param Command
* @param alias
* @param permission
*/
Command(String command, String alias, CommandPermission permission) {
this.command = command;
this.alias = alias;
this.permission = permission;
}
/**
*
* @return
*/
public String getCommand() {
return this.command;
}
/**
*
* @return
*/
public String getCommand() {
return this.command;
}
/**
*
* @return
*/
public String getAlias() {
return this.alias;
}
/**
*
* @return
*/
public String getAlias() {
return this.alias;
}
/**
*
* @return
*/
public CommandPermission getPermission() {
return this.permission;
}
/**
*
* @return
*/
public CommandPermission getPermission() {
return this.permission;
}
}

View File

@ -13,29 +13,30 @@ import org.bukkit.entity.Player;
/**
* Created by Citymonstret on 2014-08-03.
*
*
* @author Citymonstret
*/
public class CommandPermission {
/**
*
*/
private String permission;
/**
*
*/
private String permission;
/**
* @param permission
*/
public CommandPermission(String permission) {
this.permission = permission.toLowerCase();
}
/**
* @param permission
*/
public CommandPermission(String permission) {
this.permission = permission.toLowerCase();
}
/**
*
* @param player
* @return
*/
public boolean hasPermission(Player player) {
return player.hasPermission(this.permission) || player.hasPermission("plots.admin");
}
/**
*
* @param player
* @return
*/
public boolean hasPermission(Player player) {
return player.hasPermission(this.permission)
|| player.hasPermission("plots.admin");
}
}

View File

@ -20,22 +20,24 @@ import com.intellectualcrafters.plot.Plot;
*/
public class Copy extends SubCommand {
public Copy() {
super(Command.COPY, "Copy a plot", "clear", CommandCategory.ACTIONS);
}
public Copy() {
super(Command.COPY, "Copy a plot", "clear", CommandCategory.ACTIONS);
}
@Override
public boolean execute(Player plr, String... args) {
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, "You're not in a plot.");
return false;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
plot.clear(plr);
return true;
}
@Override
public boolean execute(Player plr, String... args) {
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, "You're not in a plot.");
return false;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(
plr.getUniqueId()))
&& !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
plot.clear(plr);
return true;
}
}

View File

@ -31,92 +31,105 @@ import com.intellectualcrafters.plot.RUtils;
*/
public class Debug extends SubCommand {
// private extends SubCommand^Implements {Command, Information} from
// >>\\S.txt6\\
public Debug() {
super(Command.DEBUG, "Show debug information", "debug [msg]", CommandCategory.INFO);
{
/**
* This.
*/
}
}
// private extends SubCommand^Implements {Command, Information} from
// >>\\S.txt6\\
public Debug() {
super(Command.DEBUG, "Show debug information", "debug [msg]",
CommandCategory.INFO);
{
/**
* This.
*/
}
}
@Override
public boolean execute(Player plr, String... args) {
PlotMain.getWorldSettings(plr.getWorld());
if ((args.length > 0) && args[0].equalsIgnoreCase("msg")) {
StringBuilder msg = new StringBuilder();
for (C c : C.values()) {
msg.append(c.s() + "\n");
}
PlayerFunctions.sendMessage(plr, msg.toString());
return true;
}
StringBuilder information;
String header, line, section;
/**
* {$notnull || compile:: \\Debug:Captions\\}
*/
{
information = new StringBuilder();
header = C.DEUBG_HEADER.s();
line = C.DEBUG_LINE.s();
section = C.DEBUG_SECTION.s();
}
/**
* {||direct:: load: debug::I>Captions::trsl} \\ if(missing)
* set(default) -> this->(){} \\ echo line->line(Compiler.cpp ->
* lineCompiler); when finished: now = this();
* now(getter)->setter(this())->{ "string" = getter(this);
* setter(string) = getter(this->setter); } when ^ finished compile;
* if(^compile failed -> |this->failed.|tests->failed.| ||run test
* {this->test}|on fail(action(){return FAILED})|
*/
{
StringBuilder worlds = new StringBuilder("");
for (String world : PlotMain.getPlotWorlds()) {
worlds.append(world + " ");
}
information.append(header);
information.append(getSection(section, "Lag / TPS"));
information.append(getLine(line, "Ticks Per Second", Lag.getTPS()));
information.append(getLine(line, "Lag Percentage", (int) Lag.getPercentage() + "%"));
information.append(getLine(line, "TPS Percentage", (int) Lag.getFullPercentage() + "%"));
information.append(getSection(section, "PlotWorld"));
information.append(getLine(line, "Plot Worlds", worlds));
information.append(getLine(line, "Owned Plots", PlotMain.getPlots().size()));
// information.append(getLine(line, "PlotWorld Size",
// PlotHelper.getWorldFolderSize() + "MB"));
for (String world : PlotMain.getPlotWorlds()) {
information.append(getLine(line, "World: " + world + " size", PlotHelper.getWorldFolderSize(Bukkit.getWorld(world))));
}
information.append(getLine(line, "Entities", PlotHelper.getEntities(plr.getWorld())));
information.append(getLine(line, "Loaded Tile Entities", PlotHelper.getTileEntities(plr.getWorld())));
information.append(getLine(line, "Loaded Chunks", PlotHelper.getLoadedChunks(plr.getWorld())));
information.append(getSection(section, "RAM"));
information.append(getLine(line, "Free Ram", RUtils.getFreeRam() + "MB"));
information.append(getLine(line, "Total Ram", RUtils.getTotalRam() + "MB"));
information.append(getSection(section, "Messages"));
information.append(getLine(line, "Total Messages", C.values().length));
information.append(getLine(line, "View all captions", "/plot debug msg"));
}
/**
* {function:: SEND_MESSAGE |local player -> plr|local string ->
* information.toString())}
*/
{
PlayerFunctions.sendMessage(plr, information.toString());
}
return true;
}
@Override
public boolean execute(Player plr, String... args) {
PlotMain.getWorldSettings(plr.getWorld());
if ((args.length > 0) && args[0].equalsIgnoreCase("msg")) {
StringBuilder msg = new StringBuilder();
for (C c : C.values()) {
msg.append(c.s() + "\n");
}
PlayerFunctions.sendMessage(plr, msg.toString());
return true;
}
StringBuilder information;
String header, line, section;
/**
* {$notnull || compile:: \\Debug:Captions\\}
*/
{
information = new StringBuilder();
header = C.DEUBG_HEADER.s();
line = C.DEBUG_LINE.s();
section = C.DEBUG_SECTION.s();
}
/**
* {||direct:: load: debug::I>Captions::trsl} \\ if(missing)
* set(default) -> this->(){} \\ echo line->line(Compiler.cpp ->
* lineCompiler); when finished: now = this();
* now(getter)->setter(this())->{ "string" = getter(this);
* setter(string) = getter(this->setter); } when ^ finished compile;
* if(^compile failed -> |this->failed.|tests->failed.| ||run test
* {this->test}|on fail(action(){return FAILED})|
*/
{
StringBuilder worlds = new StringBuilder("");
for (String world : PlotMain.getPlotWorlds()) {
worlds.append(world + " ");
}
information.append(header);
information.append(getSection(section, "Lag / TPS"));
information.append(getLine(line, "Ticks Per Second", Lag.getTPS()));
information.append(getLine(line, "Lag Percentage",
(int) Lag.getPercentage() + "%"));
information.append(getLine(line, "TPS Percentage",
(int) Lag.getFullPercentage() + "%"));
information.append(getSection(section, "PlotWorld"));
information.append(getLine(line, "Plot Worlds", worlds));
information.append(getLine(line, "Owned Plots", PlotMain.getPlots()
.size()));
// information.append(getLine(line, "PlotWorld Size",
// PlotHelper.getWorldFolderSize() + "MB"));
for (String world : PlotMain.getPlotWorlds()) {
information.append(getLine(line, "World: " + world + " size",
PlotHelper.getWorldFolderSize(Bukkit.getWorld(world))));
}
information.append(getLine(line, "Entities",
PlotHelper.getEntities(plr.getWorld())));
information.append(getLine(line, "Loaded Tile Entities",
PlotHelper.getTileEntities(plr.getWorld())));
information.append(getLine(line, "Loaded Chunks",
PlotHelper.getLoadedChunks(plr.getWorld())));
information.append(getSection(section, "RAM"));
information.append(getLine(line, "Free Ram", RUtils.getFreeRam()
+ "MB"));
information.append(getLine(line, "Total Ram", RUtils.getTotalRam()
+ "MB"));
information.append(getSection(section, "Messages"));
information.append(getLine(line, "Total Messages",
C.values().length));
information.append(getLine(line, "View all captions",
"/plot debug msg"));
}
/**
* {function:: SEND_MESSAGE |local player -> plr|local string ->
* information.toString())}
*/
{
PlayerFunctions.sendMessage(plr, information.toString());
}
return true;
}
private String getSection(String line, String val) {
return line.replaceAll("%val%", val) + "\n";
}
private String getSection(String line, String val) {
return line.replaceAll("%val%", val) + "\n";
}
private String getLine(String line, String var, Object val) {
return line.replaceAll("%var%", var).replaceAll("%val%", "" + val) + "\n";
}
private String getLine(String line, String var, Object val) {
return line.replaceAll("%var%", var).replaceAll("%val%", "" + val)
+ "\n";
}
}

View File

@ -9,52 +9,64 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.*;
import com.intellectualcrafters.plot.database.DBFunc;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotWorld;
import com.intellectualcrafters.plot.database.DBFunc;
/**
* Created by Citymonstret on 2014-08-01.
*/
public class Delete extends SubCommand {
public Delete() {
super(Command.DELETE, "Delete a plot", "delete", CommandCategory.ACTIONS);
}
public Delete() {
super(Command.DELETE, "Delete a plot", "delete",
CommandCategory.ACTIONS);
}
@Override
public boolean execute(Player plr, String... args) {
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, "You're not in a plot.");
return false;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (!PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) {
PlayerFunctions.sendMessage(plr, C.UNLINK_REQUIRED);
return false;
}
if ((((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId()))) && !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
PlotWorld pWorld = PlotMain.getWorldSettings(plot.getWorld());
if(PlotMain.useEconomy && pWorld.USE_ECONOMY) {
double c = pWorld.SELL_PRICE;
if(c > 0d) {
Economy economy = PlotMain.economy;
economy.depositPlayer(plr, c);
sendMessage(plr, C.ADDED_BALANCE, c + "");
}
}
boolean result = PlotMain.removePlot(plr.getWorld().getName(), plot.id, true);
if (result) {
PlotHelper.removeSign(plr, plot);
plot.clear(plr);
DBFunc.delete(plr.getWorld().getName(), plot);
} else {
PlayerFunctions.sendMessage(plr, "Plot clearing has been denied.");
}
return true;
}
@Override
public boolean execute(Player plr, String... args) {
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, "You're not in a plot.");
return false;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (!PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(
PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) {
PlayerFunctions.sendMessage(plr, C.UNLINK_REQUIRED);
return false;
}
if ((((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(
plr.getUniqueId())))
&& !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
PlotWorld pWorld = PlotMain.getWorldSettings(plot.getWorld());
if (PlotMain.useEconomy && pWorld.USE_ECONOMY) {
double c = pWorld.SELL_PRICE;
if (c > 0d) {
Economy economy = PlotMain.economy;
economy.depositPlayer(plr, c);
sendMessage(plr, C.ADDED_BALANCE, c + "");
}
}
boolean result = PlotMain.removePlot(plr.getWorld().getName(), plot.id,
true);
if (result) {
PlotHelper.removeSign(plr, plot);
plot.clear(plr);
DBFunc.delete(plr.getWorld().getName(), plot);
} else {
PlayerFunctions.sendMessage(plr, "Plot clearing has been denied.");
}
return true;
}
}

View File

@ -9,17 +9,17 @@
package com.intellectualcrafters.plot.commands;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.UUIDHandler;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.events.PlayerPlotDeniedEvent;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.util.UUID;
/**
* Created by Citymonstret on 2014-08-03.
@ -27,118 +27,100 @@ import java.util.UUID;
@SuppressWarnings("deprecated")
public class Denied extends SubCommand {
public Denied() {
super(Command.DENIED, "Manage plot helpers", "denied {add|remove} {player}", CommandCategory.ACTIONS);
}
public Denied() {
super(Command.DENIED, "Manage plot helpers",
"denied {add|remove} {player}", CommandCategory.ACTIONS);
}
private boolean hasBeenOnServer(String name) {
Player plr = Bukkit.getPlayer(name);
if (plr == null) {
OfflinePlayer oplr = Bukkit.getPlayer(name);
if (oplr == null) {
return false;
} else {
return oplr.hasPlayedBefore();
}
} else {
if (plr.isOnline()) {
return true;
} else {
return plr.hasPlayedBefore();
}
}
}
@Override
public boolean execute(Player plr, String... args) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.DENIED_NEED_ARGUMENT);
return true;
}
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
return true;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if ((plot.owner == null) || !plot.hasRights(plr)) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
return true;
}
if (args[0].equalsIgnoreCase("add")) {
if (args[1].equalsIgnoreCase("*")) {
UUID uuid = DBFunc.everyone;
plot.addDenied(uuid);
DBFunc.setDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
PlayerFunctions.sendMessage(plr, C.DENIED_ADDED);
return true;
}
/*if (!hasBeenOnServer(args[1])) {
PlayerFunctions.sendMessage(plr, C.PLAYER_HAS_NOT_BEEN_ON);
return true;
}
UUID uuid = null;
if ((Bukkit.getPlayer(args[1]) != null)) {
uuid = Bukkit.getPlayer(args[1]).getUniqueId();
} else {
uuid = Bukkit.getOfflinePlayer(args[1]).getUniqueId();
}
if (uuid == null) {
PlayerFunctions.sendMessage(plr, C.PLAYER_HAS_NOT_BEEN_ON);
return true;
}*/
UUID uuid = UUIDHandler.getUUID(args[1]);
plot.addDenied(uuid);
DBFunc.setDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
PlayerPlotDeniedEvent event = new PlayerPlotDeniedEvent(plr, plot, uuid, true);
Bukkit.getPluginManager().callEvent(event);
PlayerFunctions.sendMessage(plr, C.DENIED_ADDED);
if ((Bukkit.getPlayer(uuid) != null) && Bukkit.getPlayer(uuid).isOnline()) {
Plot pl = PlayerFunctions.getCurrentPlot(Bukkit.getPlayer((uuid)));
if (pl.id == plot.id) {
PlayerFunctions.sendMessage(Bukkit.getPlayer(uuid), C.YOU_BE_DENIED);
Bukkit.getPlayer(uuid).teleport(Bukkit.getPlayer(uuid).getWorld().getSpawnLocation());
}
}
} else if (args[0].equalsIgnoreCase("remove")) {
if (args[1].equalsIgnoreCase("*")) {
UUID uuid = DBFunc.everyone;
if (!plot.denied.contains(uuid)) {
PlayerFunctions.sendMessage(plr, C.WAS_NOT_ADDED);
return true;
}
plot.removeDenied(uuid);
DBFunc.removeDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
PlayerFunctions.sendMessage(plr, C.DENIED_REMOVED);
return true;
}
/*if (!hasBeenOnServer(args[1])) {
PlayerFunctions.sendMessage(plr, C.PLAYER_HAS_NOT_BEEN_ON);
return true;
}
UUID uuid = null;
if (Bukkit.getPlayer(args[1])!=null) {
uuid = Bukkit.getPlayer(args[1]).getUniqueId();
} else {
uuid = Bukkit.getOfflinePlayer(args[1]).getUniqueId();
}
if (!plot.denied.contains(uuid)) {
PlayerFunctions.sendMessage(plr, C.WAS_NOT_ADDED);
return true;
}
if (uuid == null) {
PlayerFunctions.sendMessage(plr, C.PLAYER_HAS_NOT_BEEN_ON);
return true;
}*/
UUID uuid = UUIDHandler.getUUID(args[1]);
plot.removeDenied(uuid);
DBFunc.removeDenied(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
PlayerPlotDeniedEvent event = new PlayerPlotDeniedEvent(plr, plot, uuid, false);
Bukkit.getPluginManager().callEvent(event);
PlayerFunctions.sendMessage(plr, C.DENIED_REMOVED);
} else {
PlayerFunctions.sendMessage(plr, C.DENIED_NEED_ARGUMENT);
return true;
}
return true;
}
@Override
public boolean execute(Player plr, String... args) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.DENIED_NEED_ARGUMENT);
return true;
}
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
return true;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if ((plot.owner == null) || !plot.hasRights(plr)) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
return true;
}
if (args[0].equalsIgnoreCase("add")) {
if (args[1].equalsIgnoreCase("*")) {
UUID uuid = DBFunc.everyone;
plot.addDenied(uuid);
DBFunc.setDenied(plr.getWorld().getName(), plot,
Bukkit.getOfflinePlayer(args[1]));
PlayerFunctions.sendMessage(plr, C.DENIED_ADDED);
return true;
}
/*
* if (!hasBeenOnServer(args[1])) { PlayerFunctions.sendMessage(plr,
* C.PLAYER_HAS_NOT_BEEN_ON); return true; } UUID uuid = null; if
* ((Bukkit.getPlayer(args[1]) != null)) { uuid =
* Bukkit.getPlayer(args[1]).getUniqueId(); } else { uuid =
* Bukkit.getOfflinePlayer(args[1]).getUniqueId(); } if (uuid ==
* null) { PlayerFunctions.sendMessage(plr,
* C.PLAYER_HAS_NOT_BEEN_ON); return true; }
*/
UUID uuid = UUIDHandler.getUUID(args[1]);
plot.addDenied(uuid);
DBFunc.setDenied(plr.getWorld().getName(), plot,
Bukkit.getOfflinePlayer(args[1]));
PlayerPlotDeniedEvent event = new PlayerPlotDeniedEvent(plr, plot,
uuid, true);
Bukkit.getPluginManager().callEvent(event);
PlayerFunctions.sendMessage(plr, C.DENIED_ADDED);
if ((Bukkit.getPlayer(uuid) != null)
&& Bukkit.getPlayer(uuid).isOnline()) {
Plot pl = PlayerFunctions.getCurrentPlot(Bukkit
.getPlayer((uuid)));
if (pl.id == plot.id) {
PlayerFunctions.sendMessage(Bukkit.getPlayer(uuid),
C.YOU_BE_DENIED);
Bukkit.getPlayer(uuid).teleport(
Bukkit.getPlayer(uuid).getWorld()
.getSpawnLocation());
}
}
} else if (args[0].equalsIgnoreCase("remove")) {
if (args[1].equalsIgnoreCase("*")) {
UUID uuid = DBFunc.everyone;
if (!plot.denied.contains(uuid)) {
PlayerFunctions.sendMessage(plr, C.WAS_NOT_ADDED);
return true;
}
plot.removeDenied(uuid);
DBFunc.removeDenied(plr.getWorld().getName(), plot,
Bukkit.getOfflinePlayer(args[1]));
PlayerFunctions.sendMessage(plr, C.DENIED_REMOVED);
return true;
}
/*
* if (!hasBeenOnServer(args[1])) { PlayerFunctions.sendMessage(plr,
* C.PLAYER_HAS_NOT_BEEN_ON); return true; } UUID uuid = null; if
* (Bukkit.getPlayer(args[1])!=null) { uuid =
* Bukkit.getPlayer(args[1]).getUniqueId(); } else { uuid =
* Bukkit.getOfflinePlayer(args[1]).getUniqueId(); } if
* (!plot.denied.contains(uuid)) { PlayerFunctions.sendMessage(plr,
* C.WAS_NOT_ADDED); return true; } if (uuid == null) {
* PlayerFunctions.sendMessage(plr, C.PLAYER_HAS_NOT_BEEN_ON);
* return true; }
*/
UUID uuid = UUIDHandler.getUUID(args[1]);
plot.removeDenied(uuid);
DBFunc.removeDenied(plr.getWorld().getName(), plot,
Bukkit.getOfflinePlayer(args[1]));
PlayerPlotDeniedEvent event = new PlayerPlotDeniedEvent(plr, plot,
uuid, false);
Bukkit.getPluginManager().callEvent(event);
PlayerFunctions.sendMessage(plr, C.DENIED_REMOVED);
} else {
PlayerFunctions.sendMessage(plr, C.DENIED_NEED_ARGUMENT);
return true;
}
return true;
}
}

View File

@ -15,12 +15,13 @@ import org.bukkit.entity.Player;
* Created by Citymonstret on 2014-08-11.
*/
public class Help extends SubCommand {
public Help() {
super("help", "", "Get this help menu", "help", "he", SubCommand.CommandCategory.INFO);
}
public Help() {
super("help", "", "Get this help menu", "help", "he",
SubCommand.CommandCategory.INFO);
}
@Override
public boolean execute(Player plr, String... args) {
return false;
}
@Override
public boolean execute(Player plr, String... args) {
return false;
}
}

View File

@ -9,126 +9,103 @@
package com.intellectualcrafters.plot.commands;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.UUIDHandler;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.events.PlayerPlotHelperEvent;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.util.UUID;
@SuppressWarnings("deprecation")
public class Helpers extends SubCommand {
public Helpers() {
super(Command.HELPERS, "Manage plot helpers", "helpers {add|remove} {player}", CommandCategory.ACTIONS);
}
public Helpers() {
super(Command.HELPERS, "Manage plot helpers",
"helpers {add|remove} {player}", CommandCategory.ACTIONS);
}
private boolean hasBeenOnServer(String name) {
Player plr = Bukkit.getPlayer(name);
if (plr == null) {
OfflinePlayer oplr = Bukkit.getOfflinePlayer(name);
if (oplr == null) {
return false;
} else {
return oplr.hasPlayedBefore();
}
} else {
if (plr.isOnline()) {
return true;
} else {
return plr.hasPlayedBefore();
}
}
}
@Override
public boolean execute(Player plr, String... args) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.HELPER_NEED_ARGUMENT);
return true;
}
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
return true;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if ((plot.owner == null) || !plot.hasRights(plr)) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
return true;
}
if (args[0].equalsIgnoreCase("add")) {
if (args[1].equalsIgnoreCase("*")) {
UUID uuid = DBFunc.everyone;
plot.addHelper(uuid);
DBFunc.setHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
PlayerFunctions.sendMessage(plr, C.HELPER_ADDED);
return true;
}
/*if (!hasBeenOnServer(args[1])) {
PlayerFunctions.sendMessage(plr, C.PLAYER_HAS_NOT_BEEN_ON);
return true;
}
UUID uuid = null;
if ((Bukkit.getPlayer(args[1]) != null)) {
uuid = Bukkit.getPlayer(args[1]).getUniqueId();
} else {
uuid = Bukkit.getOfflinePlayer(args[1]).getUniqueId();
}
if (uuid == null) {
PlayerFunctions.sendMessage(plr, C.PLAYER_HAS_NOT_BEEN_ON);
return true;
}*/
UUID uuid = UUIDHandler.getUUID(args[1]);
plot.addHelper(uuid);
DBFunc.setHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot, uuid, true);
Bukkit.getPluginManager().callEvent(event);
PlayerFunctions.sendMessage(plr, C.HELPER_ADDED);
} else if (args[0].equalsIgnoreCase("remove")) {
if (args[1].equalsIgnoreCase("*")) {
UUID uuid = DBFunc.everyone;
if (!plot.helpers.contains(uuid)) {
PlayerFunctions.sendMessage(plr, C.WAS_NOT_ADDED);
return true;
}
plot.removeHelper(uuid);
DBFunc.removeHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
PlayerFunctions.sendMessage(plr, C.HELPER_REMOVED);
return true;
}
/*if (!hasBeenOnServer(args[1])) {
PlayerFunctions.sendMessage(plr, C.PLAYER_HAS_NOT_BEEN_ON);
return true;
}
UUID uuid = null;
if (Bukkit.getPlayer(args[1]) != null) {
uuid = Bukkit.getPlayer(args[1]).getUniqueId();
} else {
uuid = Bukkit.getOfflinePlayer(args[1]).getUniqueId();
}
if (uuid == null) {
PlayerFunctions.sendMessage(plr, C.PLAYER_HAS_NOT_BEEN_ON);
return true;
}
if (!plot.helpers.contains(uuid)) {
PlayerFunctions.sendMessage(plr, C.WAS_NOT_ADDED);
return true;
}*/
UUID uuid = UUIDHandler.getUUID(args[1]);
plot.removeHelper(uuid);
DBFunc.removeHelper(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot, uuid, false);
Bukkit.getPluginManager().callEvent(event);
PlayerFunctions.sendMessage(plr, C.HELPER_REMOVED);
} else {
PlayerFunctions.sendMessage(plr, C.HELPER_NEED_ARGUMENT);
return true;
}
return true;
}
@Override
public boolean execute(Player plr, String... args) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.HELPER_NEED_ARGUMENT);
return true;
}
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
return true;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if ((plot.owner == null) || !plot.hasRights(plr)) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
return true;
}
if (args[0].equalsIgnoreCase("add")) {
if (args[1].equalsIgnoreCase("*")) {
UUID uuid = DBFunc.everyone;
plot.addHelper(uuid);
DBFunc.setHelper(plr.getWorld().getName(), plot,
Bukkit.getOfflinePlayer(args[1]));
PlayerFunctions.sendMessage(plr, C.HELPER_ADDED);
return true;
}
/*
* if (!hasBeenOnServer(args[1])) { PlayerFunctions.sendMessage(plr,
* C.PLAYER_HAS_NOT_BEEN_ON); return true; } UUID uuid = null; if
* ((Bukkit.getPlayer(args[1]) != null)) { uuid =
* Bukkit.getPlayer(args[1]).getUniqueId(); } else { uuid =
* Bukkit.getOfflinePlayer(args[1]).getUniqueId(); } if (uuid ==
* null) { PlayerFunctions.sendMessage(plr,
* C.PLAYER_HAS_NOT_BEEN_ON); return true; }
*/
UUID uuid = UUIDHandler.getUUID(args[1]);
plot.addHelper(uuid);
DBFunc.setHelper(plr.getWorld().getName(), plot,
Bukkit.getOfflinePlayer(args[1]));
PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot,
uuid, true);
Bukkit.getPluginManager().callEvent(event);
PlayerFunctions.sendMessage(plr, C.HELPER_ADDED);
} else if (args[0].equalsIgnoreCase("remove")) {
if (args[1].equalsIgnoreCase("*")) {
UUID uuid = DBFunc.everyone;
if (!plot.helpers.contains(uuid)) {
PlayerFunctions.sendMessage(plr, C.WAS_NOT_ADDED);
return true;
}
plot.removeHelper(uuid);
DBFunc.removeHelper(plr.getWorld().getName(), plot,
Bukkit.getOfflinePlayer(args[1]));
PlayerFunctions.sendMessage(plr, C.HELPER_REMOVED);
return true;
}
/*
* if (!hasBeenOnServer(args[1])) { PlayerFunctions.sendMessage(plr,
* C.PLAYER_HAS_NOT_BEEN_ON); return true; } UUID uuid = null; if
* (Bukkit.getPlayer(args[1]) != null) { uuid =
* Bukkit.getPlayer(args[1]).getUniqueId(); } else { uuid =
* Bukkit.getOfflinePlayer(args[1]).getUniqueId(); } if (uuid ==
* null) { PlayerFunctions.sendMessage(plr,
* C.PLAYER_HAS_NOT_BEEN_ON); return true; } if
* (!plot.helpers.contains(uuid)) { PlayerFunctions.sendMessage(plr,
* C.WAS_NOT_ADDED); return true; }
*/
UUID uuid = UUIDHandler.getUUID(args[1]);
plot.removeHelper(uuid);
DBFunc.removeHelper(plr.getWorld().getName(), plot,
Bukkit.getOfflinePlayer(args[1]));
PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(plr, plot,
uuid, false);
Bukkit.getPluginManager().callEvent(event);
PlayerFunctions.sendMessage(plr, C.HELPER_REMOVED);
} else {
PlayerFunctions.sendMessage(plr, C.HELPER_NEED_ARGUMENT);
return true;
}
return true;
}
}

View File

@ -9,8 +9,6 @@
package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
@ -19,62 +17,65 @@ import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotMain;
/**
*
*
* @author Citymonstret
*
*
*/
public class Home extends SubCommand {
public Home() {
super(Command.HOME, "Go to your plot", "home {id|alias}", CommandCategory.TELEPORT);
}
public Home() {
super(Command.HOME, "Go to your plot", "home {id|alias}",
CommandCategory.TELEPORT);
}
private Plot isAlias(String a) {
for (Plot p : PlotMain.getPlots()) {
if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) {
return p;
}
}
return null;
}
private Plot isAlias(String a) {
for (Plot p : PlotMain.getPlots()) {
if ((p.settings.getAlias().length() > 0)
&& p.settings.getAlias().equalsIgnoreCase(a)) {
return p;
}
}
return null;
}
@Override
public boolean execute(Player plr, String... args) {
Plot[] plots = PlotMain.getPlots(plr).toArray(new Plot[0]);
if (plots.length == 1) {
PlotMain.teleportPlayer(plr, plr.getLocation(), plots[0]);
return true;
} else if (plots.length > 1) {
if (args.length < 1) {
args = new String[] {"1"};
}
int id = 0;
try {
id = Integer.parseInt(args[0]);
} catch (Exception e) {
Plot temp;
if ((temp = isAlias(args[0])) != null) {
if (temp.hasOwner()) {
if (temp.getOwner().equals(plr.getUniqueId())) {
PlotMain.teleportPlayer(plr, plr.getLocation(), temp);
return true;
}
}
PlayerFunctions.sendMessage(plr, C.NOT_YOUR_PLOT);
return false;
}
PlayerFunctions.sendMessage(plr, C.NOT_VALID_NUMBER);
return true;
}
if ((id > (plots.length)) || (id < 1)) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_NUMBER);
return false;
}
PlotMain.teleportPlayer(plr, plr.getLocation(), plots[id - 1]);
return true;
} else {
PlayerFunctions.sendMessage(plr, C.NO_PLOTS);
return true;
}
}
@Override
public boolean execute(Player plr, String... args) {
Plot[] plots = PlotMain.getPlots(plr).toArray(new Plot[0]);
if (plots.length == 1) {
PlotMain.teleportPlayer(plr, plr.getLocation(), plots[0]);
return true;
} else if (plots.length > 1) {
if (args.length < 1) {
args = new String[] { "1" };
}
int id = 0;
try {
id = Integer.parseInt(args[0]);
} catch (Exception e) {
Plot temp;
if ((temp = isAlias(args[0])) != null) {
if (temp.hasOwner()) {
if (temp.getOwner().equals(plr.getUniqueId())) {
PlotMain.teleportPlayer(plr, plr.getLocation(),
temp);
return true;
}
}
PlayerFunctions.sendMessage(plr, C.NOT_YOUR_PLOT);
return false;
}
PlayerFunctions.sendMessage(plr, C.NOT_VALID_NUMBER);
return true;
}
if ((id > (plots.length)) || (id < 1)) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_NUMBER);
return false;
}
PlotMain.teleportPlayer(plr, plr.getLocation(), plots[id - 1]);
return true;
} else {
PlayerFunctions.sendMessage(plr, C.NO_PLOTS);
return true;
}
}
}

View File

@ -9,8 +9,9 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.*;
import com.intellectualcrafters.plot.database.DBFunc;
import java.util.ArrayList;
import java.util.UUID;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -18,120 +19,135 @@ import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.UUID;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.UUIDHandler;
import com.intellectualcrafters.plot.database.DBFunc;
/**
*
*
* @author Citymonstret
*
*
*/
public class Info extends SubCommand {
public Info() {
super(Command.INFO, "Display plot info", "info", CommandCategory.INFO);
}
public Info() {
super(Command.INFO, "Display plot info", "info", CommandCategory.INFO);
}
@Override
public boolean execute(Player player, String... args) {
if (!PlayerFunctions.isInPlot(player)) {
PlayerFunctions.sendMessage(player, C.NOT_IN_PLOT);
return true;
}
@Override
public boolean execute(Player player, String... args) {
if (!PlayerFunctions.isInPlot(player)) {
PlayerFunctions.sendMessage(player, C.NOT_IN_PLOT);
return true;
}
// ||
Plot plot = PlayerFunctions.getCurrentPlot(player);
// ||
Plot plot = PlayerFunctions.getCurrentPlot(player);
boolean hasOwner = plot.hasOwner();
boolean containsEveryone;
boolean trustedEveryone;
boolean hasOwner = plot.hasOwner();
boolean containsEveryone;
boolean trustedEveryone;
// Wildcard player {added}
{
if (plot.helpers == null) {
containsEveryone = false;
} else {
containsEveryone = plot.helpers.contains(DBFunc.everyone);
}
if (plot.trusted == null) {
trustedEveryone = false;
} else {
trustedEveryone = plot.trusted.contains(DBFunc.everyone);
}
}
// Wildcard player {added}
{
if (plot.helpers == null) {
containsEveryone = false;
} else {
containsEveryone = plot.helpers.contains(DBFunc.everyone);
}
if (plot.trusted == null) {
trustedEveryone = false;
} else {
trustedEveryone = plot.trusted.contains(DBFunc.everyone);
}
}
// Unclaimed?
if (!hasOwner && !containsEveryone && !trustedEveryone) {
PlayerFunctions.sendMessage(player, C.PLOT_INFO_UNCLAIMED, plot.id.x + ";" + plot.id.y);
return true;
}
// Unclaimed?
if (!hasOwner && !containsEveryone && !trustedEveryone) {
PlayerFunctions.sendMessage(player, C.PLOT_INFO_UNCLAIMED,
plot.id.x + ";" + plot.id.y);
return true;
}
new StringBuilder();
new StringBuilder();
String owner = "none";
if (plot.owner != null) {
owner = Bukkit.getOfflinePlayer(plot.owner).getName();
}
if (owner == null) {
owner = plot.owner.toString();
}
String owner = "none";
if (plot.owner != null) {
owner = Bukkit.getOfflinePlayer(plot.owner).getName();
}
if (owner == null) {
owner = plot.owner.toString();
}
String info = C.PLOT_INFO.s();
info = info.replaceAll("%alias%", plot.settings.getAlias().length() > 0 ? plot.settings.getAlias() : "none");
info = info.replaceAll("%id%", plot.id.toString());
info = info.replaceAll("%biome%", getBiomeAt(plot).toString());
info = info.replaceAll("%owner%", owner);
info = info.replaceAll("%time%", plot.settings.getChangeTime() ? plot.settings.getTime() + "" : "default");
info = info.replaceAll("%weather%", plot.settings.getRain() ? "rain" : "default");
info = info.replaceAll("%helpers%", getPlayerList(plot.helpers));
info = info.replaceAll("%trusted%", getPlayerList(plot.trusted));
info = info.replaceAll("%denied%", getPlayerList(plot.denied));
info = info.replaceAll("%rating%", "" + DBFunc.getRatings(plot));
info = info.replaceAll("%flags%", StringUtils.join(plot.settings.getFlags(), "").length() > 0 ? StringUtils.join(plot.settings.getFlags(), ",") : "none");
// PlayerFunctions.sendMessage(player,
// PlayerFunctions.getTopPlot(player.getWorld(), plot).id.toString());
// PlayerFunctions.sendMessage(player,
// PlayerFunctions.getBottomPlot(player.getWorld(),
// plot).id.toString());
PlayerFunctions.sendMessage(player, info);
return true;
}
String info = C.PLOT_INFO.s();
info = info.replaceAll(
"%alias%",
plot.settings.getAlias().length() > 0 ? plot.settings
.getAlias() : "none");
info = info.replaceAll("%id%", plot.id.toString());
info = info.replaceAll("%biome%", getBiomeAt(plot).toString());
info = info.replaceAll("%owner%", owner);
info = info.replaceAll("%time%",
plot.settings.getChangeTime() ? plot.settings.getTime() + ""
: "default");
info = info.replaceAll("%weather%", plot.settings.getRain() ? "rain"
: "default");
info = info.replaceAll("%helpers%", getPlayerList(plot.helpers));
info = info.replaceAll("%trusted%", getPlayerList(plot.trusted));
info = info.replaceAll("%denied%", getPlayerList(plot.denied));
info = info.replaceAll("%rating%", "" + DBFunc.getRatings(plot));
info = info
.replaceAll(
"%flags%",
StringUtils.join(plot.settings.getFlags(), "").length() > 0 ? StringUtils
.join(plot.settings.getFlags(), ",") : "none");
// PlayerFunctions.sendMessage(player,
// PlayerFunctions.getTopPlot(player.getWorld(), plot).id.toString());
// PlayerFunctions.sendMessage(player,
// PlayerFunctions.getBottomPlot(player.getWorld(),
// plot).id.toString());
PlayerFunctions.sendMessage(player, info);
return true;
}
private String getPlayerList(ArrayList<UUID> l) {
if ((l == null) || (l.size() < 1)) {
return " none";
}
String c = C.PLOT_USER_LIST.s();
StringBuilder list = new StringBuilder();
for (int x = 0; x < l.size(); x++) {
if ((x + 1) == l.size()) {
list.append(c.replace("%user%", getPlayerName(l.get(x))).replace(",", ""));
} else {
list.append(c.replace("%user%", getPlayerName(l.get(x))));
}
}
return list.toString();
}
private String getPlayerList(ArrayList<UUID> l) {
if ((l == null) || (l.size() < 1)) {
return " none";
}
String c = C.PLOT_USER_LIST.s();
StringBuilder list = new StringBuilder();
for (int x = 0; x < l.size(); x++) {
if ((x + 1) == l.size()) {
list.append(c.replace("%user%", getPlayerName(l.get(x)))
.replace(",", ""));
} else {
list.append(c.replace("%user%", getPlayerName(l.get(x))));
}
}
return list.toString();
}
private String getPlayerName(UUID uuid) {
if (uuid == null) {
return "unknown";
}
if (uuid.equals(DBFunc.everyone) || uuid.toString().equalsIgnoreCase(DBFunc.everyone.toString())) {
return "everyone";
}
/*
OfflinePlayer plr = Bukkit.getOfflinePlayer(uuid);
if (plr.getName() == null) {
return "unknown";
}
return plr.getName();*/
return UUIDHandler.getName(uuid);
}
private String getPlayerName(UUID uuid) {
if (uuid == null) {
return "unknown";
}
if (uuid.equals(DBFunc.everyone)
|| uuid.toString().equalsIgnoreCase(DBFunc.everyone.toString())) {
return "everyone";
}
/*
* OfflinePlayer plr = Bukkit.getOfflinePlayer(uuid); if (plr.getName()
* == null) { return "unknown"; } return plr.getName();
*/
return UUIDHandler.getName(uuid);
}
private Biome getBiomeAt(Plot plot) {
World w = Bukkit.getWorld(plot.world);
Location bl = PlotHelper.getPlotTopLoc(w, plot.id);
return bl.getBlock().getBiome();
}
private Biome getBiomeAt(Plot plot) {
World w = Bukkit.getWorld(plot.world);
Location bl = PlotHelper.getPlotTopLoc(w, plot.id);
return bl.getBlock().getBiome();
}
}

View File

@ -20,41 +20,48 @@ import org.bukkit.inventory.meta.ItemMeta;
public class Inventory extends SubCommand {
public Inventory() {
super("inventory", "plots.inventory", "Open a command inventory", "inventory", "inv", CommandCategory.INFO);
}
public Inventory() {
super("inventory", "plots.inventory", "Open a command inventory",
"inventory", "inv", CommandCategory.INFO);
}
@Override
public boolean execute(final Player plr, String... args) {
ArrayList<SubCommand> cmds = new ArrayList<>();
for (SubCommand cmd : MainCommand.subCommands) {
if (cmd.permission.hasPermission(plr)) {
cmds.add(cmd);
}
}
int size = 9 * (int) Math.ceil(cmds.size() / 9.0);
org.bukkit.inventory.Inventory inventory = Bukkit.createInventory(null, size, "PlotSquared Commands");
for (SubCommand cmd : cmds) {
inventory.addItem(getItem(cmd));
}
plr.openInventory(inventory);
return true;
}
@Override
public boolean execute(final Player plr, String... args) {
ArrayList<SubCommand> cmds = new ArrayList<>();
for (SubCommand cmd : MainCommand.subCommands) {
if (cmd.permission.hasPermission(plr)) {
cmds.add(cmd);
}
}
int size = 9 * (int) Math.ceil(cmds.size() / 9.0);
org.bukkit.inventory.Inventory inventory = Bukkit.createInventory(null,
size, "PlotSquared Commands");
for (SubCommand cmd : cmds) {
inventory.addItem(getItem(cmd));
}
plr.openInventory(inventory);
return true;
}
private ItemStack getItem(final SubCommand cmd) {
ItemStack stack = new ItemStack(Material.COMMAND);
ItemMeta meta = stack.getItemMeta();
{
meta.setDisplayName(ChatColor.GREEN + cmd.cmd + ChatColor.DARK_GRAY + " [" + ChatColor.GREEN + cmd.alias + ChatColor.DARK_GRAY + "]");
meta.setLore(new ArrayList<String>() {
{
add(ChatColor.RED + "Category: " + ChatColor.GOLD + cmd.category.toString());
add(ChatColor.RED + "Description: " + ChatColor.GOLD + cmd.description);
add(ChatColor.RED + "Usage: " + ChatColor.GOLD + "/plot " + cmd.usage);
}
});
}
stack.setItemMeta(meta);
return stack;
}
private ItemStack getItem(final SubCommand cmd) {
ItemStack stack = new ItemStack(Material.COMMAND);
ItemMeta meta = stack.getItemMeta();
{
meta.setDisplayName(ChatColor.GREEN + cmd.cmd + ChatColor.DARK_GRAY
+ " [" + ChatColor.GREEN + cmd.alias + ChatColor.DARK_GRAY
+ "]");
meta.setLore(new ArrayList<String>() {
{
add(ChatColor.RED + "Category: " + ChatColor.GOLD
+ cmd.category.toString());
add(ChatColor.RED + "Description: " + ChatColor.GOLD
+ cmd.description);
add(ChatColor.RED + "Usage: " + ChatColor.GOLD + "/plot "
+ cmd.usage);
}
});
}
stack.setItemMeta(meta);
return stack;
}
}

View File

@ -21,35 +21,43 @@ import com.intellectualcrafters.plot.Plot;
*/
public class Kick extends SubCommand {
public Kick() {
super(Command.KICK, "Kick a player from your plot", "kick", CommandCategory.ACTIONS);
}
public Kick() {
super(Command.KICK, "Kick a player from your plot", "kick",
CommandCategory.ACTIONS);
}
@Override
public boolean execute(Player plr, String... args) {
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, "You're not in a plot.");
return false;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (args.length != 1) {
PlayerFunctions.sendMessage(plr, "&c/plot kick <player>");
return false;
}
if (Bukkit.getPlayer(args[0]) != null) {
PlayerFunctions.sendMessage(plr, C.INVALID_PLAYER.s().replaceAll("%player%", args[0]));
return false;
}
Player player = Bukkit.getPlayer(args[0]);
if (!player.getWorld().equals(plr.getWorld()) || !PlayerFunctions.isInPlot(player) || (PlayerFunctions.getCurrentPlot(player) == null) || !PlayerFunctions.getCurrentPlot(player).equals(plot)) {
PlayerFunctions.sendMessage(plr, C.INVALID_PLAYER.s().replaceAll("%player%", args[0]));
return false;
}
player.teleport(player.getWorld().getSpawnLocation());
return true;
}
@Override
public boolean execute(Player plr, String... args) {
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, "You're not in a plot.");
return false;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(
plr.getUniqueId()))
&& !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (args.length != 1) {
PlayerFunctions.sendMessage(plr, "&c/plot kick <player>");
return false;
}
if (Bukkit.getPlayer(args[0]) != null) {
PlayerFunctions.sendMessage(plr,
C.INVALID_PLAYER.s().replaceAll("%player%", args[0]));
return false;
}
Player player = Bukkit.getPlayer(args[0]);
if (!player.getWorld().equals(plr.getWorld())
|| !PlayerFunctions.isInPlot(player)
|| (PlayerFunctions.getCurrentPlot(player) == null)
|| !PlayerFunctions.getCurrentPlot(player).equals(plot)) {
PlayerFunctions.sendMessage(plr,
C.INVALID_PLAYER.s().replaceAll("%player%", args[0]));
return false;
}
player.teleport(player.getWorld().getSpawnLocation());
return true;
}
}

View File

@ -9,133 +9,164 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.PlotMain;
import java.util.ArrayList;
import java.util.Arrays;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Arrays;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.PlotMain;
/**
* PlotMain command class
*
*
* @author Citymonstret
*
*
*/
public class MainCommand implements CommandExecutor {
private static SubCommand[] _subCommands = new SubCommand[] { new Claim(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Reload(), new Merge(), new Unlink(), new Kick(), new Setup() };
private static SubCommand[] _subCommands = new SubCommand[] { new Claim(),
new Auto(), new Home(), new Visit(), new TP(), new Set(),
new Clear(), new Delete(), new SetOwner(), new Denied(),
new Helpers(), new Trusted(), new Info(), new list(), new Help(),
new Debug(), new Schematic(), new plugin(), new Inventory(),
new Reload(), new Merge(), new Unlink(), new Kick(), new Setup() };
public static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
{
addAll(Arrays.asList(_subCommands));
}
};
public static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
{
addAll(Arrays.asList(_subCommands));
}
};
public static boolean no_permission(Player player) {
PlayerFunctions.sendMessage(player, C.NO_PERMISSION);
return false;
}
public static boolean no_permission(Player player) {
PlayerFunctions.sendMessage(player, C.NO_PERMISSION);
return false;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (!(sender instanceof Player)) {
if (args.length > 0) {
if (args[0].equalsIgnoreCase("reload")) {
new Reload().executeConsole(args);
}
} else {
PlotMain.sendConsoleSenderMessage(C.PREFIX.s() + C.HELP_HEADER.s());
PlotMain.sendConsoleSenderMessage("&6/plots reload &c-&6 reloads the plugin");
}
return false;
}
Player player = (Player) sender;
if (!player.hasPermission("plots.use")) {
return no_permission(player);
}
if ((args.length < 1) || ((args.length >= 1) && (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("he")))) {
if (args.length < 2) {
StringBuilder builder = new StringBuilder();
builder.append(C.HELP_INFO.s());
for (SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
builder.append("\n" + C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString()));
}
PlayerFunctions.sendMessage(player, builder.toString());
return true;
}
String cat = args[1];
SubCommand.CommandCategory cato = null;
for (SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
if (cat.equalsIgnoreCase(category.toString())) {
cato = category;
break;
}
}
if (cato == null) {
StringBuilder builder = new StringBuilder();
builder.append(C.HELP_INFO.s());
for (SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
builder.append("\n" + C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString()));
}
PlayerFunctions.sendMessage(player, builder.toString());
return true;
}
StringBuilder help = new StringBuilder();
for (String string : helpMenu(player, cato)) {
help.append(string + "\n");
}
PlayerFunctions.sendMessage(player, help.toString());
return true;
} else {
for (SubCommand command : subCommands) {
if (command.cmd.equalsIgnoreCase(args[0]) || command.alias.equalsIgnoreCase(args[0])) {
String[] arguments = new String[args.length - 1];
for (int x = 1; x < args.length; x++) {
arguments[x - 1] = args[x];
}
if (command.permission.hasPermission(player)) {
return command.execute(player, arguments);
} else {
return no_permission(player);
}
}
}
PlayerFunctions.sendMessage(player, C.NOT_VALID_SUBCOMMAND);
}
return false;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd,
String commandLabel, String[] args) {
if (!(sender instanceof Player)) {
if (args.length > 0) {
if (args[0].equalsIgnoreCase("reload")) {
new Reload().executeConsole(args);
}
} else {
PlotMain.sendConsoleSenderMessage(C.PREFIX.s()
+ C.HELP_HEADER.s());
PlotMain.sendConsoleSenderMessage("&6/plots reload &c-&6 reloads the plugin");
}
return false;
}
Player player = (Player) sender;
if (!player.hasPermission("plots.use")) {
return no_permission(player);
}
if ((args.length < 1)
|| ((args.length >= 1) && (args[0].equalsIgnoreCase("help") || args[0]
.equalsIgnoreCase("he")))) {
if (args.length < 2) {
StringBuilder builder = new StringBuilder();
builder.append(C.HELP_INFO.s());
for (SubCommand.CommandCategory category : SubCommand.CommandCategory
.values()) {
builder.append("\n"
+ C.HELP_INFO_ITEM
.s()
.replaceAll("%category%",
category.toString().toLowerCase())
.replaceAll("%category_desc%",
category.toString()));
}
PlayerFunctions.sendMessage(player, builder.toString());
return true;
}
String cat = args[1];
SubCommand.CommandCategory cato = null;
for (SubCommand.CommandCategory category : SubCommand.CommandCategory
.values()) {
if (cat.equalsIgnoreCase(category.toString())) {
cato = category;
break;
}
}
if (cato == null) {
StringBuilder builder = new StringBuilder();
builder.append(C.HELP_INFO.s());
for (SubCommand.CommandCategory category : SubCommand.CommandCategory
.values()) {
builder.append("\n"
+ C.HELP_INFO_ITEM
.s()
.replaceAll("%category%",
category.toString().toLowerCase())
.replaceAll("%category_desc%",
category.toString()));
}
PlayerFunctions.sendMessage(player, builder.toString());
return true;
}
StringBuilder help = new StringBuilder();
for (String string : helpMenu(player, cato)) {
help.append(string + "\n");
}
PlayerFunctions.sendMessage(player, help.toString());
return true;
} else {
for (SubCommand command : subCommands) {
if (command.cmd.equalsIgnoreCase(args[0])
|| command.alias.equalsIgnoreCase(args[0])) {
String[] arguments = new String[args.length - 1];
for (int x = 1; x < args.length; x++) {
arguments[x - 1] = args[x];
}
if (command.permission.hasPermission(player)) {
return command.execute(player, arguments);
} else {
return no_permission(player);
}
}
}
PlayerFunctions.sendMessage(player, C.NOT_VALID_SUBCOMMAND);
}
return false;
}
public static ArrayList<String> helpMenu(Player player, final SubCommand.CommandCategory category) {
ArrayList<String> help = new ArrayList<String>() {
{
add(t(C.HELP_HEADER.s()));
add(t(C.HELP_CATEGORY.s().replaceAll("%category%", category.toString())));
}
};
for (SubCommand cmd : subCommands) {
if (cmd.permission.hasPermission(player) && (cmd.category == category)) {
String s = t(C.HELP_PAGE.s());
s = s.replaceAll("%alias%", cmd.alias);
s = s.replaceAll("%usage%", cmd.usage.contains("plot") ? cmd.usage : "/plot " + cmd.usage);
s = s.replaceAll("%cmd%", cmd.cmd);
s = s.replaceAll("%desc%", cmd.description);
help.add(s);
}
}
if (help.size() < 2) {
help.add(t(C.NO_COMMANDS.s()));
}
return help;
}
public static ArrayList<String> helpMenu(Player player,
final SubCommand.CommandCategory category) {
ArrayList<String> help = new ArrayList<String>() {
{
add(t(C.HELP_HEADER.s()));
add(t(C.HELP_CATEGORY.s().replaceAll("%category%",
category.toString())));
}
};
for (SubCommand cmd : subCommands) {
if (cmd.permission.hasPermission(player)
&& (cmd.category == category)) {
String s = t(C.HELP_PAGE.s());
s = s.replaceAll("%alias%", cmd.alias);
s = s.replaceAll("%usage%",
cmd.usage.contains("plot") ? cmd.usage : "/plot "
+ cmd.usage);
s = s.replaceAll("%cmd%", cmd.cmd);
s = s.replaceAll("%desc%", cmd.description);
help.add(s);
}
}
if (help.size() < 2) {
help.add(t(C.NO_COMMANDS.s()));
}
return help;
}
private static String t(String s) {
return ChatColor.translateAlternateColorCodes('&', s);
}
private static String t(String s) {
return ChatColor.translateAlternateColorCodes('&', s);
}
}

View File

@ -9,140 +9,173 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.*;
import com.intellectualcrafters.plot.events.PlotMergeEvent;
import java.util.ArrayList;
import net.milkbowl.vault.economy.Economy;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotWorld;
import com.intellectualcrafters.plot.SetBlockFast;
import com.intellectualcrafters.plot.events.PlotMergeEvent;
/**
*
*
* @author Citymonstret
*
*
*/
public class Merge extends SubCommand {
public static String[] values = new String[] { "north", "east", "south", "west" };
public static String[] aliases = new String[] { "n", "e", "s", "w" };
public static String[] values = new String[] { "north", "east", "south",
"west" };
public static String[] aliases = new String[] { "n", "e", "s", "w" };
public Merge() {
super(Command.MERGE, "Merge the plot you are standing on with another plot.", "merge", CommandCategory.ACTIONS);
}
public Merge() {
super(Command.MERGE,
"Merge the plot you are standing on with another plot.",
"merge", CommandCategory.ACTIONS);
}
public static String direction(float yaw) {
yaw = yaw / 90;
int i = Math.round(yaw);
switch (i) {
case -4:
case 0:
case 4:
return "SOUTH";
case -1:
case 3:
return "EAST";
case -2:
case 2:
return "NORTH";
case -3:
case 1:
return "WEST";
default:
return "";
}
}
public static String direction(float yaw) {
yaw = yaw / 90;
int i = Math.round(yaw);
switch (i) {
case -4:
case 0:
case 4:
return "SOUTH";
case -1:
case 3:
return "EAST";
case -2:
case 2:
return "NORTH";
case -3:
case 1:
return "WEST";
default:
return "";
}
}
@Override
public boolean execute(Player plr, String... args) {
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
return true;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if ((plot == null) || !plot.hasOwner()) {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (!plot.getOwner().equals(plr.getUniqueId())) {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (args.length < 1) {
PlayerFunctions.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values, C.BLOCK_LIST_SEPARATER.s()));
PlayerFunctions.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(plr.getLocation().getYaw())));
return false;
}
int direction = -1;
for (int i = 0; i < values.length; i++) {
if (args[0].equalsIgnoreCase(values[i]) || args[0].equalsIgnoreCase(aliases[i])) {
direction = i;
break;
}
}
if (direction == -1) {
PlayerFunctions.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values, C.BLOCK_LIST_SEPARATER.s()));
PlayerFunctions.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(plr.getLocation().getYaw())));
return false;
}
World world = plr.getWorld();
PlotId bot = PlayerFunctions.getBottomPlot(world, plot).id;
PlotId top = PlayerFunctions.getTopPlot(world, plot).id;
ArrayList<PlotId> plots;
switch (direction) {
case 0: // north = -y
plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
break;
case 1: // east = +x
plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y));
break;
case 2: // south = +y
plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1));
break;
case 3: // west = -x
plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(), new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y));
break;
default:
return false;
}
for (PlotId myid : plots) {
Plot myplot = PlotMain.getPlots(world).get(myid);
if ((myplot == null) || !myplot.hasOwner() || !(myplot.getOwner().equals(plr.getUniqueId()))) {
PlayerFunctions.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
return false;
}
}
@Override
public boolean execute(Player plr, String... args) {
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
return true;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if ((plot == null) || !plot.hasOwner()) {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (!plot.getOwner().equals(plr.getUniqueId())) {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (args.length < 1) {
PlayerFunctions.sendMessage(
plr,
C.SUBCOMMAND_SET_OPTIONS_HEADER.s()
+ StringUtils.join(values,
C.BLOCK_LIST_SEPARATER.s()));
PlayerFunctions.sendMessage(
plr,
C.DIRECTION.s().replaceAll("%dir%",
direction(plr.getLocation().getYaw())));
return false;
}
int direction = -1;
for (int i = 0; i < values.length; i++) {
if (args[0].equalsIgnoreCase(values[i])
|| args[0].equalsIgnoreCase(aliases[i])) {
direction = i;
break;
}
}
if (direction == -1) {
PlayerFunctions.sendMessage(
plr,
C.SUBCOMMAND_SET_OPTIONS_HEADER.s()
+ StringUtils.join(values,
C.BLOCK_LIST_SEPARATER.s()));
PlayerFunctions.sendMessage(
plr,
C.DIRECTION.s().replaceAll("%dir%",
direction(plr.getLocation().getYaw())));
return false;
}
World world = plr.getWorld();
PlotId bot = PlayerFunctions.getBottomPlot(world, plot).id;
PlotId top = PlayerFunctions.getTopPlot(world, plot).id;
ArrayList<PlotId> plots;
switch (direction) {
case 0: // north = -y
plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(),
new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
break;
case 1: // east = +x
plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(),
new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y));
break;
case 2: // south = +y
plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(),
new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1));
break;
case 3: // west = -x
plots = PlayerFunctions.getPlotSelectionIds(plr.getWorld(),
new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y));
break;
default:
return false;
}
for (PlotId myid : plots) {
Plot myplot = PlotMain.getPlots(world).get(myid);
if ((myplot == null) || !myplot.hasOwner()
|| !(myplot.getOwner().equals(plr.getUniqueId()))) {
PlayerFunctions.sendMessage(plr, C.NO_PERM_MERGE.s()
.replaceAll("%plot%", myid.toString()));
return false;
}
}
PlotWorld plotWorld = PlotMain.getWorldSettings(world);
if (PlotMain.useEconomy && plotWorld.USE_ECONOMY) {
double cost = plotWorld.MERGE_PRICE;
cost = plots.size() * cost;
if (cost > 0d) {
Economy economy = PlotMain.economy;
if (economy.getBalance(plr) < cost) {
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
return false;
}
economy.withdrawPlayer(plr, cost);
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
}
}
PlotWorld plotWorld = PlotMain.getWorldSettings(world);
if (PlotMain.useEconomy && plotWorld.USE_ECONOMY) {
double cost = plotWorld.MERGE_PRICE;
cost = plots.size() * cost;
if (cost > 0d) {
Economy economy = PlotMain.economy;
if (economy.getBalance(plr) < cost) {
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
return false;
}
economy.withdrawPlayer(plr, cost);
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
}
}
PlotMergeEvent event = new PlotMergeEvent(world, plot, plots);
PlotMergeEvent event = new PlotMergeEvent(world, plot, plots);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
event.setCancelled(true);
PlayerFunctions.sendMessage(plr, "&cMerge has been cancelled");
return false;
}
PlayerFunctions.sendMessage(plr, "&cPlots have been merged");
PlotHelper.mergePlots(world, plots);
if (PlotHelper.canSetFast) {
SetBlockFast.update(plr);
}
return true;
}
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
event.setCancelled(true);
PlayerFunctions.sendMessage(plr, "&cMerge has been cancelled");
return false;
}
PlayerFunctions.sendMessage(plr, "&cPlots have been merged");
PlotHelper.mergePlots(world, plots);
if (PlotHelper.canSetFast) {
SetBlockFast.update(plr);
}
return true;
}
}

View File

@ -11,62 +11,63 @@ import com.intellectualcrafters.plot.Plot;
*/
public class Rate extends SubCommand {
/*
* String cmd, String permission, String description, String usage, String
* alias, CommandCategory category
*/
/*
* String cmd, String permission, String description, String usage, String
* alias, CommandCategory category
*/
public Rate() {
super("rate", "plots.rate", "Rate the plot", "rate {0-10}", "rt", CommandCategory.ACTIONS);
}
public Rate() {
super("rate", "plots.rate", "Rate the plot", "rate {0-10}", "rt",
CommandCategory.ACTIONS);
}
@Override
public boolean execute(Player plr, String... args) {
if (args.length < 1) {
sendMessage(plr, C.RATING_NOT_VALID);
return true;
}
if (!PlayerFunctions.isInPlot(plr)) {
sendMessage(plr, C.NOT_IN_PLOT);
return true;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (!plot.hasOwner()) {
sendMessage(plr, C.RATING_NOT_OWNED);
return true;
}
if (plot.getOwner().equals(plr.getUniqueId())) {
sendMessage(plr, C.RATING_NOT_YOUR_OWN);
return true;
}
String arg = args[0];
boolean o = false;
for (char c : arg.toCharArray()) {
if (!Character.isDigit(c)) {
o = true;
break;
}
}
int rating = 0;
if (!o) {
rating = Integer.parseInt(arg);
}
if (o || ((rating < 0) || (rating > 10))) {
sendMessage(plr, C.RATING_NOT_VALID);
return true;
}
// TODO implement check for already rated
boolean rated = false;
if (rated) {
sendMessage(plr, C.RATING_ALREADY_EXISTS, plot.getId().toString());
}
// TODO actually do something...
boolean success = false;
if (success) {
sendMessage(plr, C.RATING_APPLIED, plot.getId().toString());
} else {
sendMessage(plr, C.COMMAND_WENT_WRONG);
}
return true;
}
@Override
public boolean execute(Player plr, String... args) {
if (args.length < 1) {
sendMessage(plr, C.RATING_NOT_VALID);
return true;
}
if (!PlayerFunctions.isInPlot(plr)) {
sendMessage(plr, C.NOT_IN_PLOT);
return true;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (!plot.hasOwner()) {
sendMessage(plr, C.RATING_NOT_OWNED);
return true;
}
if (plot.getOwner().equals(plr.getUniqueId())) {
sendMessage(plr, C.RATING_NOT_YOUR_OWN);
return true;
}
String arg = args[0];
boolean o = false;
for (char c : arg.toCharArray()) {
if (!Character.isDigit(c)) {
o = true;
break;
}
}
int rating = 0;
if (!o) {
rating = Integer.parseInt(arg);
}
if (o || ((rating < 0) || (rating > 10))) {
sendMessage(plr, C.RATING_NOT_VALID);
return true;
}
// TODO implement check for already rated
boolean rated = false;
if (rated) {
sendMessage(plr, C.RATING_ALREADY_EXISTS, plot.getId().toString());
}
// TODO actually do something...
boolean success = false;
if (success) {
sendMessage(plr, C.RATING_APPLIED, plot.getId().toString());
} else {
sendMessage(plr, C.COMMAND_WENT_WRONG);
}
return true;
}
}

View File

@ -20,23 +20,24 @@ import com.intellectualcrafters.plot.PlotMain;
*/
public class Reload extends SubCommand {
public Reload() {
super("reload", "plots.admin", "Reload configurations", "", "reload", CommandCategory.INFO);
}
public Reload() {
super("reload", "plots.admin", "Reload configurations", "", "reload",
CommandCategory.INFO);
}
@Override
public boolean execute(Player plr, String... args) {
try {
PlotMain.reloadTranslations();
PlotMain.BroadcastWithPerms(C.RELOADED_CONFIGS);
} catch (Exception e) {
if (plr != null) {
PlayerFunctions.sendMessage(plr, C.RELOAD_FAILED);
} else {
PlotMain.sendConsoleSenderMessage(C.RELOAD_FAILED);
}
}
return true;
}
@Override
public boolean execute(Player plr, String... args) {
try {
PlotMain.reloadTranslations();
PlotMain.BroadcastWithPerms(C.RELOADED_CONFIGS);
} catch (Exception e) {
if (plr != null) {
PlayerFunctions.sendMessage(plr, C.RELOAD_FAILED);
} else {
PlotMain.sendConsoleSenderMessage(C.RELOAD_FAILED);
}
}
return true;
}
}

View File

@ -4,67 +4,78 @@ import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.SchematicHandler;
public class Schematic extends SubCommand {
public Schematic() {
super("schematic", "plots.admin", "Schematic Command", "schematic {arg}", "sch", CommandCategory.ACTIONS);
}
public Schematic() {
super("schematic", "plots.admin", "Schematic Command",
"schematic {arg}", "sch", CommandCategory.ACTIONS);
}
@Override
public boolean execute(Player plr, String... args) {
if (args.length < 1) {
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
return true;
}
String arg = args[0];
String file;
SchematicHandler.Schematic schematic;
switch (arg) {
case "paste":
if (args.length < 2) {
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
break;
}
if (!PlayerFunctions.isInPlot(plr)) {
sendMessage(plr, C.NOT_IN_PLOT);
break;
}
file = args[1];
schematic = new SchematicHandler().getSchematic(file);
boolean s = new SchematicHandler().paste(plr.getLocation(), schematic, PlayerFunctions.getCurrentPlot(plr));
if (s) {
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
} else {
sendMessage(plr, C.SCHEMATIC_PASTE_FAILED);
}
break;
case "test":
if (args.length < 2) {
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
break;
}
file = args[1];
schematic = new SchematicHandler().getSchematic(file);
if (schematic == null) {
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent");
break;
}
int l1 = schematic.getSchematicDimension().getX();
int l2 = schematic.getSchematicDimension().getZ();
int length = PlotMain.getWorldSettings(plr.getWorld()).PLOT_WIDTH;
if ((l1 != length) || (l2 != length)) {
sendMessage(plr, C.SCHEMATIC_INVALID, String.format("Wrong size (x: %s, z: %d) vs %d ", l1, l2, length));
break;
}
sendMessage(plr, C.SCHEMATIC_VALID);
break;
default:
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
break;
}
return true;
}
@Override
public boolean execute(Player plr, String... args) {
if (args.length < 1) {
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
return true;
}
String arg = args[0];
String file;
SchematicHandler.Schematic schematic;
switch (arg) {
case "paste":
if (args.length < 2) {
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
break;
}
if (!PlayerFunctions.isInPlot(plr)) {
sendMessage(plr, C.NOT_IN_PLOT);
break;
}
file = args[1];
schematic = new SchematicHandler().getSchematic(file);
boolean s = new SchematicHandler().paste(plr.getLocation(),
schematic, PlayerFunctions.getCurrentPlot(plr));
if (s) {
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
} else {
sendMessage(plr, C.SCHEMATIC_PASTE_FAILED);
}
break;
case "test":
if (args.length < 2) {
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
break;
}
file = args[1];
schematic = new SchematicHandler().getSchematic(file);
if (schematic == null) {
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent");
break;
}
if (!PlayerFunctions.isInPlot(plr)) {
sendMessage(plr, C.NOT_IN_PLOT);
break;
}
int l1 = schematic.getSchematicDimension().getX();
int l2 = schematic.getSchematicDimension().getZ();
Plot plot = PlayerFunctions.getCurrentPlot(plr);
int length = PlotHelper.getPlotWidth(plr.getWorld(), plot.id);
if ((l1 != length) || (l2 != length)) {
sendMessage(plr, C.SCHEMATIC_INVALID, String.format(
"Wrong size (x: %s, z: %d) vs %d ", l1, l2, length));
break;
}
sendMessage(plr, C.SCHEMATIC_VALID);
break;
default:
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
break;
}
return true;
}
}

View File

@ -26,6 +26,7 @@ import com.intellectualcrafters.plot.Flag;
import com.intellectualcrafters.plot.FlagManager;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotBlock;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotHomePosition;
import com.intellectualcrafters.plot.PlotMain;
@ -35,380 +36,413 @@ import com.intellectualcrafters.plot.events.PlotFlagAddEvent;
import com.intellectualcrafters.plot.events.PlotFlagRemoveEvent;
/**
*
*
* @author Citymonstret
*
*
*/
public class Set extends SubCommand {
public Set() {
super(Command.SET, "Set a plot value", "set {arg} {value...}", CommandCategory.ACTIONS);
}
public Set() {
super(Command.SET, "Set a plot value", "set {arg} {value...}",
CommandCategory.ACTIONS);
}
public static String[] values = new String[] { "biome", "wall", "wall_filling", "floor", "alias", "home", "rain", "flag" };
public static String[] aliases = new String[] { "b", "w", "wf", "f", "a", "h", "r", "fl" };
public static String[] values = new String[] { "biome", "wall",
"wall_filling", "floor", "alias", "home", "rain", "flag" };
public static String[] aliases = new String[] { "b", "w", "wf", "f", "a",
"h", "r", "fl" };
@SuppressWarnings("deprecation")
@Override
public boolean execute(Player plr, String... args) {
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
return false;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
@SuppressWarnings("deprecation")
@Override
public boolean execute(Player plr, String... args) {
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
return false;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (!plot.hasRights(plr) && !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (args.length < 1) {
StringBuilder builder = new StringBuilder();
builder.append(C.SUBCOMMAND_SET_OPTIONS_HEADER.s());
builder.append(getArgumentList(values));
PlayerFunctions.sendMessage(plr, builder.toString());
return false;
}
for (int i = 0; i < aliases.length; i++) {
if (aliases[i].equalsIgnoreCase(args[0])) {
args[0] = values[i];
break;
}
}
/* TODO: Implement option */
boolean advanced_permissions = true;
if (advanced_permissions) {
if (!plr.hasPermission("plots.set." + args[0].toLowerCase())) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
return false;
}
}
if (!plot.hasRights(plr) && !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (args.length < 1) {
StringBuilder builder = new StringBuilder();
builder.append(C.SUBCOMMAND_SET_OPTIONS_HEADER.s());
builder.append(getArgumentList(values));
PlayerFunctions.sendMessage(plr, builder.toString());
return false;
}
for (int i = 0; i < aliases.length; i++) {
if (aliases[i].equalsIgnoreCase(args[0])) {
args[0] = values[i];
break;
}
}
/* TODO: Implement option */
boolean advanced_permissions = true;
if (advanced_permissions) {
if (!plr.hasPermission("plots.set." + args[0].toLowerCase())) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
return false;
}
}
if (args[0].equalsIgnoreCase("flag")) {
if (args.length < 2) {
String message = StringUtils.join(FlagManager.getFlags(), "&c, &6");
if (PlotMain.worldGuardListener != null) {
if (message.equals("")) {
message = StringUtils.join(PlotMain.worldGuardListener.str_flags, "&c, &6");
} else {
message += "," + StringUtils.join(PlotMain.worldGuardListener.str_flags, "&c, &6");
}
}
PlayerFunctions.sendMessage(plr, C.NEED_KEY.s().replaceAll("%values%", message));
return false;
}
if (!FlagManager.getFlags().contains(args[1].toLowerCase()) && (PlotMain.worldGuardListener != null) && !PlotMain.worldGuardListener.str_flags.contains(args[1].toLowerCase())) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_FLAG);
return false;
}
if (!plr.hasPermission("plots.set.flag" + args[1].toLowerCase())) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
return false;
}
if (args.length == 2) {
if (plot.settings.getFlag(args[1].toLowerCase()) == null) {
if (PlotMain.worldGuardListener != null) {
if (PlotMain.worldGuardListener.str_flags.contains(args[1].toLowerCase())) {
PlotMain.worldGuardListener.removeFlag(plr, plr.getWorld(), plot, args[1]);
return false;
}
}
PlayerFunctions.sendMessage(plr, C.FLAG_NOT_IN_PLOT);
return false;
}
Flag flag = plot.settings.getFlag(args[1].toLowerCase());
PlotFlagRemoveEvent event = new PlotFlagRemoveEvent(flag, plot);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
PlayerFunctions.sendMessage(plr, C.FLAG_NOT_REMOVED);
event.setCancelled(true);
return false;
}
java.util.Set<Flag> newflags = plot.settings.getFlags();
Flag oldFlag = plot.settings.getFlag(args[1].toLowerCase());
if (oldFlag != null) {
newflags.remove(oldFlag);
}
plot.settings.setFlags(newflags.toArray(new Flag[0]));
DBFunc.setFlags(plr.getWorld().getName(), plot, newflags.toArray(new Flag[0]));
PlayerFunctions.sendMessage(plr, C.FLAG_REMOVED);
return true;
}
try {
String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
if ((FlagManager.getFlag(args[1].toLowerCase()) == null) && (PlotMain.worldGuardListener != null)) {
PlotMain.worldGuardListener.addFlag(plr, plr.getWorld(), plot, args[1], value);
return false;
}
Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), value);
PlotFlagAddEvent event = new PlotFlagAddEvent(flag, plot);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
PlayerFunctions.sendMessage(plr, C.FLAG_NOT_ADDED);
event.setCancelled(true);
return false;
}
plot.settings.addFlag(flag);
DBFunc.setFlags(plr.getWorld().getName(), plot, plot.settings.getFlags().toArray(new Flag[0]));
PlayerFunctions.sendMessage(plr, C.FLAG_ADDED);
return true;
} catch (Exception e) {
PlayerFunctions.sendMessage(plr, "&c" + e.getMessage());
return false;
}
}
if (args[0].equalsIgnoreCase("rain")) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.NEED_ON_OFF);
return false;
}
String word = args[1];
if (!word.equalsIgnoreCase("on") && !word.equalsIgnoreCase("off")) {
PlayerFunctions.sendMessage(plr, C.NEED_ON_OFF);
return true;
}
boolean b = word.equalsIgnoreCase("on");
DBFunc.setWeather(plr.getWorld().getName(), plot, b);
PlayerFunctions.sendMessage(plr, C.SETTING_UPDATED);
for (Player p : Bukkit.getOnlinePlayers()) {
if (PlayerFunctions.getCurrentPlot(plr).id == plot.id) {
if (b) {
p.setPlayerWeather(WeatherType.DOWNFALL);
} else {
p.resetPlayerWeather();
}
}
}
return true;
}
if (args[0].equalsIgnoreCase("flag")) {
if (args.length < 2) {
String message = StringUtils.join(FlagManager.getFlags(),
"&c, &6");
if (PlotMain.worldGuardListener != null) {
if (message.equals("")) {
message = StringUtils
.join(PlotMain.worldGuardListener.str_flags,
"&c, &6");
} else {
message += ","
+ StringUtils.join(
PlotMain.worldGuardListener.str_flags,
"&c, &6");
}
}
PlayerFunctions.sendMessage(plr,
C.NEED_KEY.s().replaceAll("%values%", message));
return false;
}
if (!FlagManager.getFlags().contains(args[1].toLowerCase())
&& (PlotMain.worldGuardListener != null)
&& !PlotMain.worldGuardListener.str_flags.contains(args[1]
.toLowerCase())) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_FLAG);
return false;
}
if (!plr.hasPermission("plots.set.flag" + args[1].toLowerCase())) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
return false;
}
if (args.length == 2) {
if (plot.settings.getFlag(args[1].toLowerCase()) == null) {
if (PlotMain.worldGuardListener != null) {
if (PlotMain.worldGuardListener.str_flags
.contains(args[1].toLowerCase())) {
PlotMain.worldGuardListener.removeFlag(plr,
plr.getWorld(), plot, args[1]);
return false;
}
}
PlayerFunctions.sendMessage(plr, C.FLAG_NOT_IN_PLOT);
return false;
}
Flag flag = plot.settings.getFlag(args[1].toLowerCase());
PlotFlagRemoveEvent event = new PlotFlagRemoveEvent(flag, plot);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
PlayerFunctions.sendMessage(plr, C.FLAG_NOT_REMOVED);
event.setCancelled(true);
return false;
}
java.util.Set<Flag> newflags = plot.settings.getFlags();
Flag oldFlag = plot.settings.getFlag(args[1].toLowerCase());
if (oldFlag != null) {
newflags.remove(oldFlag);
}
plot.settings.setFlags(newflags.toArray(new Flag[0]));
DBFunc.setFlags(plr.getWorld().getName(), plot,
newflags.toArray(new Flag[0]));
PlayerFunctions.sendMessage(plr, C.FLAG_REMOVED);
return true;
}
try {
String value = StringUtils.join(
Arrays.copyOfRange(args, 2, args.length), " ");
if ((FlagManager.getFlag(args[1].toLowerCase()) == null)
&& (PlotMain.worldGuardListener != null)) {
PlotMain.worldGuardListener.addFlag(plr, plr.getWorld(),
plot, args[1], value);
return false;
}
Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(),
true), value);
PlotFlagAddEvent event = new PlotFlagAddEvent(flag, plot);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
PlayerFunctions.sendMessage(plr, C.FLAG_NOT_ADDED);
event.setCancelled(true);
return false;
}
plot.settings.addFlag(flag);
DBFunc.setFlags(plr.getWorld().getName(), plot, plot.settings
.getFlags().toArray(new Flag[0]));
PlayerFunctions.sendMessage(plr, C.FLAG_ADDED);
return true;
} catch (Exception e) {
PlayerFunctions.sendMessage(plr, "&c" + e.getMessage());
return false;
}
}
if (args[0].equalsIgnoreCase("rain")) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.NEED_ON_OFF);
return false;
}
String word = args[1];
if (!word.equalsIgnoreCase("on") && !word.equalsIgnoreCase("off")) {
PlayerFunctions.sendMessage(plr, C.NEED_ON_OFF);
return true;
}
boolean b = word.equalsIgnoreCase("on");
DBFunc.setWeather(plr.getWorld().getName(), plot, b);
PlayerFunctions.sendMessage(plr, C.SETTING_UPDATED);
for (Player p : Bukkit.getOnlinePlayers()) {
if (PlayerFunctions.getCurrentPlot(plr).id == plot.id) {
if (b) {
p.setPlayerWeather(WeatherType.DOWNFALL);
} else {
p.resetPlayerWeather();
}
}
}
return true;
}
if (args[0].equalsIgnoreCase("home")) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.MISSING_POSITION);
return false;
}
PlotHomePosition position = null;
for (PlotHomePosition p : PlotHomePosition.values()) {
if (p.isMatching(args[1])) {
position = p;
}
}
if (position == null) {
PlayerFunctions.sendMessage(plr, C.INVALID_POSITION);
return false;
}
DBFunc.setPosition(plr.getWorld().getName(), plot, position.toString());
PlayerFunctions.sendMessage(plr, C.POSITION_SET);
return true;
}
if (args[0].equalsIgnoreCase("home")) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.MISSING_POSITION);
return false;
}
PlotHomePosition position = null;
for (PlotHomePosition p : PlotHomePosition.values()) {
if (p.isMatching(args[1])) {
position = p;
}
}
if (position == null) {
PlayerFunctions.sendMessage(plr, C.INVALID_POSITION);
return false;
}
DBFunc.setPosition(plr.getWorld().getName(), plot,
position.toString());
PlayerFunctions.sendMessage(plr, C.POSITION_SET);
return true;
}
if (args[0].equalsIgnoreCase("alias")) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.MISSING_ALIAS);
return false;
}
String alias = args[1];
for (Plot p : PlotMain.getPlots(plr.getWorld()).values()) {
if (p.settings.getAlias().equalsIgnoreCase(alias)) {
PlayerFunctions.sendMessage(plr, C.ALIAS_IS_TAKEN);
return false;
}
if (Bukkit.getOfflinePlayer(alias).hasPlayedBefore()) {
PlayerFunctions.sendMessage(plr, C.ALIAS_IS_TAKEN);
return false;
}
}
DBFunc.setAlias(plr.getWorld().getName(), plot, alias);
PlayerFunctions.sendMessage(plr, C.ALIAS_SET_TO.s().replaceAll("%alias%", alias));
return true;
}
if (args[0].equalsIgnoreCase("biome")) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.NEED_BIOME);
return true;
}
Biome biome = null;
for (Biome b : Biome.values()) {
if (b.toString().equalsIgnoreCase(args[1])) {
biome = b;
break;
}
}
if (biome == null) {
PlayerFunctions.sendMessage(plr, getBiomeList(Arrays.asList(Biome.values())));
return true;
}
PlotHelper.setBiome(plr.getWorld(), plot, biome);
PlayerFunctions.sendMessage(plr, C.BIOME_SET_TO.s() + biome.toString().toLowerCase());
return true;
}
if (args[0].equalsIgnoreCase("wall")) {
PlotWorld plotworld = PlotMain.getWorldSettings(plr.getWorld());
if (plotworld == null) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return true;
}
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.NEED_BLOCK);
return true;
}
Material material = null;
for (Material m : PlotWorld.BLOCKS) {
if (m.toString().equalsIgnoreCase(args[1])) {
material = m;
break;
}
}
if (material == null) {
PlayerFunctions.sendMessage(plr, getBlockList(PlotWorld.BLOCKS));
return true;
}
byte data = 0;
if (args[0].equalsIgnoreCase("alias")) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.MISSING_ALIAS);
return false;
}
String alias = args[1];
for (Plot p : PlotMain.getPlots(plr.getWorld()).values()) {
if (p.settings.getAlias().equalsIgnoreCase(alias)) {
PlayerFunctions.sendMessage(plr, C.ALIAS_IS_TAKEN);
return false;
}
if (Bukkit.getOfflinePlayer(alias).hasPlayedBefore()) {
PlayerFunctions.sendMessage(plr, C.ALIAS_IS_TAKEN);
return false;
}
}
DBFunc.setAlias(plr.getWorld().getName(), plot, alias);
PlayerFunctions.sendMessage(plr,
C.ALIAS_SET_TO.s().replaceAll("%alias%", alias));
return true;
}
if (args[0].equalsIgnoreCase("biome")) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.NEED_BIOME);
return true;
}
Biome biome = null;
for (Biome b : Biome.values()) {
if (b.toString().equalsIgnoreCase(args[1])) {
biome = b;
break;
}
}
if (biome == null) {
PlayerFunctions.sendMessage(plr,
getBiomeList(Arrays.asList(Biome.values())));
return true;
}
PlotHelper.setBiome(plr.getWorld(), plot, biome);
PlayerFunctions.sendMessage(plr, C.BIOME_SET_TO.s()
+ biome.toString().toLowerCase());
return true;
}
if (args[0].equalsIgnoreCase("wall")) {
PlotWorld plotworld = PlotMain.getWorldSettings(plr.getWorld());
if (plotworld == null) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return true;
}
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.NEED_BLOCK);
return true;
}
Material material = null;
for (Material m : PlotWorld.BLOCKS) {
if (m.toString().equalsIgnoreCase(args[1])) {
material = m;
break;
}
}
if (material == null) {
PlayerFunctions
.sendMessage(plr, getBlockList(PlotWorld.BLOCKS));
return true;
}
byte data = 0;
if (args.length > 2) {
try {
data = (byte) Integer.parseInt(args[2]);
} catch (Exception e) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA);
return true;
}
}
PlayerFunctions.sendMessage(plr, C.GENERATING_WALL);
PlotHelper.adjustWall(plr.getWorld(), plot, (short) material.getId(), data);
return true;
}
if (args[0].equalsIgnoreCase("floor")) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.NEED_BLOCK);
return true;
}
PlotWorld plotworld = PlotMain.getWorldSettings(plr.getWorld());
if (plotworld == null) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return true;
}
//
@SuppressWarnings("unchecked")
ArrayList<Material> materials = (ArrayList<Material>) PlotWorld.BLOCKS.clone();
materials.add(Material.AIR);
//
String[] strings = args[1].split(",");
//
Material[] material = new Material[strings.length];
byte[] data = new byte[strings.length];
//
int index = 0;
//
byte b = (byte) 0;
Material m = null;
//
for (String s : strings) {
s = s.replaceAll(",", "");
String[] ss = s.split(";");
ss[0] = ss[0].replaceAll(";", "");
for (Material ma : materials) {
if (ma.toString().equalsIgnoreCase(ss[0])) {
m = ma;
}
}
if (m == null) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_BLOCK);
return true;
}
if (ss.length == 1) {
data[index] = (byte) 0;
material[index] = m;
} else {
try {
b = (byte) Integer.parseInt(ss[1]);
} catch (Exception e) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA);
return true;
}
data[index] = b;
material[index] = m;
}
index++;
}
PlotHelper.setFloor(plr, plot, material, data);
return true;
}
if (args[0].equalsIgnoreCase("wall_filling")) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.NEED_BLOCK);
return true;
}
PlotWorld plotworld = PlotMain.getWorldSettings(plr.getWorld());
if (plotworld == null) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return true;
}
Material material = null;
for (Material m : PlotWorld.BLOCKS) {
if (m.toString().equalsIgnoreCase(args[1])) {
material = m;
break;
}
}
if (material == null) {
PlayerFunctions.sendMessage(plr, getBlockList(PlotWorld.BLOCKS));
return true;
}
byte data = 0;
if (args.length > 2) {
try {
data = (byte) Integer.parseInt(args[2]);
} catch (Exception e) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA);
return true;
}
}
PlayerFunctions.sendMessage(plr, C.GENERATING_WALL);
PlotHelper.adjustWall(plr, plot,
new PlotBlock((short) material.getId(), data));
return true;
}
if (args[0].equalsIgnoreCase("floor")) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.NEED_BLOCK);
return true;
}
PlotWorld plotworld = PlotMain.getWorldSettings(plr.getWorld());
if (plotworld == null) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return true;
}
//
@SuppressWarnings("unchecked")
ArrayList<Material> materials = (ArrayList<Material>) PlotWorld.BLOCKS
.clone();
materials.add(Material.AIR);
//
String[] strings = args[1].split(",");
//
int index = 0;
//
byte b = (byte) 0;
Material m = null;
//
PlotBlock[] blocks = new PlotBlock[strings.length];
if (args.length > 2) {
try {
data = (byte) Integer.parseInt(args[2]);
} catch (Exception e) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA);
return true;
}
}
PlotHelper.adjustWallFilling(plr, plr.getWorld(), plot, (short) material.getId(), data);
return true;
}
StringBuilder builder = new StringBuilder();
builder.append(C.SUBCOMMAND_SET_OPTIONS_HEADER.s());
builder.append(getArgumentList(values));
PlayerFunctions.sendMessage(plr, builder.toString());
return false;
}
for (String s : strings) {
s = s.replaceAll(",", "");
String[] ss = s.split(";");
ss[0] = ss[0].replaceAll(";", "");
for (Material ma : materials) {
if (ma.toString().equalsIgnoreCase(ss[0])) {
m = ma;
}
}
if (m == null) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_BLOCK);
return true;
}
if (ss.length == 1) {
private String getMaterial(Material m) {
return ChatColor.translateAlternateColorCodes('&', C.BLOCK_LIST_ITEM.s().replaceAll("%mat%", m.toString().toLowerCase()));
}
blocks[index] = new PlotBlock((short) m.getId(), (byte) 0);
} else {
try {
b = (byte) Integer.parseInt(ss[1]);
} catch (Exception e) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA);
return true;
}
blocks[index] = new PlotBlock((short) m.getId(), b);
}
index++;
}
PlotHelper.setFloor(plr, plot, blocks);
return true;
}
if (args[0].equalsIgnoreCase("wall_filling")) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.NEED_BLOCK);
return true;
}
PlotWorld plotworld = PlotMain.getWorldSettings(plr.getWorld());
if (plotworld == null) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return true;
}
Material material = null;
for (Material m : PlotWorld.BLOCKS) {
if (m.toString().equalsIgnoreCase(args[1])) {
material = m;
break;
}
}
if (material == null) {
PlayerFunctions
.sendMessage(plr, getBlockList(PlotWorld.BLOCKS));
return true;
}
byte data = 0;
private String getBiome(Biome b) {
return ChatColor.translateAlternateColorCodes('&', C.BLOCK_LIST_ITEM.s().replaceAll("%mat%", b.toString().toLowerCase()));
}
if (args.length > 2) {
try {
data = (byte) Integer.parseInt(args[2]);
} catch (Exception e) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_DATA);
return true;
}
}
PlotHelper.adjustWallFilling(plr, plot, new PlotBlock(
(short) material.getId(), data));
return true;
}
StringBuilder builder = new StringBuilder();
builder.append(C.SUBCOMMAND_SET_OPTIONS_HEADER.s());
builder.append(getArgumentList(values));
PlayerFunctions.sendMessage(plr, builder.toString());
return false;
}
private String getString(String s) {
return ChatColor.translateAlternateColorCodes('&', C.BLOCK_LIST_ITEM.s().replaceAll("%mat%", s));
}
private String getMaterial(Material m) {
return ChatColor.translateAlternateColorCodes('&', C.BLOCK_LIST_ITEM
.s().replaceAll("%mat%", m.toString().toLowerCase()));
}
private String getArgumentList(String[] strings) {
StringBuilder builder = new StringBuilder();
for (String s : strings) {
builder.append(getString(s));
}
return builder.toString().substring(1, builder.toString().length() - 1);
}
private String getBiome(Biome b) {
return ChatColor.translateAlternateColorCodes('&', C.BLOCK_LIST_ITEM
.s().replaceAll("%mat%", b.toString().toLowerCase()));
}
private String getBiomeList(List<Biome> biomes) {
StringBuilder builder = new StringBuilder();
builder.append(ChatColor.translateAlternateColorCodes('&', C.NOT_VALID_BLOCK_LIST_HEADER.s()));
for (Biome b : biomes) {
builder.append(getBiome(b));
}
return builder.toString().substring(1, builder.toString().length() - 1);
}
private String getString(String s) {
return ChatColor.translateAlternateColorCodes('&', C.BLOCK_LIST_ITEM
.s().replaceAll("%mat%", s));
}
private String getBlockList(List<Material> blocks) {
StringBuilder builder = new StringBuilder();
builder.append(ChatColor.translateAlternateColorCodes('&', C.NOT_VALID_BLOCK_LIST_HEADER.s()));
for (Material b : blocks) {
builder.append(getMaterial(b));
}
return builder.toString().substring(1, builder.toString().length() - 1);
}
private String getArgumentList(String[] strings) {
StringBuilder builder = new StringBuilder();
for (String s : strings) {
builder.append(getString(s));
}
return builder.toString().substring(1, builder.toString().length() - 1);
}
private String getBiomeList(List<Biome> biomes) {
StringBuilder builder = new StringBuilder();
builder.append(ChatColor.translateAlternateColorCodes('&',
C.NOT_VALID_BLOCK_LIST_HEADER.s()));
for (Biome b : biomes) {
builder.append(getBiome(b));
}
return builder.toString().substring(1, builder.toString().length() - 1);
}
private String getBlockList(List<Material> blocks) {
StringBuilder builder = new StringBuilder();
builder.append(ChatColor.translateAlternateColorCodes('&',
C.NOT_VALID_BLOCK_LIST_HEADER.s()));
for (Material b : blocks) {
builder.append(getMaterial(b));
}
return builder.toString().substring(1, builder.toString().length() - 1);
}
}

View File

@ -9,44 +9,50 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.*;
import com.intellectualcrafters.plot.database.DBFunc;
import java.util.UUID;
import org.bukkit.entity.Player;
import java.util.UUID;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.UUIDHandler;
import com.intellectualcrafters.plot.database.DBFunc;
@SuppressWarnings("deprecation")
public class SetOwner extends SubCommand {
public SetOwner() {
super("setowner", "plots.admin", "Set the plot owner", "setowner {player}", "so", CommandCategory.ACTIONS);
}
public SetOwner() {
super("setowner", "plots.admin", "Set the plot owner",
"setowner {player}", "so", CommandCategory.ACTIONS);
}
/*
private UUID getUUID(String string) {
OfflinePlayer player = Bukkit.getOfflinePlayer(string);
return ((player != null) && player.hasPlayedBefore()) ? player.getUniqueId() : null;
}*/
/*
* private UUID getUUID(String string) { OfflinePlayer player =
* Bukkit.getOfflinePlayer(string); return ((player != null) &&
* player.hasPlayedBefore()) ? player.getUniqueId() : null; }
*/
private UUID getUUID(String string) {
return UUIDHandler.getUUID(string);
}
private UUID getUUID(String string) {
return UUIDHandler.getUUID(string);
}
@Override
public boolean execute(Player plr, String... args) {
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
return true;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (args.length < 1) {
PlayerFunctions.sendMessage(plr, C.NEED_USER);
return true;
}
plot.owner = getUUID(args[0]);
PlotMain.updatePlot(plot);
DBFunc.setOwner(plot, plot.owner);
PlayerFunctions.sendMessage(plr, C.SET_OWNER);
return true;
}
@Override
public boolean execute(Player plr, String... args) {
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
return true;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (args.length < 1) {
PlayerFunctions.sendMessage(plr, C.NEED_USER);
return true;
}
plot.owner = getUUID(args[0]);
PlotMain.updatePlot(plot);
DBFunc.setOwner(plot, plot.owner);
PlayerFunctions.sendMessage(plr, C.SET_OWNER);
return true;
}
}

View File

@ -1,16 +1,15 @@
package com.intellectualcrafters.plot.commands;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.bukkit.block.Biome;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.ConfigurationNode;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotWorld;
@ -20,244 +19,148 @@ import com.intellectualcrafters.plot.PlotWorld;
*/
public class Setup extends SubCommand implements Listener {
public static Map<String, SetupObject> setupMap = new HashMap<>();
public static Map<String, SetupObject> setupMap = new HashMap<>();
private static class SetupStep {
private String constant;
private Object default_value;
private String description;
private Object value = 0;
private String type;
private class SetupObject {
String world;
int current = 0;
public SetupStep(String constant, Object default_value, String description, String type, boolean require_previous) {
this.constant = constant;
this.default_value = default_value;
this.description = description;
this.type = type;
}
ConfigurationNode[] step;
public String getType() {
return this.type;
}
public SetupObject(String world, PlotWorld plotworld) {
this.world = world;
this.step = plotworld.getSettingNodes();
}
public boolean setValue(String string) {
if (!validValue(string)) {
return false;
}
switch (this.type) {
case "integer":
this.value = Integer.parseInt(string);
break;
case "boolean":
this.value = Boolean.parseBoolean(string);
break;
case "double":
this.value = Double.parseDouble(string);
break;
case "float":
this.value = Float.parseFloat(string);
break;
case "biome":
this.value = (string.toUpperCase());
break;
case "block":
this.value = string;
break;
case "blocklist":
this.value = string.split(",");
break;
case "string":
this.value = string;
break;
}
return true;
}
public int getCurrent() {
return this.current;
}
public boolean validValue(String string) {
try {
if (this.type.equals("integer")) {
Integer.parseInt(string);
return true;
}
if (this.type.equals("boolean")) {
Boolean.parseBoolean(string);
return true;
}
if (this.type.equals("double")) {
Double.parseDouble(string);
return true;
}
if (this.type.equals("float")) {
Float.parseFloat(string);
return true;
}
if (this.type.equals("biome")) {
Biome.valueOf(string.toUpperCase());
return true;
}
if (this.type.equals("block")) {
if (string.contains(":")) {
String[] split = string.split(":");
Short.parseShort(split[0]);
Short.parseShort(split[1]);
} else {
Short.parseShort(string);
}
return true;
}
if (this.type.equals("blocklist")) {
for (String block : string.split(",")) {
if (block.contains(":")) {
String[] split = block.split(":");
Short.parseShort(split[0]);
Short.parseShort(split[1]);
} else {
Short.parseShort(block);
}
}
return true;
}
if (this.type.equals("string")) {
return true;
}
} catch (Exception e) {
}
return false;
}
public int getMax() {
return this.step.length;
}
}
public Object getValue() {
if (this.value instanceof String[]) {
return Arrays.asList((String[]) this.value);
}
return this.value;
}
public Setup() {
super("setup", "plots.admin", "Setup a PlotWorld", "setup {world}",
"setup", CommandCategory.ACTIONS);
}
public String getConstant() {
return this.constant;
}
@Override
public boolean execute(Player plr, String... args) {
boolean finished = false;
public Object getDefaultValue() {
if (this.default_value instanceof String[]) {
return StringUtils.join((String[]) this.default_value, ",");
}
return this.default_value;
}
if (!finished) {
// TODO recode this to work with the multiple generators
PlayerFunctions
.sendMessage(plr, "&4CURRENTLY NOT IMPLEMENTED YET!");
public String getDescription() {
return this.description;
}
}
return false;
}
private class SetupObject {
String world;
int current = 0;
if (setupMap.containsKey(plr.getName())) {
SetupObject object = setupMap.get(plr.getName());
if (object.getCurrent() == object.getMax()) {
sendMessage(plr, C.SETUP_FINISHED, object.world);
SetupStep[] step = new SetupStep[] { new SetupStep("road.height", PlotWorld.ROAD_HEIGHT_DEFAULT, "Height of road", "integer", false), new SetupStep("plot.height", PlotWorld.PLOT_HEIGHT_DEFAULT, "Height of plot", "integer", false), new SetupStep("wall.height", PlotWorld.WALL_HEIGHT_DEFAULT, "Height of wall", "integer", false), new SetupStep("plot.size", PlotWorld.PLOT_WIDTH_DEFAULT, "Size of plot", "integer", false), new SetupStep("road.width", PlotWorld.ROAD_WIDTH_DEFAULT, "Width of road", "integer", false), new SetupStep("plot.biome", PlotWorld.PLOT_BIOME_DEFAULT, "Plot biome", "biome", false), new SetupStep("plot.filling", PlotWorld.MAIN_BLOCK_DEFAULT, "Plot filling", "blocklist", false), new SetupStep("plot.floor", PlotWorld.TOP_BLOCK_DEFAULT, "Plot floor", "blocklist", false), new SetupStep("wall.block", PlotWorld.WALL_BLOCK_DEFAULT, "Wall block", "block", false), new SetupStep("wall.filling", PlotWorld.WALL_FILLING_DEFAULT, "Wall filling", "block", false),
new SetupStep("road.enable_stripes", PlotWorld.ROAD_STRIPES_ENABLED_DEFAULT, "Enable road stripes", "boolean", false), new SetupStep("road.stripes", PlotWorld.ROAD_STRIPES_DEFAULT, "Road stripes block", "block", true), new SetupStep("road.block", PlotWorld.ROAD_BLOCK_DEFAULT, "Road block", "block", false), };
ConfigurationNode[] steps = object.step;
String world = object.world;
for (ConfigurationNode step : steps) {
PlotMain.config.set(
"worlds." + world + "." + step.getConstant(),
step.getValue());
}
try {
PlotMain.config.save(PlotMain.configFile);
} catch (IOException e) {
e.printStackTrace();
}
public SetupObject(String world) {
this.world = world;
}
// World newWorld = WorldCreator.name(world).generator(new
// WorldGenerator(world)).createWorld();
// plr.teleport(newWorld.getSpawnLocation());
public int getCurrent() {
return this.current;
}
setupMap.remove(plr.getName());
public int getMax() {
return this.step.length;
}
}
return true;
}
ConfigurationNode step = object.step[object.current];
if (args.length < 1) {
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "",
step.getDescription(), step.getType(),
step.getDefaultValue() + "");
return true;
} else {
if (args[0].equalsIgnoreCase("cancel")) {
setupMap.remove(plr.getName());
PlayerFunctions.sendMessage(plr, "&cCancelled setup.");
return true;
}
if (args[0].equalsIgnoreCase("back")) {
if (object.current > 0) {
object.current--;
step = object.step[object.current];
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "",
step.getDescription(), step.getType(),
step.getDefaultValue() + "");
return true;
} else {
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "",
step.getDescription(), step.getType(),
step.getDefaultValue() + "");
return true;
}
}
boolean valid = step.isValid(args[0]);
if (valid) {
sendMessage(plr, C.SETUP_VALID_ARG, step.getConstant(),
args[0]);
step.setValue(args[0]);
object.current++;
if (object.getCurrent() == object.getMax()) {
execute(plr, args);
return true;
}
step = object.step[object.current];
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "",
step.getDescription(), step.getType(),
step.getDefaultValue() + "");
return true;
} else {
sendMessage(plr, C.SETUP_INVALID_ARG, args[0],
step.getConstant());
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "",
step.getDescription(), step.getType(),
step.getDefaultValue() + "");
return true;
}
}
} else {
if (args.length < 1) {
sendMessage(plr, C.SETUP_MISSING_WORLD);
return true;
}
String world = args[0];
if (StringUtils.isNumeric(args[0])) {
sendMessage(plr, C.SETUP_WORLD_TAKEN, world);
return true;
}
if (PlotMain.getWorldSettings(world) != null) {
sendMessage(plr, C.SETUP_WORLD_TAKEN, world);
return true;
}
public Setup() {
super("setup", "plots.admin", "Setup a PlotWorld", "setup {world}", "setup", CommandCategory.ACTIONS);
}
PlotWorld plotworld = PlotMain.getWorldSettings("//TODO"); // TODO
@Override
public boolean execute(Player plr, String... args) {
if (setupMap.containsKey(plr.getName())) {
SetupObject object = setupMap.get(plr.getName());
if (object.getCurrent() == object.getMax()) {
sendMessage(plr, C.SETUP_FINISHED, object.world);
SetupStep[] steps = object.step;
String world = object.world;
for (SetupStep step : steps) {
PlotMain.config.set("worlds." + world + "." + step.constant, step.getValue());
}
try {
PlotMain.config.save(PlotMain.configFile);
} catch (IOException e) {
e.printStackTrace();
}
// World newWorld = WorldCreator.name(world).generator(new
// WorldGenerator(world)).createWorld();
// plr.teleport(newWorld.getSpawnLocation());
setupMap.remove(plr.getName());
return true;
}
SetupStep step = object.step[object.current];
if (args.length < 1) {
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType(), step.getDefaultValue() + "");
return true;
} else {
if (args[0].equalsIgnoreCase("cancel")) {
setupMap.remove(plr.getName());
PlayerFunctions.sendMessage(plr, "&cCancelled setup.");
return true;
}
if (args[0].equalsIgnoreCase("back")) {
if (object.current > 0) {
object.current--;
step = object.step[object.current];
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType(), step.getDefaultValue() + "");
return true;
} else {
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType(), step.getDefaultValue() + "");
return true;
}
}
boolean valid = step.validValue(args[0]);
if (valid) {
sendMessage(plr, C.SETUP_VALID_ARG, step.getConstant(), args[0]);
step.setValue(args[0]);
object.current++;
if (object.getCurrent() == object.getMax()) {
execute(plr, args);
return true;
}
step = object.step[object.current];
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType(), step.getDefaultValue() + "");
return true;
} else {
sendMessage(plr, C.SETUP_INVALID_ARG, args[0], step.getConstant());
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType(), step.getDefaultValue() + "");
return true;
}
}
} else {
if (args.length < 1) {
sendMessage(plr, C.SETUP_MISSING_WORLD);
return true;
}
String world = args[0];
if (StringUtils.isNumeric(args[0])) {
sendMessage(plr, C.SETUP_WORLD_TAKEN, world);
return true;
}
if (PlotMain.getWorldSettings(world) != null) {
sendMessage(plr, C.SETUP_WORLD_TAKEN, world);
return true;
}
setupMap.put(plr.getName(), new SetupObject(world));
sendMessage(plr, C.SETUP_INIT);
SetupObject object = setupMap.get(plr.getName());
SetupStep step = object.step[object.current];
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType(), step.getDefaultValue() + "");
return true;
}
}
setupMap.put(plr.getName(), new SetupObject(world, plotworld));
sendMessage(plr, C.SETUP_INIT);
SetupObject object = setupMap.get(plr.getName());
ConfigurationNode step = object.step[object.current];
sendMessage(plr, C.SETUP_STEP, object.current + 1 + "",
step.getDescription(), step.getType(),
step.getDefaultValue() + "");
return true;
}
}
}

View File

@ -16,117 +16,120 @@ import com.intellectualcrafters.plot.PlayerFunctions;
/**
* SubCommand class
*
*
* @author Citymonstret
*
*
*/
public abstract class SubCommand {
/**
* Command
*/
public String cmd;
/**
* Permission node
*/
public CommandPermission permission;
/**
* Simple description
*/
public String description;
/**
* Alias
*/
public String alias;
/**
* Command
*/
public String cmd;
/**
* Permission node
*/
public CommandPermission permission;
/**
* Simple description
*/
public String description;
/**
* Alias
*/
public String alias;
/**
* Command usage
*/
public String usage;
/**
* Command usage
*/
public String usage;
public CommandCategory category;
public CommandCategory category;
/**
*
* @param cmd
* Command /plot {cmd} <-- That!
* @param permission
* Permission Node
* @param description
* Simple description
* @param usage
* Usage description: /plot command {args...}
* @param alias
* Command alias
* @param category
* CommandCategory. Pick whichever closests to what you want.
*/
public SubCommand(String cmd, String permission, String description, String usage, String alias, CommandCategory category) {
this.cmd = cmd;
this.permission = new CommandPermission(permission);
this.description = description;
this.alias = alias;
this.usage = usage;
this.category = category;
}
/**
*
* @param cmd
* Command /plot {cmd} <-- That!
* @param permission
* Permission Node
* @param description
* Simple description
* @param usage
* Usage description: /plot command {args...}
* @param alias
* Command alias
* @param category
* CommandCategory. Pick whichever closests to what you want.
*/
public SubCommand(String cmd, String permission, String description,
String usage, String alias, CommandCategory category) {
this.cmd = cmd;
this.permission = new CommandPermission(permission);
this.description = description;
this.alias = alias;
this.usage = usage;
this.category = category;
}
/**
*
* @param command
* Command /plot {cmd} <-- That!
* @param description
* Simple description
* @param usage
* Usage description: /plot command {args...}
* @param category
* CommandCategory. Pick whichever closests to what you want.
*/
public SubCommand(Command command, String description, String usage, CommandCategory category) {
this.cmd = command.getCommand();
this.permission = command.getPermission();
this.alias = command.getAlias();
this.description = description;
this.usage = usage;
this.category = category;
}
/**
*
* @param command
* Command /plot {cmd} <-- That!
* @param description
* Simple description
* @param usage
* Usage description: /plot command {args...}
* @param category
* CommandCategory. Pick whichever closests to what you want.
*/
public SubCommand(Command command, String description, String usage,
CommandCategory category) {
this.cmd = command.getCommand();
this.permission = command.getPermission();
this.alias = command.getAlias();
this.description = description;
this.usage = usage;
this.category = category;
}
/**
* Execute.
*
* @param plr
* executor
* @param args
* arguments
* @return true on success, false on failure
*/
public abstract boolean execute(Player plr, String... args);
/**
* Execute.
*
* @param plr
* executor
* @param args
* arguments
* @return true on success, false on failure
*/
public abstract boolean execute(Player plr, String... args);
public void executeConsole(String... args) {
this.execute(null, args);
}
public void executeConsole(String... args) {
this.execute(null, args);
}
/**
* Send a message
*
* @param plr
* @param c
* @param args
*/
public void sendMessage(Player plr, C c, String... args) {
PlayerFunctions.sendMessage(plr, c, args);
}
/**
* Send a message
*
* @param plr
* @param c
* @param args
*/
public void sendMessage(Player plr, C c, String... args) {
PlayerFunctions.sendMessage(plr, c, args);
}
public enum CommandCategory {
CLAIMING("Claiming"), TELEPORT("Teleportation"), ACTIONS("Actions"), INFO("Information");
private String name;
public enum CommandCategory {
CLAIMING("Claiming"), TELEPORT("Teleportation"), ACTIONS("Actions"), INFO(
"Information");
private String name;
CommandCategory(String name) {
this.name = name;
}
CommandCategory(String name) {
this.name = name;
}
@Override
public String toString() {
return this.name;
}
}
@Override
public String toString() {
return this.name;
}
}
}

View File

@ -22,71 +22,76 @@ import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain;
/**
*
*
* @author Citymonstret
*
*
*/
public class TP extends SubCommand {
public TP() {
super(Command.TP, "Teleport to a plot", "tp {alias|id}", CommandCategory.TELEPORT);
}
public TP() {
super(Command.TP, "Teleport to a plot", "tp {alias|id}",
CommandCategory.TELEPORT);
}
@Override
public boolean execute(Player plr, String... args) {
if (args.length < 1) {
PlayerFunctions.sendMessage(plr, C.NEED_PLOT_ID);
return false;
}
String id = args[0];
PlotId plotid;
World world = plr.getWorld();
if (args.length == 2) {
if (Bukkit.getWorld(args[1]) != null) {
world = Bukkit.getWorld(args[1]);
}
}
if (!PlotMain.isPlotWorld(world)) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return false;
}
Plot temp;
if ((temp = isAlias(world, id)) != null) {
PlotMain.teleportPlayer(plr, plr.getLocation(), temp);
return true;
}
try {
plotid = new PlotId(Integer.parseInt(id.split(";")[0]), Integer.parseInt(id.split(";")[1]));
PlotMain.teleportPlayer(plr, plr.getLocation(), PlotHelper.getPlot(world, plotid));
return true;
} catch (Exception e) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
}
return false;
}
@Override
public boolean execute(Player plr, String... args) {
if (args.length < 1) {
PlayerFunctions.sendMessage(plr, C.NEED_PLOT_ID);
return false;
}
String id = args[0];
PlotId plotid;
World world = plr.getWorld();
if (args.length == 2) {
if (Bukkit.getWorld(args[1]) != null) {
world = Bukkit.getWorld(args[1]);
}
}
if (!PlotMain.isPlotWorld(world)) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return false;
}
Plot temp;
if ((temp = isAlias(world, id)) != null) {
PlotMain.teleportPlayer(plr, plr.getLocation(), temp);
return true;
}
try {
plotid = new PlotId(Integer.parseInt(id.split(";")[0]),
Integer.parseInt(id.split(";")[1]));
PlotMain.teleportPlayer(plr, plr.getLocation(),
PlotHelper.getPlot(world, plotid));
return true;
} catch (Exception e) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
}
return false;
}
private Plot isAlias(World world, String a) {
int index = 0;
if (a.contains(";")) {
String[] split = a.split(";");
if ((split[1].length() > 0) && StringUtils.isNumeric(split[1])) {
index = Integer.parseInt(split[1]);
}
a = split[0];
}
Player player = Bukkit.getPlayer(a);
if (player != null) {
Plot[] plots = PlotMain.getPlots(world, player).toArray(new Plot[0]);
if (plots.length > index) {
return plots[index];
}
return null;
}
for (Plot p : PlotMain.getPlots(world).values()) {
if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) {
return p;
}
}
return null;
}
private Plot isAlias(World world, String a) {
int index = 0;
if (a.contains(";")) {
String[] split = a.split(";");
if ((split[1].length() > 0) && StringUtils.isNumeric(split[1])) {
index = Integer.parseInt(split[1]);
}
a = split[0];
}
Player player = Bukkit.getPlayer(a);
if (player != null) {
Plot[] plots = PlotMain.getPlots(world, player)
.toArray(new Plot[0]);
if (plots.length > index) {
return plots[index];
}
return null;
}
for (Plot p : PlotMain.getPlots(world).values()) {
if ((p.settings.getAlias().length() > 0)
&& p.settings.getAlias().equalsIgnoreCase(a)) {
return p;
}
}
return null;
}
}

View File

@ -9,127 +9,103 @@
package com.intellectualcrafters.plot.commands;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.UUIDHandler;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.events.PlayerPlotTrustedEvent;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.util.UUID;
@SuppressWarnings("deprecation")
public class Trusted extends SubCommand {
public Trusted() {
super(Command.TRUSTED, "Manage trusted users for a plot", "trusted {add|remove} {player}", CommandCategory.ACTIONS);
}
public Trusted() {
super(Command.TRUSTED, "Manage trusted users for a plot",
"trusted {add|remove} {player}", CommandCategory.ACTIONS);
}
private boolean hasBeenOnServer(String name) {
Player plr = Bukkit.getPlayer(name);
if (plr == null) {
OfflinePlayer oplr = Bukkit.getOfflinePlayer(name);
if (oplr == null) {
return false;
} else {
return oplr.hasPlayedBefore();
}
} else {
if (plr.isOnline()) {
return true;
} else {
return plr.hasPlayedBefore();
}
}
}
@Override
public boolean execute(Player plr, String... args) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.TRUSTED_NEED_ARGUMENT);
return true;
}
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
return true;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if ((plot.owner == null) || !plot.hasRights(plr)) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
return true;
}
if (args[0].equalsIgnoreCase("add")) {
if (args[1].equalsIgnoreCase("*")) {
UUID uuid = DBFunc.everyone;
plot.addTrusted(uuid);
DBFunc.setTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
PlayerFunctions.sendMessage(plr, C.TRUSTED_ADDED);
return true;
}
/*if (!hasBeenOnServer(args[1])) {
PlayerFunctions.sendMessage(plr, C.PLAYER_HAS_NOT_BEEN_ON);
return true;
}
UUID uuid = null;
if ((Bukkit.getPlayer(args[1]) != null)) {
uuid = Bukkit.getPlayer(args[1]).getUniqueId();
} else {
uuid = Bukkit.getOfflinePlayer(args[1]).getUniqueId();
}
if (uuid == null) {
PlayerFunctions.sendMessage(plr, C.PLAYER_HAS_NOT_BEEN_ON);
return true;
}*/
UUID uuid = UUIDHandler.getUUID(args[1]);
plot.addTrusted(uuid);
DBFunc.setTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr, plot, uuid, true);
Bukkit.getPluginManager().callEvent(event);
PlayerFunctions.sendMessage(plr, C.TRUSTED_ADDED);
} else if (args[0].equalsIgnoreCase("remove")) {
if (args[1].equalsIgnoreCase("*")) {
UUID uuid = DBFunc.everyone;
if (!plot.trusted.contains(uuid)) {
PlayerFunctions.sendMessage(plr, C.T_WAS_NOT_ADDED);
return true;
}
plot.removeTrusted(uuid);
DBFunc.removeTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
PlayerFunctions.sendMessage(plr, C.TRUSTED_REMOVED);
return true;
}
/*
if (!hasBeenOnServer(args[1])) {
PlayerFunctions.sendMessage(plr, C.PLAYER_HAS_NOT_BEEN_ON);
return true;
}
UUID uuid = null;
if (Bukkit.getPlayer(args[1]) != null) {
uuid = Bukkit.getPlayer(args[1]).getUniqueId();
} else {
uuid = Bukkit.getOfflinePlayer(args[1]).getUniqueId();
}
if (uuid == null) {
PlayerFunctions.sendMessage(plr, C.PLAYER_HAS_NOT_BEEN_ON);
return true;
}
if (!plot.trusted.contains(uuid)) {
PlayerFunctions.sendMessage(plr, C.T_WAS_NOT_ADDED);
return true;
}*/
UUID uuid = UUIDHandler.getUUID(args[1]);
plot.removeTrusted(uuid);
DBFunc.removeTrusted(plr.getWorld().getName(), plot, Bukkit.getOfflinePlayer(args[1]));
PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr, plot, uuid, false);
Bukkit.getPluginManager().callEvent(event);
PlayerFunctions.sendMessage(plr, C.TRUSTED_REMOVED);
} else {
PlayerFunctions.sendMessage(plr, C.TRUSTED_NEED_ARGUMENT);
return true;
}
return true;
}
@Override
public boolean execute(Player plr, String... args) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.TRUSTED_NEED_ARGUMENT);
return true;
}
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT);
return true;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if ((plot.owner == null) || !plot.hasRights(plr)) {
PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
return true;
}
if (args[0].equalsIgnoreCase("add")) {
if (args[1].equalsIgnoreCase("*")) {
UUID uuid = DBFunc.everyone;
plot.addTrusted(uuid);
DBFunc.setTrusted(plr.getWorld().getName(), plot,
Bukkit.getOfflinePlayer(args[1]));
PlayerFunctions.sendMessage(plr, C.TRUSTED_ADDED);
return true;
}
/*
* if (!hasBeenOnServer(args[1])) { PlayerFunctions.sendMessage(plr,
* C.PLAYER_HAS_NOT_BEEN_ON); return true; } UUID uuid = null; if
* ((Bukkit.getPlayer(args[1]) != null)) { uuid =
* Bukkit.getPlayer(args[1]).getUniqueId(); } else { uuid =
* Bukkit.getOfflinePlayer(args[1]).getUniqueId(); } if (uuid ==
* null) { PlayerFunctions.sendMessage(plr,
* C.PLAYER_HAS_NOT_BEEN_ON); return true; }
*/
UUID uuid = UUIDHandler.getUUID(args[1]);
plot.addTrusted(uuid);
DBFunc.setTrusted(plr.getWorld().getName(), plot,
Bukkit.getOfflinePlayer(args[1]));
PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr,
plot, uuid, true);
Bukkit.getPluginManager().callEvent(event);
PlayerFunctions.sendMessage(plr, C.TRUSTED_ADDED);
} else if (args[0].equalsIgnoreCase("remove")) {
if (args[1].equalsIgnoreCase("*")) {
UUID uuid = DBFunc.everyone;
if (!plot.trusted.contains(uuid)) {
PlayerFunctions.sendMessage(plr, C.T_WAS_NOT_ADDED);
return true;
}
plot.removeTrusted(uuid);
DBFunc.removeTrusted(plr.getWorld().getName(), plot,
Bukkit.getOfflinePlayer(args[1]));
PlayerFunctions.sendMessage(plr, C.TRUSTED_REMOVED);
return true;
}
/*
* if (!hasBeenOnServer(args[1])) { PlayerFunctions.sendMessage(plr,
* C.PLAYER_HAS_NOT_BEEN_ON); return true; } UUID uuid = null; if
* (Bukkit.getPlayer(args[1]) != null) { uuid =
* Bukkit.getPlayer(args[1]).getUniqueId(); } else { uuid =
* Bukkit.getOfflinePlayer(args[1]).getUniqueId(); } if (uuid ==
* null) { PlayerFunctions.sendMessage(plr,
* C.PLAYER_HAS_NOT_BEEN_ON); return true; } if
* (!plot.trusted.contains(uuid)) { PlayerFunctions.sendMessage(plr,
* C.T_WAS_NOT_ADDED); return true; }
*/
UUID uuid = UUIDHandler.getUUID(args[1]);
plot.removeTrusted(uuid);
DBFunc.removeTrusted(plr.getWorld().getName(), plot,
Bukkit.getOfflinePlayer(args[1]));
PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(plr,
plot, uuid, false);
Bukkit.getPluginManager().callEvent(event);
PlayerFunctions.sendMessage(plr, C.TRUSTED_REMOVED);
} else {
PlayerFunctions.sendMessage(plr, C.TRUSTED_NEED_ARGUMENT);
return true;
}
return true;
}
}

View File

@ -12,16 +12,15 @@ package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotManager;
import com.intellectualcrafters.plot.PlotWorld;
import com.intellectualcrafters.plot.SetBlockFast;
import com.intellectualcrafters.plot.database.DBFunc;
@ -32,186 +31,91 @@ import com.intellectualcrafters.plot.events.PlotUnlinkEvent;
*/
public class Unlink extends SubCommand {
private short w_id;
private byte w_v;
private short wf_id;
private byte wf_v;
private short f1_id;
private byte f1_v;
private int pathsize;
private int wallheight;
private int roadheight;
public Unlink() {
super(Command.UNLINK, "Unlink a mega-plot", "unlink",
CommandCategory.ACTIONS);
}
public Unlink() {
super(Command.UNLINK, "Unlink a mega-plot", "unlink", CommandCategory.ACTIONS);
}
@Override
public boolean execute(Player plr, String... args) {
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, "You're not in a plot.");
return true;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(
plr.getUniqueId()))
&& !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
return true;
}
if (PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(
PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) {
PlayerFunctions.sendMessage(plr, C.UNLINK_IMPOSSIBLE);
return true;
}
World world = plr.getWorld();
PlotId pos1 = PlayerFunctions.getBottomPlot(world, plot).id;
PlotId pos2 = PlayerFunctions.getTopPlot(world, plot).id;
ArrayList<PlotId> ids = PlayerFunctions.getPlotSelectionIds(world,
pos1, pos2);
@Override
public boolean execute(Player plr, String... args) {
if (!PlayerFunctions.isInPlot(plr)) {
PlayerFunctions.sendMessage(plr, "You're not in a plot.");
return true;
}
Plot plot = PlayerFunctions.getCurrentPlot(plr);
if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS);
return true;
}
if (PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) {
PlayerFunctions.sendMessage(plr, C.UNLINK_IMPOSSIBLE);
return true;
}
World world = plr.getWorld();
PlotId pos1 = PlayerFunctions.getBottomPlot(world, plot).id;
PlotId pos2 = PlayerFunctions.getTopPlot(world, plot).id;
ArrayList<PlotId> ids = PlayerFunctions.getPlotSelectionIds(world, pos1, pos2);
PlotUnlinkEvent event = new PlotUnlinkEvent(world, ids);
PlotUnlinkEvent event = new PlotUnlinkEvent(world, ids);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
event.setCancelled(true);
PlayerFunctions.sendMessage(plr, "&cUnlink has been cancelled");
return false;
}
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
event.setCancelled(true);
PlayerFunctions.sendMessage(plr, "&cUnlink has been cancelled");
return false;
}
for (PlotId id : ids) {
Plot myplot = PlotMain.getPlots(world).get(id);
for (PlotId id : ids) {
Plot myplot = PlotMain.getPlots(world).get(id);
if (plot.helpers != null) {
myplot.helpers = plot.helpers;
}
if (plot.denied != null) {
myplot.denied = plot.denied;
}
myplot.deny_entry = plot.deny_entry;
myplot.settings.setMerged(new boolean[] { false, false, false,
false });
DBFunc.setMerged(world.getName(), myplot,
myplot.settings.getMerged());
}
PlotManager manager = PlotMain.getPlotManager(world);
PlotWorld plotworld = PlotMain.getWorldSettings(world);
for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) {
boolean lx = x < pos2.x;
boolean ly = y < pos2.y;
if (plot.helpers != null) {
myplot.helpers = plot.helpers;
}
if (plot.denied != null) {
myplot.denied = plot.denied;
}
myplot.deny_entry = plot.deny_entry;
myplot.settings.setMerged(new boolean[] { false, false, false, false });
DBFunc.setMerged(world.getName(), myplot, myplot.settings.getMerged());
}
new PlotId(x, y);
PlotWorld plotworld = PlotMain.getWorldSettings(world);
this.pathsize = plotworld.ROAD_WIDTH;
this.roadheight = plotworld.ROAD_HEIGHT;
this.wallheight = plotworld.WALL_HEIGHT;
// WALL
short[] result_w = PlotHelper.getBlock(plotworld.WALL_BLOCK);
this.w_id = result_w[0];
this.w_v = (byte) result_w[1];
if (lx) {
manager.removeRoadEast(plotworld, plot);
// WALL FILLING
short[] result_wf = PlotHelper.getBlock(plotworld.WALL_FILLING);
this.wf_id = result_wf[0];
this.wf_v = (byte) result_wf[1];
if (ly) {
manager.removeRoadSouthEast(plotworld, plot);
}
// ROAD
short[] result_f1 = PlotHelper.getBlock(plotworld.ROAD_BLOCK);
this.f1_id = result_f1[0];
this.f1_v = (byte) result_f1[1];
//
}
PlotHelper.getBlock(plotworld.ROAD_STRIPES);
for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) {
boolean lx = x < pos2.x;
boolean ly = y < pos2.y;
if (ly) {
manager.removeRoadSouth(plotworld, plot);
}
PlotId id = new PlotId(x, y);
}
}
if (lx) {
setRoadX(world, id);
try {
SetBlockFast.update(plr);
} catch (Exception e) {
if (ly) {
setRoadXY(world, id);
}
}
}
if (ly) {
setRoadY(world, id);
}
}
}
try {
SetBlockFast.update(plr);
} catch (Exception e) {
}
PlayerFunctions.sendMessage(plr, "&6Plots unlinked successfully!");
return true;
}
/**
* Setting the road with the greatest X value
*
* @param world
* @param id
*/
public void setRoadX(World w, PlotId id) {
Location pos1 = PlotHelper.getPlotBottomLocAbs(w, id);
Location pos2 = PlotHelper.getPlotTopLocAbs(w, id);
int sx = pos2.getBlockX();
int ex = (sx + this.pathsize);
int sz = pos1.getBlockZ() - 1;
int ez = pos2.getBlockZ() + 2;
PlotHelper.setSimpleCuboid(w, new Location(w, sx, Math.min(this.wallheight, this.roadheight) + 1, sz + 1), new Location(w, ex + 1, 257 + 1, ez), (short) 0);
PlotHelper.setCuboid(w, new Location(w, sx, 1, sz + 1), new Location(w, sx + 1, this.wallheight + 1, ez), new short[] { this.wf_id }, new short[] { this.wf_v });
PlotHelper.setCuboid(w, new Location(w, sx, this.wallheight + 1, sz + 1), new Location(w, sx + 1, this.wallheight + 2, ez), new short[] { this.w_id }, new short[] { this.w_v });
PlotHelper.setCuboid(w, new Location(w, ex, 1, sz + 1), new Location(w, ex + 1, this.wallheight + 1, ez), new short[] { this.wf_id }, new short[] { this.wf_v });
PlotHelper.setCuboid(w, new Location(w, ex, this.wallheight + 1, sz + 1), new Location(w, ex + 1, this.wallheight + 2, ez), new short[] { this.w_id }, new short[] { this.w_v });
PlotHelper.setCuboid(w, new Location(w, sx + 1, 1, sz + 1), new Location(w, ex, this.roadheight + 1, ez), new short[] { this.f1_id }, new short[] { this.f1_v });
}
/**
* Setting the road with the greatest Y value
*
* @param world
* @param id
*/
public void setRoadY(World w, PlotId id) {
Location pos1 = PlotHelper.getPlotBottomLocAbs(w, id);
Location pos2 = PlotHelper.getPlotTopLocAbs(w, id);
int sz = pos2.getBlockZ();
int ez = (sz + this.pathsize);
int sx = pos1.getBlockX() - 1;
int ex = pos2.getBlockX() + 2;
PlotHelper.setSimpleCuboid(w, new Location(w, sx, Math.min(this.wallheight, this.roadheight) + 1, sz + 1), new Location(w, ex + 1, 257 + 1, ez), (short) 0);
PlotHelper.setCuboid(w, new Location(w, sx + 1, 1, sz), new Location(w, ex, this.wallheight + 1, sz + 1), new short[] { this.wf_id }, new short[] { this.wf_v });
PlotHelper.setCuboid(w, new Location(w, sx + 1, this.wallheight + 1, sz), new Location(w, ex, this.wallheight + 2, sz + 1), new short[] { this.w_id }, new short[] { this.w_v });
PlotHelper.setCuboid(w, new Location(w, sx + 1, 1, ez), new Location(w, ex, this.wallheight + 1, ez + 1), new short[] { this.wf_id }, new short[] { this.wf_v });
PlotHelper.setCuboid(w, new Location(w, sx + 1, this.wallheight + 1, ez), new Location(w, ex, this.wallheight + 2, ez + 1), new short[] { this.w_id }, new short[] { this.w_v });
PlotHelper.setCuboid(w, new Location(w, sx + 1, 1, sz + 1), new Location(w, ex, this.roadheight + 1, ez), new short[] { this.f1_id }, new short[] { this.f1_v });
}
/**
* Setting the intersection with the greatest X and Y value
*
* @param world
* @param id
*/
public void setRoadXY(World w, PlotId id) {
Location pos2 = PlotHelper.getPlotTopLocAbs(w, id);
int sx = pos2.getBlockX() + 1;
int ex = (sx + this.pathsize) - 1;
int sz = pos2.getBlockZ() + 1;
int ez = (sz + this.pathsize) - 1;
PlotHelper.setSimpleCuboid(w, new Location(w, sx, this.roadheight + 1, sz + 1), new Location(w, ex + 1, 257 + 1, ez), (short) 0);
PlotHelper.setCuboid(w, new Location(w, sx + 1, 1, sz + 1), new Location(w, ex, this.roadheight + 1, ez), new short[] { this.f1_id }, new short[] { this.f1_v });
}
PlayerFunctions.sendMessage(plr, "&6Plots unlinked successfully!");
return true;
}
}

View File

@ -22,51 +22,53 @@ import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotMain;
public class Visit extends SubCommand {
public Visit() {
super("visit", "plots.visit", "Visit someones plot", "visit {player} [#]", "v", CommandCategory.TELEPORT);
}
public Visit() {
super("visit", "plots.visit", "Visit someones plot",
"visit {player} [#]", "v", CommandCategory.TELEPORT);
}
public List<Plot> getPlots(UUID uuid) {
List<Plot> plots = new ArrayList<>();
for (Plot p : PlotMain.getPlots()) {
if (p.owner.equals(uuid)) {
plots.add(p);
}
}
return plots;
}
public List<Plot> getPlots(UUID uuid) {
List<Plot> plots = new ArrayList<>();
for (Plot p : PlotMain.getPlots()) {
if (p.owner.equals(uuid)) {
plots.add(p);
}
}
return plots;
}
@SuppressWarnings("deprecation")
@Override
public boolean execute(Player plr, String... args) {
if (args.length < 1) {
PlayerFunctions.sendMessage(plr, C.NEED_USER);
return true;
}
String username = args[0];
List<Plot> plots = getPlots(Bukkit.getOfflinePlayer(username).getUniqueId());
if (plots.isEmpty()) {
PlayerFunctions.sendMessage(plr, C.FOUND_NO_PLOTS);
return true;
}
if (args.length < 2) {
Plot plot = plots.get(0);
PlotMain.teleportPlayer(plr, plr.getLocation(), plot);
return true;
}
int i;
try {
i = Integer.parseInt(args[1]);
} catch (Exception e) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_NUMBER);
return true;
}
if ((i < 0) || (i > plots.size())) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_NUMBER);
return true;
}
Plot plot = plots.get(i);
PlotMain.teleportPlayer(plr, plr.getLocation(), plot);
return true;
}
@SuppressWarnings("deprecation")
@Override
public boolean execute(Player plr, String... args) {
if (args.length < 1) {
PlayerFunctions.sendMessage(plr, C.NEED_USER);
return true;
}
String username = args[0];
List<Plot> plots = getPlots(Bukkit.getOfflinePlayer(username)
.getUniqueId());
if (plots.isEmpty()) {
PlayerFunctions.sendMessage(plr, C.FOUND_NO_PLOTS);
return true;
}
if (args.length < 2) {
Plot plot = plots.get(0);
PlotMain.teleportPlayer(plr, plr.getLocation(), plot);
return true;
}
int i;
try {
i = Integer.parseInt(args[1]);
} catch (Exception e) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_NUMBER);
return true;
}
if ((i < 0) || (i > plots.size())) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_NUMBER);
return true;
}
Plot plot = plots.get(i);
PlotMain.teleportPlayer(plr, plr.getLocation(), plot);
return true;
}
}

View File

@ -9,106 +9,156 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.*;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.UUIDHandler;
/**
*
*
* @author Citymonstret
*
*
*/
public class list extends SubCommand {
public list() {
super(Command.LIST, "List all plots", "list {mine|all|world}", CommandCategory.INFO);
}
public list() {
super(Command.LIST, "List all plots", "list {mine|all|world}",
CommandCategory.INFO);
}
@Override
public boolean execute(Player plr, String... args) {
if (args.length < 1) {
StringBuilder builder = new StringBuilder();
builder.append(C.SUBCOMMAND_SET_OPTIONS_HEADER.s());
builder.append(getArgumentList(new String[] { "mine", "shared", "world", "all" }));
PlayerFunctions.sendMessage(plr, builder.toString());
return true;
}
if (args[0].equalsIgnoreCase("mine")) {
StringBuilder string = new StringBuilder();
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "your") + "\n");
int idx = 0;
for (Plot p : PlotMain.getPlots(plr)) {
string.append(C.PLOT_LIST_ITEM.s().replaceAll("%id%", p.id.x + ";" + p.id.y + ";" + p.world).replaceAll("%owner%", getName(p.owner)) + "\n");
idx++;
}
if (idx == 0) {
PlayerFunctions.sendMessage(plr, C.NO_PLOTS);
return true;
}
string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "You have").replaceAll("%num%", idx + "").replaceAll("%plot%", idx == 1 ? "plot" : "plots"));
PlayerFunctions.sendMessage(plr, string.toString());
return true;
} else if (args[0].equalsIgnoreCase("shared")) {
StringBuilder string = new StringBuilder();
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all") + "\n");
for (Plot p : PlotMain.getPlots()) {
if (p.helpers.contains(plr.getUniqueId())) {
string.append(C.PLOT_LIST_ITEM.s().replaceAll("%id%", p.id.x + ";" + p.id.y + ";" + p.world).replaceAll("%owner%", getName(p.owner)) + "\n");
}
}
string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There is").replaceAll("%num%", PlotMain.getPlots().size() + "").replaceAll("%plot%", PlotMain.getPlots().size() == 1 ? "plot" : "plots"));
PlayerFunctions.sendMessage(plr, string.toString());
return true;
} else if (args[0].equalsIgnoreCase("all")) {
StringBuilder string = new StringBuilder();
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all") + "\n");
for (Plot p : PlotMain.getPlots()) {
string.append(C.PLOT_LIST_ITEM.s().replaceAll("%id%", p.id.x + ";" + p.id.y + ";" + p.world).replaceAll("%owner%", getName(p.owner)) + "\n");
}
string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There is").replaceAll("%num%", PlotMain.getPlots().size() + "").replaceAll("%plot%", PlotMain.getPlots().size() == 1 ? "plot" : "plots"));
PlayerFunctions.sendMessage(plr, string.toString());
return true;
} else if (args[0].equalsIgnoreCase("world")) {
StringBuilder string = new StringBuilder();
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all") + "\n");
HashMap<PlotId, Plot> plots = PlotMain.getPlots(plr.getWorld());
for (Plot p : plots.values()) {
string.append(C.PLOT_LIST_ITEM.s().replaceAll("%id%", p.id.x + ";" + p.id.y + ";" + p.world).replaceAll("%owner%", getName(p.owner)) + "\n");
}
string.append(C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There is").replaceAll("%num%", plots.values().size() + "").replaceAll("%plot%", plots.values().size() == 1 ? "plot" : "plots"));
PlayerFunctions.sendMessage(plr, string.toString());
return true;
} else {
execute(plr);
return false;
}
}
@Override
public boolean execute(Player plr, String... args) {
if (args.length < 1) {
StringBuilder builder = new StringBuilder();
builder.append(C.SUBCOMMAND_SET_OPTIONS_HEADER.s());
builder.append(getArgumentList(new String[] { "mine", "shared",
"world", "all" }));
PlayerFunctions.sendMessage(plr, builder.toString());
return true;
}
if (args[0].equalsIgnoreCase("mine")) {
StringBuilder string = new StringBuilder();
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "your")
+ "\n");
int idx = 0;
for (Plot p : PlotMain.getPlots(plr)) {
string.append(C.PLOT_LIST_ITEM
.s()
.replaceAll("%id%",
p.id.x + ";" + p.id.y + ";" + p.world)
.replaceAll("%owner%", getName(p.owner))
+ "\n");
idx++;
}
if (idx == 0) {
PlayerFunctions.sendMessage(plr, C.NO_PLOTS);
return true;
}
string.append(C.PLOT_LIST_FOOTER.s()
.replaceAll("%word%", "You have")
.replaceAll("%num%", idx + "")
.replaceAll("%plot%", idx == 1 ? "plot" : "plots"));
PlayerFunctions.sendMessage(plr, string.toString());
return true;
} else if (args[0].equalsIgnoreCase("shared")) {
StringBuilder string = new StringBuilder();
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all")
+ "\n");
for (Plot p : PlotMain.getPlots()) {
if (p.helpers.contains(plr.getUniqueId())) {
string.append(C.PLOT_LIST_ITEM
.s()
.replaceAll("%id%",
p.id.x + ";" + p.id.y + ";" + p.world)
.replaceAll("%owner%", getName(p.owner))
+ "\n");
}
}
string.append(C.PLOT_LIST_FOOTER
.s()
.replaceAll("%word%", "There is")
.replaceAll("%num%", PlotMain.getPlots().size() + "")
.replaceAll("%plot%",
PlotMain.getPlots().size() == 1 ? "plot" : "plots"));
PlayerFunctions.sendMessage(plr, string.toString());
return true;
} else if (args[0].equalsIgnoreCase("all")) {
StringBuilder string = new StringBuilder();
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all")
+ "\n");
for (Plot p : PlotMain.getPlots()) {
string.append(C.PLOT_LIST_ITEM
.s()
.replaceAll("%id%",
p.id.x + ";" + p.id.y + ";" + p.world)
.replaceAll("%owner%", getName(p.owner))
+ "\n");
}
string.append(C.PLOT_LIST_FOOTER
.s()
.replaceAll("%word%", "There is")
.replaceAll("%num%", PlotMain.getPlots().size() + "")
.replaceAll("%plot%",
PlotMain.getPlots().size() == 1 ? "plot" : "plots"));
PlayerFunctions.sendMessage(plr, string.toString());
return true;
} else if (args[0].equalsIgnoreCase("world")) {
StringBuilder string = new StringBuilder();
string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all")
+ "\n");
HashMap<PlotId, Plot> plots = PlotMain.getPlots(plr.getWorld());
for (Plot p : plots.values()) {
string.append(C.PLOT_LIST_ITEM
.s()
.replaceAll("%id%",
p.id.x + ";" + p.id.y + ";" + p.world)
.replaceAll("%owner%", getName(p.owner))
+ "\n");
}
string.append(C.PLOT_LIST_FOOTER
.s()
.replaceAll("%word%", "There is")
.replaceAll("%num%", plots.values().size() + "")
.replaceAll("%plot%",
plots.values().size() == 1 ? "plot" : "plots"));
PlayerFunctions.sendMessage(plr, string.toString());
return true;
} else {
execute(plr);
return false;
}
}
private static String getName(UUID id) {
if (id == null) {
return "none";
}
/*String name = Bukkit.getOfflinePlayer(id).getName();
if (name == null) {
return "none";
}
return name;*/
return UUIDHandler.getName(id);
}
private static String getName(UUID id) {
if (id == null) {
return "none";
}
/*
* String name = Bukkit.getOfflinePlayer(id).getName(); if (name ==
* null) { return "none"; } return name;
*/
return UUIDHandler.getName(id);
}
private String getArgumentList(String[] strings) {
StringBuilder builder = new StringBuilder();
for (String s : strings) {
builder.append(getString(s));
}
return builder.toString().substring(1, builder.toString().length() - 1);
}
private String getArgumentList(String[] strings) {
StringBuilder builder = new StringBuilder();
for (String s : strings) {
builder.append(getString(s));
}
return builder.toString().substring(1, builder.toString().length() - 1);
}
private String getString(String s) {
return ChatColor.translateAlternateColorCodes('&', C.BLOCK_LIST_ITEM.s().replaceAll("%mat%", s));
}
private String getString(String s) {
return ChatColor.translateAlternateColorCodes('&', C.BLOCK_LIST_ITEM
.s().replaceAll("%mat%", s));
}
}

View File

@ -9,69 +9,80 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.PlotMain;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.PlotMain;
public class plugin extends SubCommand {
public plugin() {
super("plugin", "plots.use", "Show plugin information", "plugin", "pl", CommandCategory.INFO);
}
public plugin() {
super("plugin", "plots.use", "Show plugin information", "plugin", "pl",
CommandCategory.INFO);
}
@Override
public boolean execute(final Player plr, String... args) {
Bukkit.getScheduler().runTaskAsynchronously(JavaPlugin.getPlugin(PlotMain.class), new Runnable() {
@Override
public void run() {
ArrayList<String> strings = new ArrayList<String>() {
{
String
downloads = getInfo("https://intellectualsites.com/spigot_api.php?method=downloads&url=http://www.spigotmc.org/resources/plotsquared.1177/"),
version = getInfo("https://intellectualsites.com/spigot_api.php?method=version&resource=1177");
add(String.format("&c>> &6PlotSquared (Version: %s)", PlotMain.getMain().getDescription().getVersion()));
add(String.format("&c>> &6Made by Citymonstret and Empire92"));
add(String.format("&c>> &6Download at &lhttp://i-s.link/ps"));
add(String.format("&c>> &cNewest Version (Spigot): %s", version));
add(String.format("&c>> &cTotal Downloads (Spigot): %s", downloads));
}
};
for (String s : strings) {
PlayerFunctions.sendMessage(plr, s);
}
}
});
return true;
}
@Override
public boolean execute(final Player plr, String... args) {
Bukkit.getScheduler().runTaskAsynchronously(
JavaPlugin.getPlugin(PlotMain.class), new Runnable() {
@Override
public void run() {
ArrayList<String> strings = new ArrayList<String>() {
{
String downloads = getInfo("https://intellectualsites.com/spigot_api.php?method=downloads&url=http://www.spigotmc.org/resources/plotsquared.1177/"), version = getInfo("https://intellectualsites.com/spigot_api.php?method=version&resource=1177");
add(String.format(
"&c>> &6PlotSquared (Version: %s)",
PlotMain.getMain().getDescription()
.getVersion()));
add(String
.format("&c>> &6Made by Citymonstret and Empire92"));
add(String
.format("&c>> &6Download at &lhttp://i-s.link/ps"));
add(String.format(
"&c>> &cNewest Version (Spigot): %s",
version));
add(String.format(
"&c>> &cTotal Downloads (Spigot): %s",
downloads));
}
};
for (String s : strings) {
PlayerFunctions.sendMessage(plr, s);
}
}
});
return true;
}
/**
*
* @param link
* @return
*/
private String getInfo(String link) {
try {
URLConnection connection = new URL(link).openConnection();
connection.addRequestProperty("User-Agent", "Mozilla/4.0");
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String document = "", line;
while ((line = reader.readLine()) != null) {
document += (line + "\n");
}
reader.close();
return document;
} catch(Exception e) {
e.printStackTrace();
return "";
}
}
/**
*
* @param link
* @return
*/
private String getInfo(String link) {
try {
URLConnection connection = new URL(link).openConnection();
connection.addRequestProperty("User-Agent", "Mozilla/4.0");
BufferedReader reader = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String document = "", line;
while ((line = reader.readLine()) != null) {
document += (line + "\n");
}
reader.close();
return document;
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
}

View File

@ -9,90 +9,93 @@ import org.bukkit.plugin.Plugin;
/**
* Abstract Database class, serves as a base for any connection method (MySQL,
* SQLite, etc.)
*
*
* @author -_Husky_-
* @author tips48
*/
public abstract class Database {
/**
* Plugin instance, use for plugin.getDataFolder()
*/
protected Plugin plugin;
/**
* Plugin instance, use for plugin.getDataFolder()
*/
protected Plugin plugin;
/**
* Creates a new Database
*
* @param plugin
* Plugin instance
*/
protected Database(Plugin plugin) {
this.plugin = plugin;
}
/**
* Creates a new Database
*
* @param plugin
* Plugin instance
*/
protected Database(Plugin plugin) {
this.plugin = plugin;
}
/**
* Opens a connection with the database
*
* @return Opened connection
* @throws SQLException
* if the connection can not be opened
* @throws ClassNotFoundException
* if the driver cannot be found
*/
public abstract Connection openConnection() throws SQLException, ClassNotFoundException;
/**
* Opens a connection with the database
*
* @return Opened connection
* @throws SQLException
* if the connection can not be opened
* @throws ClassNotFoundException
* if the driver cannot be found
*/
public abstract Connection openConnection() throws SQLException,
ClassNotFoundException;
/**
* Checks if a connection is open with the database
*
* @return true if the connection is open
* @throws SQLException
* if the connection cannot be checked
*/
public abstract boolean checkConnection() throws SQLException;
/**
* Checks if a connection is open with the database
*
* @return true if the connection is open
* @throws SQLException
* if the connection cannot be checked
*/
public abstract boolean checkConnection() throws SQLException;
/**
* Gets the connection with the database
*
* @return Connection with the database, null if none
*/
public abstract Connection getConnection();
/**
* Gets the connection with the database
*
* @return Connection with the database, null if none
*/
public abstract Connection getConnection();
/**
* Closes the connection with the database
*
* @return true if successful
* @throws SQLException
* if the connection cannot be closed
*/
public abstract boolean closeConnection() throws SQLException;
/**
* Closes the connection with the database
*
* @return true if successful
* @throws SQLException
* if the connection cannot be closed
*/
public abstract boolean closeConnection() throws SQLException;
/**
* Executes a SQL Query<br>
*
* If the connection is closed, it will be opened
*
* @param query
* Query to be run
* @return the results of the query
* @throws SQLException
* If the query cannot be executed
* @throws ClassNotFoundException
* If the driver cannot be found; see {@link #openConnection()}
*/
public abstract ResultSet querySQL(String query) throws SQLException, ClassNotFoundException;
/**
* Executes a SQL Query<br>
*
* If the connection is closed, it will be opened
*
* @param query
* Query to be run
* @return the results of the query
* @throws SQLException
* If the query cannot be executed
* @throws ClassNotFoundException
* If the driver cannot be found; see {@link #openConnection()}
*/
public abstract ResultSet querySQL(String query) throws SQLException,
ClassNotFoundException;
/**
* Executes an Update SQL Query<br>
* See {@link java.sql.Statement#executeUpdate(String)}<br>
* If the connection is closed, it will be opened
*
* @param query
* Query to be run
* @return Result Code, see {@link java.sql.Statement#executeUpdate(String)}
* @throws SQLException
* If the query cannot be executed
* @throws ClassNotFoundException
* If the driver cannot be found; see {@link #openConnection()}
*/
public abstract int updateSQL(String query) throws SQLException, ClassNotFoundException;
/**
* Executes an Update SQL Query<br>
* See {@link java.sql.Statement#executeUpdate(String)}<br>
* If the connection is closed, it will be opened
*
* @param query
* Query to be run
* @return Result Code, see {@link java.sql.Statement#executeUpdate(String)}
* @throws SQLException
* If the query cannot be executed
* @throws ClassNotFoundException
* If the driver cannot be found; see {@link #openConnection()}
*/
public abstract int updateSQL(String query) throws SQLException,
ClassNotFoundException;
}

View File

@ -10,98 +10,104 @@ import org.bukkit.plugin.Plugin;
/**
* Connects to and uses a MySQL database
*
*
* @author -_Husky_-
* @author tips48
*/
public class MySQL extends Database {
private final String user;
private final String database;
private final String password;
private final String port;
private final String hostname;
private final String user;
private final String database;
private final String password;
private final String port;
private final String hostname;
private Connection connection;
private Connection connection;
/**
* Creates a new MySQL instance
*
* @param plugin
* Plugin instance
* @param hostname
* Name of the host
* @param port
* Port number
* @param database
* Database name
* @param username
* Username
* @param password
* Password
*/
public MySQL(Plugin plugin, String hostname, String port, String database, String username, String password) {
super(plugin);
this.hostname = hostname;
this.port = port;
this.database = database;
this.user = username;
this.password = password;
this.connection = null;
}
/**
* Creates a new MySQL instance
*
* @param plugin
* Plugin instance
* @param hostname
* Name of the host
* @param port
* Port number
* @param database
* Database name
* @param username
* Username
* @param password
* Password
*/
public MySQL(Plugin plugin, String hostname, String port, String database,
String username, String password) {
super(plugin);
this.hostname = hostname;
this.port = port;
this.database = database;
this.user = username;
this.password = password;
this.connection = null;
}
@Override
public Connection openConnection() throws SQLException, ClassNotFoundException {
if (checkConnection()) {
return this.connection;
}
Class.forName("com.mysql.jdbc.Driver");
this.connection = DriverManager.getConnection("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database, this.user, this.password);
return this.connection;
}
@Override
public Connection openConnection() throws SQLException,
ClassNotFoundException {
if (checkConnection()) {
return this.connection;
}
Class.forName("com.mysql.jdbc.Driver");
this.connection = DriverManager.getConnection("jdbc:mysql://"
+ this.hostname + ":" + this.port + "/" + this.database,
this.user, this.password);
return this.connection;
}
@Override
public boolean checkConnection() throws SQLException {
return (this.connection != null) && !this.connection.isClosed();
}
@Override
public boolean checkConnection() throws SQLException {
return (this.connection != null) && !this.connection.isClosed();
}
@Override
public Connection getConnection() {
return this.connection;
}
@Override
public Connection getConnection() {
return this.connection;
}
@Override
public boolean closeConnection() throws SQLException {
if (this.connection == null) {
return false;
}
this.connection.close();
return true;
}
@Override
public boolean closeConnection() throws SQLException {
if (this.connection == null) {
return false;
}
this.connection.close();
return true;
}
@Override
public ResultSet querySQL(String query) throws SQLException, ClassNotFoundException {
if (checkConnection()) {
openConnection();
}
@Override
public ResultSet querySQL(String query) throws SQLException,
ClassNotFoundException {
if (checkConnection()) {
openConnection();
}
Statement statement = this.connection.createStatement();
Statement statement = this.connection.createStatement();
ResultSet result = statement.executeQuery(query);
ResultSet result = statement.executeQuery(query);
return result;
}
return result;
}
@Override
public int updateSQL(String query) throws SQLException, ClassNotFoundException {
if (checkConnection()) {
openConnection();
}
@Override
public int updateSQL(String query) throws SQLException,
ClassNotFoundException {
if (checkConnection()) {
openConnection();
}
Statement statement = this.connection.createStatement();
Statement statement = this.connection.createStatement();
int result = statement.executeUpdate(query);
int result = statement.executeUpdate(query);
return result;
}
return result;
}
}

View File

@ -1,7 +1,5 @@
package com.intellectualcrafters.plot.database;
import java.io.File;
import java.io.FilenameFilter;
import java.io.PrintStream;
import java.lang.reflect.Field;
import java.util.ArrayList;
@ -25,130 +23,190 @@ import com.worldcretornica.plotme.PlotManager;
*/
public class PlotMeConverter {
private PlotMain plugin;
private PlotMain plugin;
public PlotMeConverter(PlotMain plugin) {
this.plugin = plugin;
}
public PlotMeConverter(PlotMain plugin) {
this.plugin = plugin;
}
public void runAsync() throws Exception {
public void runAsync() throws Exception {
final PrintStream stream = new PrintStream("converter_log.txt");
final PrintStream stream = new PrintStream("converter_log.txt");
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, new Runnable() {
@Override
public void run() {
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Conversion has started");
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Caching playerdata...");
ArrayList<com.intellectualcrafters.plot.Plot> createdPlots = new ArrayList<com.intellectualcrafters.plot.Plot>();
boolean online = Bukkit.getServer().getOnlineMode();
for (World world : Bukkit.getWorlds()) {
HashMap<String, Plot> plots = PlotManager.getPlots(world);
if (plots != null) {
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Processing '" + plots.size() + "' plots for world '" + world.getName() + "'");
Bukkit.getScheduler().runTaskAsynchronously(this.plugin,
new Runnable() {
@Override
public void run() {
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Conversion has started");
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Caching playerdata...");
ArrayList<com.intellectualcrafters.plot.Plot> createdPlots = new ArrayList<com.intellectualcrafters.plot.Plot>();
boolean online = Bukkit.getServer().getOnlineMode();
for (World world : Bukkit.getWorlds()) {
HashMap<String, Plot> plots = PlotManager
.getPlots(world);
if (plots != null) {
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Processing '"
+ plots.size()
+ "' plots for world '"
+ world.getName() + "'");
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Converting " + plots.size() + " plots for '" + world.toString() + "'...");
for (Plot plot : plots.values()) {
ArrayList<UUID> psAdded = new ArrayList<>();
ArrayList<UUID> psTrusted = new ArrayList<>();
ArrayList<UUID> psDenied = new ArrayList<>();
if (world == null) {
world = Bukkit.getWorld("world");
}
long eR3040bl230 = 22392948l;
try {
if (online) {
PlayerList denied = null;
PlayerList added = null;
Field fAdded = plot.getClass().getDeclaredField("allowed");
Field fDenied = plot.getClass().getDeclaredField("denied");
fAdded.setAccessible(true);
fDenied.setAccessible(true);
added = (PlayerList) fAdded.get(plot);
denied = (PlayerList) fDenied.get(plot);
for (Map.Entry<String, UUID> set : added.getAllPlayers().entrySet()) {
if ((set.getValue() != null) || set.getKey().equals("*")) {
if (set.getKey().equalsIgnoreCase("*") || set.getValue().toString().equals("*")) {
psAdded.add(DBFunc.everyone);
continue;
}
}
if (set.getValue() != null) {
psAdded.add(set.getValue());
}
}
for (Map.Entry<String, UUID> set : denied.getAllPlayers().entrySet()) {
if ((set.getValue() != null) || set.getKey().equals("*")) {
if (set.getKey().equals("*") || set.getValue().toString().equals("*")) {
psDenied.add(DBFunc.everyone);
continue;
}
}
if (set.getValue() != null) {
psDenied.add(set.getValue());
}
}
} else {
for (String user : plot.getAllowed().split(",")) {
if (user.equals("*")) {
psAdded.add(DBFunc.everyone);
} else {
UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + user).getBytes(Charsets.UTF_8));
psAdded.add(uuid);
}
}
try {
for (String user : plot.getDenied().split(",")) {
if (user.equals("*")) {
psDenied.add(DBFunc.everyone);
} else {
UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + user).getBytes(Charsets.UTF_8));
psDenied.add(uuid);
}
}
} catch (Throwable e) {
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Converting "
+ plots.size()
+ " plots for '"
+ world.toString() + "'...");
for (Plot plot : plots.values()) {
ArrayList<UUID> psAdded = new ArrayList<>();
ArrayList<UUID> psTrusted = new ArrayList<>();
ArrayList<UUID> psDenied = new ArrayList<>();
if (world == null) {
world = Bukkit.getWorld("world");
}
long eR3040bl230 = 22392948l;
try {
if (online) {
PlayerList denied = null;
PlayerList added = null;
Field fAdded = plot
.getClass()
.getDeclaredField("allowed");
Field fDenied = plot.getClass()
.getDeclaredField("denied");
fAdded.setAccessible(true);
fDenied.setAccessible(true);
added = (PlayerList) fAdded
.get(plot);
denied = (PlayerList) fDenied
.get(plot);
for (Map.Entry<String, UUID> set : added
.getAllPlayers().entrySet()) {
if ((set.getValue() != null)
|| set.getKey().equals(
"*")) {
if (set.getKey()
.equalsIgnoreCase(
"*")
|| set.getValue()
.toString()
.equals("*")) {
psAdded.add(DBFunc.everyone);
continue;
}
}
if (set.getValue() != null) {
psAdded.add(set.getValue());
}
}
for (Map.Entry<String, UUID> set : denied
.getAllPlayers().entrySet()) {
if ((set.getValue() != null)
|| set.getKey().equals(
"*")) {
if (set.getKey()
.equals("*")
|| set.getValue()
.toString()
.equals("*")) {
psDenied.add(DBFunc.everyone);
continue;
}
}
if (set.getValue() != null) {
psDenied.add(set.getValue());
}
}
} else {
for (String user : plot
.getAllowed().split(",")) {
if (user.equals("*")) {
psAdded.add(DBFunc.everyone);
} else {
UUID uuid = UUID
.nameUUIDFromBytes(("OfflinePlayer:" + user)
.getBytes(Charsets.UTF_8));
psAdded.add(uuid);
}
}
try {
for (String user : plot
.getDenied().split(",")) {
if (user.equals("*")) {
psDenied.add(DBFunc.everyone);
} else {
UUID uuid = UUID
.nameUUIDFromBytes(("OfflinePlayer:" + user)
.getBytes(Charsets.UTF_8));
psDenied.add(uuid);
}
}
} catch (Throwable e) {
}
}
} catch (Throwable e) {
e.printStackTrace();
eR3040bl230 = 232000499888388747l;
} finally {
eR3040bl230 = 232999304998392004l;
}
stream.println(eR3040bl230);
PlotId id = new PlotId(Integer.parseInt(plot.id.split(";")[0]), Integer.parseInt(plot.id.split(";")[1]));
com.intellectualcrafters.plot.Plot pl = null;
if (online) {
pl = new com.intellectualcrafters.plot.Plot(id, plot.getOwnerId(), plot.getBiome(), psAdded, psTrusted, psDenied, false, 8000l, false, "", PlotHomePosition.DEFAULT, null, world.getName(), new boolean[] { false, false, false, false });
} else {
String owner = plot.getOwner();
pl = new com.intellectualcrafters.plot.Plot(id, UUID.nameUUIDFromBytes(("OfflinePlayer:" + owner).getBytes(Charsets.UTF_8)), plot.getBiome(), psAdded, psTrusted, psDenied, false, 8000l, false, "", PlotHomePosition.DEFAULT, null, world.getName(), new boolean[] { false, false, false, false });
}
}
}
} catch (Throwable e) {
e.printStackTrace();
eR3040bl230 = 232000499888388747l;
} finally {
eR3040bl230 = 232999304998392004l;
}
stream.println(eR3040bl230);
PlotId id = new PlotId(
Integer.parseInt(plot.id.split(";")[0]),
Integer.parseInt(plot.id.split(";")[1]));
com.intellectualcrafters.plot.Plot pl = null;
if (online) {
pl = new com.intellectualcrafters.plot.Plot(
id, plot.getOwnerId(), plot
.getBiome(), psAdded,
psTrusted, psDenied, false,
8000l, false, "",
PlotHomePosition.DEFAULT, null,
world.getName(), new boolean[] {
false, false, false,
false });
} else {
String owner = plot.getOwner();
pl = new com.intellectualcrafters.plot.Plot(
id,
UUID.nameUUIDFromBytes(("OfflinePlayer:" + owner)
.getBytes(Charsets.UTF_8)),
plot.getBiome(), psAdded,
psTrusted, psDenied, false,
8000l, false, "",
PlotHomePosition.DEFAULT, null,
world.getName(), new boolean[] {
false, false, false,
false });
}
// TODO createPlot doesn't add helpers / denied
// users
if (pl != null) {
createdPlots.add(pl);
}
}
}
}
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Creating plot DB");
DBFunc.createPlots(createdPlots);
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Creating settings/helpers DB");
DBFunc.createAllSettingsAndHelpers(createdPlots);
stream.close();
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Conversion has finished");
// TODO disable PlotMe -> Unload all plot worlds, change the
// generator, restart the server automatically
// Possibly use multiverse / multiworld if it's to difficult
// modifying a world's generator while the server is running
// Should really do that? Would seem pretty bad from our side +
// bukkit wouldn't approve
// TODO createPlot doesn't add helpers /
// denied
// users
if (pl != null) {
createdPlots.add(pl);
}
}
}
}
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Creating plot DB");
DBFunc.createPlots(createdPlots);
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Creating settings/helpers DB");
DBFunc.createAllSettingsAndHelpers(createdPlots);
stream.close();
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7Conversion has finished");
// TODO disable PlotMe -> Unload all plot worlds, change
// the
// generator, restart the server automatically
// Possibly use multiverse / multiworld if it's to
// difficult
// modifying a world's generator while the server is
// running
// Should really do that? Would seem pretty bad from our
// side +
// bukkit wouldn't approve
Bukkit.getPluginManager().disablePlugin(PlotMeConverter.this.plugin);
}
});
}
Bukkit.getPluginManager().disablePlugin(
PlotMeConverter.this.plugin);
}
});
}
}

View File

@ -13,91 +13,97 @@ import org.bukkit.plugin.Plugin;
/**
* Connects to and uses a SQLite database
*
*
* @author Citymonstret
* @author tips48
*/
public class SQLite extends Database {
private Connection connection;
private final String dbLocation;
private Connection connection;
private final String dbLocation;
/**
* Creates a new SQLite instance
*
* @param plugin
* Plugin instance
* @param dbLocation
* Location of the Database (Must end in .db)
*/
public SQLite(Plugin plugin, String dbLocation) {
super(plugin);
this.dbLocation = dbLocation;
}
/**
* Creates a new SQLite instance
*
* @param plugin
* Plugin instance
* @param dbLocation
* Location of the Database (Must end in .db)
*/
public SQLite(Plugin plugin, String dbLocation) {
super(plugin);
this.dbLocation = dbLocation;
}
@Override
public Connection openConnection() throws SQLException, ClassNotFoundException {
if (checkConnection()) {
return this.connection;
}
if (!this.plugin.getDataFolder().exists()) {
this.plugin.getDataFolder().mkdirs();
}
File file = new File(this.plugin.getDataFolder(), this.dbLocation);
if (!(file.exists())) {
try {
file.createNewFile();
} catch (IOException e) {
this.plugin.getLogger().log(Level.SEVERE, "Unable to create database!");
}
}
Class.forName("org.sqlite.JDBC");
this.connection = DriverManager.getConnection("jdbc:sqlite:" + this.plugin.getDataFolder().toPath().toString() + "/" + this.dbLocation);
return this.connection;
}
@Override
public Connection openConnection() throws SQLException,
ClassNotFoundException {
if (checkConnection()) {
return this.connection;
}
if (!this.plugin.getDataFolder().exists()) {
this.plugin.getDataFolder().mkdirs();
}
File file = new File(this.plugin.getDataFolder(), this.dbLocation);
if (!(file.exists())) {
try {
file.createNewFile();
} catch (IOException e) {
this.plugin.getLogger().log(Level.SEVERE,
"Unable to create database!");
}
}
Class.forName("org.sqlite.JDBC");
this.connection = DriverManager.getConnection("jdbc:sqlite:"
+ this.plugin.getDataFolder().toPath().toString() + "/"
+ this.dbLocation);
return this.connection;
}
@Override
public boolean checkConnection() throws SQLException {
return (this.connection != null) && !this.connection.isClosed();
}
@Override
public boolean checkConnection() throws SQLException {
return (this.connection != null) && !this.connection.isClosed();
}
@Override
public Connection getConnection() {
return this.connection;
}
@Override
public Connection getConnection() {
return this.connection;
}
@Override
public boolean closeConnection() throws SQLException {
if (this.connection == null) {
return false;
}
this.connection.close();
return true;
}
@Override
public boolean closeConnection() throws SQLException {
if (this.connection == null) {
return false;
}
this.connection.close();
return true;
}
@Override
public ResultSet querySQL(String query) throws SQLException, ClassNotFoundException {
if (checkConnection()) {
openConnection();
}
@Override
public ResultSet querySQL(String query) throws SQLException,
ClassNotFoundException {
if (checkConnection()) {
openConnection();
}
Statement statement = this.connection.createStatement();
Statement statement = this.connection.createStatement();
ResultSet result = statement.executeQuery(query);
ResultSet result = statement.executeQuery(query);
return result;
}
return result;
}
@Override
public int updateSQL(String query) throws SQLException, ClassNotFoundException {
if (checkConnection()) {
openConnection();
}
@Override
public int updateSQL(String query) throws SQLException,
ClassNotFoundException {
if (checkConnection()) {
openConnection();
}
Statement statement = this.connection.createStatement();
Statement statement = this.connection.createStatement();
int result = statement.executeUpdate(query);
int result = statement.executeUpdate(query);
return result;
}
return result;
}
}

View File

@ -20,47 +20,47 @@ import com.intellectualcrafters.plot.Plot;
* Created by Citymonstret on 2014-08-09.
*/
public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable {
private static HandlerList handlers = new HandlerList();
private boolean cancelled;
private static HandlerList handlers = new HandlerList();
private boolean cancelled;
private Plot plot;
private Plot plot;
/**
* PlayerClaimPlotEvent: Called when a plot is claimed
*
* @param player
* @param plot
*/
public PlayerClaimPlotEvent(Player player, Plot plot) {
super(player);
this.plot = plot;
}
/**
* PlayerClaimPlotEvent: Called when a plot is claimed
*
* @param player
* @param plot
*/
public PlayerClaimPlotEvent(Player player, Plot plot) {
super(player);
this.plot = plot;
}
/**
* Get the plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
/**
* Get the plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
public static HandlerList getHandlerList() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(boolean b) {
this.cancelled = b;
}
@Override
public void setCancelled(boolean b) {
this.cancelled = b;
}
}

View File

@ -11,33 +11,33 @@ import com.intellectualcrafters.plot.Plot;
*/
public class PlayerEnterPlotEvent extends PlayerEvent {
private static HandlerList handlers = new HandlerList();
private static HandlerList handlers = new HandlerList();
private Plot plot;
private Plot plot;
/**
* PlayerEnterPlotEvent: Called when a player leaves a plot
*
* @param player
* @param plot
*/
public PlayerEnterPlotEvent(Player player, Plot plot) {
super(player);
this.plot = plot;
}
/**
* PlayerEnterPlotEvent: Called when a player leaves a plot
*
* @param player
* @param plot
*/
public PlayerEnterPlotEvent(Player player, Plot plot) {
super(player);
this.plot = plot;
}
/**
* Get the plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
/**
* Get the plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
}

View File

@ -10,32 +10,32 @@ import com.intellectualcrafters.plot.Plot;
* Created by Citymonstret on 2014-08-16.
*/
public class PlayerLeavePlotEvent extends PlayerEvent {
private static HandlerList handlers = new HandlerList();
private static HandlerList handlers = new HandlerList();
private Plot plot;
private Plot plot;
/**
* PlayerLeavePlotEvent: Called when a player leaves a plot
*
* @param player
* @param plot
*/
public PlayerLeavePlotEvent(Player player, Plot plot) {
super(player);
this.plot = plot;
}
/**
* PlayerLeavePlotEvent: Called when a player leaves a plot
*
* @param player
* @param plot
*/
public PlayerLeavePlotEvent(Player player, Plot plot) {
super(player);
this.plot = plot;
}
/**
* Get the plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
/**
* Get the plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
}

View File

@ -12,67 +12,68 @@ import com.intellectualcrafters.plot.Plot;
* Created by Citymonstret on 2014-08-16.
*/
public class PlayerPlotDeniedEvent extends Event {
private static HandlerList handlers = new HandlerList();
private static HandlerList handlers = new HandlerList();
private Plot plot;
private Player initiator;
private boolean added;
private UUID player;
private Plot plot;
private Player initiator;
private boolean added;
private UUID player;
/**
* PlayerPlotDeniedEvent: Called when the denied UUID list is modified for a
* plot
*
* @param initiator
* @param plot
* @param player
* @param added
*/
public PlayerPlotDeniedEvent(Player initiator, Plot plot, UUID player, boolean added) {
this.initiator = initiator;
this.plot = plot;
this.added = added;
this.player = player;
}
/**
* PlayerPlotDeniedEvent: Called when the denied UUID list is modified for a
* plot
*
* @param initiator
* @param plot
* @param player
* @param added
*/
public PlayerPlotDeniedEvent(Player initiator, Plot plot, UUID player,
boolean added) {
this.initiator = initiator;
this.plot = plot;
this.added = added;
this.player = player;
}
/**
* If a user was added
*
* @return boolean
*/
public boolean wasAdded() {
return this.added;
}
/**
* If a user was added
*
* @return boolean
*/
public boolean wasAdded() {
return this.added;
}
/**
* The player added/removed
*
* @return UUID
*/
public UUID getPlayer() {
return this.player;
}
/**
* The player added/removed
*
* @return UUID
*/
public UUID getPlayer() {
return this.player;
}
/**
* The plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
/**
* The plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
/**
* The player initiating the action
*
* @return Player
*/
public Player getInitiator() {
return this.initiator;
}
/**
* The player initiating the action
*
* @return Player
*/
public Player getInitiator() {
return this.initiator;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
}

View File

@ -12,66 +12,67 @@ import com.intellectualcrafters.plot.Plot;
* Created by Citymonstret on 2014-08-16.
*/
public class PlayerPlotHelperEvent extends Event {
private static HandlerList handlers = new HandlerList();
private static HandlerList handlers = new HandlerList();
private Plot plot;
private Player initiator;
private boolean added;
private UUID player;
private Plot plot;
private Player initiator;
private boolean added;
private UUID player;
/**
* PlayerPlotHelperEvent: Called when a plot helper is added/removed
*
* @param initiator
* @param plot
* @param player
* @param added
*/
public PlayerPlotHelperEvent(Player initiator, Plot plot, UUID player, boolean added) {
this.initiator = initiator;
this.plot = plot;
this.added = added;
this.player = player;
}
/**
* PlayerPlotHelperEvent: Called when a plot helper is added/removed
*
* @param initiator
* @param plot
* @param player
* @param added
*/
public PlayerPlotHelperEvent(Player initiator, Plot plot, UUID player,
boolean added) {
this.initiator = initiator;
this.plot = plot;
this.added = added;
this.player = player;
}
/**
* If a player was added
*
* @return boolean
*/
public boolean wasAdded() {
return this.added;
}
/**
* If a player was added
*
* @return boolean
*/
public boolean wasAdded() {
return this.added;
}
/**
* The UUID added/removed
*
* @return UUID
*/
public UUID getPlayer() {
return this.player;
}
/**
* The UUID added/removed
*
* @return UUID
*/
public UUID getPlayer() {
return this.player;
}
/**
* The plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
/**
* The plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
/**
* The player initiating the action
*
* @return Player
*/
public Player getInitiator() {
return this.initiator;
}
/**
* The player initiating the action
*
* @return Player
*/
public Player getInitiator() {
return this.initiator;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
}

View File

@ -12,66 +12,67 @@ import com.intellectualcrafters.plot.Plot;
* Created by Citymonstret on 2014-08-16.
*/
public class PlayerPlotTrustedEvent extends Event {
private static HandlerList handlers = new HandlerList();
private static HandlerList handlers = new HandlerList();
private Plot plot;
private Player initiator;
private boolean added;
private UUID player;
private Plot plot;
private Player initiator;
private boolean added;
private UUID player;
/**
* PlayerPlotTrustedEvent: Called when a plot trusted user is added/removed
*
* @param initiator
* @param plot
* @param player
* @param added
*/
public PlayerPlotTrustedEvent(Player initiator, Plot plot, UUID player, boolean added) {
this.initiator = initiator;
this.plot = plot;
this.added = added;
this.player = player;
}
/**
* PlayerPlotTrustedEvent: Called when a plot trusted user is added/removed
*
* @param initiator
* @param plot
* @param player
* @param added
*/
public PlayerPlotTrustedEvent(Player initiator, Plot plot, UUID player,
boolean added) {
this.initiator = initiator;
this.plot = plot;
this.added = added;
this.player = player;
}
/**
* If a player was added
*
* @return boolean
*/
public boolean wasAdded() {
return this.added;
}
/**
* If a player was added
*
* @return boolean
*/
public boolean wasAdded() {
return this.added;
}
/**
* The UUID added/removed
*
* @return UUID
*/
public UUID getPlayer() {
return this.player;
}
/**
* The UUID added/removed
*
* @return UUID
*/
public UUID getPlayer() {
return this.player;
}
/**
* The plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
/**
* The plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
/**
* The player initiating the action
*
* @return Player
*/
public Player getInitiator() {
return this.initiator;
}
/**
* The player initiating the action
*
* @return Player
*/
public Player getInitiator() {
return this.initiator;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
}

View File

@ -20,61 +20,62 @@ import com.intellectualcrafters.plot.Plot;
/**
* Called when a player teleports to a plot
*/
public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
public class PlayerTeleportToPlotEvent extends PlayerEvent implements
Cancellable {
private static final HandlerList handlers = new HandlerList();
private Location from;
private Plot plot;
private Location from;
private Plot plot;
private boolean cancelled;
private boolean cancelled;
/**
* PlayerTeleportToPlotEvent: Called when a player teleports to a plot
*
* @param player
* @param from
* @param plot
*/
public PlayerTeleportToPlotEvent(Player player, Location from, Plot plot) {
super(player);
this.from = from;
this.plot = plot;
}
/**
* PlayerTeleportToPlotEvent: Called when a player teleports to a plot
*
* @param player
* @param from
* @param plot
*/
public PlayerTeleportToPlotEvent(Player player, Location from, Plot plot) {
super(player);
this.from = from;
this.plot = plot;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
/**
* Get the from location
*
* @return Location
*/
public Location getFrom() {
return this.from;
}
/**
* Get the from location
*
* @return Location
*/
public Location getFrom() {
return this.from;
}
/**
* Get the plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
/**
* Get the plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
public static HandlerList getHandlerList() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -19,57 +19,57 @@ import com.intellectualcrafters.plot.PlotId;
* Called when a plot is cleared
*/
public class PlotClearEvent extends Event implements Cancellable {
private static HandlerList handlers = new HandlerList();
private boolean cancelled;
private static HandlerList handlers = new HandlerList();
private boolean cancelled;
private PlotId id;
private String world;
private PlotId id;
private String world;
/**
* PlotDeleteEvent: Called when a plot is cleared
*
* @param world
* @param id
*/
public PlotClearEvent(String world, PlotId id) {
this.id = id;
this.world = world;
}
/**
* PlotDeleteEvent: Called when a plot is cleared
*
* @param world
* @param id
*/
public PlotClearEvent(String world, PlotId id) {
this.id = id;
this.world = world;
}
/**
* Get the PlotId
*
* @return PlotId
*/
public PlotId getPlotId() {
return this.id;
}
/**
* Get the PlotId
*
* @return PlotId
*/
public PlotId getPlotId() {
return this.id;
}
/**
* Get the world name
*
* @return String
*/
public String getWorld() {
return this.world;
}
/**
* Get the world name
*
* @return String
*/
public String getWorld() {
return this.world;
}
public static HandlerList getHandlerList() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(boolean b) {
this.cancelled = b;
}
@Override
public void setCancelled(boolean b) {
this.cancelled = b;
}
}

View File

@ -19,57 +19,57 @@ import com.intellectualcrafters.plot.PlotId;
* Called when a plot is deleted
*/
public class PlotDeleteEvent extends Event implements Cancellable {
private static HandlerList handlers = new HandlerList();
private boolean cancelled;
private static HandlerList handlers = new HandlerList();
private boolean cancelled;
private PlotId id;
private String world;
private PlotId id;
private String world;
/**
* PlotDeleteEvent: Called when a plot is deleted
*
* @param world
* @param id
*/
public PlotDeleteEvent(String world, PlotId id) {
this.id = id;
this.world = world;
}
/**
* PlotDeleteEvent: Called when a plot is deleted
*
* @param world
* @param id
*/
public PlotDeleteEvent(String world, PlotId id) {
this.id = id;
this.world = world;
}
/**
* Get the PlotId
*
* @return PlotId
*/
public PlotId getPlotId() {
return this.id;
}
/**
* Get the PlotId
*
* @return PlotId
*/
public PlotId getPlotId() {
return this.id;
}
/**
* Get the world name
*
* @return String
*/
public String getWorld() {
return this.world;
}
/**
* Get the world name
*
* @return String
*/
public String getWorld() {
return this.world;
}
public static HandlerList getHandlerList() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(boolean b) {
this.cancelled = b;
}
@Override
public void setCancelled(boolean b) {
this.cancelled = b;
}
}

View File

@ -20,57 +20,57 @@ import com.intellectualcrafters.plot.Plot;
* Called when a Flag is added to a plot
*/
public class PlotFlagAddEvent extends Event implements Cancellable {
private static HandlerList handlers = new HandlerList();
private boolean cancelled;
private static HandlerList handlers = new HandlerList();
private boolean cancelled;
private Plot plot;
private Flag flag;
private Plot plot;
private Flag flag;
/**
* PlotFlagAddEvent: Called when a Flag is added to a plot
*
* @param flag
* @param plot
*/
public PlotFlagAddEvent(Flag flag, Plot plot) {
this.plot = plot;
this.flag = flag;
}
/**
* PlotFlagAddEvent: Called when a Flag is added to a plot
*
* @param flag
* @param plot
*/
public PlotFlagAddEvent(Flag flag, Plot plot) {
this.plot = plot;
this.flag = flag;
}
/**
* Get the plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
/**
* Get the plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
/**
* Get the flag involved
*
* @return Flag
*/
public Flag getFlag() {
return this.flag;
}
/**
* Get the flag involved
*
* @return Flag
*/
public Flag getFlag() {
return this.flag;
}
public static HandlerList getHandlerList() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(boolean b) {
this.cancelled = b;
}
@Override
public void setCancelled(boolean b) {
this.cancelled = b;
}
}

View File

@ -20,57 +20,57 @@ import com.intellectualcrafters.plot.Plot;
* Called when a flag is removed from a plot
*/
public class PlotFlagRemoveEvent extends Event implements Cancellable {
private static HandlerList handlers = new HandlerList();
private boolean cancelled;
private static HandlerList handlers = new HandlerList();
private boolean cancelled;
private Plot plot;
private Flag flag;
private Plot plot;
private Flag flag;
/**
* PlotFlagRemoveEvent: Called when a flag is removed from a plot
*
* @param flag
* @param plot
*/
public PlotFlagRemoveEvent(Flag flag, Plot plot) {
this.plot = plot;
this.flag = flag;
}
/**
* PlotFlagRemoveEvent: Called when a flag is removed from a plot
*
* @param flag
* @param plot
*/
public PlotFlagRemoveEvent(Flag flag, Plot plot) {
this.plot = plot;
this.flag = flag;
}
/**
* Get the plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
/**
* Get the plot involved
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
/**
* Get the flag involved
*
* @return Flag
*/
public Flag getFlag() {
return this.flag;
}
/**
* Get the flag involved
*
* @return Flag
*/
public Flag getFlag() {
return this.flag;
}
public static HandlerList getHandlerList() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(boolean b) {
this.cancelled = b;
}
@Override
public void setCancelled(boolean b) {
this.cancelled = b;
}
}

View File

@ -23,61 +23,61 @@ import com.intellectualcrafters.plot.PlotId;
* Created by Citymonstret on 2014-08-09.
*/
public class PlotMergeEvent extends Event implements Cancellable {
private static HandlerList handlers = new HandlerList();
private boolean cancelled;
private static HandlerList handlers = new HandlerList();
private boolean cancelled;
private ArrayList<PlotId> plots;
private Plot plot;
private World world;
private ArrayList<PlotId> plots;
private Plot plot;
private World world;
/**
* PlotMergeEvent: Called when plots are merged
*
* @param player
* @param plot
*/
public PlotMergeEvent(World world, Plot plot, ArrayList<PlotId> plots) {
this.plots = plots;
}
/**
* PlotMergeEvent: Called when plots are merged
*
* @param player
* @param plot
*/
public PlotMergeEvent(World world, Plot plot, ArrayList<PlotId> plots) {
this.plots = plots;
}
/**
* Get the plots being added;
*
* @return Plot
*/
public ArrayList<PlotId> getPlots() {
return this.plots;
}
/**
* Get the plots being added;
*
* @return Plot
*/
public ArrayList<PlotId> getPlots() {
return this.plots;
}
/**
* Get the main plot
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
/**
* Get the main plot
*
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
public World getWorld() {
return this.world;
}
public World getWorld() {
return this.world;
}
public static HandlerList getHandlerList() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(boolean b) {
this.cancelled = b;
}
@Override
public void setCancelled(boolean b) {
this.cancelled = b;
}
}

View File

@ -22,52 +22,52 @@ import com.intellectualcrafters.plot.PlotId;
* Created by Citymonstret on 2014-08-09.
*/
public class PlotUnlinkEvent extends Event implements Cancellable {
private static HandlerList handlers = new HandlerList();
private boolean cancelled;
private static HandlerList handlers = new HandlerList();
private boolean cancelled;
private ArrayList<PlotId> plots;
private World world;
private ArrayList<PlotId> plots;
private World world;
/**
* Called when a mega-plot is unlinked.
*
* @param world
* @param plots
*/
public PlotUnlinkEvent(World world, ArrayList<PlotId> plots) {
this.plots = plots;
this.world = world;
}
/**
* Called when a mega-plot is unlinked.
*
* @param world
* @param plots
*/
public PlotUnlinkEvent(World world, ArrayList<PlotId> plots) {
this.plots = plots;
this.world = world;
}
/**
* Get the plots involved
*
* @return PlotId
*/
public ArrayList<PlotId> getPlots() {
return this.plots;
}
/**
* Get the plots involved
*
* @return PlotId
*/
public ArrayList<PlotId> getPlots() {
return this.plots;
}
public World getWorld() {
return this.world;
}
public World getWorld() {
return this.world;
}
public static HandlerList getHandlerList() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(boolean b) {
this.cancelled = b;
}
@Override
public void setCancelled(boolean b) {
this.cancelled = b;
}
}

View File

@ -10,170 +10,194 @@ import com.intellectualcrafters.plot.PlotWorld;
public class DefaultPlotWorld extends PlotWorld {
/*
* These variables are set to ensure fast access to config settings
* Strings are used as little as possible to optimize math performance in many of the functions/algorithms
*
*/
/**
* Road Height
*/
public int ROAD_HEIGHT;
/**
* Default Road Height: 64
*/
public static int ROAD_HEIGHT_DEFAULT = 64;
/*
* These variables are set to ensure fast access to config settings Strings
* are used as little as possible to optimize math performance in many of
* the functions/algorithms
*/
/**
* plot height
*/
public int PLOT_HEIGHT;
/**
* Default plot height: 64
*/
public static int PLOT_HEIGHT_DEFAULT = 64;
/**
* Road Height
*/
public int ROAD_HEIGHT;
/**
* Default Road Height: 64
*/
public static int ROAD_HEIGHT_DEFAULT = 64;
/**
* Wall height
*/
public int WALL_HEIGHT;
/**
* Default Wall Height: 64
*/
public static int WALL_HEIGHT_DEFAULT = 64;
/**
* plot height
*/
public int PLOT_HEIGHT;
/**
* Default plot height: 64
*/
public static int PLOT_HEIGHT_DEFAULT = 64;
/**
* plot width
*/
public int PLOT_WIDTH;
/**
* Default plot width: 32
*/
public static int PLOT_WIDTH_DEFAULT = 32;
/**
* Wall height
*/
public int WALL_HEIGHT;
/**
* Default Wall Height: 64
*/
public static int WALL_HEIGHT_DEFAULT = 64;
/**
* Road width
*/
public int ROAD_WIDTH;
/**
* Default road width: 7
*/
public static int ROAD_WIDTH_DEFAULT = 7;
/**
* plot width
*/
public int PLOT_WIDTH;
/**
* Default plot width: 32
*/
public static int PLOT_WIDTH_DEFAULT = 32;
/**
* Plot biome
*/
public PlotBlock[] MAIN_BLOCK;
/**
* Default main block: 1
*/
public static PlotBlock[] MAIN_BLOCK_DEFAULT = new PlotBlock[] { new PlotBlock((short) 1, (byte) 0) };
/**
* Top blocks
*/
public PlotBlock[] TOP_BLOCK;
/**
* Default top blocks: {"2"}
*/
public static PlotBlock[] TOP_BLOCK_DEFAULT = new PlotBlock[] { new PlotBlock((short) 2, (byte) 0) };
/**
* Road width
*/
public int ROAD_WIDTH;
/**
* Default road width: 7
*/
public static int ROAD_WIDTH_DEFAULT = 7;
/**
* Wall block
*/
public PlotBlock WALL_BLOCK;
/**
* Default wall block: 44
*/
public static String WALL_BLOCK_DEFAULT = "44:0";
/**
* Plot biome
*/
public PlotBlock[] MAIN_BLOCK;
/**
* Default main block: 1
*/
public static PlotBlock[] MAIN_BLOCK_DEFAULT = new PlotBlock[] { new PlotBlock(
(short) 1, (byte) 0) };
/**
* Top blocks
*/
public PlotBlock[] TOP_BLOCK;
/**
* Default top blocks: {"2"}
*/
public static PlotBlock[] TOP_BLOCK_DEFAULT = new PlotBlock[] { new PlotBlock(
(short) 2, (byte) 0) };
/**
* Wall filling
*/
public PlotBlock WALL_FILLING;
/**
* Default wall filling: 1
*/
public static PlotBlock WALL_FILLING_DEFAULT = new PlotBlock((short) 1, (byte) 0);
/**
* Wall block
*/
public PlotBlock WALL_BLOCK;
/**
* Default wall block: 44
*/
public static String WALL_BLOCK_DEFAULT = "44:0";
/**
* Road stripes
*/
public PlotBlock ROAD_STRIPES;
/**
* Default road stripes: 35
*/
public static PlotBlock ROAD_STRIPES_DEFAULT = new PlotBlock((short) 98, (byte) 0);
/**
* enable road stripes
*/
public boolean ROAD_STRIPES_ENABLED;
public static boolean ROAD_STRIPES_ENABLED_DEFAULT = false;
/**
* Road block
*/
public PlotBlock ROAD_BLOCK;
/**
* Default road block: 155
*/
public static PlotBlock ROAD_BLOCK_DEFAULT = new PlotBlock((short) 155, (byte) 0);
/*
* Here we are just calling the super method, nothing special
*/
public DefaultPlotWorld(String worldname) {
super(worldname);
}
/**
* Wall filling
*/
public PlotBlock WALL_FILLING;
/**
* Default wall filling: 1
*/
public static PlotBlock WALL_FILLING_DEFAULT = new PlotBlock((short) 1,
(byte) 0);
/*
* CONFIG NODE | DEFAULT VALUE | DESCRIPTION | CONFIGURATION TYPE | REQUIRED FOR INITIAL SETUP
*
* Set the last boolean to false if you do not require a specific config node to be set while using the setup command
* - this may be useful if a config value can be changed at a later date, and has no impact on the actual world generation
*
*/
@Override
public ConfigurationNode[] getSettingNodes() {
// TODO return a set of configuration nodes (used for setup command)
return
new ConfigurationNode[] {
new ConfigurationNode("plot.height", PLOT_HEIGHT, "Plot height", Configuration.INTEGER, true),
new ConfigurationNode("plot.width", PLOT_WIDTH, "Plot width", Configuration.INTEGER, true),
new ConfigurationNode("plot.filling", MAIN_BLOCK, "Plot block", Configuration.BLOCKLIST, true),
new ConfigurationNode("plot.floor", TOP_BLOCK, "Plot floor block", Configuration.BLOCKLIST, true),
new ConfigurationNode("wall.block", WALL_BLOCK, "Top wall block", Configuration.BLOCK, true),
new ConfigurationNode("road.width", ROAD_WIDTH, "Road width", Configuration.INTEGER, true),
new ConfigurationNode("road.height", ROAD_HEIGHT, "Road height", Configuration.INTEGER, true),
new ConfigurationNode("road.enable_stripes", ROAD_STRIPES_ENABLED, "Enable road stripes", Configuration.BOOLEAN, true),
new ConfigurationNode("road.block", ROAD_BLOCK, "Road block", Configuration.BLOCK, true),
new ConfigurationNode("road.stripes", ROAD_STRIPES, "Road stripe block", Configuration.BLOCK, true),
new ConfigurationNode("wall.filling", WALL_FILLING, "Wall filling block", Configuration.BLOCK, true),
new ConfigurationNode("wall.height", WALL_HEIGHT, "Wall height", Configuration.INTEGER, true),
};
}
/**
* Road stripes
*/
public PlotBlock ROAD_STRIPES;
/**
* Default road stripes: 35
*/
public static PlotBlock ROAD_STRIPES_DEFAULT = new PlotBlock((short) 98,
(byte) 0);
/**
* enable road stripes
*/
public boolean ROAD_STRIPES_ENABLED;
public static boolean ROAD_STRIPES_ENABLED_DEFAULT = false;
/**
* Road block
*/
public PlotBlock ROAD_BLOCK;
/**
* Default road block: 155
*/
public static PlotBlock ROAD_BLOCK_DEFAULT = new PlotBlock((short) 155,
(byte) 0);
/*
* This method is called when a world loads. Make sure you set all your constants here.
* You are provided with the configuration section for that specific world.
*/
@Override
public void loadConfiguration(ConfigurationSection config) {
this.PLOT_HEIGHT = config.getInt("plot.height");
this.PLOT_WIDTH = config.getInt("plot.width");
this.MAIN_BLOCK = (PlotBlock[]) Configuration.BLOCKLIST.parseString(StringUtils.join(config.getStringList("plot.filling"),','));
this.TOP_BLOCK = (PlotBlock[]) Configuration.BLOCKLIST.parseString(StringUtils.join(config.getStringList("plot.floor"),','));
this.WALL_BLOCK = (PlotBlock) Configuration.BLOCK.parseString(config.getString("wall.block"));
this.ROAD_WIDTH = config.getInt("road.width");
this.ROAD_HEIGHT = config.getInt("road.height");
this.ROAD_STRIPES_ENABLED = config.getBoolean("road.enable_stripes");
this.ROAD_BLOCK = (PlotBlock) Configuration.BLOCK.parseString(config.getString("road.block"));
this.ROAD_STRIPES = (PlotBlock) Configuration.BLOCK.parseString(config.getString("road.stripes"));
this.WALL_FILLING = (PlotBlock) Configuration.BLOCK.parseString(config.getString("wall.filling"));
this.WALL_HEIGHT = config.getInt("wall.height");
}
/*
* Here we are just calling the super method, nothing special
*/
public DefaultPlotWorld(String worldname) {
super(worldname);
}
/*
* CONFIG NODE | DEFAULT VALUE | DESCRIPTION | CONFIGURATION TYPE | REQUIRED
* FOR INITIAL SETUP
*
* Set the last boolean to false if you do not require a specific config
* node to be set while using the setup command - this may be useful if a
* config value can be changed at a later date, and has no impact on the
* actual world generation
*/
@Override
public ConfigurationNode[] getSettingNodes() {
// TODO return a set of configuration nodes (used for setup command)
return new ConfigurationNode[] {
new ConfigurationNode("plot.height", this.PLOT_HEIGHT,
"Plot height", Configuration.INTEGER, true),
new ConfigurationNode("plot.width", this.PLOT_WIDTH,
"Plot width", Configuration.INTEGER, true),
new ConfigurationNode("plot.filling", this.MAIN_BLOCK,
"Plot block", Configuration.BLOCKLIST, true),
new ConfigurationNode("plot.floor", this.TOP_BLOCK,
"Plot floor block", Configuration.BLOCKLIST, true),
new ConfigurationNode("wall.block", this.WALL_BLOCK,
"Top wall block", Configuration.BLOCK, true),
new ConfigurationNode("road.width", this.ROAD_WIDTH,
"Road width", Configuration.INTEGER, true),
new ConfigurationNode("road.height", this.ROAD_HEIGHT,
"Road height", Configuration.INTEGER, true),
new ConfigurationNode("road.enable_stripes",
this.ROAD_STRIPES_ENABLED, "Enable road stripes",
Configuration.BOOLEAN, true),
new ConfigurationNode("road.block", this.ROAD_BLOCK,
"Road block", Configuration.BLOCK, true),
new ConfigurationNode("road.stripes", this.ROAD_STRIPES,
"Road stripe block", Configuration.BLOCK, true),
new ConfigurationNode("wall.filling", this.WALL_FILLING,
"Wall filling block", Configuration.BLOCK, true),
new ConfigurationNode("wall.height", this.WALL_HEIGHT,
"Wall height", Configuration.INTEGER, true), };
}
/*
* This method is called when a world loads. Make sure you set all your
* constants here. You are provided with the configuration section for that
* specific world.
*/
@Override
public void loadConfiguration(ConfigurationSection config) {
this.PLOT_HEIGHT = config.getInt("plot.height");
this.PLOT_WIDTH = config.getInt("plot.width");
this.MAIN_BLOCK = (PlotBlock[]) Configuration.BLOCKLIST
.parseString(StringUtils.join(
config.getStringList("plot.filling"), ','));
this.TOP_BLOCK = (PlotBlock[]) Configuration.BLOCKLIST
.parseString(StringUtils.join(
config.getStringList("plot.floor"), ','));
this.WALL_BLOCK = (PlotBlock) Configuration.BLOCK.parseString(config
.getString("wall.block"));
this.ROAD_WIDTH = config.getInt("road.width");
this.ROAD_HEIGHT = config.getInt("road.height");
this.ROAD_STRIPES_ENABLED = config.getBoolean("road.enable_stripes");
this.ROAD_BLOCK = (PlotBlock) Configuration.BLOCK.parseString(config
.getString("road.block"));
this.ROAD_STRIPES = (PlotBlock) Configuration.BLOCK.parseString(config
.getString("road.stripes"));
this.WALL_FILLING = (PlotBlock) Configuration.BLOCK.parseString(config
.getString("wall.filling"));
this.WALL_HEIGHT = config.getInt("wall.height");
}
}

View File

@ -11,442 +11,535 @@ import com.intellectualcrafters.plot.PlotBlock;
import com.intellectualcrafters.plot.PlotWorld;
/**
*
*
* @author Citymonstret
*
*
*/
public class XPopulator extends BlockPopulator {
/*
* Sorry, this isn't well documented at the moment.
*
* We advise you to take a look at a world generation tutorial for information about how a BlockPopulator works.
*
*/
private int X;
private int Z;
private long state;
public final long nextLong() {
long a = this.state;
this.state = xorShift64(a);
return a;
}
/*
* Sorry, this isn't well documented at the moment.
*
* We advise you to take a look at a world generation tutorial for
* information about how a BlockPopulator works.
*/
public final long xorShift64(long a) {
a ^= (a << 21);
a ^= (a >>> 35);
a ^= (a << 4);
return a;
}
private int X;
private int Z;
private long state;
public final int random(int n) {
long result = ((nextLong() >>> 32) * n) >> 32;
return (int) result;
}
public final long nextLong() {
long a = this.state;
this.state = xorShift64(a);
return a;
}
public void setCuboidRegion(int x1, int x2, int y1, int y2, int z1, int z2, PlotBlock block, World w) {
if (block.data == 0) {
return;
}
for (int x = x1; x < x2; x++) {
for (int z = z1; z < z2; z++) {
for (int y = y1; y < y2; y++) {
setBlock(w, x, y, z, block.id, block.data);
}
}
}
}
public final long xorShift64(long a) {
a ^= (a << 21);
a ^= (a >>> 35);
a ^= (a << 4);
return a;
}
private void setCuboidRegion(int x1, int x2, int y1, int y2, int z1, int z2, PlotBlock[] blocks, World w) {
if (blocks.length == 1) {
setCuboidRegion(x1, x2, y1, y2, z1, z2, blocks[0], w);
} else {
for (int x = x1; x < x2; x++) {
for (int z = z1; z < z2; z++) {
for (int y = y1; y < y2; y++) {
int i = random(blocks.length);
if (blocks[i].data != 0) {
setBlock(w, x, y, z, blocks[i].id, blocks[i].data);
}
}
}
}
}
public final int random(int n) {
long result = ((nextLong() >>> 32) * n) >> 32;
return (int) result;
}
}
public void setCuboidRegion(int x1, int x2, int y1, int y2, int z1, int z2,
PlotBlock block, World w) {
if (block.data == 0) {
return;
}
for (int x = x1; x < x2; x++) {
for (int z = z1; z < z2; z++) {
for (int y = y1; y < y2; y++) {
setBlock(w, x, y, z, block.id, block.data);
}
}
}
}
public short[] getBlock(String block) {
if (block.contains(":")) {
String[] split = block.split(":");
return new short[] { Short.parseShort(split[0]), Short.parseShort(split[1]) };
}
return new short[] { Short.parseShort(block), 0 };
}
private void setCuboidRegion(int x1, int x2, int y1, int y2, int z1,
int z2, PlotBlock[] blocks, World w) {
if (blocks.length == 1) {
setCuboidRegion(x1, x2, y1, y2, z1, z2, blocks[0], w);
} else {
for (int x = x1; x < x2; x++) {
for (int z = z1; z < z2; z++) {
for (int y = y1; y < y2; y++) {
int i = random(blocks.length);
if (blocks[i].data != 0) {
setBlock(w, x, y, z, blocks[i].id, blocks[i].data);
}
}
}
}
}
int plotsize;
int pathsize;
PlotBlock wall;
PlotBlock wallfilling;
PlotBlock floor1;
PlotBlock floor2;
int size;
Biome biome;
int roadheight;
int wallheight;
int plotheight;
PlotBlock[] plotfloors;
PlotBlock[] filling;
}
private double pathWidthLower;
private DefaultPlotWorld plotworld;
public short[] getBlock(String block) {
if (block.contains(":")) {
String[] split = block.split(":");
return new short[] { Short.parseShort(split[0]),
Short.parseShort(split[1]) };
}
return new short[] { Short.parseShort(block), 0 };
}
public XPopulator(PlotWorld pw) {
this.plotworld = (DefaultPlotWorld) pw;
int plotsize;
int pathsize;
PlotBlock wall;
PlotBlock wallfilling;
PlotBlock floor1;
PlotBlock floor2;
int size;
Biome biome;
int roadheight;
int wallheight;
int plotheight;
PlotBlock[] plotfloors;
PlotBlock[] filling;
// save configuration
private double pathWidthLower;
private DefaultPlotWorld plotworld;
plotsize = plotworld.PLOT_WIDTH;
pathsize = plotworld.ROAD_WIDTH;
public XPopulator(PlotWorld pw) {
this.plotworld = (DefaultPlotWorld) pw;
floor1 = plotworld.ROAD_BLOCK;
floor2 = plotworld.ROAD_STRIPES;
wallfilling = plotworld.WALL_FILLING;
size = pathsize + plotsize;
wall = plotworld.WALL_BLOCK;
// save configuration
plotfloors = plotworld.TOP_BLOCK;
filling = plotworld.MAIN_BLOCK;
wallheight = plotworld.WALL_HEIGHT;
roadheight = plotworld.ROAD_HEIGHT;
plotheight = plotworld.PLOT_HEIGHT;
this.plotsize = this.plotworld.PLOT_WIDTH;
this.pathsize = this.plotworld.ROAD_WIDTH;
if ((this.pathsize % 2) == 0) {
this.pathWidthLower = Math.floor(this.pathsize / 2) - 1;
} else {
this.pathWidthLower = Math.floor(this.pathsize / 2);
}
}
this.floor1 = this.plotworld.ROAD_BLOCK;
this.floor2 = this.plotworld.ROAD_STRIPES;
@Override
public void populate(World w, Random r, Chunk c) {
int cx = c.getX(), cz = c.getZ();
this.wallfilling = this.plotworld.WALL_FILLING;
this.size = this.pathsize + this.plotsize;
this.wall = this.plotworld.WALL_BLOCK;
final int prime = 31;
int h = 1;
h = (prime * h) + cx;
h = (prime * h) + cz;
this.state = h;
this.plotfloors = this.plotworld.TOP_BLOCK;
this.filling = this.plotworld.MAIN_BLOCK;
this.X = cx << 4;
this.Z = cz << 4;
cx = (cx % this.size) + (8 * this.size);
cz = (cz % this.size) + (8 * this.size);
double absX = ((((cx * 16) + 16) - this.pathWidthLower - 1) + (8 * this.size)), absZ = ((((cz * 16) + 16) - this.pathWidthLower - 1) + (8 * this.size));
int plotMinX = (int) (((absX) % this.size));
int plotMinZ = (int) (((absZ) % this.size));
int roadStartX = (plotMinX + this.pathsize);
int roadStartZ = (plotMinZ + this.pathsize);
if (roadStartX >= this.size) {
roadStartX -= this.size;
}
if (roadStartZ >= this.size) {
roadStartZ -= this.size;
}
this.wallheight = this.plotworld.WALL_HEIGHT;
this.roadheight = this.plotworld.ROAD_HEIGHT;
this.plotheight = this.plotworld.PLOT_HEIGHT;
// ROADS
if ((this.pathsize % 2) == 0) {
this.pathWidthLower = Math.floor(this.pathsize / 2) - 1;
} else {
this.pathWidthLower = Math.floor(this.pathsize / 2);
}
}
if ((this.pathsize > 16) && ((plotMinX > roadStartX) || (plotMinZ > roadStartZ)) && !((roadStartX < 16) && (roadStartZ < 16)) && (((roadStartX > 16) && (roadStartZ > 16)) || ((plotMinX > roadStartX) && (plotMinZ > roadStartZ)))) {
setCuboidRegion(0, 16, 1, this.roadheight + 1, 0, 16, this.floor1, w);
return;
}
@Override
public void populate(World w, Random r, Chunk c) {
int cx = c.getX(), cz = c.getZ();
if (((plotMinZ + 1) <= 16) || ((roadStartZ <= 16) && (roadStartZ > 0))) {
int start = Math.max((16 - plotMinZ - this.pathsize) + 1, (16 - roadStartZ) + 1);
int end = Math.min(16 - plotMinZ - 1, (16 - roadStartZ) + this.pathsize);
if ((start >= 0) && (start <= 16) && (end < 0)) {
end = 16;
}
setCuboidRegion(0, 16, 1, this.roadheight + 1, Math.max(start, 0), Math.min(16, end), this.floor1, w);
}
if (((plotMinX + 1) <= 16) || ((roadStartX <= 16) && (roadStartX > 0))) {
int start = Math.max((16 - plotMinX - this.pathsize) + 1, (16 - roadStartX) + 1);
int end = Math.min(16 - plotMinX - 1, (16 - roadStartX) + this.pathsize);
if ((start >= 0) && (start <= 16) && (end < 0)) {
end = 16;
}
setCuboidRegion(Math.max(start, 0), Math.min(16, end), 1, this.roadheight + 1, 0, 16, this.floor1, w);
}
final int prime = 31;
int h = 1;
h = (prime * h) + cx;
h = (prime * h) + cz;
this.state = h;
// STRIPES
if ((this.pathsize > 4) && this.plotworld.ROAD_STRIPES_ENABLED) {
if ((plotMinZ + 2) <= 16) {
int value = (plotMinZ + 2);
int start, end;
if ((plotMinX + 2) <= 16) {
start = 16 - plotMinX - 1;
} else {
start = 16;
}
if ((roadStartX - 1) <= 16) {
end = (16 - roadStartX) + 1;
} else {
end = 0;
}
if (!(((plotMinX + 2) <= 16) || ((roadStartX - 1) <= 16))) {
start = 0;
}
setCuboidRegion(0, end, this.roadheight, this.roadheight + 1, 16 - value, (16 - value) + 1, this.floor2, w); //
setCuboidRegion(start, 16, this.roadheight, this.roadheight + 1, 16 - value, (16 - value) + 1, this.floor2, w); //
}
if ((plotMinX + 2) <= 16) {
int value = (plotMinX + 2);
int start, end;
if ((plotMinZ + 2) <= 16) {
start = 16 - plotMinZ - 1;
} else {
start = 16;
}
if ((roadStartZ - 1) <= 16) {
end = (16 - roadStartZ) + 1;
} else {
end = 0;
}
if (!(((plotMinZ + 2) <= 16) || ((roadStartZ - 1) <= 16))) {
start = 0;
}
setCuboidRegion(16 - value, (16 - value) + 1, this.roadheight, this.roadheight + 1, 0, end, this.floor2, w); //
setCuboidRegion(16 - value, (16 - value) + 1, this.roadheight, this.roadheight + 1, start, 16, this.floor2, w); //
}
if ((roadStartZ <= 16) && (roadStartZ > 1)) {
int val = roadStartZ;
int start, end;
if ((plotMinX + 2) <= 16) {
start = 16 - plotMinX - 1;
} else {
start = 16;
}
if ((roadStartX - 1) <= 16) {
end = (16 - roadStartX) + 1;
} else {
end = 0;
}
if (!(((plotMinX + 2) <= 16) || ((roadStartX - 1) <= 16))) {
start = 0;
}
setCuboidRegion(0, end, this.roadheight, this.roadheight + 1, (16 - val) + 1, (16 - val) + 2, this.floor2, w);
setCuboidRegion(start, 16, this.roadheight, this.roadheight + 1, (16 - val) + 1, (16 - val) + 2, this.floor2, w);
}
if ((roadStartX <= 16) && (roadStartX > 1)) {
int val = roadStartX;
int start, end;
if ((plotMinZ + 2) <= 16) {
start = 16 - plotMinZ - 1;
} else {
start = 16;
}
if ((roadStartZ - 1) <= 16) {
end = (16 - roadStartZ) + 1;
} else {
end = 0;
}
if (!(((plotMinZ + 2) <= 16) || ((roadStartZ - 1) <= 16))) {
start = 0;
}
setCuboidRegion((16 - val) + 1, (16 - val) + 2, this.roadheight, this.roadheight + 1, 0, end, this.floor2, w); //
setCuboidRegion((16 - val) + 1, (16 - val) + 2, this.roadheight, this.roadheight + 1, start, 16, this.floor2, w); //
}
}
// WALLS
if (this.pathsize > 0) {
if ((plotMinZ + 1) <= 16) {
int start, end;
if ((plotMinX + 2) <= 16) {
start = 16 - plotMinX - 1;
} else {
start = 16;
}
if ((roadStartX - 1) <= 16) {
end = (16 - roadStartX) + 1;
} else {
end = 0;
}
if (!(((plotMinX + 2) <= 16) || ((roadStartX - 1) <= 16))) {
start = 0;
}
setCuboidRegion(0, end, 1, this.wallheight + 1, 16 - plotMinZ - 1, 16 - plotMinZ, this.wallfilling, w);
setCuboidRegion(0, end, this.wallheight + 1, this.wallheight + 2, 16 - plotMinZ - 1, 16 - plotMinZ, this.wall, w);
setCuboidRegion(start, 16, 1, this.wallheight + 1, 16 - plotMinZ - 1, 16 - plotMinZ, this.wallfilling, w);
setCuboidRegion(start, 16, this.wallheight + 1, this.wallheight + 2, 16 - plotMinZ - 1, 16 - plotMinZ, this.wall, w);
}
if ((plotMinX + 1) <= 16) {
int start, end;
if ((plotMinZ + 2) <= 16) {
start = 16 - plotMinZ - 1;
} else {
start = 16;
}
if ((roadStartZ - 1) <= 16) {
end = (16 - roadStartZ) + 1;
} else {
end = 0;
}
if (!(((plotMinZ + 2) <= 16) || ((roadStartZ - 1) <= 16))) {
start = 0;
}
setCuboidRegion(16 - plotMinX - 1, 16 - plotMinX, 1, this.wallheight + 1, 0, end, this.wallfilling, w);
setCuboidRegion(16 - plotMinX - 1, 16 - plotMinX, this.wallheight + 1, this.wallheight + 2, 0, end, this.wall, w);
setCuboidRegion(16 - plotMinX - 1, 16 - plotMinX, 1, this.wallheight + 1, start, 16, this.wallfilling, w);
setCuboidRegion(16 - plotMinX - 1, 16 - plotMinX, this.wallheight + 1, this.wallheight + 2, start, 16, this.wall, w);
}
if ((roadStartZ <= 16) && (roadStartZ > 0)) {
int start, end;
if ((plotMinX + 1) <= 16) {
start = 16 - plotMinX;
} else {
start = 16;
}
if ((roadStartX + 1) <= 16) {
end = (16 - roadStartX) + 1;
} else {
end = 0;
}
if (!(((plotMinX + 1) <= 16) || (roadStartX <= 16))) {
start = 0;
}
setCuboidRegion(0, end, 1, this.wallheight + 1, 16 - roadStartZ, (16 - roadStartZ) + 1, this.wallfilling, w);
setCuboidRegion(0, end, this.wallheight + 1, this.wallheight + 2, 16 - roadStartZ, (16 - roadStartZ) + 1, this.wall, w);
setCuboidRegion(start, 16, 1, this.wallheight + 1, 16 - roadStartZ, (16 - roadStartZ) + 1, this.wallfilling, w);
setCuboidRegion(start, 16, this.wallheight + 1, this.wallheight + 2, 16 - roadStartZ, (16 - roadStartZ) + 1, this.wall, w);
}
if ((roadStartX <= 16) && (roadStartX > 0)) {
int start, end;
if ((plotMinZ + 1) <= 16) {
start = 16 - plotMinZ;
} else {
start = 16;
}
if ((roadStartZ + 1) <= 16) {
end = (16 - roadStartZ) + 1;
} else {
end = 0;
}
if (!(((plotMinZ + 1) <= 16) || ((roadStartZ + 1) <= 16))) {
start = 0;
}
setCuboidRegion(16 - roadStartX, (16 - roadStartX) + 1, 1, this.wallheight + 1, 0, end, this.wallfilling, w);
setCuboidRegion(16 - roadStartX, (16 - roadStartX) + 1, this.wallheight + 1, this.roadheight + 2, 0, end, this.wall, w);
setCuboidRegion(16 - roadStartX, (16 - roadStartX) + 1, 1, this.wallheight + 1, start, 16, this.wallfilling, w);
setCuboidRegion(16 - roadStartX, (16 - roadStartX) + 1, this.wallheight + 1, this.wallheight + 2, start, 16, this.wall, w);
}
}
this.X = cx << 4;
this.Z = cz << 4;
cx = (cx % this.size) + (8 * this.size);
cz = (cz % this.size) + (8 * this.size);
double absX = ((((cx * 16) + 16) - this.pathWidthLower - 1) + (8 * this.size)), absZ = ((((cz * 16) + 16)
- this.pathWidthLower - 1) + (8 * this.size));
int plotMinX = (int) (((absX) % this.size));
int plotMinZ = (int) (((absZ) % this.size));
int roadStartX = (plotMinX + this.pathsize);
int roadStartZ = (plotMinZ + this.pathsize);
if (roadStartX >= this.size) {
roadStartX -= this.size;
}
if (roadStartZ >= this.size) {
roadStartZ -= this.size;
}
// PLOT
// ROADS
if (this.plotsize > 16) {
if (roadStartX <= 16) {
if (roadStartZ <= 16) {
setCuboidRegion(0, 16 - roadStartX, 1, this.plotheight, 0, 16 - roadStartZ, this.filling, w);
setCuboidRegion(0, 16 - roadStartX, this.plotheight, this.plotheight + 1, 0, 16 - roadStartZ, this.plotfloors, w);
}
if (plotMinZ <= 16) {
setCuboidRegion(0, 16 - roadStartX, 1, this.plotheight, 16 - plotMinZ, 16, this.filling, w);
setCuboidRegion(0, 16 - roadStartX, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.plotfloors, w);
}
} else {
if (roadStartZ <= 16) {
if (plotMinX > 16) {
setCuboidRegion(0, 16, 1, this.plotheight, 0, 16 - roadStartZ, this.filling, w);
setCuboidRegion(0, 16, this.plotheight, this.plotheight + 1, 0, 16 - roadStartZ, this.plotfloors, w);
}
}
}
if (plotMinX <= 16) {
if (plotMinZ <= 16) {
setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 16 - plotMinZ, 16, this.filling, w);
setCuboidRegion(16 - plotMinX, 16, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.plotfloors, w);
} else {
int z = 16 - roadStartZ;
if (z < 0) {
z = 16;
}
setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 0, z, this.filling, w);
setCuboidRegion(16 - plotMinX, 16, this.plotheight, this.plotheight + 1, 0, z, this.plotfloors, w);
}
if (roadStartZ <= 16) {
setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 0, 16 - roadStartZ, this.filling, w);
setCuboidRegion(16 - plotMinX, 16, this.plotheight, this.plotheight + 1, 0, 16 - roadStartZ, this.plotfloors, w);
} else {
if (roadStartX <= 16) {
if (plotMinZ > 16) {
int x = 16 - roadStartX;
if (x < 0) {
x = 16;
}
setCuboidRegion(0, x, 1, this.plotheight, 0, 16, this.filling, w);
setCuboidRegion(0, x, this.plotheight, this.plotheight + 1, 0, 16, this.plotfloors, w);
}
}
}
} else {
if (plotMinZ <= 16) {
if (roadStartX > 16) {
int x = 16 - roadStartX;
if (x < 0) {
x = 16;
}
setCuboidRegion(0, x, 1, this.plotheight, 16 - plotMinZ, 16, this.filling, w);
setCuboidRegion(0, x, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.plotfloors, w);
}
} else {
if (roadStartZ > 16) {
int x = 16 - roadStartX;
if (x < 0) {
x = 16;
}
int z = 16 - roadStartZ;
if (z < 0) {
z = 16;
}
if (roadStartX > 16) {
setCuboidRegion(0, x, 1, this.plotheight, 0, z, this.filling, w);
setCuboidRegion(0, x, this.plotheight, this.plotheight + 1, 0, z, this.plotfloors, w);
} else {
setCuboidRegion(0, x, 1, this.plotheight, 0, z, this.filling, w);
setCuboidRegion(0, x, this.plotheight, this.plotheight + 1, 0, z, this.plotfloors, w);
}
}
}
}
} else {
if (roadStartX <= 16) {
if (roadStartZ <= 16) {
setCuboidRegion(0, 16 - roadStartX, 1, this.plotheight, 0, 16 - roadStartZ, this.filling, w);
setCuboidRegion(0, 16 - roadStartX, this.plotheight, this.plotheight + 1, 0, 16 - roadStartZ, this.plotfloors, w);
}
if (plotMinZ <= 16) {
setCuboidRegion(0, 16 - roadStartX, 1, this.plotheight, 16 - plotMinZ, 16, this.filling, w);
setCuboidRegion(0, 16 - roadStartX, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.plotfloors, w);
}
}
if (plotMinX <= 16) {
if (plotMinZ <= 16) {
setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 16 - plotMinZ, 16, this.filling, w);
setCuboidRegion(16 - plotMinX, 16, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.plotfloors, w);
}
if (roadStartZ <= 16) {
setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 0, 16 - roadStartZ, this.filling, w);
setCuboidRegion(16 - plotMinX, 16, this.plotheight, this.plotheight + 1, 0, 16 - roadStartZ, this.plotfloors, w);
}
}
}
}
if ((this.pathsize > 16)
&& ((plotMinX > roadStartX) || (plotMinZ > roadStartZ))
&& !((roadStartX < 16) && (roadStartZ < 16))
&& (((roadStartX > 16) && (roadStartZ > 16)) || ((plotMinX > roadStartX) && (plotMinZ > roadStartZ)))) {
setCuboidRegion(0, 16, 1, this.roadheight + 1, 0, 16, this.floor1,
w);
return;
}
private void setBlock(World w, int x, int y, int z, short id, byte val) {
w.getBlockAt(this.X + x, y, this.Z + z).setData(val, false);
}
if (((plotMinZ + 1) <= 16) || ((roadStartZ <= 16) && (roadStartZ > 0))) {
int start = Math.max((16 - plotMinZ - this.pathsize) + 1,
(16 - roadStartZ) + 1);
int end = Math.min(16 - plotMinZ - 1, (16 - roadStartZ)
+ this.pathsize);
if ((start >= 0) && (start <= 16) && (end < 0)) {
end = 16;
}
setCuboidRegion(0, 16, 1, this.roadheight + 1, Math.max(start, 0),
Math.min(16, end), this.floor1, w);
}
if (((plotMinX + 1) <= 16) || ((roadStartX <= 16) && (roadStartX > 0))) {
int start = Math.max((16 - plotMinX - this.pathsize) + 1,
(16 - roadStartX) + 1);
int end = Math.min(16 - plotMinX - 1, (16 - roadStartX)
+ this.pathsize);
if ((start >= 0) && (start <= 16) && (end < 0)) {
end = 16;
}
setCuboidRegion(Math.max(start, 0), Math.min(16, end), 1,
this.roadheight + 1, 0, 16, this.floor1, w);
}
// STRIPES
if ((this.pathsize > 4) && this.plotworld.ROAD_STRIPES_ENABLED) {
if ((plotMinZ + 2) <= 16) {
int value = (plotMinZ + 2);
int start, end;
if ((plotMinX + 2) <= 16) {
start = 16 - plotMinX - 1;
} else {
start = 16;
}
if ((roadStartX - 1) <= 16) {
end = (16 - roadStartX) + 1;
} else {
end = 0;
}
if (!(((plotMinX + 2) <= 16) || ((roadStartX - 1) <= 16))) {
start = 0;
}
setCuboidRegion(0, end, this.roadheight, this.roadheight + 1,
16 - value, (16 - value) + 1, this.floor2, w); //
setCuboidRegion(start, 16, this.roadheight,
this.roadheight + 1, 16 - value, (16 - value) + 1,
this.floor2, w); //
}
if ((plotMinX + 2) <= 16) {
int value = (plotMinX + 2);
int start, end;
if ((plotMinZ + 2) <= 16) {
start = 16 - plotMinZ - 1;
} else {
start = 16;
}
if ((roadStartZ - 1) <= 16) {
end = (16 - roadStartZ) + 1;
} else {
end = 0;
}
if (!(((plotMinZ + 2) <= 16) || ((roadStartZ - 1) <= 16))) {
start = 0;
}
setCuboidRegion(16 - value, (16 - value) + 1, this.roadheight,
this.roadheight + 1, 0, end, this.floor2, w); //
setCuboidRegion(16 - value, (16 - value) + 1, this.roadheight,
this.roadheight + 1, start, 16, this.floor2, w); //
}
if ((roadStartZ <= 16) && (roadStartZ > 1)) {
int val = roadStartZ;
int start, end;
if ((plotMinX + 2) <= 16) {
start = 16 - plotMinX - 1;
} else {
start = 16;
}
if ((roadStartX - 1) <= 16) {
end = (16 - roadStartX) + 1;
} else {
end = 0;
}
if (!(((plotMinX + 2) <= 16) || ((roadStartX - 1) <= 16))) {
start = 0;
}
setCuboidRegion(0, end, this.roadheight, this.roadheight + 1,
(16 - val) + 1, (16 - val) + 2, this.floor2, w);
setCuboidRegion(start, 16, this.roadheight,
this.roadheight + 1, (16 - val) + 1, (16 - val) + 2,
this.floor2, w);
}
if ((roadStartX <= 16) && (roadStartX > 1)) {
int val = roadStartX;
int start, end;
if ((plotMinZ + 2) <= 16) {
start = 16 - plotMinZ - 1;
} else {
start = 16;
}
if ((roadStartZ - 1) <= 16) {
end = (16 - roadStartZ) + 1;
} else {
end = 0;
}
if (!(((plotMinZ + 2) <= 16) || ((roadStartZ - 1) <= 16))) {
start = 0;
}
setCuboidRegion((16 - val) + 1, (16 - val) + 2,
this.roadheight, this.roadheight + 1, 0, end,
this.floor2, w); //
setCuboidRegion((16 - val) + 1, (16 - val) + 2,
this.roadheight, this.roadheight + 1, start, 16,
this.floor2, w); //
}
}
// WALLS
if (this.pathsize > 0) {
if ((plotMinZ + 1) <= 16) {
int start, end;
if ((plotMinX + 2) <= 16) {
start = 16 - plotMinX - 1;
} else {
start = 16;
}
if ((roadStartX - 1) <= 16) {
end = (16 - roadStartX) + 1;
} else {
end = 0;
}
if (!(((plotMinX + 2) <= 16) || ((roadStartX - 1) <= 16))) {
start = 0;
}
setCuboidRegion(0, end, 1, this.wallheight + 1,
16 - plotMinZ - 1, 16 - plotMinZ, this.wallfilling, w);
setCuboidRegion(0, end, this.wallheight + 1,
this.wallheight + 2, 16 - plotMinZ - 1, 16 - plotMinZ,
this.wall, w);
setCuboidRegion(start, 16, 1, this.wallheight + 1,
16 - plotMinZ - 1, 16 - plotMinZ, this.wallfilling, w);
setCuboidRegion(start, 16, this.wallheight + 1,
this.wallheight + 2, 16 - plotMinZ - 1, 16 - plotMinZ,
this.wall, w);
}
if ((plotMinX + 1) <= 16) {
int start, end;
if ((plotMinZ + 2) <= 16) {
start = 16 - plotMinZ - 1;
} else {
start = 16;
}
if ((roadStartZ - 1) <= 16) {
end = (16 - roadStartZ) + 1;
} else {
end = 0;
}
if (!(((plotMinZ + 2) <= 16) || ((roadStartZ - 1) <= 16))) {
start = 0;
}
setCuboidRegion(16 - plotMinX - 1, 16 - plotMinX, 1,
this.wallheight + 1, 0, end, this.wallfilling, w);
setCuboidRegion(16 - plotMinX - 1, 16 - plotMinX,
this.wallheight + 1, this.wallheight + 2, 0, end,
this.wall, w);
setCuboidRegion(16 - plotMinX - 1, 16 - plotMinX, 1,
this.wallheight + 1, start, 16, this.wallfilling, w);
setCuboidRegion(16 - plotMinX - 1, 16 - plotMinX,
this.wallheight + 1, this.wallheight + 2, start, 16,
this.wall, w);
}
if ((roadStartZ <= 16) && (roadStartZ > 0)) {
int start, end;
if ((plotMinX + 1) <= 16) {
start = 16 - plotMinX;
} else {
start = 16;
}
if ((roadStartX + 1) <= 16) {
end = (16 - roadStartX) + 1;
} else {
end = 0;
}
if (!(((plotMinX + 1) <= 16) || (roadStartX <= 16))) {
start = 0;
}
setCuboidRegion(0, end, 1, this.wallheight + 1,
16 - roadStartZ, (16 - roadStartZ) + 1,
this.wallfilling, w);
setCuboidRegion(0, end, this.wallheight + 1,
this.wallheight + 2, 16 - roadStartZ,
(16 - roadStartZ) + 1, this.wall, w);
setCuboidRegion(start, 16, 1, this.wallheight + 1,
16 - roadStartZ, (16 - roadStartZ) + 1,
this.wallfilling, w);
setCuboidRegion(start, 16, this.wallheight + 1,
this.wallheight + 2, 16 - roadStartZ,
(16 - roadStartZ) + 1, this.wall, w);
}
if ((roadStartX <= 16) && (roadStartX > 0)) {
int start, end;
if ((plotMinZ + 1) <= 16) {
start = 16 - plotMinZ;
} else {
start = 16;
}
if ((roadStartZ + 1) <= 16) {
end = (16 - roadStartZ) + 1;
} else {
end = 0;
}
if (!(((plotMinZ + 1) <= 16) || ((roadStartZ + 1) <= 16))) {
start = 0;
}
setCuboidRegion(16 - roadStartX, (16 - roadStartX) + 1, 1,
this.wallheight + 1, 0, end, this.wallfilling, w);
setCuboidRegion(16 - roadStartX, (16 - roadStartX) + 1,
this.wallheight + 1, this.roadheight + 2, 0, end,
this.wall, w);
setCuboidRegion(16 - roadStartX, (16 - roadStartX) + 1, 1,
this.wallheight + 1, start, 16, this.wallfilling, w);
setCuboidRegion(16 - roadStartX, (16 - roadStartX) + 1,
this.wallheight + 1, this.wallheight + 2, start, 16,
this.wall, w);
}
}
// PLOT
if (this.plotsize > 16) {
if (roadStartX <= 16) {
if (roadStartZ <= 16) {
setCuboidRegion(0, 16 - roadStartX, 1, this.plotheight, 0,
16 - roadStartZ, this.filling, w);
setCuboidRegion(0, 16 - roadStartX, this.plotheight,
this.plotheight + 1, 0, 16 - roadStartZ,
this.plotfloors, w);
}
if (plotMinZ <= 16) {
setCuboidRegion(0, 16 - roadStartX, 1, this.plotheight,
16 - plotMinZ, 16, this.filling, w);
setCuboidRegion(0, 16 - roadStartX, this.plotheight,
this.plotheight + 1, 16 - plotMinZ, 16,
this.plotfloors, w);
}
} else {
if (roadStartZ <= 16) {
if (plotMinX > 16) {
setCuboidRegion(0, 16, 1, this.plotheight, 0,
16 - roadStartZ, this.filling, w);
setCuboidRegion(0, 16, this.plotheight,
this.plotheight + 1, 0, 16 - roadStartZ,
this.plotfloors, w);
}
}
}
if (plotMinX <= 16) {
if (plotMinZ <= 16) {
setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight,
16 - plotMinZ, 16, this.filling, w);
setCuboidRegion(16 - plotMinX, 16, this.plotheight,
this.plotheight + 1, 16 - plotMinZ, 16,
this.plotfloors, w);
} else {
int z = 16 - roadStartZ;
if (z < 0) {
z = 16;
}
setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 0,
z, this.filling, w);
setCuboidRegion(16 - plotMinX, 16, this.plotheight,
this.plotheight + 1, 0, z, this.plotfloors, w);
}
if (roadStartZ <= 16) {
setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 0,
16 - roadStartZ, this.filling, w);
setCuboidRegion(16 - plotMinX, 16, this.plotheight,
this.plotheight + 1, 0, 16 - roadStartZ,
this.plotfloors, w);
} else {
if (roadStartX <= 16) {
if (plotMinZ > 16) {
int x = 16 - roadStartX;
if (x < 0) {
x = 16;
}
setCuboidRegion(0, x, 1, this.plotheight, 0, 16,
this.filling, w);
setCuboidRegion(0, x, this.plotheight,
this.plotheight + 1, 0, 16,
this.plotfloors, w);
}
}
}
} else {
if (plotMinZ <= 16) {
if (roadStartX > 16) {
int x = 16 - roadStartX;
if (x < 0) {
x = 16;
}
setCuboidRegion(0, x, 1, this.plotheight,
16 - plotMinZ, 16, this.filling, w);
setCuboidRegion(0, x, this.plotheight,
this.plotheight + 1, 16 - plotMinZ, 16,
this.plotfloors, w);
}
} else {
if (roadStartZ > 16) {
int x = 16 - roadStartX;
if (x < 0) {
x = 16;
}
int z = 16 - roadStartZ;
if (z < 0) {
z = 16;
}
if (roadStartX > 16) {
setCuboidRegion(0, x, 1, this.plotheight, 0, z,
this.filling, w);
setCuboidRegion(0, x, this.plotheight,
this.plotheight + 1, 0, z, this.plotfloors,
w);
} else {
setCuboidRegion(0, x, 1, this.plotheight, 0, z,
this.filling, w);
setCuboidRegion(0, x, this.plotheight,
this.plotheight + 1, 0, z, this.plotfloors,
w);
}
}
}
}
} else {
if (roadStartX <= 16) {
if (roadStartZ <= 16) {
setCuboidRegion(0, 16 - roadStartX, 1, this.plotheight, 0,
16 - roadStartZ, this.filling, w);
setCuboidRegion(0, 16 - roadStartX, this.plotheight,
this.plotheight + 1, 0, 16 - roadStartZ,
this.plotfloors, w);
}
if (plotMinZ <= 16) {
setCuboidRegion(0, 16 - roadStartX, 1, this.plotheight,
16 - plotMinZ, 16, this.filling, w);
setCuboidRegion(0, 16 - roadStartX, this.plotheight,
this.plotheight + 1, 16 - plotMinZ, 16,
this.plotfloors, w);
}
}
if (plotMinX <= 16) {
if (plotMinZ <= 16) {
setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight,
16 - plotMinZ, 16, this.filling, w);
setCuboidRegion(16 - plotMinX, 16, this.plotheight,
this.plotheight + 1, 16 - plotMinZ, 16,
this.plotfloors, w);
}
if (roadStartZ <= 16) {
setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 0,
16 - roadStartZ, this.filling, w);
setCuboidRegion(16 - plotMinX, 16, this.plotheight,
this.plotheight + 1, 0, 16 - roadStartZ,
this.plotfloors, w);
}
}
}
}
private void setBlock(World w, int x, int y, int z, short id, byte val) {
w.getBlockAt(this.X + x, y, this.Z + z).setData(val, false);
}
}

View File

@ -27,135 +27,146 @@ import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.database.DBFunc;
/**
*
*
* @author Citymonstret
*
*
*/
public class WorldEditListener implements Listener {
public final Set<String> blockedcmds = new HashSet<String>(Arrays.asList("/gmask", "//gmask", "/worldedit:gmask"));
public final Set<String> restrictedcmds = new HashSet<String>(Arrays.asList("/up", "//up", "/worldedit:up"));
public final Set<String> blockedcmds = new HashSet<String>(Arrays.asList(
"/gmask", "//gmask", "/worldedit:gmask"));
public final Set<String> restrictedcmds = new HashSet<String>(
Arrays.asList("/up", "//up", "/worldedit:up"));
private boolean isPlotWorld(Location l) {
return (PlotMain.isPlotWorld(l.getWorld()));
}
private boolean isPlotWorld(Location l) {
return (PlotMain.isPlotWorld(l.getWorld()));
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onInteract(PlayerInteractEvent e) {
Block b = e.getClickedBlock();
if (b == null) {
return;
}
Player p = e.getPlayer();
Location l = b.getLocation();
if (!isPlotWorld(l)) {
return;
}
p.getItemInHand();
if ((p.getItemInHand() == null) || (p.getItemInHand().getType() == Material.AIR)) {
return;
}
Plot plot = PlotHelper.getCurrentPlot(b.getLocation());
if (plot != null) {
if ((plot != null) && plot.hasOwner() && (plot.helpers != null) && (plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) {
PWE.setMask(p, l);
}
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onInteract(PlayerInteractEvent e) {
Block b = e.getClickedBlock();
if (b == null) {
return;
}
Player p = e.getPlayer();
Location l = b.getLocation();
if (!isPlotWorld(l)) {
return;
}
p.getItemInHand();
if ((p.getItemInHand() == null)
|| (p.getItemInHand().getType() == Material.AIR)) {
return;
}
Plot plot = PlotHelper.getCurrentPlot(b.getLocation());
if (plot != null) {
if ((plot != null)
&& plot.hasOwner()
&& (plot.helpers != null)
&& (plot.helpers.contains(DBFunc.everyone) || plot.helpers
.contains(p.getUniqueId()))) {
PWE.setMask(p, l);
}
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
Player p = e.getPlayer();
if (PlotMain.hasPermission(p, "plots.worldedit.bypass") || !PlotMain.isPlotWorld(p.getWorld())) {
return;
}
String cmd = e.getMessage().toLowerCase();
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
Player p = e.getPlayer();
if (PlotMain.hasPermission(p, "plots.worldedit.bypass")
|| !PlotMain.isPlotWorld(p.getWorld())) {
return;
}
String cmd = e.getMessage().toLowerCase();
if (cmd.contains(" ")) {
cmd = cmd.substring(0, cmd.indexOf(" "));
}
if (this.restrictedcmds.contains(cmd)) {
Plot plot = PlayerFunctions.getCurrentPlot(p);
if ((plot == null) || !(plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) {
e.setCancelled(true);
}
} else if (this.blockedcmds.contains(cmd)) {
e.setCancelled(true);
}
}
if (cmd.contains(" ")) {
cmd = cmd.substring(0, cmd.indexOf(" "));
}
if (this.restrictedcmds.contains(cmd)) {
Plot plot = PlayerFunctions.getCurrentPlot(p);
if ((plot == null)
|| !(plot.helpers.contains(DBFunc.everyone) || plot.helpers
.contains(p.getUniqueId()))) {
e.setCancelled(true);
}
} else if (this.blockedcmds.contains(cmd)) {
e.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerJoin(final PlayerJoinEvent e) {
Player p = e.getPlayer();
if (PlotMain.hasPermission(p, "plots.worldedit.bypass")) {
return;
}
Location l = p.getLocation();
if (isPlotWorld(l)) {
PWE.setMask(p, l);
} else {
PWE.removeMask(p);
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerJoin(final PlayerJoinEvent e) {
Player p = e.getPlayer();
if (PlotMain.hasPermission(p, "plots.worldedit.bypass")) {
return;
}
Location l = p.getLocation();
if (isPlotWorld(l)) {
PWE.setMask(p, l);
} else {
PWE.removeMask(p);
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerMove(final PlayerMoveEvent e) {
Location t = e.getTo();
if (!isPlotWorld(t)) {
return;
}
Location f = e.getFrom();
Player p = e.getPlayer();
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerMove(final PlayerMoveEvent e) {
Location t = e.getTo();
if (!isPlotWorld(t)) {
return;
}
Location f = e.getFrom();
Player p = e.getPlayer();
if ((f.getBlockX() != t.getBlockX()) || (f.getBlockZ() != t.getBlockZ())) {
PlotId idF = PlayerFunctions.getPlot(f);
PlotId idT = PlayerFunctions.getPlot(t);
if (PlotMain.hasPermission(e.getPlayer(), "plots.worldedit.bypass")) {
return;
}
if ((idT != null) && !(idF == idT)) {
PWE.setMask(p, t);
}
}
}
if ((f.getBlockX() != t.getBlockX())
|| (f.getBlockZ() != t.getBlockZ())) {
PlotId idF = PlayerFunctions.getPlot(f);
PlotId idT = PlayerFunctions.getPlot(t);
if (PlotMain.hasPermission(e.getPlayer(), "plots.worldedit.bypass")) {
return;
}
if ((idT != null) && !(idF == idT)) {
PWE.setMask(p, t);
}
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPortal(PlayerPortalEvent e) {
if (PlotMain.hasPermission(e.getPlayer(), "plots.worldedit.bypass")) {
return;
}
Player p = e.getPlayer();
Location t = e.getTo();
Location f = e.getFrom();
if (t==null) {
PWE.removeMask(p);
return;
}
if (isPlotWorld(t)) {
PWE.setMask(p, t);
return;
}
if (f!=null && isPlotWorld(f)) {
PWE.removeMask(p);
return;
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPortal(PlayerPortalEvent e) {
if (PlotMain.hasPermission(e.getPlayer(), "plots.worldedit.bypass")) {
return;
}
Player p = e.getPlayer();
Location t = e.getTo();
Location f = e.getFrom();
if (t == null) {
PWE.removeMask(p);
return;
}
if (isPlotWorld(t)) {
PWE.setMask(p, t);
return;
}
if (f != null && isPlotWorld(f)) {
PWE.removeMask(p);
return;
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTeleport(final PlayerTeleportEvent e) {
if (PlotMain.hasPermission(e.getPlayer(), "plots.worldedit.bypass")) {
return;
}
Player p = e.getPlayer();
Location t = e.getTo();
Location f = e.getFrom();
if (!isPlotWorld(t)) {
if (isPlotWorld(f)) {
PWE.removeMask(p);
} else {
return;
}
}
PWE.setMask(p, t);
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTeleport(final PlayerTeleportEvent e) {
if (PlotMain.hasPermission(e.getPlayer(), "plots.worldedit.bypass")) {
return;
}
Player p = e.getPlayer();
Location t = e.getTo();
Location f = e.getFrom();
if (!isPlotWorld(t)) {
if (isPlotWorld(f)) {
PWE.removeMask(p);
} else {
return;
}
}
PWE.setMask(p, t);
}
}

View File

@ -31,147 +31,165 @@ import com.sk89q.worldguard.protection.regions.ProtectedRegion;
* Created by Citymonstret on 2014-09-24.
*/
public class WorldGuardListener implements Listener {
public ArrayList<String> str_flags = new ArrayList<String>();
public ArrayList<Flag<?>> flags = new ArrayList<Flag<?>>();
public ArrayList<String> str_flags = new ArrayList<String>();
public ArrayList<Flag<?>> flags = new ArrayList<Flag<?>>();
public WorldGuardListener(PlotMain plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
for (Flag<?> flag : DefaultFlag.getFlags()) {
this.str_flags.add(flag.getName());
this.flags.add(flag);
}
}
public WorldGuardListener(PlotMain plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
for (Flag<?> flag : DefaultFlag.getFlags()) {
this.str_flags.add(flag.getName());
this.flags.add(flag);
}
}
public void removeFlag(Player requester, World world, Plot plot, String key) {
boolean op = requester.isOp();
requester.setOp(true);
try {
RegionManager manager = PlotMain.worldGuard.getRegionManager(world);
manager.getRegion(plot.id.x + "-" + plot.id.y);
for (Flag flag : this.flags) {
if (flag.getName().equalsIgnoreCase(key)) {
requester.performCommand("region flag " + (plot.id.x + "-" + plot.id.y) + " " + key);
}
}
} catch (Exception e) {
requester.setOp(op);
} finally {
requester.setOp(op);
}
}
public void removeFlag(Player requester, World world, Plot plot, String key) {
boolean op = requester.isOp();
requester.setOp(true);
try {
RegionManager manager = PlotMain.worldGuard.getRegionManager(world);
manager.getRegion(plot.id.x + "-" + plot.id.y);
for (Flag flag : this.flags) {
if (flag.getName().equalsIgnoreCase(key)) {
requester.performCommand("region flag "
+ (plot.id.x + "-" + plot.id.y) + " " + key);
}
}
} catch (Exception e) {
requester.setOp(op);
} finally {
requester.setOp(op);
}
}
public void addFlag(Player requester, World world, Plot plot, String key, String value) {
boolean op = requester.isOp();
requester.setOp(true);
try {
RegionManager manager = PlotMain.worldGuard.getRegionManager(world);
manager.getRegion(plot.id.x + "-" + plot.id.y);
for (Flag flag : this.flags) {
if (flag.getName().equalsIgnoreCase(key)) {
requester.performCommand("region flag " + (plot.id.x + "-" + plot.id.y) + " " + key + " " + value);
}
}
} catch (Exception e) {
requester.setOp(op);
} finally {
requester.setOp(op);
}
}
public void addFlag(Player requester, World world, Plot plot, String key,
String value) {
boolean op = requester.isOp();
requester.setOp(true);
try {
RegionManager manager = PlotMain.worldGuard.getRegionManager(world);
manager.getRegion(plot.id.x + "-" + plot.id.y);
for (Flag flag : this.flags) {
if (flag.getName().equalsIgnoreCase(key)) {
requester.performCommand("region flag "
+ (plot.id.x + "-" + plot.id.y) + " " + key + " "
+ value);
}
}
} catch (Exception e) {
requester.setOp(op);
} finally {
requester.setOp(op);
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMerge(PlotMergeEvent event) {
Plot main = event.getPlot();
ArrayList<PlotId> plots = event.getPlots();
World world = event.getWorld();
RegionManager manager = PlotMain.worldGuard.getRegionManager(world);
for (PlotId plot : plots) {
if (!plot.equals(main)) {
manager.removeRegion(plot.x + "-" + plot.y);
}
}
ProtectedRegion region = manager.getRegion(main.id.x + "-" + main.id.y);
DefaultDomain owner = region.getOwners();
Map<Flag<?>, Object> flags = region.getFlags();
DefaultDomain members = region.getMembers();
manager.removeRegion(main.id.x + "-" + main.id.y);
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMerge(PlotMergeEvent event) {
Plot main = event.getPlot();
ArrayList<PlotId> plots = event.getPlots();
World world = event.getWorld();
RegionManager manager = PlotMain.worldGuard.getRegionManager(world);
for (PlotId plot : plots) {
if (!plot.equals(main)) {
manager.removeRegion(plot.x + "-" + plot.y);
}
}
ProtectedRegion region = manager.getRegion(main.id.x + "-" + main.id.y);
DefaultDomain owner = region.getOwners();
Map<Flag<?>, Object> flags = region.getFlags();
DefaultDomain members = region.getMembers();
manager.removeRegion(main.id.x + "-" + main.id.y);
Location location1 = PlotHelper.getPlotBottomLocAbs(world, plots.get(0));
Location location2 = PlotHelper.getPlotTopLocAbs(world, plots.get(plots.size() - 1));
Location location1 = PlotHelper
.getPlotBottomLocAbs(world, plots.get(0));
Location location2 = PlotHelper.getPlotTopLocAbs(world,
plots.get(plots.size() - 1));
BlockVector vector1 = new BlockVector(location1.getBlockX(), 1, location1.getBlockZ());
BlockVector vector2 = new BlockVector(location2.getBlockX(), world.getMaxHeight(), location2.getBlockZ());
ProtectedRegion rg = new ProtectedCuboidRegion(main.id.x + "-" + main.id.y, vector1, vector2);
BlockVector vector1 = new BlockVector(location1.getBlockX(), 1,
location1.getBlockZ());
BlockVector vector2 = new BlockVector(location2.getBlockX(),
world.getMaxHeight(), location2.getBlockZ());
ProtectedRegion rg = new ProtectedCuboidRegion(main.id.x + "-"
+ main.id.y, vector1, vector2);
rg.setFlags(flags);
rg.setFlags(flags);
rg.setOwners(owner);
rg.setOwners(owner);
rg.setMembers(members);
rg.setMembers(members);
manager.addRegion(rg);
}
manager.addRegion(rg);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onUnlink(PlotUnlinkEvent event) {
World w = event.getWorld();
ArrayList<PlotId> plots = event.getPlots();
Plot main = PlotMain.getPlots(w).get(plots.get(0));
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onUnlink(PlotUnlinkEvent event) {
World w = event.getWorld();
ArrayList<PlotId> plots = event.getPlots();
Plot main = PlotMain.getPlots(w).get(plots.get(0));
RegionManager manager = PlotMain.worldGuard.getRegionManager(w);
ProtectedRegion region = manager.getRegion(main.id.x + "-" + main.id.y);
RegionManager manager = PlotMain.worldGuard.getRegionManager(w);
ProtectedRegion region = manager.getRegion(main.id.x + "-" + main.id.y);
DefaultDomain owner = region.getOwners();
Map<Flag<?>, Object> flags = region.getFlags();
DefaultDomain members = region.getMembers();
DefaultDomain owner = region.getOwners();
Map<Flag<?>, Object> flags = region.getFlags();
DefaultDomain members = region.getMembers();
manager.removeRegion(main.id.x + "-" + main.id.y);
for (int i = 1; i < plots.size(); i++) {
PlotId id = plots.get(i);
Location location1 = PlotHelper.getPlotBottomLocAbs(w, id);
Location location2 = PlotHelper.getPlotTopLocAbs(w, id);
manager.removeRegion(main.id.x + "-" + main.id.y);
for (int i = 1; i < plots.size(); i++) {
PlotId id = plots.get(i);
Location location1 = PlotHelper.getPlotBottomLocAbs(w, id);
Location location2 = PlotHelper.getPlotTopLocAbs(w, id);
BlockVector vector1 = new BlockVector(location1.getBlockX(), 1, location1.getBlockZ());
BlockVector vector2 = new BlockVector(location2.getBlockX(), w.getMaxHeight(), location2.getBlockZ());
ProtectedRegion rg = new ProtectedCuboidRegion(id.x + "-" + id.y, vector1, vector2);
BlockVector vector1 = new BlockVector(location1.getBlockX(), 1,
location1.getBlockZ());
BlockVector vector2 = new BlockVector(location2.getBlockX(),
w.getMaxHeight(), location2.getBlockZ());
ProtectedRegion rg = new ProtectedCuboidRegion(id.x + "-" + id.y,
vector1, vector2);
rg.setFlags(flags);
rg.setFlags(flags);
rg.setOwners(owner);
rg.setOwners(owner);
rg.setMembers(members);
rg.setMembers(members);
manager.addRegion(rg);
}
}
manager.addRegion(rg);
}
}
@EventHandler
public void onPlotClaim(PlayerClaimPlotEvent event) {
Player player = event.getPlayer();
Plot plot = event.getPlot();
RegionManager manager = PlotMain.worldGuard.getRegionManager(plot.getWorld());
@EventHandler
public void onPlotClaim(PlayerClaimPlotEvent event) {
Player player = event.getPlayer();
Plot plot = event.getPlot();
RegionManager manager = PlotMain.worldGuard.getRegionManager(plot
.getWorld());
Location location1 = PlotHelper.getPlotBottomLoc(plot.getWorld(), plot.getId());
Location location2 = PlotHelper.getPlotTopLoc(plot.getWorld(), plot.getId());
Location location1 = PlotHelper.getPlotBottomLoc(plot.getWorld(),
plot.getId());
Location location2 = PlotHelper.getPlotTopLoc(plot.getWorld(),
plot.getId());
BlockVector vector1 = new BlockVector(location1.getBlockX(), 1, location1.getBlockZ());
BlockVector vector2 = new BlockVector(location2.getBlockX(), plot.getWorld().getMaxHeight(), location2.getBlockZ());
BlockVector vector1 = new BlockVector(location1.getBlockX(), 1,
location1.getBlockZ());
BlockVector vector2 = new BlockVector(location2.getBlockX(), plot
.getWorld().getMaxHeight(), location2.getBlockZ());
ProtectedRegion region = new ProtectedCuboidRegion(plot.getId().x + "-" + plot.getId().y, vector1, vector2);
ProtectedRegion region = new ProtectedCuboidRegion(plot.getId().x + "-"
+ plot.getId().y, vector1, vector2);
DefaultDomain owner = new DefaultDomain();
owner.addPlayer(PlotMain.worldGuard.wrapPlayer(player));
DefaultDomain owner = new DefaultDomain();
owner.addPlayer(PlotMain.worldGuard.wrapPlayer(player));
region.setOwners(owner);
region.setOwners(owner);
manager.addRegion(region);
}
manager.addRegion(region);
}
@EventHandler
public void onPlotDelete(PlotDeleteEvent event) {
PlotId plot = event.getPlotId();
World world = Bukkit.getWorld(event.getWorld());
@EventHandler
public void onPlotDelete(PlotDeleteEvent event) {
PlotId plot = event.getPlotId();
World world = Bukkit.getWorld(event.getWorld());
RegionManager manager = PlotMain.worldGuard.getRegionManager(world);
manager.removeRegion(plot.x + "-" + plot.y);
}
RegionManager manager = PlotMain.worldGuard.getRegionManager(world);
manager.removeRegion(plot.x + "-" + plot.y);
}
}

View File

@ -15,39 +15,42 @@ import org.json.simple.parser.JSONParser;
import com.google.common.collect.ImmutableList;
/**
*
*
* @author
*
*
*/
public class NameFetcher implements Callable<Map<UUID, String>> {
private static final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/";
private final JSONParser jsonParser = new JSONParser();
private final List<UUID> uuids;
private static final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/";
private final JSONParser jsonParser = new JSONParser();
private final List<UUID> uuids;
public NameFetcher(List<UUID> uuids) {
this.uuids = ImmutableList.copyOf(uuids);
}
public NameFetcher(List<UUID> uuids) {
this.uuids = ImmutableList.copyOf(uuids);
}
@Override
public Map<UUID, String> call() throws Exception {
Map<UUID, String> uuidStringMap = new HashMap<UUID, String>();
for (UUID uuid : this.uuids) {
if (uuidStringMap.containsKey(uuid)) {
continue;
}
HttpURLConnection connection = (HttpURLConnection) new URL(PROFILE_URL + uuid.toString().replace("-", "")).openConnection();
JSONObject response = (JSONObject) this.jsonParser.parse(new InputStreamReader(connection.getInputStream()));
String name = (String) response.get("name");
if (name == null) {
continue;
}
String cause = (String) response.get("cause");
String errorMessage = (String) response.get("errorMessage");
if ((cause != null) && (cause.length() > 0)) {
throw new IllegalStateException(errorMessage);
}
uuidStringMap.put(uuid, name);
}
return uuidStringMap;
}
@Override
public Map<UUID, String> call() throws Exception {
Map<UUID, String> uuidStringMap = new HashMap<UUID, String>();
for (UUID uuid : this.uuids) {
if (uuidStringMap.containsKey(uuid)) {
continue;
}
HttpURLConnection connection = (HttpURLConnection) new URL(
PROFILE_URL + uuid.toString().replace("-", ""))
.openConnection();
JSONObject response = (JSONObject) this.jsonParser
.parse(new InputStreamReader(connection.getInputStream()));
String name = (String) response.get("name");
if (name == null) {
continue;
}
String cause = (String) response.get("cause");
String errorMessage = (String) response.get("errorMessage");
if ((cause != null) && (cause.length() > 0)) {
throw new IllegalStateException(errorMessage);
}
uuidStringMap.put(uuid, name);
}
return uuidStringMap;
}
}

View File

@ -22,84 +22,91 @@ import com.google.common.collect.ImmutableList;
* @author
*/
public class UUIDFetcher implements Callable<Map<String, UUID>> {
private static final double PROFILES_PER_REQUEST = 100;
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
private final JSONParser jsonParser = new JSONParser();
private final List<String> names;
private final boolean rateLimiting;
private static final double PROFILES_PER_REQUEST = 100;
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
private final JSONParser jsonParser = new JSONParser();
private final List<String> names;
private final boolean rateLimiting;
public UUIDFetcher(List<String> names, boolean rateLimiting) {
this.names = ImmutableList.copyOf(names);
this.rateLimiting = rateLimiting;
}
public UUIDFetcher(List<String> names, boolean rateLimiting) {
this.names = ImmutableList.copyOf(names);
this.rateLimiting = rateLimiting;
}
public UUIDFetcher(List<String> names) {
this(names, true);
}
public UUIDFetcher(List<String> names) {
this(names, true);
}
@Override
public Map<String, UUID> call() throws Exception {
Map<String, UUID> uuidMap = new HashMap<String, UUID>();
int requests = (int) Math.ceil(this.names.size() / PROFILES_PER_REQUEST);
for (int i = 0; i < requests; i++) {
HttpURLConnection connection = createConnection();
String body = JSONArray.toJSONString(this.names.subList(i * 100, Math.min((i + 1) * 100, this.names.size())));
writeBody(connection, body);
JSONArray array = (JSONArray) this.jsonParser.parse(new InputStreamReader(connection.getInputStream()));
for (Object profile : array) {
JSONObject jsonProfile = (JSONObject) profile;
String id = (String) jsonProfile.get("id");
String name = (String) jsonProfile.get("name");
UUID uuid = UUIDFetcher.getUUID(id);
uuidMap.put(name, uuid);
}
if (this.rateLimiting && (i != (requests - 1))) {
Thread.sleep(100L);
}
}
return uuidMap;
}
@Override
public Map<String, UUID> call() throws Exception {
Map<String, UUID> uuidMap = new HashMap<String, UUID>();
int requests = (int) Math
.ceil(this.names.size() / PROFILES_PER_REQUEST);
for (int i = 0; i < requests; i++) {
HttpURLConnection connection = createConnection();
String body = JSONArray.toJSONString(this.names.subList(i * 100,
Math.min((i + 1) * 100, this.names.size())));
writeBody(connection, body);
JSONArray array = (JSONArray) this.jsonParser
.parse(new InputStreamReader(connection.getInputStream()));
for (Object profile : array) {
JSONObject jsonProfile = (JSONObject) profile;
String id = (String) jsonProfile.get("id");
String name = (String) jsonProfile.get("name");
UUID uuid = UUIDFetcher.getUUID(id);
uuidMap.put(name, uuid);
}
if (this.rateLimiting && (i != (requests - 1))) {
Thread.sleep(100L);
}
}
return uuidMap;
}
private static void writeBody(HttpURLConnection connection, String body) throws Exception {
OutputStream stream = connection.getOutputStream();
stream.write(body.getBytes());
stream.flush();
stream.close();
}
private static void writeBody(HttpURLConnection connection, String body)
throws Exception {
OutputStream stream = connection.getOutputStream();
stream.write(body.getBytes());
stream.flush();
stream.close();
}
private static HttpURLConnection createConnection() throws Exception {
URL url = new URL(PROFILE_URL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
return connection;
}
private static HttpURLConnection createConnection() throws Exception {
URL url = new URL(PROFILE_URL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
return connection;
}
public static UUID getUUID(String id) {
return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id.substring(20, 32));
}
public static UUID getUUID(String id) {
return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12)
+ "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-"
+ id.substring(20, 32));
}
public static byte[] toBytes(UUID uuid) {
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
byteBuffer.putLong(uuid.getMostSignificantBits());
byteBuffer.putLong(uuid.getLeastSignificantBits());
return byteBuffer.array();
}
public static byte[] toBytes(UUID uuid) {
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
byteBuffer.putLong(uuid.getMostSignificantBits());
byteBuffer.putLong(uuid.getLeastSignificantBits());
return byteBuffer.array();
}
public static UUID fromBytes(byte[] array) {
if (array.length != 16) {
throw new IllegalArgumentException("Illegal byte array length: " + array.length);
}
ByteBuffer byteBuffer = ByteBuffer.wrap(array);
long mostSignificant = byteBuffer.getLong();
long leastSignificant = byteBuffer.getLong();
return new UUID(mostSignificant, leastSignificant);
}
public static UUID fromBytes(byte[] array) {
if (array.length != 16) {
throw new IllegalArgumentException("Illegal byte array length: "
+ array.length);
}
ByteBuffer byteBuffer = ByteBuffer.wrap(array);
long mostSignificant = byteBuffer.getLong();
long leastSignificant = byteBuffer.getLong();
return new UUID(mostSignificant, leastSignificant);
}
public static UUID getUUIDOf(String name) throws Exception {
return new UUIDFetcher(Arrays.asList(name)).call().get(name);
}
public static UUID getUUIDOf(String name) throws Exception {
return new UUIDFetcher(Arrays.asList(name)).call().get(name);
}
}

View File

@ -15,78 +15,89 @@ import org.simpleframework.http.core.Container;
*/
public class IndexHandler implements Container {
private JavaPlugin plugin;
private String title;
private JavaPlugin plugin;
private String title;
public IndexHandler(JavaPlugin plugin, String title) {
this.plugin = plugin;
this.title = title;
}
public IndexHandler(JavaPlugin plugin, String title) {
this.plugin = plugin;
this.title = title;
}
@Override
public void handle(Request request, Response response) {
try {
PrintStream body;
long time;
String coverage;
@Override
public void handle(Request request, Response response) {
try {
PrintStream body;
long time;
String coverage;
body = response.getPrintStream();
time = System.currentTimeMillis();
request.getQuery();
request.getPath();
body = response.getPrintStream();
time = System.currentTimeMillis();
request.getQuery();
request.getPath();
if ((request.getInteger("page")) < 0) {
}
if (((coverage = request.getTarget()) == null) || coverage.equals("/")) {
coverage = "index";
}
if ((request.getInteger("page")) < 0) {
}
if (((coverage = request.getTarget()) == null)
|| coverage.equals("/")) {
coverage = "index";
}
coverage = coverage.toLowerCase();
coverage = coverage.toLowerCase();
List<String> list = new ArrayList<>(Arrays.asList(new String[] { "install", "index", "stylesheet" }));
List<String> list = new ArrayList<>(Arrays.asList(new String[] {
"install", "index", "stylesheet" }));
if (!list.contains(coverage)) {
coverage = "index";
}
if (!list.contains(coverage)) {
coverage = "index";
}
if (coverage.equals("stylesheet")) {
response.setValue("Content-Type", "text/css");
response.setValue("Server", "PlotWeb/1.0 (Simple 5.0)");
response.setDate("Date", time);
response.setDate("Last-Modified", time);
if (coverage.equals("stylesheet")) {
response.setValue("Content-Type", "text/css");
response.setValue("Server", "PlotWeb/1.0 (Simple 5.0)");
response.setDate("Date", time);
response.setDate("Last-Modified", time);
ResourceHandler stylesheet = new ResourceHandler("stylesheet", ResourceHandler.FileType.CSS, this.plugin.getDataFolder());
ResourceHandler stylesheet = new ResourceHandler("stylesheet",
ResourceHandler.FileType.CSS,
this.plugin.getDataFolder());
String stylesheetHTML = stylesheet.getHTML();
String stylesheetHTML = stylesheet.getHTML();
stylesheet.done();
stylesheet.done();
body.print(stylesheetHTML);
} else {
response.setValue("Content-Type", "html");
response.setValue("Server", "PlotWeb/1.0 (Simple 5.0)");
response.setDate("Date", time);
response.setDate("Last-Modified", time);
body.print(stylesheetHTML);
} else {
response.setValue("Content-Type", "html");
response.setValue("Server", "PlotWeb/1.0 (Simple 5.0)");
response.setDate("Date", time);
response.setDate("Last-Modified", time);
ResourceHandler header = new ResourceHandler("header", ResourceHandler.FileType.HTML, this.plugin.getDataFolder());
ResourceHandler footer = new ResourceHandler("footer", ResourceHandler.FileType.HTML, this.plugin.getDataFolder());
ResourceHandler cPage = new ResourceHandler(coverage, ResourceHandler.FileType.HTML, this.plugin.getDataFolder());
ResourceHandler header = new ResourceHandler("header",
ResourceHandler.FileType.HTML,
this.plugin.getDataFolder());
ResourceHandler footer = new ResourceHandler("footer",
ResourceHandler.FileType.HTML,
this.plugin.getDataFolder());
ResourceHandler cPage = new ResourceHandler(coverage,
ResourceHandler.FileType.HTML,
this.plugin.getDataFolder());
String headerHTML = header.getHTML().replace("@title", this.title);
String footerHTML = footer.getHTML();
String cPageHTML = cPage.getHTML();
String headerHTML = header.getHTML().replace("@title",
this.title);
String footerHTML = footer.getHTML();
String cPageHTML = cPage.getHTML();
header.done();
footer.done();
cPage.done();
header.done();
footer.done();
cPage.done();
body.print(headerHTML);
body.print(cPageHTML);
body.print(footerHTML);
}
body.close();
} catch (Exception e) {
e.printStackTrace();
}
}
body.print(headerHTML);
body.print(cPageHTML);
body.print(footerHTML);
}
body.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -17,34 +17,35 @@ import com.intellectualcrafters.plot.PlotMain;
*/
public class PlotWeb {
// TODO instructions on how to setup and use PlotWeb.
// TODO instructions on how to setup and use PlotWeb.
public static PlotWeb PLOTWEB;
public static PlotWeb PLOTWEB;
private String title;
private int port;
private Server server;
private Connection connection;
private Container container;
private SocketAddress address;
private String title;
private int port;
private Server server;
private Connection connection;
private Container container;
private SocketAddress address;
public PlotWeb(String title, int port) {
this.title = title;
this.port = port;
}
public PlotWeb(String title, int port) {
this.title = title;
this.port = port;
}
public void start() throws Exception {
this.container = new IndexHandler(JavaPlugin.getPlugin(PlotMain.class), this.title);
this.server = new ContainerServer(this.container);
this.connection = new SocketConnection(this.server);
this.address = new InetSocketAddress(this.port);
public void start() throws Exception {
this.container = new IndexHandler(JavaPlugin.getPlugin(PlotMain.class),
this.title);
this.server = new ContainerServer(this.container);
this.connection = new SocketConnection(this.server);
this.address = new InetSocketAddress(this.port);
this.connection.connect(this.address);
PLOTWEB = this;
}
this.connection.connect(this.address);
PLOTWEB = this;
}
public void stop() throws Exception {
this.connection.close();
PLOTWEB = null;
}
public void stop() throws Exception {
this.connection.close();
PLOTWEB = null;
}
}

View File

@ -10,43 +10,49 @@ import java.io.InputStreamReader;
*/
public class ResourceHandler {
private File file;
private BufferedReader reader;
private File file;
private BufferedReader reader;
public ResourceHandler(String filePath, FileType fileType, File folder) throws Exception {
if (fileType == FileType.CSS) {
this.file = new File(folder.toPath().toString() + File.separator + "web" + File.separator + "css" + File.separator + filePath + "." + fileType.toString());
} else {
this.file = new File(folder.toPath().toString() + File.separator + "web" + File.separator + filePath + "." + fileType.toString());
}
}
public ResourceHandler(String filePath, FileType fileType, File folder)
throws Exception {
if (fileType == FileType.CSS) {
this.file = new File(folder.toPath().toString() + File.separator
+ "web" + File.separator + "css" + File.separator
+ filePath + "." + fileType.toString());
} else {
this.file = new File(folder.toPath().toString() + File.separator
+ "web" + File.separator + filePath + "."
+ fileType.toString());
}
}
public String getHTML() throws Exception {
StringBuilder html = new StringBuilder();
this.reader = new BufferedReader(new InputStreamReader(new FileInputStream(this.file)));
String line = "";
while ((line = this.reader.readLine()) != null) {
html.append(line);
}
return html.toString();
}
public String getHTML() throws Exception {
StringBuilder html = new StringBuilder();
this.reader = new BufferedReader(new InputStreamReader(
new FileInputStream(this.file)));
String line = "";
while ((line = this.reader.readLine()) != null) {
html.append(line);
}
return html.toString();
}
public void done() throws Exception {
this.reader.close();
}
public void done() throws Exception {
this.reader.close();
}
public static enum FileType {
CSS("css"), HTML("html"), JS("js");
public static enum FileType {
CSS("css"), HTML("html"), JS("js");
private String ext;
private String ext;
FileType(String ext) {
this.ext = ext;
}
FileType(String ext) {
this.ext = ext;
}
@Override
public String toString() {
return this.ext;
}
}
@Override
public String toString() {
return this.ext;
}
}
}

View File

@ -5,12 +5,12 @@ package com.intellectualsites.web;
*/
public class Test {
public static void main(String[] args) {
try {
new PlotWeb("Test", 9000).start();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
new PlotWeb("Test", 9000).start();
} catch (Exception e) {
e.printStackTrace();
}
}
}