Skip to content

Commit

Permalink
Update gradle and use newer java methods
Browse files Browse the repository at this point in the history
  • Loading branch information
md5sha256 committed Oct 23, 2022
1 parent 8d5b417 commit 26d88ee
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ private static MessageKey resolveMessageKey(@NotNull Object object) {
@Override
public MessageRegistry deserialize(Type type, Object obj) {
final Map<MessageKey, Message> messageMap = new HashMap<>();
if (obj instanceof ConfigurationNode) {
final ConfigurationNode root = (ConfigurationNode) obj;
if (obj instanceof final ConfigurationNode root) {
for (Map.Entry<Object, ? extends ConfigurationNode> entry : root.childrenMap().entrySet()) {
final MessageKey key = resolveMessageKey(entry.getKey());
final ConfigurationNode node = entry.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class SimpleShopConfiguration implements ShopConfiguration {

@Setting
private Map<Key, Double> unitPrices = new HashMap<>();
private final Map<Key, Double> unitPrices = new HashMap<>();

@Override
public double unitPrice(@NotNull final IDrugComponent drugComponent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ protected boolean checkPermissions(@NotNull CommandSender sender, @NotNull DrugI
final IDrug drug = itemData.drug();
if (!drug.permission().isBlank() && !sender.hasPermission(drug.permission())) {
sender.sendMessage(Utils.legacyColorize(this.plugin.getConfig().getString("nopermstoconsume")));
return false;
return true;
}
return true;
return false;
}

protected abstract void sendMessageOnItemUse(@NotNull Player player, @NotNull DrugItemData used);
Expand All @@ -56,7 +56,7 @@ protected void handleDrugUse(@NotNull LivingEntity entity,
@NotNull ItemStack itemStack,
@NotNull DrugItemData itemData
) {
if (!checkPermissions(entity, itemData)) {
if (checkPermissions(entity, itemData)) {
return;
}
final IDrug drug = itemData.drug();
Expand All @@ -83,20 +83,16 @@ protected void handleDrugUse(@NotNull LivingEntity entity,

protected void handlePlayerDrugUse(@NotNull Player player, @NotNull EquipmentSlot equipmentSlot,
@NotNull ItemStack itemStack, @NotNull DrugItemData itemData) {
if (!checkPermissions(player, itemData)) {
if (checkPermissions(player, itemData)) {
return;
}
handleDrugUse(player, itemStack, itemData);
itemStack.setAmount(itemStack.getAmount() - 1);
player.getInventory().setItem(equipmentSlot, itemStack);
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1.0f, 0.6f);
sendMessageOnItemUse(player, itemData);
Bukkit.getScheduler().runTaskLater(this.plugin, () -> {
// if (this.plugin.acs)
if (true) {
player.playSound(player.getLocation(), Sound.ENTITY_EVOKER_CELEBRATE, 0.6f, 1.0f);
}
}, 8L);
Runnable playSound = () -> player.playSound(player.getLocation(), Sound.ENTITY_EVOKER_CELEBRATE, 0.6f, 1.0f);
Bukkit.getScheduler().runTaskLater(this.plugin, playSound, 8L);
}

protected void scheduleTask(@NotNull Runnable task, long delayTicks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void onDrugUse(PlayerInteractEvent event) {
return;
}
final Optional<DrugItemData> optionalData = this.drugRegistry.dataFor(used);
if (!optionalData.isPresent()) {
if (optionalData.isEmpty()) {
return;
}
event.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,15 @@ protected void sendMessageOnItemUse(@NotNull Player player, @NotNull DrugItemDat
public void handleSyringeInjection(final EntityDamageByEntityEvent event) {
final Entity entityDamager = event.getDamager();
final Entity entityTarget = event.getEntity();
if (!(entityDamager instanceof Player) || !(entityTarget instanceof LivingEntity)) {
if (!(entityDamager instanceof final Player damager) || !(entityTarget instanceof final LivingEntity target)) {
return;
}
final Player damager = (Player) entityDamager;
final LivingEntity target = (LivingEntity) entityTarget;

final PlayerInventory inventory = damager.getInventory();

final ItemStack inMainHand = inventory.getItemInMainHand();
final Optional<DrugItemData> optionalItemData = this.drugRegistry.dataFor(inMainHand);
if (!optionalItemData.isPresent()) {
if (optionalItemData.isEmpty()) {
return;
}
final DrugItemData data = optionalItemData.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public void registerSlur(@NotNull UUID player, @NotNull ISlurEffect effect, long
@Override
public void registerSlur(@NotNull UUID player, @NotNull IDrug drug) {
@NotNull Optional<DrugMeta> optionalDrugMeta = this.drugRegistry.metaData(drug, DrugMeta.KEY);
if (!optionalDrugMeta.isPresent()) {
if (optionalDrugMeta.isEmpty()) {
throw new IllegalStateException("Failed to get DrugMeta for drug: " + drug.key());
}
final DrugMeta meta = optionalDrugMeta.get();
final Optional<ISlurEffect> optionalEffect = meta.slurEffect();
if (!optionalEffect.isPresent()) {
if (optionalEffect.isEmpty()) {
return;
}
final ISlurEffect effect = optionalEffect.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import cloud.commandframework.meta.SimpleCommandMeta;
import cloud.commandframework.minecraft.extras.MinecraftHelp;
import cloud.commandframework.paper.PaperCommandManager;
import com.google.inject.Inject;
import io.github.md5sha256.addictiveexperience.api.drugs.DrugRegistry;
import io.github.md5sha256.addictiveexperience.api.drugs.IDrug;
import io.github.md5sha256.addictiveexperience.api.drugs.IDrugComponent;
Expand All @@ -24,7 +25,6 @@
import io.github.md5sha256.addictiveexperience.api.util.KeyRegistry;
import io.github.md5sha256.addictiveexperience.implementation.shop.DrugShopUI;
import io.github.md5sha256.addictiveexperience.util.Utils;
import com.google.inject.Inject;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
Expand Down Expand Up @@ -56,10 +56,11 @@ public class AddictiveExperienceCommandHandler {
private final IDrugForms drugForms;

@Inject
public AddictiveExperienceCommandHandler(@NotNull Plugin plugin,
@NotNull DrugRegistry drugRegistry,
@NotNull IDrugForms drugForms,
@NotNull DrugShopUI drugShopUI
public AddictiveExperienceCommandHandler(
@NotNull Plugin plugin,
@NotNull DrugRegistry drugRegistry,
@NotNull IDrugForms drugForms,
@NotNull DrugShopUI drugShopUI
) {
this.drugShopUI = drugShopUI;
this.drugForms = drugForms;
Expand Down Expand Up @@ -93,7 +94,7 @@ public AddictiveExperienceCommandHandler(@NotNull Plugin plugin,
manager.registerAsynchronousCompletions();
} catch (final Exception e) {
plugin.getLogger()
.warning("Failed to enable asynchronous completions: " + e.getMessage());
.warning("Failed to enable asynchronous completions: " + e.getMessage());
}

final MinecraftHelp<CommandSender> minecraftHelp = new MinecraftHelp<>(
Expand All @@ -111,8 +112,10 @@ public AddictiveExperienceCommandHandler(@NotNull Plugin plugin,


@Suggestions("drug-components")
public @NotNull List<String> suggestDrugComponents(@NotNull CommandContext<CommandSender> context,
@NotNull String input) {
public @NotNull List<String> suggestDrugComponents(
@NotNull CommandContext<CommandSender> context,
@NotNull String input
) {
return suggestFromKeyRegistry(input, this.drugRegistry.keysForComponents());
}

Expand All @@ -135,35 +138,35 @@ public AddictiveExperienceCommandHandler(@NotNull Plugin plugin,
) {
if (input == null || input.isEmpty()) {
return keyRegistry.keys().stream()
.sorted(Comparator.reverseOrder())
.collect(Collectors.toList());
.sorted(Comparator.reverseOrder())
.toList();
}
final Matcher matcher = PATTERN_KEY.matcher(input);
if (!matcher.matches()) {
// Suggest the keys first
if (input.indexOf(':') == -1) {
return keyRegistry.keys().stream()
.sorted(Comparator.reverseOrder())
.map(s -> s + ":")
.collect(Collectors.toList());
.sorted(Comparator.reverseOrder())
.map(s -> s + ":")
.toList();
}
// Try to resolve anyway
final String end = ":" + input;
final Set<String> keys = keyRegistry.keysForValue(input);
return keys.stream()
.sorted(Comparator.reverseOrder())
.map(s -> s + end)
.collect(Collectors.toList());
.sorted(Comparator.reverseOrder())
.map(s -> s + end)
.collect(Collectors.toList());
}
final String key = matcher.group(1);
final Set<String> values = keyRegistry.values(key);
final String value = matcher.group(2);
Stream<String> stream = values.stream()
.sorted(Comparator.reverseOrder());
.sorted(Comparator.reverseOrder());
if (value != null && !value.isEmpty()) {
stream = stream.filter(suggestion ->
value.startsWith(suggestion) || value
.equalsIgnoreCase(suggestion));
value.startsWith(suggestion) || value
.equalsIgnoreCase(suggestion));
}
return stream.collect(Collectors.toList());
}
Expand All @@ -184,8 +187,10 @@ public IDrugForm parseDrugForm(@NotNull CommandContext<CommandSender> context,

@Parser
@SuppressWarnings("PatternValidation")
public IDrugComponent parseDrugComponent(@NotNull CommandContext<CommandSender> context,
@NotNull Queue<String> inputs) throws ParseException {
public IDrugComponent parseDrugComponent(
@NotNull CommandContext<CommandSender> context,
@NotNull Queue<String> inputs
) throws ParseException {
final String input = inputs.remove();
if (input == null) {
throw new ParseException("No input!", 0);
Expand Down Expand Up @@ -237,7 +242,7 @@ public void openDrugShop(Player player) {
public void giveItem(Player player,
@NotNull
@Argument(value = "item", suggestions = "drug-components")
IDrugComponent component,
IDrugComponent component,
@Flag(value = "form", suggestions = "drug-forms") IDrugForm form,
@Flag(value = "amount") @Range(min = "1", max = "64") Integer amt,
@Flag(value = "model-only") boolean modelOnly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public SimpleDrugItemDataFactory(@NotNull Plugin plugin, @NotNull DrugRegistry d
final Key keyComponent = Key.key(identifierComponent);
final Optional<IDrugForm> optionalDrugForm = this.drugRegistry.formByKey(keyForm);
final Optional<IDrug> optionalDrug = this.drugRegistry.drugByKey(keyComponent);
if (!optionalDrugForm.isPresent() || !optionalDrug.isPresent()) {
if (optionalDrugForm.isEmpty() || optionalDrug.isEmpty()) {
return Optional.empty();
}
return Optional.of(DrugItemData.of(optionalDrug.get(), optionalDrugForm.get()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,11 @@ public final class Blunts implements IBlunts {

@Override
public @NotNull FormBlunt of(@NotNull BluntState state) {
switch (state) {
case LIT:
return this.lit;
case UNLIT:
return this.unlit;
default:
throw new IllegalArgumentException("Unknown BluntState: " + state);
}
return switch (state) {
case LIT -> this.lit;
case UNLIT -> this.unlit;
default -> throw new IllegalArgumentException("Unknown BluntState: " + state);
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void onPlayerChat(@NotNull AsyncChatEvent event) {
) {
final Optional<ISlurEffect> optional = this.slurEffectState
.currentSlurEffect(source.getUniqueId());
if (!optional.isPresent()) {
if (optional.isEmpty()) {
return ChatRenderer.defaultRenderer()
.render(source, sourceDisplayName, message, viewer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void onAsyncPlayerChat(@NotNull AsyncPlayerChatEvent event) {
final Player player = event.getPlayer();
final Optional<ISlurEffect> optional = this.slurEffectState
.currentSlurEffect(player.getUniqueId());
if (!optional.isPresent()) {
if (optional.isEmpty()) {
return;
}
final String message = convertToFormat(player, event.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected Object serialize(Key item, Predicate<Class<?>> typeSupported) {
}

@Override
public Key deserialize(Type type, Object obj) throws SerializationException {
public Key deserialize(Type type, Object obj) {
return Key.key(obj.toString());
}
}
8 changes: 5 additions & 3 deletions core/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: AddictiveExperience
version: "@version@"
main: com.github.md5sha256.addictiveexperience.AddictiveExperiencePlugin
api-version: 1.16
main: io.github.md5sha256.addictiveexperience.AddictiveExperiencePlugin
api-version: 1.18
depend:
- Vault
- vault
softdepend:
- essentials
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
# Platform
minecraft = "1.18.2-R0.1-SNAPSHOT"
minecraft = "1.19.2-R0.1-SNAPSHOT"
findbugs = "3.0.2"
gson = "2.8.0"
adventure = "4.10.1"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit 26d88ee

Please sign in to comment.