forked from Slimefun/Slimefun4
-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(research): economy unlock research
- Loading branch information
1 parent
baef038
commit 650f47a
Showing
10 changed files
with
526 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuideUnlockMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package io.github.thebusybiscuit.slimefun4.core.guide; | ||
|
||
import io.github.thebusybiscuit.slimefun4.api.researches.Research; | ||
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; | ||
import io.github.thebusybiscuit.slimefun4.integrations.VaultIntegration; | ||
import java.util.Locale; | ||
import javax.annotation.Nonnull; | ||
import org.bukkit.entity.Player; | ||
|
||
/** | ||
* This enum holds the different unlock research modes a {@link SlimefunGuide} can have. | ||
* Each constant corresponds to a research unlock mode and a unlock provider | ||
* | ||
* @author StarWishsama | ||
* @see SlimefunGuide | ||
* @see SlimefunGuideImplementation | ||
* @see SlimefunGuideUnlockProvider | ||
*/ | ||
public enum SlimefunGuideUnlockMode { | ||
/** | ||
* Unlock research by withdrawing player's experience level. | ||
*/ | ||
EXPERIENCE(new SlimefunGuideUnlockProvider() { | ||
@Override | ||
public boolean canUnlock(@Nonnull Research research, @Nonnull Player p) { | ||
return p.getLevel() >= research.getCost(); | ||
} | ||
|
||
@Override | ||
public void processPayment(@Nonnull Research research, @Nonnull Player p) { | ||
p.setLevel(p.getLevel() - research.getCost()); | ||
} | ||
}), | ||
|
||
/** | ||
* Unlock research by withdrawing player's balance. | ||
*/ | ||
ECONOMY(new SlimefunGuideUnlockProvider() { | ||
@Override | ||
public boolean canUnlock(@Nonnull Research research, @Nonnull Player p) { | ||
return VaultIntegration.getPlayerBalance(p) >= research.getCost(); | ||
} | ||
|
||
@Override | ||
public void processPayment(@Nonnull Research research, @Nonnull Player p) { | ||
VaultIntegration.withdrawPlayer(p, research.getCost()); | ||
} | ||
}); | ||
|
||
/** | ||
* Research unlock provider | ||
* <p> | ||
* Process player can unlock research and process research payment. | ||
* | ||
* @see SlimefunGuideUnlockProvider | ||
*/ | ||
@Nonnull | ||
private final SlimefunGuideUnlockProvider unlockProvider; | ||
|
||
SlimefunGuideUnlockMode(@Nonnull SlimefunGuideUnlockProvider unlockProvider) { | ||
this.unlockProvider = unlockProvider; | ||
} | ||
|
||
/** | ||
* Convert string to certain {@link SlimefunGuideUnlockMode}. | ||
* If string is invalid will fall back to default one (player level) | ||
* | ||
* @param s text to validate | ||
* @return {@link SlimefunGuideUnlockMode} | ||
*/ | ||
public static SlimefunGuideUnlockMode check(String s) { | ||
if (s == null) { | ||
return SlimefunGuideUnlockMode.EXPERIENCE; | ||
} | ||
|
||
for (SlimefunGuideUnlockMode value : SlimefunGuideUnlockMode.values()) { | ||
if (value.toString().equalsIgnoreCase(s)) { | ||
return value; | ||
} | ||
} | ||
|
||
return SlimefunGuideUnlockMode.EXPERIENCE; | ||
} | ||
|
||
@Nonnull | ||
public SlimefunGuideUnlockProvider getUnlockProvider() { | ||
return unlockProvider; | ||
} | ||
|
||
public String getTokenName() { | ||
return Slimefun.getLocalization().getMessage("guide.unlock-mode-" + toString().toLowerCase(Locale.ROOT)); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/SlimefunGuideUnlockProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.github.thebusybiscuit.slimefun4.core.guide; | ||
|
||
import io.github.thebusybiscuit.slimefun4.api.researches.Research; | ||
import javax.annotation.Nonnull; | ||
import org.bukkit.entity.Player; | ||
|
||
public interface SlimefunGuideUnlockProvider { | ||
boolean canUnlock(@Nonnull Research research, @Nonnull Player p); | ||
|
||
void processPayment(@Nonnull Research research, @Nonnull Player p); | ||
} |
Oops, something went wrong.