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.command; 020 021import com.plotsquared.core.configuration.caption.TranslatableCaption; 022import com.plotsquared.core.location.BlockLoc; 023import com.plotsquared.core.location.Location; 024import com.plotsquared.core.player.PlotPlayer; 025import com.plotsquared.core.plot.Plot; 026import net.kyori.adventure.text.Component; 027import net.kyori.adventure.text.minimessage.tag.Tag; 028import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; 029 030@CommandDeclaration(command = "sethome", 031 permission = "plots.set.home", 032 usage = "/plot sethome [none]", 033 aliases = {"sh", "seth"}, 034 category = CommandCategory.SETTINGS, 035 requiredType = RequiredType.PLAYER) 036public class SetHome extends SetCommand { 037 038 @Override 039 public boolean set(PlotPlayer<?> player, Plot plot, String value) { 040 if (!plot.hasOwner()) { 041 player.sendMessage(TranslatableCaption.of("info.plot_unowned")); 042 return false; 043 } 044 switch (value.toLowerCase()) { 045 case "unset", "reset", "remove", "none" -> { 046 Plot base = plot.getBasePlot(false); 047 base.setHome(null); 048 player.sendMessage(TranslatableCaption.of("position.position_unset")); 049 return true; 050 } 051 case "" -> { 052 Plot base = plot.getBasePlot(false); 053 Location bottom = base.getBottomAbs(); 054 Location location = player.getLocationFull(); 055 BlockLoc rel = new BlockLoc( 056 location.getX() - bottom.getX(), 057 location.getY(), // y is absolute 058 location.getZ() - bottom.getZ(), 059 location.getYaw(), 060 location.getPitch() 061 ); 062 base.setHome(rel); 063 player.sendMessage(TranslatableCaption.of("position.position_set")); 064 return true; 065 } 066 default -> { 067 player.sendMessage( 068 TranslatableCaption.of("commandconfig.command_syntax"), 069 TagResolver.resolver("value", Tag.inserting(Component.text("Use /plot set home [none]"))) 070 ); 071 return false; 072 } 073 } 074 } 075 076}