mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-24 22:26:45 +01:00
Merge branch 'v5' into v6
# Conflicts: # Bukkit/build.gradle # Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java # Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java # Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java # Core/src/main/java/com/plotsquared/core/PlotPlatform.java # Core/src/main/java/com/plotsquared/core/PlotSquared.java # Core/src/main/java/com/plotsquared/core/generator/ClassicPlotManager.java # Core/src/main/java/com/plotsquared/core/util/EventDispatcher.java # Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java # build.gradle
This commit is contained in:
commit
3180d2ddf2
@ -14,6 +14,7 @@ repositories {
|
||||
maven { url = "https://ci.ender.zone/plugin/repository/everything/" }
|
||||
maven { url = "https://mvn.intellectualsites.com/content/repositories/snapshots" }
|
||||
maven { url = "https://repo.wea-ondara.net/repository/public/" }
|
||||
maven { url = "http://repo.mvdw-software.be/content/groups/public/" }
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
@ -43,6 +44,7 @@ dependencies {
|
||||
compile('com.sk89q:squirrelid:1.0.0-SNAPSHOT'){ transitive = false }
|
||||
// logging
|
||||
implementation('org.apache.logging.log4j:log4j-slf4j-impl:2.8.1')
|
||||
compile('be.maximvdw:MVdWPlaceholderAPI:3.1.1-SNAPSHOT'){ transitive = false }
|
||||
}
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
|
@ -27,7 +27,7 @@
|
||||
<dependency>
|
||||
<groupId>com.plotsquared</groupId>
|
||||
<artifactId>PlotSquared-Core</artifactId>
|
||||
<version>5.12.5</version>
|
||||
<version>5.13.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -90,6 +90,18 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>be.maximvdw</groupId>
|
||||
<artifactId>MVdWPlaceholderAPI</artifactId>
|
||||
<version>3.1.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>*</artifactId>
|
||||
<groupId>*</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
<artifactId>worldedit-core</artifactId>
|
||||
|
@ -36,15 +36,19 @@ import com.plotsquared.bukkit.inject.BackupModule;
|
||||
import com.plotsquared.bukkit.inject.BukkitModule;
|
||||
import com.plotsquared.bukkit.inject.PermissionModule;
|
||||
import com.plotsquared.bukkit.inject.WorldManagerModule;
|
||||
import com.plotsquared.bukkit.listener.BlockEventListener;
|
||||
import com.plotsquared.bukkit.listener.ChunkListener;
|
||||
import com.plotsquared.bukkit.listener.EntityEventListener;
|
||||
import com.plotsquared.bukkit.listener.EntitySpawnListener;
|
||||
import com.plotsquared.bukkit.listener.PaperListener;
|
||||
import com.plotsquared.bukkit.listener.PlayerEvents;
|
||||
import com.plotsquared.bukkit.listener.PlayerEventListener;
|
||||
import com.plotsquared.bukkit.listener.ProjectileEventListener;
|
||||
import com.plotsquared.bukkit.listener.ServerListener;
|
||||
import com.plotsquared.bukkit.listener.SingleWorldListener;
|
||||
import com.plotsquared.bukkit.listener.WorldEvents;
|
||||
import com.plotsquared.bukkit.placeholder.PlaceholderFormatter;
|
||||
import com.plotsquared.bukkit.placeholder.Placeholders;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||
import com.plotsquared.bukkit.placeholder.PAPIPlaceholders;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayerManager;
|
||||
import com.plotsquared.bukkit.util.BukkitChatManager;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
@ -314,7 +318,11 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
}
|
||||
|
||||
if (Settings.Enabled_Components.EVENTS) {
|
||||
getServer().getPluginManager().registerEvents(getInjector().getInstance(PlayerEvents.class), this);
|
||||
getServer().getPluginManager().registerEvents(getInjector().getInstance(PlayerEventListener.class), this);
|
||||
getServer().getPluginManager().registerEvents(getInjector().getInstance(BlockEventListener.class), this);
|
||||
getServer().getPluginManager().registerEvents(getInjector().getInstance(EntityEventListener.class), this);
|
||||
getServer().getPluginManager().registerEvents(getInjector().getInstance(ProjectileEventListener.class), this);
|
||||
getServer().getPluginManager().registerEvents(getInjector().getInstance(ServerListener.class), this);
|
||||
getServer().getPluginManager().registerEvents(getInjector().getInstance(EntitySpawnListener.class), this);
|
||||
if (PaperLib.isPaper() && Settings.Paper_Components.PAPER_LISTENERS) {
|
||||
getServer().getPluginManager().registerEvents(getInjector().getInstance(PaperListener.class), this);
|
||||
@ -502,7 +510,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||
}
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
injector.getInstance(Placeholders.class).register();
|
||||
injector.getInstance(PAPIPlaceholders.class).register();
|
||||
if (Settings.Enabled_Components.EXTERNAL_PLACEHOLDERS) {
|
||||
ChatFormatter.formatters.add(getInjector().getInstance(PlaceholderFormatter.class));
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,340 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.plotsquared.bukkit.util.BukkitEntityUtil;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.flag.implementations.DisablePhysicsFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.ExplosionFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.InvincibleFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.MobPlaceFlag;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.FallingBlock;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.event.entity.EntityCombustByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||
import org.bukkit.event.vehicle.VehicleCreateEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class EntityEventListener implements Listener {
|
||||
|
||||
private float lastRadius;
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
|
||||
EntityDamageByEntityEvent eventChange =
|
||||
new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(),
|
||||
EntityDamageEvent.DamageCause.FIRE_TICK, event.getDuration());
|
||||
onEntityDamageByEntityEvent(eventChange);
|
||||
if (eventChange.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
|
||||
Entity damager = event.getDamager();
|
||||
Location location = BukkitUtil.getLocation(damager);
|
||||
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||
return;
|
||||
}
|
||||
Entity victim = event.getEntity();
|
||||
/*
|
||||
if (victim.getType().equals(EntityType.ITEM_FRAME)) {
|
||||
Plot plot = BukkitUtil.getLocation(victim).getPlot();
|
||||
if (plot != null && !plot.isAdded(damager.getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
*/
|
||||
if (!BukkitEntityUtil.entityDamage(damager, victim, event.getCause())) {
|
||||
if (event.isCancelled()) {
|
||||
if (victim instanceof Ageable) {
|
||||
Ageable ageable = (Ageable) victim;
|
||||
if (ageable.getAge() == -24000) {
|
||||
ageable.setAge(0);
|
||||
ageable.setAdult();
|
||||
}
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void creatureSpawnEvent(CreatureSpawnEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
Location location = BukkitUtil.getLocation(entity.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
CreatureSpawnEvent.SpawnReason reason = event.getSpawnReason();
|
||||
switch (reason.toString()) {
|
||||
case "DISPENSE_EGG":
|
||||
case "EGG":
|
||||
case "OCELOT_BABY":
|
||||
case "SPAWNER_EGG":
|
||||
if (!area.isSpawnEggs()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "REINFORCEMENTS":
|
||||
case "NATURAL":
|
||||
case "MOUNT":
|
||||
case "PATROL":
|
||||
case "RAID":
|
||||
case "SHEARED":
|
||||
case "SHOULDER_ENTITY":
|
||||
case "SILVERFISH_BLOCK":
|
||||
case "TRAP":
|
||||
case "VILLAGE_DEFENSE":
|
||||
case "VILLAGE_INVASION":
|
||||
case "BEEHIVE":
|
||||
case "CHUNK_GEN":
|
||||
if (!area.isMobSpawning()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
case "BREEDING":
|
||||
if (!area.isSpawnBreeding()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "BUILD_IRONGOLEM":
|
||||
case "BUILD_SNOWMAN":
|
||||
case "BUILD_WITHER":
|
||||
case "CUSTOM":
|
||||
if (!area.isSpawnCustom() && entity.getType() != EntityType.ARMOR_STAND) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "SPAWNER":
|
||||
if (!area.isMobSpawnerSpawning()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
Plot plot = area.getOwnedPlotAbs(location);
|
||||
if (plot == null) {
|
||||
if (!area.isMobSpawning()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (BukkitEntityUtil.checkEntity(entity, plot)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onEntityFall(EntityChangeBlockEvent event) {
|
||||
if (event.getEntityType() != EntityType.FALLING_BLOCK) {
|
||||
return;
|
||||
}
|
||||
Block block = event.getBlock();
|
||||
World world = block.getWorld();
|
||||
String worldName = world.getName();
|
||||
if (!PlotSquared.get().hasPlotArea(worldName)) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getOwnedPlotAbs(location);
|
||||
if (plot == null || plot.getFlag(DisablePhysicsFlag.class)) {
|
||||
event.setCancelled(true);
|
||||
if (plot != null) {
|
||||
plot.debug("Falling block event was cancelled because disable-physics = true");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (event.getTo().hasGravity()) {
|
||||
Entity entity = event.getEntity();
|
||||
List<MetadataValue> meta = entity.getMetadata("plot");
|
||||
if (meta.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Plot origin = (Plot) meta.get(0).value();
|
||||
if (origin != null && !origin.equals(plot)) {
|
||||
event.setCancelled(true);
|
||||
entity.remove();
|
||||
}
|
||||
} else if (event.getTo() == Material.AIR) {
|
||||
event.getEntity()
|
||||
.setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH) public void onDamage(EntityDamageEvent event) {
|
||||
if (event.getEntityType() != EntityType.PLAYER) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.getLocation(event.getEntity());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot == null) {
|
||||
if (area.isRoadFlags() && area.getRoadFlag(InvincibleFlag.class)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (plot.getFlag(InvincibleFlag.class)) {
|
||||
plot.debug(
|
||||
event.getEntity().getName() + " could not take damage because invincible = true");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBigBoom(EntityExplodeEvent event) {
|
||||
Location location = BukkitUtil.getLocation(event.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
boolean plotArea = location.isPlotArea();
|
||||
if (!plotArea) {
|
||||
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getOwnedPlot(location);
|
||||
if (plot != null) {
|
||||
if (plot.getFlag(ExplosionFlag.class)) {
|
||||
List<MetadataValue> meta = event.getEntity().getMetadata("plot");
|
||||
Plot origin;
|
||||
if (meta.isEmpty()) {
|
||||
origin = plot;
|
||||
} else {
|
||||
origin = (Plot) meta.get(0).value();
|
||||
}
|
||||
if (this.lastRadius != 0) {
|
||||
List<Entity> nearby = event.getEntity()
|
||||
.getNearbyEntities(this.lastRadius, this.lastRadius, this.lastRadius);
|
||||
for (Entity near : nearby) {
|
||||
if (near instanceof TNTPrimed || near.getType()
|
||||
.equals(EntityType.MINECART_TNT)) {
|
||||
if (!near.hasMetadata("plot")) {
|
||||
near.setMetadata("plot",
|
||||
new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot));
|
||||
}
|
||||
}
|
||||
}
|
||||
this.lastRadius = 0;
|
||||
}
|
||||
Iterator<Block> iterator = event.blockList().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Block block = iterator.next();
|
||||
location = BukkitUtil.getLocation(block.getLocation());
|
||||
if (!area.contains(location.getX(), location.getZ()) || (origin != null
|
||||
&& !origin.equals(area.getOwnedPlot(location)))) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
plot.debug("Explosion was cancelled because explosion = false");
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPeskyMobsChangeTheWorldLikeWTFEvent(EntityChangeBlockEvent event) {
|
||||
Entity e = event.getEntity();
|
||||
if (!(e instanceof FallingBlock)) {
|
||||
Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area != null) {
|
||||
Plot plot = area.getOwnedPlot(location);
|
||||
if (plot != null && plot.getFlag(MobPlaceFlag.class)) {
|
||||
return;
|
||||
}
|
||||
if (plot != null) {
|
||||
plot.debug(e.getType() + " could not change block because mob-place = false");
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler public void onPrime(ExplosionPrimeEvent event) {
|
||||
this.lastRadius = event.getRadius() + 1;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onVehicleCreate(VehicleCreateEvent event) {
|
||||
Vehicle entity = event.getVehicle();
|
||||
Location location = BukkitUtil.getLocation(entity);
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getOwnedPlotAbs(location);
|
||||
if (plot == null || BukkitEntityUtil.checkEntity(entity, plot)) {
|
||||
entity.remove();
|
||||
return;
|
||||
}
|
||||
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
||||
entity
|
||||
.setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot));
|
||||
}
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@
|
||||
*/
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.plotsquared.bukkit.util.BukkitEntityUtil;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
@ -155,7 +156,7 @@ public class EntitySpawnListener implements Listener {
|
||||
}
|
||||
switch (entity.getType()) {
|
||||
case ENDER_CRYSTAL:
|
||||
if (PlayerEvents.checkEntity(entity, plot)) {
|
||||
if (BukkitEntityUtil.checkEntity(entity, plot)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
case SHULKER:
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,156 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.plotsquared.bukkit.util.BukkitEntityUtil;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.location.Location;
|
||||
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.util.Permissions;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.entity.ThrownPotion;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.LingeringPotionSplashEvent;
|
||||
import org.bukkit.event.entity.PotionSplashEvent;
|
||||
import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||
import org.bukkit.projectiles.BlockProjectileSource;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class ProjectileEventListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPotionSplash(LingeringPotionSplashEvent event) {
|
||||
Projectile entity = event.getEntity();
|
||||
Location location = BukkitUtil.getLocation(entity);
|
||||
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||
return;
|
||||
}
|
||||
if (!this.onProjectileHit(event)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPotionSplash(PotionSplashEvent event) {
|
||||
ThrownPotion damager = event.getPotion();
|
||||
Location location = BukkitUtil.getLocation(damager);
|
||||
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||
return;
|
||||
}
|
||||
int count = 0;
|
||||
for (LivingEntity victim : event.getAffectedEntities()) {
|
||||
if (!BukkitEntityUtil.entityDamage(damager, victim)) {
|
||||
event.setIntensity(victim, 0);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if ((count > 0 && count == event.getAffectedEntities().size()) || !onProjectileHit(event)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler public void onProjectileLaunch(ProjectileLaunchEvent event) {
|
||||
Projectile entity = event.getEntity();
|
||||
if (!(entity instanceof ThrownPotion)) {
|
||||
return;
|
||||
}
|
||||
ProjectileSource shooter = entity.getShooter();
|
||||
if (!(shooter instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Location location = BukkitUtil.getLocation(entity);
|
||||
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||
return;
|
||||
}
|
||||
PlotPlayer<Player> pp = BukkitUtil.getPlayer((Player) shooter);
|
||||
Plot plot = location.getOwnedPlot();
|
||||
if (plot != null && !plot.isAdded(pp.getUUID())) {
|
||||
entity.remove();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"BooleanMethodIsAlwaysInverted", "cos it's not... dum IntelliJ"}) @EventHandler
|
||||
public boolean onProjectileHit(ProjectileHitEvent event) {
|
||||
Projectile entity = event.getEntity();
|
||||
Location location = BukkitUtil.getLocation(entity);
|
||||
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
|
||||
return true;
|
||||
}
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
return true;
|
||||
}
|
||||
Plot plot = area.getPlot(location);
|
||||
ProjectileSource shooter = entity.getShooter();
|
||||
if (shooter instanceof Player) {
|
||||
PlotPlayer<?> pp = BukkitUtil.getPlayer((Player) shooter);
|
||||
if (plot == null) {
|
||||
if (!Permissions.hasPermission(pp, Captions.PERMISSION_PROJECTILE_UNOWNED)) {
|
||||
entity.remove();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (plot.isAdded(pp.getUUID()) || Permissions
|
||||
.hasPermission(pp, Captions.PERMISSION_PROJECTILE_OTHER)) {
|
||||
return true;
|
||||
}
|
||||
entity.remove();
|
||||
return false;
|
||||
}
|
||||
if (!(shooter instanceof Entity) && shooter != null) {
|
||||
if (plot == null) {
|
||||
entity.remove();
|
||||
return false;
|
||||
}
|
||||
Location sLoc =
|
||||
BukkitUtil.getLocation(((BlockProjectileSource) shooter).getBlock().getLocation());
|
||||
if (!area.contains(sLoc.getX(), sLoc.getZ())) {
|
||||
entity.remove();
|
||||
return false;
|
||||
}
|
||||
Plot sPlot = area.getOwnedPlotAbs(sLoc);
|
||||
if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) {
|
||||
entity.remove();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.listener;
|
||||
|
||||
import com.plotsquared.bukkit.BukkitPlatform;
|
||||
import com.plotsquared.bukkit.placeholder.MVdWPlaceholders;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.ServerLoadEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ServerListener implements Listener {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + ServerListener.class.getSimpleName());
|
||||
|
||||
private final BukkitPlatform plugin;
|
||||
|
||||
public ServerListener(BukkitPlatform plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler public void onServerLoad(ServerLoadEvent event) {
|
||||
if (Bukkit.getPluginManager().getPlugin("MVdWPlaceholderAPI") != null) {
|
||||
new MVdWPlaceholders(this.plugin, PlotSquared.get().getPlaceholderRegistry());
|
||||
logger.info(Captions.PREFIX + "&6PlotSquared hooked into MVdWPlaceholderAPI");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.placeholder;
|
||||
|
||||
import be.maximvdw.placeholderapi.PlaceholderAPI;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.util.placeholders.Placeholder;
|
||||
import com.plotsquared.core.util.placeholders.PlaceholderRegistry;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Placeholder support for MVdWPlaceholderAPI
|
||||
*/
|
||||
public class MVdWPlaceholders {
|
||||
|
||||
private static final String PREFIX = "plotsquared_";
|
||||
private final Plugin plugin;
|
||||
private final PlaceholderRegistry registry;
|
||||
|
||||
public MVdWPlaceholders(@NotNull final Plugin plugin,
|
||||
@NotNull final PlaceholderRegistry registry) {
|
||||
this.plugin = plugin;
|
||||
this.registry = registry;
|
||||
for (final Placeholder placeholder : registry.getPlaceholders()) {
|
||||
this.addPlaceholder(placeholder);
|
||||
}
|
||||
PlotSquared.get().getEventDispatcher().registerListener(this);
|
||||
}
|
||||
|
||||
@Subscribe public void onNewPlaceholder(@NotNull final
|
||||
PlaceholderRegistry.PlaceholderAddedEvent event) {
|
||||
this.addPlaceholder(event.getPlaceholder());
|
||||
}
|
||||
|
||||
private void addPlaceholder(@NotNull final Placeholder placeholder) {
|
||||
PlaceholderAPI.registerPlaceholder(plugin, PREFIX + String.format("%s", placeholder.getKey()),
|
||||
placeholderReplaceEvent -> {
|
||||
if (!placeholderReplaceEvent.isOnline() || placeholderReplaceEvent.getPlayer() == null) {
|
||||
return "";
|
||||
}
|
||||
final PlotPlayer<Player> player = BukkitUtil.getPlayer(placeholderReplaceEvent.getPlayer());
|
||||
if (player == null) {
|
||||
return "";
|
||||
}
|
||||
String key = placeholderReplaceEvent.getPlaceholder().substring(PREFIX.length());
|
||||
return registry.getPlaceholderValue(key, player);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.placeholder;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PAPIPlaceholders extends PlaceholderExpansion {
|
||||
|
||||
public PAPIPlaceholders() {
|
||||
}
|
||||
|
||||
@Override public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public boolean canRegister() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public String getAuthor() {
|
||||
return "IntellectualSites";
|
||||
}
|
||||
|
||||
@Override public String getIdentifier() {
|
||||
return "plotsquared";
|
||||
}
|
||||
|
||||
@Override public String getVersion() {
|
||||
return "3";
|
||||
}
|
||||
|
||||
@Override public String onPlaceholderRequest(Player p, String identifier) {
|
||||
final PlotPlayer<?> pl = PlotSquared.imp().getPlayerManager().getPlayerIfExists(p.getUniqueId());
|
||||
|
||||
if (pl == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// PAPI specific ones that don't translate well over into other placeholder APIs
|
||||
if (identifier.startsWith("has_plot_")) {
|
||||
identifier = identifier.substring("has_plot_".length());
|
||||
if (identifier.isEmpty())
|
||||
return "";
|
||||
|
||||
return pl.getPlotCount(identifier) > 0 ?
|
||||
PlaceholderAPIPlugin.booleanTrue() :
|
||||
PlaceholderAPIPlugin.booleanFalse();
|
||||
}
|
||||
|
||||
if (identifier.startsWith("plot_count_")) {
|
||||
identifier = identifier.substring("plot_count_".length());
|
||||
if (identifier.isEmpty())
|
||||
return "";
|
||||
|
||||
return String.valueOf(pl.getPlotCount(identifier));
|
||||
}
|
||||
|
||||
// PlotSquared placeholders
|
||||
return PlotSquared.get().getPlaceholderRegistry().getPlaceholderValue(identifier, pl);
|
||||
}
|
||||
|
||||
}
|
@ -1,213 +0,0 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.placeholder;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.flag.GlobalFlagContainer;
|
||||
import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Placeholders extends PlaceholderExpansion {
|
||||
|
||||
public Placeholders() {
|
||||
}
|
||||
|
||||
@Override public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public boolean canRegister() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public String getAuthor() {
|
||||
return "NotMyFault";
|
||||
}
|
||||
|
||||
@Override public String getIdentifier() {
|
||||
return "plotsquared";
|
||||
}
|
||||
|
||||
@Override public String getVersion() {
|
||||
return "2.5";
|
||||
}
|
||||
|
||||
@Override public String onPlaceholderRequest(Player p, String identifier) {
|
||||
final PlotPlayer pl = PlotSquared.platform().getPlayerManager().getPlayerIfExists(p.getUniqueId());
|
||||
|
||||
if (pl == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (identifier.startsWith("has_plot_")) {
|
||||
identifier = identifier.substring("has_plot_".length());
|
||||
if (identifier.isEmpty())
|
||||
return "";
|
||||
|
||||
return pl.getPlotCount(identifier) > 0 ?
|
||||
PlaceholderAPIPlugin.booleanTrue() :
|
||||
PlaceholderAPIPlugin.booleanFalse();
|
||||
}
|
||||
|
||||
if (identifier.startsWith("plot_count_")) {
|
||||
identifier = identifier.substring("plot_count_".length());
|
||||
if (identifier.isEmpty())
|
||||
return "";
|
||||
|
||||
return String.valueOf(pl.getPlotCount(identifier));
|
||||
}
|
||||
|
||||
switch (identifier) {
|
||||
case "currentplot_world": {
|
||||
return p.getWorld().getName();
|
||||
}
|
||||
case "has_plot": {
|
||||
return (pl.getPlotCount() > 0) ?
|
||||
PlaceholderAPIPlugin.booleanTrue() :
|
||||
PlaceholderAPIPlugin.booleanFalse();
|
||||
}
|
||||
case "allowed_plot_count": {
|
||||
return String.valueOf(pl.getAllowedPlots());
|
||||
}
|
||||
case "plot_count": {
|
||||
return String.valueOf(pl.getPlotCount());
|
||||
}
|
||||
}
|
||||
|
||||
Plot plot = pl.getCurrentPlot();
|
||||
|
||||
if (plot == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
switch (identifier) {
|
||||
case "currentplot_alias": {
|
||||
return plot.getAlias();
|
||||
}
|
||||
case "currentplot_owner": {
|
||||
final UUID plotOwner = plot.getOwnerAbs();
|
||||
if (plotOwner == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
try {
|
||||
return PlayerManager.getName(plotOwner, false);
|
||||
} catch (final Exception ignored) {}
|
||||
|
||||
final String name = Bukkit.getOfflinePlayer(plotOwner).getName();
|
||||
return name != null ? name : "unknown";
|
||||
}
|
||||
case "currentplot_members": {
|
||||
if (plot.getMembers() == null && plot.getTrusted() == null) {
|
||||
return "0";
|
||||
}
|
||||
return String.valueOf(plot.getMembers().size() + plot.getTrusted().size());
|
||||
}
|
||||
case "currentplot_members_added": {
|
||||
if (plot.getMembers() == null) {
|
||||
return "0";
|
||||
}
|
||||
return String.valueOf(plot.getMembers().size());
|
||||
}
|
||||
case "currentplot_members_trusted": {
|
||||
if (plot.getTrusted() == null) {
|
||||
return "0";
|
||||
}
|
||||
return String.valueOf(plot.getTrusted().size());
|
||||
}
|
||||
case "currentplot_members_denied": {
|
||||
if (plot.getDenied() == null) {
|
||||
return "0";
|
||||
}
|
||||
return String.valueOf(plot.getDenied().size());
|
||||
}
|
||||
case "has_build_rights": {
|
||||
return plot.isAdded(pl.getUUID()) ?
|
||||
PlaceholderAPIPlugin.booleanTrue() :
|
||||
PlaceholderAPIPlugin.booleanFalse();
|
||||
}
|
||||
case "currentplot_x": {
|
||||
return String.valueOf(plot.getId().getX());
|
||||
}
|
||||
case "currentplot_y": {
|
||||
return String.valueOf(plot.getId().getY());
|
||||
}
|
||||
case "currentplot_xy": {
|
||||
return plot.getId().getX() + ";" + plot.getId().getY();
|
||||
}
|
||||
case "currentplot_rating": {
|
||||
return String.valueOf(plot.getAverageRating());
|
||||
}
|
||||
case "currentplot_biome": {
|
||||
return plot.getBiomeSynchronous() + "";
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (identifier.startsWith("currentplot_localflag_")) {
|
||||
return getFlagValue(plot, identifier.substring("currentplot_localflag_".length()),
|
||||
false);
|
||||
}
|
||||
if (identifier.startsWith("currentplot_flag_")) {
|
||||
return getFlagValue(plot, identifier.substring("currentplot_flag_".length()), true);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the flag value from its name on the current plot.
|
||||
* If the flag doesn't exist it returns an empty string.
|
||||
* If the flag exists but it is not set on current plot and the parameter inherit is set to true,
|
||||
* it returns the default value.
|
||||
*
|
||||
* @param plot Current plot where the player is
|
||||
* @param flagName Name of flag to get from current plot
|
||||
* @param inherit Define if it returns only the flag set on currentplot or also inherited flag
|
||||
* @return The value of flag serialized in string
|
||||
*/
|
||||
private String getFlagValue(final Plot plot, final String flagName, final boolean inherit) {
|
||||
if (flagName.isEmpty())
|
||||
return "";
|
||||
final PlotFlag<?, ?> flag = GlobalFlagContainer.getInstance().getFlagFromString(flagName);
|
||||
if (flag == null)
|
||||
return "";
|
||||
|
||||
if (inherit) {
|
||||
return plot.getFlag(flag).toString();
|
||||
} else {
|
||||
final PlotFlag<?, ?> plotFlag = plot.getFlagContainer().queryLocal(flag.getClass());
|
||||
return (plotFlag != null) ? plotFlag.getValue().toString() : "";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,363 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.util;
|
||||
|
||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.flag.implementations.AnimalAttackFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.AnimalCapFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.EntityCapFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.HangingBreakFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.HostileAttackFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.HostileCapFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.MiscBreakFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.MiscCapFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.MobCapFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.PveFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.PvpFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.TamedAttackFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.VehicleCapFlag;
|
||||
import com.plotsquared.core.util.EntityUtil;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.entity.EntityCategories;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.projectiles.BlockProjectileSource;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class BukkitEntityUtil {
|
||||
|
||||
public static final com.sk89q.worldedit.world.entity.EntityType FAKE_ENTITY_TYPE =
|
||||
new com.sk89q.worldedit.world.entity.EntityType("plotsquared:fake");
|
||||
|
||||
public static boolean entityDamage(Entity damager, Entity victim) {
|
||||
return entityDamage(damager, victim, null);
|
||||
}
|
||||
|
||||
public static boolean entityDamage(Entity damager, Entity victim,
|
||||
EntityDamageEvent.DamageCause cause) {
|
||||
Location dloc = BukkitUtil.getLocation(damager);
|
||||
Location vloc = BukkitUtil.getLocation(victim);
|
||||
PlotArea dArea = dloc.getPlotArea();
|
||||
PlotArea vArea;
|
||||
if (dArea != null && dArea.contains(vloc.getX(), vloc.getZ())) {
|
||||
vArea = dArea;
|
||||
} else {
|
||||
vArea = vloc.getPlotArea();
|
||||
}
|
||||
if (dArea == null && vArea == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Plot dplot;
|
||||
if (dArea != null) {
|
||||
dplot = dArea.getPlot(dloc);
|
||||
} else {
|
||||
dplot = null;
|
||||
}
|
||||
Plot vplot;
|
||||
if (vArea != null) {
|
||||
vplot = vArea.getPlot(vloc);
|
||||
} else {
|
||||
vplot = null;
|
||||
}
|
||||
|
||||
Plot plot;
|
||||
String stub;
|
||||
boolean isPlot = true;
|
||||
if (dplot == null && vplot == null) {
|
||||
if (dArea == null) {
|
||||
return true;
|
||||
}
|
||||
plot = null;
|
||||
stub = "road";
|
||||
isPlot = false;
|
||||
} else {
|
||||
// Prioritize plots for close to seamless pvp zones
|
||||
if (victim.getTicksLived() > damager.getTicksLived()) {
|
||||
if (dplot == null || !(victim instanceof Player)) {
|
||||
if (vplot == null) {
|
||||
plot = dplot;
|
||||
} else {
|
||||
plot = vplot;
|
||||
}
|
||||
} else {
|
||||
plot = dplot;
|
||||
}
|
||||
} else if (dplot == null || !(victim instanceof Player)) {
|
||||
if (vplot == null) {
|
||||
plot = dplot;
|
||||
} else {
|
||||
plot = vplot;
|
||||
}
|
||||
} else if (vplot == null) {
|
||||
plot = dplot;
|
||||
} else {
|
||||
plot = vplot;
|
||||
}
|
||||
if (plot.hasOwner()) {
|
||||
stub = "other";
|
||||
} else {
|
||||
stub = "unowned";
|
||||
}
|
||||
}
|
||||
boolean roadFlags = vArea != null ? vArea.isRoadFlags() : dArea.isRoadFlags();
|
||||
PlotArea area = vArea != null ? vArea : dArea;
|
||||
|
||||
Player player;
|
||||
if (damager instanceof Player) { // attacker is player
|
||||
player = (Player) damager;
|
||||
} else if (damager instanceof Projectile) {
|
||||
Projectile projectile = (Projectile) damager;
|
||||
ProjectileSource shooter = projectile.getShooter();
|
||||
if (shooter instanceof Player) { // shooter is player
|
||||
player = (Player) shooter;
|
||||
} else { // shooter is not player
|
||||
if (shooter instanceof BlockProjectileSource) {
|
||||
Location sLoc = BukkitUtil
|
||||
.getLocation(((BlockProjectileSource) shooter).getBlock().getLocation());
|
||||
dplot = dArea.getPlot(sLoc);
|
||||
}
|
||||
player = null;
|
||||
}
|
||||
} else { // Attacker is not player
|
||||
player = null;
|
||||
}
|
||||
if (player != null) {
|
||||
BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
|
||||
|
||||
final com.sk89q.worldedit.world.entity.EntityType entityType;
|
||||
|
||||
// Create a fake entity type if the type does not have a name
|
||||
if (victim.getType().getName() == null) {
|
||||
entityType = FAKE_ENTITY_TYPE;
|
||||
} else {
|
||||
entityType = BukkitAdapter.adapt(victim.getType());
|
||||
}
|
||||
|
||||
if (EntityCategories.HANGING.contains(entityType)) { // hanging
|
||||
if (plot != null && (plot.getFlag(HangingBreakFlag.class) || plot
|
||||
.isAdded(plotPlayer.getUUID()))) {
|
||||
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
|
||||
if (!Permissions
|
||||
.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
|
||||
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||
Captions.PERMISSION_ADMIN_BUILD_OTHER);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.destroy." + stub)) {
|
||||
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||
"plots.admin.destroy." + stub);
|
||||
return false;
|
||||
}
|
||||
} else if (victim.getType() == EntityType.ARMOR_STAND) {
|
||||
if (plot != null && (plot.getFlag(MiscBreakFlag.class) || plot
|
||||
.isAdded(plotPlayer.getUUID()))) {
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.destroy." + stub)) {
|
||||
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||
"plots.admin.destroy." + stub);
|
||||
if (plot != null) {
|
||||
plot.debug(player.getName()
|
||||
+ " could not break armor stand because misc-break = false");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else if (EntityCategories.HOSTILE.contains(entityType)) {
|
||||
if (isPlot) {
|
||||
if (plot.getFlag(HostileAttackFlag.class) || plot.getFlag(PveFlag.class) || plot
|
||||
.isAdded(plotPlayer.getUUID())) {
|
||||
return true;
|
||||
}
|
||||
} else if (roadFlags && (area.getRoadFlag(HostileAttackFlag.class) || area
|
||||
.getFlag(PveFlag.class))) {
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
||||
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||
"plots.admin.pve." + stub);
|
||||
if (plot != null) {
|
||||
plot.debug(player.getName() + " could not attack " + entityType
|
||||
+ " because pve = false OR hostile-attack = false");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else if (EntityCategories.TAMEABLE.contains(entityType)) { // victim is tameable
|
||||
if (isPlot) {
|
||||
if (plot.getFlag(TamedAttackFlag.class) || plot.getFlag(PveFlag.class) || plot
|
||||
.isAdded(plotPlayer.getUUID())) {
|
||||
return true;
|
||||
}
|
||||
} else if (roadFlags && (area.getRoadFlag(TamedAttackFlag.class) || area
|
||||
.getFlag(PveFlag.class))) {
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
||||
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||
"plots.admin.pve." + stub);
|
||||
if (plot != null) {
|
||||
plot.debug(player.getName() + " could not attack " + entityType
|
||||
+ " because pve = false OR tamned-attack = false");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else if (EntityCategories.PLAYER.contains(entityType)) {
|
||||
if (isPlot) {
|
||||
if (!plot.getFlag(PvpFlag.class) && !Permissions
|
||||
.hasPermission(plotPlayer, "plots.admin.pvp." + stub)) {
|
||||
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||
"plots.admin.pvp." + stub);
|
||||
plot.debug(player.getName() + " could not attack " + entityType
|
||||
+ " because pve = false");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else if (roadFlags && area.getRoadFlag(PvpFlag.class)) {
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pvp." + stub)) {
|
||||
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||
"plots.admin.pvp." + stub);
|
||||
return false;
|
||||
}
|
||||
} else if (EntityCategories.ANIMAL.contains(entityType)) { // victim is animal
|
||||
if (isPlot) {
|
||||
if (plot.getFlag(AnimalAttackFlag.class) || plot.getFlag(PveFlag.class) || plot
|
||||
.isAdded(plotPlayer.getUUID())) {
|
||||
plot.debug(player.getName() + " could not attack " + entityType
|
||||
+ " because pve = false OR animal-attack = false");
|
||||
return true;
|
||||
}
|
||||
} else if (roadFlags && (area.getRoadFlag(AnimalAttackFlag.class) || area
|
||||
.getFlag(PveFlag.class))) {
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
||||
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||
"plots.admin.pve." + stub);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (EntityCategories.VEHICLE
|
||||
.contains(entityType)) { // Vehicles are managed in vehicle destroy event
|
||||
return true;
|
||||
} else { // victim is something else
|
||||
if (isPlot) {
|
||||
if (plot.getFlag(PveFlag.class) || plot.isAdded(plotPlayer.getUUID())) {
|
||||
return true;
|
||||
}
|
||||
} else if (roadFlags && area.getRoadFlag(PveFlag.class)) {
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
|
||||
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
|
||||
"plots.admin.pve." + stub);
|
||||
if (plot != null) {
|
||||
plot.debug(player.getName() + " could not attack " + entityType
|
||||
+ " because pve = false");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if (dplot != null && (!dplot.equals(vplot) || Objects
|
||||
.equals(dplot.getOwnerAbs(), vplot.getOwnerAbs()))) {
|
||||
return vplot != null && vplot.getFlag(PveFlag.class);
|
||||
}
|
||||
//disable the firework damage. too much of a headache to support at the moment.
|
||||
if (vplot != null) {
|
||||
if (EntityDamageEvent.DamageCause.ENTITY_EXPLOSION == cause
|
||||
&& damager.getType() == EntityType.FIREWORK) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (vplot == null && roadFlags && area.getRoadFlag(PveFlag.class)) {
|
||||
return true;
|
||||
}
|
||||
return ((vplot != null && vplot.getFlag(PveFlag.class)) || !(damager instanceof Arrow
|
||||
&& !(victim instanceof Creature)));
|
||||
}
|
||||
|
||||
public static boolean checkEntity(Entity entity, Plot plot) {
|
||||
if (plot == null || !plot.hasOwner() || plot.getFlags().isEmpty() && plot.getArea()
|
||||
.getFlagContainer().getFlagMap().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final com.sk89q.worldedit.world.entity.EntityType entityType =
|
||||
BukkitAdapter.adapt(entity.getType());
|
||||
|
||||
if (EntityCategories.PLAYER.contains(entityType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (EntityCategories.PROJECTILE.contains(entityType) || EntityCategories.OTHER
|
||||
.contains(entityType) || EntityCategories.HANGING.contains(entityType)) {
|
||||
return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED,
|
||||
MiscCapFlag.MISC_CAP_UNLIMITED);
|
||||
}
|
||||
|
||||
// Has to go go before vehicle as horses are both
|
||||
// animals and vehicles
|
||||
if (EntityCategories.ANIMAL.contains(entityType) || EntityCategories.VILLAGER
|
||||
.contains(entityType) || EntityCategories.TAMEABLE.contains(entityType)) {
|
||||
return EntityUtil
|
||||
.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED, MobCapFlag.MOB_CAP_UNLIMITED,
|
||||
AnimalCapFlag.ANIMAL_CAP_UNLIMITED);
|
||||
}
|
||||
|
||||
if (EntityCategories.HOSTILE.contains(entityType)) {
|
||||
return EntityUtil
|
||||
.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED, MobCapFlag.MOB_CAP_UNLIMITED,
|
||||
HostileCapFlag.HOSTILE_CAP_UNLIMITED);
|
||||
}
|
||||
|
||||
if (EntityCategories.VEHICLE.contains(entityType)) {
|
||||
return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED,
|
||||
VehicleCapFlag.VEHICLE_CAP_UNLIMITED);
|
||||
}
|
||||
|
||||
return EntityUtil.checkEntity(plot, EntityCapFlag.ENTITY_CAP_UNLIMITED);
|
||||
}
|
||||
|
||||
}
|
@ -6,7 +6,7 @@ load: STARTUP
|
||||
description: "Easy, yet powerful Plot World generation and management."
|
||||
authors: [Citymonstret, Empire92, MattBDev, dordsor21, NotMyFault, SirYwell]
|
||||
website: https://www.spigotmc.org/resources/77506/
|
||||
softdepend: [Vault, PlaceholderAPI, Essentials, LuckPerms, BungeePerms]
|
||||
softdepend: [Vault, PlaceholderAPI, Essentials, LuckPerms, BungeePerms, MVdWPlaceholderAPI]
|
||||
loadbefore: [MultiWorld, Multiverse-Core]
|
||||
depend: [WorldEdit]
|
||||
database: false
|
||||
|
@ -56,6 +56,8 @@ import com.plotsquared.core.plot.PlotId;
|
||||
import com.plotsquared.core.plot.PlotManager;
|
||||
import com.plotsquared.core.plot.expiration.ExpireManager;
|
||||
import com.plotsquared.core.plot.expiration.ExpiryTask;
|
||||
import com.plotsquared.core.plot.flag.GlobalFlagContainer;
|
||||
import com.plotsquared.core.plot.world.DefaultPlotAreaManager;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.plot.world.SinglePlotArea;
|
||||
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
|
||||
@ -64,6 +66,13 @@ import com.plotsquared.core.util.FileUtils;
|
||||
import com.plotsquared.core.util.LegacyConverter;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.ReflectionUtils;
|
||||
import com.plotsquared.core.util.RegionManager;
|
||||
import com.plotsquared.core.util.SchematicHandler;
|
||||
import com.plotsquared.core.util.SetupUtils;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.logger.ILogger;
|
||||
import com.plotsquared.core.util.placeholders.PlaceholderRegistry;
|
||||
import com.plotsquared.core.util.query.PlotQuery;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.uuid.UUIDPipeline;
|
||||
@ -146,6 +155,7 @@ public class PlotSquared {
|
||||
private File storageFile;
|
||||
@Getter private EventDispatcher eventDispatcher;
|
||||
@Getter private PlotListener plotListener;
|
||||
@Getter private PlaceholderRegistry placeholderRegistry;
|
||||
|
||||
/**
|
||||
* Initialize PlotSquared with the desired Implementation class.
|
||||
@ -171,6 +181,9 @@ public class PlotSquared {
|
||||
//
|
||||
ConfigurationSerialization.registerClass(BlockBucket.class, "BlockBucket");
|
||||
|
||||
// Setup the global flag container
|
||||
GlobalFlagContainer.setup();
|
||||
|
||||
try {
|
||||
new ReflectionUtils(this.platform.getNMSPackage());
|
||||
try {
|
||||
|
@ -40,8 +40,8 @@ import com.plotsquared.core.util.RegionManager;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@ -53,16 +53,14 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
private final ClassicPlotWorld classicPlotWorld;
|
||||
private final RegionManager regionManager;
|
||||
|
||||
public ClassicPlotManager(@Nonnull final ClassicPlotWorld classicPlotWorld,
|
||||
@Nonnull final RegionManager regionManager) {
|
||||
public ClassicPlotManager(@Nonnull final ClassicPlotWorld classicPlotWorld, @Nonnull final RegionManager regionManager) {
|
||||
super(classicPlotWorld, regionManager);
|
||||
this.classicPlotWorld = classicPlotWorld;
|
||||
this.regionManager = regionManager;
|
||||
}
|
||||
|
||||
@Override public boolean setComponent(PlotId plotId, String component, Pattern blocks) {
|
||||
final Optional<ClassicPlotManagerComponent> componentOptional =
|
||||
ClassicPlotManagerComponent.fromString(component);
|
||||
final Optional<ClassicPlotManagerComponent> componentOptional = ClassicPlotManagerComponent.fromString(component);
|
||||
if (componentOptional.isPresent()) {
|
||||
switch (componentOptional.get()) {
|
||||
case FLOOR:
|
||||
@ -88,8 +86,8 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
|
||||
@Override public boolean unClaimPlot(Plot plot, Runnable whenDone) {
|
||||
setWallFilling(plot.getId(), classicPlotWorld.WALL_FILLING.toPattern());
|
||||
if (!classicPlotWorld.WALL_BLOCK.isAir() || !classicPlotWorld.WALL_BLOCK
|
||||
.equals(classicPlotWorld.CLAIMED_WALL_BLOCK)) {
|
||||
if (classicPlotWorld.PLACE_TOP_BLOCK && (!classicPlotWorld.WALL_BLOCK.isAir() || !classicPlotWorld.WALL_BLOCK
|
||||
.equals(classicPlotWorld.CLAIMED_WALL_BLOCK))) {
|
||||
setWall(plot.getId(), classicPlotWorld.WALL_BLOCK.toPattern());
|
||||
}
|
||||
return PlotSquared.platform().getGlobalBlockQueue().addEmptyTask(whenDone);
|
||||
@ -98,8 +96,8 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
public boolean setFloor(PlotId plotId, Pattern blocks) {
|
||||
Plot plot = classicPlotWorld.getPlotAbs(plotId);
|
||||
if (plot.isBasePlot()) {
|
||||
return this.regionManager.setCuboids(classicPlotWorld, plot.getRegions(), blocks,
|
||||
classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.PLOT_HEIGHT);
|
||||
return this.regionManager
|
||||
.setCuboids(classicPlotWorld, plot.getRegions(), blocks, classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.PLOT_HEIGHT);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -115,8 +113,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
public boolean setAir(PlotId plotId, Pattern blocks) {
|
||||
Plot plot = classicPlotWorld.getPlotAbs(plotId);
|
||||
if (plot.isBasePlot()) {
|
||||
return this.regionManager.setCuboids(classicPlotWorld, plot.getRegions(), blocks,
|
||||
classicPlotWorld.PLOT_HEIGHT + 1, getWorldHeight());
|
||||
return this.regionManager.setCuboids(classicPlotWorld, plot.getRegions(), blocks, classicPlotWorld.PLOT_HEIGHT + 1, getWorldHeight());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -124,8 +121,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
public boolean setMain(PlotId plotId, Pattern blocks) {
|
||||
Plot plot = classicPlotWorld.getPlotAbs(plotId);
|
||||
if (plot.isBasePlot()) {
|
||||
return this.regionManager.setCuboids(classicPlotWorld, plot.getRegions(), blocks, 1,
|
||||
classicPlotWorld.PLOT_HEIGHT - 1);
|
||||
return this.regionManager.setCuboids(classicPlotWorld, plot.getRegions(), blocks, 1, classicPlotWorld.PLOT_HEIGHT - 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -194,12 +190,8 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
}
|
||||
if (plot.isBasePlot()) {
|
||||
for (CuboidRegion region : plot.getRegions()) {
|
||||
Location pos1 =
|
||||
Location.at(classicPlotWorld.getWorldName(), region.getMinimumPoint().getX(),
|
||||
maxY, region.getMinimumPoint().getZ());
|
||||
Location pos2 =
|
||||
Location.at(classicPlotWorld.getWorldName(), region.getMaximumPoint().getX(),
|
||||
maxY, region.getMaximumPoint().getZ());
|
||||
Location pos1 = Location.at(classicPlotWorld.getWorldName(), region.getMinimumPoint().getX(), maxY, region.getMinimumPoint().getZ());
|
||||
Location pos2 = Location.at(classicPlotWorld.getWorldName(), region.getMaximumPoint().getX(), maxY, region.getMaximumPoint().getZ());
|
||||
queue.setCuboid(pos1, pos2, blocks);
|
||||
}
|
||||
}
|
||||
@ -217,9 +209,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
return true;
|
||||
}
|
||||
Plot plot = classicPlotWorld.getPlotAbs(plotId);
|
||||
Location bot = plot.getExtendedBottomAbs()
|
||||
.subtract(plot.getMerged(Direction.WEST) ? 0 : 1, 0,
|
||||
plot.getMerged(Direction.NORTH) ? 0 : 1);
|
||||
Location bot = plot.getExtendedBottomAbs().subtract(plot.getMerged(Direction.WEST) ? 0 : 1, 0, plot.getMerged(Direction.NORTH) ? 0 : 1);
|
||||
Location top = plot.getExtendedTopAbs().add(1, 0, 1);
|
||||
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
|
||||
if (!plot.getMerged(Direction.NORTH)) {
|
||||
@ -240,8 +230,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
}
|
||||
if (!plot.getMerged(Direction.SOUTH)) {
|
||||
int z = top.getZ();
|
||||
for (int x = bot.getX();
|
||||
x < top.getX() + (plot.getMerged(Direction.EAST) ? 0 : 1); x++) {
|
||||
for (int x = bot.getX(); x < top.getX() + (plot.getMerged(Direction.EAST) ? 0 : 1); x++) {
|
||||
for (int y = 1; y <= classicPlotWorld.WALL_HEIGHT; y++) {
|
||||
queue.setBlock(x, y, z, blocks);
|
||||
}
|
||||
@ -249,8 +238,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
}
|
||||
if (!plot.getMerged(Direction.EAST)) {
|
||||
int x = top.getX();
|
||||
for (int z = bot.getZ();
|
||||
z < top.getZ() + (plot.getMerged(Direction.SOUTH) ? 0 : 1); z++) {
|
||||
for (int z = bot.getZ(); z < top.getZ() + (plot.getMerged(Direction.SOUTH) ? 0 : 1); z++) {
|
||||
for (int y = 1; y <= classicPlotWorld.WALL_HEIGHT; y++) {
|
||||
queue.setBlock(x, y, z, blocks);
|
||||
}
|
||||
@ -270,9 +258,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
return true;
|
||||
}
|
||||
Plot plot = classicPlotWorld.getPlotAbs(plotId);
|
||||
Location bot = plot.getExtendedBottomAbs()
|
||||
.subtract(plot.getMerged(Direction.WEST) ? 0 : 1, 0,
|
||||
plot.getMerged(Direction.NORTH) ? 0 : 1);
|
||||
Location bot = plot.getExtendedBottomAbs().subtract(plot.getMerged(Direction.WEST) ? 0 : 1, 0, plot.getMerged(Direction.NORTH) ? 0 : 1);
|
||||
Location top = plot.getExtendedTopAbs().add(1, 0, 1);
|
||||
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
|
||||
int y = classicPlotWorld.WALL_HEIGHT + 1;
|
||||
@ -290,15 +276,13 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
}
|
||||
if (!plot.getMerged(Direction.SOUTH)) {
|
||||
int z = top.getZ();
|
||||
for (int x = bot.getX();
|
||||
x < top.getX() + (plot.getMerged(Direction.EAST) ? 0 : 1); x++) {
|
||||
for (int x = bot.getX(); x < top.getX() + (plot.getMerged(Direction.EAST) ? 0 : 1); x++) {
|
||||
queue.setBlock(x, y, z, blocks);
|
||||
}
|
||||
}
|
||||
if (!plot.getMerged(Direction.EAST)) {
|
||||
int x = top.getX();
|
||||
for (int z = bot.getZ();
|
||||
z < top.getZ() + (plot.getMerged(Direction.SOUTH) ? 0 : 1); z++) {
|
||||
for (int z = bot.getZ(); z < top.getZ() + (plot.getMerged(Direction.SOUTH) ? 0 : 1); z++) {
|
||||
queue.setBlock(x, y, z, blocks);
|
||||
}
|
||||
}
|
||||
@ -317,32 +301,26 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
int ez = pos2.getZ() + 2;
|
||||
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
|
||||
int maxY = getWorldHeight();
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx,
|
||||
Math.min(classicPlotWorld.WALL_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz + 1),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex, maxY, ez - 1),
|
||||
BlockTypes.AIR.getDefaultState());
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, 0, sz + 1),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex, 0, ez - 1),
|
||||
queue.setCuboid(
|
||||
Location.at(classicPlotWorld.getWorldName(), sx, Math.min(classicPlotWorld.WALL_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz + 1),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex, maxY, ez - 1), BlockTypes.AIR.getDefaultState());
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, 0, sz + 1), Location.at(classicPlotWorld.getWorldName(), ex, 0, ez - 1),
|
||||
BlockUtil.get((short) 7, (byte) 0));
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, 1, sz + 1),
|
||||
Location.at(classicPlotWorld.getWorldName(), sx, classicPlotWorld.WALL_HEIGHT, ez - 1),
|
||||
classicPlotWorld.WALL_FILLING.toPattern());
|
||||
queue.setCuboid(
|
||||
Location.at(classicPlotWorld.getWorldName(), sx, classicPlotWorld.WALL_HEIGHT + 1,
|
||||
sz + 1),
|
||||
Location.at(classicPlotWorld.getWorldName(), sx, classicPlotWorld.WALL_HEIGHT + 1,
|
||||
ez - 1), classicPlotWorld.WALL_BLOCK.toPattern());
|
||||
Location.at(classicPlotWorld.getWorldName(), sx, classicPlotWorld.WALL_HEIGHT, ez - 1), classicPlotWorld.WALL_FILLING.toPattern());
|
||||
|
||||
if (classicPlotWorld.PLACE_TOP_BLOCK) {
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, classicPlotWorld.WALL_HEIGHT + 1, sz + 1),
|
||||
Location.at(classicPlotWorld.getWorldName(), sx, classicPlotWorld.WALL_HEIGHT + 1, ez - 1), classicPlotWorld.WALL_BLOCK.toPattern());
|
||||
}
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), ex, 1, sz + 1),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.WALL_HEIGHT, ez - 1),
|
||||
classicPlotWorld.WALL_FILLING.toPattern());
|
||||
queue.setCuboid(
|
||||
Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.WALL_HEIGHT + 1,
|
||||
sz + 1),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.WALL_HEIGHT + 1,
|
||||
ez - 1), classicPlotWorld.WALL_BLOCK.toPattern());
|
||||
Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.WALL_HEIGHT, ez - 1), classicPlotWorld.WALL_FILLING.toPattern());
|
||||
if (classicPlotWorld.PLACE_TOP_BLOCK) {
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.WALL_HEIGHT + 1, sz + 1),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.WALL_HEIGHT + 1, ez - 1), classicPlotWorld.WALL_BLOCK.toPattern());
|
||||
}
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, 1, sz + 1),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.ROAD_HEIGHT,
|
||||
ez - 1), classicPlotWorld.ROAD_BLOCK.toPattern());
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.ROAD_HEIGHT, ez - 1), classicPlotWorld.ROAD_BLOCK.toPattern());
|
||||
return queue.enqueue();
|
||||
}
|
||||
|
||||
@ -354,33 +332,27 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
int sx = pos1.getX() - 2;
|
||||
int ex = pos2.getX() + 2;
|
||||
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1,
|
||||
Math.min(classicPlotWorld.WALL_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1,
|
||||
classicPlotWorld.getPlotManager().getWorldHeight(), ez),
|
||||
queue.setCuboid(
|
||||
Location.at(classicPlotWorld.getWorldName(), sx + 1, Math.min(classicPlotWorld.WALL_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.getPlotManager().getWorldHeight(), ez),
|
||||
BlockTypes.AIR.getDefaultState());
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, 0, sz),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, 0, ez),
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, 0, sz), Location.at(classicPlotWorld.getWorldName(), ex - 1, 0, ez),
|
||||
BlockUtil.get((short) 7, (byte) 0));
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, 1, sz),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.WALL_HEIGHT, sz),
|
||||
classicPlotWorld.WALL_FILLING.toPattern());
|
||||
queue.setCuboid(
|
||||
Location.at(classicPlotWorld.getWorldName(), sx + 1, classicPlotWorld.WALL_HEIGHT + 1,
|
||||
sz),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.WALL_HEIGHT + 1,
|
||||
sz), classicPlotWorld.WALL_BLOCK.toPattern());
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.WALL_HEIGHT, sz), classicPlotWorld.WALL_FILLING.toPattern());
|
||||
|
||||
if (classicPlotWorld.PLACE_TOP_BLOCK) {
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, classicPlotWorld.WALL_HEIGHT + 1, sz),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.WALL_HEIGHT + 1, sz), classicPlotWorld.WALL_BLOCK.toPattern());
|
||||
}
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, 1, ez),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.WALL_HEIGHT, ez),
|
||||
classicPlotWorld.WALL_FILLING.toPattern());
|
||||
queue.setCuboid(
|
||||
Location.at(classicPlotWorld.getWorldName(), sx + 1, classicPlotWorld.WALL_HEIGHT + 1,
|
||||
ez),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.WALL_HEIGHT + 1,
|
||||
ez), classicPlotWorld.WALL_BLOCK.toPattern());
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.WALL_HEIGHT, ez), classicPlotWorld.WALL_FILLING.toPattern());
|
||||
if (classicPlotWorld.PLACE_TOP_BLOCK) {
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, classicPlotWorld.WALL_HEIGHT + 1, ez),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.WALL_HEIGHT + 1, ez), classicPlotWorld.WALL_BLOCK.toPattern());
|
||||
}
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, 1, sz + 1),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.ROAD_HEIGHT,
|
||||
ez - 1), classicPlotWorld.ROAD_BLOCK.toPattern());
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.ROAD_HEIGHT, ez - 1), classicPlotWorld.ROAD_BLOCK.toPattern());
|
||||
return queue.enqueue();
|
||||
}
|
||||
|
||||
@ -391,17 +363,13 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
int sz = pos2.getZ() + 1;
|
||||
int ez = sz + classicPlotWorld.ROAD_WIDTH - 1;
|
||||
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
|
||||
queue.setCuboid(
|
||||
Location.at(classicPlotWorld.getWorldName(), sx + 1, classicPlotWorld.ROAD_HEIGHT + 1,
|
||||
sz + 1), Location.at(classicPlotWorld.getWorldName(), ex - 1,
|
||||
classicPlotWorld.getPlotManager().getWorldHeight(), ez - 1),
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, classicPlotWorld.ROAD_HEIGHT + 1, sz + 1),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.getPlotManager().getWorldHeight(), ez - 1),
|
||||
BlockTypes.AIR.getDefaultState());
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, 0, sz + 1),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, 0, ez - 1),
|
||||
BlockUtil.get((short) 7, (byte) 0));
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, 0, ez - 1), BlockUtil.get((short) 7, (byte) 0));
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, 1, sz + 1),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.ROAD_HEIGHT,
|
||||
ez - 1), classicPlotWorld.ROAD_BLOCK.toPattern());
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.ROAD_HEIGHT, ez - 1), classicPlotWorld.ROAD_BLOCK.toPattern());
|
||||
return queue.enqueue();
|
||||
}
|
||||
|
||||
@ -413,18 +381,14 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
int sz = pos1.getZ() - 1;
|
||||
int ez = pos2.getZ() + 1;
|
||||
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx,
|
||||
Math.min(classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex,
|
||||
classicPlotWorld.getPlotManager().getWorldHeight(), ez),
|
||||
queue
|
||||
.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, Math.min(classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.getPlotManager().getWorldHeight(), ez),
|
||||
BlockTypes.AIR.getDefaultState());
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, 1, sz + 1),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.PLOT_HEIGHT - 1,
|
||||
ez - 1), classicPlotWorld.MAIN_BLOCK.toPattern());
|
||||
queue.setCuboid(
|
||||
Location.at(classicPlotWorld.getWorldName(), sx, classicPlotWorld.PLOT_HEIGHT, sz + 1),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.PLOT_HEIGHT, ez - 1),
|
||||
classicPlotWorld.TOP_BLOCK.toPattern());
|
||||
Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.PLOT_HEIGHT - 1, ez - 1), classicPlotWorld.MAIN_BLOCK.toPattern());
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, classicPlotWorld.PLOT_HEIGHT, sz + 1),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.PLOT_HEIGHT, ez - 1), classicPlotWorld.TOP_BLOCK.toPattern());
|
||||
return queue.enqueue();
|
||||
}
|
||||
|
||||
@ -436,18 +400,14 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
int sx = pos1.getX() - 1;
|
||||
int ex = pos2.getX() + 1;
|
||||
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx,
|
||||
Math.min(classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex,
|
||||
classicPlotWorld.getPlotManager().getWorldHeight(), ez),
|
||||
queue
|
||||
.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, Math.min(classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.getPlotManager().getWorldHeight(), ez),
|
||||
BlockTypes.AIR.getDefaultState());
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, 1, sz),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.PLOT_HEIGHT - 1,
|
||||
ez), classicPlotWorld.MAIN_BLOCK.toPattern());
|
||||
queue.setCuboid(
|
||||
Location.at(classicPlotWorld.getWorldName(), sx + 1, classicPlotWorld.PLOT_HEIGHT, sz),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.PLOT_HEIGHT, ez),
|
||||
classicPlotWorld.TOP_BLOCK.toPattern());
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.PLOT_HEIGHT - 1, ez), classicPlotWorld.MAIN_BLOCK.toPattern());
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx + 1, classicPlotWorld.PLOT_HEIGHT, sz),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex - 1, classicPlotWorld.PLOT_HEIGHT, ez), classicPlotWorld.TOP_BLOCK.toPattern());
|
||||
return queue.enqueue();
|
||||
}
|
||||
|
||||
@ -458,18 +418,14 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
int sz = location.getZ() + 1;
|
||||
int ez = sz + classicPlotWorld.ROAD_WIDTH - 1;
|
||||
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx,
|
||||
Math.min(classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex,
|
||||
classicPlotWorld.getPlotManager().getWorldHeight(), ez),
|
||||
queue
|
||||
.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, Math.min(classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.getPlotManager().getWorldHeight(), ez),
|
||||
BlockTypes.AIR.getDefaultState());
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, 1, sz),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.PLOT_HEIGHT - 1, ez),
|
||||
classicPlotWorld.MAIN_BLOCK.toPattern());
|
||||
queue.setCuboid(
|
||||
Location.at(classicPlotWorld.getWorldName(), sx, classicPlotWorld.PLOT_HEIGHT, sz),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.PLOT_HEIGHT, ez),
|
||||
classicPlotWorld.TOP_BLOCK.toPattern());
|
||||
Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.PLOT_HEIGHT - 1, ez), classicPlotWorld.MAIN_BLOCK.toPattern());
|
||||
queue.setCuboid(Location.at(classicPlotWorld.getWorldName(), sx, classicPlotWorld.PLOT_HEIGHT, sz),
|
||||
Location.at(classicPlotWorld.getWorldName(), ex, classicPlotWorld.PLOT_HEIGHT, ez), classicPlotWorld.TOP_BLOCK.toPattern());
|
||||
return queue.enqueue();
|
||||
}
|
||||
|
||||
@ -480,7 +436,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
*/
|
||||
@Override public boolean finishPlotMerge(List<PlotId> plotIds) {
|
||||
final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK;
|
||||
if (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK)) {
|
||||
if (classicPlotWorld.PLACE_TOP_BLOCK && (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK))) {
|
||||
for (PlotId plotId : plotIds) {
|
||||
setWall(plotId, claim.toPattern());
|
||||
}
|
||||
@ -496,7 +452,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
|
||||
@Override public boolean finishPlotUnlink(List<PlotId> plotIds) {
|
||||
final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK;
|
||||
if (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK)) {
|
||||
if (classicPlotWorld.PLACE_TOP_BLOCK && (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK))) {
|
||||
for (PlotId id : plotIds) {
|
||||
setWall(id, claim.toPattern());
|
||||
}
|
||||
@ -514,7 +470,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
|
||||
@Override public boolean claimPlot(Plot plot) {
|
||||
final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK;
|
||||
if (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK)) {
|
||||
if (classicPlotWorld.PLACE_TOP_BLOCK && (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK))) {
|
||||
return setWall(plot.getId(), claim.toPattern());
|
||||
}
|
||||
return true;
|
||||
@ -533,8 +489,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
@Override public Location getSignLoc(Plot plot) {
|
||||
plot = plot.getBasePlot(false);
|
||||
final Location bot = plot.getBottomAbs();
|
||||
return Location.at(classicPlotWorld.getWorldName(), bot.getX() - 1,
|
||||
classicPlotWorld.ROAD_HEIGHT + 1, bot.getZ() - 2);
|
||||
return Location.at(classicPlotWorld.getWorldName(), bot.getX() - 1, classicPlotWorld.ROAD_HEIGHT + 1, bot.getZ() - 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
|
||||
public BlockBucket ROAD_BLOCK = new BlockBucket(BlockTypes.QUARTZ_BLOCK);
|
||||
// BlockUtil.get((short) 155, (byte) 0);
|
||||
public boolean PLOT_BEDROCK = true;
|
||||
public boolean PLACE_TOP_BLOCK = true;
|
||||
|
||||
public ClassicPlotWorld(@Nonnull final String worldName,
|
||||
@Nullable final String id,
|
||||
@ -90,6 +91,8 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
|
||||
ConfigurationUtil.BLOCK_BUCKET),
|
||||
new ConfigurationNode("wall.block_claimed", this.CLAIMED_WALL_BLOCK,
|
||||
"Wall block (claimed)", ConfigurationUtil.BLOCK_BUCKET),
|
||||
new ConfigurationNode("wall.place_top_block", this.PLACE_TOP_BLOCK,
|
||||
"Place or not the top block", ConfigurationUtil.BOOLEAN),
|
||||
new ConfigurationNode("road.width", this.ROAD_WIDTH, "Road width",
|
||||
ConfigurationUtil.INTEGER),
|
||||
new ConfigurationNode("road.height", this.ROAD_HEIGHT, "Road height",
|
||||
@ -120,5 +123,6 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
|
||||
this.WALL_FILLING = new BlockBucket(config.getString("wall.filling"));
|
||||
this.WALL_HEIGHT = Math.min(254, config.getInt("wall.height"));
|
||||
this.CLAIMED_WALL_BLOCK = new BlockBucket(config.getString("wall.block_claimed"));
|
||||
this.PLACE_TOP_BLOCK = config.getBoolean("wall.place_top_block");
|
||||
}
|
||||
}
|
||||
|
@ -180,8 +180,10 @@ public class HybridGen extends IndependentPlotGenerator {
|
||||
result.setBlock(x, y, z, hybridPlotWorld.WALL_FILLING.toPattern());
|
||||
}
|
||||
if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
|
||||
if (hybridPlotWorld.PLACE_TOP_BLOCK) {
|
||||
result.setBlock(x, hybridPlotWorld.WALL_HEIGHT + 1, z,
|
||||
hybridPlotWorld.WALL_BLOCK.toPattern());
|
||||
}
|
||||
} else {
|
||||
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z,
|
||||
true);
|
||||
@ -205,8 +207,10 @@ public class HybridGen extends IndependentPlotGenerator {
|
||||
result.setBlock(x, y, z, hybridPlotWorld.WALL_FILLING.toPattern());
|
||||
}
|
||||
if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
|
||||
if (hybridPlotWorld.PLACE_TOP_BLOCK) {
|
||||
result.setBlock(x, hybridPlotWorld.WALL_HEIGHT + 1, z,
|
||||
hybridPlotWorld.WALL_BLOCK.toPattern());
|
||||
}
|
||||
} else {
|
||||
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z,
|
||||
true);
|
||||
|
@ -2351,7 +2351,7 @@ public class Plot {
|
||||
*
|
||||
* @return The plot alias
|
||||
*/
|
||||
public String getAlias() {
|
||||
@NotNull public String getAlias() {
|
||||
if (this.settings == null) {
|
||||
return "";
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
*/
|
||||
package com.plotsquared.core.plot.flag;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.plotsquared.core.plot.flag.implementations.AnalysisFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.AnimalAttackFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.AnimalCapFlag;
|
||||
@ -114,7 +115,13 @@ import java.util.Map;
|
||||
|
||||
public final class GlobalFlagContainer extends FlagContainer {
|
||||
|
||||
@Getter private static final GlobalFlagContainer instance = new GlobalFlagContainer();
|
||||
@Getter private static GlobalFlagContainer instance;
|
||||
|
||||
public static void setup() {
|
||||
Preconditions.checkState(instance == null, "Cannot setup the container twice");
|
||||
instance = new GlobalFlagContainer();
|
||||
}
|
||||
|
||||
private static Map<String, Class<?>> stringClassMap;
|
||||
|
||||
private GlobalFlagContainer() {
|
||||
@ -124,6 +131,7 @@ public final class GlobalFlagContainer extends FlagContainer {
|
||||
}
|
||||
});
|
||||
stringClassMap = new HashMap<>();
|
||||
|
||||
// Register all default flags here
|
||||
// Boolean flags
|
||||
this.addFlag(ExplosionFlag.EXPLOSION_FALSE);
|
||||
|
@ -43,7 +43,7 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
|
||||
* Entity related general utility methods
|
||||
*/
|
||||
@UtilityClass
|
||||
public final class EntityUtil {
|
||||
public class EntityUtil {
|
||||
|
||||
private static int capNumeral(@Nonnull final String flagName) {
|
||||
int i;
|
||||
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.core.util.placeholders;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A placeholder is a keyed value that gets replaced by a {@link PlotPlayer player}-specific value at runtime
|
||||
*/
|
||||
@EqualsAndHashCode(of = "key") @ToString(of = "key")
|
||||
public abstract class Placeholder {
|
||||
|
||||
private final String key;
|
||||
|
||||
public Placeholder(@NotNull final String key) {
|
||||
this.key = Preconditions.checkNotNull(key, "Key may not be null");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the placeholder for a particular player
|
||||
*
|
||||
* @param player Player
|
||||
* @return Placeholder value. Return {@code ""} if no placeholder value can be returned
|
||||
*/
|
||||
@NotNull public abstract String getValue(@NotNull final PlotPlayer<?> player);
|
||||
|
||||
/**
|
||||
* Get the placeholder key
|
||||
*
|
||||
* @return Placeholder key
|
||||
*/
|
||||
@NotNull public final String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,230 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.core.util.placeholders;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.flag.GlobalFlagContainer;
|
||||
import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
/**
|
||||
* Registry that contains {@link Placeholder placeholders}
|
||||
*/
|
||||
public final class PlaceholderRegistry {
|
||||
|
||||
private final Map<String, Placeholder> placeholders;
|
||||
private final EventDispatcher eventDispatcher;
|
||||
|
||||
public PlaceholderRegistry(@NotNull final EventDispatcher eventDispatcher) {
|
||||
this.placeholders = Maps.newHashMap();
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.registerDefault();
|
||||
}
|
||||
|
||||
private void registerDefault() {
|
||||
final GlobalFlagContainer globalFlagContainer = GlobalFlagContainer.getInstance();
|
||||
for (final PlotFlag<?, ?> flag : globalFlagContainer.getRecognizedPlotFlags()) {
|
||||
this.registerPlaceholder(new PlotFlagPlaceholder(flag, true));
|
||||
this.registerPlaceholder(new PlotFlagPlaceholder(flag, false));
|
||||
}
|
||||
GlobalFlagContainer.getInstance().subscribe((flag, type) -> {
|
||||
this.registerPlaceholder(new PlotFlagPlaceholder(flag, true));
|
||||
this.registerPlaceholder(new PlotFlagPlaceholder(flag, false));
|
||||
});
|
||||
this.createPlaceholder("currentplot_world", player -> player.getLocation().getWorld());
|
||||
this.createPlaceholder("has_plot", player -> player.getPlotCount() > 0 ? "true" : "false");
|
||||
this.createPlaceholder("allowed_plot_count", player -> Integer.toString(player.getAllowedPlots()));
|
||||
this.createPlaceholder("plot_count", player -> Integer.toString(player.getPlotCount()));
|
||||
this.createPlaceholder("currentplot_alias", (player, plot) -> plot.getAlias());
|
||||
this.createPlaceholder("currentplot_owner", (player, plot) -> {
|
||||
final UUID plotOwner = plot.getOwnerAbs();
|
||||
if (plotOwner == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
try {
|
||||
return MainUtil.getName(plotOwner, false);
|
||||
} catch (final Exception ignored) {}
|
||||
|
||||
return "unknown";
|
||||
});
|
||||
this.createPlaceholder("currentplot_members", (player, plot) -> {
|
||||
if (plot.getMembers() == null && plot.getTrusted() == null) {
|
||||
return "0";
|
||||
}
|
||||
return String.valueOf(plot.getMembers().size() + plot.getTrusted().size());
|
||||
});
|
||||
this.createPlaceholder("currentplot_members_added", (player, plot) -> {
|
||||
if (plot.getMembers() == null) {
|
||||
return "0";
|
||||
}
|
||||
return String.valueOf(plot.getMembers().size());
|
||||
});
|
||||
this.createPlaceholder("currentplot_members_trusted", (player, plot) -> {
|
||||
if (plot.getTrusted() == null) {
|
||||
return "0";
|
||||
}
|
||||
return String.valueOf(plot.getTrusted().size());
|
||||
});
|
||||
this.createPlaceholder("currentplot_members_denied", (player, plot) -> {
|
||||
if (plot.getDenied() == null) {
|
||||
return "0";
|
||||
}
|
||||
return String.valueOf(plot.getDenied().size());
|
||||
});
|
||||
this.createPlaceholder("has_build_rights", (player, plot) ->
|
||||
plot.isAdded(player.getUUID()) ? "true" : "false");
|
||||
this.createPlaceholder("currentplot_x", (player, plot) -> Integer.toString(plot.getId().getX()));
|
||||
this.createPlaceholder("currentplot_y", (player, plot) -> Integer.toString(plot.getId().getY()));
|
||||
this.createPlaceholder("currentplot_xy", (player, plot) -> plot.getId().toString());
|
||||
this.createPlaceholder("currentplot_rating", (player, plot) -> Double.toString(plot.getAverageRating()));
|
||||
this.createPlaceholder("currentplot_biome", (player, plot) -> plot.getBiomeSynchronous().toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a functional placeholder
|
||||
*
|
||||
* @param key Placeholder key
|
||||
* @param placeholderFunction Placeholder generator. Cannot return null
|
||||
*/
|
||||
@SuppressWarnings("ALL") public void createPlaceholder(@NotNull final String key,
|
||||
@NotNull final Function<PlotPlayer<?>, String> placeholderFunction) {
|
||||
this.registerPlaceholder(new Placeholder(key) {
|
||||
@Override @NotNull public String getValue(@NotNull final PlotPlayer<?> player) {
|
||||
return placeholderFunction.apply(player);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a functional placeholder
|
||||
*
|
||||
* @param key Placeholder key
|
||||
* @param placeholderFunction Placeholder generator. Cannot return null
|
||||
*/
|
||||
public void createPlaceholder(@NotNull final String key,
|
||||
@NotNull final BiFunction<PlotPlayer<?>, Plot, String> placeholderFunction) {
|
||||
this.registerPlaceholder(new PlotSpecificPlaceholder(key) {
|
||||
@Override @NotNull public String getValue(@NotNull final PlotPlayer<?> player, @NotNull final Plot plot) {
|
||||
return placeholderFunction.apply(player, plot);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a placeholder
|
||||
*
|
||||
* @param placeholder Placeholder instance
|
||||
*/
|
||||
public void registerPlaceholder(@NotNull final Placeholder placeholder) {
|
||||
final Placeholder previous = this.placeholders
|
||||
.put(placeholder.getKey().toLowerCase(Locale.ENGLISH),
|
||||
Preconditions.checkNotNull(placeholder, "Placeholder may not be null"));
|
||||
if (previous == null) {
|
||||
this.eventDispatcher.callGenericEvent(new PlaceholderAddedEvent(placeholder));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a placeholder instance from its key
|
||||
*
|
||||
* @param key Placeholder key
|
||||
* @return Placeholder value
|
||||
*/
|
||||
@Nullable public Placeholder getPlaceholder(@NotNull final String key) {
|
||||
return this.placeholders.get(
|
||||
Preconditions.checkNotNull(key, "Key may not be null").toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the placeholder value evaluated for a player, and catch and deal with any problems
|
||||
* occurring while doing so
|
||||
*
|
||||
* @param key Placeholder key
|
||||
* @param player Player to evaluate for
|
||||
* @return Replacement value
|
||||
*/
|
||||
@NotNull public String getPlaceholderValue(@NotNull final String key,
|
||||
@NotNull final PlotPlayer<?> player) {
|
||||
final Placeholder placeholder = getPlaceholder(key);
|
||||
if (placeholder == null) {
|
||||
return "";
|
||||
}
|
||||
String placeholderValue = "";
|
||||
try {
|
||||
placeholderValue = placeholder.getValue(player);
|
||||
// If a placeholder for some reason decides to be disobedient, we catch it here
|
||||
if (placeholderValue == null) {
|
||||
new RuntimeException(String
|
||||
.format("Placeholder '%s' returned null for player '%s'", placeholder.getKey(),
|
||||
player.getName())).printStackTrace();
|
||||
}
|
||||
} catch (final Exception exception) {
|
||||
new RuntimeException(String
|
||||
.format("Placeholder '%s' failed to evalulate for player '%s'",
|
||||
placeholder.getKey(), player.getName()), exception).printStackTrace();
|
||||
}
|
||||
return placeholderValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all placeholders
|
||||
*
|
||||
* @return Unmodifiable collection of placeholders
|
||||
*/
|
||||
@NotNull public Collection<Placeholder> getPlaceholders() {
|
||||
return Collections.unmodifiableCollection(this.placeholders.values());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Event called when a new {@link Placeholder} has been added
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public static class PlaceholderAddedEvent {
|
||||
|
||||
private final Placeholder placeholder;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.core.util.placeholders;
|
||||
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.flag.GlobalFlagContainer;
|
||||
import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class PlotFlagPlaceholder extends PlotSpecificPlaceholder {
|
||||
|
||||
private final PlotFlag<?, ?> flag;
|
||||
private final boolean local;
|
||||
|
||||
public PlotFlagPlaceholder(@NotNull final PlotFlag<?, ?> flag, final boolean local) {
|
||||
super(String.format("currentplot_%sflag_%s", local ? "local": "", flag.getName()));
|
||||
this.flag = flag;
|
||||
this.local = local;
|
||||
}
|
||||
|
||||
@Override @NotNull public String getValue(@NotNull final PlotPlayer<?> player, @NotNull final Plot plot) {
|
||||
return this.getFlagValue(plot, this.flag.getName(), !this.local);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the flag value from its name on the current plot.
|
||||
* If the flag doesn't exist it returns an empty string.
|
||||
* If the flag exists but it is not set on current plot and the parameter inherit is set to true,
|
||||
* it returns the default value.
|
||||
*
|
||||
* @param plot Current plot where the player is
|
||||
* @param flagName Name of flag to get from current plot
|
||||
* @param inherit Define if it returns only the flag set on the current plot or also inherited flags
|
||||
* @return The value of flag serialized in string
|
||||
*/
|
||||
@NotNull private String getFlagValue(@NotNull final Plot plot, @NotNull final String flagName, final boolean inherit) {
|
||||
if (flagName.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
final PlotFlag<?, ?> flag = GlobalFlagContainer.getInstance().getFlagFromString(flagName);
|
||||
if (flag == null) {
|
||||
return "";
|
||||
}
|
||||
if (inherit) {
|
||||
return plot.getFlag(flag).toString();
|
||||
} else {
|
||||
final PlotFlag<?, ?> plotFlag = plot.getFlagContainer().queryLocal(flag.getClass());
|
||||
return (plotFlag != null) ? plotFlag.getValue().toString() : "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.core.util.placeholders;
|
||||
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A {@link Placeholder placeholder} that requires a {@link com.plotsquared.core.plot.Plot plot}
|
||||
*/
|
||||
public abstract class PlotSpecificPlaceholder extends Placeholder {
|
||||
|
||||
public PlotSpecificPlaceholder(@NotNull final String key) {
|
||||
super(key);
|
||||
}
|
||||
|
||||
@Override @NotNull public final String getValue(@NotNull final PlotPlayer<?> player) {
|
||||
final Plot plot = player.getCurrentPlot();
|
||||
if (plot == null) {
|
||||
return "";
|
||||
}
|
||||
return this.getValue(player, plot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the placeholder for the {@link PlotPlayer player} in a specific {@link Plot plot}
|
||||
*
|
||||
* @param player Player that the placeholder is evaluated for
|
||||
* @param plot Plot that the player is in
|
||||
* @return Placeholder value, or {@code ""} if the placeholder does not apply
|
||||
*/
|
||||
@NotNull public abstract String getValue(@NotNull final PlotPlayer<?> player,
|
||||
@NotNull final Plot plot);
|
||||
|
||||
}
|
@ -31,11 +31,11 @@ import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.util.ThreadUtils;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -168,8 +168,10 @@ public class UUIDPipeline {
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
} catch (TimeoutException ignored) {
|
||||
logger.warn("[P2] (UUID) Request for {} timed out", username);
|
||||
// This is completely valid, we just don't care anymore
|
||||
if (Settings.DEBUG) {
|
||||
logger.warn("[P2] (UUID) Request for {} timed out", username);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -191,8 +193,10 @@ public class UUIDPipeline {
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
} catch (TimeoutException ignored) {
|
||||
logger.warn("[P2] (UUID) Request for {} timed out", uuid);
|
||||
// This is completely valid, we just don't care anymore
|
||||
if (Settings.DEBUG) {
|
||||
logger.warn("[P2] (UUID) Request for {} timed out", uuid);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -203,8 +207,7 @@ public class UUIDPipeline {
|
||||
* @param username Username
|
||||
* @param uuid UUID consumer
|
||||
*/
|
||||
public void getSingle(@Nonnull final String username,
|
||||
@Nonnull final BiConsumer<UUID, Throwable> uuid) {
|
||||
public void getSingle(@Nonnull final String username, @Nonnull final BiConsumer<UUID, Throwable> uuid) {
|
||||
this.getUUIDs(Collections.singletonList(username)).applyToEither(timeoutAfter(Settings.UUID.NON_BLOCKING_TIMEOUT), Function.identity())
|
||||
.whenComplete((uuids, throwable) -> {
|
||||
if (throwable != null) {
|
||||
@ -225,8 +228,7 @@ public class UUIDPipeline {
|
||||
* @param uuid UUID
|
||||
* @param username Username consumer
|
||||
*/
|
||||
public void getSingle(@Nonnull final UUID uuid,
|
||||
@Nonnull final BiConsumer<String, Throwable> username) {
|
||||
public void getSingle(@Nonnull final UUID uuid, @Nonnull final BiConsumer<String, Throwable> username) {
|
||||
this.getNames(Collections.singletonList(uuid)).applyToEither(timeoutAfter(Settings.UUID.NON_BLOCKING_TIMEOUT), Function.identity())
|
||||
.whenComplete((uuids, throwable) -> {
|
||||
if (throwable != null) {
|
||||
@ -251,8 +253,7 @@ public class UUIDPipeline {
|
||||
* @param timeout Timeout in milliseconds
|
||||
* @return Mappings
|
||||
*/
|
||||
public CompletableFuture<List<UUIDMapping>> getNames(@Nonnull final Collection<UUID> requests,
|
||||
final long timeout) {
|
||||
public CompletableFuture<List<UUIDMapping>> getNames(@Nonnull final Collection<UUID> requests, final long timeout) {
|
||||
return this.getNames(requests).applyToEither(timeoutAfter(timeout), Function.identity());
|
||||
}
|
||||
|
||||
@ -266,8 +267,7 @@ public class UUIDPipeline {
|
||||
* @param timeout Timeout in milliseconds
|
||||
* @return Mappings
|
||||
*/
|
||||
public CompletableFuture<List<UUIDMapping>> getUUIDs(@Nonnull final Collection<String> requests,
|
||||
final long timeout) {
|
||||
public CompletableFuture<List<UUIDMapping>> getUUIDs(@Nonnull final Collection<String> requests, final long timeout) {
|
||||
return this.getUUIDs(requests).applyToEither(timeoutAfter(timeout), Function.identity());
|
||||
}
|
||||
|
||||
@ -345,8 +345,7 @@ public class UUIDPipeline {
|
||||
* @param requests Names
|
||||
* @return Mappings
|
||||
*/
|
||||
public CompletableFuture<List<UUIDMapping>> getUUIDs(
|
||||
@Nonnull final Collection<String> requests) {
|
||||
public CompletableFuture<List<UUIDMapping>> getUUIDs(@Nonnull final Collection<String> requests) {
|
||||
if (requests.isEmpty()) {
|
||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user