Minor code clean up.

This commit is contained in:
Brianna 2021-03-05 08:09:00 -06:00
parent b5ef30c629
commit b87f73589c
8 changed files with 21 additions and 81 deletions

View File

@ -135,7 +135,7 @@ public class UltimateStacker extends SongodaPlugin {
for (EntityType value : EntityType.values()) {
if (value.isSpawnable() && value.isAlive() && !value.toString().contains("ARMOR")) {
mobFile.addDefault("Mobs." + value.name() + ".Enabled", true);
mobFile.addDefault("Mobs." + value.name() + ".Display Name", Methods.formatText(value.name().toLowerCase().replace("_", " "), true));
mobFile.addDefault("Mobs." + value.name() + ".Display Name", TextUtils.formatText(value.name().toLowerCase().replace("_", " "), true));
mobFile.addDefault("Mobs." + value.name() + ".Max Stack Size", -1);
mobFile.addDefault("Mobs." + value.name() + ".Kill Whole Stack", false);
}
@ -154,7 +154,7 @@ public class UltimateStacker extends SongodaPlugin {
for (EntityType value : EntityType.values()) {
if (value.isSpawnable() && value.isAlive() && !value.toString().contains("ARMOR")) {
spawnerFile.addDefault("Spawners." + value.name() + ".Max Stack Size", -1);
spawnerFile.addDefault("Spawners." + value.name() + ".Display Name", Methods.formatText(value.name().toLowerCase().replace("_", " "), true));
spawnerFile.addDefault("Spawners." + value.name() + ".Display Name", TextUtils.formatText(value.name().toLowerCase().replace("_", " "), true));
}
}
spawnerFile.load();

View File

@ -2,6 +2,7 @@ package com.songoda.ultimatestacker.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.gui.GuiManager;
import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatestacker.gui.GUIConvert;
import com.songoda.ultimatestacker.utils.Methods;
import org.bukkit.Bukkit;
@ -25,7 +26,7 @@ public class CommandConvert extends AbstractCommand {
|| Bukkit.getPluginManager().isPluginEnabled("StackMob")) {
guiManager.showGUI((Player) sender, new GUIConvert());
} else {
sender.sendMessage(Methods.formatText("&cYou need to have the plugin &4WildStacker &cor &4StackMob &cenabled " +
sender.sendMessage(TextUtils.formatText("&cYou need to have the plugin &4WildStacker &cor &4StackMob &cenabled " +
"in order to convert data."));
}
return ReturnType.SUCCESS;

View File

@ -1,6 +1,7 @@
package com.songoda.ultimatestacker.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.utils.Methods;
import org.bukkit.Bukkit;
@ -48,7 +49,7 @@ public class CommandGiveSpawner extends AbstractCommand {
if (types.isSpawnable() && types.isAlive() && !types.toString().contains("ARMOR"))
list.append(types.name().toUpperCase().replace(" ", "_")).append("&7, &6");
}
sender.sendMessage(Methods.formatText("&6" + list));
sender.sendMessage(TextUtils.formatText("&6" + list));
} else {
int amt = args.length == 3 ? Integer.parseInt(args[2]) : 1;

View File

@ -66,7 +66,7 @@ public class CommandRemoveAll extends AbstractCommand {
+ type + " exist that could be removed.").sendPrefixedMessage(sender);
} else {
plugin.getLocale().newMessage("&7Removed &6" + amountRemoved + (all ? " " : " stacked ")
+ Methods.formatText(type.toLowerCase(), true) + " &7Successfully.").sendPrefixedMessage(sender);
+ TextUtils.formatText(type.toLowerCase(), true) + " &7Successfully.").sendPrefixedMessage(sender);
}
return ReturnType.SUCCESS;
}

View File

@ -1,6 +1,7 @@
package com.songoda.ultimatestacker.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.stackable.entity.EntityStack;
import com.songoda.ultimatestacker.utils.Methods;
@ -51,7 +52,7 @@ public class CommandSpawn extends AbstractCommand {
if (types.isSpawnable() && types.isAlive() && !types.toString().contains("ARMOR"))
list.append(types.name().toUpperCase().replace(" ", "_")).append("&7, &6");
}
sender.sendMessage(Methods.formatText("&6" + list));
sender.sendMessage(TextUtils.formatText("&6" + list));
} else {
LivingEntity entity = (LivingEntity)player.getWorld().spawnEntity(player.getTargetBlock((Set<Material>)null, 200).getLocation(), type);
EntityStack stack = plugin.getEntityStackManager().addStack(entity);

View File

@ -3,6 +3,7 @@ package com.songoda.ultimatestacker.gui;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiUtils;
import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.convert.Convert;
import com.songoda.ultimatestacker.utils.Methods;
@ -62,6 +63,6 @@ public class GUIConvertWhat extends Gui {
convertFrom.disablePlugin();
exit();
player.sendMessage(Methods.formatText("&7Data converted successfully. Remove &6" + convertFrom.getName() + " &7and restart your server to continue."));
player.sendMessage(TextUtils.formatText("&7Data converted successfully. Remove &6" + convertFrom.getName() + " &7and restart your server to continue."));
}
}

View File

@ -1,6 +1,7 @@
package com.songoda.ultimatestacker.stackable.block;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.settings.Settings;
import com.songoda.ultimatestacker.stackable.Hologramable;
@ -83,12 +84,12 @@ public class BlockStack implements Stackable, Hologramable {
@Override
public String getHologramName() {
String nameFormat = Settings.NAME_FORMAT_BLOCK.getString();
String displayName = Methods.formatText(material.name().toLowerCase().replace("_", " "), true);
String displayName = TextUtils.formatText(material.name().toLowerCase().replace("_", " "), true);
nameFormat = nameFormat.replace("{TYPE}", displayName);
nameFormat = nameFormat.replace("{AMT}", Integer.toString(amount));
return Methods.formatText(nameFormat).trim();
return TextUtils.formatText(nameFormat).trim();
}
@Override

View File

@ -7,13 +7,9 @@ import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.settings.Settings;
import com.songoda.ultimatestacker.stackable.entity.custom.CustomEntity;
import com.songoda.ultimatestacker.stackable.entity.custom.CustomEntityManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
@ -24,9 +20,6 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockStateMeta;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Methods {
@ -92,7 +85,7 @@ public class Methods {
public static String compileItemName(ItemStack item, int amount) {
String nameFormat = Settings.NAME_FORMAT_ITEM.getString();
String displayName = Methods.formatText(UltimateStacker.getInstance().getItemFile()
String displayName = TextUtils.formatText(UltimateStacker.getInstance().getItemFile()
.getString("Items." + item.getType().name() + ".Display Name"));
if (item.hasItemMeta() && item.getItemMeta().hasDisplayName())
@ -110,31 +103,31 @@ public class Methods {
String info = TextUtils.convertToInvisibleString(Methods.insertSemicolon(String.valueOf(amount)) + ":");
return info + Methods.formatText(nameFormat).trim();
return info + TextUtils.formatText(nameFormat).trim();
}
public static String compileSpawnerName(EntityType entityType, int amount) {
String nameFormat = UltimateStacker.getInstance().getConfig().getString("Spawners.Name Format");
String displayName = Methods.formatText(UltimateStacker.getInstance().getSpawnerFile().getString("Spawners." + entityType.name() + ".Display Name"));
String displayName = TextUtils.formatText(UltimateStacker.getInstance().getSpawnerFile().getString("Spawners." + entityType.name() + ".Display Name"));
nameFormat = nameFormat.replace("{TYPE}", displayName);
nameFormat = nameFormat.replace("{AMT}", Integer.toString(amount));
return Methods.formatText(nameFormat).trim();
return TextUtils.formatText(nameFormat).trim();
}
public static String compileEntityName(Entity entity, int amount) {
String nameFormat = Settings.NAME_FORMAT_ENTITY.getString();
String displayName = Methods.formatText(UltimateStacker.getInstance().getMobFile().getString("Mobs." + entity.getType().name() + ".Display Name"));
String displayName = TextUtils.formatText(UltimateStacker.getInstance().getMobFile().getString("Mobs." + entity.getType().name() + ".Display Name"));
CustomEntity customEntity = UltimateStacker.getInstance().getCustomEntityManager().getCustomEntity(entity);
CustomEntity customEntity = UltimateStacker.getInstance().getCustomEntityManager().getCustomEntity(entity);
if (customEntity != null)
displayName = customEntity.getDisplayName(entity);
nameFormat = nameFormat.replace("{TYPE}", displayName);
nameFormat = nameFormat.replace("{AMT}", Integer.toString(amount));
return Methods.formatText(nameFormat).trim();
return TextUtils.formatText(nameFormat).trim();
}
public static void takeItem(Player player, int amount) {
@ -173,31 +166,6 @@ public class Methods {
return true;
}
private static Map<String, Location> serializeCache = new HashMap<>();
/**
* Deserializes a location from the string.
*
* @param str The string to parse.
* @return The location that was serialized in the string.
*/
public static Location unserializeLocation(String str) {
if (str == null || str.equals(""))
return null;
if (serializeCache.containsKey(str)) {
return serializeCache.get(str).clone();
}
String cacheKey = str;
str = str.replace("y:", ":").replace("z:", ":").replace("w:", "").replace("x:", ":").replace("/", ".");
List<String> args = Arrays.asList(str.split("\\s*:\\s*"));
World world = Bukkit.getWorld(args.get(0));
double x = Double.parseDouble(args.get(1)), y = Double.parseDouble(args.get(2)), z = Double.parseDouble(args.get(3));
Location location = new Location(world, x, y, z, 0, 0);
serializeCache.put(cacheKey, location.clone());
return location;
}
public static String insertSemicolon(String s) {
if (s == null || s.equals(""))
return "";
@ -205,37 +173,4 @@ public class Methods {
for (char c : s.toCharArray()) hidden.append(";").append(c);
return hidden.toString();
}
public static String formatText(String text) {
if (text == null || text.equals(""))
return "";
return formatText(text, false);
}
public static String formatText(String text, boolean cap) {
if (text == null || text.equals(""))
return "";
if (cap)
text = text.substring(0, 1).toUpperCase() + text.substring(1);
return ChatColor.translateAlternateColorCodes('&', text);
}
public static class Tuple<key, value> {
public final key x;
public final value y;
public Tuple(key x, value y) {
this.x = x;
this.y = y;
}
public key getKey() {
return this.x;
}
public value getValue() {
return this.y;
}
}
}