Last active
August 25, 2019 10:05
-
-
Save AlexandreGerault/fcfa434d78ce15e870f35ef58efa7192 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.github.alexandregerault.battleroyale.commands; | |
import java.util.Optional; | |
import org.spongepowered.api.command.CommandException; | |
import org.spongepowered.api.command.CommandResult; | |
import org.spongepowered.api.command.CommandSource; | |
import org.spongepowered.api.command.args.CommandContext; | |
import org.spongepowered.api.command.spec.CommandExecutor; | |
import org.spongepowered.api.entity.living.player.Player; | |
import org.spongepowered.api.text.Text; | |
import org.spongepowered.api.text.format.TextColors; | |
import com.flowpowered.math.vector.Vector3i; | |
import io.github.alexandregerault.battleroyale.data.ClipboardKeys; | |
import org.spongepowered.api.world.schematic.Schematic; | |
public class CopySelectionCommand implements CommandExecutor { | |
public CopySelectionCommand () {} | |
@Override | |
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { | |
if (!(src instanceof Player)) { | |
src.sendMessage(Text.of(TextColors.RED, "Player command only")); | |
return CommandResult.success(); | |
} | |
Player player = (Player) src; | |
Optional<Vector3i> optPositionOne = player.get(ClipboardKeys.CORNER_ONE).get(); | |
Optional<Vector3i> optPositionTwo = player.get(ClipboardKeys.CORNER_TWO).get(); | |
if (!optPositionOne.isPresent() || !optPositionTwo.isPresent()) { | |
player.sendMessage(Text.of(TextColors.RED, "Error, you must have selected two corners with golden hoe")); | |
return CommandResult.success(); | |
} | |
Vector3i positionOne = optPositionOne.get(); | |
Vector3i positionTwo = optPositionTwo.get(); | |
Vector3i origin = new Vector3i( | |
( positionOne.getX() + positionTwo.getX() )/2, | |
positionOne.min(positionTwo).getY(), | |
( positionOne.getZ() + positionTwo.getZ() )/2 | |
); | |
Schematic volume = Schematic.builder().volume(player.getWorld().getExtentView(positionOne, positionTwo)).build(); | |
player.offer(ClipboardKeys.CLIPBOARD, Optional.of(volume)); | |
player.sendMessage(Text.of(TextColors.LIGHT_PURPLE, "Copying from " + positionOne.toString() + " to " + positionTwo.toString() +"! Clipboard updated.")); | |
return CommandResult.success(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.github.alexandregerault.battleroyale.commands; | |
import java.util.Optional; | |
import org.spongepowered.api.command.CommandException; | |
import org.spongepowered.api.command.CommandResult; | |
import org.spongepowered.api.command.CommandSource; | |
import org.spongepowered.api.command.args.CommandContext; | |
import org.spongepowered.api.command.spec.CommandExecutor; | |
import org.spongepowered.api.entity.living.player.Player; | |
import org.spongepowered.api.text.Text; | |
import org.spongepowered.api.text.format.TextColors; | |
import com.flowpowered.math.vector.Vector3i; | |
import io.github.alexandregerault.battleroyale.data.ClipboardKeys; | |
public class CopySelectionCommand implements CommandExecutor { | |
public CopySelectionCommand () {} | |
@Override | |
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { | |
if (!(src instanceof Player)) { | |
src.sendMessage(Text.of(TextColors.RED, "Player command only")); | |
return CommandResult.success(); | |
} | |
Player player = (Player) src; | |
Optional<Vector3i> optPositionOne = player.get(ClipboardKeys.CORNER_ONE).get(); | |
Optional<Vector3i> optPositionTwo = player.get(ClipboardKeys.CORNER_TWO).get(); | |
if (!optPositionOne.isPresent() || !optPositionTwo.isPresent()) { | |
player.sendMessage(Text.of(TextColors.RED, "Error, you must have selected two corners with golden hoe")); | |
return CommandResult.success(); | |
} | |
Vector3i positionOne = optPositionOne.get(); | |
Vector3i positionTwo = optPositionTwo.get(); | |
Vector3i origin = new Vector3i( | |
( positionOne.getX() + positionTwo.getX() )/2, | |
positionOne.min(positionTwo).getY(), | |
( positionOne.getZ() + positionTwo.getZ() )/2 | |
); | |
player.offer(ClipboardKeys.CLIPBOARD, Optional.of(player.getWorld().createArchetypeVolume(positionOne.min(positionTwo), positionOne.max(positionTwo), origin))); | |
player.sendMessage(Text.of(TextColors.LIGHT_PURPLE, "Copying from " + positionOne.toString() + " to " + positionTwo.toString() +"! Clipboard updated.")); | |
return CommandResult.success(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[23:58:55 ERROR] [Sponge]: Error occurred while executing command 'brp cp' for source EntityPlayerMP['Gunnolfson'/239, l='world', x=-609,29, y=69,00, z=531,65]: The box is degenerate on y | |
java.lang.IllegalArgumentException: The box is degenerate on y | |
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:122) ~[minecraft_server.1.12.2.jar:?] | |
at org.spongepowered.api.util.AABB.<init>(AABB.java:93) ~[AABB.class:1.12.2-7.1.6] | |
at org.spongepowered.api.util.AABB.<init>(AABB.java:62) ~[AABB.class:1.12.2-7.1.6] | |
at org.spongepowered.common.world.extent.DefaultedExtent.createArchetypeVolume(DefaultedExtent.java:196) ~[DefaultedExtent.class:1.12.2-7.1.6] | |
at io.github.alexandregerault.battleroyale.commands.CopySelectionCommand.execute(CopySelectionCommand.java:48) ~[CopySelectionCommand.class:?] | |
at org.spongepowered.api.command.args.ChildCommandElementExecutor.execute(ChildCommandElementExecutor.java:255) ~[ChildCommandElementExecutor.class:1.12.2-7.1.6] | |
at org.spongepowered.api.command.spec.CommandSpec.process(CommandSpec.java:388) ~[CommandSpec.class:1.12.2-7.1.6] | |
at org.spongepowered.api.command.dispatcher.SimpleDispatcher.process(SimpleDispatcher.java:340) ~[SimpleDispatcher.class:1.12.2-7.1.6] | |
at org.spongepowered.common.command.SpongeCommandManager.process(SpongeCommandManager.java:337) ~[SpongeCommandManager.class:1.12.2-7.1.6] | |
at net.minecraft.command.ServerCommandManager.func_71556_a(SourceFile:1156) ~[dh.class:?] | |
at net.minecraft.network.NetHandlerPlayServer.func_147361_d(SourceFile:855) ~[pa.class:?] | |
at net.minecraft.network.NetHandlerPlayServer.func_147354_a(SourceFile:842) ~[pa.class:?] | |
at net.minecraft.network.play.client.CPacketChatMessage.func_148833_a(SourceFile:37) ~[la.class:?] | |
at net.minecraft.network.play.client.CPacketChatMessage.func_148833_a(SourceFile:9) ~[la.class:?] | |
at org.spongepowered.common.event.tracking.phase.packet.PacketPhaseUtil.onProcessPacket(PacketPhaseUtil.java:193) ~[PacketPhaseUtil.class:1.12.2-7.1.6] | |
at net.minecraft.network.PacketThreadUtil$1.redirect$onProcessPacket$zlg000(SourceFile:539) ~[hv$1.class:?] | |
at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13) ~[hv$1.class:?] | |
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_222] | |
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_222] | |
at net.minecraft.util.Util.func_181617_a(SourceFile:46) ~[h.class:?] | |
at org.spongepowered.common.SpongeImplHooks.onUtilRunTask(SpongeImplHooks.java:307) ~[SpongeImplHooks.class:1.12.2-7.1.6] | |
at net.minecraft.server.MinecraftServer.redirect$onRun$zjk000(SourceFile:4130) ~[MinecraftServer.class:?] | |
at net.minecraft.server.MinecraftServer.func_71190_q(SourceFile:1581) ~[MinecraftServer.class:?] | |
at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(SourceFile:349) ~[nz.class:?] | |
at net.minecraft.server.MinecraftServer.func_71217_p(SourceFile:560) ~[MinecraftServer.class:?] | |
at net.minecraft.server.MinecraftServer.run(SourceFile:464) ~[MinecraftServer.class:?] | |
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_222] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vector3i positionOne = optPositionOne.get(); | |
Vector3i positionTwo = optPositionTwo.get(); | |
if (positionOne.getX() == positionTwo.getX()) { | |
positionTwo = positionTwo.add(1,0,0); | |
} | |
if (positionOne.getY() == positionTwo.getY()) { | |
positionTwo = positionTwo.add(0,1,0); | |
} | |
if (positionOne.getZ() == positionTwo.getZ()) { | |
positionTwo = positionTwo.add(0,0,1); | |
} | |
Vector3i origin = new Vector3i( | |
( positionOne.getX() + positionTwo.getX() )/2, | |
positionOne.min(positionTwo).getY(), | |
( positionOne.getZ() + positionTwo.getZ() )/2 | |
); | |
ArchetypeVolume volume = player.getWorld().createArchetypeVolume(positionOne.min(positionTwo), positionOne.max(positionTwo), origin); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment