added kind of working jump plates (they placeing really isnt working)

This commit is contained in:
steev 2022-06-07 04:33:50 +02:00
parent 3714ffa85a
commit f9e1c5eb03
14 changed files with 243 additions and 99 deletions

8
Links.txt Normal file
View File

@ -0,0 +1,8 @@
https://www.google.com/search?client=firefox-b-d&q=hide+players+spigot
https://www.google.com/search?client=firefox-b-d&q=spigot+toggle+players
https://www.google.com/search?client=firefox-b-d&q=spigot+get+pressureplate+press
https://riptutorial.com/bukkit/example/25262/hiding-a-player-from-other-players
https://www.spigotmc.org/threads/hide-player.66254/
https://www.spigotmc.org/threads/launch-player-in-specific-direction.408591/
https://bukkit.org/threads/player-pressure-plate-event.161460/
https://www.spigotmc.org/threads/playerinteractevent-pressure-plate.403327/

View File

@ -1,63 +1,6 @@
menu:
navigator:
title: "Navigator"
material: "COMPASS"
slots: 54
slot: 4
permission: slpnet.lobby.navigator
items:
tridentwar:
title: "TridentWar"
material: "TRIDENT"
description: "test\ntest"
slot: 18
action:
type: "connect"
argument: "tw1"
bedwars:
title: "Bedwars"
material: "RED_BED"
description: "test\ntest"
slot: 20
action:
type: "connect"
argument: "tw1"
masterbuilders:
title: "Master Builder"
material: "CRAFTING_TABLE"
description: "test\ntest"
slot: 22
action:
type: "connect"
argument: "tw1"
profile:
title: "Profile"
material: "BOOK"
slot: 2
slots: 54
permission: slpnet.lobby.profile
items:
tridentwar:
title: "TridentWar"
material: "TRIDENT"
description: "test\ntest"
slot: 18
action:
type: "connect"
argument: "tw1"
bedwars:
title: "Bedwars"
material: "RED_BED"
description: "test\ntest"
slot: 20
action:
type: "connect"
argument: "tw1"
masterbuilders:
title: "Master Builder"
material: "CRAFTING_TABLE"
description: "test\ntest"
slot: 22
action:
type: "connect"
argument: "tw1"
forceSpawn: true
defaultSpawn: example
jumpPlates:
ground: EMERALD_BLOCK
plate: STONE_PRESSURE_PLATE
multiplier: 4

20
off.txt
View File

@ -1,20 +0,0 @@
Inventory inv = inventories.get(this.lobbyManager.getLobby().config.getString(key + ".title"));
// Nullpointer debugging
System.out.println(key + "0");
if(this.lobbyManager.getLobby().config.get("menu." + key + ".items") == null) System.out.println("Error: no items have been set, Menu will not be created"); // fixes nullpointer
if(this.lobbyManager.getLobby().config.get("menu." + key + ".items") == null) return; // fixes nullpointer
for(String keyItem : this.lobbyManager.getLobby().config.getConfigurationSection("menu." + key + ".items").getKeys(true)) {
if(this.lobbyManager.getLobby().config.get("menu." + key + ".items") == null) System.out.println("Error: no items have been set, Menu will not be created"); // fixes nullpointer
if(this.lobbyManager.getLobby().config.get("menu." + key + ".items") == null) return; // fixes nullpointer
// Error: material from config results null though it shouldn't
System.out.println(this.lobbyManager.getLobby().config.getString("menu."+key+".items."+keyItem+".material") + "1");
System.out.println(keyItem + "2");
inv.setItem(this.lobbyManager.getLobby().config.getInt("menu." + key + ".items." + keyItem + ".slot"),
createGuiItem(Material.getMaterial(this.lobbyManager.getLobby().config.getString("menu." + key + ".items." + keyItem + ".material")),
this.lobbyManager.getLobby().config.getString("menu." + key + ".items." + keyItem + ".title"),
this.lobbyManager.getLobby().config.getString("menu." + key + ".items." + keyItem + ".description")
)
);
}

