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.util; 020 021import com.plotsquared.core.plot.PlotArea; 022import com.sk89q.worldedit.regions.CuboidRegion; 023import org.khelekore.prtree.MBRConverter; 024 025public class PlotAreaConverter implements MBRConverter<PlotArea> { 026 027 public static final int AXIS_X = 0; 028 public static final int AXIS_Y = 1; 029 public static final int AXIS_Z = 2; 030 031 @Override 032 public int getDimensions() { 033 return 3; 034 } 035 036 @Override 037 public double getMin(final int axis, final PlotArea area) { 038 final CuboidRegion region = area.getRegion(); 039 if (axis == AXIS_X) { 040 return region.getMinimumPoint().getX(); 041 } else if (axis == AXIS_Y) { 042 return region.getMinimumPoint().getY(); 043 } else if (axis == AXIS_Z) { 044 return region.getMinimumPoint().getZ(); 045 } else { 046 throw new IllegalArgumentException("Unknown axis: " + axis); 047 } 048 } 049 050 @Override 051 public double getMax(final int axis, final PlotArea area) { 052 final CuboidRegion region = area.getRegion(); 053 if (axis == AXIS_X) { 054 return region.getMaximumPoint().getX(); 055 } else if (axis == AXIS_Y) { 056 return region.getMaximumPoint().getY(); 057 } else if (axis == AXIS_Z) { 058 return region.getMaximumPoint().getZ(); 059 } else { 060 throw new IllegalArgumentException("Unknown axis: " + axis); 061 } 062 } 063 064}