Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
d3nbr0 committed Nov 9, 2024
0 parents commit f0e7e0d
Show file tree
Hide file tree
Showing 18 changed files with 724 additions and 0 deletions.
113 changes: 113 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# User-specific stuff
.idea/

*.iml
*.ipr
*.iws

# IntelliJ
out/

# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

target/

pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next

release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
.flattened-pom.xml

# Common working directory
run/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Denis Shurygin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Hookah Plugin

___

Hookah is a plugin for the Minecraft server that adds hookahs to the game.
Add a twist to your server, allowing players to enjoy the wonderful taste of tobacco

![](https://raw.githubusercontent.com/d3nbr0/mc-hookah/main/media/banner.png "Banner")

## How to use

Put any glass, and add a potion maker on top, as in the picture above.
Right-click on the potion maker will allow you to smoke a hookah

## Configuration

This plugin can be configured using the `config.yml` file

Variables:

- **max-smoked** - The maximum number of hookah uses in a row before the player starts to get negative effects
- **smoke-duration** - The time it takes to reset all hookah smoking attempts
- **damage** - Damage inflicted on a player who smoked a hookah
- **positive-effect-duration** - The duration of the positive effect of restoring health in seconds
- **negative-effect-duration** - The duration of the negative deceleration effect in seconds
- **message-radius** - The radius in which other players will see effects, hear sounds, and see chat messages
- **limit-message** - A message to the user warning that he is getting negative effects
- **puff-messages** - List of hookah smoking chat messages
- **damage-messages** - List of chat messages when receiving hookah damage
- **die-messages** - List of chat messages at death from hookah

Also, users who are in creative mode or have `hookah.nonegative` permission are not subject
to the negative effects of hookah

### Enjoy your game!
Binary file added media/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.jedels</groupId>
<artifactId>hookah</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>hookah</name>

<properties>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<defaultGoal>clean package</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.21.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
11 changes: 11 additions & 0 deletions src/main/java/org/jedels/hookah/Controller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.jedels.hookah;

import org.bukkit.plugin.java.JavaPlugin;

public class Controller {
public static JavaPlugin plugin;

public static void setup(JavaPlugin plugin) {
Controller.plugin = plugin;
}
}
124 changes: 124 additions & 0 deletions src/main/java/org/jedels/hookah/Database.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package org.jedels.hookah;

import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.scheduler.BukkitRunnable;

import java.io.File;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.logging.Level;

public class Database {
private static Database INSTANCE;

private final String fileName = "database.yml";
private final File file;
private final FileConfiguration database;

public Database() {
this.file = new File(Controller.plugin.getDataFolder(), this.fileName);

if (!this.file.exists()) {
this.file.getParentFile().mkdirs();
Controller.plugin.saveResource(this.fileName, false);
}

this.database = YamlConfiguration.loadConfiguration(this.file);
this.saveTask();
}

public void deleteUser(Player player) {
this.database.set(this.getPath(player, "users.{0}"), null);
}

public void deleteUser(String player) {
this.database.set(this.getPath(player, "users.{0}"), null);
}

public void increasePuffs(Player player) {
final int puffs = this.getPuffs(player);
final long now = System.currentTimeMillis() / 1000L;

this.database.set(this.getPath(player, "users.{0}.count"), puffs + 1);
this.database.set(this.getPath(player, "users.{0}.ts"), now);
}

public int getPuffs(Player player) {
return this.database.getInt(this.getPath(player, "users.{0}.count"));
}

public int getPuffs(String player) {
return this.database.getInt(this.getPath(player, "users.{0}.count"));
}

public long getTimestamp(Player player) {
return this.database.getLong(this.getPath(player, "users.{0}.ts"));
}

public long getTimestamp(String player) {
return this.database.getLong(this.getPath(player, "users.{0}.ts"));
}

public void save() {
try {
database.save(file);
} catch (IOException e) {
Controller.plugin.getLogger().log(
Level.SEVERE,
"Could not save config to " + String.valueOf(file),
e
);
}
}

public void clearGarbage() {
ConfigurationSection users = this.database.getConfigurationSection("users");

if (users == null) {
return;
}

Settings settings = Settings.getInstance();
final long now = System.currentTimeMillis() / 1000L;

for (String playerName : users.getValues(false).keySet()) {
if (this.getPuffs(playerName) == 0 || now - this.getTimestamp(playerName) >= settings.smokeDuration) {
this.deleteUser(playerName);
}
}
}

private String getPath(Player player, String path) {
return MessageFormat.format(path, player.getDisplayName());
}

private String getPath(String player, String path) {
return MessageFormat.format(path, player);
}

private void saveTask() {
new BukkitRunnable() {
@Override
public void run() {
clearGarbage();
save();
}
}.runTaskTimer(Controller.plugin, 60L * 20L, 60L * 20);
}

public static Database getInstance() {
if (INSTANCE == null) {
synchronized (Database.class) {
if (INSTANCE == null) {
INSTANCE = new Database();
}
}
}

return INSTANCE;
}
}
Loading

0 comments on commit f0e7e0d

Please sign in to comment.