1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

[Ci skip] Some more refactoring

This commit is contained in:
TheBusyBiscuit 2020-02-21 22:13:38 +01:00
parent 6175cff35a
commit 9ca20379a2
7 changed files with 82 additions and 16 deletions

View File

@ -1,5 +1,7 @@
package io.github.thebusybiscuit.slimefun4.api;
import java.util.logging.Logger;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
@ -34,5 +36,35 @@ public interface SlimefunAddon {
* @return The URL for this Plugin's Bug Tracker, or null
*/
String getBugTrackerURL();
/**
* This method returns the name of this addon, it defaults to the name
* of the {@link JavaPlugin} provided by {@link SlimefunAddon#getJavaPlugin()}
*
* @return The Name of this {@link SlimefunAddon}
*/
default String getName() {
return getJavaPlugin().getName();
}
/**
* This method returns the version of this addon, it defaults to the version
* of the {@link JavaPlugin} provided by {@link SlimefunAddon#getJavaPlugin()}
*
* @return The version of this {@link SlimefunAddon}
*/
default String getPluginVersion() {
return getJavaPlugin().getDescription().getVersion();
}
/**
* This method returns the {@link Logger} of this addon, it defaults to the {@link Logger}
* of the {@link JavaPlugin} provided by {@link SlimefunAddon#getJavaPlugin()}
*
* @return The {@link Logger} of this {@link SlimefunAddon}
*/
default Logger getLogger() {
return getJavaPlugin().getLogger();
}
}

View File

