Compare commits

..

1 Commits

19 changed files with 28 additions and 404 deletions

View File

@ -44,7 +44,6 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
import com.plotsquared.core.plot.flag.implementations.ProjectilesFlag;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.Permissions;
import net.kyori.adventure.text.minimessage.Template;
@ -353,15 +352,13 @@ public class PaperListener implements Listener {
event.setCancelled(true);
}
} else if (!plot.isAdded(pp.getUUID())) {
if (!plot.getFlag(ProjectilesFlag.class)) {
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) {
pp.sendMessage(
TranslatableCaption.of("permission.no_permission_event"),
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER))
);
entity.remove();
event.setCancelled(true);
}
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) {
pp.sendMessage(
TranslatableCaption.of("permission.no_permission_event"),
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER))
);
entity.remove();
event.setCancelled(true);
}
}
}

View File

@ -35,7 +35,6 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotHandler;
import com.plotsquared.core.plot.flag.implementations.ProjectilesFlag;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.Permissions;
import net.kyori.adventure.text.minimessage.Template;
@ -129,15 +128,13 @@ public class ProjectileEventListener implements Listener {
event.setCancelled(true);
}
} else if (!plot.isAdded(pp.getUUID())) {
if (!plot.getFlag(ProjectilesFlag.class)) {
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) {
pp.sendMessage(
TranslatableCaption.of("permission.no_permission_event"),
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER))
);
entity.remove();
event.setCancelled(true);
}
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) {
pp.sendMessage(
TranslatableCaption.of("permission.no_permission_event"),
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER))
);
entity.remove();
event.setCancelled(true);
}
}
}
@ -165,7 +162,7 @@ public class ProjectileEventListener implements Listener {
return;
}
if (plot.isAdded(pp.getUUID()) || Permissions
.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER) || plot.getFlag(ProjectilesFlag.class)) {
.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) {
return;
}
entity.remove();

View File

