From e6c76ad3f37367f2bd03228b00a08a00f4bd5922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sat, 11 Apr 2020 21:49:08 +0200 Subject: [PATCH] Entity categories implementation --- .../plotsquared/plot/commands/Debug.java | 16 ++++++ .../plot/util/entity/EntityCategories.java | 57 +++++++++++++++++++ .../plot/util/entity/EntityCategory.java | 53 +++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/entity/EntityCategories.java create mode 100644 Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/entity/EntityCategory.java diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Debug.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Debug.java index b83b44372..fef6f015b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Debug.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Debug.java @@ -33,6 +33,9 @@ import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; +import com.github.intellectualsites.plotsquared.plot.util.entity.EntityCategories; +import com.github.intellectualsites.plotsquared.plot.util.entity.EntityCategory; +import com.sk89q.worldedit.world.entity.EntityType; import java.util.Map; @@ -60,6 +63,19 @@ public class Debug extends SubCommand { Thread.currentThread().getName())); return true; } + if (args.length > 0 && "entitytypes".equalsIgnoreCase(args[0])) { + EntityCategories.init(); + player.sendMessage(Captions.PREFIX.getTranslated() + "§cEntity Categories: "); + EntityCategory.REGISTRY.forEach(category -> { + final StringBuilder builder = new StringBuilder("§7- §6") + .append(category.getId()).append("§7: §6"); + for (final EntityType entityType : category.getAll()) { + builder.append(entityType.getId()).append(" "); + } + player.sendMessage(Captions.PREFIX.getTranslated() + builder.toString()); + }); + return true; + } if ((args.length > 0) && args[0].equalsIgnoreCase("msg")) { StringBuilder msg = new StringBuilder(); for (Captions caption : Captions.values()) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/entity/EntityCategories.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/entity/EntityCategories.java new file mode 100644 index 000000000..b55ff4296 --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/entity/EntityCategories.java @@ -0,0 +1,57 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2020 IntellectualSites + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.github.intellectualsites.plotsquared.plot.util.entity; + +import com.sk89q.worldedit.world.entity.EntityType; +import com.sk89q.worldedit.world.entity.EntityTypes; + +import java.util.Arrays; +import java.util.HashSet; + +/** + * A collection of {@link EntityCategory entity categories} + */ +public class EntityCategories { + + public static final EntityCategory ANIMAL = register("animal"); + public static final EntityCategory TAMEABLE = register("tameable", + EntityTypes.HORSE, EntityTypes.OCELOT, EntityTypes.WOLF, EntityTypes.DONKEY, + EntityTypes.MULE, EntityTypes.PARROT, EntityTypes.LLAMA); + public static final EntityCategory VEHICLE = register("vehicle"); + public static final EntityCategory HOSTILE = register("hostile", + EntityTypes.ZOMBIE); + public static final EntityCategory HANGING = register("hanging", + EntityTypes.PAINTING, EntityTypes.ITEM_FRAME); + + public static EntityCategory register(final String id, final EntityType ... types) { + final EntityCategory entityCategory = new EntityCategory(id, new HashSet<>(Arrays.asList(types))); + EntityCategory.REGISTRY.register(entityCategory.getId(), entityCategory); + return entityCategory; + } + + public static void init() {} + +} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/entity/EntityCategory.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/entity/EntityCategory.java new file mode 100644 index 000000000..c1edf9217 --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/entity/EntityCategory.java @@ -0,0 +1,53 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2020 IntellectualSites + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.github.intellectualsites.plotsquared.plot.util.entity; + +import com.sk89q.worldedit.registry.Category; +import com.sk89q.worldedit.registry.Keyed; +import com.sk89q.worldedit.registry.NamespacedRegistry; +import com.sk89q.worldedit.world.entity.EntityType; + +import java.util.Set; + +/** + * Categories to which an {@link com.sk89q.worldedit.entity.Entity} may belong + */ +public class EntityCategory extends Category implements Keyed { + + public static final NamespacedRegistry REGISTRY = new NamespacedRegistry<>("entity type"); + + private final Set types; + + protected EntityCategory(final String id, final Set types) { + super("plotsquared:" + id); + this.types = types; + } + + @Override protected Set load() { + return types; + } + +}