View File

@ -9,6 +9,8 @@ import org.bukkit.entity.Player;
import java.util.Locale;
// TODO: Implement Permission handling
public class slpl implements CommandExecutor {
private LobbyManager lobbyManager;
private admin cmdAdmin;
@ -22,13 +24,20 @@ public class slpl implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player player = sender.getServer().getPlayer(sender.getName());
System.out.println("Debug -> Command Output");
System.out.println(args[0]);
System.out.println(args[1]);
System.out.println(args[2]);
if(args.length >= 0) {
switch (args[0].toLowerCase()) {
case "admin":
switch (args[1].toLowerCase()) {
case "help" -> admin.sendHelp(player);
case "setLoc" -> cmdAdmin.setLoc(player.getLocation(), args[2].toString().toLowerCase());
case "remLoc" -> cmdAdmin.remLoc(args[2]);
case "help" -> cmdAdmin.sendHelp(player);
case "setloc" -> cmdAdmin.setLoc(player.getLocation(), args[2].toLowerCase());
case "remloc" -> cmdAdmin.remLoc(args[2]);
case "setjump" -> cmdAdmin.setJumpPlate(player, args);
case "remjump" -> cmdAdmin.remJumpPlate(args[2].toLowerCase());
}
break;
}

View File

@ -2,8 +2,17 @@ package de.slpnetwork.lobby.Commands.subcommands;
import de.slpnetwork.lobby.Manager.LobbyManager;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import java.io.IOException;
import java.util.Locale;
// TODO: Implement Permission Handling
public class admin {
private LobbyManager lobbyManager;
@ -16,6 +25,69 @@ public class admin {
* @param player player reference
*/
public static void sendHelp(Player player) {
// Send help message (when done)
}
/**
* sets a Jumplate and adds it to config 1: Name, 2: Sound, 3: Vertical Speed, 4: Horizontal Speed, 5: x-grid plates, 6: y-grid plates
* @param args command arguments passed by executor
*/
public void setJumpPlate(Player player, String[] args) {
try {
if(args[1] != null) {
String sound = "ENTITY_GENERIC_EXPLODE";
int vertical = 1;
int horizontal = 8;
int grid_x = 1;
int grid_y = 1;
try {
if (args[3] != null) { sound = args[3]; }
if (args[4] != null) { vertical = Integer.parseInt(args[4]); }
if (args[5] != null) { horizontal = Integer.parseInt(args[5]); }
if (args[6] != null) { grid_x = Integer.parseInt(args[6]); }
if (args[7] != null) { grid_y = Integer.parseInt(args[7]); }
} catch (Exception ex){
}
// Check for arguments and place plates
if(grid_x > 1 && grid_y > 1) {
for(int x = Math.round((grid_x/2)*(-1)); x < Math.round((grid_x/2)); x++) {
for (int y = Math.round((grid_y/2)*(-1)); y < Math.round((grid_y/2)); y++) {
Location loc = new Location(
player.getWorld(),
player.getLocation().getBlockX() + x,
player.getLocation().getBlockY(),
player.getLocation().getBlockZ() + y
);
platePlacement(loc, args[1], horizontal, vertical);
}
}
} else {
platePlacement(player.getLocation(), args[1], horizontal, vertical);
}
// save data to files
this.lobbyManager.getLobby().jumpDataConfig.save(this.lobbyManager.getLobby().jumpData);
}
} catch (IOException exception) {
// Just dont do anything
}
}
/**
* removes a specific plate
* @param name the plates name
*/
public void remJumpPlate(String name){
try {
// TODO: Get the Plates Position
this.lobbyManager.getLobby().jumpDataConfig.set("plates." + name, null);
this.lobbyManager.getLobby().jumpDataConfig.save(this.lobbyManager.getLobby().jumpData);
} catch (IOException exception) {
}
}
/**
@ -24,7 +96,17 @@ public class admin {
* @param name locations reference name
*/
public void setLoc(Location loc, String name){
// set location in locations.yml
System.out.println("DEBUG -> SetLoc Input: " + name + ", " + loc);
try {
// set location in locations.yml
this.lobbyManager.getLobby().teleportDataConfig.set("locations." + name + ".name", name);
this.lobbyManager.getLobby().teleportDataConfig.set("locations." + name + ".world", loc.getWorld().getName());
this.lobbyManager.getLobby().teleportDataConfig.set("locations." + name + ".X", loc.getBlockX());
this.lobbyManager.getLobby().teleportDataConfig.set("locations." + name + ".Y", loc.getBlockY());
this.lobbyManager.getLobby().teleportDataConfig.save(this.lobbyManager.getLobby().teleportData);
} catch (IOException ex) {
// this is bads
}
}
/**
@ -33,5 +115,28 @@ public class admin {
*/
public void remLoc(String name){
// set location in locations.yml
// set location in locations.yml
this.lobbyManager.getLobby().teleportDataConfig.set("locations." + name, null);
try {
this.lobbyManager.getLobby().teleportDataConfig.save(this.lobbyManager.getLobby().teleportData);
} catch (IOException ex) {
// this is bads
}
}
// Prevents messy code
private void platePlacement(Location loc, String name, int horizontalVel, int verticalVel){
// Set Location
this.lobbyManager.getLobby().jumpDataConfig.set("plates." + name + ".location.world", loc.getWorld().getName());
this.lobbyManager.getLobby().jumpDataConfig.set("plates." + name + ".location.X", loc.getBlockX());
this.lobbyManager.getLobby().jumpDataConfig.set("plates." + name + ".location.Y", loc.getBlockY());
this.lobbyManager.getLobby().jumpDataConfig.set("plates." + name + ".location.Z", loc.getBlockZ());
// Set Modifier
this.lobbyManager.getLobby().jumpDataConfig.set("plates." + name + ".multiplier.vertical", verticalVel);
this.lobbyManager.getLobby().jumpDataConfig.set("plates." + name + ".multiplier.horizontal", horizontalVel);
Block plate = loc.getWorld().getBlockAt(loc);
plate.setType(Material.getMaterial(this.lobbyManager.getLobby().config.getString("jumpPlates.plate")));
}
}

View File

@ -0,0 +1,60 @@
package de.slpnetwork.lobby.Events;
import de.slpnetwork.lobby.Manager.LobbyManager;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.util.Vector;
public class PlayerInteract implements Listener {
private LobbyManager lobbyManager;
public PlayerInteract(LobbyManager lobbyManager) {
this.lobbyManager = lobbyManager;
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event){
if(event.getAction().equals(Action.PHYSICAL)) {
Player player = event.getPlayer();
Block block = event.getClickedBlock();
if(event.getClickedBlock().getType() == Material.getMaterial(this.lobbyManager.getLobby().config.getString("jumpPlates.plate"))) {
// TODO: Test Jumpplate Code
for(String key: this.lobbyManager.getLobby().jumpDataConfig.getConfigurationSection("plates").getKeys(false)) {
// Construct Launcher
System.out.println("DEBUG -> plate-key: " + key);
System.out.println("DEBUG -> loc world: " + this.lobbyManager.getLobby().jumpDataConfig.getString("plates." + key + ".location.world"));
System.out.println("DEBUG -> loc x: " + this.lobbyManager.getLobby().jumpDataConfig.getDouble("plates." + key + ".location.X"));
System.out.println("DEBUG -> loc y: " + this.lobbyManager.getLobby().jumpDataConfig.getDouble("plates." + key + ".location.Y"));
System.out.println("DEBUG -> loc z: " + this.lobbyManager.getLobby().jumpDataConfig.getDouble("plates." + key + ".location.Z"));
System.out.println("DEBUG -----------------------------------");
System.out.println("DEBUG -> loc world: " + block.getLocation().getWorld().getName() == this.lobbyManager.getLobby().jumpDataConfig.getString("plates." + key + ".location.world"));
System.out.println("DEBUG -> loc x: " + ((int)block.getLocation().getBlockX() == this.lobbyManager.getLobby().jumpDataConfig.getInt("plates." + key + ".location.X")));
System.out.println("DEBUG -> loc y: " + ((int)block.getLocation().getBlockY() == this.lobbyManager.getLobby().jumpDataConfig.getInt("plates." + key + ".location.Y")));
System.out.println("DEBUG -> loc z: " + ((int)block.getLocation().getBlockZ() == this.lobbyManager.getLobby().jumpDataConfig.getInt("plates." + key + ".location.Z")));
if((int)block.getLocation().getBlockX() == this.lobbyManager.getLobby().jumpDataConfig.getInt("plates." + key + ".location.X") &&
(int)block.getLocation().getBlockY() == this.lobbyManager.getLobby().jumpDataConfig.getInt("plates." + key + ".location.Y") &&
(int)block.getLocation().getBlockZ() == this.lobbyManager.getLobby().jumpDataConfig.getInt("plates." + key + ".location.Z")) {
// Launch Player in looking direction
System.out.println("DEBUG -> Launching Player");
player.setVelocity(new Vector(
player.getLocation().getDirection().multiply(this.lobbyManager.getLobby().jumpDataConfig.getInt("plates." + key + ".multiplier.horizontal")).getX(),
this.lobbyManager.getLobby().jumpDataConfig.getInt("plates." + key + ".multiplier.vertical"),
player.getLocation().getDirection().multiply(this.lobbyManager.getLobby().jumpDataConfig.getInt("plates." + key + ".multiplier.horizontal")).getZ()));
// Player Sound
player.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_GROWL, 5.0f, 1.0f);
}
}
}
}
}
}

View File

@ -1,8 +1,10 @@
package de.slpnetwork.lobby;
import de.slpnetwork.lobby.Commands.slpl;
import de.slpnetwork.lobby.Events.PlayerInteract;
import de.slpnetwork.lobby.Manager.InventoryManager;
import de.slpnetwork.lobby.Manager.LobbyManager;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@ -17,11 +19,8 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.PluginMessageListener;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.file.Files;
// TODO: Impplement Pluginmetrics
public class Lobby extends JavaPlugin implements Listener, PluginMessageListener {
public LobbyManager lobbyManager;
public FileConfiguration config;
@ -31,7 +30,8 @@ public class Lobby extends JavaPlugin implements Listener, PluginMessageListener
public FileConfiguration menuDataConfig;
public File teleportData;
public FileConfiguration teleportDataConfig;
public File jumpData;
public FileConfiguration jumpDataConfig;
@Override
public void onEnable(){
@ -44,27 +44,32 @@ public class Lobby extends JavaPlugin implements Listener, PluginMessageListener
itemData = new File(this.getDataFolder(), "items.yml");
menuData = new File(this.getDataFolder(), "menus.yml");
teleportData = new File(this.getDataFolder(), "locations.yml");
jumpData = new File(this.getDataFolder(), "jumps.yml");
if(!itemData.exists() || !menuData.exists() || !teleportData.exists()) {
System.out.println("Loading config files");
itemData = new File(this.getDataFolder(), "items.yml");
menuData = new File(this.getDataFolder(), "menus.yml");
teleportData = new File(this.getDataFolder(), "locations.yml");
jumpData = new File(this.getDataFolder(), "jumps.yml");
itemDataConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(this.getResource("items.yml")));
menuDataConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(this.getResource("menus.yml")));
teleportDataConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(this.getResource("locations.yml")));
jumpDataConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(this.getResource("jumps.yml")));
itemDataConfig.save(itemData);
menuDataConfig.save(menuData);
teleportDataConfig.save(teleportData);
jumpDataConfig.save(jumpData);
}
itemDataConfig = YamlConfiguration.loadConfiguration(itemData);
menuDataConfig = YamlConfiguration.loadConfiguration(menuData);
teleportDataConfig = YamlConfiguration.loadConfiguration(teleportData);
jumpDataConfig = YamlConfiguration.loadConfiguration(jumpData);
}catch (Exception ex) {
this.getServer().getLogger().warning("Could not load or create files due to exceotion: " + ex.getLocalizedMessage());
this.getServer().getLogger().warning("Could not load or create files due to exception: " + ex.getLocalizedMessage());
}
this.lobbyManager = new LobbyManager(this);
@ -72,6 +77,7 @@ public class Lobby extends JavaPlugin implements Listener, PluginMessageListener
this.getCommand("slpl").setExecutor(new slpl(this.lobbyManager));
this.getServer().getPluginManager().registerEvents(this, this);
this.getServer().getPluginManager().registerEvents(new PlayerInteract(this.lobbyManager), this);
this.getServer().getPluginManager().registerEvents(new InventoryManager(this.lobbyManager), this);
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", this);

