Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make old worlds have min Y 0 #1396

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ publishing {

tasks {
processResources {
filesMatching(listOf("plugin.yml")) {
filesMatching(listOf("plugin.yml", "paper-plugin.yml")) {
expand(
"name" to project.name,
"description" to project.description,
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/tc/oc/pgm/api/map/WorldInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public interface WorldInfo {
*
* @return The world environment type.
*/
int getEnvironment();
World.Environment getEnvironment();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package tc.oc.pgm.filters.matcher.player;

import static tc.oc.pgm.util.bukkit.InventoryViewUtil.INVENTORY_VIEW;

import com.google.common.collect.ImmutableList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -39,16 +41,16 @@ public Collection<Class<? extends Event>> getRelevantEvents() {

@Override
protected Stream<ItemStack> getItems(MatchPlayer player) {
Stream<ItemStack> inventory =
Stream.concat(
Arrays.stream(player.getBukkit().getInventory().getContents()),
Stream.of(player.getBukkit().getItemOnCursor()));
Stream<ItemStack> inventory = Stream.concat(
Arrays.stream(player.getBukkit().getInventory().getContents()),
Stream.of(player.getBukkit().getItemOnCursor()));

// Potentially add the crafting grid if that's the currently open inventory
InventoryView invView = player.getBukkit().getOpenInventory();
InventoryType type = invView.getType();
InventoryType type = INVENTORY_VIEW.getType(invView);
if (type == InventoryType.CRAFTING || type == InventoryType.WORKBENCH) {
return Stream.concat(inventory, Arrays.stream(invView.getTopInventory().getContents()));
return Stream.concat(
inventory, Arrays.stream(INVENTORY_VIEW.getTopInventory(invView).getContents()));
}
return inventory;
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/tc/oc/pgm/flag/state/Carried.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static net.kyori.adventure.text.Component.translatable;
import static net.kyori.adventure.title.Title.title;
import static tc.oc.pgm.util.TimeUtils.fromTicks;
import static tc.oc.pgm.util.bukkit.InventoryViewUtil.INVENTORY_VIEW;
import static tc.oc.pgm.util.nms.Packets.PLAYERS;

import java.time.Duration;
Expand Down Expand Up @@ -309,10 +310,9 @@ public void onEvent(ParticipantDespawnEvent event) {
@Override
public void onEvent(InventoryClickEvent event) {
super.onEvent(event);
if (this.isCarrier(event.getWhoClicked())
&& event.getSlot() == ArmorType.HELMET.inventorySlot()) {
if (isCarrier(event.getWhoClicked()) && event.getSlot() == ArmorType.HELMET.inventorySlot()) {
event.setCancelled(true);
event.getView().setCursor(null);
INVENTORY_VIEW.setCursor(event.getView(), null);
event.setCurrentItem(null);
this.flag.getMatch().getExecutor(MatchScope.RUNNING).execute(() -> {
if (isCurrent()) dropFlag();
Expand Down
12 changes: 7 additions & 5 deletions core/src/main/java/tc/oc/pgm/kits/ClearItemsKit.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package tc.oc.pgm.kits;

import static tc.oc.pgm.util.bukkit.InventoryViewUtil.INVENTORY_VIEW;

import java.util.List;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
Expand Down Expand Up @@ -47,12 +49,12 @@ public void applyPostEvent(MatchPlayer player, boolean force, List<ItemStack> di
}
if (this.items) {
player.getBukkit().getInventory().clear();
player.getBukkit().getOpenInventory().setCursor(null);
INVENTORY_VIEW.setCursor(player.getBukkit().getOpenInventory(), null);
InventoryView openInventory = player.getBukkit().getOpenInventory();
if (openInventory != null
&& (openInventory.getType().equals(InventoryType.CRAFTING)
|| openInventory.getType().equals(InventoryType.WORKBENCH))) {
Inventory topInventory = openInventory.getTopInventory();
InventoryType type = openInventory == null ? null : INVENTORY_VIEW.getType(openInventory);
if (type != null
&& (type.equals(InventoryType.CRAFTING) || type.equals(InventoryType.WORKBENCH))) {
Inventory topInventory = INVENTORY_VIEW.getTopInventory(openInventory);
if (topInventory != null) {
topInventory.clear();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tc.oc.pgm.listeners;

import static net.kyori.adventure.text.Component.translatable;
import static tc.oc.pgm.util.bukkit.InventoryViewUtil.INVENTORY_VIEW;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -205,7 +206,7 @@ public void giveKit(final ObserverKitApplyEvent event) {
public void cloneCraftingWindow(final PlayerInteractEvent event) {
if (!event.isCancelled()
&& event.getAction() == Action.RIGHT_CLICK_BLOCK
&& event.getPlayer().getOpenInventory().getType() == InventoryType.CRAFTING) {
&& INVENTORY_VIEW.getType(event.getPlayer().getOpenInventory()) == InventoryType.CRAFTING) {
Block block = event.getClickedBlock();
if (block != null
&& block.getType() == Materials.WORKBENCH
Expand Down
25 changes: 12 additions & 13 deletions core/src/main/java/tc/oc/pgm/map/WorldInfoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,26 @@ public class WorldInfoImpl implements WorldInfo {
private static final Random random = new Random();
private final long seed; // 0 means random every time
private final boolean terrain;
private final int environment;
private final World.Environment environment;

public WorldInfoImpl() {
this(0L, false, 0);
}

public WorldInfoImpl(long seed, boolean terrain, int environment) {
this.seed = seed;
this.terrain = terrain;
this.environment = environment > 1 || environment < -1 ? 0 : environment;
this(0L, false, World.Environment.NORMAL);
}

public WorldInfoImpl(Element element) throws InvalidXMLException {
this(
parseSeed(assertNotNull(element).getAttributeValue("seed")),
XMLUtils.parseBoolean(element.getAttribute("vanilla"), false),
XMLUtils.parseEnum(
Node.fromLastChildOrAttr(element, "environment"),
World.Environment.class,
World.Environment.NORMAL)
.ordinal());
Node.fromLastChildOrAttr(element, "environment"),
World.Environment.class,
World.Environment.NORMAL));
}

private WorldInfoImpl(long seed, boolean terrain, World.Environment environment) {
this.seed = seed;
this.terrain = terrain;
this.environment = environment;
}

@Override
Expand All @@ -49,7 +48,7 @@ public boolean hasTerrain() {
}

@Override
public int getEnvironment() {
public World.Environment getEnvironment() {
return environment;
}

Expand Down
18 changes: 5 additions & 13 deletions core/src/main/java/tc/oc/pgm/match/MatchFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Stack;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
Expand All @@ -25,7 +26,6 @@
import org.bukkit.Difficulty;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.entity.Player;
import tc.oc.pgm.api.PGM;
import tc.oc.pgm.api.map.MapContext;
Expand All @@ -37,7 +37,6 @@
import tc.oc.pgm.api.player.MatchPlayer;
import tc.oc.pgm.spawns.SpawnMatchModule;
import tc.oc.pgm.util.FileUtils;
import tc.oc.pgm.util.chunk.NullChunkGenerator;
import tc.oc.pgm.util.text.TextException;
import tc.oc.pgm.util.text.TextParser;
import tc.oc.pgm.util.text.TextTranslations;
Expand Down Expand Up @@ -67,7 +66,7 @@ public Match call() {
// Match creation was cancelled, no need to show an error
if (e.getCause() instanceof InterruptedException) throw e;

Throwable err = e.getCause();
Throwable err = Objects.requireNonNullElse(e.getCause(), e);
PGM.get().getGameLogger().log(Level.SEVERE, err.getMessage(), err.getCause());
throw e;
}
Expand Down Expand Up @@ -267,16 +266,9 @@ private InitWorldStage(MapContext map, String worldName) {

private Stage advanceSync() throws IllegalStateException {
final WorldInfo info = map.getInfo().getWorld();
WorldCreator creator = NMS_HACKS.detectWorld(worldName);
if (creator == null) {
creator = new WorldCreator(worldName);
}
final World world = PGM.get()
.getServer()
.createWorld(creator
.environment(environments[info.getEnvironment()])
.generator(info.hasTerrain() ? null : NullChunkGenerator.INSTANCE)
.seed(info.hasTerrain() ? info.getSeed() : creator.seed()));
final World world = NMS_HACKS.createWorld(
worldName, info.getEnvironment(), info.hasTerrain(), info.getSeed());

if (world == null) throw new IllegalStateException("Unable to load a null world");

world.setPVP(true);
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/tc/oc/pgm/picker/PickerMatchModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static net.kyori.adventure.text.Component.text;
import static net.kyori.adventure.text.Component.translatable;
import static tc.oc.pgm.util.Assert.assertTrue;
import static tc.oc.pgm.util.bukkit.InventoryViewUtil.INVENTORY_VIEW;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -489,7 +490,7 @@ private boolean checkWindow(MatchPlayer player) {
*/
private @Nullable Inventory getOpenWindow(MatchPlayer player) {
if (picking.contains(player)) {
return player.getBukkit().getOpenInventory().getTopInventory();
return INVENTORY_VIEW.getTopInventory(player.getBukkit().getOpenInventory());
}
return null;
}
Expand Down Expand Up @@ -713,7 +714,7 @@ private void scheduleClose(final MatchPlayer player) {

match.getExecutor(MatchScope.LOADED).execute(() -> {
if (bukkit.isOnline()) {
bukkit.getOpenInventory().getTopInventory().clear();
INVENTORY_VIEW.getTopInventory(bukkit.getOpenInventory()).clear();
bukkit.closeInventory();
}
});
Expand Down
18 changes: 18 additions & 0 deletions core/src/main/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: PGM
api-version: 1.21.1
description: ${description}
main: ${mainClass}
version: ${version} (git-${commitHash})
website: ${url}
bootstrapper: tc.oc.pgm.platform.modern.PgmBootstrap

dependencies:
server:
ProtocolLib:
load: BEFORE
required: true
join-classpath: true
ViaVersion:
load: BEFORE
required: false
join-classpath: true
Loading