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