Skip to content

Commit

Permalink
Replace most Easter Egg Hunt references with Treasure Hunt
Browse files Browse the repository at this point in the history
  • Loading branch information
Blitheness committed Oct 13, 2023
1 parent d41694c commit 1d6e778
Show file tree
Hide file tree
Showing 36 changed files with 158 additions and 125 deletions.
6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This plugin is provided free of charge with no guarantees that it will work, and

## Configuration options
```
eggHuntEnabled: false
treasureHuntEnabled: false
apiEndpoint: ''
apikey: ''
hunts:
Expand All @@ -18,19 +18,20 @@ hunts:
enabled: true
```

### eggHuntEnabled
true if the plugin should attempt to initialise and start egg hunts.
false if egg hunts are globally disabled and the plugin should do nothing.
### treasureHuntEnabled
true if the plugin should attempt to initialise and start treasure hunts.
false if treasure hunts are globally disabled and the plugin should do nothing.

### apiEndpoint
URL of API endpoint for keeping track of player scores, without a trailing slash.
_e.g. apiEndpoint: 'https://example.com/egg-hunt-api'_
_e.g. apiEndpoint: 'https://example.com/treasure-hunt-api'_

The data sent in the JSON payload has the following keys:
- uuid (player UUID)
- name (player name)
- egg (name of the item found)
- region (ID of the WorldGuard region the item was found in)
- world (name of world where item was found)

The 'API Key' is sent as a query parameter in the GET request to the endpoint, with a name of 'k'.

Expand All @@ -39,5 +40,5 @@ Token for authenticating your game server against the score tracking API

### hunts
_**World and region names must be written in lowercase letters in config.yml**_
Tree comprising world names, and regions within those worlds where egg hunts are to be configured.
Set 'enabled' _(boolean)_ below a region name to either **true** or **false** to enable or disable an egg hunt in this region.
Tree comprising world names, and regions within those worlds where treasure hunts are to be configured.
Set 'enabled' _(boolean)_ below a region name to either **true** or **false** to enable or disable a treasure hunt in this region.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<modelVersion>4.0.0</modelVersion>

<groupId>us.shirecraft</groupId>
<artifactId>EasterEggHunt</artifactId>
<version>0.4.19</version>
<artifactId>TreasureHunt</artifactId>
<version>0.5.0</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down Expand Up @@ -53,7 +53,7 @@
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.20-R0.1-SNAPSHOT</version>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -65,13 +65,13 @@
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
<version>3.11.50</version>
<version>5.0.47</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api-plugin</artifactId>
<version>2.11.3</version>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package us.shirecraft.easteregghunt;
package us.shirecraft.treasurehunt;

import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
Expand All @@ -21,7 +21,7 @@
import java.util.concurrent.ExecutionException;

