diff --git a/src/main/java/org/ultramine/commands/basic/BasicCommands.java b/src/main/java/org/ultramine/commands/basic/BasicCommands.java index 7666184..441ce06 100644 --- a/src/main/java/org/ultramine/commands/basic/BasicCommands.java +++ b/src/main/java/org/ultramine/commands/basic/BasicCommands.java @@ -1,5 +1,6 @@ package org.ultramine.commands.basic; +import java.util.List; import java.util.Map; import static net.minecraft.util.EnumChatFormatting.*; @@ -8,10 +9,12 @@ import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.ChatStyle; import net.minecraft.util.MathHelper; +import net.minecraft.world.WorldSettings.GameType; import net.minecraft.world.storage.WorldInfo; import org.ultramine.commands.Command; import org.ultramine.commands.CommandContext; +import org.ultramine.commands.IExtendedCommand; import org.ultramine.server.Teleporter; import org.ultramine.server.data.player.PlayerData; import org.ultramine.server.util.InventoryUtil; @@ -20,6 +23,46 @@ public class BasicCommands { @Command( + name = "help", + group = "player", + aliases = {"?"}, + permissions = {"command.help"}, + syntax = { + "", + "" + } + ) + public static void help(CommandContext ctx) + { + @SuppressWarnings("unchecked") + List cmds = (List)ctx.getServer().getCommandManager().getPossibleCommands(ctx.getSender()); + int pages = cmds.size()/10 + (cmds.size()%10 == 0 ? 0 : 1); + int page = ctx.contains("page") ? ctx.get("page").asString().equals("all") ? -1 : ctx.get("page").asInt(1, pages) -1 : 0; + + int start = page == -1 ? 0 : page*10; + int limit = page == -1 ? cmds.size() : Math.min(cmds.size(), start + 10); + + ctx.sendMessage("commands.help.header", page+1, pages); + + String group = ""; + for(int i = start; i < limit; i++) + { + IExtendedCommand cmd = cmds.get(i); + + if(!group.equals(cmd.getGroup())) + { + group = cmd.getGroup(); + ctx.sendMessage("%s:", group); + } + ChatComponentTranslation usage = new ChatComponentTranslation(cmd.getCommandUsage(ctx.getSender())); + ChatComponentTranslation desc = new ChatComponentTranslation(cmd.getDescription()); + usage.getChatStyle().setColor(YELLOW); + desc.getChatStyle().setColor(DARK_AQUA); + ctx.sendMessage(DARK_GRAY, YELLOW, " - %s <- %s", usage, desc); + } + } + + @Command( name = "home", group = "player", aliases = {"дом", "хата"}, @@ -96,6 +139,7 @@ @Command( name = "warp", + aliases = {"go", "пойти", "на"}, group = "player", permissions = {"command.warp", "command.warp.other"}, syntax = { @@ -313,4 +357,22 @@ is.stackSize *= ctx.get("count").asInt(); InventoryUtil.addItem(ctx.getSenderAsPlayer().inventory, is); } + + @Command( + name = "gm", + group = "admin", + permissions = {"command.gm"}, + syntax = {""} + ) + public static void gm(CommandContext ctx) + { + EntityPlayerMP player = ctx.getSenderAsPlayer(); + + GameType type = player.theItemInWorldManager.getGameType(); + GameType newtype = GameType.SURVIVAL; + if(type == GameType.SURVIVAL) + newtype = GameType.CREATIVE; + + player.setGameType(newtype); + } } diff --git a/src/main/java/org/ultramine/commands/basic/TechCommands.java b/src/main/java/org/ultramine/commands/basic/TechCommands.java index 734fc4c..3b27655 100644 --- a/src/main/java/org/ultramine/commands/basic/TechCommands.java +++ b/src/main/java/org/ultramine/commands/basic/TechCommands.java @@ -1,6 +1,9 @@ package org.ultramine.commands.basic; +import net.minecraft.entity.Entity; import net.minecraft.entity.EnumCreatureType; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.passive.EntityVillager; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; @@ -16,6 +19,8 @@ import org.ultramine.server.MultiWorld; import org.ultramine.server.Teleporter; +import cpw.mods.fml.common.functions.GenericIterableFactory; + public class TechCommands { @Command( @@ -165,4 +170,113 @@ Teleporter.tpNow(ctx.getSenderAsPlayer(), dim, world.getWorldInfo().getSpawnX(), world.getWorldInfo().getSpawnY(), world.getWorldInfo().getSpawnZ()); } } + + @Command( + name = "countentity", + group = "technical", + permissions = {"command.countentity"}, + syntax = {""} + ) + public static void countentity(CommandContext ctx) + { + int radius = ctx.get("radius").asInt(); + EntityPlayerMP player = ctx.getSenderAsPlayer(); + + double minX = player.posX - radius; + double minY = player.posY - radius; + double minZ = player.posZ - radius; + double maxX = player.posX + radius; + double maxY = player.posY + radius; + double maxZ = player.posZ + radius; + + int count = 0; + int itemcount = 0; + int mobcount = 0; + + int monsters = 0; + int animals = 0; + int ambient = 0; + int water = 0; + + for(Entity ent : GenericIterableFactory.newCastingIterable(player.worldObj.loadedEntityList, Entity.class)) + { + if(!ent.isDead && (ent.posX > minX && ent.posX < maxX) && (ent.posY > minY && ent.posY < maxY) && (ent.posZ > minZ && ent.posZ < maxZ)) + { + count ++; + if(ent.isEntityLiving() && !ent.isEntityPlayer()) + { + mobcount++; + if(ent.isEntityMonster()) + monsters++; + else if(ent.isEntityAnimal()) + animals++; + else if(ent.isEntityAmbient()) + ambient++; + else if(ent.isEntityWater()) + water++; + + } + else if(ent instanceof EntityItem) + { + itemcount++; + } + } + } + ctx.sendMessage("command.countentity.result1", count, mobcount, itemcount); + ctx.sendMessage("command.countentity.result2", monsters, animals, water, ambient); + } + + @Command( + name = "clearentity", + group = "technical", + permissions = {"command.countentity"}, + syntax = { + "", + "[all mobs items] " + } + ) + public static void clearentity(CommandContext ctx) + { + int radius = ctx.get("radius").asInt(); + EntityPlayerMP player = ctx.getSenderAsPlayer(); + + boolean items = true; + boolean mobs = true; + if(ctx.getAction().equals("mobs")) + items = false; + if(ctx.getAction().equals("items")) + mobs = false; + + double minX = player.posX - radius; + double minY = player.posY - radius; + double minZ = player.posZ - radius; + double maxX = player.posX + radius; + double maxY = player.posY + radius; + double maxZ = player.posZ + radius; + + int count = 0; + int itemcount = 0; + int mobcount = 0; + + for(Entity ent : GenericIterableFactory.newCastingIterable(player.worldObj.loadedEntityList, Entity.class)) + { + if(!ent.isDead && (ent.posX > minX && ent.posX < maxX) && (ent.posY > minY && ent.posY < maxY) && (ent.posZ > minZ && ent.posZ < maxZ)) + { + if(mobs && ent.isEntityLiving() && !ent.isEntityPlayer() && !(ent instanceof EntityVillager)) + { + count ++; + mobcount++; + ent.setDead(); + } + else if(items && ent instanceof EntityItem) + { + count ++; + itemcount++; + ent.setDead(); + } + } + } + + ctx.sendMessage("command.clearentity.success", count, mobcount, itemcount); + } } diff --git a/src/main/resources/assets/ultramine/lang/en_US.lang b/src/main/resources/assets/ultramine/lang/en_US.lang index af3a7ca..8086dec 100644 --- a/src/main/resources/assets/ultramine/lang/en_US.lang +++ b/src/main/resources/assets/ultramine/lang/en_US.lang @@ -138,6 +138,9 @@ command.dupe.description=Dupe the item in hand command.dupe.fail=Get item for dupe to the hand first +command.gm.usage=/gm +command.gm.description=Toggle gamemode + #Technical commands command.id.usage=/id command.id.description=Displays information about specified item id @@ -162,3 +165,12 @@ command.multiworld.load.success=Dimension successfuly loaded command.multiworld.unload.success=Dimension successfuly unloaded command.warplist.list.head=Dimension list: + +command.countentity.usage=/countentity +command.countentity.description=Specifies the number of Entity radially +command.countentity.result1=Found %s Entity. Mobs: %s, items: %s +command.countentity.result2=Monsters: %s, Animals: %s, Water: %s, Ambient: %s + +command.clearentity.usage=/clearentity [all|mobs|items] +command.clearentity.description=All multiworld commands +command.clearentity.success=Cleared %s Entity. Mobs: %s, Items: %s