001/* 002 * PlotSquared, a land and world management plugin for Minecraft. 003 * Copyright (C) IntellectualSites <https://intellectualsites.com> 004 * Copyright (C) IntellectualSites team and contributors 005 * 006 * This program is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 018 */ 019package com.plotsquared.core.plot; 020 021import com.google.common.collect.ImmutableList; 022import com.plotsquared.core.location.BlockLoc; 023import com.plotsquared.core.location.Direction; 024import com.plotsquared.core.plot.comment.PlotComment; 025 026import java.util.ArrayList; 027import java.util.Collections; 028import java.util.HashMap; 029import java.util.List; 030import java.util.Map; 031import java.util.UUID; 032 033/** 034 * Generic settings class. 035 * - Does not keep a reference to a parent class 036 * - Direct changes here will not occur in the db (Use the parent plot object for that) 037 */ 038public class PlotSettings { 039 040 /** 041 * Merged plots. 042 */ 043 private boolean[] merged = new boolean[]{false, false, false, false}; 044 /** 045 * Plot alias. 046 */ 047 private String alias = ""; 048 /** 049 * The ratings for a plot. 050 */ 051 private HashMap<UUID, Integer> ratings; 052 /** 053 * Plot comments. 054 */ 055 private List<PlotComment> comments = null; 056 /** 057 * Home Position. 058 */ 059 private BlockLoc position; 060 061 /** 062 * <b>Check if the plot is merged in a direction</b><br> 0 = North<br> 1 = East<br> 2 = South<br> 3 = West<br> 063 * 064 * @param direction Direction to check 065 * @return boolean merged 066 */ 067 public boolean getMerged(int direction) { 068 return this.merged[direction]; 069 } 070 071 public Map<UUID, Integer> getRatings() { 072 if (this.ratings == null) { 073 this.ratings = new HashMap<>(); 074 } 075 return this.ratings; 076 } 077 078 public void setRatings(HashMap<UUID, Integer> ratings) { 079 this.ratings = ratings; 080 } 081 082 public boolean setMerged(Direction direction, boolean merged) { 083 if (Direction.ALL == direction) { 084 throw new IllegalArgumentException("You cannot use Direction.ALL in this method!"); 085 } 086 if (this.merged[direction.getIndex()] != merged) { 087 this.merged[direction.getIndex()] = merged; 088 return true; 089 } 090 return false; 091 } 092 093 public BlockLoc getPosition() { 094 if (this.position == null) { 095 return BlockLoc.MINY; 096 } 097 return this.position; 098 } 099 100 public void setPosition(BlockLoc position) { 101 if (position != null && position.getX() == 0 && position.getY() == 0 102 && position.getZ() == 0) { 103 position = null; 104 } 105 this.position = position; 106 } 107 108 public List<PlotComment> getComments(String inbox) { 109 if (this.comments == null) { 110 return Collections.emptyList(); 111 } 112 113 return this.comments.stream().filter(comment -> comment.inbox().equals(inbox)) 114 .collect(ImmutableList.toImmutableList()); 115 } 116 117 boolean removeComment(PlotComment comment) { 118 if (this.comments == null) { 119 return false; 120 } 121 return this.comments.remove(comment); 122 } 123 124 void removeComments(List<PlotComment> comments) { 125 comments.forEach(this::removeComment); 126 } 127 128 void addComment(PlotComment comment) { 129 if (this.comments == null) { 130 this.comments = new ArrayList<>(); 131 } 132 this.comments.add(comment); 133 } 134 135 public boolean[] getMerged() { 136 return this.merged; 137 } 138 139 public void setMerged(boolean[] merged) { 140 this.merged = merged; 141 } 142 143 public String getAlias() { 144 return this.alias; 145 } 146 147 public void setAlias(String alias) { 148 this.alias = alias; 149 } 150 151 public void setComments(List<PlotComment> comments) { 152 this.comments = comments; 153 } 154 155}