Merge pull request #34 from khyperia/master

This commit is contained in:
KHobbits 2011-12-03 12:36:38 -08:00
commit 343618642b
10 changed files with 461 additions and 8 deletions

View file

@ -140,4 +140,6 @@ public interface ISettings extends IConf
boolean getUpdateBedAtDaytime();
boolean getRepairEnchanted();
boolean getIsWorldTeleportPermissions();
}

View file

@ -29,7 +29,7 @@ public class Settings implements ISettings
{
return config.getBoolean("respawn-at-home", false);
}
@Override
public boolean getUpdateBedAtDaytime()
{
@ -332,7 +332,7 @@ public class Settings implements ISettings
public void reloadConfig()
{
config.load();
noGodWorlds = new HashSet<String>(config.getStringList("no-god-in-worlds",Collections.<String>emptyList()));
noGodWorlds = new HashSet<String>(config.getStringList("no-god-in-worlds", Collections.<String>emptyList()));
}
@Override
@ -535,13 +535,12 @@ public class Settings implements ISettings
{
return config.getBoolean("death-messages", true);
}
Set <String> noGodWorlds = new HashSet<String>();
Set<String> noGodWorlds = new HashSet<String>();
@Override
public Set<String> getNoGodWorlds()
{
return noGodWorlds;
}
@Override
@ -549,8 +548,16 @@ public class Settings implements ISettings
{
this.debug = debug;
}
public boolean getRepairEnchanted() {
@Override
public boolean getRepairEnchanted()
{
return config.getBoolean("repair-enchanted", true);
}
@Override
public boolean getIsWorldTeleportPermissions()
{
return config.getBoolean("world-teleport-permissions", false);
}
}

View file

@ -0,0 +1,40 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.event.block.BlockBreakEvent;
public class Commandbreak extends EssentialsCommand
{
public Commandbreak()
{
super("break");
}
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
Block block = user.getTargetBlock(null, 20);
if (block.getType() == Material.AIR)
{
throw new NoChargeException();
}
if (block.getType() == Material.BEDROCK && !user.isAuthorized("essentials.break.bedrock"))
{
throw new NoChargeException();
}
BlockBreakEvent event = new BlockBreakEvent(block, user);
server.getPluginManager().callEvent(event);
if (event.isCancelled())
{
throw new NoChargeException();
}
else
{
block.setType(Material.AIR);
}
}
}

View file

@ -0,0 +1,146 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.Mob;
import static com.earth2me.essentials.I18n._;
import java.util.Collections;
import org.bukkit.Chunk;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Animals;
import org.bukkit.entity.ComplexLivingEntity;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Flying;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.NPC;
import org.bukkit.entity.Player;
import org.bukkit.entity.Slime;
import org.bukkit.entity.Snowman;
import org.bukkit.entity.WaterMob;
import org.bukkit.entity.Wolf;
import org.bukkit.event.entity.EntityDeathEvent;
public class Commandbutcher extends EssentialsCommand
{
public Commandbutcher()
{
super("butcher");
}
@Override
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
{
String type = "all";
int radius = -1;
World world;
if (sender instanceof Player)
{
world = ((Player)sender).getWorld();
if (args.length == 1)
{
try
{
radius = Integer.parseInt(args[0]);
}
catch (NumberFormatException e1)
{
type = args[0];
}
}
else if (args.length > 1)
{
type = args[0];
try
{
radius = Integer.parseInt(args[1]);
}
catch (NumberFormatException e)
{
throw new Exception(_("numberRequired"));
}
}
}
else
{
if (args.length == 0)
{
throw new NotEnoughArgumentsException();
}
else if (args.length == 1)
{
world = ess.getWorld(args[0]);
}
else
{
type = args[0];
world = ess.getWorld(args[1]);
}
}
String killType = type.toLowerCase();
int numKills = 0;
for (Chunk chunk : world.getLoadedChunks())
{
for (Entity entity : chunk.getEntities())
{
if (sender instanceof Player)
{
if (((Player)sender).getLocation().distance(entity.getLocation()) > radius && radius >= 0)
{
continue;
}
}
if (entity instanceof LivingEntity == false || entity instanceof HumanEntity)
{
continue;
}
if (entity instanceof Wolf)
{
if (((Wolf)entity).isTamed())
{
continue;
}
}
if (killType.contains("animal"))
{
if (entity instanceof Animals || entity instanceof NPC || entity instanceof Snowman || entity instanceof WaterMob)
{
EntityDeathEvent event = new EntityDeathEvent(entity, Collections.EMPTY_LIST);
ess.getServer().getPluginManager().callEvent(event);
entity.remove();
numKills++;
}
}
else if (killType.contains("monster"))
{
if (entity instanceof Monster || entity instanceof ComplexLivingEntity || entity instanceof Flying || entity instanceof Slime)
{
EntityDeathEvent event = new EntityDeathEvent(entity, Collections.EMPTY_LIST);
ess.getServer().getPluginManager().callEvent(event);
entity.remove();
numKills++;
}
}
else if (killType.contains("all"))
{
EntityDeathEvent event = new EntityDeathEvent(entity, Collections.EMPTY_LIST);
ess.getServer().getPluginManager().callEvent(event);
entity.remove();
numKills++;
}
else
{
if (Mob.fromName(killType).getType().getEntityClass().isAssignableFrom(entity.getClass()))
{
EntityDeathEvent event = new EntityDeathEvent(entity, Collections.EMPTY_LIST);
ess.getServer().getPluginManager().callEvent(event);
entity.remove();
numKills++;
}
}
}
}
sender.sendMessage(_("kill", numKills));
}
}

