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

203 lines
6.3 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-11-16 10:48:18 +01:00
package com.intellectualcrafters.plot.object;
2014-09-22 13:02:14 +02:00
2015-01-13 17:38:15 +01:00
import java.util.ArrayList;
import java.util.HashMap;
2015-04-06 14:16:24 +02:00
import java.util.List;
import java.util.UUID;
2015-01-08 15:08:17 +01:00
2015-01-13 17:38:15 +01:00
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
2015-04-05 16:59:56 +02:00
import com.intellectualcrafters.plot.object.comment.PlotComment;
2015-02-22 08:13:27 +01:00
import com.intellectualcrafters.plot.util.BlockManager;
2015-02-20 12:23:48 +01:00
import com.intellectualcrafters.plot.util.MainUtil;
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
*/
2015-02-20 07:34:19 +01:00
@SuppressWarnings("unused")
public class PlotSettings {
2014-11-21 23:45:46 +01:00
/**
* Plot
*/
2014-12-18 03:15:11 +01:00
private final Plot plot;
2014-11-05 04:42:08 +01:00
/**
* merged plots
*/
2015-02-20 07:34:19 +01:00
private boolean[] merged = new boolean[] { false, false, false, false };
2014-11-05 04:42:08 +01:00
/**
* plot alias
*/
2014-12-18 03:15:11 +01:00
private String alias;
2014-11-05 04:42:08 +01:00
/**
2014-11-16 10:48:18 +01:00
* Comments
2014-11-05 04:42:08 +01:00
*/
2015-04-06 14:16:24 +02:00
private List<PlotComment> comments = null;
/**
* The ratings for a plot
*/
public HashMap<UUID, Integer> ratings;
2014-11-05 04:42:08 +01:00
/**
2014-11-16 10:48:18 +01:00
* Flags
2014-11-05 04:42:08 +01:00
*/
public HashMap<String, Flag> flags;
2014-11-16 10:48:18 +01:00
/**
* Home Position
*/
private BlockLoc position;
2015-02-23 02:32:27 +01:00
2014-11-05 04:42:08 +01:00
/**
* Constructor
*
2014-12-18 03:15:11 +01:00
* @param plot object
2014-11-05 04:42:08 +01:00
*/
public PlotSettings(final Plot plot) {
this.alias = "";
this.plot = plot;
2015-07-04 08:37:33 +02:00
this.flags = new HashMap<>();
2014-11-05 04:42:08 +01:00
}
2015-02-23 02:32:27 +01:00
2014-11-05 04:42:08 +01:00
/**
2014-12-18 03:15:11 +01: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>
*
* @param direction Direction to check
2014-11-05 04:42:08 +01:00
*
2014-11-16 10:48:18 +01:00
* @return boolean merged
2014-11-05 04:42:08 +01:00
*/
public boolean getMerged(final int direction) {
return this.merged[direction];
}
2015-02-23 02:32:27 +01:00
2014-11-05 04:42:08 +01:00
/**
* 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]);
}
2015-02-23 02:32:27 +01:00
2014-11-05 04:42:08 +01:00
public boolean[] getMerged() {
return this.merged;
}
2015-02-23 02:32:27 +01:00
2014-11-05 04:42:08 +01:00
public void setMerged(final boolean[] merged) {
this.merged = merged;
}
2015-02-23 02:32:27 +01:00
2014-11-05 04:42:08 +01:00
public void setMerged(final int direction, final boolean merged) {
this.merged[direction] = merged;
}
2015-02-23 02:32:27 +01:00
2014-11-05 04:42:08 +01:00
/**
2014-11-09 19:27:46 +01:00
* @return biome at plot loc
2014-11-05 04:42:08 +01:00
*/
2015-02-22 08:13:27 +01:00
public String getBiome() {
2015-02-20 12:23:48 +01:00
final Location loc = MainUtil.getPlotBottomLoc(this.plot.world, this.plot.getId()).add(1, 0, 1);
2015-02-22 08:13:27 +01:00
return BlockManager.manager.getBiome(loc);
2014-11-05 04:42:08 +01:00
}
2015-02-23 02:32:27 +01:00
public BlockLoc getPosition() {
if (this.position == null) {
return new BlockLoc(0, 0, 0);
}
2014-11-05 04:42:08 +01:00
return this.position;
}
2015-02-23 02:32:27 +01:00
2015-02-20 07:34:19 +01:00
public void setPosition(final BlockLoc position) {
2014-11-05 04:42:08 +01:00
this.position = position;
}
2015-02-23 02:32:27 +01:00
2014-11-05 04:42:08 +01:00
public String getAlias() {
return this.alias;
}
2015-02-23 02:32:27 +01:00
/**
2014-11-16 10:48:18 +01:00
* Set the plot alias
*
2014-12-18 03:15:11 +01:00
* @param alias alias to be used
*/
public void setAlias(final String alias) {
this.alias = alias;
}
2015-02-23 02:32:27 +01:00
2014-11-05 04:42:08 +01:00
public String getJoinMessage() {
2015-02-20 07:34:19 +01:00
final Flag greeting = FlagManager.getPlotFlag(this.plot, "greeting");
2014-11-16 10:48:18 +01:00
if (greeting != null) {
return greeting.getValueString();
2014-11-16 10:48:18 +01:00
}
2014-11-05 04:42:08 +01:00
return "";
}
2015-02-23 02:32:27 +01:00
2014-11-16 10:48:18 +01:00
/**
* Get the "farewell" flag value
*
* @return Farewell flag
*/
2014-11-05 04:42:08 +01:00
public String getLeaveMessage() {
2015-02-20 07:34:19 +01:00
final Flag farewell = FlagManager.getPlotFlag(this.plot, "farewell");
2014-11-16 10:48:18 +01:00
if (farewell != null) {
return farewell.getValueString();
2014-11-16 10:48:18 +01:00
}
2014-11-05 04:42:08 +01:00
return "";
}
2015-02-23 02:32:27 +01:00
2015-04-06 11:59:22 +02:00
public ArrayList<PlotComment> getComments(final String inbox) {
2014-11-16 10:48:18 +01:00
final ArrayList<PlotComment> c = new ArrayList<>();
2015-01-11 17:25:33 +01:00
if (this.comments == null) {
2015-01-25 02:17:11 +01:00
return null;
2015-01-11 17:25:33 +01:00
}
2014-11-05 04:42:08 +01:00
for (final PlotComment comment : this.comments) {
2015-04-06 11:59:22 +02:00
if (comment.inbox.equals(inbox)) {
c.add(comment);
}
2014-11-05 04:42:08 +01:00
}
return c;
}
2015-02-23 02:32:27 +01:00
2015-04-06 14:16:24 +02:00
public void setComments(final List<PlotComment> comments) {
2014-11-05 04:42:08 +01:00
this.comments = comments;
}
2015-02-23 02:32:27 +01:00
2014-12-16 06:03:20 +01:00
public void removeComment(final PlotComment comment) {
2014-11-06 08:23:21 +01:00
if (this.comments.contains(comment)) {
this.comments.remove(comment);
}
}
2015-02-23 02:32:27 +01:00
2015-04-06 14:16:24 +02:00
public void removeComments(final List<PlotComment> comments) {
2014-12-16 06:03:20 +01:00
for (final PlotComment comment : comments) {
2014-11-06 08:23:21 +01:00
removeComment(comment);
}
}
2015-02-23 02:32:27 +01:00
2014-11-05 04:42:08 +01: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 04:42:08 +01:00
}
2014-09-22 13:02:14 +02:00
}