mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-30 13:07:46 +01:00
Fixed code smells and bugs, added flower pot protection
This commit is contained in:
parent
60a0c486f3
commit
31455a033d
@ -211,6 +211,6 @@ public interface WorldSettings {
|
||||
/**
|
||||
* @return the visitorBannedCommands
|
||||
*/
|
||||
public List<String> getVisitorBannedCommands();
|
||||
List<String> getVisitorBannedCommands();
|
||||
|
||||
}
|
||||
|
@ -44,7 +44,6 @@ public class BSBDatabase<T> {
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
|
||||
| InvocationTargetException | ClassNotFoundException | IntrospectionException e) {
|
||||
logger.severe(() -> "Could not load objects from database! Error: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -61,7 +60,6 @@ public class BSBDatabase<T> {
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
||||
| ClassNotFoundException | IntrospectionException e) {
|
||||
logger.severe(() -> "Could not load object from database! " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package us.tastybento.bskyblock.database.objects;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@ -103,7 +104,7 @@ public class Island implements DataObject {
|
||||
@Expose
|
||||
private int levelHandicap;
|
||||
@Expose
|
||||
private Map<Environment, Location> spawnPoint = new HashMap<>();
|
||||
private Map<Environment, Location> spawnPoint = new EnumMap<>(Environment.class);
|
||||
|
||||
public Island() {}
|
||||
public Island(Location location, UUID owner, int protectionRange) {
|
||||
|
@ -45,7 +45,7 @@ public class FlagSerializer2 implements AdapterInterface<Map<Flag, Integer>, Map
|
||||
}
|
||||
Map<Flag, Integer> flags = (Map<Flag, Integer>)object;
|
||||
for (Entry<Flag, Integer> en: flags.entrySet()) {
|
||||
result.put(en.getKey().getID(), en.getValue() < 0 ? false : true);
|
||||
result.put(en.getKey().getID(), en.getValue() >= 0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Nameable;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Banner;
|
||||
import org.bukkit.block.Block;
|
||||
@ -83,6 +82,14 @@ public class Clipboard {
|
||||
|
||||
private static final String LOAD_ERROR = "Could not load schems file - does not exist : ";
|
||||
|
||||
private static final String BEDROCK = "bedrock";
|
||||
|
||||
private static final String INVENTORY = "inventory";
|
||||
|
||||
private static final String ENTITY = "entity";
|
||||
|
||||
private static final String COLOR = "color";
|
||||
|
||||
private YamlConfiguration blockConfig = new YamlConfiguration();
|
||||
private Location pos1;
|
||||
private Location pos2;
|
||||
@ -199,8 +206,8 @@ public class Clipboard {
|
||||
public void paste(World world, Island island, Runnable task) {
|
||||
// Offset due to bedrock
|
||||
Vector off = new Vector(0,0,0);
|
||||
if (blockConfig.contains("bedrock")) {
|
||||
String[] offset = blockConfig.getString("bedrock").split(",");
|
||||
if (blockConfig.contains(BEDROCK)) {
|
||||
String[] offset = blockConfig.getString(BEDROCK).split(",");
|
||||
off = new Vector(Integer.valueOf(offset[0]), Integer.valueOf(offset[1]), Integer.valueOf(offset[2]));
|
||||
}
|
||||
// Calculate location for pasting
|
||||
@ -302,7 +309,6 @@ public class Clipboard {
|
||||
if (md instanceof Directional) {
|
||||
Directional facing = (Directional)md;
|
||||
if (md instanceof Stairs) {
|
||||
//facing.setFacingDirection(BlockFace.valueOf(s.getString(FACING)).getOppositeFace());
|
||||
Stairs stairs = (Stairs)md;
|
||||
stairs.setInverted(config.getBoolean("inverted"));
|
||||
stairs.setFacingDirection(BlockFace.valueOf(config.getString(FACING, "NORTH")));
|
||||
@ -359,26 +365,24 @@ public class Clipboard {
|
||||
if (bs instanceof InventoryHolder) {
|
||||
bs.update(true, false);
|
||||
Inventory ih = ((InventoryHolder)bs).getInventory();
|
||||
if (config.isConfigurationSection("inventory")) {
|
||||
ConfigurationSection inv = config.getConfigurationSection("inventory");
|
||||
if (config.isConfigurationSection(INVENTORY)) {
|
||||
ConfigurationSection inv = config.getConfigurationSection(INVENTORY);
|
||||
inv.getKeys(false).forEach(i -> ih.setItem(Integer.valueOf(i), (ItemStack)inv.get(i)));
|
||||
}
|
||||
}
|
||||
|
||||
// Entities
|
||||
if (config.isConfigurationSection("entity")) {
|
||||
ConfigurationSection en = config.getConfigurationSection("entity");
|
||||
if (config.isConfigurationSection(ENTITY)) {
|
||||
ConfigurationSection en = config.getConfigurationSection(ENTITY);
|
||||
en.getKeys(false).forEach(k -> {
|
||||
ConfigurationSection ent = en.getConfigurationSection(k);
|
||||
Location center = block.getLocation().add(new Vector(0.5, 0.0, 0.5));
|
||||
LivingEntity e = (LivingEntity)block.getWorld().spawnEntity(center, EntityType.valueOf(ent.getString("type", "PIG")));
|
||||
if (e instanceof Nameable) {
|
||||
if (e != null) {
|
||||
e.setCustomName(ent.getString("name"));
|
||||
}
|
||||
if (e instanceof Colorable) {
|
||||
if (ent.contains("color")) {
|
||||
((Colorable) e).setColor(DyeColor.valueOf(ent.getString("color")));
|
||||
}
|
||||
if (e instanceof Colorable && ent.contains(COLOR)) {
|
||||
((Colorable) e).setColor(DyeColor.valueOf(ent.getString(COLOR)));
|
||||
}
|
||||
if (e instanceof Tameable) {
|
||||
((Tameable)e).setTamed(ent.getBoolean("tamed"));
|
||||
@ -396,7 +400,7 @@ public class Clipboard {
|
||||
if (e instanceof AbstractHorse) {
|
||||
AbstractHorse horse = (AbstractHorse)e;
|
||||
horse.setDomestication(ent.getInt("domestication"));
|
||||
ConfigurationSection inv = ent.getConfigurationSection("inventory");
|
||||
ConfigurationSection inv = ent.getConfigurationSection(INVENTORY);
|
||||
inv.getKeys(false).forEach(i -> horse.getInventory().setItem(Integer.valueOf(i), (ItemStack)inv.get(i)));
|
||||
}
|
||||
|
||||
@ -427,12 +431,10 @@ public class Clipboard {
|
||||
for (LivingEntity e: entities) {
|
||||
ConfigurationSection en = s.createSection("entity." + e.getUniqueId());
|
||||
en.set("type", e.getType().name());
|
||||
if (e instanceof Nameable) {
|
||||
en.set("name", e.getCustomName());
|
||||
}
|
||||
en.set("name", e.getCustomName());
|
||||
if (e instanceof Colorable) {
|
||||
Colorable c = (Colorable)e;
|
||||
en.set("color", c.getColor().name());
|
||||
en.set(COLOR, c.getColor().name());
|
||||
}
|
||||
if (e instanceof Tameable && ((Tameable)e).isTamed()) {
|
||||
en.set("tamed", true);
|
||||
@ -471,7 +473,7 @@ public class Clipboard {
|
||||
s.set("data", block.getData());
|
||||
}
|
||||
if (block.getType().equals(Material.BEDROCK)) {
|
||||
blockConfig.set("bedrock", x + "," + y + "," + z);
|
||||
blockConfig.set(BEDROCK, x + "," + y + "," + z);
|
||||
}
|
||||
|
||||
// Block state
|
||||
@ -485,7 +487,6 @@ public class Clipboard {
|
||||
}
|
||||
if (md instanceof Directional) {
|
||||
if (md instanceof Stairs) {
|
||||
//facing.setFacingDirection(BlockFace.valueOf(s.getString(FACING)).getOppositeFace());
|
||||
Stairs stairs = (Stairs)md;
|
||||
s.set("inverted", stairs.isInverted());
|
||||
s.set(FACING, stairs.getAscendingDirection().name());
|
||||
@ -502,11 +503,11 @@ public class Clipboard {
|
||||
}
|
||||
if (md instanceof Colorable) {
|
||||
Colorable c = (Colorable)md;
|
||||
s.set("color", c.getColor().name());
|
||||
s.set(COLOR, c.getColor().name());
|
||||
}
|
||||
if (block.getType().equals(Material.CARPET)) {
|
||||
DyeColor c = DyeColor.getByWoolData(block.getData());
|
||||
s.set("color", c.name());
|
||||
s.set(COLOR, c.name());
|
||||
}
|
||||
if (md instanceof Redstone) {
|
||||
Redstone r = (Redstone)md;
|
||||
|
@ -1,6 +1,3 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -22,7 +19,7 @@ public class BannedVisitorCommands implements Listener {
|
||||
private BSkyBlock plugin;
|
||||
|
||||
/**
|
||||
* @param plugin
|
||||
* @param plugin - plugin
|
||||
*/
|
||||
public BannedVisitorCommands(BSkyBlock plugin) {
|
||||
this.plugin = plugin;
|
||||
|
@ -1,7 +1,5 @@
|
||||
package us.tastybento.bskyblock.listeners;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@ -119,7 +117,7 @@ public class NetherPortals implements Listener {
|
||||
if (plugin.getIWM().isEndGenerate(overWorld) && plugin.getIWM().isEndIslands(overWorld)) {
|
||||
World endWorld = plugin.getIWM().getEndWorld(overWorld);
|
||||
// End exists and end islands are being used
|
||||
Location to = plugin.getIslands().getIslandAt(e.getFrom()).map(i -> i.getSpawnPoint(Environment.THE_END)).filter(Objects::nonNull).orElse(e.getFrom().toVector().toLocation(endWorld));
|
||||
Location to = plugin.getIslands().getIslandAt(e.getFrom()).map(i -> i.getSpawnPoint(Environment.THE_END)).orElse(e.getFrom().toVector().toLocation(endWorld));
|
||||
e.setCancelled(true);
|
||||
new SafeTeleportBuilder(plugin)
|
||||
.entity(e.getPlayer())
|
||||
@ -179,7 +177,7 @@ public class NetherPortals implements Listener {
|
||||
if (e.getFrom().getWorld().getEnvironment().equals(Environment.NETHER)) {
|
||||
// If this is from the island nether, then go to the same vector, otherwise try island home location
|
||||
Location to = plugin.getIWM().isNetherIslands(overWorld)
|
||||
? plugin.getIslands().getIslandAt(e.getFrom()).map(i -> i.getSpawnPoint(Environment.NORMAL)).filter(Objects::nonNull).orElse(e.getFrom().toVector().toLocation(overWorld))
|
||||
? plugin.getIslands().getIslandAt(e.getFrom()).map(i -> i.getSpawnPoint(Environment.NORMAL)).orElse(e.getFrom().toVector().toLocation(overWorld))
|
||||
: plugin.getIslands().getIslandLocation(overWorld, e.getPlayer().getUniqueId());
|
||||
|
||||
e.setCancelled(true);
|
||||
@ -194,7 +192,7 @@ public class NetherPortals implements Listener {
|
||||
World nether = plugin.getIWM().getNetherWorld(overWorld);
|
||||
// If this is to island nether, then go to the same vector, otherwise try spawn
|
||||
Location to = (plugin.getIWM().isNetherIslands(overWorld) && plugin.getIWM().isNetherGenerate(overWorld))
|
||||
? plugin.getIslands().getIslandAt(e.getFrom()).map(i -> i.getSpawnPoint(Environment.NETHER)).filter(Objects::nonNull).orElse(e.getFrom().toVector().toLocation(nether))
|
||||
? plugin.getIslands().getIslandAt(e.getFrom()).map(i -> i.getSpawnPoint(Environment.NETHER)).orElse(e.getFrom().toVector().toLocation(nether))
|
||||
: nether.getSpawnLocation();
|
||||
e.setCancelled(true);
|
||||
// Else other worlds teleport to the nether
|
||||
|
@ -1,5 +1,7 @@
|
||||
package us.tastybento.bskyblock.listeners.flags;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.FlowerPot;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
@ -124,40 +126,19 @@ public class BlockInteractionListener extends AbstractFlagListener {
|
||||
case REDSTONE_COMPARATOR:
|
||||
checkIsland(e, e.getClickedBlock().getLocation(), Flags.REDSTONE);
|
||||
break;
|
||||
case ARMOR_STAND:
|
||||
this.getPlugin().log("DEBUG: " + e.getClickedBlock().getType());
|
||||
break;
|
||||
case BANNER:
|
||||
this.getPlugin().log("DEBUG: " + e.getClickedBlock().getType());
|
||||
break;
|
||||
case BED:
|
||||
this.getPlugin().log("DEBUG: " + e.getClickedBlock().getType());
|
||||
break;
|
||||
case BOAT:
|
||||
case BOAT_ACACIA:
|
||||
case BOAT_BIRCH:
|
||||
case BOAT_DARK_OAK:
|
||||
case BOAT_JUNGLE:
|
||||
case BOAT_SPRUCE:
|
||||
this.getPlugin().log("DEBUG: " + e.getClickedBlock().getType());
|
||||
break;
|
||||
case DRAGON_EGG:
|
||||
checkIsland(e, e.getClickedBlock().getLocation(), Flags.BREAK_BLOCKS);
|
||||
break;
|
||||
case ENDER_PORTAL_FRAME:
|
||||
this.getPlugin().log("DEBUG: " + e.getClickedBlock().getType());
|
||||
checkIsland(e, e.getClickedBlock().getLocation(), Flags.PLACE_BLOCKS);
|
||||
break;
|
||||
case FLOWER_POT:
|
||||
this.getPlugin().log("DEBUG: " + e.getClickedBlock().getType());
|
||||
break;
|
||||
case MOB_SPAWNER:
|
||||
this.getPlugin().log("DEBUG: " + e.getClickedBlock().getType());
|
||||
break;
|
||||
case OBSERVER:
|
||||
this.getPlugin().log("DEBUG: " + e.getClickedBlock().getType());
|
||||
break;
|
||||
case POWERED_MINECART:
|
||||
this.getPlugin().log("DEBUG: " + e.getClickedBlock().getType());
|
||||
FlowerPot pot = (FlowerPot) e.getClickedBlock().getState();
|
||||
if (pot.getContents() == null || pot.getContents().getItemType().equals(Material.AIR)) {
|
||||
checkIsland(e, e.getClickedBlock().getLocation(), Flags.PLACE_BLOCKS);
|
||||
} else {
|
||||
checkIsland(e, e.getClickedBlock().getLocation(), Flags.BREAK_BLOCKS);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -18,6 +18,7 @@ import org.bukkit.event.vehicle.VehicleDamageEvent;
|
||||
import org.bukkit.util.BlockIterator;
|
||||
|
||||
import us.tastybento.bskyblock.api.flags.AbstractFlagListener;
|
||||
import us.tastybento.bskyblock.api.localization.TextVariables;
|
||||
import us.tastybento.bskyblock.api.user.User;
|
||||
import us.tastybento.bskyblock.lists.Flags;
|
||||
|
||||
@ -100,14 +101,14 @@ public class BreakBlocksListener extends AbstractFlagListener {
|
||||
getIslands().getIslandAt(e.getVehicle().getLocation()).ifPresent(x -> {
|
||||
if (!x.isAllowed(user, Flags.BREAK_BLOCKS)) {
|
||||
e.setCancelled(true);
|
||||
user.sendMessage("protection.protected");
|
||||
user.notify("protection.protected", TextVariables.DESCRIPTION, user.getTranslation(Flags.BREAK_BLOCKS.getHintReference()));
|
||||
}
|
||||
});
|
||||
|
||||
// The player is in the world, but not on an island, so general world settings apply
|
||||
if (!Flags.BREAK_BLOCKS.isSetForWorld(e.getVehicle().getWorld())) {
|
||||
e.setCancelled(true);
|
||||
user.sendMessage("protection.protected");
|
||||
user.notify("protection.protected", TextVariables.DESCRIPTION, user.getTranslation(Flags.BREAK_BLOCKS.getHintReference()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -704,7 +704,6 @@ public class IslandsManager {
|
||||
handler.saveObject(island);
|
||||
} catch (Exception e) {
|
||||
plugin.logError("Could not save island to database when running async! " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
midSave = false;
|
||||
|
@ -82,7 +82,6 @@ public class SchemsManager {
|
||||
islandSchems.put(world, cb);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
plugin.logError("Could not load " + name + " schem");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -190,9 +190,7 @@ public class NewIsland {
|
||||
// Find a free spot
|
||||
Map<Result, Integer> result = new EnumMap<>(Result.class);
|
||||
Result r = isIsland(last);
|
||||
while (!r.equals(Result.FREE)
|
||||
&& (result.getOrDefault(Result.BLOCK_AT_CENTER, 0) < MAX_UNOWNED_ISLANDS
|
||||
&& result.getOrDefault(Result.BLOCK_AT_CENTER, 0) < MAX_UNOWNED_ISLANDS)) {
|
||||
while (!r.equals(Result.FREE) && result.getOrDefault(Result.BLOCK_AT_CENTER, 0) < MAX_UNOWNED_ISLANDS) {
|
||||
last = nextGridLocation(last);
|
||||
result.merge(r, 1, (k,v) -> v++);
|
||||
r = isIsland(last);
|
||||
|
Loading…
Reference in New Issue
Block a user