Changes the ClaimOneLocation command to make it work

This commit is contained in:
Kristian Knarvik 2023-08-26 14:49:20 +02:00
parent 461528d5af
commit 747e38c60d
4 changed files with 25 additions and 26 deletions

View File

@ -11,6 +11,6 @@ public class CmdFactionsClaim extends FactionsCommand {
public CmdFactionsSetSquare cmdFactionsClaimSquare = new CmdFactionsSetSquare(true);
public CmdFactionsSetCircle cmdFactionsClaimCircle = new CmdFactionsSetCircle(true);
public CmdFactionsSetAll cmdFactionsClaimAll = new CmdFactionsSetAll(true);
public CmdFactionsSetOneLocation cmdFactionsSetOneLocation = new CmdFactionsSetOneLocation(true);
public CmdFactionsSetOneLocation cmdFactionsClaimOneLocation = new CmdFactionsSetOneLocation(true);
}

View File

@ -1,16 +1,12 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.type.TypeFaction;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.cmd.type.TypeMPlayer;
import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.FactionColl;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.command.type.TypeWorld;
import com.massivecraft.massivecore.command.type.primitive.TypeDouble;
import com.massivecraft.massivecore.command.requirement.RequirementIsntPlayer;
import com.massivecraft.massivecore.ps.PS;
import org.bukkit.Location;
import org.bukkit.World;
import java.util.Collections;
import java.util.Set;
@ -32,32 +28,34 @@ public class CmdFactionsSetOneLocation extends FactionsCommand {
// Aliases
this.addAliases("onel");
this.addParameter(TypeWorld.get(), true, "world").setDesc("the world of the location");
this.addParameter(TypeDouble.get(), true, "x").setDesc("the x coordinate of the location");
this.addParameter(TypeDouble.get(), true, "y").setDesc("the y coordinate of the location");
this.addParameter(TypeDouble.get(), true, "z").setDesc("the z coordinate of the location");
this.addParameter(TypeFaction.get(), "faction").setDesc("you");
this.addParameter(TypeMPlayer.get(), true, "player").setDesc("the player to claim for");
// Requirements
Perm perm = claim ? Perm.CLAIM_ONE : Perm.UNCLAIM_ONE;
this.addRequirements(RequirementHasPerm.get(perm));
this.addRequirements(RequirementIsntPlayer.get());
}
@Override
public void perform() throws MassiveException {
// Args
World world = this.readArgAt(0);
double x = this.readArgAt(1);
double y = this.readArgAt(2);
double z = this.readArgAt(3);
final Faction newFaction = this.readArgAt(4);
MPlayer player = this.readArgAt(0);
Set<PS> chunks = Collections.singleton(PS.valueOf(new Location(world, x, y, z)).getChunk());
if (!player.hasFaction()) {
throw new MassiveException();
}
PS chunk = PS.valueOf(player.getPlayer().getLocation()).getChunk(true);
Set<PS> chunks = Collections.singleton(chunk);
// Apply / Inform
if (this.claim) {
msender.tryClaim(newFaction, chunks);
if (!BoardColl.get().getFactionAt(chunk).isNone()) {
throw new MassiveException().setMsg("<b>Only <h>wilderness<b> can be claimed using this method.");
}
msender.tryClaim(player.getFaction(), chunks);
} else {
if (!BoardColl.get().getFactionAt(chunk).equals(player.getFaction())) {
throw new MassiveException();
}
msender.tryClaim(FactionColl.get().getNone(), chunks);
}
}

View File

@ -11,6 +11,6 @@ public class CmdFactionsUnclaim extends FactionsCommand {
public CmdFactionsSetSquare cmdFactionsUnclaimSquare = new CmdFactionsSetSquare(false);
public CmdFactionsSetCircle cmdFactionsUnclaimCircle = new CmdFactionsSetCircle(false);
public CmdFactionsSetAll cmdFactionsUnclaimAll = new CmdFactionsSetAll(false);
public CmdFactionsSetOneLocation cmdFactionsSetOneLocation = new CmdFactionsSetOneLocation(false);
public CmdFactionsSetOneLocation cmdFactionsUnclaimOneLocation = new CmdFactionsSetOneLocation(false);
}

View File

@ -16,6 +16,7 @@ import com.massivecraft.massivecore.mixin.MixinWorld;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.Txt;
import org.bukkit.ChatColor;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -59,8 +60,8 @@ public class EngineChunkChange extends Engine {
final Set<Faction> currentFactions = currentFactionChunks.keySet();
final Set<PS> chunks = event.getChunks();
// Override Mode? Sure!
if (mplayer.isOverriding()) {
// Override Mode or console? Sure!
if (mplayer.isOverriding() || event.getSender() instanceof ConsoleCommandSender) {
return;
}