Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.bgsoftware.wildstacker.hooks;

import com.bgsoftware.wildstacker.WildStackerPlugin;
import com.bgsoftware.wildstacker.utils.entity.EntityUtils;
import com.bgsoftware.wildstacker.utils.names.CustomNames;
import net.brcdev.shopgui.ShopGuiPlusApi;
import net.brcdev.shopgui.provider.spawner.SpawnerProvider;
import org.bukkit.entity.EntityType;
Expand Down Expand Up @@ -33,12 +33,16 @@ public ItemStack getSpawnerItem(String entityId, String customName) {

@Override
public String getSpawnerEntityId(ItemStack itemStack) {
return plugin.getProviders().getSpawnersProvider().getSpawnerType(itemStack).name();
return getSpawnerEntityType(itemStack).name();
}

@Override
public String getSpawnerEntityName(ItemStack itemStack) {
return EntityUtils.getFormattedType(getSpawnerEntityId(itemStack));
return CustomNames.getSpawnerCustomName(getSpawnerEntityType(itemStack));
}

private EntityType getSpawnerEntityType(ItemStack itemStack) {
return plugin.getProviders().getSpawnersProvider().getSpawnerType(itemStack);
}

}
Expand Down
4 changes: 2 additions & 2 deletions NMS/src/main/templates/AbstractNMSSpawners.java.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.bgsoftware.wildstacker.nms.${NMS_VERSION}.spawner.SpawnerWatcherTicki
import com.bgsoftware.wildstacker.nms.${NMS_VERSION}.spawner.StackedBaseSpawner;
import com.bgsoftware.wildstacker.nms.${NMS_VERSION}.spawner.SyncedCreatureSpawnerImpl;
import com.bgsoftware.wildstacker.objects.WStackedSpawner;
import com.bgsoftware.wildstacker.utils.entity.EntityUtils;
import com.bgsoftware.wildstacker.utils.names.CustomNames;
import com.bgsoftware.wildstacker.utils.spawners.SpawnerCachedData;
import com.bgsoftware.wildstacker.utils.spawners.SyncedCreatureSpawner;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -161,7 +161,7 @@ public abstract class AbstractNMSSpawners implements NMSSpawners {
}

