Progress but no progress?

This commit is contained in:
destro174
2021-12-25 18:05:07 +01:00
parent 95d219d546
commit 2c0d255219
29 changed files with 599 additions and 155 deletions
+21 -1
View File
@@ -1,10 +1,30 @@
plugins {
`maven-publish`
id("com.github.johnrengelman.shadow")
}
dependencies {
// API
implementation(project(":boosters-api"))
// Galaxy
compileOnly("com.alttd:galaxy-api:1.17.1-R0.1-SNAPSHOT")
compileOnly("com.alttd:Galaxy-API:1.18.1-R0.1-SNAPSHOT")
// MyPet
compileOnly("de.keyle:mypet:3.12-SNAPSHOT")
// mcMMO
compileOnly("com.gmail.nossr50.mcMMO:mcMMO:2.1.206")
compileOnly("com.sk89q.worldguard:worldguard-core:7.0.4") {
exclude("com.google.code.findbugs")
}
}
tasks {
shadowJar {
archiveFileName.set("${project.name}-${project.version}.jar")
}
build {
dependsOn(shadowJar)
}
}
@@ -1,6 +0,0 @@
package com.alttd.boosters;
import com.alttd.boosters.api.BoosterAPI;
public class BoosterAPIProvider implements BoosterAPI {
}
@@ -1,6 +1,13 @@
package com.alttd.boosters;
import com.alttd.boosters.api.BoosterAPI;
import com.alttd.boosterapi.BoosterAPI;
import com.alttd.boosterapi.BoosterImplementation;
import com.alttd.boosterapi.config.Config;
import com.alttd.boosters.listeners.MCmmoListener;
import com.alttd.boosters.listeners.MyPetListener;
import com.alttd.boosters.listeners.PhantomSpawnListener;
import com.alttd.boosters.listeners.PluginMessage;
import com.alttd.boosters.managers.BoosterManager;
import org.bukkit.command.CommandExecutor;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
@@ -9,16 +16,29 @@ public final class BoostersPlugin extends JavaPlugin {
private static BoostersPlugin instance;
private static BoosterAPI boosterAPI;
private static BoosterManager boosterManager;
@Override
public void onEnable() {
instance = this;
boosterAPI = new BoosterAPIProvider();
boosterAPI = new BoosterImplementation();
boosterManager = new BoosterManager();
if (getServer().getPluginManager().isPluginEnabled("MyPet")) {
registerListener(new MyPetListener());
}
if (getServer().getPluginManager().isPluginEnabled("mcMMO")) {
registerListener(new MCmmoListener());
}
registerListener(new PhantomSpawnListener());
getServer().getMessenger().registerOutgoingPluginChannel(this, Config.pluginMessageChannel);
getServer().getMessenger().registerIncomingPluginChannel(this, Config.pluginMessageChannel, new PluginMessage());
}
@Override
public void onDisable() {
instance = null;
boosterAPI = null;
}
public void registerListener(Listener... listeners) {
@@ -38,4 +58,8 @@ public final class BoostersPlugin extends JavaPlugin {
public BoosterAPI getAPI() {
return boosterAPI;
}
public BoosterManager getBoosterManager() {
return boosterManager;
}
}
@@ -1,10 +1,10 @@
package com.alttd.boosters.data;
import com.alttd.boosters.api.BoosterType;
import com.alttd.boosterapi.BoosterType;
import java.util.UUID;
public class Booster implements com.alttd.boosters.api.Booster {
public class Booster implements com.alttd.boosterapi.Booster {
private UUID uuid;
private String activator;
@@ -114,4 +114,16 @@ public class Booster implements com.alttd.boosters.api.Booster {
}
@Override
public void finish() {
}
@Override
public boolean finished() {
return false;
}
}
@@ -0,0 +1,23 @@
package com.alttd.boosters.listeners;
import com.alttd.boosterapi.Booster;
import com.alttd.boosterapi.BoosterType;
import com.alttd.boosters.BoostersPlugin;
import com.alttd.boosters.managers.BoosterManager;
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class MCmmoListener implements Listener {
@EventHandler
public void onMcMMOExperienceEvent(McMMOPlayerXpGainEvent event) {
BoosterManager bm = BoostersPlugin.getInstance().getBoosterManager();
if(bm.isBoosted(BoosterType.MCMMO)) {
Booster b = bm.getBoosted(BoosterType.MCMMO);
int multiplier = b.getMultiplier();
event.setRawXpGained(event.getRawXpGained() * multiplier);
}
}
// TODO : add individual mcmmo skill boosters
}
@@ -0,0 +1,22 @@
package com.alttd.boosters.listeners;
import com.alttd.boosterapi.Booster;
import com.alttd.boosterapi.BoosterType;
import com.alttd.boosters.BoostersPlugin;
import com.alttd.boosters.managers.BoosterManager;
import de.Keyle.MyPet.api.event.MyPetExpEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class MyPetListener implements Listener {
@EventHandler
public void onMyPetExpEvent(MyPetExpEvent event) {
BoosterManager bm = BoostersPlugin.getInstance().getBoosterManager();
if(bm.isBoosted(BoosterType.MYPET)) {
Booster b = bm.getBoosted(BoosterType.MYPET);
int multiplier = b.getMultiplier();
event.setExp(event.getExp() * multiplier);
}
}
}
@@ -0,0 +1,22 @@
package com.alttd.boosters.listeners;
import com.alttd.boosterapi.BoosterType;
import com.alttd.boosters.BoostersPlugin;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class PhantomSpawnListener implements Listener {
@EventHandler
public void onPhantomPreSpawn(com.destroystokyo.paper.event.entity.PhantomPreSpawnEvent event) {
Entity spawningEntity = event.getSpawningEntity();
if (spawningEntity instanceof Player player
&& BoostersPlugin.getInstance().getBoosterManager().isBoosted(BoosterType.PHANTOM)) {
event.setCancelled(true);
event.setShouldAbortSpawn(true);
}
}
}
@@ -0,0 +1,22 @@
package com.alttd.boosters.listeners;
import com.alttd.boosterapi.config.Config;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
public class PluginMessage implements PluginMessageListener {
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] bytes) {
if(!channel.equals(Config.pluginMessageChannel)) return;
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
String subChannel = in.readUTF();
// Listen to plugin messages from velocity to either activate or deactive a booster.
switch (subChannel) {
default:
break;
}
}
}
@@ -0,0 +1,29 @@
package com.alttd.boosters.managers;
import com.alttd.boosterapi.Booster;
import com.alttd.boosterapi.BoosterType;
import java.util.List;
public class BoosterManager {
private static List<Booster> activeBoosters;
public boolean isBoosted(BoosterType type) {
for (Booster b : activeBoosters) {
if (b.getType() == type && b.isActive()) {
return true;
}
}
return false;
}
public Booster getBoosted(BoosterType type) {
for (Booster b : activeBoosters) {
if (b.getType() == type && b.isActive()) {
return b;
}
}
return null;
}
}