mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-17 21:02:20 +01:00
Cleaned up some vulnerabilities and code smells.
This commit is contained in:
parent
3404fac8f2
commit
b402450253
@ -535,6 +535,9 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
* @return the world
|
||||
*/
|
||||
public World getWorld() {
|
||||
if (world == null) {
|
||||
plugin.logError(getLabel() + " did not setWorld in setup!");
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
||||
|
@ -82,11 +82,7 @@ public class PanelItem {
|
||||
|
||||
public void setGlow(boolean glow) {
|
||||
this.glow = glow;
|
||||
if (glow) {
|
||||
meta.addEnchant(Enchantment.ARROW_DAMAGE, 0, true);
|
||||
} else {
|
||||
meta.addEnchant(Enchantment.ARROW_DAMAGE, 0, false);
|
||||
}
|
||||
meta.addEnchant(Enchantment.ARROW_DAMAGE, 0, glow);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,7 @@
|
||||
package us.tastybento.bskyblock.commands.admin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -57,7 +58,6 @@ public class AdminSchemCommand extends CompositeCommand {
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
user.sendMessage("commands.admin.schem.could-not-load");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
@ -79,7 +79,12 @@ public class AdminSchemCommand extends CompositeCommand {
|
||||
if (args.size() == 2) {
|
||||
File file = new File(schemFolder, args.get(1));
|
||||
user.sendMessage("general.success");
|
||||
cb.save(file);
|
||||
try {
|
||||
cb.save(file);
|
||||
} catch (IOException e) {
|
||||
user.sendRawMessage("Could not save!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
showHelp(this, user);
|
||||
|
@ -53,6 +53,8 @@ public class Clipboard {
|
||||
UP
|
||||
}
|
||||
|
||||
private static final String ATTACHED = "attached";
|
||||
|
||||
private YamlConfiguration blockConfig = new YamlConfiguration();
|
||||
private Location pos1;
|
||||
private Location pos2;
|
||||
@ -127,8 +129,8 @@ public class Clipboard {
|
||||
int z = location.getBlockZ() + Integer.valueOf(pos[2]);
|
||||
Material m = Material.getMaterial(s.getString("type"));
|
||||
Block block = location.getWorld().getBlockAt(x, y, z);
|
||||
if (s.getBoolean("attached")) {
|
||||
plugin.getLogger().info("Setting 1 tick later for " + m.toString());
|
||||
if (s.getBoolean(ATTACHED)) {
|
||||
plugin.log("Setting 1 tick later for " + m.toString());
|
||||
plugin.getServer().getScheduler().runTask(plugin, () -> setBlock(block, s, m));
|
||||
} else {
|
||||
setBlock(block, s, m);
|
||||
@ -139,7 +141,7 @@ public class Clipboard {
|
||||
private void setBlock(Block block, ConfigurationSection s, Material m) {
|
||||
// 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"));
|
||||
|
||||
Block rel = block.getRelative(BlockFace.DOWN);
|
||||
@ -271,7 +273,7 @@ public class Clipboard {
|
||||
Attachable facing = (Attachable)md;
|
||||
s.set("facing", facing.getFacing().name());
|
||||
s.set("attached-face", facing.getAttachedFace().name());
|
||||
s.set("attached", true);
|
||||
s.set(ATTACHED, true);
|
||||
}
|
||||
if (md instanceof Colorable) {
|
||||
Bukkit.getLogger().info("Colorable");
|
||||
@ -366,20 +368,14 @@ public class Clipboard {
|
||||
/**
|
||||
* Save the clipboard to a file
|
||||
* @param file
|
||||
* @throws IOException
|
||||
*/
|
||||
public void save(File file) {
|
||||
try {
|
||||
public void save(File file) throws IOException {
|
||||
getBlockConfig().save(file);
|
||||
zip(file);
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void zip(File targetFile) {
|
||||
private void zip(File targetFile) throws IOException {
|
||||
|
||||
try (ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(targetFile.getAbsolutePath() + ".schem"))) {
|
||||
zipOutputStream.putNextEntry(new ZipEntry(targetFile.getName()));
|
||||
@ -392,11 +388,10 @@ public class Clipboard {
|
||||
}
|
||||
inputStream.close();
|
||||
zipOutputStream.close();
|
||||
targetFile.delete();
|
||||
if (!targetFile.delete()) {
|
||||
throw new IOException("Could not delete temp file");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,6 @@ import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.Chest;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.Constants;
|
||||
import us.tastybento.bskyblock.Constants.GameType;
|
||||
import us.tastybento.bskyblock.api.user.User;
|
||||
@ -49,7 +48,7 @@ public class IslandBuilder {
|
||||
|
||||
//TODO support companions?
|
||||
|
||||
public IslandBuilder(BSkyBlock plugin, Island island) {
|
||||
public IslandBuilder(Island island) {
|
||||
this.island = island;
|
||||
world = island.getWorld();
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ public class IslandWorldManager {
|
||||
* @return Set of world names
|
||||
*/
|
||||
public Set<String> getOverWorldNames() {
|
||||
return worlds.entrySet().stream().filter(e -> e.getKey().getEnvironment().equals(Environment.NORMAL)).map(w -> w.getValue()).collect(Collectors.toSet());
|
||||
return worlds.entrySet().stream().filter(e -> e.getKey().getEnvironment().equals(Environment.NORMAL)).map(Map.Entry::getValue).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -159,7 +159,7 @@ public class IslandWorldManager {
|
||||
public Set<String> getFreeOverWorldNames(User user) {
|
||||
return worlds.entrySet().stream().filter(e -> e.getKey().getEnvironment().equals(Environment.NORMAL))
|
||||
.filter(w -> !plugin.getIslands().hasIsland(w.getKey(), user))
|
||||
.map(w -> w.getValue()).collect(Collectors.toSet());
|
||||
.map(Map.Entry::getValue).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -198,7 +198,7 @@ public class IslandWorldManager {
|
||||
* @return world, or null if it does not exist
|
||||
*/
|
||||
public World getWorld(String friendlyName) {
|
||||
return worlds.entrySet().stream().filter(n -> n.getValue().equalsIgnoreCase(friendlyName)).map(e -> e.getKey()).findFirst().orElse(null);
|
||||
return worlds.entrySet().stream().filter(n -> n.getValue().equalsIgnoreCase(friendlyName)).map(Map.Entry::getKey).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -366,7 +366,7 @@ public class IslandWorldManager {
|
||||
* @return nether world, or null if it does not exist
|
||||
*/
|
||||
public World getNetherWorld(World overWorld) {
|
||||
return Bukkit.getWorld(overWorld.getName() + "_nether");
|
||||
return Bukkit.getWorld(overWorld.getName() + NETHER);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -375,7 +375,7 @@ public class IslandWorldManager {
|
||||
* @return end world, or null if it does not exist
|
||||
*/
|
||||
public World getEndWorld(World overWorld) {
|
||||
return Bukkit.getWorld(overWorld.getName() + "_the_end");
|
||||
return Bukkit.getWorld(overWorld.getName() + THE_END);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -416,7 +416,7 @@ public class IslandWorldManager {
|
||||
* @return world, or null if not known
|
||||
*/
|
||||
public World getIslandWorld(String friendlyWorldName) {
|
||||
return worlds.entrySet().stream().filter(e -> e.getValue().equalsIgnoreCase(friendlyWorldName)).findFirst().map(en -> en.getKey()).orElse(null);
|
||||
return worlds.entrySet().stream().filter(e -> e.getValue().equalsIgnoreCase(friendlyWorldName)).findFirst().map(Map.Entry::getKey).orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,7 +11,7 @@ import us.tastybento.bskyblock.database.objects.Island;
|
||||
*
|
||||
*/
|
||||
public class IslandGrid {
|
||||
private TreeMap<Integer, TreeMap<Integer, Island>> islandGrid = new TreeMap<>();
|
||||
private TreeMap<Integer, TreeMap<Integer, Island>> grid = new TreeMap<>();
|
||||
|
||||
/**
|
||||
* Adds island to grid
|
||||
@ -19,20 +19,20 @@ public class IslandGrid {
|
||||
* @return true if successfully added, false if island already exists, or there is an overlap
|
||||
*/
|
||||
public boolean addToGrid(Island island) {
|
||||
if (islandGrid.containsKey(island.getMinX())) {
|
||||
TreeMap<Integer, Island> zEntry = islandGrid.get(island.getMinX());
|
||||
if (grid.containsKey(island.getMinX())) {
|
||||
TreeMap<Integer, Island> zEntry = grid.get(island.getMinX());
|
||||
if (zEntry.containsKey(island.getMinZ())) {
|
||||
return false;
|
||||
} else {
|
||||
// Add island
|
||||
zEntry.put(island.getMinZ(), island);
|
||||
islandGrid.put(island.getMinX(), zEntry);
|
||||
grid.put(island.getMinX(), zEntry);
|
||||
}
|
||||
} else {
|
||||
// Add island
|
||||
TreeMap<Integer, Island> zEntry = new TreeMap<>();
|
||||
zEntry.put(island.getMinZ(), island);
|
||||
islandGrid.put(island.getMinX(), zEntry);
|
||||
grid.put(island.getMinX(), zEntry);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -47,12 +47,12 @@ public class IslandGrid {
|
||||
if (island != null) {
|
||||
int x = island.getMinX();
|
||||
int z = island.getMinZ();
|
||||
if (islandGrid.containsKey(x)) {
|
||||
TreeMap<Integer, Island> zEntry = islandGrid.get(x);
|
||||
if (grid.containsKey(x)) {
|
||||
TreeMap<Integer, Island> zEntry = grid.get(x);
|
||||
if (zEntry.containsKey(z)) {
|
||||
// Island exists - delete it
|
||||
zEntry.remove(z);
|
||||
islandGrid.put(x, zEntry);
|
||||
grid.put(x, zEntry);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -69,7 +69,7 @@ public class IslandGrid {
|
||||
* @return Island or null
|
||||
*/
|
||||
public Island getIslandAt(int x, int z) {
|
||||
Entry<Integer, TreeMap<Integer, Island>> en = islandGrid.floorEntry(x);
|
||||
Entry<Integer, TreeMap<Integer, Island>> en = grid.floorEntry(x);
|
||||
if (en != null) {
|
||||
Entry<Integer, Island> ent = en.getValue().floorEntry(z);
|
||||
if (ent != null) {
|
||||
|
@ -120,20 +120,20 @@ public class NewIsland {
|
||||
.build();
|
||||
if (!event.isCancelled()) {
|
||||
// Create island
|
||||
new IslandBuilder(plugin, island)
|
||||
new IslandBuilder(island)
|
||||
.setPlayer(user.getPlayer())
|
||||
.setChestItems(plugin.getSettings().getChestItems())
|
||||
.setType(IslandType.ISLAND)
|
||||
.build();
|
||||
if (plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands() && plugin.getIWM().getNetherWorld() != null) {
|
||||
new IslandBuilder(plugin,island)
|
||||
new IslandBuilder(island)
|
||||
.setPlayer(user.getPlayer())
|
||||
.setChestItems(plugin.getSettings().getChestItems())
|
||||
.setType(IslandType.NETHER)
|
||||
.build();
|
||||
}
|
||||
if (plugin.getSettings().isEndGenerate() && plugin.getSettings().isEndIslands() && plugin.getIWM().getEndWorld() != null) {
|
||||
new IslandBuilder(plugin,island)
|
||||
new IslandBuilder(island)
|
||||
.setPlayer(user.getPlayer())
|
||||
.setChestItems(plugin.getSettings().getChestItems())
|
||||
.setType(IslandType.END)
|
||||
|
@ -23,12 +23,14 @@ import us.tastybento.bskyblock.api.user.User;
|
||||
/**
|
||||
* A set of utility methods
|
||||
*
|
||||
* @author Tastybento
|
||||
* @author tastybento
|
||||
* @author Poslovitch
|
||||
*/
|
||||
public class Util {
|
||||
|
||||
private static final DecimalFormat df = new DecimalFormat("#.###");
|
||||
private static final String NETHER = "_nether";
|
||||
private static final String THE_END = "_the_end";
|
||||
private static String serverVersion = null;
|
||||
private static BSkyBlock plugin = BSkyBlock.getInstance();
|
||||
|
||||
@ -223,8 +225,8 @@ public class Util {
|
||||
* @return true if the same
|
||||
*/
|
||||
public static boolean sameWorld(World world, World world2) {
|
||||
String worldName = world.getName().replaceAll("_nether", "").replaceAll("_the_end", "");
|
||||
String world2Name = world2.getName().replaceAll("_nether", "").replaceAll("_the_end", "");
|
||||
String worldName = world.getName().replaceAll(NETHER, "").replaceAll(THE_END, "");
|
||||
String world2Name = world2.getName().replaceAll(NETHER, "").replaceAll(THE_END, "");
|
||||
return worldName.equalsIgnoreCase(world2Name);
|
||||
}
|
||||
|
||||
@ -234,7 +236,7 @@ public class Util {
|
||||
* @return over world
|
||||
*/
|
||||
public static World getWorld(World world) {
|
||||
return world.getEnvironment().equals(Environment.NORMAL) ? world : Bukkit.getWorld(world.getName().replaceAll("_nether", "").replaceAll("_the_end", ""));
|
||||
return world.getEnvironment().equals(Environment.NORMAL) ? world : Bukkit.getWorld(world.getName().replaceAll(NETHER, "").replaceAll(THE_END, ""));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user