mirror of
				https://github.com/mcMMO-Dev/mcMMO.git
				synced 2025-10-31 17:23:42 +01:00 
			
		
		
		
	Changed /mmoedit to use Bukkit command info. Also fixed bug where
/mcrefresh was registered with the info of /mcgod
This commit is contained in:
		| @@ -9,6 +9,8 @@ import com.gmail.nossr50.mcMMO; | |||||||
| import com.gmail.nossr50.commands.admin.AddlevelsCommand; | import com.gmail.nossr50.commands.admin.AddlevelsCommand; | ||||||
| import com.gmail.nossr50.commands.admin.AddxpCommand; | import com.gmail.nossr50.commands.admin.AddxpCommand; | ||||||
| import com.gmail.nossr50.commands.admin.McgodCommand; | import com.gmail.nossr50.commands.admin.McgodCommand; | ||||||
|  | import com.gmail.nossr50.commands.admin.McrefreshCommand; | ||||||
|  | import com.gmail.nossr50.commands.admin.MmoeditCommand; | ||||||
| import com.gmail.nossr50.locale.LocaleLoader; | import com.gmail.nossr50.locale.LocaleLoader; | ||||||
| import com.gmail.nossr50.skills.acrobatics.AcrobaticsCommand; | import com.gmail.nossr50.skills.acrobatics.AcrobaticsCommand; | ||||||
| import com.gmail.nossr50.skills.archery.ArcheryCommand; | import com.gmail.nossr50.skills.archery.ArcheryCommand; | ||||||
| @@ -28,7 +30,6 @@ import com.gmail.nossr50.util.Misc; | |||||||
|  |  | ||||||
| public final class CommandRegistrationHelper { | public final class CommandRegistrationHelper { | ||||||
|     private CommandRegistrationHelper() {}; |     private CommandRegistrationHelper() {}; | ||||||
|  |  | ||||||
|     private static String permissionsMessage = LocaleLoader.getString("mcMMO.NoPermission"); |     private static String permissionsMessage = LocaleLoader.getString("mcMMO.NoPermission"); | ||||||
|  |  | ||||||
|     public static void registerSkillCommands() { |     public static void registerSkillCommands() { | ||||||
| @@ -148,6 +149,15 @@ public final class CommandRegistrationHelper { | |||||||
|         command.setPermission("mcmmo.commands.mcrefresh"); |         command.setPermission("mcmmo.commands.mcrefresh"); | ||||||
|         command.setPermissionMessage(permissionsMessage); |         command.setPermissionMessage(permissionsMessage); | ||||||
|         command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mcrefresh", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]")); |         command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mcrefresh", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]")); | ||||||
|         command.setExecutor(new McgodCommand()); |         command.setExecutor(new McrefreshCommand()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static void registerMmoeditCommand() { | ||||||
|  |         PluginCommand command = mcMMO.p.getCommand("mmoedit"); | ||||||
|  |         command.setDescription(LocaleLoader.getString("Commands.Description.mmoedit")); | ||||||
|  |         command.setPermission("mcmmo.commands.mmoedit"); | ||||||
|  |         command.setPermissionMessage(permissionsMessage); | ||||||
|  |         command.setUsage(LocaleLoader.getString("Commands.Usage.3", "mmoedit", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]", "<" + LocaleLoader.getString("Commands.Usage.Skill") + ">", "<" + LocaleLoader.getString("Commands.Usage.Level") + ">")); | ||||||
|  |         command.setExecutor(new MmoeditCommand()); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -5,13 +5,13 @@ import org.bukkit.command.CommandExecutor; | |||||||
| import org.bukkit.command.CommandSender; | import org.bukkit.command.CommandSender; | ||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
|  |  | ||||||
| import com.gmail.nossr50.commands.CommandHelper; |  | ||||||
| import com.gmail.nossr50.datatypes.McMMOPlayer; | import com.gmail.nossr50.datatypes.McMMOPlayer; | ||||||
| import com.gmail.nossr50.datatypes.PlayerProfile; | import com.gmail.nossr50.datatypes.PlayerProfile; | ||||||
| import com.gmail.nossr50.locale.LocaleLoader; | import com.gmail.nossr50.locale.LocaleLoader; | ||||||
| import com.gmail.nossr50.skills.utilities.SkillTools; | import com.gmail.nossr50.skills.utilities.SkillTools; | ||||||
| import com.gmail.nossr50.skills.utilities.SkillType; | import com.gmail.nossr50.skills.utilities.SkillType; | ||||||
| import com.gmail.nossr50.util.Misc; | import com.gmail.nossr50.util.Misc; | ||||||
|  | import com.gmail.nossr50.util.Permissions; | ||||||
| import com.gmail.nossr50.util.Users; | import com.gmail.nossr50.util.Users; | ||||||
|  |  | ||||||
| public class MmoeditCommand implements CommandExecutor { | public class MmoeditCommand implements CommandExecutor { | ||||||
| @@ -20,87 +20,57 @@ public class MmoeditCommand implements CommandExecutor { | |||||||
|         PlayerProfile profile; |         PlayerProfile profile; | ||||||
|         int newValue; |         int newValue; | ||||||
|         SkillType skill; |         SkillType skill; | ||||||
|         String skillName; |  | ||||||
|         String usage = LocaleLoader.getString("Commands.Usage.3", "mmoedit", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]", "<" + LocaleLoader.getString("Commands.Usage.Skill") + ">", "<" + LocaleLoader.getString("Commands.Usage.Level") + ">"); |  | ||||||
|  |  | ||||||
|         switch (args.length) { |         switch (args.length) { | ||||||
|         case 2: |         case 2: | ||||||
|             if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mmoedit")) { |             if (!(sender instanceof Player)) { | ||||||
|                 return true; |                 return false; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (sender instanceof Player) { |             if (!SkillTools.isSkill(args[0])) { | ||||||
|                 if (!SkillTools.isSkill(args[0])) { |  | ||||||
|                     sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); |  | ||||||
|                     return true; |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 if (Misc.isInt(args[1])) { |  | ||||||
|                     Player player = (Player) sender; |  | ||||||
|                     newValue = Integer.valueOf(args[1]); |  | ||||||
|                     skill = SkillTools.getSkillType(args[0]); |  | ||||||
|                     profile = Users.getProfile(player); |  | ||||||
|  |  | ||||||
|                     if (skill.equals(SkillType.ALL)) { |  | ||||||
|                         sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", newValue)); |  | ||||||
|                     } |  | ||||||
|                     else { |  | ||||||
|                         sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", Misc.getCapitalized(skill.toString()), newValue)); |  | ||||||
|                     } |  | ||||||
|  |  | ||||||
|                     profile.modifySkill(skill, newValue); |  | ||||||
|                 } |  | ||||||
|                 else { |  | ||||||
|                     sender.sendMessage(usage); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             else { |  | ||||||
|                 sender.sendMessage(usage); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             return true; |  | ||||||
|  |  | ||||||
|         case 3: |  | ||||||
|             if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mmoedit.others")) { |  | ||||||
|                 return true; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             if (!Misc.isInt(args[2])) { |  | ||||||
|                 sender.sendMessage(usage); |  | ||||||
|                 return true; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             skill = SkillTools.getSkillType(args[1]); |  | ||||||
|  |  | ||||||
|             if (skill == null) { |  | ||||||
|                 sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); |                 sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); | ||||||
|                 return true; |                 return true; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             newValue = Integer.valueOf(args[2]); |             if (!Misc.isInt(args[1])) { | ||||||
|             McMMOPlayer mcmmoPlayer = Users.getPlayer(args[0]); |                 return false; | ||||||
|  |             } | ||||||
|  |  | ||||||
|             if (mcmmoPlayer != null) { |             newValue = Integer.valueOf(args[1]); | ||||||
|                 profile = mcmmoPlayer.getProfile(); |             skill = SkillTools.getSkillType(args[0]); | ||||||
|  |             profile = Users.getPlayer((Player) sender).getProfile(); | ||||||
|  |  | ||||||
|                 if (profile == null) { |             if (skill == SkillType.ALL) { | ||||||
|                     sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); |                 sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", newValue)); | ||||||
|                     return true; |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 profile.modifySkill(skill, newValue); |  | ||||||
|                 if (skill == SkillType.ALL) { |  | ||||||
|                     mcmmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", newValue)); |  | ||||||
|                     sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0])); |  | ||||||
|                 } |  | ||||||
|                 else { |  | ||||||
|                     skillName = Misc.getCapitalized(skill.toString()); |  | ||||||
|  |  | ||||||
|                     mcmmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", skillName, newValue)); |  | ||||||
|                     sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", skillName, args[0])); |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|             else { |             else { | ||||||
|  |                 sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", Misc.getCapitalized(skill.toString()), newValue)); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             profile.modifySkill(skill, newValue); | ||||||
|  |             return true; | ||||||
|  |  | ||||||
|  |         case 3: | ||||||
|  |             if (Permissions.hasPermission(sender, "mcmmo.commands.mmoedit.others")) { | ||||||
|  |                 sender.sendMessage(command.getPermissionMessage()); | ||||||
|  |                 return true; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             if (!SkillTools.isSkill(args[1])) { | ||||||
|  |                 sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); | ||||||
|  |                 return true; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             if (!Misc.isInt(args[2])) { | ||||||
|  |                 return false; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             newValue = Integer.valueOf(args[2]); | ||||||
|  |             skill = SkillTools.getSkillType(args[1]); | ||||||
|  |             McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]); | ||||||
|  |  | ||||||
|  |             // If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process. | ||||||
|  |             if (mcMMOPlayer == null) { | ||||||
|                 profile = new PlayerProfile(args[0], false); //Temporary Profile |                 profile = new PlayerProfile(args[0], false); //Temporary Profile | ||||||
|  |  | ||||||
|                 if (!profile.isLoaded()) { |                 if (!profile.isLoaded()) { | ||||||
| @@ -109,20 +79,36 @@ public class MmoeditCommand implements CommandExecutor { | |||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 profile.modifySkill(skill, newValue); |                 profile.modifySkill(skill, newValue); | ||||||
|                 profile.save(); |                 profile.save(); // Since this is a temporary profile, we save it here. | ||||||
|  |             } | ||||||
|  |             else { | ||||||
|  |                 profile = mcMMOPlayer.getProfile(); | ||||||
|  |                 Player player = mcMMOPlayer.getPlayer(); | ||||||
|  |  | ||||||
|                 if (skill == SkillType.ALL) { |                 profile.modifySkill(skill, newValue); | ||||||
|                     sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0])); |  | ||||||
|                 } |                 // Check if the player is online before we try to send them a message. | ||||||
|                 else { |                 if (player.isOnline()) { | ||||||
|                     sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", Misc.getCapitalized(skill.toString()), args[0])); |                     if (skill == SkillType.ALL) { | ||||||
|  |                         player.sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", newValue)); | ||||||
|  |                     } | ||||||
|  |                     else { | ||||||
|  |                         player.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1",  Misc.getCapitalized(skill.toString()), newValue)); | ||||||
|  |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  |             if (skill == SkillType.ALL) { | ||||||
|  |                 sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0])); | ||||||
|  |             } | ||||||
|  |             else { | ||||||
|  |                 sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", Misc.getCapitalized(skill.toString()), args[0])); | ||||||
|  |             } | ||||||
|  |  | ||||||
|             return true; |             return true; | ||||||
|  |  | ||||||
|         default: |         default: | ||||||
|             sender.sendMessage(usage); |             return false; | ||||||
|             return true; |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -25,7 +25,6 @@ import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManagerFactory; | |||||||
| import com.gmail.nossr50.chat.commands.ACommand; | import com.gmail.nossr50.chat.commands.ACommand; | ||||||
| import com.gmail.nossr50.chat.commands.PCommand; | import com.gmail.nossr50.chat.commands.PCommand; | ||||||
| import com.gmail.nossr50.commands.CommandRegistrationHelper; | import com.gmail.nossr50.commands.CommandRegistrationHelper; | ||||||
| import com.gmail.nossr50.commands.admin.MmoeditCommand; |  | ||||||
| import com.gmail.nossr50.commands.admin.SkillResetCommand; | import com.gmail.nossr50.commands.admin.SkillResetCommand; | ||||||
| import com.gmail.nossr50.commands.admin.XprateCommand; | import com.gmail.nossr50.commands.admin.XprateCommand; | ||||||
| import com.gmail.nossr50.commands.player.InspectCommand; | import com.gmail.nossr50.commands.player.InspectCommand; | ||||||
| @@ -454,7 +453,7 @@ public class mcMMO extends JavaPlugin { | |||||||
|         // Other commands |         // Other commands | ||||||
|         CommandRegistrationHelper.registerAddxpCommand(); |         CommandRegistrationHelper.registerAddxpCommand(); | ||||||
|         CommandRegistrationHelper.registerAddlevelsCommand(); |         CommandRegistrationHelper.registerAddlevelsCommand(); | ||||||
|         getCommand("mmoedit").setExecutor(new MmoeditCommand()); |         CommandRegistrationHelper.registerMmoeditCommand(); | ||||||
|         getCommand("inspect").setExecutor(new InspectCommand()); |         getCommand("inspect").setExecutor(new InspectCommand()); | ||||||
|         getCommand("xprate").setExecutor(new XprateCommand()); |         getCommand("xprate").setExecutor(new XprateCommand()); | ||||||
|         getCommand("mmoupdate").setExecutor(new MmoupdateCommand()); |         getCommand("mmoupdate").setExecutor(new MmoupdateCommand()); | ||||||
|   | |||||||
| @@ -690,4 +690,5 @@ Commands.Description.addlevels=Add mcMMO levels to a user | |||||||
| Commands.Description.addxp=Add mcMMO XP to a user | Commands.Description.addxp=Add mcMMO XP to a user | ||||||
| Commands.Description.mcgod=Toggle mcMMO god-mode on/off | Commands.Description.mcgod=Toggle mcMMO god-mode on/off | ||||||
| Commands.Description.mcrefresh=Refresh all cooldowns for mcMMO | Commands.Description.mcrefresh=Refresh all cooldowns for mcMMO | ||||||
|  | Commands.Description.mmoedit=Edit mcMMO levels for a user | ||||||
| Commands.Description.Skill=Display detailed mcMMO skill info for {0} | Commands.Description.Skill=Display detailed mcMMO skill info for {0} | ||||||
|   | |||||||
| @@ -59,8 +59,7 @@ commands: | |||||||
|         aliases: [] |         aliases: [] | ||||||
|         description: Remove a user from the database |         description: Remove a user from the database | ||||||
|     mmoedit: |     mmoedit: | ||||||
|         aliases: [] |         description: Edit the mcMMO skill values for a user | ||||||
|         description: Edit the skill values for a user |  | ||||||
|     ptp: |     ptp: | ||||||
|         aliases: [] |         aliases: [] | ||||||
|         description: Teleport to a party member |         description: Teleport to a party member | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 GJ
					GJ