@ -37,10 +37,6 @@ dependencies {
// Logging
compileOnlyApi(libs.log4j)
// Records are cool. Builders are cooler
compileOnly(libs.recordBuilderProcessor)
annotationProcessor(libs.recordBuilderProcessor)
// Other libraries
api(libs.prtree)
api(libs.aopalliance)

View File

@ -1,8 +0,0 @@
package com.plotsquared.core.player;
public enum PlotRole {
OWNER,
HELPER,
TRUSTED,
DENIED,
}

View File

@ -290,14 +290,14 @@ public class Plot {
* @param area the plot's PlotArea
* @param merged an array giving merged plots
* @param timestamp when the plot was created
* @param temp value representing whatever DBManager needs it to. Do not touch tbh.
* @param temp value representing whatever DBManager needs to to. Do not touch tbh.
*/
public Plot(
@NonNull PlotId id,
UUID owner,
Set<UUID> trusted,
Set<UUID> members,
Set<UUID> denied,
HashSet<UUID> trusted,
HashSet<UUID> members,
HashSet<UUID> denied,
String alias,
BlockLoc position,
Collection<PlotFlag<?, ?>> flags,
@ -310,9 +310,9 @@ public class Plot {
this.area = area;
this.owner = owner;
this.settings = new PlotSettings();
this.members = new HashSet<>(members);
this.trusted = new HashSet<>(trusted);
this.denied = new HashSet<>(denied);
this.members = members;
this.trusted = trusted;
this.denied = denied;
this.settings.setAlias(alias);
this.settings.setPosition(position);
this.settings.setMerged(merged);
@ -321,7 +321,9 @@ public class Plot {
if (area != null) {
this.flagContainer.setParentContainer(area.getFlagContainer());
if (flags != null) {
flags.forEach(this.flagContainer::addFlag);
for (PlotFlag<?, ?> flag : flags) {
this.flagContainer.addFlag(flag);
}
}
}
PlotSquared.platform().injector().injectMembers(this);

View File

@ -1,56 +0,0 @@
package com.plotsquared.core.plot;
import com.plotsquared.core.repository.PlotRepository;
import com.plotsquared.core.repository.PlotRoleRepository;
import com.plotsquared.core.repository.PlotSettingsRepository;
import com.plotsquared.core.repository.dbo.PlotSettingsDBOBuilder;
import org.checkerframework.checker.nullness.qual.NonNull;
import javax.inject.Inject;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
public final class PlotService {
private static final String PLOT_SETTINGS_DEFAULT_POSITION = "default";
private final PlotRepository plotRepository;
private final PlotSettingsRepository plotSettingsRepository;
private final PlotRoleRepository plotRoleRepository;
@Inject
public PlotService(
final @NonNull PlotRepository plotRepository,
final @NonNull PlotSettingsRepository plotSettingsRepository,
final @NonNull PlotRoleRepository plotRoleRepository
) {
this.plotRepository = plotRepository;
this.plotSettingsRepository = plotSettingsRepository;
this.plotRoleRepository = plotRoleRepository;
}
/**
* Returns a list containing all the plots in the given {@code plotArea}.
*
* @param plotArea the area
* @return all plots in the area
*/
public @NonNull Collection<Plot> getPlotsInArea(final @NonNull PlotArea plotArea) {
return this.plotRepository.getPlotsInArea(plotArea.getId())
.map(plotDBO -> {
final var settings = this.plotSettingsRepository.findById(plotDBO)
.orElseGet(() -> PlotSettingsDBOBuilder.builder()
.plot(plotDBO)
.position(PLOT_SETTINGS_DEFAULT_POSITION)
.build()
);
return plotDBO.toPlot(
plotArea,
settings,
this.plotRoleRepository.findAllFor(plotDBO),
List.of()
);
}).collect(Collectors.toList());
}
}

View File

@ -93,7 +93,6 @@ import com.plotsquared.core.plot.flag.implementations.PlayerInteractFlag;
import com.plotsquared.core.plot.flag.implementations.PlotTitleFlag;
import com.plotsquared.core.plot.flag.implementations.PreventCreativeCopyFlag;
import com.plotsquared.core.plot.flag.implementations.PriceFlag;
import com.plotsquared.core.plot.flag.implementations.ProjectilesFlag;
import com.plotsquared.core.plot.flag.implementations.PveFlag;
import com.plotsquared.core.plot.flag.implementations.PvpFlag;
import com.plotsquared.core.plot.flag.implementations.RedstoneFlag;
@ -199,7 +198,6 @@ public final class GlobalFlagContainer extends FlagContainer {
this.addFlag(VehicleUseFlag.VEHICLE_USE_FALSE);
this.addFlag(VillagerInteractFlag.VILLAGER_INTERACT_FALSE);
this.addFlag(VineGrowFlag.VINE_GROW_TRUE);
this.addFlag(ProjectilesFlag.PROJECTILES_FALSE);
// Double flags
this.addFlag(PriceFlag.PRICE_NOT_BUYABLE);

View File

@ -1,46 +0,0 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2014 - 2022 IntellectualSites
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
import org.checkerframework.checker.nullness.qual.NonNull;
public class ProjectilesFlag extends BooleanFlag<ProjectilesFlag> {
public static final ProjectilesFlag PROJECTILES_TRUE = new ProjectilesFlag(true);
public static final ProjectilesFlag PROJECTILES_FALSE = new ProjectilesFlag(false);
private ProjectilesFlag(boolean value){
super(value, TranslatableCaption.of("flags.flag_description_projectiles"));
}
@Override
protected ProjectilesFlag flagOf(@NonNull final Boolean value) {
return value ? PROJECTILES_TRUE : PROJECTILES_FALSE;
}
}

View File

@ -1,21 +0,0 @@
package com.plotsquared.core.repository;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.repository.dbo.PlotDBO;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.stream.Stream;
/**
* {@link Repository} storing {@link PlotDBO plots} identified by their respective {@link PlotId}.
*/
public interface PlotRepository extends Repository<PlotDBO, Integer> {
/**
* Returns all plots in the given {@code area}.
*
* @param area the plot area
* @return a stream with all plots in the given area.
*/
@NonNull Stream<PlotDBO> getPlotsInArea(@NonNull String area);
}

View File

@ -1,12 +0,0 @@
package com.plotsquared.core.repository;
import com.plotsquared.core.repository.dbo.PlotDBO;
import com.plotsquared.core.repository.dbo.PlotRoleDBO;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.List;
public interface PlotRoleRepository extends Repository<PlotRoleDBO, PlotRoleDBO.Key> {
List<PlotRoleDBO> findAllFor(@NonNull PlotDBO plotDBO);
}

View File

@ -1,8 +0,0 @@
package com.plotsquared.core.repository;
import com.plotsquared.core.repository.dbo.PlotDBO;
import com.plotsquared.core.repository.dbo.PlotSettingsDBO;
public interface PlotSettingsRepository extends Repository<PlotSettingsDBO, PlotDBO> {
}

View File

@ -1,28 +0,0 @@
package com.plotsquared.core.repository;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Optional;
/**
* Generic object repository.
*
* @param <T> the type of object stored in the repository.
* @param <U> the type used to identify objects stored in the repository.
*/
public interface Repository<@NonNull T, @NonNull U> {
/**
* Saves the given object.
*
* @param object {@code the object}.
*/
void save(T object);
/**
* Finds the object by its {@code id}.
*
* @param id the id
*/
@NonNull Optional<T> findById(U id);
}

View File

@ -1,65 +0,0 @@
package com.plotsquared.core.repository.dbo;
import com.plotsquared.core.location.BlockLoc;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.flag.PlotFlag;
import io.soabase.recordbuilder.core.RecordBuilder;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.time.Instant;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
@RecordBuilder
public record PlotDBO(
@Nullable Integer id,
int plotIdX,
int plotIdZ,
@NonNull String world,
@NonNull UUID owner,
@NonNull Instant timestamp
) {
public @NonNull Plot toPlot(
final @NonNull PlotArea plotArea,
final @NonNull PlotSettingsDBO plotSettingsDBO,
final @NonNull Collection<PlotRoleDBO> plotRoles,
final @NonNull Collection<PlotFlag<?, ?>> flags
) {
final PlotId plotId = PlotId.of(this.plotIdX(), this.plotIdZ());
final int id = Objects.requireNonNull(id(), "id may not be null");
final Set<UUID> trusted = new HashSet<>();
final Set<UUID> members = new HashSet<>();
final Set<UUID> denied = new HashSet<>();
for (final PlotRoleDBO plotRole : plotRoles) {
switch (plotRole.plotRole()) {
case TRUSTED -> trusted.add(plotRole.userId());
case HELPER -> members.add(plotRole.userId());
case DENIED -> denied.add(plotRole.userId());
}
}
return new Plot(
plotId,
this.owner(),
Collections.unmodifiableSet(trusted),
Collections.unmodifiableSet(members),
Collections.unmodifiableSet(denied),
plotSettingsDBO.alias(),
BlockLoc.fromString(plotSettingsDBO.position()),
flags,
plotArea,
plotSettingsDBO.unwrapMerged(),
this.timestamp().toEpochMilli(),
id
);
}
}

View File

@ -1,22 +0,0 @@
package com.plotsquared.core.repository.dbo;
import com.plotsquared.core.player.PlotRole;
import io.soabase.recordbuilder.core.RecordBuilder;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.UUID;
@RecordBuilder
public record PlotRoleDBO(
@NonNull PlotDBO plot,
@NonNull UUID userId,
@NonNull PlotRole plotRole
) {
public @NonNull Key key() {
return new Key(this.plot(), this.userId());
}
public record Key(@NonNull PlotDBO plot, @NonNull UUID userId) {
}
}

View File

@ -1,29 +0,0 @@
package com.plotsquared.core.repository.dbo;
import io.soabase.recordbuilder.core.RecordBuilder;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@RecordBuilder
public record PlotSettingsDBO(
@NonNull PlotDBO plot,
@Nullable String alias,
Integer merged,
@NonNull String position
) {
/**
* Unwraps {@link #merged()} into an array indicating whether the plot is merged in
* any given cardinal direction. The indices of the array correspond to the ordinals of
* {@link com.plotsquared.core.location.Direction}.
*
* @return unwrapped merged status
*/
public boolean@NonNull [] unwrapMerged() {
final boolean[] merged = new boolean[4];
for (int i = 0; i < 4; i++) {
merged[3 - i] = (this.merged() & 1 << i) != 0;
}
return merged;
}
}

View File

@ -613,7 +613,6 @@
"flags.flag_description_lectern_read_book": "<gray>Prevent players taking books from lecterns.</gray>",
"flags.flag_description_prevent_creative_copy": "<gray>Prevents people from copying item NBT data in the plot unless they're added as members.</gray>",
"flags.flag_description_leaf_decay": "<gray>Set to `false` to prevent leaves from decaying.",
"flags.flag_description_projectiles": "<gray>Prevents guests from shooting projectiles on the plot when set to false.</gray>",
"flags.flag_error_boolean": "Flag value must be a boolean (true | false).",
"flags.flag_error_enum": "Must be one of: <list>",
"flags.flag_error_integer": "Flag value must be a whole positive number.",

View File

@ -1,68 +0,0 @@
create table if not exists ${prefix}plot(
id int(11) not null auto_increment,
plot_id_x int(11) not null,
plot_id_z int(11) not null,
world varchar(45) not null,
owner varchar(40) not null,
timestamp timestamp not null default current_timestamp,
primary key (id)
) engine=InnoDB default charset=utf8 auto_increment=0;
-- TODO: Migrating existing data to this table.
create table if not exists ${prefix}plot_role(
plot_id int(11) not null,
user_id varchar(45) not null,
role enum('helper', 'trusted', 'denied') not null,
foreign key (plot_id) references ${prefix}plot(id) on delete cascade,
primary key (plot_id, user_id)
) engine=InnoDB default charset=utf8 auto_increment=0;
create table if not exists ${prefix}plot_comments(
world varchar(45) not null,
comment varchar(45) not null,
inbox varchar(45) not null,
timestamp int(11) not null,
sender varchar(45) not null
) engine=InnoDB default charset=utf8 auto_increment=0;
-- TODO: Look into what to do with this one...
-- Most data is now found in flags.
create table if not exists ${prefix}plot_settings(
plot_plot_id int(11) not null,
biome varchar(45) default 'FOREST', -- Unused. Moved to flags.
rain int(1) default 0, -- Unused. Moved to flags.
custom_time tinyint(1) default 0, -- Unused. Moved to flags.
time int(11) default 8000, -- Unused. Moved to flags.
deny_entry tinyint(1) default 0, -- Unused. Moved to flags.
alias varchar(50) default null,
merged int(11) default null,
position varchar(50) not null default 'default',
foreign key (plot_plot_id) references ${prefix}plot(id) on delete cascade,
primary key (plot_plot_id)
) engine=InnoDB default charset=utf8;
-- TODO: Look into adding foreign keys to this.
create table if not exists ${prefix}plot_rating(
plot_plot_id int(11) not null,
rating int(2) not null,
player varchar(45) not null
) engine=InnoDB default charset=utf8;
-- TODO: Drop the key and make the player ID the key instead.
create table if not exists ${prefix}player_meta(
meta_id int(11) not null auto_increment,
uuid varchar(45) not null,
key varchar(32) not null,
value blob not null,
primary key (meta_id)
) engine=InnoDB default charset=utf8 auto_increment=0;
-- TODO: Drop the ID and make (plot_id, flag) the new primary key.
create table if not exists ${prefix}plot_flags(
id int(11) not null auto_increment primary key,
plot_id int(11) not null,
flag varchar(64),
value varchar(512),
foreign key (plot_id) references ${prefix}plot(id) on delete cascade,
unique (plot_id, flag)
) engine=InnoDB default charset=utf8 auto_increment=0;

View File

@ -18,7 +18,7 @@ plugins {
idea
}
version = "6.7.1-SNAPSHOT"
version = "6.6.4-SNAPSHOT"
allprojects {
group = "com.plotsquared"
@ -140,7 +140,7 @@ allprojects {
}
developer {
id.set("NotMyFault")
name.set("Alexander Brandes")
name.set("NotMyFault")
organization.set("IntellectualSites")
email.set("contact@notmyfault.dev")
}

View File

@ -8,7 +8,7 @@ guava = "31.0.1-jre" # Version set by Minecraft
paper = "1.18.1-R0.1-SNAPSHOT"
checker-qual = "3.22.0"
guice = "5.1.0"
spotbugs = "4.7.0"
spotbugs = "4.6.0"
snakeyaml = "1.30" # Version set by Bukkit
# Adventure & MiniMessage
@ -36,7 +36,6 @@ paperlib = "1.0.7"
squirrelid = "0.3.1"
serverlib = "2.3.1"
http4j = "1.3"
record-builder-processor = "33"
# Gradle plugins
shadow = "7.1.2"
@ -87,7 +86,6 @@ arkitektonika = { group = "com.intellectualsites.arkitektonika", name = "Arkitek
http4j = { group = "com.intellectualsites.http", name = "HTTP4J", version.ref = "http4j" }
paster = { group = "com.intellectualsites.paster", name = "Paster", version.ref = "paster" }
guava = { group = "com.google.guava", name = "guava", version.ref = "guava" }
recordBuilderProcessor = { group = "io.soabase.record-builder", name = "record-builder-processor", version.ref = "record-builder-processor" }
[plugins]
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }