Merge pull request #10 from HyperSMP/multi-version-support-dev

Add backwards compatibility from 1.17+
This commit is contained in:
John Locke 2023-07-30 12:35:02 -04:00 committed by GitHub
commit 375959fb78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 273 additions and 87 deletions

39
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View file

@ -0,0 +1,39 @@
---
name: Bug report
about: Report issues with this plugin
title: "[BUG] Short summary of the issue here"
labels: triage
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Provide a numbered list of steps to reproduce the behavior.
**Expected behavior**
A clear and concise description of what should happen.
**Version Information:**
- Version of this plugin
- Minecraft version [e.g. Minecraft 1.20.2]
- Server software [Bukkit, Paper, Fabric, Purpur, etc.]
If applicable, also attach the following information:
- Any other installed plugins
- Server build [e.g. Paper build #65]
- Minecraft client [e.g. vanilla minecraft]
**Configuration and logs:**
If applicable, attach the `config.yml` and `data.yml` files inside the `/plugins/EggHunt/` directory, which is generated when the plugin is first run.
Also attach any relevant log files.
Do not upload zipped log files (ending in `.gz`), first unzip the log file(s) inside with a utility like (7-zip)[https://www.7-zip.org/].
**Screenshots**
If applicable, attach screenshots to help explain the issue.
**Additional context**
Add any other relevant context about the problem here.

View file

@ -0,0 +1,27 @@
---
name: Feature request
about: Suggest an idea for this project
title: "[Feature Req] Short summary of the request here"
labels: enhancement, triage
assignees: ''
---
Improving player experience is an important focus of this project. However, please note that due to technical and time restrictions, it may not be possible to implement any given feature requests.
See [here](https://github.com/HyperSMP/EggHuntPlugin/projects/1) for this project's to-do list.
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe a good solution**
A clear and concise description of what should happen instead.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.
**Screenshots**
Please attach any relevant screenshots.

View file

@ -19,7 +19,7 @@ A plugin for hunting down the dragon egg and stealing it from other players.
## Customization
This plugin's configuration file (`config.yml`) allows for several gameplay customizations to accomodate different types of servers.
This plugin's configuration file (`config.yml`) allows for several gameplay customizations to accommodate different types of servers.
- The egg can be made invulnerable, or can be set to respawn in The End when it is destroyed
- If set to respawn, the egg can either respawn immediately, or only after the dragon is beaten again
- When the egg teleports, it can become "lost", so it will no longer have an owner until a player finds it

BIN
media/commands.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 KiB

BIN
media/event.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 KiB

BIN
media/explode.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 491 KiB

BIN
media/tracking.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 484 KiB

BIN
media/void.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 400 KiB

30
pom.xml
View file

@ -1,8 +1,15 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>EggHunt</name>
<version>1.1.1</version>
<url>https://github.com/HyperSMP/EggHuntPlugin</url>
<description>Minecraft plugin adding the ability to track and steal the Dragon Egg from other players.</description>
<groupId>io.github.J0hnL0cke</groupId>
<artifactId>EggHunt</artifactId>
<version>1.20.1</version>
<build>
<plugins>
<plugin>
@ -20,7 +27,8 @@
<minimizeJar>true</minimizeJar>
<shadedArtifactAttached>true</shadedArtifactAttached>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
</transformers>
</configuration>
<executions>
@ -32,18 +40,32 @@
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>plugin.yml</include>
<include>config.yml</include>
</includes>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>LATEST</version><!--change this value depending on the version-->
<version>LATEST</version><!--change
this value depending on the version-->
<type>jar</type>
<scope>provided</scope>
</dependency>

View file

@ -43,13 +43,17 @@ public class CommandHandler {
String storageMsg = data.getEggHolderString(); //"is in <x>"
if (data.getEggType() != Egg_Storage_Type.DNE) {
Location origin = null; //get location of player that sent the command for distance calculation
if(sender instanceof Player){
if (sender instanceof Player) {
origin = ((Player) sender).getLocation();
}
String locStr = Announcement.formatLocation(data.getEggLocation(), origin);
sendMessage(sender, String.format("%s %s at %s.", msgStart, storageMsg, locStr));
} else {
sendMessage(sender, String.format("%s %s.", msgStart, storageMsg));
}
} else {
sendMessage(sender, NOT_PERMITTED_MSG);

View file

@ -155,11 +155,23 @@ public class EggDestroyListener implements Listener {
//that means editing the list does not change which blocks are actually affected by the event
//as a workaround, allow egg blocks to be destroyed, but respawn the egg as an item
if (!eggs.isEmpty()) {
if (config.getEggInvulnerable()) {
for (Block egg : eggs) {
EggController.spawnEggItem(egg.getLocation(), config, data);
}
logger.log("Egg overwritten by the end spawn platform, spawning egg item at block location");
} else {
for (Block b : eggs) {
Egg.removeEgg(b); //delete egg
}
log("Dragon egg was replaced");
EggController.eggDestroyed(config, data, logger);
}
}
}
}

View file

@ -6,6 +6,7 @@ import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Entity;
import org.bukkit.scoreboard.Criteria;
import org.bukkit.scoreboard.Criterias;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.RenderType;
import org.bukkit.scoreboard.Score;
@ -15,6 +16,7 @@ import org.bukkit.scoreboard.ScoreboardManager;
import io.github.J0hnL0cke.egghunt.Model.Configuration;
import io.github.J0hnL0cke.egghunt.Model.Data;
import io.github.J0hnL0cke.egghunt.Model.LogHandler;
import io.github.J0hnL0cke.egghunt.Model.Version;
/**
* Handles interactions with the scoreboard api
@ -26,6 +28,7 @@ public class ScoreboardController {
private Data data;
private Configuration config;
private LogHandler logger;
private Version version;
private ScoreboardManager manager;
private Scoreboard board;
private Objective eggMinutes;
@ -34,17 +37,18 @@ public class ScoreboardController {
private static final String EGG_MINUTES_KEY = "eggOwnedMinutes";
private static final String EGG_SECONDS_KEY = "eggOwnedSeconds";
public static ScoreboardController getScoreboardHandler(Data data, Configuration configuration, LogHandler logger) {
public static ScoreboardController getScoreboardHandler(Data data, Configuration configuration, LogHandler logger, Version version) {
if (thisHandler == null) {
thisHandler = new ScoreboardController(data, configuration, logger);
thisHandler = new ScoreboardController(data, configuration, logger, version);
}
return thisHandler;
}
private ScoreboardController(Data data, Configuration config, LogHandler logger) {
private ScoreboardController(Data data, Configuration config, LogHandler logger, Version version) {
this.data = data;
this.config = config;
this.logger = logger;
this.version = version;
if (config.getKeepScore()) {
logger.log("Scorekeeping is enabled, loading scoreboard...");
@ -81,6 +85,10 @@ public class ScoreboardController {
public void updateScores() {
if (config.getKeepScore() && data.getEggType()!= Data.Egg_Storage_Type.DNE) {
logger.log("Updating scoreboard");
if(eggMinutes == null || eggSeconds == null){
logger.warning("Objective does not exist, cannot update scoreboard!");
return;
}
if (data.getEggType() == Data.Egg_Storage_Type.ENTITY) {
Entity eggEntity = data.getEggEntity();
@ -117,18 +125,25 @@ public class ScoreboardController {
}
public Objective getOrMakeObjective(String key, String displayName) {
Objective obj = board.getObjective(key);
if (obj == null) {
logger.info(String.format("No scoreboard objective \"%s\" found, creating new objective", key));
obj = board.registerNewObjective(key, Criteria.DUMMY, displayName, RenderType.INTEGER);
Objective objective = board.getObjective(key);
if (objective == null) {
logger.warning(String.format("No scoreboard objective \"%s\" found, creating new objective", key));
//older versions of the Bukkit API use Criterias instead of Criteria, so handle older versions
if (version.hasCriteria()) {
objective = board.registerNewObjective(key, Criteria.DUMMY, displayName, RenderType.INTEGER);
} else {
@SuppressWarnings("deprecation")
Objective o = board.registerNewObjective(key, "dummy", displayName, RenderType.INTEGER);
objective = o;
}
}
if (!obj.isModifiable()) {
if (!objective.isModifiable()) {
String msg = "Could not modify objective \"%s\"! Make sure objective criteria is set to dummy!";
logger.warning(String.format(msg, obj.getName()));
logger.warning(String.format(msg, objective.getName()));
}
return obj;
return objective;
}
private void addScore(String name, Objective obj, int score) {

View file

@ -0,0 +1,62 @@
package io.github.J0hnL0cke.egghunt.Model;
import org.bukkit.Bukkit;
/**
* Provides functionality related to backwards compatability
*/
public class Version {
private int majorVersion;
private boolean cavesAndCliffsPart1;
private boolean netherUpdate;
public Version() {
//Convert raw version string to major game version
String version = Bukkit.getVersion(); //git-Paper-411 (MC: 1.17.1)
version = version.substring(version.indexOf(":")); //: 1.17.1)
String[] v = version.split("\\."); //[": 1","17","1)"] split at periods, use \\ to escape period in regex
version = v[1]; //17
majorVersion = Integer.parseInt(version);
cavesAndCliffsPart1 = majorVersion >= 17;
netherUpdate = majorVersion >= 16;
}
public boolean hasPortalCreate() {
return majorVersion >= 13;
}
public boolean hasShulkers() {
return majorVersion >= 14;
}
public boolean hasCustomWorlds() {
return cavesAndCliffsPart1;
}
public boolean hasGlowFrames() {
return cavesAndCliffsPart1;
}
public boolean hasBundles() {
return cavesAndCliffsPart1;
}
public boolean hasDragonFight() {
return netherUpdate;
}
public boolean hasLodestone() {
return netherUpdate;
}
public boolean hasAllays() {
return majorVersion >= 1.19;
}
public boolean hasCriteria() {
return majorVersion >= 20;
}
}

View file

@ -19,6 +19,7 @@ import io.github.J0hnL0cke.egghunt.Controller.InventoryListener;
import io.github.J0hnL0cke.egghunt.Model.Configuration;
import io.github.J0hnL0cke.egghunt.Model.Data;
import io.github.J0hnL0cke.egghunt.Model.LogHandler;
import io.github.J0hnL0cke.egghunt.Model.Version;
import io.github.J0hnL0cke.egghunt.Persistence.ConfigFileDAO;
import io.github.J0hnL0cke.egghunt.Persistence.DataFileDAO;
@ -26,6 +27,7 @@ import io.github.J0hnL0cke.egghunt.Persistence.DataFileDAO;
public final class egghunt extends JavaPlugin {
Configuration config;
Data data;
Version version;
CommandHandler commandHandler;
BukkitTask belowWorldTask;
@ -42,11 +44,12 @@ public final class egghunt extends JavaPlugin {
//create model instances using dependency injection
config = new Configuration(new ConfigFileDAO(this));
data = new Data(DataFileDAO.getDataDAO(this, logger), logger);
version = new Version();
logger.setDebug(config.getDebugEnabled());
//create controller instances
ScoreboardController scoreboardController = ScoreboardController.getScoreboardHandler(data, config, logger);
ScoreboardController scoreboardController = ScoreboardController.getScoreboardHandler(data, config, logger, version);
MiscListener miscListener = new MiscListener(logger, config, data);
InventoryListener inventoryListener = new InventoryListener(logger, config, data);
EggDestroyListener destroyListener = new EggDestroyListener(logger, config, data);

View file

@ -1,5 +1,5 @@
#If enabled, logs extra debugging information to the console. This information will appear in logs regardless of debug setting.
debug: true
debug: false
#Name of your end world, usually to "world_the_end" on spigot
end: world_the_end

View file

@ -1,10 +1,12 @@
name: EggHunt
main: io.github.J0hnL0cke.egghunt.egghunt
website: https://github.com/HyperSMP/EggHuntPlugin
version: 1.20.1
api-version: '1.20'
#See pom.xml for this information
name: ${project.name}
website: ${project.url}
version: ${project.version}
description: ${project.description}
api-version: '1.17'
author: J0hnL0cke
main: io.github.J0hnL0cke.egghunt.egghunt
commands:
locateegg:
description: Gives the current coordinates of the dragon egg