Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies {
implementation("io.papermc:paperlib:1.0.7")
implementation("co.aikar:idb-core:1.0.0-SNAPSHOT")
implementation("com.zaxxer:HikariCP:5.1.0")
implementation("com.github.retrooper.packetevents:spigot:2.2.0")
implementation("com.github.retrooper.packetevents:spigot:2.2.1")
compileOnly("com.github.N0RSKA:DeluxeSellwandsAPI:32c")
compileOnly("com.ghostchu:quickshop-api:5.2.0.8")
compileOnly("com.google.guava:guava:33.0.0-jre")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ private int getActivePermission(Location location, Material material){
}

private int getActivePermission(UUID uuid, Location location, PermissionRoute route){ //should only be executed with a location inside the claim
if (uuid.equals(owner))
if (uuid.equals(owner)) {
return PermState.ENABLED;
}

if (location != null && subClaims.size() > 0){
if (location != null && !subClaims.isEmpty()){
SubClaim subClaim = getSubClaim(location.getBlockX(), location.getBlockZ());
if (subClaim != null){
return PermissionRouter.getLayeredPermission(this, subClaim, uuid, route);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public GlobalPermissionSet() {

}

public GlobalPermissionSet(int build, int interactions, int entities, int explosions, int entityGrief, int teleportation, int viewSubClaims, HashMap<Material, Integer> containers, int defaultContainerValue, int pistons, int fluids) {
super(build, interactions, entities, teleportation, viewSubClaims, containers, defaultContainerValue);
public GlobalPermissionSet(int build, int interactions, int entities, int explosions, int entityGrief, int teleportation, int viewSubClaims, HashMap<Material, Integer> containers, int defaultContainerValue, int pistons, int fluids, int dropPickupItems) {
super(build, interactions, entities, teleportation, viewSubClaims, containers, defaultContainerValue, dropPickupItems);
this.entityGrief = entityGrief;
this.pistons = pistons;
this.explosions = explosions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ public abstract class PermissionSet implements Cloneable{
private int entities;
private int teleportation;
private int viewSubClaims;
private int dropPickupItems;

private HashMap<Material, Integer> containers;
private int defaultContainerValue;

public PermissionSet(){
public PermissionSet() {

}

public PermissionSet(int build, int interactions, int entities, int teleportation, int viewSubClaims, HashMap<Material, Integer> containers, int defaultContainerValue) {
public PermissionSet(int build, int interactions, int entities, int teleportation, int viewSubClaims, HashMap<Material, Integer> containers, int defaultContainerValue, int dropPickupItems) {
this.build = build;
this.interactions = interactions;
this.entities = entities;
this.teleportation = teleportation;
this.viewSubClaims = viewSubClaims;
this.containers = containers;
this.defaultContainerValue = defaultContainerValue;
this.dropPickupItems = dropPickupItems;
}

public int getBuild() {
Expand Down Expand Up @@ -76,6 +78,14 @@ public HashMap<Material, Integer> getContainers() {
return containers;
}

public int getDropPickupItems() {
return dropPickupItems;
}

public void setDropPickupItems(int dropPickupItems) {
this.dropPickupItems = dropPickupItems;
}

public PermissionSet clone() {
try {
return (PermissionSet) super.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public PlayerPermissionSet() {

}

public PlayerPermissionSet(int build, int interactions, int entities, int explosions, int teleportation, int viewSubClaims, HashMap<Material, Integer> containers, int defaultContainerValue, int modifyPermissions, int modifyClaim) {
super(build, interactions, entities, teleportation, viewSubClaims, containers, defaultContainerValue);
public PlayerPermissionSet(int build, int interactions, int entities, int explosions, int teleportation, int viewSubClaims, HashMap<Material, Integer> containers, int defaultContainerValue, int modifyPermissions, int modifyClaim, int dropPickupItems) {
super(build, interactions, entities, teleportation, viewSubClaims, containers, defaultContainerValue, dropPickupItems);
this.modifyPermissions = modifyPermissions;
this.modifyClaim = modifyClaim;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public SubPermissionGroup(BaseClaim owner, GlobalPermissionSet globalPermissionS
@Override
public PlayerPermissionSet createPlayerPermissionSet() {
return new PlayerPermissionSet(PermState.NEUTRAL, PermState.NEUTRAL, PermState.NEUTRAL, PermState.NEUTRAL, PermState.NEUTRAL,
PermState.NEUTRAL, new HashMap<>(), PermState.NEUTRAL, PermState.NEUTRAL, PermState.NEUTRAL);
PermState.NEUTRAL, new HashMap<>(), PermState.NEUTRAL, PermState.NEUTRAL, PermState.NEUTRAL, PermState.NEUTRAL);
}

@Override
public GlobalPermissionSet createGlobalPermissionSet() {
return new GlobalPermissionSet(PermState.NEUTRAL, PermState.NEUTRAL, PermState.NEUTRAL, PermState.NEUTRAL, PermState.NEUTRAL, PermState.NEUTRAL,
PermState.NEUTRAL, new HashMap<>(), PermState.NEUTRAL, PermState.NEUTRAL, PermState.NEUTRAL);
PermState.NEUTRAL, new HashMap<>(), PermState.NEUTRAL, PermState.NEUTRAL, PermState.NEUTRAL, PermState.NEUTRAL);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public ParentPermissionGroup(BaseClaim owner, GlobalPermissionSet globalPermissi
@Override
public PlayerPermissionSet createPlayerPermissionSet() {
return new PlayerPermissionSet(PermState.NEUTRAL, PermState.NEUTRAL, PermState.NEUTRAL, PermState.NEUTRAL, PermState.NEUTRAL, PermState.NEUTRAL,
new HashMap<>(), PermState.NEUTRAL, PermState.DISABLE, PermState.DISABLE);
new HashMap<>(), PermState.NEUTRAL, PermState.DISABLE, PermState.DISABLE, PermState.NEUTRAL);
}

@Override
public GlobalPermissionSet createGlobalPermissionSet() {
return new GlobalPermissionSet(PermState.DISABLE, PermState.DISABLE, PermState.DISABLE, PermState.DISABLE, PermState.DISABLE, PermState.ENABLED, PermState.ENABLED,
new HashMap<>(), PermState.DISABLE, PermState.DISABLE, PermState.DISABLE);
new HashMap<>(), PermState.DISABLE, PermState.DISABLE, PermState.DISABLE, PermState.ENABLED);
}

@Override
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/net/crashcraft/crashclaim/data/MaterialName.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@ public MaterialName(){
names = new HashMap<>();

for (Material material : Material.values()){
names.put(material,
StringUtils.capitalize(StringUtils.join(StringUtils.split(
CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, material.name())
), ' ')));
String[] split = material.toString().split("_");

StringBuilder builder = new StringBuilder();
for (String s : split) {
builder.append(StringUtils.capitalize(s.toLowerCase()));
builder.append(" ");
}

String capitalize = StringUtils.capitalize(StringUtils.join(StringUtils.split(
CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, builder.toString())
), ' '));

names.put(material, capitalize);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ private void setInitialParams(){

private void updateDatabase(){
int latestVersion = (dataVersions.get(dataVersions.size() - 1).getVersion());
if (currentRevision == latestVersion){
if (currentRevision >= latestVersion){
if (currentRevision > latestVersion){
logger.severe("Database is at a higher version than the plugin, tread with caution");
}
return;
}

Expand Down Expand Up @@ -77,6 +80,7 @@ private void setupDataVersions(){
registerDataVersion(new DataRev2());
registerDataVersion(new DataRev3());
registerDataVersion(new DataRev4());
registerDataVersion(new DataRev5());
}

private void validateDataVersions(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ private void savePermissions(int data_id, PermissionGroup group) throws SQLExcep

DB.executeUpdate("INSERT INTO permission_set(data_id, players_id, build, interactions, entities, explosions, entityGrief, teleportation, defaultContainer, viewSubClaims, pistons, fluids) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT (data_id, players_id) DO UPDATE SET " +
"build = ?, interactions = ?, entities = ?, explosions = ?, entityGrief = ?, teleportation = ?, defaultContainer = ?, viewSubClaims = ?, pistons = ?, fluids = ?",
"build = ?, interactions = ?, entities = ?, explosions = ?, entityGrief = ?, teleportation = ?, defaultContainer = ?, viewSubClaims = ?, pistons = ?, fluids = ?, dropPickupItems = ?",
data_id,
-1,
global.getBuild(),
Expand All @@ -324,7 +324,8 @@ private void savePermissions(int data_id, PermissionGroup group) throws SQLExcep
global.getDefaultConatinerValue(),
global.getViewSubClaims(),
global.getPistons(),
global.getFluids()
global.getFluids(),
global.getDropPickupItems()
);

addContainers(data_id, -1, global.getContainers());
Expand All @@ -339,7 +340,7 @@ private void savePermissions(int data_id, PermissionGroup group) throws SQLExcep

DB.executeUpdate("INSERT INTO permission_set(data_id, players_id, build, interactions, entities, teleportation, defaultContainer, viewSubClaims, modifyPermissions, modifyClaim) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT (data_id, players_id) DO UPDATE SET " +
"build = ?, interactions = ?, entities = ?, teleportation = ?, defaultContainer = ?, viewSubClaims = ?, modifyPermissions = ?, modifyClaim = ?",
"build = ?, interactions = ?, entities = ?, teleportation = ?, defaultContainer = ?, viewSubClaims = ?, modifyPermissions = ?, modifyClaim = ?, dropPickupItems = ?",
data_id,
player_id,
perms.getBuild(),
Expand All @@ -358,7 +359,8 @@ private void savePermissions(int data_id, PermissionGroup group) throws SQLExcep
perms.getDefaultConatinerValue(),
perms.getViewSubClaims(),
perms.getModifyPermissions(),
perms.getModifyClaim()
perms.getModifyClaim(),
perms.getDropPickupItems()
);

addContainers(data_id, player_id, perms.getContainers());
Expand Down Expand Up @@ -539,8 +541,8 @@ public Claim loadClaim(Integer id) {
return null;
}

private GlobalPermissionSet getGlobalPermissionSet(int data_id) throws SQLException{
DbRow globalPermissionRow = DB.getFirstRow("SELECT build, interactions, entities, explosions, entityGrief, teleportation, viewSubClaims, pistons, fluids, defaultContainer FROM permission_set " +
private GlobalPermissionSet getGlobalPermissionSet(int data_id) throws SQLException {
DbRow globalPermissionRow = DB.getFirstRow("SELECT build, interactions, entities, explosions, entityGrief, teleportation, viewSubClaims, pistons, fluids, defaultContainer, dropPickupItems FROM permission_set " +
"WHERE data_id = ? AND players_id = -1", data_id);

HashMap<Material, Integer> globalContainers = new HashMap<>();
Expand All @@ -549,24 +551,25 @@ private GlobalPermissionSet getGlobalPermissionSet(int data_id) throws SQLExcept
}

return new GlobalPermissionSet(
globalPermissionRow.getInt("build"),
globalPermissionRow.getInt("interactions"),
globalPermissionRow.getInt("entities"),
globalPermissionRow.getInt("explosions"),
globalPermissionRow.getInt("entityGrief"),
globalPermissionRow.getInt("teleportation"),
globalPermissionRow.getInt("viewSubClaims"),
globalPermissionRow.getInt("build", PermState.ENABLED),
globalPermissionRow.getInt("interactions", PermState.ENABLED),
globalPermissionRow.getInt("entities", PermState.ENABLED),
globalPermissionRow.getInt("explosions", PermState.ENABLED),
globalPermissionRow.getInt("entityGrief", PermState.ENABLED),
globalPermissionRow.getInt("teleportation", PermState.ENABLED),
globalPermissionRow.getInt("viewSubClaims", PermState.ENABLED),
globalContainers,
globalPermissionRow.getInt("defaultContainer"),
globalPermissionRow.getInt("pistons"),
globalPermissionRow.getInt("fluids")
globalPermissionRow.getInt("defaultContainer", PermState.ENABLED),
globalPermissionRow.getInt("pistons", PermState.ENABLED),
globalPermissionRow.getInt("fluids", PermState.ENABLED),
globalPermissionRow.getInt("dropPickupItems", PermState.ENABLED)
);
}

private HashMap<UUID, PlayerPermissionSet> getPlayerPermissions(int data_id) throws SQLException{
private HashMap<UUID, PlayerPermissionSet> getPlayerPermissions(int data_id) throws SQLException {
HashMap<UUID, PlayerPermissionSet> perms = new HashMap<>();

for (DbRow permissionRow : DB.getResults("SELECT players_id, (SELECT uuid FROM players WHERE players.id = permission_set.players_id) AS uuid, build, interactions, entities, teleportation, viewSubClaims, defaultContainer, modifyPermissions, modifyClaim FROM permission_set " +
for (DbRow permissionRow : DB.getResults("SELECT players_id, (SELECT uuid FROM players WHERE players.id = permission_set.players_id) AS uuid, build, interactions, entities, teleportation, viewSubClaims, defaultContainer, modifyPermissions, modifyClaim, dropPickupItems FROM permission_set " +
"WHERE data_id = ? AND players_id IS NOT -1", data_id)){

HashMap<Material, Integer> containers = new HashMap<>();
Expand All @@ -576,16 +579,17 @@ private HashMap<UUID, PlayerPermissionSet> getPlayerPermissions(int data_id) thr
}

PlayerPermissionSet set = new PlayerPermissionSet(
permissionRow.getInt("build"),
permissionRow.getInt("interactions"),
permissionRow.getInt("entities"),
permissionRow.getInt("build", PermState.ENABLED),
permissionRow.getInt("interactions", PermState.ENABLED),
permissionRow.getInt("entities", PermState.ENABLED),
PermState.ENABLED, // TODO not used
permissionRow.getInt("teleportation"),
permissionRow.getInt("viewSubClaims"),
permissionRow.getInt("teleportation", PermState.ENABLED),
permissionRow.getInt("viewSubClaims", PermState.ENABLED),
containers,
permissionRow.getInt("defaultContainer"),
permissionRow.getInt("modifyPermissions"),
permissionRow.getInt("modifyClaim")
permissionRow.getInt("defaultContainer", PermState.ENABLED),
permissionRow.getInt("modifyPermissions", PermState.ENABLED),
permissionRow.getInt("modifyClaim", PermState.ENABLED),
permissionRow.getInt("dropPickupItems", PermState.ENABLED)
);

perms.put(UUID.fromString(permissionRow.getString("uuid")), set);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.crashcraft.crashclaim.data.providers.sqlite.versions;

import co.aikar.idb.DB;
import net.crashcraft.crashclaim.data.providers.sqlite.DataVersion;

import java.sql.SQLException;

public class DataRev5 implements DataVersion {
@Override
public int getVersion() {
return 5;
}

// add dropPickupItems column to permission_set
@Override
public void executeUpgrade(int fromRevision) throws SQLException {
DB.executeUpdate("ALTER TABLE permission_set ADD COLUMN dropPickupItems INTEGER DEFAULT 2");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
import net.crashcraft.crashclaim.permissions.PermissionRoute;
import net.crashcraft.crashclaim.permissions.PermissionSetup;
import net.crashcraft.crashclaim.visualize.VisualizationManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Container;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.block.data.type.Dispenser;
import org.bukkit.entity.*;
Expand All @@ -38,15 +38,7 @@
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPickupArrowEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.*;
import org.bukkit.event.vehicle.VehicleDamageEvent;
import org.bukkit.inventory.BlockInventoryHolder;

Expand Down Expand Up @@ -197,6 +189,30 @@ private boolean isFullOfLiquid(Block block){
|| (block.getBlockData() instanceof Waterlogged && ((Waterlogged) block.getBlockData()).isWaterlogged());
}

@EventHandler
public void onItemDrop(PlayerDropItemEvent event) {
if (GlobalConfig.disabled_worlds.contains(event.getPlayer().getWorld().getUID())){
return;
}

if (!helper.hasPermission(event.getPlayer().getUniqueId(), event.getPlayer().getLocation(), PermissionRoute.ITEM_DROP_PICKUP)){
event.setCancelled(true);
visuals.sendAlert(event.getPlayer(), Localization.ALERT__NO_PERMISSIONS__DROP_PICKUP.getMessage(event.getPlayer()));
}
}

@EventHandler
public void onItemPickup(PlayerAttemptPickupItemEvent event) {
if (GlobalConfig.disabled_worlds.contains(event.getPlayer().getWorld().getUID())){
return;
}

if (!helper.hasPermission(event.getPlayer().getUniqueId(), event.getItem().getLocation(), PermissionRoute.ITEM_DROP_PICKUP)){
event.setCancelled(true);
visuals.sendAlert(event.getPlayer(), Localization.ALERT__NO_PERMISSIONS__DROP_PICKUP.getMessage(event.getPlayer()));
}
}

@EventHandler (priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPistonEvent(BlockPistonExtendEvent event){
if (GlobalConfig.disabled_worlds.contains(event.getBlock().getWorld().getUID())){
Expand Down
Loading