Added /npc clear back
This commit is contained in:
parent
f6f484c134
commit
addc423c2d
@ -0,0 +1,39 @@
|
||||
package mineplex.core.npc.Commands;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.npc.NpcManager;
|
||||
|
||||
public class ClearCommand extends CommandBase<NpcManager>
|
||||
{
|
||||
public ClearCommand(NpcManager plugin)
|
||||
{
|
||||
super(plugin, Rank.DEVELOPER, "clear");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
if (args != null)
|
||||
Plugin.Help(caller);
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
Plugin.ClearNpcs();
|
||||
|
||||
UtilPlayer.message(caller, F.main(Plugin.GetName(), "Cleared NPCs."));
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
Plugin.Help(caller, "Database error.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ public class NpcCommand extends MultiCommandBase<NpcManager>
|
||||
AddCommand(new AddCommand(plugin));
|
||||
AddCommand(new DeleteCommand(plugin));
|
||||
AddCommand(new HomeCommand(plugin));
|
||||
AddCommand(new ClearCommand(plugin));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -121,9 +121,10 @@ public class NpcManager extends MiniPlugin
|
||||
public void Help(Player caller, String message)
|
||||
{
|
||||
UtilPlayer.message(caller, F.main(_moduleName, "Commands List:"));
|
||||
UtilPlayer.message(caller, F.help("/npc add <type> [radius] [adult] [name]", "Right click mob to attach npc.", Rank.DEVELOPER));
|
||||
UtilPlayer.message(caller, F.help("/npc del ", "Right click npc to delete", Rank.DEVELOPER));
|
||||
UtilPlayer.message(caller, F.help("/npc home", " Teleport npcs to home locations.", Rank.DEVELOPER));
|
||||
UtilPlayer.message(caller, F.help("/npc add <type> [radius] [adult] [name]", "Create a new NPC.", Rank.DEVELOPER));
|
||||
UtilPlayer.message(caller, F.help("/npc del ", "Right click NPC to delete.", Rank.DEVELOPER));
|
||||
UtilPlayer.message(caller, F.help("/npc home", "Teleport NPCs to home locations.", Rank.DEVELOPER));
|
||||
UtilPlayer.message(caller, F.help("/npc clear", "Deletes all NPCs.", Rank.DEVELOPER));
|
||||
|
||||
if (message != null)
|
||||
UtilPlayer.message(caller, F.main(_moduleName, ChatColor.RED + message));
|
||||
@ -478,4 +479,28 @@ public class NpcManager extends MiniPlugin
|
||||
{
|
||||
return _npcDeletingPlayers;
|
||||
}
|
||||
|
||||
public void ClearNpcs() throws SQLException
|
||||
{
|
||||
String serverType = _plugin.getClass().getSimpleName();
|
||||
|
||||
try (Connection connection = DBPool.getInstance().getConnection())
|
||||
{
|
||||
DSL.using(connection)
|
||||
.delete(Tables.npcs)
|
||||
.where(Tables.npcs.server.eq(serverType))
|
||||
.execute();
|
||||
|
||||
for (World world : Bukkit.getWorlds())
|
||||
{
|
||||
for (LivingEntity entity : world.getEntitiesByClass(LivingEntity.class))
|
||||
{
|
||||
if (isNpc(entity))
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
|
||||
_npcs.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user