#help-development
1 messages · Page 1441 of 1
there's a scoreboard api....
yeah but i've set up my scoreboard so it refreshes every second
heck the first line of the code uses it
its a shitty scoreboard system i have never bothered to change cuz it works sorta
?paste
this
idk what to do to make it better anyway
its ran every second
in a runnablr
Whats the best way to store the players last position with packets?
Hello, how to remove <plugin>:<command>?
in what context
you'll have to register it internally somehow, but all commands have a prefix
default minecraft commands are minecraft:<command>
the point of the prefix is as to not interfere with other plugins
if a server owner wants to remove that, the best way is through an external tab-completion controller
so i want to get the players last location but im not using events so theres no getFrom()
why are you not using events
the packet will probably only send what their new location is
yes thats what it does
:]
So what’s the issue
not so much "more stuff" as "less stuff"
I want to get the position the player came from but theres no build in function thing for that with packets
packet receiving is probably done before the player is moved server-side
It is
And it only contains the movement, not the full location
It’s not really possible to move the player before the packet is received
hello all! Is there a standard way to create a stopwatch in Spigot? (i.e. tell the player how long they took to do a task)
store System.currentTimeMillis, then subtract that stored value from System.currentTimeMillis when needed
perfect, thank you! That is exactly what I needed
are there methods for setting and getting localisednames in spigot 1.8.8?
currentyl makeing a 1.16 plugin 1.8 compatible
is it for material?
Actually yes, you need to use multi-project or something like that. But If you want to use libs, you can check this out https://www.spigotmc.org/threads/xseries-xmaterial-xparticle-xsound-xpotion-titles-actionbar-etc.378136/.
thx
I hope this works
if(event.getTo().getBlockX() != event.getFrom().getBlockX() || event.getTo().getBlockY() != event.getFrom().getBlockY()){
event.setCancelled(true);
}```
Y is the height right?
public void onDeath(EntityDeathEvent event) {
event.getDrops().clear();
event.getDrops().add(drops);
}
i believe (dont have my ide open rn though)
Y is height yes
ok
it didnt work for me for some reason
;/
iirc the returned collection only supports removals, not additions
pretty sure it works fine for both, though iirc the user is on 1.7 or something
reloads the config of the plugin
reloads the file returned by getConfig
you're probably caching it somewhere
And tested
the config loading code inside the plugin still needs to execute
ie where you call getConfig().getString etc
it's not gonna magically update all of the values you've already pulled out of the config
you have to pull the freshly loaded values out again
Well, how do i make a /pluginname reload command then?
depends on what you're doing
move your config loading code out of onEnable and then just call that method again
so move it out of onEnable and call the method in onEnable?
Whats the difference?
yes
the difference is that now you can call it without calling onEnable
pff I've been looking for a while but I don't find anything, I'm looking for bukkit code that makes you can lock a container WITHOUT a key
I found something like this
Block b = your block;
if (b.getBlockData() instanceof Chest) {
Chest chest = (Chest) b.getBlockData();
chest.setLock("someLock");
}
the block data will never be an instance of Chest
not that Chest, anyway
there are two Chest's
one for BlockData, the other for BlockState
uh
you have imported the BlockState one, but are getting the BlockData one
Block::getBlockData returns the block data; you want Block::getState
which returns the block state
which you can then call setLock on
@wraith rapids what time zone you in cause you always seem to be around? Or is ur sleep schedule just fucked
sleep is for the weak
Fair enough then
pff i understand it half but yea
you have imported org.bukkit.block.Chest but the getBlockData method returns an org.bukkit.block.data.type.Chest
you'll want to call getState which returns an org.bukkit.block.Chest
well it's not mt code xd
well it's still wrong
can you give me how i could fix it?
BlockState state = block.getState();
if (state instanceof Lockable) {
((Lockable) state).setLock("someLock");
state.update();
}```` Not sure what you are attempting to do, but thats how to set a lock for the block.
lockable is also a subtype of BlockState
Block itself is never actually subtyped by anything
you always want either Block::getBlockData or Block::getState
the latter in this case
yes... and Lockable is a type of BlockState
not a type of Block
a Block will never be an instanceof Lockable, but its BlockState might be
i want to make a command that is able to lock a chest for other people than the owner
save the uuid of the owner in the chest's pdc and cancel anyone else's opening attempts
there, fixed
lockette and blocklocker in particular
yea but i dont want to use signs/ keys
Then set a key using the players UUID and check it in the event to open it.
how can I get default world?
Explain?
Bukkit.getWorlds().get[0]

Overworld is always index zero and can never be unloaded
I died for 8 hours and lived in a fantasy world. But I'm alive again now.
glad to hear that
how can i get the player's uuid who executed the command?
this does not work
Player target = Bukkit.getServer().getPlayer(args[0]);
uhh i want to get the uuid of the players who executes the command :/
if (sender instanceof Player) {
UUID = sender.getUniqueId();```
okay
👍 😀
pseudo, so fix it to be proper code
and now i want to get the container where the person rightclicked on
something like this
if (event.getAction.equals(Action.RIGHT_CLICK_BLOCK) {
//Do Stuff
}
Hello, I made a plugin with one command by overriding onCommand in my main class that extends JavaPlugin, on now I overrided onTabComplete for that exact same command but that method doesn't even get called, I get the default player list tab completion instead... Why doesn't it get called ? It is registered in the plugin.yml file
onTabComplete(CommandSender sender, Command command, String alias, String[] args) with @Override
no errors?
Yes yes
then it should be called
Everything works, the command works but it is not called
debug (sysout)
There is no reason for it to not be called. In fact its impossible. JavaPlugin implements TabCompleter
real men use the async tab complete event anyway
^ Not Spigot
real men don't use spigot
:/
You'll be saying real men wear dresses next
they can wear dresses if they so choose
there is nothing more manly than being unquestionable and confident with your decisions
😮
Says the cucked 😉
did you register it on your main class?
this.getCommand("command").setExecutor(new Classname());
i'm going to cuck my fist into your ass
seesh
Ok my "compile and run" configuration wasn't compiling, sorry
mild oversight
Hi this code not work me very good who can fix me he
import org.bukkit.Location;
import org.bukkit.Material;
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.inventory.ItemStack;
public class leave_bed_inbepaarty implements Listener{
@EventHandler
public void onRightClick(PlayerInteractEvent er) {
ItemStack bed = new ItemStack(Material.RED_BED);
if (er.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (er.getItem() == bed) {
Player player = (Player) er.getPlayer();
Location lobby = LocationManeger.getLocation("lobby");
player.teleport(lobby);
}
}
}
}
nice class name
Yes
it may be beneficial to learn a common human language like english before trying to learn a common programming language like java
talking with computers is nice and all but you often end up having to ask help from fellow humans
lol that my code
true
you should tell it to work harder
huh
good thinking
i don't remember if event.getBlock returns the placed block for block place event
o
you may want to call getPlacedBlock or some sort of an alternative
most events happen before the thing they're for happens
that is, this event probably fires before the block is actually placed
so the block might not exist yet
check the javadocs
getServer().getPluginManager().registerEvents(new leave_bed_inbepaarty(), this);
this is how to register event
yes
sooo y my code dont work
what was your problem and code?
this is my code
i dont get eny errors in the console
that is not a problem
[11:52:43 ERROR]: Could not load 'plugins\rennstools.jar' in folder 'plugins' org.bukkit.plugin.InvalidDescriptionException: null is not properly structured.
bad plugin.yml
you should teach it some manners
I use spigot 1.8.8 api
@EventHandler
public void onPlacement(PlayerInteractEvent e) {
Player p = e.getPlayer();
if (e.getItem() == null || e.getItem().getType() != Material.RED_BED)
return;
if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
Location lobby = LocationManeger.getLocation("lobby");
player.teleport(lobby);
}
}
idk if this works also
idk how your server is also set up
is there a way to see on which block a player clicks?
I have this now but all blocks are accepted
@EventHandler
public void onContainerSelect(PlayerInteractEvent event) {
if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
}
}
https://paste.md-5.net/rutagiqalu.java
how would i place a block 1 block in front of the bedrock block placed
ow found it
if (block.getType().equals(Material.EMERALD_BLOCK))
what renn?
i want to make it so when a player places a bedrock block (imma use it as a barricade) it places a 2x3 wall in front of them
well I want to check if the block, the player rightclicks on, is a container (chest,enderchest,barrel etc) So can i make a list or something to check if the block.getType() is inside that list?
if(event.getAction() == Action.RIGHT_CLICK_BLOCK && block.getType().equals(Material.CHEST)) {
}
get the block's state and check if it's an instanceof Container or whatever the interface for those is
would this be possible
ye
imagine switching from intellij theme when it becomes darker ._.
some one helppppppppppppppppp
this is not working
what do you mean not working
@shy wolf
if (er.getItem() == bed) {
Player player = (Player) er.getPlayer();
Location lobby = LocationManeger.getLocation("lobby");
player.teleport(lobby);
}
the server not concting to this or something
what
you should not compare ItemStacks with ==
ugh
lol
go bomb some palestinian children or something
hi
DONT SAY THAT
WE ARE THE GOOD ONE
@shy wolf I legit did code for you , just change out what you need
lmao
ty
YOU NEED YO DIE RN
how can i select the block, the player right clicks on and make sure it does not move the 'inventory' of that block?
something like java Block b = event. ...
wdym move the inventory of that block
wdym inventory of the block
well i mean that it doesnt opens what is stored inside
what
:/
what are you trying to achieve
cancel the interact event or something
do you mean say if it were a chest it wont open?
yea thats what i meant :)))
@EventHandler
public void onContainerSelect(PlayerInteractEvent event) {
Block block = event.getClickedBlock();
if(event.getAction() == Action.RIGHT_CLICK_BLOCK && block.getState() instanceof InventoryHolder && block.getState() instanceof Lockable) {
//HERE
}
If it put event.setCancelled(true); inside the body of the if, will that block the chest from opening or just everything?
:/
How can i do crafting with custom material predicates?
can i even use an eventhandler inside my CommandExecutor?
the flies seem to disagree
i want to use an event inside the code for a command is that possible?
not really
an event will not be fired at the same time as a command is used
do you can't process them both at once
you can store data from an event and then access that data in a command handler
or vice versa
but you can't have both the command and the event being processed at once
if the person does /lock is says something like "right click on a block to lock it" and then an eventhandler looks if you click on it and then lock it
something like that :/
yes then you would have to store information that the player has executed the command and then have the event handler look at that information and act based on it
:/
Player p = (Player) sender;
p.sendMessage(Color("your message here"));
return false;
No need to cast to player. The sender has the sendMessage method.
hmm i'm really stuck at this
put the player in a set or something when they execute the command
and then check if the set contains that player when they click a block
players UUID
then lock the block and remove them from the set
real men use weak hashsets so they can put the Player in directly :fingerguns:
Real men never use anything weak.
weakness is subjective
a weak thing becomes a strong thing by mere virtue of being used by a real man
like this?
public static List<UUID> playersWhoExecuteThisCommandIdk = new ArrayList<>();
oh never worked with before
then expose it with a method that tests whether the player is in a set
public boolean isPlayerLockingSomething(UUID uuid) { return set.contains(uuid)
and so on
hello i have this https://paste.md-5.net/obupotehuz.java
it makes small barricade
but it doesnt always face the right way, i think its something to do with the pitch or yaw or something but i dont know how to fix it
i also want to make the blocks slowly break within 5 seconds but i dont know how :/
yes
and when they click a block, you remove them from the set
and if they were in the set, you do whatever you do to lock the whatever block they're clicking
wait is this an ArrayList?
set is abstract
yes
just like List is
you need to choose an implementation of Set to instantiate
for List you used ArrayList
for Set use HashSet
new HashSet<>()
oh
or any other set implementation you choose
does anybody know
with the method
uhh
you need to
- be able to add players to it -> create a public method that adds a player to it
- test if a player is in it -> create a public method that tests if a player is in it
- remove a player from it -> create a public method that removes a player from it
and those methods has to be in my main class wathever
or wherever else, doesn't really matter where they are
as long as they are in the same class as the Set
main class so ._.
i wes trying whan player right click an item the player tp to the lobby
idk how to get the sender its not inside the onCommand
the method should accept the player as a parameter
the method isn't concerned with where the player comes from or what the player is
the method's purpose is to mark a given player as wanting to lock a container
therefore it should take a Player as a parameter
and then do the thing
that is not how you declare a method with a parameter
public void addPlayer(Player player) {
and where do i get that player from??
doesn't matter
that's the problem of the guy calling the method
for the moment just focus on the method
but it gives an error
what is the error
that it cant find player
this is the whole class :/
package io.github.FourteenBrush.MagmaBuildNetwork;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.bukkit.entity.Player;
public class PublicMethods {
private final Set<UUID> playersWantingLock= new HashSet<>();
public void addPlayerToWantingLock() {
playersWantingLock.add(Player player);
}
}
that is not how you declare a fucking method
🤦
with a parameter
public void addPlayerToWantingLock(Player player) {
//your fucking code here
is saying I'm tired a good excuse?
no
no.
you make me want to go bomb palestinian children
NNYa got his 10 minutes of cardio for today
lmao
yes i know i was doing some random things idk
i have a recipe with iron in it, and i wanna accept only iron that has custom model data
yea lets go
you need to use ExactChoice rather than MaterialChoice
materialchoice accepts any itemstack that is of a specific material
exactchoice only accepts identical itemstacks
which includes model data and lore and whatever
but it won't work if item would have enchantments or display name
i'm not sure if you can, but you could try implementing the RecipeChoice interface yourself and doing the checks yourself
there are some classes in bukkit that you shouldn't implement, and recipechoice is probably one of them
if that doesn't cut it, listen to the prepare craft event or whatever it's called and do it manually
can anyone help?>
im trez confused
for some reason it cant resolve the method i just made
i'm going to throw a wild guess that you're trying to invoke it statically
well this is the method
oh yes the set is somewhere above this
public boolean testForUUIDInsideSet(Player player) {
if(playersWantingLock.contains(player.getUniqueId())) {
return true;
}
return false;
}
and i want to use it here
@EventHandler
public void onContainerSelect(PlayerInteractEvent event) {
Block block = event.getClickedBlock();
if(testForUUIDInsideSet()) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && block.getState() instanceof InventoryHolder && block.getState() instanceof Lockable) {
event.setCancelled(true);
}
}
}
you need to pass the player object into the testForUUIDInsideSet if statement
the method takes a parameter
testForUUIDInsideSet(event.getPlayer());
iknow
you need to supply this parameter
then the method is declared on a different class
obtain an instance of that class and call the method on that instance
but of course that means literally nothing to you since you don't know what an instance is, do you
hello does anyone know how to translate messages ?
huh?
i found this TranslatableComponent but it doesent help me at all because it is used for bungee and not for spigot
you do not understand what my question is or what is the problem?
oh yea
it is used for spigot
spigot uses the bungee chat api
as for why the fuck it was designed that way, don't ask me
TranslatableComponent no it is not it is used for bungee
it is also used for spigot
spigot includes the bungee chat api
spigot makes use of the bungee chat api
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
are you reading what I am saying
the guide you linked has a fucking section on how to use these on spigot
Send message in Spigot:
player.spigot().sendMessage(component)
tf calm down my mistake

private void loadGuns(final Player player) {
File[] files = guns.listFiles();
if (files.length == 0) {
warn("§eNot found files.."); return;
}
Arrays.asList(files).stream()
for (File file : files) {``` who is best ?
?
how about you don't do disk io on the main thread
@wraith rapids how expensive is it to run a Runnable task on an asnyc worker, then pipe back the result to the main thread?
depends on your definition of expensive
it will introduce a delay that may be significant depending on context
since the task will have to wait till it gets executed by a thread, and then it has to wait up to 50ms until it gets synced back to main
i see
the individual overhead of scheduling a single task is negligible but you don't want to be doing that for thousands of tasks as even the small overhead will add up
overloading the bukkit scheduler ends in tears
int x4 = block.getX(); int y4 = block.getY() +1; int z4 = block.getZ() +1; Location loc4 = new Location(player.getWorld(), x4, y4, z4); loc4.setDirection(player.getLocation().getDirection()); loc4.getBlock().setType(Material.BEDROCK);
how do i set the direction? that doesnt do anything ^
a good example of things not to do that with is to schedule 1000 tasks that each change the type of 1 block
Of the location or the player?
working on a territory plugin that notifies players whenever they enter a region
lets assume the server has 100 territory definition, each of them consist of a rectangle (tl and br coordinate)
what my problem is, it starts eating TPS when 100+ players are wandering around, even if movements are only checked at block ever/leave
this is why i want to move collision checks to async thread
doable, but you should do them in bulk
wdym bulk?
that is, add each player that moves more than 1 block to a set, and once all players have moved, process the new locations in bulk asynchronously, all at once
then notify them once the async computation is complete
oh i see
instead of scheduling a new async runnable on each playermoveevent
that'll overload the scheduler
since you don't actually need to modify the event, you can do the work asynchronously
if you had to f.e cancel the event based on the result, you'd have to keep doing it sync
and doing it asynchronously would only deadlock the server
yes, unfortunately. but here its not the case
i want it to be the direction
Bruh
so if a player is facing north it makes it north, etc
BlockFace
what’s it?
block.getrelative
The block?
he wants to build a small wall when a player places down bedrock
Ah
thank you
is there an event for when water drys up in the nether?
how would i use that?
@cold tartan i dont know if there's a specific event for this. I would use PlayerBucketEvent
water placed by player buckets should instantly disappear
How do you mean "dried up"? Water can;t be placed in the nether, other than by an ice block
pretty sure ice blocks don't work anymore either
i believe he means that a player right clicks with water bucket and places water on the ground
^^^
by that i mean how would i add it to my code
i wanna make a dumb video where I jump from a high place in the nether and bucket clutch
no water appears so thats impossible
not with plugins
Listen to the bucket event and manually place water I guess
thats what im doing^
Or the interact event
note that the bucket events are sort of buggy
expect an aneurysm if you want to modify the item result
there we go
what you mean with it ?
here it is
@EventHandler
public static void onBucketPlace(PlayerBucketEmptyEvent event) {
if (event.getBlock().getType() == Material.AIR) {
event.getBlock().setType(Material.WATER);
}
}
Does the if statement pass
yep
i think the nether might nuke water on physics updates or something
not sure how it works these days
Don’t think so
i’m reading all the files in a folder, and then you’ll read the data inside them and save it to an array
last i looked at it was over half a decade ago
GunLoad read = new GunLoad(player, YamlConfiguration.loadConfiguration(file));
You could place it in the nether in a 1.17 snapshot and it worked fine
nope everything works
#help-development message
can some1 help with it
Is there a way to block messages in certain areas?
Yeah Ik but Idk how I have to code that
Is there any event that listen when Player receive or re-new potion effect?
you'd check whether the player is in a region and if they are, block the message
?paste
With what?
how can i specify that the player has to give 0 arguments?
args.length == 0
==============
Hey
! I am kick with the message "Disconnected" when I right click on an npc made of packets.
Also, I'm kicked when I left click npc. "internal exception: io.netty.handler.codec.decoderException: Java.lang.NullPointerException" I don't know why. I watched this tutorial and copied it: https://www.youtube.com/watch?v=Ema8_qxQAXM I don't know what the problem was. My code is: https://paste.md-5.net/herokoyaxa.java
In this video, you will learn how to create a custom event for NPCs! Not using Citizens or ProtocalLib API. You will learn how those APIs do it! This video shows how to right-click an NPC and perform some sort of event. Whether it's opening a GUI or sending a message, you can do whatever you would like!
Patreon:
https://www.patreon.com/codedre...
oke
oke
i need help with this getRelative thing D:
https://paste.md-5.net/hoqufopozu.java
uhh does sender.sendMessage(""); work in the onCommand or do i need to cast it to a player?
Player p = (Player) sender ?
forget it
true
oh
or ```((Player) sender).sendMessage("");
like this
Player p = (Player) sender;
p.sendMessage("Right click a chest/ barrel etc to lock it..");
ya
Sender already has sendMessage
grrrrr
here is the video:
https://www.youtube.com/watch?v=qbWb4lAhx3M
wat
wdym
why are you sending video to this channel xD
cuz i was asking for help about it earlier
ah
player#sendMessage
what event are you using?
and where do i get the player from?
what event are you using brtoo
most events has Player attributes
like event.getPlayer()
look when someone rightclicks on a block and is inside the list, the event will cancel and say the player "block locked"
ow yea i forgot
i have to sleep more
EntityPotionEffectEvent
so you made it public and static after all
Is there a way loading Hashmap properties from Yaml Configuration?
so instead of actually learning how to use the language you reverted to your old nooby ways because that was too hard
very good
🎈
config.get(path).values(true) or something close
package de.tayfun.plugin.commands;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class ServerCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
ProxiedPlayer player = (ProxiedPlayer) sender;
player.connect(ProxyServer.getInstance().getServerInfo("Skywars_desert"));
return false;
}
why doesnt work this code and how can i fix it?
mmm
Technically if you want real time transformation use Maps::transformEntries or smtng
Can you tell me what getOldEffect() and getNewEffect() method do? I'm not really clear. I've read the javadocs.
smth like this? public String Loadmembers = cfg.getString("members:"); Members.get(loadmembers);
no
get you the old and new effect?
so cool
How can I detect If the invisibility potion ran out?
It would be the oldEffect
Ah, so OldEffect is the effect that ran out.
The action would be removed
And the cause would be expiration
Yes
That’s the essence of truth
does args[0].equals("") makes sense?
isEmpty
Usually when the string is constant we do it the other way around
So
"idh ".equals(other)
oh doesnt matter
not in this case but usually yes
and whats that?
args[0] could theoretically be null
NNY can explain
i'm going to explain my boot up your ass
nice
how can it be null?
it can't in this case
which is why it doesn't matter in this case
but usually yes
unless it's a primitive array, any of its elements may be null
It can be if some stupid guy decides to call onCommand on ur command executor instance
bukkit just has a contract where it says that the elements of the String array should not be null
they could still be null, but that would be a breach of bukkit's contract, so it blowing up wouldn't be your fault
great
I have this now
else if(args.length == 1 && args[0].equalsIgnoreCase("cancel")) {
Player p = (Player) sender;
MagmaBuildNetwork.playersWantingLock.remove(p.getUniqueId());
}
make it not public
make it not static
you should not expose internal state directly
create accessor methods that expose specific functions on that state
like I told you earlier
and like you had in place
but then deleted everything because you didn't know what an instance is
are you talking to me?
yes
oh
are you kidding
no
i fixed it all now
🥺
there is bo need of forcing oop concepts on beginners imo
well i'm teached in oop ._.
learning something right the first time around is infinitely better than learning something wrong and then having to unlearn it
being teached doesnt imply knowing
yea i learned it right i was just reading it wrong
im 2nd year software engineer student
most people in my class cant even write double forloop
nothing sticks as hard as a bad habit
which class you are?
demoman
or which year or idk how to ask xd
at high school or what?
Idk we dont have these things here 🙄
it means im done with 12 years of regular school
and after that i jouned a university course o 3 years
😮
OfflinePlayer op = Bukkit.getOfflinePlayer(args[0]);
if(!UserHandler.getInstance().playerExists(op)) {
msgHandler.sendError(sender, ERRORS.PLAYER_NOT_FOUND);
return true;
}```
/bal huiwfewohifwef = Player not found
/bal JordieYT = NPE pointing at the Bukkit.getOfflinePlayer
how do people not know how to write a double for loop in your class :/
idk
i even know
being teached doesnt imply anything directly
xd
yea my school thinks nah we wont teach them that so i learn the most things by myself..
how do you not know how to declare a method with a parameter
no this guy
got any ideas for my problem?
okay
i belive getofflineplayer returns null if player with that name havent joined the server yet
getOfflienPlayer alwasy returns a player.
should it
yeah, it's weird like that
the offline players name will be null if they are unknown
i'm guessing the npe is on either msgHandler.sendError or getInstance().playerExists
https://pastebin.com/rVDuaSq1 Points to line 25 in this file
oh wait i think im stupid
im assuming user.getUUID is returning null
ignore me for a sec
i mean your intellij looks fucked
tf is that theme
too much blue
XD
let me find mine
this is my theme atm ill put a spoiler bc light theme
dude my eyes are burning
the king we didnt know we needed
Hello , This code doesnt work as intended... Any help?
public void onInteract(PlayerInteractEvent event) {
Action action = event.getAction();
Player player = event.getPlayer();
Block block = event.getClickedBlock();
if(action.equals(Action.RIGHT_CLICK_BLOCK)){
if(block.getType().equals(Material.STONE)){
player.sendMessage(ChatColor.GREEN + "Ok works");
} else{
player.sendMessage(ChatColor.GOLD + "Doesnt work :/ ");}
}```
my eyes are already burned so doesnt matter
how does it differ from what you intended
put it in triple altgr please
Nothing happens as if i didnt register the event, but i did
like this
use == to compare enum constants
AHHHHH
ok
WHERES THE SPOILER
block might also be null
lets look for a different theme 🙄
equals wont work?
it does, but you should use ==
I normally use this theme but I decided to give a light theme a shot for a bit
Your current work will be fine, but if you start handling block in the else statement, you'll encounter problems
mhm ok
What's the code for registering your event?
Oh no
Input:
System.out.println(player.toString());
System.out.println(player.getUniqueId().toString());```
Output:
```CraftPlayer{name=JordieYT}
[23:33:38 INFO]: 26dbd890-c96d-46bf-aaf2-e1d180733ed2```
So why does if (player.getUniqueId().equals(user.getUUID())) {
Give a NPE?
user.getUUID() isnt null either
put each deference on a new line and you'll see
(player
.getUniqueId()
.equals(user
.getUUID())) {
or enable verbose npe messages on your server that i'm sure is running java 16
@coral sparrow
player is null then
or, well
the uuid returned could be null but i don't know if that's possible
but player.toString is fine
send actual code and the actual stack trace
ok one sec lemme try one more thing
That wasnt the problem lol dont worry... the error was from my side
spam
Ah, ok.
Awesome 👍
thanks
how can i launch a process in java, interactively, from a string?
does somebody know how I can code a plugin where somebody will connect to an other server?
ProcessBuilder p = new ProcessBuilder(args); takes either a string (no arguments) or an array of strings
place down a sign at your server spawn telling the player to connect to another server
doesn't multiverse portals do the cross ip thing?
no?
Thats BungeeCord
is multiverse core or something good?
https://pastebin.com/aCqhzD9M
https://pastebin.com/X4TsbUR6
@wraith rapids
Output:
https://pastebin.com/0Wp0izyH
(for the record /bal with 0 args works fine)
[16:20:55]: Command being ran: cmd /c echo hi
[16:20:55]: Launching (List<String>)...
hi
[16:20:55]: Launching (String)...
java.io.IOException: Cannot run program "cmd /c echo hi": CreateProcess error=2, The system cannot find the file specified```
any ideas?
i somehow need to split the String into a List<String> but i cant split strings passed as arguments
say i were to run cmd /c echo "This is a multi-word argument encapsulated in a string."
Keep going, eventually you'll give us enough to work with
who?
you
oh
well i have this code:
public static void StartProcess(List<String> command){
final ProcessBuilder p = new ProcessBuilder(command);
p.inheritIO();
try {
p.start().waitFor();
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
}
public static void StartProcess(String command){
final ProcessBuilder p = new ProcessBuilder(command);
p.inheritIO();
try {
p.start().waitFor();
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
}```
and im calling it like this:
String[] cmd = new String[]{"cmd", "/c", "echo", "hi"};
String command = String.join(" ", cmd);
Console.WriteLine("Command being ran: " + command);
Console.WriteLine("Launching (List<String>)...");
Util.StartProcess(Arrays.asList(cmd));
Console.WriteLine("Launching (String)...");
Util.StartProcess(command);```
keep in mind this is a demo of the issue i'm having
what i want to be able to do is use Util.StartProcess(command) with arguments
dunno what else i can say @eternal oxide
not p
@wraith rapids
what do they mean its working with a key?
@eternal oxide
yes
because if you use them as one string it just doesnt work as its trying to launch "cmd /c echo hi" as an executable
@paper viper every argument needs to be separated
what
yes
yes ik they are separated
how does that have to do with the actual file
like im refeerring to a direct path
to the actual cmd.exe file
in place of the cmd subcommand
oh, nope
if you were to launch {"cmd", "/c echo hi"} it'd pass "/c echo hi" as args[0] which cmd will complain about
Does anyone know how to make ur plugin support other placeholders?
PAPI
you have to look at the papi api
ok
Guys I write a Shulker Backpack code but when I left click the shulker in inventory a error occurs in the console.This is the code https://paste.md-5.net/ikawigomon.java I guess there is a check and cast error at the line 20/21.I tried to fix it but I couldn't.How can I fix it?
nano "C:\Some Filename.txt" would get split into {"nano", "\"C:\\Some", "Filename.txt\""}
no, you have to add the extra backslash from the space
iirc
and also, you should never even use split
you cant escape out spaces under windows
wait whaa?
C:\"Test Folder"\File.txt
you can
well actualy
hm
nvm the space is still there
but why are you using split tho?
because i dont know any better way to split arguments?
kinda?
basically i have a function to launch a process, that takes a string as input
public static void LaunchProcess(String command) { /*code*/ }
(cmd /c <command> on windows or bash -c <command> on linux/mac)
You could use Runtime.exec(String cmd)
it returns a Process
then you can run that using start
yep, but Process doesn't have inheritIO()
it doesn't, but you can read the output
well, the inheritIO() is a big part in this
but what do they mean with key?
named item
bruh
yeah vanilla lets you do that
i'm making a plugin that does not use named items
to lock something
and then i see this...
listen for PlayerInteractEvent and cancel it
wait
well, you CAN use setLock but once someone figures out the key you set...
im passing both input and output
for example it runs a minecraft server
look if I do the command /protect, the player will be added at a hashset and the eventHandler below will check if you're in that and then lock the item you right click on (if its lockable)
@EventHandler
public void onContainerClick(PlayerInteractEvent event) {
Block block = event.getClickedBlock();
if(MagmaBuildNetwork.playersWantingLock.contains(event.getPlayer().getUniqueId())) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && block.getState() instanceof InventoryHolder && block.getState() instanceof Lockable) {
event.setCancelled(true);
( (Lockable) block ).setLock("lock");
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', "&2Locked!"));
MagmaBuildNetwork.playersWantingLock.remove(event.getPlayer().getUniqueId());
}
else {
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', "&2This block can't be locked!"));
MagmaBuildNetwork.playersWantingLock.remove(event.getPlayer().getUniqueId());
}
}
}
easy to bypass
🙄
just rename an item to "lock" in anvil
youre using setLock
how does processbuilder accept input tho?
yea thats what i realized now but i want to lock something based on the user their uuid
you can do ProcessBuilder#inheritIO()
oh, like internally?
Yes
no idea
well..
i dont know which method i could use to avoid keys
Cause Im looking at the docs for it
and i dont see anything that allows it to execute another command
or smthing
@tardy delta implement it yourself
use PlayerInteractEvent, if its locked, cancel the event
...
i even havent the lock
setLock requires a key i know atm but i want to avoid that
you dont need a lock if you're canceling the event for every other uuid
wdym?
Ah, I see what you are talking about now
some comamdns have something like "press enter to continue"
and require that interaction
I see
and minecraft servers for example require console input
well not require but its useful to have
but how would i link a chest to someones uuid than?
just make it so that when the chest is "locked" and bound to a uuid, cancel the event when any other player tries to click on the chest
yea
you dont need setLock for that
but
hashmap
tell me more
if you use setLock() players are required to have the named item
ah?
any idea guys?
manually processing input i guess?
final Process p = Runtime.exec("cmd"); // or whatever full command to use
final BufferedReader output = new BufferedReader(new InputStreamReader(p.getInputStream()));
final BufferedWriter input = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
input.write("AGREE"); // writes agree into the actual console input
input.flush();
then you need to have a blocking thread
of some sort if you want to wait
for the interaction
and make sure that the input/output is syncronized too
just in case
oh i'm using a hashset for the uuids
can i use items in a hashmap that are linked together and then use them together or something?
and what is pr?
final Process p = Runtime.getRuntime().exec("cmd"); // or whatever full command to use
final BufferedReader output = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter input = new BufferedWriter(new OutputStreamWriter(System.out));```
i guess this would work?
so i put an uuid for the player but how do i link it with a chest?
the location or something?
yeah ig if you want to also do io for java
and that would work
and also wdym by pr
oh
i meant p
location will work, yes
sorry
ah
you cant actually do that
you need to listen to the input of the system.in
and then send it into the input of the process
store the players UUID in the chests PDC, then test for it on interact
oh
that only creates a reader for the input of the java app, but doesnt correctly send it to the actual process itself
persistent data container
oh wait because im not calling the funcion
you need to have multiple threads prolly
one will use a while loop to continuously read the System.in
then when it finds a line which is entered in
well getting output works..
execute the method write the input
for the process
something like this?
something like this to lock a container?
container.set(key, new UUIDDataType(), uuid);
yeah its pretty slow lol
inheritIO doesnt break colors either
ill see if it works with cmd /c + command
if you're using pdc you dont need the hashmap
well this is all new for me
managed to get it workign @paper viper
apparently the solution was right in front of us
but would this work?
container.set(key, new UUIDDataType(), uuid);
final Process p = ...;
final BufferedWriter input = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
final BufferedReader output = new BufferedReader(new InputStreamReader(p.getInputStream()));
protected void readProgramInput() {
// code for reading input from java app (separate thread)
final Scanner scanner = new Scanner(System.in);
while (p.isAlive()) {
while (!scanner.hasNextLine()) {} // block thread and wait for input
final String line = scanner.nextLine();
sendProcessInput(line);
}
}
protected synchronized sendProcessInput(final String line) {
input.write(line);
}
protected void readProcessOutput() {
// code for reading output from process (separate thread)
while (p.isAlive()) {
final String line = output.readLine();
while (line == null) {
line = output.readLine();
}
ssendJavaOutput(line);
}
}
protected synchronized sendJavaOutput(final String line) {
System.out.println(line);
}
breh
and container is the block i select
public static void StartProcess2(String command){
final ProcessBuilder p = new ProcessBuilder(Arrays.asList("cmd", "/c", command));
p.inheritIO();
try {
Console.WriteLine(String.format("Launching command: %s", command));
p.start().waitFor();
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
}```
If I wanted to give a player a particle trail, that they could toggle on/off, would it be better to hashmap or arraylist it?
this SEEMS to work
what
yes
well, assuming container is the pdc instance
i mean i can try adding args with spaces
so your command could be something like echo hi?
yep
how do i get the container? like this?
Block container = event.getClickedBlock();
owh
pdc instance
cmd in itself doesnt take that much resources
how do i get that one xd
you would first need to check if the block is a chest or other container
yea i have that
then container.getPersistentDataContainer().set(...)
wat
yeah java still includes OSInfo.WINDOWS_95
🥲
This is probs gonna be stupid, but can i give a falling block more friction?