mirror of
https://github.com/BentoBoxWorld/Limits.git
synced 2024-11-22 18:46:02 +01:00
Merge pull request #112 from BentoBoxWorld/perm-event
Added new event that fires for each perm
This commit is contained in:
commit
fbf13bd99e
@ -5,13 +5,8 @@ addons:
|
||||
organization: "bentobox-world"
|
||||
|
||||
jdk:
|
||||
- openjdk8
|
||||
- openjdk11
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- jdk: openjdk11
|
||||
|
||||
script:
|
||||
# the following command line builds the project, runs the tests with coverage and then execute the SonarCloud analysis
|
||||
- mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar -Dsonar.projectKey=BentoBoxWorld_Limits
|
||||
|
@ -133,6 +133,10 @@ public class Settings {
|
||||
return gameModes;
|
||||
}
|
||||
|
||||
/**
|
||||
* A named class representing a group of entities and their limits
|
||||
*
|
||||
*/
|
||||
public static class EntityGroup {
|
||||
private final String name;
|
||||
private final Set<EntityType> types;
|
||||
|
@ -0,0 +1,116 @@
|
||||
package world.bentobox.limits.events;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import world.bentobox.limits.Settings.EntityGroup;
|
||||
import world.bentobox.limits.objects.IslandBlockCount;
|
||||
|
||||
/**
|
||||
* Fired when a player joins the server and for each perm-based limit setting.
|
||||
* If cancelled, no limit settings will be made.
|
||||
* Settings can be adjusted and will be used.
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class LimitsPermCheckEvent extends LimitsJoinPermCheckEvent {
|
||||
|
||||
private @Nullable EntityGroup entityGroup;
|
||||
private @Nullable EntityType entityType;
|
||||
private @Nullable Material material;
|
||||
private int value;
|
||||
|
||||
/**
|
||||
* Fired when a player joins the server and for each perm-based limit setting.
|
||||
* If cancelled, no limit settings will be made.
|
||||
* Settings can be adjusted and will be used.
|
||||
* @param player - player joining
|
||||
* @param islandId - the unique island id.
|
||||
* @param ibc - IslandBlockCount object for this island
|
||||
* @param material - material being limited, or null
|
||||
* @param entityType - entity type being limited, or null
|
||||
* @param entgroup - entity group being limited, or null
|
||||
* @param value - numeric limit given by the perm
|
||||
*/
|
||||
public LimitsPermCheckEvent(@NonNull Player player,
|
||||
@NonNull String islandId,
|
||||
@Nullable IslandBlockCount ibc,
|
||||
@Nullable EntityGroup entgroup,
|
||||
@Nullable EntityType entityType,
|
||||
@Nullable Material material,
|
||||
int value) {
|
||||
super(player, islandId, ibc);
|
||||
this.entityGroup = entgroup;
|
||||
this.entityType = entityType;
|
||||
this.material = material;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the entityGroup
|
||||
*/
|
||||
public EntityGroup getEntityGroup() {
|
||||
return entityGroup;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param entityGroup the entityGroup to set
|
||||
*/
|
||||
public void setEntityGroup(EntityGroup entityGroup) {
|
||||
this.entityGroup = entityGroup;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the entityType
|
||||
*/
|
||||
public EntityType getEntityType() {
|
||||
return entityType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param entityType the entityType to set
|
||||
*/
|
||||
public void setEntityType(EntityType entityType) {
|
||||
this.entityType = entityType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the material
|
||||
*/
|
||||
public Material getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param material the material to set
|
||||
*/
|
||||
public void setMaterial(Material material) {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the value
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param value the value to set
|
||||
*/
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -25,6 +25,7 @@ import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.limits.Limits;
|
||||
import world.bentobox.limits.Settings.EntityGroup;
|
||||
import world.bentobox.limits.events.LimitsJoinPermCheckEvent;
|
||||
import world.bentobox.limits.events.LimitsPermCheckEvent;
|
||||
import world.bentobox.limits.objects.IslandBlockCount;
|
||||
|
||||
/**
|
||||
@ -91,22 +92,35 @@ public class JoinListener implements Listener {
|
||||
if (ibc == null) {
|
||||
ibc = new IslandBlockCount(islandId, gameMode);
|
||||
}
|
||||
|
||||
int value = Integer.parseInt(split[4]);
|
||||
// Fire perm check event
|
||||
LimitsPermCheckEvent l = new LimitsPermCheckEvent(player, gameMode, ibc, entgroup, et, m, value);
|
||||
Bukkit.getPluginManager().callEvent(l);
|
||||
if (l.isCancelled()) continue;
|
||||
// Use event values
|
||||
ibc = l.getIbc();
|
||||
entgroup = l.getEntityGroup();
|
||||
et = l.getEntityType();
|
||||
m = l.getMaterial();
|
||||
value = l.getValue();
|
||||
|
||||
if (entgroup != null) {
|
||||
// Entity group limit
|
||||
ibc.setEntityGroupLimit(entgroup.getName(), Math.max(ibc.getEntityGroupLimit(entgroup.getName()), Integer.valueOf(split[4])));
|
||||
ibc.setEntityGroupLimit(entgroup.getName(), Math.max(ibc.getEntityGroupLimit(entgroup.getName()), value));
|
||||
} else if (et != null && m == null) {
|
||||
// Entity limit
|
||||
ibc.setEntityLimit(et, Math.max(ibc.getEntityLimit(et), Integer.valueOf(split[4])));
|
||||
ibc.setEntityLimit(et, Math.max(ibc.getEntityLimit(et), value));
|
||||
} else if (m != null && et == null) {
|
||||
// Material limit
|
||||
ibc.setBlockLimit(m, Math.max(ibc.getBlockLimit(m), Integer.valueOf(split[4])));
|
||||
ibc.setBlockLimit(m, Math.max(ibc.getBlockLimit(m), value));
|
||||
} else {
|
||||
if (m.isBlock()) {
|
||||
if (m != null && m.isBlock()) {
|
||||
// Material limit
|
||||
ibc.setBlockLimit(m, Math.max(ibc.getBlockLimit(m), Integer.valueOf(split[4])));
|
||||
} else {
|
||||
ibc.setBlockLimit(m, Math.max(ibc.getBlockLimit(m), value));
|
||||
} else if (et != null){
|
||||
// This is an entity setting
|
||||
ibc.setEntityLimit(et, Math.max(ibc.getEntityLimit(et), Integer.valueOf(split[4])));
|
||||
ibc.setEntityLimit(et, Math.max(ibc.getEntityLimit(et), value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user