Skip to content

Commit

Permalink
Performs block limiting.
Browse files Browse the repository at this point in the history
Store blocks placed in the database.

Entity limits are not done yet.
  • Loading branch information
tastybento committed Feb 7, 2019
1 parent 202aa8f commit b7b6c04
Show file tree
Hide file tree
Showing 10 changed files with 437 additions and 99 deletions.
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>bentobox.add</groupId>
<artifactId>addon-limits</artifactId>
<version>0.0.1-SNAPSHOT</version>
<groupId>world.bentobox</groupId>
<artifactId>limits</artifactId>
<version>0.0.2-SNAPSHOT</version>
<name>addon-limits</name>
<description>An add-on for BentoBox that limits entities on islands.</description>
<description>An add-on for BentoBox that limits blocks and entities on islands.</description>
<url>https://github.com/BentoBoxWorld/addon-level</url>
<inceptionYear>2018</inceptionYear>

Expand Down Expand Up @@ -41,7 +41,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13.1-R0.1-SNAPSHOT</version>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -65,7 +65,7 @@
<dependency>
<groupId>world.bentobox</groupId>
<artifactId>bentobox</artifactId>
<version>0.10.0-SNAPSHOT</version>
<version>1.3.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
59 changes: 30 additions & 29 deletions src/main/java/bentobox/addon/limits/Limits.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
package bentobox.addon.limits;

import java.util.List;
import java.util.stream.Collectors;

import org.bukkit.World;

import bentobox.addon.limits.listeners.BlockLimitsListener;
import bentobox.addon.limits.listeners.EntityLimitsListener;
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.addons.GameModeAddon;


/**
* Addon to BSkyBlock that enables island level scoring and top ten functionality
* Addon to BentoBox that monitors and enforces limits
* @author tastybento
*
*/
public class Limits extends Addon {

Settings settings;
private Settings settings;
private EntityLimitsListener listener;
private List<World> worlds;
private BlockLimitsListener blockLimitListener;

@Override
public void onDisable(){
if (listener != null) {
worlds.forEach(listener::disable);
}
if (blockLimitListener != null) {
blockLimitListener.save();
}
}

@Override
Expand All @@ -23,33 +39,18 @@ public void onEnable() {
saveDefaultConfig();
// Load settings
settings = new Settings(this);
// Register commands
// AcidIsland hook in
this.getPlugin().getAddonsManager().getAddonByName("AcidIsland").ifPresent(a -> {
CompositeCommand acidIslandCmd = getPlugin().getCommandsManager().getCommand(getConfig().getString("acidisland.user-command","ai"));
if (acidIslandCmd != null) {
CompositeCommand acidCmd = getPlugin().getCommandsManager().getCommand(getConfig().getString("acidisland.admin-command","acid"));
}
});
// BSkyBlock hook in
this.getPlugin().getAddonsManager().getAddonByName("BSkyBlock").ifPresent(a -> {
CompositeCommand bsbIslandCmd = getPlugin().getCommandsManager().getCommand(getConfig().getString("bskyblock.user-command","island"));
if (bsbIslandCmd != null) {
CompositeCommand bsbAdminCmd = getPlugin().getCommandsManager().getCommand(getConfig().getString("bskyblock.admin-command","bsbadmin"));
}
});

// Register new island listener
//registerListener(new NewIslandListener(this));
//registerListener(new JoinLeaveListener(this));
// Register worlds from GameModes
worlds = getPlugin().getAddonsManager().getGameModeAddons().stream()
.filter(gm -> settings.getGameModes().contains(gm.getDescription().getName()))
.map(GameModeAddon::getOverWorld)
.collect(Collectors.toList());
worlds.forEach(w -> log("Limits will apply to " + w.getName()));
// Register listener
//listener = new EntityLimitsListener(this);
//registerListener(listener);
blockLimitListener = new BlockLimitsListener(this);
registerListener(blockLimitListener);
// Done

}

/**
* Save the levels to the database
*/
private void save(){
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/bentobox/addon/limits/Settings.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package bentobox.addon.limits;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bukkit.configuration.ConfigurationSection;
Expand All @@ -10,8 +12,13 @@
public class Settings {

private Map<EntityType, Integer> limits = new HashMap<>();
private List<String> gameModes = new ArrayList<>();

public Settings(Limits addon) {

// GameModes
gameModes = addon.getConfig().getStringList("game-modes");

ConfigurationSection el = addon.getConfig().getConfigurationSection("entitylimits");
if (el != null) {
for (String key : el.getKeys(false)) {
Expand All @@ -34,4 +41,11 @@ public Map<EntityType, Integer> getLimits() {
return limits;
}

/**
* @return the gameModes
*/
public List<String> getGameModes() {
return gameModes;
}

}

0 comments on commit b7b6c04

Please sign in to comment.