@ -1,6 +1,5 @@
package io.github.thebusybiscuit.slimefun4.api.gps;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@ -46,16 +45,13 @@ public class GPSNetwork {
private final ItemStack worldIcon = SkullItem.fromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzljODg4MWU0MjkxNWE5ZDI5YmI2MWExNmZiMjZkMDU5OTEzMjA0ZDI2NWRmNWI0MzliM2Q3OTJhY2Q1NiJ9fX0=");
public void updateTransmitter(Location l, UUID uuid, boolean online) {
Set<Location> set = transmitters.getOrDefault(uuid, new HashSet<>());
Set<Location> set = transmitters.computeIfAbsent(uuid, id -> new HashSet<>());
if (online) {
if (set.add(l)) {
transmitters.put(uuid, set);
}
set.add(l);
}
else {
set.remove(l);
transmitters.put(uuid, set);
}
}

View File

@ -46,10 +46,10 @@ public class ResearchCommand extends SubCommand {
researchAll(sender, profile, p);
}
else if (args[2].equalsIgnoreCase("reset")) {
reset(sender, profile, p);
reset(profile, p);
}
else {
giveResearch(sender, profile, p, args[2]);
giveResearch(sender, p, args[2]);
}
});
}
@ -64,7 +64,7 @@ public class ResearchCommand extends SubCommand {
}
}
private void giveResearch(CommandSender sender, PlayerProfile profile, Player p, String input) {
private void giveResearch(CommandSender sender, Player p, String input) {
Optional<Research> research = getResearchFromString(input);
if (research.isPresent()) {
@ -86,7 +86,7 @@ public class ResearchCommand extends SubCommand {
}
}
private void reset(CommandSender sender, PlayerProfile profile, Player p) {
private void reset(PlayerProfile profile, Player p) {
for (Research res : SlimefunPlugin.getRegistry().getResearches()) {
profile.setResearched(res, false);
}

View File

@ -6,6 +6,11 @@ import me.mrCookieSlime.Slimefun.Objects.Category;
import org.bukkit.inventory.ItemStack;
/**
*
* @deprecated The method name is very misleading, therefore it should be renamed
*
*/
@Deprecated
public class ReplacingAlloy extends ReplacingItem {

View File

@ -5,6 +5,11 @@ import me.mrCookieSlime.Slimefun.Objects.Category;
import org.bukkit.inventory.ItemStack;
/**
*
* @deprecated The method name is very misleading, therefore it should be renamed
*
*/
@Deprecated
public class ReplacingItem extends SlimefunItem {

View File

@ -21,6 +21,7 @@ import io.github.thebusybiscuit.cscorelib2.collections.OptionalMap;
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
import io.github.thebusybiscuit.slimefun4.api.items.Placeable;
import me.mrCookieSlime.Slimefun.SlimefunGuide;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
@ -41,9 +42,9 @@ import me.mrCookieSlime.Slimefun.api.energy.EnergyTicker;
public class SlimefunItem implements Placeable {
private ItemState state;
private SlimefunAddon addon;
protected String id;
protected SlimefunAddon addon;
protected ItemStack item;
protected Category category;
protected ItemStack[] recipe;
@ -166,14 +167,37 @@ public class SlimefunItem implements Placeable {
return disenchantable;
}
/**
* This method returns whether this {@link SlimefunItem} was hidden from the
* {@link SlimefunGuide}.
*
* @return Whether this {@link SlimefunItem} is hidden.
*/
public boolean isHidden() {
return hidden;
}
/**
* This method returns whether this {@link SlimefunItem} was added by an addon.
*
* @return Whether this {@link SlimefunItem} was added by an addon.
*/
public boolean isAddonItem() {
return !(addon instanceof SlimefunPlugin);
}
/**
* This method returns the {@link SlimefunAddon} that registered this
* {@link SlimefunItem}. If this Item is from Slimefun itself, the current
* instance of {@link SlimefunPlugin} will be returned.
* Use an instanceof check or {@link SlimefunItem#isAddonItem()} to account for that.
*
* @return The {@link SlimefunAddon} that registered this {@link SlimefunItem}
*/
public SlimefunAddon getAddon() {
return addon;
}
public String getPermission() {
return permission;
}
@ -190,6 +214,11 @@ public class SlimefunItem implements Placeable {
return energyTicker;
}
/**
* This method returns whether this {@link SlimefunItem} is disabled.
*
* @return Whether this {@link SlimefunItem} is disabled.
*/
public boolean isDisabled() {
return state != ItemState.ENABLED;
}
@ -202,7 +231,6 @@ public class SlimefunItem implements Placeable {
*/
@Deprecated
public void register() {
// Slimefun.getLogger().log(Level.WARNING, "Another Plugin tried to register an Item (\"{0}\") without assigning it a SlimefunAddon. Please contact the author and notify them to update their Plugin. This is just a warning, performance or your overall experience will NOT be affected. (DO NOT REPORT THIS TO SLIMEFUN)", ChatColor.stripColor(getItemName()));
register((SlimefunAddon) null);
}
@ -635,7 +663,7 @@ public class SlimefunItem implements Placeable {
@Override
public String toString() {
return "SlimefunItem: " + id + " (" + state + ", addon=" + (addon == null ? "Unknown": addon.getJavaPlugin().getName()) + ")";
return "SlimefunItem: " + id + " (" + state + ", addon=" + (addon == null ? "Unknown": addon.getName()) + ")";
}
@Override

View File

@ -94,7 +94,7 @@ public class Talisman extends SlimefunItem {
@Override
public void postRegister() {
EnderTalisman talisman = new EnderTalisman(this);
talisman.register(!isAddonItem());
talisman.register(addon);
}
@Override
@ -107,7 +107,7 @@ public class Talisman extends SlimefunItem {
}
}
private static boolean isTalismanMessage(Talisman talisman){
private static boolean hasMessage(Talisman talisman){
return !("").equalsIgnoreCase(talisman.getSuffix());
}
@ -168,7 +168,7 @@ public class Talisman extends SlimefunItem {
}
private static void sendMessage(Player p, Talisman talisman){
if (isTalismanMessage(talisman)) {
if (hasMessage(talisman)) {
SlimefunPlugin.getLocal().sendMessage(p, "messages.talisman." + talisman.getSuffix(), true);
}
}