Initial commit
This commit is contained in:
113
Plugins/MineTeleporters/.gitignore
vendored
Normal file
113
Plugins/MineTeleporters/.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/
|
||||
74
Plugins/MineTeleporters/pom.xml
Normal file
74
Plugins/MineTeleporters/pom.xml
Normal file
@@ -0,0 +1,74 @@
|
||||
<?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>de.craftix</groupId>
|
||||
<artifactId>MineTeleporters</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MineTeleporters</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>${java.version}</source>
|
||||
<target>${java.version}</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>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
</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://papermc.io/repo/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.18-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,35 @@
|
||||
package de.craftix.mineteleporters;
|
||||
|
||||
import de.craftix.mineteleporters.crafting.RecipeLoader;
|
||||
import de.craftix.mineteleporters.database.DBHandler;
|
||||
import de.craftix.mineteleporters.logic.Menu;
|
||||
import de.craftix.mineteleporters.logic.OnBlockListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class MineTeleporters extends JavaPlugin {
|
||||
private static MineTeleporters instance;
|
||||
private static String[] lore;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
instance = this;
|
||||
lore = new String[] {"§7Teleportiere dich überall hin"};
|
||||
|
||||
RecipeLoader.loadRecipes();
|
||||
DBHandler.initialize();
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new OnBlockListener(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new Menu(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
DBHandler.disconnect();
|
||||
}
|
||||
|
||||
public static MineTeleporters getInstance() { return instance; }
|
||||
public static String[] getLore() { return lore; }
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package de.craftix.mineteleporters.crafting;
|
||||
|
||||
import de.craftix.mineteleporters.MineTeleporters;
|
||||
import de.craftix.mineteleporters.items.ItemCreator;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
|
||||
public class RecipeLoader {
|
||||
|
||||
public static void loadRecipes() {
|
||||
ShapedRecipe teleporter = new ShapedRecipe(new NamespacedKey(MineTeleporters.getInstance(), "teleporter"), ItemCreator.createTeleporter());
|
||||
teleporter.shape("EEE", "EPE", "EEE");
|
||||
teleporter.setIngredient('E', Material.EMERALD_BLOCK);
|
||||
teleporter.setIngredient('P', Material.ENDER_PEARL);
|
||||
|
||||
ShapedRecipe portableTeleporter = new ShapedRecipe(new NamespacedKey(MineTeleporters.getInstance(), "portable_teleporter"), ItemCreator.createPortableTeleporter());
|
||||
portableTeleporter.shape("DDD", "DPD", "DDD");
|
||||
portableTeleporter.setIngredient('D', Material.DIAMOND_BLOCK);
|
||||
portableTeleporter.setIngredient('P', Material.ENDER_PEARL);
|
||||
|
||||
Bukkit.addRecipe(teleporter);
|
||||
Bukkit.addRecipe(portableTeleporter);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package de.craftix.mineteleporters.database;
|
||||
|
||||
import de.craftix.mineteleporters.logic.TeleportLocation;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DBHandler {
|
||||
private static SQLite sqLite;
|
||||
|
||||
public static void initialize() {
|
||||
sqLite = new SQLite("plugins/MineTeleporters/data.db");
|
||||
sqLite.connect();
|
||||
|
||||
sqLite.insert("CREATE TABLE IF NOT EXISTS Data (Name VARCHAR(100), X INT(100), Y INT(100), Z INT(100), Direction VARCHAR(100), World VARCHAR(100), UUID VARCHAR(100))");
|
||||
sqLite.insert("CREATE TABLE IF NOT EXISTS Userdata (UUID VARCHAR(100), Teleporter VARCHAR(100))");
|
||||
}
|
||||
|
||||
public static void disconnect() {
|
||||
sqLite.disconnect();
|
||||
}
|
||||
|
||||
public static UUID saveLocation(String name, Block block) {
|
||||
int x = block.getLocation().getBlockX();
|
||||
int y = block.getLocation().getBlockY();
|
||||
int z = block.getLocation().getBlockZ();
|
||||
float dir = (float) Math.atan2(block.getLocation().getDirection().getZ(), block.getLocation().getDirection().getX());
|
||||
String world = block.getWorld().getName();
|
||||
UUID uuid = UUID.randomUUID();
|
||||
sqLite.insert("INSERT INTO Data VALUES (\"" + name + "\", " + x + ", " + y + ", " + z + ", \"" + dir + "\", \"" + world + "\", \"" + uuid + "\")");
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public static void delLocation(Block block) {
|
||||
TeleportLocation teleportLocation = getLocation(block);
|
||||
if (teleportLocation == null) return;
|
||||
sqLite.insert("DELETE FROM Data WHERE UUID = \"" + teleportLocation.uuid + "\"");
|
||||
sqLite.insert("DELETE FROM Userdata WHERE Teleporter = \"" + teleportLocation.uuid + "\"");
|
||||
}
|
||||
|
||||
public static TeleportLocation getLocation(Block block) {
|
||||
int x = block.getLocation().getBlockX();
|
||||
int y = block.getLocation().getBlockY();
|
||||
int z = block.getLocation().getBlockZ();
|
||||
try {
|
||||
ResultSet rs = sqLite.getData("SELECT * FROM Data WHERE X = " + x + " AND Y = " + y + " AND Z = " + z);
|
||||
if (rs.next()) {
|
||||
float yaw = Float.parseFloat(rs.getString("Direction"));
|
||||
World world = Bukkit.getWorld(rs.getString("World"));
|
||||
UUID uuid = UUID.fromString(rs.getString("UUID"));
|
||||
|
||||
return new TeleportLocation(rs.getString("Name"), new Location(world, x, y, z, yaw, 0), uuid);
|
||||
}
|
||||
}catch (Exception e) { e.printStackTrace(); }
|
||||
return null;
|
||||
}
|
||||
|
||||
public static TeleportLocation[] getLocations(Player p) {
|
||||
ArrayList<TeleportLocation> locations = new ArrayList<>();
|
||||
List<UUID> teleporters = Arrays.asList(getPlayerTeleporters(p));
|
||||
try {
|
||||
ResultSet rs = sqLite.getData("SELECT * FROM Data");
|
||||
while (rs.next()) {
|
||||
int x = rs.getInt("X");
|
||||
int y = rs.getInt("Y");
|
||||
int z = rs.getInt("Z");
|
||||
float yaw = Float.parseFloat(rs.getString("Direction"));
|
||||
World world = Bukkit.getWorld(rs.getString("World"));
|
||||
UUID uuid = UUID.fromString(rs.getString("UUID"));
|
||||
|
||||
if (teleporters.contains(uuid))
|
||||
locations.add(new TeleportLocation(rs.getString("Name"), new Location(world, x, y, z, yaw, 0), uuid));
|
||||
}
|
||||
}catch (Exception e) { e.printStackTrace(); }
|
||||
return locations.toArray(new TeleportLocation[0]);
|
||||
}
|
||||
|
||||
public static TeleportLocation getLocation(UUID uuid) {
|
||||
try {
|
||||
ResultSet rs = sqLite.getData("SELECT * FROM Data WHERE UUID = \"" + uuid + "\"");
|
||||
if (rs.next()) {
|
||||
int x = rs.getInt("X");
|
||||
int y = rs.getInt("Y");
|
||||
int z = rs.getInt("Z");
|
||||
float yaw = Float.parseFloat(rs.getString("Direction"));
|
||||
World world = Bukkit.getWorld(rs.getString("World"));
|
||||
|
||||
return new TeleportLocation(rs.getString("Name"), new Location(world, x, y, z, yaw, 0), uuid);
|
||||
}
|
||||
}catch (Exception e) { e.printStackTrace(); }
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean addPlayer(Player p, UUID teleporter) {
|
||||
boolean isNew = true;
|
||||
List<TeleportLocation> locations = Arrays.asList(getLocations(p));
|
||||
for (TeleportLocation location : locations) {
|
||||
if (location.uuid.equals(teleporter)) {
|
||||
isNew = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sqLite.insert("DELETE FROM Userdata WHERE UUID = \"" + p.getUniqueId() + "\" AND Teleporter = \"" + teleporter + "\"");
|
||||
sqLite.insert("INSERT INTO Userdata VALUES (\"" + p.getUniqueId() + "\", \"" + teleporter + "\")");
|
||||
return isNew;
|
||||
}
|
||||
|
||||
public static UUID[] getPlayerTeleporters(Player p) {
|
||||
ArrayList<UUID> teleporters = new ArrayList<>();
|
||||
try {
|
||||
ResultSet rs = sqLite.getData("SELECT Teleporter FROM Userdata WHERE UUID = \"" + p.getUniqueId() + "\"");
|
||||
while (rs.next()) {
|
||||
teleporters.add(UUID.fromString(rs.getString("Teleporter")));
|
||||
}
|
||||
}catch (Exception e) { e.printStackTrace(); }
|
||||
return teleporters.toArray(new UUID[0]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package de.craftix.mineteleporters.database;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
public class SQLite {
|
||||
|
||||
protected String path;
|
||||
protected Connection con;
|
||||
|
||||
public SQLite(String path) {
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.getParentFile().mkdirs();
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
this.path = file.getAbsolutePath();
|
||||
connect();
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
if (isConnected()) return;
|
||||
try {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
con = DriverManager.getConnection("jdbc:sqlite:" + path);
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
if (!isConnected()) return;
|
||||
try {
|
||||
con.close();
|
||||
con = null;
|
||||
}catch (Exception e) { e.printStackTrace(); }
|
||||
}
|
||||
|
||||
public boolean isConnected() { return con != null; }
|
||||
|
||||
public void insert(String qry) {
|
||||
if (!isConnected()) throw new NullPointerException("SQLite not connected");
|
||||
try {
|
||||
con.prepareStatement(qry).executeUpdate();
|
||||
}catch (Exception e) { e.printStackTrace(); }
|
||||
}
|
||||
|
||||
public ResultSet getData(String qry) {
|
||||
if (!isConnected()) throw new NullPointerException("SQLite not connected");
|
||||
try {
|
||||
return con.prepareStatement(qry).executeQuery();
|
||||
}catch (Exception e) { e.printStackTrace(); }
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package de.craftix.mineteleporters.items;
|
||||
|
||||
import de.craftix.mineteleporters.MineTeleporters;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ItemCreator {
|
||||
|
||||
public static ItemStack createItem(Material material, String name, String... lore) {
|
||||
ItemStack item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(name);
|
||||
meta.setLore(Arrays.asList(lore));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack createItem(Material material, String name, boolean glow, String... lore) {
|
||||
ItemStack item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
if (glow) {
|
||||
meta.addEnchant(Enchantment.DAMAGE_ALL, 1, true);
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
|
||||
meta.setDisplayName(name);
|
||||
meta.setLore(Arrays.asList(lore));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack createTeleporter() {
|
||||
return createTeleporter("§rTeleporter");
|
||||
}
|
||||
|
||||
public static ItemStack createTeleporter(String name) {
|
||||
return ItemCreator.createItem(Material.EMERALD_BLOCK, name, MineTeleporters.getLore());
|
||||
}
|
||||
|
||||
public static ItemStack createPortableTeleporter() {
|
||||
return ItemCreator.createItem(Material.MAGMA_CREAM, "§rPortable Teleporter", true, MineTeleporters.getLore());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package de.craftix.mineteleporters.logic;
|
||||
|
||||
import de.craftix.mineteleporters.database.DBHandler;
|
||||
import de.craftix.mineteleporters.items.ItemCreator;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Menu implements Listener {
|
||||
private static final String TITLE = "§6Teleporters";
|
||||
|
||||
public static void openMenu(Player player) {
|
||||
Inventory inv = Bukkit.createInventory(null, 6 * 9, TITLE);
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
inv.setItem(i, ItemCreator.createItem(Material.GRAY_STAINED_GLASS_PANE, " "));
|
||||
}
|
||||
for (int i = 9*5; i < inv.getSize(); i++) {
|
||||
inv.setItem(i, ItemCreator.createItem(Material.GRAY_STAINED_GLASS_PANE, " "));
|
||||
}
|
||||
|
||||
TeleportLocation[] locations = DBHandler.getLocations(player);
|
||||
int index = 9;
|
||||
for (TeleportLocation loc : locations) {
|
||||
ItemStack item = ItemCreator.createItem(Material.EMERALD_BLOCK, "§r" + loc.name.replaceAll("&", "§"), "§7Click to teleport", "", "§7" + loc.uuid.toString());
|
||||
inv.setItem(index, item);
|
||||
index++;
|
||||
if (index >= 5*9) break;
|
||||
}
|
||||
|
||||
player.openInventory(inv);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (event.getClickedInventory() == null || !event.getView().getTitle().equals(TITLE) || event.getCurrentItem() == null) return;
|
||||
if (event.getClickedInventory() == event.getView().getBottomInventory()) return;
|
||||
event.setCancelled(true);
|
||||
if (event.getSlot() < 9 || event.getSlot() > 9*5) return;
|
||||
Player p = (Player) event.getWhoClicked();
|
||||
TeleportLocation location = DBHandler.getLocation(UUID.fromString(event.getCurrentItem().getLore().get(2).replace("§7", "")));
|
||||
if (location == null) return;
|
||||
location.location.setY(location.location.getY() + 2);
|
||||
location.location.setX(location.location.getX() + 0.5);
|
||||
location.location.setZ(location.location.getZ() + 0.5);
|
||||
p.teleport(location.location);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package de.craftix.mineteleporters.logic;
|
||||
|
||||
import de.craftix.mineteleporters.MineTeleporters;
|
||||
import de.craftix.mineteleporters.database.DBHandler;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
public class OnBlockListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (!event.getPlayer().getInventory().getItemInMainHand().getItemMeta().hasLore()) return;
|
||||
if (!event.getPlayer().getInventory().getItemInMainHand().getItemMeta().getLore().containsAll(Arrays.asList(MineTeleporters.getLore()))) return;
|
||||
|
||||
String name = event.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName();
|
||||
UUID teleporter = DBHandler.saveLocation(name, event.getBlockPlaced());
|
||||
DBHandler.addPlayer(event.getPlayer(), teleporter);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockDestroy(BlockBreakEvent event) {
|
||||
if (!event.getBlock().getType().equals(Material.EMERALD_BLOCK)) return;
|
||||
DBHandler.delLocation(event.getBlock());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInteractPortableTeleporter(PlayerInteractEvent event) {
|
||||
if (event.getPlayer().getInventory().getItemInMainHand().getItemMeta() == null) return;
|
||||
if (!event.getPlayer().getInventory().getItemInMainHand().getItemMeta().hasLore()) return;
|
||||
if (!event.getPlayer().getInventory().getItemInMainHand().getItemMeta().getLore().containsAll(Arrays.asList(MineTeleporters.getLore())) ||
|
||||
!event.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.MAGMA_CREAM)) return;
|
||||
|
||||
Menu.openMenu(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockClick(PlayerInteractEvent event) {
|
||||
if (!event.hasBlock() || event.getClickedBlock() == null) return;
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
if (event.getClickedBlock().getType() != Material.EMERALD_BLOCK) return;
|
||||
|
||||
TeleportLocation location = DBHandler.getLocation(event.getClickedBlock());
|
||||
if (location == null) return;
|
||||
boolean isNew = DBHandler.addPlayer(event.getPlayer(), location.uuid);
|
||||
if (isNew) event.getPlayer().sendMessage("§aDu kannst dich nun zu diesem Teleporter teleportieren!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package de.craftix.mineteleporters.logic;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class TeleportLocation {
|
||||
|
||||
public final String name;
|
||||
public final Location location;
|
||||
public final UUID uuid;
|
||||
|
||||
public TeleportLocation(String name, Location location, UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
}
|
||||
4
Plugins/MineTeleporters/src/main/resources/plugin.yml
Normal file
4
Plugins/MineTeleporters/src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
name: MineTeleporters
|
||||
version: '${project.version}'
|
||||
main: de.craftix.mineteleporters.MineTeleporters
|
||||
api-version: 1.18
|
||||
Reference in New Issue
Block a user