public class Hunt {
public Hunt(EasterEggHunt plugin, World world, RegionManager regionManager, ProtectedRegion region, String huntType) {
public Hunt(TreasureHunt plugin, World world, RegionManager regionManager, ProtectedRegion region, String huntType) {
this.plugin = plugin;
this.world = world;
this.region = region;
Expand Down Expand Up @@ -130,7 +130,7 @@ private int getRandom(int min, int max) {
private final ProtectedRegion region;
private final RegionManager regionManager;
private final boolean enabled;
private final EasterEggHunt plugin;
private final TreasureHunt plugin;
private final Random random;
private int randomPointAttempts = 0;
private final int MAX_RANDOM_POINT_ATTEMPTS = 25;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package us.shirecraft.easteregghunt;
package us.shirecraft.treasurehunt;

import org.bukkit.scheduler.BukkitRunnable;

import java.lang.reflect.InvocationTargetException;

public class HuntTask extends BukkitRunnable {

private final EasterEggHunt plugin;
private final Hunt hunt;

public HuntTask(EasterEggHunt plugin, Hunt hunt) {
this.plugin = plugin;
public HuntTask(Hunt hunt) {
this.hunt = hunt;
}

Expand All @@ -24,5 +21,4 @@ public void run() {
e.printStackTrace();
}
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package us.shirecraft.easteregghunt;
package us.shirecraft.treasurehunt;

import org.bukkit.Material;
import org.bukkit.entity.Snowman;
Expand All @@ -8,7 +8,7 @@
import org.bukkit.event.block.EntityBlockFormEvent;

public class SnowTrailListener implements Listener {
public SnowTrailListener(EasterEggHunt plugin) {
public SnowTrailListener(TreasureHunt plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package us.shirecraft.easteregghunt;
package us.shirecraft.treasurehunt;

import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
Expand All @@ -19,15 +18,15 @@
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import us.shirecraft.easteregghunt.christmas.*;
import us.shirecraft.easteregghunt.easter.*;
import us.shirecraft.easteregghunt.halloween.*;
import us.shirecraft.easteregghunt.thanksgiving.*;
import us.shirecraft.treasurehunt.christmas.*;
import us.shirecraft.treasurehunt.easter.*;
import us.shirecraft.treasurehunt.halloween.*;
import us.shirecraft.treasurehunt.thanksgiving.*;

import java.io.IOException;
import java.util.*;

public class EasterEggHunt extends JavaPlugin {
public class TreasureHunt extends JavaPlugin {
@Override
public void onEnable() {
saveDefaultConfig();
Expand All @@ -38,12 +37,12 @@ public void onEnable() {
_tasks = new ArrayList<>();

// Egg hunt enabled?
if(!_config.getBoolean("eggHuntEnabled")) {
if(!_config.getBoolean("treasureHuntEnabled")) {
getLogger().info("Treasure hunts globally disabled in config.yml. Plugin will disable itself.");
getServer().getPluginManager().disablePlugin(this);
} else {
// Initialise egg hunts
new EggListener(this);
new TreasureListener(this);
new SnowTrailListener(this);
initialiseHunts();
}
Expand Down Expand Up @@ -78,7 +77,11 @@ private void initialiseHunts() {
if(!worlds.isEmpty()) {
for (String worldName : worlds) {
// For each world, get the region(s) under it
LinkedHashSet<String> regions = (LinkedHashSet<String>) _config.getConfigurationSection("hunts." + worldName).getKeys(false);
LinkedHashSet<String> regions =
(LinkedHashSet<String>) Objects.requireNonNull(
_config.getConfigurationSection("hunts." + worldName)
)
.getKeys(false);

// Find object for this world
World world = getServer().getWorld(worldName);
Expand All @@ -89,7 +92,7 @@ private void initialiseHunts() {

if(!regions.isEmpty()) {
// Get regions
LinkedHashSet<String> regions_tmp = (LinkedHashSet) regions.clone();
LinkedHashSet<String> regions_tmp = new LinkedHashSet<>(regions);
for (String regionName : regions_tmp) {
// Check if region is enabled in config file
boolean regionEnabled = _config.getBoolean("hunts." + worldName + "." + regionName + ".enabled");
Expand Down Expand Up @@ -203,9 +206,12 @@ private void registerEggs() {

private void startEggHunts() {
for (Hunt hunt : getHunts()) {
Runnable huntTask = new HuntTask(this, hunt);
_tasks.add(this.getServer().getScheduler()
.runTaskTimerAsynchronously(this, huntTask, TASK_DELAY_TICKS, TASK_INTERVAL_TICKS));
Runnable huntTask = new HuntTask(hunt);
_tasks.add(
this.getServer()
.getScheduler()
.runTaskTimerAsynchronously(this, huntTask, TASK_DELAY_TICKS, TASK_INTERVAL_TICKS)
);
getLogger().info("Hunt started: " + hunt);
}
}
Expand Down Expand Up @@ -260,6 +266,7 @@ public void sendToWebServer(Player player, final String eggType, final String re
+ "\"name\":\""+ playerName +"\","
+ "\"egg\":\"" + eggType + "\","
+ "\"region\":\"" + regionName + "\""
+ "\"world\":\"" + worldName + "\""
+ "}";

String endpoint = getConfig().getString("apiEndpoint");
Expand All @@ -281,15 +288,30 @@ public void sendToWebServer(Player player, final String eggType, final String re
}

private FileConfiguration _config;

private WorldGuard _worldGuard;

private RegionContainer _regionContainer;

private ArrayList<Hunt> _hunts;

private ArrayList<BukkitTask> _tasks;

@SuppressWarnings("FieldCanBeLocal")
private HashMap<Class<? extends TreasureItem>, Integer> _treasure;

@SuppressWarnings("FieldCanBeLocal")
private HashMap<Class<? extends TreasureItem>, Float> _data;

private HashMap<Class<? extends TreasureItem>, Float> _balancedData;

private final int TICKS_PER_SECOND = 20; // in an ideal situation

@SuppressWarnings("FieldCanBeLocal")
private final long TASK_DELAY_TICKS = TICKS_PER_SECOND * 3;

@SuppressWarnings("FieldCanBeLocal")
private final long TASK_INTERVAL_TICKS = TICKS_PER_SECOND * 15;

private final String[] VALID_HUNT_TYPES = new String[] {"easter", "halloween", "thanksgiving", "christmas"};
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package us.shirecraft.easteregghunt;
package us.shirecraft.treasurehunt;

import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
Expand All @@ -12,7 +12,7 @@
import java.util.List;
import java.util.UUID;

public class TreasureItem implements Comparable {
public class TreasureItem implements Comparable<TreasureItem> {
public TreasureItem(String name, int value, int frequency) {
setName(name);
setValue(value);
Expand Down Expand Up @@ -52,7 +52,7 @@ public ItemStack getItem() {
_item = new ItemStack(Material.PLAYER_HEAD, 1);

// Create game profile
GameProfile profile = new GameProfile(UUID.fromString(_playerUuid), null);
GameProfile profile = new GameProfile(UUID.fromString(_playerUuid), "unknown");
PropertyMap propertyMap = profile.getProperties();
if (propertyMap == null) {
return _item;
Expand Down Expand Up @@ -91,8 +91,8 @@ public String toString() {
return this._name;
}

public int compareTo(Object o) {
return ((TreasureItem)o)._value > this._value ? -1 : 1;
public int compareTo(TreasureItem o) {
return o._value > this._value ? -1 : 1;
}

private int _value;
Expand Down
Loading

0 comments on commit 1d6e778

Please sign in to comment.