Skip to content

Commit 61010ec

Browse files
authored
Update 1.1.1: Fix setowner command can be used to exceed the max limit of plots
Fix setowner command can be used to exceed the max limit of plots (#13)
1 parent c6b6ff0 commit 61010ec

7 files changed

Lines changed: 69 additions & 38 deletions

File tree

README.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Commands and Permissions
5252
| ~ | reload | plot.command.admin.reload | --- |
5353
| ~ | removehelper | --- | remove, untrust |
5454
| ~ | sethome | --- | --- |
55-
| ~ | setowner | --- | --- |
55+
| ~ | setowner | plot.command.setowner | --- |
5656
| ~ | setroads | plot.command.admin.setroads | --- |
5757
| ~ | setting | --- | config |
5858
| ~ | teleport | plot.command.admin.teleport | tp |
@@ -71,32 +71,32 @@ Commands that need to be enabled in config.yml
7171
Other Permissions
7272
------------------------------
7373

74-
| Permission | Discription |
75-
|---------------------------------|--------------------------------------------------------------------------|
76-
| plot.command.admin.addhelper | Bypasses the owner check when adding a helper to a plot. |
77-
| plot.command.admin.border | Bypasses the owner check when changing the plot border block. |
78-
| plot.command.admin.clear | Bypasses the owner check when clearing a plot. |
79-
| plot.command.admin.deletehome | Bypasses the owner check when deleting the spawn point of a plot |
80-
| plot.command.admin.deny | Bypasses the owner check when denying a player from a plot. |
81-
| plot.command.admin.dispose | Bypasses the owner check when disposing a plot. |
82-
| plot.command.admin.info | Bypasses the empty check when seeing the information of a plot. |
83-
| plot.command.admin.kick | Bypasses the owner check when kicking a player from a plot. |
84-
| plot.command.admin.merge | Bypasses the owner check when merging a plot. |
85-
| plot.command.admin.removehelper | Bypasses the owner check when removing a helper from a plot. |
86-
| plot.command.admin.sethome | Bypasses the owner check when setting the spawn point of a plot. |
87-
| plot.command.admin.setowner | Bypasses the owner check when setting the owner of a plot. |
88-
| plot.command.admin.config | Bypasses the owner check when setting the configuration of a plot. |
89-
| plot.command.admin.undeny | Bypasses the owner check when undenying a player from a plot. |
90-
| plot.command.admin.unlink | Bypasses the owner check when unlinking a plot. |
91-
| plot.command.admin.wall | Bypasses the owner check when changing the plot wall block. |
92-
| plot.admin.bypass.deny | Bypasses the denial of a player from a plot. |
93-
| plot.admin.bypass.kick | Bypasses the kick of a player from a plot. |
94-
| plot.admin.interact | Allows you to interact with blocks on the road. |
95-
| plot.admin.damage | Allows you to damage players on roads or if pvp is disabled on the plot. |
96-
| plot.admin.bucket.fill | Allows you to fill up buckets from the road. |
97-
| plot.admin.bucket.emtpy | Allows you to empty buckets from the road. |
98-
| plot.admin.break | Allows you to break blocks on the road. |
99-
| plot.admin.place | Allows you to place blocks on the road. |
100-
| plot.merge.unlimited | Allows you to merge unlimited plots. |
101-
| plot.merge.limit.\<any number> | Limits the player to only merge up to the given amount of plots. |
102-
| plot.limit.\<any number> | Limits the player to only claim up to the given amount of plots. |
74+
| Permission | Description |
75+
|---------------------------------|-----------------------------------------------------------------------------------------|
76+
| plot.command.admin.addhelper | Bypasses the owner check when adding a helper to a plot. |
77+
| plot.command.admin.border | Bypasses the owner check when changing the plot border block. |
78+
| plot.command.admin.clear | Bypasses the owner check when clearing a plot. |
79+
| plot.command.admin.deletehome | Bypasses the owner check when deleting the spawn point of a plot |
80+
| plot.command.admin.deny | Bypasses the owner check when denying a player from a plot. |
81+
| plot.command.admin.dispose | Bypasses the owner check when disposing a plot. |
82+
| plot.command.admin.info | Bypasses the empty check when seeing the information of a plot. |
83+
| plot.command.admin.kick | Bypasses the owner check when kicking a player from a plot. |
84+
| plot.command.admin.merge | Bypasses the owner check when merging a plot. |
85+
| plot.command.admin.removehelper | Bypasses the owner check when removing a helper from a plot. |
86+
| plot.command.admin.sethome | Bypasses the owner check when setting the spawn point of a plot. |
87+
| plot.command.admin.setowner | Bypasses the owner check, self check and player limit when setting the owner of a plot. |
88+
| plot.command.admin.config | Bypasses the owner check when setting the configuration of a plot. |
89+
| plot.command.admin.undeny | Bypasses the owner check when undenying a player from a plot. |
90+
| plot.command.admin.unlink | Bypasses the owner check when unlinking a plot. |
91+
| plot.command.admin.wall | Bypasses the owner check when changing the plot wall block. |
92+
| plot.admin.bypass.deny | Bypasses the denial of a player from a plot. |
93+
| plot.admin.bypass.kick | Bypasses the kick of a player from a plot. |
94+
| plot.admin.interact | Allows you to interact with blocks on the road. |
95+
| plot.admin.damage | Allows you to damage players on roads or if pvp is disabled on the plot. |
96+
| plot.admin.bucket.fill | Allows you to fill up buckets from the road. |
97+
| plot.admin.bucket.emtpy | Allows you to empty buckets from the road. |
98+
| plot.admin.break | Allows you to break blocks on the road. |
99+
| plot.admin.place | Allows you to place blocks on the road. |
100+
| plot.merge.unlimited | Allows you to merge unlimited plots. |
101+
| plot.merge.limit.\<any number> | Limits the player to only merge up to the given amount of plots. |
102+
| plot.limit.\<any number> | Limits the player to only claim up to the given amount of plots. |

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>ms.kevi</groupId>
88
<artifactId>plotplugin</artifactId>
9-
<version>1.1.0</version>
9+
<version>1.1.1</version>
1010

1111
<properties>
1212
<maven.compiler.source>17</maven.compiler.source>

src/main/java/ms/kevi/plotplugin/command/defaults/SetOwnerCommand.java

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class SetOwnerCommand extends SubCommand {
3636

3737
public SetOwnerCommand(PlotPlugin plugin, PlotCommand parent) {
3838
super(plugin, parent, "setowner");
39+
this.setPermission("plot.command.setowner");
3940
this.addParameter(CommandParameter.newType("player", CommandParamType.TARGET));
4041
}
4142

@@ -52,8 +53,8 @@ public boolean execute(Player player, String[] args) {
5253
final UUID targetId = this.plugin.getUniqueIdByName(targetName, false);
5354
final Player target = targetId != null ? player.getServer().getPlayer(targetId).orElse(null) : null;
5455

55-
if(targetName.equalsIgnoreCase(player.getName()) && !player.hasPermission("plot.command.admin.setowner")) {
56-
player.sendMessage(this.translate(player, TranslationKey.PLAYER_SELF));
56+
if(!plot.isOwner(player.getUniqueId()) && !player.hasPermission("plot.command.admin.setowner")) {
57+
player.sendMessage(this.translate(player, TranslationKey.NO_PLOT_OWNER));
5758
return false;
5859
}
5960

@@ -62,15 +63,42 @@ public boolean execute(Player player, String[] args) {
6263
return false;
6364
}
6465

65-
if(!player.hasPermission("plot.command.admin.setowner") && !plot.isOwner(player.getUniqueId())) {
66-
player.sendMessage(this.translate(player, TranslationKey.NO_PLOT_OWNER));
66+
if(target == null) {
67+
player.sendMessage(this.translate(player, TranslationKey.PLAYER_NOT_ONLINE));
68+
return false;
69+
}
70+
71+
if(targetName.equalsIgnoreCase(player.getName()) && !player.hasPermission("plot.command.admin.setowner")) {
72+
player.sendMessage(this.translate(player, TranslationKey.PLAYER_SELF));
6773
return false;
6874
}
6975

76+
final int ownedPlots = plotManager.getPlotsByOwner(targetId).size();
77+
if(!target.isOp() && !player.hasPermission("plot.command.admin.setowner")) {
78+
int maxLimit = -1;
79+
for(String permission : target.getEffectivePermissions().keySet()) {
80+
if(permission.startsWith("plot.limit.")) {
81+
try {
82+
final String limitStr = permission.substring("plot.limit.".length());
83+
if(limitStr.isBlank()) continue;
84+
final int limit = Integer.parseInt(limitStr);
85+
86+
if(limit > maxLimit) maxLimit = limit;
87+
} catch(NumberFormatException ignored) {
88+
}
89+
}
90+
}
91+
92+
if(maxLimit > 0 && ownedPlots >= maxLimit) {
93+
player.sendMessage(this.translate(player, TranslationKey.SETOWNER_FAILURE_TOO_MANY));
94+
return false;
95+
}
96+
}
97+
7098
plot.setOwner(targetId);
7199
plotManager.savePlots();
72-
if(target != null)
73-
target.sendMessage(this.translate(player, TranslationKey.SETOWNER_SUCCESS_TARGET, plot.getId()));
100+
101+
target.sendMessage(this.translate(target, TranslationKey.SETOWNER_SUCCESS_TARGET, plot.getId()));
74102
player.sendMessage(this.translate(player, TranslationKey.SETOWNER_SUCCESS, this.plugin.getCorrectName(targetId)));
75103
return true;
76104
}

src/main/java/ms/kevi/plotplugin/lang/TranslationKey.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public enum TranslationKey {
148148
RELOAD_SUCCESS,
149149
REMOVED_HELPER,
150150
SETHOME_SUCCESS,
151+
SETOWNER_FAILURE_TOO_MANY,
151152
SETOWNER_SUCCESS,
152153
SETOWNER_SUCCESS_TARGET,
153154
SETROADS_FINISHED,

src/main/resources/lang/de_DE.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ info-end=&7====== &6Grundstücks Info &7======
7272
info-failure=&6&lCitybuild &8&l» &r&cDieses Grundstück gehört keiner Person.
7373
removed-helper=&6&lCitybuild &8&l» &r&6{0}&r&a ist nun kein Helfer mehr!
7474
no-helper=&6&lCitybuild &8&l» &r&6{0}&r&c ist kein Helfer!
75+
setowner-failure-too-many=&6&lCitybuild &8&l» &r&cDieser Spieler besitzt bereits die maximale Anzahl an Grundstücken!
7576
setowner-success-target=&6&lCitybuild &8&l» &r&aDu wurdest zum Besitzer des Grundstückes &6{0}&r&a ernannt!
7677
setowner-success=&6&lCitybuild &8&l» &r&6{0}&r&a ist nun Besitzer von diesem Grundstück!
7778
undeny-success=&6&lCitybuild &8&l» &r&6{0}&r&a darf nun dein Grundstück wieder betreten!

src/main/resources/lang/en_US.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ info-end=&7====== &6Plot Info &7======
7474
info-failure=&6&lCitybuild &8&l» &r&cThis plot is not owned by a player.
7575
removed-helper=&6&lCitybuild &8&l» &r&6{0}&r&a is now no longer a helper!
7676
no-helper=&6&lCitybuild &8&l» &r&6{0}&r&c is not a helper!
77+
setowner-failure-too-many=&6&lCitybuild &8&l» &r&cThis player already has the maximum amount of plots!
7778
setowner-success-target=&6&lCitybuild &8&l» &r&aYou have been appointed the owner of the plot &6{0}&r&a!
7879
setowner-success=&6&lCitybuild &8&l» &r&6{0}&r&a is now owner of this plot!
7980
undeny-success=&6&lCitybuild &8&l» &r&6{0}&r&a may now enter your plot again!

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Plots
2-
version: "1.1.0"
2+
version: "1.1.1"
33
api: [ "1.0.13" ]
44
author: Kevims
55
main: ms.kevi.plotplugin.PlotPlugin

0 commit comments

Comments
 (0)