custom model data command + disable dungeon for now
This commit is contained in:
unurled 2022-05-24 11:25:35 +02:00
parent f82a3481ac
commit 0cf90ea696
12 changed files with 233 additions and 77 deletions

1
.gitignore vendored
View file

@ -8,6 +8,7 @@
api/
*.iml
worlds/
bin/
.gradle/
gradle.properties

View file

@ -1,14 +0,0 @@
version: "${version}"
motd: "YAY, Super server!"
motd-reload: "Server reloading!"
storage: "MONGODB" # switch between "MONGODB", "MYSQL"(not implemented), "YML"(currently making it)
# if MYSQL or MongoDB
username: "no_usr" # if mysql if you are on mongodb, add username in the url
password: "no_pass" # if mysql if you are on mongodb, add password in the url
url: "mongodb://localhost:27017"
useResourcePack: false
resource_pack_url: "https://mc-packs.net/" # recommend to use https://mc-packs.net/ => free resource pack hoster (will eventually develop one myself but not atm)
resource_pack_sha1: "sha1hallo" # sha1 hash
debug: true

View file

@ -1,49 +0,0 @@
name: Raxen
version: '${version}'
main: gq.unurled.raxen.Raxen
author: unurled
api-version: 1.18
depend: [ProtocolLib, PlaceholderAPI]
softdepend: [AureliumSkills, LuckPerms]
commands:
reloadplugin:
aliases:
- rlpl
- reloadpl
description: reload command that stops the server.
skills:
aliases:
- skill
description: skill command.
testgui:
description: test gui command
storage:
description: acces player storage
nbt:
description: nbt command
raxen:
description: raxen main command
itemlist:
aliases: itl
description: Open ItemList menu
entityspawn:
description: Spawn an custom entity
class:
description: player command that make them choose their class and then their stats
permissions:
raxen.reload.cmd:
description: reload command permission
raxen.test.gui.cmd:
description: testgui command permission
raxen.nbt.cmd:
description: nbt command permission
raxen.raxen.cmd:
description: raxen command permssion
raxen.itemlist.cmd:
description: itemlist command permission
raxen.entityspawn.cmd:
description: entityspawn command permission
raxen.class.cmd:
description: class command premission

View file

