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