1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

[CI skip] Some refactoring

This commit is contained in:
TheBusyBiscuit 2019-12-12 01:45:55 +01:00
parent aa9652cf88
commit 7cb0c521f6
11 changed files with 45 additions and 40 deletions

View File

@ -1,4 +1,4 @@
package me.mrCookieSlime.Slimefun.guides; package io.github.thebusybiscuit.slimefun4.core.guide;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -9,12 +9,13 @@ import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import me.mrCookieSlime.CSCoreLibPlugin.PlayerRunnable; import me.mrCookieSlime.CSCoreLibPlugin.PlayerRunnable;
import me.mrCookieSlime.CSCoreLibPlugin.general.Chat.TellRawMessage; import me.mrCookieSlime.CSCoreLibPlugin.general.Chat.TellRawMessage;
import me.mrCookieSlime.CSCoreLibPlugin.general.Chat.TellRawMessage.HoverAction; import me.mrCookieSlime.CSCoreLibPlugin.general.Chat.TellRawMessage.HoverAction;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.CustomBookOverlay; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.CustomBookOverlay;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
import me.mrCookieSlime.CSCoreLibPlugin.general.String.StringUtils;
import me.mrCookieSlime.Slimefun.SlimefunGuide; import me.mrCookieSlime.Slimefun.SlimefunGuide;
import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
@ -87,25 +88,25 @@ public class BookSlimefunGuide implements ISlimefunGuide {
actions.add(null); actions.add(null);
} }
} }
texts.add(ChatColor.translateAlternateColorCodes('&', "&8\u21E8 &6Tier " + tier)); texts.add(ChatColors.color("&8\u21E8 &6Tier " + tier));
tooltips.add(null); tooltips.add(null);
actions.add(null); actions.add(null);
} }
if (category instanceof LockedCategory && !((LockedCategory) category).hasUnlocked(p, profile)) { if (category instanceof LockedCategory && !((LockedCategory) category).hasUnlocked(p, profile)) {
StringBuilder parents = new StringBuilder(ChatColor.translateAlternateColorCodes('&', "&4&lLOCKED\n\n&7In order to unlock this Category,\n&7you need to unlock all Items from\n&7the following Categories first:\n")); StringBuilder parents = new StringBuilder(ChatColors.color("&4&lLOCKED\n\n&7In order to unlock this Category,\n&7you need to unlock all Items from\n&7the following Categories first:\n"));
for (Category parent: ((LockedCategory) category).getParents()) { for (Category parent: ((LockedCategory) category).getParents()) {
parents.append(ChatColor.translateAlternateColorCodes('&', "\n&c" + StringUtils.formatItemName(parent.getItem(), false))); parents.append(ChatColors.color("\n&c" + ItemUtils.getItemName(parent.getItem())));
} }
texts.add(ChatColor.translateAlternateColorCodes('&', shorten("&c" , StringUtils.formatItemName(category.getItem(), false)))); texts.add(ChatColors.color(shorten("&c" , ItemUtils.getItemName(category.getItem()))));
tooltips.add(parents.toString()); tooltips.add(parents.toString());
actions.add(null); actions.add(null);
} }
else if (category instanceof SeasonalCategory) { else if (category instanceof SeasonalCategory) {
if (((SeasonalCategory) category).isUnlocked()) { if (((SeasonalCategory) category).isUnlocked()) {
texts.add(ChatColor.translateAlternateColorCodes('&', shorten("&a", StringUtils.formatItemName(category.getItem(), false)))); texts.add(ChatColors.color(shorten("&a", ItemUtils.getItemName(category.getItem()))));
tooltips.add(ChatColor.translateAlternateColorCodes('&', "&eClick to open the following Category:\n" + StringUtils.formatItemName(category.getItem(), false))); tooltips.add(ChatColors.color("&eClick to open the following Category:\n" + ItemUtils.getItemName(category.getItem())));
actions.add(new PlayerRunnable(1) { actions.add(new PlayerRunnable(1) {
@Override @Override
public void run(final Player p) { public void run(final Player p) {
@ -115,8 +116,8 @@ public class BookSlimefunGuide implements ISlimefunGuide {
} }
} }
else { else {
texts.add(ChatColor.translateAlternateColorCodes('&', shorten("&a", StringUtils.formatItemName(category.getItem(), false)))); texts.add(ChatColors.color(shorten("&a", ItemUtils.getItemName(category.getItem()))));
tooltips.add(ChatColor.translateAlternateColorCodes('&', "&eClick to open the following Category:\n" + StringUtils.formatItemName(category.getItem(), false))); tooltips.add(ChatColors.color("&eClick to open the following Category:\n" + ItemUtils.getItemName(category.getItem())));
actions.add(new PlayerRunnable(1) { actions.add(new PlayerRunnable(1) {
@Override @Override
public void run(final Player p) { public void run(final Player p) {
@ -141,7 +142,7 @@ public class BookSlimefunGuide implements ISlimefunGuide {
for (int i = 0; i < texts.size(); i = i + 10) { for (int i = 0; i < texts.size(); i = i + 10) {
TellRawMessage pageMessage = new TellRawMessage(); TellRawMessage pageMessage = new TellRawMessage();
pageMessage.addText(ChatColor.translateAlternateColorCodes('&', "&b&l- Slimefun Guide -\n\n")); pageMessage.addText(ChatColors.color("&b&l- Slimefun Guide -\n\n"));
for (int j = i; j < texts.size() && j < i + 10; j++) { for (int j = i; j < texts.size() && j < i + 10; j++) {
pageMessage.addText(texts.get(j) + "\n"); pageMessage.addText(texts.get(j) + "\n");
if (tooltips.get(j) != null) pageMessage.addHoverEvent(HoverAction.SHOW_TEXT, tooltips.get(j)); if (tooltips.get(j) != null) pageMessage.addHoverEvent(HoverAction.SHOW_TEXT, tooltips.get(j));
@ -175,8 +176,8 @@ public class BookSlimefunGuide implements ISlimefunGuide {
if (survival && !Slimefun.hasUnlocked(p, item, false) && item.getResearch() != null) { if (survival && !Slimefun.hasUnlocked(p, item, false) && item.getResearch() != null) {
final Research research = item.getResearch(); final Research research = item.getResearch();
texts.add(ChatColor.translateAlternateColorCodes('&', shorten("&7", StringUtils.formatItemName(item.getItem(), false)))); texts.add(ChatColors.color(shorten("&7", item.getItemName())));
tooltips.add(ChatColor.translateAlternateColorCodes('&', StringUtils.formatItemName(item.getItem(), false) + "\n&c&lLOCKED\n\n&7Cost: " + (p.getLevel() >= research.getCost() ? "&b": "&4") + research.getCost() + " Levels\n\n&a> Click to unlock")); tooltips.add(ChatColors.color(item.getItemName() + "\n&c&lLOCKED\n\n&7Cost: " + (p.getLevel() >= research.getCost() ? "&b": "&4") + research.getCost() + " Levels\n\n&a> Click to unlock"));
actions.add(new PlayerRunnable(2) { actions.add(new PlayerRunnable(2) {
@Override @Override
@ -207,11 +208,11 @@ public class BookSlimefunGuide implements ISlimefunGuide {
}); });
} }
else { else {
texts.add(ChatColor.translateAlternateColorCodes('&', shorten("&a", StringUtils.formatItemName(item.getItem(), false)))); texts.add(ChatColors.color(shorten("&a", item.getItemName())));
StringBuilder tooltip = new StringBuilder(); StringBuilder tooltip = new StringBuilder();
tooltip.append(StringUtils.formatItemName(item.getItem(), false)); tooltip.append(item.getItemName());
if (item.getItem().hasItemMeta() && item.getItem().getItemMeta().hasLore()) { if (item.getItem().hasItemMeta() && item.getItem().getItemMeta().hasLore()) {
for (String line : item.getItem().getItemMeta().getLore()) { for (String line : item.getItem().getItemMeta().getLore()) {
@ -219,7 +220,7 @@ public class BookSlimefunGuide implements ISlimefunGuide {
} }
} }
tooltip.append(ChatColor.translateAlternateColorCodes('&', "\n\n&e&oClick for more Info")); tooltip.append(ChatColors.color("\n\n&e&oClick for more Info"));
tooltips.add(tooltip.toString()); tooltips.add(tooltip.toString());
actions.add(new PlayerRunnable(2) { actions.add(new PlayerRunnable(2) {
@ -233,15 +234,15 @@ public class BookSlimefunGuide implements ISlimefunGuide {
} }
} }
else { else {
texts.add(ChatColor.translateAlternateColorCodes('&', shorten("&4", StringUtils.formatItemName(item.getItem(), false)))); texts.add(ChatColors.color(shorten("&4", ItemUtils.getItemName(item.getItem()))));
tooltips.add(ChatColor.translateAlternateColorCodes('&', "&cNo Permission!")); tooltips.add(ChatColors.color("&cNo Permission!"));
actions.add(null); actions.add(null);
} }
} }
for (int i = 0; i < texts.size(); i = i + 10) { for (int i = 0; i < texts.size(); i = i + 10) {
TellRawMessage pageMessage = new TellRawMessage(); TellRawMessage pageMessage = new TellRawMessage();
pageMessage.addText(ChatColor.translateAlternateColorCodes('&', "&b&l- Slimefun Guide -\n\n")); pageMessage.addText(ChatColors.color("&b&l- Slimefun Guide -\n\n"));
for (int j = i; j < texts.size() && j < i + 10; j++) { for (int j = i; j < texts.size() && j < i + 10; j++) {
pageMessage.addText(texts.get(j) + "\n"); pageMessage.addText(texts.get(j) + "\n");
@ -250,8 +251,8 @@ public class BookSlimefunGuide implements ISlimefunGuide {
} }
pageMessage.addText("\n"); pageMessage.addText("\n");
pageMessage.addText(ChatColor.translateAlternateColorCodes('&', "&6\u21E6 &lBack")); pageMessage.addText(ChatColors.color("&6\u21E6 &lBack"));
pageMessage.addHoverEvent(HoverAction.SHOW_TEXT, ChatColor.translateAlternateColorCodes('&', "&eClick to go back to the Category Overview")); pageMessage.addHoverEvent(HoverAction.SHOW_TEXT, ChatColors.color("&eClick to go back to the Category Overview"));
pageMessage.addClickEvent(new PlayerRunnable(2) { pageMessage.addClickEvent(new PlayerRunnable(2) {
@Override @Override

View File

@ -1,4 +1,4 @@
package me.mrCookieSlime.Slimefun.guides; package io.github.thebusybiscuit.slimefun4.core.guide;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -93,7 +93,7 @@ public class ChestSlimefunGuide implements ISlimefunGuide {
Category category = categories.get(target); Category category = categories.get(target);
boolean locked = true; boolean locked = true;
for (SlimefunItem item: category.getItems()) { for (SlimefunItem item : category.getItems()) {
if (Slimefun.isEnabled(p, item, false)) { if (Slimefun.isEnabled(p, item, false)) {
locked = false; locked = false;
break; break;

View File

@ -1,4 +1,4 @@
package me.mrCookieSlime.Slimefun.guides; package io.github.thebusybiscuit.slimefun4.core.guide;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
@ -196,7 +196,7 @@ public final class GuideSettings {
List<String> lore = new LinkedList<>(); List<String> lore = new LinkedList<>();
lore.add(""); lore.add("");
for (Map.Entry<String, Integer> entry: contributor.getContributions().entrySet()) { for (Map.Entry<String, Integer> entry : contributor.getContributions().entrySet()) {
String info = entry.getKey(); String info = entry.getKey();
if (entry.getValue() > 0) { if (entry.getValue() > 0) {

View File

@ -1,4 +1,4 @@
package me.mrCookieSlime.Slimefun.guides; package io.github.thebusybiscuit.slimefun4.core.guide;
import java.util.LinkedList; import java.util.LinkedList;
@ -22,8 +22,12 @@ public interface ISlimefunGuide {
void displayItem(PlayerProfile profile, SlimefunItem item, boolean addToHistory); void displayItem(PlayerProfile profile, SlimefunItem item, boolean addToHistory);
default String shorten(String string, String string2) { default String shorten(String string, String string2) {
if (ChatColor.stripColor(string + string2).length() > 19) return (string + ChatColor.stripColor(string2)).substring(0, 18) + "..."; if (ChatColor.stripColor(string + string2).length() > 19) {
else return (string + ChatColor.stripColor(string2)); return (string + ChatColor.stripColor(string2)).substring(0, 18) + "...";
}
else {
return string + ChatColor.stripColor(string2);
}
} }
default Object getLastEntry(PlayerProfile profile, boolean remove) { default Object getLastEntry(PlayerProfile profile, boolean remove) {

View File

@ -1,4 +1,4 @@
package me.mrCookieSlime.Slimefun.guides; package io.github.thebusybiscuit.slimefun4.core.guide;
public enum SlimefunGuideLayout { public enum SlimefunGuideLayout {

View File

@ -12,16 +12,16 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors; import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
import io.github.thebusybiscuit.slimefun4.core.guide.BookSlimefunGuide;
import io.github.thebusybiscuit.slimefun4.core.guide.ChestSlimefunGuide;
import io.github.thebusybiscuit.slimefun4.core.guide.ISlimefunGuide;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager; import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
import me.mrCookieSlime.Slimefun.api.PlayerProfile; import me.mrCookieSlime.Slimefun.api.PlayerProfile;
import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.guides.BookSlimefunGuide;
import me.mrCookieSlime.Slimefun.guides.ChestSlimefunGuide;
import me.mrCookieSlime.Slimefun.guides.ISlimefunGuide;
import me.mrCookieSlime.Slimefun.guides.SlimefunGuideLayout;
public final class SlimefunGuide { public final class SlimefunGuide {

View File

@ -3,11 +3,11 @@ package me.mrCookieSlime.Slimefun.commands.subcommands;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout;
import me.mrCookieSlime.Slimefun.SlimefunGuide; import me.mrCookieSlime.Slimefun.SlimefunGuide;
import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.commands.SlimefunCommand; import me.mrCookieSlime.Slimefun.commands.SlimefunCommand;
import me.mrCookieSlime.Slimefun.commands.SubCommand; import me.mrCookieSlime.Slimefun.commands.SubCommand;
import me.mrCookieSlime.Slimefun.guides.SlimefunGuideLayout;
public class GuideCommand extends SubCommand { public class GuideCommand extends SubCommand {

View File

@ -3,11 +3,11 @@ package me.mrCookieSlime.Slimefun.commands.subcommands;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout;
import me.mrCookieSlime.Slimefun.SlimefunGuide; import me.mrCookieSlime.Slimefun.SlimefunGuide;
import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.commands.SlimefunCommand; import me.mrCookieSlime.Slimefun.commands.SlimefunCommand;
import me.mrCookieSlime.Slimefun.commands.SubCommand; import me.mrCookieSlime.Slimefun.commands.SubCommand;
import me.mrCookieSlime.Slimefun.guides.SlimefunGuideLayout;
public class OpenGuideCommand extends SubCommand { public class OpenGuideCommand extends SubCommand {

View File

@ -5,9 +5,9 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout;
import me.mrCookieSlime.Slimefun.SlimefunGuide; import me.mrCookieSlime.Slimefun.SlimefunGuide;
import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.guides.SlimefunGuideLayout;
public class GuideOnJoinListener implements Listener { public class GuideOnJoinListener implements Listener {

View File

@ -37,6 +37,8 @@ import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import io.github.thebusybiscuit.slimefun4.core.guide.GuideSettings;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout;
import me.mrCookieSlime.CSCoreLibPlugin.events.ItemUseEvent; import me.mrCookieSlime.CSCoreLibPlugin.events.ItemUseEvent;
import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull; import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull;
import me.mrCookieSlime.Slimefun.SlimefunGuide; import me.mrCookieSlime.Slimefun.SlimefunGuide;
@ -58,8 +60,6 @@ import me.mrCookieSlime.Slimefun.api.energy.ItemEnergy;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu;
import me.mrCookieSlime.Slimefun.guides.GuideSettings;
import me.mrCookieSlime.Slimefun.guides.SlimefunGuideLayout;
import me.mrCookieSlime.Slimefun.utils.Utilities; import me.mrCookieSlime.Slimefun.utils.Utilities;
public class ItemListener implements Listener { public class ItemListener implements Listener {

View File

@ -16,6 +16,8 @@ import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.config.Config; import io.github.thebusybiscuit.cscorelib2.config.Config;
import io.github.thebusybiscuit.slimefun4.core.guide.ISlimefunGuide;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout;
import me.mrCookieSlime.Slimefun.GEO.OreGenResource; import me.mrCookieSlime.Slimefun.GEO.OreGenResource;
import me.mrCookieSlime.Slimefun.Lists.Categories; import me.mrCookieSlime.Slimefun.Lists.Categories;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
@ -34,8 +36,6 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu;
import me.mrCookieSlime.Slimefun.api.item_transport.CargoTransportEvent; import me.mrCookieSlime.Slimefun.api.item_transport.CargoTransportEvent;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemRequest; import me.mrCookieSlime.Slimefun.api.item_transport.ItemRequest;
import me.mrCookieSlime.Slimefun.guides.ISlimefunGuide;
import me.mrCookieSlime.Slimefun.guides.SlimefunGuideLayout;
/** /**
* Really dirty way to store stuff, but you can dump * Really dirty way to store stuff, but you can dump