Skip to content

Commit

Permalink
Add PAPI support and more styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Efnilite committed Jan 3, 2021
1 parent 7197dd0 commit 0560792
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 67 deletions.
26 changes: 18 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,39 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.9</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api-v1164</artifactId>
<artifactId>spigot-api</artifactId>
<version>1.16.4-R0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/spigot-1.16.4.jar</systemPath>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api-v1163</artifactId>
<artifactId>spigot-api-v163</artifactId>
<version>1.16.3-R0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/spigot-1.16.3.jar</systemPath>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/Vault.jar</systemPath>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
Expand Down
36 changes: 18 additions & 18 deletions src/main/java/dev/efnilite/witp/ParkourPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public ParkourPlayer(@NotNull Player player, int highScore, String time, String

player.setPlayerTime(getTime(time), false);
WITP.getDivider().generate(this);
if (showDeathMsg) {
if (showDeathMsg && ParkourGenerator.Configurable.SCOREBOARD) {
updateScoreboard();
}
if (player.isOp() && WITP.isOutdated) {
Expand Down Expand Up @@ -196,7 +196,7 @@ public void menu() {
InventoryBuilder builder3 = new InventoryBuilder(this, 3, "Time").open();

if (WITP.getConfiguration().getFile("config").getBoolean("styles.enabled")) {
builder.setItem(10, new ItemBuilder(Material.END_STONE, "&a&lParkour style")
builder.setItem(9, new ItemBuilder(Material.END_STONE, "&a&lParkour style")
.setLore("&7The style of your parkour.", "&7(which blocks will be used)", "", "&7Currently: &a" + style).build(), (t, e) -> {
List<String> styles = Util.getNode(WITP.getConfiguration().getFile("config"), "styles.list");
if (styles == null) {
Expand Down Expand Up @@ -226,7 +226,7 @@ public void menu() {
builder2.build();
});
}
builder.setItem(11, new ItemBuilder(Material.GLASS, "&a&lLead")
builder.setItem(10, new ItemBuilder(Material.GLASS, "&a&lLead")
.setLore("&7How many blocks will", "&7be generated ahead of you.", "", "&7Currently: &a" + blockLead + " blocks").build(), (t, e) -> {
for (int i = 10; i < 17; i++) {
builder1.setItem(i, new ItemBuilder(Material.PAPER, "&b&l" + (i - 9) + " block(s)").build(), (t2, e2) -> {
Expand All @@ -239,7 +239,7 @@ public void menu() {
builder1.setItem(26, new ItemBuilder(Material.ARROW, "&c&lClose").build(), (t2, e2) -> player.closeInventory());
builder1.build();
});
builder.setItem(12, new ItemBuilder(Material.CLOCK, "&a&lTime")
builder.setItem(11, new ItemBuilder(Material.CLOCK, "&a&lTime")
.setLore("&7The time of day.", "", "&7Currently: &a" + time.toLowerCase()).build(), (t, e) -> {
List<String> times = Arrays.asList("Day", "Noon", "Dawn", "Night", "Midnight");
int i = 11;
Expand All @@ -261,7 +261,7 @@ public void menu() {
Material difficulty = useDifficulty ? Material.GREEN_WOOL : Material.RED_WOOL;
String difficultyString = Boolean.toString(useDifficulty);
String difficultyValue = Util.normalizeBoolean(Util.colorBoolean(difficultyString));
builder.setItem(13, new ItemBuilder(difficulty, "&a&lUse difficulty")
builder.setItem(12, new ItemBuilder(difficulty, "&a&lUse difficulty")
.setLore("&7If enabled having a higher score will mean", "&7the parkour becomes more difficult.", "",
"&7Currently: " + difficultyValue).build(), (t2, e2) -> {
useDifficulty = !useDifficulty;
Expand Down Expand Up @@ -304,26 +304,26 @@ public void menu() {
String specialString = Boolean.toString(useSpecial);
String specialValue = Util.normalizeBoolean(Util.colorBoolean(specialString));
builder.setItem(16, new ItemBuilder(special, "&a&lUse special blocks")
.setLore("&7If enabled uses special blocks.", "",
.setLore("&7If enabled uses special blocks like ice and slabs.", "",
"&7Currently: " + specialValue).build(), (t2, e2) -> {
useSpecial = !useSpecial;
send("&7You changed your usage of special blocks to " +
Util.normalizeBoolean(Util.colorBoolean(Util.reverseBoolean(specialString))));
saveStats();
player.closeInventory();
});
// Material structures = useStructures ? Material.GREEN_WOOL : Material.RED_WOOL;
// String structuresString = Boolean.toString(useStructures);
// String structuresValue = Util.normalizeBoolean(Util.colorBoolean(useStructures));
// builder.setItem(15, new ItemBuilder(structures, "&a&lUse structures")
// .setLore("&7If enabled static structures", "&7will appear throughout the parkour.", "",
// "&7Currently: " + structuresValue).build(), (t2, e2) -> {
// useStructures = !useStructures;
// send("&7You changed your changed your usage of structures to " +
// Util.normalizeBoolean(Util.colorBoolean(Util.reverseBoolean(structuresString))));
// saveStats();
// player.closeInventory();
// });
Material structures = useStructure ? Material.GREEN_WOOL : Material.RED_WOOL;
String structuresString = Boolean.toString(useStructure);
String structuresValue = Util.normalizeBoolean(Util.colorBoolean(structuresString));
builder.setItem(17, new ItemBuilder(structures, "&a&lUse structures")
.setLore("&7If enabled static structures", "&7will appear throughout the parkour.", "",
"&7Currently: " + structuresValue).build(), (t2, e2) -> {
useStructure = !useStructure;
send("&7You changed your usage of structures to " +
Util.normalizeBoolean(Util.colorBoolean(Util.reverseBoolean(structuresString))));
saveStats();
player.closeInventory();
});
builder.setItem(26, new ItemBuilder(Material.BARRIER, "&4&lQuit").build(), (t2, e2) -> {
try {
ParkourPlayer.unregister(this, true);
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/dev/efnilite/witp/WITP.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.efnilite.witp.command.MainCommand;
import dev.efnilite.witp.generator.ParkourGenerator;
import dev.efnilite.witp.generator.subarea.SubareaDivider;
import dev.efnilite.witp.hook.PlaceholderHook;
import dev.efnilite.witp.util.Configuration;
import dev.efnilite.witp.util.Util;
import dev.efnilite.witp.util.Verbose;
Expand Down Expand Up @@ -68,6 +69,9 @@ public void onEnable() {
if (configuration.getFile("config").getBoolean("metrics")) {
new Metrics(this, 9272);
}
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
new PlaceholderHook().register();
}

ParkourGenerator.Configurable.init();
this.getServer().getPluginManager().registerEvents(this, this);
Expand All @@ -80,7 +84,7 @@ public void onEnable() {
public void run() {
checker.check();
}
}, 20 * 60 * 20);
}, 30 * 60 * 20);
}

private void addCommand(String name, BukkitCommand wrapper) {
Expand Down
46 changes: 30 additions & 16 deletions src/main/java/dev/efnilite/witp/generator/ParkourGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public ParkourGenerator(ParkourPlayer player) {
this.borderOffset = Configurable.BORDER_SIZE / 2.0;
this.stopped = false;
this.player = player;
this.structureCooldown = 30;
this.structureCooldown = 20;
this.lastSpawn = player.getPlayer().getLocation().clone();
this.lastPlayer = lastSpawn.clone();
this.distanceChances = new HashMap<>();
Expand Down Expand Up @@ -131,10 +131,10 @@ public void run() {
// Structure deletion check
if (structureBlocks.contains(current) && current.getType() == Material.RED_WOOL && !deleteStructure) {
score += 10;
if (player.showDeathMsg) {
if (player.showDeathMsg && Configurable.SCOREBOARD) {
player.updateScoreboard();
}
structureCooldown = 30;
structureCooldown = 20;
generateNext(player.blockLead);
deleteStructure = true;
return;
Expand All @@ -150,16 +150,18 @@ public void run() {
totalScore++;

// Rewards
if (Configurable.REWARDS && totalScore % Configurable.REWARDS_INTERVAL == 0 && Configurable.REWARDS_COMMAND != null) {
Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), Configurable.REWARDS_COMMAND);
player.send(Configurable.REWARDS_MESSAGE);
if (Configurable.REWARDS && totalScore % Configurable.REWARDS_INTERVAL == 0) {
if (Configurable.REWARDS_COMMAND != null) {
Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), Configurable.REWARDS_COMMAND);
}
if (Configurable.REWARDS_MONEY != 0) {
Util.depositPlayer(player.getPlayer(), Configurable.REWARDS_MONEY);
}
player.send(Configurable.REWARDS_MESSAGE);
}

new PlayerScoreEvent(player).call();
if (player.showDeathMsg) {
if (player.showDeathMsg && Configurable.SCOREBOARD) {
player.updateScoreboard();
}
List<String> locations = new ArrayList<>(buildLog.keySet());
Expand All @@ -185,7 +187,7 @@ public void run() {
}
time = stopwatch.toString();
player.getPlayer().setSaturation(20);
if (player.showDeathMsg) {
if (player.showDeathMsg && Configurable.SCOREBOARD) {
player.updateScoreboard();
}
}
Expand All @@ -209,7 +211,7 @@ public void reset(boolean regenerate) {
for (String s : buildLog.keySet()) {
Util.parseLocation(s).getBlock().setType(Material.AIR);
}
structureCooldown = 30;
structureCooldown = 20;
buildLog.clear();
player.getPlayer().teleport(playerSpawn);
if (player.showDeathMsg) {
Expand Down Expand Up @@ -412,7 +414,6 @@ public void generateNext() {
List<Block> possible = getPossible(gap - height, height);
if (possible.size() == 0) {
lastSpawn = local;
generateNext();
return;
}

Expand All @@ -436,17 +437,30 @@ public void generateNext() {
List<File> files = Arrays.asList(folder.listFiles((dir, name) -> name.contains("parkour-")));
File structure = files.get(random.nextInt(files.size() - 1));

structureCooldown = 30;
structureCooldown = 20;
int gapStructure = distanceChances.get(random.nextInt(distanceChances.size())) + 1;

Location local2 = lastSpawn.clone();
List<Block> possibleStructure = getPossible(gapStructure, 0);
if (possibleStructure.size() == 0) {
lastSpawn = local2;
return;
}
Block chosenStructure = possibleStructure.get(random.nextInt(possibleStructure.size()));

StructureData data = WITP.getVersionManager().placeAt(structure, chosenStructure.getLocation(), heading);
structureBlocks = new ArrayList<>(data.blocks);
structureBlocks = data.blocks;
lastSpawn = data.end.clone();

// if something during the pasting was set to air
List<String> locations = new ArrayList<>(buildLog.keySet());
int index = buildLog.get(Util.toString(lastPlayer, false));
for (int i = 0; i < index; i++) {
Block block = Util.parseLocation(locations.get(i)).getBlock();
if (!structureBlocks.contains(block) && block.getType() == Material.AIR) {
block.setType(player.randomMaterial());
}
}
break;
}

Expand Down Expand Up @@ -540,10 +554,6 @@ public boolean isNearBorder(Vector vector) {
return Math.abs(borderOffset - Math.abs(vector.getX())) < 25 || Math.abs(borderOffset - Math.abs(vector.getZ())) < 25;
}

public boolean isNearIsland(Vector vector) {
return vector.distance(playerSpawn.toVector()) < 50;
}

/**
* Class for variables required in generating without accessing the file a lot (constants)
*/
Expand Down Expand Up @@ -581,6 +591,8 @@ public static class Configurable {
public static int SOUND_PITCH;
public static Particle PARTICLE_TYPE;

public static boolean SCOREBOARD;

// Advanced settings
public static double BORDER_SIZE;
public static int GENERATOR_CHECK;
Expand Down Expand Up @@ -629,6 +641,8 @@ public static void init() {
REWARDS_MESSAGE = null;
}

SCOREBOARD = config.getBoolean("scoreboard.enabled");

SOUND_TYPE = Sound.valueOf(config.getString("particles.sound-type").toUpperCase());
SOUND_PITCH = config.getInt("particles.sound-pitch");
PARTICLE_TYPE = Particle.valueOf(config.getString("particles.particle-type").toUpperCase());
Expand Down
72 changes: 72 additions & 0 deletions src/main/java/dev/efnilite/witp/hook/PlaceholderHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package dev.efnilite.witp.hook;

import dev.efnilite.witp.ParkourPlayer;
import dev.efnilite.witp.WITP;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public class PlaceholderHook extends PlaceholderExpansion {

@Override
public @NotNull String getIdentifier() {
return "witp";
}

@Override
public @NotNull String getAuthor() {
return "Efnilite";
}

@Override
public boolean canRegister(){
return true;
}


@Override
public boolean persist(){
return true;
}

@Override
public @NotNull String getVersion() {
return WITP.getInstance().getDescription().getVersion();
}

@Override
public String onPlaceholderRequest(Player player, @NotNull String params) {
if (player == null) {
return "player doesn't exist";
}
ParkourPlayer pp = ParkourPlayer.getPlayer(player);
if (pp == null) {
return "player is not registered";
}

switch (params) {
case "highscore":
case "high_score":
return Integer.toString(pp.highScore);
case "score":
case "current_score":
return Integer.toString(pp.getGenerator().score);
case "time":
case "current_time":
return pp.getGenerator().time;
case "version":
case "ver":
return WITP.getInstance().getDescription().getVersion();
case "blocklead":
case "lead":
return Integer.toString(pp.blockLead);
case "style":
return pp.style;
case "time_pref":
case "time_preference":
return pp.time;
}

return null;
}
}
2 changes: 1 addition & 1 deletion src/main/java/dev/efnilite/witp/util/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Configuration(Plugin plugin) {
* Downloads the structures
*/
private void structures() {
if (!(new File(plugin.getDataFolder().toString() + "/structures/spawn-island.nbt").exists())) {
if (!(new File(plugin.getDataFolder().toString() + "/structures/parkour-1.nbt").exists())) {
String[] schematics = new String[] {"spawn-island.nbt"};
File folder = new File(plugin.getDataFolder().toString() + "/structures");
folder.mkdirs();
Expand Down
Loading

0 comments on commit 0560792

Please sign in to comment.