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.player.PlotPlayer; 023import com.plotsquared.core.util.task.RunnableVal2; 024import com.plotsquared.core.util.task.RunnableVal3; 025import net.kyori.adventure.text.Component; 026import net.kyori.adventure.text.minimessage.tag.Tag; 027import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; 028 029@CommandDeclaration(command = "toggle", 030 aliases = {"attribute"}, 031 permission = "plots.toggle", 032 usage = "/plot toggle <chat | chatspy | clear-confirmation | time | titles | worldedit>", 033 requiredType = RequiredType.NONE, 034 category = CommandCategory.SETTINGS) 035public class Toggle extends Command { 036 037 public Toggle() { 038 super(MainCommand.getInstance(), true); 039 } 040 041 @CommandDeclaration(command = "chatspy", 042 aliases = {"spy"}, 043 permission = "plots.admin.command.chatspy") 044 public void chatspy( 045 Command command, PlotPlayer<?> player, String[] args, 046 RunnableVal3<Command, Runnable, Runnable> confirm, 047 RunnableVal2<Command, CommandResult> whenDone 048 ) { 049 if (toggle(player, "chatspy")) { 050 player.sendMessage( 051 TranslatableCaption.of("toggle.toggle_disabled"), 052 TagResolver.resolver("setting", Tag.inserting(Component.text(command.toString()))) 053 ); 054 } else { 055 player.sendMessage( 056 TranslatableCaption.of("toggle.toggle_enabled"), 057 TagResolver.resolver("setting", Tag.inserting(Component.text(command.toString()))) 058 ); 059 } 060 } 061 062 @CommandDeclaration(command = "worldedit", 063 aliases = {"we", "wea"}, 064 permission = "plots.worldedit.bypass") 065 public void worldedit( 066 Command command, PlotPlayer<?> player, String[] args, 067 RunnableVal3<Command, Runnable, Runnable> confirm, 068 RunnableVal2<Command, CommandResult> whenDone 069 ) { 070 if (toggle(player, "worldedit")) { 071 player.sendMessage( 072 TranslatableCaption.of("toggle.toggle_disabled"), 073 TagResolver.resolver("setting", Tag.inserting(Component.text(command.toString()))) 074 ); 075 } else { 076 player.sendMessage( 077 TranslatableCaption.of("toggle.toggle_enabled"), 078 TagResolver.resolver("setting", Tag.inserting(Component.text(command.toString()))) 079 ); 080 } 081 } 082 083 @CommandDeclaration(command = "chat", 084 permission = "plots.toggle.chat") 085 public void chat( 086 Command command, PlotPlayer<?> player, String[] args, 087 RunnableVal3<Command, Runnable, Runnable> confirm, 088 RunnableVal2<Command, CommandResult> whenDone 089 ) { 090 if (toggle(player, "chat")) { 091 player.sendMessage( 092 TranslatableCaption.of("toggle.toggle_disabled"), 093 TagResolver.resolver("setting", Tag.inserting(Component.text(command.toString()))) 094 ); 095 } else { 096 player.sendMessage( 097 TranslatableCaption.of("toggle.toggle_enabled"), 098 TagResolver.resolver("setting", Tag.inserting(Component.text(command.toString()))) 099 ); 100 } 101 } 102 103 @CommandDeclaration(command = "clear-confirmation", 104 permission = "plots.admin.command.autoclear") 105 public void clearConfirmation( 106 Command command, PlotPlayer<?> player, String[] args, 107 RunnableVal3<Command, Runnable, Runnable> confirm, 108 RunnableVal2<Command, CommandResult> whenDone 109 ) { 110 if (toggle(player, "ignoreExpireTask")) { 111 player.sendMessage( 112 TranslatableCaption.of("toggle.toggle_enabled"), 113 TagResolver.resolver("setting", Tag.inserting(Component.text(command.toString()))) 114 ); 115 } else { 116 player.sendMessage( 117 TranslatableCaption.of("toggle.toggle_disabled"), 118 TagResolver.resolver("setting", Tag.inserting(Component.text(command.toString()))) 119 ); 120 } 121 } 122 123 @CommandDeclaration(command = "titles", 124 permission = "plots.toggle.titles") 125 public void titles( 126 Command command, PlotPlayer<?> player, String[] args, 127 RunnableVal3<Command, Runnable, Runnable> confirm, 128 RunnableVal2<Command, CommandResult> whenDone 129 ) { 130 if (toggle(player, "disabletitles")) { 131 player.sendMessage( 132 TranslatableCaption.of("toggle.toggle_enabled"), 133 TagResolver.resolver("setting", Tag.inserting(Component.text(command.toString()))) 134 ); 135 } else { 136 player.sendMessage( 137 TranslatableCaption.of("toggle.toggle_disabled"), 138 TagResolver.resolver("setting", Tag.inserting(Component.text(command.toString()))) 139 ); 140 } 141 } 142 143 @CommandDeclaration(command = "time", 144 permission = "plots.toggle.time") 145 public void time( 146 Command command, PlotPlayer<?> player, String[] args, 147 RunnableVal3<Command, Runnable, Runnable> confirm, 148 RunnableVal2<Command, CommandResult> whenDone 149 ) { 150 if (toggle(player, "disabletime")) { 151 player.sendMessage( 152 TranslatableCaption.of("toggle.toggle_enabled"), 153 TagResolver.resolver("setting", Tag.inserting(Component.text(command.toString()))) 154 ); 155 } else { 156 player.sendMessage( 157 TranslatableCaption.of("toggle.toggle_disabled"), 158 TagResolver.resolver("setting", Tag.inserting(Component.text(command.toString()))) 159 ); 160 } 161 } 162 163 @CommandDeclaration(command = "debug", 164 permission = "plots.toggle.debug") 165 public void debug( 166 Command command, PlotPlayer<?> player, String[] args, 167 RunnableVal3<Command, Runnable, Runnable> confirm, 168 RunnableVal2<Command, CommandResult> whenDone 169 ) { 170 if (toggle(player, "debug")) { 171 player.sendMessage( 172 TranslatableCaption.of("toggle.toggle_disabled"), 173 TagResolver.resolver("setting", Tag.inserting(Component.text(command.toString()))) 174 ); 175 } else { 176 player.sendMessage( 177 TranslatableCaption.of("toggle.toggle_enabled"), 178 TagResolver.resolver("setting", Tag.inserting(Component.text(command.toString()))) 179 ); 180 } 181 player.refreshDebug(); 182 } 183 184 public boolean toggle(PlotPlayer<?> player, String key) { 185 if (player.getAttribute(key)) { 186 player.removeAttribute(key); 187 return true; 188 } else { 189 player.setAttribute(key); 190 return false; 191 } 192 } 193 194}