View File

@ -15,6 +15,8 @@ import org.bukkit.inventory.meta.ItemMeta;
import java.util.Arrays;
import java.util.HashMap;
//TODO: Implement Permission Handling
public class InventoryManager implements Listener {
private final LobbyManager lobbyManager;
private HashMap<String, Inventory> inventories;

View File

@ -0,0 +1,6 @@
package de.slpnetwork.lobby.Manager;
// TODO: Figure out how Settings can be Implemented
public class SettingsManager {
}

View File

@ -1,8 +1,11 @@
package de.slpnetwork.lobby.Utils;
import de.slpnetwork.lobby.Manager.LobbyManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.Locale;
import java.util.Objects;
public class CommandInterpreter {
@ -26,13 +29,19 @@ public class CommandInterpreter {
this.lobbyManager.getInventoryManager().openInventory(executor, args);
break;
case "teleport":
this.lobbyManager.getPlayerManager().teleportPlayer(executor, this.lobbyManager.getLobby().teleportDataConfig.getLocation("locations." + args));
this.lobbyManager.getLobby().teleportDataConfig.getLocation("locations." + args);
Location destination = new Location(Bukkit.getServer().getWorld(this.lobbyManager.getLobby().teleportDataConfig.getString("locations." + args + ".world")),
this.lobbyManager.getLobby().teleportDataConfig.getDouble("locations." + args + ".X"),
this.lobbyManager.getLobby().teleportDataConfig.getDouble("locations." + args + ".Y"),
this.lobbyManager.getLobby().teleportDataConfig.getDouble("locations." + args + ".Z"));
this.lobbyManager.getPlayerManager().teleportPlayer(executor, destination);
break;
case "connect":
this.lobbyManager.getPlayerManager().moveFromServer(args, Objects.requireNonNull(executor.getPlayer()));
break;
case "execute":
// Not yet implemented
// Might be droped during development phase
break;
}
}

View File

@ -10,4 +10,4 @@ items:
display: "Profile"
slot: 2
material: "BOOK"
permission: "lobby.item.profil"
permission: "lobby.item.profile"

View File

@ -0,0 +1,10 @@
plates:
example:
multiplier:
vertical: 4
horizontal: 1
location:
world: world
X: 0
Y: 0
Z: 0

View File

@ -1 +1,7 @@
locations:
example:
name: example
world: world
X: 0
y: 0
Z: 0

View File

@ -14,13 +14,13 @@ menus:
type: "connect"
argument: "tw1"
RED_BED:
title: "Bedwars"
title: "Spawn"
material: "RED_BED"
description: "test\ntest"
slot: 20
action:
type: "connect"
argument: "tw1"
type: "teleport"
argument: "spawn"
CRAFTING_TABLE:
title: "Master Builder"
material: "CRAFTING_TABLE"