Skip to content

Commit 29aea0f

Browse files
Merge pull request #430 from VolmitSoftware/Development
Development
2 parents 6fa8705 + 870d640 commit 29aea0f

File tree

9 files changed

+148
-47
lines changed

9 files changed

+148
-47
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.9.2-1.19.4'
26+
version '1.9.3-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/api/skill/SkillRegistry.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,16 @@
4545
import org.bukkit.inventory.ItemStack;
4646
import org.bukkit.persistence.PersistentDataType;
4747

48-
import java.io.IOException;
4948
import java.lang.reflect.InvocationTargetException;
50-
import java.util.HashMap;
5149
import java.util.List;
5250
import java.util.Map;
5351
import java.util.UUID;
52+
import java.util.concurrent.ConcurrentHashMap;
5453

5554
public class SkillRegistry extends TickedObject {
56-
public static final Map<String, Skill<?>> skills = new HashMap<>();
55+
public static final Map<String, Skill<?>> skills = new ConcurrentHashMap<>();
5756

58-
public SkillRegistry() throws IOException {
57+
public SkillRegistry() {
5958
super("registry", UUID.randomUUID() + "-sk", 1250);
6059
registerSkill(SkillAgility.class);
6160
registerSkill(SkillArchitect.class);
@@ -93,10 +92,16 @@ public void on(PlayerExpChangeEvent e) {
9392
public void on(PlayerInteractEvent e) {
9493
Player p = e.getPlayer();
9594

96-
if (!e.getBlockFace().equals(BlockFace.UP) && !e.getBlockFace().equals(BlockFace.DOWN) && !p.isSneaking() && e.getAction().equals(Action.RIGHT_CLICK_BLOCK)
95+
boolean commonConditions = p.isSneaking() && e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && e.getClickedBlock() != null;
96+
boolean isLectern = commonConditions && e.getClickedBlock().getType().equals(Material.LECTERN);
97+
boolean isObserver = commonConditions && e.getClickedBlock().getType().equals(Material.OBSERVER);
98+
boolean isAdaptActivator = !e.getBlockFace().equals(BlockFace.UP) && !e.getBlockFace().equals(BlockFace.DOWN) && !p.isSneaking() && e.getAction().equals(Action.RIGHT_CLICK_BLOCK)
99+
&& e.getClickedBlock() != null
97100
&& e.getClickedBlock().getType().equals(Material.valueOf(AdaptConfig.get().adaptActivatorBlock)) && (p.getInventory().getItemInMainHand().getType().equals(Material.AIR)
98101
|| !p.getInventory().getItemInMainHand().getType().isBlock()) &&
99-
(p.getInventory().getItemInOffHand().getType().equals(Material.AIR) || !p.getInventory().getItemInOffHand().getType().isBlock())) {
102+
(p.getInventory().getItemInOffHand().getType().equals(Material.AIR) || !p.getInventory().getItemInOffHand().getType().isBlock());
103+
104+
if (isAdaptActivator) {
100105
e.getClickedBlock().getWorld().playSound(e.getClickedBlock().getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.5f, 0.72f);
101106
e.getClickedBlock().getWorld().playSound(e.getClickedBlock().getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 0.35f, 0.755f);
102107
SkillsGui.open(p);
@@ -105,19 +110,17 @@ public void on(PlayerInteractEvent e) {
105110
p.getWorld().spawnParticle(Particle.ENCHANTMENT_TABLE, e.getClickedBlock().getLocation().clone().add(0.5, 1, 0.5), 12, 0, 0, 0, 1.1);
106111
}
107112

108-
if (p.isSneaking() && e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && e.getClickedBlock().getType().equals(Material.LECTERN)) {
113+
if (isLectern) {
109114
ItemStack it = p.getInventory().getItemInMainHand();
110-
111115
if (it.getItemMeta() != null && !it.getItemMeta().getPersistentDataContainer().getKeys().isEmpty()) {
112116
e.setCancelled(true);
113117
playDebug(p);
114118
it.getItemMeta().getPersistentDataContainer().getKeys().forEach(k -> Bukkit.getServer().getConsoleSender().sendMessage(k + " = " + it.getItemMeta().getPersistentDataContainer().getOrDefault(k, PersistentDataType.STRING, "Not a String")));
115119
}
116120
}
117121

118-
if (p.isSneaking() && e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && e.getClickedBlock().getType().equals(Material.OBSERVER)) {
122+
if (isObserver) {
119123
ItemStack it = p.getInventory().getItemInMainHand();
120-
121124
if (it.getType().equals(Material.EXPERIENCE_BOTTLE)) {
122125
e.setCancelled(true);
123126
Bukkit.getServer().getConsoleSender().sendMessage(" ");
@@ -132,7 +135,6 @@ public void on(PlayerInteractEvent e) {
132135
String vv = i.getMultiplier() > 0 ? "+" + Form.pc(i.getMultiplier()) : Form.pc(i.getMultiplier());
133136
Bukkit.getServer().getConsoleSender().sendMessage(C.GREEN + "* " + vv + C.GRAY + " for " + Form.duration(i.getGoodFor() - M.ms(), 0));
134137
}
135-
136138
for (XPMultiplier i : Adapt.instance.getAdaptServer().getData().getMultipliers()) {
137139
String vv = i.getMultiplier() > 0 ? "+" + Form.pc(i.getMultiplier()) : Form.pc(i.getMultiplier());
138140
Bukkit.getServer().getConsoleSender().sendMessage(C.GREEN + "* " + vv + C.GRAY + " for " + Form.duration(i.getGoodFor() - M.ms(), 0));
@@ -142,7 +144,6 @@ public void on(PlayerInteractEvent e) {
142144
Skill<?> s = i.getRawSkill(a);
143145
String v = i.getMultiplier() - a.getData().getMultiplier() > 0 ? "+" + Form.pc(i.getMultiplier() - a.getData().getMultiplier()) : Form.pc(i.getMultiplier() - a.getData().getMultiplier());
144146
Bukkit.getServer().getConsoleSender().sendMessage(" " + s.getDisplayName() + C.GRAY + ": " + s.getColor() + v);
145-
146147
for (XPMultiplier j : i.getMultipliers()) {
147148
String vv = j.getMultiplier() > 0 ? "+" + Form.pc(j.getMultiplier()) : Form.pc(j.getMultiplier());
148149
Bukkit.getServer().getConsoleSender().sendMessage(" " + s.getShortName() + C.GRAY + " " + vv + " for " + Form.duration(j.getGoodFor() - M.ms(), 0));
@@ -151,8 +152,7 @@ public void on(PlayerInteractEvent e) {
151152
}
152153
}
153154
}
154-
155-
private void playDebug(Player p) {
155+
private void playDebug(Player p) {
156156
p.playSound(p.getLocation(), Sound.BLOCK_BELL_RESONATE, 1f, 0.6f);
157157
p.playSound(p.getLocation(), Sound.BLOCK_BEACON_ACTIVATE, 1f, 0.1f);
158158
p.playSound(p.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 1f, 1.6f);

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

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import org.bukkit.event.player.PlayerQuitEvent;
4848

4949
import java.io.File;
50-
import java.io.IOException;
5150
import java.util.*;
5251

5352
public class AdaptServer extends TickedObject {
@@ -64,33 +63,25 @@ public AdaptServer() {
6463
spatialTickets = new ArrayList<>();
6564
players = new HashMap<>();
6665
load();
67-
try {
68-
skillRegistry = new SkillRegistry();
69-
} catch (IOException e) {
70-
e.printStackTrace();
71-
}
72-
for (Player i : Bukkit.getServer().getOnlinePlayers()) {
73-
join(i);
74-
}
66+
skillRegistry = new SkillRegistry();
67+
68+
Bukkit.getOnlinePlayers().forEach(this::join);
7569
}
7670

7771
public void offer(SpatialXP xp) {
78-
try {
79-
if (xp == null || xp.getSkill() == null || xp.getRadius() > 0 || xp.getMs() > 0 || xp.getLocation() == null) {
80-
return;
81-
}
82-
spatialTickets.add(xp);
83-
} catch (Exception ignored) {
84-
Adapt.verbose("Failed to offer spatial xp");
72+
if (xp == null || xp.getSkill() == null || xp.getRadius() > 0 || xp.getMs() > 0 || xp.getLocation() == null) {
73+
return;
8574
}
75+
spatialTickets.add(xp);
8676
}
8777

8878
public void takeSpatial(AdaptPlayer p) {
8979
J.attempt(() -> {
90-
SpatialXP x = spatialTickets.getRandom();
91-
if (x == null) {
80+
Optional<SpatialXP> optX = spatialTickets.stream().findAny();
81+
if (optX.isEmpty()) {
9282
return;
9383
}
84+
SpatialXP x = optX.get();
9485
if (M.ms() > x.getMs()) {
9586
spatialTickets.remove(x);
9687
return;
@@ -118,23 +109,18 @@ public void takeSpatial(AdaptPlayer p) {
118109
}
119110

120111
public void join(Player p) {
121-
if (!players.containsKey(p)) {
122-
players.put(p, new AdaptPlayer(p));
123-
players.get(p).loggedIn();
124-
}
112+
AdaptPlayer a = new AdaptPlayer(p);
113+
players.put(p, a);
114+
a.loggedIn();
125115
}
126116

127117
public void quit(Player p) {
128-
if (players.containsKey(p)) {
129-
players.remove(p).unregister();
130-
}
118+
Optional.ofNullable(players.remove(p)).ifPresent(AdaptPlayer::unregister);
131119
}
132120

133121
@Override
134122
public void unregister() {
135-
for (Player i : players.k()) {
136-
quit(i);
137-
}
123+
new HashSet<>(players.keySet()).forEach(this::quit);
138124
skillRegistry.unregister();
139125
save();
140126
super.unregister();

src/main/java/com/volmit/adapt/commands/openGui/CommandOpen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public List<String> getRequiredPermissions() {
4343

4444
@Override
4545
public boolean handle(MortarSender sender, String[] args) {
46-
if (!sender.hasPermission("adapt.cheatitem")) {
46+
if (!sender.hasPermission("adapt.opengui")) {
4747
sender.sendMessage("You do not have permission to use this command.");
4848
Adapt.info("Player: " + sender.getName() + " attempted to use command " + this + " without permission.");
4949
return true;
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*------------------------------------------------------------------------------
2+
- Adapt is a Skill/Integration plugin for Minecraft Bukkit Servers
3+
- Copyright (c) 2022 Arcane Arts (Volmit Software)
4+
-
5+
- This program is free software: you can redistribute it and/or modify
6+
- it under the terms of the GNU General Public License as published by
7+
- the Free Software Foundation, either version 3 of the License, or
8+
- (at your option) any later version.
9+
-
10+
- This program is distributed in the hope that it will be useful,
11+
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
- GNU General Public License for more details.
14+
-
15+
- You should have received a copy of the GNU General Public License
16+
- along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
-----------------------------------------------------------------------------*/
18+
package com.volmit.adapt.content.adaptation.nether;
19+
20+
import com.volmit.adapt.api.adaptation.SimpleAdaptation;
21+
import com.volmit.adapt.util.*;
22+
import lombok.Data;
23+
import lombok.NoArgsConstructor;
24+
import org.bukkit.Material;
25+
import org.bukkit.entity.Player;
26+
import org.bukkit.event.EventHandler;
27+
import org.bukkit.event.EventPriority;
28+
import org.bukkit.event.entity.EntityDamageEvent;
29+
30+
import java.util.Random;
31+
32+
public class NetherFireResist extends SimpleAdaptation<NetherFireResist.Config> {
33+
private final Random random = new Random();
34+
35+
public NetherFireResist() {
36+
super("nether-fire-resist");
37+
registerConfiguration(Config.class);
38+
setDescription(Localizer.dLocalize("nether", "fireresist", "description"));
39+
setDisplayName(Localizer.dLocalize("nether", "fireresist", "name"));
40+
setIcon(Material.BLAZE_POWDER);
41+
setBaseCost(getConfig().baseCost);
42+
setCostFactor(getConfig().costFactor);
43+
setMaxLevel(getConfig().maxLevel);
44+
setInitialCost(getConfig().initialCost);
45+
setInterval(4333);
46+
}
47+
48+
@Override
49+
public void addStats(int level, Element v) {
50+
v.addLore(C.RED + "+ " + Form.pc(getFireResist(level), 0) + C.GRAY + " " + Localizer.dLocalize("nether", "fireresist", "lore1"));
51+
}
52+
53+
@EventHandler(priority = EventPriority.HIGH)
54+
public void on(EntityDamageEvent e) {
55+
if (e.isCancelled()) {
56+
return;
57+
}
58+
59+
if (!(e.getEntity() instanceof Player p)) {
60+
return;
61+
}
62+
63+
if (!hasAdaptation(p)) {
64+
return;
65+
}
66+
67+
if (e.getCause() != EntityDamageEvent.DamageCause.FIRE && e.getCause() != EntityDamageEvent.DamageCause.FIRE_TICK) {
68+
return;
69+
}
70+
71+
72+
if (random.nextDouble() < getFireResist(getLevel(p))) {
73+
e.setCancelled(true);
74+
}
75+
}
76+
77+
public double getFireResist(double level) {
78+
return getConfig().fireResistBase + (getConfig().fireResistFactor * level);
79+
}
80+
81+
@Override
82+
public void onTick() {
83+
84+
}
85+
86+
@Override
87+
public boolean isEnabled() {
88+
return getConfig().enabled;
89+
}
90+
91+
@Override
92+
public boolean isPermanent() {
93+
return getConfig().permanent;
94+
}
95+
96+
@Data
97+
@NoArgsConstructor
98+
public static class Config {
99+
boolean permanent = false;
100+
boolean enabled = true;
101+
int baseCost = 4;
102+
double costFactor = 0.75;
103+
int maxLevel = 3;
104+
int initialCost = 6;
105+
double fireResistBase = 0.10;
106+
double fireResistFactor = 0.25;
107+
}
108+
}

src/main/java/com/volmit/adapt/content/skill/SkillHunter.java

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

1919
package com.volmit.adapt.content.skill;
2020

21-
import com.volmit.adapt.Adapt;
2221
import com.volmit.adapt.api.skill.SimpleSkill;
2322
import com.volmit.adapt.content.adaptation.hunter.*;
2423
import com.volmit.adapt.util.C;
@@ -137,7 +136,6 @@ private void handleEntityKill(Player p, Entity entity) {
137136
if (entity.getPortalCooldown() > 0) {
138137
xpAmount *= getConfig().spawnerMobReductionXpMultiplier;
139138
}
140-
Adapt.info("Entity Death Event, XP: " + xpAmount);
141139
getPlayer(p).getData().addStat("killed.kills", 1);
142140
handleCooldownAndXp(p, xpAmount);
143141
}

src/main/java/com/volmit/adapt/content/skill/SkillNether.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package com.volmit.adapt.content.skill;
2020

2121
import com.volmit.adapt.api.skill.SimpleSkill;
22+
import com.volmit.adapt.content.adaptation.nether.NetherFireResist;
2223
import com.volmit.adapt.content.adaptation.nether.NetherSkullYeet;
2324
import com.volmit.adapt.content.adaptation.nether.NetherWitherResist;
2425
import com.volmit.adapt.util.C;
@@ -49,6 +50,7 @@ public SkillNether() {
4950
setIcon(Material.NETHER_STAR);
5051
registerAdaptation(new NetherWitherResist());
5152
registerAdaptation(new NetherSkullYeet());
53+
registerAdaptation(new NetherFireResist());
5254
}
5355

5456
private boolean shouldReturnForEventWithCause(Player p, EntityDamageEvent.DamageCause cause) {

src/main/resources/en_US.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,11 @@
842842
"lore1": "chance to negate withering (per piece).",
843843
"lore2": "Passive: Wearing Netherite Armor has a chance to negate ",
844844
"lore3": "withering."
845+
},
846+
"fireresist": {
847+
"name": "Fire Resistance",
848+
"description": "Resists fire by hardening your skin.",
849+
"lore1": "chance to negate the burning effect!"
845850
}
846851
},
847852
"pickaxe": {

src/main/resources/plugin.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
name: ${name}
32
main: com.volmit.adapt.Adapt
43
version: ${version}
@@ -300,6 +299,9 @@ permissions:
300299
adapt.blacklist.netherwitherresist:
301300
description: Blacklist the adaptation NetherWitherResist
302301
default: false
302+
adapt.blacklist.netherfireresist:
303+
description: Blacklist the adaptation NetherFireResist
304+
default: false
303305
adapt.blacklist.pickaxe:
304306
description: Blacklist the skill Pickaxe
305307
default: false

0 commit comments

Comments
 (0)