2019-07-24 05:31:17 +02:00
/ *
* This file is part of GriefDefender , licensed under the MIT License ( MIT ) .
*
* Copyright ( c ) bloodmc
* Copyright ( c ) contributors
*
* Permission is hereby granted , free of charge , to any person obtaining a copy
* of this software and associated documentation files ( the " Software " ) , to deal
* in the Software without restriction , including without limitation the rights
* to use , copy , modify , merge , publish , distribute , sublicense , and / or sell
* copies of the Software , and to permit persons to whom the Software is
* furnished to do so , subject to the following conditions :
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software .
*
* THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR
* IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY ,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER
* LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM ,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE .
* /
package com.griefdefender.command ;
2019-08-23 22:49:00 +02:00
import java.time.Duration ;
import java.time.Instant ;
import java.time.ZonedDateTime ;
import java.time.temporal.ChronoUnit ;
import java.util.ArrayList ;
import java.util.Collections ;
import java.util.Comparator ;
import java.util.HashSet ;
import java.util.Iterator ;
import java.util.List ;
import java.util.Map ;
import java.util.Set ;
import java.util.UUID ;
import java.util.function.Consumer ;
import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
import org.bukkit.Bukkit ;
import org.bukkit.Location ;
import org.bukkit.World.Environment ;
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Player ;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause ;
import org.bukkit.plugin.Plugin ;
2019-07-24 05:31:17 +02:00
import com.flowpowered.math.vector.Vector3i ;
import com.google.common.collect.ImmutableMap ;
2019-08-23 22:49:00 +02:00
import com.google.common.reflect.TypeToken ;
2019-07-24 05:31:17 +02:00
import com.google.gson.Gson ;
import com.griefdefender.GDPlayerData ;
import com.griefdefender.GriefDefenderPlugin ;
2019-08-23 22:49:00 +02:00
import com.griefdefender.api.GriefDefender ;
import com.griefdefender.api.Subject ;
2019-07-24 05:31:17 +02:00
import com.griefdefender.api.Tristate ;
import com.griefdefender.api.claim.Claim ;
import com.griefdefender.api.claim.ClaimContexts ;
2019-07-30 22:53:58 +02:00
import com.griefdefender.api.claim.ClaimResult ;
2019-07-24 05:31:17 +02:00
import com.griefdefender.api.claim.TrustType ;
import com.griefdefender.api.claim.TrustTypes ;
2020-06-06 01:26:14 +02:00
import com.griefdefender.api.economy.PaymentTransaction ;
import com.griefdefender.api.economy.PaymentType ;
import com.griefdefender.api.economy.TransactionResultType ;
import com.griefdefender.api.economy.TransactionType ;
2019-07-24 05:31:17 +02:00
import com.griefdefender.api.permission.Context ;
2020-06-06 01:26:14 +02:00
import com.griefdefender.api.permission.ContextKeys ;
2019-07-24 05:31:17 +02:00
import com.griefdefender.api.permission.PermissionResult ;
import com.griefdefender.api.permission.ResultTypes ;
import com.griefdefender.api.permission.flag.Flag ;
import com.griefdefender.api.permission.flag.Flags ;
2019-08-23 22:49:00 +02:00
import com.griefdefender.api.permission.option.Option ;
2019-07-24 05:31:17 +02:00
import com.griefdefender.api.permission.option.Options ;
2019-08-23 22:49:00 +02:00
import com.griefdefender.api.permission.option.type.CreateModeTypes ;
2019-07-30 22:53:58 +02:00
import com.griefdefender.cache.MessageCache ;
2019-07-24 05:31:17 +02:00
import com.griefdefender.cache.PermissionHolderCache ;
import com.griefdefender.claim.GDClaim ;
import com.griefdefender.configuration.GriefDefenderConfig ;
2019-07-27 07:30:09 +02:00
import com.griefdefender.configuration.MessageStorage ;
2020-06-06 01:26:14 +02:00
import com.griefdefender.economy.GDPaymentTransaction ;
2019-08-23 22:49:00 +02:00
import com.griefdefender.event.GDCauseStackManager ;
2019-07-24 05:31:17 +02:00
import com.griefdefender.internal.pagination.PaginationList ;
import com.griefdefender.internal.registry.BlockTypeRegistryModule ;
import com.griefdefender.internal.registry.EntityTypeRegistryModule ;
import com.griefdefender.internal.registry.ItemTypeRegistryModule ;
import com.griefdefender.internal.util.NMSUtil ;
import com.griefdefender.internal.util.VecHelper ;
2020-06-06 01:26:14 +02:00
import com.griefdefender.internal.visual.GDClaimVisual ;
2019-07-24 05:31:17 +02:00
import com.griefdefender.permission.GDPermissionHolder ;
import com.griefdefender.permission.GDPermissionManager ;
import com.griefdefender.permission.GDPermissionResult ;
import com.griefdefender.permission.GDPermissionUser ;
import com.griefdefender.permission.GDPermissions ;
2019-08-23 22:49:00 +02:00
import com.griefdefender.permission.flag.GDFlag ;
import com.griefdefender.permission.ui.MenuType ;
import com.griefdefender.permission.ui.UIHelper ;
2019-07-24 05:31:17 +02:00
import com.griefdefender.text.action.GDCallbackHolder ;
2020-06-06 01:26:14 +02:00
import com.griefdefender.util.EconomyUtil ;
2019-07-24 05:31:17 +02:00
import com.griefdefender.util.PermissionUtil ;
2019-08-25 17:19:25 +02:00
import com.griefdefender.util.PlayerUtil ;
2019-07-24 05:31:17 +02:00
import com.griefdefender.util.TaskUtil ;
import net.kyori.text.Component ;
import net.kyori.text.TextComponent ;
import net.kyori.text.adapter.bukkit.TextAdapter ;
import net.kyori.text.event.ClickEvent ;
import net.kyori.text.event.HoverEvent ;
import net.kyori.text.format.TextColor ;
import net.kyori.text.format.TextDecoration ;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer ;
import net.kyori.text.serializer.plain.PlainComponentSerializer ;
import net.milkbowl.vault.economy.Economy ;
import net.milkbowl.vault.economy.EconomyResponse ;
public class CommandHelper {
public static Comparator < Component > PLAIN_COMPARATOR = ( text1 , text2 ) - > PlainComponentSerializer . INSTANCE . serialize ( text1 ) . compareTo ( PlainComponentSerializer . INSTANCE . serialize ( text2 ) ) ;
public static Player checkPlayer ( CommandSender source ) {
if ( source instanceof Player ) {
return ( ( Player ) source ) ;
} else {
return null ;
}
}
public static boolean validateFlagTarget ( Flag flag , String target ) {
if ( ! ( flag instanceof GDFlag ) ) {
return true ;
}
2019-12-31 00:25:55 +01:00
if ( flag = = Flags . BLOCK_BREAK | | flag = = Flags . BLOCK_PLACE | | flag = = Flags . COLLIDE_BLOCK ) {
2019-07-24 05:31:17 +02:00
if ( validateBlockTarget ( target ) | |
validateItemTarget ( target ) ) {
return true ;
}
return false ;
}
2019-12-31 00:25:55 +01:00
if ( flag = = Flags . ENTER_CLAIM | | flag = = Flags . EXIT_CLAIM | | flag = = Flags . ENTITY_RIDING | |
flag = = Flags . ENTITY_DAMAGE | | flag = = Flags . PORTAL_USE ) {
2019-07-24 05:31:17 +02:00
if ( validateEntityTarget ( target ) | |
validateBlockTarget ( target ) | |
validateItemTarget ( target ) ) {
return true ;
}
return false ;
}
2019-12-31 00:25:55 +01:00
if ( flag = = Flags . INTERACT_INVENTORY ) {
2019-08-23 22:49:00 +02:00
// Always return true due to custom inventories
return true ;
}
2019-12-31 00:25:55 +01:00
if ( flag = = Flags . LIQUID_FLOW | | flag = = Flags . INTERACT_BLOCK_PRIMARY
| | flag = = Flags . INTERACT_BLOCK_SECONDARY ) {
2019-07-24 05:31:17 +02:00
return validateBlockTarget ( target ) ;
}
2019-12-31 00:25:55 +01:00
if ( flag = = Flags . ENTITY_CHUNK_SPAWN | | flag = = Flags . ENTITY_SPAWN | |
flag = = Flags . INTERACT_ENTITY_PRIMARY | | flag = = Flags . INTERACT_ENTITY_SECONDARY ) {
2019-07-24 05:31:17 +02:00
return validateEntityTarget ( target ) ;
}
2019-12-31 00:25:55 +01:00
if ( flag = = Flags . ITEM_DROP | | flag = = Flags . ITEM_PICKUP | |
flag = = Flags . ITEM_SPAWN | | flag = = Flags . ITEM_USE ) {
2019-07-24 05:31:17 +02:00
return validateItemTarget ( target ) ;
}
return true ;
}
private static boolean validateEntityTarget ( String target ) {
if ( EntityTypeRegistryModule . getInstance ( ) . getById ( target ) . isPresent ( ) ) {
return true ;
}
return false ;
}
private static boolean validateItemTarget ( String target ) {
if ( ItemTypeRegistryModule . getInstance ( ) . getById ( target ) . isPresent ( ) ) {
return true ;
}
// target could be an item block, so validate blockstate
2019-08-23 22:49:00 +02:00
//if (BlockTypeRegistryModule.getInstance().getById(target).isPresent()) {
// return true;
//}
2019-07-24 05:31:17 +02:00
return false ;
}
private static boolean validateBlockTarget ( String target ) {
if ( BlockTypeRegistryModule . getInstance ( ) . getById ( target ) . isPresent ( ) ) {
return true ;
}
return false ;
}
2019-12-31 00:25:55 +01:00
public static PermissionResult addFlagPermission ( CommandSender src , GDPermissionHolder subject , Claim claim , Flag flag , String target , Tristate value , Set < Context > contexts ) {
2019-07-24 05:31:17 +02:00
if ( src instanceof Player ) {
Component denyReason = ( ( GDClaim ) claim ) . allowEdit ( ( Player ) src ) ;
if ( denyReason ! = null ) {
GriefDefenderPlugin . sendMessage ( src , denyReason ) ;
return new GDPermissionResult ( ResultTypes . NO_PERMISSION ) ;
}
2020-01-02 03:21:05 +01:00
if ( value = = null ) {
GriefDefenderPlugin . sendMessage ( src , MessageCache . getInstance ( ) . COMMAND_INVALID ) ;
return new GDPermissionResult ( ResultTypes . FAILURE ) ;
}
2019-07-24 05:31:17 +02:00
}
// special handling for commands
2019-12-31 00:25:55 +01:00
target = adjustTargetForTypes ( target , flag ) ;
if ( flag = = Flags . COMMAND_EXECUTE | | flag = = Flags . COMMAND_EXECUTE_PVP ) {
2019-07-24 05:31:17 +02:00
target = handleCommandFlag ( src , target ) ;
if ( target = = null ) {
// failed
return new GDPermissionResult ( ResultTypes . TARGET_NOT_VALID ) ;
}
} else {
if ( ! target . equalsIgnoreCase ( " any " ) ) {
2019-08-23 22:49:00 +02:00
if ( ! target . startsWith ( " # " ) & & ! target . contains ( " : " ) ) {
2019-07-24 05:31:17 +02:00
// assume vanilla
target = " minecraft: " + target ;
}
String [ ] parts = target . split ( " : " ) ;
2020-01-02 03:21:05 +01:00
if ( parts . length = = 1 ) {
addFlagContexts ( contexts , flag , target ) ;
} else if ( parts . length > 1 & & ! parts [ 1 ] . equalsIgnoreCase ( " any " ) ) {
2020-05-05 06:56:59 +02:00
addFlagContexts ( contexts , flag , target ) ;
if ( ! target . contains ( " # " ) & & ! CommandHelper . validateFlagTarget ( flag , target ) ) {
2019-07-24 05:31:17 +02:00
return new GDPermissionResult ( ResultTypes . TARGET_NOT_VALID ) ;
}
}
} else {
target = " " ;
}
}
2019-12-31 00:25:55 +01:00
return applyFlagPermission ( src , subject , claim , flag , target , value , contexts , null , false ) ;
2019-07-24 05:31:17 +02:00
}
2019-12-31 00:25:55 +01:00
public static PermissionResult applyFlagPermission ( CommandSender src , GDPermissionHolder subject , Claim claim , Flag flag , String target , Tristate value , Set < Context > contexts , MenuType flagType ) {
return applyFlagPermission ( src , subject , claim , flag , target , value , contexts , flagType , false ) ;
2019-07-24 05:31:17 +02:00
}
2019-12-31 00:25:55 +01:00
public static PermissionResult applyFlagPermission ( CommandSender src , GDPermissionHolder subject , Claim claim , Flag flag , String target , Tristate value , Set < Context > contexts , MenuType flagType , boolean clicked ) {
2019-07-24 05:31:17 +02:00
boolean hasDefaultContext = false ;
boolean hasOverrideContext = false ;
2020-06-06 01:26:14 +02:00
boolean replaceOverrideContext = false ;
2019-07-24 05:31:17 +02:00
Component reason = null ;
Iterator < Context > iterator = contexts . iterator ( ) ;
while ( iterator . hasNext ( ) ) {
final Context context = iterator . next ( ) ;
// validate perms
if ( context . getKey ( ) . equalsIgnoreCase ( " reason " ) ) {
reason = LegacyComponentSerializer . legacy ( ) . deserialize ( context . getValue ( ) , '&' ) ;
iterator . remove ( ) ;
continue ;
}
if ( hasDefaultContext | | hasOverrideContext ) {
continue ;
}
if ( context . getKey ( ) . contains ( " gd_claim_default " ) ) {
hasDefaultContext = true ;
} else if ( context . getKey ( ) . contains ( " gd_claim_override " ) ) {
2020-06-06 01:26:14 +02:00
if ( context . getValue ( ) . equalsIgnoreCase ( " claim " ) ) {
iterator . remove ( ) ;
replaceOverrideContext = true ;
}
2019-07-24 05:31:17 +02:00
hasOverrideContext = true ;
}
}
2020-06-06 01:26:14 +02:00
if ( replaceOverrideContext ) {
contexts . add ( new Context ( ContextKeys . CLAIM_OVERRIDE , claim . getUniqueId ( ) . toString ( ) ) ) ;
}
2019-08-23 22:49:00 +02:00
// Add target context
if ( target ! = null & & ! target . isEmpty ( ) & & ! target . equalsIgnoreCase ( " any " ) ) {
contexts . add ( new Context ( " target " , target ) ) ;
}
2019-07-24 05:31:17 +02:00
if ( flagType = = null ) {
if ( hasDefaultContext ) {
2019-08-23 22:49:00 +02:00
flagType = MenuType . DEFAULT ;
2019-07-24 05:31:17 +02:00
} else if ( hasOverrideContext ) {
2019-08-23 22:49:00 +02:00
flagType = MenuType . OVERRIDE ;
2019-07-24 05:31:17 +02:00
} else {
2019-08-23 22:49:00 +02:00
flagType = MenuType . CLAIM ;
2019-07-24 05:31:17 +02:00
}
}
2019-08-23 22:49:00 +02:00
2019-07-24 05:31:17 +02:00
TextComponent . Builder builder = null ;
2019-08-23 22:49:00 +02:00
if ( flagType = = MenuType . OVERRIDE ) {
2019-07-24 05:31:17 +02:00
builder = TextComponent . builder ( " OVERRIDE " ) . color ( TextColor . RED ) ;
2019-08-23 22:49:00 +02:00
} else if ( flagType = = MenuType . DEFAULT ) {
2019-07-24 05:31:17 +02:00
builder = TextComponent . builder ( " DEFAULT " ) . color ( TextColor . LIGHT_PURPLE ) ;
2019-08-23 22:49:00 +02:00
} else if ( flagType = = MenuType . CLAIM ) {
2019-07-24 05:31:17 +02:00
builder = TextComponent . builder ( " CLAIM " ) . color ( TextColor . GOLD ) ;
if ( contexts instanceof HashSet ) {
contexts . add ( claim . getContext ( ) ) ;
}
}
Component flagTypeText = builder . build ( ) ;
if ( contexts . isEmpty ( ) ) {
// default to claim
contexts . add ( claim . getContext ( ) ) ;
}
// wilderness overrides affect all worlds
if ( ! contexts . contains ( ClaimContexts . WILDERNESS_OVERRIDE_CONTEXT ) & & ! contexts . contains ( claim . getContext ( ) ) ) {
if ( contexts instanceof HashSet ) {
//contexts.add(claim.getWorld().getContext());
}
}
2019-12-31 00:25:55 +01:00
// Check if player can manage flag with contexts
if ( src instanceof Player ) {
final GDPermissionUser sourceUser = PermissionHolderCache . getInstance ( ) . getOrCreateUser ( ( ( Player ) src ) ) ;
final Tristate result = PermissionUtil . getInstance ( ) . getPermissionValue ( sourceUser , GDPermissions . USER_CLAIM_FLAGS + " . " + flag . getName ( ) . toLowerCase ( ) , contexts ) ;
if ( result ! = Tristate . TRUE ) {
GriefDefenderPlugin . sendMessage ( src , MessageCache . getInstance ( ) . PERMISSION_FLAG_USE ) ;
return new GDPermissionResult ( ResultTypes . NO_PERMISSION ) ;
}
}
2019-08-23 22:49:00 +02:00
if ( subject = = GriefDefenderPlugin . DEFAULT_HOLDER ) {
2020-08-16 06:39:38 +02:00
if ( flagType = = MenuType . OVERRIDE ) {
PermissionUtil . getInstance ( ) . setPermissionValue ( GriefDefenderPlugin . GD_OVERRIDE_HOLDER , flag , value , contexts ) ;
} else if ( flagType = = MenuType . CLAIM ) {
PermissionUtil . getInstance ( ) . setPermissionValue ( GriefDefenderPlugin . GD_CLAIM_HOLDER , flag , value , contexts ) ;
} else {
PermissionUtil . getInstance ( ) . setPermissionValue ( GriefDefenderPlugin . GD_DEFAULT_HOLDER , flag , value , contexts ) ;
}
2019-07-30 22:53:58 +02:00
if ( ! clicked & & src instanceof Player ) {
2019-07-24 05:31:17 +02:00
TextAdapter . sendComponent ( src , TextComponent . builder ( " " )
2019-07-30 22:53:58 +02:00
. append ( TextComponent . builder ( " \ n[ " ) . append ( MessageCache . getInstance ( ) . FLAG_UI_RETURN_FLAGS . color ( TextColor . AQUA ) ) . append ( " ] \ n " )
2019-07-24 05:31:17 +02:00
. clickEvent ( ClickEvent . runCommand ( GDCallbackHolder . getInstance ( ) . createCallbackRunCommand ( createCommandConsumer ( src , " claimflag " , " " ) ) ) ) . build ( ) )
2019-08-23 22:49:00 +02:00
. append ( MessageStorage . MESSAGE_DATA . getMessage ( MessageStorage . FLAG_SET_PERMISSION_TARGET ,
2019-07-30 22:53:58 +02:00
ImmutableMap . of (
" type " , flagTypeText ,
2019-12-31 00:25:55 +01:00
" permission " , flag . getPermission ( ) ,
2019-07-30 22:53:58 +02:00
" contexts " , getFriendlyContextString ( claim , contexts ) ,
2019-12-31 00:25:55 +01:00
" value " , getClickableText ( src , ( GDClaim ) claim , subject , contexts , flag , value , flagType ) . color ( TextColor . LIGHT_PURPLE ) ,
2020-06-06 01:26:14 +02:00
" target " , MessageCache . getInstance ( ) . TITLE_ALL ) ) )
2019-07-30 22:53:58 +02:00
. build ( ) ) ;
2019-07-24 05:31:17 +02:00
}
} else {
2019-12-31 00:25:55 +01:00
PermissionUtil . getInstance ( ) . setPermissionValue ( subject , flag , value , contexts ) ;
2019-07-30 22:53:58 +02:00
if ( ! clicked & & src instanceof Player ) {
2019-07-24 05:31:17 +02:00
TextAdapter . sendComponent ( src , TextComponent . builder ( " " )
. append ( TextComponent . builder ( " " )
. append ( " \ n[ " )
2019-07-30 22:53:58 +02:00
. append ( MessageCache . getInstance ( ) . FLAG_UI_RETURN_FLAGS . color ( TextColor . AQUA ) )
2019-07-24 05:31:17 +02:00
. append ( " ] \ n " , TextColor . WHITE )
2019-08-23 22:49:00 +02:00
. clickEvent ( ClickEvent . runCommand ( GDCallbackHolder . getInstance ( ) . createCallbackRunCommand ( createCommandConsumer ( src , subject instanceof GDPermissionUser ? " claimflagplayer " : " claimflaggroup " , subject . getFriendlyName ( ) ) ) ) ) . build ( ) )
. append ( MessageStorage . MESSAGE_DATA . getMessage ( MessageStorage . FLAG_SET_PERMISSION_TARGET ,
2019-07-30 22:53:58 +02:00
ImmutableMap . of (
" type " , flagTypeText ,
2019-12-31 00:25:55 +01:00
" permission " , flag . getPermission ( ) ,
2019-07-30 22:53:58 +02:00
" contexts " , getFriendlyContextString ( claim , contexts ) ,
2019-12-31 00:25:55 +01:00
" value " , getClickableText ( src , ( GDClaim ) claim , subject , contexts , flag , value , flagType ) . color ( TextColor . LIGHT_PURPLE ) ,
2019-08-23 22:49:00 +02:00
" target " , subject . getFriendlyName ( ) ) ) )
2019-07-30 22:53:58 +02:00
. build ( ) ) ;
2019-07-24 05:31:17 +02:00
}
}
return new GDPermissionResult ( ResultTypes . SUCCESS ) ;
}
2019-08-23 22:49:00 +02:00
public static String adjustTargetForTypes ( String target , Flag flag ) {
if ( target . equals ( " player " ) | | target . equals ( " minecraft:player " ) | | target . equalsIgnoreCase ( " any " ) ) {
return target ;
}
if ( flag . getName ( ) . contains ( " entity " ) | | flag = = Flags . ITEM_SPAWN ) {
final String contextKey = " target " ;
String [ ] parts = target . split ( " : " ) ;
String targetId = " " ;
if ( parts . length = = 1 ) {
targetId = parts [ 0 ] ;
} else {
targetId = parts [ 1 ] ;
}
if ( targetId . equalsIgnoreCase ( " animal " ) ) {
return " #animal " ;
} else if ( targetId . equalsIgnoreCase ( " aquatic " ) ) {
return " #aquatic " ;
} else if ( targetId . equalsIgnoreCase ( " monster " ) ) {
return " #monster " ;
} else if ( targetId . equalsIgnoreCase ( " ambient " ) ) {
return " #ambient " ;
}
return target ;
} else {
if ( ( target . equals ( " food " ) | | target . endsWith ( " :food " ) ) & & ! target . startsWith ( " # " ) ) {
target = " # " + target ;
}
}
return target ;
}
public static void addFlagContexts ( Set < Context > contexts , Flag flag , String target ) {
if ( target . equals ( " player " ) | | target . equals ( " minecraft:player " ) | | target . equalsIgnoreCase ( " any " ) ) {
return ;
}
if ( flag . getName ( ) . contains ( " entity " ) | | flag = = Flags . ITEM_SPAWN ) {
final String contextKey = " target " ;
String [ ] parts = target . split ( " : " ) ;
if ( parts . length = = 1 ) {
contexts . add ( new Context ( contextKey , target ) ) ;
return ;
}
if ( parts [ 1 ] . equalsIgnoreCase ( " animal " ) ) {
contexts . add ( new Context ( contextKey , " #animal " ) ) ;
} else if ( parts [ 1 ] . equalsIgnoreCase ( " aquatic " ) ) {
contexts . add ( new Context ( contextKey , " #aquatic " ) ) ;
} else if ( parts [ 1 ] . equalsIgnoreCase ( " monster " ) ) {
contexts . add ( new Context ( contextKey , " #monster " ) ) ;
} else if ( parts [ 1 ] . equalsIgnoreCase ( " ambient " ) ) {
contexts . add ( new Context ( contextKey , " #ambient " ) ) ;
} else {
contexts . add ( new Context ( contextKey , target ) ) ;
}
}
}
public static Component getFriendlyContextString ( Claim claim , Set < Context > contexts ) {
if ( contexts . isEmpty ( ) ) {
return TextComponent . of ( " [] " , TextColor . WHITE ) ;
}
TextComponent . Builder builder = TextComponent . builder ( ) ;
2019-07-24 05:31:17 +02:00
final Iterator < Context > iterator = contexts . iterator ( ) ;
while ( iterator . hasNext ( ) ) {
final Context context = iterator . next ( ) ;
2019-08-23 22:49:00 +02:00
builder . append ( " \ n[ " , TextColor . WHITE )
. append ( context . getKey ( ) , TextColor . GREEN )
. append ( " = " , TextColor . GRAY )
. append ( context . getValue ( ) , TextColor . WHITE ) ;
if ( iterator . hasNext ( ) ) {
builder . append ( " ], " ) ;
} else {
builder . append ( " ] " ) ;
2019-07-24 05:31:17 +02:00
}
}
2019-08-23 22:49:00 +02:00
return builder . build ( ) ;
2019-07-24 05:31:17 +02:00
}
2019-08-23 22:49:00 +02:00
public static TextColor getPermissionMenuTypeColor ( MenuType type ) {
2019-07-24 05:31:17 +02:00
TextColor color = TextColor . LIGHT_PURPLE ;
2019-08-23 22:49:00 +02:00
if ( type = = MenuType . CLAIM ) {
2019-07-24 05:31:17 +02:00
color = TextColor . GOLD ;
2019-08-23 22:49:00 +02:00
} else if ( type = = MenuType . OVERRIDE ) {
2019-07-24 05:31:17 +02:00
color = TextColor . RED ;
}
return color ;
}
2019-12-31 00:25:55 +01:00
public static Consumer < CommandSender > createFlagConsumer ( CommandSender src , GDClaim claim , Subject subject , Set < Context > contexts , Flag flag , Tristate flagValue , MenuType flagType ) {
2019-07-24 05:31:17 +02:00
return consumer - > {
Tristate newValue = Tristate . UNDEFINED ;
if ( flagValue = = Tristate . TRUE ) {
newValue = Tristate . FALSE ;
} else if ( flagValue = = Tristate . UNDEFINED ) {
newValue = Tristate . TRUE ;
}
Component flagTypeText = TextComponent . empty ( ) ;
2019-08-23 22:49:00 +02:00
if ( flagType = = MenuType . OVERRIDE ) {
2019-07-24 05:31:17 +02:00
flagTypeText = TextComponent . of ( " OVERRIDE " , TextColor . RED ) ;
2019-08-23 22:49:00 +02:00
} else if ( flagType = = MenuType . DEFAULT ) {
2019-07-24 05:31:17 +02:00
flagTypeText = TextComponent . of ( " DEFAULT " , TextColor . LIGHT_PURPLE ) ;
2019-08-23 22:49:00 +02:00
} else if ( flagType = = MenuType . CLAIM ) {
2019-07-24 05:31:17 +02:00
flagTypeText = TextComponent . of ( " CLAIM " , TextColor . GOLD ) ;
}
2019-12-31 00:25:55 +01:00
2019-07-24 05:31:17 +02:00
Set < Context > newContexts = new HashSet < > ( contexts ) ;
2019-12-31 00:25:55 +01:00
PermissionUtil . getInstance ( ) . setPermissionValue ( GriefDefenderPlugin . DEFAULT_HOLDER , flag , newValue , newContexts ) ;
2019-07-24 05:31:17 +02:00
TextAdapter . sendComponent ( src , TextComponent . builder ( " " )
. append ( " Set " , TextColor . GREEN )
. append ( flagTypeText )
. append ( " permission " )
2019-12-31 00:25:55 +01:00
. append ( flag . getName ( ) . toLowerCase ( ) , TextColor . AQUA )
2019-07-24 05:31:17 +02:00
. append ( " \ n to " , TextColor . GREEN )
2019-12-31 00:25:55 +01:00
. append ( getClickableText ( src , ( GDClaim ) claim , subject , newContexts , flag , newValue , flagType ) . color ( TextColor . LIGHT_PURPLE ) )
2019-07-24 05:31:17 +02:00
. append ( " for " , TextColor . GREEN )
2019-08-23 22:49:00 +02:00
. append ( subject . getFriendlyName ( ) , TextColor . GOLD ) . build ( ) ) ;
2019-07-24 05:31:17 +02:00
} ;
}
public static Consumer < CommandSender > createCommandConsumer ( CommandSender src , String command , String arguments ) {
return createCommandConsumer ( src , command , arguments , null ) ;
}
public static Consumer < CommandSender > createCommandConsumer ( CommandSender src , String command , String arguments , Consumer < CommandSender > postConsumerTask ) {
return consumer - > {
if ( ! NMSUtil . getInstance ( ) . getBukkitCommandMap ( ) . dispatch ( src , command + " " + arguments ) ) {
2019-08-23 22:49:00 +02:00
TextAdapter . sendComponent ( src , MessageStorage . MESSAGE_DATA . getMessage ( MessageStorage . COMMAND_EXECUTE_FAILED ,
2019-07-30 22:53:58 +02:00
ImmutableMap . of (
" command " , command ,
" args " , arguments ) ) ) ;
2019-07-24 05:31:17 +02:00
}
if ( postConsumerTask ! = null ) {
postConsumerTask . accept ( src ) ;
}
} ;
}
public static void executeCommand ( CommandSender src , String command , String arguments ) {
if ( ! NMSUtil . getInstance ( ) . getBukkitCommandMap ( ) . dispatch ( src , command + " " + arguments ) ) {
2019-08-23 22:49:00 +02:00
TextAdapter . sendComponent ( src , MessageStorage . MESSAGE_DATA . getMessage ( MessageStorage . COMMAND_EXECUTE_FAILED ,
2019-07-30 22:53:58 +02:00
ImmutableMap . of (
" command " , command ,
" args " , arguments ) ) ) ;
2019-07-24 05:31:17 +02:00
}
}
public static void showClaims ( CommandSender src , Set < Claim > claims ) {
if ( claims . isEmpty ( ) ) {
// do nothing
return ;
}
showClaims ( src , claims , 0 , false ) ;
}
public static void showOverlapClaims ( CommandSender src , Set < Claim > claims , int height ) {
showClaims ( src , claims , height , true , true ) ;
}
public static void showClaims ( CommandSender src , Set < Claim > claims , int height , boolean visualizeClaims ) {
showClaims ( src , claims , height , visualizeClaims , false ) ;
}
public static void showClaims ( CommandSender src , Set < Claim > claims , int height , boolean visualizeClaims , boolean overlap ) {
final String worldName = src instanceof Player ? ( ( Player ) src ) . getWorld ( ) . getName ( ) : Bukkit . getWorlds ( ) . get ( 0 ) . getName ( ) ;
2019-09-18 17:28:49 +02:00
List < Component > claimsTextList = generateClaimTextList ( new ArrayList < Component > ( ) , claims , worldName , null , src , createShowClaimsConsumer ( src , claims , height , visualizeClaims ) , false , overlap , false ) ;
2019-07-24 05:31:17 +02:00
if ( visualizeClaims & & src instanceof Player ) {
Player player = ( Player ) src ;
final GDPlayerData playerData = GriefDefenderPlugin . getInstance ( ) . dataStore . getOrCreatePlayerData ( player . getWorld ( ) , player . getUniqueId ( ) ) ;
2020-06-06 01:26:14 +02:00
final boolean hideBorders = GriefDefenderPlugin . getInstance ( ) . getWorldEditProvider ( ) ! = null & &
GriefDefenderPlugin . getInstance ( ) . getWorldEditProvider ( ) . hasCUISupport ( player ) & &
GriefDefenderPlugin . getActiveConfig ( player . getWorld ( ) . getUID ( ) ) . getConfig ( ) . visual . hideBorders ;
2019-07-24 05:31:17 +02:00
if ( claims . size ( ) > 1 ) {
2020-06-06 01:26:14 +02:00
if ( ! hideBorders ) {
if ( height ! = 0 ) {
height = playerData . lastValidInspectLocation ! = null ? playerData . lastValidInspectLocation . getBlockY ( ) : player . getEyeLocation ( ) . getBlockY ( ) ;
}
for ( Claim claim : claims ) {
GDClaimVisual visualization = GDClaimVisual . fromClaim ( claim , playerData . getClaimCreateMode ( ) = = CreateModeTypes . VOLUME ? height : player . getEyeLocation ( ) . getBlockY ( ) , player . getLocation ( ) , playerData , null ) ;
visualization . apply ( player ) ;
}
2019-07-24 05:31:17 +02:00
}
2020-06-06 01:26:14 +02:00
if ( GriefDefenderPlugin . getInstance ( ) . getWorldEditProvider ( ) ! = null ) {
GriefDefenderPlugin . getInstance ( ) . getWorldEditProvider ( ) . visualizeClaims ( claims , player , playerData , true ) ;
}
2019-07-24 05:31:17 +02:00
} else {
2020-06-06 01:26:14 +02:00
if ( ! hideBorders ) {
for ( Claim claim : claims ) {
GDClaim gdClaim = ( GDClaim ) claim ;
final GDClaimVisual visual = gdClaim . getVisualizer ( ) ;
if ( visual . getVisualTransactions ( ) . isEmpty ( ) ) {
visual . createClaimBlockVisuals ( height , player . getLocation ( ) , playerData ) ;
}
visual . apply ( player ) ;
}
2019-07-24 05:31:17 +02:00
}
2020-06-06 01:26:14 +02:00
if ( GriefDefenderPlugin . getInstance ( ) . getWorldEditProvider ( ) ! = null ) {
GriefDefenderPlugin . getInstance ( ) . getWorldEditProvider ( ) . visualizeClaims ( claims , player , playerData , true ) ;
}
2019-07-24 05:31:17 +02:00
}
}
2020-06-06 01:26:14 +02:00
if ( ! claimsTextList . isEmpty ( ) ) {
PaginationList . Builder builder = PaginationList . builder ( ) . title ( MessageCache . getInstance ( ) . CLAIMLIST_UI_TITLE . color ( TextColor . RED ) ) . padding ( TextComponent . builder ( " " ) . decoration ( TextDecoration . STRIKETHROUGH , true ) . build ( ) ) . contents ( claimsTextList ) ;
builder . sendTo ( src ) ;
}
2019-07-24 05:31:17 +02:00
}
private static Consumer < CommandSender > createShowClaimsConsumer ( CommandSender src , Set < Claim > claims , int height , boolean visualizeClaims ) {
return consumer - > {
showClaims ( src , claims , height , visualizeClaims ) ;
} ;
}
2019-09-18 17:28:49 +02:00
public static List < Component > generateClaimTextListCommand ( List < Component > claimsTextList , Set < Claim > claimList , String worldName , GDPermissionUser user , CommandSender src , Consumer < CommandSender > returnCommand , boolean listChildren ) {
return generateClaimTextList ( claimsTextList , claimList , worldName , user , src , returnCommand , listChildren , false , true ) ;
2019-07-24 05:31:17 +02:00
}
2019-09-18 17:28:49 +02:00
public static List < Component > generateClaimTextList ( List < Component > claimsTextList , Set < Claim > claimList , String worldName , GDPermissionUser user , CommandSender src , Consumer < CommandSender > returnCommand , boolean listChildren ) {
return generateClaimTextList ( claimsTextList , claimList , worldName , user , src , returnCommand , listChildren , false , false ) ;
}
public static List < Component > generateClaimTextList ( List < Component > claimsTextList , Set < Claim > claimList , String worldName , GDPermissionUser user , CommandSender src , Consumer < CommandSender > returnCommand , boolean listChildren , boolean overlap , boolean listCommand ) {
2019-07-24 05:31:17 +02:00
if ( claimList . size ( ) > 0 ) {
2019-12-31 10:00:25 +01:00
final Player player = src instanceof Player ? ( Player ) src : null ;
2019-07-24 05:31:17 +02:00
for ( Claim playerClaim : claimList ) {
GDClaim claim = ( GDClaim ) playerClaim ;
2020-06-06 01:26:14 +02:00
if ( player ! = null & & claim . getEconomyData ( ) ! = null & & ! claim . getEconomyData ( ) . isForSale ( )
& & ! claim . getEconomyData ( ) . isForRent ( ) & & ( claim . allowEdit ( player ) ! = null & & ! claim . isUserTrusted ( player , TrustTypes . ACCESSOR ) ) ) {
2019-12-31 10:00:25 +01:00
continue ;
}
2020-06-06 01:26:14 +02:00
if ( ! listCommand & & ! overlap & & ! listChildren & & ( claim . isSubdivision ( ) & & claimList . size ( ) > 1 )
& & claim . getEconomyData ( ) ! = null & & ! claim . getEconomyData ( ) . isForSale ( ) & & ! claim . getEconomyData ( ) . isForRent ( ) ) {
2019-07-24 05:31:17 +02:00
continue ;
}
double teleportHeight = claim . getOwnerPlayerData ( ) = = null ? 65 . 0D : ( claim . getOwnerMinClaimLevel ( ) > 65 . 0D ? claim . getOwnerMinClaimLevel ( ) : 65 ) ;
Vector3i lesserPos = claim . lesserBoundaryCorner ;
Vector3i greaterPos = claim . greaterBoundaryCorner ;
Vector3i center = claim . lesserBoundaryCorner . add ( lesserPos . getX ( ) , lesserPos . getY ( ) , lesserPos . getZ ( ) ) . div ( 2 ) ;
Vector3i newCenter = new Vector3i ( center . getX ( ) , teleportHeight , center . getZ ( ) ) ;
Vector3i southWest = new Vector3i ( newCenter . getX ( ) , newCenter . getY ( ) , newCenter . getZ ( ) ) ;
//final double teleportHeight = claim.getOwnerPlayerData() == null ? 65.0D : (claim.getOwnerPlayerData().getMinClaimLevel() > 65.0D ? claim.getOwnerPlayerData().getMinClaimLevel() : 65);
//Location<World> southWest = claim.lesserBoundaryCorner.setPosition(new Vector3d(claim.lesserBoundaryCorner.getPosition().getX(), teleportHeight, claim.greaterBoundaryCorner.getPosition().getZ()));
Component claimName = claim . getData ( ) . getName ( ) . orElse ( TextComponent . empty ( ) ) ;
Component teleportName = claim . getData ( ) . getName ( ) . orElse ( claim . getFriendlyNameType ( ) ) ;
2019-07-30 22:53:58 +02:00
Component ownerLine = TextComponent . builder ( )
. append ( MessageCache . getInstance ( ) . LABEL_OWNER . color ( TextColor . YELLOW ) )
2019-07-24 05:31:17 +02:00
. append ( " : " , TextColor . WHITE )
2020-06-06 01:26:14 +02:00
. append ( claim . getOwnerDisplayName ( ) . color ( TextColor . GOLD ) )
2019-07-24 05:31:17 +02:00
. append ( " \ n " ) . build ( ) ;
Component claimTypeInfo = TextComponent . builder ( " Type " ) . color ( TextColor . YELLOW )
. append ( " : " , TextColor . WHITE )
. append ( claim . getFriendlyNameType ( ) )
. append ( " " )
. append ( claim . isCuboid ( ) ? " 3D " : " 2D " , TextColor . GRAY )
2019-07-30 22:53:58 +02:00
. append ( " ( " )
. append ( MessageCache . getInstance ( ) . LABEL_AREA )
. append ( " : " , TextColor . WHITE )
2019-07-24 05:31:17 +02:00
. append ( String . valueOf ( claim . getClaimBlocks ( ) ) , TextColor . GRAY )
. append ( " blocks) \ n " , TextColor . WHITE ) . build ( ) ;
2019-07-30 22:53:58 +02:00
Component clickInfo = MessageCache . getInstance ( ) . CLAIMLIST_UI_CLICK_INFO ;
2019-07-24 05:31:17 +02:00
Component basicInfo = TextComponent . builder ( " " )
. append ( ownerLine )
. append ( claimTypeInfo )
. append ( clickInfo ) . build ( ) ;
Component claimInfoCommandClick = TextComponent . builder ( " " )
. append ( claim . getFriendlyNameType ( ) )
. clickEvent ( ClickEvent . runCommand ( GDCallbackHolder . getInstance ( ) . createCallbackRunCommand ( CommandHelper . createCommandConsumer ( src , " claiminfo " , claim . getUniqueId ( ) . toString ( ) , createReturnClaimListConsumer ( src , returnCommand ) ) ) ) )
. hoverEvent ( HoverEvent . showText ( basicInfo ) ) . build ( ) ;
Component claimSpawn = null ;
2020-01-06 22:24:24 +01:00
if ( player ! = null & & PermissionUtil . getInstance ( ) . canPlayerTeleport ( player , claim ) ) {
final Vector3i spawnPos = claim . getData ( ) . getSpawnPos ( ) . orElse ( null ) ;
if ( spawnPos ! = null ) {
Location spawnLoc = new Location ( claim . getWorld ( ) , spawnPos . getX ( ) , spawnPos . getY ( ) , spawnPos . getZ ( ) ) ;
claimSpawn = TextComponent . builder ( " " )
. append ( " [ " )
. append ( " TP " , TextColor . LIGHT_PURPLE )
. append ( " ] " )
. clickEvent ( ClickEvent . runCommand ( GDCallbackHolder . getInstance ( ) . createCallbackRunCommand ( CommandHelper . createTeleportConsumer ( src , spawnLoc , claim , true ) ) ) )
. hoverEvent ( HoverEvent . showText ( MessageStorage . MESSAGE_DATA . getMessage ( MessageStorage . CLAIMLIST_UI_CLICK_TELEPORT_TARGET ,
ImmutableMap . of (
" name " , teleportName ,
" target " , " 's spawn @ " + spawnPos . toString ( ) ,
" world " , claim . getWorld ( ) . getName ( ) ) ) ) )
. build ( ) ;
} else {
claimSpawn = TextComponent . builder ( " " )
. append ( " [ " )
. append ( " TP " , TextColor . LIGHT_PURPLE )
. append ( " ] " )
. clickEvent ( ClickEvent . runCommand ( GDCallbackHolder . getInstance ( ) . createCallbackRunCommand ( CommandHelper . createTeleportConsumer ( src , VecHelper . toLocation ( claim . getWorld ( ) , southWest ) , claim ) ) ) )
. hoverEvent ( HoverEvent . showText ( MessageStorage . MESSAGE_DATA . getMessage ( MessageStorage . CLAIMLIST_UI_CLICK_TELEPORT_TARGET ,
ImmutableMap . of (
2019-07-30 22:53:58 +02:00
" name " , teleportName ,
2020-01-06 22:24:24 +01:00
" target " , southWest . toString ( ) ,
2019-07-30 22:53:58 +02:00
" world " , claim . getWorld ( ) . getName ( ) ) ) ) )
2020-01-06 22:24:24 +01:00
. build ( ) ;
}
2019-07-24 05:31:17 +02:00
}
List < Component > childrenTextList = new ArrayList < > ( ) ;
if ( ! listChildren ) {
2019-09-18 17:28:49 +02:00
childrenTextList = generateClaimTextList ( new ArrayList < Component > ( ) , claim . getChildren ( true ) , worldName , user , src , returnCommand , true ) ;
2019-07-24 05:31:17 +02:00
}
Component buyClaim = TextComponent . empty ( ) ;
if ( player ! = null & & claim . getEconomyData ( ) . isForSale ( ) & & claim . getEconomyData ( ) . getSalePrice ( ) > - 1 ) {
2019-07-30 22:53:58 +02:00
Component buyInfo = TextComponent . builder ( )
. append ( MessageCache . getInstance ( ) . LABEL_PRICE . color ( TextColor . AQUA ) )
. append ( " : " , TextColor . WHITE )
2019-07-24 05:31:17 +02:00
. append ( String . valueOf ( claim . getEconomyData ( ) . getSalePrice ( ) ) , TextColor . GOLD )
2019-07-30 22:53:58 +02:00
. append ( " \ n " )
. append ( MessageCache . getInstance ( ) . CLAIMLIST_UI_CLICK_PURCHASE ) . build ( ) ;
2019-07-24 05:31:17 +02:00
buyClaim = TextComponent . builder ( )
2020-06-06 01:26:14 +02:00
. append ( TextComponent . builder ( " [ " ) . append ( MessageCache . getInstance ( ) . LABEL_BUY . color ( TextColor . GREEN ) ) . append ( " ] " , TextColor . WHITE ) . build ( ) )
2019-07-24 05:31:17 +02:00
. clickEvent ( ClickEvent . runCommand ( GDCallbackHolder . getInstance ( ) . createCallbackRunCommand ( buyClaimConsumerConfirmation ( src , claim ) ) ) )
2019-07-30 22:53:58 +02:00
. hoverEvent ( HoverEvent . showText ( player . getUniqueId ( ) . equals ( claim . getOwnerUniqueId ( ) ) ? MessageCache . getInstance ( ) . CLAIM_OWNER_ALREADY : buyInfo ) ) . build ( ) ;
2019-07-24 05:31:17 +02:00
}
2020-06-06 01:26:14 +02:00
Component rentClaim = TextComponent . empty ( ) ;
if ( player ! = null & & claim . getEconomyData ( ) . isForRent ( ) & & player . hasPermission ( GDPermissions . USER_RENT_BASE ) ) {
Component rentInfo = TextComponent . builder ( )
. append ( MessageCache . getInstance ( ) . LABEL_PRICE . color ( TextColor . AQUA ) )
. append ( " : " , TextColor . WHITE )
. append ( String . valueOf ( claim . getEconomyData ( ) . getRentRate ( ) + " per " + ( claim . getEconomyData ( ) . getPaymentType ( ) = = PaymentType . DAILY ? " day " : " hour " ) ) , TextColor . GOLD )
. append ( " \ n " )
. append ( MessageCache . getInstance ( ) . CLAIMLIST_UI_CLICK_RENT ) . build ( ) ;
rentClaim = TextComponent . builder ( )
. append ( TextComponent . builder ( " [ " ) . append ( MessageCache . getInstance ( ) . LABEL_RENT . color ( TextColor . GREEN ) ) . append ( " ] " , TextColor . WHITE ) . build ( ) )
. clickEvent ( ClickEvent . runCommand ( GDCallbackHolder . getInstance ( ) . createCallbackRunCommand ( EconomyUtil . getInstance ( ) . rentClaimConsumerConfirmation ( src , claim ) ) ) )
. hoverEvent ( HoverEvent . showText ( player . getUniqueId ( ) . equals ( claim . getOwnerUniqueId ( ) ) ? MessageCache . getInstance ( ) . CLAIM_OWNER_ALREADY : rentInfo ) ) . build ( ) ;
}
2019-07-24 05:31:17 +02:00
if ( ! childrenTextList . isEmpty ( ) ) {
Component children = TextComponent . builder ( " [ " )
2019-07-30 22:53:58 +02:00
. append ( MessageCache . getInstance ( ) . LABEL_CHILDREN . color ( TextColor . AQUA ) )
2019-07-24 05:31:17 +02:00
. append ( " ] " , TextColor . WHITE )
. clickEvent ( ClickEvent . runCommand ( GDCallbackHolder . getInstance ( ) . createCallbackRunCommand ( showChildrenList ( childrenTextList , src , returnCommand , claim ) ) ) )
2019-07-30 22:53:58 +02:00
. hoverEvent ( HoverEvent . showText ( MessageCache . getInstance ( ) . CLAIMLIST_UI_CLICK_VIEW_CHILDREN ) ) . build ( ) ;
2019-07-24 05:31:17 +02:00
claimsTextList . add ( TextComponent . builder ( " " )
2020-01-06 22:24:24 +01:00
. append ( claimSpawn ! = null ? claimSpawn . append ( TextComponent . of ( " " ) ) : TextComponent . of ( " " ) )
2019-07-24 05:31:17 +02:00
. append ( claimInfoCommandClick )
. append ( " : " , TextColor . WHITE )
2020-07-05 03:06:59 +02:00
. append ( claim . getOwnerDisplayName ( ) . color ( TextColor . GOLD )
. clickEvent ( ClickEvent . suggestCommand ( " /claimlist " + claim . getOwnerName ( ) ) )
. hoverEvent ( HoverEvent . showText ( MessageCache . getInstance ( ) . CLAIMLIST_UI_CLICK_PLAYER_LIST ) ) )
2019-07-24 05:31:17 +02:00
. append ( " " )
. append ( claimName = = TextComponent . empty ( ) ? TextComponent . of ( " " ) : claimName )
. append ( " " )
2019-07-30 22:53:58 +02:00
. append ( children )
. append ( " " )
2019-07-24 05:31:17 +02:00
. append ( buyClaim )
2020-06-06 01:26:14 +02:00
. append ( " " )
. append ( rentClaim )
2019-07-24 05:31:17 +02:00
. build ( ) ) ;
} else {
claimsTextList . add ( TextComponent . builder ( " " )
2020-01-06 22:24:24 +01:00
. append ( claimSpawn ! = null ? claimSpawn . append ( TextComponent . of ( " " ) ) : TextComponent . of ( " " ) )
2019-07-24 05:31:17 +02:00
. append ( claimInfoCommandClick )
. append ( " : " , TextColor . WHITE )
2020-07-05 03:06:59 +02:00
. append ( claim . getOwnerDisplayName ( ) . color ( TextColor . GOLD )
. clickEvent ( ClickEvent . suggestCommand ( " /claimlist " + claim . getOwnerName ( ) ) )
. hoverEvent ( HoverEvent . showText ( MessageCache . getInstance ( ) . CLAIMLIST_UI_CLICK_PLAYER_LIST ) ) )
2019-07-24 05:31:17 +02:00
. append ( " " )
. append ( claimName = = TextComponent . empty ( ) ? TextComponent . of ( " " ) : claimName )
. append ( buyClaim )
2020-06-06 01:26:14 +02:00
. append ( " " )
. append ( rentClaim )
2019-07-24 05:31:17 +02:00
. build ( ) ) ;
}
}
2020-06-06 01:26:14 +02:00
if ( claimsTextList . size ( ) = = 0 & & player ! = null ) {
final GDPermissionUser srcUser = PermissionHolderCache . getInstance ( ) . getOrCreateUser ( player ) ;
if ( srcUser . getInternalPlayerData ( ) . showNoClaimsFoundMessage ) {
claimsTextList . add ( MessageCache . getInstance ( ) . CLAIMLIST_UI_NO_CLAIMS_FOUND . color ( TextColor . RED ) ) ;
} else {
srcUser . getInternalPlayerData ( ) . showNoClaimsFoundMessage = true ;
}
2019-07-24 05:31:17 +02:00
}
}
return claimsTextList ;
}
public static Consumer < CommandSender > buyClaimConsumerConfirmation ( CommandSender src , Claim claim ) {
return confirm - > {
final Player player = ( Player ) src ;
if ( player . getUniqueId ( ) . equals ( claim . getOwnerUniqueId ( ) ) ) {
return ;
}
2019-07-30 22:53:58 +02:00
final Economy economy = GriefDefenderPlugin . getInstance ( ) . getVaultProvider ( ) . getApi ( ) ;
if ( ! economy . hasAccount ( player ) ) {
final Component message = GriefDefenderPlugin . getInstance ( ) . messageData . getMessage ( MessageStorage . ECONOMY_PLAYER_NOT_FOUND , ImmutableMap . of (
" player " , player . getName ( ) ) ) ;
GriefDefenderPlugin . sendMessage ( player , message ) ;
2019-07-24 05:31:17 +02:00
return ;
}
2019-07-30 22:53:58 +02:00
final double balance = economy . getBalance ( player ) ;
2019-07-24 05:31:17 +02:00
if ( balance < claim . getEconomyData ( ) . getSalePrice ( ) ) {
2019-07-30 22:53:58 +02:00
Map < String , Object > params = ImmutableMap . of (
" amount " , claim . getEconomyData ( ) . getSalePrice ( ) ,
2019-07-24 05:31:17 +02:00
" balance " , balance ,
2019-07-30 22:53:58 +02:00
" amount_required " , claim . getEconomyData ( ) . getSalePrice ( ) - balance ) ;
GriefDefenderPlugin . sendMessage ( player , GriefDefenderPlugin . getInstance ( ) . messageData . getMessage ( MessageStorage . ECONOMY_CLAIM_BUY_NOT_ENOUGH_FUNDS , params ) ) ;
2019-07-24 05:31:17 +02:00
return ;
}
2019-07-30 22:53:58 +02:00
final Component message = GriefDefenderPlugin . getInstance ( ) . messageData . getMessage ( MessageStorage . ECONOMY_CLAIM_BUY_CONFIRMATION ,
2019-08-23 22:49:00 +02:00
ImmutableMap . of ( " amount " , " $ " + claim . getEconomyData ( ) . getSalePrice ( ) ) ) ;
final Component buyConfirmationText = TextComponent . builder ( )
. append ( message )
. append ( TextComponent . builder ( )
. append ( " \ n[ " )
. append ( MessageCache . getInstance ( ) . LABEL_CONFIRM . color ( TextColor . GREEN ) )
. append ( " ] \ n " )
2020-06-06 01:26:14 +02:00
. clickEvent ( ClickEvent . runCommand ( GDCallbackHolder . getInstance ( ) . createCallbackRunCommand ( src , createBuyConsumerConfirmed ( src , claim ) , true ) ) ) . build ( ) )
2019-08-23 22:49:00 +02:00
. build ( ) ;
2019-07-30 22:53:58 +02:00
GriefDefenderPlugin . sendMessage ( player , buyConfirmationText ) ;
2019-07-24 05:31:17 +02:00
} ;
}
private static Consumer < CommandSender > createBuyConsumerConfirmed ( CommandSender src , Claim claim ) {
return confirm - > {
final Player player = ( Player ) src ;
2019-07-30 22:53:58 +02:00
final GDPermissionUser owner = PermissionHolderCache . getInstance ( ) . getOrCreateUser ( claim . getOwnerUniqueId ( ) ) ;
final Economy economy = GriefDefenderPlugin . getInstance ( ) . getVaultProvider ( ) . getApi ( ) ;
if ( ! economy . hasAccount ( owner . getOfflinePlayer ( ) ) ) {
final Component message = GriefDefenderPlugin . getInstance ( ) . messageData . getMessage ( MessageStorage . ECONOMY_PLAYER_NOT_FOUND , ImmutableMap . of (
" player " , owner . getName ( ) ) ) ;
GriefDefenderPlugin . sendMessage ( player , message ) ;
2019-07-24 05:31:17 +02:00
return ;
}
2019-08-23 22:49:00 +02:00
GDCauseStackManager . getInstance ( ) . pushCause ( player ) ;
final ClaimResult result = ( ( GDClaim ) claim ) . transferOwner ( player . getUniqueId ( ) , true , false ) ;
2019-07-24 05:31:17 +02:00
if ( ! result . successful ( ) ) {
2019-08-23 22:49:00 +02:00
final Component defaultMessage = MessageStorage . MESSAGE_DATA . getMessage ( MessageStorage . ECONOMY_CLAIM_BUY_TRANSFER_CANCELLED ,
2019-07-30 22:53:58 +02:00
ImmutableMap . of (
" owner " , owner . getName ( ) ,
2019-08-23 22:49:00 +02:00
" player " , player . getName ( ) ,
" result " , result . getMessage ( ) . orElse ( TextComponent . of ( result . getResultType ( ) . toString ( ) ) ) ) ) ;
2019-07-24 05:31:17 +02:00
TextAdapter . sendComponent ( src , result . getMessage ( ) . orElse ( defaultMessage ) ) ;
return ;
}
2020-06-06 01:26:14 +02:00
final double balance = economy . getBalance ( player ) ;
if ( balance < claim . getEconomyData ( ) . getSalePrice ( ) ) {
Map < String , Object > params = ImmutableMap . of (
" amount " , claim . getEconomyData ( ) . getSalePrice ( ) ,
" balance " , balance ,
" amount_required " , claim . getEconomyData ( ) . getSalePrice ( ) - balance ) ;
GriefDefenderPlugin . sendMessage ( player , GriefDefenderPlugin . getInstance ( ) . messageData . getMessage ( MessageStorage . ECONOMY_CLAIM_BUY_NOT_ENOUGH_FUNDS , params ) ) ;
return ;
}
2019-07-24 05:31:17 +02:00
final double salePrice = claim . getEconomyData ( ) . getSalePrice ( ) ;
2019-07-30 22:53:58 +02:00
final EconomyResponse response = economy . depositPlayer ( owner . getOfflinePlayer ( ) , salePrice ) ;
if ( response . transactionSuccess ( ) ) {
2020-06-06 01:26:14 +02:00
final EconomyResponse withdrawResponse = EconomyUtil . getInstance ( ) . withdrawFunds ( player , salePrice ) ;
2019-07-30 22:53:58 +02:00
final Component message = GriefDefenderPlugin . getInstance ( ) . messageData . getMessage ( MessageStorage . ECONOMY_CLAIM_BUY_CONFIRMED ,
ImmutableMap . of (
2019-08-23 22:49:00 +02:00
" amount " , String . valueOf ( " $ " + salePrice ) ) ) ;
2019-07-30 22:53:58 +02:00
final Component saleMessage = GriefDefenderPlugin . getInstance ( ) . messageData . getMessage ( MessageStorage . ECONOMY_CLAIM_SOLD ,
ImmutableMap . of (
2019-08-23 22:49:00 +02:00
" amount " , String . valueOf ( " $ " + salePrice ) ,
" balance " , String . valueOf ( " $ " + economy . getBalance ( owner . getOfflinePlayer ( ) ) ) ) ) ;
2019-07-30 22:53:58 +02:00
if ( owner . getOnlinePlayer ( ) ! = null ) {
TextAdapter . sendComponent ( owner . getOnlinePlayer ( ) , saleMessage ) ;
}
claim . getEconomyData ( ) . setForSale ( false ) ;
claim . getEconomyData ( ) . setSalePrice ( 0 ) ;
claim . getData ( ) . save ( ) ;
GriefDefenderPlugin . sendMessage ( src , message ) ;
2019-07-24 05:31:17 +02:00
}
} ;
}
public static Consumer < CommandSender > showChildrenList ( List < Component > childrenTextList , CommandSender src , Consumer < CommandSender > returnCommand , GDClaim parent ) {
return consumer - > {
Component claimListReturnCommand = TextComponent . builder ( " " )
. append ( " \ n[ " )
2019-07-30 22:53:58 +02:00
. append ( MessageCache . getInstance ( ) . CLAIMLIST_UI_RETURN_CLAIMSLIST . color ( TextColor . AQUA ) )
2019-07-24 05:31:17 +02:00
. append ( " ] \ n " , TextColor . WHITE )
. clickEvent ( ClickEvent . runCommand ( GDCallbackHolder . getInstance ( ) . createCallbackRunCommand ( returnCommand ) ) ) . build ( ) ;
List < Component > textList = new ArrayList < > ( ) ;
textList . add ( claimListReturnCommand ) ;
textList . addAll ( childrenTextList ) ;
PaginationList . Builder builder = PaginationList . builder ( )
. title ( parent . getName ( ) . orElse ( parent . getFriendlyNameType ( ) )
2019-07-30 22:53:58 +02:00
. append ( TextComponent . of ( " " ) . append ( MessageCache . getInstance ( ) . CLAIMLIST_UI_TITLE_CHILD_CLAIMS ) ) ) . padding ( TextComponent . builder ( " " ) . decoration ( TextDecoration . STRIKETHROUGH , true ) . build ( ) ) . contents ( textList ) ;
2019-07-24 05:31:17 +02:00
builder . sendTo ( src ) ;
} ;
}
public static Consumer < CommandSender > createReturnClaimListConsumer ( CommandSender src , Consumer < CommandSender > returnCommand ) {
return consumer - > {
Component claimListReturnCommand = TextComponent . builder ( " " )
. append ( " \ n[ " )
2019-07-30 22:53:58 +02:00
. append ( MessageCache . getInstance ( ) . CLAIMLIST_UI_RETURN_CLAIMSLIST . color ( TextColor . AQUA ) )
2019-07-24 05:31:17 +02:00
. append ( " ] \ n " , TextColor . WHITE )
. clickEvent ( ClickEvent . runCommand ( GDCallbackHolder . getInstance ( ) . createCallbackRunCommand ( returnCommand ) ) ) . build ( ) ;
TextAdapter . sendComponent ( src , claimListReturnCommand ) ;
} ;
}
public static Consumer < CommandSender > createReturnClaimListConsumer ( CommandSender src , String arguments ) {
return consumer - > {
Component claimListReturnCommand = TextComponent . builder ( " " )
. append ( " \ n[ " )
2019-07-30 22:53:58 +02:00
. append ( MessageCache . getInstance ( ) . CLAIMLIST_UI_RETURN_CLAIMSLIST . color ( TextColor . AQUA ) )
2019-07-24 05:31:17 +02:00
. append ( " ] \ n " , TextColor . WHITE )
. clickEvent ( ClickEvent . runCommand ( GDCallbackHolder . getInstance ( ) . createCallbackRunCommand ( CommandHelper . createCommandConsumer ( src , " /claimslist " , arguments ) ) ) ) . build ( ) ;
TextAdapter . sendComponent ( src , claimListReturnCommand ) ;
} ;
}
2019-12-31 00:25:55 +01:00
public static Consumer < CommandSender > createFlagConsumer ( CommandSender src , GDPermissionHolder subject , String subjectName , Set < Context > contexts , GDClaim claim , Flag flag , Tristate flagValue , String source ) {
2019-07-24 05:31:17 +02:00
return consumer - > {
2019-12-31 00:25:55 +01:00
String target = flag . getName ( ) . toLowerCase ( ) ;
2019-07-24 05:31:17 +02:00
if ( target . isEmpty ( ) ) {
target = " any " ;
}
Tristate newValue = Tristate . UNDEFINED ;
if ( flagValue = = Tristate . TRUE ) {
newValue = Tristate . FALSE ;
} else if ( flagValue = = Tristate . UNDEFINED ) {
newValue = Tristate . TRUE ;
}
2019-12-31 00:25:55 +01:00
CommandHelper . applyFlagPermission ( src , subject , claim , flag , target , newValue , null , MenuType . GROUP ) ;
2019-07-24 05:31:17 +02:00
} ;
}
2019-12-31 00:25:55 +01:00
public static Component getClickableText ( CommandSender src , GDClaim claim , Subject subject , Set < Context > contexts , Flag flag , Tristate flagValue , MenuType type ) {
2019-07-24 05:31:17 +02:00
TextComponent . Builder textBuilder = TextComponent . builder ( flagValue . toString ( ) . toLowerCase ( ) )
. hoverEvent ( HoverEvent . showText ( TextComponent . builder ( " " )
2019-08-23 22:49:00 +02:00
. append ( MessageStorage . MESSAGE_DATA . getMessage ( MessageStorage . CLAIMLIST_UI_CLICK_TOGGLE_VALUE ,
2019-07-30 22:53:58 +02:00
ImmutableMap . of ( " type " , type . name ( ) . toLowerCase ( ) ) ) )
2019-07-24 05:31:17 +02:00
. append ( " \ n " )
2019-08-23 22:49:00 +02:00
. append ( UIHelper . getPermissionMenuTypeHoverText ( type ) ) . build ( ) ) )
2019-12-31 00:25:55 +01:00
. clickEvent ( ClickEvent . runCommand ( GDCallbackHolder . getInstance ( ) . createCallbackRunCommand ( createFlagConsumer ( src , claim , subject , contexts , flag , flagValue , type ) ) ) ) ;
2019-07-24 05:31:17 +02:00
return textBuilder . build ( ) ;
}
2019-12-31 00:25:55 +01:00
public static Component getClickableText ( CommandSender src , GDPermissionHolder subject , String subjectName , Set < Context > contexts , GDClaim claim , Flag flag , Tristate flagValue , String source , MenuType type ) {
2019-08-23 22:49:00 +02:00
Component onClickText = MessageStorage . MESSAGE_DATA . getMessage ( MessageStorage . CLAIMLIST_UI_CLICK_TOGGLE_VALUE ,
2019-07-30 22:53:58 +02:00
ImmutableMap . of ( " type " , " flag " ) ) ;
2019-07-24 05:31:17 +02:00
boolean hasPermission = true ;
2019-08-23 22:49:00 +02:00
if ( type = = MenuType . INHERIT ) {
onClickText = MessageStorage . MESSAGE_DATA . getMessage ( MessageStorage . FLAG_UI_INHERIT_PARENT ,
2019-07-30 22:53:58 +02:00
ImmutableMap . of ( " name " , claim . getFriendlyNameType ( ) ) ) ;
2019-07-24 05:31:17 +02:00
hasPermission = false ;
} else if ( src instanceof Player ) {
Component denyReason = claim . allowEdit ( ( Player ) src ) ;
if ( denyReason ! = null ) {
onClickText = denyReason ;
hasPermission = false ;
}
}
TextComponent . Builder textBuilder = TextComponent . builder ( flagValue . toString ( ) . toLowerCase ( ) )
. hoverEvent ( HoverEvent . showText ( TextComponent . builder ( " " )
. append ( onClickText )
. append ( " \ n " )
2019-08-23 22:49:00 +02:00
. append ( UIHelper . getPermissionMenuTypeHoverText ( type ) ) . build ( ) ) ) ;
2019-07-24 05:31:17 +02:00
if ( hasPermission ) {
2019-12-31 00:25:55 +01:00
textBuilder . clickEvent ( ClickEvent . runCommand ( GDCallbackHolder . getInstance ( ) . createCallbackRunCommand ( createFlagConsumer ( src , subject , subjectName , contexts , claim , flag , flagValue , source ) ) ) ) ;
2019-07-24 05:31:17 +02:00
}
return textBuilder . build ( ) ;
}
public static String handleCommandFlag ( CommandSender src , String target ) {
String pluginId = " minecraft " ;
String args = " " ;
String command = " " ;
int argsIndex = target . indexOf ( " [ " ) ;
if ( argsIndex ! = - 1 ) {
if ( argsIndex = = 0 ) {
// invalid
2019-07-30 22:53:58 +02:00
TextAdapter . sendComponent ( src , MessageCache . getInstance ( ) . COMMAND_INVALID ) ;
2019-07-24 05:31:17 +02:00
return null ;
}
command = target . substring ( 0 , argsIndex ) ;
String [ ] parts = command . split ( " : " ) ;
if ( parts . length > 1 ) {
pluginId = parts [ 0 ] ;
command = parts [ 1 ] ;
}
if ( ! validateCommandMapping ( src , command , pluginId ) ) {
return null ;
}
2019-08-23 22:49:00 +02:00
if ( ! pluginId . equals ( " minecraft " ) ) {
Plugin pluginContainer = Bukkit . getPluginManager ( ) . getPlugin ( pluginId ) ;
2019-07-24 05:31:17 +02:00
if ( pluginContainer = = null ) {
2019-08-23 22:49:00 +02:00
TextAdapter . sendComponent ( src , MessageStorage . MESSAGE_DATA . getMessage ( MessageStorage . PLUGIN_NOT_FOUND ,
ImmutableMap . of ( " id " , pluginId ) ) ) ;
2019-07-24 05:31:17 +02:00
return null ;
}
2019-08-23 22:49:00 +02:00
}
2019-07-24 05:31:17 +02:00
args = target . substring ( argsIndex , target . length ( ) ) ;
Pattern p = Pattern . compile ( " \\ [([^ \\ ]]+) \\ ] " ) ;
Matcher m = p . matcher ( args ) ;
if ( ! m . find ( ) ) {
// invalid
2019-08-23 22:49:00 +02:00
TextAdapter . sendComponent ( src , MessageStorage . MESSAGE_DATA . getMessage ( MessageStorage . COMMAND_EXECUTE_FAILED ,
2019-07-30 22:53:58 +02:00
ImmutableMap . of (
" command " , command ,
" args " , args ) ) ) ;
2019-07-24 05:31:17 +02:00
return null ;
}
args = m . group ( 1 ) ;
2019-08-23 22:49:00 +02:00
target = pluginId + " : " + command + " . " + args . replace ( " : " , " . " ) ;
2019-07-24 05:31:17 +02:00
} else {
String [ ] parts = target . split ( " : " ) ;
if ( parts . length > 1 ) {
pluginId = parts [ 0 ] ;
command = parts [ 1 ] ;
} else {
command = target ;
}
2019-08-23 22:49:00 +02:00
target = pluginId + " : " + command ;
2019-07-24 05:31:17 +02:00
}
// validate command
if ( ! validateCommandMapping ( src , command , pluginId ) ) {
return null ;
}
return target ;
}
private static boolean validateCommandMapping ( CommandSender src , String command , String pluginId ) {
2020-01-31 16:56:43 +01:00
if ( command . equalsIgnoreCase ( " any " ) ) {
return true ;
}
2019-07-24 05:31:17 +02:00
Command commandMapping = NMSUtil . getInstance ( ) . getBukkitCommandMap ( ) . getCommand ( command ) ;
if ( commandMapping = = null ) {
Update for 1.5.5 release.
* Add potion effects support.
* Add item enchantment support.
* Add pvp lookup methods for claim and playerdata.
* Add 'block-tileentity-id-list' used to override mod block id's that are used for many TE's.
- Ex. IC2 uses a base block id 'ic2:te' for all TE's. When the id is detected during block/item usage, it will be converted to the actual id.
* Add TileEntity registry to better support hybrid servers.
* Add '/claiminfo' UUID click support to copy text to chat.
* Add support for overriding option 'player-command-exit/enter' on player.
* Add command description translation support.
* Add zh_HK language support.
* Fix event cause not clearing on push.
* Fix abandon claim within town returning funds to owner in economy mode.
* Fix player afk detection during claim block task.
* Fix async chunk load during visual revert.
* Fix '/gd claim we' command.
* Fix advanced flag GUI toggle with definitions.
* Fix rent sign update not checking all children claims.
* Fix rent sign not being updated when cancelled via '/claimrent cancel'.
* Fix '/claimsell' on admin claim.
* Fix NPE when attempting to purchase an admin claim for sale.
* Fix command description translations.
* Fix isInvulnerable NPE on 1.8.8 servers.
* Fix '/abandonworld' exiting when no economy data found for player.
* Fix '/deletealladmin' only deleting admin claims in current world when passing no world argument.
* Fix '/claimcontract' and '/claimexpand' NPE in economy mode.
* Fix GD claim enter/exit prefix. The prefix will now use '[<playername>]'.
Note: This can be configured in lang file under 'claim-prefix-enter' and 'claim-prefix-exit'
* Clean up advanced flag GUI code.
* Disable /buyblocks command when economy-block-cost is <= 0
* Deny town claim abandon if basic claims exist owned by owner.
* Allow to input string as option value.
* Improve pvp source contexts.
* Clean up '/acb' command code.
* (Bukkit) Add potion splash protection support.
* (Bukkit) Fix tamed entities being hit by projectiles.
* (Bukkit) Fix enderman block place protection.
* (Hybrid) Fix wrong EnumCreatureType being registered for entities.
* (Hybrid) Add TileEntity registry.
* (Hybrid) Add mod command support for 'command-execute' flag.
* (Sponge) Add PlaceHolderAPI support.
* (Sponge) Add Nucleus v2 support.
* (Sponge) Add IgniteEntityEvent support.
* (Sponge) Fix '/cpp' and '/cpg' command.
* (Sponge) Fix player block placement deny not sending message.
Fixes #4
Fixes #200, Fixes #206, Fixes #222
Fixes #232, Fixes #237, Fixes #267
Fixes #269, Fixes #276, Fixes #296
Fixes #310, Fixes #311, Fixes #317
Fixes #324, Fixes #333, Fixes #334
Fixes #335, Fixes #336, Fixes #347
2020-12-28 23:28:12 +01:00
// check mod command mapping
commandMapping = NMSUtil . getInstance ( ) . getModCommandMap ( ) . getCommand ( command ) ;
if ( commandMapping = = null ) {
TextAdapter . sendComponent ( src , MessageStorage . MESSAGE_DATA . getMessage ( MessageStorage . PLUGIN_COMMAND_NOT_FOUND ,
ImmutableMap . of (
" command " , command ,
" id " , pluginId ) ) ) ;
return false ;
}
2019-07-24 05:31:17 +02:00
}
return true ;
}
public static String getTrustPermission ( TrustType trustType ) {
if ( trustType = = TrustTypes . ACCESSOR ) {
return GDPermissions . TRUST_ACCESSOR ;
} else if ( trustType = = TrustTypes . CONTAINER ) {
return GDPermissions . TRUST_CONTAINER ;
} else if ( trustType = = TrustTypes . BUILDER ) {
return GDPermissions . TRUST_BUILDER ;
} else {
return GDPermissions . TRUST_MANAGER ;
}
}
public static Consumer < CommandSender > createTeleportConsumer ( CommandSender src , Location location , Claim claim ) {
2019-09-03 19:59:12 +02:00
return createTeleportConsumer ( src , location , claim , false ) ;
}
public static Consumer < CommandSender > createTeleportConsumer ( CommandSender src , Location location , Claim claim , boolean isClaimSpawn ) {
2019-07-24 05:31:17 +02:00
return teleport - > {
if ( ! ( src instanceof Player ) ) {
// ignore
return ;
}
2020-01-06 22:24:24 +01:00
final Player player = ( Player ) src ;
2020-05-01 00:26:35 +02:00
// check if world is loaded
if ( Bukkit . getWorld ( location . getWorld ( ) . getUID ( ) ) = = null ) {
TextAdapter . sendComponent ( player , MessageCache . getInstance ( ) . TELEPORT_NO_SAFE_LOCATION ) ;
return ;
}
2020-01-06 22:24:24 +01:00
final GDPlayerData playerData = GriefDefenderPlugin . getInstance ( ) . dataStore . getPlayerData ( player . getWorld ( ) , player . getUniqueId ( ) ) ;
2019-09-18 17:28:49 +02:00
final int teleportDelay = GDPermissionManager . getInstance ( ) . getInternalOptionValue ( TypeToken . of ( Integer . class ) , player , Options . PLAYER_TELEPORT_DELAY , claim ) ;
2019-09-03 19:59:12 +02:00
if ( isClaimSpawn ) {
2019-09-18 17:28:49 +02:00
if ( teleportDelay > 0 ) {
playerData . teleportDelay = teleportDelay + 1 ;
playerData . teleportSourceLocation = player . getLocation ( ) ;
playerData . teleportLocation = location ;
return ;
}
2019-09-03 19:59:12 +02:00
player . teleport ( location , TeleportCause . PLUGIN ) ;
return ;
}
2020-06-06 01:26:14 +02:00
final double safeY = location . getWorld ( ) . getHighestBlockYAt ( location ) ;
2019-08-25 17:19:25 +02:00
location . setY ( safeY ) ;
int currentY = location . getBlockY ( ) ;
2020-06-06 01:26:14 +02:00
while ( currentY > 0 & & currentY < location . getWorld ( ) . getMaxHeight ( ) ) {
2019-08-25 17:19:25 +02:00
if ( PlayerUtil . getInstance ( ) . isSafeLocation ( location ) ) {
2019-09-18 17:28:49 +02:00
if ( teleportDelay > 0 ) {
playerData . teleportDelay = teleportDelay + 1 ;
playerData . teleportLocation = location ;
return ;
}
2019-08-25 17:19:25 +02:00
player . teleport ( location , TeleportCause . PLUGIN ) ;
return ;
}
2020-06-06 01:26:14 +02:00
if ( location . getWorld ( ) . getEnvironment ( ) = = Environment . NETHER ) {
currentY - - ;
} else {
currentY + + ;
}
2019-08-25 17:19:25 +02:00
location . setY ( currentY ) ;
}
2019-07-24 05:31:17 +02:00
2019-08-25 17:19:25 +02:00
TextAdapter . sendComponent ( player , MessageCache . getInstance ( ) . TELEPORT_NO_SAFE_LOCATION ) ;
2019-07-24 05:31:17 +02:00
} ;
}
public static void handleBankTransaction ( CommandSender src , String [ ] args , GDClaim claim ) {
if ( GriefDefenderPlugin . getInstance ( ) . getVaultProvider ( ) = = null ) {
2019-07-30 22:53:58 +02:00
GriefDefenderPlugin . sendMessage ( src , MessageCache . getInstance ( ) . ECONOMY_NOT_INSTALLED ) ;
2019-07-24 05:31:17 +02:00
return ;
}
if ( claim . isSubdivision ( ) | | claim . isAdminClaim ( ) ) {
return ;
}
if ( ! claim . getEconomyAccountId ( ) . isPresent ( ) ) {
2019-07-30 22:53:58 +02:00
GriefDefenderPlugin . sendMessage ( src , MessageCache . getInstance ( ) . ECONOMY_VIRTUAL_NOT_SUPPORTED ) ;
2019-07-24 05:31:17 +02:00
return ;
}
final Economy economy = GriefDefenderPlugin . getInstance ( ) . getVaultProvider ( ) . getApi ( ) ;
final String command = args [ 0 ] ;
final double amount = args . length > 1 ? Double . parseDouble ( args [ 1 ] ) : 0 ;
final UUID playerSource = ( ( Player ) src ) . getUniqueId ( ) ;
final GDPlayerData playerData = GriefDefenderPlugin . getInstance ( ) . dataStore . getPlayerData ( claim . getWorld ( ) , claim . getOwnerUniqueId ( ) ) ;
if ( playerData . canIgnoreClaim ( claim ) | | claim . getOwnerUniqueId ( ) . equals ( playerSource ) | | claim . getUserTrusts ( TrustTypes . MANAGER ) . contains ( playerData . playerID ) ) {
final UUID bankAccount = claim . getEconomyAccountId ( ) . orElse ( null ) ;
if ( bankAccount = = null ) {
2019-07-30 22:53:58 +02:00
GriefDefenderPlugin . sendMessage ( src , MessageCache . getInstance ( ) . ECONOMY_VIRTUAL_NOT_SUPPORTED ) ;
2019-07-24 05:31:17 +02:00
return ;
}
if ( command . equalsIgnoreCase ( " withdraw " ) ) {
EconomyResponse result = economy . bankWithdraw ( bankAccount . toString ( ) , amount ) ;
if ( result . transactionSuccess ( ) ) {
2019-07-27 07:30:09 +02:00
final Component message = GriefDefenderPlugin . getInstance ( ) . messageData . getMessage ( MessageStorage . BANK_WITHDRAW ,
ImmutableMap . of (
" amount " , amount ) ) ;
2019-08-23 22:49:00 +02:00
GriefDefenderPlugin . sendMessage ( src , message ) ;
2019-07-24 05:31:17 +02:00
economy . depositPlayer ( ( ( Player ) src ) , amount ) ;
2020-06-06 01:26:14 +02:00
claim . getData ( ) . getEconomyData ( ) . addPaymentTransaction (
new GDPaymentTransaction ( TransactionType . BANK_WITHDRAW , TransactionResultType . SUCCESS , playerData . playerID , Instant . now ( ) , amount ) ) ;
2019-07-24 05:31:17 +02:00
} else {
2019-07-27 07:30:09 +02:00
final Component message = GriefDefenderPlugin . getInstance ( ) . messageData . getMessage ( MessageStorage . BANK_WITHDRAW_NO_FUNDS ,
ImmutableMap . of (
2019-07-24 05:31:17 +02:00
" balance " , economy . bankBalance ( bankAccount . toString ( ) ) ,
2019-07-27 07:30:09 +02:00
" amount " , amount ) ) ;
2019-07-24 05:31:17 +02:00
GriefDefenderPlugin . sendMessage ( src , message ) ;
claim . getData ( ) . getEconomyData ( )
2020-06-06 01:26:14 +02:00
. addPaymentTransaction ( new GDPaymentTransaction ( TransactionType . BANK_WITHDRAW , TransactionResultType . FAIL , playerData . playerID , Instant . now ( ) , amount ) ) ;
2019-07-24 05:31:17 +02:00
return ;
}
} else if ( command . equalsIgnoreCase ( " deposit " ) ) {
2020-06-06 01:26:14 +02:00
EconomyResponse result = EconomyUtil . getInstance ( ) . withdrawFunds ( ( ( Player ) src ) , amount ) ;
2019-07-24 05:31:17 +02:00
if ( result . transactionSuccess ( ) ) {
double depositAmount = amount ;
if ( claim . getData ( ) . isExpired ( ) ) {
final double taxBalance = claim . getEconomyData ( ) . getTaxBalance ( ) ;
depositAmount - = claim . getEconomyData ( ) . getTaxBalance ( ) ;
if ( depositAmount > = 0 ) {
2020-06-06 01:26:14 +02:00
claim . getEconomyData ( ) . addPaymentTransaction ( new GDPaymentTransaction ( TransactionType . TAX , TransactionResultType . SUCCESS , Instant . now ( ) , taxBalance ) ) ;
2019-07-24 05:31:17 +02:00
claim . getEconomyData ( ) . setTaxPastDueDate ( null ) ;
claim . getEconomyData ( ) . setTaxBalance ( 0 ) ;
claim . getInternalClaimData ( ) . setExpired ( false ) ;
2020-06-06 01:26:14 +02:00
final Component message = GriefDefenderPlugin . getInstance ( ) . messageData . getMessage ( MessageStorage . TAX_PAID_BALANCE ,
2019-07-27 07:30:09 +02:00
ImmutableMap . of (
" amount " , taxBalance ) ) ;
2019-07-24 05:31:17 +02:00
GriefDefenderPlugin . sendMessage ( src , message ) ;
if ( depositAmount = = 0 ) {
return ;
}
} else {
final double newTaxBalance = Math . abs ( depositAmount ) ;
claim . getEconomyData ( ) . setTaxBalance ( newTaxBalance ) ;
2020-06-06 01:26:14 +02:00
final Component message = GriefDefenderPlugin . getInstance ( ) . messageData . getMessage ( MessageStorage . TAX_PAID_PARTIAL ,
2019-07-27 07:30:09 +02:00
ImmutableMap . of (
2019-07-24 05:31:17 +02:00
" amount " , depositAmount ,
2019-07-27 07:30:09 +02:00
" balance " , newTaxBalance ) ) ;
2019-07-24 05:31:17 +02:00
GriefDefenderPlugin . sendMessage ( src , message ) ;
return ;
}
}
2019-07-27 07:30:09 +02:00
final Component message = GriefDefenderPlugin . getInstance ( ) . messageData . getMessage ( MessageStorage . BANK_DEPOSIT , ImmutableMap . of (
" amount " , depositAmount ) ) ;
2019-07-24 05:31:17 +02:00
GriefDefenderPlugin . sendMessage ( src , message ) ;
economy . bankDeposit ( bankAccount . toString ( ) , depositAmount ) ;
2020-06-06 01:26:14 +02:00
claim . getData ( ) . getEconomyData ( ) . addPaymentTransaction (
new GDPaymentTransaction ( TransactionType . BANK_DEPOSIT , TransactionResultType . SUCCESS , playerData . playerID , Instant . now ( ) , depositAmount ) ) ;
2019-07-24 05:31:17 +02:00
} else {
2019-07-27 07:30:09 +02:00
GriefDefenderPlugin . sendMessage ( src , GriefDefenderPlugin . getInstance ( ) . messageData . getMessage ( MessageStorage . BANK_WITHDRAW_NO_FUNDS ) ) ;
2019-07-24 05:31:17 +02:00
claim . getData ( ) . getEconomyData ( )
2020-06-06 01:26:14 +02:00
. addPaymentTransaction ( new GDPaymentTransaction ( TransactionType . BANK_DEPOSIT , TransactionResultType . FAIL , playerData . playerID , Instant . now ( ) , amount ) ) ;
2019-07-24 05:31:17 +02:00
return ;
}
}
} else {
2019-07-27 07:30:09 +02:00
final Component message = GriefDefenderPlugin . getInstance ( ) . messageData . getMessage ( MessageStorage . BANK_NO_PERMISSION ,
ImmutableMap . of (
" player " , claim . getOwnerName ( ) ) ) ;
2019-07-24 05:31:17 +02:00
GriefDefenderPlugin . sendMessage ( src , message ) ;
}
}
public static void displayClaimBankInfo ( Player player , GDClaim claim ) {
displayClaimBankInfo ( player , claim , false , false ) ;
}
public static void displayClaimBankInfo ( CommandSender player , GDClaim claim , boolean checkTown , boolean returnToClaimInfo ) {
if ( GriefDefenderPlugin . getInstance ( ) . getVaultProvider ( ) = = null ) {
2019-07-30 22:53:58 +02:00
GriefDefenderPlugin . sendMessage ( player , MessageCache . getInstance ( ) . ECONOMY_NOT_INSTALLED ) ;
2019-07-24 05:31:17 +02:00
return ;
}
if ( checkTown & & ! claim . isInTown ( ) ) {
2019-07-30 22:53:58 +02:00
GriefDefenderPlugin . sendMessage ( player , MessageCache . getInstance ( ) . TOWN_NOT_IN ) ;
2019-07-24 05:31:17 +02:00
return ;
}
if ( ! checkTown & & ( claim . isSubdivision ( ) | | claim . isAdminClaim ( ) ) ) {
return ;
}
final GDClaim town = claim . getTownClaim ( ) ;
final UUID bankAccount = checkTown ? town . getEconomyAccountId ( ) . orElse ( null ) : claim . getEconomyAccountId ( ) . orElse ( null ) ;
if ( bankAccount = = null ) {
2019-07-30 22:53:58 +02:00
GriefDefenderPlugin . sendMessage ( player , MessageCache . getInstance ( ) . ECONOMY_VIRTUAL_NOT_SUPPORTED ) ;
2019-07-24 05:31:17 +02:00
return ;
}
final Economy economy = GriefDefenderPlugin . getInstance ( ) . getVaultProvider ( ) . getApi ( ) ;
final GDPlayerData playerData = GriefDefenderPlugin . getInstance ( ) . dataStore . getPlayerData ( claim . getWorld ( ) , claim . getOwnerUniqueId ( ) ) ;
final double claimBalance = economy . bankBalance ( bankAccount . toString ( ) ) . balance ;
double taxOwed = - 1 ;
2019-08-23 22:49:00 +02:00
final double playerTaxRate = GDPermissionManager . getInstance ( ) . getInternalOptionValue ( TypeToken . of ( Double . class ) , ( Player ) player , Options . TAX_RATE , claim ) ;
2019-07-24 05:31:17 +02:00
if ( checkTown ) {
if ( ! town . getOwnerUniqueId ( ) . equals ( playerData . playerID ) ) {
for ( Claim playerClaim : playerData . getInternalClaims ( ) ) {
GDClaim playerTown = ( GDClaim ) playerClaim . getTown ( ) . orElse ( null ) ;
if ( ! playerClaim . isTown ( ) & & playerTown ! = null & & playerTown . getUniqueId ( ) . equals ( claim . getUniqueId ( ) ) ) {
taxOwed + = playerTown . getClaimBlocks ( ) * playerTaxRate ;
}
}
} else {
taxOwed = town . getClaimBlocks ( ) * playerTaxRate ;
}
} else {
taxOwed = claim . getClaimBlocks ( ) * playerTaxRate ;
}
final GriefDefenderConfig < ? > activeConfig = GriefDefenderPlugin . getActiveConfig ( claim . getWorld ( ) . getUID ( ) ) ;
2020-06-06 01:26:14 +02:00
final ZonedDateTime withdrawDate = TaskUtil . getNextTargetZoneDate ( activeConfig . getConfig ( ) . economy . taxApplyHour , 0 , 0 ) ;
2019-07-24 05:31:17 +02:00
Duration duration = Duration . between ( Instant . now ( ) . truncatedTo ( ChronoUnit . SECONDS ) , withdrawDate . toInstant ( ) ) ;
final long s = duration . getSeconds ( ) ;
final String timeLeft = String . format ( " %d:%02d:%02d " , s / 3600 , ( s % 3600 ) / 60 , ( s % 60 ) ) ;
2019-07-27 07:30:09 +02:00
final Component message = GriefDefenderPlugin . getInstance ( ) . messageData . getMessage ( MessageStorage . BANK_INFO ,
ImmutableMap . of (
2019-07-24 05:31:17 +02:00
" balance " , claimBalance ,
2019-07-27 07:30:09 +02:00
" tax-amount " , taxOwed ,
" time-remaining " , timeLeft ,
" tax-balance " , claim . getData ( ) . getEconomyData ( ) . getTaxBalance ( ) ) ) ;
2019-07-24 05:31:17 +02:00
Component transactions = TextComponent . builder ( " " )
2019-07-30 22:53:58 +02:00
. append ( MessageCache . getInstance ( ) . BANK_TITLE_TRANSACTIONS . color ( TextColor . AQUA ) . decoration ( TextDecoration . ITALIC , true ) )
2019-07-24 05:31:17 +02:00
. clickEvent ( ClickEvent . runCommand ( GDCallbackHolder . getInstance ( ) . createCallbackRunCommand ( createBankTransactionsConsumer ( player , claim , checkTown , returnToClaimInfo ) ) ) )
2019-07-30 22:53:58 +02:00
. hoverEvent ( HoverEvent . showText ( MessageCache . getInstance ( ) . BANK_CLICK_VIEW_TRANSACTIONS ) )
2019-07-24 05:31:17 +02:00
. build ( ) ;
List < Component > textList = new ArrayList < > ( ) ;
if ( returnToClaimInfo ) {
textList . add ( TextComponent . builder ( " " )
. append ( " \ n[ " )
2019-07-30 22:53:58 +02:00
. append ( MessageCache . getInstance ( ) . CLAIMINFO_UI_RETURN_CLAIMINFO . color ( TextColor . AQUA ) )
2019-07-24 05:31:17 +02:00
. append ( " ] \ n " )
. clickEvent ( ClickEvent . runCommand ( GDCallbackHolder . getInstance ( ) . createCallbackRunCommand ( CommandHelper . createCommandConsumer ( player , " claiminfo " , " " ) ) ) ) . build ( ) ) ;
}
textList . add ( message ) ;
textList . add ( transactions ) ;
PaginationList . Builder builder = PaginationList . builder ( )
. title ( TextComponent . of ( " Bank Info " , TextColor . AQUA ) ) . padding ( TextComponent . builder ( " " ) . decoration ( TextDecoration . STRIKETHROUGH , true ) . build ( ) ) . contents ( textList ) ;
builder . sendTo ( player ) ;
}
public static Consumer < CommandSender > createBankTransactionsConsumer ( CommandSender src , GDClaim claim , boolean checkTown , boolean returnToClaimInfo ) {
return settings - > {
2020-06-06 01:26:14 +02:00
List < PaymentTransaction > paymentTransactions = claim . getData ( ) . getEconomyData ( ) . getPaymentTransactions ( TransactionType . BANK_DEPOSIT ) ;
2019-07-24 05:31:17 +02:00
List < Component > textList = new ArrayList < > ( ) ;
textList . add ( TextComponent . builder ( " " )
. append ( " \ n[ " )
2019-07-30 22:53:58 +02:00
. append ( MessageCache . getInstance ( ) . CLAIMINFO_UI_RETURN_BANKINFO . color ( TextColor . AQUA ) )
2019-07-24 05:31:17 +02:00
. append ( " ] \ n " )
. clickEvent ( ClickEvent . runCommand ( GDCallbackHolder . getInstance ( ) . createCallbackRunCommand ( consumer - > { displayClaimBankInfo ( src , claim , checkTown , returnToClaimInfo ) ; } ) ) ) . build ( ) ) ;
2020-06-06 01:26:14 +02:00
for ( PaymentTransaction transaction : paymentTransactions ) {
final Duration duration = Duration . between ( transaction . getTimestamp ( ) , Instant . now ( ) . truncatedTo ( ChronoUnit . SECONDS ) ) ;
2019-07-24 05:31:17 +02:00
final long s = duration . getSeconds ( ) ;
2020-06-06 01:26:14 +02:00
final GDPermissionUser user = PermissionHolderCache . getInstance ( ) . getOrCreateUser ( transaction . getSource ( ) . orElse ( null ) ) ;
2019-07-24 05:31:17 +02:00
final String timeLeft = String . format ( " %dh %02dm %02ds " , s / 3600 , ( s % 3600 ) / 60 , ( s % 60 ) ) + " ago " ;
textList . add ( TextComponent . builder ( " " )
2020-06-06 01:26:14 +02:00
. append ( transaction . getResultType ( ) . name ( ) , getTransactionColor ( transaction . getResultType ( ) ) )
2019-07-24 05:31:17 +02:00
. append ( " | " , TextColor . BLUE )
2020-06-06 01:26:14 +02:00
. append ( TextComponent . of ( String . valueOf ( transaction . getAmount ( ) ) ) )
2019-07-24 05:31:17 +02:00
. append ( " | " , TextColor . BLUE )
. append ( timeLeft , TextColor . GRAY )
. append ( user = = null ? TextComponent . empty ( ) : TextComponent . builder ( " " )
. append ( " | " , TextColor . BLUE )
. append ( user . getName ( ) , TextColor . LIGHT_PURPLE )
. build ( ) )
. build ( ) ) ;
}
textList . add ( TextComponent . builder ( " " )
. append ( " \ n[ " )
2019-07-30 22:53:58 +02:00
. append ( MessageCache . getInstance ( ) . CLAIMINFO_UI_RETURN_BANKINFO . color ( TextColor . AQUA ) )
2019-07-24 05:31:17 +02:00
. append ( " ] \ n " )
. clickEvent ( ClickEvent . runCommand ( GDCallbackHolder . getInstance ( ) . createCallbackRunCommand ( CommandHelper . createCommandConsumer ( src , " claimbank " , " " ) ) ) ) . build ( ) ) ;
PaginationList . Builder builder = PaginationList . builder ( )
2019-07-30 22:53:58 +02:00
. title ( MessageCache . getInstance ( ) . BANK_TITLE_TRANSACTIONS . color ( TextColor . AQUA ) ) . padding ( TextComponent . builder ( " " ) . decoration ( TextDecoration . STRIKETHROUGH , true ) . build ( ) ) . contents ( textList ) ;
2019-07-24 05:31:17 +02:00
builder . sendTo ( src ) ;
} ;
}
2020-06-06 01:26:14 +02:00
public static Consumer < CommandSender > createRentTransactionsConsumer ( CommandSender src , GDClaim claim , boolean checkTown , boolean returnToClaimInfo ) {
return settings - > {
List < PaymentTransaction > paymentTransactions = claim . getData ( ) . getEconomyData ( ) . getPaymentTransactions ( TransactionType . RENT ) ;
List < Component > textList = new ArrayList < > ( ) ;
textList . add ( TextComponent . builder ( " " )
. append ( " \ n[ " )
. append ( MessageCache . getInstance ( ) . RENT_UI_RETURN_INFO . color ( TextColor . AQUA ) )
. append ( " ] \ n " )
. clickEvent ( ClickEvent . runCommand ( GDCallbackHolder . getInstance ( ) . createCallbackRunCommand ( CommandHelper . createCommandConsumer ( src , " claimrent " , " info " ) ) ) ) . build ( ) ) ;
for ( PaymentTransaction transaction : paymentTransactions ) {
final Duration duration = Duration . between ( transaction . getTimestamp ( ) , Instant . now ( ) . truncatedTo ( ChronoUnit . SECONDS ) ) ;
final long s = duration . getSeconds ( ) ;
final GDPermissionUser user = PermissionHolderCache . getInstance ( ) . getOrCreateUser ( transaction . getSource ( ) . orElse ( null ) ) ;
final String timeLeft = String . format ( " %dh %02dm %02ds " , s / 3600 , ( s % 3600 ) / 60 , ( s % 60 ) ) + " ago " ;
textList . add ( TextComponent . builder ( " " )
. append ( transaction . getResultType ( ) . name ( ) , getTransactionColor ( transaction . getResultType ( ) ) )
. append ( " | " , TextColor . BLUE )
. append ( TextComponent . of ( String . valueOf ( transaction . getAmount ( ) ) ) )
. append ( " | " , TextColor . BLUE )
. append ( timeLeft , TextColor . GRAY )
. append ( user = = null ? TextComponent . empty ( ) : TextComponent . builder ( " " )
. append ( " | " , TextColor . BLUE )
. append ( user . getName ( ) , TextColor . LIGHT_PURPLE )
. build ( ) )
. build ( ) ) ;
}
textList . add ( TextComponent . builder ( " " )
. append ( " \ n[ " )
. append ( MessageCache . getInstance ( ) . RENT_UI_RETURN_INFO . color ( TextColor . AQUA ) )
. append ( " ] \ n " )
. clickEvent ( ClickEvent . runCommand ( GDCallbackHolder . getInstance ( ) . createCallbackRunCommand ( CommandHelper . createCommandConsumer ( src , " claimrent " , " info " ) ) ) ) . build ( ) ) ;
PaginationList . Builder builder = PaginationList . builder ( )
. title ( MessageCache . getInstance ( ) . RENT_UI_TITLE_TRANSACTIONS . color ( TextColor . AQUA ) ) . padding ( TextComponent . builder ( " " ) . decoration ( TextDecoration . STRIKETHROUGH , true ) . build ( ) ) . contents ( textList ) ;
builder . sendTo ( src ) ;
} ;
}
public static TextColor getTransactionColor ( TransactionResultType type ) {
2019-07-24 05:31:17 +02:00
switch ( type ) {
2020-06-06 01:26:14 +02:00
case SUCCESS :
2019-07-24 05:31:17 +02:00
return TextColor . GREEN ;
2020-06-06 01:26:14 +02:00
case FAIL :
2019-07-24 05:31:17 +02:00
return TextColor . RED ;
default :
return TextColor . GREEN ;
}
}
2019-08-23 22:49:00 +02:00
public static Component getBaseOptionOverlayText ( String option ) {
String baseFlag = option . replace ( GDPermissions . OPTION_BASE + " . " , " " ) ;
2019-07-24 05:31:17 +02:00
int endIndex = baseFlag . indexOf ( " . " ) ;
if ( endIndex ! = - 1 ) {
baseFlag = baseFlag . substring ( 0 , endIndex ) ;
}
2019-08-23 22:49:00 +02:00
final Option flag = GriefDefender . getRegistry ( ) . getType ( Option . class , baseFlag ) . orElse ( null ) ;
2019-07-24 05:31:17 +02:00
if ( flag = = null ) {
2019-08-23 22:49:00 +02:00
return MessageStorage . MESSAGE_DATA . getMessage ( MessageStorage . OPTION_NOT_FOUND , ImmutableMap . of (
" option " , baseFlag ) ) ;
2019-07-24 05:31:17 +02:00
}
return flag . getDescription ( ) ;
}
public static TrustType getTrustType ( String type ) {
switch ( type . toLowerCase ( ) ) {
case " accessor " :
return TrustTypes . ACCESSOR ;
case " builder " :
return TrustTypes . BUILDER ;
case " container " :
return TrustTypes . CONTAINER ;
case " manager " :
return TrustTypes . MANAGER ;
case " none " :
return TrustTypes . NONE ;
default :
return null ;
}
}
public static boolean checkTrustPermission ( Player player , TrustType type ) {
if ( type = = TrustTypes . ACCESSOR ) {
return player . hasPermission ( GDPermissions . GIVE_ACCESS_TRUST ) ;
}
if ( type = = TrustTypes . BUILDER ) {
return player . hasPermission ( GDPermissions . GIVE_BUILDER_TRUST ) ;
}
if ( type = = TrustTypes . CONTAINER ) {
return player . hasPermission ( GDPermissions . GIVE_CONTAINER_TRUST ) ;
}
if ( type = = TrustTypes . MANAGER ) {
return player . hasPermission ( GDPermissions . GIVE_MANAGER_TRUST ) ;
}
if ( type = = TrustTypes . NONE ) {
return player . hasPermission ( GDPermissions . REMOVE_TRUST ) ;
}
return true ;
}
}