mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
[CI skip] Removed CS-CoreLib Auto-Installer and reduced technical debt
This commit is contained in:
parent
5730907da3
commit
59fb83e871
@ -25,7 +25,7 @@ public class NetherIceResource implements OreGenResource {
|
||||
|
||||
@Override
|
||||
public String getMeasurementUnit() {
|
||||
return "Blocks";
|
||||
return "Block(s)";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -86,7 +86,7 @@ public class OilResource implements OreGenResource {
|
||||
|
||||
@Override
|
||||
public String getMeasurementUnit() {
|
||||
return "Buckets";
|
||||
return "Bucket(s)";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,7 +39,7 @@ public class UraniumResource implements OreGenResource {
|
||||
|
||||
@Override
|
||||
public String getMeasurementUnit() {
|
||||
return "Pieces";
|
||||
return "Piece(s)";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,13 +39,15 @@ public final class GEOScanner {
|
||||
}
|
||||
|
||||
int index = 10;
|
||||
for (OreGenResource resource: OreGenSystem.listResources()) {
|
||||
for (OreGenResource resource : OreGenSystem.listResources()) {
|
||||
int supply = OreGenSystem.getSupplies(resource, chunk, true);
|
||||
|
||||
ItemStack item = new CustomItem(resource.getItem(), "&r" + resource.getName(), "&8\u21E8 &e" + supply + ' ' + resource.getMeasurementUnit());
|
||||
|
||||
if (supply > 1) {
|
||||
item.setAmount(supply > item.getMaxStackSize() ? item.getMaxStackSize(): supply);
|
||||
}
|
||||
|
||||
menu.addItem(index, item, (pl, slot, stack, action) -> false);
|
||||
index++;
|
||||
|
||||
|
@ -132,22 +132,6 @@ public class Category {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to get the category with the given display item.
|
||||
*
|
||||
* @param item the display item of the category to get
|
||||
* @return Category if found, or null
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
@Deprecated
|
||||
public static Category getByItem(ItemStack item) {
|
||||
for (Category c: list()) {
|
||||
if (c.getItem().isSimilar(item)) return c;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tier of this category.
|
||||
*
|
||||
|
@ -86,7 +86,8 @@ public class LockedCategory extends Category {
|
||||
* @see #removeParent(Category)
|
||||
*/
|
||||
public void addParent(Category category) {
|
||||
if (category == this) throw new IllegalArgumentException("Category '" + this.getItem().getItemMeta().getDisplayName() + "' cannot be a parent of itself.");
|
||||
if (category == this || category == null) throw new IllegalArgumentException("Category '" + this.getItem().getItemMeta().getDisplayName() + "' cannot be a parent of itself or have a 'null' parent.");
|
||||
|
||||
this.parents.add(category);
|
||||
}
|
||||
|
||||
@ -116,8 +117,8 @@ public class LockedCategory extends Category {
|
||||
}
|
||||
|
||||
public boolean hasUnlocked(Player p, PlayerProfile profile) {
|
||||
for (Category category: parents) {
|
||||
for (SlimefunItem item: category.getItems()) {
|
||||
for (Category category : parents) {
|
||||
for (SlimefunItem item : category.getItems()) {
|
||||
if (Slimefun.isEnabled(p, item, false)
|
||||
&& Slimefun.hasPermission(p, item, false)
|
||||
&& item.getResearch() != null
|
||||
@ -126,6 +127,7 @@ public class LockedCategory extends Category {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
*/
|
||||
public class Research {
|
||||
|
||||
private static final int[] research_progress = {23, 44, 57, 92};
|
||||
private static final int[] RESEARCH_PROGRESS = {23, 44, 57, 92};
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
@ -94,32 +94,6 @@ public class Research {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cost in XP levels to unlock the research.
|
||||
*
|
||||
* @return The cost in XP levels of the research
|
||||
*
|
||||
* @since 4.0
|
||||
* @deprecated Moved to {@link #getCost()}
|
||||
*/
|
||||
@Deprecated
|
||||
public int getLevel() {
|
||||
return getCost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cost in XP levels to unlock the research.
|
||||
*
|
||||
* @param level Cost in XP levels
|
||||
*
|
||||
* @since 4.0
|
||||
* @deprecated Moved to {@link #setCost(int)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setLevel(int level) {
|
||||
setCost(level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cost in XP levels to unlock the research.
|
||||
*
|
||||
@ -258,19 +232,19 @@ public class Research {
|
||||
SlimefunPlugin.getUtilities().researching.add(p.getUniqueId());
|
||||
SlimefunPlugin.getLocal().sendMessage(p, "messages.research.start", true, msg -> msg.replace("%research%", getName()));
|
||||
|
||||
for (int i = 1; i < research_progress.length + 1; i++) {
|
||||
for (int i = 1; i < RESEARCH_PROGRESS.length + 1; i++) {
|
||||
int j = i;
|
||||
|
||||
Slimefun.runSync(() -> {
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 0.7F, 1F);
|
||||
SlimefunPlugin.getLocal().sendMessage(p, "messages.research.progress", true, msg -> msg.replace("%research%", getName()).replace("%progress%", research_progress[j - 1] + "%"));
|
||||
SlimefunPlugin.getLocal().sendMessage(p, "messages.research.progress", true, msg -> msg.replace("%research%", getName()).replace("%progress%", RESEARCH_PROGRESS[j - 1] + "%"));
|
||||
}, i * 20L);
|
||||
}
|
||||
|
||||
Slimefun.runSync(() -> {
|
||||
runnable.run();
|
||||
SlimefunPlugin.getUtilities().researching.remove(p.getUniqueId());
|
||||
}, (research_progress.length + 1) * 20L);
|
||||
}, (RESEARCH_PROGRESS.length + 1) * 20L);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -18,7 +18,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
*/
|
||||
public class SeasonalCategory extends Category {
|
||||
|
||||
private int month = -1;
|
||||
private final int month;
|
||||
|
||||
/**
|
||||
* The constructor for a SeasonCategory.
|
||||
@ -34,6 +34,11 @@ public class SeasonalCategory extends Category {
|
||||
*/
|
||||
public SeasonalCategory(int month, int tier, ItemStack item) {
|
||||
super(item, tier);
|
||||
|
||||
if (month < 1 || month > 12) {
|
||||
throw new IllegalArgumentException("There is no month no. " + month);
|
||||
}
|
||||
|
||||
this.month = month - 1;
|
||||
}
|
||||
|
||||
@ -58,7 +63,6 @@ public class SeasonalCategory extends Category {
|
||||
* @see #getMonth()
|
||||
*/
|
||||
public boolean isUnlocked() {
|
||||
if (month == -1) return true;
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
return month == calendar.get(Calendar.MONTH);
|
||||
}
|
||||
|
@ -1,161 +0,0 @@
|
||||
package me.mrCookieSlime.Slimefun.Setup;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
@Deprecated
|
||||
public class CSCoreLibLoader {
|
||||
|
||||
private Plugin plugin;
|
||||
private URL url;
|
||||
private URL download;
|
||||
private File file;
|
||||
|
||||
public CSCoreLibLoader(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
try {
|
||||
this.url = new URL("https://api.curseforge.com/servermods/files?projectIds=88802");
|
||||
} catch (MalformedURLException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "The Auto-Updater URL is malformed!", e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean load() {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("CS-CoreLib")) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
plugin.getLogger().log(Level.INFO, " ");
|
||||
plugin.getLogger().log(Level.INFO, "#################### - INFO - ####################");
|
||||
plugin.getLogger().log(Level.INFO, " ");
|
||||
plugin.getLogger().log(Level.INFO, plugin.getName() + " could not be loaded (yet).");
|
||||
plugin.getLogger().log(Level.INFO, "It appears that you have not installed CS-CoreLib.");
|
||||
plugin.getLogger().log(Level.INFO, "Your Server will now try to download and install");
|
||||
plugin.getLogger().log(Level.INFO, "CS-CoreLib for you.");
|
||||
plugin.getLogger().log(Level.INFO, "You will be asked to restart your Server when it's finished.");
|
||||
plugin.getLogger().log(Level.INFO, "If this somehow fails, please download and install CS-CoreLib manually:");
|
||||
plugin.getLogger().log(Level.INFO, "https://dev.bukkit.org/projects/cs-corelib");
|
||||
plugin.getLogger().log(Level.INFO, " ");
|
||||
plugin.getLogger().log(Level.INFO, "#################### - INFO - ####################");
|
||||
plugin.getLogger().log(Level.INFO, " ");
|
||||
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
|
||||
if (connect()) {
|
||||
install();
|
||||
}
|
||||
}, 10L);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean connect() {
|
||||
try {
|
||||
final URLConnection connection = this.url.openConnection();
|
||||
connection.setConnectTimeout(5000);
|
||||
connection.addRequestProperty("User-Agent", "CS-CoreLib Loader (by mrCookieSlime)");
|
||||
connection.setDoOutput(true);
|
||||
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
final JsonArray array = new JsonParser().parse(reader).getAsJsonArray();
|
||||
final JsonObject json = array.get(array.size() - 1).getAsJsonObject();
|
||||
|
||||
download = traceURL(json.get("downloadUrl").getAsString().replace("https:", "http:"));
|
||||
file = new File("plugins/" + json.get("name").getAsString() + ".jar");
|
||||
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().log(Level.WARNING, " ");
|
||||
plugin.getLogger().log(Level.WARNING, "#################### - WARNING - ####################");
|
||||
plugin.getLogger().log(Level.WARNING, " ");
|
||||
plugin.getLogger().log(Level.WARNING, "Could not connect to BukkitDev.");
|
||||
plugin.getLogger().log(Level.WARNING, "Please download & install CS-CoreLib manually:");
|
||||
plugin.getLogger().log(Level.WARNING, "https://dev.bukkit.org/projects/cs-corelib");
|
||||
plugin.getLogger().log(Level.WARNING, " ");
|
||||
plugin.getLogger().log(Level.WARNING, "#################### - WARNING - ####################");
|
||||
plugin.getLogger().log(Level.WARNING, " ");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private URL traceURL(String location) throws IOException {
|
||||
HttpURLConnection connection = null;
|
||||
|
||||
while (true) {
|
||||
URL url = new URL(location);
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
|
||||
connection.setInstanceFollowRedirects(false);
|
||||
connection.setConnectTimeout(5000);
|
||||
connection.addRequestProperty("User-Agent", "Auto Updater (by mrCookieSlime)");
|
||||
|
||||
int response = connection.getResponseCode();
|
||||
|
||||
if (response == HttpURLConnection.HTTP_MOVED_PERM || response == HttpURLConnection.HTTP_MOVED_TEMP) {
|
||||
String loc = connection.getHeaderField("Location");
|
||||
location = new URL(new URL(location), loc).toExternalForm();
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new URL(connection.getURL().toString().replace(" ", "%20"));
|
||||
}
|
||||
|
||||
private void install() {
|
||||
BufferedInputStream input = null;
|
||||
FileOutputStream output = null;
|
||||
try {
|
||||
input = new BufferedInputStream(download.openStream());
|
||||
output = new FileOutputStream(file);
|
||||
|
||||
final byte[] data = new byte[1024];
|
||||
int read;
|
||||
while ((read = input.read(data, 0, 1024)) != -1) {
|
||||
output.write(data, 0, read);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
plugin.getLogger().log(Level.WARNING, " ");
|
||||
plugin.getLogger().log(Level.WARNING, "#################### - WARNING - ####################");
|
||||
plugin.getLogger().log(Level.WARNING, " ");
|
||||
plugin.getLogger().log(Level.WARNING, "Failed to download CS-CoreLib");
|
||||
plugin.getLogger().log(Level.WARNING, "Please download & install CS-CoreLib manually:");
|
||||
plugin.getLogger().log(Level.WARNING, "https://dev.bukkit.org/projects/cs-corelib");
|
||||
plugin.getLogger().log(Level.WARNING, " ");
|
||||
plugin.getLogger().log(Level.WARNING, "#################### - WARNING - ####################");
|
||||
plugin.getLogger().log(Level.WARNING, " ");
|
||||
} finally {
|
||||
try {
|
||||
if (input != null) input.close();
|
||||
if (output != null) output.close();
|
||||
plugin.getLogger().log(Level.INFO, " ");
|
||||
plugin.getLogger().log(Level.INFO, "#################### - INFO - ####################");
|
||||
plugin.getLogger().log(Level.INFO, " ");
|
||||
plugin.getLogger().log(Level.INFO, "Please restart your Server to finish the Installation");
|
||||
plugin.getLogger().log(Level.INFO, "of " + plugin.getName() + " and CS-CoreLib");
|
||||
plugin.getLogger().log(Level.INFO, " ");
|
||||
plugin.getLogger().log(Level.INFO, "#################### - INFO - ####################");
|
||||
plugin.getLogger().log(Level.INFO, " ");
|
||||
} catch (IOException x) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An Error occured while closing the Download Stream for CS-CoreLib", x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -36,7 +36,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AGenerator;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AReactor;
|
||||
import me.mrCookieSlime.Slimefun.Objects.tasks.ArmorTask;
|
||||
import me.mrCookieSlime.Slimefun.Setup.CSCoreLibLoader;
|
||||
import me.mrCookieSlime.Slimefun.Setup.Files;
|
||||
import me.mrCookieSlime.Slimefun.Setup.MiscSetup;
|
||||
import me.mrCookieSlime.Slimefun.Setup.ResearchSetup;
|
||||
@ -106,7 +105,7 @@ public final class SlimefunPlugin extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
if (new CSCoreLibLoader(this).load()) {
|
||||
if (getServer().getPluginManager().isPluginEnabled("CS-CoreLib")) {
|
||||
|
||||
String currentVersion = ReflectionUtils.getVersion();
|
||||
|
||||
@ -317,9 +316,16 @@ public final class SlimefunPlugin extends JavaPlugin {
|
||||
CSCoreLib.getLib().filterLog("([A-Za-z0-9_]{3,16}) issued server command: /sf elevator (.{0,})");
|
||||
}
|
||||
else {
|
||||
getLogger().log(Level.INFO, "#################### - INFO - ####################");
|
||||
getLogger().log(Level.INFO, " ");
|
||||
getLogger().log(Level.INFO, "Slimefun could not be loaded (yet).");
|
||||
getLogger().log(Level.INFO, "It appears that you have not installed CS-CoreLib.");
|
||||
getLogger().log(Level.INFO, "Please download and install CS-CoreLib manually:");
|
||||
getLogger().log(Level.INFO, "https://thebusybiscuit.github.io/builds/TheBusyBiscuit/CS-CoreLib/master/");
|
||||
|
||||
getCommand("slimefun").setExecutor((sender, cmd, label, args) -> {
|
||||
sender.sendMessage("You have forgotten to install CS-CoreLib! Slimefun is disabled.");
|
||||
sender.sendMessage("https://dev.bukkit.org/projects/cs-corelib");
|
||||
sender.sendMessage("https://thebusybiscuit.github.io/builds/TheBusyBiscuit/CS-CoreLib/master/");
|
||||
return true;
|
||||
});
|
||||
}
|
||||
@ -342,7 +348,7 @@ public final class SlimefunPlugin extends JavaPlugin {
|
||||
if (profile.isDirty()) profile.save();
|
||||
});
|
||||
|
||||
for (World world: Bukkit.getWorlds()) {
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
try {
|
||||
BlockStorage storage = BlockStorage.getStorage(world);
|
||||
|
||||
@ -357,7 +363,7 @@ public final class SlimefunPlugin extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
for (UniversalBlockMenu menu: utilities.universalInventories.values()) {
|
||||
for (UniversalBlockMenu menu : utilities.universalInventories.values()) {
|
||||
menu.save();
|
||||
}
|
||||
|
||||
@ -375,7 +381,7 @@ public final class SlimefunPlugin extends JavaPlugin {
|
||||
|
||||
instance = null;
|
||||
|
||||
for (Player p: Bukkit.getOnlinePlayers()) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
p.closeInventory();
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
|
||||
public class AltarRecipe {
|
||||
|
||||
private ItemStack catalyst;
|
||||
private List<ItemStack> input;
|
||||
private ItemStack output;
|
||||
private final ItemStack catalyst;
|
||||
private final List<ItemStack> input;
|
||||
private final ItemStack output;
|
||||
|
||||
public AltarRecipe(List<ItemStack> input, ItemStack output) {
|
||||
this.catalyst = input.get(4);
|
||||
|
@ -102,7 +102,7 @@ public class AncientAltarListener implements Listener {
|
||||
|
||||
if (catalyst.getType() != Material.AIR) {
|
||||
List<ItemStack> input = new ArrayList<>();
|
||||
for (Block pedestal: pedestals) {
|
||||
for (Block pedestal : pedestals) {
|
||||
Item stack = findItem(pedestal);
|
||||
if (stack != null) input.add(fixItemStack(stack.getItemStack(), stack.getCustomName()));
|
||||
}
|
||||
@ -177,7 +177,7 @@ public class AncientAltarListener implements Listener {
|
||||
}
|
||||
|
||||
public static Item findItem(Block b) {
|
||||
for (Entity n: b.getChunk().getEntities()) {
|
||||
for (Entity n : b.getChunk().getEntities()) {
|
||||
if (n instanceof Item && b.getLocation().add(0.5, 1.2, 0.5).distanceSquared(n.getLocation()) < 0.5D && n.getCustomName() != null) return (Item) n;
|
||||
}
|
||||
return null;
|
||||
|
@ -54,7 +54,8 @@ public final class Pedestals {
|
||||
|
||||
if (SlimefunManager.isItemSimilar(catalyst, SlimefunItems.BROKEN_SPAWNER, false)) {
|
||||
if (checkRecipe(SlimefunItems.BROKEN_SPAWNER, input) == null) return null;
|
||||
final ItemStack spawner = SlimefunItems.REPAIRED_SPAWNER.clone();
|
||||
|
||||
ItemStack spawner = SlimefunItems.REPAIRED_SPAWNER.clone();
|
||||
ItemMeta im = spawner.getItemMeta();
|
||||
im.setLore(Arrays.asList(catalyst.getItemMeta().getLore().get(0)));
|
||||
spawner.setItemMeta(im);
|
||||
@ -65,7 +66,7 @@ public final class Pedestals {
|
||||
}
|
||||
|
||||
private static ItemStack checkRecipe(ItemStack catalyst, List<ItemStack> items) {
|
||||
for (AltarRecipe recipe: SlimefunPlugin.getUtilities().altarRecipes) {
|
||||
for (AltarRecipe recipe : SlimefunPlugin.getUtilities().altarRecipes) {
|
||||
if (SlimefunManager.isItemSimilar(catalyst, recipe.getCatalyst(), true)) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (SlimefunManager.isItemSimilar(items.get(i), recipe.getInput().get(0), true)) {
|
||||
|
@ -49,7 +49,7 @@ public class RitualAnimation implements Runnable {
|
||||
this.running = true;
|
||||
this.stage = 0;
|
||||
|
||||
for (Block pedestal: this.pedestals) {
|
||||
for (Block pedestal : this.pedestals) {
|
||||
Item item = AncientAltarListener.findItem(pedestal);
|
||||
this.itemLock.put(item, item.getLocation().clone());
|
||||
}
|
||||
@ -78,7 +78,7 @@ public class RitualAnimation implements Runnable {
|
||||
}
|
||||
|
||||
private boolean checkLockedItems() {
|
||||
for (Map.Entry<Item, Location> entry: itemLock.entrySet()) {
|
||||
for (Map.Entry<Item, Location> entry : itemLock.entrySet()) {
|
||||
if (entry.getKey().getLocation().distance(entry.getValue()) > 0.3) {
|
||||
return false;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public class BlockAutoSaver implements Runnable {
|
||||
if (!worlds.isEmpty()) {
|
||||
Slimefun.getLogger().log(Level.INFO, "Auto-Saving Block Data... (Next Auto-Save: " + SlimefunPlugin.getCfg().getInt("options.auto-save-delay-in-minutes") + "m)");
|
||||
|
||||
for (BlockStorage storage: worlds) {
|
||||
for (BlockStorage storage : worlds) {
|
||||
storage.save(false);
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ public class SlimefunCommand implements CommandExecutor, Listener {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
for (SubCommand command: commands) {
|
||||
for (SubCommand command : commands) {
|
||||
if (args[0].equalsIgnoreCase(command.getName())) {
|
||||
command.onExecute(sender, args);
|
||||
return true;
|
||||
@ -110,7 +110,8 @@ public class SlimefunCommand implements CommandExecutor, Listener {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aSlimefun &2v" + Slimefun.getVersion()));
|
||||
sender.sendMessage("");
|
||||
for (SubCommand cmd: commands) {
|
||||
|
||||
for (SubCommand cmd : commands) {
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&3/sf " + cmd.getName() + " &b") + cmd.getDescription());
|
||||
}
|
||||
}
|
||||
|
@ -29,9 +29,11 @@ public class SlimefunTabCompleter implements TabCompleter {
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("research")) {
|
||||
List<String> researches = new ArrayList<>();
|
||||
|
||||
for (Research res : Research.list()) {
|
||||
researches.add(res.getName().toUpperCase().replace(' ', '_'));
|
||||
}
|
||||
|
||||
researches.add("all");
|
||||
researches.add("reset");
|
||||
return createReturnList(researches, args[2]);
|
||||
@ -55,11 +57,13 @@ public class SlimefunTabCompleter implements TabCompleter {
|
||||
if (string.equals("")) return list;
|
||||
|
||||
List<String> returnList = new ArrayList<>();
|
||||
|
||||
for (String item : list) {
|
||||
if (item.toLowerCase().startsWith(string.toLowerCase())) {
|
||||
returnList.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
return returnList;
|
||||
}
|
||||
|
||||
|
@ -23,10 +23,12 @@ public class WorldEditHook {
|
||||
@Subscribe
|
||||
public void wrapForLogging(final EditSessionEvent event) {
|
||||
event.setExtent(new AbstractDelegateExtent(event.getExtent()) {
|
||||
|
||||
@Override
|
||||
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 pos, T block) throws WorldEditException {
|
||||
if (block.getBlockType().getMaterial().isAir()) {
|
||||
World world = Bukkit.getWorld(event.getWorld().getName());
|
||||
|
||||
if (world != null) {
|
||||
Location l = new Location(world, pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
|
||||
if (BlockStorage.hasBlockInfo(l)) BlockStorage.clearBlockInfo(l);
|
||||
@ -34,6 +36,7 @@ public class WorldEditHook {
|
||||
}
|
||||
return getExtent().setBlock(pos, block);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package me.mrCookieSlime.Slimefun.listeners;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@ -21,8 +22,6 @@ import me.mrCookieSlime.Slimefun.androids.AndroidEntity;
|
||||
|
||||
public class AndroidKillingListener implements Listener {
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
public AndroidKillingListener(SlimefunPlugin plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
@ -42,6 +41,8 @@ public class AndroidKillingListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
Random random = ThreadLocalRandom.current();
|
||||
|
||||
switch (e.getEntityType()) {
|
||||
case BLAZE:
|
||||
items.add(new ItemStack(Material.BLAZE_ROD, 1 + random.nextInt(2)));
|
||||
@ -58,7 +59,7 @@ public class AndroidKillingListener implements Listener {
|
||||
break;
|
||||
}
|
||||
|
||||
obj.getAndroid().addItems(obj.getBlock(), items.toArray(new ItemStack[items.size()]));
|
||||
obj.getAndroid().addItems(obj.getBlock(), items.toArray(new ItemStack[0]));
|
||||
ExperienceOrb exp = (ExperienceOrb) e.getEntity().getWorld().spawnEntity(e.getEntity().getLocation(), EntityType.EXPERIENCE_ORB);
|
||||
exp.setExperience(1 + random.nextInt(6));
|
||||
}, 1L);
|
||||
|
@ -34,7 +34,7 @@ public class AutonomousToolsListener implements Listener {
|
||||
SlimefunItem machine = BlockStorage.check(dispenser);
|
||||
|
||||
if (machine != null) {
|
||||
for (ItemHandler handler: SlimefunItem.getHandlers("AutonomousMachineHandler")) {
|
||||
for (ItemHandler handler : SlimefunItem.getHandlers("AutonomousMachineHandler")) {
|
||||
if (((AutonomousMachineHandler) handler).onBlockDispense(e, dispenser, d, block, chest, machine)) break;
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ public class BackpackListener implements Listener {
|
||||
if (SlimefunPlugin.getUtilities().backpack.containsKey(e.getPlayer().getUniqueId())){
|
||||
ItemStack item = e.getItemDrop().getItemStack();
|
||||
SlimefunItem sfItem = SlimefunItem.getByItem(item);
|
||||
|
||||
if (sfItem instanceof SlimefunBackpack) e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class BlockListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPistonRetract(BlockPistonRetractEvent e) {
|
||||
if (e.isSticky()) {
|
||||
for (Block b: e.getBlocks()) {
|
||||
for (Block b : e.getBlocks()) {
|
||||
if (BlockStorage.hasBlockInfo(b) || b.getRelative(e.getDirection()).getType() == Material.AIR && BlockStorage.hasBlockInfo(b.getRelative(e.getDirection()))) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
@ -75,7 +75,7 @@ public class BlockListener implements Listener {
|
||||
Block b = e.getClickedBlock();
|
||||
LinkedList<MultiBlock> multiblocks = new LinkedList<>();
|
||||
|
||||
for (MultiBlock mb: MultiBlock.list()) {
|
||||
for (MultiBlock mb : MultiBlock.list()) {
|
||||
Block center = b.getRelative(mb.getTriggerBlock());
|
||||
|
||||
if (compareMaterials(center, mb.getBuild(), mb.isSymmetric())) {
|
||||
@ -87,7 +87,7 @@ public class BlockListener implements Listener {
|
||||
e.setCancelled(true);
|
||||
MultiBlock multiblock = multiblocks.getLast();
|
||||
|
||||
for (ItemHandler handler: SlimefunItem.getHandlers("MultiBlockInteractionHandler")) {
|
||||
for (ItemHandler handler : SlimefunItem.getHandlers("MultiBlockInteractionHandler")) {
|
||||
if (((MultiBlockInteractionHandler) handler).onInteract(p, multiblock, b)) break;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package me.mrCookieSlime.Slimefun.listeners;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Arrow;
|
||||
@ -19,6 +18,7 @@ import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BowShootHandler;
|
||||
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
|
||||
public class BowListener implements Listener {
|
||||
|
||||
@ -35,10 +35,14 @@ public class BowListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onArrowHit(final ProjectileHitEvent e) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> {
|
||||
if (!e.getEntity().isValid()) return;
|
||||
SlimefunPlugin.getUtilities().arrows.remove(e.getEntity().getUniqueId());
|
||||
if (e.getEntity() instanceof Arrow) handleGrapplingHook((Arrow) e.getEntity());
|
||||
Slimefun.runSync(() -> {
|
||||
if (e.getEntity().isValid()) {
|
||||
SlimefunPlugin.getUtilities().arrows.remove(e.getEntity().getUniqueId());
|
||||
|
||||
if (e.getEntity() instanceof Arrow) {
|
||||
handleGrapplingHook((Arrow) e.getEntity());
|
||||
}
|
||||
}
|
||||
}, 4L);
|
||||
}
|
||||
|
||||
@ -58,11 +62,11 @@ public class BowListener implements Listener {
|
||||
p.setVelocity(arrow.getLocation().toVector().subtract(p.getLocation().toVector()));
|
||||
}
|
||||
|
||||
for (Entity n: SlimefunPlugin.getUtilities().remove.get(p.getUniqueId())) {
|
||||
for (Entity n : SlimefunPlugin.getUtilities().remove.get(p.getUniqueId())) {
|
||||
if (n.isValid()) n.remove();
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> {
|
||||
Slimefun.runSync(() -> {
|
||||
SlimefunPlugin.getUtilities().jumpState.remove(p.getUniqueId());
|
||||
SlimefunPlugin.getUtilities().remove.remove(p.getUniqueId());
|
||||
}, 20L);
|
||||
@ -87,11 +91,11 @@ public class BowListener implements Listener {
|
||||
|
||||
p.setVelocity(v);
|
||||
|
||||
for (Entity n: SlimefunPlugin.getUtilities().remove.get(p.getUniqueId())) {
|
||||
for (Entity n : SlimefunPlugin.getUtilities().remove.get(p.getUniqueId())) {
|
||||
if (n.isValid()) n.remove();
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> {
|
||||
Slimefun.runSync(() -> {
|
||||
SlimefunPlugin.getUtilities().jumpState.remove(p.getUniqueId());
|
||||
SlimefunPlugin.getUtilities().remove.remove(p.getUniqueId());
|
||||
}, 20L);
|
||||
@ -103,8 +107,10 @@ public class BowListener implements Listener {
|
||||
public void onArrowSuccessfulHit(EntityDamageByEntityEvent e) {
|
||||
if (e.getDamager() instanceof Arrow) {
|
||||
if (SlimefunPlugin.getUtilities().arrows.containsKey(e.getDamager().getUniqueId()) && e.getEntity() instanceof LivingEntity) {
|
||||
for (ItemHandler handler: SlimefunItem.getHandlers("BowShootHandler")) {
|
||||
if (((BowShootHandler) handler).onHit(e, (LivingEntity) e.getEntity())) break;
|
||||
for (ItemHandler handler : SlimefunItem.getHandlers("BowShootHandler")) {
|
||||
if (((BowShootHandler) handler).onHit(e, (LivingEntity) e.getEntity())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SlimefunPlugin.getUtilities().arrows.remove(e.getDamager().getUniqueId());
|
||||
|
@ -27,7 +27,7 @@ public class CoolerListener implements Listener {
|
||||
public void onStarve(FoodLevelChangeEvent e) {
|
||||
if (e.getFoodLevel() < ((Player) e.getEntity()).getFoodLevel()) {
|
||||
Player p = (Player) e.getEntity();
|
||||
for (ItemStack item: p.getInventory().getContents()) {
|
||||
for (ItemStack item : p.getInventory().getContents()) {
|
||||
if (SlimefunManager.isItemSimilar(item, SlimefunItems.COOLER, false)) {
|
||||
BackpackInventory backpack = PlayerProfile.getBackpack(item);
|
||||
if (backpack != null) {
|
||||
@ -45,7 +45,7 @@ public class CoolerListener implements Listener {
|
||||
if (slot >= 0) {
|
||||
PotionMeta im = (PotionMeta) inv.getItem(slot).getItemMeta();
|
||||
|
||||
for (PotionEffect effect: im.getCustomEffects()) {
|
||||
for (PotionEffect effect : im.getCustomEffects()) {
|
||||
p.addPotionEffect(effect);
|
||||
}
|
||||
|
||||
|
@ -359,7 +359,7 @@ public class ItemListener implements Listener {
|
||||
// Remove the glass bottle once drunk
|
||||
final int m = mode;
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> {
|
||||
Slimefun.runSync(() -> {
|
||||
if (m == 0) p.getEquipment().getItemInMainHand().setAmount(0);
|
||||
else if (m == 1) p.getEquipment().getItemInOffHand().setAmount(0);
|
||||
else if (m == 2) p.getInventory().removeItem(new ItemStack(Material.GLASS_BOTTLE, 1));
|
||||
@ -449,7 +449,7 @@ public class ItemListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onItemDrop(PlayerDropItemEvent e) {
|
||||
for (ItemHandler handler: SlimefunItem.getHandlers("ItemDropHandler")) {
|
||||
for (ItemHandler handler : SlimefunItem.getHandlers("ItemDropHandler")) {
|
||||
if (((ItemDropHandler) handler).onItemDrop(e, e.getPlayer(), e.getItemDrop())) return;
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class TalismanListener implements Listener {
|
||||
|
||||
private Random random = new Random();
|
||||
private final Random random = new Random();
|
||||
|
||||
public TalismanListener(SlimefunPlugin plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
@ -81,7 +81,7 @@ public class TalismanListener implements Listener {
|
||||
|
||||
// Did the tool in our hand broke or was it an Armorpiece?
|
||||
if (!inv.getItem(inv.getHeldItemSlot()).equals(e.getBrokenItem())) {
|
||||
for (int s: armorSlots) {
|
||||
for (int s : armorSlots) {
|
||||
if (inv.getItem(s).equals(e.getBrokenItem())) {
|
||||
slot = s;
|
||||
break;
|
||||
@ -89,7 +89,7 @@ public class TalismanListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
final ItemStack item = e.getBrokenItem().clone();
|
||||
ItemStack item = e.getBrokenItem().clone();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
if (meta instanceof Damageable) {
|
||||
@ -98,14 +98,16 @@ public class TalismanListener implements Listener {
|
||||
|
||||
item.setItemMeta(meta);
|
||||
|
||||
final int itemSlot = slot;
|
||||
SlimefunPlugin.instance.getServer().getScheduler().runTaskLater(SlimefunPlugin.instance, () -> inv.setItem(itemSlot, item), 1L);
|
||||
int itemSlot = slot;
|
||||
Slimefun.runSync(() -> inv.setItem(itemSlot, item), 1L);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onSprint(PlayerToggleSprintEvent e) {
|
||||
if (e.isSprinting()) Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_TRAVELLER);
|
||||
if (e.isSprinting()) {
|
||||
Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_TRAVELLER);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -35,7 +35,7 @@ public class TeleporterListener implements Listener {
|
||||
SlimefunItem teleporter = BlockStorage.check(e.getClickedBlock().getRelative(BlockFace.DOWN));
|
||||
|
||||
if (teleporter instanceof Teleporter) {
|
||||
for (BlockFace face: faces) {
|
||||
for (BlockFace face : faces) {
|
||||
if (!BlockStorage.check(e.getClickedBlock().getRelative(BlockFace.DOWN).getRelative(face), "GPS_TELEPORTER_PYLON")) return;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
@ -47,7 +48,6 @@ public class ToolListener implements Listener {
|
||||
|
||||
// Materials that require a Block under it, e.g. Pressure Plates
|
||||
private final Set<Material> sensitiveMaterials = new HashSet<>();
|
||||
private final Random random = new Random();
|
||||
private final Utilities utilities;
|
||||
|
||||
public ToolListener(SlimefunPlugin plugin) {
|
||||
@ -164,7 +164,7 @@ public class ToolListener implements Listener {
|
||||
gifts.add(new CustomItem(SlimefunItems.CHRISTMAS_APPLE_PIE, 4));
|
||||
gifts.add(new ItemStack(Material.EMERALD));
|
||||
|
||||
e.getBlockPlaced().getWorld().dropItemNaturally(e.getBlockPlaced().getLocation(), gifts.get(random.nextInt(gifts.size())));
|
||||
e.getBlockPlaced().getWorld().dropItemNaturally(e.getBlockPlaced().getLocation(), gifts.get(ThreadLocalRandom.current().nextInt(gifts.size())));
|
||||
}
|
||||
else if (SlimefunManager.isItemSimilar(item, SlimefunItems.CARGO_INPUT, false)) {
|
||||
if (e.getBlock().getY() != e.getBlockAgainst().getY()) {
|
||||
@ -266,6 +266,8 @@ public class ToolListener implements Listener {
|
||||
}
|
||||
else if (item != null) {
|
||||
if (item.getEnchantments().containsKey(Enchantment.LOOT_BONUS_BLOCKS) && !item.getEnchantments().containsKey(Enchantment.SILK_TOUCH)) {
|
||||
Random random = ThreadLocalRandom.current();
|
||||
|
||||
fortune = random.nextInt(item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) + 2) - 1;
|
||||
if (fortune <= 0) fortune = 1;
|
||||
fortune = (e.getBlock().getType() == Material.LAPIS_ORE ? 4 + random.nextInt(5) : 1) * (fortune + 1);
|
||||
|
Loading…
Reference in New Issue
Block a user