Skip to content

Commit

Permalink
Add PAPI Support.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Mar 8, 2024
1 parent c635bc2 commit f28d03e
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 1 deletion.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<id>litecommands-repo</id>
<url>https://repo.panda-lang.org/releases</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -43,6 +47,12 @@
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.3</version>
<scope>provided</scope>
</dependency>
<!-- <dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/me/lokka30/phantomworlds/PhantomWorlds.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import me.lokka30.phantomworlds.managers.FileManager;
import me.lokka30.phantomworlds.managers.WorldManager;
import me.lokka30.phantomworlds.misc.CompatibilityChecker;
import me.lokka30.phantomworlds.misc.PAPIHook;
import me.lokka30.phantomworlds.misc.UpdateCheckerResult;
import me.lokka30.phantomworlds.misc.Utils;
import me.lokka30.phantomworlds.scheduler.BackupScheduler;
Expand Down Expand Up @@ -129,6 +130,12 @@ public void onEnable() {

instance = this;

if(Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
new PAPIHook().register();
} else {

}

createTabs.addAll(generateCreateSuggestions());

QuickTimer timer = new QuickTimer(TimeUnit.MILLISECONDS);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package me.lokka30.phantomworlds.listeners.plugin;
/*
* Phantom Worlds
* Copyright (C) 2023 - 2024 Daniel "creatorfromhell" Vidmar
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import me.lokka30.phantomworlds.misc.PAPIHook;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginEnableEvent;

/**
* PluginEnableListener
*
* @author creatorfromhell
* @since 2.0.5.0
*/
public class PluginEnableListener implements Listener {

@EventHandler
public void onEvent(PluginEnableEvent event) {
if(event.getPlugin().getName().equalsIgnoreCase("placeholderapi")) {
new PAPIHook().register();
}
}
}
69 changes: 68 additions & 1 deletion src/main/java/me/lokka30/phantomworlds/misc/PAPIHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,78 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* PAPIHook
*
* @author creatorfromhell
* @since 2.0.5.0
*/
public class PAPIHook {
public class PAPIHook extends PlaceholderExpansion {
@Override
public @NotNull String getIdentifier() {
return "pw";
}

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

@Override
public @NotNull String getVersion() {
return "2.0.8";
}

@Override
public @Nullable String onPlaceholderRequest(Player player, @NotNull String params) {
if(player == null) {
return null;
}

final String[] args = params.split("_");

//%pw_name%
if(args[0].equalsIgnoreCase("name")) {

return player.getWorld().getName();
}

//%pw_time%
if(args[0].equalsIgnoreCase("time")) {

return String.valueOf(player.getWorld().getTime());
}

//%pw_period%
if(args[0].equalsIgnoreCase("period")) {
return period(player.getWorld().getTime());
}

//%pw_environment%
if(args[0].equalsIgnoreCase("environment")) {
return player.getWorld().getEnvironment().name();
}

return null;
}

private String period(final long time) {
if(time >= 6000 && time <= 11999) {
return "noon";
} else if(time >= 12000 && time <= 12999) {
return "sunset";
} else if(time >= 13000 && time <= 17999) {
return "night";
} else if(time >= 18000 && time <= 22999) {
return "midnight";
} else if(time >= 23000 || time <= 999) {
return "sunrise";
}
return "day";
}
}

0 comments on commit f28d03e

Please sign in to comment.