View file

@ -0,0 +1,37 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import org.bukkit.Server;
import org.bukkit.entity.Player;
public class Commandfeed extends EssentialsCommand
{
public Commandfeed()
{
super("feed");
}
@Override
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
if (args.length > 0)
{
Player player = ess.getServer().getPlayer(args[0]);
if (player != null)
{
player.setFoodLevel(20);
player.setSaturation(10);
}
else
{
throw new NotEnoughArgumentsException(); // TODO: Translate "Player not found"
}
}
else
{
user.setFoodLevel(20);
user.setSaturation(10); // 10 because 20 seems way overpowered
}
}
}

View file

@ -0,0 +1,50 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import static com.earth2me.essentials.I18n._;
import java.util.Locale;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
public class Commandmore extends EssentialsCommand
{
public Commandmore()
{
super("more");
}
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
ItemStack stack = user.getItemInHand();
if (stack == null)
{
throw new Exception(_("cantSpawnItem", "Air"));
}
if (stack.getAmount() >= ((user.isAuthorized("essentials.oversizedstacks"))
? ess.getSettings().getOversizedStackSize() : stack.getMaxStackSize()))
{
throw new NoChargeException();
}
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
if (ess.getSettings().permissionBasedItemSpawn()
? (!user.isAuthorized("essentials.itemspawn.item-all")
&& !user.isAuthorized("essentials.itemspawn.item-" + itemname)
&& !user.isAuthorized("essentials.itemspawn.item-" + stack.getTypeId()))
: (!user.isAuthorized("essentials.itemspawn.exempt")
&& !user.canSpawnItem(stack.getTypeId())))
{
throw new Exception(_("cantSpawnItem", itemname));
}
if (user.isAuthorized("essentials.oversizedstacks"))
{
stack.setAmount(ess.getSettings().getOversizedStackSize());
}
else
{
stack.setAmount(stack.getMaxStackSize());
}
user.updateInventory();
}
}

View file

