Skip to content

Commit

Permalink
fix: shifting function with tutorial plot
Browse files Browse the repository at this point in the history
* separate out shifted outline function to its own method
* organized and deleted some unused line
* if cause to generating outline protection between normal and tutorial plot (tutorial plot doesn't require shifting)
  • Loading branch information
tintinkung committed Apr 12, 2024
1 parent 81b86c1 commit 44230cf
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 73 deletions.
9 changes: 8 additions & 1 deletion src/main/java/com/alpsbte/plotsystem/commands/CMD_Tpll.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
// Convert terra coordinates to plot relative coordinates
CompletableFuture<double[]> plotCoords = plot != null ? PlotUtils.convertTerraToPlotXZ(plot, terraCoords) : null;

Bukkit.getLogger().log(Level.INFO, "doing TPLL to coords: " + plotCoords);


if(plotCoords == null) {
player.sendMessage(Utils.ChatUtils.getAlertFormat(langUtil.get(sender, LangPaths.Message.Error.CANNOT_TELEPORT_OUTSIDE_PLOT)));
Expand All @@ -130,6 +130,13 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
highestY = PlotWorld.MIN_WORLD_HEIGHT;
}

Bukkit.getLogger().log(Level.INFO, "Doing TPLL to terraCoords: (lon: "
+ terraCoords[0] + ", lat: "
+ terraCoords[1] + ") "
+ "To block coordinate: (x: "
+ plotCoords.get()[0]
+ ", y: " + plotCoords.get()[1] + ")"
);
player.teleport(new Location(playerWorld, plotCoords.get()[0], highestY + 1, plotCoords.get()[1], player.getLocation().getYaw(), player.getLocation().getPitch()));

DecimalFormat df = new DecimalFormat("##.#####");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected void setMenuItemsAsync() {
getMenu().getSlot(15).setItem(
new ItemBuilder(AlpsHeadUtils.getCustomHead(CustomHeads.CITY_INSPIRATION_MODE_BUTTON.getId()))
.setName(text(LangUtil.getInstance().get(getMenuPlayer(), LangPaths.MenuTitle.SELECT_CITY_INSPIRATION_MODE), GOLD, BOLD)
.append(text(" [", DARK_GRAY).append(text("BETA", RED).append(text("]", DARK_GRAY))))) // temporary BETA tag
.append(text(" [", DARK_GRAY).append(text("WORK IN PROGRESS", RED).append(text("]", DARK_GRAY))))) // temporary BETA tag
.setLore(new LoreBuilder()
.addLines(LangUtil.getInstance().get(getMenuPlayer(), LangPaths.MenuDescription.SELECT_CITY_INSPIRATION_MODE))
.build())
Expand All @@ -93,8 +93,8 @@ protected void setMenuItemsAsync() {
int selectedPlotTypeSlot = 13;
if(builder.getPlotTypeSetting() == PlotType.FOCUS_MODE)
selectedPlotTypeSlot = 11;
if(builder.getPlotTypeSetting() == PlotType.CITY_INSPIRATION_MODE)
selectedPlotTypeSlot = 15;
// if(builder.getPlotTypeSetting() == PlotType.CITY_INSPIRATION_MODE)
// selectedPlotTypeSlot = 15;
getMenu().getSlot(selectedPlotTypeSlot - 9).setItem(new ItemBuilder(Material.LIME_STAINED_GLASS_PANE, 1).setName(empty()).build());


Expand All @@ -117,9 +117,10 @@ protected void setItemClickEventsAsync() {
reloadMenuAsync();
}));

// WORK IN PROGRESS: Disabled city project of type
getMenu().getSlot(15).setClickHandler(((clickPlayer, clickInformation) -> {
builder.setPlotTypeSetting(PlotType.CITY_INSPIRATION_MODE);
getMenuPlayer().playSound(getMenuPlayer().getLocation(), Utils.SoundUtils.DONE_SOUND, 1f, 1f);
// builder.setPlotTypeSetting(PlotType.CITY_INSPIRATION_MODE);
getMenuPlayer().playSound(getMenuPlayer().getLocation(), Utils.SoundUtils.ERROR_SOUND, 1f, 1f);
reloadMenuAsync();
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;

import static com.alpsbte.plotsystem.core.system.plot.world.PlotWorld.MAX_WORLD_HEIGHT;
import static com.alpsbte.plotsystem.core.system.plot.world.PlotWorld.MIN_WORLD_HEIGHT;

public abstract class AbstractPlot {
public static final double PLOT_VERSION = 3;

Expand All @@ -67,6 +65,8 @@ public abstract class AbstractPlot {

protected List<BlockVector2> outline;
protected List<BlockVector2> blockOutline;
protected List<BlockVector2> shiftedOutline;


public AbstractPlot(int id) {
this.ID = id;
Expand Down Expand Up @@ -217,6 +217,22 @@ protected List<BlockVector2> getOutlinePoints(String outlinePoints) throws SQLEx
return locations;
}

public final List<BlockVector2> getShiftedOutline() throws SQLException, IOException {
if(this.shiftedOutline != null)
return this.shiftedOutline;

List<BlockVector2> outline = getOutline();
List<BlockVector2> shiftedOutlines = new LinkedList<>(outline);

BlockVector2 center = PlotUtils.getCenterFromOutline(outline);
for(int i = 0; i < shiftedOutlines.size(); i++)
shiftedOutlines.set(i, BlockVector2.at(outline.get(i).getX() - center.getX(), outline.get(i).getZ() - center.getZ()));


this.shiftedOutline = shiftedOutlines;
return shiftedOutline;
}

/**
* @return the outline of the polygon with one point per Block
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.alpsbte.plotsystem.core.system.Builder;
import com.alpsbte.plotsystem.core.system.plot.AbstractPlot;
import com.alpsbte.plotsystem.core.system.plot.Plot;
import com.alpsbte.plotsystem.core.system.plot.TutorialPlot;
import com.alpsbte.plotsystem.core.system.plot.utils.PlotType;
import com.alpsbte.plotsystem.core.system.plot.utils.PlotUtils;
import com.alpsbte.plotsystem.core.system.plot.world.CityPlotWorld;
Expand Down Expand Up @@ -77,9 +78,7 @@
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.logging.Level;

public abstract class AbstractPlotGenerator {
Expand Down Expand Up @@ -174,20 +173,15 @@ protected void generateOutlines(@NotNull File plotSchematic, @Nullable File envi
protected void createPlotProtection() throws StorageException, SQLException, IOException {
RegionContainer regionContainer = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionManager regionManager = regionContainer.get(BukkitAdapter.adapt(world.getBukkitWorld()));
List<BlockVector2> plotOutlines = plot instanceof TutorialPlot ? plot.getOutline() : plot.getShiftedOutline();

if (regionManager != null) {
BlockVector2 center = BlockVector2.at(plot.getCenter().getX(), plot.getCenter().getZ()) ;
// Create build region for plot from the outline of the plot
List<BlockVector2> plotOutlines = plot.getOutline();

Bukkit.getLogger().log(Level.INFO, "Configuring Plot outlines protection from:\n" + plotOutlines);
for(int i = 0; i < plotOutlines.size(); i++)
plotOutlines.set(i, BlockVector2.at(plotOutlines.get(i).getX() - center.getX(), plotOutlines.get(i).getZ() - center.getZ()));
Bukkit.getLogger().log(Level.INFO, "Configured Plot outlines protection to:\n" + plotOutlines);

ProtectedRegion protectedBuildRegion = new ProtectedPolygonalRegion(world.getRegionName(), plotOutlines, PlotWorld.MIN_WORLD_HEIGHT, PlotWorld.MAX_WORLD_HEIGHT);
protectedBuildRegion.setPriority(100);

Bukkit.getLogger().log(Level.INFO, "Configured Plot outlines protection to:\n" + protectedBuildRegion.getPoints() + "\n" + protectedBuildRegion);

// Create protected plot region for plot
World weWorld = new BukkitWorld(world.getBukkitWorld());
CylinderRegion cylinderRegion = new CylinderRegion(weWorld, BlockVector3.at(0, plot.getCenter().getY(), 0), Vector2.at(PlotWorld.PLOT_SIZE, PlotWorld.PLOT_SIZE), PlotWorld.MIN_WORLD_HEIGHT, PlotWorld.MAX_WORLD_HEIGHT);
Expand Down Expand Up @@ -304,9 +298,7 @@ public static void pasteSchematic(@Nullable Mask pasteMask, File schematicFile,
World weWorld = new BukkitWorld(world.getBukkitWorld());
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(world.getBukkitWorld()))) {
if (clearArea) {
BlockVector3 center = BlockVector3.at(world.getPlot().getCenter().getBlockX(), world.getPlotHeight(), world.getPlot().getCenter().getBlockZ());
Polygonal2DRegion polyRegion = new Polygonal2DRegion(weWorld, world.getPlot().getOutline(), 0, PlotWorld.MAX_WORLD_HEIGHT);
polyRegion.shift(BlockVector3.at(-center.getX(), 0, -center.getZ()));
Polygonal2DRegion polyRegion = new Polygonal2DRegion(weWorld, world.getPlot().getShiftedOutline(), 0, PlotWorld.MAX_WORLD_HEIGHT);

Bukkit.getLogger().log(Level.INFO, "Clearing plot region at:\n" + polyRegion);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,15 @@ public static boolean savePlotAsSchematic(Plot plot) throws IOException, SQLExce
Clipboard clipboard = FaweAPI.load(plot.getOutlinesSchematic());
if (clipboard != null) {
CuboidRegion cuboidRegion = getPlotAsRegion(plot);
Bukkit.getLogger().log(Level.INFO, "Getting Plot region for saving from: " + cuboidRegion);

if (cuboidRegion != null) {
BlockVector3 plotCenter = plot.getCenter();

// Get plot outline
List<BlockVector2> plotOutlines = plot.getOutline();
Bukkit.getLogger().log(Level.INFO, "Getting Plot region for saving from: " + cuboidRegion);


List<BlockVector2> plotOutlines = plot.getShiftedOutline();

// Shift schematic region to the force (0, 0) paste
for(int i = 0; i < plotOutlines.size(); i++)
plotOutlines.set(i, BlockVector2.at(plotOutlines.get(i).getX() - plotCenter.getX(), plotOutlines.get(i).getZ() - plotCenter.getZ()));
cuboidRegion.shift(BlockVector3.at(-plotCenter.getX(), 0, -plotCenter.getZ()));

Bukkit.getLogger().log(Level.INFO, "Shifted Plot region for saving to: " + cuboidRegion);
Expand All @@ -221,7 +217,7 @@ public static boolean savePlotAsSchematic(Plot plot) throws IOException, SQLExce
com.sk89q.worldedit.world.World world = new BukkitWorld(plot.getWorld().getBukkitWorld());
Polygonal2DRegion region = new Polygonal2DRegion(world, plotOutlines, cuboidRegion.getMinimumPoint().getBlockY(), cuboidRegion.getMaximumPoint().getBlockY());

Bukkit.getLogger().log(Level.INFO, "Saving schems at region: " + region);
Bukkit.getLogger().log(Level.INFO, "Saving Schematic at region: " + region);

// Copy and write finished plot clipboard to schematic file
File finishedSchematicFile = Paths.get(PlotUtils.getDefaultSchematicPath(),
Expand Down Expand Up @@ -314,6 +310,24 @@ public static CompletableFuture<double[]> convertTerraToPlotXZ(AbstractPlot plot
return null;
}

public static BlockVector2 getCenterFromOutline(List<BlockVector2> points) {
int minX = points.get(0).getX();
int minZ = points.get(0).getZ();
int maxX = points.get(0).getX();
int maxZ = points.get(0).getZ();

for (BlockVector2 v : points) {
int x = v.getX();
int z = v.getZ();
if (x < minX) minX = x;
if (z < minZ) minZ = z;
if (x > maxX) maxX = x;
if (z > maxZ) maxZ = z;
}
Vector3 center = BlockVector2.at(minX, minZ).add(BlockVector2.at(maxX, maxZ)).toVector3().divide(2);
return BlockVector2.at(center.getX(), center.getZ());
}

public static void checkPlotsForLastActivity() {
Bukkit.getScheduler().runTaskTimerAsynchronously(PlotSystem.getPlugin(), () -> {
try {
Expand Down Expand Up @@ -594,43 +608,11 @@ public static void showOutlines(){
continue;

List<BlockVector2> points = plot.getBlockOutline();
// BlockVector2 center = BlockVector2.at(plot.getCenter().getX(), plot.getCenter().getZ());

// for(int i = 0; i < points.size(); i++)
// points.set(i, BlockVector2.at(points.get(i).getX() - center.getX(), points.get(i).getZ() - center.getZ()));

BlockVector2 min = BlockVector2.ZERO;
BlockVector2 max = BlockVector2.ZERO;

int minX = points.get(0).getX();
int minZ = points.get(0).getZ();
int maxX = points.get(0).getX();
int maxZ = points.get(0).getZ();

for (BlockVector2 v : points) {
int x = v.getX();
int z = v.getZ();
if (x < minX) {
minX = x;
}
if (z < minZ) {
minZ = z;
}
if (x > maxX) {
maxX = x;
}
if (z > maxZ) {
maxZ = z;
}
}

min = BlockVector2.at(minX, minZ);
max = BlockVector2.at(maxX, maxZ);

Vector3 center = min.add(max).toVector3().divide(2);
BlockVector2 center = getCenterFromOutline(points);

for (BlockVector2 point : points) {
BlockVector2 shiftedPoint = BlockVector2.at(point.getX() - center.getX(), point.getZ() - center.getZ());

if (shiftedPoint.distanceSq(playerPos2D) < 50 * 50)
if (!ParticleAPIEnabled)
player.spawnParticle(Particle.FLAME, shiftedPoint.getX(), player.getLocation().getY() + 1, shiftedPoint.getZ(), 1, 0.0, 0.0, 0.0, 0);
Expand Down Expand Up @@ -771,12 +753,5 @@ public static void sendUnreviewedPlotsReminderMessage(List<Plot> plots, Player p
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(LangUtil.getInstance().get(player, LangPaths.MenuTitle.SHOW_PLOTS))));
player.spigot().sendMessage(tc);
}

public static BlockVector3 getCoordinateNormalised(int x, int y, int z) {

BlockVector3 normalised = BlockVector3.at(x, y, z).normalize();

return BlockVector3.at(normalised.getX(), y, normalised.getZ());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public enum CustomHeads {
GLOBE_HEAD("49973"),
PLOT_TYPE_BUTTON("4159"),
FOCUS_MODE_BUTTON("38199"),
CITY_INSPIRATION_MODE_BUTTON("38094");
CITY_INSPIRATION_MODE_BUTTON("24175");

final String id;

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/lang/en_GB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ menu-title:
select-plot-type: 'Select Plot Type'
select-focus-mode: 'Select Focus Mode'
select-local-inspiration-mode: 'Select Inspiration Mode'
select-city-inspiration-mode: 'Select City Inspiration Mode'
select-city-inspiration-mode: 'City Inspiration Mode'
filter-by-country: 'Filter By Country'
information: 'Info'
tutorials: 'Tutorials'
Expand Down

0 comments on commit 44230cf

Please sign in to comment.