Added remove villager command
This commit is contained in:
parent
391d58efeb
commit
f471e83618
|
|
@ -4,6 +4,7 @@ import com.alttd.VillagerUI;
|
|||
import com.alttd.commands.subcommands.CommandCreateVillager;
|
||||
import com.alttd.commands.subcommands.CommandHelp;
|
||||
import com.alttd.commands.subcommands.CommandReload;
|
||||
import com.alttd.commands.subcommands.CommandRemoveVillager;
|
||||
import com.alttd.config.Config;
|
||||
import com.alttd.util.Logger;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
|
@ -37,7 +38,8 @@ public class CommandManager implements CommandExecutor, TabExecutor {
|
|||
subCommands = Arrays.asList(
|
||||
new CommandHelp(this),
|
||||
new CommandCreateVillager(),
|
||||
new CommandReload());
|
||||
new CommandReload(),
|
||||
new CommandRemoveVillager());
|
||||
miniMessage = MiniMessage.get();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,51 @@
|
|||
package com.alttd.commands.subcommands;
|
||||
|
||||
public class CommandRemoveVillager {
|
||||
import com.alttd.commands.SubCommand;
|
||||
import com.alttd.config.Config;
|
||||
import com.alttd.config.VillagerConfig;
|
||||
import com.alttd.objects.LoadedVillagers;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CommandRemoveVillager extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
commandSender.sendMessage(getMiniMessage().parse(Config.NO_CONSOLE));
|
||||
return true;
|
||||
}
|
||||
|
||||
for(Entity entity : player.getNearbyEntities(2, 2, 2)){
|
||||
if (!entity.getType().equals(EntityType.VILLAGER))
|
||||
continue;
|
||||
UUID uuid = entity.getUniqueId();
|
||||
if (LoadedVillagers.getLoadedVillager(uuid) == null)
|
||||
continue;
|
||||
LoadedVillagers.removeLoadedVillager(uuid);
|
||||
VillagerConfig.removeVillager(uuid);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "removevillager";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabComplete(CommandSender commandSender, String[] args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Config.REMOVE_VILLAGER_MESSAGE;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,12 +62,14 @@ public final class Config extends AbstractConfig {
|
|||
public static String HELP_MESSAGE = "<green>Show this menu: <gold>/villagerui help</gold></green>";
|
||||
public static String RELOAD_MESSAGE = "<green>Reload configs: <gold>/villagerui reload</gold></green>";
|
||||
public static String CREATE_VILLAGER_MESSAGE = "<green>Create a new trading villager: <gold>/villagerui createvillager <type> <biome> <x> <y> <z> <yaw> <pitch> <world></gold></green>";
|
||||
public static String REMOVE_VILLAGER_MESSAGE = "<green>Removes all existing trading villagers in a 2 block radius: <gold>/villagerui removevillager</gold></green>";
|
||||
|
||||
private static void loadHelp() {
|
||||
HELP_MESSAGE_WRAPPER = config.getString("help.help-wrapper", HELP_MESSAGE_WRAPPER);
|
||||
HELP_MESSAGE = config.getString("help.help", HELP_MESSAGE);
|
||||
RELOAD_MESSAGE = config.getString("help.reload", RELOAD_MESSAGE);
|
||||
CREATE_VILLAGER_MESSAGE = config.getString("help.create-villager", CREATE_VILLAGER_MESSAGE);
|
||||
REMOVE_VILLAGER_MESSAGE = config.getString("help.remove-villager", REMOVE_VILLAGER_MESSAGE);
|
||||
}
|
||||
|
||||
public static String NO_PERMISSION = "<red>You do not have permission to do that.</red>";
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ public class VillagerConfig extends AbstractConfig {
|
|||
});
|
||||
}
|
||||
|
||||
public static void removeVillager(UUID uuid) {
|
||||
config.getConfigurationSection("").set(uuid.toString(), null);
|
||||
}
|
||||
|
||||
public static void addVillager(UUID uuid, VillagerType villagerType) {
|
||||
config.set(uuid.toString(), villagerType.getName());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,15 +3,20 @@ package com.alttd.events;
|
|||
import com.alttd.GUI.windows.OpenGUI;
|
||||
import com.alttd.VillagerUI;
|
||||
import com.alttd.config.Config;
|
||||
import com.alttd.config.VillagerConfig;
|
||||
import com.alttd.objects.LoadedVillagers;
|
||||
import com.alttd.objects.VillagerType;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class VillagerInteract implements Listener {
|
||||
|
||||
@EventHandler
|
||||
|
|
@ -40,4 +45,14 @@ public class VillagerInteract implements Listener {
|
|||
}
|
||||
}.runTaskAsynchronously(VillagerUI.getInstance());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onVillagerDeath(EntityDeathEvent event) {
|
||||
if (!event.getEntityType().equals(EntityType.VILLAGER))
|
||||
return;
|
||||
UUID uuid = event.getEntity().getUniqueId();
|
||||
|
||||
LoadedVillagers.removeLoadedVillager(uuid);
|
||||
VillagerConfig.removeVillager(uuid);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user