Initial Commit
This commit is contained in:
113
.gitignore
vendored
Normal file
113
.gitignore
vendored
Normal file
@@ -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/
|
68
pom.xml
Normal file
68
pom.xml
Normal file
@@ -0,0 +1,68 @@
|
||||
<?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>me.miningtcup</groupId>
|
||||
<artifactId>directxp</artifactId>
|
||||
<version>1.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>directxp</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>papermc-repo</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.21.8-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
110
src/main/java/me/miningtcup/directXP/DirectXP.java
Normal file
110
src/main/java/me/miningtcup/directXP/DirectXP.java
Normal file
@@ -0,0 +1,110 @@
|
||||
package me.miningtcup.directXP;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.bukkit.Bukkit.getPluginManager;
|
||||
import static org.bukkit.Bukkit.getScheduler;
|
||||
|
||||
public final class DirectXP extends JavaPlugin implements Listener {
|
||||
private final FileConfiguration config = getConfig();
|
||||
private final Map<Player, Integer> remainingDings = new HashMap<>();
|
||||
private final Map<Player, Boolean> isPlaying = new HashMap<>();
|
||||
private final Map<Player, Long> lastDingTime = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
saveDefaultConfig();
|
||||
this.getLogger().info("DirectXP is enabled.");
|
||||
getPluginManager().registerEvents(this, this);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDeath(EntityDeathEvent event) {
|
||||
reloadConfig();
|
||||
if (!config.getBoolean("entity-death", true)) return;
|
||||
if (event.getDamageSource().getCausingEntity() instanceof Player player) {
|
||||
int exp = event.getDroppedExp();
|
||||
player.giveExp(exp, true);
|
||||
event.setDroppedExp(0);
|
||||
ding(player, exp);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
reloadConfig();
|
||||
if (!config.getBoolean("break-block", true)) return;
|
||||
int exp = event.getExpToDrop();
|
||||
if (exp > 0) {
|
||||
Player player = event.getPlayer();
|
||||
player.giveExp(exp, true);
|
||||
event.setExpToDrop(0);
|
||||
ding(player, exp);
|
||||
}
|
||||
}
|
||||
|
||||
public void ding(Player player, int exp) {
|
||||
reloadConfig();
|
||||
if (config.getBoolean("multi-sounds")) {
|
||||
int newDings = calculateOrbs(exp).size();
|
||||
remainingDings.put(player, remainingDings.getOrDefault(player, 0) + newDings);
|
||||
startPlaying(player);
|
||||
} else {
|
||||
reloadConfig();
|
||||
long currentTime = System.currentTimeMillis();
|
||||
int soundDelayMillis = config.getInt("sound-delay", 2) * 50;
|
||||
long lastTime = lastDingTime.getOrDefault(player, 0L);
|
||||
|
||||
if (currentTime - lastTime >= soundDelayMillis) {
|
||||
lastDingTime.put(player, currentTime);
|
||||
player.playSound(player.getLocation(),
|
||||
Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 0.1F, (float) (0.55 + Math.random() * 0.7));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void startPlaying(Player player) {
|
||||
reloadConfig();
|
||||
if (isPlaying.getOrDefault(player, false)) return;
|
||||
isPlaying.put(player, true);
|
||||
|
||||
getScheduler().runTaskTimer(this, task -> {
|
||||
int dingsLeft = remainingDings.getOrDefault(player, 0);
|
||||
if (dingsLeft > 0) {
|
||||
player.playSound(player.getLocation(),
|
||||
Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 0.1F, (float) (0.55 + Math.random() * 0.7));
|
||||
remainingDings.put(player, dingsLeft - 1);
|
||||
} else {
|
||||
task.cancel();
|
||||
isPlaying.put(player, false);
|
||||
}
|
||||
}, 0, config.getInt("sound-delay", 2));
|
||||
}
|
||||
|
||||
private static final int[] ORB_VALUES = {2477, 1237, 617, 307, 149, 73, 37, 17, 7, 3, 1};
|
||||
|
||||
public static List<Integer> calculateOrbs(int totalExperience) {
|
||||
List<Integer> orbs = new ArrayList<>();
|
||||
|
||||
for (int value : ORB_VALUES) {
|
||||
while (totalExperience >= value) {
|
||||
totalExperience -= value;
|
||||
orbs.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
return orbs;
|
||||
}
|
||||
}
|
11
src/main/resources/config.yml
Normal file
11
src/main/resources/config.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
# Should DirectXP apply to breaking blocks?
|
||||
break-block: true
|
||||
|
||||
# Should DirectXP apply to killing entities?
|
||||
entity-death: true
|
||||
|
||||
# Should multiple sounds be played if it's calculated the amount of exp dropped would have resulted in multiple orbs?
|
||||
multi-sounds: true
|
||||
|
||||
# How many ticks between sounds? 2 is vanilla.
|
||||
sound-delay: 2
|
6
src/main/resources/plugin.yml
Normal file
6
src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
name: DirectXP
|
||||
version: '1.1'
|
||||
main: me.miningtcup.directXP.DirectXP
|
||||
api-version: '1.21'
|
||||
authors: [ MiningTcup ]
|
||||
description: Collect XP directly, instead of from orbs.
|
Reference in New Issue
Block a user