Skip to content

Commit

Permalink
Merge branch 'dev' into hologram-refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Herrera <[email protected]>
  • Loading branch information
Pablete1234 authored Aug 11, 2023
2 parents 7bbe423 + c9c4b3e commit e52095a
Show file tree
Hide file tree
Showing 135 changed files with 5,632 additions and 2,143 deletions.
1 change: 1 addition & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<include>org.slf4j:slf4j-api:*</include>
<include>fr.minuskube.inv:smart-invs</include>
<include>net.objecthunter:exp4j:*</include>
<include>io.github.bananapuncher714:nbteditor:*</include>
</includes>
</artifactSet>
<filters>
Expand Down
78 changes: 40 additions & 38 deletions core/src/main/java/tc/oc/pgm/PGMConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.Normalizer;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -23,9 +26,11 @@
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.stream.Collectors;
import net.kyori.adventure.text.Component;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
Expand All @@ -38,7 +43,7 @@
import tc.oc.pgm.api.Permissions;
import tc.oc.pgm.api.map.factory.MapSourceFactory;
import tc.oc.pgm.map.source.GitMapSourceFactory;
import tc.oc.pgm.map.source.SystemMapSourceFactory;
import tc.oc.pgm.map.source.PathMapSourceFactory;
import tc.oc.pgm.util.bukkit.BukkitUtils;
import tc.oc.pgm.util.text.TextException;