protected final void createCondition(String id, BiPredicate<ServerLevel, BlockPos> predicate, EntityType... entityTypes) {
SpawnCondition spawnCondition = SpawnCondition.register(new SpawnCondition(id, EntityUtils.format(id)) {
SpawnCondition spawnCondition = SpawnCondition.register(new SpawnCondition(id, CustomNames.format(id)) {
@Override
public boolean test(Location location) {
return predicate.test(((CraftWorld) location.getWorld()).getHandle(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.bgsoftware.wildstacker.nms.v1_12_R1.spawner.SyncedCreatureSpawnerImpl;
import com.bgsoftware.wildstacker.nms.v1_12_R1.spawner.TileEntityMobSpawnerWatcher;
import com.bgsoftware.wildstacker.objects.WStackedSpawner;
import com.bgsoftware.wildstacker.utils.entity.EntityUtils;
import com.bgsoftware.wildstacker.utils.names.CustomNames;
import com.bgsoftware.wildstacker.utils.spawners.SpawnerCachedData;
import com.bgsoftware.wildstacker.utils.spawners.SyncedCreatureSpawner;
import net.minecraft.server.v1_12_R1.BiomeBase;
Expand Down Expand Up @@ -46,7 +46,7 @@ public final class NMSSpawnersImpl implements NMSSpawners {
private static final WildStackerPlugin plugin = WildStackerPlugin.getPlugin();

private static void createCondition(String id, BiPredicate<World, BlockPosition> predicate, EntityType... entityTypes) {
SpawnCondition spawnCondition = SpawnCondition.register(new SpawnCondition(id, EntityUtils.format(id)) {
SpawnCondition spawnCondition = SpawnCondition.register(new SpawnCondition(id, CustomNames.format(id)) {
@Override
public boolean test(Location location) {
return predicate.test(((CraftWorld) location.getWorld()).getHandle(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.bgsoftware.wildstacker.nms.v1_16_R3.spawner.SyncedCreatureSpawnerImpl;
import com.bgsoftware.wildstacker.nms.v1_16_R3.spawner.TileEntityMobSpawnerWatcher;
import com.bgsoftware.wildstacker.objects.WStackedSpawner;
import com.bgsoftware.wildstacker.utils.entity.EntityUtils;
import com.bgsoftware.wildstacker.utils.names.CustomNames;
import com.bgsoftware.wildstacker.utils.spawners.SpawnerCachedData;
import com.bgsoftware.wildstacker.utils.spawners.SyncedCreatureSpawner;
import net.minecraft.server.v1_16_R3.BiomeBase;
Expand Down Expand Up @@ -52,7 +52,7 @@ public final class NMSSpawnersImpl implements NMSSpawners {
private static final WildStackerPlugin plugin = WildStackerPlugin.getPlugin();

private static void createCondition(String id, BiPredicate<World, BlockPosition> predicate, EntityType... entityTypes) {
SpawnCondition spawnCondition = SpawnCondition.register(new SpawnCondition(id, EntityUtils.format(id)) {
SpawnCondition spawnCondition = SpawnCondition.register(new SpawnCondition(id, CustomNames.format(id)) {
@Override
public boolean test(Location location) {
return predicate.test(((CraftWorld) location.getWorld()).getHandle(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.bgsoftware.wildstacker.nms.v1_7_R4.spawner.TileEntityMobSpawnerWatcher;
import com.bgsoftware.wildstacker.nms.v1_7_R4.world.BlockPosition;
import com.bgsoftware.wildstacker.objects.WStackedSpawner;
import com.bgsoftware.wildstacker.utils.entity.EntityUtils;
import com.bgsoftware.wildstacker.utils.names.CustomNames;
import com.bgsoftware.wildstacker.utils.spawners.SpawnerCachedData;
import com.bgsoftware.wildstacker.utils.spawners.SyncedCreatureSpawner;
import net.minecraft.server.v1_7_R4.BiomeBase;
Expand Down Expand Up @@ -43,7 +43,7 @@ public final class NMSSpawnersImpl implements NMSSpawners {
private static final WildStackerPlugin plugin = WildStackerPlugin.getPlugin();

private static void createCondition(String id, BiPredicate<World, BlockPosition> predicate, EntityType... entityTypes) {
SpawnCondition spawnCondition = SpawnCondition.register(new SpawnCondition(id, EntityUtils.format(id)) {
SpawnCondition spawnCondition = SpawnCondition.register(new SpawnCondition(id, CustomNames.format(id)) {
@Override
public boolean test(Location location) {
return predicate.test(((CraftWorld) location.getWorld()).getHandle(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.bgsoftware.wildstacker.nms.v1_8_R3.spawner.SyncedCreatureSpawnerImpl;
import com.bgsoftware.wildstacker.nms.v1_8_R3.spawner.TileEntityMobSpawnerWatcher;
import com.bgsoftware.wildstacker.objects.WStackedSpawner;
import com.bgsoftware.wildstacker.utils.entity.EntityUtils;
import com.bgsoftware.wildstacker.utils.names.CustomNames;
import com.bgsoftware.wildstacker.utils.spawners.SpawnerCachedData;
import com.bgsoftware.wildstacker.utils.spawners.SyncedCreatureSpawner;
import net.minecraft.server.v1_8_R3.BiomeBase;
Expand Down Expand Up @@ -42,7 +42,7 @@ public final class NMSSpawnersImpl implements NMSSpawners {
private static final WildStackerPlugin plugin = WildStackerPlugin.getPlugin();

private static void createCondition(String id, BiPredicate<World, BlockPosition> predicate, EntityType... entityTypes) {
SpawnCondition spawnCondition = SpawnCondition.register(new SpawnCondition(id, EntityUtils.format(id)) {
SpawnCondition spawnCondition = SpawnCondition.register(new SpawnCondition(id, CustomNames.format(id)) {
@Override
public boolean test(Location location) {
return predicate.test(((CraftWorld) location.getWorld()).getHandle(),
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/bgsoftware/wildstacker/Locale.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public final class Locale {
public static Locale BARREL_TOGGLE_ON = new Locale("BARREL_TOGGLE_ON");
public static Locale BARREL_TOGGLE_OFF = new Locale("BARREL_TOGGLE_OFF");
public static Locale BARREL_NO_PERMISSION = new Locale("BARREL_NO_PERMISSION");
public static Locale CHUNK_LIMIT_EXCEEDED = new Locale("CHUNK_LIMIT_EXCEEDED");
public static Locale BARREL_CHUNK_LIMIT_EXCEEDED = new Locale("BARREL_CHUNK_LIMIT_EXCEEDED");
public static Locale COMMAND_USAGE = new Locale("COMMAND_USAGE");
public static Locale ENTITY_NAMES_TOGGLE_ON = new Locale("ENTITY_NAMES_TOGGLE_ON");
public static Locale ENTITY_NAMES_TOGGLE_OFF = new Locale("ENTITY_NAMES_TOGGLE_OFF");
Expand Down Expand Up @@ -60,6 +60,7 @@ public final class Locale {
public static Locale SPAWNER_CHANGE_NOT_ENOUGH_ITEMS = new Locale("SPAWNER_CHANGE_NOT_ENOUGH_ITEMS");
public static Locale SPAWNER_UPGRADE_NOT_ENOUGH_MONEY = new Locale("SPAWNER_UPGRADE_NOT_ENOUGH_MONEY");
public static Locale SPAWNER_UPGRADE_SUCCESS = new Locale("SPAWNER_UPGRADE_SUCCESS");
public static Locale SPAWNER_CHUNK_LIMIT_EXCEEDED = new Locale("SPAWNER_CHUNK_LIMIT_EXCEEDED");
public static Locale STACK_GIVE_PLAYER = new Locale("STACK_GIVE_PLAYER");
public static Locale STACK_RECEIVE = new Locale("STACK_RECEIVE");
public static Locale STACK_INFO_INVALID = new Locale("STACK_INFO_INVALID");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
import com.bgsoftware.wildstacker.WildStackerPlugin;
import com.bgsoftware.wildstacker.api.upgrades.SpawnerUpgrade;
import com.bgsoftware.wildstacker.command.ICommand;
import com.bgsoftware.wildstacker.utils.ServerVersion;
import com.bgsoftware.wildstacker.utils.entity.EntityUtils;
import com.bgsoftware.wildstacker.utils.items.ItemUtils;
import com.bgsoftware.wildstacker.utils.legacy.Materials;
import com.bgsoftware.wildstacker.utils.names.CustomNames;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -79,9 +76,6 @@ public void perform(WildStackerPlugin plugin, CommandSender sender, String[] arg
return;
}

ItemStack itemStack;
String typeName;

int stackSize;

try {
Expand All @@ -91,14 +85,15 @@ public void perform(WildStackerPlugin plugin, CommandSender sender, String[] arg
return;
}

boolean reformatItem = true;
ItemStack itemStack;
String typeName;

if (args[2].equalsIgnoreCase("egg")) {
EntityType entityType;

try {
entityType = EntityType.valueOf(args[3].toUpperCase());
typeName = EntityUtils.getFormattedType(entityType.name());
typeName = CustomNames.getEggCustomName(entityType);
} catch (IllegalArgumentException ex) {
Locale.INVALID_ENTITY.send(sender, args[3]);
return;
Expand All @@ -115,27 +110,13 @@ public void perform(WildStackerPlugin plugin, CommandSender sender, String[] arg
}
}

Material eggType = Materials.getSpawnEgg(entityType);
if (eggType == null || ServerVersion.isLegacy()) {
if (ServerVersion.isLegacy()) {
itemStack = new ItemStack(Material.MONSTER_EGG);
ItemUtils.setEntityType(itemStack, entityType);
} else {
itemStack = ItemUtils.getItemNMSEntityType(entityType);
}
} else {
itemStack = new ItemStack(eggType);
}

itemStack = ItemUtils.setSpawnerItemAmount(itemStack, stackSize);
if (spawnerUpgrade != null && !spawnerUpgrade.isDefault())
itemStack = ItemUtils.setSpawnerUpgrade(itemStack, spawnerUpgrade.getId());
itemStack = ItemUtils.getEggItem(entityType, stackSize, spawnerUpgrade);
} else if (args[2].equalsIgnoreCase("spawner")) {
EntityType entityType;

try {
entityType = EntityType.valueOf(args[3].toUpperCase());
typeName = EntityUtils.getFormattedType(entityType.name());
typeName = CustomNames.getSpawnerCustomName(entityType);
} catch (IllegalArgumentException ex) {
Locale.INVALID_ENTITY.send(sender, args[3]);
return;
Expand All @@ -154,14 +135,12 @@ public void perform(WildStackerPlugin plugin, CommandSender sender, String[] arg

itemStack = plugin.getProviders().getSpawnersProvider().getSpawnerItem(entityType,
stackSize, spawnerUpgrade);

reformatItem = false;
} else if (args[2].equalsIgnoreCase("barrel")) {
Material barrelType;

try {
barrelType = Material.getMaterial(args[3].toUpperCase());
typeName = ItemUtils.getFormattedType(new ItemStack(barrelType));
typeName = CustomNames.getBarrelCustomName(new ItemStack(barrelType));
} catch (IllegalArgumentException | NullPointerException ex) {
Locale.INVALID_BARREL.send(sender, args[3]);
return;
Expand All @@ -172,25 +151,12 @@ public void perform(WildStackerPlugin plugin, CommandSender sender, String[] arg
return;
}

itemStack = new ItemStack(barrelType);
itemStack = ItemUtils.setSpawnerItemAmount(itemStack, stackSize);
itemStack = ItemUtils.getBarrelItem(barrelType, stackSize);
} else {
Locale.INVALID_TYPE.send(sender);
return;
}

if (reformatItem) {
args[2] = args[2].substring(0, 1).toUpperCase() + args[2].substring(1).toLowerCase();

ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName(WildStackerPlugin.getPlugin().getSettings().giveItemName
.replace("{0}", stackSize + "")
.replace("{1}", typeName)
.replace("{2}", args[2])
);
itemStack.setItemMeta(itemMeta);
}

ItemUtils.addItem(itemStack, target.getInventory(), target.getLocation());

if (!silence || !(sender instanceof Player))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import com.bgsoftware.wildstacker.command.ICommand;
import com.bgsoftware.wildstacker.objects.WStackedBarrel;
import com.bgsoftware.wildstacker.objects.WStackedSpawner;
import com.bgsoftware.wildstacker.utils.entity.EntityUtils;
import com.bgsoftware.wildstacker.utils.items.ItemUtils;
import com.bgsoftware.wildstacker.utils.legacy.Materials;
import com.bgsoftware.wildstacker.utils.names.CustomNames;
import com.google.common.collect.Sets;
import org.bukkit.ChatColor;
import org.bukkit.Material;
Expand Down Expand Up @@ -68,7 +67,7 @@ public void perform(WildStackerPlugin plugin, CommandSender sender, String[] arg
StackedSpawner stackedSpawner = WStackedSpawner.of(targetBlock);

Locale.SPAWNER_INFO_HEADER.send(sender);
Locale.SPAWNER_INFO_TYPE.send(sender, EntityUtils.getFormattedType(stackedSpawner.getSpawnedType().name()));
Locale.SPAWNER_INFO_TYPE.send(sender, CustomNames.getSpawnerCustomName(stackedSpawner.getSpawnedType()));
Locale.SPAWNER_INFO_AMOUNT.send(sender, stackedSpawner.getStackAmount());
Locale.SPAWNER_INFO_UPGRADE.send(sender, stackedSpawner.getUpgrade().getName());
Locale.SPAWNER_INFO_FOOTER.send(sender);
Expand All @@ -77,7 +76,7 @@ public void perform(WildStackerPlugin plugin, CommandSender sender, String[] arg
StackedBarrel stackedBarrel = WStackedBarrel.of(targetBlock);

Locale.BARREL_INFO_HEADER.send(sender);
Locale.BARREL_INFO_TYPE.send(sender, ItemUtils.getFormattedType(stackedBarrel.getBarrelItem(1)));
Locale.BARREL_INFO_TYPE.send(sender, CustomNames.getBarrelCustomName(stackedBarrel.getBarrelItem(1)));
Locale.BARREL_INFO_AMOUNT.send(sender, stackedBarrel.getStackAmount());
Locale.BARREL_INFO_FOOTER.send(sender);
return;
Expand Down
Loading