public void executeCommand(World w, String s, Entity e) {
Location loc;
ArmorStand stand;
Location entityLoc = e.getLocation();
loc = new Location(w, entityLoc.getX(), entityLoc.getY() - 300, entityLoc.getZ());
stand = (ArmorStand) w.spawnEntity(loc, EntityType.ARMOR_STAND);
stand.setVisible(false);
stand.setGravity(false);
Bukkit.getServer().dispatchCommand(stand, s);
Bukkit.broadcastMessage("Test");
stand.remove();
}
#help-development
1 messages Β· Page 2149 of 1
for some reason, when i took a bunch of projects and then put them together (made sure that they had no errors, and I just copied and pasted the code) only the main class worked. any ideas why?
so what cases would commands need to be specific to a certain world? maybe some vanilla ones but it would be possible to just make another command with world support
hello there,
im a bit new to calling events, but I was wondering what the reason could be that I cant call an event in a loop like this:
Bukkit.getServer().broadcastMessage("Linkcount: " + links.size());
if (e.GetRedstoneDevice().HasLinks())
for (int i = 0; i < links.size(); i++) {
Bukkit.getServer().broadcastMessage("Trigger!");
Bukkit.getServer().getPluginManager().callEvent(new BreakEvent(links.get(i), e.GetPlayer()));
}
Bukkit.getServer().broadcastMessage("Done!");
My links List has 2 items. Now I want to iterate over both (or all) of them. However no matter how many items I got in my list. All my code stops after calling for the first event. Not sure how to bypass this or why this happens. Spigot 1.18.2
Output of thise code:
Linkcount: 2
Trigger!
Done!
sounds like an exception might be getting thrown
First of all: Add brackets to all your codeblocks.
for example lets say, /effect give, and searching for an entity at a entity's coords or nearby it (but the command can be literally anything), i already have the x, y and z coord down for lets say the "hit" entity from a entitydamagebyentity event, anyways any solution to what i was asking originally?
alr ill see if that fixes it
Probably not
nope indeed, doesnt work
are you getting any exceptions in console?
Do an enhanced for loop
none
idk why it would work in one of your classes but not the other then
also, im not exactly sure why you would be able to get the x y and z but not the world, location contains that
for(Link link : links) {
Bukkit.getServer().broadcastMessage("Trigger!");
Bukkit.getServer().getPluginManager().callEvent(new BreakEvent(link, e.GetPlayer()));
}
so i have an event listener that listens for InventoryOpenEvent, when it equals the player's ender chest i cancel the event and open my own custom ender chest GUI
Question, so we were messing around with attriubte modifiers and know we have no idea how to remove it.
This is how we set the attribute:
problem is, when i close the ender chest, the ender chest block is still open
how do i cleanly close the ender chest
use playerinteractevent and see if the clicked block is an ender chest
it was experimental code tbh
trying different things
then the ender chest doesnt open at all
Modifiers have group names (Strings) and identifier (UUIDs)
to see if my solution was fixed and later fix up the optimization
well, im not exactly sure then. havent really made entities run commands before
Okay? And how does that help?
can you send your code for the inventoryopenevent then
(btw you could just open the enderchest animation with packets)
Thats how you identify attributes you want to remove
already did
Like this?
player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).removeModifier(new AttributeModifier("Boost", speed, AttributeModifier.Operation.MULTIPLY_SCALAR_1));
@EventHandler
public void enderChestOpenListener(InventoryOpenEvent event) {
if (event.getInventory().equals(event.getPlayer().getEnderChest())) {
if (ExtendedEnderChest.openedEnderChest.contains(event.getPlayer().getUniqueId())) return;
event.setCancelled(true);
ExtendedEnderChest.openedEnderChest.add(event.getPlayer().getUniqueId());
Bukkit.getScheduler().runTaskLater(Main.instance, new Runnable() {
public void run() {
ExtendedEnderChest gui = new ExtendedEnderChest();
gui.openInventory((Player) event.getPlayer());
}
}, 1L);
}
}
ender chest block opens fine and the gui appears
well then just cancel playerinteractevent and send the packet?
oh
yes but my event is deleting one of the items in that list, ill get an error for modifying it
right now i have this
Show the whole code please
also dont really think it would make a difference but you should add @Override to the run method
yeah
right now my solution was to use reflection to get the net.minecraft.world.level.block.entity.TileEntityEnderChest
then call the stopOpen method
which reduces the open counter
and sends a packet to the client to close the chest
and the chest immediately reopens
no NMS does that for me
seems a bit overkill
i just tell NMS that the player closed the chest
@valid totem try looking at this https://www.spigotmc.org/threads/open-chest-animation.333678/
the event being called is doing only this:
for (int i = 0; i < links.size(); i++){
if(links.get(i).getId().equalsIgnoreCase(id)){
links.remove(links.get(i));
return;
}
}
outdated
and i already tried it
hm
what if i tell craftbukkit that the chest closed instead of NMS
i call some method on CraftEnderChest
you dont just wanna instantly close the inventory
Cant help you if you dont show your code π€·
also basicly when i remove that iteration the event doest trigger twice like it is supposed to.
the vanilla one or custom one?
custom one
@lost matrix ill have to dm you to avoid spam
Or make a thread?
sure if u want to
?paste
right now im just grepping craftbukkit codee
heyyy this looks very promising
wait it literally calls the same method
:q
- You should use a Map<String, Link> inside RedstoneDevice
- You should not store the players id as a String. Just keep it a UUID...
alr thnx ill see if it fixes
is there something wrong with this?
commands:
ArrowLogs:
ArrowShot:
Flag:
w:
w2:
fumble:
h:
pc:
```?
yes
what is it?
you are just creating a key of something with no value
this is a plugin.yml
You should never have getters for any collections. No getters for lists, sets, maps etc.
Make .GetLinks() return a copy of your original data. This will fix the ConcurrentModificationException
so how should I do multiple commands?
so what is the problem you are having then
that only the first command works
are you registering them?
alright i added a getter GetLinks()
public List<Link> GetLinks(){
return links;
}
altough running it again seems to not help
like doing:
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(cmd.getName().equalsIgnoreCase("ArrowShot")) {
cause that was how i was taught
it might work but it is also incredibly messy and buggy
make a command executor for every command
well it works for the commands i use when i put the commands in different classes
actually I figured out the problem
only my main class works
how do I fix that?
like any ideas whats wrong
A bunch of listeners
listeners for?
@lost matrix the code works and iterates through the list properly calling the event multiple times when I remove the code in the Break() function:
public void BreakLink(String id){
//for (Link link : GetLinks())
// if(link.getId().equalsIgnoreCase(id)){
// links.remove(link);
// return;
// }
}
people being shot, shooting, placing blocks
and some commands
like one that starts a count down
ok so can you send the code for the commands
yes
im assuming its not working in your other classes since you're using the not correct way of using the javaplugin command registering
in which case you would want to use commandexecutors
ok
public class Whistle extends JavaPlugin {
@Override
public void onEnable() {
// startup
// reloads
// plugin reloads
}
@Override
public void onDisable() {
//shutdown
//reloads
//plugin reloads
}
// /hello <-- Hey welcome!
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (label.equalsIgnoreCase("w")) {
if (sender instanceof Player) {
// player
Player player = (Player) sender;
if (player.hasPermission("Hello.use")) {
Bukkit.broadcastMessage(ChatColor.WHITE + "<" + ChatColor.AQUA + "BlockyRef" + ChatColor.WHITE + "> " + ChatColor.RED + "" + ChatColor.BOLD + "THE REFEREE HAS WHISTLED STOP THE GAME");
for (Player players1 : Bukkit.getOnlinePlayers())
{
players1.playSound(players1.getLocation(), Sound.ENTITY_ARROW_HIT, 1, 1);
return true;
}
}
player.sendMessage(ChatColor.RED + "You do not have permission!");
return true;
}
else {
// console
sender.sendMessage("Hey console!");
return true;
}
}
return false;
}
}}
ik its probably messy
so this is your main class?
how do i close the chest
no
why is it extending javaplugin then...
yes...
ok ty
there is only supposed to be one class that extends javaplugin
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
would I also delete on enable?
yes
ok ty
callEvent in loop
would I also register all my listeners in my main class?
@crisp steeple so I did what you said and most of the stuff works. But the classes I have where there are commands AND listeners wont work, any fixes?
you should seperate command and listener classes for sake of organization
when doing this you have to make sure you register not only the command but also the listener
ok
The Worldgaurd docs are quite bad, does anyone know how to check what region a player is in?
Commenting in between method invocations is different. I'd personally do // getEnderChestInventory(), stopOpen() at the end of the line, but I guess it's a matter of preference and readability
whats the event when someone double clicks an item to get all items of the stack to get picked up by the cursor
for ex theres 32 dirt in the chest
and 32 in my inventory
i double click the 32 in my inventory and now i have all 64
this is so cursed
are you cancelling the click menu slot event? (Clicking items inside the inventory menu)
no
then there you go
well
"Ender Chest"
an ender chest but you cant put items in
so unless there's some kind of spigot thing you could do here, there's two options
You could rename the glass panes to something specific so that the player won't have the item and therefore cannot double click it, although you're already doing this so I assume you don't want this
yeah no player has glass panes called " "
but on hypixel skyblock someone gave me these "menu glass" and i was farming free glass from the guis
you could also make ur own system, where you set the slot item to the cursor item if the clicked item is air, or add to the item's stack size if it's not air
might look jank but yk
can someone help me please ?
If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply. Make sure you use the right channel regarding the topic of your question. Create a thread in case the channel is already in use!
is it possible to detect te mouse scrolling when a player spectate an entity ???
you need to set the player's gamemode to creative after you set the spectate target
make sure you clear their inventory every tick though
and also cancel drop item
how would setting a players gamemode to creative let you detect mouse scrolling
can't use hotbar events otherwise
thereβs a way to stop double clicking certain items out
also you wanna lock the hotbar slot to 5 (cancel change slot event) and check if the event slot is above or below 5 to see if they scrolled down or up
thanks π
you would want to cancel the item creation event
thereβs a lot of ways you could get around this otherwise
Wait, if I install an api as a jar file, can I still import it through pom.xml somehow or should I add it as a module
is there a way to hide the HUD when the gamemode is survival???
i mean not with f1
i mean force hide the HUD
that's why you should set the gamemode to creative
so that the xp bar doesn't show
yoo
this sucks, im compiling a plugin with maven in intellij and I know it's usually 2mb but somehow now every time I compile it's 25kb
needless to say it doesn't load, but also doesn't give any errors or warnings
<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>io.github.TurpCoding</groupId>
<artifactId>EasyReport</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>EasyReport</name>
<description>Easy and simple way to report players, all additional features are disabled by default.</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<url>TurpCoding.github.io</url>
<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>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>```
here is the pom
can someone please help me
?paste
fuck all if I'm reading that in that format
very creative!
thats actually really cool
thats really fucking cool
is that an already made plugin
by you i suppose
sheesh that is real cool
I tried to Maven import it but I am still getting the same the error
are you importing spigot or spigot-api
does opening another inventory over an already opened inventory call inventorycloseevent for that inventory
Yes, but don;t open an inventory from teh InventoryClickEvent
yep, thats teh correct way to do it
Hello! Has anyone ever heard anything about being able to apply the worldborder effect to something? https://i.imgur.com/kJi8K6j.png
I have a use case where I'd like to apply this effect to a certain area. I don't want it to be the worldborder, but I'd like to use the graphical effect.
So you just want the red screen effect?
If Mojang keeps adding materials, I think some one needs to categorize them π€·
8 GB of ram is not even enough for Intelij when trying to use Materials π It always freeze for several seconds π¦
Finally I did it... Any exception my plugin throw, Is now handled by my own plugin!
I've never seen 8 GB of ram being used by intellij with multiple instances of things open and running π
I had a horrible problem with intellij today using horrible amounts of resources
What is the most efficient way to check if a random location is within a border spigot
Get the size of the world border and check if the value of the random location is less than or equal to the size of the border.
Well that was my initial thought, but the world border is constantly moving so there's no telling where the world could go to which could present an issue.
That shouldn't be an issue though. As long as you are grabbing an updated/recent value, then it should be fine.
Well if I'm going to getting locations hundreds if not thousands of times fairly consistently couldn't that start to slow down the server?
Because it's impossible to know how many times it will have to retry to find a safe location
My other thought was maybe to use the world border and size to create some sort of mathematical function that could get a random location
Only if you are actually dealing with locations on that scale.
The world border is just a number. So it won't take up that much memory. Locations on the other hand, they take up a little bit more.
Are you planning on having thousands of locations checked frequently?
Yes, upwards of 5 minutes straight
That's why I think this may be better
Hmm, what are you creating here? Because I'm under the impression its something like a random teleport system that checks for safe locations.
It is, but its for hundreds of entities
Not just players?
Not players at all, it would be mobs such as creepers, enderman, pigs, cows, etc.
could i ask how you managed that? π
Interesting. What's the purpose? A gamemode? Simulated mob spawning?
Sort of like entity raining
Idk I'm just bored and want to test it out
Thought I might be able to learn from it
Overrided the logger!
Well if you are worried about the performance, it'll come down to how you make your safe location check. It's what will be called the most. If you take what most rtp plugins use for players and modify it to allow entities, then it shouldn't be that bad.
It all depends on your world/map and what you are checking for. If you are just trying to avoid lava, you likely won't have more than 5 tries at the worst per entity. If you need a more thorough check like no lava and the surrounding area around the entity, then it will become more computational heavy.
I can see the next generation of plugins using this π
I made a (intentional) NPE (with no try and catch) in the code and instead of a full trace back I have this
Im already using something similar but I still try catch and save it to a log file
imagine a while loop which always throws an exception, wouldnt wanna have a file for each one
How can i get the display name of the block i am placing so that i can avoid player from placing a specific block?
np
Call a BorderMoveEvent once the safe location has been finally found and do your calculations there
Easy
Ofc make that class
guys is there a way to listen for a player's inventory update and get the item(s) added to it ?
with packets or whatever
im trying to make a rarity system
i am trying to summon a sqaure wall of custom length but i am getting messed up by loop,is there any way or formula i can use to summon it?
well, what do you mean by added?
there is no generic event you could check for
you will have to loop
the items removed or added to the inventory
of a player
i am trying but the way i am using it just creates wierd shape i want it to be a sqaure
so show us what you got (code+screens would be useful)
you would have to listen to every event that is fired when an item is added (pickup, inventorydrag, etc) and removed(drop, inventorydrag, etc)
for(float i=0;i<4;i++){
Block block1 = locationInFront.add(0,i,0).getBlock();
block1.setType(Material.COBWEB);
Block block2 = locationInFront.add(1,i,0).getBlock();
block2.setType(Material.COBWEB);
Block block3 = locationInFront.add(0,i,1).getBlock();
block3.setType(Material.COBWEB);
}```
I cant attach image?
Doesn't the exception break the loop π€
(My exception handler has a try catch to make sure if something went wrong it gets handled as well)
But now you mentioned it... I think I will try to not save duplicated errors.
well maybe not a loop, but something that gets called a lot... just had something the other day that gave me an error in my log file in the CreatureSpawnEvent, it was a good way to recognize and fix unnecessary method calls in my case...
how do i use database pls tell
youre not gonna get a full course on databases here so youre gonna have to be specific
?notworking
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
verify
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
ok so
i do that
.append("wheels", 4)
.append("isFast", true);
col.insertOne(data);
i try that
and it doesnt work
all good things are 3 huh
never hardcode that
Why is the password hardcoded ;/
?
Why hardcode a password when you can make it configurable, saving time in case a server node dies or the IP switches
how do you prevent your personal db password from getting into the hands of people who decompile your jar file?
been wondering that for a good while now
Something like this?
at one point I had 72k lines of errors in my log file
I use my web server to get and save data (RestAPI)
I minimized a full traceback into just one line π€·
well the good thing is that I knew I had to fix something
normally your personal DB isnt in the hand of others
Not fully secure but better than having DB info in the plugin
as long as you authenticate it
how would one authenticate it when the plugin runs on a lot of servers
with a token or whatever
hey guys
I am getting an error while serializing my YAML file
it says it cant find my custom class
Stack trace please. Does your custom class implement ConfigurationSerializable?
Yes it does
give me a second
even though I
-Register it
-have a constructor with map<String, Object>
-have a valueOf method
-have a deserialize method
One of them is enough. Remove the other ones.
.
This might indicate that you are trying to load a yml file before the class loader of your plugin is initialized.
gimme a sec imma check quickly
When are you loading this file?
So in your onLoad?
@Override
public void onEnable() {
// Plugin startup logic
portalsFile = new File(getDataFolder(), "portals.yml");
if (!portalsFile.exists()) {
config = new YamlConfiguration();
List<Portal> portalList = List.of(createDefaultPortal(), createDefaultPortal());
config.set("portals", portalList);
try {
config.save(portalsFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
config = YamlConfiguration.loadConfiguration(portalsFile);
}
ConfigurationSerialization.registerClass(Portal.class, "Portal");
this.getCommand("vreload").setExecutor(new ReloadConfig(this));
this.getServer().getPluginManager().registerEvents(new PlayerBlockEnterEvent(this), this);
loadPortals();
}
private void loadPortals() {
config.getMapList("portals")
.forEach(map -> portals.add(Portal.deserialize((Map<String, Object>) map)));
}
Your loadPortals method is not quite right.
It should be
((List<Portal>)config.getList("portals")).forEach(portal -> portals.add(portal));
o
wait a second
lemme show my yaml
as i was confused bout this part
the yaml is kinda like this
- objectOne:
.....
- objectTwo:
.....
I know how your yaml file looks like by looking at your default creation
Its a list of objects. In your case: A list of Portal
o
Whats the type of your "portals" variable?
Then you can either use the bulk operator:
portals.addAll((List<Portal>)config.getList("portals"));
Or directly define it with the deserialized stuff:
portals = (List<Portal>)config.getList("portals");
Whatever you prefer.
public final class VClasses extends JavaPlugin {
private YamlConfiguration config;
private List<Portal> portals = new ArrayList<>();
private File portalsFile;
@Override
public void onEnable() {
// Plugin startup logic
portalsFile = new File(getDataFolder(), "portals.yml");
if (!portalsFile.exists()) {
config = new YamlConfiguration();
List<Portal> portalList = List.of(createDefaultPortal(), createDefaultPortal());
config.set("portals", portalList);
try {
config.save(portalsFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
config = YamlConfiguration.loadConfiguration(portalsFile);
}
ConfigurationSerialization.registerClass(Portal.class, "Portal");
this.getCommand("vreload").setExecutor(new ReloadConfig(this));
this.getServer().getPluginManager().registerEvents(new PlayerBlockEnterEvent(this), this);
loadPortals();
}
public YamlConfiguration getConfig() {
return config;
}
public List<Portal> getPortals() { return portals; }
public File getPortalsFile() { return portalsFile; }
private Portal createDefaultPortal() {
Location start = Bukkit.getWorlds().get(0).getSpawnLocation();
Location end = Bukkit.getWorlds().get(0).getSpawnLocation();
List<String> commands = List.of("/spawn %p%", "/help");
List<ItemStack> items = List.of(new ItemStack(Material.STONE, 32), new ItemStack(Material.COBBLESTONE, 32));
List<PotionEffect> effects = List.of(new PotionEffect(PotionEffectType.ABSORPTION, 500, 1));
return new Portal(start, end, commands, items, effects);
}
private void loadPortals() {
portals.addAll(((List<Portal>) config.getList("portals")));
}
}
Then you can either use the bulk operator:
portals.addAll((List<Portal>)config.getList("portals"));
Yea i m doing ths thing
One bracket pair too many
wdym
portals.addAll(((List<Portal>) config.getList("portals"))); -> portals.addAll((List<Portal>) config.getList("portals"));
getting this error
@Override
public void onEnable() {
// Plugin startup logic
portalsFile = new File(getDataFolder(), "portals.yml");
if (!portalsFile.exists()) {
config = new YamlConfiguration();
List<Portal> portalList = List.of(createDefaultPortal(), createDefaultPortal());
config.set("portals", portalList);
try {
config.save(portalsFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
config = YamlConfiguration.loadConfiguration(portalsFile);
}
ConfigurationSerialization.registerClass(Portal.class, "Portal");
this.getCommand("vreload").setExecutor(new ReloadConfig(this));
this.getServer().getPluginManager().registerEvents(new PlayerBlockEnterEvent(this), this);
loadPortals();
}
are you using a ConfigurationSerializable?
('io.github.vinesh27.vclasses.entities.Portal')
yes
I did that
i jsut saw
you need to do it BEFORE load the config
is there a simple way to track if a player is stationary, for context im making a stamina system and i want the player to regenerate stamina faster when not moving
you can create an object for the player
and store the old location
and have a runnable that runs each tick
and see if the player moved
or just use player move event
doesnt get ran if the player doesn't move and it still runs every tick
also runs if u move camera tho
thatts the problem
just do this tho
doesnt ran if the player is stopped
he will need a runnable
to see if the player is stopped
r u guys talking abt the same thing lmfao im so confused
uhh
so
i get a runnable
and grab the location x y z of a player
class MyPlayer {
Player player;
boolean stopped;
}```
and at the move event, set stopped to false
i lost myself
//Check if the player is in a portal and get which one is it
public Portal getPortal(Player player) {
for (Portal portal : vClasses.getPortals()) {
BoundingBox box = BoundingBox.of(
portal.startBlock(),
portal.endBlock()
);
if(box.overlaps(player.getBoundingBox()))
return portal;
}
return null;
}
This is how I check if a player is inside a specific portal, but even though the player is, it returns null
public PlayerMove(PlayerMoveEvent e){
if (e.getTo().getX() == e.getFrom().getX()){
//stationary, do this for y and z too
}
}
@EventHandler
public void onPlayerEnterPortal(PlayerPortalEvent event) {
Portal portal = util.getPortal(event.getPlayer());
if(portal == null) {
System.out.println("Portal is null");
return;
}
util.giveRewards(portal, event.getPlayer());
}
yeah but the problem with playermove event is that im pretty sure if u move ur camera it procs?
so i do this
what is the startBlock and endBlock type
location
like, are they a Location or Vector
Location
and then set moving to false when i track movement with this
yes
make sure to check the y and z variables too
so you could check for playerVector.isInAABB(start, end)
oo
withou needing to create 2 vectors object
you would create only 1 from playerLocation.toVector
or
wait
@golden kelp
you can simply grab the code inside isInAABB
o nice
and create a separate method that accepts location
//Check if the player is in a portal and get which one is it
public Portal getPortal(Player player) {
for (Portal portal : vClasses.getPortals()) {
// BoundingBox box = BoundingBox.of(
// );
boolean x = player.getLocation().toVector().isInAABB(
portal.startBlock().toVector(),
portal.endBlock().toVector()
);
if(x) {
System.out.println("In the portal B");
return portal;
}
}
return null;
}
not working
says portal is null
public boolean isInAABB(Location toCheck, Location start, Location end) {
if (!location.getWorld().equals(start.getWorld())
return false;
//grab code from the vector class
}```
line 391
do the same
but with Location
using the star and end
start will be the min
end will be the max
use getters
return x >= min.x && x <= max.x && y >= min.y && y <= max.y && z >= min.z && z <= max.z;
this is some smart af maths i m too dumb to understand xD
it just looks complicated
that is not math
really isnt
yes
it is just a greater than smaller than check
i would use the getX
to be more precise
aight
Stil
Still
nvm wait a sec
Nop, the portal is still null
//Check if the player is in a portal and get which one is it
public Portal getPortal(Player player) {
for (Portal portal : vClasses.getPortals()) {
if(isInAABB(player.getLocation(), portal.startBlock(), portal.endBlock())) {
System.out.println("In the portal B");
return portal;
}
}
return null;
}
public boolean isInAABB(Location toCheck, Location start, Location end) {
if (!toCheck.getWorld().equals(start.getWorld()))
return false;
//grab code from the vector class
return
toCheck.getX() >= start.getX()
&& toCheck.getX() <= end.getX()
&& toCheck.getY() >= start.getY()
&& toCheck.getY() <= end.getY()
&& toCheck.getZ() >= start.getZ()
&& toCheck.getZ() <= end.getZ();
}
bump
what is the goal here?
to check if the player went through a specific portal
and if he did
return that one
and what is a start and endblock of a portal?
and this big confusing block of booleans
Took the suggestion from here
so you want to check if the player is standing in a portal, right?
and the portals location is probably just a location?
wdym
yes
and i have confirmed the coords in the code are same
(i get them from the config)
either or question : yes
oh
sorry
is it like a huge area
yes
public Portal(
Location startBlock,
Location endBlock,
List<String> commands,
List<ItemStack> items,
List<PotionEffect> effects
) {
this.startBlock = startBlock;
this.endBlock = endBlock;
this.commands = commands;
this.items = items;
this.effects = effects;
}
this is a portal
Whoever sent me the article from spigot explaining about databases and how it should be done, may god bless you.
well, step by step. are in the list any entries?
yes
I printed the entry as I iterate it, and it did show the right portal (object, not the ingame portal)
Is it better to use MysqlDataSource, or DriverManager, if so, what is the difference ?
If someone can explain?
Everything else works fine, it just cant find if its that portal
debug it and see where it fails
//Check if the player is in a portal and get which one is it
public Portal getPortal(Player player) {
for (Portal portal : vClasses.getPortals()) {
player.sendMessage(portal.toString() + "\n");
if(isInAABB(player.getLocation(), portal.startBlock(), portal.endBlock())) {
System.out.println("In the portal B");
return portal;
}
if(isInAABB(player.getLocation(), portal.endBlock(), portal.startBlock())) {
System.out.println("In the portal B");
return portal;
}
return portal;
}
return null;
}
here
public boolean isInAABB(Location toCheck, Location start, Location end) {
if (!toCheck.getWorld().equals(start.getWorld()))
return false;
return
toCheck.getX() >= start.getX()
&& toCheck.getX() <= end.getX()
&& toCheck.getY() >= start.getY()
&& toCheck.getY() <= end.getY()
&& toCheck.getZ() >= start.getZ()
&& toCheck.getZ() <= end.getZ();
}
this is the method
It loops through each portal, but the ifcheck is always false
wdym
like the Vector class does
I dont understand
yeah u have to Math.min / Math.max
so you would need to find the min and maxs of start and end
ohhh
how do i check if end is bigger than start? getting each axis and doing it?
since you always have 2 corners no matter what, you would just have to Math.min and Math.max the values
like min(start.x, end.x)
ohh okay
you do that for x, y and z and have your 2 corners
then you can do your check if its between
nvm it returns an int
so I make a location with all the max ints
and thats my start?
no you then just compare the values with your toCheck
basically exactly what the Vector class does
return
toCheck.getX() >= Math.max(start.getX(), end.getX()
&& toCheck.getX() <= end.getX()
&& toCheck.getY() >= start.getY()
&& toCheck.getY() <= end.getY()
&& toCheck.getZ() >= start.getZ()
&& toCheck.getZ() <= end.getZ();
like the first condition
for all?
return
toCheck.getX() >= Math.max(start.getX(), end.getX())
&& toCheck.getX() <= Math.min(start.getX(), end.getX())
&& toCheck.getY() >= Math.max(start.getY(), end.getY())
&& toCheck.getY() <= Math.min(start.getY(), end.getY())
&& toCheck.getZ() >= Math.max(start.getZ(), end.getZ())
&& toCheck.getZ() <= Math.min(start.getZ(), end.getZ());
wrong order
min is max and max is min?
oh
ty
public boolean isInAABB(Location toCheck, Location start, Location end) {
if (!toCheck.getWorld().equals(start.getWorld()))
return false;
return
toCheck.getX() >= Math.min(start.getX(), end.getX())
&& toCheck.getX() <= Math.max(start.getX(), end.getX())
&& toCheck.getY() >= Math.min(start.getY(), end.getY())
&& toCheck.getY() <= Math.max(start.getY(), end.getY())
&& toCheck.getZ() >= Math.min(start.getZ(), end.getZ())
&& toCheck.getZ() <= Math.max(start.getZ(), end.getZ());
}
still the same thing
Hello everybody, can someone please take a look at my problem ?
https://www.spigotmc.org/threads/biomeprovider-crash.557387/
i mean
if you already have the start and end organized
I m sorry if thats wrong, its very confusing
you dont need to call Math.min .max
he does. bet the start and end is just what point he set first. so if start is the bigger point of both the first check will fail instantly
well
in this case
he should save the correct locations from the beginning
like when he did config.set
yes the locations are correct indeed
i got this idea
i can make an array of all the blocks from the start to the end of the portal
and then check if the player's location is in that array
bad for performance i think though
return BoundingBox.of(start, end).contains(toCheck.toVector())```
oh
//Check if the player is in a portal and get which one is it
public Portal getPortal(Player player) {
for (Portal portal : vClasses.getPortals()) {
if(BoundingBox.of(portal.startBlock(), portal.endBlock()).contains(player.getLocation().toVector())) {
return portal;
}
}
return null;
}
it still says the portal is null
i would store the boundingbox in the portals instead of creating a new one every time
since when does BoundingBox exist?
If it still says its not a portal, your portal locations are wrong
I checked the locations and those are right
do yoru start/end cover only 1 pixel width? or the whole block?
the whole block
if your start is Block#getX() etc, then your end shoudl be Block#getX()+1
public class PlayerMove implements Listener {
@EventHandler
public void PlayerMove(PlayerMoveEvent e) {
if (e.getTo().getX() != e.getFrom().getX() || e.getTo().getY() != e.getFrom().getY() || e.getTo().getZ() != e.getFrom().getZ()) {
Player p = e.getPlayer();
PersistentDataContainer data = p.getPersistentDataContainer();
data.set(new NamespacedKey(Main.getPlugin(), "PlayerMoving"), PersistentDataType.INTEGER, 1);
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.getPlugin(), new Runnable() {
public void run() {
data.set(new NamespacedKey(Main.getPlugin(), "PlayerMoving"), PersistentDataType.INTEGER, 0);
}
}, 20L);
}
}
}
from this block to this one
yes, you are only covering a single pixel wide
this should set the PlayerMoving int to 1 and then remove it in 1s everytime the player moves right
oh
so what should i do now?
your start is fine, but your end needs to be one block out
or at least 0.5
depending on portal orientation
and how do i find the portal orientation
simpler would be, when you setup your portal scan the bounding box for portal blocks. Add each Block to a Set.
@golden kelp
Yes?
what will the portal do
just give the player some items
how
You end up with a Set of Block for that portal. In the portal event you can test using Set#contains(portalBlock)
by checking which portal it is, and each portal has a ItemStack[] in it
i wanted somethin like "he will enter the portal" or "the portal will give items x seconds"
how will it be
ohh
Anyone experience with contributing to spigot? I have a tiny case I am unsure how to handle properly
wizardly can u help me check this ;-;
?ask
If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply. Make sure you use the right channel regarding the topic of your question. Create a thread in case the channel is already in use!
but you dont really want to create 2 NamespacedKey objects everytime your player moves his mouse
and probably also dont want to create a task everytime
ok so
-player enters portal
-iterate through portal list, and check if any of them have the player inside them
-if any portal does, get the itemstacks from it
Tryjava return BoundingBox.of(start, end.add(1,1,1)).contains(toCheck.toVector())
PlayerPortalEvent?
Yes
yes that works
1,0,0 does too
and check if getFrom is inside your portal
now I just need to find the orientation and then add based on it
so long as it is an upright portal it will always be add(1,0,1)
you can safely do add(1,1,1) and that will handle end portals too
So I am trying to write wrappers for advancements in minecraft since there is very to little possible right now. Even getting the name of the advancement is currently not possible.
I am struggling to create a good interface for the following enum.
Making an interface that returns the enum values is easy enough, but I would like to preserve the enum type in some way such that you can easily compare them in the api. Eg event.getAdvancement().getDisplay().getType() == AdvancementType.GOAL.
Now I could combine the 2 but that feels rather odd. Any idea on how to approach this?
you are simply adjusting the end Location to cover teh whole width of a block in each direction
i would create an object for the player that would store his last action. you would listen for player events like move, eat and etc and set the last action to the current milliseconds. then you would have only 1 runnable to check if the last action minus now is greater than some value, like 3 seconds
that would miss off the very bottom block.
huh...
add(1,1,1) would be best
start will be: start - portalBlockFace.getDirection().multiply(0.5);
end will be: start (after the change) + portalBlockFace.getDirection()
also my whole custom stat system is based off of persistentdatacontainers should i change that cause i dont rly wanna pull from a database everytime someone takes dmg
now its not working
yo
if(BoundingBox.of(portal.startBlock(), portal.endBlock().add(1,1,1)).contains(player.getLocation().toVector())) {
portal;
}
yes
that was a question
As you are modifying the end Location you are likely not cloning it.
or do you mean obsidian?
but earlier it was working without cloaning
do you save your start/end?
and which is the blockstate of the nether portal frame
if you do you may have been modifying your end
BlockData****
yes i do
one sec
wait i dont
i dont store them in a variable
i just call them, add 1,1,1 and pass it
https://i.imgur.com/hjeYo49.png why wont it accept the integer?
yea but when i then add a different function that wants an integer
We need more info for anything else, what method, etc
is an integer not an object?
it should be an object but its stupid
Not tested, but this "should" find all portal blocks between your start/end. You can then simply call Set#contains on your portal block in yoru portal event to see if is this portal.
public Set<Block> findPortal(Location start, Location end) {
Set<Block> portal = new HashSet<>();
World world = start.getWorld();
for (int x = start.getBlockX(); x != end.getBlockX(); x += (start.getBlockX() < end.getBlockX())? 1: -1) {
for (int y = start.getBlockY(); y != end.getBlockY(); y += (start.getBlockY() < end.getBlockY())? 1: -1) {
for (int z = start.getBlockZ(); z != end.getBlockZ(); z += (start.getBlockZ() < end.getBlockZ())? 1: -1) {
Block block = world.getBlockAt(x, y, z);
if (block.getType() == Material.NETHER_PORTAL)
portal.add(block);
}
}
}
return portal;
}```
ty
Hello, does anyone has an idea to solve my problem ?
https://www.spigotmc.org/threads/biomeprovider-crash.557387/
@calm whale anything exceptions?
nothing, the server just stop responding
How is the voronoi map preloaded or generated?
Do you do it as you're trying to gen the world or before?
the voronoi is generated when I set my CustomBiomeProvider as BiomeProvider
I have this in my onEnable
It crash after "0"
yes it works
Ok
Crash report? Because creating a world can freeze the main thread
?paste
It's just creating the world then
Creating a world will freeze the main thread because the resources required to make a world
There is no fix for this
so explain me something please
I dont understand why it crashes tbh
Server creator lags the server natively as it's intensive
OH
I have school rn but that's how world creator functions
You can't run it async either
@calm whale how many colors are there?
private int count = 0;
public MapReader(){
voronoi = new Voronoi(2, 150);
}
public Biome getBiome(int x, int z){
count++;
System.out.println(count);
return BiomesEnum.getBiomeFromColor(voronoi.getPixels()[x + Voronoi.SIZE /2][z + Voronoi.SIZE /2]);
}```
Why does the count value never reach the 2048*2048 limit ?
Tbh for(BiomesEnum biomeΒ :Β values()){
Β Β Β Β Β if(biome.getColor()Β ==Β color){
Β Β Β Β Β Β Β returnΒ biome.getBiome();
Β Β Β Β Β }
Β Β Β }
don't worry about the colors that's not the point
You should use a map here
mmmmm
Instead of a for loop
it's from an enum so...
How many biomeenums are there?
27
@calm whale throw in a while loop that never ends and see how long it takes fornthe server to crash
The only thing that makes sense is the server thinks that it's frozen and crashes
why should I do that ?
This
As I say it actually doesn't
It just stops?
i'm on Paper and it detects when the server stop from responding.
The server doesn't stop by itself, I can't even shutdown it properly. Wait I make a video to show it.
public Portal getPortal(Location loc) {
for (Portal portal : vClasses.getPortals()) {
Set<Block> portalBlocks = findPortal(portal.startBlock(), portal.endBlock().add(1,1,1));
System.out.println(Arrays.stream(portalBlocks.toArray()).toList());
if(portalBlocks.contains(loc.getBlock())) return portal;
}
return null;
}
The set doesnt contain any elements
A chunk is 65,536 blocks and it's taking more than 1 second to figure out the biomes for a chunk
I did say untested. Check the math on the for loops. I may have got the increment wrong
Try to not print the progress and use a map instead of a for loop
Nit sure if printing takes place on the main thread but it slows progress
but how should I setup it ?
I know how to create a map, my question was where, but I figured out
Can do it anywhere tbh
In the biomeprovide class as a static block or on initialization
Maybe in the enum itself
Can't remember if that's possible
On teh for loops change teh for lop end condition to != instead of <=
Still empty
Don't think so, I put it in the mapReader constructor with the voronoi
public Set<Block> findPortal(Location start, Location end) {
Set<Block> portal = new HashSet<>();
World world = start.getWorld();
for (int x = start.getBlockX(); x != end.getBlockX(); x += (start.getBlockX() < end.getBlockX())? 1: -1) {
for (int y = start.getBlockY(); y != end.getBlockY(); y += (start.getBlockY() < end.getBlockY())? 1: -1) {
for (int z = start.getBlockZ(); z != end.getBlockZ(); z += (start.getBlockZ() < end.getBlockZ())? 1: -1) {
Block block = world.getBlockAt(x, y, z);
if (block.getType() == Material.NETHER_PORTAL)
portal.add(block);
}
}
}
return portal;
}
Yup that'll work
bro
But its still blocked
are you at this?
Sorry change to == not !=
Oh, np, and ty
i had a philosophy lesson
wnt to interval
and you still are talking about portals
yea sadly
to me
the blockdata of the portal frame
you can have a help that will end this
check it for me
okay
in something like PlayerInteractEvent
get the block
do a sout in the .getClass.getName
yea done
show it pls
ok
use setBlock
then get the block at that location
and get the class name
and print
use setBlock
for what location?
it is just for a test
I do
nope I was correct first time !=
the set was null that time
INSERT IGNORE INTO player_data (uuid, money, chips, team) VALUES (?, ?, ?, ?);```
For some reason, it inserts it again.
But how to use it with a plugin ? I build the jar with maven direct*ly into the plugins folder of my server then I start it into Intellij
@golden turret so when I do set, it sets the portal purple thing to water
Even if I launch my build in debug mode there is no debug available because it's running in a third party
Intellij is only hosting the terminal window of my bat script
And the block name is org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock
There is a way but i only know how to do it on your machine
Do you have any link or keyword to search on google ?
Intellij debugger spigotmc
from getState and getData pls
There's a page on how to do it
indeed
In this
LEGACY_AIR(0)
Is that where the output stops
[18:27:54] [Server thread/WARN]: Initializing Legacy Material Support. Unless you have legacy plugins and/or data this is a bug!
[18:27:57] [Server thread/INFO]: LEGACY_AIR(0)
yes
I can't stop the processs even with ctrl+c
@golden kelp alright
Make the map and array concurrent
Do you have a primary key against which a duplicate would be flagged as an error?
Ideally your UUID would be a PRIMARY KEY
me ?
I just made it primary.
i.e. before you executed that statement? Or you've done it just now?
Which array ?
Pixels array
ah ok
Also don't remove the map even though it didn't solve ur issue
It's still faster that way
If I install NMS for 1.16.1, what Minecraft versions will it be compatible with? just 1.16.1?
Not sure
I dont know too much abt concurrency so I'd use a map
Concurrent hashmap
Map the xz coords to the pixel
So I transform the pixel array to a ConcurrentHashMap too ?
Create a coordinate object that holds x and z with a equals and hashcode method
Yes
same for the HashMap biome color ?
Yes make it concurrent as well
This not necessarily the most efficient solution but it should fix your issue
Then you can optimize afterwards
Can you add fake lights around a player?
I want to make a spotlight effect.
My plan was to add lanterns around the player (invisibile) as I also want to change the colour (red/blue)
and if my plan is good, can I also increase the intensity
there is something called LightAPI
I DID A NOT SO GOOD THING
i published my premium resource for free and posted an update how do i remove the resource
oof
@vagrant stratus
could you remove my resource please? ASAP
@vagrant stratus sorry for the pings but i kinda need ur help asap :/
nop @humble tulip sadly it didn't fix it
https://www.spigotmc.org/posts/524682/
@kind coral
can u provide a link to docs, their repo looks so overwhelming
where you see hidden class stuff like the Bukkit class which invokes methods of classes that spigot-api doesn't have access to, is there a name for that type of coding?
oh
i was looking at their github
ty
I want to make it so the light follows the player all the time
so, on the player move event, i spawn a new light? and remove the old one?
& i would like if i could change the colour
Well same result?
? Bukkit calls methods on Server. Bukkit is a bridge class
public final class Bukkit {
private static Server server;
public static void setServer(Server server) {
Bukkit.server = server;
}
public static Server getServer() {
return server;
}
public static BlockData createBlockData(String data) {
return server.createBlockData(data);
}
}```
@calm whale can you add the debug statements back for count and send the output?
If that gives you any indication of how it works. CraftBukkit calls setServer()
It's how Bukkit and CraftBukkit are "linked"
it's on the way
it stop exactly at the same number
Is map you generate random?
Run it again see if it stops at the same number
hi i got this code and when the command be don it say player not found
//Get name
String name = e.getClickedInventory().getItem(4).getItemMeta().getDisplayName();
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "eco take " + name + " 1000");
player.sendMessage(ChatColor.GREEN + " Player");```
it stops at this number since I'm stuck on this xD
Oh wow
What's so special abt that number
Does it stop when it switches to another thread?
As it did before?
I renember I did something similar and it was working well
no idea
Reverd to your old getpixel method
But just make it synchrnised
And make sure everything else is thread safe
You should make a thread on discord tbh
already see dupes with this
It's okay we wait till he releases server with plygin and abuse it
@crisp steeple i like ur background
what do you mean?
thanks
youβre using Bukkit.dispatchCommand
not the api for whatever economy plugin youβre using
and?
bad
i could click whatever button that is and then in the same tick pay someone all my money
and it would try to take money that i donβt even have from me
I've always said that if you're using commands in your plugin, you might as well be using command blocks
Take a look at Vault. It will help you interact with economies more fluidly
i don't lose money no but i have essentials so do you now what api?
vault
ok
Oh, sorry, I didnβt see your message. Iβm importing the api- as done here: https://www.spigotmc.org/wiki/spigot-maven/
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
Prolly shouldβve turned ping off
But canβt change that now.
Is there a more efficient way to get exp from level without using a while loop? It severely lags the server at high levels.
private int getExpToLevel(int level){
if(level >= 0) return (int) (Math.pow(level + 1, 2) + (5 * (level + 1)));
return 0;
}
private long getExpFromLevel(int level){
if(level < 1) return 0;
long totalExp = 0;
while (level > 0){
level--;
totalExp += getExpToLevel(level);
}
return totalExp;
}```
Am I able to just include JDA in my plugin to make it link to a discord bot?
I did it before
Just don't call jda on the main thread
It works idk if it's the best practice
hm alright
I mean I'd try to cache xp per level or sth
am I able to do this on a 1.8.8 server
link me docs pls
I feel like there is a way to calculate it using an equation but I cannot figure out how
that depends on how your level system is built up
Is getexptolevel
And getlevelfromexp
Are they opposite methods
Like one does the opposite of the other?
The names are confusijg me tbh
Getexptolevel
getLevelFromExp gets the total amount of exp from that level. So, if you are level 1 should return 6, level 2 should return 20, level 3- 44.
new Thread(() -> {}).start();
I mean you probably wanna await the bot's bootstrap in onEnable
getExpToLevel is the amount of exp needed to get to the next level
Shouldn't the top one be getlevelfromexp and the variable be exp
Not level
It's throwing me off
I'll see the get the inverse of the eqn for u
Might be a quadratic
No, I don't need to get level from the exp.
So you want a more efficent way to get the amoint of xp needed to get to the next level?
No, I want a more efficient way to get the total exp from level, without using a while loop.
I've tried multiple equations but I couldn't find one that works for all levels.
Minecraft Wiki
Experience (EXP or XP for short) can be obtained by gathering experience orbs from mining, defeating mobs, breeding, trading, fishing, completing advancements,β[Java Edition only] and using grindstones and furnaces. Experience gained during a player's life affects the player's score on the death screen. While having no direct effect on the playe...
level^2 + 6 Γ level (at levels 0β16)
2.5 Γ level^2 β 40.5 Γ level + 360 (at levels 17β31)
4.5 Γ level^2 β 162.5 Γ level + 2220 (at levels 32+)
I'm using a custom exp system.
I don't. I have exp and level cached. When exp gets added, if it is at or above getExpToLevel() then level gets added and exp = 0. I don't store the complete total amount of exp that was collected, hence why I am trying to get it using an equation.
@shadow pulsar (18 + 29 n + 12 n^2 + n^3)/3
How can I remove NPC from server? using NMS
I have tried ```java
npc.getBukkitEntity().remove();
and ```java
ps.send(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER,npc));
try that formula
1/3 (n + 1) (n + 2) (n + 9)
which is that
n is the level
private int getExpFromLevel(int level){
if(level >= 0) return (level+1) * (level+2) * (level+9)/3
return 0;
}
fixed by using 2nd code and added
ps.send(new ClientboundRemoveEntitiesPacket(npc.getId()));
i sent a method for you to use above
How do I run a scoreboard loop async ?
BukkitRunnable#runTaskTimerAsynchronously
Are there any real benefits to using maven?
I know that it combines all the dependencies into one jar (uber jar) which might help with performance or whatever it is, however I find it more confusing than it needs to be.
Would it be bad if I just used vanilla java to make my plugins? It might be considered "bad practice", but aside from that?
if he's making simple plugins and just needs to import vault and some library which he will shade into the jarfile. maven is not necessary imo
i guess it depends on the use case
using maven or gradle is always a smart decision