Expand All @@ -56,8 +61,8 @@ public final class PGMConfig implements Config {

// map.*
private final List<MapSourceFactory> mapSourceFactories;
private final String mapPoolFile;
private final String includesDirectory;
private final Path mapPoolFile;
private final Path includesDirectory;

// countdown.*
private final Duration startTime;
Expand Down Expand Up @@ -85,6 +90,7 @@ public final class PGMConfig implements Config {
// ui.*
private final boolean showSideBar;
private final boolean showTabList;
private final boolean resizeTabList;
private final boolean showTabListPing;
private final boolean showProximity;
private final boolean showFireworks;
Expand Down Expand Up @@ -150,22 +156,11 @@ public final class PGMConfig implements Config {
}

for (String folder : folders) {
File folderFile = new File(folder);
this.mapSourceFactories.add(
new SystemMapSourceFactory(
folderFile.isAbsolute() ? folderFile : folderFile.getAbsoluteFile()));
}

final String mapPoolFile = config.getString("map.pools");
this.mapPoolFile =
mapPoolFile == null || mapPoolFile.isEmpty()
? null
: new File(dataFolder, mapPoolFile).getAbsolutePath();
final String includesDirectory = config.getString("map.includes");
this.includesDirectory =
includesDirectory == null || includesDirectory.isEmpty()
? null
: new File(dataFolder, includesDirectory).getAbsolutePath();
this.mapSourceFactories.add(new PathMapSourceFactory(Paths.get(folder)));
}

this.mapPoolFile = getPath(dataFolder.toPath(), config.getString("map.pools"));
this.includesDirectory = getPath(dataFolder.toPath(), config.getString("map.includes"));

this.startTime = parseDuration(config.getString("countdown.start", "30s"));
this.huddleTime = parseDuration(config.getString("countdown.huddle", "0s"));
Expand All @@ -189,6 +184,7 @@ public final class PGMConfig implements Config {
this.showProximity = parseBoolean(config.getString("ui.proximity", "false"));
this.showSideBar = parseBoolean(config.getString("ui.sidebar", "true"));
this.showTabList = parseBoolean(config.getString("ui.tablist", "true"));
this.resizeTabList = parseBoolean(config.getString("ui.tablist-resize", "false"));
this.showTabListPing = parseBoolean(config.getString("ui.ping", "true"));
this.participantsSeeObservers =
parseBoolean(config.getString("ui.participants-see-observers", "true"));
Expand Down Expand Up @@ -225,6 +221,12 @@ public final class PGMConfig implements Config {
this.experiments = experiments == null ? ImmutableMap.of() : experiments.getValues(false);
}

private Path getPath(Path base, String dir) {
if (dir == null || dir.isEmpty()) return null;
Path path = Paths.get(dir);
return path.isAbsolute() ? path : base.resolve(path);
}

public static final Map<?, ?> DEFAULT_REMOTE_REPO =
ImmutableMap.of("uri", "https://github.com/PGMDev/Maps", "path", "default-maps");

Expand All @@ -238,31 +240,26 @@ public static void registerRemoteMapSource(
}

String path = String.valueOf(repository.get("path"));
final File folder;
if (path.isEmpty() || path.equals("null")) {
folder =
new File("maps", (uri.getHost() + uri.getPath()).replaceAll("[/._]", "-").toLowerCase());
} else {
folder = new File(path);
String normalizedPath =
Normalizer.normalize(uri.getHost() + uri.getPath(), Normalizer.Form.NFD)
.replaceAll("[^A-Za-z0-9_]", "-")
.toLowerCase(Locale.ROOT);
path = "maps" + File.separator + normalizedPath;
}

mapSources.add(new GitMapSourceFactory(folder, uri, branch));
Path base = Paths.get(path).toAbsolutePath();

TreeSet<File> folders = new TreeSet<>();
// Set up a path filter, if needed
List<Path> children = null;
final Object subFolders = repository.get("folders");
if (subFolders instanceof List) {
for (Object subFolder : (List) subFolders) {
folders.add(new File(folder, subFolder.toString()));
}
} else {
folders.add(folder);
children =
((List<?>) subFolders)
.stream().map(Object::toString).map(Paths::get).collect(Collectors.toList());
}

for (File folderFile : folders) {
mapSources.add(
new SystemMapSourceFactory(
folderFile.isAbsolute() ? folderFile : folderFile.getAbsoluteFile()));
}
mapSources.add(new GitMapSourceFactory(base, children, uri, branch));
}

// TODO: Can be removed after 1.0 release
Expand Down Expand Up @@ -469,12 +466,12 @@ public List<? extends MapSourceFactory> getMapSourceFactories() {
}

@Override
public String getMapPoolFile() {
public Path getMapPoolFile() {
return mapPoolFile;
}

@Override
public @Nullable String getIncludesDirectory() {
public @Nullable Path getIncludesDirectory() {
return includesDirectory;
}

Expand Down Expand Up @@ -578,6 +575,11 @@ public boolean showTabList() {
return showTabList;
}

@Override
public boolean resizeTabList() {
return resizeTabList;
}

@Override
public boolean showTabListPing() {
return showTabListPing;
Expand Down
15 changes: 14 additions & 1 deletion core/src/main/java/tc/oc/pgm/PGMPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
import tc.oc.pgm.util.listener.ItemTransferListener;
import tc.oc.pgm.util.listener.PlayerBlockListener;
import tc.oc.pgm.util.listener.PlayerMoveListener;
import tc.oc.pgm.util.nms.NMSHacks;
import tc.oc.pgm.util.tablist.TablistResizer;
import tc.oc.pgm.util.text.TextException;
import tc.oc.pgm.util.text.TextTranslations;
import tc.oc.pgm.util.xml.InvalidXMLException;
Expand Down Expand Up @@ -114,6 +116,9 @@ public void onEnable() {
return; // Indicates the plugin failed to load, so exit early
}

// Sanity test PGM is running on a supported version before doing any work
NMSHacks.allocateEntityId();

Permissions.registerAll();

final CommandSender console = getServer().getConsoleSender();
Expand Down Expand Up @@ -174,7 +179,7 @@ public void onEnable() {

if (config.getMapPoolFile() != null) {
MapPoolManager manager =
new MapPoolManager(logger, new File(config.getMapPoolFile()), datastore);
new MapPoolManager(logger, config.getMapPoolFile().toFile(), datastore);
if (manager.getActiveMapPool() != null) mapOrder = manager;
}
if (mapOrder == null) mapOrder = new RandomMapOrder(Lists.newArrayList(mapLibrary.getMaps()));
Expand Down Expand Up @@ -214,6 +219,14 @@ public void onEnable() {

if (config.showTabList()) {
matchTabManager = new MatchTabManager(this);

if (config.resizeTabList()) {
if (this.getServer().getPluginManager().isPluginEnabled("ProtocolLib")) {
TablistResizer.registerAdapter(this);
} else {
logger.warning("ProtocolLib is required when 'ui.resize' is enabled");
}
}
}

if (!config.getUptimeLimit().isNegative()) {
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/tc/oc/pgm/action/actions/FillAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.api.region.Region;
import tc.oc.pgm.filters.query.BlockQuery;
import tc.oc.pgm.util.nms.NMSHacks;

public class FillAction extends AbstractAction<Match> {

Expand All @@ -32,7 +33,7 @@ public void trigger(Match match) {
if (filter != null && filter.query(new BlockQuery(block)).isDenied()) continue;

BlockState newState = block.getState();
newState.setMaterialData(materialData);
NMSHacks.setBlockStateData(newState, materialData);

if (events) {
BlockFormEvent event = new BlockFormEvent(block, newState);
Expand Down
12 changes: 10 additions & 2 deletions core/src/main/java/tc/oc/pgm/api/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static net.kyori.adventure.text.event.ClickEvent.openUrl;
import static net.kyori.adventure.text.event.HoverEvent.showText;

import java.nio.file.Path;
import java.time.Duration;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -58,15 +59,15 @@ public interface Config {
* @return A path to a map pool, or null for no map pools.
*/
@Nullable
String getMapPoolFile();
Path getMapPoolFile();

/**
* Gets a path to the includes directory.
*
* @return A path to the includes directory, or null for none.
*/
@Nullable
String getIncludesDirectory();
Path getIncludesDirectory();

/**
* Gets a duration to wait before starting a match.
Expand Down Expand Up @@ -207,6 +208,13 @@ public interface Config {
*/
boolean showTabList();

/**
* Gets whether the tab list should be resized to 4 rows for 1.7 players.
*
* @return If the tab list will be resized.
*/
boolean resizeTabList();

/**
* Gets whether the tab list is should show real ping.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import tc.oc.pgm.util.block.BlockStates;
import tc.oc.pgm.util.event.GeneralizedEvent;
import tc.oc.pgm.util.event.entity.ExplosionPrimeByEntityEvent;
import tc.oc.pgm.util.nms.NMSHacks;

/** Called when a {@link Block} transforms from one {@link BlockState} to another. */
public class BlockTransformEvent extends GeneralizedEvent {
Expand Down Expand Up @@ -97,8 +98,7 @@ public final BlockState getNewState() {
return newState;
} else {
final BlockState state = newState.getBlock().getState();
state.setType(drops.replacement.getItemType());
state.setData(drops.replacement);
NMSHacks.setBlockStateData(state, drops.replacement);
return state;
}
}
Expand Down
9 changes: 4 additions & 5 deletions core/src/main/java/tc/oc/pgm/api/map/Gamemode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
public enum Gamemode {
ATTACK_DEFEND("ad", "Attack/Defend", "A/D"),
ARCADE("arcade", "Arcade", "Arcade"),
BEDWARS("bedwars", "Bedwars", "Bedwars"),
BEDWARS("bedwars", "Bed Wars", "Bed Wars"),
BLITZ("blitz", "Blitz", "Blitz"),
BLITZ_RAGE("br", "Blitz: Rage", "Blitz: Rage"),
BRIDGE("bridge", "Bridge", "Bridge"),
CAPTURE_THE_FLAG("ctf", "Capture The Flag", "CTF"),
CAPTURE_THE_FLAG("ctf", "Capture the Flag", "CTF"),
CONTROL_THE_POINT("cp", "Control the Point", "CP"),
CAPTURE_THE_WOOL("ctw", "Capture the Wool", "CTW"),
DESTROY_THE_CORE("dtc", "Destoy the Core", "DTC"),
DESTROY_THE_CORE("dtc", "Destroy the Core", "DTC"),
DESTROY_THE_MONUMENT("dtm", "Destroy the Monument", "DTM"),
FREE_FOR_ALL("ffa", "Free for All", "FFA"),
FLAG_FOOTBALL("ffb", "Flag Football", "FFB"),
Expand All @@ -24,8 +24,7 @@ public enum Gamemode {
SCOREBOX("scorebox", "Scorebox", "Scorebox"),
SKYWARS("skywars", "Skywars", "Skywars"),
SURVIVAL_GAMES("sg", "Survival Games", "SG"),
DEATHMATCH("tdm", "Deathmatch", "TDM"),
OBJECTIVES("obj", "Objectives", "Objectives");
DEATHMATCH("tdm", "Deathmatch", "TDM");

private final String id;

Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/tc/oc/pgm/api/map/MapContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import tc.oc.pgm.api.module.ModuleContext;

/** A {@link MapInfo} that is "loaded" with its {@link MapModule}s and a {@link MapSource}. */
public interface MapContext extends MapInfo, ModuleContext<MapModule> {
public interface MapContext extends ModuleContext<MapModule> {

/**
* Get a {@link MapSource} to access the maps's files.
* Get an immutable {@link MapInfo} which doesn't hold strong references to the context.
*
* @return A {@link MapSource}.
* @return A {@link MapInfo} for this context.
*/
MapSource getSource();
MapInfo getInfo();
}
26 changes: 23 additions & 3 deletions core/src/main/java/tc/oc/pgm/api/map/MapInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ public interface MapInfo extends Comparable<MapInfo>, Cloneable {
*/
String getId();

/**
* The map variant this info represents
*
* @return A variant for the map, if any.
*/
@Nullable
String getVariant();

/** @return the subfolder in which the world is in, or null for the parent folder */
@Nullable
String getWorldFolder();

/**
* Get the proto of the map's {@link org.jdom2.Document}.
*
Expand Down Expand Up @@ -157,11 +169,19 @@ default String getStyledNameLegacy(MapNameStyle style, @Nullable CommandSender s
boolean getFriendlyFire();

/**
* Create an immutable copy of this info.
* Get a {@link MapSource} to access the maps's files.
*
* @return A {@link MapSource}.
*/
MapSource getSource();

/**
* Get the {@link MapContext} for this map, it may be null if the map unloaded
*
* @return A cloned {@link MapInfo}.
* @return A {@link MapContext} for this map, or null if unloaded.
*/
MapInfo clone();
@Nullable
MapContext getContext();

@Override
default int compareTo(MapInfo o) {
Expand Down
Loading

0 comments on commit e52095a

Please sign in to comment.