Skip to content

Commit

Permalink
fix wakeups on player join, #57
Browse files Browse the repository at this point in the history
  • Loading branch information
Jsinco committed Dec 9, 2024
1 parent 121d814 commit 72e8585
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 24 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
---

> [!IMPORTANT]
> Brewery**X** is based off of an over **decade** old plugin called Brewery. A lot of this code is old and awful to look at. If you see poorly written code, don't assume the worst because chances are, I didn't even write it. Thanks
> Brewery**X** is based off of an over **decade** old plugin, [Brewery](https://github.com/DieReicheErethons/Brewery).
> Bugs and issues are bound to happen, so please report them on our [Discord](https://discord.gg/aV5Am7uxWr) or [GitHub issues](https://github.com/BreweryTeam/BreweryX/issues)!

### Brewery is a Plugin for an alternate brewing process, including alcoholic Potions.

Works with Spigot, Paper, and Folia from `1.21.1` to `1.8.x`!
Works with Spigot, Paper, and Folia from `1.21.4` to `1.8.9`!

The somewhat difficult brewing process rewards you with a diversity of Potions, which, through their effects, create a drunkenness that has never existed in Minecraft before.

Expand Down Expand Up @@ -57,7 +58,7 @@ The somewhat difficult brewing process rewards you with a diversity of Potions,

- [Depenizen support](https://github.com/DenizenScript/Depenizen/pull/430) for Denizen Scripters

### For Java developers, use any release jar locally or get any release from [Jitpack](https://jitpack.io/#BreweryTeam/BreweryX)
### For Java developers, find our repository for the BreweryX API [here](https://repo.jsinco.dev/#/releases/com/dre/brewery/BreweryX).

Check [the documentation](https://brewery.lumamc.net/api/api/) for more information.

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ publishing {

if (user != null && pass != null) {
create<MavenPublication>("jsinco") {
groupId = "com.dre.brewery"
groupId = project.group.toString()
artifactId = "BreweryX"
version = project.version.toString()
artifact(tasks.shadowJar.get().archiveFile) {
Expand Down
25 changes: 13 additions & 12 deletions docs/en/api/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,22 @@ Lombok is recommended for Java developers to reduce boilerplate code.

# External Plugin API

For Java developers, use any release jar locally or preferably, use JitPack:
For Java developers, you can use [JitPack](https://jitpack.io/#BreweryTeam/BreweryX) or the [provided repository](https://repo.jsinco.dev/#/releases/com/dre/brewery/BreweryX) to add BreweryX as a dependency:

## Maven

```XML
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
<id>jsinco-repo</id>
<url>https://repo.jsinco.dev/releases</url>
</repository>


<dependency>
<groupId>com.github.BreweryTeam</groupId>
<artifactId>BreweryX</artifactId>
<version>VERSION</version>
<scope>provided</scope>
<groupId>com.dre.brewery</groupId>
<artifactId>BreweryX</artifactId>
<version>VERSION</version>
<scope>provided</scope>
</dependency>
```

Expand All @@ -223,29 +224,29 @@ For Java developers, use any release jar locally or preferably, use JitPack:

``` groovy
repositories {
maven { url 'https://jitpack.io' }
maven { url 'https://repo.jsinco.dev/releases' }
}

dependencies {
implementation 'com.github.BreweryTeam:BreweryX:VERSION'
implementation 'com.dre.brewery:BreweryX:VERSION'
}
```

=== "Gradle (KTS)"

``` kotlin
repositories {
maven("https://jitpack.io")
maven("https://repo.jsinco.dev/releases")
}

dependencies {
implementation("com.github.BreweryTeam:BreweryX:VERSION")
implementation("com.dre.brewery:BreweryX:VERSION")
}
```

!!! warning

Don't forget to replace `VERSION` with a version [available on JitPack](https://jitpack.io/#BreweryTeam/BreweryX#releasesLink).
Don't forget to replace `VERSION` with an available [version](https://repo.jsinco.dev/#/releases/com/dre/brewery/BreweryX).

You also need to add a dependency in the `plugin.yml` or `paper-plugin.yml` file. This ensures BreweryX loads before your plugin.

Expand Down
14 changes: 10 additions & 4 deletions src/main/java/com/dre/brewery/BPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import com.dre.brewery.utility.MinecraftVersion;
import com.dre.brewery.utility.PermissionUtil;
import com.github.Anon8281.universalScheduler.scheduling.tasks.MyScheduledTask;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -61,6 +64,9 @@
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

@ToString
@Getter
@Setter
public class BPlayer {

private static final MinecraftVersion VERSION = BreweryPlugin.getMCVersion();
Expand Down Expand Up @@ -511,9 +517,8 @@ public int canJoin() {

// he may be having a hangover
public void join(final Player player) {
if (offlineDrunk == 0) {
return;
}
// TODO: Rewrite part of this class to not use offlinedrunk, a bunch of this overhead boilerplate is completely unnecessary and overcomplicates our code
// Modified this method a bit to just patch wakeups not working but this *REALLY* needs a rewrite

if (drunkenness < 10) {
if (offlineDrunk > 60) {
Expand All @@ -529,7 +534,7 @@ public void join(final Player player) {
remove(player);
}

} else if (offlineDrunk - drunkenness >= 30) {
} else if (offlineDrunk >= 30 || drunkenness >= 30) {
if (config.isEnableWake() && !player.hasPermission("brewery.bypass.teleport")) {
Location randomLoc = Wakeup.getRandom(player.getLocation());
if (randomLoc != null) {
Expand All @@ -538,6 +543,7 @@ public void join(final Player player) {
}
}
}

offlineDrunk = 0;
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/dre/brewery/commands/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,10 @@ public static void removeSubCommand(SubCommand subCommand) {
subCommands.remove(key);
}
}

public static void execute(Class<? extends SubCommand> clazz, CommandSender sender, String label, String[] args) {
subCommands.values().stream()
.filter(subCommand -> subCommand.getClass().equals(clazz))
.forEach(subCommand -> subCommand.execute(plugin, lang, sender, label, args));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package com.dre.brewery.commands.subcommands;

import com.dre.brewery.BreweryPlugin;
import com.dre.brewery.commands.CommandManager;
import com.dre.brewery.commands.SubCommand;
import com.dre.brewery.configuration.ConfigManager;
import com.dre.brewery.configuration.files.Config;
Expand All @@ -43,6 +44,7 @@ public void execute(BreweryPlugin breweryPlugin, Lang lang, CommandSender sender

switch (args[1].toLowerCase()) {
case "reload" -> BreweryPlugin.getDataManager().exit(true, true, () -> {
CommandManager.execute(ReloadCommand.class, sender, label, args);
try {
BreweryPlugin.setDataManager(DataManager.createDataManager(ConfigManager.getConfig(Config.class).getStorage()));
Logging.msg(sender, "Reloaded the DataManager!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,12 @@ public Map<String, ConfigRecipe> getRecipes() {
map.putAll(ConfigManager.getConfig(Config.class).getRecipes());

// Filter out the disabled ones now
// TODO: Remove debug
System.out.println("Recipes: " + map.size());
map.values().removeIf(recipe -> {
if (recipe.getEnabled() == null) {
return false;
}
return !recipe.getEnabled();
});
System.out.println("Recipes: " + map.size());

return map;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/languages/es.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Traducción al español for BreweryX
# Author: KoCitrusMaker
# Brew
Brew_-times: veces
Brew_-times: -veces
Brew_BadPotion: Bebida arruinada
Brew_BarrelRiped: Añejado en tonel
Brew_DistillUndefined: Destilado turbio
Expand Down

0 comments on commit 72e8585

Please sign in to comment.