Skip to content

Commit dc04725

Browse files
Merge pull request #418 from VolmitSoftware/Development
Development
2 parents a353be7 + ff7a198 commit dc04725

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1349
-1539
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ plugins {
2323
id "de.undercouch.download" version "5.0.1"
2424
}
2525

26-
version '1.8.0-1.19.4'
26+
version '1.9.0-1.19.4'
2727
def nmsVersion = "1.19.4" //[NMS]
2828
def apiVersion = '1.19'
2929
def specialSourceVersion = '1.11.0' //[NMS]

src/main/java/com/volmit/adapt/Adapt.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import java.io.File;
5151
import java.io.InputStreamReader;
5252
import java.net.URL;
53+
import java.text.MessageFormat;
5354
import java.util.HashMap;
5455
import java.util.Map;
5556
import java.util.Random;
@@ -107,26 +108,23 @@ public static void printInformation() {
107108

108109
@SneakyThrows
109110
public static void autoUpdateCheck() {
110-
try {
111-
URL url = new URL("https://raw.githubusercontent.com/VolmitSoftware/Adapt/main/build.gradle");
112-
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
113-
String inputLine;
111+
try (BufferedReader in = new BufferedReader(new InputStreamReader(new URL("https://raw.githubusercontent.com/VolmitSoftware/Adapt/main/build.gradle").openStream()))) {
114112
info("Checking for updates...");
113+
String inputLine;
115114
while ((inputLine = in.readLine()) != null) {
116115
if (inputLine.contains("version '")) {
117-
String version = inputLine.remove("version '").remove("'").remove("// Needs to be version specific").remove(" ");
116+
String version = inputLine.replace("version '", "").replace("'", "").replace("// Needs to be version specific", "").replace(" ", "");
118117
if (instance.getDescription().getVersion().contains("development")) {
119118
info("Development build detected. Skipping update check.");
120119
return;
121120
} else if (!version.equals(instance.getDescription().getVersion())) {
122-
info("Please update your Adapt plugin to the latest version! (Current: " + instance.getDescription().getVersion() + " Latest: " + version + ")");
121+
info(MessageFormat.format("Please update your Adapt plugin to the latest version! (Current: {0} Latest: {1})", instance.getDescription().getVersion(), version));
123122
} else {
124123
info("You are running the latest version of Adapt!");
125124
}
126125
break;
127126
}
128127
}
129-
in.close();
130128
} catch (Throwable e) {
131129
error("Failed to check for updates.");
132130
}

src/main/java/com/volmit/adapt/api/adaptation/Adaptation.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ default boolean setStorage(Player p, String key, Object value) {
7777
}
7878

7979
default boolean canUse(AdaptPlayer player) {
80+
Adapt.verbose("Checking if " + player.getPlayer().getName() + " can use " + getName() + "...");
8081
AdaptAdaptationUseEvent e = new AdaptAdaptationUseEvent(!Bukkit.isPrimaryThread(), player, this);
8182
Bukkit.getServer().getPluginManager().callEvent(e);
8283
return (!e.isCancelled());
@@ -86,6 +87,15 @@ default boolean canUse(Player player) {
8687
return canUse(getPlayer(player));
8788
}
8889

90+
default boolean hasBlacklistPermission(Player p, Adaptation a) {
91+
if (p.isOp()) { // If the player is an operator, bypass the permission check
92+
return false;
93+
}
94+
String blacklistPermission = "adapt.blacklist." + a.getName().replaceAll("-", "");
95+
Adapt.verbose("Checking if player " + p.getName() + " has blacklist permission " + blacklistPermission);
96+
97+
return p.hasPermission(blacklistPermission);
98+
}
8999

90100
default String getStorageString(Player p, String key, String defaultValue) {
91101
return getStorage(p, key, defaultValue);
@@ -235,6 +245,15 @@ default boolean hasAdaptation(Player p) {
235245
Adapt.verbose("Player " + p.getName() + " don't have adaptation - " + this.getName() + " permission.");
236246
return false;
237247
}
248+
249+
if (hasBlacklistPermission(p, this)) {
250+
Adapt.verbose("Player " + p.getName() + " has blacklist permission for adaptation " + this.getName());
251+
return false;
252+
}
253+
if (!canUse(p)) {
254+
Adapt.verbose("Player " + p.getName() + " can't use adaptation, This is an API restriction" + this.getName());
255+
return false;
256+
}
238257
Adapt.verbose("Player " + p.getName() + " used adaptation " + this.getName());
239258
return true;
240259
} else {

src/main/java/com/volmit/adapt/api/skill/SimpleSkill.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import art.arcane.amulet.io.FileWatcher;
2222
import com.google.gson.Gson;
2323
import com.volmit.adapt.Adapt;
24+
import com.volmit.adapt.AdaptConfig;
2425
import com.volmit.adapt.api.adaptation.Adaptation;
2526
import com.volmit.adapt.api.advancement.AdaptAdvancement;
2627
import com.volmit.adapt.api.recipe.AdaptRecipe;
@@ -34,8 +35,12 @@
3435
import com.volmit.adapt.util.advancements.advancement.AdvancementVisibility;
3536
import lombok.Data;
3637
import lombok.EqualsAndHashCode;
38+
import org.bukkit.GameMode;
3739
import org.bukkit.Material;
40+
import org.bukkit.World;
3841
import org.bukkit.entity.EntityType;
42+
import org.bukkit.entity.Player;
43+
import org.bukkit.event.Cancellable;
3944

4045
import java.io.File;
4146
import java.io.IOException;
@@ -152,13 +157,45 @@ public void registerAdvancement(AdaptAdvancement a) {
152157
}
153158

154159
public boolean checkValidEntity(EntityType e) {
155-
// Adapt.verbose("EntityType " + e.name() + "wasChecked");
156160
if (!e.isAlive()) {
157161
return false;
158162
}
159163
return !ItemListings.getInvalidDamageableEntities().contains(e);
160164
}
161165

166+
protected boolean shouldReturnForPlayer(Player p) {
167+
Adapt.verbose("Checking " + p.getName() + " for " + getName());
168+
return !this.isEnabled() || hasBlacklistPermission(p, this) || isWorldBlacklisted(p) || isInCreativeOrSpectator(p);
169+
}
170+
protected void shouldReturnForPlayer(Player p, Runnable r) {
171+
if (shouldReturnForPlayer(p)) {
172+
return;
173+
}
174+
r.run();
175+
}
176+
177+
protected void shouldReturnForPlayer(Player p, Cancellable c, Runnable r) {
178+
if (c.isCancelled()) {
179+
return;
180+
}
181+
if (shouldReturnForPlayer(p)) {
182+
return;
183+
}
184+
r.run();
185+
}
186+
187+
protected boolean shouldReturnForWorld(World world, Skill skill) {
188+
return !skill.isEnabled() || AdaptConfig.get().blacklistedWorlds.contains(world.getName());
189+
}
190+
191+
protected boolean isWorldBlacklisted(Player p) {
192+
return AdaptConfig.get().blacklistedWorlds.contains(p.getWorld().getName());
193+
}
194+
195+
protected boolean isInCreativeOrSpectator(Player p) {
196+
return !AdaptConfig.get().isXpInCreative() && (p.getGameMode().equals(GameMode.CREATIVE) || p.getGameMode().equals(GameMode.SPECTATOR));
197+
}
198+
162199
@Override
163200
public String getDisplayName() {
164201
return displayName == null ? Skill.super.getDisplayName() : (C.RESET + "" + C.BOLD + getColor().toString() + getEmojiName() + " " + displayName);

src/main/java/com/volmit/adapt/api/skill/Skill.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ default void checkStatTrackers(AdaptPlayer player) {
9696

9797
void onRegisterAdvancements(List<AdaptAdvancement> advancements);
9898

99+
default boolean hasBlacklistPermission(Player p, Skill s) {
100+
if (p.isOp()) { // If the player is an operator, bypass the permission check
101+
return false;
102+
}
103+
String blacklistPermission = "adapt.blacklist." + s.getName().replaceAll("-", "");
104+
Adapt.verbose("Checking if player " + p.getName() + " has blacklist permission " + blacklistPermission);
105+
return p.hasPermission(blacklistPermission);
106+
}
107+
99108
default String getDisplayName() {
100109
if (!this.isEnabled()) {
101110
this.unregister();
@@ -194,6 +203,9 @@ default void openGui(Player player) {
194203
int ind = 0;
195204

196205
for (Adaptation i : getAdaptations()) {
206+
if (i.hasBlacklistPermission(player, i)) {
207+
continue;
208+
}
197209
int pos = w.getPosition(ind);
198210
int row = w.getRow(ind);
199211
int lvl = getPlayer(player).getData().getSkillLine(getName()).getAdaptationLevel(i.getName());

src/main/java/com/volmit/adapt/api/world/PlayerSkillLine.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package com.volmit.adapt.api.world;
2020

21+
import com.volmit.adapt.Adapt;
2122
import com.volmit.adapt.AdaptConfig;
2223
import com.volmit.adapt.api.adaptation.Adaptation;
2324
import com.volmit.adapt.api.notification.ActionBarNotification;
@@ -36,7 +37,6 @@
3637
import java.util.HashMap;
3738
import java.util.List;
3839
import java.util.Map;
39-
import java.util.concurrent.TimeUnit;
4040

4141
@Data
4242
@NoArgsConstructor
@@ -67,8 +67,19 @@ public void giveXP(Notifier p, double xp) {
6767
last = M.ms();
6868
if (AdaptConfig.get().isActionbarNotifyXp()) {
6969
p.notifyXP(line, xp);
70-
} else {
71-
// bossbar thing here
70+
}
71+
72+
}
73+
}
74+
75+
public void giveXPFresh(Notifier p, double xp) {
76+
xp = multiplier * xp;
77+
this.xp += xp;
78+
79+
if (p != null) {
80+
last = M.ms();
81+
if (AdaptConfig.get().isActionbarNotifyXp()) {
82+
p.notifyXP(line, xp);
7283
}
7384
}
7485
}
@@ -117,12 +128,11 @@ public void update(AdaptPlayer p, String line, PlayerData data) {
117128
}
118129
}
119130

120-
if (!p.isBusy() && getXp() > XP.getXpForLevel(100)) {
121-
xp = getXp() - XP.getXpForLevel(100);
122-
lastXP = xp;
123-
lastLevel = (int) Math.floor(XP.getLevelForXp(getXp()));
131+
//check if they are exceeding the max level, and just set it to the last level XP and level
132+
if (!p.isBusy() && getXp() > XP.getXpForLevel(AdaptConfig.get().experienceMaxLevel)) {
124133
p.getData().addWisdom();
125-
boost(0.25, (int) TimeUnit.HOURS.toMillis(1));
134+
Adapt.warn("A Player has reached the maximum level of " + AdaptConfig.get().experienceMaxLevel + " and has been granted 1 wisdom, Dropping Level to " + lastLevel);
135+
setXp(XP.getXpForLevel(AdaptConfig.get().experienceMaxLevel -1));
126136
}
127137

128138
double max = 1D + (getLevel() * 0.004);

src/main/java/com/volmit/adapt/api/xp/SkyrimNewtonCurve.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/main/java/com/volmit/adapt/api/xp/WOWNewtonCurve.java

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/main/java/com/volmit/adapt/commands/CommandAdapt.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class CommandAdapt extends MortarCommand {
4242
@Command
4343
private final CommandVerbose verbose = new CommandVerbose();
4444

45+
4546
public CommandAdapt() {
4647
super("adapt", "ada", "a");
4748
this.setDescription("This is the main command for Adapt");

src/main/java/com/volmit/adapt/commands/item/CommandItemExperienceOrb.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ public boolean handle(MortarSender sender, String[] args) {
4141
args.toList().set(0, skill.getName());
4242
giveOrb(sender, args);
4343
}
44-
} else {
44+
} else if (args[0] != null && args[0].equals("[random]")) {
45+
args.toList().set(0, SkillRegistry.skills.sortV().getRandom().getName());
46+
giveOrb(sender, args);
47+
48+
}else {
4549
giveOrb(sender, args);
4650
}
4751
return true;
@@ -71,6 +75,7 @@ public void addTabOptions(MortarSender sender, String[] args, List<String> list)
7175
list.add(skill.getName());
7276
}
7377
list.add("[all]");
78+
list.add("[random]");
7479
}
7580
if (args.length == 1) {
7681
list.add(List.of("1", "10", "100", "1000", "10000", "100000", "1000000"));

0 commit comments

Comments
 (0)