-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
281 additions
and
50 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package carpet.commands; | ||
|
||
import carpet.CarpetSettings; | ||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.mojang.brigadier.builder.LiteralArgumentBuilder; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import net.minecraft.command.CommandSource; | ||
import net.minecraft.command.ISuggestionProvider; | ||
import net.minecraft.command.arguments.EntityArgument; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.init.MobEffects; | ||
import net.minecraft.potion.PotionEffect; | ||
import net.minecraft.world.GameType; | ||
|
||
import static com.mojang.brigadier.arguments.StringArgumentType.getString; | ||
import static com.mojang.brigadier.arguments.StringArgumentType.word; | ||
import static net.minecraft.command.Commands.argument; | ||
import static net.minecraft.command.Commands.literal; | ||
|
||
public class CameraModeCommand | ||
{ | ||
public static void register(CommandDispatcher<CommandSource> dispatcher) | ||
{ | ||
LiteralArgumentBuilder<CommandSource> camera = literal("c"). | ||
requires((player) -> CarpetSettings.getBool("commandCameramode")). | ||
executes((c) -> cameraMode(c.getSource(), c.getSource().asPlayer())). | ||
then(argument("player", EntityArgument.singlePlayer()). | ||
executes( (c) -> cameraMode(c.getSource(), EntityArgument.getOnePlayer(c, "player")))); | ||
|
||
LiteralArgumentBuilder<CommandSource> survival = literal("s"). | ||
requires((player) -> CarpetSettings.getBool("commandCameramode")). | ||
executes((c) -> survivalMode( | ||
c.getSource(), | ||
c.getSource().asPlayer())). | ||
then(argument("player", EntityArgument.singlePlayer()). | ||
executes( (c) -> survivalMode(c.getSource(), EntityArgument.getOnePlayer(c, "player")))); | ||
|
||
dispatcher.register(camera); | ||
dispatcher.register(survival); | ||
} | ||
private static boolean iCanHasPermissions(CommandSource source, EntityPlayer player) | ||
{ | ||
try | ||
{ | ||
return source.hasPermissionLevel(2) || source.asPlayer() == player; | ||
} | ||
catch (CommandSyntaxException e) | ||
{ | ||
return true; // shoudn't happen because server has all permissions anyways | ||
} | ||
} | ||
private static int cameraMode(CommandSource source, EntityPlayer player) | ||
{ | ||
if (!(iCanHasPermissions(source, player))) return 0; | ||
player.setGameType(GameType.SPECTATOR); | ||
player.addPotionEffect(new PotionEffect(MobEffects.NIGHT_VISION, 999999, 0, false, false)); | ||
player.addPotionEffect(new PotionEffect(MobEffects.CONDUIT_POWER, 999999, 0, false, false)); | ||
return 1; | ||
} | ||
private static int survivalMode(CommandSource source, EntityPlayer player) | ||
{ | ||
if (!(iCanHasPermissions(source, player))) return 0; | ||
player.setGameType(GameType.SURVIVAL); | ||
player.removePotionEffect(MobEffects.NIGHT_VISION); | ||
player.removePotionEffect(MobEffects.CONDUIT_POWER); | ||
return 1; | ||
} | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package carpet.commands; | ||
|
||
import carpet.CarpetSettings; | ||
import carpet.utils.EntityInfo; | ||
import carpet.utils.Messenger; | ||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.mojang.brigadier.builder.LiteralArgumentBuilder; | ||
import net.minecraft.command.CommandSource; | ||
import net.minecraft.command.ISuggestionProvider; | ||
import net.minecraft.command.arguments.BlockPosArgument; | ||
import net.minecraft.command.arguments.EntityArgument; | ||
import net.minecraft.command.arguments.EntitySelector; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.text.ITextComponent; | ||
|
||
import javax.swing.*; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import static com.mojang.brigadier.arguments.StringArgumentType.getString; | ||
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString; | ||
import static com.mojang.brigadier.arguments.StringArgumentType.word; | ||
import static net.minecraft.command.Commands.argument; | ||
import static net.minecraft.command.Commands.literal; | ||
|
||
public class InfoCommand | ||
{ | ||
public static void register(CommandDispatcher<CommandSource> dispatcher) | ||
{ | ||
LiteralArgumentBuilder<CommandSource> command = literal("info"). | ||
requires((player) -> CarpetSettings.getBool("commandCameramode")). | ||
then(literal("block"). | ||
then(argument("block position", BlockPosArgument.blockPos()). | ||
executes( (c) -> infoBlock( | ||
c.getSource(), | ||
BlockPosArgument.getBlockPos(c, "block position"), null)). | ||
then(literal("grep"). | ||
then(argument("regexp",greedyString()). | ||
executes( (c) -> infoBlock( | ||
c.getSource(), | ||
BlockPosArgument.getBlockPos(c, "block position"), | ||
getString(c, "regexp"))))))). | ||
then(literal("entity"). | ||
then(argument("entity selector", EntityArgument.multipleEntities()). | ||
executes( (c) -> infoEntities( | ||
c.getSource(), EntityArgument.getEntities(c,"entity selector"), null)). | ||
then(literal("grep"). | ||
then(argument("regexp",greedyString()). | ||
executes( (c) -> infoEntities( | ||
c.getSource(), | ||
EntityArgument.getEntities(c,"entity selector"), | ||
getString(c, "regexp"))))))); | ||
|
||
dispatcher.register(command); | ||
} | ||
|
||
public static void printEntity(List<ITextComponent> messages, CommandSource source, String grep) | ||
{ | ||
List<ITextComponent> actual = new ArrayList<>(); | ||
if (grep != null) | ||
{ | ||
Pattern p = Pattern.compile(grep); | ||
actual.add(messages.get(0)); | ||
boolean empty = true; | ||
for (int i = 1; i<messages.size(); i++) | ||
{ | ||
ITextComponent line = messages.get(i); | ||
Matcher m = p.matcher(line.getString()); | ||
if (m.find()) | ||
{ | ||
empty = false; | ||
actual.add(line); | ||
} | ||
} | ||
if (empty) | ||
{ | ||
return; | ||
} | ||
} | ||
else | ||
{ | ||
actual = messages; | ||
} | ||
Messenger.m(source, ""); | ||
Messenger.send(source, actual); | ||
} | ||
|
||
public static void printBlock(List<ITextComponent> messages, CommandSource source, String grep) | ||
{ | ||
Messenger.m(source, ""); | ||
if (grep != null) | ||
{ | ||
Pattern p = Pattern.compile(grep); | ||
Messenger.m(source, messages.get(0)); | ||
for (int i = 1; i<messages.size(); i++) | ||
{ | ||
ITextComponent line = messages.get(i); | ||
Matcher m = p.matcher(line.getString()); | ||
if (m.find()) | ||
{ | ||
Messenger.m(source, line); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
Messenger.send(source, messages); | ||
} | ||
} | ||
|
||
|
||
|
||
private static int infoEntities(CommandSource source, Collection<? extends Entity> entities, String grep) | ||
{ | ||
for (Entity e: entities) | ||
{ | ||
List<ITextComponent> report = EntityInfo.entityInfo(e, source.getWorld()); | ||
printEntity(report, source, grep); | ||
} | ||
return 1; | ||
} | ||
private static int infoBlock(CommandSource source, BlockPos pos, String grep) | ||
{ | ||
Messenger.m(source, "r Not done yet: check.... tomorrow"); | ||
return 1; | ||
} | ||
|
||
} |
This file contains 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
Oops, something went wrong.