Beta 0.1
This commit is contained in:
commit
36dec8b4c5
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/
|
||||||
71
pom.xml
Normal file
71
pom.xml
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?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>net.ichverstehs</groupId>
|
||||||
|
<artifactId>ATM_Plugin</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>ATM_Plugin</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>16</source>
|
||||||
|
<target>16</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</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>
|
||||||
|
<repository>
|
||||||
|
<id>sonatype</id>
|
||||||
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.papermc.paper</groupId>
|
||||||
|
<artifactId>paper-api</artifactId>
|
||||||
|
<version>1.20.4-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
227
src/main/java/net/ichverstehs/atm_plugin/ATM_Plugin.java
Normal file
227
src/main/java/net/ichverstehs/atm_plugin/ATM_Plugin.java
Normal file
@ -0,0 +1,227 @@
|
|||||||
|
package net.ichverstehs.atm_plugin;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Interaction;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public final class ATM_Plugin extends JavaPlugin implements Listener {
|
||||||
|
|
||||||
|
private final Map<Player, Integer> withdrawAmounts = new HashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
Bukkit.getPluginManager().registerEvents(this, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerInteract(PlayerInteractEntityEvent event) {
|
||||||
|
if (event.getRightClicked() instanceof Interaction) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
openATMMenu(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openATMMenu(Player player) {
|
||||||
|
withdrawAmounts.put(player, 0);
|
||||||
|
|
||||||
|
int currentBalance = getCurrentBalance(player);
|
||||||
|
|
||||||
|
Inventory menu = Bukkit.createInventory(null, 54, ChatColor.GREEN + "ATM " + ChatColor.DARK_GREEN + "| " + ChatColor.GOLD + currentBalance + "€");
|
||||||
|
|
||||||
|
menu.setItem(10, createItem(Material.DIAMOND, "Einzahlen", "Geld Einzahlen"));
|
||||||
|
menu.setItem(12, createItem(Material.GOLD_INGOT, "Abheben", "Geld Abheben"));
|
||||||
|
menu.setItem(14, createItem(Material.PAPER, "Überweisung", "Geld Überweisen"));
|
||||||
|
|
||||||
|
for (int i = 0; i < 9; i++) {
|
||||||
|
menu.setItem(i, createGlassPane());
|
||||||
|
menu.setItem(45 + i, createGlassPane());
|
||||||
|
}
|
||||||
|
|
||||||
|
player.openInventory(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openWithdrawalMenu(Player player) {
|
||||||
|
int currentBalance = getCurrentBalance(player);
|
||||||
|
|
||||||
|
Inventory withdrawalMenu = Bukkit.createInventory(null, 27, ChatColor.GREEN + "Abheben " + ChatColor.DARK_GREEN + "| " + ChatColor.GOLD + currentBalance + "€");
|
||||||
|
|
||||||
|
for (int i = 0; i < 9; i++) {
|
||||||
|
withdrawalMenu.setItem(i, createGlassPane());
|
||||||
|
withdrawalMenu.setItem(18 + i, createGlassPane());
|
||||||
|
}
|
||||||
|
|
||||||
|
withdrawalMenu.setItem(11, createEmerald(1, "1 Euro", 0));
|
||||||
|
withdrawalMenu.setItem(12, createEmerald(5, "50 Euro", 0));
|
||||||
|
withdrawalMenu.setItem(13, createEmerald(2, "100 Euro", 0));
|
||||||
|
withdrawalMenu.setItem(14, createEmerald(3, "500 Euro", 0));
|
||||||
|
withdrawalMenu.setItem(15, createEmerald(4, "1000 Euro", 0));
|
||||||
|
|
||||||
|
withdrawalMenu.setItem(22, createItem(Material.CHEST, "Abheben", ""));
|
||||||
|
withdrawalMenu.setItem(26, createItem(Material.BARRIER, "Zurück", "Zurück zum Hauptmenü"));
|
||||||
|
|
||||||
|
updateWithdrawAmountDisplay(player, withdrawalMenu);
|
||||||
|
player.openInventory(withdrawalMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateWithdrawAmountDisplay(Player player, Inventory menu) {
|
||||||
|
int amount = withdrawAmounts.getOrDefault(player, 0);
|
||||||
|
ItemStack display = new ItemStack(Material.PAPER);
|
||||||
|
ItemMeta meta = display.getItemMeta();
|
||||||
|
|
||||||
|
if (meta != null) {
|
||||||
|
meta.setDisplayName(ChatColor.AQUA + "Betrag: " + String.valueOf(amount) + "€");
|
||||||
|
display.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
menu.setItem(4, display);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getCurrentBalance(Player player) {
|
||||||
|
return Bukkit.getScoreboardManager().getMainScoreboard()
|
||||||
|
.getObjective("Konto")
|
||||||
|
.getScore(player.getName())
|
||||||
|
.getScore();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack createItem(Material material, String name, String desc) {
|
||||||
|
ItemStack item = new ItemStack(material);
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
|
||||||
|
if (meta != null) {
|
||||||
|
meta.setDisplayName(ChatColor.YELLOW + name);
|
||||||
|
List<String> lore = new ArrayList<>();
|
||||||
|
lore.add(ChatColor.GRAY + desc);
|
||||||
|
meta.setLore(lore);
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack createEmerald(int customModelData, String name, int count) {
|
||||||
|
ItemStack emerald = new ItemStack(Material.EMERALD);
|
||||||
|
ItemMeta meta = emerald.getItemMeta();
|
||||||
|
|
||||||
|
if (meta != null) {
|
||||||
|
meta.setDisplayName(ChatColor.YELLOW + name);
|
||||||
|
meta.setCustomModelData(customModelData);
|
||||||
|
List<String> lore = new ArrayList<>();
|
||||||
|
lore.add(ChatColor.GRAY + String.valueOf(count) + "x");
|
||||||
|
meta.setLore(lore);
|
||||||
|
emerald.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
return emerald;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack createGlassPane() {
|
||||||
|
ItemStack glassPane = new ItemStack(Material.YELLOW_STAINED_GLASS_PANE);
|
||||||
|
ItemMeta meta = glassPane.getItemMeta();
|
||||||
|
|
||||||
|
if (meta != null) {
|
||||||
|
meta.setDisplayName(" ");
|
||||||
|
glassPane.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
return glassPane;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
|
Player player = (Player) event.getWhoClicked();
|
||||||
|
|
||||||
|
if (event.getView().getTitle().startsWith(ChatColor.GREEN + "ATM")) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
if (event.getCurrentItem() != null && event.getCurrentItem().getType() == Material.GOLD_INGOT) {
|
||||||
|
openWithdrawalMenu(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.getView().getTitle().startsWith(ChatColor.GREEN + "Abheben")) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
if (event.getCurrentItem() != null) {
|
||||||
|
Material clickedType = event.getCurrentItem().getType();
|
||||||
|
ItemStack clickedItem = event.getCurrentItem();
|
||||||
|
ItemMeta meta = clickedItem.getItemMeta();
|
||||||
|
|
||||||
|
if (meta != null && meta.hasCustomModelData()) {
|
||||||
|
int value = getEmeraldValue(meta.getCustomModelData());
|
||||||
|
int amount = withdrawAmounts.getOrDefault(player, 0);
|
||||||
|
|
||||||
|
if (event.getClick().isLeftClick()) {
|
||||||
|
amount += value;
|
||||||
|
updateEmeraldLore(clickedItem, meta, 1);
|
||||||
|
} else if (event.getClick().isRightClick() && amount >= value) {
|
||||||
|
amount -= value;
|
||||||
|
updateEmeraldLore(clickedItem, meta, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
withdrawAmounts.put(player, amount);
|
||||||
|
updateWithdrawAmountDisplay(player, event.getInventory());
|
||||||
|
} else if (clickedType == Material.CHEST) {
|
||||||
|
withdrawAmountFromAccount(player);
|
||||||
|
player.closeInventory();
|
||||||
|
} else if (clickedType == Material.BARRIER) {
|
||||||
|
openATMMenu(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateEmeraldLore(ItemStack item, ItemMeta meta, int change) {
|
||||||
|
List<String> lore = meta.getLore();
|
||||||
|
|
||||||
|
if (lore != null && !lore.isEmpty()) {
|
||||||
|
String firstLine = lore.get(0);
|
||||||
|
int count = Integer.parseInt(firstLine.replace(ChatColor.GRAY.toString(), "").replace("x", "").trim()) + change;
|
||||||
|
count = Math.max(count, 0); // Verhindert negative Werte
|
||||||
|
lore.set(0, ChatColor.GRAY + String.valueOf(count) + "x");
|
||||||
|
meta.setLore(lore);
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getEmeraldValue(int customModelData) {
|
||||||
|
switch (customModelData) {
|
||||||
|
case 1: return 1;
|
||||||
|
case 2: return 100;
|
||||||
|
case 3: return 500;
|
||||||
|
case 4: return 1000;
|
||||||
|
case 5: return 50;
|
||||||
|
default: return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void withdrawAmountFromAccount(Player player) {
|
||||||
|
int amount = withdrawAmounts.getOrDefault(player, 0);
|
||||||
|
int balance = getCurrentBalance(player);
|
||||||
|
|
||||||
|
if (amount > 0 && balance >= amount) {
|
||||||
|
Bukkit.getScoreboardManager().getMainScoreboard()
|
||||||
|
.getObjective("Konto")
|
||||||
|
.getScore(player.getName())
|
||||||
|
.setScore(balance - amount);
|
||||||
|
player.sendMessage(ChatColor.GREEN + "Du hast " + amount + "€ abgehoben!");
|
||||||
|
} else {
|
||||||
|
player.sendMessage(ChatColor.RED + "Nicht genug Geld!");
|
||||||
|
}
|
||||||
|
|
||||||
|
withdrawAmounts.put(player, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/main/resources/plugin.yml
Normal file
14
src/main/resources/plugin.yml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
name: ATM_Plugin
|
||||||
|
version: '${project.version}'
|
||||||
|
main: net.ichverstehs.atm_plugin.ATM_Plugin
|
||||||
|
api-version: '1.20'
|
||||||
|
commands:
|
||||||
|
testmenu:
|
||||||
|
description: Öffne das Test-Menü
|
||||||
|
usage: /<command>
|
||||||
|
createarmorstand:
|
||||||
|
description: Erstellt einen Armorstand mit einem Tag
|
||||||
|
usage: /createarmorstand
|
||||||
|
giveuncopyableemerald:
|
||||||
|
description: "Gibt dir einen unkopierbaren Smaragd"
|
||||||
|
usage: "/giveuncopyableemerald"
|
||||||
Loading…
x
Reference in New Issue
Block a user