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

[CI skip] Some more refactoring

This commit is contained in:
TheBusyBiscuit 2019-12-12 02:52:24 +01:00
parent 7cb0c521f6
commit 7268fb0505
20 changed files with 194 additions and 175 deletions

View File

@ -51,18 +51,7 @@ public class ErrorReport {
List<String> plugins = new ArrayList<>();
List<String> addons = new ArrayList<>();
for (Plugin p: Bukkit.getPluginManager().getPlugins()) {
if (Bukkit.getPluginManager().isPluginEnabled(p)) {
plugins.add(" + " + p.getName() + ' ' + p.getDescription().getVersion());
if (p.getDescription().getDepend().contains("Slimefun") || p.getDescription().getSoftDepend().contains("Slimefun"))
addons.add(" + " + p.getName() + ' ' + p.getDescription().getVersion());
}
else {
plugins.add(" - " + p.getName() + ' ' + p.getDescription().getVersion());
if (p.getDescription().getDepend().contains("Slimefun") || p.getDescription().getSoftDepend().contains("Slimefun"))
addons.add(" - " + p.getName() + ' ' + p.getDescription().getVersion());
}
}
scanPlugins(plugins, addons);
stream.println("Installed Addons (" + addons.size() + ")");
addons.forEach(stream::println);
@ -151,18 +140,35 @@ public class ErrorReport {
});
}
private void scanPlugins(List<String> plugins, List<String> addons) {
String dependency = "Slimefun";
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
if (Bukkit.getPluginManager().isPluginEnabled(plugin)) {
plugins.add(" + " + plugin.getName() + ' ' + plugin.getDescription().getVersion());
if (plugin.getDescription().getDepend().contains(dependency) || plugin.getDescription().getSoftDepend().contains(dependency))
addons.add(" + " + plugin.getName() + ' ' + plugin.getDescription().getVersion());
}
else {
plugins.add(" - " + plugin.getName() + ' ' + plugin.getDescription().getVersion());
if (plugin.getDescription().getDepend().contains(dependency) || plugin.getDescription().getSoftDepend().contains(dependency))
addons.add(" - " + plugin.getName() + ' ' + plugin.getDescription().getVersion());
}
}
}
private File getNewFile() {
String path = "plugins/Slimefun/error-reports/" + new SimpleDateFormat("yyyy-MM-dd-HH-mm").format(new Date());
File file = new File(path + ".err");
File newFile = new File(path + ".err");
if (file.exists()) {
if (newFile.exists()) {
IntStream stream = IntStream.iterate(1, i -> i + 1).filter(i -> !new File(path + " (" + i + ").err").exists());
int id = stream.findFirst().getAsInt();
file = new File(path + " (" + id + ").err");
newFile = new File(path + " (" + id + ").err");
}
return file;
return newFile;
}
public File getFile() {

View File

@ -1,10 +1,12 @@
package me.mrCookieSlime.Slimefun.Events;
package io.github.thebusybiscuit.slimefun4.api.events;
import org.bukkit.block.Block;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import me.mrCookieSlime.Slimefun.androids.AndroidEntity;
/**
* This event is fired before a miner android mines a block.
* If this event is cancelled, the block will not be mined.
@ -14,14 +16,14 @@ public class AndroidMineEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final Block block;
private final Block android;
private final AndroidEntity android;
private boolean cancelled;
/**
* @param block - mined block
* @param android - the block of the android
*/
public AndroidMineEvent(Block block, Block android) {
public AndroidMineEvent(Block block, AndroidEntity android) {
this.block = block;
this.android = android;
}
@ -40,7 +42,7 @@ public class AndroidMineEvent extends Event implements Cancellable {
* @return the mined block
*/
public Block getBlock() {
return this.block;
return block;
}
/**
@ -49,18 +51,18 @@ public class AndroidMineEvent extends Event implements Cancellable {
*
* @return the block of the android
*/
public Block getAndroid() {
return this.android;
public AndroidEntity getAndroid() {
return android;
}
@Override
public boolean isCancelled() {
return this.cancelled;
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
cancelled = cancel;
}
}

View File

@ -1,4 +1,4 @@
package me.mrCookieSlime.Slimefun.Events;
package io.github.thebusybiscuit.slimefun4.api.events;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
@ -14,6 +14,7 @@ public class AutoDisenchantEvent extends Event implements Cancellable {
public AutoDisenchantEvent(ItemStack item) {
super(true);
this.item = item;
}

View File

@ -1,4 +1,4 @@
package me.mrCookieSlime.Slimefun.Events;
package io.github.thebusybiscuit.slimefun4.api.events;
import me.mrCookieSlime.Slimefun.Objects.MultiBlock;
@ -12,9 +12,9 @@ public class MultiBlockInteractEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private Player p;
private MultiBlock mb;
private Block b;
private Player player;
private MultiBlock multiBlock;
private Block clickedBlock;
private boolean cancelled;
public HandlerList getHandlers() {
@ -26,21 +26,21 @@ public class MultiBlockInteractEvent extends Event implements Cancellable {
}
public MultiBlockInteractEvent(Player p, MultiBlock mb, Block clicked) {
this.p = p;
this.mb = mb;
this.b = clicked;
this.player = p;
this.multiBlock = mb;
this.clickedBlock = clicked;
}
public Player getPlayer() {
return this.p;
return this.player;
}
public MultiBlock getMultiBlock() {
return this.mb;
return this.multiBlock;
}
public Block getClickedBlock() {
return this.b;
return this.clickedBlock;
}
@Override

View File

@ -1,4 +1,4 @@
package me.mrCookieSlime.Slimefun.Events;
package io.github.thebusybiscuit.slimefun4.api.events;
import me.mrCookieSlime.Slimefun.Objects.Research;
@ -11,8 +11,8 @@ public class ResearchUnlockEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private Player p;
private Research r;
private Player player;
private Research research;
private boolean cancelled;
public HandlerList getHandlers() {
@ -23,17 +23,17 @@ public class ResearchUnlockEvent extends Event implements Cancellable {
return handlers;
}
public ResearchUnlockEvent(Player p, Research res) {
this.p = p;
this.r = res;
public ResearchUnlockEvent(Player p, Research research) {
this.player = p;
this.research = research;
}
public Player getPlayer() {
return this.p;
return this.player;
}
public Research getResearch() {
return this.r;
return this.research;
}
@Override

View File

@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.core.utils;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
@ -15,4 +16,8 @@ public final class ChatUtils {
p.sendMessage("");
}
public static String christmas(String text) {
return ChatColors.alternating(text, ChatColor.GREEN, ChatColor.RED);
}
}

View File

@ -2,11 +2,11 @@ package me.mrCookieSlime.Slimefun.Lists;
import org.bukkit.Material;
import io.github.thebusybiscuit.slimefun4.core.utils.ChatUtils;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.LockedCategory;
import me.mrCookieSlime.Slimefun.Objects.SeasonalCategory;
import me.mrCookieSlime.Slimefun.utils.Christmas;
/**
* Built-in categories.
@ -21,7 +21,7 @@ public final class Categories {
private static final String LORE = "&a> Click to open";
public static final Category WEAPONS = new Category(new CustomItem(SlimefunItems.SWORD_OF_BEHEADING, "&7Weapons", "", LORE), 1);
public static final Category WEAPONS = new Category(new CustomItem(SlimefunItems.BLADE_OF_VAMPIRES, "&7Weapons", "", LORE), 1);
public static final Category TOOLS = new Category(new CustomItem(SlimefunItems.AUTO_SMELT_PICKAXE, "&7Tools", "", LORE), 1);
public static final Category PORTABLE = new Category(new CustomItem(SlimefunItems.BACKPACK_MEDIUM, "&7Items", "", LORE), 1);
public static final Category FOOD = new Category(new CustomItem(SlimefunItems.FORTUNE_COOKIE, "&7Food", "", LORE), 2);
@ -41,9 +41,9 @@ public final class Categories {
public static final LockedCategory TALISMANS_2 = new LockedCategory(new CustomItem(SlimefunItems.ENDER_TALISMAN, "&7Talismans - &aTier II", "", LORE), 3, TALISMANS_1);
// Seasonal Categories
public static final SeasonalCategory CHRISTMAS = new SeasonalCategory(12, 1, new CustomItem(Material.NETHER_STAR, Christmas.color("Christmas"), "", "&c> Click to help &aSanta"));
public static final SeasonalCategory VALENTINES_DAY = new SeasonalCategory(2, 2, new CustomItem(Material.POPPY, "&dValentine's Day", "", "&d> Click to celebrate Love"));
public static final SeasonalCategory EASTER = new SeasonalCategory(4, 2, new CustomItem(Material.EGG, "&6Easter", "", "&a> Click to paint some Eggs"));
public static final SeasonalCategory CHRISTMAS = new SeasonalCategory(12, 1, new CustomItem(Material.NETHER_STAR, ChatUtils.christmas("Christmas") + " &7(December)", "", "&c> Click to help &aSanta"));
public static final SeasonalCategory VALENTINES_DAY = new SeasonalCategory(2, 2, new CustomItem(Material.POPPY, "&dValentine's Day" + " &7(February)", "", "&d> Click to celebrate Love"));
public static final SeasonalCategory EASTER = new SeasonalCategory(4, 2, new CustomItem(Material.EGG, "&6Easter" + " &7(April)", "", "&a> Click to paint some Eggs"));
public static final SeasonalCategory BIRTHDAY = new SeasonalCategory(10, 1, new CustomItem(Material.FIREWORK_ROCKET, "&a&lTheBusyBiscuit's Birthday &7(26th October)", "", "&a> Click to celebrate with me"));
}

View File

@ -13,9 +13,9 @@ import org.bukkit.Sound;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import io.github.thebusybiscuit.slimefun4.api.events.ResearchUnlockEvent;
import me.mrCookieSlime.CSCoreLibPlugin.general.Particles.FireworkShow;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Events.ResearchUnlockEvent;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Setup.ResearchSetup;
import me.mrCookieSlime.Slimefun.api.PlayerProfile;

View File

@ -4,18 +4,18 @@ import org.bukkit.inventory.ItemStack;
public class MachineFuel {
private int seconds;
private int ticks;
private ItemStack fuel;
private ItemStack output;
public MachineFuel(int seconds, ItemStack fuel) {
this.seconds = seconds * 2;
this.ticks = seconds * 2;
this.fuel = fuel;
this.output = null;
}
public MachineFuel(int seconds, ItemStack fuel, ItemStack output) {
this.seconds = seconds * 2;
this.ticks = seconds * 2;
this.fuel = fuel;
this.output = output;
}
@ -29,7 +29,7 @@ public class MachineFuel {
}
public int getTicks() {
return seconds;
return ticks;
}
}

View File

@ -5,7 +5,6 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import me.mrCookieSlime.Slimefun.Events.AutoDisenchantEvent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -32,6 +31,8 @@ import me.mrCookieSlime.Slimefun.utils.MachineHelper;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.Repairable;
import io.github.thebusybiscuit.slimefun4.api.events.AutoDisenchantEvent;
public class AutoDisenchanter extends AContainer {
public AutoDisenchanter(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
@ -82,7 +83,7 @@ public class AutoDisenchanter extends AContainer {
Map<Enchantment, Integer> enchantments = new HashMap<>();
Set<ItemEnchantment> enchantments2 = new HashSet<>();
for (int slot: getInputSlots()) {
for (int slot : getInputSlots()) {
ItemStack target = menu.getItemInSlot(slot == getInputSlots()[0] ? getInputSlots()[1]: getInputSlots()[0]);
ItemStack item = menu.getItemInSlot(slot);
@ -156,7 +157,7 @@ public class AutoDisenchanter extends AContainer {
if (recipe != null) {
if (!fits(b, recipe.getOutput())) return;
for (int slot: getInputSlots()) {
for (int slot : getInputSlots()) {
menu.replaceExistingItem(slot, InvUtils.decreaseItem(menu.getItemInSlot(slot), 1));
}

View File

@ -45,19 +45,20 @@ public abstract class BioGenerator extends AGenerator {
registerFuel(new MachineFuel(20, new ItemStack(Material.DRIED_KELP_BLOCK)));
registerFuel(new MachineFuel(1, new ItemStack(Material.SEAGRASS)));
registerFuel(new MachineFuel(2, new ItemStack(Material.SEA_PICKLE)));
registerFuel(new MachineFuel(2, new ItemStack(Material.SWEET_BERRIES)));
// Leaves
for(Material m: Tag.LEAVES.getValues()) {
for(Material m : Tag.LEAVES.getValues()) {
registerFuel(new MachineFuel(1, new ItemStack(m)));
}
// Saplings
for (Material m: Tag.SAPLINGS.getValues()) {
for (Material m : Tag.SAPLINGS.getValues()) {
registerFuel(new MachineFuel(1, new ItemStack(m)));
}
// Small Flowers (formally just dandelions and poppies.
for (Material m: Tag.SMALL_FLOWERS.getValues()) {
for (Material m : Tag.SMALL_FLOWERS.getValues()) {
registerFuel(new MachineFuel(1, new ItemStack(m)));
}
}

View File

@ -22,17 +22,17 @@ public abstract class CoalGenerator extends AGenerator {
registerFuel(new MachineFuel(12, new ItemStack(Material.BLAZE_ROD)));
// Coals
for (Material mat: Tag.ITEMS_COALS.getValues()) {
for (Material mat : Tag.ITEMS_COALS.getValues()) {
registerFuel(new MachineFuel(8, new ItemStack(mat)));
}
// Logs
for (Material mat: Tag.LOGS.getValues()) {
for (Material mat : Tag.LOGS.getValues()) {
registerFuel(new MachineFuel(2, new ItemStack(mat)));
}
// Wooden Planks
for (Material mat: Tag.PLANKS.getValues()) {
for (Material mat : Tag.PLANKS.getValues()) {
registerFuel(new MachineFuel(1, new ItemStack(mat)));
}
}

View File

@ -18,6 +18,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
@Deprecated
public class CSCoreLibLoader {
private Plugin plugin;

View File

@ -27,7 +27,7 @@ public final class WikiSetup {
JsonElement element = parser.parse(reader.lines().collect(Collectors.joining("")));
JsonObject json = element.getAsJsonObject();
for (Map.Entry<String, JsonElement> entry: json.entrySet()) {
for (Map.Entry<String, JsonElement> entry : json.entrySet()) {
SlimefunItem item = SlimefunItem.getByID(entry.getKey());
if (item != null) {

View File

@ -2,12 +2,12 @@ package me.mrCookieSlime.Slimefun.androids;
import org.bukkit.block.Block;
public class AndroidObject {
public class AndroidEntity {
private ProgrammableAndroid android;
private Block b;
private final ProgrammableAndroid android;
private final Block b;
public AndroidObject(ProgrammableAndroid android, Block b) {
public AndroidEntity(ProgrammableAndroid android, Block b) {
this.android = android;
this.b = b;
}

View File

@ -11,6 +11,7 @@ import java.util.Optional;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Predicate;
import java.util.logging.Level;
@ -39,11 +40,13 @@ import org.bukkit.metadata.FixedMetadataValue;
import io.github.thebusybiscuit.cscorelib2.blocks.Vein;
import io.github.thebusybiscuit.cscorelib2.chat.ChatInput;
import io.github.thebusybiscuit.cscorelib2.collections.RandomizedSet;
import io.github.thebusybiscuit.cscorelib2.config.Config;
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
import io.github.thebusybiscuit.cscorelib2.materials.MaterialConverter;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import io.github.thebusybiscuit.cscorelib2.skull.SkullItem;
import io.github.thebusybiscuit.slimefun4.api.events.AndroidMineEvent;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu.AdvancedMenuClickHandler;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ClickAction;
@ -52,7 +55,6 @@ import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull;
import me.mrCookieSlime.ExoticGarden.ExoticGarden;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Events.AndroidMineEvent;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.Category;
@ -75,26 +77,24 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
private static final int[] border = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 18, 24, 25, 26, 27, 33, 35, 36, 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53};
private static final int[] border_out = {10, 11, 12, 13, 14, 19, 23, 28, 32, 37, 38, 39, 40, 41};
private static final ItemStack[] fish = new ItemStack[] {new ItemStack(Material.COD), new ItemStack(Material.SALMON), new ItemStack(Material.PUFFERFISH), new ItemStack(Material.TROPICAL_FISH), new ItemStack(Material.STRING), new ItemStack(Material.BONE), new ItemStack(Material.STICK)};
private static final List<BlockFace> directions = Arrays.asList(BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST);
private static final List<Material> blockblacklist = new ArrayList<>();
private static final RandomizedSet<ItemStack> fishingLoot = new RandomizedSet<>();
static {
blockblacklist.add(Material.BEDROCK);
blockblacklist.add(Material.BARRIER);
blockblacklist.add(Material.END_PORTAL_FRAME);
blockblacklist.add(Material.END_PORTAL);
blockblacklist.add(Material.NETHER_PORTAL);
blockblacklist.add(Material.COMMAND_BLOCK);
blockblacklist.add(Material.CHAIN_COMMAND_BLOCK);
blockblacklist.add(Material.REPEATING_COMMAND_BLOCK);
blockblacklist.add(Material.STRUCTURE_BLOCK);
for (Material fish : MaterialCollections.getAllFishItems()) {
fishingLoot.add(new ItemStack(fish), 20);
}
fishingLoot.add(new ItemStack(Material.BONE), 10);
fishingLoot.add(new ItemStack(Material.STRING), 10);
fishingLoot.add(new ItemStack(Material.STICK), 5);
fishingLoot.add(new ItemStack(Material.INK_SAC), 4);
fishingLoot.add(new ItemStack(Material.ROTTEN_FLESH), 3);
fishingLoot.add(new ItemStack(Material.LEATHER), 2);
}
private static final List<BlockFace> directions = Arrays.asList(BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST);
private final Set<MachineFuel> recipes = new HashSet<>();
private final Random random = new Random();
@Override
public int[] getInputSlots() {
@ -118,17 +118,17 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
registerFuel(new MachineFuel(45, new ItemStack(Material.BLAZE_ROD)));
// Coals
for (Material mat: Tag.ITEMS_COALS.getValues()) {
for (Material mat : Tag.ITEMS_COALS.getValues()) {
registerFuel(new MachineFuel(8, new ItemStack(mat)));
}
// Logs
for (Material mat: Tag.LOGS.getValues()) {
for (Material mat : Tag.LOGS.getValues()) {
registerFuel(new MachineFuel(2, new ItemStack(mat)));
}
// Wooden Planks
for (Material mat: Tag.PLANKS.getValues()) {
for (Material mat : Tag.PLANKS.getValues()) {
registerFuel(new MachineFuel(1, new ItemStack(mat)));
}
}
@ -147,11 +147,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
@Override
public void init() {
try {
constructMenu(this);
} catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, "An Error occured while constructing an Android Inventory for Slimefun " + Slimefun.getVersion(), x);
}
constructMenu(this);
}
@Override
@ -165,32 +161,28 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
@Override
public void newInstance(BlockMenu menu, final Block b) {
try {
menu.replaceExistingItem(15, new CustomItem(SkullItem.fromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZTAxYzdiNTcyNjE3ODk3NGIzYjNhMDFiNDJhNTkwZTU0MzY2MDI2ZmQ0MzgwOGYyYTc4NzY0ODg0M2E3ZjVhIn19fQ=="), "&aStart/Continue"));
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
SlimefunPlugin.getLocal().sendMessage(p, "robot.started", true);
BlockStorage.addBlockInfo(b, "paused", "false");
p.closeInventory();
return false;
});
menu.replaceExistingItem(15, new CustomItem(SkullItem.fromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZTAxYzdiNTcyNjE3ODk3NGIzYjNhMDFiNDJhNTkwZTU0MzY2MDI2ZmQ0MzgwOGYyYTc4NzY0ODg0M2E3ZjVhIn19fQ=="), "&aStart/Continue"));
menu.addMenuClickHandler(15, (p, slot, item, action) -> {
SlimefunPlugin.getLocal().sendMessage(p, "robot.started", true);
BlockStorage.addBlockInfo(b, "paused", "false");
p.closeInventory();
return false;
});
menu.replaceExistingItem(17, new CustomItem(SkullItem.fromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTYxMzlmZDFjNTY1NGU1NmU5ZTRlMmM4YmU3ZWIyYmQ1YjQ5OWQ2MzM2MTY2NjNmZWVlOTliNzQzNTJhZDY0In19fQ=="), "&4Pause"));
menu.addMenuClickHandler(17, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "paused", "true");
SlimefunPlugin.getLocal().sendMessage(p, "robot.stopped", true);
return false;
});
menu.replaceExistingItem(17, new CustomItem(SkullItem.fromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTYxMzlmZDFjNTY1NGU1NmU5ZTRlMmM4YmU3ZWIyYmQ1YjQ5OWQ2MzM2MTY2NjNmZWVlOTliNzQzNTJhZDY0In19fQ=="), "&4Pause"));
menu.addMenuClickHandler(17, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "paused", "true");
SlimefunPlugin.getLocal().sendMessage(p, "robot.stopped", true);
return false;
});
menu.replaceExistingItem(16, new CustomItem(SkullItem.fromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDc4ZjJiN2U1ZTc1NjM5ZWE3ZmI3OTZjMzVkMzY0YzRkZjI4YjQyNDNlNjZiNzYyNzdhYWRjZDYyNjEzMzcifX19"), "&bMemory Core", "", "&8\u21E8 &7Click to open the Script Editor"));
menu.addMenuClickHandler(16, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "paused", "true");
SlimefunPlugin.getLocal().sendMessage(p, "robot.stopped", true);
openScriptEditor(p, b);
return false;
});
} catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, "An Error occured while creating a new Instance of an Android Inventory for Slimefun " + Slimefun.getVersion(), x);
}
menu.replaceExistingItem(16, new CustomItem(SkullItem.fromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDc4ZjJiN2U1ZTc1NjM5ZWE3ZmI3OTZjMzVkMzY0YzRkZjI4YjQyNDNlNjZiNzYyNzdhYWRjZDYyNjEzMzcifX19"), "&bMemory Core", "", "&8\u21E8 &7Click to open the Script Editor"));
menu.addMenuClickHandler(16, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "paused", "true");
SlimefunPlugin.getLocal().sendMessage(p, "robot.stopped", true);
openScriptEditor(p, b);
return false;
});
}
@Override
@ -210,6 +202,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
BlockStorage.addBlockInfo(b, "rotation", p.getFacing().getOppositeFace().toString());
BlockStorage.addBlockInfo(b, "paused", "true");
b.setType(Material.PLAYER_HEAD);
Rotatable blockData = (Rotatable) b.getBlockData();
blockData.setRotation(p.getFacing());
b.setBlockData(blockData);
@ -221,12 +214,14 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
if (allow) {
BlockMenu inv = BlockStorage.getInventory(b);
if (inv != null) {
if (inv.getItemInSlot(43) != null) {
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(43));
inv.replaceExistingItem(43, null);
}
for (int slot: getOutputSlots()) {
for (int slot : getOutputSlots()) {
if (inv.getItemInSlot(slot) != null) {
b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot));
inv.replaceExistingItem(slot, null);
@ -323,8 +318,8 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
Block water = b.getRelative(BlockFace.DOWN);
if (water.getType() == Material.WATER) {
water.getWorld().playSound(water.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1F, 1F);
if (random.nextInt(100) < 10 * getTier()) {
ItemStack drop = fish[random.nextInt(fish.length)];
if (ThreadLocalRandom.current().nextInt(100) < 10 * getTier()) {
ItemStack drop = fishingLoot.getRandom();
if (menu.fits(drop, getOutputSlots())) {
menu.pushItem(drop, getOutputSlots());
}
@ -344,7 +339,8 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
case INTERFACE_ITEMS:
if (BlockStorage.check(b.getRelative(face), "ANDROID_INTERFACE_ITEMS") && b.getRelative(face).getState() instanceof Dispenser) {
Dispenser d = (Dispenser) b.getRelative(face).getState();
for (int slot: getOutputSlots()) {
for (int slot : getOutputSlots()) {
ItemStack stack = menu.getItemInSlot(slot);
if (stack != null) {
@ -387,16 +383,16 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
}
break;
case FARM_FORWARD:
farm(b, menu, b.getRelative(face));
farm(menu, b.getRelative(face));
break;
case FARM_DOWN:
farm(b, menu, b.getRelative(BlockFace.DOWN));
farm(menu, b.getRelative(BlockFace.DOWN));
break;
case FARM_EXOTIC_FORWARD:
exoticFarm(b, menu, b.getRelative(face));
exoticFarm(menu, b.getRelative(face));
break;
case FARM_EXOTIC_DOWN:
exoticFarm(b, menu, b.getRelative(BlockFace.DOWN));
exoticFarm(menu, b.getRelative(BlockFace.DOWN));
break;
case CHOP_TREE:
if (MaterialCollections.getAllLogs().contains(b.getRelative(face).getType())) {
@ -449,7 +445,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
private void killEntities(Block b, double damage, Predicate<Entity> predicate) {
double radius = 4.0 + getTier();
for (Entity n: b.getWorld().getNearbyEntities(b.getLocation(), radius, radius, radius, n -> n instanceof LivingEntity && !(n instanceof ArmorStand) && !(n instanceof Player) && n.isValid() && predicate.test(n))) {
for (Entity n : b.getWorld().getNearbyEntities(b.getLocation(), radius, radius, radius, n -> n instanceof LivingEntity && !(n instanceof ArmorStand) && !(n instanceof Player) && n.isValid() && predicate.test(n))) {
boolean attack = false;
switch (BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"))) {
@ -470,8 +466,11 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
}
if (attack) {
if (n.hasMetadata("android_killer")) n.removeMetadata("android_killer", SlimefunPlugin.instance);
n.setMetadata("android_killer", new FixedMetadataValue(SlimefunPlugin.instance, new AndroidObject(this, b)));
if (n.hasMetadata("android_killer")) {
n.removeMetadata("android_killer", SlimefunPlugin.instance);
}
n.setMetadata("android_killer", new FixedMetadataValue(SlimefunPlugin.instance, new AndroidEntity(this, b)));
((LivingEntity) n).damage(damage);
break;
@ -499,15 +498,17 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
private void mine(Block b, BlockMenu menu, Block block) {
Collection<ItemStack> drops = block.getDrops();
if (!blockblacklist.contains(block.getType()) && !drops.isEmpty() && SlimefunPlugin.getProtectionManager().hasPermission(Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner"))), block.getLocation(), ProtectableAction.BREAK_BLOCK)) {
if (!MaterialCollections.getAllUnbreakableBlocks().contains(block.getType()) && !drops.isEmpty() && SlimefunPlugin.getProtectionManager().hasPermission(Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner"))), block.getLocation(), ProtectableAction.BREAK_BLOCK)) {
String item = BlockStorage.checkID(block);
AndroidMineEvent event = new AndroidMineEvent(block, b);
AndroidMineEvent event = new AndroidMineEvent(block, new AndroidEntity(this, b));
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
if (item == null) {
for (ItemStack drop: drops) {
for (ItemStack drop : drops) {
if (menu.fits(drop, getOutputSlots())) {
menu.pushItem(drop, getOutputSlots());
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
@ -532,15 +533,17 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
private void movedig(Block b, BlockMenu menu, BlockFace face, Block block) {
Collection<ItemStack> drops = block.getDrops();
if (!blockblacklist.contains(block.getType()) && !drops.isEmpty() && SlimefunPlugin.getProtectionManager().hasPermission(Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner"))), block.getLocation(), ProtectableAction.BREAK_BLOCK)) {
if (!MaterialCollections.getAllUnbreakableBlocks().contains(block.getType()) && !drops.isEmpty() && SlimefunPlugin.getProtectionManager().hasPermission(Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner"))), block.getLocation(), ProtectableAction.BREAK_BLOCK)) {
SlimefunItem item = BlockStorage.check(block);
AndroidMineEvent event = new AndroidMineEvent(block, b);
AndroidMineEvent event = new AndroidMineEvent(block, new AndroidEntity(this, b));
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
if (item == null) {
for (ItemStack drop: drops) {
for (ItemStack drop : drops) {
if (menu.fits(drop, getOutputSlots())) {
menu.pushItem(drop, getOutputSlots());
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
@ -578,34 +581,9 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
return ageable.getAge() >= ageable.getMaximumAge();
}
private void farm(Block b, BlockMenu menu, Block block) {
private void farm(BlockMenu menu, Block block) {
if (isFullGrown(block)) {
ItemStack drop = null;
switch (block.getType()) {
case WHEAT:
drop = new ItemStack(Material.WHEAT, random.nextInt(2) + 1);
break;
case POTATOES:
drop = new ItemStack(Material.POTATO, random.nextInt(3) + 1);
break;
case CARROTS:
drop = new ItemStack(Material.CARROT, random.nextInt(3) + 1);
break;
case BEETROOTS:
drop = new ItemStack(Material.BEETROOT, random.nextInt(3) + 1);
break;
case COCOA:
drop = new ItemStack(Material.COCOA_BEANS, random.nextInt(3) + 1);
break;
case NETHER_WART:
drop = new ItemStack(Material.NETHER_WART, random.nextInt(3) + 1);
break;
case SWEET_BERRY_BUSH:
drop = new ItemStack(Material.SWEET_BERRIES, random.nextInt(3) + 1);
break;
default:
break;
}
ItemStack drop = getDropFromCrop(block.getType());
if (drop != null && menu.fits(drop, getOutputSlots())) {
menu.pushItem(drop, getOutputSlots());
@ -617,8 +595,32 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
}
}
private void exoticFarm(Block b, BlockMenu menu, Block block) {
farm(b, menu, block);
private ItemStack getDropFromCrop(Material crop) {
Random random = ThreadLocalRandom.current();
switch (crop) {
case WHEAT:
return new ItemStack(Material.WHEAT, random.nextInt(2) + 1);
case POTATOES:
return new ItemStack(Material.POTATO, random.nextInt(3) + 1);
case CARROTS:
return new ItemStack(Material.CARROT, random.nextInt(3) + 1);
case BEETROOTS:
return new ItemStack(Material.BEETROOT, random.nextInt(3) + 1);
case COCOA:
return new ItemStack(Material.COCOA_BEANS, random.nextInt(3) + 1);
case NETHER_WART:
return new ItemStack(Material.NETHER_WART, random.nextInt(3) + 1);
case SWEET_BERRY_BUSH:
return new ItemStack(Material.SWEET_BERRIES, random.nextInt(3) + 1);
default:
return null;
}
}
private void exoticFarm(BlockMenu menu, Block block) {
farm(menu, block);
if (SlimefunPlugin.getHooks().isExoticGardenInstalled()) {
ItemStack drop = ExoticGarden.harvestPlant(block);
if (drop != null && menu.fits(drop, getOutputSlots())) {
@ -628,7 +630,7 @@ public abstract class ProgrammableAndroid extends SlimefunItem implements Invent
}
}
private void constructMenu(BlockMenuPreset preset) throws Exception {
private void constructMenu(BlockMenuPreset preset) {
for (int i : border) {
preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
}

View File

@ -1,12 +1,9 @@
package me.mrCookieSlime.Slimefun.androids;
import java.util.logging.Level;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.skull.SkullItem;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
import me.mrCookieSlime.Slimefun.api.Slimefun;
public enum ScriptPart {
@ -62,12 +59,8 @@ public enum ScriptPart {
private AndroidType type;
private ScriptPart(AndroidType type, String name, String texture) {
try {
this.type = type;
this.item = new CustomItem(SkullItem.fromBase64(texture), name);
} catch(Exception x) {
Slimefun.getLogger().log(Level.SEVERE, "An Error occured while initializing Android-Script Texture for Slimefun " + Slimefun.getVersion(), x);
}
this.type = type;
this.item = new CustomItem(SkullItem.fromBase64(texture), name);
}
public ItemStack toItemStack() {

View File

@ -17,7 +17,7 @@ import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.androids.AndroidObject;
import me.mrCookieSlime.Slimefun.androids.AndroidEntity;
public class AndroidKillingListener implements Listener {
@ -30,7 +30,7 @@ public class AndroidKillingListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onDeath(final EntityDeathEvent e) {
if (e.getEntity().hasMetadata("android_killer")) {
final AndroidObject obj = (AndroidObject) e.getEntity().getMetadata("android_killer").get(0).value();
final AndroidEntity obj = (AndroidEntity) e.getEntity().getMetadata("android_killer").get(0).value();
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunPlugin.instance, () -> {
List<ItemStack> items = new ArrayList<>();

View File

@ -18,8 +18,8 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.events.MultiBlockInteractEvent;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Events.MultiBlockInteractEvent;
import me.mrCookieSlime.Slimefun.Objects.MultiBlock;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler;

View File

@ -3,7 +3,14 @@ package me.mrCookieSlime.Slimefun.utils;
import org.bukkit.ChatColor;
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
import io.github.thebusybiscuit.slimefun4.core.utils.ChatUtils;
/**
*
* @deprecated This class will be deleted after X-Mas 2019. It will be replaced by {@link ChatUtils#christmas(String)}
*
*/
@Deprecated
public final class Christmas {
private Christmas() {}