mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-07-04 06:34:42 +02:00
Add persistent meta, and added plot grants
This commit is contained in:
@ -28,11 +28,7 @@ import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@ -104,8 +100,21 @@ public class Claim extends SubCommand {
|
||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(loc.getWorld(), plr);
|
||||
|
||||
boolean removeGrantedPlot = false;
|
||||
|
||||
if (currentPlots >= MainUtil.getAllowedPlots(plr)) {
|
||||
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
||||
if (plr.hasPersistentMeta("grantedPlots")) {
|
||||
int grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots"));
|
||||
if (grantedPlots < 1) {
|
||||
plr.removePersistentMeta("grantedPlots");
|
||||
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
||||
} else {
|
||||
removeGrantedPlot = true;
|
||||
}
|
||||
} else {
|
||||
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
||||
}
|
||||
}
|
||||
if (!MainUtil.canClaim(plr, plot)) {
|
||||
return sendMessage(plr, C.PLOT_IS_CLAIMED);
|
||||
@ -121,6 +130,11 @@ public class Claim extends SubCommand {
|
||||
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
||||
}
|
||||
}
|
||||
if (removeGrantedPlot) {
|
||||
int grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots"));
|
||||
plr.setPersistentMeta("grantedPlots", ByteArrayUtilities.integerToBytes(grantedPlots - 1));
|
||||
sendMessage(plr, C.REMOVED_GRANTED_PLOT, "" + (grantedPlots - 1));
|
||||
}
|
||||
if (!schematic.equals("")) {
|
||||
if (world.SCHEMATIC_CLAIM_SPECIFY) {
|
||||
if (!world.SCHEMATICS.contains(schematic.toLowerCase())) {
|
||||
|
@ -0,0 +1,71 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.ByteArrayUtilities;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "grant",
|
||||
category = CommandCategory.CLAIMING,
|
||||
usage = "/plot grant <check|add> [...]",
|
||||
permission = "plots.grant",
|
||||
requiredType = RequiredType.NONE
|
||||
)
|
||||
public class Grant extends SubCommand {
|
||||
|
||||
void grantPlayer(PlotPlayer plr, String enteredName) {
|
||||
PlotPlayer player = UUIDHandler.getPlayer(enteredName);
|
||||
if (player == null) {
|
||||
sendMessage(plr, C.GRANTED_PLOT_FAILED, "Player not found");
|
||||
} else {
|
||||
int n = 1;
|
||||
if (player.hasPersistentMeta("grantedPlots")) {
|
||||
n += ByteArrayUtilities.bytesToInteger(player.getPersistentMeta("grantedPlots"));
|
||||
}
|
||||
player.setPersistentMeta("grantedPlots", ByteArrayUtilities.integerToBytes(n));
|
||||
sendMessage(plr, C.GRANTED_PLOT, enteredName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(PlotPlayer plr, String[] arguments) {
|
||||
if (plr == null || plr instanceof ConsolePlayer) {
|
||||
if (arguments.length != 1) {
|
||||
MainUtil.sendMessage(null, "Usage: /plot grant <Player>");
|
||||
} else {
|
||||
grantPlayer(null, arguments[0]);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (arguments.length < 1) {
|
||||
arguments = new String[] { "check" };
|
||||
}
|
||||
switch (arguments[0]) {
|
||||
case "check": {
|
||||
int grantedPlots = 0;
|
||||
if (plr.hasPersistentMeta("grantedPlots")) {
|
||||
grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots"));
|
||||
}
|
||||
return sendMessage(plr, C.GRANTED_PLOTS, "" + grantedPlots);
|
||||
}
|
||||
case "add": {
|
||||
if (!plr.hasPermission("plots.grant.add")) {
|
||||
return sendMessage(plr, C.NO_PERMISSION, "plots.grant.add");
|
||||
}
|
||||
if (arguments.length < 2) {
|
||||
plr.sendMessage("&cUsage: /plot grant add <player>");
|
||||
} else {
|
||||
grantPlayer(plr, arguments[1]);
|
||||
}
|
||||
} break;
|
||||
default: return onCommand(plr, new String[] { "check" });
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -129,6 +129,7 @@ public class MainCommand extends CommandManager<PlotPlayer> {
|
||||
createCommand(new Continue());
|
||||
createCommand(new BO3());
|
||||
createCommand(new Middle());
|
||||
createCommand(new Grant());
|
||||
// set commands
|
||||
createCommand(new Owner());
|
||||
createCommand(new Desc());
|
||||
|
Reference in New Issue
Block a user