Skip to content

Commit

Permalink
Update 1.1.2 (#14)
Browse files Browse the repository at this point in the history
Changes of this update:
- `/plot clear` and `/plot dispose` do not unlink all connected merges plots anymore.
- `/plot` subcommands can now be shown client-side.

Fixes of this update:
- `/plot setroads` y-coordinate calucalation
  • Loading branch information
KCodeYT authored Aug 2, 2022
1 parent 61010ec commit 2617312
Show file tree
Hide file tree
Showing 32 changed files with 308 additions and 137 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ jobs:
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Delete old snapshot
uses: dev-drprasad/[email protected]
with:
delete_release: true
tag_name: ${{env.VER}}-SNAPSHOT
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Create Release
id: create_release
uses: actions/create-release@v1
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Other Permissions
| 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.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.unlimited | Allows you to claim unlimited 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.1</version>
<version>1.1.2</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/ms/kevi/plotplugin/PlotPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
import ms.kevi.plotplugin.manager.PlayerManager;
import ms.kevi.plotplugin.manager.PlayerNameFunction;
import ms.kevi.plotplugin.manager.PlotManager;
import ms.kevi.plotplugin.util.BlockEntry;
import ms.kevi.plotplugin.util.PlotLevelRegistration;
import ms.kevi.plotplugin.util.PlotLevelSettings;
import ms.kevi.plotplugin.util.Utils;
import ms.kevi.plotplugin.util.BlockEntry;
import ms.kevi.plotplugin.util.async.TaskExecutor;

import java.io.BufferedReader;
Expand Down Expand Up @@ -82,6 +82,9 @@ public class PlotPlugin extends PluginBase {
@Getter
private int plotsPerPage = 5;

@Getter
private boolean showCommandParams = true;

@Getter
private boolean addOtherCommands = true;

Expand Down Expand Up @@ -136,6 +139,13 @@ public void onEnable() {

this.plotsPerPage = config.getInt("plots_per_page");

if(!config.exists("show_command_params")) {
config.set("show_command_params", this.showCommandParams);
config.save();
}

this.showCommandParams = config.getBoolean("show_command_params");

if(!config.exists("add_other_commands")) {
config.set("add_other_commands", this.addOtherCommands);
config.save();
Expand Down
41 changes: 38 additions & 3 deletions src/main/java/ms/kevi/plotplugin/command/PlotCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
import cn.nukkit.Player;
import cn.nukkit.command.Command;
import cn.nukkit.command.CommandSender;
import cn.nukkit.command.data.*;
import ms.kevi.plotplugin.PlotPlugin;
import ms.kevi.plotplugin.command.defaults.*;
import ms.kevi.plotplugin.command.other.BorderCommand;
import ms.kevi.plotplugin.command.other.WallCommand;
import ms.kevi.plotplugin.lang.TranslationKey;

import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.*;

/**
* @author Kevims KCodeYT
Expand Down Expand Up @@ -73,6 +72,24 @@ public PlotCommand(PlotPlugin plugin) {
this.subCommands.add(new BorderCommand(this.plugin, this));
this.subCommands.add(new WallCommand(this.plugin, this));
}

if(this.plugin.isShowCommandParams()) {
this.commandParameters.clear();

for(SubCommand subCommand : this.subCommands) {
final Set<CommandParameter> parameterSet = subCommand.getParameters();

for(String alias : subCommand.getAliases()) {
final CommandParameter[] parameters = new CommandParameter[parameterSet.size() + 1];
parameters[0] = CommandParameter.newEnum("subcommand", false, new CommandEnum("PlotSubcommand" + alias, alias));

int i = 1;
for(CommandParameter parameter : parameterSet) parameters[i++] = parameter;

this.commandParameters.put(alias, parameters);
}
}
}
}

@Override
Expand Down Expand Up @@ -107,4 +124,22 @@ protected String translate(Player player, TranslationKey key, Object... params)
return this.plugin.getLanguage().translate(player, key, params);
}

@Override
public CommandDataVersions generateCustomCommandData(Player player) {
final CommandDataVersions versions = super.generateCustomCommandData(player);
final CommandData commandData = versions.versions.get(0);

final Map<String, CommandOverload> overloads = new HashMap<>(commandData.overloads);
for(Map.Entry<String, CommandOverload> entry : overloads.entrySet()) {
for(SubCommand subCommand : this.subCommands) {
if(subCommand.getAliases().contains(entry.getKey())) {
if(!subCommand.hasPermission(player)) commandData.overloads.remove(entry.getKey());
break;
}
}
}

return versions;
}

}
4 changes: 2 additions & 2 deletions src/main/java/ms/kevi/plotplugin/command/SubCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

import cn.nukkit.Player;
import cn.nukkit.command.data.CommandParameter;
import ms.kevi.plotplugin.PlotPlugin;
import ms.kevi.plotplugin.lang.TranslationKey;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import ms.kevi.plotplugin.PlotPlugin;
import ms.kevi.plotplugin.lang.TranslationKey;

import java.util.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public boolean execute(Player player, String[] args) {
}

final int ownedPlots = plotManager.getPlotsByOwner(player.getUniqueId()).size();
if(!player.isOp()) {
if(!player.hasPermission("plot.limit.unlimited")) {
int maxLimit = -1;
for(String permission : player.getEffectivePermissions().keySet()) {
if(permission.startsWith("plot.limit.")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public boolean execute(Player player, String[] args) {
}

final int ownedPlots = plotManager.getPlotsByOwner(player.getUniqueId()).size();
if(!player.isOp()) {
if(!player.hasPermission("plot.limit.unlimited")) {
int maxLimit = -1;
for(String permission : player.getEffectivePermissions().keySet()) {
if(permission.startsWith("plot.limit.")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,19 @@ public boolean execute(Player player, String[] args) {
return false;
}

if(player.hasPermission("plot.command.admin.dispose") || plot.isOwner(player.getUniqueId())) {
plotManager.disposePlot(plot);
plotManager.savePlots();
player.sendMessage(this.translate(player, TranslationKey.DISPOSE_SUCCESS));
return true;
} else {
if(!plot.isOwner(player.getUniqueId()) && !player.hasPermission("plot.command.admin.dispose")) {
player.sendMessage(this.translate(player, TranslationKey.DISPOSE_FAILURE));
return false;
}

if(!plotManager.disposePlot(plot)) {
player.sendMessage(this.translate(player, TranslationKey.DISPOSE_FAILURE_COULD_NOT_DISPOSE));
return false;
}

plotManager.savePlots();
player.sendMessage(this.translate(player, TranslationKey.DISPOSE_SUCCESS));
return true;
}

}
73 changes: 32 additions & 41 deletions src/main/java/ms/kevi/plotplugin/command/defaults/MergeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,64 +52,55 @@ public boolean execute(Player player, String[] args) {
final int dir = (NukkitMath.floorDouble((player.getYaw() * 4 / 360) + 0.5) - 2) & 3;
final Set<Plot> plotsToMerge = plotManager.calculatePlotsToMerge(plot, dir);

boolean isOwner = player.hasPermission("plot.command.admin.merge");
if(!isOwner) {
isOwner = true;
if(!player.hasPermission("plot.command.admin.merge")) {
for(Plot plotToMerge : plotsToMerge) {
if(!plotToMerge.isOwner(player.getUniqueId())) {
isOwner = false;
break;
player.sendMessage(this.translate(player, TranslationKey.MERGE_FAILURE_OWNER));
return false;
}
}
}

if(isOwner) {
if(!player.hasPermission("plot.merge.unlimited") && !player.isOp()) {
if(!player.isOp()) {
int maxLimit = -1;
for(String permission : player.getEffectivePermissions().keySet()) {
if(permission.startsWith("plot.merge.limit.")) {
try {
final String limitStr = permission.substring("plot.merge.limit.".length());
if(limitStr.isBlank()) continue;
final int limit = Integer.parseInt(limitStr);

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

if(maxLimit > 0 && plotsToMerge.size() > maxLimit) {
player.sendMessage(this.translate(player, TranslationKey.MERGE_FAILURE_TOO_MANY, plotsToMerge.size()));
return false;
if(!player.hasPermission("plot.merge.limit.unlimited")) {
int maxLimit = -1;
for(String permission : player.getEffectivePermissions().keySet()) {
if(permission.startsWith("plot.merge.limit.")) {
try {
final String limitStr = permission.substring("plot.merge.limit.".length());
if(limitStr.isBlank()) continue;
final int limit = Integer.parseInt(limitStr);

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

if(plot.isMerged(dir)) {
player.sendMessage(this.translate(player, TranslationKey.MERGE_FAILURE_ALREADY_MERGED));
if(maxLimit > 0 && plotsToMerge.size() > maxLimit) {
player.sendMessage(this.translate(player, TranslationKey.MERGE_FAILURE_TOO_MANY, plotsToMerge.size()));
return false;
}
}

final PlotPreMergeEvent plotPreMergeEvent = new PlotPreMergeEvent(player, plot, dir, plotsToMerge);
this.plugin.getServer().getPluginManager().callEvent(plotPreMergeEvent);
if(plotPreMergeEvent.isCancelled()) return false;

if(!plotManager.startMerge(plot, plotsToMerge)) {
player.sendMessage(this.translate(player, TranslationKey.MERGE_FAILURE_NO_PLOTS_FOUND));
return false;
}
if(plot.isMerged(dir)) {
player.sendMessage(this.translate(player, TranslationKey.MERGE_FAILURE_ALREADY_MERGED));
return false;
}

final PlotMergeEvent plotMergeEvent = new PlotMergeEvent(player, plot, plotsToMerge);
this.plugin.getServer().getPluginManager().callEvent(plotMergeEvent);
final PlotPreMergeEvent plotPreMergeEvent = new PlotPreMergeEvent(player, plot, dir, plotsToMerge);
this.plugin.getServer().getPluginManager().callEvent(plotPreMergeEvent);
if(plotPreMergeEvent.isCancelled()) return false;

player.sendMessage(this.translate(player, TranslationKey.MERGE_SUCCESS));
return true;
} else {
player.sendMessage(this.translate(player, TranslationKey.MERGE_FAILURE_OWNER));
if(!plotManager.startMerge(plot, plotsToMerge)) {
player.sendMessage(this.translate(player, TranslationKey.MERGE_FAILURE_NO_PLOTS_FOUND));
return false;
}

final PlotMergeEvent plotMergeEvent = new PlotMergeEvent(player, plot, plotsToMerge);
this.plugin.getServer().getPluginManager().callEvent(plotMergeEvent);

player.sendMessage(this.translate(player, TranslationKey.MERGE_SUCCESS));
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public boolean execute(Player player, String[] args) {
}

final int ownedPlots = plotManager.getPlotsByOwner(targetId).size();
if(!target.isOp() && !player.hasPermission("plot.command.admin.setowner")) {
if(!target.hasPermission("plot.limit.unlimited") && !player.hasPermission("plot.command.admin.setowner")) {
int maxLimit = -1;
for(String permission : target.getEffectivePermissions().keySet()) {
if(permission.startsWith("plot.limit.")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public boolean execute(Player player, String[] args) {

for(int y = startPos.getFloorY(); y <= endPos.getFloorY(); y++) {
final Vector3 defaultBlockVector = new Vector3(x, y, z);
final Vector3 blockVector = new Vector3(x - startPos.getFloorX(), y, z - startPos.getFloorZ());
final Vector3 blockVector = new Vector3(x - startPos.getFloorX(), y - startPos.getFloorY(), z - startPos.getFloorZ());

final BlockState blockState0 = level.getBlockStateAt(x, y, z, 0);
final BlockState blockState1 = level.getBlockStateAt(x, y, z, 1);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ms/kevi/plotplugin/event/PlotClaimEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import cn.nukkit.Player;
import cn.nukkit.event.HandlerList;
import ms.kevi.plotplugin.util.Plot;
import lombok.Getter;
import ms.kevi.plotplugin.util.Plot;

/**
* @author Kevims KCodeYT
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ms/kevi/plotplugin/event/PlotClearEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import cn.nukkit.event.Cancellable;
import cn.nukkit.event.HandlerList;
import ms.kevi.plotplugin.util.Plot;
import lombok.Getter;
import ms.kevi.plotplugin.util.Plot;

/**
* @author Kevims KCodeYT
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ms/kevi/plotplugin/event/PlotEnterEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import cn.nukkit.Player;
import cn.nukkit.event.Cancellable;
import cn.nukkit.event.HandlerList;
import ms.kevi.plotplugin.util.Plot;
import lombok.Getter;
import ms.kevi.plotplugin.util.Plot;

/**
* @author Kevims KCodeYT
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ms/kevi/plotplugin/event/PlotEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package ms.kevi.plotplugin.event;

import cn.nukkit.event.Event;
import ms.kevi.plotplugin.util.Plot;
import lombok.AllArgsConstructor;
import lombok.Getter;
import ms.kevi.plotplugin.util.Plot;

/**
* @author Kevims KCodeYT
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ms/kevi/plotplugin/event/PlotLeaveEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import cn.nukkit.Player;
import cn.nukkit.event.Cancellable;
import cn.nukkit.event.HandlerList;
import ms.kevi.plotplugin.util.Plot;
import lombok.Getter;
import ms.kevi.plotplugin.util.Plot;

/**
* @author Kevims KCodeYT
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ms/kevi/plotplugin/event/PlotPreClaimEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import cn.nukkit.Player;
import cn.nukkit.event.Cancellable;
import cn.nukkit.event.HandlerList;
import ms.kevi.plotplugin.util.Plot;
import ms.kevi.plotplugin.util.Waiter;
import lombok.Getter;
import lombok.Setter;
import ms.kevi.plotplugin.util.Plot;
import ms.kevi.plotplugin.util.Waiter;

/**
* @author Kevims KCodeYT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import cn.nukkit.Player;
import cn.nukkit.event.Cancellable;
import cn.nukkit.event.HandlerList;
import ms.kevi.plotplugin.util.Plot;
import lombok.Getter;
import ms.kevi.plotplugin.util.Plot;

import java.util.Set;

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 @@ -51,6 +51,7 @@ public enum TranslationKey {
DENY_FAILURE,
DENY_SUCCESS,
DISPOSE_FAILURE,
DISPOSE_FAILURE_COULD_NOT_DISPOSE,
DISPOSE_SUCCESS,
GENERATE_DIMENSION,
GENERATE_FAILURE,
Expand Down
Loading

0 comments on commit 2617312

Please sign in to comment.