mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-01 05:57:54 +01:00
Cleaned up some code smells.
This commit is contained in:
parent
e69971d73c
commit
b87b00d887
@ -139,8 +139,8 @@ public class Clipboard {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void setBlock(Block block, ConfigurationSection s, Material m) {
|
||||
// Block state
|
||||
|
||||
// Block state
|
||||
|
||||
if (s.getBoolean(ATTACHED) && m.toString().contains("TORCH")) {
|
||||
TorchDir d = TorchDir.valueOf(s.getString("facing"));
|
||||
|
||||
@ -163,7 +163,7 @@ public class Clipboard {
|
||||
}
|
||||
|
||||
block.setType(m);
|
||||
|
||||
|
||||
BlockState bs = block.getState();
|
||||
|
||||
byte data = (byte)s.getInt("data");
|
||||
@ -219,11 +219,11 @@ public class Clipboard {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bs.update(true, false);
|
||||
if (bs instanceof InventoryHolder) {
|
||||
Bukkit.getLogger().info("Inventory holder " + s.getCurrentPath());
|
||||
|
||||
|
||||
InventoryHolder ih = (InventoryHolder)bs;
|
||||
@SuppressWarnings("unchecked")
|
||||
List<ItemStack> items = (List<ItemStack>) s.get("inventory");
|
||||
@ -233,7 +233,7 @@ public class Clipboard {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void copyBlock(Block block, Location origin) {
|
||||
if (block.getType().equals(Material.AIR)) {
|
||||
@ -324,15 +324,15 @@ public class Clipboard {
|
||||
* @throws InvalidConfigurationException
|
||||
*/
|
||||
public void load(File file) throws IOException, InvalidConfigurationException {
|
||||
unzip(file.getAbsolutePath());
|
||||
blockConfig.load(file);
|
||||
copied = true;
|
||||
Files.delete(file.toPath());
|
||||
unzip(file.getAbsolutePath());
|
||||
blockConfig.load(file);
|
||||
copied = true;
|
||||
Files.delete(file.toPath());
|
||||
}
|
||||
|
||||
|
||||
private void unzip(final String zipFilePath) throws IOException {
|
||||
Path path = Paths.get(zipFilePath);
|
||||
if (!(Files.exists(path))) {
|
||||
if (!(path.toFile().exists())) {
|
||||
return;
|
||||
}
|
||||
try (ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(zipFilePath))) {
|
||||
@ -362,19 +362,18 @@ public class Clipboard {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save the clipboard to a file
|
||||
* @param file
|
||||
* @throws IOException
|
||||
*/
|
||||
public void save(File file) throws IOException {
|
||||
getBlockConfig().save(file);
|
||||
zip(file);
|
||||
getBlockConfig().save(file);
|
||||
zip(file);
|
||||
}
|
||||
|
||||
private void zip(File targetFile) throws IOException {
|
||||
|
||||
private void zip(File targetFile) throws IOException {
|
||||
try (ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(targetFile.getAbsolutePath() + ".schem"))) {
|
||||
zipOutputStream.putNextEntry(new ZipEntry(targetFile.getName()));
|
||||
try (FileInputStream inputStream = new FileInputStream(targetFile)) {
|
||||
@ -386,13 +385,15 @@ public class Clipboard {
|
||||
}
|
||||
inputStream.close();
|
||||
zipOutputStream.close();
|
||||
if (!targetFile.delete()) {
|
||||
throw new IOException("Could not delete temp file");
|
||||
try {
|
||||
Files.delete(targetFile.toPath());
|
||||
} catch (Exception e) {
|
||||
plugin.logError(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean isFull() {
|
||||
return copied;
|
||||
}
|
||||
|
@ -48,17 +48,11 @@ public class AddonsManager {
|
||||
public void loadAddons() {
|
||||
plugin.log("Loading addons...");
|
||||
File f = new File(plugin.getDataFolder(), "addons");
|
||||
if (!f.exists()) {
|
||||
f.mkdirs();
|
||||
if (!f.exists() && !f.mkdirs()) {
|
||||
plugin.logError("Cannot make addons folder!");
|
||||
return;
|
||||
}
|
||||
Arrays.stream(Objects.requireNonNull(f.listFiles())).filter(x -> !x.isDirectory() && x.getName().endsWith(".jar")).forEach(t -> {
|
||||
plugin.log("Loading " + t.getName());
|
||||
try {
|
||||
loadAddon(t);
|
||||
} catch (Exception e) {
|
||||
plugin.logError("Could not load addon " + t.getName() + " : " + e.getMessage());
|
||||
}
|
||||
});
|
||||
Arrays.stream(Objects.requireNonNull(f.listFiles())).filter(x -> !x.isDirectory() && x.getName().endsWith(".jar")).forEach(this::loadAddon);
|
||||
addons.forEach(Addon::onLoad);
|
||||
}
|
||||
|
||||
@ -150,7 +144,9 @@ public class AddonsManager {
|
||||
loader.forEach(l -> {
|
||||
try {
|
||||
l.close();
|
||||
} catch (IOException ignore) {}
|
||||
} catch (IOException ignore) {
|
||||
// Ignore
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -168,7 +164,6 @@ public class AddonsManager {
|
||||
|
||||
/**
|
||||
* Finds a class by name that has been loaded by this loader
|
||||
* Code copied from Bukkit JavaPluginLoader
|
||||
* @param name - name of the class
|
||||
* @return Class - the class
|
||||
*/
|
||||
@ -178,22 +173,12 @@ public class AddonsManager {
|
||||
|
||||
/**
|
||||
* Sets a class that this loader should know about
|
||||
* Code copied from Bukkit JavaPluginLoader
|
||||
*
|
||||
* @param name - name of the class
|
||||
* @param clazz - the class
|
||||
*/
|
||||
public void setClass(final String name, final Class<?> clazz) {
|
||||
classes.putIfAbsent(name, clazz);
|
||||
/*
|
||||
if (!classes.containsKey(name)) {
|
||||
classes.put(name, clazz);
|
||||
|
||||
if (ConfigurationSerializable.class.isAssignableFrom(clazz)) {
|
||||
Class<? extends ConfigurationSerializable> serializable = clazz.asSubclass(ConfigurationSerializable.class);
|
||||
ConfigurationSerialization.registerClass(serializable);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,9 +1,7 @@
|
||||
package us.tastybento.bskyblock.panels;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.panels.PanelItem;
|
||||
import us.tastybento.bskyblock.api.panels.builders.PanelBuilder;
|
||||
import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
|
||||
import us.tastybento.bskyblock.api.user.User;
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user