@ -0,0 +1,138 @@
package com.earth2me.essentials.commands;
import java.util.Locale;
import static com.earth2me.essentials.I18n._;
import org.bukkit.Chunk;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Boat;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.Item;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Painting;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
public class Commandremove extends EssentialsCommand
{
public Commandremove()
{
super("remove");
}
private enum ToRemove
{
DROPS,
ARROWS,
BOATS,
MINECARTS,
XP,
PAINTINGS
}
@Override
protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
{
if (args.length < 2)
{
throw new NotEnoughArgumentsException();
}
World world;
int radius = -1;
if (sender instanceof Player)
{
world = ((Player)sender).getWorld();
try
{
radius = Integer.parseInt(args[1]);
}
catch (NumberFormatException e)
{
throw new Exception(_("numberRequired"));
}
}
else
{
world = ess.getWorld(args[1]);
}
if (world == null)
{
throw new Exception(_("invalidWorld"));
}
ToRemove toRemove;
try
{
toRemove = ToRemove.valueOf(args[0].toUpperCase(Locale.ENGLISH));
}
catch (IllegalArgumentException e)
{
throw new NotEnoughArgumentsException(); //TODO: translate and list types
}
int removed = 0;
for (Chunk chunk : world.getLoadedChunks())
{
for (Entity e : chunk.getEntities())
{
if (sender instanceof Player)
{
if (((Player)sender).getLocation().distance(e.getLocation()) > radius && radius >= 0)
{
continue;
}
}
if (toRemove == ToRemove.DROPS)
{
if (e instanceof Item)
{
e.remove();
removed++;
}
}
else if (toRemove == ToRemove.ARROWS)
{
if (e instanceof Projectile)
{
e.remove();
removed++;
}
}
else if (toRemove == ToRemove.BOATS)
{
if (e instanceof Boat)
{
e.remove();
removed++;
}
}
else if (toRemove == ToRemove.DROPS)
{
if (e instanceof Minecart)
{
e.remove();
removed++;
}
}
else if (toRemove == ToRemove.XP)
{
if (e instanceof ExperienceOrb)
{
e.remove();
removed++;
}
}
else if (toRemove == ToRemove.PAINTINGS)
{
if (e instanceof Painting)
{
e.remove();
removed++;
}
}
}
}
sender.sendMessage(_("kill", removed));
}
}

View file

@ -53,6 +53,15 @@ public class Commandworld extends EssentialsCommand
}
}
if (ess.getSettings().getIsWorldTeleportPermissions())
{
if (!user.isAuthorized("essentials.world." + world.getName()))
{
user.sendMessage(_("invalidWorld")); //TODO: Make a "world teleport denied" translation
throw new NoChargeException();
}
}
double factor;
if (user.getWorld().getEnvironment() == World.Environment.NETHER && world.getEnvironment() == World.Environment.NORMAL)
{

View file

@ -220,6 +220,10 @@ death-messages: true
no-god-in-worlds:
# - world_nether
# Set to true to enable per-world permissions for teleporting with /world
# Give someone permission to teleport to a world with essentials.world.<worldname>
world-teleport-permissions: false
# Oversized stacks are stacks that ignore the normal max stacksize.
# They can be obtained using /give and /item, if the player has essentials.oversizedstacks permission.
# How many items should be in a oversized stack?

View file

@ -39,6 +39,10 @@ commands:
description: Bans an IP address.
usage: /<command> <address>
aliases: [ebanip]
break:
description: Breaks the block you are looking at.
usage: /<command>
aliases: [ebreak]
broadcast:
description: Broadcasts a message to the entire server.
usage: /<command> <msg>
@ -51,6 +55,10 @@ commands:
description: Set a player on fire.
usage: /<command> <player> <seconds>
aliases: [eburn]
butcher:
description: Kill all mobs in a world.
usage: /<command> <mobType> <radius>
aliases: [ebutcher]
clearinventory:
description: Clear all items in your inventory.
usage: /<command>
@ -90,6 +98,10 @@ commands:
description: Extinguish players.
usage: /<command> [player]
aliases: [extinguish,eext,eextinguish]
feed:
description: Shove food down someone's throat.
usage: /<command> <player>
aliases: [efeed]
fireball:
description: Throw a fireball.
usage: /<command> [small]
@ -186,6 +198,10 @@ commands:
description: Describes an action in the context of the player.
usage: /<command> <description>
aliases: [action,describe,eme,eaction,edescribe]
more:
description: Fills the item stack in hand to maximum size.
usage: /<command>
aliases: [emore]
motd:
description: Views the Message Of The Day.
usage: /<command>
@ -238,6 +254,10 @@ commands:
description: Displays the username of a user based on nickname.
usage: /<command> <nickname>
aliases: [erealname]
remove:
description: Removes entities in your world
usage: /<command> <drops|arrows|boats|minecarts|xp|paintings> <radius>
aliases: [eremove]
repair:
description: Repairs the durability of all or one item.
usage: /<command> <hand|all>
@ -393,4 +413,4 @@ commands:
worth:
description: Calculates the worth of items in hand or as specified.
usage: /<command> [item] [amount]
aliases: [eworth]
aliases: [eworth]