@@ -52,64 +52,55 @@ public boolean execute(Player player, String[] args) {
5252 final int dir = (NukkitMath .floorDouble ((player .getYaw () * 4 / 360 ) + 0.5 ) - 2 ) & 3 ;
5353 final Set <Plot > plotsToMerge = plotManager .calculatePlotsToMerge (plot , dir );
5454
55- boolean isOwner = player .hasPermission ("plot.command.admin.merge" );
56- if (!isOwner ) {
57- isOwner = true ;
55+ if (!player .hasPermission ("plot.command.admin.merge" )) {
5856 for (Plot plotToMerge : plotsToMerge ) {
5957 if (!plotToMerge .isOwner (player .getUniqueId ())) {
60- isOwner = false ;
61- break ;
58+ player . sendMessage ( this . translate ( player , TranslationKey . MERGE_FAILURE_OWNER )) ;
59+ return false ;
6260 }
6361 }
6462 }
6563
66- if (isOwner ) {
67- if (!player .hasPermission ("plot.merge.unlimited" ) && !player .isOp ()) {
68- if (!player .isOp ()) {
69- int maxLimit = -1 ;
70- for (String permission : player .getEffectivePermissions ().keySet ()) {
71- if (permission .startsWith ("plot.merge.limit." )) {
72- try {
73- final String limitStr = permission .substring ("plot.merge.limit." .length ());
74- if (limitStr .isBlank ()) continue ;
75- final int limit = Integer .parseInt (limitStr );
76-
77- if (limit > maxLimit ) maxLimit = limit ;
78- } catch (NumberFormatException ignored ) {
79- }
80- }
81- }
82-
83- if (maxLimit > 0 && plotsToMerge .size () > maxLimit ) {
84- player .sendMessage (this .translate (player , TranslationKey .MERGE_FAILURE_TOO_MANY , plotsToMerge .size ()));
85- return false ;
64+ if (!player .hasPermission ("plot.merge.limit.unlimited" )) {
65+ int maxLimit = -1 ;
66+ for (String permission : player .getEffectivePermissions ().keySet ()) {
67+ if (permission .startsWith ("plot.merge.limit." )) {
68+ try {
69+ final String limitStr = permission .substring ("plot.merge.limit." .length ());
70+ if (limitStr .isBlank ()) continue ;
71+ final int limit = Integer .parseInt (limitStr );
72+
73+ if (limit > maxLimit ) maxLimit = limit ;
74+ } catch (NumberFormatException ignored ) {
8675 }
8776 }
8877 }
8978
90- if (plot . isMerged ( dir ) ) {
91- player .sendMessage (this .translate (player , TranslationKey .MERGE_FAILURE_ALREADY_MERGED ));
79+ if (maxLimit > 0 && plotsToMerge . size () > maxLimit ) {
80+ player .sendMessage (this .translate (player , TranslationKey .MERGE_FAILURE_TOO_MANY , plotsToMerge . size () ));
9281 return false ;
9382 }
83+ }
9484
95- final PlotPreMergeEvent plotPreMergeEvent = new PlotPreMergeEvent (player , plot , dir , plotsToMerge );
96- this .plugin .getServer ().getPluginManager ().callEvent (plotPreMergeEvent );
97- if (plotPreMergeEvent .isCancelled ()) return false ;
98-
99- if (!plotManager .startMerge (plot , plotsToMerge )) {
100- player .sendMessage (this .translate (player , TranslationKey .MERGE_FAILURE_NO_PLOTS_FOUND ));
101- return false ;
102- }
85+ if (plot .isMerged (dir )) {
86+ player .sendMessage (this .translate (player , TranslationKey .MERGE_FAILURE_ALREADY_MERGED ));
87+ return false ;
88+ }
10389
104- final PlotMergeEvent plotMergeEvent = new PlotMergeEvent (player , plot , plotsToMerge );
105- this .plugin .getServer ().getPluginManager ().callEvent (plotMergeEvent );
90+ final PlotPreMergeEvent plotPreMergeEvent = new PlotPreMergeEvent (player , plot , dir , plotsToMerge );
91+ this .plugin .getServer ().getPluginManager ().callEvent (plotPreMergeEvent );
92+ if (plotPreMergeEvent .isCancelled ()) return false ;
10693
107- player .sendMessage (this .translate (player , TranslationKey .MERGE_SUCCESS ));
108- return true ;
109- } else {
110- player .sendMessage (this .translate (player , TranslationKey .MERGE_FAILURE_OWNER ));
94+ if (!plotManager .startMerge (plot , plotsToMerge )) {
95+ player .sendMessage (this .translate (player , TranslationKey .MERGE_FAILURE_NO_PLOTS_FOUND ));
11196 return false ;
11297 }
98+
99+ final PlotMergeEvent plotMergeEvent = new PlotMergeEvent (player , plot , plotsToMerge );
100+ this .plugin .getServer ().getPluginManager ().callEvent (plotMergeEvent );
101+
102+ player .sendMessage (this .translate (player , TranslationKey .MERGE_SUCCESS ));
103+ return true ;
113104 }
114105
115106}
0 commit comments