@ -55,10 +55,9 @@ repositories {
dependencies {
// lombok stuff
implementation 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
testCompileOnly 'org.projectlombok:lombok:1.18.22'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
implementation 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
testCompileOnly 'org.projectlombok:lombok:1.18.24'
// mongo stuff
implementation 'org.mongodb:mongodb-driver-sync:4.5.1'
@ -71,8 +70,8 @@ dependencies {
compileOnly 'net.luckperms:api:5.4'
compileOnly 'com.github.MilkBowl:VaultAPI:1.7.1'
compileOnly 'net.essentialsx:EssentialsX:2.19.4'
compileOnly 'com.fastasyncworldedit:FastAsyncWorldEdit-Core:2.1.0'
compileOnly 'com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit:2.1.0'
compileOnly 'com.fastasyncworldedit:FastAsyncWorldEdit-Core:2.1.2'
compileOnly 'com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit:2.1.2'
compileOnly 'me.clip:placeholderapi:2.11.1'
compileOnly 'net.citizensnpcs:citizens-main:2.0.29-SNAPSHOT'
compileOnly 'com.onarandombox.multiversecore:Multiverse-Core:4.3.1'
@ -81,7 +80,7 @@ dependencies {
}
group = 'gq.unurled'
version = '0.5.1'
version = '0.5.2'
description = 'Raxen'
java.sourceCompatibility = JavaVersion.VERSION_17

View file

@ -18,7 +18,7 @@ import static gq.unurled.raxen.utils.Utils.colorComp;
public final class Raxen extends JavaPlugin {
private static final String prefix = "<aqua>Rx</aqua><light_purple>></light_purple> ";
@Getter private static String version = "0.5.1";
@Getter private static String version = "0.5.2";
private final PluginManager pm = getServer().getPluginManager();
private static Raxen plugin;

View file

@ -0,0 +1,105 @@
package gq.unurled.raxen.commands.admin;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static gq.unurled.raxen.utils.Utils.*;
public class CustomModelDataCommand implements TabExecutor {
/**
* change custom model data of an item
* @param sender Source of the command
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args Passed command arguments
* @return
*/
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!(sender instanceof Player)) {
errorConsoleSender(sender);
return true;
}
Player p = (Player) sender;
if (!(p.hasPermission("raxen.custommodeldata.cmd"))) {
p.sendMessage(noPerms());
return true;
}
ItemStack it = p.getInventory().getItemInMainHand();
if (args.length == 0) {
p.sendMessage(colorComp("<gold>Usage: /custommodeldata <model-data-value> <item-name></gold>"));
return true;
}
if (!(isInt(args[0]))) {
Material material = Material.getMaterial(args[1]);
if (material != null) {
it = customModelData(new ItemStack(material), Integer.parseInt(args[0]));
p.getInventory().setItemInMainHand(it);
p.updateInventory();
} else {
p.sendMessage(colorComp("<red>Please specify a valid Item Name or a valid Integer.</red>"));
}
} else {
if (it != null && it.getType() != Material.AIR) { // check if player has an item in hand
// has item in hand applying the custom model data
it = customModelData(it, Integer.parseInt(args[0]));
p.getInventory().setItemInMainHand(it);
p.updateInventory();
} else {
p.sendMessage(colorComp("<red>Get an item in hand please or specify an item</red>"));
p.sendMessage(colorComp("<gold>Usage: /custommodeldata <model-data-value> <item-name></gold>"));
}
}
return true;
}
/**
* @param sender Source of the command. For players tab-completing a
* command inside of a command block, this will be the player, not
* the command block.
* @param command Command which was executed
* @param label Alias of the command which was used
* @param args The arguments passed to the command, including final
* partial argument to be completed
* @return
*/
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
final List<String> completions = new ArrayList<>();
List<String> SUB_COMMANDS= new ArrayList<>();
if (!(isInt(args[0]))) {
return Arrays.asList( "§c" + args[0]);
}
if (args.length == 2) {
for (Material mat : Material.values()) {
SUB_COMMANDS.add(mat.name());
}
StringUtil.copyPartialMatches(args[1], SUB_COMMANDS, completions);
Collections.sort(completions);
}
return completions;
}
private ItemStack customModelData(ItemStack it, Integer in) {
ItemMeta itm = it.getItemMeta();
itm.setCustomModelData(in);
it.setItemMeta(itm);
return it;
}
}

View file

@ -0,0 +1,27 @@
package gq.unurled.raxen.listener.player;
import gq.unurled.raxen.components.dungeons.Gate;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityPortalEnterEvent;
import static gq.unurled.raxen.utils.DungeonUtils.isInRange;
import static gq.unurled.raxen.utils.DungeonUtils.whichIsInRange;
public class PortalEvent implements Listener {
@EventHandler
public void PortalE(EntityPortalEnterEvent e) {
if (e.getEntity() instanceof Player) {
Player p = (Player) e.getEntity();
Location loc = e.getLocation();
// if loc is in range
if (isInRange(loc)) {
Gate g = whichIsInRange(loc);
//g.t
}
}
}
}

View file

@ -22,6 +22,7 @@ public class CommandManager {
private RaxenCommand raxenCommand;
private SpawnEntity entityspawn;
private ClassCommand classCommand;
private CustomModelDataCommand customModelDataCommand;
public CommandManager(Raxen main) {
this.main = main;
@ -31,6 +32,7 @@ public class CommandManager {
this.classCommand = new ClassCommand(this.main);
this.skillsCommand = new SkillsCommand(main);
this.raxenCommand = new RaxenCommand(main);
this.customModelDataCommand = new CustomModelDataCommand();
}
/**
@ -64,6 +66,11 @@ public class CommandManager {
main.getCommand("class").setTabCompleter(classCommand);
main.getCommand("class").setExecutor(classCommand);
main.getCommand("custommodeldata").setTabCompleter(customModelDataCommand);
main.getCommand("custommodeldata").setExecutor(customModelDataCommand);
}
}

View file

@ -4,17 +4,17 @@ import gq.unurled.raxen.Raxen;
import gq.unurled.raxen.components.dungeons.Dungeon;
import gq.unurled.raxen.components.dungeons.Gate;
import gq.unurled.raxen.components.dungeons.types.forest.ForestDungeon;
import org.bukkit.Location;
import java.util.HashMap;
import java.util.UUID;
public class DungeonsManager {
private Raxen main;
private HashMap<UUID, Gate> gates = new HashMap<>();
private HashMap<Gate, Location> gates = new HashMap<>();
private HashMap<String, Dungeon> dungeons = new HashMap<>();
private HashMap<Gate, Dungeon> dungeons = new HashMap<>();
public DungeonsManager(Raxen main) {
this.main = main;
@ -26,10 +26,16 @@ public class DungeonsManager {
*/
public void registerDungeons() {
ForestDungeon forestDungeon = new ForestDungeon();
dungeons.put("FOREST", forestDungeon);
dungeons.put(forestDungeon.getGate(), forestDungeon);
gates.put(forestDungeon.getGate(), forestDungeon.getGate().getLoc());
/*
for (String s : dungeons.keySet()) {
main.getManager().getWorldManager().loadWorld(dungeons.get(s).getName());
}
*/
}
public HashMap getGates() {
return gates;
}
}

View file

@ -1,9 +1,14 @@
package gq.unurled.raxen.utils;
import gq.unurled.raxen.Raxen;
import gq.unurled.raxen.components.dungeons.Gate;
import gq.unurled.raxen.components.dungeons.Rank;
import gq.unurled.raxen.components.dungeons.Types;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Random;
public class DungeonUtils {
@ -49,4 +54,50 @@ public class DungeonUtils {
Random r = new Random();
r.nextInt();
}
/**
* if a gate is in range of the player
* @return boolean
*/
public static Boolean isInRange(Location loc) {
Raxen main = (Raxen) Bukkit.getServer().getPluginManager().getPlugin("Raxen");
HashMap<Gate, Location> gats = main.getManager().getDungeonsManager().getGates();
for (Gate g : gats.keySet()) {
Double x = g.getLoc().getX();
Double y = g.getLoc().getY();
Double z = g.getLoc().getZ();
Double radius = Double.valueOf(g.getPortalRadius());
if (loc.getX() < x+radius && loc.getX() > x-radius) {
if (loc.getY() < y+radius && loc.getY() > y-radius) {
if (loc.getZ() < z+radius && loc.getZ() > z-radius) {
return true;
}
}
}
}
return false;
}
/**
* if a gate is in range of the player
* @return the gates which is in range
*/
public static Gate whichIsInRange(Location loc) {
Raxen main = (Raxen) Bukkit.getServer().getPluginManager().getPlugin("Raxen");
HashMap<Gate, Location> gats = main.getManager().getDungeonsManager().getGates();
for (Gate g : gats.keySet()) {
Double x = g.getLoc().getX();
Double y = g.getLoc().getY();
Double z = g.getLoc().getZ();
Double radius = Double.valueOf(g.getPortalRadius());
if (loc.getX() < x+radius && loc.getX() > x-radius) {
if (loc.getY() < y+radius && loc.getY() > y-radius) {
if (loc.getZ() < z+radius && loc.getZ() > z-radius) {
return g;
}
}
}
}
return null;
}
}

View file

@ -316,6 +316,10 @@ public class Utils {
return colorComp("<red>An Error has occurred. Please retry or contact an Admin.");
}
public static void errorConsoleSender(CommandSender sender) {
sender.sendMessage(colorComp("<red>Can't use this command as the console.</red>"));
}
/**
* Copy folder from sourceDirectoryLocation to destinationDirectoryLocation
* @param sourceDirectoryLocation the source directory
@ -350,4 +354,16 @@ public class Utils {
}
Files.delete(path);
}
public static boolean isInt(String strNum) {
if (strNum == null) {
return false;
}
try {
double d = Integer.parseInt(strNum);
} catch (NumberFormatException nfe) {
return false;
}
return true;
}
}

View file

@ -31,6 +31,11 @@ commands:
description: Spawn an custom entity
class:
description: player command that make them choose their class and then their stats
custommodeldata:
aliases:
- cmdata
- cmd
description: set custom model data to item
permissions:
raxen.reload.cmd:
@ -46,4 +51,6 @@ permissions:
raxen.entityspawn.cmd:
description: entityspawn command permission
raxen.class.cmd:
description: class command premission
description: class command permission
raxen.custommodeldata.cmd:
description: custom model data command permission