Added enchant interface

Other misc stuff
This commit is contained in:
Steven Lawson 2011-11-29 00:41:47 -05:00
parent 41f2a0e232
commit d60963cc7c
8 changed files with 231 additions and 10 deletions

View File

@ -34,6 +34,7 @@ disable_weather: true
# Enable misc. features:
landmines_enabled: false
mp44_enabled: false
tossmob_enabled: false
# Moblimiter:
mob_limiter_enabled: true

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
@ -33,13 +34,21 @@ public class Command_creative extends TFM_Command
}
else
{
try
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
p = getPlayer(args[0]);
try
{
p = getPlayer(args[0]);
}
catch (CantFindPlayerException ex)
{
sender.sendMessage(ex.getMessage());
return true;
}
}
catch (CantFindPlayerException ex)
else
{
sender.sendMessage(ex.getMessage());
sender.sendMessage("Only superadmins can change other user's gamemode.");
return true;
}
}

View File

@ -0,0 +1,130 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class Command_enchant extends TFM_Command
{
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (senderIsConsole)
{
sender.sendMessage(TotalFreedomMod.NOT_FROM_CONSOLE);
return true;
}
if (!sender.isOp())
{
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true;
}
if (args.length < 1)
{
return false;
}
ItemStack itemInHand = sender_p.getItemInHand();
if (itemInHand == null)
{
sender.sendMessage("You are holding an invalid item.");
return true;
}
if (args[0].equalsIgnoreCase("list"))
{
boolean has_enchantments = false;
StringBuilder possible_ench = new StringBuilder("Possible enchantments for held item: ");
for (Enchantment ench : Enchantment.values())
{
if (ench.canEnchantItem(itemInHand))
{
has_enchantments = true;
possible_ench.append(ench.getName()).append(", ");
}
}
if (has_enchantments)
{
sender.sendMessage(possible_ench.toString());
}
else
{
sender.sendMessage("The held item has no enchantments.");
}
}
else if (args[0].equalsIgnoreCase("addall"))
{
for (Enchantment ench : Enchantment.values())
{
if (ench.canEnchantItem(itemInHand))
{
itemInHand.addEnchantment(ench, ench.getMaxLevel());
}
}
sender.sendMessage("Added all possible enchantments for this item.");
}
else if (args[0].equalsIgnoreCase("reset"))
{
for (Enchantment ench : itemInHand.getEnchantments().keySet())
{
itemInHand.removeEnchantment(ench);
}
sender.sendMessage("Removed all enchantments.");
}
else
{
if (args.length < 2)
{
return false;
}
Enchantment ench = null;
try
{
ench = Enchantment.getByName(args[1]);
}
catch (Exception ex)
{
}
if (ench == null)
{
sender.sendMessage(args[1] + " is an invalid enchantment for the held item. Type \"/enchant list\" for valid enchantments for this item.");
return true;
}
if (args[0].equalsIgnoreCase("add"))
{
if (ench.canEnchantItem(itemInHand))
{
itemInHand.addEnchantment(ench, ench.getMaxLevel());
sender.sendMessage("Added enchantment: " + ench.getName());
}
else
{
sender.sendMessage("Can't use this enchantment on held item.");
}
}
else if (args[0].equalsIgnoreCase("remove"))
{
itemInHand.removeEnchantment(ench);
sender.sendMessage("Removed enchantment: " + ench.getName());
}
}
return true;
}
}

View File

@ -0,0 +1,58 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Command_setexp extends TFM_Command
{
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (senderIsConsole)
{
sender.sendMessage(TotalFreedomMod.NOT_FROM_CONSOLE);
return true;
}
if (!sender.isOp())
{
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true;
}
if (args.length != 1)
{
return false;
}
int exp_amount;
try
{
exp_amount = Integer.parseInt(args[0]);
if (exp_amount < 0)
{
exp_amount = 0;
}
else if (exp_amount > (int) Short.MAX_VALUE)
{
exp_amount = (int) Short.MAX_VALUE;
}
}
catch (NumberFormatException ex)
{
sender.sendMessage(ChatColor.RED + "Invalid exp amount.");
return true;
}
sender_p.setExperience(exp_amount);
sender.sendMessage(ChatColor.AQUA + "Experience points set to: " + sender_p.getExperience());
return true;
}
}

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
@ -33,13 +34,21 @@ public class Command_survival extends TFM_Command
}
else
{
try
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
{
p = getPlayer(args[0]);
try
{
p = getPlayer(args[0]);
}
catch (CantFindPlayerException ex)
{
sender.sendMessage(ex.getMessage());
return true;
}
}
catch (CantFindPlayerException ex)
else
{
sender.sendMessage(ex.getMessage());
sender.sendMessage("Only superadmins can change other user's gamemode.");
return true;
}
}

View File

@ -19,6 +19,12 @@ public class Command_tossmob extends TFM_Command
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!TotalFreedomMod.tossmobEnabled)
{
sender.sendMessage(ChatColor.RED + "Tossmob is currently disabled.");
return true;
}
if (senderIsConsole)
{
sender.sendMessage(TotalFreedomMod.NOT_FROM_CONSOLE);
@ -36,7 +42,7 @@ public class Command_tossmob extends TFM_Command
sender.sendMessage(ChatColor.GREEN + "MobThrower is disabled.");
return true;
}
if (args[0].equalsIgnoreCase("list"))
{
StringBuilder output = new StringBuilder("Supported mobs: ");
@ -47,7 +53,7 @@ public class Command_tossmob extends TFM_Command
sender.sendMessage(ChatColor.GREEN + output.toString());
return true;
}
try
{
creature = TFM_Util.getCreatureType(args[0]);

View File

@ -144,6 +144,7 @@ public class TotalFreedomMod extends JavaPlugin
public static boolean mobLimiterDisableGhast = true;
public static boolean mobLimiterDisableSlime = true;
public static boolean mobLimiterDisableGiant = true;
public static boolean tossmobEnabled = false;
public void loadMainConfig()
{
@ -174,6 +175,7 @@ public class TotalFreedomMod extends JavaPlugin
mobLimiterDisableGhast = config.getBoolean("mob_limiter_disable_ghast", mobLimiterDisableGhast);
mobLimiterDisableSlime = config.getBoolean("mob_limiter_disable_slime", mobLimiterDisableSlime);
mobLimiterDisableGiant = config.getBoolean("mob_limiter_disable_giant", mobLimiterDisableGiant);
tossmobEnabled = config.getBoolean("mp44_enabled", tossmobEnabled);
}
public static List<String> superadmins = new ArrayList<String>();

View File

@ -25,6 +25,9 @@ commands:
deopall:
description: Superadmin command - Deop everyone on the server. Use 'purge' to clear ops.txt as well.
usage: /<command> [purge]
enchant:
description: Enchant items.
usage: /<command> <list | addall | reset | add <name> | remove <name>>
expel:
description: Superadmin command - Push people away from you.
usage: /<command> [radius] [strength]
@ -121,6 +124,9 @@ commands:
setspawnworld:
description: Superadmin Command - Set world spawnpoint.
usage: /<command>
# setexp:
# description: Sets how many expierence points you have (this is not the same as your "level").
# usage: /<command> <value>
ender:
description: Goto the ender / "The End".
usage: /<command>