TF-PlotSquared/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotSettings.java

243 lines
6.9 KiB
Java
Raw Normal View History

2014-11-08 20:27:09 +01:00
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
2014-09-22 13:02:14 +02:00
2014-11-16 10:48:18 +01:00
package com.intellectualcrafters.plot.object;
2014-09-22 13:02:14 +02:00
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
2014-12-16 16:03:20 +11:00
import org.bukkit.block.Biome;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.util.PlotHelper;
import com.sun.istack.internal.NotNull;
2014-09-22 13:02:14 +02:00
/**
* plot settings
*
2014-09-22 13:02:14 +02:00
* @author Citymonstret
2014-11-16 10:48:18 +01:00
* @author Empire92
2014-09-22 13:02:14 +02:00
*/
@SuppressWarnings("unused")
2014-09-22 13:02:14 +02:00
public class PlotSettings {
2014-11-21 23:45:46 +01:00
/**
* Plot
*/
2014-12-16 16:03:20 +11:00
private final Plot plot;
2014-11-05 14:42:08 +11:00
/**
* merged plots
*/
2014-12-16 16:03:20 +11:00
private boolean[] merged = new boolean[] { false, false, false, false };
2014-11-05 14:42:08 +11:00
/**
* plot alias
*/
2014-12-16 16:03:20 +11:00
private String alias;
2014-11-05 14:42:08 +11:00
/**
2014-11-16 10:48:18 +01:00
* Comments
2014-11-05 14:42:08 +11:00
*/
private ArrayList<PlotComment> comments = null;
/**
2014-11-16 10:48:18 +01:00
* Flags
2014-11-05 14:42:08 +11:00
*/
2014-12-16 16:03:20 +11:00
private Set<Flag> flags;
2014-11-16 10:48:18 +01:00
/**
* Home Position
*/
2014-12-16 16:03:20 +11:00
private PlotHomePosition position;
2014-11-16 10:48:18 +01:00
2014-11-05 14:42:08 +11:00
/**
* Constructor
*
2014-12-16 16:03:20 +11:00
* @param plot
* object
2014-11-05 14:42:08 +11:00
*/
public PlotSettings(final Plot plot) {
this.alias = "";
this.plot = plot;
2014-11-05 14:42:08 +11:00
}
/**
* <b>Check if the plot is merged in a direction</b><br>
* 0 = North<br>
* 1 = East<br>
* 2 = South<br>
* 3 = West<br>
*
2014-12-16 16:03:20 +11:00
* @param direction
* Direction to check
2014-11-16 10:48:18 +01:00
* @return boolean merged
2014-11-05 14:42:08 +11:00
*/
public boolean getMerged(final int direction) {
return this.merged[direction];
}
/**
* Returns true if the plot is merged (i.e. if it's a mega plot)
*/
public boolean isMerged() {
return (this.merged[0] || this.merged[1] || this.merged[2] || this.merged[3]);
}
public boolean[] getMerged() {
return this.merged;
}
public void setMerged(final boolean[] merged) {
this.merged = merged;
}
public void setMerged(final int direction, final boolean merged) {
this.merged[direction] = merged;
}
/**
2014-11-09 19:27:46 +01:00
* @return biome at plot loc
2014-11-05 14:42:08 +11:00
*/
public Biome getBiome() {
2014-12-16 16:03:20 +11:00
return PlotHelper.getPlotBottomLoc(this.plot.getWorld(), this.plot.getId()).add(1, 0, 1).getBlock().getBiome();
2014-11-05 14:42:08 +11:00
}
/**
2014-12-16 16:03:20 +11:00
* @param flag
* to add
2014-11-05 14:42:08 +11:00
*/
public void addFlag(final Flag flag) {
final Flag hasFlag = getFlag(flag.getKey());
if (hasFlag != null) {
this.flags.remove(hasFlag);
}
this.flags.add(flag);
}
/**
2014-11-16 10:48:18 +01:00
* Get all flags applied for the plot
*
* @return flags
2014-11-05 14:42:08 +11:00
*/
public Set<Flag> getFlags() {
return this.flags;
2014-11-05 14:42:08 +11:00
}
/**
* Set multiple flags
*
2014-12-16 16:03:20 +11:00
* @param flags
* Flag Array
2014-11-05 14:42:08 +11:00
*/
public void setFlags(@NotNull final Flag[] flags) {
this.flags = new HashSet<>(Arrays.asList(flags));
2014-11-05 14:42:08 +11:00
}
/**
* Get a flag
*
2014-12-16 16:03:20 +11:00
* @param flag
* Flag to get
* @return flag
2014-11-05 14:42:08 +11:00
*/
public Flag getFlag(final String flag) {
for (final Flag myflag : this.flags) {
if (myflag.getKey().equals(flag)) {
return myflag;
}
}
return null;
}
public PlotHomePosition getPosition() {
return this.position;
}
public void setPosition(final PlotHomePosition position) {
this.position = position;
}
public String getAlias() {
return this.alias;
}
/**
2014-11-16 10:48:18 +01:00
* Set the plot alias
*
2014-12-16 16:03:20 +11:00
* @param alias
* alias to be used
*/
public void setAlias(final String alias) {
this.alias = alias;
}
2014-11-05 14:42:08 +11:00
public String getJoinMessage() {
2014-12-16 16:03:20 +11:00
final Flag greeting = getFlag("greeting");
2014-11-16 10:48:18 +01:00
if (greeting != null) {
return greeting.getValue();
}
2014-11-05 14:42:08 +11:00
return "";
}
2014-11-16 10:48:18 +01:00
/**
* Get the "farewell" flag value
*
* @return Farewell flag
*/
2014-11-05 14:42:08 +11:00
public String getLeaveMessage() {
2014-12-16 16:03:20 +11:00
final Flag farewell = getFlag("farewell");
2014-11-16 10:48:18 +01:00
if (farewell != null) {
return farewell.getValue();
}
2014-11-05 14:42:08 +11:00
return "";
}
public ArrayList<PlotComment> getComments(final int tier) {
2014-11-16 10:48:18 +01:00
final ArrayList<PlotComment> c = new ArrayList<>();
2014-11-05 14:42:08 +11:00
for (final PlotComment comment : this.comments) {
if (comment.tier == tier) {
c.add(comment);
}
}
return c;
}
public void setComments(final ArrayList<PlotComment> comments) {
this.comments = comments;
}
2014-11-08 20:27:09 +01:00
2014-12-16 16:03:20 +11:00
public void removeComment(final PlotComment comment) {
2014-11-06 18:23:21 +11:00
if (this.comments.contains(comment)) {
this.comments.remove(comment);
}
}
2014-11-05 14:42:08 +11:00
2014-12-16 16:03:20 +11:00
public void removeComments(final ArrayList<PlotComment> comments) {
for (final PlotComment comment : comments) {
2014-11-06 18:23:21 +11:00
removeComment(comment);
}
}
2014-11-08 20:27:09 +01:00
2014-11-05 14:42:08 +11:00
public void addComment(final PlotComment comment) {
if (this.comments == null) {
2014-11-16 10:48:18 +01:00
this.comments = new ArrayList<>();
}
this.comments.add(comment);
2014-11-05 14:42:08 +11:00
}
2014-09-22 13:02:14 +02:00
}