Skip to content

Commit

Permalink
Update 1.1.1: Fix setowner command can be used to exceed the max limi…
Browse files Browse the repository at this point in the history
…t of plots

Fix setowner command can be used to exceed the max limit of plots (#13)
  • Loading branch information
KCodeYT authored Jul 30, 2022
1 parent c6b6ff0 commit 61010ec
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 38 deletions.
60 changes: 30 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Commands and Permissions
| ~ | reload | plot.command.admin.reload | --- |
| ~ | removehelper | --- | remove, untrust |
| ~ | sethome | --- | --- |
| ~ | setowner | --- | --- |
| ~ | setowner | plot.command.setowner | --- |
| ~ | setroads | plot.command.admin.setroads | --- |
| ~ | setting | --- | config |
| ~ | teleport | plot.command.admin.teleport | tp |
Expand All @@ -71,32 +71,32 @@ Commands that need to be enabled in config.yml
Other Permissions
------------------------------

| Permission | Discription |
|---------------------------------|--------------------------------------------------------------------------|
| plot.command.admin.addhelper | Bypasses the owner check when adding a helper to a plot. |
| plot.command.admin.border | Bypasses the owner check when changing the plot border block. |
| plot.command.admin.clear | Bypasses the owner check when clearing a plot. |
| plot.command.admin.deletehome | Bypasses the owner check when deleting the spawn point of a plot |
| plot.command.admin.deny | Bypasses the owner check when denying a player from a plot. |
| plot.command.admin.dispose | Bypasses the owner check when disposing a plot. |
| plot.command.admin.info | Bypasses the empty check when seeing the information of a plot. |
| plot.command.admin.kick | Bypasses the owner check when kicking a player from a plot. |
| plot.command.admin.merge | Bypasses the owner check when merging a plot. |
| plot.command.admin.removehelper | Bypasses the owner check when removing a helper from a plot. |
| plot.command.admin.sethome | Bypasses the owner check when setting the spawn point of a plot. |
| plot.command.admin.setowner | Bypasses the owner check when setting the owner of a plot. |
| plot.command.admin.config | Bypasses the owner check when setting the configuration of a plot. |
| plot.command.admin.undeny | Bypasses the owner check when undenying a player from a plot. |
| plot.command.admin.unlink | Bypasses the owner check when unlinking a plot. |
| plot.command.admin.wall | Bypasses the owner check when changing the plot wall block. |
| plot.admin.bypass.deny | Bypasses the denial of a player from a plot. |
| plot.admin.bypass.kick | Bypasses the kick of a player from a plot. |
| plot.admin.interact | Allows you to interact with blocks on the road. |
| plot.admin.damage | Allows you to damage players on roads or if pvp is disabled on the plot. |
| plot.admin.bucket.fill | Allows you to fill up buckets from the road. |
| plot.admin.bucket.emtpy | Allows you to empty buckets from the road. |
| plot.admin.break | Allows you to break blocks on the road. |
| plot.admin.place | Allows you to place blocks on the road. |
| plot.merge.unlimited | Allows you to merge unlimited plots. |
| plot.merge.limit.\<any number> | Limits the player to only merge up to the given amount of plots. |
| plot.limit.\<any number> | Limits the player to only claim up to the given amount of plots. |
| Permission | Description |
|---------------------------------|-----------------------------------------------------------------------------------------|
| plot.command.admin.addhelper | Bypasses the owner check when adding a helper to a plot. |
| plot.command.admin.border | Bypasses the owner check when changing the plot border block. |
| plot.command.admin.clear | Bypasses the owner check when clearing a plot. |
| plot.command.admin.deletehome | Bypasses the owner check when deleting the spawn point of a plot |
| plot.command.admin.deny | Bypasses the owner check when denying a player from a plot. |
| plot.command.admin.dispose | Bypasses the owner check when disposing a plot. |
| plot.command.admin.info | Bypasses the empty check when seeing the information of a plot. |
| plot.command.admin.kick | Bypasses the owner check when kicking a player from a plot. |
| plot.command.admin.merge | Bypasses the owner check when merging a plot. |
| plot.command.admin.removehelper | Bypasses the owner check when removing a helper from a plot. |
| plot.command.admin.sethome | Bypasses the owner check when setting the spawn point of a plot. |
| plot.command.admin.setowner | Bypasses the owner check, self check and player limit when setting the owner of a plot. |
| plot.command.admin.config | Bypasses the owner check when setting the configuration of a plot. |
| plot.command.admin.undeny | Bypasses the owner check when undenying a player from a plot. |
| plot.command.admin.unlink | Bypasses the owner check when unlinking a plot. |
| plot.command.admin.wall | Bypasses the owner check when changing the plot wall block. |
| plot.admin.bypass.deny | Bypasses the denial of a player from a plot. |
| plot.admin.bypass.kick | Bypasses the kick of a player from a plot. |
| plot.admin.interact | Allows you to interact with blocks on the road. |
| plot.admin.damage | Allows you to damage players on roads or if pvp is disabled on the plot. |
| plot.admin.bucket.fill | Allows you to fill up buckets from the road. |
| plot.admin.bucket.emtpy | Allows you to empty buckets from the road. |
| plot.admin.break | Allows you to break blocks on the road. |
| plot.admin.place | Allows you to place blocks on the road. |
| plot.merge.unlimited | Allows you to merge unlimited plots. |
| plot.merge.limit.\<any number> | Limits the player to only merge up to the given amount of plots. |
| plot.limit.\<any number> | Limits the player to only claim up to the given amount of plots. |
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ms.kevi</groupId>
<artifactId>plotplugin</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class SetOwnerCommand extends SubCommand {

public SetOwnerCommand(PlotPlugin plugin, PlotCommand parent) {
super(plugin, parent, "setowner");
this.setPermission("plot.command.setowner");
this.addParameter(CommandParameter.newType("player", CommandParamType.TARGET));
}

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

if(targetName.equalsIgnoreCase(player.getName()) && !player.hasPermission("plot.command.admin.setowner")) {
player.sendMessage(this.translate(player, TranslationKey.PLAYER_SELF));
if(!plot.isOwner(player.getUniqueId()) && !player.hasPermission("plot.command.admin.setowner")) {
player.sendMessage(this.translate(player, TranslationKey.NO_PLOT_OWNER));
return false;
}

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

if(!player.hasPermission("plot.command.admin.setowner") && !plot.isOwner(player.getUniqueId())) {
player.sendMessage(this.translate(player, TranslationKey.NO_PLOT_OWNER));
if(target == null) {
player.sendMessage(this.translate(player, TranslationKey.PLAYER_NOT_ONLINE));
return false;
}

if(targetName.equalsIgnoreCase(player.getName()) && !player.hasPermission("plot.command.admin.setowner")) {
player.sendMessage(this.translate(player, TranslationKey.PLAYER_SELF));
return false;
}

final int ownedPlots = plotManager.getPlotsByOwner(targetId).size();
if(!target.isOp() && !player.hasPermission("plot.command.admin.setowner")) {
int maxLimit = -1;
for(String permission : target.getEffectivePermissions().keySet()) {
if(permission.startsWith("plot.limit.")) {
try {
final String limitStr = permission.substring("plot.limit.".length());
if(limitStr.isBlank()) continue;
final int limit = Integer.parseInt(limitStr);

if(limit > maxLimit) maxLimit = limit;
} catch(NumberFormatException ignored) {
}
}
}

if(maxLimit > 0 && ownedPlots >= maxLimit) {
player.sendMessage(this.translate(player, TranslationKey.SETOWNER_FAILURE_TOO_MANY));
return false;
}
}

plot.setOwner(targetId);
plotManager.savePlots();
if(target != null)
target.sendMessage(this.translate(player, TranslationKey.SETOWNER_SUCCESS_TARGET, plot.getId()));

target.sendMessage(this.translate(target, TranslationKey.SETOWNER_SUCCESS_TARGET, plot.getId()));
player.sendMessage(this.translate(player, TranslationKey.SETOWNER_SUCCESS, this.plugin.getCorrectName(targetId)));
return true;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/ms/kevi/plotplugin/lang/TranslationKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public enum TranslationKey {
RELOAD_SUCCESS,
REMOVED_HELPER,
SETHOME_SUCCESS,
SETOWNER_FAILURE_TOO_MANY,
SETOWNER_SUCCESS,
SETOWNER_SUCCESS_TARGET,
SETROADS_FINISHED,
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/de_DE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ info-end=&7====== &6Grundstücks Info &7======
info-failure=&6&lCitybuild &8&l» &r&cDieses Grundstück gehört keiner Person.
removed-helper=&6&lCitybuild &8&l» &r&6{0}&r&a ist nun kein Helfer mehr!
no-helper=&6&lCitybuild &8&l» &r&6{0}&r&c ist kein Helfer!
setowner-failure-too-many=&6&lCitybuild &8&l» &r&cDieser Spieler besitzt bereits die maximale Anzahl an Grundstücken!
setowner-success-target=&6&lCitybuild &8&l» &r&aDu wurdest zum Besitzer des Grundstückes &6{0}&r&a ernannt!
setowner-success=&6&lCitybuild &8&l» &r&6{0}&r&a ist nun Besitzer von diesem Grundstück!
undeny-success=&6&lCitybuild &8&l» &r&6{0}&r&a darf nun dein Grundstück wieder betreten!
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/en_US.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ info-end=&7====== &6Plot Info &7======
info-failure=&6&lCitybuild &8&l» &r&cThis plot is not owned by a player.
removed-helper=&6&lCitybuild &8&l» &r&6{0}&r&a is now no longer a helper!
no-helper=&6&lCitybuild &8&l» &r&6{0}&r&c is not a helper!
setowner-failure-too-many=&6&lCitybuild &8&l» &r&cThis player already has the maximum amount of plots!
setowner-success-target=&6&lCitybuild &8&l» &r&aYou have been appointed the owner of the plot &6{0}&r&a!
setowner-success=&6&lCitybuild &8&l» &r&6{0}&r&a is now owner of this plot!
undeny-success=&6&lCitybuild &8&l» &r&6{0}&r&a may now enter your plot again!
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Plots
version: "1.1.0"
version: "1.1.1"
api: [ "1.0.13" ]
author: Kevims
main: ms.kevi.plotplugin.PlotPlugin

0 comments on commit 61010ec

Please sign in to comment.